Documentation Index
Fetch the complete documentation index at: https://docs.xandrlabs.ai/llms.txt
Use this file to discover all available pages before exploring further.
kbHashFromEnvelope() is the primary identity function in ALX Protocol. Given a canonical envelope object, it projects only the hash-scoped fields, sorts sources, serializes the result with canonicalize(), and then computes keccak256("KB_V1" + canonicalJson). The resulting hex string is the kbId that the registry stores on-chain.
Because identity is content-derived, any change to a hash-scoped field changes kbHash. Fields outside the hash scope — timestamps, curator address, signatures, and transport metadata — do not affect identity.
Hash scope
Only the following fields from the envelope are included in the hash preimage. All other fields are stripped before hashing.| Field | Type | Description |
|---|---|---|
type | string | KB type identifier |
domain | string | Domain string (e.g. "software.security") |
sources | string[] | Parent kbHash values; sorted lexicographically |
artifactHash | string | Content commitment to off-chain artifact bytes |
tier | string | Access tier ("open", "verified", "premium", "restricted") |
payload | object | Type-specific payload object |
derivation | object | Derivation recipe when the KB is derived |
metadata, curator, createdAt, signature, and the top-level kbHash replay field are excluded by design.
Signatures
kbHashFromEnvelope
sources lexicographically, runs canonicalize(), and returns keccak256("KB_V1" + canonical) as a 0x-prefixed 64-character hex string.
contentHashFromEnvelope (deprecated)
keccak256(canonical) without the "KB_V1" domain prefix. The two functions produce different hashes. On-chain kbId values are derived with kbHashFromEnvelope; contentHashFromEnvelope is retained only for v1 conformance test vectors.
domainHashFromCanonical
keccak256(UTF8(domainTag) + UTF8(canonicalJson)). You can use this to implement domain-tagged hashing for custom domain tags from DOMAIN_TAGS.
domainHashFromObject
canonicalize(value) then delegates to domainHashFromCanonical. Equivalent to kbHashFromEnvelope when called with DOMAIN_TAGS.KB and a pre-normalized envelope.
Parameters
A canonical envelope object. You do not need to pre-normalize it —
kbHashFromEnvelope projects only the hash-scoped fields internally. However, ensure that sources contains valid kbHash hex strings and that payload conforms to your KB type schema.The wire format may supply parents instead of sources; the normalization step maps parents → sources automatically.Return value
A
0x-prefixed 64-character lowercase hex string representing the Keccak-256 hash of the domain-tagged canonical preimage. This value is used as kbId in registry calls.DOMAIN_TAGS
DOMAIN_TAGS.KB when computing KB identity. Other tags are used internally by the protocol for sub-object hashing in state machines, task graphs, and constraint trees.
Example
Notes
kbHashFromEnvelopeis the canonical function for new code. Never usecontentHashFromEnvelopein production.sourcesis treated as a set for identity: the order you supply does not matter. The normalization step sorts the array before hashing, so["0xaaa", "0xbbb"]and["0xbbb", "0xaaa"]produce the samekbHash.- If the envelope contains a top-level
kbHashfield, it is silently excluded from the hash preimage by the normalization step — only the seven hash-scope keys are included. That said, keeping your data model clean by storingkbHashseparately is recommended. - A future breaking change to identity rules will use
KB_V2and a new vector set. Never hardcode the domain string; useDOMAIN_TAGS.KB.