Skip to main content

Module canonical

Module canonical 

Source
Expand description

Canonical wire-byte form for events + cards.

Rules (v0.1):

  1. Object keys serialize in lexicographic byte order.
  2. No whitespace anywhere (, and : separators only).
  3. UTF-8 throughout — non-ASCII is NOT \uXXXX-escaped.
  4. The top-level fields signature and public_key_id are stripped before serialization (they are computed over the canonical bytes, so they cannot be inside them).
  5. The top-level field event_id is stripped iff strict = truecompute_event_id uses strict-mode bytes; verify_message_v31 uses non-strict because the wire copy carries event_id already.

Implementation note — serde_json::Map uses BTreeMap internally when the preserve_order cargo feature is OFF (which is the default). This gives us free lexicographic key ordering at every nesting level. If a downstream crate ever enables preserve_order we’ll need to walk and re-sort manually; for now the default is sufficient.

Functions§

canonical
Canonical bytes for a JSON value.