gunk-dev/the-valley

README.md

source933f202462e5main's published tip history
4.3 KiB · Rendered
1# Conformance vectors for the written form and the note
2
3These files are the interop contract for an attestation. A second implementation of `attest` — a
4rewrite of this one, or a reader written in another language — must write every `input.json` here as
5exactly the bytes of the `statement.txt` beside it, and must verify every `statement.note`. Anything
6else and the two sign different bytes over the same statement, so a signature made by one does not
7verify against the other, and the way that failure arrives is a verification error that names
8nothing.
9
10The written form is lines, and the envelope is a signed note. Both are specified in
11[design/verification.md](../../design/verification.md); the reasons behind each rule are in
12[`../text.go`](../text.go) and [`../sign.go`](../sign.go), and the decision node those cite.
13
14## What is here
15
16Each directory under `vectors/` is one vector.
17
18- `input.json` is a statement or a fragment of one, written in some arbitrary rendering — members
19 out of order, whitespace anywhere, escapes chosen freely. It is input, not output.
20- `statement.txt` is the exact byte sequence the written form produces from it. It is what a
21 signature covers, and nothing else is.
22- `statement.note`, where present, is that text with a blank line and one signature line per signer
23 beneath it. The keys are in [`known_keys`](./known_keys); they exist for these vectors and hold no
24 authority anywhere.
25
26The vectors cover the places implementations part company: line order over keys that differ only in
27case, keys where one is a prefix of another, and a dash against the letter that sorts after it;
28dotted paths through nested objects, and arrays long enough that index `10` sits between `1` and `2`
29where a reader who trusts line order rather than the index will get the array wrong; values written
30as their own bytes, including the characters a JSON encoder would have escaped, text above the basic
31multiplane, and leading, trailing and repeated spaces, which are all load-bearing and none of which
32survive an editor that trims whitespace; a statement with and without provenance; and a note with
33two signature lines, which is what "several parties attest to one subject" looks like.
34
35`known_keys` is the whole of what a verifier is given: one line per key, each a name, the key hash
36its name and public key produce, and the public key itself.
37
38Every `statement.txt` that is a whole statement also vets against
39[`../../schema/attestation.cue`](../../schema/attestation.cue), so the set does not drift into
40documents no verifier would accept.
41
42`refused/` is the other half of the contract: documents and texts that must not be written or read
43at all. A `.json` there is a document with no written form — a number, an empty object, a value
44carrying a newline, a field name a line cannot carry. A `.txt` there is text that is not the written
45form of anything: lines out of order, a repeated key, an array with a gap in it, a key that is both
46a value and a path. An implementation that accepts any of them will sooner or later sign bytes
47another one reads differently.
48
49## Running them
50
51`nix flake check` runs them as `attest-conformance`. Each vector is written out with
52`attest render`, compared byte for byte, and written out again from its own recorded text to confirm
53the form is a fixed point. Each signed vector is put through `attest verify`, so the path from a
54statement to a note something else can check is pinned end to end rather than only the
55serialization. Each file under `refused/` is put through `attest render` and must fail. The check
56also perturbs one recorded byte sequence and one signature and requires both to be rejected, so a
57vector set that agrees with itself vacuously cannot pass.
58
59By hand, against any one vector:
60
61```
62$ nix run .#attest -- render attest/conformance/vectors/01-key-order/input.json \
63 | cmp - attest/conformance/vectors/01-key-order/statement.txt
64$ nix run .#attest -- verify \
65 --note attest/conformance/vectors/07-two-signers/statement.note \
66 --known-keys attest/conformance/known_keys
67```
68
69## Changing them
70
71A vector's recorded bytes may only change when the written form itself changes, and that invalidates
72every signature ever made under it. Regenerating a `statement.txt` to make a failing check pass is
73the one thing this directory exists to prevent. A new vector is a new directory and needs no
74registration; the check finds it.