Expand description
Domain-tagged, length-prefixed BLAKE3 hash chain (T-1.B.1 + T-1.B.6).
§Framing
Two hashes participate in the chain:
-
payload_hash—blake3(canonical_payload_bytes). The canonical encoding of aserde_json::Valueis the ordered, no-whitespace form produced bycanonical_payload_bytes. Object keys are sorted lexicographically; arrays preserve order; numbers, strings, and booleans are emitted in their canonical JSON form. This makes the hash stable across re-serialization: aValueparsed from JSON and re-serialized via the canonical encoder produces the same bytes regardless of the original key order or whitespace. -
event_hash— domain-tagged, length-prefixed framing:event_hash = blake3( DOMAIN_TAG_EVENT_HASH // 1 byte: 0x01 || prev_event_hash.len() as u64 (LE) // 8 bytes || prev_event_hash bytes // 32 bytes (or 0 if genesis) || payload_hash.len() as u64 (LE) // 8 bytes || payload_hash bytes // 32 bytes )
§Why length-prefix + domain tag (T-1.B.6 — THREATS T-EV-5)
Without length prefixes, two distinct (prev, payload) splits could
concatenate to the same byte string and collide. Example: prev = "AB",
payload = "CD" vs prev = "ABC", payload = "D" both yield "ABCD".
Length prefixes make the boundary unambiguous.
Without a domain tag, an event_hash byte string could be
reinterpreted as some other domain’s hash input (e.g. an audit_hash)
and collide cross-domain. The 1-byte DOMAIN_TAG_EVENT_HASH = 0x01
reserves a domain-separated input space; future domains take other
tags (0x02 audit, 0x03 trace seal, …).
The framing_resists_boundary_confusion proptest (≥200 cases) asserts
that no two distinct (prev, payload) pairs produce the same
event_hash.
Constants§
- DOMAIN_
TAG_ EVENT_ HASH - Domain tag for
event_hashframing. Reserved: 0x01. - HEX_
HASH_ LEN - Length-in-bytes of a hex-encoded BLAKE3 hash (32 bytes → 64 hex chars).
Functions§
- canonical_
payload_ bytes - Canonical, deterministic JSON encoding of a payload
Value. - event_
hash - Compute
event_hashfor an event with the given previous hash and payload hash, both as hex strings. - payload_
hash - BLAKE3 hash of the canonical payload bytes, hex-encoded.
- seal
- Recompute
payload_hashandevent_hashfor an event in-place.