Skip to main content

Module hashchain

Module hashchain 

Source
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_hash of 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-256 over its canonical JSON, hex-encoded.
sha256_hex
Hex-encoded SHA-256 of arbitrary bytes.
verify_chain
Verify that records form an unbroken chain starting from genesis.