@agledger/verify-core 2.1.0 → 2.2.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.
@@ -6,7 +6,7 @@
6
6
  * normalized entry and runs `verifyChain`.
7
7
  *
8
8
  * The three row-level input-gated checks run on the export path when the wire
9
- * carries their inputs (engine ≥ v0.26.x): the `actorOidcSynthesized` flag +
9
+ * carries their inputs (Server 0.26 and later): the `actorOidcSynthesized` flag +
10
10
  * `actorOidcIss/Sub` enable the OIDC-actor cross-check; `signingKeyWindows` +
11
11
  * per-entry `createdAt` enable temporal key-validity; and the per-entry
12
12
  * denormalized `payload` + `entryType` enable binding-integrity, the export's
@@ -14,7 +14,7 @@
14
14
  * tampering of the human-readable `payload`/`criteria` view: the verifier
15
15
  * re-decodes the signed predicate from `coseSign1` and deep-equals it against
16
16
  * the row `payload`, so a rewritten `payload` with an intact envelope fails
17
- * CHAIN_PAYLOAD_BINDING_MISMATCH (validated against a real engine v0.26.4
17
+ * CHAIN_PAYLOAD_BINDING_MISMATCH (validated against a real Server v0.26.4
18
18
  * export; `buildPredicateForRow` reconstructs the signed predicate exactly).
19
19
  * Older exports without these fields stay `skipped_no_input`, surfaced in the
20
20
  * result so a caller never mistakes "not checked here" for "checked and passed".
@@ -22,6 +22,7 @@
22
22
  import { buildAgentKeyRegistry, buildKeyRegistry, earliestKeyActivation, verifyChain, } from './chain.js';
23
23
  import { instantMs } from './instant.js';
24
24
  import { assertKnownOptions } from './options.js';
25
+ import { decodeCoseSign1, decodePredicate } from './primitives.js';
25
26
  import { buildFederationKeyRegistry } from './federation-wire.js';
26
27
  import { applyKeyTrust, assertNotPinnedAndDistrusted, computeKeyTrust, keyStatementsFromExport, statementsFromMap, reportKeyTrust, settleKeyTrust, verdictOf, } from './key-statements.js';
27
28
  const SUPPORTED_FORMAT_VERSION = '2.0';
@@ -50,18 +51,28 @@ export function verifyAuditExport(exportData, given = {}) {
50
51
  throw new TypeError('distrustedKeys act only inside the key-statement walk, which runs from trustAnchors; pass trustAnchors as well.');
51
52
  }
52
53
  assertNotPinnedAndDistrusted(options.trustAnchors, options.distrustedKeys);
54
+ if (options.expectedEntryCount !== undefined
55
+ && !(typeof options.expectedEntryCount === 'number' && Number.isInteger(options.expectedEntryCount) && options.expectedEntryCount >= 0)) {
56
+ throw new TypeError(`verifyAuditExport: expectedEntryCount must be a non-negative integer (got ${JSON.stringify(options.expectedEntryCount)}).`);
57
+ }
58
+ // Caller-supplied keys are refused before the export is read, so a bad option
59
+ // is reported as such whatever the input holds.
60
+ const agentKeys = options.agentKeys !== undefined ? buildAgentKeyRegistry(options.agentKeys) : undefined;
61
+ const federationKeys = options.federationKeys !== undefined ? buildFederationKeyRegistry(options.federationKeys) : undefined;
53
62
  const meta = exportData.exportMetadata;
54
63
  const entries = exportData.entries ?? [];
55
- if (meta.exportFormatVersion && meta.exportFormatVersion !== SUPPORTED_FORMAT_VERSION) {
56
- return earlyFailure(meta.recordId, entries.length, `Unsupported exportFormatVersion ${meta.exportFormatVersion} (this verifier reads ${SUPPORTED_FORMAT_VERSION}).`);
64
+ if (meta.exportFormatVersion !== SUPPORTED_FORMAT_VERSION) {
65
+ return earlyFailure(meta.recordId, entries.length, meta.exportFormatVersion === undefined || meta.exportFormatVersion === null || meta.exportFormatVersion === ''
66
+ ? `The export states no exportFormatVersion (this verifier reads ${SUPPORTED_FORMAT_VERSION}).`
67
+ : `Unsupported exportFormatVersion ${JSON.stringify(meta.exportFormatVersion)} (this verifier reads ${SUPPORTED_FORMAT_VERSION}).`);
57
68
  }
58
- if (meta.canonicalization && meta.canonicalization !== SUPPORTED_CANONICALIZATION) {
59
- return earlyFailure(meta.recordId, entries.length, `Unsupported canonicalization ${meta.canonicalization} (only ${SUPPORTED_CANONICALIZATION} supported).`);
69
+ if (meta.canonicalization !== SUPPORTED_CANONICALIZATION) {
70
+ return earlyFailure(meta.recordId, entries.length, meta.canonicalization === undefined || meta.canonicalization === null || meta.canonicalization === ''
71
+ ? `The export states no canonicalization (only ${SUPPORTED_CANONICALIZATION} supported).`
72
+ : `Unsupported canonicalization ${JSON.stringify(meta.canonicalization)} (only ${SUPPORTED_CANONICALIZATION} supported).`);
60
73
  }
61
74
  const resolvedKeys = resolveKeys(exportData, options);
62
75
  let keys = buildKeyRegistry(resolvedKeys);
63
- const agentKeys = options.agentKeys !== undefined ? buildAgentKeyRegistry(options.agentKeys) : undefined;
64
- const federationKeys = options.federationKeys !== undefined ? buildFederationKeyRegistry(options.federationKeys) : undefined;
65
76
  // An empty trustAnchors is the same as none: no walk, keyTrust 'no_anchor'.
66
77
  const trust = options.trustAnchors !== undefined && options.trustAnchors.length > 0
67
78
  ? computeKeyTrust({
@@ -73,7 +84,7 @@ export function verifyAuditExport(exportData, given = {}) {
73
84
  : null;
74
85
  if (trust !== null)
75
86
  keys = applyKeyTrust(keys, trust);
76
- // When the install began signing, for CHAIN_ENTRY_UNSIGNED. The engine reads
87
+ // When the install began signing, for CHAIN_ENTRY_UNSIGNED. The Server reads
77
88
  // it as min(activated_at) over its whole key registry, retired keys included,
78
89
  // and `signingKeyWindows` publishes that whole registry. So the instant is
79
90
  // taken over every key the verifier holds (with each key's window resolved
@@ -91,6 +102,12 @@ export function verifyAuditExport(exportData, given = {}) {
91
102
  const signedActivations = trust === null ? [] : [...trust.byDigest.values()].filter((k) => k.trusted);
92
103
  const signingSince = earliestKeyActivation([...resolvedKeys, ...windowOnly, ...signedActivations]);
93
104
  const walkReport = reportKeyTrust(keys, trust, meta.anchoredFrom ?? null);
105
+ // An entry's `payload` and `entryType` are what the binding check and the
106
+ // federation-wire check read. Once any entry carries them, or the caller
107
+ // supplied federation keys, an entry without them is a check that cannot
108
+ // run on it, which is a failure and not a skip.
109
+ const carriesBinding = (raw) => isRecord(raw) && (raw.payload !== undefined || raw.entryType !== undefined);
110
+ const bindingExpected = options.federationKeys !== undefined || entries.some(carriesBinding);
94
111
  const normalized = entries.map((raw) => {
95
112
  // An entry or integrity block that is not an object carries none of the
96
113
  // fields the walk reads, and fails CHAIN_MALFORMED_ENTRY there.
@@ -106,7 +123,7 @@ export function verifyAuditExport(exportData, given = {}) {
106
123
  createdAt: e.createdAt,
107
124
  };
108
125
  // Binding-integrity: when the export carries the denormalized row `payload`
109
- // (engine ≥ v0.26.x), cross-check it against the predicate decoded from the
126
+ // (Server 0.26 and later), cross-check it against the predicate decoded from the
110
127
  // signed bytes, the export's own verificationGuide step 4. The threat is
111
128
  // post-export tampering of the human-readable `payload`/`criteria` view: an
112
129
  // attacker rewrites `payload` and leaves `coseSign1` intact. The verifier
@@ -118,6 +135,14 @@ export function verifyAuditExport(exportData, given = {}) {
118
135
  recordId: e.recordId ?? null,
119
136
  entryType: e.entryType,
120
137
  payload: e.payload,
138
+ extensionsProjected: true,
139
+ };
140
+ }
141
+ else if (bindingExpected) {
142
+ const missing = [e.payload === undefined ? 'payload' : null, e.entryType === undefined ? 'entryType' : null].filter((m) => m !== null).join(' and ');
143
+ base.bindingRequired = {
144
+ detail: `The entry carries no ${missing}, which the binding and federation-wire checks read: ${options.federationKeys !== undefined && !entries.some(carriesBinding) ? 'federationKeys were supplied' : 'other entries of this export carry it'}, so an entry without it cannot be checked.`,
145
+ federationWire: options.federationKeys !== undefined,
121
146
  };
122
147
  }
123
148
  // An inlined evidence body is unsigned; it is re-bound to the hash the
@@ -156,6 +181,7 @@ export function verifyAuditExport(exportData, given = {}) {
156
181
  requireSuppliedKeys: options.requireSuppliedKeys,
157
182
  agentKeys,
158
183
  federationKeys,
184
+ allowAfterRetirement: options.allowAfterRetirement === true,
159
185
  signingSince,
160
186
  });
161
187
  // Under a walk every key a signature verifies against is anchored, so the
@@ -167,12 +193,14 @@ export function verifyAuditExport(exportData, given = {}) {
167
193
  // A finding on the key statements has no chain position; it is reported
168
194
  // at position 0, the place for findings that precede the walk.
169
195
  const registryFinding = keyTrust.findings[0];
196
+ const count = statedEntryCount(meta, entries.length, options.expectedEntryCount);
197
+ const identity = signedRecordId(meta.recordId, entries);
170
198
  const brokenAt = chain.brokenAt
171
199
  ? { position: chain.brokenAt.position, code: chain.brokenAt.code, detail: chain.brokenAt.detail }
172
200
  : registryFinding
173
201
  ? { position: 0, code: registryFinding.code, detail: registryFinding.detail }
174
- : undefined;
175
- const valid = chain.valid && keyTrust.findings.length === 0;
202
+ : identity.finding ?? count.finding;
203
+ const valid = chain.valid && keyTrust.findings.length === 0 && count.finding === undefined && identity.finding === undefined;
176
204
  return {
177
205
  valid,
178
206
  totalEntries: chain.totalEntries,
@@ -185,19 +213,130 @@ export function verifyAuditExport(exportData, given = {}) {
185
213
  detail: r.failure?.detail,
186
214
  signature: r.signature,
187
215
  })),
188
- recordId: meta.recordId,
216
+ recordId: identity.recordId,
189
217
  signatureCoverage: chain.signatureCoverage,
190
- optionalChecks: chain.optionalChecks,
218
+ optionalChecks: { ...chain.optionalChecks, entry_count: count.applied ? 'applied' : 'skipped_no_input' },
191
219
  keyProvenance: chain.keyProvenance,
192
220
  unsignedProjectionFields: exportData.verificationGuide?.unsignedFields ?? [],
193
221
  agentSignatures: chain.agentSignatures,
194
222
  federationWire: chain.federationWire,
195
223
  evidenceBinding: chain.evidenceBinding,
224
+ entryCount: count.entryCount,
196
225
  keyTrust,
197
- verdict: verdictOf({ valid, keyTrust }),
226
+ verdict: verdictOf({ valid, keyTrust }, () => {
227
+ const { trustAnchors: _pinned, distrustedKeys: _distrusted, ...unpinned } = options;
228
+ return verifyAuditExport(exportData, unpinned).valid;
229
+ }),
230
+ };
231
+ }
232
+ /**
233
+ * Hold the chain's length to the counts the export states. A chain that was
234
+ * cut from the end still links and verifies entry by entry, so its length is
235
+ * the only thing that shows the cut: against the latest checkpoint position
236
+ * (a chain shorter than its checkpoint lost rows below it) and against the number of
237
+ * entries the Server wrote. A count that is present and is not a non-negative
238
+ * integer is refused rather than skipped.
239
+ */
240
+ function statedEntryCount(meta, held, supplied) {
241
+ const read = (name) => {
242
+ const value = meta[name];
243
+ if (value === undefined || value === null)
244
+ return null;
245
+ return typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : 'malformed';
246
+ };
247
+ const expected = read('expectedEntries');
248
+ const stated = read('totalEntries');
249
+ const entryCount = {
250
+ expectedEntries: expected === 'malformed' ? null : expected,
251
+ statedEntries: stated === 'malformed' ? null : stated,
252
+ };
253
+ for (const [name, value] of [['expectedEntries', expected], ['totalEntries', stated]]) {
254
+ if (value === 'malformed') {
255
+ return {
256
+ entryCount,
257
+ applied: true,
258
+ finding: { position: 0, code: 'UNSUPPORTED_FORMAT', detail: `exportMetadata.${name} is ${JSON.stringify(meta[name])}, not a non-negative integer or null, so the chain's length cannot be held to it.` },
259
+ };
260
+ }
261
+ }
262
+ if (supplied !== undefined && held !== supplied) {
263
+ return {
264
+ entryCount,
265
+ applied: true,
266
+ finding: {
267
+ position: Math.min(held, supplied) + 1,
268
+ code: 'CHAIN_POSITION_GAP',
269
+ detail: `The export carries ${held} ${held === 1 ? 'entry' : 'entries'} and expectedEntryCount, supplied by the caller, is ${supplied}: ${held < supplied ? 'entries were removed from the end' : 'entries were added past the end'} of the chain.`,
270
+ },
271
+ };
272
+ }
273
+ if (entryCount.expectedEntries !== null && held < entryCount.expectedEntries) {
274
+ return {
275
+ entryCount,
276
+ applied: true,
277
+ finding: {
278
+ position: entryCount.expectedEntries,
279
+ code: 'CHECKPOINT_ROW_MISSING',
280
+ detail: `The export states a signed checkpoint at position ${entryCount.expectedEntries} and carries ${held} ${held === 1 ? 'entry' : 'entries'}: the chain was cut below its checkpoint.`,
281
+ },
282
+ };
283
+ }
284
+ if (entryCount.statedEntries !== null && held < entryCount.statedEntries) {
285
+ return {
286
+ entryCount,
287
+ applied: true,
288
+ finding: {
289
+ position: held + 1,
290
+ code: 'CHAIN_POSITION_GAP',
291
+ detail: `The export states ${entryCount.statedEntries} entries and carries ${held}: entries were removed from the end after the Server wrote it.`,
292
+ },
293
+ };
294
+ }
295
+ return { entryCount, applied: supplied !== undefined || entryCount.expectedEntries !== null || entryCount.statedEntries !== null };
296
+ }
297
+ /**
298
+ * The record id the export is about, taken from what it signs. The id in
299
+ * `exportMetadata` is unsigned, so it is held to the id each entry's signed
300
+ * predicate names and to the entry's own `recordId` column: any disagreement,
301
+ * among the entries or with the metadata, fails CHAIN_PAYLOAD_BINDING_MISMATCH,
302
+ * and the id reported is the signed one, never the metadata's.
303
+ */
304
+ function signedRecordId(stated, entries) {
305
+ const seen = [];
306
+ entries.forEach((raw, i) => {
307
+ if (!isRecord(raw))
308
+ return;
309
+ const position = typeof raw.chainPosition === 'number' ? raw.chainPosition : typeof raw.position === 'number' ? raw.position : i + 1;
310
+ if (typeof raw.recordId === 'string')
311
+ seen.push({ id: raw.recordId, position, source: 'its recordId column' });
312
+ const integrity = raw.integrity;
313
+ if (!isRecord(integrity) || typeof integrity.coseSign1 !== 'string')
314
+ return;
315
+ const parts = decodeCoseSign1(Buffer.from(integrity.coseSign1, 'base64'));
316
+ const signed = parts === null ? null : decodePredicate(parts.payloadBstr)?.['record_id'];
317
+ if (typeof signed === 'string')
318
+ seen.push({ id: signed, position, source: 'its signed predicate' });
319
+ });
320
+ const statedId = typeof stated === 'string' ? stated : '';
321
+ const first = seen.find((s) => s.source === 'its signed predicate') ?? seen[0];
322
+ if (first === undefined)
323
+ return { recordId: statedId };
324
+ const same = (a, b) => a.toLowerCase() === b.toLowerCase();
325
+ const other = seen.find((s) => !same(s.id, first.id));
326
+ if (other === undefined && same(statedId, first.id))
327
+ return { recordId: first.id };
328
+ return {
329
+ recordId: first.id,
330
+ finding: {
331
+ position: (other ?? first).position,
332
+ code: 'CHAIN_PAYLOAD_BINDING_MISMATCH',
333
+ detail: other !== undefined
334
+ ? `The entries of this export name different records: ${first.id} (${first.source}) and ${other.id} (${other.source}).`
335
+ : `The entries of this export are about record ${first.id} (${first.source}) and exportMetadata.recordId says ${JSON.stringify(stated)}: the unsigned metadata was edited.`,
336
+ },
198
337
  };
199
338
  }
200
- const EXPORT_OPTIONS = ['publicKeys', 'requireKeyId', 'requireSuppliedKeys', 'trustAnchors', 'distrustedKeys', 'agentKeys', 'federationKeys'];
339
+ const EXPORT_OPTIONS = ['publicKeys', 'requireKeyId', 'requireSuppliedKeys', 'trustAnchors', 'distrustedKeys', 'agentKeys', 'federationKeys', 'allowAfterRetirement', 'expectedEntryCount'];
201
340
  function isKeysEnvelope(value) {
202
341
  return isRecord(value) && Array.isArray(value.data);
203
342
  }
@@ -276,12 +415,14 @@ function earlyFailure(recordId, totalEntries, detail) {
276
415
  key_anchoring: 'skipped_no_input',
277
416
  federation_wire: 'skipped_no_input',
278
417
  evidence_binding: 'skipped_no_input',
418
+ entry_count: 'skipped_no_input',
279
419
  },
280
420
  keyProvenance: { supplied: 0, embedded: 0 },
281
421
  unsignedProjectionFields: [],
282
422
  agentSignatures: { present: 0, verified: 0 },
283
423
  federationWire: { present: 0, verified: 0, failed: 0, afterRetirement: 0 },
284
424
  evidenceBinding: { present: 0, verified: 0, clientHashed: 0, failed: 0 },
425
+ entryCount: { expectedEntries: null, statedEntries: null },
285
426
  keyTrust: reportKeyTrust(new Map(), null, null),
286
427
  verdict: 'failed',
287
428
  };
@@ -312,7 +453,7 @@ function resolveKeys(exportData, options) {
312
453
  });
313
454
  }
314
455
  }
315
- // Attach activation/retirement windows from exportMetadata (engine ≥ v0.26.x).
456
+ // Attach activation/retirement windows from exportMetadata (Server 0.26 and later).
316
457
  // Older exports omit signingKeyWindows; keys stay without a window and
317
458
  // verifyChain reports `key_temporal` as `skipped_no_input`.
318
459
  const windows = meta.signingKeyWindows;
@@ -0,0 +1,9 @@
1
+ import type { DecodeOptions } from 'cborg';
2
+ /**
3
+ * Decode options for every CBOR value this package reads. The signed bytes
4
+ * are deterministic CBOR (RFC 8949 section 4.2.1), so anything a conforming
5
+ * encoder would not emit is refused rather than tolerated: duplicate map
6
+ * keys (two readers could take different values), non-minimal integer and
7
+ * length encodings, indefinite lengths, `undefined`, and invalid UTF-8.
8
+ */
9
+ export declare const STRICT_CBOR_DECODE: Pick<DecodeOptions, 'strict' | 'allowIndefinite' | 'allowUndefined' | 'rejectDuplicateMapKeys' | 'rejectInvalidUtf8'>;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Decode options for every CBOR value this package reads. The signed bytes
3
+ * are deterministic CBOR (RFC 8949 section 4.2.1), so anything a conforming
4
+ * encoder would not emit is refused rather than tolerated: duplicate map
5
+ * keys (two readers could take different values), non-minimal integer and
6
+ * length encodings, indefinite lengths, `undefined`, and invalid UTF-8.
7
+ */
8
+ export const STRICT_CBOR_DECODE = {
9
+ strict: true,
10
+ allowIndefinite: false,
11
+ allowUndefined: false,
12
+ rejectDuplicateMapKeys: true,
13
+ rejectInvalidUtf8: true,
14
+ };
package/dist/chain.d.ts CHANGED
@@ -19,7 +19,7 @@
19
19
  * inputs): binding-integrity, OIDC-actor cross-check, temporal
