Expand description
Tamper-evident audit hash chain (SPEC §9).
Every trace record carries the hash of the previous record (prev_hash), forming an
append-only chain: altering any past record changes its hash and breaks every link after
it. The chain is re-derivable by an external auditor from the stored records alone —
so hashing must not depend on struct field order or on which serde features are compiled
in. We achieve that by canonicalizing to sorted-key, whitespace-free JSON before hashing.
A record hashes over its entire content including its own prev_hash, but not
any field holding its own hash (that would be circular) — hence trace records store
prev_hash only, and their own hash is derived on demand via record_hash.
Constants§
- GENESIS_
HASH - The
prev_hashof the first record in a chain: 64 hex zeros (SHA-256 width).
Traits§
- Chained
- A record that participates in the hash chain by exposing the previous record’s hash.
Functions§
- canonical_
json - Canonical JSON encoding of a value: object keys sorted lexicographically at every depth, no insignificant whitespace.
- record_
hash - The hash of a record:
SHA-256over its canonical JSON, hex-encoded. - sha256_
hex - Hex-encoded SHA-256 of arbitrary bytes.
- verify_
chain - Verify that
recordsform an unbroken chain starting fromgenesis.