@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/dist/audit-export.js
CHANGED
|
@@ -20,16 +20,70 @@
|
|
|
20
20
|
* result so a caller never mistakes "not checked here" for "checked and passed".
|
|
21
21
|
*/
|
|
22
22
|
import { buildAgentKeyRegistry, buildKeyRegistry, earliestKeyActivation, verifyChain, } from './chain.js';
|
|
23
|
-
import { instantMs } from './instant.js';
|
|
23
|
+
import { instantMs, rfc3339Ms } from './instant.js';
|
|
24
|
+
import { BATCH_PENDING_GRACE_SECONDS } from './batch.js';
|
|
25
|
+
import { buildBatchHeadRegistry } from './batch-head.js';
|
|
26
|
+
import { planHistorySeals } from './history-seal.js';
|
|
24
27
|
import { assertKnownOptions } from './options.js';
|
|
25
|
-
import {
|
|
28
|
+
import { verifyRewindAcknowledgements } from './anchors.js';
|
|
29
|
+
import { readAcknowledgementSources } from './acknowledgements.js';
|
|
30
|
+
import { decodeSignedClaim } from './claim.js';
|
|
31
|
+
import { readComplianceRecords, verifyAttestations } from './attestation.js';
|
|
32
|
+
import { verifyCheckpointCoverage, verifyExportAnchors } from './export-anchors.js';
|
|
33
|
+
import { judgeListedCheckpoints } from './walk-checkpoints.js';
|
|
34
|
+
import { decodeCoseSign1, decodePredicate, anchorAlgorithms, hasComputableAnchor, isVerifyingAsIfHostComputed, runtimeBelowFloor, uncomputableAlgorithms, verifyAsIfHostComputed } from './primitives.js';
|
|
26
35
|
import { buildFederationKeyRegistry } from './federation-wire.js';
|
|
27
|
-
import {
|
|
36
|
+
import { verifyExportCheckpoint, verifyExportReceipts, } from './export-evidence.js';
|
|
37
|
+
import { applyKeyTrust, assertNotPinnedAndDistrusted, computeKeyTrust, keyStatementsFromExport, statementsFromMap, reportKeyTrust, settleKeyTrust, sealedVerdict, unverifiableVerdict, pinReachesNoKey, verdictOf, } from './key-statements.js';
|
|
38
|
+
/** One entry of a `/audit-export` document. */
|
|
39
|
+
/** 0000-01-01T00:00:00Z, the earliest instant an RFC 3339 string can spell. */
|
|
40
|
+
const YEAR_ZERO_MS = -62_167_219_200_000;
|
|
41
|
+
/** A verdict held at best `unanchored` when any cap applies. */
|
|
42
|
+
export function capVerdict(verdict, caps) {
|
|
43
|
+
return verdict === 'trusted' && caps.length > 0 ? 'unanchored' : verdict;
|
|
44
|
+
}
|
|
28
45
|
const SUPPORTED_FORMAT_VERSION = '2.0';
|
|
29
46
|
const SUPPORTED_CANONICALIZATION = 'RFC8949-CDE';
|
|
30
47
|
function isRecord(value) {
|
|
31
48
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
32
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Which of the Server's cross-record exports a document is, or null: a page
|
|
52
|
+
* of `GET /v1/audit-vault/export` (`'bulk'`) or of
|
|
53
|
+
* `GET /v1/audit-vault/schema-chain/export` (`'schema-chain'`). Both carry
|
|
54
|
+
* their entries in `data` beside `chainMetadata`, where a record's audit
|
|
55
|
+
* export carries `entries`. `verifyAuditExport` reads a record's audit export
|
|
56
|
+
* and names the function that reads these: `verifyBulkExport` and
|
|
57
|
+
* `verifySchemaChainExport`. An NDJSON page parsed line by line is read by
|
|
58
|
+
* those functions as text.
|
|
59
|
+
*/
|
|
60
|
+
export function auditVaultExportKind(value) {
|
|
61
|
+
if (!isRecord(value) || !Array.isArray(value.data) || !isRecord(value.chainMetadata) || 'entries' in value)
|
|
62
|
+
return null;
|
|
63
|
+
return 'chain' in value.chainMetadata || 'checkpointKey' in value.chainMetadata ? 'schema-chain' : 'bulk';
|
|
64
|
+
}
|
|
65
|
+
/** What reads a cross-record export page in place of `verifyAuditExport`. */
|
|
66
|
+
export const NOT_A_RECORD_EXPORT = {
|
|
67
|
+
bulk: 'This is a page of GET /v1/audit-vault/export, the export across records, not one record\'s audit export, and verifyAuditExport reached no verdict on it. Verify the walk, every page from the first to the one whose nextCursor is null, with verifyBulkExport (agledger-verify reads the page files or their directory).',
|
|
68
|
+
'schema-chain': 'This is a page of GET /v1/audit-vault/schema-chain/export, a schema-registry chain, not a record\'s audit export, and verifyAuditExport reached no verdict on it. Verify the walk, every page from the first to the one whose nextCursor is null, with verifySchemaChainExport (agledger-verify reads the page files or their directory).',
|
|
69
|
+
};
|
|
70
|
+
const READINGS = new WeakMap();
|
|
71
|
+
/**
|
|
72
|
+
* The instant from which a batched entry with no proof, read at `readAt`, is
|
|
73
|
+
* still waiting for its head: `readAt` less `BATCH_PENDING_GRACE_SECONDS`.
|
|
74
|
+
* Null when `readAt` is not an RFC 3339 instant, or when the grace would carry
|
|
75
|
+
* it before year 0000.
|
|
76
|
+
*/
|
|
77
|
+
function batchPendingSinceOf(readAt) {
|
|
78
|
+
const cutAt = typeof readAt === 'string' ? rfc3339Ms(readAt) : NaN;
|
|
79
|
+
const graceStart = cutAt - BATCH_PENDING_GRACE_SECONDS * 1000;
|
|
80
|
+
return Number.isNaN(cutAt) || graceStart < YEAR_ZERO_MS ? null : new Date(graceStart).toISOString();
|
|
81
|
+
}
|
|
82
|
+
/** `verifyAuditExport` on a document built for one chain of a cross-record export. Internal to this package. */
|
|
83
|
+
export function verifyExportChain(exportData, options, reading) {
|
|
84
|
+
READINGS.set(exportData, reading);
|
|
85
|
+
return verifyAuditExport(exportData, options);
|
|
86
|
+
}
|
|
33
87
|
/**
|
|
34
88
|
* Verify one record's `/audit-export` document offline.
|
|
35
89
|
*
|
|
@@ -46,6 +100,15 @@ export function verifyAuditExport(exportData, given = {}) {
|
|
|
46
100
|
|| (exportData.entries !== undefined && exportData.entries !== null && !Array.isArray(exportData.entries))) {
|
|
47
101
|
throw new TypeError('Expected an /audit-export document: { exportMetadata: { recordId, ... }, entries: [...] }.');
|
|
48
102
|
}
|
|
103
|
+
const anchorDocuments = readAnchorDocumentsOption(options.anchorDocuments);
|
|
104
|
+
if (options.exportDate !== undefined && (typeof options.exportDate !== 'string' || Number.isNaN(rfc3339Ms(options.exportDate)))) {
|
|
105
|
+
throw new TypeError(`verifyAuditExport: exportDate must be an RFC 3339 instant such as 2026-12-04T10:00:00Z (got ${JSON.stringify(options.exportDate)}).`);
|
|
106
|
+
}
|
|
107
|
+
const suppliedSources = readAcknowledgementSources('verifyAuditExport', options.acknowledgements);
|
|
108
|
+
const complianceRecords = options.complianceRecords !== undefined ? readComplianceRecords(options.complianceRecords) : undefined;
|
|
109
|
+
const otherExport = auditVaultExportKind(exportData);
|
|
110
|
+
if (otherExport !== null)
|
|
111
|
+
throw new TypeError(NOT_A_RECORD_EXPORT[otherExport]);
|
|
49
112
|
if ((options.trustAnchors === undefined || options.trustAnchors.length === 0)
|
|
50
113
|
&& options.distrustedKeys !== undefined && options.distrustedKeys.length > 0) {
|
|
51
114
|
throw new TypeError('distrustedKeys act only inside the key-statement walk, which runs from trustAnchors; pass trustAnchors as well.');
|
|
@@ -102,13 +165,16 @@ export function verifyAuditExport(exportData, given = {}) {
|
|
|
102
165
|
const signedActivations = trust === null ? [] : [...trust.byDigest.values()].filter((k) => k.trusted);
|
|
103
166
|
const signingSince = earliestKeyActivation([...resolvedKeys, ...windowOnly, ...signedActivations]);
|
|
104
167
|
const walkReport = reportKeyTrust(keys, trust, meta.anchoredFrom ?? null);
|
|
168
|
+
if (!isVerifyingAsIfHostComputed())
|
|
169
|
+
READINGS.get(exportData)?.keys?.(keys, signingSince);
|
|
105
170
|
// An entry's `payload` and `entryType` are what the binding check and the
|
|
106
171
|
// federation-wire check read. Once any entry carries them, or the caller
|
|
107
172
|
// supplied federation keys, an entry without them is a check that cannot
|
|
108
173
|
// run on it, which is a failure and not a skip.
|
|
109
174
|
const carriesBinding = (raw) => isRecord(raw) && (raw.payload !== undefined || raw.entryType !== undefined);
|
|
110
175
|
const bindingExpected = options.federationKeys !== undefined || entries.some(carriesBinding);
|
|
111
|
-
const
|
|
176
|
+
const entryReadTimes = READINGS.get(exportData)?.entryReadTimes;
|
|
177
|
+
const normalized = entries.map((raw, index) => {
|
|
112
178
|
// An entry or integrity block that is not an object carries none of the
|
|
113
179
|
// fields the walk reads, and fails CHAIN_MALFORMED_ENTRY there.
|
|
114
180
|
const e = isRecord(raw) ? raw : {};
|
|
@@ -122,6 +188,10 @@ export function verifyAuditExport(exportData, given = {}) {
|
|
|
122
188
|
signingKeyId: integrity.signingKeyId,
|
|
123
189
|
createdAt: e.createdAt,
|
|
124
190
|
};
|
|
191
|
+
if (integrity.batch !== undefined && integrity.batch !== null)
|
|
192
|
+
base.batch = integrity.batch;
|
|
193
|
+
if (entryReadTimes !== undefined)
|
|
194
|
+
base.batchPendingSince = batchPendingSinceOf(entryReadTimes[index] ?? null);
|
|
125
195
|
// Binding-integrity: when the export carries the denormalized row `payload`
|
|
126
196
|
// (Server 0.26 and later), cross-check it against the predicate decoded from the
|
|
127
197
|
// signed bytes, the export's own verificationGuide step 4. The threat is
|
|
@@ -176,7 +246,35 @@ export function verifyAuditExport(exportData, given = {}) {
|
|
|
176
246
|
}
|
|
177
247
|
return base;
|
|
178
248
|
});
|
|
249
|
+
// Batch heads are verified under the same keys as the entries. An entry
|
|
250
|
+
// with the batch marker and no proof is still waiting for its head only
|
|
251
|
+
// when it was written within the Server's grace of the export being cut;
|
|
252
|
+
// `exportDate` is the export's own word, so it can only excuse the last
|
|
253
|
+
// entries of a chain, which then read `pending` and count as unsigned.
|
|
254
|
+
const rawHeads = meta.batchHeads;
|
|
255
|
+
const batchHeads = buildBatchHeadRegistry(Array.isArray(rawHeads) ? rawHeads.filter(isRecord) : [], keys);
|
|
256
|
+
const batchPendingSince = batchPendingSinceOf(meta.exportDate);
|
|
257
|
+
// History seals: what an ML-DSA key signed over everything the classical
|
|
258
|
+
// keys before it wrote. Judged against the walk; with no walk, or a walk
|
|
259
|
+
// that trusts no ML-DSA key, no entry is held to one.
|
|
260
|
+
const rawSeals = meta.historySeals;
|
|
261
|
+
const sealRows = Array.isArray(rawSeals) ? rawSeals.filter(isRecord) : [];
|
|
262
|
+
const historySeals = planHistorySeals(sealRows, keys, trust);
|
|
263
|
+
const historySealProofs = new Map();
|
|
264
|
+
for (const row of sealRows) {
|
|
265
|
+
const id = row['id'];
|
|
266
|
+
if (typeof id !== 'string')
|
|
267
|
+
continue;
|
|
268
|
+
const proof = row['proof'];
|
|
269
|
+
historySealProofs.set(id.toLowerCase(), isRecord(proof) ? proof : null);
|
|
270
|
+
}
|
|
271
|
+
const reading = READINGS.get(exportData);
|
|
179
272
|
const chain = verifyChain(normalized, keys, {
|
|
273
|
+
...(reading?.slice !== undefined ? { slice: reading.slice } : {}),
|
|
274
|
+
batchHeads,
|
|
275
|
+
batchPendingSince,
|
|
276
|
+
historySeals,
|
|
277
|
+
historySealProofs,
|
|
180
278
|
requireKeyId: options.requireKeyId,
|
|
181
279
|
requireSuppliedKeys: options.requireSuppliedKeys,
|
|
182
280
|
agentKeys,
|
|
@@ -194,13 +292,123 @@ export function verifyAuditExport(exportData, given = {}) {
|
|
|
194
292
|
// at position 0, the place for findings that precede the walk.
|
|
195
293
|
const registryFinding = keyTrust.findings[0];
|
|
196
294
|
const count = statedEntryCount(meta, entries.length, options.expectedEntryCount);
|
|
197
|
-
const identity = signedRecordId(meta.recordId, entries);
|
|
198
|
-
const
|
|
295
|
+
const identity = reading?.identity !== undefined ? reading.identity(entries) : signedRecordId(meta.recordId, entries);
|
|
296
|
+
const checkpoint = verifyExportCheckpoint(meta.recordId, meta.checkpointEvidence, normalized, keys, signingSince);
|
|
297
|
+
const receipts = verifyExportReceipts(normalized.map((n, i) => {
|
|
298
|
+
const raw = entries[i];
|
|
299
|
+
const integrity = isRecord(raw) ? raw.integrity : undefined;
|
|
300
|
+
return { chainPosition: n.chainPosition, coseSign1: n.coseSign1, receipt: isRecord(integrity) ? integrity.receipt : undefined };
|
|
301
|
+
}), keys);
|
|
302
|
+
const positions = normalized.map((n) => n.chainPosition);
|
|
303
|
+
const coverage = verifyCheckpointCoverage(meta.checkpointEvidence, positions);
|
|
304
|
+
const supplied = verifyRewindAcknowledgements(suppliedSources.map((s) => s.item), identity.recordId, keys, signingSince, true);
|
|
305
|
+
const callerRead = options.exportDate !== undefined ? rfc3339Ms(options.exportDate) : null;
|
|
306
|
+
if (callerRead !== null)
|
|
307
|
+
assertReadAfterSigned(callerRead, options.exportDate, normalized, meta.checkpointEvidence);
|
|
308
|
+
const walkView = reading?.anchors !== undefined || supplied.acknowledgements.length > 0
|
|
309
|
+
? { judgedThroughIat: null, ...reading?.anchors, acknowledgements: [...(reading?.anchors?.acknowledgements ?? []), ...supplied.acknowledgements] }
|
|
310
|
+
: undefined;
|
|
311
|
+
const bucket = verifyExportAnchors(identity.recordId, meta.checkpointEvidence, normalized, anchorDocuments, keys, signingSince, walkView, callerRead !== null ? { judgedThroughIat: Math.floor(callerRead / 1000) - 1 } : undefined);
|
|
312
|
+
const listed = reading?.listedCheckpoints !== undefined
|
|
313
|
+
? judgeListedCheckpoints(identity.recordId, reading.listedCheckpoints.rows, normalized, keys, signingSince, reading.listedCheckpoints.view)
|
|
314
|
+
: null;
|
|
315
|
+
const readTimeFinding = statedReadTimeFinding(meta, normalized);
|
|
316
|
+
const attestation = verifyAttestations(identity.recordId, normalized.map((n, i) => {
|
|
317
|
+
const raw = entries[i];
|
|
318
|
+
const integrity = isRecord(raw) ? raw.integrity : undefined;
|
|
319
|
+
return { chainPosition: n.chainPosition, coseSign1: n.coseSign1, contentBinding: isRecord(integrity) ? integrity.contentBinding : undefined };
|
|
320
|
+
}), complianceRecords);
|
|
321
|
+
// Placed after every earlier export-level finding, so the break a result
|
|
322
|
+
// names on an export without these inputs is unchanged.
|
|
323
|
+
const evidenceFindings = [coverage.finding, readTimeFinding, ...supplied.findings, ...bucket.findings, ...attestation.findings, ...(listed?.findings ?? [])]
|
|
324
|
+
.flatMap((f) => (f !== undefined ? [{ position: f.position, code: f.code, detail: f.detail }] : []));
|
|
325
|
+
const firstBreak = chain.brokenAt
|
|
199
326
|
? { position: chain.brokenAt.position, code: chain.brokenAt.code, detail: chain.brokenAt.detail }
|
|
200
327
|
: registryFinding
|
|
201
328
|
? { position: 0, code: registryFinding.code, detail: registryFinding.detail }
|
|
202
|
-
: identity.finding ?? count.finding;
|
|
203
|
-
const valid = chain.valid && keyTrust.findings.length === 0 && count.finding === undefined && identity.finding === undefined
|
|
329
|
+
: identity.finding ?? checkpoint.finding ?? count.finding ?? receipts.finding ?? evidenceFindings[0];
|
|
330
|
+
const valid = chain.valid && keyTrust.findings.length === 0 && count.finding === undefined && identity.finding === undefined
|
|
331
|
+
&& checkpoint.finding === undefined && receipts.finding === undefined && evidenceFindings.length === 0;
|
|
332
|
+
const failureCodes = [
|
|
333
|
+
...chain.entries.flatMap((r) => (r.failure !== undefined ? [r.failure.code] : [])),
|
|
334
|
+
...keyTrust.findings.map((f) => f.code),
|
|
335
|
+
...[identity.finding, checkpoint.finding, count.finding, receipts.finding].flatMap((f) => (f !== undefined ? [f.code] : [])),
|
|
336
|
+
...evidenceFindings.map((f) => f.code),
|
|
337
|
+
];
|
|
338
|
+
// Every signature check that could not be computed: the failures that say
|
|
339
|
+
// so, and the key statements the walk could not check (which are not
|
|
340
|
+
// failures of their own; what they leave unreached is).
|
|
341
|
+
const uncomputableCount = failureCodes.filter((c) => c === UNSUPPORTED).length + (trust?.statements.unverifiable ?? 0);
|
|
342
|
+
const algorithms = uncomputableCount === 0 ? [] : uncomputableAlgorithms([
|
|
343
|
+
...[...keys.values()].map((k) => k.spkiBase64),
|
|
344
|
+
...trustKeysOf(exportData, options).map((k) => k.publicKey),
|
|
345
|
+
...(agentKeys?.values() ?? []),
|
|
346
|
+
...[...(federationKeys?.values() ?? [])].flatMap((list) => list.map((k) => k.publicKey)),
|
|
347
|
+
]);
|
|
348
|
+
// Under a pin this host can compute, a key is trusted only through
|
|
349
|
+
// signatures this host computed: the rerun assumes no key statement.
|
|
350
|
+
const anchorKeys = () => [
|
|
351
|
+
...[...keys.values()].map((k) => k.spkiBase64),
|
|
352
|
+
...trustKeysOf(exportData, options).map((k) => k.publicKey),
|
|
353
|
+
];
|
|
354
|
+
const computableAnchor = () => hasComputableAnchor(options.trustAnchors ?? [], anchorKeys());
|
|
355
|
+
// A counterfactual rerun (see verifyAsIfHostComputed) reads only `valid`,
|
|
356
|
+
// so it takes no verdict of its own and runs no rerun of its own.
|
|
357
|
+
// The rerun's own result, when it ran: on a failed result its first break
|
|
358
|
+
// is one the host's refusals do not explain, by construction.
|
|
359
|
+
let rerun = null;
|
|
360
|
+
let pinUnmet = false;
|
|
361
|
+
const baseVerdict = isVerifyingAsIfHostComputed()
|
|
362
|
+
? (valid ? 'unanchored' : 'failed')
|
|
363
|
+
: unverifiableVerdict({ valid, uncomputable: { count: uncomputableCount, algorithms }, passesIfComputed: () => {
|
|
364
|
+
rerun = verifyAsIfHostComputed(() => verifyAuditExport(exportData, given), { statements: !computableAnchor() });
|
|
365
|
+
if (rerun.valid)
|
|
366
|
+
return true;
|
|
367
|
+
// A pin that names no key here anchors nothing on any host. Where
|
|
368
|
+
// every check computes, that reads `unanchored` when the input
|
|
369
|
+
// passes without the pin (see verdictOf); where this host refused
|
|
370
|
+
// checks, it reads `unverifiable` when the input would pass without
|
|
371
|
+
// the pin had those checks verified. Nothing was refuted either way.
|
|
372
|
+
// An input that passes on this host without the pin is `unanchored`
|
|
373
|
+
// by verdictOf below, as on any host; this reading is for the one
|
|
374
|
+
// that does not.
|
|
375
|
+
const { trustAnchors: _pinned, distrustedKeys: _distrusted, ...unpinned } = given;
|
|
376
|
+
pinUnmet = !computableAnchor() && pinReachesNoKey(rerun.keyTrust)
|
|
377
|
+
&& !verifyAuditExport(exportData, unpinned).valid
|
|
378
|
+
&& verifyAsIfHostComputed(() => verifyAuditExport(exportData, unpinned).valid);
|
|
379
|
+
return pinUnmet;
|
|
380
|
+
} }, () => sealedVerdict(verdictOf({ valid, keyTrust }, () => {
|
|
381
|
+
const { trustAnchors: _pinned, distrustedKeys: _distrusted, ...unpinned } = options;
|
|
382
|
+
return verifyAuditExport(exportData, unpinned).valid;
|
|
383
|
+
}, (trustAnchors) => verifyAuditExport(exportData, { ...options, trustAnchors }).valid), chain.historySeal));
|
|
384
|
+
const capped = [...bucket.anchors.capped, ...(listed?.capped ?? [])].map((detail) => ({ reason: 'read_time_not_given', detail }));
|
|
385
|
+
const verdict = capVerdict(baseVerdict, capped);
|
|
386
|
+
// After every rerun above, so the outer run's report is the last one given.
|
|
387
|
+
if (listed !== null)
|
|
388
|
+
reading?.listedCheckpoints?.report(listed.heldTo);
|
|
389
|
+
const belowFloor = runtimeBelowFloor();
|
|
390
|
+
const uncomputable = {
|
|
391
|
+
count: uncomputableCount,
|
|
392
|
+
algorithms,
|
|
393
|
+
consequences: verdict === 'unverifiable' ? [...new Set(failureCodes.filter((c) => c !== UNSUPPORTED))] : [],
|
|
394
|
+
...(verdict === 'unverifiable'
|
|
395
|
+
? computableAnchor()
|
|
396
|
+
? { assumed: 'data' }
|
|
397
|
+
: { assumed: 'data-and-key-statements', anchorAlgorithms: anchorAlgorithms(options.trustAnchors ?? [], anchorKeys()), ...(pinUnmet ? { pinUnmet: true } : {}) }
|
|
398
|
+
: {}),
|
|
399
|
+
};
|
|
400
|
+
// On a failed result the break named is the first one that is not a check
|
|
401
|
+
// this host or build could not compute; those are summed up in
|
|
402
|
+
// `uncomputable`. Where this run found none, the rerun's first break names
|
|
403
|
+
// what failed with the refused checks assumed; where neither did (a key of
|
|
404
|
+
// a type this build cannot compute, which the input alone asserts), the
|
|
405
|
+
// first of them stands.
|
|
406
|
+
const rerunBreak = rerun?.brokenAt;
|
|
407
|
+
const brokenAt = verdict === 'failed' && firstBreak?.code === UNSUPPORTED
|
|
408
|
+
? firstRefutation(chain.entries, keyTrust.findings, [identity.finding, checkpoint.finding, count.finding, receipts.finding, ...evidenceFindings])
|
|
409
|
+
?? (rerunBreak !== undefined && rerunBreak.code !== UNSUPPORTED ? rerunBreak : undefined)
|
|
410
|
+
?? firstBreak
|
|
411
|
+
: firstBreak;
|
|
204
412
|
return {
|
|
205
413
|
valid,
|
|
206
414
|
totalEntries: chain.totalEntries,
|
|
@@ -215,20 +423,51 @@ export function verifyAuditExport(exportData, given = {}) {
|
|
|
215
423
|
})),
|
|
216
424
|
recordId: identity.recordId,
|
|
217
425
|
signatureCoverage: chain.signatureCoverage,
|
|
218
|
-
optionalChecks: {
|
|
426
|
+
optionalChecks: {
|
|
427
|
+
...chain.optionalChecks,
|
|
428
|
+
entry_count: count.applied ? 'applied' : 'skipped_no_input',
|
|
429
|
+
checkpoint_evidence: checkpoint.applicability,
|
|
430
|
+
receipts: receipts.applicability,
|
|
431
|
+
anchors: bucket.anchors.applicability,
|
|
432
|
+
attestation_bodies: attestation.report.applicability,
|
|
433
|
+
},
|
|
219
434
|
keyProvenance: chain.keyProvenance,
|
|
220
435
|
unsignedProjectionFields: exportData.verificationGuide?.unsignedFields ?? [],
|
|
221
436
|
agentSignatures: chain.agentSignatures,
|
|
222
437
|
federationWire: chain.federationWire,
|
|
223
438
|
evidenceBinding: chain.evidenceBinding,
|
|
439
|
+
historySeal: chain.historySeal,
|
|
224
440
|
entryCount: count.entryCount,
|
|
441
|
+
checkpointEvidence: checkpoint.report,
|
|
442
|
+
receipts: receipts.counts,
|
|
443
|
+
checkpointCoverage: coverage.report,
|
|
444
|
+
acknowledgedRewinds: bucket.acknowledgedRewinds,
|
|
445
|
+
anchors: bucket.anchors,
|
|
446
|
+
suppliedAcknowledgements: supplied.report,
|
|
447
|
+
capped,
|
|
448
|
+
attestations: attestation.report,
|
|
225
449
|
keyTrust,
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}),
|
|
450
|
+
uncomputable,
|
|
451
|
+
...(belowFloor !== null ? { runtime: belowFloor } : {}),
|
|
452
|
+
verdict,
|
|
230
453
|
};
|
|
231
454
|
}
|
|
455
|
+
const UNSUPPORTED = 'CHAIN_UNSUPPORTED_ALGORITHM';
|
|
456
|
+
/**
|
|
457
|
+
* The first failure that is not a signature check this host or build could not
|
|
458
|
+
* compute: the first such entry, else the first such key-statement finding (at
|
|
459
|
+
* position 0), else the first such export-level finding. Undefined when every
|
|
460
|
+
* failure is one of those.
|
|
461
|
+
*/
|
|
462
|
+
function firstRefutation(entries, findings, others) {
|
|
463
|
+
const entry = entries.find((e) => e.failure !== undefined && e.failure.code !== UNSUPPORTED);
|
|
464
|
+
if (entry?.failure !== undefined)
|
|
465
|
+
return { position: entry.position, code: entry.failure.code, detail: entry.failure.detail };
|
|
466
|
+
const finding = findings.find((f) => f.code !== UNSUPPORTED);
|
|
467
|
+
if (finding !== undefined)
|
|
468
|
+
return { position: 0, code: finding.code, detail: finding.detail };
|
|
469
|
+
return others.find((f) => f !== undefined && f.code !== UNSUPPORTED);
|
|
470
|
+
}
|
|
232
471
|
/**
|
|
233
472
|
* Hold the chain's length to the counts the export states. A chain that was
|
|
234
473
|
* cut from the end still links and verifies entry by entry, so its length is
|
|
@@ -301,7 +540,7 @@ function statedEntryCount(meta, held, supplied) {
|
|
|
301
540
|
* among the entries or with the metadata, fails CHAIN_PAYLOAD_BINDING_MISMATCH,
|
|
302
541
|
* and the id reported is the signed one, never the metadata's.
|
|
303
542
|
*/
|
|
304
|
-
function signedRecordId(stated, entries) {
|
|
543
|
+
export function signedRecordId(stated, entries) {
|
|
305
544
|
const seen = [];
|
|
306
545
|
entries.forEach((raw, i) => {
|
|
307
546
|
if (!isRecord(raw))
|
|
@@ -336,7 +575,46 @@ function signedRecordId(stated, entries) {
|
|
|
336
575
|
},
|
|
337
576
|
};
|
|
338
577
|
}
|
|
339
|
-
|
|
578
|
+
/**
|
|
579
|
+
* Resolve `publicKeys`, `trustAnchors` and `distrustedKeys` exactly as
|
|
580
|
+
* `verifyAuditExport` does for an export that embeds no key of its own: the
|
|
581
|
+
* same shapes accepted (the `/v1/verification-keys` body included), the same
|
|
582
|
+
* `TypeError`s at the boundary, the same walk from the anchors over the
|
|
583
|
+
* statements the supplied keys carry. Internal to this package: the read-log
|
|
584
|
+
* reader verifies documents that carry no keys with it.
|
|
585
|
+
*/
|
|
586
|
+
export function suppliedKeyContext(fn, given) {
|
|
587
|
+
const options = isKeysEnvelope(given.publicKeys) ? { ...given, publicKeys: given.publicKeys.data } : { ...given };
|
|
588
|
+
if ((options.trustAnchors === undefined || options.trustAnchors.length === 0)
|
|
589
|
+
&& options.distrustedKeys !== undefined && options.distrustedKeys.length > 0) {
|
|
590
|
+
throw new TypeError(`${fn}: distrustedKeys act only inside the key-statement walk, which runs from trustAnchors; pass trustAnchors as well.`);
|
|
591
|
+
}
|
|
592
|
+
assertNotPinnedAndDistrusted(options.trustAnchors, options.distrustedKeys);
|
|
593
|
+
// Refused here under the caller's own name, before the shared resolution reads them.
|
|
594
|
+
normalizeSuppliedKeys(options.publicKeys, fn);
|
|
595
|
+
const bare = { exportMetadata: { recordId: '' }, entries: [] };
|
|
596
|
+
const resolved = resolveKeys(bare, options);
|
|
597
|
+
let keys = buildKeyRegistry(resolved);
|
|
598
|
+
const trust = options.trustAnchors !== undefined && options.trustAnchors.length > 0
|
|
599
|
+
? computeKeyTrust({
|
|
600
|
+
keys: trustKeysOf(bare, options),
|
|
601
|
+
statements: trustStatementsOf(bare, options),
|
|
602
|
+
trustAnchors: options.trustAnchors,
|
|
603
|
+
...(options.distrustedKeys !== undefined ? { distrustedKeys: options.distrustedKeys } : {}),
|
|
604
|
+
})
|
|
605
|
+
: null;
|
|
606
|
+
if (trust !== null)
|
|
607
|
+
keys = applyKeyTrust(keys, trust);
|
|
608
|
+
const signedActivations = trust === null ? [] : [...trust.byDigest.values()].filter((k) => k.trusted);
|
|
609
|
+
return {
|
|
610
|
+
keys,
|
|
611
|
+
trust,
|
|
612
|
+
signingSince: earliestKeyActivation([...resolved, ...signedActivations]),
|
|
613
|
+
walkReport: reportKeyTrust(keys, trust, null),
|
|
614
|
+
publicKeys: resolved.map((k) => k.spkiBase64),
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
const EXPORT_OPTIONS = ['publicKeys', 'requireKeyId', 'requireSuppliedKeys', 'trustAnchors', 'distrustedKeys', 'agentKeys', 'federationKeys', 'allowAfterRetirement', 'expectedEntryCount', 'anchorDocuments', 'complianceRecords', 'exportDate', 'acknowledgements'];
|
|
340
618
|
function isKeysEnvelope(value) {
|
|
341
619
|
return isRecord(value) && Array.isArray(value.data);
|
|
342
620
|
}
|
|
@@ -397,6 +675,91 @@ function trustStatementsOf(exportData, options) {
|
|
|
397
675
|
return rest;
|
|
398
676
|
return all.map(({ createdAt: _c, ...s }) => s);
|
|
399
677
|
}
|
|
678
|
+
/** The `anchorDocuments` option, held to its shape at the boundary. */
|
|
679
|
+
function readAnchorDocumentsOption(value) {
|
|
680
|
+
if (value === undefined)
|
|
681
|
+
return undefined;
|
|
682
|
+
if (!Array.isArray(value))
|
|
683
|
+
throw new TypeError('verifyAuditExport: anchorDocuments must be an array of { source, document, objectKey? }.');
|
|
684
|
+
return value.map((d, i) => {
|
|
685
|
+
if (!isRecord(d) || typeof d.source !== 'string' || !('document' in d) || (d.objectKey !== undefined && typeof d.objectKey !== 'string')) {
|
|
686
|
+
throw new TypeError(`verifyAuditExport: anchorDocuments[${i}] is not { source: string, document: <parsed JSON>, objectKey?: string }.`);
|
|
687
|
+
}
|
|
688
|
+
return d;
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
/** The Server's margin under a read time: `anchorsJudgedThroughIat` is the whole second of `evidenceReadAt` less this. */
|
|
692
|
+
const ANCHOR_JUDGE_MARGIN_SECONDS = 1;
|
|
693
|
+
/** The signed iat of each entry and of the embedded checkpoint, in position order, where one decodes. */
|
|
694
|
+
function signedTimes(entries, evidence) {
|
|
695
|
+
const out = [];
|
|
696
|
+
for (const e of entries) {
|
|
697
|
+
if (typeof e.coseSign1 !== 'string' || !Number.isSafeInteger(e.chainPosition))
|
|
698
|
+
continue;
|
|
699
|
+
const iat = decodeSignedClaim(Buffer.from(e.coseSign1, 'base64'))?.iat;
|
|
700
|
+
if (typeof iat === 'number' && Number.isFinite(iat))
|
|
701
|
+
out.push({ what: `the entry at position ${e.chainPosition}`, position: e.chainPosition, iat });
|
|
702
|
+
}
|
|
703
|
+
const cp = isRecord(evidence) && isRecord(evidence['checkpoint']) ? evidence['checkpoint'] : null;
|
|
704
|
+
if (cp !== null && typeof cp['coseSign1'] === 'string' && Number.isSafeInteger(cp['chainPosition'])) {
|
|
705
|
+
const iat = decodeSignedClaim(Buffer.from(cp['coseSign1'], 'base64'))?.iat;
|
|
706
|
+
if (typeof iat === 'number' && Number.isFinite(iat))
|
|
707
|
+
out.push({ what: `the embedded checkpoint at position ${String(cp['chainPosition'])}`, position: cp['chainPosition'], iat });
|
|
708
|
+
}
|
|
709
|
+
return out.sort((a, b) => a.position - b.position);
|
|
710
|
+
}
|
|
711
|
+
const isoOfIat = (iat) => {
|
|
712
|
+
const ms = iat * 1000;
|
|
713
|
+
return Number.isFinite(ms) && Math.abs(ms) <= 8.64e15 ? new Date(ms).toISOString() : String(iat);
|
|
714
|
+
};
|
|
715
|
+
/**
|
|
716
|
+
* Throw `TypeError` when the caller's read time is earlier than the signed
|
|
717
|
+
* iat of an entry or of the embedded checkpoint: what the export holds was
|
|
718
|
+
* signed after it, so it is not when the export was read. The iat is the
|
|
719
|
+
* whole second, rounded down, so a read in that same second still holds.
|
|
720
|
+
*/
|
|
721
|
+
function assertReadAfterSigned(readMs, given, entries, evidence) {
|
|
722
|
+
const late = signedTimes(entries, evidence).find((t) => t.iat * 1000 > readMs);
|
|
723
|
+
if (late !== undefined) {
|
|
724
|
+
throw new TypeError(`verifyAuditExport: exportDate ${given} is earlier than ${late.what}, signed at iat ${late.iat} (${isoOfIat(late.iat)}): the export was read after that. Give the time the export was read.`);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Hold the read times the export states about itself to the signed iat of
|
|
729
|
+
* what it holds: `exportMetadata.exportDate` against every entry and the
|
|
730
|
+
* embedded checkpoint; `checkpointEvidence.evidenceReadAt` and
|
|
731
|
+
* `anchorsJudgedThroughIat` against the entries up to the block's
|
|
732
|
+
* `lastEntryPosition` (the ones it read) and its checkpoint. A stated time
|
|
733
|
+
* earlier than one of them is EXPORT_READ_TIME_INVALID at that entry.
|
|
734
|
+
*/
|
|
735
|
+
function statedReadTimeFinding(meta, entries) {
|
|
736
|
+
const times = signedTimes(entries, meta.checkpointEvidence);
|
|
737
|
+
if (times.length === 0)
|
|
738
|
+
return undefined;
|
|
739
|
+
const ev = isRecord(meta.checkpointEvidence) ? meta.checkpointEvidence : null;
|
|
740
|
+
const lastRead = ev !== null && Number.isSafeInteger(ev['lastEntryPosition']) ? ev['lastEntryPosition'] : Infinity;
|
|
741
|
+
const checks = [];
|
|
742
|
+
const exportMs = typeof meta.exportDate === 'string' ? rfc3339Ms(meta.exportDate) : NaN;
|
|
743
|
+
if (!Number.isNaN(exportMs))
|
|
744
|
+
checks.push({ field: `exportMetadata.exportDate ${meta.exportDate}`, latestIat: Math.floor(exportMs / 1000), scope: 'all' });
|
|
745
|
+
const readAt = ev !== null && typeof ev['evidenceReadAt'] === 'string' ? rfc3339Ms(ev['evidenceReadAt']) : NaN;
|
|
746
|
+
if (!Number.isNaN(readAt))
|
|
747
|
+
checks.push({ field: `checkpointEvidence.evidenceReadAt ${String(ev?.['evidenceReadAt'])}`, latestIat: Math.floor(readAt / 1000), scope: 'block' });
|
|
748
|
+
const judged = ev?.['anchorsJudgedThroughIat'];
|
|
749
|
+
if (typeof judged === 'number' && Number.isSafeInteger(judged))
|
|
750
|
+
checks.push({ field: `checkpointEvidence.anchorsJudgedThroughIat ${judged}`, latestIat: judged + ANCHOR_JUDGE_MARGIN_SECONDS, scope: 'block' });
|
|
751
|
+
for (const c of checks) {
|
|
752
|
+
const late = times.find((t) => (c.scope === 'all' || t.position <= lastRead) && t.iat > c.latestIat);
|
|
753
|
+
if (late !== undefined) {
|
|
754
|
+
return {
|
|
755
|
+
position: late.position,
|
|
756
|
+
code: 'EXPORT_READ_TIME_INVALID',
|
|
757
|
+
detail: `The export states ${c.field}, and ${late.what} is signed at iat ${late.iat} (${isoOfIat(late.iat)}), later: the stated read time was moved earlier than the read, which can set aside an anchor that shows a cut.`,
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return undefined;
|
|
762
|
+
}
|
|
400
763
|
function earlyFailure(recordId, totalEntries, detail) {
|
|
401
764
|
return {
|
|
402
765
|
valid: false,
|
|
@@ -405,7 +768,7 @@ function earlyFailure(recordId, totalEntries, detail) {
|
|
|
405
768
|
brokenAt: { position: 0, code: 'UNSUPPORTED_FORMAT', detail },
|
|
406
769
|
entries: [{ position: 0, valid: false, code: 'UNSUPPORTED_FORMAT', detail }],
|
|
407
770
|
recordId,
|
|
408
|
-
signatureCoverage: { signed: 0, unsigned: 0, skipped: 0, total: totalEntries },
|
|
771
|
+
signatureCoverage: { signed: 0, unsigned: 0, skipped: 0, total: totalEntries, pending: 0, batched: 0 },
|
|
409
772
|
optionalChecks: {
|
|
410
773
|
payload_binding: 'skipped_no_input',
|
|
411
774
|
oidc_actor: 'skipped_no_input',
|
|
@@ -415,15 +778,30 @@ function earlyFailure(recordId, totalEntries, detail) {
|
|
|
415
778
|
key_anchoring: 'skipped_no_input',
|
|
416
779
|
federation_wire: 'skipped_no_input',
|
|
417
780
|
evidence_binding: 'skipped_no_input',
|
|
781
|
+
history_seal: 'skipped_no_input',
|
|
418
782
|
entry_count: 'skipped_no_input',
|
|
783
|
+
checkpoint_evidence: 'skipped_no_input',
|
|
784
|
+
receipts: 'skipped_no_input',
|
|
785
|
+
anchors: 'skipped_no_input',
|
|
786
|
+
attestation_bodies: 'skipped_no_input',
|
|
419
787
|
},
|
|
420
788
|
keyProvenance: { supplied: 0, embedded: 0 },
|
|
421
789
|
unsignedProjectionFields: [],
|
|
422
790
|
agentSignatures: { present: 0, verified: 0 },
|
|
423
791
|
federationWire: { present: 0, verified: 0, failed: 0, afterRetirement: 0 },
|
|
424
792
|
evidenceBinding: { present: 0, verified: 0, clientHashed: 0, failed: 0 },
|
|
793
|
+
historySeal: { sealed: 0, unsealed: 0, unsealedKeys: [] },
|
|
425
794
|
entryCount: { expectedEntries: null, statedEntries: null },
|
|
795
|
+
checkpointEvidence: { position: null, state: 'absent' },
|
|
796
|
+
receipts: { present: 0, verified: 0 },
|
|
797
|
+
checkpointCoverage: { applicability: 'skipped_no_input', checked: [] },
|
|
798
|
+
acknowledgedRewinds: { applicability: 'skipped_no_input', present: 0, verified: 0, items: [], linkChecked: false },
|
|
799
|
+
anchors: { applicability: 'skipped_no_input', chainKey: recordId, judgedThroughIat: null, verdicts: [], counts: { agree: 0, disagree: 0, accounted: 0, notComparable: 0 }, findings: [], capped: [], embeddedCheckpoint: null },
|
|
800
|
+
suppliedAcknowledgements: { applicability: 'skipped_no_input', present: 0, verified: 0, items: [], linkChecked: false },
|
|
801
|
+
capped: [],
|
|
802
|
+
attestations: { applicability: 'skipped_no_input', entries: [], otherRecords: [] },
|
|
426
803
|
keyTrust: reportKeyTrust(new Map(), null, null),
|
|
804
|
+
uncomputable: { count: 0, algorithms: [], consequences: [] },
|
|
427
805
|
verdict: 'failed',
|
|
428
806
|
};
|
|
429
807
|
}
|
|
@@ -497,19 +875,19 @@ function resolveKeys(exportData, options) {
|
|
|
497
875
|
* Returns `null` when no keys were supplied; otherwise an array of normalized
|
|
498
876
|
* entries ready to merge into the registry.
|
|
499
877
|
*/
|
|
500
|
-
function normalizeSuppliedKeys(publicKeys) {
|
|
878
|
+
function normalizeSuppliedKeys(publicKeys, fn = 'verifyAuditExport') {
|
|
501
879
|
if (publicKeys === undefined || publicKeys === null)
|
|
502
880
|
return null;
|
|
503
881
|
if (Array.isArray(publicKeys)) {
|
|
504
882
|
return publicKeys.map((entry, i) => {
|
|
505
883
|
if (entry === null || typeof entry !== 'object') {
|
|
506
|
-
throw new TypeError(
|
|
884
|
+
throw new TypeError(`${fn}: publicKeys[${i}] is not an object (got ${typeof entry}). ` +
|
|
507
885
|
`Expected { keyId, publicKey } entries, e.g. the .data[] from client.verificationKeys.list().`);
|
|
508
886
|
}
|
|
509
887
|
const keyId = entry.keyId;
|
|
510
888
|
const publicKey = entry.publicKey;
|
|
511
889
|
if (typeof keyId !== 'string' || typeof publicKey !== 'string') {
|
|
512
|
-
throw new TypeError(
|
|
890
|
+
throw new TypeError(`${fn}: publicKeys[${i}] is missing required string fields { keyId, publicKey } ` +
|
|
513
891
|
`(got keyId=${typeof keyId}, publicKey=${typeof publicKey}). ` +
|
|
514
892
|
`Expected the SDK VerificationKey shape: publicKey must be SPKI DER base64.`);
|
|
515
893
|
}
|
|
@@ -520,7 +898,7 @@ function normalizeSuppliedKeys(publicKeys) {
|
|
|
520
898
|
// is: one that is not would be read by the host's clock or not at all.
|
|
521
899
|
for (const [edge, value] of [['activatedAt', activatedAt], ['retiredAt', retiredAt]]) {
|
|
522
900
|
if (value !== undefined && value !== null && (typeof value !== 'string' || Number.isNaN(instantMs(value)))) {
|
|
523
|
-
throw new TypeError(
|
|
901
|
+
throw new TypeError(`${fn}: publicKeys[${i}] (key ${keyId}) has ${edge} ${JSON.stringify(value)}, which is not an RFC 3339 instant ` +
|
|
524
902
|
'(2026-09-01T00:00:00.000Z: a T, an offset or Z, a real calendar date).');
|
|
525
903
|
}
|
|
526
904
|
}
|
|
@@ -532,13 +910,13 @@ function normalizeSuppliedKeys(publicKeys) {
|
|
|
532
910
|
});
|
|
533
911
|
}
|
|
534
912
|
if (typeof publicKeys !== 'object') {
|
|
535
|
-
throw new TypeError(
|
|
913
|
+
throw new TypeError(`${fn}: publicKeys must be a Record<keyId, base64SpkiDer> or an array of ` +
|
|
536
914
|
`{ keyId, publicKey } entries (got ${typeof publicKeys}).`);
|
|
537
915
|
}
|
|
538
916
|
const entries = [];
|
|
539
917
|
for (const [keyId, value] of Object.entries(publicKeys)) {
|
|
540
918
|
if (typeof value !== 'string') {
|
|
541
|
-
throw new TypeError(
|
|
919
|
+
throw new TypeError(`${fn}: publicKeys["${keyId}"] is not a base64 string (got ${typeof value}). ` +
|
|
542
920
|
`If you passed the .data[] from client.verificationKeys.list(), pass it as an array, ` +
|
|
543
921
|
`not via Object.fromEntries on the raw list.`);
|
|
544
922
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type BatchHeadRegistry, type BatchHeadVerdict } from './batch.js';
|
|
2
|
+
import { type KeyRegistry } from './chain.js';
|
|
3
|
+
/** A batch head as an artifact carries it. */
|
|
4
|
+
export interface BatchHeadInput {
|
|
5
|
+
/** The head's id: an export's `batchHeads[].id`, a dump row's `id`. */
|
|
6
|
+
id: string;
|
|
7
|
+
signingKeyId: string;
|
|
8
|
+
/** The signed head, base64 or bytes. */
|
|
9
|
+
coseSign1: string | Uint8Array;
|
|
10
|
+
/** When the Server stored the head: what its key's window is held to. */
|
|
11
|
+
createdAt?: string | null;
|
|
12
|
+
/** A dump row's `tree_size` column, bound to the signed `treeSize` when given. */
|
|
13
|
+
treeSize?: number;
|
|
14
|
+
/** A dump row's `root_hash` column (lowercase hex), bound to the signed `root` when given. */
|
|
15
|
+
rootHash?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Judge one batch head against the keys the artifact's entries are verified
|
|
19
|
+
* with (after `applyKeyTrust`, when a walk ran). Never throws on a malformed
|
|
20
|
+
* head: it is `invalid`, with the reason.
|
|
21
|
+
*/
|
|
22
|
+
export declare function judgeBatchHead(head: BatchHeadInput, keys: KeyRegistry): BatchHeadVerdict;
|
|
23
|
+
/**
|
|
24
|
+
* Judge every head an artifact carries and index them by id (lowercase). A
|
|
25
|
+
* head listed twice under one id with different bytes is `invalid`: nothing
|
|
26
|
+
* says which one the entries mean.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildBatchHeadRegistry(heads: readonly BatchHeadInput[], keys: KeyRegistry): BatchHeadRegistry;
|