kanonak-codec (Rust)
The generic, ontology-independent Kanonak codec runtime — the Rust port of
@kanonak-protocol/codec. Given a CodecSchema (the per-package metadata a generated
typed SDK embeds) and a set of typed nodes, it builds the canonical input model
and content-addresses it via kanonak-canonical,
producing the exact content hash the kanonak hash CLI emits. It also
(de)serializes the normalized-JSON wire form.
A node is a plain JSON object (serde_json::Map<String, serde_json::Value>):
the $-envelope ($type, $id, optional $extra, …) plus alias-collapsed
local-name fields. A generated typed model serializes to one.
API
use ;
// nodes: &[Node], schema/pkg: &serde_json::Value
let hash = content_hash?; // "sha256:..."
let form = canonical_form?; // {"subjects":[...]}
let wire = serialize; // normalized-JSON Node
let node = deserialize?; // typed Node (unmodeled -> $extra)
build_package— the canonical input model (subject per node + synthesized package-wrapper subject). The seam every other entrypoint shares.content_hash/canonical_form— delegate tokanonak-canonical.serialize— modeled fields (nulls dropped) then$extraspread as siblings (modeled wins a collision; no$extrakey on the wire).deserialize—$-keys and$type-modeled fields stay top-level; everything else collects into$extrafor lossless round-trip.
Embedded object values are not yet supported — pass a reference ({"$ref": ...}).
Malformed input fails loudly (CodecError); no fallbacks.
Test
Runs the shared golden vectors in ../vectors/codec-vectors.json.