| 1 | --- |
| 2 | type: decision |
| 3 | id: dcr-74c4353 |
| 4 | status: decided |
| 5 | title: The statement is signed as canonical JSON, narrowed by excluding numbers |
| 6 | created: 2026-08-02 |
| 7 | source: design conversation, 2026-08-02 |
| 8 | --- |
| 9 | |
| 10 | # The statement is signed as canonical JSON |
| 11 | |
| 12 | An attestation's statement — the typed record of what check ran, over what tree, with what result — |
| 13 | is serialized as canonical JSON, the form specified by RFC 8785. That specification takes an |
| 14 | ordinary JSON document and fixes every choice a serializer would otherwise be free to make: object |
| 15 | members are sorted by key, no whitespace appears between tokens, and each string is escaped one |
| 16 | particular way. Two serializers following it turn the same document into the same bytes. |
| 17 | |
| 18 | The-valley's statements narrow it by one rule: a statement carries strings, objects and arrays, and |
| 19 | never a number. The detached signature covers those canonical bytes and nothing else — no envelope, |
| 20 | no git object, no re-serialization at verification time. |
| 21 | |
| 22 | The statement's shape is [schema/attestation.cue](../../schema/attestation.cue); the renderer is |
| 23 | `attest/canonical.go`. |
| 24 | |
| 25 | ## The stored statement is the signed bytes |
| 26 | |
| 27 | An attestation is stored as the statement and a detached signature beside it, so what a reader gets |
| 28 | back from the ref is the byte sequence that was signed. There is no re-derivation step between what |
| 29 | is stored and what is checked, and no encoding to decode before reading. A statement can be read |
| 30 | with `git cat-file`, searched with `grep`, and vetted against the schema exactly as stored — the |
| 31 | same plain-files property the knowledge graph has, applied to evidence. |
| 32 | |
| 33 | Verification makes this a rule rather than a convenience. A statement whose bytes are not the |
| 34 | canonical form of what it says is refused, even when its signature checks out, because that |
| 35 | statement would fail to verify wherever it was next recomposed. |
| 36 | |
| 37 | ## Excluding numbers removes the specification's hard part |
| 38 | |
| 39 | Almost all of RFC 8785 is mechanical. The exception is numbers: canonicalizing them means pinning a |
| 40 | single textual form for every IEEE 754 double, which is where independent implementations disagree |
| 41 | and where the specification carries most of its weight. |
| 42 | |
| 43 | A statement has no field that is a number. Digests are hex strings, times are RFC 3339 strings, |
| 44 | results are enumerated strings. So the rule is enforced rather than merely observed: a number |
| 45 | reaching the renderer is refused, because the canonical form of a statement carrying one has never |
| 46 | been decided and a guess would be a guess about signed bytes. |
| 47 | |
| 48 | ## Keys are ASCII, so member order is unambiguous |
| 49 | |
| 50 | Member order is the other place a serializer can be subtly wrong. The renderer sorts members by |
| 51 | their keys' UTF-8 bytes, and RFC 8785 sorts them by UTF-16 code units. The two orderings agree over |
| 52 | ASCII and part company above it, so ASCII keys are a condition of these bytes being the bytes anyone |
| 53 | else produces. |
| 54 | |
| 55 | `#AsciiKey` in the schema holds keys to printable ASCII, and any map whose keys come from a caller |
| 56 | rather than from the schema is written under that constraint — the ecosystem-specific key-value |
| 57 | context strings of [[ida-d2dc957]] |
| 58 | ([ida-d2dc957-attestations-ride-on-a-transparent-leaf.md](../ideas/ida-d2dc957-attestations-ride-on-a-transparent-leaf.md)) |
| 59 | are the case already in view. A key outside it fails `cue vet`, and one that reaches the renderer |
| 60 | anyway is refused there rather than sorted. The failure this prevents is the quiet kind: two |
| 61 | implementations signing different bytes over one statement, surfacing much later as a signature that |
| 62 | does not verify, with nothing pointing at the key that caused it. |
| 63 | |
| 64 | ## Conformance vectors are what hold a second implementation |
| 65 | |
| 66 | The canonical bytes are an interop contract, so they are pinned by fixed files rather than by the |
| 67 | code that happens to produce them. `attest/conformance/` holds statements and fragments paired with |
| 68 | their exact expected bytes, covering the cases implementations actually part company over: member |
| 69 | order across case, prefixes and the empty key; nesting; empty objects, arrays and strings; the full |
| 70 | escape table; and the difference between an absent field and one present but empty. One vector |
| 71 | carries a detached signature made by a fixed key, so the path from a statement to a signature |
| 72 | something else can check is pinned end to end and not only the serialization. |
| 73 | |
| 74 | The flake's `attest-conformance` check renders every vector and compares byte for byte. That check |
| 75 | is the standard a regenerated or independently written `attest` is held to, and a vector's recorded |
| 76 | bytes may change only when the canonical form itself changes — which invalidates every signature |
| 77 | ever made under it. |
| 78 | |
| 79 | ## Where this sits |
| 80 | |
| 81 | This refines `dcr-0de694f`, which fixes the attestation's five elements and lands on branch |
| 82 | `dcr/phase2-attestation-shape`, by settling the one it leaves to the implementation: how a statement |
| 83 | becomes the bytes a signature covers. Nothing above changes what a statement says, who signs it, or |
| 84 | where it is stored. |
| 85 | |
| 86 | ## Related |
| 87 | |
| 88 | - The statement and envelope directions this serves: [[ida-d2dc957]] |
| 89 | ([ida-d2dc957-attestations-ride-on-a-transparent-leaf.md](../ideas/ida-d2dc957-attestations-ride-on-a-transparent-leaf.md)) |
| 90 | - Why the signature covers the statement rather than a git object: [[ida-51605e8]] |
| 91 | ([ida-51605e8-authenticity-not-git-coupled.md](../ideas/ida-51605e8-authenticity-not-git-coupled.md)) |
| 92 | - The helper and what it verifies: [verification.md](../../design/verification.md#the-helper) |