| 1 | # Conformance vectors for the written form and the note |
| 2 | |
| 3 | These files are the interop contract for an attestation. A second implementation of `attest` — a |
| 4 | rewrite of this one, or a reader written in another language — must write every `input.json` here as |
| 5 | exactly the bytes of the `statement.txt` beside it, and must verify every `statement.note`. Anything |
| 6 | else and the two sign different bytes over the same statement, so a signature made by one does not |
| 7 | verify against the other, and the way that failure arrives is a verification error that names |
| 8 | nothing. |
| 9 | |
| 10 | The written form is lines in a fixed order, 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 | |
| 16 | Each directory under `vectors/` is one vector. |
| 17 | |
| 18 | - `input.json` is a statement written in some arbitrary rendering — members out of order, whitespace |
| 19 | 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 | |
| 26 | Every vector is a whole statement, because line order is defined per predicate type and a fragment |
| 27 | has no order at all. Between them they cover the places implementations part company: all three |
| 28 | predicate types, each in its own order; the transfer claim written both ways — a check list, and |
| 29 | `predicate.required none` for a policy that required nothing of the change, which is the case where |
| 30 | absence carries the claim and an empty list would have no written form at all; a digest set with |
| 31 | several members, whose entries sort by key while everything around them does not; a delegation chain |
| 32 | long enough that index `10` follows index `9`, where an implementation ordering by the key's bytes |
| 33 | rather than by the index will get the array wrong; values written as their own bytes, including the |
| 34 | characters a JSON encoder would have escaped, text above the basic multilingual plane, and leading, |
| 35 | trailing and repeated spaces, which are all load-bearing and none of which survive an editor that |
| 36 | trims whitespace; a statement with and without provenance; and a note with two signature lines, |
| 37 | which is what "several parties attest to one subject" looks like. |
| 38 | |
| 39 | `known_keys` is the whole of what a verifier is given: one line per key, each a name, the key hash |
| 40 | its name and public key produce, and the public key itself. |
| 41 | |
| 42 | Every vector also vets against [`../../schema/attestation.cue`](../../schema/attestation.cue), so |
| 43 | the set does not drift into documents no verifier would accept. |
| 44 | |
| 45 | `refused/` is the other half of the contract: documents and texts that must not be written or read |
| 46 | at all. A `.json` there is a document with no written form — a number, an empty object, a value |
| 47 | carrying a newline, a field name a line cannot carry. A `.txt` there is text that is not the written |
| 48 | form of anything: sections out of order, a set out of order, an array element out of its position, a |
| 49 | repeated key, an array with a gap in it, a key that is both a value and a path. An implementation |
| 50 | that accepts any of them will sooner or later sign bytes another one reads differently. |
| 51 | |
| 52 | ## Running them |
| 53 | |
| 54 | `nix flake check` runs them as `attest-conformance`. Each vector is written out with |
| 55 | `attest render`, compared byte for byte, and written out again from its own recorded text to confirm |
| 56 | the form is a fixed point. Each signed vector is put through `attest verify`, so the path from a |
| 57 | statement to a note something else can check is pinned end to end rather than only the |
| 58 | serialization. Each file under `refused/` is put through `attest render` and must fail. The check |
| 59 | also perturbs one recorded byte sequence and one signature and requires both to be rejected, so a |
| 60 | vector set that agrees with itself vacuously cannot pass. |
| 61 | |
| 62 | By hand, against any one vector: |
| 63 | |
| 64 | ``` |
| 65 | $ nix run .#attest -- render attest/conformance/vectors/01-statement-minimal/input.json \ |
| 66 | | cmp - attest/conformance/vectors/01-statement-minimal/statement.txt |
| 67 | $ nix run .#attest -- verify \ |
| 68 | --note attest/conformance/vectors/04-two-signers/statement.note \ |
| 69 | --known-keys attest/conformance/known_keys |
| 70 | ``` |
| 71 | |
| 72 | ## Changing them |
| 73 | |
| 74 | A vector's recorded bytes may only change when the written form itself changes, and that invalidates |
| 75 | every signature ever made under it. Regenerating a `statement.txt` to make a failing check pass is |
| 76 | the one thing this directory exists to prevent. A new vector is a new directory and needs no |
| 77 | registration; the check finds it. |