Repository navigation
Expand file tree
/
Copy pathtest-trust.mjs
More file actions
437 lines (389 loc) · 21.6 KB
/
Copy pathtest-trust.mjs
File metadata and controls
437 lines (389 loc) · 21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
/**
* Trust-profile verification tests for insumer-verify.
*
* Covers POST /v1/trust (and /v1/trust/batch entries) under both schemes:
* insumer-attest-v1 → bare JSON.stringify(trust) (v1, frozen)
* insumer-trust-v2 → "insumer.trust.v2\n" + canonical JSON (v2, domain-separated)
*
* Test 5 is the domain-separation guard: a signature made over the ATTEST
* domain must not verify as a trust profile, even though both message types
* share one key. Test 11/12 are the scheme-difference guard: reordering the
* payload's keys breaks v1 (insertion-order preimage) but not v2 (canonical).
*
* No secrets: every key here is an ephemeral P-256 keypair generated at
* runtime; the wallet is a public/well-known dummy address.
*
* Run: node test-trust.mjs
*/
import { verifyTrustProfile } from "./build/index.js";
const subtle = globalThis.crypto.subtle;
const V2_TRUST_DOMAIN = "insumer.trust.v2";
const V2_TRUST_KID = "insumer-trust-v2";
const V1_KID = "insumer-attest-v1";
const V2_ATTEST_DOMAIN = "insumer.attestation.v2";
let passed = 0;
let failed = 0;
function assert(condition, name) {
if (condition) { console.log(` PASS: ${name}`); passed++; }
else { console.log(` FAIL: ${name}`); failed++; }
}
// Must match build/index.js canonicalize (recursive sorted-key).
function canonicalize(value) {
if (Array.isArray(value)) return "[" + value.map(canonicalize).join(",") + "]";
if (value && typeof value === "object") {
return "{" + Object.keys(value).sort()
.map((k) => JSON.stringify(k) + ":" + canonicalize(value[k]))
.join(",") + "}";
}
return JSON.stringify(value);
}
const b64 = (bytes) => btoa(String.fromCharCode(...bytes));
async function genKey() {
return subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, ["sign", "verify"]);
}
// Web Crypto ECDSA emits P1363 (raw r||s), the encoding the API's sig field uses.
async function sign(privateKey, str) {
const sig = await subtle.sign({ name: "ECDSA", hash: "SHA-256" }, privateKey, new TextEncoder().encode(str));
return b64(new Uint8Array(sig));
}
function mockJwks(publicKey, kids) {
const original = globalThis.fetch;
globalThis.fetch = async (url) => {
if (typeof url === "string" && url.includes("jwks")) {
const jwk = await subtle.exportKey("jwk", publicKey);
return {
ok: true,
json: async () => ({
keys: kids.map((kid) => ({ kty: jwk.kty, crv: jwk.crv, x: jwk.x, y: jwk.y, kid })),
}),
};
}
return original(url);
};
return () => { globalThis.fetch = original; };
}
const JWKS = "https://test.example.com/.well-known/jwks.json";
const WALLET = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; // USDC contract, public
/**
* Build a trust payload in the key order the API constructs it:
* id, wallet, conditionSetVersion, dimensions, summary, profiledAt, expiresAt.
*/
function makeTrustPayload({ v2 = true, ageMs = 0, ttlMs = 30 * 60 * 1000, blockAgeMs = 0 } = {}) {
const now = new Date(Date.now() - ageMs);
const blockTs = new Date(Date.now() - blockAgeMs).toISOString();
return {
id: "trust_test_0001",
wallet: WALLET,
conditionSetVersion: v2 ? "v2" : "v1",
// real backend shape: dimensions keyed by name, each with a checks[] array
// whose entries carry an on-chain blockTimestamp (exercises nested freshness
// + recursive canonicalization)
dimensions: {
onChainActivity: { checks: [{ label: "tx count", met: true, blockTimestamp: blockTs }] },
tokenHoldings: { checks: [{ label: "USDC", met: true, blockTimestamp: blockTs }] },
},
summary: {
totalChecks: 5,
totalPassed: 4,
totalFailed: 1,
dimensionsWithActivity: 2,
dimensionsChecked: 2,
},
profiledAt: now.toISOString(),
expiresAt: new Date(now.getTime() + ttlMs).toISOString(),
};
}
const wrap = (trust, sig, kid) => ({ ok: true, data: { trust, sig, kid }, meta: {} });
console.log("\ninsumer-verify — trust profile suite\n");
const { privateKey: priv, publicKey: pub } = await genKey();
const restore = mockJwks(pub, [V1_KID, "insumer-attest-v2", V2_TRUST_KID]);
try {
// 1. v2 happy path
{
const trust = makeTrustPayload({ v2: true });
const sig = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const r = await verifyTrustProfile(wrap(trust, sig, V2_TRUST_KID), { jwksUrl: JWKS });
assert(r.valid === true, "v2 trust profile verifies");
assert(r.checks.signature.passed === true, "v2 signature check passes");
assert(r.checks.expiry.passed === true, "v2 expiry check passes");
}
// 2. v1 happy path (bare JSON.stringify, shared attest kid)
{
const trust = makeTrustPayload({ v2: false });
const sig = await sign(priv, JSON.stringify(trust));
const r = await verifyTrustProfile(wrap(trust, sig, V1_KID), { jwksUrl: JWKS });
assert(r.valid === true, "v1 trust profile verifies");
}
// 3. tampered payload — v2
{
const trust = makeTrustPayload({ v2: true });
const sig = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const tampered = { ...trust, summary: { ...trust.summary, totalPassed: 5 } };
const r = await verifyTrustProfile(wrap(tampered, sig, V2_TRUST_KID), { jwksUrl: JWKS });
assert(r.valid === false && r.checks.signature.passed === false, "v2 tampered summary rejected");
}
// 4. tampered payload — v1
{
const trust = makeTrustPayload({ v2: false });
const sig = await sign(priv, JSON.stringify(trust));
const tampered = { ...trust, wallet: "0x0000000000000000000000000000000000000001" };
const r = await verifyTrustProfile(wrap(tampered, sig, V1_KID), { jwksUrl: JWKS });
assert(r.valid === false && r.checks.signature.passed === false, "v1 tampered wallet rejected");
}
// 5. DOMAIN SEPARATION — attest-domain signature must not verify as trust
{
const trust = makeTrustPayload({ v2: true });
const sig = await sign(priv, V2_ATTEST_DOMAIN + "\n" + canonicalize(trust));
const r = await verifyTrustProfile(wrap(trust, sig, V2_TRUST_KID), { jwksUrl: JWKS });
assert(r.valid === false, "attest-domain signature rejected as trust profile");
}
// 6. scheme confusion — v2 bytes labelled with the v1 kid
{
const trust = makeTrustPayload({ v2: true });
const sig = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const r = await verifyTrustProfile(wrap(trust, sig, V1_KID), { jwksUrl: JWKS });
assert(r.valid === false, "v2 bytes under v1 kid rejected");
}
// 7. expired profile
{
const trust = makeTrustPayload({ v2: true, ageMs: 60 * 60 * 1000, ttlMs: 30 * 60 * 1000 });
const sig = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const r = await verifyTrustProfile(wrap(trust, sig, V2_TRUST_KID), { jwksUrl: JWKS });
assert(r.checks.signature.passed === true, "expired profile still has a valid signature");
assert(r.checks.expiry.passed === false && r.valid === false, "expired profile rejected");
}
// 8. freshness via maxAge
{
const trust = makeTrustPayload({ v2: true, ageMs: 10 * 60 * 1000, ttlMs: 60 * 60 * 1000 });
const sig = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const stale = await verifyTrustProfile(wrap(trust, sig, V2_TRUST_KID), { jwksUrl: JWKS, maxAge: 60 });
const fresh = await verifyTrustProfile(wrap(trust, sig, V2_TRUST_KID), { jwksUrl: JWKS, maxAge: 3600 });
assert(stale.checks.freshness.passed === false && stale.valid === false, "maxAge 60s rejects a 10min-old profile");
assert(fresh.valid === true, "maxAge 3600s accepts a 10min-old profile");
}
// 9. batch-entry shape (no { data } wrapper)
{
const trust = makeTrustPayload({ v2: true });
const sig = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const r = await verifyTrustProfile({ trust, sig, kid: V2_TRUST_KID }, { jwksUrl: JWKS });
assert(r.valid === true, "bare { trust, sig, kid } batch entry verifies");
}
// 10. malformed input
{
const a = await verifyTrustProfile({ ok: true, data: {} }, { jwksUrl: JWKS });
const b = await verifyTrustProfile("not an object", { jwksUrl: JWKS });
assert(a.valid === false, "missing trust rejected");
assert(b.valid === false, "non-object rejected");
}
// 11. v1 is insertion-order sensitive (documents why trust is not rebuilt)
{
const trust = makeTrustPayload({ v2: false });
const sig = await sign(priv, JSON.stringify(trust));
const reordered = {
expiresAt: trust.expiresAt,
profiledAt: trust.profiledAt,
summary: trust.summary,
dimensions: trust.dimensions,
conditionSetVersion: trust.conditionSetVersion,
wallet: trust.wallet,
id: trust.id,
};
const r = await verifyTrustProfile(wrap(reordered, sig, V1_KID), { jwksUrl: JWKS });
assert(r.valid === false, "v1 rejects a key-reordered payload (insertion-order preimage)");
}
// 12. v2 is order-independent (canonical preimage)
{
const trust = makeTrustPayload({ v2: true });
const sig = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const reordered = {
expiresAt: trust.expiresAt,
profiledAt: trust.profiledAt,
summary: trust.summary,
dimensions: trust.dimensions,
conditionSetVersion: trust.conditionSetVersion,
wallet: trust.wallet,
id: trust.id,
};
const r = await verifyTrustProfile(wrap(reordered, sig, V2_TRUST_KID), { jwksUrl: JWKS });
assert(r.valid === true, "v2 accepts a key-reordered payload (canonical preimage)");
}
// 13. wrong key entirely
{
const other = await genKey();
const trust = makeTrustPayload({ v2: true });
const sig = await sign(other.privateKey, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const r = await verifyTrustProfile(wrap(trust, sig, V2_TRUST_KID), { jwksUrl: JWKS });
assert(r.valid === false, "signature from a foreign key rejected");
}
// ── Fix 1: structural gate against the shared v1 kid ────────────────
// 14. a validly v1-signed object of another type must NOT pass as a trust profile
{
const now = new Date();
const otherArtifact = {
kind: "other-v1-artifact", value: 1,
expiresAt: new Date(now.getTime() + 1800000).toISOString(),
};
const sig = await sign(priv, JSON.stringify(otherArtifact)); // genuine v1 signature
const r = await verifyTrustProfile(wrap(otherArtifact, sig, V1_KID), { jwksUrl: JWKS });
assert(r.valid === false, "validly-signed object of another type rejected (not trust-shaped)");
assert(/not a trust profile/i.test(r.checks.signature.reason || ""), "rejection cites shape, not crypto");
}
// 15. a genuine attestation object, validly signed v1, must NOT pass as trust
{
const now = new Date();
const attn = {
id: "att_1", pass: true, results: [], attestedAt: now.toISOString(),
expiresAt: new Date(now.getTime() + 1800000).toISOString(),
};
const sig = await sign(priv, JSON.stringify(attn));
const r = await verifyTrustProfile(wrap(attn, sig, V1_KID), { jwksUrl: JWKS });
assert(r.valid === false, "validly-signed attestation rejected (not trust-shaped)");
}
// ── Fix 2: the verified object is returned ──────────────────────────
// 16. result.trust echoes the exact verified profile on success; absent on parse-fail
{
const trust = makeTrustPayload({ v2: true });
const sig = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const r = await verifyTrustProfile(wrap(trust, sig, V2_TRUST_KID), { jwksUrl: JWKS });
assert(r.valid === true && r.trust && r.trust.wallet === WALLET && r.trust.id === trust.id,
"result.trust returns the verified profile");
const bad = await verifyTrustProfile({ ok: true, data: {} }, { jwksUrl: JWKS });
assert(bad.trust === undefined, "result.trust is undefined when parsing fails");
}
// ── Fix 3: nested on-chain blockTimestamp freshness ─────────────────
// 17. profiledAt fresh, but a dimension's on-chain read is stale → fails freshness
{
const trust = makeTrustPayload({ v2: true, ageMs: 0, blockAgeMs: 10 * 60 * 1000 });
const sig = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const r = await verifyTrustProfile(wrap(trust, sig, V2_TRUST_KID), { jwksUrl: JWKS, maxAge: 60 });
assert(r.checks.signature.passed === true, "stale-block profile still has a valid signature");
assert(r.checks.freshness.passed === false && r.valid === false, "stale nested blockTimestamp fails freshness");
assert(/on-chain data/i.test(r.checks.freshness.reason || ""), "freshness reason names the on-chain staleness");
}
// 18. profiledAt and nested blockTimestamp both fresh → passes under maxAge
{
const trust = makeTrustPayload({ v2: true, ageMs: 5000, blockAgeMs: 5000 });
const sig = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const r = await verifyTrustProfile(wrap(trust, sig, V2_TRUST_KID), { jwksUrl: JWKS, maxAge: 3600 });
assert(r.valid === true, "fresh profiledAt + fresh nested block passes under maxAge");
}
// ── Condition hashes inside the profile (every check carries one since October 2026) ──
const sha256hex = async (str) =>
"0x" + Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(str)))).map((b) => b.toString(16).padStart(2, "0")).join("");
const v1Form = (ec) => JSON.stringify(ec, Object.keys(ec).sort());
async function makeHashedTrust({ v2 = true, breakHash = false, dropHash = false } = {}) {
const trust = makeTrustPayload({ v2 });
const ec = { type: "token_balance", chainId: 1, contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", operator: "gte", threshold: 0, decimals: 6 };
for (const dim of Object.values(trust.dimensions)) {
for (const c of dim.checks) {
c.evaluatedCondition = ec;
c.conditionHash = await sha256hex(v2 ? canonicalize(ec) : v1Form(ec));
}
}
if (breakHash) trust.dimensions.tokenHoldings.checks[0].conditionHash = "0x" + "00".repeat(32);
if (dropHash) delete trust.dimensions.tokenHoldings.checks[0].conditionHash;
return trust;
}
// 23. v2: every check's hash recomputes → passes with no reason
{
const trust = await makeHashedTrust({ v2: true });
const sig = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const r = await verifyTrustProfile(wrap(trust, sig, V2_TRUST_KID), { jwksUrl: JWKS });
assert(r.valid === true && r.checks.conditionHashes.passed === true && r.checks.conditionHashes.reason === undefined,
"v2 profile with matching condition hashes passes the hash check");
}
// 24. v1: the sorted-key form is the one recomputed under the v1 kid
{
const trust = await makeHashedTrust({ v2: false });
const sig = await sign(priv, JSON.stringify(trust));
const r = await verifyTrustProfile(wrap(trust, sig, V1_KID), { jwksUrl: JWKS });
assert(r.valid === true && r.checks.conditionHashes.passed === true, "v1 profile with matching condition hashes passes the hash check");
}
// 25. a wrong hash, signed as issued, fails the hash verdict alone and names the check
{
const trust = await makeHashedTrust({ v2: true, breakHash: true });
const sig = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const r = await verifyTrustProfile(wrap(trust, sig, V2_TRUST_KID), { jwksUrl: JWKS });
assert(r.checks.signature.passed === true, "wrong hash: signature still verifies (signed as issued)");
assert(r.checks.conditionHashes.passed === false && r.valid === false, "wrong hash fails the profile");
assert(JSON.stringify(r.checks.conditionHashes.failures) === JSON.stringify(["tokenHoldings[0]"]), "failure names dimension[index]");
}
// 26. a check missing its hash while others carry one fails at that check
{
const trust = await makeHashedTrust({ v2: true, dropHash: true });
const sig = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const r = await verifyTrustProfile(wrap(trust, sig, V2_TRUST_KID), { jwksUrl: JWKS });
assert(r.checks.conditionHashes.passed === false && r.checks.conditionHashes.failures[0] === "tokenHoldings[0]", "missing hash on one check fails at that check");
}
// 27. a profile with no hashes anywhere (issued before the fields) passes with a reason
{
const trust = makeTrustPayload({ v2: true });
const sig = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
const r = await verifyTrustProfile(wrap(trust, sig, V2_TRUST_KID), { jwksUrl: JWKS });
assert(r.valid === true && r.checks.conditionHashes.passed === true && /No condition hashes/.test(r.checks.conditionHashes.reason || ""),
"profile without condition hashes passes the hash check with a reason");
}
// 28. parse failure reports the hash verdict as skipped
{
const r = await verifyTrustProfile({ ok: true, data: {} }, { jwksUrl: JWKS });
assert(r.checks.conditionHashes.passed === false && /Skipped/.test(r.checks.conditionHashes.reason || ""), "parse failure skips the hash check");
}
// ── Clock-skew allowance (options.clockSkew, default 60s; spec Section 9.4) ──
// 19. expiry: 30s past expiresAt is inside the default allowance; clockSkew: 0 refuses it;
// 90s past is beyond it
{
const within = makeTrustPayload({ v2: true, ageMs: 30 * 60 * 1000 + 30000, ttlMs: 30 * 60 * 1000 });
const sigW = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(within));
let r = await verifyTrustProfile(wrap(within, sigW, V2_TRUST_KID), { jwksUrl: JWKS });
assert(r.checks.expiry.passed === true && r.valid === true, "30s past expiresAt passes under the default 60s skew");
r = await verifyTrustProfile(wrap(within, sigW, V2_TRUST_KID), { jwksUrl: JWKS, clockSkew: 0 });
assert(r.checks.expiry.passed === false && r.valid === false, "30s past expiresAt fails with clockSkew: 0");
const beyond = makeTrustPayload({ v2: true, ageMs: 30 * 60 * 1000 + 90000, ttlMs: 30 * 60 * 1000 });
const sigB = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(beyond));
r = await verifyTrustProfile(wrap(beyond, sigB, V2_TRUST_KID), { jwksUrl: JWKS });
assert(r.checks.expiry.passed === false && r.valid === false, "90s past expiresAt fails under the default 60s skew");
}
// 20. freshness: the allowance is added to maxAge on profiledAt and on nested blockTimestamps
{
const profile = makeTrustPayload({ v2: true, ageMs: 100000, blockAgeMs: 0, ttlMs: 60 * 60 * 1000 });
const sigP = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(profile));
let r = await verifyTrustProfile(wrap(profile, sigP, V2_TRUST_KID), { jwksUrl: JWKS, maxAge: 60 });
assert(r.checks.freshness.passed === true, "100s-old profiledAt passes maxAge 60 under the default 60s skew");
r = await verifyTrustProfile(wrap(profile, sigP, V2_TRUST_KID), { jwksUrl: JWKS, maxAge: 60, clockSkew: 0 });
assert(r.checks.freshness.passed === false, "100s-old profiledAt fails maxAge 60 with clockSkew: 0");
const block = makeTrustPayload({ v2: true, ageMs: 0, blockAgeMs: 100000, ttlMs: 60 * 60 * 1000 });
const sigK = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(block));
r = await verifyTrustProfile(wrap(block, sigK, V2_TRUST_KID), { jwksUrl: JWKS, maxAge: 60 });
assert(r.checks.freshness.passed === true, "100s-old nested block passes maxAge 60 under the default 60s skew");
r = await verifyTrustProfile(wrap(block, sigK, V2_TRUST_KID), { jwksUrl: JWKS, maxAge: 60, clockSkew: 0 });
assert(r.checks.freshness.passed === false && /on-chain data/i.test(r.checks.freshness.reason || ""),
"100s-old nested block fails maxAge 60 with clockSkew: 0");
const beyond = makeTrustPayload({ v2: true, ageMs: 0, blockAgeMs: 130000, ttlMs: 60 * 60 * 1000 });
const sigX = await sign(priv, V2_TRUST_DOMAIN + "\n" + canonicalize(beyond));
r = await verifyTrustProfile(wrap(beyond, sigX, V2_TRUST_KID), { jwksUrl: JWKS, maxAge: 60 });
assert(r.checks.freshness.passed === false, "130s-old nested block fails maxAge 60 under the default 60s skew");
}
} finally {
restore();
}
console.log("\n kid is mandatory and bound to the artifact type (1.8.2)");
{
const kp = await genKey();
const restore2 = mockJwks(kp.publicKey, ["insumer-attest-v1", "insumer-attest-v2", V2_TRUST_KID]);
try {
const trust = makeTrustPayload({ v2: true });
const sig = await sign(kp.privateKey, V2_TRUST_DOMAIN + "\n" + canonicalize(trust));
let r = await verifyTrustProfile(wrap(trust, sig, undefined), { jwksUrl: JWKS });
assert(!r.valid && /no kid/.test(r.checks.signature.reason), "missing kid on a trust profile fails closed");
assert(r.checks.freshness.passed && r.checks.expiry.passed && r.checks.pq.status === "absent", "missing kid: freshness, expiry and the companion still report their own results");
r = await verifyTrustProfile(wrap(trust, sig, "insumer-trust-v9"), { jwksUrl: JWKS });
assert(!r.valid && /no key matching kid/.test(r.checks.signature.reason), "a kid the key set does not hold fails the signature verdict with that reason");
assert(r.checks.freshness.passed && r.checks.expiry.passed && r.checks.pq.status === "absent", "...and the other verdicts are still reported on their own");
r = await verifyTrustProfile(wrap(trust, sig, "insumer-attest-v2"), { jwksUrl: JWKS });
assert(!r.valid && /does not sign trust profiles/.test(r.checks.signature.reason), "an attestation v2 kid on a trust profile fails Check 1");
r = await verifyTrustProfile(wrap(trust, sig, V2_TRUST_KID), { jwksUrl: JWKS });
assert(r.checks.signature.passed, "control: the same profile under insumer-trust-v2 verifies");
} finally { restore2(); }
}
console.log(`\n ${passed} passed, ${failed} failed\n`);
if (failed > 0) process.exit(1);