mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-09-08 11:31:55 +00:00
Add hash of current state to events
This commit is contained in:
parent
3b4dec442d
commit
97a096b507
@ -75,6 +75,7 @@ class SynapseEvent(JsonEncodedObject):
|
||||
"signatures",
|
||||
"prev_state",
|
||||
"auth_events",
|
||||
"state_hash",
|
||||
]
|
||||
|
||||
required_keys = [
|
||||
|
@ -81,6 +81,15 @@ def compute_event_signature(event, signature_name, signing_key):
|
||||
|
||||
def add_hashes_and_signatures(event, signature_name, signing_key,
|
||||
hash_algorithm=hashlib.sha256):
|
||||
if hasattr(event, "old_state_events"):
|
||||
state_json_bytes = encode_canonical_json(
|
||||
[e.event_id for e in event.old_state_events.values()]
|
||||
)
|
||||
hashed = hash_algorithm(state_json_bytes)
|
||||
event.state_hash = {
|
||||
hashed.name: encode_base64(hashed.digest())
|
||||
}
|
||||
|
||||
hashed = _compute_content_hash(event, hash_algorithm=hash_algorithm)
|
||||
|
||||
if not hasattr(event, "hashes"):
|
||||
|
Loading…
Reference in New Issue
Block a user