@agledger/verify-core 2.1.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.
Files changed (54) hide show
  1. package/LICENSE +18 -18
  2. package/README.md +869 -53
  3. package/dist/acknowledgements.d.ts +32 -0
  4. package/dist/acknowledgements.js +88 -0
  5. package/dist/anchors.d.ts +349 -0
  6. package/dist/anchors.js +654 -0
  7. package/dist/attestation.d.ts +98 -0
  8. package/dist/attestation.js +145 -0
  9. package/dist/audit-export.d.ts +404 -29
  10. package/dist/audit-export.js +547 -28
  11. package/dist/batch-head.d.ts +28 -0
  12. package/dist/batch-head.js +169 -0
  13. package/dist/batch.d.ts +69 -0
  14. package/dist/batch.js +99 -0
  15. package/dist/bulk-export.d.ts +161 -0
  16. package/dist/bulk-export.js +711 -0
  17. package/dist/cbor-strict.d.ts +9 -0
  18. package/dist/cbor-strict.js +14 -0
  19. package/dist/chain.d.ts +221 -31
  20. package/dist/chain.js +339 -65
  21. package/dist/claim.d.ts +23 -0
  22. package/dist/claim.js +100 -0
  23. package/dist/export-anchors.d.ts +84 -0
  24. package/dist/export-anchors.js +109 -0
  25. package/dist/export-evidence.d.ts +90 -0
  26. package/dist/export-evidence.js +186 -0
  27. package/dist/export-pages.d.ts +476 -0
  28. package/dist/export-pages.js +586 -0
  29. package/dist/failures.d.ts +44 -26
  30. package/dist/failures.js +81 -31
  31. package/dist/federation-wire.d.ts +106 -20
  32. package/dist/federation-wire.js +286 -76
  33. package/dist/history-seal.d.ts +100 -0
  34. package/dist/history-seal.js +301 -0
  35. package/dist/index.d.ts +37 -9
  36. package/dist/index.js +18 -5
  37. package/dist/instant.d.ts +1 -1
  38. package/dist/instant.js +1 -1
  39. package/dist/key-statements.d.ts +160 -11
  40. package/dist/key-statements.js +261 -60
  41. package/dist/ml-dsa-kats.d.ts +18 -0
  42. package/dist/ml-dsa-kats.js +241 -0
  43. package/dist/options.js +4 -4
  44. package/dist/primitives.d.ts +287 -47
  45. package/dist/primitives.js +673 -101
  46. package/dist/read-log.d.ts +350 -0
  47. package/dist/read-log.js +816 -0
  48. package/dist/schema-chain-export.d.ts +82 -0
  49. package/dist/schema-chain-export.js +474 -0
  50. package/dist/walk-anchors.d.ts +115 -0
  51. package/dist/walk-anchors.js +133 -0
  52. package/dist/walk-checkpoints.d.ts +125 -0
  53. package/dist/walk-checkpoints.js +118 -0
  54. package/package.json +9 -5
@@ -1,8 +1,16 @@
1
+ import { type Uncomputable } from './primitives.js';
1
2
  import type { KeyRegistry } from './chain.js';
2
3
  /** Content type of a key statement's COSE_Sign1 (protected header label 3). */
3
4
  export declare const KEY_STATEMENT_CTY = "application/vnd.agledger.key-statement+cbor";
4
5
  export declare const KEY_STATEMENT_KINDS: readonly ['succession', 'closure', 'genesis'];
5
6
  export type KeyStatementKind = (typeof KEY_STATEMENT_KINDS)[number];
7
+ /**
8
+ * The COSE `alg` a statement signature must carry for its key's algorithm.
9
+ * Exactly one per algorithm, as the Server signs and checks them; the chain
10
+ * envelope's wider acceptance (RFC 9864 fully-specified code points) does not
11
+ * apply to statements.
12
+ */
13
+ export declare const STATEMENT_COSE_ALG: Readonly<Record<string, number>>;
6
14
  /**
7
15
  * One key statement as a source carries it. A dump row maps onto it with
8
16
  * {@link keyStatementFromDumpRow}; a key document's `statements` with
@@ -13,7 +21,7 @@ export interface KeyStatementInput {
13
21
  /**
14
22
  * Row id (the dump's or a key document's `id`), named in findings. Under the
15
23
  * write order it breaks a tie between two statements whose `createdAt` are
16
- * the same microsecond, as the engine's `created_at, id` does.
24
+ * the same microsecond, as the Server's `created_at, id` does.
17
25
  */
18
26
  id?: string | null;
19
27
  /** The source's own `kind` column, bound to the signed `typ`. */
