@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.
Files changed (49) hide show
  1. package/LICENSE +18 -18
  2. package/README.md +797 -29
  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 +343 -20
  10. package/dist/audit-export.js +400 -22
  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/chain.d.ts +135 -13
  18. package/dist/chain.js +229 -24
  19. package/dist/claim.d.ts +23 -0
  20. package/dist/claim.js +100 -0
  21. package/dist/export-anchors.d.ts +84 -0
  22. package/dist/export-anchors.js +109 -0
  23. package/dist/export-evidence.d.ts +90 -0
  24. package/dist/export-evidence.js +186 -0
  25. package/dist/export-pages.d.ts +476 -0
  26. package/dist/export-pages.js +586 -0
  27. package/dist/failures.d.ts +20 -16
  28. package/dist/failures.js +44 -16
  29. package/dist/federation-wire.d.ts +78 -11
  30. package/dist/federation-wire.js +199 -57
  31. package/dist/history-seal.d.ts +100 -0
  32. package/dist/history-seal.js +301 -0
  33. package/dist/index.d.ts +36 -8
  34. package/dist/index.js +17 -4
  35. package/dist/key-statements.d.ts +138 -5
  36. package/dist/key-statements.js +191 -20
  37. package/dist/ml-dsa-kats.d.ts +18 -0
  38. package/dist/ml-dsa-kats.js +241 -0
  39. package/dist/primitives.d.ts +255 -18
  40. package/dist/primitives.js +612 -55
  41. package/dist/read-log.d.ts +350 -0
  42. package/dist/read-log.js +816 -0
  43. package/dist/schema-chain-export.d.ts +82 -0
  44. package/dist/schema-chain-export.js +474 -0
  45. package/dist/walk-anchors.d.ts +115 -0
  46. package/dist/walk-anchors.js +133 -0
  47. package/dist/walk-checkpoints.d.ts +125 -0
  48. package/dist/walk-checkpoints.js +118 -0
  49. package/package.json +6 -5
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Anchor documents and listed checkpoints held to a page walk: the inputs
3
+ * sorted by the chain they sign, the judged-through time a walk's read time
4
+ * gives, the acknowledgements of lost history a walk's platform-ops chain
5
+ * holds, and the walk-wide anchor report.
6
+ *
7
+ * Each chain the walk holds is compared with its own documents as a record
8
+ * export's chain is (`compareCheckpointAnchors`), with three differences a
9
+ * walk brings. Its read time is the latest page's (each page's own
10
+ * `exportMetadata.exportDate`, or for pages that state none the caller's
11
+ * `exportDate`; an anchor signed after it less one second is not judged),
12
+ * or, with none, the rule a dump follows: an anchor at or below the last
13
+ * entry held is judged and one above it is not. A chain the walk holds in
14
+ * part is judged only at the positions it holds. And the acknowledgements
15
+ * come from the walk's own platform-ops chain, when the walk holds it whole.
16
+ */
17
+ import type { CheckApplicability } from './chain.js';
18
+ import { type AnchorDocumentInput, type AnchorVerdict, type RewindAcknowledgement } from './anchors.js';
19
+ import type { VerifyExportResult } from './audit-export.js';
20
+ import type { ExportPageRow } from './export-pages.js';
21
+ import type { VaultCheckpointRow } from './walk-checkpoints.js';
22
+ /** Where a walk's acknowledgements of lost history came from. */
23
+ export interface WalkAcknowledgements {
24
+ /**
25
+ * `platform-ops-chain`: the RESTORE_EPOCH entries of the platform-ops
26
+ * chain the walk holds whole (a walk under a platform key), each verified
27
+ * with its link. `checkpoint-evidence`: the schema chain's
28
+ * `checkpointEvidence.acknowledgedRewinds`. `given`: only those the
29
+ * caller gave (`acknowledgements`), each verified from its own envelope.
30
+ * `pages`: those a bulk walk's pages carry (`exportMetadata.acknowledgedRewinds`,
31
+ * Server 4.0.0), with any given, each verified from its own envelope.
32
+ * The first two add those carried or given to their own. `none`: no acknowledgement is
33
+ * in reach, so none accounts for a disagreement.
34
+ */
35
+ source: 'platform-ops-chain' | 'checkpoint-evidence' | 'pages' | 'given' | 'none';
36
+ detail: string;
37
+ items: Array<{
38
+ entryId: string | null;
39
+ chainPosition: number;
40
+ state: RewindAcknowledgement['state'];
41
+ iat: number;
42
+ }>;
43
+ }
44
+ /** The anchor documents against the chains of a walk. */
45
+ export interface WalkAnchorsReport {
46
+ /** `skipped_no_input` with no documents, `applied` once one was compared, `not_checked` when none could be. */
47
+ applicability: CheckApplicability;
48
+ /**
49
+ * The latest signed iat judged on a chain read by the walk's read time
50
+ * (`readTime.exportDate` less one second), or null when no page was dated.
51
+ * A schema chain whose checkpoint block was applied is judged by the
52
+ * block's own `anchorsJudgedThroughIat`, which its
53
+ * `anchors.judgedThroughIat` reports.
54
+ */
55
+ judgedThroughIat: number | null;
56
+ /**
57
+ * Where `judgedThroughIat` came from: `pages`, a page's own
58
+ * `exportMetadata.exportDate`; `exportDate`, the caller's option;
59
+ * `checkpointEvidence`, the schema chain's checkpoint block (its
60
+ * `anchorsJudgedThroughIat`, or its `evidenceReadAt` on pages that state no
61
+ * read time).
62
+ */
63
+ judgedThroughSource: 'pages' | 'exportDate' | 'checkpointEvidence' | null;
64
+ acknowledgements: WalkAcknowledgements;
65
+ /** Every document's verdict, with the chain it was compared with (null for one no chain could be read from). */
66
+ verdicts: Array<AnchorVerdict & {
67
+ chainKey: string | null;
68
+ }>;
69
+ counts: {
70
+ agree: number;
71
+ disagree: number;
72
+ accounted: number;
73
+ notComparable: number;
74
+ };
75
+ }
76
+ /** The latest signed iat judged against a walk read at `exportDate`: its whole second less one, or null. */
77
+ export declare function judgedThroughOf(exportDate: string | null | undefined): number | null;
78
+ /** The `judgedThroughSource` a page read-time source gives. */
79
+ export declare function judgedThroughSourceOf(source: 'pages' | 'option' | 'checkpoint_evidence' | null): WalkAnchorsReport['judgedThroughSource'];
80
+ /** Throw `TypeError` on an `anchorDocuments` option that is not `{ source, document, objectKey? }[]`. */
81
+ export declare function assertWalkAnchorDocuments(fn: string, value: unknown): void;
82
+ /** The documents by the chain key their checkpoint signs, and the verdicts on those that name none. */
83
+ export declare function groupAnchorDocuments(documents: readonly AnchorDocumentInput[] | undefined): {
84
+ byChain: Map<string, AnchorDocumentInput[]>;
85
+ unreadable: AnchorVerdict[];
86
+ };
87
+ /**
88
+ * Throw `TypeError` on a `checkpoints` option that is not an array of
89
+ * `GET /v1/audit-vault/checkpoints` pages; return their rows by the chain
90
+ * they are filed under, each named by page and row.
91
+ */
92
+ export declare function readCheckpointPages(fn: string, value: unknown): Map<string, Array<{
93
+ row: VaultCheckpointRow;
94
+ source: string;
95
+ }>> | null;
96
+ /**
97
+ * The acknowledgements a platform-ops chain the walk holds whole carries: each
98
+ * RESTORE_EPOCH entry that verified with its link (`verified`), or whose
99
+ * signature this host refused (`uncomputable`).
100
+ */
101
+ export declare function platformOpsAcknowledgements(rows: readonly ExportPageRow[], result: VerifyExportResult): RewindAcknowledgement[];
102
+ /** The verdict on a document of a chain the walk does not hold. */
103
+ export declare function chainNotHeldVerdict(chainKey: string, d: AnchorDocumentInput, what: string): AnchorVerdict & {
104
+ chainKey: string;
105
+ };
106
+ /** Put the walk's anchor report together from each chain's comparison and the documents no chain took. */
107
+ export declare function walkAnchorsReport(input: {
108
+ given: boolean;
109
+ judgedThroughIat: number | null;
110
+ judgedThroughSource: WalkAnchorsReport['judgedThroughSource'];
111
+ acknowledgements: WalkAcknowledgements;
112
+ verdicts: Array<AnchorVerdict & {
113
+ chainKey: string | null;
114
+ }>;
115
+ }): WalkAnchorsReport;
@@ -0,0 +1,133 @@
1
+ import { anchorDocumentChainKey, rewindAcknowledgementOf, unreadableAnchorVerdict, } from './anchors.js';
2
+ import { rfc3339Ms } from './instant.js';
3
+ /** The latest signed iat judged against a walk read at `exportDate`: its whole second less one, or null. */
4
+ export function judgedThroughOf(exportDate) {
5
+ if (typeof exportDate !== 'string')
6
+ return null;
7
+ const ms = rfc3339Ms(exportDate);
8
+ return Number.isNaN(ms) ? null : Math.floor(ms / 1000) - 1;
9
+ }
10
+ /** The `judgedThroughSource` a page read-time source gives. */
11
+ export function judgedThroughSourceOf(source) {
12
+ return source === 'pages' ? 'pages' : source === 'option' ? 'exportDate' : source === 'checkpoint_evidence' ? 'checkpointEvidence' : null;
13
+ }
14
+ /** Throw `TypeError` on an `anchorDocuments` option that is not `{ source, document, objectKey? }[]`. */
15
+ export function assertWalkAnchorDocuments(fn, value) {
16
+ if (value === undefined)
17
+ return;
18
+ if (!Array.isArray(value))
19
+ throw new TypeError(`${fn}: anchorDocuments must be an array of { source, document, objectKey? }.`);
20
+ value.forEach((d, i) => {
21
+ const r = d;
22
+ if (r === null || typeof r !== 'object' || typeof r['source'] !== 'string' || !('document' in r) || (r['objectKey'] !== undefined && typeof r['objectKey'] !== 'string')) {
23
+ throw new TypeError(`${fn}: anchorDocuments[${i}] is not { source: string, document: <parsed JSON>, objectKey?: string }.`);
24
+ }
25
+ });
26
+ }
27
+ /** The documents by the chain key their checkpoint signs, and the verdicts on those that name none. */
28
+ export function groupAnchorDocuments(documents) {
29
+ const byChain = new Map();
30
+ const unreadable = [];
31
+ for (const d of documents ?? []) {
32
+ const chainKey = anchorDocumentChainKey(d);
33
+ if (chainKey === null) {
34
+ const v = unreadableAnchorVerdict(d);
35
+ if (v !== null)
36
+ unreadable.push(v);
37
+ continue;
38
+ }
39
+ const list = byChain.get(chainKey) ?? [];
40
+ list.push(d);
41
+ byChain.set(chainKey, list);
42
+ }
43
+ return { byChain, unreadable };
44
+ }
45
+ /**
46
+ * Throw `TypeError` on a `checkpoints` option that is not an array of
47
+ * `GET /v1/audit-vault/checkpoints` pages; return their rows by the chain
48
+ * they are filed under, each named by page and row.
49
+ */
50
+ export function readCheckpointPages(fn, value) {
51
+ if (value === undefined)
52
+ return null;
53
+ if (!Array.isArray(value))
54
+ throw new TypeError(`${fn}: checkpoints must be an array of GET /v1/audit-vault/checkpoints pages ({ data: [...] }).`);
55
+ const out = new Map();
56
+ value.forEach((page, i) => {
57
+ const p = page;
58
+ if (p === null || typeof p !== 'object' || !Array.isArray(p.data)) {
59
+ throw new TypeError(`${fn}: checkpoints[${i}] is not a GET /v1/audit-vault/checkpoints page ({ data: [...] }).`);
60
+ }
61
+ p.data.forEach((row, j) => {
62
+ if (row === null || typeof row !== 'object')
63
+ throw new TypeError(`${fn}: checkpoints[${i}].data[${j}] is not an object.`);
64
+ const key = typeof row.recordId === 'string' ? row.recordId.toLowerCase() : '';
65
+ const list = out.get(key) ?? [];
66
+ list.push({ row, source: `checkpoints[${i}].data[${j}]${typeof row.id === 'string' ? ` (${row.id})` : ''}` });
67
+ out.set(key, list);
68
+ });
69
+ });
70
+ return out;
71
+ }
72
+ /**
73
+ * The acknowledgements a platform-ops chain the walk holds whole carries: each
74
+ * RESTORE_EPOCH entry that verified with its link (`verified`), or whose
75
+ * signature this host refused (`uncomputable`).
76
+ */
77
+ export function platformOpsAcknowledgements(rows, result) {
78
+ const outcome = new Map(result.entries.map((r) => [r.position, r]));
79
+ const out = [];
80
+ for (const row of rows) {
81
+ if (row.entryType !== 'RESTORE_EPOCH' || row.signingKeyId == null || typeof row.coseSign1 !== 'string' || !Number.isSafeInteger(row.chainPosition))
82
+ continue;
83
+ const r = outcome.get(row.chainPosition);
84
+ if (r === undefined)
85
+ continue;
86
+ const state = r.valid && r.signature === 'ok' ? 'verified' : r.code === 'CHAIN_UNSUPPORTED_ALGORITHM' ? 'uncomputable' : null;
87
+ if (state === null)
88
+ continue;
89
+ const ack = rewindAcknowledgementOf(Buffer.from(row.coseSign1, 'base64'), typeof row.id === 'string' ? row.id : null, state, true);
90
+ if (ack !== null)
91
+ out.push(ack);
92
+ }
93
+ return out;
94
+ }
95
+ /** The verdict on a document of a chain the walk does not hold. */
96
+ export function chainNotHeldVerdict(chainKey, d, what) {
97
+ return {
98
+ chainKey,
99
+ kind: 'not_comparable',
100
+ reason: 'chain_not_held',
101
+ source: d.source,
102
+ ...(d.objectKey !== undefined ? { objectKey: d.objectKey } : {}),
103
+ position: null,
104
+ iat: null,
105
+ keyId: null,
106
+ unsignedDisagreements: [],
107
+ detail: `${d.source}: a checkpoint of chain ${chainKey}, which this walk does not hold. ${what}`,
108
+ };
109
+ }
110
+ /** Put the walk's anchor report together from each chain's comparison and the documents no chain took. */
111
+ export function walkAnchorsReport(input) {
112
+ const counts = { agree: 0, disagree: 0, accounted: 0, notComparable: 0 };
113
+ for (const v of input.verdicts) {
114
+ if (v.kind === 'agree')
115
+ counts.agree++;
116
+ else if (v.kind === 'disagree')
117
+ counts.disagree++;
118
+ else if (v.kind === 'accounted')
119
+ counts.accounted++;
120
+ else
121
+ counts.notComparable++;
122
+ }
123
+ const applied = counts.agree + counts.disagree + counts.accounted > 0
124
+ || input.verdicts.some((v) => v.kind === 'not_comparable' && v.reason === 'unsupported_algorithm');
125
+ return {
126
+ applicability: !input.given ? 'skipped_no_input' : applied ? 'applied' : 'not_checked',
127
+ judgedThroughIat: input.judgedThroughIat,
128
+ judgedThroughSource: input.judgedThroughSource,
129
+ acknowledgements: input.acknowledgements,
130
+ verdicts: input.verdicts,
131
+ counts,
132
+ };
133
+ }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * The signed checkpoints `GET /v1/audit-vault/checkpoints` lists, held to the
3
+ * chains a page walk holds.
4
+ *
5
+ * A page walk carries no checkpoint, so the last position it holds of a
6
+ * chain is held there by the page content alone. Each listed checkpoint is a
7
+ * Server-signed vault checkpoint over one chain: its signed claim names the
8
+ * chain (by subject), a position, the count and range 1 to that position,
9
+ * and the payloadHash of the entry there. A listed checkpoint whose envelope
10
+ * verifies, at a position the walk holds with that payloadHash, holds the
11
+ * chain to that position: entries 1 through it are the chain's, linked to
12
+ * the signed tip. One at the last position the walk holds holds the chain's
13
+ * end there.
14
+ */
15
+ import type { KeyRegistry } from './chain.js';
16
+ import type { FailureCode } from './failures.js';
17
+ /** One row of `GET /v1/audit-vault/checkpoints` (`data[]`). */
18
+ export interface VaultCheckpointRow {
19
+ id?: string;
20
+ /** The chain the checkpoint is filed under: a record id, a schema chain's checkpoint key, or the platform-ops key. */
21
+ recordId?: string;
22
+ /** `record`, `schema` or `admin` (the platform-ops chain). Unsigned; the signed subject names the chain. */
23
+ chain?: string;
24
+ chainPosition?: number;
25
+ /** Hex sha256: the payloadHash of the entry at `chainPosition`, which the envelope signs as `chain_tip_hash`. */
26
+ payloadHash?: string;
27
+ /** Base64 COSE_Sign1 over the vault-checkpoint in-toto Statement. */
28
+ coseSign1?: string;
29
+ signingKeyId?: string | null;
30
+ createdAt?: string;
31
+ }
32
+ /** One page of `GET /v1/audit-vault/checkpoints`. */
33
+ export interface VaultCheckpointsPage {
34
+ data: VaultCheckpointRow[];
35
+ /** The sweep's cadence and last run. Unsigned; not read. */
36
+ checkpointing?: Record<string, unknown>;
37
+ total?: number;
38
+ hasMore?: boolean;
39
+ nextCursor?: string | null;
40
+ }
41
+ /** What one listed checkpoint showed against the chain the walk holds. */
42
+ export interface ListedCheckpointOutcome {
43
+ id: string | null;
44
+ position: number | null;
45
+ /** Where it was read: the input's index and the row's, or the name the caller gave. */
46
+ source: string;
47
+ /**
48
+ * `agrees`: its envelope verifies and the entry the walk holds at its
49
+ * position has the payloadHash it signs. `disagrees`: a failure on the
50
+ * chain (its envelope fails, or the walk's entries disagree with it).
51
+ * `unchecked`: its signature is under an algorithm this host cannot
52
+ * compute, so it neither agrees nor disagrees (the chain reads
53
+ * `unverifiable`). `not_comparable`: it verifies and signs a position
54
+ * outside what the walk holds or can judge. `not_evidence`: unsigned,
55
+ * signed by a key a distrusted-key entry sets aside, or not a checkpoint
56
+ * row.
57
+ */
58
+ outcome: 'agrees' | 'disagrees' | 'unchecked' | 'not_comparable' | 'not_evidence';
59
+ detail: string;
60
+ }
61
+ /** How far a chain the walk holds is held, and by what. */
62
+ export interface ChainHeldTo {
63
+ /** The last position the walk holds of the chain. */
64
+ position: number;
65
+ /**
66
+ * `signed_checkpoint`: a listed checkpoint that verifies signs the entry
67
+ * at that position. `page_content`: the pages alone hold it there.
68
+ */
69
+ by: 'page_content' | 'signed_checkpoint';
70
+ /** The highest listed checkpoint that agrees with the walk, or null with none. */
71
+ checkpoint: {
72
+ id: string | null;
73
+ position: number;
74
+ source: string;
75
+ } | null;
76
+ /** Every listed checkpoint filed under the chain, in the order given. */
77
+ checkpoints: ListedCheckpointOutcome[];
78
+ detail: string;
79
+ }
80
+ /** The run of the chain the walk holds, and what is known of its end. */
81
+ export interface ListedCheckpointView {
82
+ firstHeld: number;
83
+ lastHeld: number;
84
+ /** The walk establishes the chain's tip (a walk read to its end, with no `to` bound). */
85
+ tipEstablished: boolean;
86
+ /** The latest signed iat judged (the walk's read time less one second), or null. */
87
+ judgedThroughIat: number | null;
88
+ /**
89
+ * Whether `judgedThroughIat` comes from a read time the caller gave. A
90
+ * checkpoint above the last position held that is set aside on the pages'
91
+ * own unsigned read time, or on none, holds the verdict at best
92
+ * `unanchored` (`capped`).
93
+ */
94
+ readTimeGiven?: boolean;
95
+ }
96
+ export interface ListedCheckpointFinding {
97
+ position: number;
98
+ code: FailureCode;
99
+ detail: string;
100
+ }
101
+ /**
102
+ * Hold the listed checkpoints filed under one chain to the entries the walk
103
+ * holds of it. Each is verified as the checkpoint a record export embeds is
104
+ * (its claim against its row, unsigned-after-signing, its key and the trust
105
+ * walk, its signature, the key window at its signed iat), then compared with
106
+ * the entry at its position.
107
+ */
108
+ export declare function judgeListedCheckpoints(chainKey: string, listed: ReadonlyArray<{
109
+ row: VaultCheckpointRow;
110
+ source: string;
111
+ }>, entries: ReadonlyArray<{
112
+ chainPosition: number;
113
+ payloadHash: unknown;
114
+ }>, keys: KeyRegistry, signingSince: string | null, view: ListedCheckpointView): {
115
+ heldTo: ChainHeldTo;
116
+ findings: ListedCheckpointFinding[];
117
+ capped: string[];
118
+ };
119
+ /** The sha256 of each listed envelope, for the anchor comparison's `same_bytes`. */
120
+ export declare function listedEnvelopeShas(listed: ReadonlyArray<{
121
+ row: VaultCheckpointRow;
122
+ }>): Array<{
123
+ chainPosition: number;
124
+ coseSign1Sha256: string;
125
+ }>;
@@ -0,0 +1,118 @@
1
+ import { decodeSignedClaim } from './claim.js';
2
+ import { verifyExportCheckpoint } from './export-evidence.js';
3
+ import { entryRun, sha256Hex } from './primitives.js';
4
+ const HEX64 = /^[0-9a-f]{64}$/;
5
+ /**
6
+ * Hold the listed checkpoints filed under one chain to the entries the walk
7
+ * holds of it. Each is verified as the checkpoint a record export embeds is
8
+ * (its claim against its row, unsigned-after-signing, its key and the trust
9
+ * walk, its signature, the key window at its signed iat), then compared with
10
+ * the entry at its position.
11
+ */
12
+ export function judgeListedCheckpoints(chainKey, listed, entries, keys, signingSince, view) {
13
+ const findings = [];
14
+ const capped = [];
15
+ const outcomes = [];
16
+ const byPosition = new Map(entries.map((e) => [e.chainPosition, e.payloadHash]));
17
+ let best = null;
18
+ for (const { row, source } of listed) {
19
+ const id = typeof row.id === 'string' ? row.id : null;
20
+ const P = Number.isSafeInteger(row.chainPosition) && row.chainPosition >= 1 ? row.chainPosition : null;
21
+ const out = (outcome, detail) => {
22
+ outcomes.push({ id, position: P, source, outcome, detail: `${source}: ${detail}` });
23
+ };
24
+ const tip = typeof row.payloadHash === 'string' ? row.payloadHash.toLowerCase() : '';
25
+ if (P === null || !HEX64.test(tip) || typeof row.coseSign1 !== 'string') {
26
+ out('not_evidence', 'not a checkpoint row { id, recordId, chainPosition, payloadHash, coseSign1, signingKeyId, createdAt }.');
27
+ continue;
28
+ }
29
+ const cp = {
30
+ ...(id !== null ? { id } : {}),
31
+ chainPosition: P,
32
+ chainTipHash: `sha256:${tip}`,
33
+ signingKeyId: row.signingKeyId ?? null,
34
+ createdAt: typeof row.createdAt === 'string' ? row.createdAt : '',
35
+ coseSign1: row.coseSign1,
36
+ };
37
+ // The envelope on its own: the entry it is checked against is the one it names.
38
+ const envelope = verifyExportCheckpoint(chainKey, { checkpoint: cp }, [{ chainPosition: P, payloadHash: tip }], keys, signingSince);
39
+ if (envelope.finding !== undefined) {
40
+ findings.push({ position: P, code: envelope.finding.code, detail: `Listed checkpoint ${source}: ${envelope.finding.detail}` });
41
+ out(envelope.finding.code === 'CHAIN_UNSUPPORTED_ALGORITHM' ? 'unchecked' : 'disagrees', envelope.finding.detail);
42
+ continue;
43
+ }
44
+ if (envelope.report.state === 'unsigned') {
45
+ out('not_evidence', `the checkpoint at position ${P} is unsigned (written before signing began), which anyone who can read the chain tip can make.`);
46
+ continue;
47
+ }
48
+ if (envelope.report.state !== 'verified') {
49
+ out('not_evidence', `the checkpoint at position ${P} is signed by a key distrustedKeys sets aside at its write time, so it counts for nothing.`);
50
+ continue;
51
+ }
52
+ if (P < view.firstHeld) {
53
+ out('not_comparable', `the checkpoint signs position ${P}, below position ${view.firstHeld}, the first the walk holds of this chain.`);
54
+ continue;
55
+ }
56
+ if (P <= view.lastHeld) {
57
+ const held = byPosition.get(P);
58
+ if (held === undefined) {
59
+ const detail = `the checkpoint signs position ${P} and the walk holds no entry there.`;
60
+ findings.push({ position: P, code: 'CHECKPOINT_ROW_MISSING', detail: `Listed checkpoint ${source}: ${detail}` });
61
+ out('disagrees', detail);
62
+ }
63
+ else if (held !== tip) {
64
+ const detail = `the checkpoint signs tip sha256:${tip} at position ${P}, and the entry the walk holds there has payloadHash ${JSON.stringify(held)}: the chain was written again at or below position ${P}.`;
65
+ findings.push({ position: P, code: 'CHECKPOINT_HASH_MISMATCH', detail: `Listed checkpoint ${source}: ${detail}` });
66
+ out('disagrees', detail);
67
+ }
68
+ else {
69
+ out('agrees', `the checkpoint signs position ${P} with the payloadHash of the entry the walk holds there.`);
70
+ if (best === null || P > best.position)
71
+ best = { id, position: P, source };
72
+ }
73
+ continue;
74
+ }
75
+ // Above the last position held.
76
+ const iat = decodeSignedClaim(Buffer.from(row.coseSign1, 'base64'))?.iat ?? null;
77
+ if (!view.tipEstablished) {
78
+ out('not_comparable', `the checkpoint signs position ${P}, above position ${view.lastHeld}, the last the walk holds of this chain; the walk holds the chain in part, so entries above it are not in the walk.`);
79
+ }
80
+ else if (view.judgedThroughIat === null) {
81
+ out('not_comparable', `the checkpoint signs position ${P}, above position ${view.lastHeld}, the last the walk holds, and no read time is known, so entries written after the walk cannot be told from a cut, and the verdict reads at best not anchored. Give the time the last page was read as exportDate to judge it.`);
82
+ capped.push(`Listed checkpoint ${source} signs position ${P}, above position ${view.lastHeld}, the last the walk holds of chain ${chainKey}, and no read time is known. Give the time the last page was read as exportDate to judge it.`);
83
+ }
84
+ else if (iat === null || iat > view.judgedThroughIat) {
85
+ if (view.readTimeGiven === true) {
86
+ out('not_comparable', `the checkpoint signs position ${P} at iat ${String(iat)}, after ${view.judgedThroughIat}, the latest iat judged against the walk; it may cover entries written since.`);
87
+ }
88
+ else {
89
+ out('not_comparable', `the checkpoint signs position ${P}, above position ${view.lastHeld}, the last the walk holds, at iat ${String(iat)}, after ${view.judgedThroughIat}, the latest iat judged against the read time the pages state, which is unsigned: it is either entries written after the walk or a cut, and the verdict reads at best not anchored. Give the time the last page was read as exportDate to judge it.`);
90
+ capped.push(`Listed checkpoint ${source} signs position ${P}, above position ${view.lastHeld}, the last the walk holds of chain ${chainKey}, after the read time the pages state, which is unsigned. Give the time the last page was read as exportDate to judge it.`);
91
+ }
92
+ }
93
+ else {
94
+ const detail = `the checkpoint signs position ${P} at iat ${iat}, before the walk was read, and the last entry the walk holds is at ${view.lastHeld}: ${entryRun(view.lastHeld + 1, P, 'were')} cut.`;
95
+ findings.push({ position: view.lastHeld + 1, code: 'CHECKPOINT_ROW_MISSING', detail: `Listed checkpoint ${source}: ${detail}` });
96
+ out('disagrees', detail);
97
+ }
98
+ }
99
+ const atTip = best !== null && best.position === view.lastHeld;
100
+ const heldTo = {
101
+ position: view.lastHeld,
102
+ by: atTip ? 'signed_checkpoint' : 'page_content',
103
+ checkpoint: best,
104
+ checkpoints: outcomes,
105
+ detail: atTip
106
+ ? `Held to position ${view.lastHeld} by signed checkpoint ${best?.source ?? ''}${view.firstHeld === 1 ? `: the chain is whole through position ${view.lastHeld}` : ''}.`
107
+ : best !== null
108
+ ? `Held to position ${best.position} by signed checkpoint ${best.source}, and from there to position ${view.lastHeld} by the page content.`
109
+ : `Held to position ${view.lastHeld} by the page content.`,
110
+ };
111
+ return { heldTo, findings, capped };
112
+ }
113
+ /** The sha256 of each listed envelope, for the anchor comparison's `same_bytes`. */
114
+ export function listedEnvelopeShas(listed) {
115
+ return listed.flatMap(({ row }) => (typeof row.coseSign1 === 'string' && Number.isSafeInteger(row.chainPosition)
116
+ ? [{ chainPosition: row.chainPosition, coseSign1Sha256: sha256Hex(Buffer.from(row.coseSign1, 'base64')) }]
117
+ : []));
118
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@agledger/verify-core",
3
- "version": "2.2.0",
4
- "description": "Shared offline verification core for AGLedger audit chains: COSE_Sign1 (RFC 9052), Ed25519 and ES256, hash-chain walk, key-statement trust walk, RFC 9162 Merkle proofs, canonical failure taxonomy. One dependency (cborg); no network. Patent pending.",
3
+ "version": "4.0.0",
4
+ "description": "Shared offline verification core for AGLedger audit chains: COSE_Sign1 (RFC 9052), Ed25519, ES256, ES384 and ML-DSA, hash-chain walk, key-statement trust walk, RFC 9162 Merkle proofs, canonical failure taxonomy. One dependency (cborg); no network. Patent pending.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
7
7
  "engines": {
8
- "node": ">=24.0.0"
8
+ "node": ">=24.6.0"
9
9
  },
10
10
  "main": "./dist/index.js",
11
11
  "types": "./dist/index.d.ts",
@@ -39,9 +39,10 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@arethetypeswrong/cli": "^0.18.3",
42
+ "@cyclonedx/cyclonedx-npm": "7.0.1",
42
43
  "@types/node": "^24.13.3",
43
- "oxlint": "1.94.0",
44
- "oxlint-tsgolint": "7.0.2008",
44
+ "oxlint": "1.96.0",
45
+ "oxlint-tsgolint": "7.0.2009",
45
46
  "publint": "^0.3.22",
46
47
  "typescript": "^7.0.2",
47
48
  "vitest": "^5.0.0"