Skip to content

Canonicalization

All INK messages are canonicalized using JSON Canonicalization Scheme (JCS, RFC 8785) before signing. This ensures deterministic byte-level representation regardless of JSON serialization order.

Procedure

Implementations MUST:

  1. Serialize the message body (excluding the signature field itself) using JCS.
  2. Construct the signature base: METHOD + "\n" + PATH + "\n" + recipientDid + "\n" + JCS(body) + "\n" + timestamp.
  3. Sign the resulting byte string with the sender’s Ed25519 private key.

Why JCS

SSB’s original design used JSON.stringify with specific key ordering, which caused interoperability bugs across implementations. JCS (RFC 8785) is a proper IETF standard that defines canonical JSON serialization unambiguously.

Key JCS rules:

  • Object keys sorted lexicographically by code point
  • No whitespace between tokens
  • Numbers serialized per ECMAScript Number.toString()
  • Strings escaped per JSON spec with no unnecessary escaping