Class EventFormat
Hashing, IDs, signatures and redaction of persistent data units, the events of the room graph.
Inherited Members
Namespace: Uniform.Matrix.Protocol.Server
Assembly: Uniform.Matrix.Protocol.Server.dll
Syntax
public static class EventFormat
Remarks
Events are JsonObjects, as signatures and hashes cover the exact fields, including ones this library does not model.
Methods
| Edit this page View SourceComputeEventId(JsonObject, RoomVersion)
Return the event ID: $ and the URL-safe base64 reference hash of the redacted event.
Declaration
public static string ComputeEventId(JsonObject pdu, RoomVersion version)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonObject | pdu | |
| RoomVersion | version |
Returns
| Type | Description |
|---|---|
| string |
ContentHash(JsonObject)
Return the content hash: SHA-256 of the canonical event without unsigned, signatures and hashes.
Declaration
public static string ContentHash(JsonObject pdu)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonObject | pdu |
Returns
| Type | Description |
|---|---|
| string |
HasValidContentHash(JsonObject)
Return whether hashes.sha256 matches the content; a mismatch means the event must be redacted before use.
Declaration
public static bool HasValidContentHash(JsonObject pdu)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonObject | pdu |
Returns
| Type | Description |
|---|---|
| bool |
HasValidSignature(JsonObject, RoomVersion, string, string, string)
Return whether serverName's key keyId validly signed the redacted event.
Declaration
public static bool HasValidSignature(JsonObject pdu, RoomVersion version, string serverName, string keyId, string publicKey)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonObject | pdu | |
| RoomVersion | version | |
| string | serverName | |
| string | keyId | |
| string | publicKey |
Returns
| Type | Description |
|---|---|
| bool |
HashAndSign(JsonObject, RoomVersion, string, string, string)
Add the content hash and the server's signature over the redacted event, as when creating an event.
Declaration
public static void HashAndSign(JsonObject pdu, RoomVersion version, string serverName, string keyId, string secret)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonObject | pdu | Event to hash and sign in place. |
| RoomVersion | version | Room version, for redaction. |
| string | serverName | Signing server. |
| string | keyId | Key ID, e.g. |
| string | secret | Ed25519 seed, base64. |
Redact(JsonObject, RoomVersion)
Return a copy with only the keys the room version keeps under redaction; content is emptied except for keys that protect the room's integrity.
Declaration
public static JsonObject Redact(JsonObject pdu, RoomVersion version)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonObject | pdu | |
| RoomVersion | version |
Returns
| Type | Description |
|---|---|
| JsonObject |
Sign(JsonObject, RoomVersion, string, string, string)
Add the server's signature to an event another server built and hashed, such as an invite of this server's user.
Declaration
public static void Sign(JsonObject pdu, RoomVersion version, string serverName, string keyId, string secret)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonObject | pdu | |
| RoomVersion | version | |
| string | serverName | |
| string | keyId | |
| string | secret |