gunk-dev/the-valley

dcr-74c4353-statement-signed-as-canonical-json.md

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