@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.
package/dist/chain.js 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.
@@ -91,9 +91,9 @@ export function chainOfScope(scopeId) {
91
91
  /**
92
92
  * The earliest `activatedAt` among `keys`, as the ISO string it was given in,
93
93
  * or `null` when no key carries a parseable one. This is the instant from
94
- * which the engine treats every chain entry and checkpoint as required to be
94
+ * which the Server treats every chain entry and checkpoint as required to be
95
95
  * signed; pass every key the verifier knows, retired ones included, since the
96
- * engine reads it as `min(activated_at)` over its whole key registry.
96
+ * Server reads it as `min(activated_at)` over its whole key registry.
97
97
  */
98
98
  export function earliestKeyActivation(keys) {
99
99
  let earliest = null;
@@ -117,7 +117,7 @@ export function earliestKeyActivation(keys) {
117
117
  *
118
118
  * False when `signingSince` is absent or unparseable: with no instant from
119
119
  * which the install signs, nothing has to be signed. True when `signingSince`
120
- * is known and `writtenAt` is missing or not strict RFC 3339: the engine times every
120
+ * is known and `writtenAt` is missing or not strict RFC 3339: the Server times every
121
121
  * row, so a row with no readable time was edited, and it cannot be placed
122
122
  * before signing began. It fails closed rather than reading as early history.
123
123
  */
@@ -150,7 +150,7 @@ function positionKey(position) {
150
150
  * validates the true chain; tampering surfaces through the hash links).
151
151
  */
152
152
  export function verifyChain(entries, keys, options = {}) {
153
- assertKnownOptions('verifyChain', options, ['requireKeyId', 'requireSuppliedKeys', 'agentKeys', 'federationKeys', 'signingSince']);
153
+ assertKnownOptions('verifyChain', options, ['requireKeyId', 'requireSuppliedKeys', 'agentKeys', 'federationKeys', 'allowAfterRetirement', 'signingSince']);
154
154
  const scopeId = entries[0]?.scopeId ?? '(empty)';
155
155
  const sorted = entries
156
156
  .map((entry, at) => ({ entry, at, key: positionKey(entry.chainPosition) }))
@@ -203,23 +203,30 @@ export function verifyChain(entries, keys, options = {}) {
203
203
  }
204
204
  }
205
205
  const mustSign = { signedBefore: false, signingSince };
206
+ const unbound = { payload: false, federation: false };
206
207
  let previousHash = null;
207
208
  for (let i = 0; i < sorted.length; i++) {
208
209
  const entry = sorted[i];
209
210
  const expectedPosition = i + 1;
210
211
  let result = verifyEntry(entry, expectedPosition, previousHash, keys, options, optionalChecks, mustSign);
211
- // As the engine's walk does: any earlier row naming a key, whatever its own
212
+ // As the Server's walk does: any earlier row naming a key, whatever its own
212
213
  // verdict, means this chain was already being signed.
213
214
  if (entry.signingKeyId !== null)
214
215
  mustSign.signedBefore = true;
215
216
  if (result.valid && result.accounted === undefined) {
216
217
  result = checkAgentSignature(entry, result, options.agentKeys, optionalChecks, agentSignatures);
217
218
  }
219
+ if (result.valid && result.accounted === undefined && entry.binding === undefined && entry.bindingRequired !== undefined) {
220
+ unbound.payload = true;
221
+ if (entry.bindingRequired.federationWire)
222
+ unbound.federation = true;
223
+ result = failAfterSignature(entry, result, 'CHAIN_PAYLOAD_BINDING_MISMATCH', entry.bindingRequired.detail);
224
+ }
218
225
  if (result.valid && result.accounted === undefined && entry.binding !== undefined) {
219
- result = checkSealedFederationWire(entry, result, options.federationKeys, optionalChecks, federationWire);
226
+ result = checkSealedFederationWire(entry, result, options.federationKeys, optionalChecks, federationWire, options.allowAfterRetirement === true);
220
227
  }
221
228
  if (result.valid && result.accounted === undefined && entry.inlinedEvidence !== undefined) {
222
- result = checkInlinedEvidence(entry, result, optionalChecks, evidenceBinding);
229
+ result = checkInlinedEvidence(entry, entry.inlinedEvidence.value, result, optionalChecks, evidenceBinding);
223
230
  }
224
231
  entryResults.push(result);
225
232
  if (result.accounted !== undefined) {
@@ -254,9 +261,16 @@ export function verifyChain(entries, keys, options = {}) {
254
261
  // 'not-checked' / 'invalid' / 'decode-fail' / 'unsupported' are failure
255
262
  // states: the entry is already counted as broken, so it contributes to
256
263
  // no coverage bucket.
264
+ default:
265
+ break;
257
266
  }
258
267
  previousHash = entry.payloadHash;
259
268
  }
269
+ // A check some entry could not take part in is not a check that ran.
270
+ if (unbound.payload)
271
+ optionalChecks.payload_binding = 'not_checked';
272
+ if (unbound.federation)
273
+ optionalChecks.federation_wire = 'not_checked';
260
274
  // The caller walked the key statements (every key carries a verdict), but no
261
275
  // entry got as far as the anchoring check.
262
276
  if (optionalChecks.key_anchoring === 'skipped_no_input' && [...keys.values()].some((k) => k.trust !== undefined)) {
@@ -292,14 +306,13 @@ const EVIDENCE_HASH_FIELD = {
292
306
  * signs a hash its submitter computed over the cleartext, and the export
293
307
  * inlines the ciphertext, so it is counted and left unbound.
294
308
  */
295
- function checkInlinedEvidence(entry, result, optionalChecks, counts) {
309
+ function checkInlinedEvidence(entry, body, result, optionalChecks, counts) {
296
310
  optionalChecks.evidence_binding = 'applied';
297
311
  counts.present++;
298
312
  const failed = (detail) => {
299
313
  counts.failed++;
300
314
  return failAfterSignature(entry, result, 'CHAIN_EVIDENCE_BINDING_MISMATCH', detail);
301
315
  };
302
- const body = entry.inlinedEvidence.value;
303
316
  if (entry.binding === undefined) {
304
317
  return failed('The entry inlines an evidence body but carries no payload, so no signed hash binds the body to the chain.');
305
318
  }
@@ -332,7 +345,7 @@ function checkInlinedEvidence(entry, result, optionalChecks, counts) {
332
345
  * its agreement with the entry, and, under a supplied key for the sending
333
346
  * hub, its signature. See `federation-wire.ts`.
334
347
  */
335
- function checkSealedFederationWire(entry, result, federationKeys, optionalChecks, counts) {
348
+ function checkSealedFederationWire(entry, result, federationKeys, optionalChecks, counts, allowAfterRetirement) {
336
349
  if (entry.binding === undefined)
337
350
  return result;
338
351
  const wire = extractFederationWire(entry.binding.payload);
@@ -343,7 +356,7 @@ function checkSealedFederationWire(entry, result, federationKeys, optionalChecks
343
356
  return failAfterSignature(entry, result, 'CHAIN_FEDERATION_WIRE_INVALID', 'payload.wire is present but is not a sealed federation message (an object with scheme, senderHubId, senderPublicKey, recipientHubId, method, path, bodyHash, timestamp, nonce, signature and an object body).');
344
357
  }
345
358
  counts.present++;
346
- const outcome = checkFederationWire(entry.binding.entryType, entry.binding.recordId, entry.binding.payload, wire, federationKeys);
359
+ const outcome = checkFederationWire(entry.binding.entryType, entry.binding.recordId, entry.binding.payload, wire, federationKeys, { allowAfterRetirement });
347
360
  if (outcome.outcome === 'ok') {
348
361
  if (outcome.signatureChecked)
349
362
  counts.verified++;
@@ -358,10 +371,10 @@ function checkSealedFederationWire(entry, result, federationKeys, optionalChecks
358
371
  }
359
372
  /**
360
373
  * Offline re-check of a sealed agent signature, on an entry that already
361
- * passed every other check (so its payload is the engine's signed bytes).
374
+ * passed every other check (so its payload is the Server's signed bytes).
362
375
  *
363
- * Runs only on an engine-validated identity (`on_behalf_of.validated: true`).
364
- * On a caller-asserted one, entries written before the engine sealed these
376
+ * Runs only on a Server-validated identity (`on_behalf_of.validated: true`).
377
+ * On a caller-asserted one, entries written before the Server sealed these
365
378
  * fields itself carry them as caller passthrough, and the marker telling the
366
379
  * two apart is a column neither the export nor the dump publishes, so a
367
380
  * failure there could not be told from a claim nobody ever checked.
@@ -446,14 +459,14 @@ function verifyEntry(entry, expectedPosition, expectedPrevHash, keys, options, o
446
459
  return fail(scopeId, expectedPosition, 'CHAIN_COSE_HEADER_MISMATCH', `Signed protected-header chain claim (position=${chainClaim?.position ?? 'null'}, prev=${chainClaim?.previous_hash ?? 'null'}) diverges from row columns (position=${entry.chainPosition}, prev=${entry.previousHash ?? 'null'}).`);
447
460
  }
448
461
  // Input-gated: actor attribution. The row's actorId/actorOwnerId columns are
449
- // the projection a report displays as "who did this", and the engine's own
462
+ // the projection a report displays as "who did this", and the Server's own
450
463
  // export guide names them as the trustworthy attribution while listing only
451
464
  // actorDisplayName / actorOwnerType / humanReadableLabel as unsigned. They
452
465
  // are signature-covered, at CWT_Claims label 15 -> private label -65539, so
453
466
  // a rewritten column is a re-attribution of the action to another actor and
454
467
  // must not verify. Same shape as the signed-kid check above: compare the
455
468
  // column against the signed claim, and skip only when one side is absent
456
- // (an older engine that never carried the claim, or an artifact that does
469
+ // (an older Server that never carried the claim, or an artifact that does
457
470
  // not carry the columns).
458
471
  const attribution = entry.actorAttribution;
459
472
  if (attribution) {
@@ -476,7 +489,7 @@ function verifyEntry(entry, expectedPosition, expectedPrevHash, keys, options, o
476
489
  }
477
490
  }
478
491
  // Input-gated: binding-integrity. Runs whenever the row payload is present:
479
- // the dump always carries it, and the export now carries it too (engine ≥ v0.26.x).
492
+ // the dump always carries it, and the export now carries it too (Server ≥ v0.26.x).
480
493
  if (entry.binding) {
481
494
  optionalChecks.payload_binding = 'applied';
482
495
  const decodedRaw = decodePredicate(parts.payloadBstr);
@@ -486,8 +499,8 @@ function verifyEntry(entry, expectedPosition, expectedPrevHash, keys, options, o
486
499
  decoded === null ||
487
500
  rebuilt === null ||
488
501
  !deepEqual(rebuilt, decoded) ||
489
- !envelopeExtensionsMatch(entry.binding.payload, decodedRaw)) {
490
- return fail(scopeId, expectedPosition, 'CHAIN_PAYLOAD_BINDING_MISMATCH', 'Denormalised row payload no longer matches the canonical projection of the signed predicate.');
502
+ !envelopeExtensionsMatch(entry.binding.payload, decodedRaw, entry.binding.extensionsProjected === true)) {
503
+ return fail(scopeId, expectedPosition, 'CHAIN_PAYLOAD_BINDING_MISMATCH', 'Denormalised row payload does not match the canonical projection of the signed predicate.');
491
504
  }
492
505
  }
493
506
  // Input-gated: OIDC-actor cross-check. Only when the dump carried the columns.
@@ -498,12 +511,12 @@ function verifyEntry(entry, expectedPosition, expectedPrevHash, keys, options, o
498
511
  return oidcFailure;
499
512
  }
500
513
  // Signature (last, so a null-key row still ran every structural check above).
501
- // Only a true null is the engine's unsigned-mode marker. Any other value,
502
- // including the empty string no engine emits, must resolve in the registry
514
+ // Only a true null is the Server's unsigned-mode marker. Any other value,
515
+ // including the empty string no Server emits, must resolve in the registry
503
516
  // and fails CHAIN_SIGNATURE_MISSING_KEY below: a truthiness shortcut here
504
517
  // would let a tampered signingKeyId:"" row skip its signature check.
505
518
  if (entry.signingKeyId === null) {
506
- // Engine mirror of `signature_missing`. An unsigned entry is reduced
519
+ // Server mirror of `signature_missing`. An unsigned entry is reduced
507
520
  // coverage only where the install had not yet begun to sign: before any
508
521
  // signed entry in this chain, and before the earliest key activation.
509
522
  // Anywhere else no process of the install could have written it; it is
@@ -513,7 +526,7 @@ function verifyEntry(entry, expectedPosition, expectedPrevHash, keys, options, o
513
526
  if (mustSign.signedBefore) {
514
527
  return fail(scopeId, expectedPosition, 'CHAIN_ENTRY_UNSIGNED', 'Entry has no signingKeyId but follows a signed entry in the same chain.');
515
528
  }
516
- // The engine times every entry. Without a time the walk can read, an
529
+ // The Server times every entry. Without a time the walk can read, an
517
530
  // unsigned entry cannot be placed before signing began, so it is not
518
531
  // early history: it fails closed.
519
532
  if (mustSign.signingSince !== null && !isInstant(entry.createdAt)) {
@@ -541,8 +554,8 @@ function verifyEntry(entry, expectedPosition, expectedPrevHash, keys, options, o
541
554
  if (options.requireSuppliedKeys && key.source !== 'supplied') {
542
555
  return fail(scopeId, expectedPosition, 'CHAIN_KEY_POLICY_VIOLATION', `Key ${entry.signingKeyId} is embedded in the artifact; this run requires supplied keys.`);
543
556
  }
544
- // Signed-kid binding (engine mirror: signing_key_drift), ahead of every
545
- // question about the key, as the engine orders it. The row's signingKeyId
557
+ // Signed-kid binding (Server mirror: signing_key_drift), ahead of every
558
+ // question about the key, as the Server orders it. The row's signingKeyId
546
559
  // column selected the key above, but the column is a denormalized
547
560
  // convenience; the kid at protected-header label 4 is signature-covered. A
548
561
  // divergence means the column was rewritten after signing, e.g. to point
@@ -553,7 +566,7 @@ function verifyEntry(entry, expectedPosition, expectedPrevHash, keys, options, o
553
566
  if (signedKid !== null && signedKid !== entry.signingKeyId) {
554
567
  return fail(scopeId, expectedPosition, 'CHAIN_SIGNING_KEY_DRIFT', `Row signingKeyId=${entry.signingKeyId} does not match the signature-covered kid ${signedKid} in the protected header.`);
555
568
  }
556
- // Input-gated: key anchoring (engine mirror: signing_key_unanchored). Runs
569
+ // Input-gated: key anchoring (Server mirror: signing_key_unanchored). Runs
557
570
  // when a key-statement walk marked the registry. A key nothing signed links
558
571
  // to a pinned anchor is one anything with write access to the Server's
559
572
  // database can register, so an entry under it is a forgery until shown
@@ -578,7 +591,7 @@ function verifyEntry(entry, expectedPosition, expectedPrevHash, keys, options, o
578
591
  }
579
592
  }
580
593
  // Registry self-consistency: when the input surface declares an algorithm for
581
- // this key (vault_signing_keys.algorithm), it must agree with what the SPKI
594
+ // this key, it must agree with what the SPKI
582
595
  // key material commits to. A registry row that lies about its own key is the
583
596
  // signature of a mis-registered key (the pre-guard P-256 corruption shape) or
584
597
  // a rewritten registry, and nothing verified against it can be trusted.
@@ -587,7 +600,7 @@ function verifyEntry(entry, expectedPosition, expectedPrevHash, keys, options, o
587
600
  }
588
601
  // Input-gated: temporal key-validity, whenever the key carries a window.
589
602
  // Compared at millisecond precision, the precision of an entry's write time,
590
- // truncating a microsecond window edge the way the engine does. The engine
603
+ // truncating a microsecond window edge the way the Server does. The Server
591
604
  // times every entry, so an entry with no time the walk can read cannot be
592
605
  // placed inside the window, and fails closed rather than skipping it.
593
606
  if (typeof key.activatedAt === 'string' || typeof key.retiredAt === 'string' || typeof key.distrustCutoff === 'string') {
@@ -621,7 +634,7 @@ function verifyEntry(entry, expectedPosition, expectedPrevHash, keys, options, o
621
634
  const outcome = verifyCoseSign1(envelopeBytes, key.spkiBase64);
622
635
  if (outcome === 'unsigned') {
623
636
  // An all-zero signature slot on an entry that CLAIMS a signing key. The
624
- // engine writes a key id only beside a signature it made with that key,
637
+ // Server writes a key id only beside a signature it made with that key,
625
638
  // and fails this shape `signature_invalid`, so it is a forged or wiped
626
639
  // signature, never an unsigned entry. (A genuinely unsigned entry carries
627
640
  // a null signingKeyId and is graded above.)
@@ -658,21 +671,21 @@ function checkOidcActor(oidc, payloadBstr, scopeId, position) {
658
671
  }
659
672
  return null;
660
673
  }
661
- // synthesized=false: engine writers leave the columns null. Any populated
662
- // state is a DB-level CHECK-constraint bypass.
674
+ // synthesized=false: the Server leaves the columns null. Any populated
675
+ // state means the row was altered outside the Server.
663
676
  if (synthesized === false && (rowIss !== null || rowSub !== null)) {
664
677
  return fail(scopeId, position, 'CHAIN_OIDC_ACTOR_MISMATCH', `actor_oidc_synthesized=false but iss/sub populated (${rowIss ?? 'null'}/${rowSub ?? 'null'}).`);
665
678
  }
666
679
  return null;
667
680
  }
668
681
  /**
669
- * Temporal key-validity, split by direction. Both directions used to report
670
- * `CHAIN_KEY_EXPIRED`, so a consumer branching on the code saw "expired" for a
671
- * key that had not started yet and would reason about rotation or retention
672
- * when the real condition is clock skew or backdating. Those are different
673
- * investigations, and the activation side is the security-relevant one.
682
+ * Temporal key-validity, split by direction. A key not yet active reports
683
+ * `CHAIN_KEY_NOT_YET_ACTIVE` and a retired key reports `CHAIN_KEY_EXPIRED`, so a
684
+ * consumer branching on the code does not read clock skew or backdating as
685
+ * rotation or retention. Those are different investigations, and the
686
+ * activation side is the security-relevant one.
674
687
  */
675
- function temporalKeyFailure(createdAt, key) {
688
+ function temporalKeyFailure(createdAt, key, what = 'Entry') {
676
689
  const written = rfc3339Ms(createdAt);
677
690
  if (Number.isNaN(written))
678
691
  return null;
@@ -681,7 +694,7 @@ function temporalKeyFailure(createdAt, key) {
681
694
  if (!Number.isNaN(activated) && written < activated) {
682
695
  return {
683
696
  code: 'CHAIN_KEY_NOT_YET_ACTIVE',
684
- detail: `Entry written ${createdAt} predates key ${key.keyId} activation ${key.activatedAt}.`,
697
+ detail: `${what} written ${createdAt} predates key ${key.keyId} activation ${key.activatedAt}.`,
685
698
  };
686
699
  }
687
700
  }
@@ -690,7 +703,7 @@ function temporalKeyFailure(createdAt, key) {
690
703
  if (!Number.isNaN(cutoff) && written > cutoff) {
691
704
  return {
692
705
  code: 'CHAIN_KEY_EXPIRED',
693
- detail: `Entry written ${createdAt} postdates ${key.distrustCutoff}, the instant distrustedKeys (VAULT_DISTRUSTED_KEYS on the Server) gives for key ${key.keyId}; the key was not retired then.`,
706
+ detail: `${what} written ${createdAt} postdates ${key.distrustCutoff}, the instant distrustedKeys (VAULT_DISTRUSTED_KEYS on the Server) gives for key ${key.keyId}; the key was not retired then.`,
694
707
  };
695
708
  }
696
709
  }
@@ -699,9 +712,65 @@ function temporalKeyFailure(createdAt, key) {
699
712
  if (!Number.isNaN(retired) && written > retired) {
700
713
  return {
701
714
  code: 'CHAIN_KEY_EXPIRED',
702
- detail: `Entry written ${createdAt} postdates key ${key.keyId} retirement ${key.retiredAt}.`,
715
+ detail: `${what} written ${createdAt} postdates key ${key.keyId} retirement ${key.retiredAt}.`,
703
716
  };
704
717
  }
705
718
  }
706
719
  return null;
707
720
  }
721
+ /**
722
+ * Place a vault checkpoint, a read-log leaf or a read-log tree head in the
723
+ * signed window of its key, by the time its row was written. The rule is the
724
+ * one chain entries are held to (CHAIN_KEY_NOT_YET_ACTIVE, CHAIN_KEY_EXPIRED):
725
+ * each edge is checked only when the key carries it, at millisecond
726
+ * precision, and an artifact written exactly at the key's retirement is
727
+ * inside. `what` names the artifact in the detail ("Checkpoint", "Leaf").
728
+ *
729
+ * The caller verifies the signature first: the Server reports a signature
730
+ * that does not verify ahead of a window finding.
731
+ */
732
+ export function placeInKeyWindow(key, writtenAt, what) {
733
+ if (typeof key.activatedAt !== 'string' && typeof key.retiredAt !== 'string' && typeof key.distrustCutoff !== 'string') {
734
+ return { placement: 'inside' };
735
+ }
736
+ for (const [edge, value] of [['activatedAt', key.activatedAt], ['retiredAt', key.retiredAt], ['distrustCutoff', key.distrustCutoff]]) {
737
+ if (typeof value === 'string' && !isInstant(value)) {
738
+ return { placement: 'unplaceable', detail: `Key ${key.keyId}'s ${edge} ${JSON.stringify(value)} is not an RFC 3339 instant, so the ${what.toLowerCase()} cannot be placed inside its window.` };
739
+ }
740
+ }
741
+ if (!isInstant(writtenAt)) {
742
+ return { placement: 'unplaceable', detail: `${what} has no parseable write time, so it cannot be placed inside key ${key.keyId}'s window.` };
743
+ }
744
+ const temporal = temporalKeyFailure(writtenAt, key, what);
745
+ if (temporal === null)
746
+ return { placement: 'inside' };
747
+ const span = key.distrustSpan;
748
+ const written = rfc3339Ms(writtenAt);
749
+ if (temporal.code === 'CHAIN_KEY_EXPIRED' && span !== undefined && span.cutoff !== null && span.retiredAt !== null
750
+ && written >= instantMs(span.cutoff) && written < instantMs(span.retiredAt)) {
751
+ return { placement: 'accounted' };
752
+ }
753
+ return { placement: temporal.code === 'CHAIN_KEY_EXPIRED' ? 'expired' : 'not-yet-active', detail: temporal.detail };
754
+ }
755
+ /**
756
+ * Whether a `distrustedKeys` entry and the retirement a trusted key signed
757
+ * account for an artifact signed under `key` and written at `writtenAt`: the
758
+ * key is unanchored only because of the entry, or anchored and the artifact
759
+ * written at or after the entry's instant, and in both cases the artifact was
760
+ * written before that retirement. The same condition lists a chain entry as
761
+ * CHAIN_SIGNED_BY_DISTRUSTED_KEY.
762
+ *
763
+ * Such an artifact is listed, never verified, and never evidence for or
764
+ * against anything else. The caller still verifies its signature under the
765
+ * key before setting it aside: anything else under the key's id is bytes
766
+ * whoever writes to the database wrote.
767
+ */
768
+ export function distrustAccounts(key, writtenAt) {
769
+ if (key.trust === 'undecided' || declaredAlgorithmLies(key))
770
+ return false;
771
+ if (key.trust === 'unanchored') {
772
+ const bound = key.distrustSpan?.retiredAt ?? null;
773
+ return bound !== null && isInstant(writtenAt) && rfc3339Ms(writtenAt) < instantMs(bound);
774
+ }
775
+ return placeInKeyWindow(key, writtenAt, 'Artifact').placement === 'accounted';
776
+ }
@@ -41,48 +41,62 @@
41
41
  * verdict, never a silent pass.
42
42
  *
43
43
  * Later additions:
44
- * - CHAIN_ENTRY_UNSIGNED engine mirror of `signature_missing`: an entry with
44
+ * - CHAIN_ENTRY_UNSIGNED Server mirror of `signature_missing`: an entry with
45
45
  * no signing key id after a signed entry in its
46
46
  * chain, or written at or after the earliest
47
47
  * activatedAt in the key set. Earlier unsigned
48
48
  * entries stay reduced coverage.
49
- * - CHECKPOINT_UNSIGNED engine mirror of `checkpoint_unsigned`: the same
49
+ * - CHECKPOINT_UNSIGNED Server mirror of `checkpoint_unsigned`: the same
50
50
  * instant, applied to an unsigned checkpoint.
51
51
  * - TENANT_READ_LEAF_UNSIGNED and TENANT_CHECKPOINT_UNSIGNED the same two
52
- * rules on the org_admin_reads log (engine
52
+ * rules on the org_admin_reads log (Server
53
53
  * `leaf_signature_missing`, `checkpoint_unsigned`).
54
- * - CHAIN_SIGNING_KEY_UNANCHORED engine mirror of `signing_key_unanchored`:
54
+ * - CHAIN_SIGNING_KEY_UNANCHORED Server mirror of `signing_key_unanchored`:
55
55
  * the entry's key is not linked by signed key
56
56
  * statements to a pinned trust anchor. With
57
57
  * CHECKPOINT_KEY_UNANCHORED,
58
58
  * TENANT_READ_KEY_UNANCHORED and
59
59
  * TENANT_CHECKPOINT_KEY_UNANCHORED for the
60
- * engine's `checkpoint_key_unanchored` and
60
+ * Server's `checkpoint_key_unanchored` and
61
61
  * `leaf_key_unanchored`.
62
+ * - CHECKPOINT_KEY_NOT_YET_ACTIVE, CHECKPOINT_KEY_EXPIRED, and the
63
+ * TENANT_READ_KEY_* and TENANT_CHECKPOINT_KEY_* pairs Server mirror of
64
+ * `checkpoint_key_not_yet_active`,
65
+ * `checkpoint_key_expired`, `leaf_key_not_yet_active`
66
+ * and `leaf_key_expired`: a vault checkpoint, a
67
+ * read-log leaf or a read-log tree head written
68
+ * outside its signing key's signed window, by
69
+ * the rule CHAIN_KEY_NOT_YET_ACTIVE and
70
+ * CHAIN_KEY_EXPIRED apply to entries.
71
+ * - CHECKPOINT_ACCOUNTED_ONLY, CHECKPOINT_ACCOUNTED_RUN_EXCEEDED Server mirror
72
+ * of `accounted_checkpoint_only` and
73
+ * `checkpoint_accounted_run_exceeded`: what a
74
+ * chain is left with when the checkpoints a
75
+ * distrustedKeys entry accounts for are set aside.
62
76
  * - KEY_STATEMENT_INVALID, KEY_CLOSURE_INVALID, CHAIN_KEY_WINDOW_DRIFT
63
- * engine mirrors of the key registry findings
77
+ * Server mirrors of the key registry findings
64
78
  * `key_statement_invalid`, `key_closure_invalid`
65
79
  * and `key_window_drift`. They are about the
66
80
  * registry, not about any one entry.
67
81
  * - CHECKPOINT_CLAIM_MISMATCH, TENANT_READ_CLAIM_MISMATCH,
68
- * TENANT_CHECKPOINT_CLAIM_MISMATCH engine mirrors of the vault's
82
+ * TENANT_CHECKPOINT_CLAIM_MISMATCH Server mirrors of the vault's
69
83
  * `checkpoint_claim_mismatch` and the read log's
70
84
  * `leaf_claim_mismatch` and
71
85
  * `checkpoint_claim_mismatch`: the claim signed
72
86
  * inside the envelope does not decode, or says
73
87
  * something the row's columns do not.
74
88
  *
75
- * Server-side cert re-checks are not mirrored here. The engine's chain
89
+ * Server-side cert re-checks are not mirrored here. The Server's chain
76
90
  * verification also reports `cert_missing`, `cert_actor_drift`,
77
91
  * `cert_window_drift`, `cert_expired` and `agent_signature_invalid`, by
78
92
  * comparing what an entry sealed in `predicate.on_behalf_of.cert` against the
79
- * live `ephemeral_certs` row. Neither the export nor the dump carries that
80
- * table, so an offline verifier cannot reproduce those comparisons, and it
93
+ * Server's cert record. Neither the export nor the dump carries that
94
+ * record, so an offline verifier cannot reproduce those comparisons, and it
81
95
  * does not need to: it trusts only the signed bytes, which already fix the
82
96
  * sealed cert id, thumbprint and expiry. The one cert-related check that can
83
97
  * run offline is the agent signature, and only when the caller supplies the
84
98
  * cert's public key (CHAIN_AGENT_SIGNATURE_INVALID below).
85
99
  */
86
- export type FailureCode = 'UNSUPPORTED_FORMAT' | 'CHAIN_EMPTY' | 'CHAIN_POSITION_GAP' | 'CHAIN_GENESIS_INVALID' | 'CHAIN_LINK_BROKEN' | 'CHAIN_HASH_MISMATCH' | 'CHAIN_MALFORMED_ENTRY' | 'CHAIN_COSE_DECODE_FAILED' | 'CHAIN_COSE_HEADER_MISMATCH' | 'CHAIN_PAYLOAD_BINDING_MISMATCH' | 'CHAIN_OIDC_ACTOR_MISMATCH' | 'CHAIN_SIGNATURE_INVALID' | 'CHAIN_SIGNATURE_MISSING_KEY' | 'CHAIN_KEY_POLICY_VIOLATION' | 'CHAIN_KEY_EXPIRED' | 'CHAIN_KEY_NOT_YET_ACTIVE' | 'CHAIN_ALG_MISMATCH' | 'CHAIN_UNSUPPORTED_ALGORITHM' | 'CHAIN_SIGNING_KEY_DRIFT' | 'CHAIN_ACTOR_ATTRIBUTION_MISMATCH' | 'CHAIN_AGENT_SIGNATURE_INVALID' | 'CHAIN_FEDERATION_WIRE_INVALID' | 'CHAIN_EVIDENCE_BINDING_MISMATCH' | 'CHAIN_ENTRY_UNSIGNED' | 'CHAIN_SIGNING_KEY_UNANCHORED' | 'CHAIN_KEY_WINDOW_DRIFT' | 'CHECKPOINT_ROW_MISSING' | 'CHECKPOINT_HASH_MISMATCH' | 'CHECKPOINT_SIGNATURE_INVALID' | 'CHECKPOINT_UNSIGNED' | 'CHECKPOINT_KEY_UNANCHORED' | 'CHECKPOINT_CLAIM_MISMATCH' | 'TENANT_READ_LEAF_HASH_MISMATCH' | 'TENANT_READ_LEAF_INDEX_GAP' | 'TENANT_READ_SIGNATURE_INVALID' | 'TENANT_READ_LEAF_UNSIGNED' | 'TENANT_READ_KEY_UNANCHORED' | 'TENANT_READ_CLAIM_MISMATCH' | 'TENANT_CHECKPOINT_LEAF_COUNT_MISMATCH' | 'TENANT_CHECKPOINT_ROOT_MISMATCH' | 'TENANT_CHECKPOINT_SIGNATURE_INVALID' | 'TENANT_CHECKPOINT_UNSIGNED' | 'TENANT_CHECKPOINT_KEY_UNANCHORED' | 'TENANT_CHECKPOINT_CLAIM_MISMATCH' | 'TENANT_CHECKPOINT_FORK' | 'KEY_STATEMENT_INVALID' | 'KEY_CLOSURE_INVALID';
100
+ export type FailureCode = 'UNSUPPORTED_FORMAT' | 'CHAIN_EMPTY' | 'CHAIN_POSITION_GAP' | 'CHAIN_GENESIS_INVALID' | 'CHAIN_LINK_BROKEN' | 'CHAIN_HASH_MISMATCH' | 'CHAIN_MALFORMED_ENTRY' | 'CHAIN_COSE_DECODE_FAILED' | 'CHAIN_COSE_HEADER_MISMATCH' | 'CHAIN_PAYLOAD_BINDING_MISMATCH' | 'CHAIN_OIDC_ACTOR_MISMATCH' | 'CHAIN_SIGNATURE_INVALID' | 'CHAIN_SIGNATURE_MISSING_KEY' | 'CHAIN_KEY_POLICY_VIOLATION' | 'CHAIN_KEY_EXPIRED' | 'CHAIN_KEY_NOT_YET_ACTIVE' | 'CHAIN_ALG_MISMATCH' | 'CHAIN_UNSUPPORTED_ALGORITHM' | 'CHAIN_SIGNING_KEY_DRIFT' | 'CHAIN_ACTOR_ATTRIBUTION_MISMATCH' | 'CHAIN_AGENT_SIGNATURE_INVALID' | 'CHAIN_FEDERATION_WIRE_INVALID' | 'CHAIN_EVIDENCE_BINDING_MISMATCH' | 'CHAIN_ENTRY_UNSIGNED' | 'CHAIN_SIGNING_KEY_UNANCHORED' | 'CHAIN_KEY_WINDOW_DRIFT' | 'CHECKPOINT_ROW_MISSING' | 'CHECKPOINT_HASH_MISMATCH' | 'CHECKPOINT_SIGNATURE_INVALID' | 'CHECKPOINT_UNSIGNED' | 'CHECKPOINT_KEY_UNANCHORED' | 'CHECKPOINT_CLAIM_MISMATCH' | 'CHECKPOINT_KEY_NOT_YET_ACTIVE' | 'CHECKPOINT_KEY_EXPIRED' | 'CHECKPOINT_ACCOUNTED_ONLY' | 'CHECKPOINT_ACCOUNTED_RUN_EXCEEDED' | 'TENANT_READ_LEAF_HASH_MISMATCH' | 'TENANT_READ_LEAF_INDEX_GAP' | 'TENANT_READ_SIGNATURE_INVALID' | 'TENANT_READ_LEAF_UNSIGNED' | 'TENANT_READ_KEY_UNANCHORED' | 'TENANT_READ_CLAIM_MISMATCH' | 'TENANT_READ_KEY_NOT_YET_ACTIVE' | 'TENANT_READ_KEY_EXPIRED' | 'TENANT_CHECKPOINT_LEAF_COUNT_MISMATCH' | 'TENANT_CHECKPOINT_ROOT_MISMATCH' | 'TENANT_CHECKPOINT_SIGNATURE_INVALID' | 'TENANT_CHECKPOINT_UNSIGNED' | 'TENANT_CHECKPOINT_KEY_UNANCHORED' | 'TENANT_CHECKPOINT_CLAIM_MISMATCH' | 'TENANT_CHECKPOINT_KEY_NOT_YET_ACTIVE' | 'TENANT_CHECKPOINT_KEY_EXPIRED' | 'TENANT_CHECKPOINT_FORK' | 'KEY_STATEMENT_INVALID' | 'KEY_CLOSURE_INVALID';
87
101
  /** The actionable next step for a failure code. */
88
102
  export declare function suggestion(code: FailureCode): string;
package/dist/failures.js CHANGED
@@ -41,43 +41,57 @@
41
41
  * verdict, never a silent pass.
42
42
  *
43
43
  * Later additions:
44
- * - CHAIN_ENTRY_UNSIGNED engine mirror of `signature_missing`: an entry with
44
+ * - CHAIN_ENTRY_UNSIGNED Server mirror of `signature_missing`: an entry with
45
45
  * no signing key id after a signed entry in its
46
46
  * chain, or written at or after the earliest
47
47
  * activatedAt in the key set. Earlier unsigned
48
48
  * entries stay reduced coverage.
49
- * - CHECKPOINT_UNSIGNED engine mirror of `checkpoint_unsigned`: the same
49
+ * - CHECKPOINT_UNSIGNED Server mirror of `checkpoint_unsigned`: the same
50
50
  * instant, applied to an unsigned checkpoint.
51
51
  * - TENANT_READ_LEAF_UNSIGNED and TENANT_CHECKPOINT_UNSIGNED the same two
52
- * rules on the org_admin_reads log (engine
52
+ * rules on the org_admin_reads log (Server
53
53
  * `leaf_signature_missing`, `checkpoint_unsigned`).
54
- * - CHAIN_SIGNING_KEY_UNANCHORED engine mirror of `signing_key_unanchored`:
54
+ * - CHAIN_SIGNING_KEY_UNANCHORED Server mirror of `signing_key_unanchored`:
55
55
  * the entry's key is not linked by signed key
56
56
  * statements to a pinned trust anchor. With
57
57
  * CHECKPOINT_KEY_UNANCHORED,
58
58
  * TENANT_READ_KEY_UNANCHORED and
59
59
  * TENANT_CHECKPOINT_KEY_UNANCHORED for the
60
- * engine's `checkpoint_key_unanchored` and
60
+ * Server's `checkpoint_key_unanchored` and
61
61
  * `leaf_key_unanchored`.
62
+ * - CHECKPOINT_KEY_NOT_YET_ACTIVE, CHECKPOINT_KEY_EXPIRED, and the
63
+ * TENANT_READ_KEY_* and TENANT_CHECKPOINT_KEY_* pairs Server mirror of
64
+ * `checkpoint_key_not_yet_active`,
65
+ * `checkpoint_key_expired`, `leaf_key_not_yet_active`
66
+ * and `leaf_key_expired`: a vault checkpoint, a
67
+ * read-log leaf or a read-log tree head written
68
+ * outside its signing key's signed window, by
69
+ * the rule CHAIN_KEY_NOT_YET_ACTIVE and
70
+ * CHAIN_KEY_EXPIRED apply to entries.
71
+ * - CHECKPOINT_ACCOUNTED_ONLY, CHECKPOINT_ACCOUNTED_RUN_EXCEEDED Server mirror
72
+ * of `accounted_checkpoint_only` and
73
+ * `checkpoint_accounted_run_exceeded`: what a
74
+ * chain is left with when the checkpoints a
75
+ * distrustedKeys entry accounts for are set aside.
62
76
  * - KEY_STATEMENT_INVALID, KEY_CLOSURE_INVALID, CHAIN_KEY_WINDOW_DRIFT
63
- * engine mirrors of the key registry findings
77
+ * Server mirrors of the key registry findings
64
78
  * `key_statement_invalid`, `key_closure_invalid`
65
79
  * and `key_window_drift`. They are about the
66
80
  * registry, not about any one entry.
67
81
  * - CHECKPOINT_CLAIM_MISMATCH, TENANT_READ_CLAIM_MISMATCH,
68
- * TENANT_CHECKPOINT_CLAIM_MISMATCH engine mirrors of the vault's
82
+ * TENANT_CHECKPOINT_CLAIM_MISMATCH Server mirrors of the vault's
69
83
  * `checkpoint_claim_mismatch` and the read log's
70
84
  * `leaf_claim_mismatch` and
71
85
  * `checkpoint_claim_mismatch`: the claim signed
72
86
  * inside the envelope does not decode, or says
73
87
  * something the row's columns do not.
74
88
  *
75
- * Server-side cert re-checks are not mirrored here. The engine's chain
89
+ * Server-side cert re-checks are not mirrored here. The Server's chain
76
90
  * verification also reports `cert_missing`, `cert_actor_drift`,
77
91
  * `cert_window_drift`, `cert_expired` and `agent_signature_invalid`, by
78
92
  * comparing what an entry sealed in `predicate.on_behalf_of.cert` against the
79
- * live `ephemeral_certs` row. Neither the export nor the dump carries that
80
- * table, so an offline verifier cannot reproduce those comparisons, and it
93
+ * Server's cert record. Neither the export nor the dump carries that
94
+ * record, so an offline verifier cannot reproduce those comparisons, and it
81
95
  * does not need to: it trusts only the signed bytes, which already fix the
82
96
  * sealed cert id, thumbprint and expiry. The one cert-related check that can
83
97
  * run offline is the agent signature, and only when the caller supplies the
@@ -88,13 +102,13 @@
88
102
  * verifier's caller (auditor, compliance team, or agent) should do next.
89
103
  */
90
104
  const SUGGESTIONS = {
91
- UNSUPPORTED_FORMAT: 'This verifier reads exportFormatVersion 2.0 / RFC8949-CDE canonicalization. Re-export the chain from a current AGLedger instance, or upgrade the verifier to match the producing engine.',
105
+ UNSUPPORTED_FORMAT: 'This verifier reads exportFormatVersion 2.0 / RFC8949-CDE canonicalization. Re-export the chain from a current AGLedger instance, or upgrade the verifier to match the producing Server.',
92
106
  CHAIN_EMPTY: 'No entries were present to verify. Confirm the record id / dump directory is correct and that the chain has not been truncated to zero rows.',
93
107
  CHAIN_POSITION_GAP: 'A chain position is missing or out of order. The chain was truncated or reordered. Obtain a complete, unmodified export/dump from the operator and re-run.',
94
108
  CHAIN_GENESIS_INVALID: 'The first entry must carry previousHash = null. A non-null genesis link means the head of the chain was removed. Request the full chain from position 1.',
95
109
  CHAIN_LINK_BROKEN: 'An entry\'s previousHash does not match the prior entry\'s payloadHash. The chain was edited between these two entries. Treat every entry from this position on as untrusted.',
96
110
  CHAIN_HASH_MISMATCH: 'sha256(cose_sign1) does not equal the stored payloadHash. The envelope bytes or the stored hash were altered. The signed bytes are authoritative; the row was tampered with.',
97
- CHAIN_MALFORMED_ENTRY: 'An entry is missing a field the engine writes on every entry (coseSign1, payloadHash, or a parseable createdAt where a key window or the start of signing needs one), or carries it as another type. The export/dump is incomplete or was edited, and an entry the verifier cannot place is never read as early unsigned history. Regenerate the export/dump from the operator and re-run.',
111
+ CHAIN_MALFORMED_ENTRY: 'An entry is missing a field the Server writes on every entry (coseSign1, payloadHash, or a parseable createdAt where a key window or the start of signing needs one), or carries it as another type. The export/dump is incomplete or was edited, and an entry the verifier cannot place is never read as early unsigned history. Regenerate the export/dump from the operator and re-run.',
98
112
  CHAIN_COSE_DECODE_FAILED: 'The COSE_Sign1 envelope did not decode as a tagged 4-element structure. The signed bytes are corrupt. Regenerate the export/dump.',
99
113
  CHAIN_COSE_HEADER_MISMATCH: 'The position/previousHash signed in the COSE protected header disagree with the row columns. The visible columns were renumbered after signing. Trust the signed header, not the columns.',
100
114
  CHAIN_PAYLOAD_BINDING_MISMATCH: 'The signed payload\'s structure no longer matches the canonical projection of the row columns it is bound to: the visible (denormalised) payload was altered after signing. This is a binding-integrity failure, not a judgement on content.',
@@ -108,31 +122,39 @@ const SUGGESTIONS = {
108
122
  CHAIN_UNSUPPORTED_ALGORITHM: 'The entry\'s trusted verification key commits to a signature algorithm that could not be computed, either because this verifier build does not implement it or because the host runtime refused it (an active OpenSSL FIPS provider carries no EdDSA). The chain is NOT verified, and this is NOT tamper evidence: the signature was never checked. Upgrade the verifier, or re-run on a host without the restriction. Never treat this result as a pass.',
109
123
  CHAIN_SIGNING_KEY_DRIFT: 'The entry\'s signingKeyId column names a different key than the signature-covered kid in the COSE protected header. The column is a denormalized convenience and was rewritten after signing (possibly to point verification at another key). Trust the signed kid; treat the row as tampered.',
110
124
  CHAIN_ACTOR_ATTRIBUTION_MISMATCH: 'The entry\'s actorId / actorOwnerId columns name a different actor than the signature-covered actor claim in the COSE protected header (CWT_Claims label 15, private label -65539). The columns are the projection a report displays and they were rewritten after signing, re-attributing the action to another actor. Trust the signed claim; treat the row as tampered and re-obtain the export from the operator.',
111
- CHAIN_AGENT_SIGNATURE_INVALID: 'The agent signature sealed in predicate.on_behalf_of.agent_signature does not verify under the supplied key whose RFC 7638 thumbprint the entry itself names, or is sealed in a shape nothing can verify. The engine checks this signature at intake and the envelope signature says the engine wrote it, so this is not a caller mistake: treat the agent attribution of this entry as unproven and escalate to the operator.',
125
+ CHAIN_AGENT_SIGNATURE_INVALID: 'The agent signature sealed in predicate.on_behalf_of.agent_signature does not verify under the supplied key whose RFC 7638 thumbprint the entry itself names, or is sealed in a shape nothing can verify. The Server checks this signature at intake and the envelope signature says the Server wrote it, so this is not a caller mistake: treat the agent attribution of this entry as unproven and escalate to the operator.',
112
126
  CHAIN_FEDERATION_WIRE_INVALID: 'The federation message sealed in payload.wire does not hold: its body no longer hashes to the bodyHash the sender signed, the entry asserts a state, type, recommendation or dispute the sealed body does not carry, or (under the sender\'s federation key you supplied) the signature does not verify or the sealed senderPublicKey is not that key. The receiving Server verified the message at intake and signed this entry, so this is not a caller mistake: treat what the entry says the peer asserted as unproven and escalate to both operators.',
113
127
  CHAIN_EVIDENCE_BINDING_MISMATCH: 'An evidence body inlined in the export (entries[].evidence, from ?evidence=true) does not hash to the payload.evidenceHash or payload.payloadHash its entry signs, or sits on an entry that signs no such hash. The body is an unsigned projection whose only authority is that hash, so it was edited after export or attached where it does not belong. Trust the signed hash, not the body: re-obtain the evidence from the operator and re-bind it (SHA-256 over its RFC 8785 form).',
114
128
  CHAIN_ENTRY_UNSIGNED: 'The entry carries no signing key id where the install could not have written an unsigned entry: after a signed entry in the same chain, or at or after the earliest activation time in the signing key set (retired keys included). From that instant every writer holds a registered key, so this is what a writer without one leaves on the chain, or a signed row whose key id was nulled. Treat the entry as forged and escalate to the operator. Unsigned entries from before the first key activation stay reduced signature coverage, not a break.',
115
129
  CHAIN_SIGNING_KEY_UNANCHORED: 'The entry is signed by a key that no signed key statement links to a trust anchor you pinned. Anything with write access to the Server\'s database can register a key and sign entries with it; what it cannot write is a statement signed by a key you trust. Treat the entry as forged. If the key is one you vouch for, pin it (trustAnchors) from a source outside the Server, never from the document that served it.',
116
130
  CHAIN_KEY_WINDOW_DRIFT: 'A key registry column (activatedAt, retiredAt or status in a dump row or key document) differs from the value its signed key statements carry. The signed value is the one entries are graded against; the column was rewritten, or the retirement was written without its closure statement. Treat the registry as tampered and compare it with the Server\'s own scan (key_window_drift). Where the detail names a distrust entry the listing says the Server applies (distrustedFrom, VAULT_DISTRUSTED_KEYS), the listed retirement may be that entry\'s cut, which the verifier was not given or was given at another instant; the listing\'s word is unsigned, so it stays tampering until the Server\'s operator confirms the entry.',
117
- CHECKPOINT_ROW_MISSING: 'A signed checkpoint anchors a position that has no matching chain row. The chain was truncated below a checkpoint (out-of-band DELETE/TRUNCATE). The checkpoint is proof of the missing rows.',
131
+ CHECKPOINT_ROW_MISSING: 'A signed checkpoint anchors a position that has no matching chain row. Chain entries below a checkpoint were removed out of band. The checkpoint is proof of the missing entries. On a record export the position is the one the export states (exportMetadata.expectedEntries): fetch the export again and verify the file exactly as served.',
118
132
  CHECKPOINT_HASH_MISMATCH: 'A checkpoint\'s payloadHash does not match the chain row at its position. The chain diverged from what was checkpointed. Treat the chain as tampered.',
119
133
  CHECKPOINT_SIGNATURE_INVALID: 'A checkpoint\'s COSE_Sign1 signature did not verify. The checkpoint was forged or altered. Re-run with out-of-band verification keys.',
120
134
  CHECKPOINT_UNSIGNED: 'A checkpoint carries no signing key id but was written at or after the earliest activation time in the signing key set (retired keys included), when every writer holds a registered key. The checkpoint was forged or its key id nulled, and nothing it anchors can be trusted. Escalate to the operator.',
121
135
  CHECKPOINT_KEY_UNANCHORED: 'A vault checkpoint is signed by a key that no signed key statement links to a trust anchor you pinned. Nothing it anchors can be trusted; treat it as forged (see CHAIN_SIGNING_KEY_UNANCHORED).',
122
136
  CHECKPOINT_CLAIM_MISMATCH: 'The claim signed inside a vault checkpoint envelope does not decode, or says something the checkpoint row\'s columns do not (chain position, chain tip hash, subject digest or signed kid). A column was rewritten beside an intact envelope. Trust the signed claim, treat the checkpoint row as tampered, and obtain the dump from the operator again.',
137
+ CHECKPOINT_KEY_NOT_YET_ACTIVE: 'A vault checkpoint was written before the activation its signing key\'s statements sign. A checkpoint backdated under a later key, or a key used before its succession was recorded: treat what it anchors as unproven and compare with the Server\'s own scan (checkpoint_key_not_yet_active).',
138
+ CHECKPOINT_KEY_EXPIRED: 'A vault checkpoint was written after its signing key was retired, or after the instant distrustedKeys gives for that key; the detail says which. Possible use of a compromised key: check the rotation record for that key id, and treat what the checkpoint anchors as unproven.',
139
+ CHECKPOINT_ACCOUNTED_ONLY: 'A chain has no entry in the dump, and its only checkpoints are ones a distrustedKeys entry accounts for. Nothing vouches for the chain and nothing explains its absence: a chain is never empty once written. Obtain the chain from a backup or replica and escalate to the operator (Server scan: accounted_checkpoint_only).',
140
+ CHECKPOINT_ACCOUNTED_RUN_EXCEEDED: 'More than 1000 checkpoints a distrustedKeys entry accounts for sit above the newest checkpoint that entry does not cover. A rotation writes a fresh checkpoint at the next tip, so a run this long is rows planted under the leaked key. Treat the chain as unanchored and escalate to the operator (Server scan: checkpoint_accounted_run_exceeded).',
123
141
  TENANT_READ_LEAF_HASH_MISMATCH: 'An org_admin_reads leaf_hash does not match the RFC 9162 leaf hash of its envelope, sha256(0x00 || cose_sign1). The read-log leaf was altered after recording.',
124
142
  TENANT_READ_LEAF_INDEX_GAP: 'org_admin_reads leaf indices are not gap-free for this org. A read-log entry was removed. Obtain the complete log.',
125
143
  TENANT_READ_SIGNATURE_INVALID: 'An org_admin_reads leaf\'s COSE_Sign1 signature did not verify. The read-log leaf was forged or altered.',
126
144
  TENANT_READ_LEAF_UNSIGNED: 'An org_admin_reads leaf carries the unsigned kid where the install could not have written one: after a signed leaf in the same org log, or at or after the earliest activation time in the signing key set. Treat the leaf as forged and escalate to the operator.',
127
145
  TENANT_READ_KEY_UNANCHORED: 'An org_admin_reads leaf is signed by a key that no signed key statement links to a trust anchor you pinned. Treat the leaf as forged (see CHAIN_SIGNING_KEY_UNANCHORED).',
128
146
  TENANT_READ_CLAIM_MISMATCH: 'The claim signed inside an org_admin_reads leaf envelope does not decode, or says something the leaf row\'s columns do not (position, previous_hash, record_id or subject digest). A column was rewritten beside an intact envelope. Trust the signed claim and treat the read-log leaf as tampered.',
147
+ TENANT_READ_KEY_NOT_YET_ACTIVE: 'An org_admin_reads leaf was written before the activation its signing key\'s statements sign. Treat the leaf as backdated or forged and compare with the Server\'s own scan (leaf_key_not_yet_active).',
148
+ TENANT_READ_KEY_EXPIRED: 'An org_admin_reads leaf was written after its signing key was retired, or after the instant distrustedKeys gives for that key; the detail says which. Possible use of a compromised key: check the rotation record for that key id.',
129
149
  TENANT_CHECKPOINT_LEAF_COUNT_MISMATCH: 'A signed tree head commits to more leaves than the dump contains. The read log was truncated below a checkpoint.',
130
150
  TENANT_CHECKPOINT_ROOT_MISMATCH: 'The RFC 9162 Merkle root recomputed over the leaves does not match the signed root_hash. The read log diverged from what was checkpointed.',
131
151
  TENANT_CHECKPOINT_SIGNATURE_INVALID: 'A signed-tree-head COSE_Sign1 signature did not verify. The STH was forged or altered.',
132
152
  TENANT_CHECKPOINT_UNSIGNED: 'An org_admin_reads signed tree head carries no signing key id but was written at or after the earliest activation time in the signing key set. The tree head was forged or its key id nulled; escalate to the operator.',
133
153
  TENANT_CHECKPOINT_KEY_UNANCHORED: 'An org_admin_reads signed tree head is signed by a key that no signed key statement links to a trust anchor you pinned. Treat it as forged (see CHAIN_SIGNING_KEY_UNANCHORED).',
134
154
  TENANT_CHECKPOINT_CLAIM_MISMATCH: 'The claim signed inside an org_admin_reads tree-head envelope does not decode, or says something the tree-head row\'s columns do not (position, chain_tip_hash, leaf count, subject digest or signed kid). A column was rewritten beside an intact envelope. Trust the signed claim and treat the tree-head row as tampered.',
135
- TENANT_CHECKPOINT_FORK: 'Two signed tree heads at the same tree_size carry different roots. This is an engine fork or signing-key compromise. Escalate immediately.',
155
+ TENANT_CHECKPOINT_KEY_NOT_YET_ACTIVE: 'An org_admin_reads signed tree head was written before the activation its signing key\'s statements sign. Treat the tree head as backdated or forged and compare with the Server\'s own scan (checkpoint_key_not_yet_active).',
156
+ TENANT_CHECKPOINT_KEY_EXPIRED: 'An org_admin_reads signed tree head was written after its signing key was retired, or after the instant distrustedKeys gives for that key; the detail says which. Possible use of a compromised key: check the rotation record for that key id.',
157
+ TENANT_CHECKPOINT_FORK: 'Two signed tree heads at the same tree_size carry different roots. This is a Server fork or signing-key compromise. Escalate immediately.',
136
158
  KEY_STATEMENT_INVALID: 'A key statement does not verify, disagrees with the columns it was stored under, touches no anchored key, or was signed by a key after its closure or after the key was already admitted. It admits nothing. One that does not verify, or that a key signed after its closure, is what a writer with database access or a leaked retired key produces: have the operator retire that key with force and add it to VAULT_DISTRUSTED_KEYS, and pass the same entry as distrustedKeys.',
137
159
  KEY_CLOSURE_INVALID: 'A key is retired with no closure that counts for it, or a closure is signed by a key the walk does not anchor, by a key after its own retirement, or dates a retirement before its subject was activated, or is signed by a key the walk reaches but does not anchor and retires an anchored key earlier, or with force, than any closure a published key signed (so a walk over the published key documents reads that key differently). A closure that still counts ends its subject\'s window whoever wrote it; if its signer leaked, have the operator add it to VAULT_DISTRUSTED_KEYS and pass the same entry as distrustedKeys.',
138
160
  };