Skip to main content

Module chain

Module chain 

Source
Expand description

Proof-event chain and merkle-tree helpers.

Matches tools/tf-types-ts/src/core/chain.ts byte-for-byte via conformance/chain-vectors.yaml.

  • event_hash(event)sha256:<hex> over the canonical JSON of the event with its signature field removed. This is the bytes a signer actually signs; putting the signature inside the event would make the hash self-referential.
  • verify_chain(events) → asserts every events[i].parent_hash equals event_hash(events[i-1]) for i > 0 (the first event has no parent).
  • merkle_root(events) → sha256 over pair-wise concatenated hashes, duplicating the last leaf at each odd level (Bitcoin convention).
  • chain_hash(events) → rolling sha256(prev || event_hash) seeded with 32 zero bytes.

Enums§

ChainError

Functions§

canonical_of
Minimal serialization helper used by tests that need to serialize an arbitrary Serialize value to canonical JSON.
chain_hash
Rolling chain hash: seeded with 32 zero bytes, then for each event the hash is sha256(prev || sha256_bytes_of_event).
event_hash
The sha256:<hex> hash of an event’s signed payload.
event_signed_payload
Canonical JSON of an event with its signature stripped.
merkle_root
Merkle root over the event hashes. Empty trees return a sentinel zero hash; single-event trees return that event’s hash; otherwise pair-wise hash up, duplicating the last leaf when a level has an odd number of nodes.
verify_chain
Verify a chain of events. events[0] may have no parent_hash; every subsequent event must declare parent_hash == event_hash(events[i-1]).