@@ -30,7 +38,7 @@ export interface KeyStatementInput {
30
38
  * Where the statement was read from. `dump`: a row of a dump's
31
39
  * `vault_key_statements.ndjson` ({@link keyStatementFromDumpRow} sets it),
32
40
  * whose `created_at` the walk holds a distrusted key's statements to, as the
33
- * engine does. Anything else, absent included, is a key document's (an
41
+ * Server does. Anything else, absent included, is a key document's (an
34
42
  * export's or a supplied `/v1/verification-keys` entry's): its `createdAt`
35
43
  * orders it but never keeps an edge out of a distrusted key.
36
44
  */
@@ -120,7 +128,7 @@ export interface KeyRegistryFinding {
120
128
  * Something the walk did that is not a finding and does not fail a verdict:
121
129
  * a statement from a key document signed by a distrusted key that admits
122
130
  * nothing here, because the document's write time is the holder's word and is
123
- * never held against the key's cutoff, though the engine, holding it to the
131
+ * never held against the key's cutoff, though the Server, holding it to the
124
132
  * time it was stored, counts it. It still dates windows and cuts edges back.
125
133
  * Also a listed key whose `distrustedFrom` differs from the instant the
126
134
  * caller's `distrustedKeys` entry gives it, where no finding on its window
@@ -171,8 +179,12 @@ export interface KeyTrust {
171
179
  /** SPKI digests of the undecided keys. */
172
180
  undecided: ReadonlySet<string>;
173
181
  findings: KeyRegistryFinding[];
182
+ /** Each key's counting closures signed by a trusted key, by the key's SPKI digest. */
183
+ closures: ReadonlyMap<string, readonly CountedClosure[]>;
174
184
  /** Non-fatal: see {@link KeyTrustNote}. */
175
185
  notes: KeyTrustNote[];
186
+ /** ML-DSA keys (`sha256:<hex>`) a trusted classical key handed over to, which the walk did not follow from it. */
187
+ successorPins: string[];
176
188
  /**
177
189
  * Non-fatal: statements of a dump that a `distrustedKeys` key signed, that
178
190
  * count for nothing, and that were stored before a key the walk trusts
@@ -199,8 +211,23 @@ export interface KeyTrust {
199
211
  unverifiable: number;
200
212
  };
201
213
  }
214
+ /** A closure the walk counts, signed by a key it trusts: what a history seal is bound to. */
215
+ export interface CountedClosure {
216
+ /** SHA-256 (lowercase hex) of the closure's signed payload bytes. */
217
+ digest: string;
218
+ /** The key that signed it. */
219
+ endorserKeyId: string;
220
+ /** The retirement it signs for its subject. */
221
+ retiredAt: string;
222
+ /** The history seal it names, when it names one. */
223
+ history: {
224
+ seal: string;
225
+ root: string;
226
+ treeSize: number;
227
+ } | null;
228
+ }
202
229
  /**
203
- * What a `distrustedKeys` entry covers for one key, as the engine's
230
+ * What a `distrustedKeys` entry covers for one key, as the Server's
204
231
  * `distrustSpans` gives it. `cutoff`: the instant from which what the key
205
232
  * signs counts for nothing (the entry's own, else `retiredAt`; null: trusted
206
233
  * for nothing). `retiredAt`: the earliest retirement of the key that a key
@@ -238,10 +265,25 @@ export declare function parseDistrustedKeys(raw: string | readonly string[]): Di
238
265
  * (`sha256:<hex>@<instant>`) is how a leaked key whose history is still
239
266
  * needed is kept from signing anything new: the pin vouches for what it
240
267
  * stored before the instant. `computeKeyTrust` itself walks any pair as the
241
- * engine's walk does; a verifier calls this on what its caller passed before
268
+ * Server's walk does; a verifier calls this on what its caller passed before
242
269
  * it walks.
243
270
  */
244
271
  export declare function assertNotPinnedAndDistrusted(trustAnchors: string | readonly string[] | undefined, distrustedKeys: ReadonlyArray<string | DistrustedKey> | undefined): void;
272
+ /** A decoded statement-style COSE_Sign1: protected header `{1: alg, 3: cty, 4: kid}`. Internal. */
273
+ export interface Sign1 {
274
+ protectedBstr: Uint8Array;
275
+ payloadBstr: Uint8Array;
276
+ signature: Uint8Array;
277
+ alg: number | null;
278
+ cty: unknown;
279
+ kid: string | null;
280
+ }
281
+ /** Internal: not re-exported from the package. */
282
+ export declare function decodeSign1(raw: unknown): Sign1 | null;
283
+ /** Internal: not re-exported from the package. */
284
+ export declare function sigStructure(protectedBstr: Uint8Array, payloadBstr: Uint8Array): Uint8Array;
285
+ /** Whether a key (base64 SPKI DER) is an ML-DSA key. */
286
+ export declare function isPostQuantumKey(spkiBase64: string): boolean;
245
287
  /**
246
288
  * Walk the key statements from `trustAnchors` and decide which keys are
247
289
  * trusted and what window each carries. Two passes, no fixpoint:
@@ -346,7 +388,7 @@ export declare function keyStatementsFromVerificationKeys(doc: VerificationKeysD
346
388
  /**
347
389
  * Mark every key of a registry with the walk's verdict, and give each anchored
348
390
  * key the window its statements sign in place of whatever window it carried,
349
- * as the engine grades entries. An anchored key no statement dates carries no
391
+ * as the Server grades entries. An anchored key no statement dates carries no
350
392
  * edge on that side. A key is anchored only when its key id is the
351
393
  * fingerprint of its own SPKI: a row filed under another key's id names that
352
394
  * key's entries, and is anchored to nothing. On a walk over a dump, a key a
@@ -376,14 +418,113 @@ export type KeyTrustStatus = 'walked' | 'no_anchor' | 'no_anchored_signature';
376
418
  * The one-word reading of a verification result, as every surface prints it:
377
419
  * `failed` when it is not valid, `trusted` when it is valid and the walk
378
420
  * anchored a signature (`keyTrust.status: 'walked'`), and `unanchored` when it
379
- * is valid but rests on nothing pinned. Read this rather than `valid` alone: a
380
- * valid result with no `trustAnchors` is `unanchored`.
421
+ * is valid but rests on nothing pinned, or when the only thing that failed is
422
+ * that nothing is signed by a key the pinned trustAnchors anchor (see
423
+ * {@link verdictOf}). `unverifiable` when it is not valid and would be valid
424
+ * if the signature checks this host refused, under algorithms this build
425
+ * supports, had verified: nothing was found wrong, and the signatures this
426
+ * host refused were not verified
427
+ * (see {@link isUnverifiable}). Read this rather than `valid`
428
+ * alone: a valid result with no `trustAnchors` is `unanchored`.
429
+ */
430
+ export type Verdict = 'trusted' | 'unanchored' | 'unverifiable' | 'failed';
431
+ /**
432
+ * Whether a result is `unverifiable`: it is not valid, at least one signature
433
+ * check could not be computed (`uncomputable.count`), this host refused an
434
+ * algorithm this build supports (an `uncomputable.algorithms` entry with cause
435
+ * `host`), and the same input with the same options would be valid if the
436
+ * checks this host refused had verified (`passesIfComputed`, a rerun inside
437
+ * `verifyAsIfHostComputed`, called only when the rest holds).
438
+ *
439
+ * Nothing else is assumed in that rerun: a check under a key of a type this
440
+ * build cannot compute still fails, a signature that was checked and did not
441
+ * verify still fails, and hash, link and count checks run as they are. So a
442
+ * finding that follows only from a refused check (a key closure the refused
443
+ * key signed, an entry under a key the walk could not reach past it) leaves
444
+ * the result `unverifiable`, and any other failure makes it `failed`.
445
+ *
446
+ * The verdict is reserved for a refusal the verifier establishes on this host
447
+ * itself: cause `host` rests on this build's own known-answer test of the
448
+ * algorithm (`runtimeCanCompute`), which nothing in an artifact can change.
449
+ * On a host that computes every algorithm this build supports there is no such
450
+ * cause, the rerun never runs, and no artifact reads `unverifiable`.
451
+ */
452
+ export declare function isUnverifiable(result: {
453
+ valid: boolean;
454
+ uncomputable: Pick<Uncomputable, 'count' | 'algorithms'>;
455
+ passesIfComputed: () => boolean;
456
+ }): boolean;
457
+ /**
458
+ * The {@link Verdict} of a result, with the could-not-compute rule first:
459
+ * `unverifiable` when {@link isUnverifiable} holds, and otherwise whatever
460
+ * `otherwise` gives (`sealedVerdict(verdictOf(...))`, which is called only
461
+ * then, so its reruns cost nothing on an unverifiable result). So a real
462
+ * failure anywhere is `failed`, a result that would be valid had this host
463
+ * computed the algorithms it refused is `unverifiable`, and the `unanchored`
464
+ * readings of a pin that was not met or that predates the move to ML-DSA
465
+ * apply only to a result that is not. `valid` is unchanged: an unverifiable
466
+ * result is not valid.
467
+ */
468
+ export declare function unverifiableVerdict(result: {
469
+ valid: boolean;
470
+ uncomputable: Pick<Uncomputable, 'count' | 'algorithms'>;
471
+ passesIfComputed: () => boolean;
472
+ }, otherwise: () => Verdict): Verdict;
473
+ /**
474
+ * The {@link Verdict} of a result that carries `valid` and a `keyTrust` report.
475
+ *
476
+ * Pass `passesUnpinned` on a run that supplied trustAnchors: it reruns the
477
+ * same input with the same options minus `trustAnchors` and `distrustedKeys`
478
+ * and says whether that run is valid. A pinned run that failed, whose walk
479
+ * anchored no key at all, and whose unpinned rerun passes, is `unanchored`
480
+ * rather than `failed`: the only thing wrong is that the pin reaches nothing
481
+ * in the artifact (the key-statement findings and CHAIN_SIGNING_KEY_UNANCHORED
482
+ * entries such a walk reports all follow from that). That is an export checked
483
+ * against another Server's pin, and equally one re-signed wholesale under keys
484
+ * of its own; neither is trusted, and the result keeps `valid: false`. An
485
+ * artifact in which the pin anchors even one key stays `failed`, since an
486
+ * entry beside it under an unanchored key is a substitution.
487
+ *
488
+ * Pass `passesPinnedOn` as well: it reruns the same input with `trustAnchors`
489
+ * replaced by the list it is given and says whether that run is valid. A
490
+ * pinned run that failed, whose pin is a classical key that handed over to an
491
+ * ML-DSA key (`keyTrust.successorPins`), and whose rerun with those keys
492
+ * pinned beside it passes, is `unanchored` too: the pin predates the move to
493
+ * ML-DSA, and the only thing wrong is that a classical pin does not reach the
494
+ * keys after it. The pinned key itself signed the handover, so this is not a
495
+ * key from elsewhere; it is still not a trusted verdict, since nothing
496
+ * post-quantum links the pin to them. The result keeps `valid: false`.
497
+ *
498
+ * This never returns `unverifiable`: wrap it in {@link unverifiableVerdict},
499
+ * which takes precedence over both `unanchored` readings of a failed run.
381
500
  */
382
- export type Verdict = 'trusted' | 'unanchored' | 'failed';
383
- /** The {@link Verdict} of a result that carries `valid` and a `keyTrust` report. */
384
501
  export declare function verdictOf(result: {
385
502
  valid: boolean;
386
- keyTrust: Pick<KeyTrustReport, 'status'>;
503
+ keyTrust: Pick<KeyTrustReport, 'status' | 'anchoredKeyIds'> & Partial<Pick<KeyTrustReport, 'anchors' | 'successorPins'>>;
504
+ }, passesUnpinned?: () => boolean, passesPinnedOn?: (trustAnchors: string[]) => boolean): Verdict;
505
+ /** Whether a pinned walk anchored no key at all: the pin names nothing this input holds or links to. */
506
+ export declare function pinReachesNoKey(keyTrust: Pick<KeyTrustReport, 'status' | 'anchoredKeyIds'>): boolean;
507
+ /**
508
+ * Whether a failed pinned run failed only because its pin predates the move to
509
+ * ML-DSA: the walk names successor keys, and the same input passes with them
510
+ * pinned beside the anchors given.
511
+ */
512
+ export declare function pinPredatesSuccessors(keyTrust: Partial<Pick<KeyTrustReport, 'anchors' | 'successorPins'>>, passesPinnedOn?: (trustAnchors: string[]) => boolean): boolean;
513
+ /**
514
+ * What to tell the holder of a pin that predates the move to ML-DSA (a result
515
+ * whose verdict is `unanchored`, `valid` false and `keyTrust.successorPins`
516
+ * not empty): what happened, that it is not evidence of tampering, and which
517
+ * key to confirm and pin.
518
+ */
519
+ export declare function pinPredatesDetail(successorPins: readonly string[]): string;
520
+ /**
521
+ * A verdict, given how the entries classical keys signed stand against the
522
+ * history seals: `trusted` becomes `unanchored` when any such entry is
523
+ * unsealed, since it then rests on a classical signature no ML-DSA key vouches
524
+ * for. Every other verdict is unchanged.
525
+ */
526
+ export declare function sealedVerdict(verdict: Verdict, historySeal: {
527
+ unsealed: number;
387
528
  }): Verdict;
388
529
  /** What a verification result says about key anchoring. */
389
530
  export interface KeyTrustReport {
@@ -404,6 +545,14 @@ export interface KeyTrustReport {
404
545
  findings: KeyRegistryFinding[];
405
546
  /** Non-fatal notes from the walk (see {@link KeyTrustNote}); they never fail a verdict. */
406
547
  notes: KeyTrustNote[];
548
+ /**
549
+ * The ML-DSA keys (`sha256:<hex>`) an anchored classical key handed over to
550
+ * in a succession the walk verified on the classical side and did not
551
+ * follow, since a classical signature admits no ML-DSA key. Not empty means
552
+ * the pin predates the move to ML-DSA: the keys after it, and what they
553
+ * signed, are unanchored from that pin alone (see {@link verdictOf}).
554
+ */
555
+ successorPins: string[];
407
556
  /**
408
557
  * Non-fatal: the statements of a dump a `distrustedKeys` key signed that its
409
558
  * entry and a trusted key's retirement of it account for (see