@agledger/verify-core 2.0.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.
@@ -4,12 +4,11 @@
4
4
  * A vault key is trusted only when signed key statements link it to a key the
5
5
  * verifier pinned out of band (`trustAnchors`). The Server's database stores
6
6
  * the statements and never vouches for them: anything with write access to it
7
- * can add a `vault_signing_keys` row and a statement row, and neither makes a
7
+ * can add a key row and a statement row, and neither makes a
8
8
  * key trusted, because every edge below is a signature that writer cannot
9
- * produce. This is the engine's `computeKeyTrust`
10
- * (audit-vault/key-statements.ts), re-implemented so the verifier has no engine
11
- * dependency. Where the two could disagree, this one must never trust a key the
12
- * engine refuses.
9
+ * produce. This is the same walk the Server runs over its own
10
+ * key registry, re-implemented so the verifier has no Server dependency. Where the two could disagree, this one must never trust a key the
11
+ * Server refuses.
13
12
  *
14
13
  * **Format.** Each statement is one or two COSE_Sign1 (RFC 9052, tag 18) over
15
14
  * the SAME deterministic-CBOR (RFC 8949 §4.2.1) payload, protected header
@@ -37,11 +36,11 @@
37
36
  * statement's `id` and `createdAt` at microseconds, and lists under a trusted
38
37
  * key its admission, every later genesis or succession it signed, and its
39
38
  * counting closures. A walk over a document therefore dates a window and
