Make ty happy
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
from resolvematrix import ServerResolver
|
||||
from types import SimpleNamespace
|
||||
from collections import Counter
|
||||
|
||||
import vona.config as config
|
||||
import nacl.encoding
|
||||
import nacl.signing
|
||||
import time as ti
|
||||
import hashlib
|
||||
@@ -15,7 +17,7 @@ import re
|
||||
version = "1.5.0"
|
||||
|
||||
|
||||
def canonical_json(value):
|
||||
def canonical_json(value: dict | list) -> bytes:
|
||||
return json.dumps(
|
||||
value,
|
||||
ensure_ascii=False,
|
||||
@@ -24,7 +26,7 @@ def canonical_json(value):
|
||||
).encode("UTF-8")
|
||||
|
||||
|
||||
def sign_json(data):
|
||||
def sign_json(data: dict) -> dict:
|
||||
parts = config.signing_key.split()
|
||||
base64_key = parts[2]
|
||||
|
||||
@@ -53,7 +55,7 @@ def sign_json(data):
|
||||
return signed_json
|
||||
|
||||
|
||||
def sign_json_without_discard(data):
|
||||
def sign_json_without_discard(data: dict) -> dict:
|
||||
parts = config.signing_key.split()
|
||||
base64_key = parts[2]
|
||||
|
||||
@@ -86,7 +88,7 @@ def sign_json_without_discard(data):
|
||||
return data
|
||||
|
||||
|
||||
def make_event_id(seed=None):
|
||||
def make_event_id(seed: str | int | None = None) -> str:
|
||||
if seed is not None:
|
||||
random.seed(seed)
|
||||
|
||||
@@ -104,7 +106,7 @@ def make_event_id(seed=None):
|
||||
return event_id
|
||||
|
||||
|
||||
def event_hash(event_object):
|
||||
def event_hash(event_object: dict) -> str:
|
||||
event_object = dict(event_object)
|
||||
|
||||
event_object.pop("unsigned", None)
|
||||
@@ -174,7 +176,7 @@ def redact_event(
|
||||
event: dict,
|
||||
for_event_id: bool = False,
|
||||
room_ver: int = 1,
|
||||
):
|
||||
) -> dict:
|
||||
# Returns a redacted event as per
|
||||
# the algorithm for v1 to v11 rooms.
|
||||
|
||||
@@ -272,7 +274,7 @@ def redact_event(
|
||||
def hash_and_sign_event(
|
||||
event_object: dict,
|
||||
room_ver: int = 1,
|
||||
):
|
||||
) -> dict:
|
||||
content_hash = event_hash(event_object)
|
||||
event_object["hashes"] = {"sha256": content_hash}
|
||||
stripped_object = redact_event(
|
||||
@@ -288,7 +290,7 @@ def hash_and_sign_event(
|
||||
def make_ref_hash(
|
||||
event: dict,
|
||||
room_ver: int = 3,
|
||||
):
|
||||
) -> str:
|
||||
stripped = redact_event(
|
||||
event=event,
|
||||
for_event_id=True,
|
||||
@@ -309,7 +311,7 @@ def make_ref_hash(
|
||||
return "$" + evt_hash
|
||||
|
||||
|
||||
def room_version_from_id(room):
|
||||
def room_version_from_id(room) -> str:
|
||||
room_id_no_sigil = (
|
||||
room
|
||||
.replace("!", "")
|
||||
|
||||
Reference in New Issue
Block a user