@agledger/verify-core 2.2.0 → 4.0.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/LICENSE +18 -18
- package/README.md +797 -29
- package/dist/acknowledgements.d.ts +32 -0
- package/dist/acknowledgements.js +88 -0
- package/dist/anchors.d.ts +349 -0
- package/dist/anchors.js +654 -0
- package/dist/attestation.d.ts +98 -0
- package/dist/attestation.js +145 -0
- package/dist/audit-export.d.ts +343 -20
- package/dist/audit-export.js +400 -22
- package/dist/batch-head.d.ts +28 -0
- package/dist/batch-head.js +169 -0
- package/dist/batch.d.ts +69 -0
- package/dist/batch.js +99 -0
- package/dist/bulk-export.d.ts +161 -0
- package/dist/bulk-export.js +711 -0
- package/dist/chain.d.ts +135 -13
- package/dist/chain.js +229 -24
- package/dist/claim.d.ts +23 -0
- package/dist/claim.js +100 -0
- package/dist/export-anchors.d.ts +84 -0
- package/dist/export-anchors.js +109 -0
- package/dist/export-evidence.d.ts +90 -0
- package/dist/export-evidence.js +186 -0
- package/dist/export-pages.d.ts +476 -0
- package/dist/export-pages.js +586 -0
- package/dist/failures.d.ts +20 -16
- package/dist/failures.js +44 -16
- package/dist/federation-wire.d.ts +78 -11
- package/dist/federation-wire.js +199 -57
- package/dist/history-seal.d.ts +100 -0
- package/dist/history-seal.js +301 -0
- package/dist/index.d.ts +36 -8
- package/dist/index.js +17 -4
- package/dist/key-statements.d.ts +138 -5
- package/dist/key-statements.js +191 -20
- package/dist/ml-dsa-kats.d.ts +18 -0
- package/dist/ml-dsa-kats.js +241 -0
- package/dist/primitives.d.ts +255 -18
- package/dist/primitives.js +612 -55
- package/dist/read-log.d.ts +350 -0
- package/dist/read-log.js +816 -0
- package/dist/schema-chain-export.d.ts +82 -0
- package/dist/schema-chain-export.js +474 -0
- package/dist/walk-anchors.d.ts +115 -0
- package/dist/walk-anchors.js +133 -0
- package/dist/walk-checkpoints.d.ts +125 -0
- package/dist/walk-checkpoints.js +118 -0
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@ The shared offline verification core for AGLedger audit chains. Decodes
|
|
|
4
4
|
canonical **COSE_Sign1** envelopes (RFC 9052, tag 18) over in-toto v1
|
|
5
5
|
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
|
-
commits to (Ed25519 or
|
|
7
|
+
commits to (Ed25519, ES256, ES384 or ML-DSA), with no Server, 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
|
|
9
|
+
Reads exports and dumps from an AGLedger Server 2.0 or later. For exports from a 1.x Server, use `npm i @agledger/verify-core@1.5.0`, the last release that reads them.
|
|
10
10
|
|
|
11
11
|
This is the single body of logic that underpins the SDK `/verify` subpath
|
|
12
12
|
(`@agledger/sdk/verify`), the [`@agledger/cli`](https://github.com/agledger-ai/cli)
|
|
@@ -26,7 +26,10 @@ CBOR decoding.
|
|
|
26
26
|
npm install @agledger/verify-core
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
Node 24 or newer
|
|
29
|
+
Node.js 24.6.0 or newer, the first release that computes ML-DSA, the Server's
|
|
30
|
+
default signing algorithm. `runtimeBelowFloor()` reports an older runtime, and a
|
|
31
|
+
result reached on one carries `runtime` (show `belowFloorNotice(result.runtime)`
|
|
32
|
+
first, and verify again on a current Node.js before acting on the verdict). If you want a ready-made verifier rather than a library, use
|
|
30
33
|
[`@agledger/verify`](https://github.com/agledger-ai/verify) for a full-vault dump
|
|
31
34
|
or the `verify` command in [`@agledger/cli`](https://github.com/agledger-ai/cli)
|
|
32
35
|
for a single record export.
|
|
@@ -45,12 +48,30 @@ if (result.verdict === 'failed') {
|
|
|
45
48
|
console.error(`Broken at position ${result.brokenAt?.position}: ${result.brokenAt?.code}`);
|
|
46
49
|
process.exit(1);
|
|
47
50
|
}
|
|
48
|
-
console.log(result.verdict); // 'trusted',
|
|
51
|
+
console.log(result.verdict); // 'trusted', 'unanchored' when nothing pinned backs the pass, or 'unverifiable'
|
|
49
52
|
// { valid: true, verdict, verifiedEntries, totalEntries, keyTrust, keyProvenance: { supplied, embedded }, ... }
|
|
50
53
|
```
|
|
51
54
|
|
|
52
55
|
Read `verdict` rather than `valid`: a valid result with no `trustAnchors` is
|
|
53
|
-
`unanchored`, which is not a trusted verdict.
|
|
56
|
+
`unanchored`, which is not a trusted verdict. The four verdicts:
|
|
57
|
+
|
|
58
|
+
- `trusted`: every check passed, and the walk from your `trustAnchors`
|
|
59
|
+
anchored the keys the signatures verified under.
|
|
60
|
+
- `unanchored`: every check passed, but nothing you pinned backs it (see
|
|
61
|
+
"Anchoring keys"). Also a pinned result that fails only because the pin was
|
|
62
|
+
not met, or only because the pin predates the move to ML-DSA.
|
|
63
|
+
- `unverifiable`: `valid` is false, this host refused to compute signatures
|
|
64
|
+
under an algorithm this build supports, and the result would be valid if
|
|
65
|
+
the checks this host refused had verified. Under a pin this host can
|
|
66
|
+
compute, a key is trusted only through signatures this host computed.
|
|
67
|
+
The signatures this host refused were not verified, so this is not a
|
|
68
|
+
verified result (see "Verifying on a FIPS-locked host").
|
|
69
|
+
- `failed`: anything else that failed. A real failure anywhere (a hash
|
|
70
|
+
mismatch, a signature that was checked and did not verify, a key-statement
|
|
71
|
+
finding, a count that does not hold) is `failed`, whatever else is
|
|
72
|
+
uncomputed beside it.
|
|
73
|
+
|
|
74
|
+
An option the function does not
|
|
54
75
|
read throws `TypeError` rather than being ignored, so a misspelt option, or
|
|
55
76
|
the old name `requireOutOfBandKeys` (the option is `requireSuppliedKeys`),
|
|
56
77
|
cannot turn a check off without a word.
|
|
@@ -64,8 +85,9 @@ cannot turn a check off without a word.
|
|
|
64
85
|
- **Signed chain-claim cross-check**: the chain position and linkage claimed in
|
|
65
86
|
the COSE protected header match the row columns.
|
|
66
87
|
- **Envelope signature**: over the reconstructed `Sig_structure`, against the
|
|
67
|
-
matched verification key, under the algorithm its SPKI commits to (Ed25519
|
|
68
|
-
or
|
|
88
|
+
matched verification key, under the algorithm its SPKI commits to (Ed25519,
|
|
89
|
+
ES256, ES384, or ML-DSA-44, -65 or -87; anything else fails closed as
|
|
90
|
+
`CHAIN_UNSUPPORTED_ALGORITHM`).
|
|
69
91
|
- **Signed-kid binding**: the row's `signingKeyId` names the key the protected
|
|
70
92
|
header signed. An entry that names a key but carries an all-zero signature
|
|
71
93
|
fails `CHAIN_SIGNATURE_INVALID`.
|
|
@@ -111,6 +133,58 @@ cannot turn a check off without a word.
|
|
|
111
133
|
band as `expectedEntryCount`: an export carrying a different number of
|
|
112
134
|
entries fails `CHAIN_POSITION_GAP`. `optionalChecks.entry_count` is
|
|
113
135
|
`applied` when any count was held and `skipped_no_input` when none was.
|
|
136
|
+
- **The checkpoint**, when `exportMetadata.checkpointEvidence` embeds one
|
|
137
|
+
(Server 4.0.0 or later):
|
|
138
|
+
the entry at its position must exist (else `CHECKPOINT_ROW_MISSING`) and
|
|
139
|
+
carry its tip hash (else `CHECKPOINT_HASH_MISMATCH`); its signed claim must
|
|
140
|
+
be a vault checkpoint naming that position (as `count` and as `range` 1 to
|
|
141
|
+
the position), tip, record and key (else `CHECKPOINT_CLAIM_MISMATCH`);
|
|
142
|
+
and its signature must verify under a key resolved and anchored the same way
|
|
143
|
+
as the entries' keys, with the `iat` it signs inside that key's window, give
|
|
144
|
+
or take 300 seconds at each edge (`CHECKPOINT_SIGNATURE_INVALID`,
|
|
145
|
+
`CHECKPOINT_KEY_UNANCHORED`, `CHECKPOINT_KEY_NOT_YET_ACTIVE`,
|
|
146
|
+
`CHECKPOINT_KEY_EXPIRED`). Unlike the counts above, the checkpoint is
|
|
147
|
+
signed, so a cut below it shows whatever the metadata says.
|
|
148
|
+
`result.checkpointEvidence` reports its position and state;
|
|
149
|
+
`optionalChecks.checkpoint_evidence` is `skipped_no_input` on an export
|
|
150
|
+
that embeds none.
|
|
151
|
+
- **Receipts**, on an export taken with `?receipts=true`: each entry's
|
|
152
|
+
`integrity.receipt` must verify under the key its kid names and prove the
|
|
153
|
+
entry's own `coseSign1` bytes at leaf `chainPosition - 1` of a tree no larger
|
|
154
|
+
than the chain. A Receipt that does not, or one missing from some entries
|
|
155
|
+
only, fails `RECEIPT_INVALID`. `result.receipts` counts them.
|
|
156
|
+
- **The coverage the checkpoint block states**: `lastEntryPosition`,
|
|
157
|
+
`coveredThroughPosition`, `coverage`, `uncoveredFromPosition` and
|
|
158
|
+
`uncoveredEntries` in `exportMetadata.checkpointEvidence` must be the values
|
|
159
|
+
the entries and the embedded checkpoint give, or the export fails
|
|
160
|
+
`CHECKPOINT_COVERAGE_MISMATCH`; a `lastEntryPosition` above the last entry
|
|
161
|
+
carried fails `CHAIN_POSITION_GAP`. `result.checkpointCoverage` lists the
|
|
162
|
+
fields held.
|
|
163
|
+
- **Acknowledgements of lost history** (`checkpointEvidence.acknowledgedRewinds`):
|
|
164
|
+
see [The anchor bucket](#the-anchor-bucket).
|
|
165
|
+
- **Anchor documents**, when you pass `anchorDocuments`: see
|
|
166
|
+
[The anchor bucket](#the-anchor-bucket).
|
|
167
|
+
- **Compliance attestations**: a `COMPLIANCE_ATTESTATION` or
|
|
168
|
+
`AI_IMPACT_ASSESSMENT` entry that signs `contentHash` or `attestedAt` must
|
|
169
|
+
sign them in the Server's forms (`sha256:` and 64 lowercase hex characters;
|
|
170
|
+
an RFC 3339 instant), or fails `CONTENT_BINDING_MALFORMED`. Pass the
|
|
171
|
+
responses of `GET /v1/records/{id}/compliance-records/{complianceRecordId}`
|
|
172
|
+
as `complianceRecords` (one, an array, or the list body `{ data: [...] }`)
|
|
173
|
+
and each is bound by its `id` to the entry that names it: its `attestation`
|
|
174
|
+
must hash, as SHA-256 over its RFC 8785 form, to the signed `contentHash`
|
|
175
|
+
(else `CONTENT_HASH_MISMATCH`), and its `recordId`, `recordType`,
|
|
176
|
+
`attestedBy` and `attestedAt` must be the signed values (else
|
|
177
|
+
`CONTENT_FIELD_DRIFT`). A supplied record of this record that no entry names
|
|
178
|
+
fails `CONTENT_ROW_UNSIGNED`; one of another record is listed in
|
|
179
|
+
`result.attestations.otherRecords`. `optionalChecks.attestation_bodies` says
|
|
180
|
+
whether a body was held. Each entry's `serverContentBinding` in
|
|
181
|
+
`result.attestations.entries` is the export's `integrity.contentBinding`:
|
|
182
|
+
the Server's own answer, unsigned, reported beside the verdict and kept out
|
|
183
|
+
of it.
|
|
184
|
+
- **Batched entries**, on an export from a Server on the batched signing
|
|
185
|
+
cadence: an entry with the batch marker in its protected header is verified
|
|
186
|
+
through `integrity.batch` and the head it names in
|
|
187
|
+
`exportMetadata.batchHeads` (see [Batched signing](#batched-signing)).
|
|
114
188
|
- **The record id**: `result.recordId` is the id the entries sign, never the
|
|
115
189
|
unsigned `exportMetadata.recordId`. A metadata id that disagrees with what
|
|
116
190
|
the entries sign, or entries that name different records, fails
|
|
@@ -128,11 +202,133 @@ which ran, so "not checked" never reads as "passed".
|
|
|
128
202
|
|
|
129
203
|
### SCITT receipts
|
|
130
204
|
|
|
131
|
-
`verifyAuditExport`
|
|
132
|
-
|
|
205
|
+
`verifyAuditExport` verifies the Receipts an export carries. To verify one on
|
|
206
|
+
its own (from SCRAPI, say), call
|
|
133
207
|
`verifyReceipt(receiptBytes, signedStatementBytes, transparencyServicePublicKeyBase64)`,
|
|
134
208
|
which returns `'ok'` or the reason it failed.
|
|
135
209
|
|
|
210
|
+
## Batched signing
|
|
211
|
+
|
|
212
|
+
A Server can sign chain entries in batches (`vaultSigningCadence: "batched"`
|
|
213
|
+
on `/v1/conformance`). A batched record-chain or schema-chain entry carries
|
|
214
|
+
protected-header label `-65541` with value 1 and an empty signature. The marker
|
|
215
|
+
is inside the protected header, so the entry's `payloadHash` covers it. A
|
|
216
|
+
signed batch head then covers the entry: one COSE_Sign1 under a vault key over
|
|
217
|
+
an RFC 9162 Merkle root. The platform-ops chain is always signed per entry.
|
|
218
|
+
|
|
219
|
+
`verifyAuditExport` verifies a batched entry in three steps:
|
|
220
|
+
|
|
221
|
+
1. **The entry.** Its key is resolved, anchored and held to its window as for
|
|
222
|
+
any entry, its header `alg` must be one that key signs under, and its
|
|
223
|
+
signature must be empty. A marked entry that carries a signature, and an
|
|
224
|
+
unmarked entry with an empty one, fail `CHAIN_SIGNATURE_INVALID`.
|
|
225
|
+
2. **The proof.** `integrity.batch` (`batchId`, `leafIndex`, `treeSize`,
|
|
226
|
+
`auditPath`) must reach the head's signed root from the entry's own leaf:
|
|
227
|
+
56 bytes holding the record id, the chain position and the entry's
|
|
228
|
+
`payloadHash`. A proof that does not is `BATCH_LEAF_MISMATCH`.
|
|
229
|
+
3. **The head.** The entry in `exportMetadata.batchHeads` with that id must be
|
|
230
|
+
a batch head for that id, signed by a key that is anchored and inside its
|
|
231
|
+
window at the head's `createdAt`. The head's key can differ from the
|
|
232
|
+
entry's. Anything else is `BATCH_HEAD_INVALID`.
|
|
233
|
+
|
|
234
|
+
An entry signed this way counts in `signatureCoverage.signed` and in
|
|
235
|
+
`signatureCoverage.batched`.
|
|
236
|
+
|
|
237
|
+
A batched entry with no proof is one no head covers yet. The Server gives an
|
|
238
|
+
entry 300 seconds to be covered, so the verifier reads one written within 300
|
|
239
|
+
seconds before `exportMetadata.exportDate` as `pending`: the result stays
|
|
240
|
+
valid, the entry counts in `signatureCoverage.pending` and not as signed, and
|
|
241
|
+
a result with no signed entry is not a trusted verdict. An entry with no proof
|
|
242
|
+
that is older than that, or an export that does not say when it was cut, fails
|
|
243
|
+
`BATCH_UNATTESTED`. Export the record again to get the proof.
|
|
244
|
+
|
|
245
|
+
To check a head or a proof yourself:
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
import { buildBatchHeadRegistry, checkBatchProof } from '@agledger/verify-core';
|
|
249
|
+
|
|
250
|
+
// `keys` is a KeyRegistry (buildKeyRegistry, then applyKeyTrust when you pin).
|
|
251
|
+
const heads = buildBatchHeadRegistry(exportDocument.exportMetadata.batchHeads ?? [], keys);
|
|
252
|
+
const head = heads.get(proof.batchId.toLowerCase());
|
|
253
|
+
if (head?.state === 'ok') {
|
|
254
|
+
// null when the proof reaches the signed root, else what is wrong with it.
|
|
255
|
+
const wrong = checkBatchProof(recordId, chainPosition, payloadHash, proof, head);
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## History seal
|
|
260
|
+
|
|
261
|
+
A Server that moves to ML-DSA keeps the records its Ed25519, ES256 or ES384
|
|
262
|
+
keys signed. When it retires such a key from a process that signs with ML-DSA,
|
|
263
|
+
it writes one history seal: an ML-DSA signature over an RFC 9162 Merkle root
|
|
264
|
+
with one leaf per chain, each leaf that chain's tip at the retirement. The
|
|
265
|
+
retirement waits out every write under the retired key first. The closure that
|
|
266
|
+
retires the key names the seal (`history: { seal, root, treeSize }`), and the
|
|
267
|
+
seal names the closure, both signed by one key.
|
|
268
|
+
|
|
269
|
+
An export carries every seal in `exportMetadata.historySeals`, each with the
|
|
270
|
+
record chain's inclusion proof. On a verification whose `trustAnchors` reach an
|
|
271
|
+
ML-DSA key, `verifyAuditExport` holds every entry a classical key signed to the
|
|
272
|
+
seal that covers that key:
|
|
273
|
+
|
|
274
|
+
- the seal verifies under an anchored ML-DSA key inside its window, and it and
|
|
275
|
+
the closure name each other (`HISTORY_SEAL_INVALID` otherwise);
|
|
276
|
+
- the chain's proof reaches the signed root, and the entry at the sealed
|
|
277
|
+
position is the one the leaf names (`HISTORY_SEAL_INVALID`);
|
|
278
|
+
- the entry sits at or below the sealed position (`HISTORY_SEAL_EXCEEDED`);
|
|
279
|
+
- the seal has a leaf for the chain (`HISTORY_SEAL_MISSING_CHAIN`).
|
|
280
|
+
|
|
281
|
+
So the ML-DSA-signed root, through the hash chain below the sealed tip, is what
|
|
282
|
+
vouches for those entries. A chain rewritten and re-signed under the classical
|
|
283
|
+
key no longer matches the leaf.
|
|
284
|
+
|
|
285
|
+
The seal that covers a key is its own. A key retired before any seal was
|
|
286
|
+
written is held to the first seal written after its retirement, since every
|
|
287
|
+
seal covers every chain's tip.
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
import { verifyAuditExport } from '@agledger/verify-core';
|
|
291
|
+
|
|
292
|
+
const result = verifyAuditExport(exportDocument, { trustAnchors: ['sha256:<the ML-DSA key>'] });
|
|
293
|
+
result.historySeal; // { sealed: 12, unsealed: 0, unsealedKeys: [] }
|
|
294
|
+
result.optionalChecks.history_seal; // 'applied'
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
**Unsealed keys.** A classical key that no seal covers (it is still signing
|
|
298
|
+
between the succession and its retirement, or the export carries no seal for
|
|
299
|
+
it) leaves its entries valid and resting on their classical signatures alone.
|
|
300
|
+
Such a result reads `unanchored`, never `trusted`, and
|
|
301
|
+
`historySeal.unsealedKeys` names each key and what seals it: retire the key on
|
|
302
|
+
the Server and take the export again.
|
|
303
|
+
|
|
304
|
+
**Which pin.** An ML-DSA key is reached only through an ML-DSA signature. A
|
|
305
|
+
succession from a classical key to an ML-DSA key is signed by both; the walk
|
|
306
|
+
takes the ML-DSA key's half, which leads back to the classical key, and gives
|
|
307
|
+
the classical key's half no power to admit the ML-DSA key. Pin the ML-DSA key:
|
|
308
|
+
from it the walk reaches every key before it, except past a key retired with
|
|
309
|
+
`force`, which voids every edge out of that key. Where the history holds a
|
|
310
|
+
forced retirement, pin the key it retired as well, once you have confirmed
|
|
311
|
+
it with the Server's operator.
|
|
312
|
+
|
|
313
|
+
**A pin held since before the upgrade.** A walk pinned to a classical key
|
|
314
|
+
stops at the handover: the ML-DSA key, what it signed and the retirement it
|
|
315
|
+
signed for the old key are not anchored, and those read as failures
|
|
316
|
+
(`CHAIN_SIGNING_KEY_UNANCHORED`, `KEY_CLOSURE_INVALID`). When the same input
|
|
317
|
+
verifies with the handed-over key pinned as well, nothing else is wrong, and
|
|
318
|
+
the result says so: `verdict` is `unanchored`, `valid` stays false,
|
|
319
|
+
`keyTrust.successorPins` lists the keys to pin, and
|
|
320
|
+
`pinPredatesDetail(result.keyTrust.successorPins)` is the sentence to show.
|
|
321
|
+
Confirm the current pin with the Server's operator before using it; the keys
|
|
322
|
+
named come from the artifact. Anything else wrong beside the stale pin still
|
|
323
|
+
reads `failed`.
|
|
324
|
+
|
|
325
|
+
A Server that signs with ES384 throughout (a FIPS host) writes no seal, and a
|
|
326
|
+
verification that reaches no ML-DSA key is held to none.
|
|
327
|
+
|
|
328
|
+
`planHistorySeals`, `judgeHistorySeal` and `resolveHistorySealLeaf` are
|
|
329
|
+
exported for a verifier that reads seals from another artifact, with
|
|
330
|
+
`historySeals` and `historySealProofs` as the matching `verifyChain` options.
|
|
331
|
+
|
|
136
332
|
## Anchoring keys
|
|
137
333
|
|
|
138
334
|
A vault key the Server publishes comes from its database, and anything with
|
|
@@ -366,26 +562,36 @@ the cert's public key. The envelope signature covers it as the Server wrote it.
|
|
|
366
562
|
check that the agent itself signed, without taking the Server's word for it,
|
|
367
563
|
re-verify the agent signature against the cert's public key.
|
|
368
564
|
|
|
369
|
-
The export does not carry cert public keys. Supply them as the
|
|
370
|
-
|
|
371
|
-
|
|
565
|
+
The export does not carry cert public keys. Supply them as the JWK the agent
|
|
566
|
+
sent to `POST /v1/auth/oidc/cert` (the same key is the `cnf.jwk` claim inside
|
|
567
|
+
the `certJws` it got back). A cert key is ML-DSA-87 or ML-DSA-65
|
|
568
|
+
(`{ kty: 'AKP', alg, pub }`, RFC 9964) or P-384 (`{ kty: 'EC', crv: 'P-384', x, y }`).
|
|
569
|
+
A cert a Server before 4.0.0 issued holds an Ed25519 key
|
|
570
|
+
(`{ kty: 'OKP', crv: 'Ed25519', x }`), which still verifies:
|
|
372
571
|
|
|
373
572
|
```ts
|
|
374
573
|
import { verifyAuditExport } from '@agledger/verify-core';
|
|
375
574
|
|
|
376
|
-
|
|
575
|
+
// The agent's own publicKeyJwk, as it sent it at cert exchange.
|
|
576
|
+
const agentKey = { kty: 'EC', crv: 'P-384', x: 'qc7r...', y: 'Xk2f...' } as const;
|
|
377
577
|
const result = verifyAuditExport(exportDocument, { agentKeys: [agentKey] });
|
|
378
578
|
|
|
379
579
|
console.log(result.optionalChecks.agent_signature); // 'applied'
|
|
380
580
|
console.log(result.agentSignatures); // e.g. { present: 6, verified: 6 }
|
|
381
581
|
```
|
|
382
582
|
|
|
583
|
+
`agentKeys` takes each key bare, as above, or as an agent records it,
|
|
584
|
+
`{ certId, publicKeyJwk: {...} }`: only `publicKeyJwk` is read. The file
|
|
585
|
+
`agledger-verify --agent-keys` reads holds the same entries.
|
|
586
|
+
|
|
383
587
|
A key is matched to an entry only through the thumbprint that entry signed, so
|
|
384
588
|
a key for some other cert is never checked against it and where the key came
|
|
385
589
|
from needs no trust. `present` counts entries carrying an agent signature and
|
|
386
590
|
`verified` those re-checked and found good; `present > verified` on a valid
|
|
387
591
|
result means some were not checked, never that they failed. One that does not
|
|
388
|
-
verify fails `CHAIN_AGENT_SIGNATURE_INVALID`. The
|
|
592
|
+
verify fails `CHAIN_AGENT_SIGNATURE_INVALID`. The algorithm is the cert key's
|
|
593
|
+
own: a sealed `alg` that names another one fails the same way, and never
|
|
594
|
+
chooses how the signature is checked. The check runs only where
|
|
389
595
|
`on_behalf_of.validated` is `true`: on a caller-asserted identity the two fields
|
|
390
596
|
may be passthrough from an older Server, and the export cannot tell which.
|
|
391
597
|
|
|
@@ -397,13 +603,15 @@ peer signed it, the peer's registered key, the hub ids, the body hash, the
|
|
|
397
603
|
timestamp, the nonce and the signature. Every sealed message is held to its
|
|
398
604
|
body hash and to the entry that carries it (`federation_wire` in
|
|
399
605
|
`optionalChecks`, `applied` once one was seen). Pass the peer's federation key,
|
|
400
|
-
as its operator gives it
|
|
401
|
-
|
|
606
|
+
as its operator gives it, to also re-verify the peer's signature. A federation
|
|
607
|
+
key is ML-DSA-87 or ES384, as base64 SPKI DER. A Server before 4.0.0 held an
|
|
608
|
+
Ed25519 key, which is taken as base64 SPKI DER or base64 of the raw 32 bytes,
|
|
609
|
+
so the messages it sealed still verify:
|
|
402
610
|
|
|
403
611
|
```ts
|
|
404
612
|
import { verifyAuditExport } from '@agledger/verify-core';
|
|
405
613
|
|
|
406
|
-
const result = verifyAuditExport(exportDocument, { federationKeys: { 'hub-b': '
|
|
614
|
+
const result = verifyAuditExport(exportDocument, { federationKeys: { 'hub-b': 'MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE...' } });
|
|
407
615
|
|
|
408
616
|
console.log(result.federationWire); // e.g. { present: 2, verified: 2, failed: 0, afterRetirement: 0 }
|
|
409
617
|
```
|
|
@@ -421,7 +629,7 @@ const response = await fetch('https://hub-b.example.com/.well-known/agledger-fed
|
|
|
421
629
|
const history = (await response.json()) as FederationKeyHistoryDocument;
|
|
422
630
|
|
|
423
631
|
const result = verifyAuditExport(exportDocument, {
|
|
424
|
-
federationKeys: [{ hubId: 'hub-b', publicKey: '
|
|
632
|
+
federationKeys: [{ hubId: 'hub-b', publicKey: 'MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE...', history }],
|
|
425
633
|
});
|
|
426
634
|
```
|
|
427
635
|
|
|
@@ -447,6 +655,13 @@ trusted on its own. A history that is another hub's, carries a statement that
|
|
|
447
655
|
does not verify, or lists none of the keys pinned for its hub throws
|
|
448
656
|
`TypeError` before anything is verified. Federation key histories need a Server 2.2 or later on the peer.
|
|
449
657
|
|
|
658
|
+
The signature's algorithm is the key's. Under ML-DSA-87 or ES384 it is
|
|
659
|
+
base64url without padding, at exactly the algorithm's length (4627 bytes, or
|
|
660
|
+
the 96-byte `r||s` of ES384 with low S); under an Ed25519 key it is 128 hex
|
|
661
|
+
characters. Any other spelling fails, as it does on the Server. A key history
|
|
662
|
+
can cross algorithms: each half of a succession is signed in its own key's
|
|
663
|
+
form.
|
|
664
|
+
|
|
450
665
|
A sealed signature that does not verify, a sealed key that is not the one
|
|
451
666
|
supplied for that hub, a body that no longer hashes to what was signed, or an
|
|
452
667
|
entry that asserts a state the sealed body does not carry fails
|
|
@@ -461,19 +676,481 @@ live cert record (`cert_missing`, `cert_actor_drift`, `cert_window_drift`,
|
|
|
461
676
|
counterpart; the signed bytes already fix the cert id, thumbprint and expiry an
|
|
462
677
|
entry sealed.
|
|
463
678
|
|
|
679
|
+
### Acknowledgements and counter-signatures
|
|
680
|
+
|
|
681
|
+
A Server answers a federated message with a signature of its own, and
|
|
682
|
+
counter-signs a co-sign request. Both verify offline under that Server's
|
|
683
|
+
ML-DSA-87 or ES384 federation key, in the same one spelling a sealed message's
|
|
684
|
+
signature takes:
|
|
685
|
+
|
|
686
|
+
```ts
|
|
687
|
+
import { verifyFederationAck, verifyFederationCoSign } from '@agledger/verify-core';
|
|
688
|
+
|
|
689
|
+
verifyFederationAck({ kind: 'ack', recordId, value: 'FULFILLED', serverTimestamp, serverSignature, signerPublicKey });
|
|
690
|
+
verifyFederationCoSign({ claim, counterSignature, signerPublicKey });
|
|
691
|
+
// { state: 'ok' } | { state: 'invalid', code: 'FEDERATION_SIGNATURE_INVALID', detail } | { state: 'unsupported', detail }
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
A signature a Server before 4.0.0 made verifies the same way under its Ed25519
|
|
695
|
+
key, in 128 hex characters.
|
|
696
|
+
|
|
697
|
+
An acknowledgement covers
|
|
698
|
+
`agledger.federation.ack.v1:<kind>:<recordId>:<value>:<serverTimestamp>`, with
|
|
699
|
+
`kind` one of `ack` (a state transition, `value` the state), `signal` (`value`
|
|
700
|
+
the recommendation) or `dispute` (`value` the action). A counter-signature
|
|
701
|
+
covers `agledger.federation.co-sign.v1:` followed by the RFC 8785 form of the
|
|
702
|
+
claim, which holds exactly `recordId`, `outcome`, `recommendation`,
|
|
703
|
+
`outcomeHash`, `state`, `performerHubId` and `validUntil`. Each signature
|
|
704
|
+
covers its own domain, so one made for a sealed message, or for another
|
|
705
|
+
acknowledgement kind, does not verify here.
|
|
706
|
+
|
|
707
|
+
### A key history that does not hold
|
|
708
|
+
|
|
709
|
+
In a key history, a statement that does not verify takes no part in the walk:
|
|
710
|
+
the keys it alone would link are not trusted, and the rest of the history
|
|
711
|
+
stands. `buildFederationKeyRegistry` throws `FederationKeyHistoryError` (a
|
|
712
|
+
`TypeError` with `code: 'FEDERATION_KEY_HISTORY_INVALID'`) when no key pinned
|
|
713
|
+
for a hub is a key its history admits, which is also what a pin reads when the
|
|
714
|
+
statement admitting it does not verify. Trusted keys are listed newest first.
|
|
715
|
+
|
|
716
|
+
## The anchor bucket
|
|
717
|
+
|
|
718
|
+
A Server with anchoring on writes each checkpoint to its anchor bucket as a
|
|
719
|
+
JSON document at `vault-anchors/<instanceId>/<chainKey>/<chainPosition>.json`,
|
|
720
|
+
once per position for the life of the install. Read them from the bucket (or a
|
|
721
|
+
copy of it) and pass them to `verifyAuditExport` as `anchorDocuments`, each as
|
|
722
|
+
`{ source, document, objectKey? }` with `document` the parsed JSON and
|
|
723
|
+
`objectKey` the key it was stored under. `compareCheckpointAnchors(documents,
|
|
724
|
+
chain, keys, acknowledgements)` runs the same comparison on a chain you hold
|
|
725
|
+
some other way.
|
|
726
|
+
|
|
727
|
+
Only the signed `coseSign1` inside a document is evidence. A document is
|
|
728
|
+
compared when that envelope decodes as a vault checkpoint of this chain and
|
|
729
|
+
verifies under one of the export's keys, resolved and anchored like the
|
|
730
|
+
entries' keys, with its signed `iat` inside the key's window (300 seconds of
|
|
731
|
+
skew at each edge). Each compared document reads:
|
|
732
|
+
|
|
733
|
+
- `agree`: its signed tip is the `payloadHash` of the entry at its position
|
|
734
|
+
(`how: 'same_bytes'` when it carries the very envelope the export embeds).
|
|
735
|
+
- `disagree`, which fails the verdict: `ANCHOR_CHAIN_CUT` when its position is
|
|
736
|
+
above the last entry, `ANCHOR_CHAIN_REWRITTEN` when the entry there has
|
|
737
|
+
another `payloadHash`, `ANCHOR_FORK` when two compared documents sign
|
|
738
|
+
different tips for one position.
|
|
739
|
+
- `accounted`: a disagreement an acknowledgement of lost history covers. The
|
|
740
|
+
acknowledgement is a RESTORE_EPOCH entry on the platform-ops chain, written
|
|
741
|
+
by `POST /v1/admin/vault/rewind/acknowledge`, that verifies under an anchored
|
|
742
|
+
key inside its window and lists `{ recordId: <chainKey>, lo, hi }` in its
|
|
743
|
+
signed `coveredFindings` with `lo < position <= hi` and `lo` at or below the
|
|
744
|
+
last entry, and that was signed after the anchor. An export lists the ones
|
|
745
|
+
naming its chain in `checkpointEvidence.acknowledgedRewinds`; each is
|
|
746
|
+
verified from its own envelope and its unsigned `coveredRanges` held to the
|
|
747
|
+
signed findings (else `REWIND_ACKNOWLEDGEMENT_INVALID`).
|
|
748
|
+
`result.acknowledgedRewinds.linkChecked` is false: an acknowledgement's link
|
|
749
|
+
in the platform-ops chain is established by a dump of that chain, which
|
|
750
|
+
`@agledger/verify` checks.
|
|
751
|
+
- `not_comparable`, with a `reason`, for everything else: a file that is no
|
|
752
|
+
version 2 anchor document, a SCITT tree-head anchor, a checkpoint of another
|
|
753
|
+
chain, one that is unsigned, under an unknown, unanchored or distrusted key,
|
|
754
|
+
whose signature fails, or outside its key's window. These are evidence of
|
|
755
|
+
nothing and leave the verdict as it was. So is an anchor signed after the
|
|
756
|
+
read time (`signed_after_read`), which may cover entries written since the
|
|
757
|
+
export was read, when that read time is yours.
|
|
758
|
+
|
|
759
|
+
The read time is the one you give as `exportDate` (the instant you read the
|
|
760
|
+
export), and otherwise the export's own
|
|
761
|
+
`checkpointEvidence.anchorsJudgedThroughIat`, less one second either way.
|
|
762
|
+
The export's own is unsigned, and moving it earlier would set aside an anchor
|
|
763
|
+
that shows a cut. So an anchor whose checkpoint verifies and signs a position
|
|
764
|
+
above the last entry the export holds, set aside on the export's own read
|
|
765
|
+
time or with no read time at all, is listed in `result.capped` (reason
|
|
766
|
+
`read_time_not_given`) and the verdict reads at best `unanchored`. Give
|
|
767
|
+
`exportDate` to judge it: signed before your read time, it fails
|
|
768
|
+
`ANCHOR_CHAIN_CUT` unless an acknowledgement accounts for it; signed after,
|
|
769
|
+
it is set aside. A read time the export states (`exportMetadata.exportDate`,
|
|
770
|
+
`checkpointEvidence.evidenceReadAt`, `anchorsJudgedThroughIat`) earlier than
|
|
771
|
+
the signed `iat` of an entry or checkpoint it holds fails
|
|
772
|
+
`EXPORT_READ_TIME_INVALID`; an `exportDate` you give that is earlier throws a
|
|
773
|
+
`TypeError` naming the entry.
|
|
774
|
+
|
|
775
|
+
An export lists only the acknowledgements naming its chain. Give others as
|
|
776
|
+
`acknowledgements`: record exports (their
|
|
777
|
+
`checkpointEvidence.acknowledgedRewinds`), pages of a bulk walk under a
|
|
778
|
+
platform key (the RESTORE_EPOCH rows of its platform-ops chain), or
|
|
779
|
+
`acknowledgedRewinds` items. Each is verified from its own envelope, only its
|
|
780
|
+
signed `coveredFindings` are read, and `result.suppliedAcknowledgements`
|
|
781
|
+
reports each. A `GET /v1/admin/vault/rewind` response carries no signed entry
|
|
782
|
+
and throws a `TypeError` that says where to get one.
|
|
783
|
+
|
|
784
|
+
Where more than one failure applies, `brokenAt` names the first in this
|
|
785
|
+
order: an acknowledgement that does not verify
|
|
786
|
+
(`REWIND_ACKNOWLEDGEMENT_INVALID`), then a fork (`ANCHOR_FORK`), then a cut
|
|
787
|
+
or a rewrite. Two documents of one position over different tips are a fork
|
|
788
|
+
whichever of them the export agrees with, though either alone may read as a
|
|
789
|
+
rewrite.
|
|
790
|
+
|
|
791
|
+
An anchor whose signature this host refuses to compute (an Ed25519 key on a
|
|
792
|
+
FIPS-locked host) reads `not_comparable` with `reason: 'unsupported_algorithm'`
|
|
793
|
+
and `ifVerified` naming what it would show, and the result reads
|
|
794
|
+
`unverifiable`: such an anchor is evidence neither way. A cut shown by an
|
|
795
|
+
anchor this host verified still fails.
|
|
796
|
+
|
|
797
|
+
Each document's unsigned fields (`recordId`, `chainPosition`, `payloadHash`,
|
|
798
|
+
`signingKeyId`) that differ from its signed claim are listed in its
|
|
799
|
+
`unsignedDisagreements`. `result.anchors.embeddedCheckpoint` says whether a
|
|
800
|
+
supplied document holds the checkpoint the export embeds, beside
|
|
801
|
+
`checkpointEvidence.anchor.objectKey`, the Server's hint of where it lies. A
|
|
802
|
+
plain sync of the bucket copies the current version of each key; supply every
|
|
803
|
+
object version of a key to see a fork.
|
|
804
|
+
|
|
805
|
+
## Cross-record exports
|
|
806
|
+
|
|
807
|
+
`verifyAuditExport` reads one record's audit export
|
|
808
|
+
(`GET /v1/records/{id}/audit-export`). The two exports that span chains are
|
|
809
|
+
read by their own functions, and handing a page of either to
|
|
810
|
+
`verifyAuditExport` throws a `TypeError` naming the one to call.
|
|
811
|
+
`auditVaultExportKind(doc)` answers `'bulk'`, `'schema-chain'` or `null`.
|
|
812
|
+
|
|
813
|
+
Both are paged, and the unit they verify is the walk: the pages of one
|
|
814
|
+
query, the last with a null `nextCursor`. Give the pages as parsed JSON, as
|
|
815
|
+
the text of each page (JSON, or NDJSON with `?format=ndjson`), or as one
|
|
816
|
+
NDJSON text holding them all, in any order. Each page from Server 4.0.0
|
|
817
|
+
states the cursor it was requested with (`exportMetadata.cursor`: null on the
|
|
818
|
+
first page, and page N's `nextCursor` on page N+1), and the functions put
|
|
819
|
+
pages that all state it in walk order by it. Pages that state none (a Server
|
|
820
|
+
before 4.0.0) are put in walk order by what they hold (a bulk page by its
|
|
821
|
+
first entry's id, a schema-chain page by its first entry's position; a page
|
|
822
|
+
with no entry after the page whose `nextCursor` it carries). `walk.order`
|
|
823
|
+
gives the index of each page as given. The Server ends a page's last line
|
|
824
|
+
with no newline, so join page texts with one.
|
|
825
|
+
|
|
826
|
+
`walk.endsAtNullCursor` is true when the pages end at a null `nextCursor` and
|
|
827
|
+
hold together up to it: the first page was requested with no cursor, each
|
|
828
|
+
later page with the `nextCursor` of the page before it, no page overlaps
|
|
829
|
+
another, and no chain starts above position 1 on a walk with no `from` bound.
|
|
830
|
+
`walk.incomplete` names each reason it is false, and such a walk reads at
|
|
831
|
+
best `unanchored`. The cursors are unsigned, so they catch a lost or
|
|
832
|
+
misordered page file; a page removed with every cursor rewritten to hide it
|
|
833
|
+
is caught where something signed names what it held: a chain that starts
|
|
834
|
+
above position 1, a gap inside a chain, or a checkpoints listing or anchor
|
|
835
|
+
document of a chain the walk holds no entry of (`chainSet`, below). On pages
|
|
836
|
+
that state no cursor, only those show a missing page, and `walk.notes`
|
|
837
|
+
says so.
|
|
838
|
+
|
|
839
|
+
```ts
|
|
840
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
841
|
+
import { join } from 'node:path';
|
|
842
|
+
import { verifyBulkExport, verifySchemaChainExport } from '@agledger/verify-core';
|
|
843
|
+
|
|
844
|
+
// Each page saved as its own file (page-01.json, page-02.json, ... or .ndjson), named in walk order.
|
|
845
|
+
const walkIn = (dir: string) => readdirSync(dir).sort().map((f) => readFileSync(join(dir, f), 'utf8'));
|
|
846
|
+
const pin = 'sha256:15d63684b387235c47fe3a81e3004b928f4ea535236a2c1b47465ce5fdd7ce0e';
|
|
847
|
+
|
|
848
|
+
// Each page dates itself (exportMetadata.exportDate). For pages that carry none,
|
|
849
|
+
// add exportDate: '<when the last page was read>' to the options.
|
|
850
|
+
const bulk = verifyBulkExport(walkIn('bulk-walk'), { trustAnchors: [pin] });
|
|
851
|
+
console.log(bulk.verdict); // the worst chain's verdict, or null on a walk that holds no entry
|
|
852
|
+
console.log(bulk.walk); // { pages, entries, endsAtNullCursor, incomplete: [...reasons], notes, order }
|
|
853
|
+
console.log(bulk.chainSet); // { state: 'pages_only' | 'held_to_listing' | 'undecided', detail, missing, undecided, outside }
|
|
854
|
+
console.log(bulk.capped); // [{ reason, detail }]: why a verdict that would be trusted reads unanchored
|
|
855
|
+
console.log(bulk.readTime); // { exportDate, source, chains: [{ chainKey, exportDate, source }], undated, detail }
|
|
856
|
+
for (const chain of bulk.chains) {
|
|
857
|
+
// heldTo: the last position verified, held by the page content or a signed checkpoint
|
|
858
|
+
console.log(chain.chainKey, chain.extent, chain.heldTo.position, chain.heldTo.by, chain.result.verdict, chain.sliceReason ?? '');
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
const schema = verifySchemaChainExport(walkIn('schema-walk'), { trustAnchors: [pin] });
|
|
862
|
+
console.log(schema.orgId, schema.checkpointKey); // the org the entries sign (null: the Server-wide chain), and the chain id
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
`verifyBulkExport` groups the rows by `recordId`, puts each group in chain
|
|
866
|
+
order, and verifies it as `verifyAuditExport` verifies a record export of
|
|
867
|
+
those entries: keys and their trust walk, signatures, links, batch proofs,
|
|
868
|
+
the payload against the signed predicate (with `on_behalf_of` and
|
|
869
|
+
`traceparent`), and the signed record id. The key material of every page is
|
|
870
|
+
merged; a key, window, key statement, batch head or entry that differs
|
|
871
|
+
between pages fails `EXPORT_PAGE_CONFLICT`. Each chain's `result` is a full
|
|
872
|
+
`VerifyExportResult`.
|
|
873
|
+
|
|
874
|
+
A chain the walk holds from position 1, in a walk that ends at a null
|
|
875
|
+
`nextCursor`, is `whole` and gets that verdict. A chain is a `slice` when the
|
|
876
|
+
walk holds it from a later position (a `from` filter, or a page missing
|
|
877
|
+
before it), when the walk does not end at a null `nextCursor` (`walk.incomplete`
|
|
878
|
+
says why: a last page with a `nextCursor`, a held-back page, rows out of
|
|
879
|
+
entry-id order, pages that overlap or come from another query), or when the
|
|
880
|
+
query's `to` bound ends every chain at an
|
|
881
|
+
instant. The walk's cursors carry the bound; a walk of one page carries no
|
|
882
|
+
cursor, and its `bulkExport.queryHash` (the hash of the query's filter) is
|
|
883
|
+
matched against the filters the page makes possible. `query` reports the
|
|
884
|
+
filter the pages establish, and on a walk whose pages establish none every
|
|
885
|
+
chain is a slice. A slice's entries and the links between them are
|
|
886
|
+
verified, and its verdict reads at best `unanchored`. A missing position
|
|
887
|
+
inside a chain fails `CHAIN_POSITION_GAP`. A walk whose `endsAtNullCursor` is
|
|
888
|
+
false reads at best `unanchored` whatever holds its chains (`capped`, reason
|
|
889
|
+
`walk_not_read_to_end`).
|
|
890
|
+
|
|
891
|
+
A walk verifies each chain through the last position it holds of it, and
|
|
892
|
+
`chains[].heldTo` says what holds the chain there: `page_content`, or
|
|
893
|
+
`signed_checkpoint` when a signed checkpoint of that position is given.
|
|
894
|
+
Pass pages of `GET /v1/audit-vault/checkpoints` as `checkpoints`: each
|
|
895
|
+
checkpoint filed under a chain the walk holds is verified (its claim, key,
|
|
896
|
+
signature and key window) and held to the entry at its position, so a
|
|
897
|
+
disagreement fails `CHECKPOINT_HASH_MISMATCH`. One signed before the walk's
|
|
898
|
+
read time above the last entry of a chain whose tip the walk establishes
|
|
899
|
+
fails `CHECKPOINT_ROW_MISSING`. A slice from position 1 whose last position
|
|
900
|
+
a checkpoint signs is `whole` through that position. Each listed checkpoint
|
|
901
|
+
is reported in `chains[].heldTo.checkpoints` with its `outcome`: `agrees`,
|
|
902
|
+
`disagrees` (its envelope fails, or the walk's entries differ from it),
|
|
903
|
+
`unchecked` (signed under an algorithm this host cannot compute; the chain
|
|
904
|
+
reads `unverifiable`), `not_comparable` (a position the walk does not hold or
|
|
905
|
+
cannot judge) or `not_evidence` (unsigned, set aside by `distrustedKeys`, or
|
|
906
|
+
not a checkpoint row).
|
|
907
|
+
|
|
908
|
+
A listed checkpoint or anchor document of a chain the walk holds no entry of
|
|
909
|
+
is held to the walk's query, and `chainSet` reports it. A walk under a
|
|
910
|
+
platform key (its pages carry `bulkExports`, or it holds the platform-ops
|
|
911
|
+
chain) serves every record chain and the platform-ops chain; a walk under an
|
|
912
|
+
org admin key serves that org's record chains, which that org admin's listing
|
|
913
|
+
names; no walk serves a schema chain (`chainSet.outside`). A `recordId`
|
|
914
|
+
filter serves that chain alone. Under a `to` bound, a checkpoint signed more
|
|
915
|
+
than 300 seconds before it is inside the query. One inside the query whose
|
|
916
|
+
envelope verifies under a trusted key and that was signed before the read
|
|
917
|
+
time fails `CHECKPOINT_ROW_MISSING` (a listing row) or `ANCHOR_CHAIN_CUT`
|
|
918
|
+
(an anchor, unless an acknowledgement accounts for it), and `chainSet.missing`
|
|
919
|
+
names the chain. A checkpoint the pages cannot place inside or outside the
|
|
920
|
+
query (another org's chain may be in a platform listing beside an org admin's
|
|
921
|
+
walk, an anchor of a chain no org listing names, an `agentId` or `from`
|
|
922
|
+
filter on any chain, the platform-ops chain included, a query the pages do
|
|
923
|
+
not establish, a checkpoint this host could not
|
|
924
|
+
check) leaves `chainSet.state` `undecided` and the verdict at best
|
|
925
|
+
`unanchored` (`capped`, reason `chain_set_undecided`).
|
|
926
|
+
|
|
927
|
+
Anchor documents (`anchorDocuments`) are compared with the chain each
|
|
928
|
+
signs, as on a record export, judged through the walk's read time less one
|
|
929
|
+
second: the `exportDate` you give, else the latest page read time
|
|
930
|
+
(`readTime.exportDate`), which is unsigned; `anchors.judgedThroughSource`
|
|
931
|
+
says which. An anchor or listed checkpoint above the last entry the walk
|
|
932
|
+
holds of its chain, set aside on the pages' own read time or with no read
|
|
933
|
+
time, holds the verdict at best `unanchored` (`capped`, reason
|
|
934
|
+
`read_time_not_given`) until you give `exportDate`. A page whose
|
|
935
|
+
`exportDate` is earlier than the signed `iat` of an entry it holds fails
|
|
936
|
+
`EXPORT_READ_TIME_INVALID`, and an `exportDate` you give that is earlier than
|
|
937
|
+
an entry the pages hold throws a `TypeError` naming the entry. On a slice,
|
|
938
|
+
an anchor of a position outside the run the walk holds reads
|
|
939
|
+
`chain_held_in_part`; two anchors of one position over different tips fail
|
|
940
|
+
`ANCHOR_FORK` wherever they sit. The acknowledgements of lost history are
|
|
941
|
+
the RESTORE_EPOCH entries of the platform-ops chain, when the walk holds it
|
|
942
|
+
whole (a walk under a platform key), those a bulk page carries
|
|
943
|
+
(`exportMetadata.acknowledgedRewinds`, Server 4.0.0, served to every caller
|
|
944
|
+
for the chains on that page, so an org admin's walk carries its own), and
|
|
945
|
+
those you give as `acknowledgements` (as on a record export). Each is
|
|
946
|
+
counted once. A page's item is held to its envelope as a record export's
|
|
947
|
+
is: its unsigned `coveredRanges` must be its signed `coveredFindings` for the
|
|
948
|
+
chains that page holds, or it fails `REWIND_ACKNOWLEDGEMENT_INVALID` and
|
|
949
|
+
covers nothing.
|
|
950
|
+
`anchors` reports every document's verdict and where the acknowledgements
|
|
951
|
+
came from.
|
|
952
|
+
|
|
953
|
+
Each page states the instant the Server read it, `exportMetadata.exportDate`
|
|
954
|
+
(on NDJSON, the metadata line's `exportDate`), taken after its entries and
|
|
955
|
+
their batch proofs. A batched entry served with no inclusion proof is judged
|
|
956
|
+
against the read time of its own page: written within 300 seconds before it,
|
|
957
|
+
the entry is waiting for its batch head and reads `pending`; written
|
|
958
|
+
earlier, it fails `BATCH_UNATTESTED`. Pages from a Server before 4.0.0 state
|
|
959
|
+
no read time: for those, the `exportDate` option dates them. For batched
|
|
960
|
+
entries a page that states its own read time is read at it, and the option
|
|
961
|
+
dates only the pages that state none (`walk.notes` says when
|
|
962
|
+
every page stated its own). `readTime` reports the latest read time, where
|
|
963
|
+
the read times came from (`source`: `pages`, `option`, or `mixed` when pages
|
|
964
|
+
were dated from both), the same for each chain (`readTime.chains`), and in
|
|
965
|
+
`undated` each batched entry no read time dated, which fails
|
|
966
|
+
`BATCH_UNATTESTED`. `expectedEntryCount` holds one chain's length, so
|
|
967
|
+
`verifyBulkExport` refuses it.
|
|
968
|
+
|
|
969
|
+
`verifySchemaChainExport` verifies the schema-registry chain the same way,
|
|
970
|
+
filed under `checkpointKey` (the uuid derived from the org id). It also
|
|
971
|
+
holds each entry to being a schema-registry entry of that org: no record id,
|
|
972
|
+
a SCHEMA_REGISTERED, SCHEMA_IMPORTED or SCHEMA_DIGEST_MISMATCH entry type
|
|
973
|
+
whose outcome the entry signs, the schema-event predicate and its subject,
|
|
974
|
+
and the `org_id` it signs equal to `chainMetadata.orgId`. Each row's payload
|
|
975
|
+
is held to its signed statement: a payload key that is neither one the
|
|
976
|
+
statement carries (under the name the predicate reads) nor one the Server
|
|
977
|
+
writes unsigned on that entry type fails `CHAIN_PAYLOAD_BINDING_MISMATCH`.
|
|
978
|
+
The unsigned ones (`publisherId`, `compatibility`, `registeredBy`,
|
|
979
|
+
`importedBy`, and on a SCHEMA_DIGEST_MISMATCH entry `peerDigest`,
|
|
980
|
+
`localDigest`, `peerHubId`, `recordId` and `operation`) are listed in
|
|
981
|
+
`unsignedProjectionFields` as `payload.<key>`: nothing detects a change to
|
|
982
|
+
one. A stated
|
|
983
|
+
`checkpointKey` that is not the derived one fails the walk. A walk read from
|
|
984
|
+
position 1 to its end is held to the first page's `total`, `expectedEntries`
|
|
985
|
+
and `checkpointEvidence`, taken whole from that page. A walk that starts
|
|
986
|
+
above position 1 or stops early is a slice. Each page is read at its own
|
|
987
|
+
`exportDate`, as on a bulk walk; a page that states none, with no
|
|
988
|
+
`exportDate` option, is dated by the latest
|
|
989
|
+
`checkpointEvidence.evidenceReadAt` the pages state (`source:
|
|
990
|
+
'checkpoint_evidence'`). Anchor documents are judged through the `exportDate`
|
|
991
|
+
you give, else the block's `anchorsJudgedThroughIat` when the walk applies
|
|
992
|
+
the block, else the pages' read time, with the block's `acknowledgedRewinds`
|
|
993
|
+
and those you give.
|
|
994
|
+
|
|
995
|
+
The Server's own fields (`chainMetadata.hashChainValid` on a bulk page,
|
|
996
|
+
`chainIntegrity` and its reason on a schema page) are reported under
|
|
997
|
+
`serverStatement` and take no part in the verdict. A walk that holds no entry
|
|
998
|
+
has `verdict: null` and `empty: true`: nothing was verified.
|
|
999
|
+
|
|
464
1000
|
## Verifying on a FIPS-locked host
|
|
465
1001
|
|
|
466
1002
|
This package has no crypto of its own: it verifies through the host's Node
|
|
467
1003
|
runtime. An active OpenSSL FIPS provider carries no EdDSA, so **an Ed25519
|
|
468
|
-
chain cannot be verified on a FIPS-locked host**. ES256 chains can.
|
|
1004
|
+
chain cannot be verified on a FIPS-locked host**. ES256 and ES384 chains can.
|
|
1005
|
+
A refusal names the algorithm the host refused, and a cause only when one is
|
|
1006
|
+
known (an active FIPS provider for Ed25519 or ML-DSA, a Node.js older than
|
|
1007
|
+
24.6.0 for ML-DSA).
|
|
469
1008
|
|
|
470
1009
|
That is reported as `CHAIN_UNSUPPORTED_ALGORITHM`, never as a signature
|
|
471
1010
|
failure. The two are kept apart because "I could not check this" and "I
|
|
472
1011
|
checked this and it failed" lead to opposite conclusions, and only one of them
|
|
473
|
-
is grounds for a tamper investigation.
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
the
|
|
1012
|
+
is grounds for a tamper investigation.
|
|
1013
|
+
|
|
1014
|
+
When this host refused signature checks under an algorithm this build
|
|
1015
|
+
supports, the verifier runs the same input again with the same options, as
|
|
1016
|
+
though those checks had verified. If that run is valid, the `verdict` is
|
|
1017
|
+
`unverifiable`. Nothing else is assumed in that run: a key of a type this
|
|
1018
|
+
build cannot compute still cannot be computed, a signature that was checked
|
|
1019
|
+
and did not verify still fails, and hash, link and count checks run as they
|
|
1020
|
+
are, so any of those makes the verdict `failed`. `valid` stays false, because
|
|
1021
|
+
an unverified chain is not a verified one, and every failure is still listed
|
|
1022
|
+
in `entries`.
|
|
1023
|
+
|
|
1024
|
+
What that run assumes depends on the pin:
|
|
1025
|
+
|
|
1026
|
+
- **A trust anchor this host computes** (one of `trustAnchors` is the digest
|
|
1027
|
+
of a key in the export whose algorithm this host computes): under a pin
|
|
1028
|
+
this host can compute, a key is trusted only through signatures this host
|
|
1029
|
+
computed. The run assumes only the refused signatures over data (entries,
|
|
1030
|
+
batch heads, checkpoints, receipts, agent signatures, peer messages, history
|
|
1031
|
+
seals); nothing is assumed about a key statement's refused half. A
|
|
1032
|
+
succession with one half this host refused carries exactly the edge whose
|
|
1033
|
+
own half this host computed and found valid, and only out of a key already
|
|
1034
|
+
trusted at that point of the walk, once every check that needs no
|
|
1035
|
+
computation has passed (an all-zero or wrong-length refused half makes the
|
|
1036
|
+
statement invalid). So the pinned ES384 key reaches the Ed25519 key it took
|
|
1037
|
+
over from through its own half of their succession, while entries
|
|
1038
|
+
re-signed under a key of someone else's, with a forged succession whose
|
|
1039
|
+
Ed25519 endorsement this host cannot check, still read `failed`: the edge
|
|
1040
|
+
into that key is carried only by the refused half. A refused closure is
|
|
1041
|
+
never assumed, and an ML-DSA key is still reached only through an ML-DSA
|
|
1042
|
+
signature. `uncomputable.assumed` is `'data'`:
|
|
1043
|
+
nothing was found wrong, and only signatures over data were left unchecked.
|
|
1044
|
+
- **No such anchor** (no `trustAnchors`, or every one that names a key here
|
|
1045
|
+
is of an algorithm this host refused, such as the pre-move Ed25519 pin on a
|
|
1046
|
+
FIPS-locked host): this host cannot establish any key itself, so the run
|
|
1047
|
+
assumes the refused key statements too, and the verdict reads the same for
|
|
1048
|
+
an export and a forgery of it. `uncomputable.assumed` is
|
|
1049
|
+
`'data-and-key-statements'`, `uncomputable.anchorAlgorithms` names the
|
|
1050
|
+
algorithms of the pins given that name a key here, and the sentence says
|
|
1051
|
+
only what is true: no signature was verified under an established key,
|
|
1052
|
+
and the two ways out are to pin
|
|
1053
|
+
the Server's current key of an algorithm this host computes (confirm it
|
|
1054
|
+
with the Server's operator) or to verify on a host that computes the
|
|
1055
|
+
algorithm. A pin that names no key in the input is such a case too: it
|
|
1056
|
+
anchors nothing on any host, so where the input does not pass without it
|
|
1057
|
+
on this host but would with the refused checks verified, the verdict is
|
|
1058
|
+
`unverifiable` with `uncomputable.pinUnmet: true`, as the same input reads
|
|
1059
|
+
with no pin. (An input this host passes without the pin reads `unanchored`,
|
|
1060
|
+
as everywhere.)
|
|
1061
|
+
|
|
1062
|
+
A finding that follows from a refused check is listed too: pinned on an
|
|
1063
|
+
Ed25519 key on a FIPS-locked host, the key statements that key signed cannot
|
|
1064
|
+
be checked, so the walk does not reach the keys after it, and their closures
|
|
1065
|
+
and entries read `KEY_CLOSURE_INVALID` or `CHAIN_SIGNING_KEY_UNANCHORED`.
|
|
1066
|
+
`uncomputable.consequences` names those codes on an `unverifiable` result.
|
|
1067
|
+
|
|
1068
|
+
Checks that need no computation run before the host is asked whether it
|
|
1069
|
+
computes the algorithm, so they read the same on every host: a signature of
|
|
1070
|
+
the wrong length is `CHAIN_SIGNATURE_INVALID`, an all-zero signature is the
|
|
1071
|
+
unsigned sentinel, and a protected-header `alg` the key cannot produce is
|
|
1072
|
+
`CHAIN_ALG_MISMATCH`. They run on an entry whose key this host could not
|
|
1073
|
+
establish too, and so does the key's window: an entry written after its key
|
|
1074
|
+
retired reads `CHAIN_KEY_EXPIRED` whatever this host can compute. Where this
|
|
1075
|
+
run finds no failure but could-not-compute ones and the second run fails,
|
|
1076
|
+
`brokenAt` is the second run's first break, which the refused checks do not
|
|
1077
|
+
explain.
|
|
1078
|
+
|
|
1079
|
+
The verdict is reserved for a refusal the verifier establishes on this host
|
|
1080
|
+
itself: whether the host computes an algorithm is decided by this build's own
|
|
1081
|
+
known-answer test, which nothing in the export can change. So on a host that
|
|
1082
|
+
computes every algorithm this build supports, the second run never starts and
|
|
1083
|
+
no export reads `unverifiable`. A key of a type this build cannot compute (an
|
|
1084
|
+
unrecognized key type, or ES512 or ES256K) is something the export alone
|
|
1085
|
+
asserts, so a result whose checks under one fail reads `failed`, with the
|
|
1086
|
+
detail on each entry saying to upgrade the verifier.
|
|
1087
|
+
|
|
1088
|
+
`result.uncomputable` counts the signature checks that could not be computed
|
|
1089
|
+
(entries, batch heads, checkpoints, receipts, agent signatures, peer messages,
|
|
1090
|
+
and key statements) and names the algorithms behind them, each with its cause
|
|
1091
|
+
(`host`: this build supports it and the runtime refused it; `build`: this
|
|
1092
|
+
build cannot compute it), on any verdict. On a `failed` result, `brokenAt` is
|
|
1093
|
+
the first failure that is not one of these, and `uncomputableNote(result.uncomputable)`
|
|
1094
|
+
gives the line to show beside it. Where the verdict is `unverifiable`,
|
|
1095
|
+
`brokenAt` is the first check that could not be computed, and
|
|
1096
|
+
`unverifiableDetail(result.uncomputable)` gives the sentence to show:
|
|
1097
|
+
|
|
1098
|
+
```ts
|
|
1099
|
+
import { unverifiableDetail, verifyAuditExport } from '@agledger/verify-core';
|
|
1100
|
+
|
|
1101
|
+
const result = verifyAuditExport(exportDocument);
|
|
1102
|
+
if (result.verdict === 'unverifiable') {
|
|
1103
|
+
// "3 signature checks under Ed25519 could not be computed on this host. ..."
|
|
1104
|
+
console.warn(unverifiableDetail(result.uncomputable));
|
|
1105
|
+
}
|
|
1106
|
+
```
|
|
1107
|
+
|
|
1108
|
+
A Server that moved from Ed25519 to ES384 keeps its Ed25519 history, and a
|
|
1109
|
+
pin on the ES384 key reaches that history through the succession both keys
|
|
1110
|
+
signed. On a FIPS-locked host the Ed25519 half of it cannot be checked, so
|
|
1111
|
+
the Ed25519 key is `undecided` rather than anchored or unanchored, and its
|
|
1112
|
+
entries are `CHAIN_UNSUPPORTED_ALGORITHM`. Under the ES384 pin, alone or
|
|
1113
|
+
beside the Ed25519 pin, that history reads `unverifiable` with
|
|
1114
|
+
`uncomputable.assumed` `'data'`: the ES384 key's own half of the succession
|
|
1115
|
+
reaches the Ed25519 key, and only that key's entry signatures are assumed.
|
|
1116
|
+
Under the Ed25519 pin alone, the one an installer before the move printed,
|
|
1117
|
+
and unpinned, it reads `unverifiable` with every key statement assumed. A key
|
|
1118
|
+
reached only through another refused half (an earlier Ed25519 key, before
|
|
1119
|
+
the one the ES384 key succeeded) is not established on this host, and that
|
|
1120
|
+
history reads `failed`. On a host that computes
|
|
1121
|
+
Ed25519 the same export reads `trusted` under each of those pins.
|
|
1122
|
+
|
|
1123
|
+
To actually verify an Ed25519 chain, re-run on a host without the restriction;
|
|
1124
|
+
the export and keys are portable and the verification is entirely offline, so
|
|
1125
|
+
all it needs is a second host.
|
|
1126
|
+
|
|
1127
|
+
## Post-quantum signatures (ML-DSA)
|
|
1128
|
+
|
|
1129
|
+
A vault key can be an ML-DSA key (NIST FIPS 204): ML-DSA-44, -65 or -87,
|
|
1130
|
+
published as SPKI, with COSE `alg` -48, -49 or -50. ML-DSA is designed to
|
|
1131
|
+
resist forgery by a quantum computer; Ed25519, ES256 and ES384 are not.
|
|
1132
|
+
Signatures are pure ML-DSA with an empty context over the same
|
|
1133
|
+
`Sig_structure`, and the unsigned sentinel
|
|
1134
|
+
is all zeros at the parameter set's signature length (2420, 3309 or 4627
|
|
1135
|
+
bytes). A chain can mix Ed25519, ES256 or ES384 history with ML-DSA history;
|
|
1136
|
+
each entry verifies under its own key.
|
|
1137
|
+
|
|
1138
|
+
ML-DSA needs a Node.js build whose OpenSSL carries it, and a host whose
|
|
1139
|
+
active provider computes it. On a host that does not, an ML-DSA chain is
|
|
1140
|
+
`CHAIN_UNSUPPORTED_ALGORITHM`, never a signature failure: the detail says the
|
|
1141
|
+
active OpenSSL FIPS provider did not compute it when one is active, and to
|
|
1142
|
+
upgrade Node.js otherwise (Node.js computes ML-DSA from 24.6.0; a release that
|
|
1143
|
+
loads an ML-DSA key without reporting its type reads the same way). Its verdict follows the rule above, the same way an
|
|
1144
|
+
Ed25519 chain reads on a FIPS-locked host.
|
|
1145
|
+
|
|
1146
|
+
## ES384
|
|
1147
|
+
|
|
1148
|
+
A vault key can be an ECDSA P-384 key, the algorithm a Server on a FIPS host
|
|
1149
|
+
signs with. Its signatures carry COSE `alg` -35 and are ECDSA over SHA-384 as
|
|
1150
|
+
raw `r||s` (96 bytes). -35 is the only label taken for a P-384 key, on chain
|
|
1151
|
+
entries and on key statements. An entry written with no key carries the
|
|
1152
|
+
Server's default sentinel on every host, a FIPS one included: `alg` -50 and
|
|
1153
|
+
4627 zero bytes. It is read as unsigned by its null `signingKeyId`.
|
|
477
1154
|
|
|
478
1155
|
### Asking about an algorithm directly
|
|
479
1156
|
|
|
@@ -485,8 +1162,9 @@ so a consumer writing its own report can ask about either:
|
|
|
485
1162
|
import { algorithmByName, runtimeCanCompute, describeUnsupportedAlgorithm } from '@agledger/verify-core';
|
|
486
1163
|
|
|
487
1164
|
// runtimeCanCompute takes a KeyAlgorithm from this build's table, NOT a name
|
|
488
|
-
// string. Look one up with algorithmByName ('Ed25519', 'ES256', '
|
|
489
|
-
// 'ES512', 'ES256K'); it returns null for
|
|
1165
|
+
// string. Look one up with algorithmByName ('Ed25519', 'ES256', 'ML-DSA-44',
|
|
1166
|
+
// 'ML-DSA-65', 'ML-DSA-87', 'ES384', 'ES512', 'ES256K'); it returns null for
|
|
1167
|
+
// anything else.
|
|
490
1168
|
const ed25519 = algorithmByName('Ed25519');
|
|
491
1169
|
if (ed25519 && !runtimeCanCompute(ed25519)) {
|
|
492
1170
|
console.warn('This host cannot verify Ed25519 chains.');
|
|
@@ -498,6 +1176,10 @@ if (ed25519 && !runtimeCanCompute(ed25519)) {
|
|
|
498
1176
|
console.log(describeUnsupportedAlgorithm(spkiBase64));
|
|
499
1177
|
```
|
|
500
1178
|
|
|
1179
|
+
`uncomputableAlgorithm(spkiBase64)` gives the same answer as data: null when
|
|
1180
|
+
this build and this host can both compute the key, and otherwise its algorithm
|
|
1181
|
+
and whether the `host` or the `build` is the cause.
|
|
1182
|
+
|
|
501
1183
|
`algorithmByName` exists for the case `resolveKeyAlgorithm` cannot serve: a host
|
|
502
1184
|
that refuses to *load* a key of some algorithm produces no key object to
|
|
503
1185
|
resolve, which is exactly when the question matters most.
|
|
@@ -518,19 +1200,105 @@ Both are normalized at the boundary; anything else throws `TypeError`
|
|
|
518
1200
|
|
|
519
1201
|
## Org-read log
|
|
520
1202
|
|
|
521
|
-
|
|
522
|
-
the
|
|
1203
|
+
Every read an org admin makes of another party's record is a leaf of a
|
|
1204
|
+
per-org RFC 9162 Merkle tree, and the Server signs a tree head over it on a
|
|
1205
|
+
schedule. Three functions verify what the read-log API serves, offline:
|
|
1206
|
+
|
|
1207
|
+
| Function | Input | Establishes |
|
|
1208
|
+
|---|---|---|
|
|
1209
|
+
| `verifyOrgReadCheckpoint(checkpoint, options)` | one tree head (`GET /v1/audit/org-reads/checkpoints`, one item of `data`, or the co-sign response) | the tree size and root the Server signed for the org, at the time it signed them, under an anchored key in its window; a witness co-signature under `cosignerKeys` |
|
|
1210
|
+
| `verifyOrgReadProof(proof, checkpoint, leaf, options)` | the `.../checkpoints/{id}/proof?leaf=` response, its tree head, and the leaf | the tree head, then the audit path from the leaf hash at its index to the signed root |
|
|
1211
|
+
| `verifyOrgReadLog(entries, checkpoints, options)` | pages of `GET /v1/audit/org-reads` and of `.../checkpoints` | the leaves in order, recomputed into the signed root of every tree head they reach |
|
|
1212
|
+
|
|
1213
|
+
```ts
|
|
1214
|
+
import { readFileSync } from 'node:fs';
|
|
1215
|
+
import { verifyOrgReadCheckpoint, verifyOrgReadLog, verifyOrgReadProof } from '@agledger/verify-core';
|
|
1216
|
+
import type { OrgReadCheckpointInput, OrgReadCheckpointsPage, OrgReadEntriesPage, OrgReadEntryInput, OrgReadProofInput, VerifyOrgReadOptions } from '@agledger/verify-core';
|
|
1217
|
+
|
|
1218
|
+
const read = <T>(file: string): T => JSON.parse(readFileSync(file, 'utf8')) as T;
|
|
1219
|
+
const options: VerifyOrgReadOptions = {
|
|
1220
|
+
publicKeys: read('verification-keys.json'), // GET /v1/verification-keys, as served
|
|
1221
|
+
trustAnchors: ['sha256:15d63684b387235c47fe3a81e3004b928f4ea535236a2c1b47465ce5fdd7ce0e'],
|
|
1222
|
+
};
|
|
1223
|
+
|
|
1224
|
+
const checkpoint = read<OrgReadCheckpointInput>('checkpoint.json');
|
|
1225
|
+
const head = verifyOrgReadCheckpoint(checkpoint, options);
|
|
1226
|
+
console.log(head.verdict, head.checkpoint.treeSize, head.checkpoint.rootHash);
|
|
1227
|
+
|
|
1228
|
+
const proof = read<OrgReadProofInput>('proof.json');
|
|
1229
|
+
const entry = read<OrgReadEntryInput>('entry.json'); // one row of GET /v1/audit/org-reads
|
|
1230
|
+
console.log(verifyOrgReadProof(proof, checkpoint, entry, options).inclusion); // 'included' or 'failed'
|
|
1231
|
+
|
|
1232
|
+
const walk = verifyOrgReadLog(read<OrgReadEntriesPage>('org-reads.json'), read<OrgReadCheckpointsPage>('checkpoints.json'), options);
|
|
1233
|
+
console.log(walk.verdict, walk.heldTo); // { by: 'signed_checkpoint', treeSize, checkpointId, detail }
|
|
1234
|
+
```
|
|
1235
|
+
|
|
1236
|
+
Each result carries the house verdict (`trusted`, `unanchored`, `unverifiable`,
|
|
1237
|
+
`failed`), `brokenAt` and `findings` with a canonical code, `keyTrust`,
|
|
1238
|
+
`uncomputable`, and `runtime` below the Node.js floor, read as on
|
|
1239
|
+
`verifyAuditExport`.
|
|
1240
|
+
|
|
1241
|
+
What each input binds:
|
|
1242
|
+
|
|
1243
|
+
- **A tree head** is held to its own envelope. The claim signs the root as
|
|
1244
|
+
its subject digest and `chain_tip_hash`, the tree size as its position and
|
|
1245
|
+
`count`, `range` 0 to size minus 1, the org as `sub` (equal to `logId`), the
|
|
1246
|
+
key id as `kid`, and the time it was signed as `iat`. A served field that
|
|
1247
|
+
differs fails `TENANT_CHECKPOINT_CLAIM_MISMATCH`, and so does a
|
|
1248
|
+
`checkpointAt` more than 300 seconds before the signed `iat`: the database
|
|
1249
|
+
stamps that column when it writes the row, after the Server signed the
|
|
1250
|
+
claim at its own clock. The key's window is
|
|
1251
|
+
placed at `checkpointAt`. A tree head with no `signingKeyId` written after
|
|
1252
|
+
the earliest key activation fails `TENANT_CHECKPOINT_UNSIGNED`; one written
|
|
1253
|
+
before it is reported `unsigned` and anchors nothing.
|
|
1254
|
+
- **A leaf** is a row of the listing or a row of a dump's `org_admin_reads`.
|
|
1255
|
+
A listing row carries the leaf hash and no envelope, so its hash is placed
|
|
1256
|
+
in the tree and its other columns (record, reader, time, context) are bound
|
|
1257
|
+
to nothing signed: `leaf.fieldsBound` and `fieldsBound` say `false`. A dump
|
|
1258
|
+
row carries the envelope (`cose_sign1`): its leaf hash is recomputed from
|
|
1259
|
+
those bytes (`TENANT_READ_LEAF_HASH_MISMATCH` when it differs from the
|
|
1260
|
+
served `leaf_hash`), its signature is verified, and its columns are held to
|
|
1261
|
+
its claim (`TENANT_READ_CLAIM_MISMATCH`, `TENANT_READ_OIDC_MISMATCH`). Its
|
|
1262
|
+
`read_at` is stamped when the row is written, after the claim was signed
|
|
1263
|
+
(seconds after, on a large batch read), so it is held to be no more than 300
|
|
1264
|
+
seconds before the signed `iat`, as on a whole dump.
|
|
1265
|
+
- **A walk** recomputes the root of every tree head whose size the leaves
|
|
1266
|
+
reach, from index 0 (`TENANT_CHECKPOINT_ROOT_MISMATCH`). A tree head above
|
|
1267
|
+
the last leaf given, or every tree head when the leaves start above 0, is
|
|
1268
|
+
verified on its own and reported `leaves: 'not_comparable'`. `heldTo` names
|
|
1269
|
+
the largest tree head the leaves were recomputed into, and its `detail`
|
|
1270
|
+
names the leaves after it that only the listing holds. Two tree heads of one
|
|
1271
|
+
size with different roots fail `TENANT_CHECKPOINT_FORK`; two different rows
|
|
1272
|
+
at one index fail `EXPORT_PAGE_CONFLICT`; a missing index fails
|
|
1273
|
+
`TENANT_READ_LEAF_INDEX_GAP`.
|
|
1274
|
+
|
|
1275
|
+
A witness co-signature (`witnessKeyId`, `witnessSignature`) is stored by the
|
|
1276
|
+
Server as given and verified here over the tree head's envelope bytes (the
|
|
1277
|
+
decoded `coseSign1Base64`), under the key `cosignerKeys` gives for its
|
|
1278
|
+
`witnessKeyId`: `{ [witnessKeyId]: spkiBase64 }` or `[{ keyId, publicKey }]`.
|
|
1279
|
+
The signature is read as hex or base64; Ed25519, ECDSA (raw `r||s` or DER) and
|
|
1280
|
+
ML-DSA keys are taken. `checkpoint.cosignature.state` reads `verified`,
|
|
1281
|
+
`failed`, `no_key` (none given for its id), `not_checked` (this host cannot
|
|
1282
|
+
compute its algorithm) or `absent`. A failed one is
|
|
1283
|
+
`TENANT_CHECKPOINT_COSIGNATURE_INVALID`, and so is a missing or unverified one
|
|
1284
|
+
under `requireCosignature: true`.
|
|
1285
|
+
|
|
1286
|
+
The tree's hashes are lowercase hex, and the primitives are exported:
|
|
523
1287
|
|
|
524
1288
|
```ts
|
|
525
1289
|
import { orgReadLeafHash, orgReadMerkleRoot, verifyOrgReadInclusion } from '@agledger/verify-core';
|
|
526
1290
|
|
|
527
|
-
// leaf_hash = hex(sha256(0x00 || cose_sign1)); a
|
|
1291
|
+
// leaf_hash = hex(sha256(0x00 || cose_sign1)); a tree head's root is the RFC 9162 root over them.
|
|
528
1292
|
const leaf = orgReadLeafHash(Buffer.from('cose-sign1-bytes'));
|
|
529
1293
|
const root = orgReadMerkleRoot([leaf]);
|
|
530
|
-
//
|
|
1294
|
+
// A one-leaf tree has an empty path.
|
|
531
1295
|
console.log(root === leaf, verifyOrgReadInclusion(leaf, 0, 1, [], root!)); // true true
|
|
532
1296
|
```
|
|
533
1297
|
|
|
1298
|
+
`orgReadDocumentKind(value)` names which of these documents a parsed JSON
|
|
1299
|
+
value is: `org-read-checkpoint`, `org-read-checkpoints`, `org-read-proof`,
|
|
1300
|
+
`org-read-entries`, `org-read-entry`, or `null`.
|
|
1301
|
+
|
|
534
1302
|
## Canonical failure taxonomy
|
|
535
1303
|
|
|
536
1304
|
Every failure is a canonical SCREAMING_SNAKE `FailureCode`. Importing the
|