40
- * cuts an edge back as the engine does, except where the document does not
41
- * carry a key the engine verified a statement with (the endorser of a later
39
+ * cuts an edge back as the Server does, except where the document does not
40
+ * carry a key the Server verified a statement with (the endorser of a later
42
41
  * succession, the signer of a closure): that statement is
43
42
  * KEY_STATEMENT_INVALID or KEY_CLOSURE_INVALID here, the window is wider than
44
- * the engine's, and the listed `activatedAt` or `retiredAt` reports it as
43
+ * the Server's, and the listed `activatedAt` or `retiredAt` reports it as
45
44
  * CHAIN_KEY_WINDOW_DRIFT (a listed retirement no counting closure signs, as
46
45
  * KEY_CLOSURE_INVALID).
47
46
  *
@@ -55,6 +54,7 @@
55
54
  * statement is only ever in a document that did not come from the Server. A
56
55
  * forced closure voids every edge out of its key whatever the order.
57
56
  */
57
+ import { STRICT_CBOR_DECODE } from './cbor-strict.js';
58
58
  import { decode as cborDecode, encode as cborEncode, rfc8949EncodeOptions } from 'cborg';
59
59
  import { algorithmByName, resolveKeyAlgorithm, runtimeCanCompute, sha256Hex, verifySignatureBytes, } from './primitives.js';
60
60
  import { instantMs, instantUs, rfc3339Ms } from './instant.js';
@@ -64,7 +64,7 @@ export const KEY_STATEMENT_CTY = 'application/vnd.agledger.key-statement+cbor';
64
64
  export const KEY_STATEMENT_KINDS = ['succession', 'closure', 'genesis'];
65
65
  /**
66
66
  * The COSE `alg` a statement signature must carry for its key's algorithm.
67
- * Exactly one per algorithm, as the engine signs and checks them; the chain
67
+ * Exactly one per algorithm, as the Server signs and checks them; the chain
68
68
  * envelope's wider acceptance (RFC 9864 fully-specified code points) does not
69
69
  * apply to statements.
70
70
  */
@@ -150,7 +150,7 @@ export function parseDistrustedKeys(raw) {
150
150
  * (`sha256:<hex>@<instant>`) is how a leaked key whose history is still
151
151
  * needed is kept from signing anything new: the pin vouches for what it
152
152
  * stored before the instant. `computeKeyTrust` itself walks any pair as the
153
- * engine's walk does; a verifier calls this on what its caller passed before
153
+ * Server's walk does; a verifier calls this on what its caller passed before
154
154
  * it walks.
155
155
  */
156
156
  export function assertNotPinnedAndDistrusted(trustAnchors, distrustedKeys) {
@@ -171,17 +171,20 @@ function normalizeDistrusted(raw) {
171
171
  throw new TypeError('distrustedKeys must be an array.');
172
172
  const strings = raw.filter((d) => typeof d === 'string');
173
173
  const parsed = parseDistrustedKeys(strings);
174
- for (const d of raw) {
175
- if (typeof d === 'string')
174
+ const entries = raw;
175
+ for (const item of entries) {
176
+ if (typeof item === 'string')
176
177
  continue;
177
- if (d === null || typeof d !== 'object' || typeof d.spkiSha256 !== 'string' || !HEX64.test(d.spkiSha256)
178
- || (d.cutoff !== null && (typeof d.cutoff !== 'string' || !INSTANT_US.test(d.cutoff)))) {
178
+ const d = item !== null && typeof item === 'object' ? item : {};
179
+ const { spkiSha256, cutoff } = d;
180
+ if (typeof spkiSha256 !== 'string' || !HEX64.test(spkiSha256)
181
+ || (cutoff !== null && (typeof cutoff !== 'string' || !INSTANT_US.test(cutoff)))) {
179
182
  throw new TypeError('distrustedKeys entry is not { spkiSha256: <64 lowercase hex>, cutoff: <microsecond RFC 3339 UTC instant> | null }.');
180
183
  }
181
- if (parsed.some((p) => p.spkiSha256 === d.spkiSha256)) {
182
- throw new TypeError(`distrustedKeys names sha256:${d.spkiSha256} twice. Give each key one entry, with the earliest instant it may have leaked.`);
184
+ if (parsed.some((p) => p.spkiSha256 === spkiSha256)) {
185
+ throw new TypeError(`distrustedKeys names sha256:${spkiSha256} twice. Give each key one entry, with the earliest instant it may have leaked.`);
183
186
  }
184
- parsed.push({ spkiSha256: d.spkiSha256, cutoff: d.cutoff });
187
+ parsed.push({ spkiSha256, cutoff });
185
188
  }
186
189
  return parsed;
187
190
  }
@@ -198,6 +201,7 @@ function decodeSign1(raw) {
198
201
  return null;
199
202
  try {
200
203
  const decoded = cborDecode(bytes, {
204
+ ...STRICT_CBOR_DECODE,
201
205
  useMaps: true,
202
206
  tags: { [COSE_SIGN1_TAG]: (control) => control() },
203
207
  });
@@ -206,7 +210,7 @@ function decodeSign1(raw) {
206
210
  const [p, , payload, sig] = decoded;
207
211
  if (!(p instanceof Uint8Array) || !(payload instanceof Uint8Array) || !(sig instanceof Uint8Array))
208
212
  return null;
209
- const header = cborDecode(p, { useMaps: true });
213
+ const header = cborDecode(p, { ...STRICT_CBOR_DECODE, useMaps: true });
210
214
  if (!(header instanceof Map))
211
215
  return null;
212
216
  const alg = header.get(COSE_HEADER_ALG);
@@ -247,7 +251,7 @@ function readKeyRef(v) {
247
251
  function decodeKeyStatementPayload(bytes) {
248
252
  let raw;
249
253
  try {
250
- raw = cborDecode(bytes, { useMaps: false });
254
+ raw = cborDecode(bytes, { ...STRICT_CBOR_DECODE, useMaps: false });
251
255
  }
252
256
  catch {
253
257
  return null;
@@ -293,7 +297,7 @@ function decodeKeyStatementPayload(bytes) {
293
297
  alg,
294
298
  spki: Buffer.from(spki).toString('base64'),
295
299
  activatedAt,
296
- ...(retiredAt !== undefined ? { retiredAt: retiredAt } : {}),
300
+ ...(retiredAt !== undefined ? { retiredAt } : {}),
297
301
  },
298
302
  };
299
303
  if (r['endorser'] !== undefined) {
@@ -460,7 +464,7 @@ function signedAfterWrite(signed, s) {
460
464
  }
461
465
  /** The earlier of an instant a statement signs and its write time (see {@link signedAfterWrite}). */
462
466
  function notAfterWrite(signed, s) {
463
- if (!signedAfterWrite(signed, s))
467
+ if (s.written === null || !signedAfterWrite(signed, s))
464
468
  return signed;
465
469
  return instantOfUs(s.written.micro ? s.written.us : s.storedMs * 1000);
466
470
  }
@@ -502,7 +506,10 @@ export function computeKeyTrust(input) {
502
506
  }
503
507
  const anchors = new Set(anchorDigests);
504
508
  const distrustedKeys = normalizeDistrusted(input.distrustedKeys);
505
- if (!Array.isArray(input.statements) || !Array.isArray(input.keys)) {
509
+ // Checked through `unknown` copies so the guard does not retype `input.statements` and `input.keys` as `any[]`.
510
+ const rawStatements = input.statements;
511
+ const rawKeys = input.keys;
512
+ if (!Array.isArray(rawStatements) || !Array.isArray(rawKeys)) {
506
513
  throw new TypeError('computeKeyTrust takes arrays of keys and statements.');
507
514
  }
508
515
  const withTime = input.statements.filter((s) => typeof s.createdAt === 'string').length;
@@ -516,7 +523,7 @@ export function computeKeyTrust(input) {
516
523
  // One stored row, read from two sources (an export and a key document), is
517
524
  // one statement. With no write time and no row id, two identical
518
525
  // statements are one; with them, a row is its id and write time, and a copy
519
- // of a row under another id is a second row, as the engine reads it.
526
+ // of a row under another id is a second row, as the Server reads it.
520
527
  const seen = new Set();
521
528
  const statementInputs = input.statements.filter((s) => {
522
529
  const cose = Array.isArray(s.cose) ? s.cose : [];
@@ -529,7 +536,7 @@ export function computeKeyTrust(input) {
529
536
  // The same row however its time and id are spelled: `Z` or `+00:00`, a
530
537
  // uuid in either case.
531
538
  const at = instantUs(s.createdAt ?? '');
532
- const key = order === 'written' ? JSON.stringify([s.id.toLowerCase(), Number.isNaN(at.us) ? s.createdAt : at.us, bytes]) : bytes;
539
+ const key = order === 'written' && typeof s.id === 'string' ? JSON.stringify([s.id.toLowerCase(), Number.isNaN(at.us) ? s.createdAt : at.us, bytes]) : bytes;
533
540
  if (seen.has(key))
534
541
  return false;
535
542
  seen.add(key);
@@ -558,13 +565,13 @@ export function computeKeyTrust(input) {
558
565
  // the Server writes one on every row, so it was edited, and it admits nothing.
559
566
  const checked = statementInputs.map((st) => {
560
567
  const c = checkKeyStatement(st, keyByDigest);
561
- if (order !== 'written' || !Number.isNaN(rfc3339Ms(st.createdAt)))
568
+ if (order !== 'written' || !Number.isNaN(rfc3339Ms(st.createdAt ?? '')))
562
569
  return c;
563
570
  return { ...c, verdict: 'invalid', detail: 'the row has no parseable created_at to order it by' };
564
571
  });
565
572
  const place = (c, i) => {
566
573
  if (order === 'written') {
567
- const at = instantUs(c.input.createdAt);
574
+ const at = instantUs(c.input.createdAt ?? '');
568
575
  return { c, i, k: Number.isNaN(at.us) ? Number.POSITIVE_INFINITY : at.us, micro: at.micro, r: 0 };
569
576
  }
570
577
  return { c, i, k: signedInstantOf(c) ?? '￿', micro: false, r: closureLast(c) };
@@ -589,7 +596,7 @@ export function computeKeyTrust(input) {
589
596
  // A dump row whose signed payload an earlier row already carries says
590
597
  // nothing new: a copy of a row (anything with write access to the database
591
598
  // can write one), or the same payload signed again. Only the first, in
592
- // write order, takes part, as the engine reads it; the database stamps the
599
+ // write order, takes part, as the Server reads it; the database stamps the
593
600
  // write time, so a copy always lands after what it copies. A key document's
594
601
  // write time is its holder's word, so there a copy dated earlier would push
595
602
  // the published statement aside: on a document a copy stays a second
@@ -612,7 +619,7 @@ export function computeKeyTrust(input) {
612
619
  subject: c.payload.subject.spkiSha256,
613
620
  endorser: c.payload.endorser?.spkiSha256 ?? null,
614
621
  at,
615
- storedMs: typeof k === 'number' ? rfc3339Ms(c.input.createdAt) : instantMs(k),
622
+ storedMs: typeof k === 'number' ? rfc3339Ms(c.input.createdAt ?? '') : instantMs(k),
616
623
  written: typeof k === 'number' ? { us: k, micro } : null,
617
624
  }]);
618
625
  const valid = inWriteOrder.filter((s) => s.check.verdict === 'valid');
@@ -690,7 +697,7 @@ export function computeKeyTrust(input) {
690
697
  * is not a dump row, every edge out of a distrusted key is void whatever
691
698
  * time it carries, and every closure it signed still counts: dropping an
692
699
  * edge or keeping a closure only ever takes trust away. Narrower than the
693
- * engine, never wider. The write order still orders such statements.
700
+ * Server, never wider. The write order still orders such statements.
694
701
  */
695
702
  const distrusted = (s, signer) => {
696
703
  if (signer === null || !cutoffs.has(signer))
@@ -701,7 +708,7 @@ export function computeKeyTrust(input) {
701
708
  return cutoff === null || cutoff === undefined || s.storedMs >= cutoff.at;
702
709
  };
703
710
  /**
704
- * What the engine would void: signed by a distrusted key with no cutoff, or
711
+ * What the Server would void: signed by a distrusted key with no cutoff, or
705
712
  * stored at or after its cutoff. On a key document the stored time is the
706
713
  * holder's word, so this decides only whether voiding it is a finding.
707
714
  */
@@ -745,7 +752,7 @@ export function computeKeyTrust(input) {
745
752
  // key, a forced closure's cut-off keys included, a key cut off from a
746
753
  // leaked one could retire a distrusted key it also holds and have what that
747
754
  // key forged read as accounted for. Only a signer the walk trusts and
748
- // reaches without a distrusted key bounds it, as in the engine; the cutoff
755
+ // reaches without a distrusted key bounds it, as in the Server; the cutoff
749
756
  // a bound gives an undated entry comes from the reach alone.
750
757
  const clearOfDistrust = reach(anchors, edges.filter((e) => !distrust.has(e.from)));
751
758
  for (const [d, span] of distrustSpans) {
@@ -754,7 +761,10 @@ export function computeKeyTrust(input) {
754
761
  if (s.subject !== d || s.payload.typ !== 'closure' || s.endorser === null || distrust.has(s.endorser)
755
762
  || !clearOfDistrust.has(s.endorser) || !trusted.has(s.endorser))
756
763
  continue;
757
- const retiredAt = notAfterWrite(s.payload.subject.retiredAt, s);
764
+ const signedRetiredAt = s.payload.subject.retiredAt;
765
+ if (signedRetiredAt === undefined)
766
+ continue;
767
+ const retiredAt = notAfterWrite(signedRetiredAt, s);
758
768
  if (retiredBy === null || retiredAt < retiredBy)
759
769
  retiredBy = retiredAt;
760
770
  }
@@ -862,10 +872,13 @@ export function computeKeyTrust(input) {
862
872
  continue;
863
873
  if (voided && !voidedByStoredTime(s, e)) {
864
874
  // Voided only because a key document's time is not held against the
865
- // cutoff: it admits nothing, but a statement the engine would count is
875
+ // cutoff: it admits nothing, but a statement the Server would count is
866
876
  // no finding. It still dates windows and cuts edges back, so it can
867
877
  // only narrow trust. The checks below still apply to it.
868
878
  const cutoff = cutoffs.get(e);
879
+ // Unreachable: a signer voided here has a cutoff with an instant (see voidedByStoredTime).
880
+ if (cutoff === null || cutoff === undefined)
881
+ throw new TypeError(`The distrusted key ${e} has no cutoff instant.`);
869
882
  notes.push({
870
883
  keyId: s.payload.subject.kid,
871
884
  statementId: s.check.id,
@@ -892,7 +905,7 @@ export function computeKeyTrust(input) {
892
905
  const retiredBy = distrustSpans.get(e)?.retiredAt ?? null;
893
906
  // A later admission of a trusted key that the key itself signed is
894
907
  // the record of its own half leaking, whoever co-signed it: never
895
- // accounted for, as in the engine.
908
+ // accounted for, as in the Server.
896
909
  const leakedSubject = s.payload.typ !== 'closure' && admissions.get(s.subject) !== s && s.check.subjectSigned && trusted.has(s.subject);
897
910
  if (leakedSubject) {
898
911
  finding(code, s, `${what} It is also a ${s.payload.typ} ${s.payload.subject.kid} signed after it was already admitted: ${s.payload.subject.kid}'s private half in other hands, which no distrust entry for ${by} accounts for. Move every Server process off ${s.payload.subject.kid}, retire it with force from the key they hold, and give distrustedKeys sha256:${s.subject}@<the instant it leaked> (VAULT_DISTRUSTED_KEYS on every Server process).`);
@@ -1004,10 +1017,8 @@ export function computeKeyTrust(input) {
1004
1017
  }
1005
1018
  // Keys an admission names that this walk could not verify. A key document
1006
1019
  // carries a key's admissions but not every endorser, so the walk can date a
1007
- // trusted key's window earlier than the engine did, or not at all.
1008
- const unverifiedAdmission = new Set(checked
1009
- .filter((c) => c.verdict === 'invalid' && c.payload !== null && c.payload.typ !== 'closure')
1010
- .map((c) => c.payload.subject.spkiSha256));
1020
+ // trusted key's window earlier than the Server did, or not at all.
1021
+ const unverifiedAdmission = new Set(checked.flatMap((c) => (c.verdict === 'invalid' && c.payload !== null && c.payload.typ !== 'closure' ? [c.payload.subject.spkiSha256] : [])));
1011
1022
  // A listed retirement the walk does not sign, read against the Server's own
1012
1023
  // distrust instant (`distrustedFrom`): where the listing was cut at that
1013
1024
  // instant and the walk signs a later retirement or none, the column is the
@@ -1197,7 +1208,9 @@ export function keyStatementsFromExport(signingKeyStatements) {
1197
1208
  * statement format this verifier does not read.
1198
1209
  */
1199
1210
  export function keyStatementsFromVerificationKeys(doc) {
1200
- if (doc === null || typeof doc !== 'object' || !Array.isArray(doc.data)) {
1211
+ // Checked through an `unknown` copy so the guard does not retype `doc.data` as `any[]`.
1212
+ const rawData = doc?.data;
1213
+ if (doc === null || typeof doc !== 'object' || !Array.isArray(rawData)) {
1201
1214
  throw new TypeError('Expected the /v1/verification-keys document: { data: [...], keyStatementFormat, anchoredFrom }.');
1202
1215
  }
1203
1216
  if (doc.keyStatementFormat !== undefined && doc.keyStatementFormat !== KEY_STATEMENT_CTY) {
@@ -1218,7 +1231,7 @@ export function keyStatementsFromVerificationKeys(doc) {
1218
1231
  /**
1219
1232
  * Mark every key of a registry with the walk's verdict, and give each anchored
1220
1233
  * key the window its statements sign in place of whatever window it carried,
1221
- * as the engine grades entries. An anchored key no statement dates carries no
1234
+ * as the Server grades entries. An anchored key no statement dates carries no
1222
1235
  * edge on that side. A key is anchored only when its key id is the
1223
1236
  * fingerprint of its own SPKI: a row filed under another key's id names that
1224
1237
  * key's entries, and is anchored to nothing. On a walk over a dump, a key a
@@ -1256,10 +1269,27 @@ export function applyKeyTrust(registry, trust) {
1256
1269
  }
1257
1270
  return out;
1258
1271
  }
1259
- /** The {@link Verdict} of a result that carries `valid` and a `keyTrust` report. */
1260
- export function verdictOf(result) {
1261
- if (!result.valid)
1262
- return 'failed';
1272
+ /**
1273
+ * The {@link Verdict} of a result that carries `valid` and a `keyTrust` report.
1274
+ *
1275
+ * Pass `passesUnpinned` on a run that supplied trustAnchors: it reruns the
1276
+ * same input with the same options minus `trustAnchors` and `distrustedKeys`
1277
+ * and says whether that run is valid. A pinned run that failed, whose walk
1278
+ * anchored no key at all, and whose unpinned rerun passes, is `unanchored`
1279
+ * rather than `failed`: the only thing wrong is that the pin reaches nothing
1280
+ * in the artifact (the key-statement findings and CHAIN_SIGNING_KEY_UNANCHORED
1281
+ * entries such a walk reports all follow from that). That is an export checked
1282
+ * against another Server's pin, and equally one re-signed wholesale under keys
1283
+ * of its own; neither is trusted, and the result keeps `valid: false`. An
1284
+ * artifact in which the pin anchors even one key stays `failed`, since an
1285
+ * entry beside it under an unanchored key is a substitution.
1286
+ */
1287
+ export function verdictOf(result, passesUnpinned) {
1288
+ if (!result.valid) {
1289
+ const pinNotMet = result.keyTrust.status === 'no_anchored_signature' && result.keyTrust.anchoredKeyIds.length === 0
1290
+ && passesUnpinned !== undefined && passesUnpinned();
1291
+ return pinNotMet ? 'unanchored' : 'failed';
1292
+ }
1263
1293
  return result.keyTrust.status === 'walked' ? 'trusted' : 'unanchored';
1264
1294
  }
1265
1295
  /**
package/dist/options.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Options renamed in a major release, by their old name. A caller upgrading
3
- * with the old name would otherwise drop the check it asked for and still
4
- * pass.
2
+ * Option names an earlier major release read, mapped to their current name. A
3
+ * caller still passing the old name would otherwise drop the check it asked
4
+ * for and still pass.
5
5
  */
6
6
  const RENAMED = {
7
7
  requireOutOfBandKeys: 'requireSuppliedKeys',
@@ -23,7 +23,7 @@ export function assertKnownOptions(fn, options, known) {
23
23
  continue;
24
24
  const renamed = RENAMED[key];
25
25
  throw new TypeError(renamed !== undefined && known.includes(renamed)
26
- ? `${fn}: the ${key} option is now ${renamed}; pass ${renamed} instead. It was renamed in 2.0.0, and an unknown option is refused rather than ignored.`
26
+ ? `${fn}: the ${key} option is now ${renamed}; pass ${renamed} instead. An unknown option is refused rather than ignored.`
27
27
  : `${fn}: unknown option ${key}. It reads ${known.join(', ')}.`);
28
28
  }
29
29
  }
@@ -13,7 +13,7 @@ export declare function sha256HexString(s: string): string;
13
13
  * public key can never be repurposed as a MAC key.
14
14
  */
15
15
  export interface KeyAlgorithm {
16
- /** Registry name, matching the engine's `vault_signing_keys.algorithm` values. */
16
+ /** Registry name, matching the algorithm names the Server's key registry uses. */
17
17
  name: string;
18
18
  /** COSE `alg` values (protected header label 1) acceptable for this key. */
19
19
  coseAlgs: readonly number[];
@@ -74,11 +74,11 @@ export declare function resolveKeyAlgorithm(publicKeyBase64: string): KeyAlgorit
74
74
  /**
75
75
  * Verify an Ed25519 signature over raw bytes.
76
76
  * `publicKeyBase64` is the SPKI DER public key, base64-encoded
77
- * (matches the engine's vault_signing_keys.public_key column).
77
+ * (the shape the Server's key registry publishes).
78
78
  *
79
79
  * Refuses non-Ed25519 keys. Node's `verify(null, ...)` silently falls back to
80
80
  * ECDSA/SHA-256 for EC keys, which would accept a signature no conformant
81
- * EdDSA verifier accepts (the engine guards the signing side the same way),
81
+ * EdDSA verifier accepts (the Server guards the signing side the same way),
82
82
  * so the key type is asserted before any crypto runs.
83
83
  *
84
84
  * CAUTION for direct callers: as with `verifySignatureBytes`, `false` conflates
@@ -112,9 +112,9 @@ export declare function describeUnsupportedAlgorithm(publicKeyBase64: string): s
112
112
  * the upgrade-vs-forgery distinction use `resolveKeyAlgorithm` first, as
113
113
  * `verifyCoseSign1` does).
114
114
  *
115
- * ES256 mirrors the engine's `verifyWithAlgorithm`: SHA-256 digest passed
115
+ * ES256 mirrors how the Server verifies it: SHA-256 digest passed
116
116
  * positionally, `dsaEncoding: 'ieee-p1363'` (COSE raw r||s, 64 bytes). The
117
- * engine normalizes to low-S at sign time but, like the engine's verifier,
117
+ * Server normalizes to low-S at sign time but, like the Server's verifier,
118
118
  * high-S is accepted here: ECDSA malleability changes the envelope bytes,
119
119
  * which the hash-link layer already pins.
120
120
  *
@@ -150,7 +150,7 @@ export declare function decodeCoseSign1(bytes: Uint8Array): CoseSign1Parts | nul
150
150
  * - 'decode-fail' if the envelope is malformed
151
151
  * - 'invalid' if the signature does not verify
152
152
  * - 'unsigned' if the signature slot is all-zero at the key's expected
153
- * signature length (engine booted without VAULT_SIGNING_KEY
153
+ * signature length (a Server running without a signing key
154
154
  * at write time; chain integrity falls back to the hash-link
155
155
  * layer)
156
156
  * - 'alg-mismatch' if the protected header's `alg` (label 1) is absent or is
@@ -173,10 +173,10 @@ export type CoseVerifyOutcome = 'ok' | 'decode-fail' | 'invalid' | 'unsigned' |
173
173
  export declare function verifyCoseSign1(coseSign1: Uint8Array, publicKeyBase64: string): CoseVerifyOutcome;
174
174
  /**
175
175
  * Extract the signature-covered `kid` (protected header label 4) as lowercase
176
- * hex, matching the engine's `vault_signing_keys.key_id` shape. Returns null
176
+ * hex, matching the key id shape the Server's key registry uses. Returns null
177
177
  * when absent or malformed. The caller cross-checks it against the row's
178
178
  * `signingKeyId` column: the column is a denormalized convenience, the kid is
179
- * signed, so a rewritten column surfaces as drift (engine mirror: signing_key_drift).
179
+ * signed, so a rewritten column surfaces as drift (Server mirror: signing_key_drift).
180
180
  */
181
181
  export declare function extractKid(protectedBstr: Uint8Array): string | null;
182
182
  /**
@@ -195,12 +195,12 @@ export declare function extractChainClaim(protectedBstr: Uint8Array): ChainClaim
195
195
  * Extract the actor identity claim (`-65539`) from a COSE_Sign1 protected
196
196
  * header. It is nested inside CWT_Claims (RFC 9597, label 15) rather than
197
197
  * sitting at the outer header level, because it IS an identity statement: the
198
- * engine keeps the outer level to IANA-known labels plus chain mechanics.
198
+ * Server keeps the outer level to IANA-known labels plus chain mechanics.
199
199
  *
200
- * `key_id` and `owner_id` are UUIDs the engine encodes as 16-byte CBOR byte
200
+ * `key_id` and `owner_id` are UUIDs the Server encodes as 16-byte CBOR byte
201
201
  * strings, returned here in canonical lowercase-hyphenated form so they
202
202
  * compare directly against the export's `actorId` / `actorOwnerId` columns.
203
- * Returns null when the claim is missing or malformed (engines older than the
203
+ * Returns null when the claim is missing or malformed (Servers older than the
204
204
  * claim, or an envelope that will not decode) so the caller can skip rather
205
205
  * than fail an entry that never carried it.
206
206
  */
@@ -224,7 +224,7 @@ export declare function extractOnBehalfOfClaim(payloadBstr: Uint8Array): Record<
224
224
  */
225
225
  export declare function extractTraceparentClaim(payloadBstr: Uint8Array): string | null;
226
226
  /**
227
- * Domain-separation prefix the engine applies before verifying an agent's
227
+ * Domain-separation prefix the Server applies before verifying an agent's
228
228
  * `X-Agent-Signature` at intake: the agent signs the UTF-8 bytes of this
229
229
  * prefix followed by the lowercase hex sha256 of the raw request body (the
230
230
  * hex string, not the digest bytes). Distinct from the cert proof-of-possession
@@ -239,13 +239,13 @@ export interface AgentPublicKeyJwk {
239
239
  x: string;
240
240
  }
241
241
  /**
242
- * The agent-signature evidence the engine sealed into a chain entry, read from
242
+ * The agent-signature evidence the Server sealed into a chain entry, read from
243
243
  * the signed payload. Fields are left `unknown` where the verifier must check
244
- * their shape itself: a sealed value the engine never writes is a finding, not
244
+ * their shape itself: a sealed value the Server never writes is a finding, not
245
245
  * something to coerce.
246
246
  */
247
247
  export interface AgentSignatureClaim {
248
- /** `on_behalf_of.validated === true`: the engine vouched for the identity. */
248
+ /** `on_behalf_of.validated === true`: the Server vouched for the identity. */
249
249
  validated: boolean;
250
250
  /** `on_behalf_of.cert.id`, when a cert is sealed beside the signature. */
251
251
  certId: string | null;
@@ -262,10 +262,10 @@ export interface AgentSignatureClaim {
262
262
  */
263
263
  export declare function extractAgentSignatureClaim(payloadBstr: Uint8Array): AgentSignatureClaim | null;
264
264
  /**
265
- * RFC 7638 thumbprint of an Ed25519 JWK in the engine's `sha256:<hex>` form,
265
+ * RFC 7638 thumbprint of an Ed25519 JWK in the Server's `sha256:<hex>` form,
266
266
  * or null when the value is not an Ed25519 public-key JWK. The members are
267
267
  * hashed in the RFC's lexicographic order (`crv`, `kty`, `x`), which is what
268
- * the engine's thumbprint function produces for an OKP key.
268
+ * the Server's thumbprint function produces for an OKP key.
269
269
  */
270
270
  export declare function ed25519JwkThumbprint(jwk: unknown): string | null;
271
271
  /** SPKI DER (base64) for an Ed25519 JWK, or null when it is not one. */
@@ -276,9 +276,9 @@ export type AgentSignatureOutcome = 'ok' | 'invalid' | 'malformed' | 'unsupporte
276
276
  *
277
277
  * - `ok`: the signature verifies over `AGENT_SIGNATURE_CONTEXT + <hex>`.
278
278
  * - `invalid`: well formed, does not verify under this key.
279
- * - `malformed`: a shape the engine never writes (alg other than EdDSA, a
279
+ * - `malformed`: a shape the Server never writes (alg other than EdDSA, a
280
280
  * content hash not `sha256:<hex64>`, a signature that is not 64 bytes of
281
- * standard base64). Nothing can verify it, which the engine also treats as
281
+ * standard base64). Nothing can verify it, which the Server also treats as
282
282
  * a break.
283
283
  * - `unsupported`: this host cannot compute Ed25519 (an active OpenSSL FIPS
284
284
  * provider). NOT verified and NOT tamper evidence.
@@ -292,15 +292,14 @@ export declare function verifyAgentSignature(spkiBase64: string, claim: Pick<Age
292
292
  * Decode the predicate object from a COSE_Sign1 payload bstr. The payload IS
293
293
  * the in-toto v1 Statement; the predicate body lives at `payload.predicate`.
294
294
  * Returns null on any decode failure. Used by the binding-integrity check; the
295
- * row's denormalised `payload` jsonb is a convenience view projected from this
295
+ * entry's readable `payload` is a convenience view projected from this
296
296
  * predicate at write time; if the view was altered after signing,
297
297
  * `buildPredicateForRow(...) !== decodePredicate(...)`.
298
298
  */
299
299
  export declare function decodePredicate(payloadBstr: Uint8Array): Record<string, unknown> | null;
300
300
  /**
301
301
  * Re-project (record_id, entry_type, payload) -> predicate body using the SAME
302
- * logic the engine uses at write time (engine-side: audit-vault/
303
- * build-vault-claim.ts). This is the verifier-side mirror.
302
+ * logic the Server uses at write time. This is the verifier-side mirror.
304
303
  *
305
304
  * Returns null when the row's payload is structurally insufficient (e.g.
306
305
  * SCHEMA_REGISTERED missing manifestDigest) or is not a JSON object at all (a
@@ -318,7 +317,7 @@ export declare function deepEqual(a: unknown, b: unknown): boolean;
318
317
  /**
319
318
  * Strip envelope-level sibling fields (`on_behalf_of`, `traceparent`) from a
320
319
  * decoded predicate. They ride alongside per-kind predicate fields on the wire
321
- * but the engine's `buildPredicateOnly` (and our `buildPredicateForRow`
320
+ * but the Server's own predicate builder (and our `buildPredicateForRow`
322
321
  * mirror) exclude them from the rebuilt predicate. Stripping here makes the
323
322
  * two shapes deep-equalable; envelope-level integrity is covered by the
324
323
  * signature and the OIDC-actor cross-check.
@@ -328,30 +327,34 @@ export declare function stripEnvelopeExtensions(predicate: Record<string, unknow
328
327
  * Whether the envelope extensions a row's payload carries are the ones the
329
328
  * entry signed. When a writer puts `on_behalf_of` (an object) or
330
329
  * `traceparent` (a W3C v00 string; any other value is dropped) at the top
331
- * level of the row payload, the engine lifts it into `predicate.on_behalf_of`
330
+ * level of the row payload, the Server lifts it into `predicate.on_behalf_of`
332
331
  * / `predicate.traceparent`, so a row copy must equal the signed value. The
333
332
  * row copy is what a reader of an export or dump sees, and
334
333
  * {@link stripEnvelopeExtensions} takes both sides out of the predicate
335
334
  * comparison, so without this check a rewritten or added row copy would still
336
335
  * verify.
337
336
  *
338
- * Anything else under those keys is ignored, as the engine ignores it: it
337
+ * Anything else under those keys is ignored, as the Server ignores it: it
339
338
  * lifts only an object `on_behalf_of` and a v00 `traceparent`, so a genuine
340
339
  * older row holding another shape signed nothing for it.
341
340
  *
342
- * A row without them is not a mismatch: the engine also signs an
343
- * `on_behalf_of` built from the request's authentication rather than from the
344
- * payload, and that one never reaches the row payload. Its identity is held to
345
- * the row's actor columns by the OIDC-actor check instead.
341
+ * `projected` says whether the payload is one the Server fills from the
342
+ * signed predicate. An export entry's is: the Server writes every
343
+ * `on_behalf_of` and v00 `traceparent` the entry signed into it, including an
344
+ * `on_behalf_of` built from the request's authentication, so a signed one the
345
+ * payload lacks was deleted after export. A vault row's payload never holds
346
+ * them (the Server keeps them only inside the signed envelope), so on a dump
347
+ * a row without them is not a mismatch, and the identity is held to the row's
348
+ * actor columns by the OIDC-actor check instead.
346
349
  */
347
- export declare function envelopeExtensionsMatch(rowPayload: Record<string, unknown>, signedPredicate: Record<string, unknown>): boolean;
350
+ export declare function envelopeExtensionsMatch(rowPayload: Record<string, unknown>, signedPredicate: Record<string, unknown>, projected?: boolean): boolean;
348
351
  /** RFC 9162 §2.1.1 leaf hash: SHA-256(0x00 || d). */
349
352
  export declare function rfc9162LeafHash(leafData: Uint8Array): Uint8Array;
350
353
  /** RFC 9162 §2.1.1 internal-node hash: SHA-256(0x01 || left || right). */
351
354
  export declare function rfc9162NodeHash(left: Uint8Array, right: Uint8Array): Uint8Array;
352
355
  /**
353
- * Verify a RFC 9162 §2.1.3.2 inclusion proof. Mirrors the engine-side
354
- * implementation; reproduced here so the verifier stays engine-free. False
356
+ * Verify a RFC 9162 §2.1.3.2 inclusion proof. Mirrors the Server-side
357
+ * implementation; reproduced here so the verifier stays Server-free. False
355
358
  * when `leafIndex` or `treeSize` is not a safe integer: the walk halves them,
356
359
  * and a fraction, NaN or an unsafe integer would walk some other tree.
357
360
  */