ALX Protocol uses CIDv1 to give every KB envelope a stable IPFS address. The CID is derived from the SHA-256 hash of the canonical JSON bytes of the normalized envelope, encoded as a CIDv1 with the raw codec (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.
0x55) and SHA-256 multihash (0x12). The result is a bafy... base32 multibase string suitable for pinning on IPFS and passing as rootCid to publishKB.
The CID is not the same as kbHash. They differ in both hash function (SHA-256 vs Keccak-256) and representation (multibase CIDv1 vs 0x-prefixed hex). Use kbHash as the on-chain identifier and cidV1 as the IPFS address.
Signatures
cidV1FromCanonicalSync (preferred in server environments)
crypto module, wraps the digest in a multihash, and constructs the CIDv1. Because it uses crypto from Node’s standard library, it does not require a Web Crypto polyfill and has no async overhead.
cidV1FromCanonical (browser / non-Node environments)
multiformats SHA-256 implementation, which works in browser environments and any runtime that does not expose Node’s crypto module. Both functions produce identical output for the same input.
Parameters
The canonical JSON string produced by
canonicalize() over the normalized, hash-scoped envelope. You must canonicalize the envelope yourself before calling these functions — they do not call canonicalize() internally.Return value
A CIDv1 multibase string (base32 encoding,
bafy... prefix). This is the IPFS content address for the canonical envelope.Example: compute CID and publish a KB
Choosing between the two functions
| Situation | Recommended function |
|---|---|
| Node.js server, protocol tooling, conformance tests | cidV1FromCanonicalSync — no async overhead, uses native crypto |
Browser, Deno, edge runtime without Node crypto | cidV1FromCanonical — uses multiformats SHA-256 |
| Starting from a full envelope object | cidV1FromEnvelope(envelope) — normalizes + canonicalizes before hashing |
Notes
cidV1andkbHashuse the same canonical JSON input but different hash functions and output formats. Never use acidV1value as abytes32on-chain identifier, and never use akbHashhex string as an IPFS address.- The raw codec
0x55means the CID addresses the canonical JSON bytes directly, with no IPLD framing. The SHA-256 multihash code is0x12. - Both functions produce identical results for the same
canonicalJsonstring. The async function is not slower by design — the difference is only the underlying crypto primitive.