SHA-256 Hashing
The principle
Section titled “The principle”JSON canonicalization: sorted keys · no whitespace · UTF-8 encoding. SHA-256 over the canonical bytes. If the hash depended on key ordering, whitespace, or encoding choice the proof would break — two parties computing the hash from the same JSON must always get the same answer. Otherwise the chain-of-title is fiction.
The real, shipped code paths
Section titled “The real, shipped code paths”This exact discipline ships in production today in two places:
- DefendableCloud (
api/app/hashing.py, used byapi/app/ledger.py): canonical JSON viaorjson.dumps(obj, option=orjson.OPT_SORT_KEYS), thensha256_hex(canonical(payload)). This is what backs the per-orgDCR-*hash chain at/ledger+/ledger/verify. - DefendableRouter (
core/pricing.py/ receipt writer): canonical JSON withsort_keys, fixed separators,Decimalrendered to 2-decimal strings, and ISO timestamps — hashed intochecksum_sha256for each JSONL receipt line (checksummed, not chained).
Why determinism matters
Section titled “Why determinism matters”Same algorithm · same output · every time. A buyer, a regulator, or a model can recompute the hash from the canonical JSON and get the same 64 characters the issuer stamped — no trust required, no round-trip required.
🐝 Operator-grade · books and records · to the shed.