Skip to main content

Module hash

Module hash 

Source
Expand description

SHA-256 content addressing per SPEC §6.

The content id for a record is sha256(canonical_json(payload)), lower-case hex, prefixed with the string "sha256:". Because the hash is over the canonical form (§5), two payloads that are semantically equivalent (e.g. the same keys in a different order, or a string with an alternative Unicode normalization form) map to the same id.

Constants§

HEX_LEN
Length of the hex digest portion of an id (64 hex chars for SHA-256).
ID_PREFIX
Prefix applied to every content id. Parsers use it to disambiguate future hash algorithms (e.g. "blake3:") if we ever add them.

Functions§

content_id
Compute the content id for a payload.
is_valid
True if s is a syntactically valid content id (sha256: + 64 lowercase hex).