Every Knowledge Block in ALX Protocol is identified by aDocumentation Index
Fetch the complete documentation index at: https://docs.xandrlabs.ai/llms.txt
Use this file to discover all available pages before exploring further.
kbHash — a deterministic, domain-separated Keccak-256 digest computed from a canonical subset of the artifact’s fields. Because the hash is fully deterministic, any party holding the same artifact can independently reproduce and verify the same identifier without contacting a server or registry.
What gets hashed
The identity hash covers exactly seven fields, defined in the protocol as the hash scope:| Field | Description |
|---|---|
type | KB structural type (e.g. Practice, StateMachine) |
domain | Namespaced domain string (e.g. engineering.auth.jwt) |
sources | Sorted array of parent kbHash references |
artifactHash | Keccak-256 digest of the canonical artifact payload |
tier | Access tier (open, verified, premium, restricted) |
payload | The structured KB content object |
derivation | Derivation metadata: type, inputs, and recipe |
kbHashitselfmetadatacuratorcreatedAtsignature
The
kbHash field is excluded by design. Including it would make the hash self-referential, creating a circular dependency. Strip it before computing identity, then re-attach it to the serialized artifact.The domain tag KB_V1
The hash is computed askeccak256("KB_V1" + canonicalJson) — not over the canonical JSON alone. The KB_V1 prefix is a domain separator that prevents collisions between KB hashes and hashes produced by other ALX Protocol object types (tasks, transitions, constraints, and so on). All on-chain kbId values are derived using this domain-tagged form. Do not use the undomain-tagged contentHashFromEnvelope function for new code — it is retained only for v1 conformance tests.
Source ordering and sortSources
Thesources array contains the kbHash values of parent KBs. Array ordering is normalized before hashing: sortSources sorts the sources alphabetically so that two envelopes listing the same parents in different orders produce identical hashes. You do not need to sort sources manually before passing the envelope to kbHashFromEnvelope — normalization is applied internally.
End-to-end example
The following example shows the complete identity derivation flow: stripping excluded fields, normalizing the envelope, callingcanonicalize(), and calling kbHashFromEnvelope().
Canonical JSON rules
canonicalize() follows RFC 8785 (JSON Canonicalization Scheme):
- Object keys are sorted alphabetically at every nesting level.
- No whitespace between tokens.
- Numbers use the shortest representation (integers as
123, not123.0). nullvalues,BigInt, and non-finite numbers are rejected with an error.- Arrays preserve insertion order — only object keys are sorted.
Artifact hash vs. KB identity
kbHash and artifactHash are separate, complementary values:
kbHashidentifies the Knowledge Block. It is the on-chainkbId.artifactHashis the Keccak-256 digest of the canonical payload object. It is stored in the registry for artifact integrity checks.
artifactHash at any time from payload alone using artifactHashFromPayload, without reconstructing the full envelope.