An Event coming from the server.
Summary
Types
@type t() :: %EventSourcingDB.Event{ data: any(), datacontenttype: String.t(), hash: String.t(), id: String.t(), predecessorhash: String.t(), signature: String.t() | nil, source: String.t(), specversion: String.t(), subject: String.t(), time: String.t(), traceparent: String.t() | nil, tracestate: String.t() | nil, type: String.t() }
Functions
@spec verify_hash(t()) :: :ok | {:error, EventSourcingDB.Errors.HashVerificationFailed.t()}
Verifying an Event's Hash
To verify the integrity of an event, call the Event.verify_hash function on the event. This recomputes the event's hash locally and compares it to the hash stored in the event. If the hashes differ, the function returns an error:
alias EventSourcingDB.Event
case Event.verify_hash(event) do
:ok -> # hash is valid
{:error, reason} -> # ...
endNote that this only verifies the hash. If you also want to verify the signature, you can skip this step and call verify_signature directly, which performs a hash verification internally.
@spec verify_signature(t(), any()) :: :ok | {:error, EventSourcingDB.Errors.HashVerificationFailed.t()} | {:error, EventSourcingDB.Errors.MalformedSignature.t()} | {:error, EventSourcingDB.Errors.SignatureMissing.t()} | {:error, EventSourcingDB.Errors.SignatureVerificationFailed.t()}
Verifying an Event's Signature
To verify the authenticity of an event, call the Event.verify_signature function on the event. This requires the public key that matches the private key used for signing on the server.
The function first verifies the event's hash, and then checks the signature. If any verification step fails, it returns an error:
alias EventSourcingDB.Event
verification_key = # public key as Ed25519 binary
case Event.verify_signature(event, verification_key) do
:ok -> # signature is valid
{:error, reason} -> # ...
end