@agledger/verify-core 1.5.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +333 -14
- package/dist/audit-export.d.ts +156 -24
- package/dist/audit-export.js +197 -37
- package/dist/chain.d.ts +239 -24
- package/dist/chain.js +367 -57
- package/dist/failures.d.ts +36 -2
- package/dist/failures.js +56 -6
- package/dist/federation-wire.d.ts +152 -0
- package/dist/federation-wire.js +447 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.js +6 -2
- package/dist/instant.d.ts +23 -0
- package/dist/instant.js +50 -0
- package/dist/key-statements.d.ts +429 -0
- package/dist/key-statements.js +1325 -0
- package/dist/options.d.ts +7 -0
- package/dist/options.js +29 -0
- package/dist/primitives.d.ts +28 -6
- package/dist/primitives.js +86 -42
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@ Statement payloads, walks the per-record hash chain, and verifies the
|
|
|
6
6
|
signature over each `Sig_structure` under the algorithm the verification key
|
|
7
7
|
commits to (Ed25519 or ES256), with no engine, no database, and no network.
|
|
8
8
|
|
|
9
|
+
Reads exports and dumps from an AGLedger Server 2.0 or later. For a 1.x Server's, use `npm i @agledger/verify-core@1.5.0`, the last release that reads them.
|
|
10
|
+
|
|
9
11
|
This is the single body of logic that underpins the SDK `/verify` subpath
|
|
10
12
|
(`@agledger/sdk/verify`), the [`@agledger/cli`](https://github.com/agledger-ai/cli)
|
|
11
13
|
`verify` command, the
|
|
@@ -35,17 +37,24 @@ for a single record export.
|
|
|
35
37
|
import { verifyAuditExport } from '@agledger/verify-core';
|
|
36
38
|
|
|
37
39
|
const result = verifyAuditExport(exportDocument, {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
// The SPKI digest of a vault key you took out of band (see "Anchoring keys").
|
|
41
|
+
trustAnchors: ['sha256:15d63684b387235c47fe3a81e3004b928f4ea535236a2c1b47465ce5fdd7ce0e'],
|
|
40
42
|
});
|
|
41
43
|
|
|
42
|
-
if (
|
|
44
|
+
if (result.verdict === 'failed') {
|
|
43
45
|
console.error(`Broken at position ${result.brokenAt?.position}: ${result.brokenAt?.code}`);
|
|
44
46
|
process.exit(1);
|
|
45
47
|
}
|
|
46
|
-
//
|
|
48
|
+
console.log(result.verdict); // 'trusted', or 'unanchored' when nothing pinned backs the pass
|
|
49
|
+
// { valid: true, verdict, verifiedEntries, totalEntries, keyTrust, keyProvenance: { supplied, embedded }, ... }
|
|
47
50
|
```
|
|
48
51
|
|
|
52
|
+
Read `verdict` rather than `valid`: a valid result with no `trustAnchors` is
|
|
53
|
+
`unanchored`, which is not a trusted verdict. An option the function does not
|
|
54
|
+
read throws `TypeError` rather than being ignored, so a misspelt option, or
|
|
55
|
+
`requireOutOfBandKeys` (renamed `requireSuppliedKeys` in 2.0.0), cannot turn a
|
|
56
|
+
check off without a word.
|
|
57
|
+
|
|
49
58
|
## What it verifies
|
|
50
59
|
|
|
51
60
|
- **`chainPosition` monotonicity**: gap-free, in order.
|
|
@@ -58,7 +67,17 @@ if (!result.valid) {
|
|
|
58
67
|
matched verification key, under the algorithm its SPKI commits to (Ed25519
|
|
59
68
|
or ES256; anything else fails closed as `CHAIN_UNSUPPORTED_ALGORITHM`).
|
|
60
69
|
- **Signed-kid binding**: the row's `signingKeyId` names the key the protected
|
|
61
|
-
header signed.
|
|
70
|
+
header signed. An entry that names a key but carries an all-zero signature
|
|
71
|
+
fails `CHAIN_SIGNATURE_INVALID`.
|
|
72
|
+
- **Unsigned entries**: an entry with no `signingKeyId` fails
|
|
73
|
+
`CHAIN_ENTRY_UNSIGNED` when it follows a signed entry in its chain, or when
|
|
74
|
+
it was written at or after the earliest `activatedAt` in the key set
|
|
75
|
+
(export `signingKeyWindows` and your own keys, retired keys included). With
|
|
76
|
+
`trustAnchors`, the activations an anchored key's statements sign count as
|
|
77
|
+
well, so an export stripped of its unsigned `signingKeyWindows` is still
|
|
78
|
+
held to them.
|
|
79
|
+
Earlier unsigned entries, written before the install had a key, count as
|
|
80
|
+
`signatureCoverage.skipped` rather than a break.
|
|
62
81
|
- **Payload binding**: each entry's human-readable `payload` still matches the
|
|
63
82
|
predicate inside the signed bytes, so a rewritten view of the record fails
|
|
64
83
|
`CHAIN_PAYLOAD_BINDING_MISMATCH`.
|
|
@@ -68,14 +87,234 @@ if (!result.valid) {
|
|
|
68
87
|
the attribution an export's own guide tells an auditor to rely on, match the
|
|
69
88
|
actor claim signed in the protected header, so an export re-attributed to
|
|
70
89
|
another actor fails `CHAIN_ACTOR_ATTRIBUTION_MISMATCH`.
|
|
90
|
+
- **Key anchoring**, with `trustAnchors`: each entry's key is linked by signed
|
|
91
|
+
key statements to a key you pinned, or the entry fails
|
|
92
|
+
`CHAIN_SIGNING_KEY_UNANCHORED` (below).
|
|
71
93
|
- **Key validity windows**: each entry was written inside its signing key's
|
|
72
|
-
activation window.
|
|
94
|
+
activation window. With `trustAnchors`, the window is the one the key
|
|
95
|
+
statements sign.
|
|
73
96
|
- **Agent signatures**, when you supply the agent's cert key (below).
|
|
97
|
+
- **Inlined evidence**, on an export taken with `?evidence=true`: each
|
|
98
|
+
completion's evidence body and each dispute's filed payload hashes (SHA-256
|
|
99
|
+
over its RFC 8785 form) to the `payload.evidenceHash` or `payload.payloadHash`
|
|
100
|
+
its entry signs, or the entry fails `CHAIN_EVIDENCE_BINDING_MISMATCH`.
|
|
101
|
+
`result.evidenceBinding` counts them. An encrypted-mode completion signs a
|
|
102
|
+
hash over a cleartext the export does not carry, so its ciphertext is counted
|
|
103
|
+
as `clientHashed`, not re-bound.
|
|
74
104
|
|
|
75
105
|
The payload, OIDC, attribution and key-window checks run when the export
|
|
76
106
|
carries their inputs, which every current Server does. The result's `optionalChecks` says
|
|
77
107
|
which ran, so "not checked" never reads as "passed".
|
|
78
108
|
|
|
109
|
+
## Anchoring keys
|
|
110
|
+
|
|
111
|
+
A vault key the Server publishes comes from its database, and anything with
|
|
112
|
+
write access to that database can add a key row and entries signed with it.
|
|
113
|
+
What it cannot add is a **key statement**: a COSE_Sign1 signed by a key the
|
|
114
|
+
Server already trusted (and, for a new key, by the new key too). Pass the SPKI
|
|
115
|
+
digest of a vault key you hold or took out of band as `trustAnchors`, and the
|
|
116
|
+
verifier walks the statements from it:
|
|
117
|
+
|
|
118
|
+
- the installer prints the digest of the first vault key, and the Server's
|
|
119
|
+
`signing-key-digest.js` derives one from any key you hold;
|
|
120
|
+
- the export's `exportMetadata.anchoredFrom` names the Server's own key, and
|
|
121
|
+
the result reports whether it is one of your anchors
|
|
122
|
+
(`keyTrust.anchoredFromPinned`), but it is the export's word and never
|
|
123
|
+
counts as an anchor itself.
|
|
124
|
+
|
|
125
|
+
An entry signed by a key the walk does not anchor fails
|
|
126
|
+
`CHAIN_SIGNING_KEY_UNANCHORED`, and each anchored key is held to the window its
|
|
127
|
+
statements sign. `keyTrust.status` says whether a pass can be trusted:
|
|
128
|
+
|
|
129
|
+
- `walked`: at least one entry verified under a key your anchors reach. The
|
|
130
|
+
only status a passing result is trusted on.
|
|
131
|
+
- `no_anchor`: no `trustAnchors` (an empty array is the same as none), so
|
|
132
|
+
`optionalChecks.key_anchoring` is `skipped_no_input` and the verdict rests on
|
|
133
|
+
keys nobody pinned: a key written into the database alone would pass.
|
|
134
|
+
- `no_anchored_signature`: the walk ran, but no entry verified under a key it
|
|
135
|
+
anchors, so `optionalChecks.key_anchoring` is `not_checked`. An export of
|
|
136
|
+
entries written before the install began signing passes under any pin, and
|
|
137
|
+
proves nothing about the pin.
|
|
138
|
+
|
|
139
|
+
A pass on `no_anchor` or `no_anchored_signature` is not a trusted verdict; the
|
|
140
|
+
`detail` says so, and `verdict` (and every AGLedger surface) reports it as
|
|
141
|
+
`unanchored`. `distrustedKeys` without `trustAnchors` throws `TypeError`, since
|
|
142
|
+
nothing would apply them, and so does a pinned key distrusted with no instant,
|
|
143
|
+
which the Server refuses to start with. A pin beside a dated entry
|
|
144
|
+
(`sha256:<hex>@<instant>`) is how a leaked key's history stays verifiable: the
|
|
145
|
+
pin vouches for what the key stored before the instant, and the entry
|
|
146
|
+
withdraws what it stored from then on.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { verifyAuditExport } from '@agledger/verify-core';
|
|
150
|
+
|
|
151
|
+
const result = verifyAuditExport(exportDocument, {
|
|
152
|
+
trustAnchors: ['sha256:15d63684b387235c47fe3a81e3004b928f4ea535236a2c1b47465ce5fdd7ce0e'],
|
|
153
|
+
// The operator's VAULT_DISTRUSTED_KEYS, when a key leaked: what it signed
|
|
154
|
+
// from the instant on (or, with none, from its retirement) counts for nothing.
|
|
155
|
+
distrustedKeys: [],
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const { status, anchoredKeyIds, unanchoredKeyIds, findings } = result.keyTrust;
|
|
159
|
+
console.log(status, anchoredKeyIds, unanchoredKeyIds);
|
|
160
|
+
for (const f of findings) console.log(f.code, f.keyId, f.detail);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
The statements the export carries (`exportMetadata.signingKeyStatements`) are
|
|
164
|
+
walked, together with any `statements` on keys you supply from
|
|
165
|
+
`GET /v1/verification-keys`. Findings about the statements themselves make the
|
|
166
|
+
result invalid, at position 0:
|
|
167
|
+
|
|
168
|
+
- `KEY_STATEMENT_INVALID`: a statement that does not verify, disagrees with
|
|
169
|
+
what it is filed under, touches no anchored key, was signed by a key after
|
|
170
|
+
its closure or after the key was already admitted, or admits a trusted key
|
|
171
|
+
under an endorser the walk does not trust (the Server publishes the
|
|
172
|
+
admission and not its endorser);
|
|
173
|
+
- `KEY_CLOSURE_INVALID`: a retired key with no closure that counts for it, or
|
|
174
|
+
a closure by a key the walk does not anchor, by a key after its own
|
|
175
|
+
retirement, dated before its subject was activated, dated after the time it
|
|
176
|
+
was stored, or signed by a key the walk reaches but does not anchor and
|
|
177
|
+
closing a published key (the Server publishes the closure and not its
|
|
178
|
+
signer, so no walk over what it publishes can verify it);
|
|
179
|
+
- `CHAIN_KEY_WINDOW_DRIFT`: a listed window or status that differs from the
|
|
180
|
+
signed value (compared at millisecond precision).
|
|
181
|
+
|
|
182
|
+
A key the Server's `VAULT_DISTRUSTED_KEYS` names is listed with
|
|
183
|
+
`distrustedFrom`, the instant its entry gives (in an export's
|
|
184
|
+
`signingKeyWindows` and on `/v1/verification-keys`), and where that instant is
|
|
185
|
+
earlier than the retirement the key's closures sign, the listed `retiredAt` is
|
|
186
|
+
that instant. A walk not given the same entry still fails on that window, but
|
|
187
|
+
the finding names the entry the listing says the Server applied
|
|
188
|
+
(`distrustedKeys sha256:<hex>@<distrustedFrom>`) rather than reading as a
|
|
189
|
+
rewritten column, and says so when the entry it was given carries another
|
|
190
|
+
instant; an entry at an earlier instant, which fails nothing on the window,
|
|
191
|
+
is said in `keyTrust.notes`. `distrustedFrom` is the source's unsigned word
|
|
192
|
+
and only changes that wording: it never ends, opens or widens a window and
|
|
193
|
+
never clears a finding. Confirm the instant with the Server's operator before
|
|
194
|
+
giving that `distrustedKeys` entry: off a dump an entry also voids every
|
|
195
|
+
admission the key signed, so a key it admitted that nothing else reaches is
|
|
196
|
+
no longer trusted and its window no longer graded.
|
|
197
|
+
|
|
198
|
+
Statements are walked in the order the Server's database stored them,
|
|
199
|
+
`createdAt` then the row `id`, never by an instant a statement signs. A dump
|
|
200
|
+
carries that order (`created_at`), and so does every key document an API 2.0
|
|
201
|
+
Server serves: each statement in an export's `signingKeyStatements`,
|
|
202
|
+
`/v1/verification-keys` and `/.well-known/agledger-vault-keys.json` carries
|
|
203
|
+
its row `id` and `createdAt` at microsecond precision, and `keyTrust.order`
|
|
204
|
+
reads `written`. A `createdAt` that is not strict RFC 3339 (a `T`, an offset
|
|
205
|
+
or `Z`, a real calendar date) places nothing, and its statement is
|
|
206
|
+
`KEY_STATEMENT_INVALID`. Such a document lists under a trusted key its
|
|
207
|
+
admission, every later admission it signed, and the closures that count for
|
|
208
|
+
it, so a walk over it dates each window and cuts each edge back as the engine
|
|
209
|
+
does. Where it cannot (a later succession whose endorser the document does not
|
|
210
|
+
carry, or a closure by a key it does not list), the walk grades the window
|
|
211
|
+
more loosely than the listed one, and the listed `activatedAt` or `retiredAt`
|
|
212
|
+
reads as `CHAIN_KEY_WINDOW_DRIFT` (a listed retirement no closure it could
|
|
213
|
+
verify signs is `KEY_CLOSURE_INVALID`). A statement the export and a supplied
|
|
214
|
+
key both carry is one row, however its `id` and `createdAt` are spelled.
|
|
215
|
+
|
|
216
|
+
A document from a Server that published neither field is still read, and
|
|
217
|
+
`keyTrust.order` reads `signed`: statements are ordered by the instant each
|
|
218
|
+
one signs, with a closure after any admission that signs the same instant. For
|
|
219
|
+
a document the Server served, the two orders agree. If the export and a
|
|
220
|
+
supplied key document disagree (one carries write times and the other does
|
|
221
|
+
not), a statement the older one alone carries makes the whole walk fall back
|
|
222
|
+
to the signed order.
|
|
223
|
+
|
|
224
|
+
`createdAt` is not signed: whoever holds an export or a key document can edit
|
|
225
|
+
it, as they can reorder the document, with nothing offline to tell. So a
|
|
226
|
+
document's write order is never held against `distrustedKeys`. On any
|
|
227
|
+
statement from an export or a supplied key document, in either order, an edge
|
|
228
|
+
out of a distrusted key never admits a key or keeps one reachable, whatever
|
|
229
|
+
time it carries. Such a statement still counts for everything that can only
|
|
230
|
+
narrow trust: it dates its subject's window, cuts the subject's edge back as a
|
|
231
|
+
later admission, and a closure the key signed still ends a window. Where the
|
|
232
|
+
document dates it before the cutoff, so the engine would count it, it is no
|
|
233
|
+
finding: it is listed in `keyTrust.notes`, which never fails a verdict, and an
|
|
234
|
+
honest rotation away from the key passes when you pin its successor. Pinned
|
|
235
|
+
only on the distrusted key, its successor is not anchored. This is narrower
|
|
236
|
+
than the engine, which holds the key to the time its statements were really
|
|
237
|
+
stored, and never wider. Only
|
|
238
|
+
a dump walk holds a distrusted key's statements to their `created_at`, as the
|
|
239
|
+
engine does, and that adds assurance only for a dump you took from the Server
|
|
240
|
+
yourself or over a channel you trust; for any other dump it assures no more
|
|
241
|
+
than the stored times its holder chose.
|
|
242
|
+
|
|
243
|
+
An entry's `createdAt` is not signed either, so the holder of a leaked
|
|
244
|
+
distrusted key can still sign entries dated before its cutoff, and no offline
|
|
245
|
+
verifier can tell those from the history the key wrote inside its legitimate
|
|
246
|
+
window.
|
|
247
|
+
|
|
248
|
+
Without `distrustedKeys`, a key retired without `force` whose private half
|
|
249
|
+
later leaks can still admit a key on any walk: with a statement it dates
|
|
250
|
+
before its retirement under the signed order, or with an edited `createdAt`
|
|
251
|
+
under the write order. A forced retirement voids every edge out of its key
|
|
252
|
+
under either order. When a retired key may have leaked, retire it with
|
|
253
|
+
`force` or list it in `distrustedKeys`.
|
|
254
|
+
|
|
255
|
+
### Walking a dump or a key document
|
|
256
|
+
|
|
257
|
+
`@agledger/verify` walks a full-vault dump with the same functions:
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
import { readFileSync } from 'node:fs';
|
|
261
|
+
import { applyKeyTrust, buildKeyRegistry, computeKeyTrust, keyStatementFromDumpRow, trustKeyFromDumpRow } from '@agledger/verify-core';
|
|
262
|
+
import type { DumpKeyStatementRow, DumpSigningKeyRow } from '@agledger/verify-core';
|
|
263
|
+
|
|
264
|
+
const rows = <T,>(file: string): T[] =>
|
|
265
|
+
readFileSync(file, 'utf8').split('\n').filter((l) => l.trim() !== '').map((l) => JSON.parse(l) as T);
|
|
266
|
+
const keys = rows<DumpSigningKeyRow>('vault_signing_keys.ndjson');
|
|
267
|
+
|
|
268
|
+
const trust = computeKeyTrust({
|
|
269
|
+
keys: keys.map(trustKeyFromDumpRow),
|
|
270
|
+
statements: rows<DumpKeyStatementRow>('vault_key_statements.ndjson').map(keyStatementFromDumpRow),
|
|
271
|
+
trustAnchors: ['sha256:15d63684b387235c47fe3a81e3004b928f4ea535236a2c1b47465ce5fdd7ce0e'],
|
|
272
|
+
});
|
|
273
|
+
// Marks each key anchored, unanchored or undecided and gives anchored keys
|
|
274
|
+
// their signed windows; verifyChain then grades entries against it.
|
|
275
|
+
const registry = applyKeyTrust(
|
|
276
|
+
buildKeyRegistry(keys.map((k) => ({ keyId: k.key_id, spkiBase64: k.public_key, source: 'embedded' as const }))),
|
|
277
|
+
trust,
|
|
278
|
+
);
|
|
279
|
+
console.log([...registry.values()].map((k) => `${k.keyId} ${k.trust}`), trust.findings);
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
A dump verifier reports the walk with `reportKeyTrust(registry, trust, null)`
|
|
283
|
+
and, once its chains are walked, settles it with
|
|
284
|
+
`settleKeyTrust(report, signedEntries)`, the count of entries whose signature
|
|
285
|
+
verified: with none, the status becomes `no_anchored_signature`.
|
|
286
|
+
`writtenWhileSigning(rowTime, signingSince)` is the unsigned-row rule for
|
|
287
|
+
checkpoints and read-log rows, and fails closed on a row with no readable time
|
|
288
|
+
once signing began.
|
|
289
|
+
|
|
290
|
+
A dump row repeating an earlier row's signed payload counts once, at its
|
|
291
|
+
first write: a row copied in the database under a new id and time says
|
|
292
|
+
nothing new, as the engine reads it. On a key document a copy stays a second
|
|
293
|
+
statement, since its `createdAt` is the holder's word.
|
|
294
|
+
|
|
295
|
+
On a dump, a `distrustedKeys` key that a key the walk trusts has retired is
|
|
296
|
+
bounded by that retirement (its `DistrustSpan` in `trust.distrustSpans`; only a
|
|
297
|
+
retirement by a key the walk trusts counts, as in the engine), and
|
|
298
|
+
what it signed before then is accounted for rather than failed, as the engine's
|
|
299
|
+
scan lists it: a key statement it signed that counts for nothing is listed in
|
|
300
|
+
`trust.accounted` (and the report's `accounted`) instead of `findings`, and a
|
|
301
|
+
chain entry whose signature verifies under it, outside what the key is
|
|
302
|
+
trusted for (the key unanchored, or the entry written at or after its cutoff),
|
|
303
|
+
is listed in the `verifyChain` result's `accounted` as
|
|
304
|
+
`CHAIN_SIGNED_BY_DISTRUSTED_KEY` (`AccountedEntry`: `code`, `chain`,
|
|
305
|
+
`recordId`, `orgId`, `scopeId`, `position`, `keyId`, `detail`) with signature
|
|
306
|
+
state `accounted`, and does not fail the chain. A verdict whose only items are
|
|
307
|
+
accounted ones passes, and should list them. What the key signed after that
|
|
308
|
+
retirement fails as before, and a distrusted key with a registry row that no
|
|
309
|
+
trusted key has retired is `KEY_CLOSURE_INVALID` naming the forced retire call
|
|
310
|
+
that bounds it. An audit export is never accounted for this way: its write
|
|
311
|
+
times are not the Server's word.
|
|
312
|
+
|
|
313
|
+
`keyStatementsFromVerificationKeys(document)` gives the same inputs from a
|
|
314
|
+
`GET /v1/verification-keys` response. A key reached only through a statement
|
|
315
|
+
this host cannot compute (Ed25519 history on a FIPS host) is `undecided`, and
|
|
316
|
+
entries under it are `CHAIN_UNSUPPORTED_ALGORITHM` rather than unanchored.
|
|
317
|
+
|
|
79
318
|
## Agent signatures
|
|
80
319
|
|
|
81
320
|
An agent that authenticates with an ephemeral cert can sign each request body
|
|
@@ -108,6 +347,68 @@ verify fails `CHAIN_AGENT_SIGNATURE_INVALID`. The check runs only where
|
|
|
108
347
|
`on_behalf_of.validated` is `true`: on a caller-asserted identity the two fields
|
|
109
348
|
may be passthrough from an older Server, and the export cannot tell which.
|
|
110
349
|
|
|
350
|
+
### Messages sealed from a federated peer
|
|
351
|
+
|
|
352
|
+
A receiving Server seals each peer message it accepts on the chain entry it
|
|
353
|
+
writes for it (`payload.wire` on its `FEDERATION_*` entries): the body as the
|
|
354
|
+
peer signed it, the peer's registered key, the hub ids, the body hash, the
|
|
355
|
+
timestamp, the nonce and the signature. Every sealed message is held to its
|
|
356
|
+
body hash and to the entry that carries it (`federation_wire` in
|
|
357
|
+
`optionalChecks`, `applied` once one was seen). Pass the peer's federation key,
|
|
358
|
+
as its operator gives it (base64 SPKI DER or base64 of the raw 32 bytes), to
|
|
359
|
+
also re-verify the peer's signature:
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
import { verifyAuditExport } from '@agledger/verify-core';
|
|
363
|
+
|
|
364
|
+
const result = verifyAuditExport(exportDocument, { federationKeys: { 'hub-b': 'MCowBQYDK2VwAyEA...' } });
|
|
365
|
+
|
|
366
|
+
console.log(result.federationWire); // e.g. { present: 2, verified: 2, failed: 0, afterRetirement: 0 }
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
A peer that changed its federation key signed its earlier messages under the
|
|
370
|
+
earlier key. Pass its key history (`GET /.well-known/agledger-federation-keys.json`
|
|
371
|
+
on the peer, no auth) beside the key you pinned for it, and every key the
|
|
372
|
+
history links to the pin through successions both keys signed is trusted
|
|
373
|
+
inside its window:
|
|
374
|
+
|
|
375
|
+
```ts
|
|
376
|
+
import { verifyAuditExport, type FederationKeyHistoryDocument } from '@agledger/verify-core';
|
|
377
|
+
|
|
378
|
+
const response = await fetch('https://hub-b.example.com/.well-known/agledger-federation-keys.json');
|
|
379
|
+
const history = (await response.json()) as FederationKeyHistoryDocument;
|
|
380
|
+
|
|
381
|
+
const result = verifyAuditExport(exportDocument, {
|
|
382
|
+
federationKeys: [{ hubId: 'hub-b', publicKey: 'MCowBQYDK2VwAyEA...', history }],
|
|
383
|
+
});
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
The windows come from the signed statements, not the document's `keys`
|
|
387
|
+
summary. Each message is placed by its sealed `wire.timestamp`, which the peer
|
|
388
|
+
signed and the receiver sealed under its own signature, and which comes from
|
|
389
|
+
the peer's clock, the same clock its windows are written by. The entry's
|
|
390
|
+
`createdAt` is not signed, so it places nothing. A message signed under a key
|
|
391
|
+
before that key's activation fails. One signed under a key after the key's
|
|
392
|
+
retirement verifies and is counted in `federationWire.afterRetirement`: a peer
|
|
393
|
+
process not yet restarted onto the new key sends exactly that, and it is in
|
|
394
|
+
order when the receiver's `federation.peer_revoked` audit row for the peer
|
|
395
|
+
comes after it. A key behind a genesis that named it only by digest
|
|
396
|
+
(`linked: false`) is not linked to the newer keys; name the hub a second time
|
|
397
|
+
with that key once its operator confirms it. The same goes for a key the
|
|
398
|
+
history does not list at all, such as the key in use before a change made with
|
|
399
|
+
neither predecessor setting: a second entry for the hub pins it, and it is
|
|
400
|
+
trusted on its own. A history that is another hub's, carries a statement that
|
|
401
|
+
does not verify, or lists none of the keys pinned for its hub throws
|
|
402
|
+
`TypeError` before anything is verified.
|
|
403
|
+
|
|
404
|
+
A sealed signature that does not verify, a sealed key that is not the one
|
|
405
|
+
supplied for that hub, a body that no longer hashes to what was signed, or an
|
|
406
|
+
entry that asserts a state the sealed body does not carry fails
|
|
407
|
+
`CHAIN_FEDERATION_WIRE_INVALID`. The pieces are exported for a caller that
|
|
408
|
+
reads the sealed message itself: `extractFederationWire`,
|
|
409
|
+
`checkFederationWire`, `federationSignInput`, `canonicalizeJson` (RFC 8785)
|
|
410
|
+
and `normalizeFederationKey`.
|
|
411
|
+
|
|
111
412
|
The Server's own chain verification also compares each sealed cert against its
|
|
112
413
|
live cert record (`cert_missing`, `cert_actor_drift`, `cert_window_drift`,
|
|
113
414
|
`cert_expired`). That record is not exported, so those checks have no offline
|
|
@@ -155,19 +456,35 @@ console.log(describeUnsupportedAlgorithm(spkiBase64));
|
|
|
155
456
|
that refuses to *load* a key of some algorithm produces no key object to
|
|
156
457
|
resolve, which is exactly when the question matters most.
|
|
157
458
|
|
|
158
|
-
##
|
|
459
|
+
## Supplied keys
|
|
159
460
|
|
|
160
|
-
`options.publicKeys` accepts
|
|
461
|
+
`options.publicKeys` accepts these shapes:
|
|
161
462
|
|
|
162
463
|
- a **`Record<keyId, base64SpkiDer>`** map (compact, keyed by key id), or
|
|
163
|
-
-
|
|
464
|
+
- a **`SuppliedKeyEntry[]`** array, the natural shape returned by
|
|
164
465
|
`client.verificationKeys.list().data` and SCITT COSE_KeySet listings, where
|
|
165
|
-
each entry is `{ keyId, publicKey, activatedAt?, retiredAt? }`
|
|
166
|
-
is SPKI DER base64)
|
|
466
|
+
each entry is `{ keyId, publicKey, activatedAt?, retiredAt?, statements? }`
|
|
467
|
+
(`publicKey` is SPKI DER base64), or the `/v1/verification-keys` body as
|
|
468
|
+
served, `{ data: [...] }`, read as its `data`.
|
|
167
469
|
|
|
168
470
|
Both are normalized at the boundary; anything else throws `TypeError`
|
|
169
471
|
(fail-closed: the verifier never silently falls back to embedded keys).
|
|
170
472
|
|
|
473
|
+
## Org-read log
|
|
474
|
+
|
|
475
|
+
The cross-party read log (`org_admin_reads`) is an RFC 9162 §2.1 Merkle tree,
|
|
476
|
+
the same construction SCITT Receipts use. Its hashes are lowercase hex:
|
|
477
|
+
|
|
478
|
+
```ts
|
|
479
|
+
import { orgReadLeafHash, orgReadMerkleRoot, verifyOrgReadInclusion } from '@agledger/verify-core';
|
|
480
|
+
|
|
481
|
+
// leaf_hash = hex(sha256(0x00 || cose_sign1)); a checkpoint's root is the RFC 9162 root over them.
|
|
482
|
+
const leaf = orgReadLeafHash(Buffer.from('cose-sign1-bytes'));
|
|
483
|
+
const root = orgReadMerkleRoot([leaf]);
|
|
484
|
+
// An inclusion proof from GET /v1/audit/org-reads/checkpoints/{id}/proof; a one-leaf tree has an empty path.
|
|
485
|
+
console.log(root === leaf, verifyOrgReadInclusion(leaf, 0, 1, [], root!)); // true true
|
|
486
|
+
```
|
|
487
|
+
|
|
171
488
|
## Canonical failure taxonomy
|
|
172
489
|
|
|
173
490
|
Every failure is a canonical SCREAMING_SNAKE `FailureCode`. Importing the
|
|
@@ -177,9 +494,11 @@ chain was checked by the SDK, the CLI, the MCP tool, or `@agledger/verify`.
|
|
|
177
494
|
|
|
178
495
|
## Key provenance
|
|
179
496
|
|
|
180
|
-
The result distinguishes keys supplied
|
|
181
|
-
|
|
182
|
-
|
|
497
|
+
The result distinguishes keys **supplied** by the caller from keys **embedded in
|
|
498
|
+
the export** under inspection (`keyProvenance`), and `requireSuppliedKeys`
|
|
499
|
+
refuses embedded keys. That says where a key came from, not that it is trusted:
|
|
500
|
+
a key fetched from the Server comes from its database too. Trust is what
|
|
501
|
+
`trustAnchors` establishes.
|
|
183
502
|
|
|
184
503
|
## License
|
|
185
504
|
|