20
20
  * key-validity, the agent-signature re-check, and key anchoring (a
21
21
  * registry marked by `applyKeyTrust`). The first three run on
22
- * the dump and on any export from an engine that ships the row fields
22
+ * the dump and on any export from a Server that ships the row fields
23
23
  * (>= v0.26.x). The agent-signature check needs the cert's public key,
24
24
  * which neither surface carries, so it runs only when the caller passes
25
25
  * `agentKeys`. A check without its input is reported `skipped_no_input`,
@@ -29,7 +29,7 @@
29
29
  * branch comes LAST, after the binding/OIDC checks, so a row written without a
30
30
  * signing key is still subject to every structural check, and a tamper finding
31
31
  * on it is reported under its own code rather than as CHAIN_ENTRY_UNSIGNED.
32
- * That branch grades the entry the way the engine does: an unsigned entry
32
+ * That branch grades the entry the way the Server does: an unsigned entry
33
33
  * after a signed one in its chain, or written at or after the earliest key
34
34
  * activation (`signingSince`), is CHAIN_ENTRY_UNSIGNED; an earlier one is a
35
35
  * `skipped` signature, reduced coverage rather than a break.
@@ -58,18 +58,18 @@ export type KeyTrustState = 'anchored' | 'unanchored' | 'undecided';
58
58
  /** A public key the walk can verify signatures against. */
