TheDocumentation Index
Fetch the complete documentation index at: https://docs.xandrlabs.ai/llms.txt
Use this file to discover all available pages before exploring further.
alx_protocol_v1 Rust crate implements kb_hash_from_envelope with identical semantics to the TypeScript reference implementation in @alx/protocol. Like the Python implementation, its primary purpose is conformance verification: given the same envelope, it must produce the same kbHash. The crate is validated against the canonical test vectors in test-vectors/canonical/.
The Rust crate is for conformance verification. For building production integrations with ALX Protocol, use
@alx/protocol (TypeScript), which is the primary SDK.Requirements
- Rust 2021 edition or later
- Cargo
Adding the crate
Add the following to yourCargo.toml:
alx-protocol repository, reference it by path as shown above. For external use, publish the crate to crates.io and reference it by version.
Running the conformance suite
test-vectors/canonical/ and the derivation vectors, asserting that kb_hash_from_envelope matches the expected kbHash in each expected.json file.
API
| Export | Description |
|---|---|
kb_hash_from_envelope(envelope: &Value) -> Result<String, String> | Derives kbHash: keccak256("KB_V1" + JCS(normalizedEnvelope)). Returns a 0x-prefixed hex string. |
kb_hash_from_json(json: &str) -> Result<String, String> | Parses a JSON string and calls kb_hash_from_envelope. |
canonicalize_value(value: &Value) -> Result<String, String> | RFC 8785-style (JCS) deterministic JSON serializer. Returns Err on null. |
normalize_for_hash(envelope: &Value) -> Result<Value, String> | Extracts hash-scoped fields and sorts sources deterministically. |
KB_DOMAIN_PREFIX | The "KB_V1" constant prepended before hashing. |
Example: computing kbHash in Rust
The following produces the samekbHash as the equivalent TypeScript call to kbHashFromEnvelope:
How the hash is computed
The Rust implementation follows the same three-step pipeline as the TypeScript reference:Normalize the envelope
Extract only the hash-scoped fields:
type, domain, sources, artifactHash, tier, payload, and derivation. Sort sources deterministically when there is more than one entry. Fall back to parents if sources is absent.Canonicalize
Serialize the normalized object using JCS (RFC 8785): object keys sorted lexicographically, no whitespace,
null values rejected.Canonical test vectors
The test suite covers the same vectors as the Python and TypeScript implementations:| Vector group | Coverage |
|---|---|
types/* | All canonical KB types: practice, pattern, prompt, synthesis, adaptation, compliance, enhancement, state-machine |
edge-cases/* | Empty payload fields, large payloads, max sources, unicode content |
derivation/single-parent | Single-parent lineage hash stability |
derivation/multi-parent | Multi-parent source sorting |
derivation/parent-sort | Sorted and unsorted sources must produce identical kbHash |
envelope.json (input) and expected.json (expected kbHash).