Skip to main content

Module canonical

Module canonical 

Source
Expand description

Canonical JSON serialization (sorted keys, no whitespace).

Single source of truth used wherever two parties need to compute identical byte sequences over a JSON value:

  • identity rotation attestations (mur_common::identity)
  • card signing (mur_common::card)
  • MCP description hashing (B0 rule 6 / M9.2)

The algorithm walks the serde_json::Value tree depth-first, sorts object keys lexicographically, and emits each leaf without whitespace. It does NOT attempt RFC 8785 (JCS) compliance — that would require number-canonicalisation rules we don’t need for any current caller. Two callers using this helper round-trip losslessly; that’s the only invariant we promise.

Functions§

canonical_json
Returns the canonical-JSON byte sequence for value. The output is deterministic across Rust runs, machine architectures, and serde_json versions (assuming the input Value is the same).
canonical_json_for
Serialize value directly to canonical-JSON bytes without an intermediate serde_json::Value. For types that already implement Serialize, this avoids the round-trip allocation.