59
59
  export interface VerificationKey {
60
60
  keyId: string;
61
- /** SPKI DER, base64-encoded (the engine's vault_signing_keys.public_key shape). */
61
+ /** SPKI DER, base64-encoded (the shape the Server's key registry publishes). */
62
62
  spkiBase64: string;
63
63
  /**
64
64
  * `supplied` = passed by the caller. `embedded` = shipped inside the
65
- * artifact being verified (the export or dump the engine produced). Surfaced
65
+ * artifact being verified (the export or dump the Server produced). Surfaced
66
66
  * in the result so a caller can tell whether it verified against a key it
67
67
  * brought or against the artifact's own answer key.
68
68
  */
69
69
  source: KeySource;
70
70
  /**
71
- * Algorithm the key registry DECLARES for this key (the engine's
72
- * `vault_signing_keys.algorithm` column), when the input surface carries it.
71
+ * Algorithm the key registry DECLARES for this key (the Server's
72
+ * registry algorithm field), when the input surface carries it.
73
73
  * Cross-checked against the algorithm the SPKI key material actually commits
74
74
  * to: a divergence means the registry row lies about its own key and fails
75
75
  * CHAIN_ALG_MISMATCH. The declared string never selects the verification
@@ -116,7 +116,7 @@ export type KeyRegistry = ReadonlyMap<string, VerificationKey>;
116
116
  export declare function buildKeyRegistry(keys: readonly VerificationKey[]): KeyRegistry;
117
117
  /**
118
118
  * Agent cert keys for the agent-signature check, indexed by the RFC 7638
119
- * thumbprint (`sha256:<hex>`) the engine seals as
119
+ * thumbprint (`sha256:<hex>`) the Server seals as
120
120
  * `predicate.on_behalf_of.cert.thumbprint`. Values are SPKI DER, base64.
121
121
  */
122
122
  export type AgentKeyRegistry = ReadonlyMap<string, string>;
@@ -140,7 +140,7 @@ export interface NormalizedEntry {
140
140
  signingKeyId: string | null;
141
141
  /**
142
142
  * ISO-8601 write time, for temporal key-validity and the unsigned-entry
143
- * rule. The engine writes one on every entry, so wherever the walk needs it
143
+ * rule. The Server writes one on every entry, so wherever the walk needs it
144
144
  * (the entry's key carries a window, or the entry is unsigned and the key
145
145
  * set dates the start of signing) a missing or unparseable value fails
146
146
  * CHAIN_MALFORMED_ENTRY rather than skipping the check.
@@ -151,6 +151,25 @@ export interface NormalizedEntry {
151
151
  recordId: string | null;
152
152
  entryType: string;
153
153
  payload: Record<string, unknown>;
154
+ /**
155
+ * True when `payload` is a projection that carries every envelope
156
+ * extension the entry signed, as an export entry's does: the Server
157
+ * writes `on_behalf_of` and `traceparent` into it from the signed
158
+ * predicate. Then a signed extension missing from `payload` is a
159
+ * mismatch. A vault row's payload never holds them, so the dump path
160
+ * leaves this unset.
161
+ */
162
+ extensionsProjected?: boolean;
163
+ };
164
+ /**
165
+ * Set on an entry that lacks the `binding` inputs where the walk needs them
166
+ * (a sibling carries them, or the caller supplied federation keys), with
167
+ * what is missing. The entry then fails CHAIN_PAYLOAD_BINDING_MISMATCH
168
+ * rather than reading as an entry with nothing to check.
169
+ */
170
+ bindingRequired?: {
171
+ detail: string;
172
+ federationWire: boolean;
154
173
  };
155
174
  /** Inputs for the OIDC-actor cross-check (dump path). */
156
175
  oidcActor?: {
@@ -181,7 +200,7 @@ export interface NormalizedEntry {
181
200
  }
182
201
  /**
183
202
  * Checks that run only when their input is present. `agent_signature` is
184
- * applied when at least one entry carrying an engine-validated agent signature
203
+ * applied when at least one entry carrying a Server-validated agent signature
185
204
  * had its cert key supplied by the caller (`agentKeys`); neither the export
186
205
  * nor the dump carries cert public keys.
187
206
  */
@@ -197,9 +216,9 @@ export interface SignatureOutcome {
197
216
  /**
198
217
  * - `ok` / `invalid` / `decode-fail`: the signature was checked (and passed,
199
218
  * failed, or the envelope would not decode).
200
- * - `unsigned`: retained for type compatibility; `verifyChain` no longer
201
- * produces it. An all-zero signature on an entry that names a key is
202
- * `invalid` (CHAIN_SIGNATURE_INVALID), as the engine grades it.
219
+ * - `unsigned`: kept for type compatibility; `verifyChain` does not
220
+ * produce it. An all-zero signature on an entry that names a key is
221
+ * `invalid` (CHAIN_SIGNATURE_INVALID), as the Server grades it.
203
222
  * - `skipped`: the chain is intact but this entry has no signing key, so the
204
223
  * signature check was deliberately not run. Only an entry written before
205
224
  * the install began signing gets here: before any signed entry in its
@@ -247,13 +266,13 @@ export type AccountedEntryCode = typeof ACCOUNTED_ENTRY_CODE;
247
266
  * `distrustedKeys` names, that falls outside what the key is trusted for
248
267
  * (the key is unanchored, or the entry was written at or after its cutoff),
249
268
  * and that was written before a key the walk trusts retired it. The distrust
250
- * entry and that retirement account for it, as the engine's scan lists it in
269
+ * entry and that retirement account for it, as the Server's scan lists it in
251
270
  * `distrustedEntries`: it is listed, it is not verified, and it fails
252
271
  * nothing. An entry written after that retirement, or under a distrusted key
253
272
  * no trusted key has retired, fails as before (CHAIN_SIGNING_KEY_UNANCHORED
254
273
  * or CHAIN_KEY_EXPIRED). An audit export never carries one.
255
274
  *
256
- * `chain` and `recordId`/`orgId` name the chain as the engine does: a record
275
+ * `chain` and `recordId`/`orgId` name the chain as the Server does: a record
257
276
  * chain by its record id, the platform-ops chain (record id
258
277
  * 00000000-0000-0000-0000-000000000000) as `admin`, and an org's schema chain
259
278
  * (`schema:<orgId>`, `schema:__platform__` for the platform's) as `schema`.
@@ -367,7 +386,7 @@ export interface VerifyChainOptions {
367
386
  requireSuppliedKeys?: boolean;
368
387
  /**
369
388
  * Agent cert keys (see `buildAgentKeyRegistry`). When an entry's signed
370
- * payload carries an engine-validated `on_behalf_of.agent_signature` and its
389
+ * payload carries a Server-validated `on_behalf_of.agent_signature` and its
371
390
  * sealed cert thumbprint matches a key here, the signature is re-verified
372
391
  * offline; a failure is CHAIN_AGENT_SIGNATURE_INVALID.
373
392
  */
@@ -380,6 +399,14 @@ export interface VerifyChainOptions {
380
399
  * the sealed body are checked on every sealed message, with or without a key.
381
400
  */
382
401
  federationKeys?: FederationKeyRegistry;
402
+ /**
403
+ * Accept a sealed federation message signed by a key its sender's history
404
+ * had retired before the message was signed (beyond the clock-skew
405
+ * allowance), counting it in `federationWire.afterRetirement`. For the short
406
+ * gap while a publisher restarts onto its new key. Without it such a
407
+ * message fails CHAIN_FEDERATION_WIRE_INVALID.
408
+ */
409
+ allowAfterRetirement?: boolean;
383
410
  /**
384
411
  * The instant this install began signing: the earliest `activatedAt` across
385
412
  * its whole signing key set, retired keys included. An entry with a null
@@ -399,9 +426,9 @@ export interface VerifyChainOptions {
399
426
  /**
400
427
  * The earliest `activatedAt` among `keys`, as the ISO string it was given in,
401
428
  * or `null` when no key carries a parseable one. This is the instant from
402
- * which the engine treats every chain entry and checkpoint as required to be
429
+ * which the Server treats every chain entry and checkpoint as required to be
403
430
  * signed; pass every key the verifier knows, retired ones included, since the
404
- * engine reads it as `min(activated_at)` over its whole key registry.
431
+ * Server reads it as `min(activated_at)` over its whole key registry.
405
432
  */
406
433
  export declare function earliestKeyActivation(keys: Iterable<{
407
434
  activatedAt?: string | null;
@@ -415,7 +442,7 @@ export declare function earliestKeyActivation(keys: Iterable<{
415
442
  *
416
443
  * False when `signingSince` is absent or unparseable: with no instant from
417
444
  * which the install signs, nothing has to be signed. True when `signingSince`
418
- * is known and `writtenAt` is missing or not strict RFC 3339: the engine times every
445
+ * is known and `writtenAt` is missing or not strict RFC 3339: the Server times every
419
446
  * row, so a row with no readable time was edited, and it cannot be placed
420
447
  * before signing began. It fails closed rather than reading as early history.
421
448
  */
@@ -426,3 +453,44 @@ export declare function writtenWhileSigning(writtenAt: unknown, signingSince: st
426
453
  * validates the true chain; tampering surfaces through the hash links).
427
454
  */
428
455
  export declare function verifyChain(entries: readonly NormalizedEntry[], keys: KeyRegistry, options?: VerifyChainOptions): ChainResult;
456
+ /**
457
+ * Where a signed artifact other than a chain entry falls against the window
458
+ * of the key that signed it. `inside`: the key's window covers its write time,
459
+ * or the key carries no window. `accounted`: it was written at or after the
460
+ * instant `distrustedKeys` gives for the key and before a key the walk trusts
461
+ * retired it. `not-yet-active` and `expired`: outside the window. `unplaceable`:
462
+ * the write time or a window edge is not an RFC 3339 instant, so the artifact
463
+ * cannot be placed and the caller fails closed.
464
+ */
465
+ export type KeyWindowPlacement = {
466
+ placement: 'inside' | 'accounted';
467
+ } | {
468
+ placement: 'not-yet-active' | 'expired' | 'unplaceable';
469
+ detail: string;
470
+ };
471
+ /**
472
+ * Place a vault checkpoint, a read-log leaf or a read-log tree head in the
473
+ * signed window of its key, by the time its row was written. The rule is the
474
+ * one chain entries are held to (CHAIN_KEY_NOT_YET_ACTIVE, CHAIN_KEY_EXPIRED):
475
+ * each edge is checked only when the key carries it, at millisecond
476
+ * precision, and an artifact written exactly at the key's retirement is
477
+ * inside. `what` names the artifact in the detail ("Checkpoint", "Leaf").
478
+ *
479
+ * The caller verifies the signature first: the Server reports a signature
480
+ * that does not verify ahead of a window finding.
481
+ */
482
+ export declare function placeInKeyWindow(key: VerificationKey, writtenAt: unknown, what: string): KeyWindowPlacement;
483
+ /**
484
+ * Whether a `distrustedKeys` entry and the retirement a trusted key signed
485
+ * account for an artifact signed under `key` and written at `writtenAt`: the
486
+ * key is unanchored only because of the entry, or anchored and the artifact
487
+ * written at or after the entry's instant, and in both cases the artifact was
488
+ * written before that retirement. The same condition lists a chain entry as
489
+ * CHAIN_SIGNED_BY_DISTRUSTED_KEY.
490
+ *
491
+ * Such an artifact is listed, never verified, and never evidence for or
492
+ * against anything else. The caller still verifies its signature under the
493
+ * key before setting it aside: anything else under the key's id is bytes
494
+ * whoever writes to the database wrote.
495
+ */
496
+ export declare function distrustAccounts(key: VerificationKey, writtenAt: unknown): boolean;