Skip to main content

Module canonical

Module canonical 

Source
Expand description

Canonical JSON serialization per Ratify Protocol SPEC §6.

Every implementation MUST produce byte-identical output for the same input or signatures will not verify across languages.

Rules:

  • Object members in lex order (byte order on UTF-8), RECURSIVELY.
  • No whitespace between tokens. No trailing newline.
  • UTF-8 encoding.
  • Integers as shortest decimal.
  • Byte arrays as base64-standard strings with padding.
  • ‘<’, ‘>’, ‘&’ pass through unmodified.
  • U+2028 / U+2029 escape as \u2028 / \u2029 (matches Go behavior).
  • Minimum string escaping per RFC 8259.

Modules§

base64_bytes
serde helper to (de)serialize Vec as base64-standard strings.

Functions§

base64_std_decode
Standard base64 decode.
base64_std_encode
Standard base64 encode with padding.
canonical_json
Canonical JSON-encode a serde_json::Value.
encode_bool
Write a canonical-JSON bool into out.
encode_bytes_b64
Write a base64-standard-encoded byte slice as a canonical-JSON string.
encode_constraint
Write a canonical Constraint object into out, matching the per-kind shape emitted by Constraint’s Serialize impl (alphabetical keys).
encode_constraints
Write a canonical-JSON array of Constraint objects.
encode_f64
Write a canonical-JSON f64 following the Ratify integer-valued rule: whole-number f64s emit as shortest decimal integer; others as-is.
encode_hybrid_pub_key
Write a canonical HybridPublicKey object: {"ed25519":"...","ml_dsa_65":"..."}. Keys are already in lex order: “ed25519” < “ml_dsa_65”.
encode_hybrid_sig
Write a canonical HybridSignature object: {"ed25519":"...","ml_dsa_65":"..."}.
encode_i32
Write a canonical-JSON i32 into out.
encode_i64
Write a canonical-JSON i64 (shortest decimal) into out.
encode_points_array
Write a canonical-JSON array of [f64; 2] pairs (geo polygon points).
encode_str
Write a canonical-JSON string (with escaping) into out.
encode_str_array
Write a canonical-JSON array of strings into out.
hex_decode
Lower- or upper-case hex.
hex_encode
Lowercase hex.