@agent-score/commerce 2.4.0 → 2.6.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.
Files changed (80) hide show
  1. package/README.md +19 -17
  2. package/dist/challenge/index.d.mts +31 -3
  3. package/dist/challenge/index.d.ts +31 -3
  4. package/dist/challenge/index.js +25 -9
  5. package/dist/challenge/index.js.map +1 -1
  6. package/dist/challenge/index.mjs +25 -9
  7. package/dist/challenge/index.mjs.map +1 -1
  8. package/dist/{checkout-B-MIzYzW.d.ts → checkout-C4RD7M0Z.d.ts} +117 -13
  9. package/dist/{checkout-Bn7ZKIBD.d.mts → checkout-CzB9f_jf.d.mts} +117 -13
  10. package/dist/core.d.mts +40 -7
  11. package/dist/core.d.ts +40 -7
  12. package/dist/core.js +52 -27
  13. package/dist/core.js.map +1 -1
  14. package/dist/core.mjs +52 -27
  15. package/dist/core.mjs.map +1 -1
  16. package/dist/discovery/index.d.mts +33 -3
  17. package/dist/discovery/index.d.ts +33 -3
  18. package/dist/discovery/index.js +50 -16
  19. package/dist/discovery/index.js.map +1 -1
  20. package/dist/discovery/index.mjs +49 -16
  21. package/dist/discovery/index.mjs.map +1 -1
  22. package/dist/gate-D2RP6bZg.d.ts +307 -0
  23. package/dist/gate-GCXy4FHI.d.mts +307 -0
  24. package/dist/identity/express.d.mts +28 -1
  25. package/dist/identity/express.d.ts +28 -1
  26. package/dist/identity/express.js +714 -31
  27. package/dist/identity/express.js.map +1 -1
  28. package/dist/identity/express.mjs +710 -30
  29. package/dist/identity/express.mjs.map +1 -1
  30. package/dist/identity/fastify.d.mts +14 -2
  31. package/dist/identity/fastify.d.ts +14 -2
  32. package/dist/identity/fastify.js +727 -31
  33. package/dist/identity/fastify.js.map +1 -1
  34. package/dist/identity/fastify.mjs +723 -30
  35. package/dist/identity/fastify.mjs.map +1 -1
  36. package/dist/identity/hono.d.mts +28 -1
  37. package/dist/identity/hono.d.ts +28 -1
  38. package/dist/identity/hono.js +696 -33
  39. package/dist/identity/hono.js.map +1 -1
  40. package/dist/identity/hono.mjs +692 -32
  41. package/dist/identity/hono.mjs.map +1 -1
  42. package/dist/identity/nextjs.d.mts +5 -0
  43. package/dist/identity/nextjs.d.ts +5 -0
  44. package/dist/identity/nextjs.js +695 -30
  45. package/dist/identity/nextjs.js.map +1 -1
  46. package/dist/identity/nextjs.mjs +691 -29
  47. package/dist/identity/nextjs.mjs.map +1 -1
  48. package/dist/identity/policy.d.mts +21 -2
  49. package/dist/identity/policy.d.ts +21 -2
  50. package/dist/identity/policy.js +22 -1
  51. package/dist/identity/policy.js.map +1 -1
  52. package/dist/identity/policy.mjs +21 -1
  53. package/dist/identity/policy.mjs.map +1 -1
  54. package/dist/identity/web.d.mts +26 -1
  55. package/dist/identity/web.d.ts +26 -1
  56. package/dist/identity/web.js +695 -30
  57. package/dist/identity/web.js.map +1 -1
  58. package/dist/identity/web.mjs +691 -29
  59. package/dist/identity/web.mjs.map +1 -1
  60. package/dist/index.d.mts +165 -4
  61. package/dist/index.d.ts +165 -4
  62. package/dist/index.js +3103 -534
  63. package/dist/index.js.map +1 -1
  64. package/dist/index.mjs +3086 -545
  65. package/dist/index.mjs.map +1 -1
  66. package/dist/payment/index.d.mts +1 -1
  67. package/dist/payment/index.d.ts +1 -1
  68. package/dist/payment/index.js +10 -2
  69. package/dist/payment/index.js.map +1 -1
  70. package/dist/payment/index.mjs +10 -2
  71. package/dist/payment/index.mjs.map +1 -1
  72. package/dist/stripe-multichain/index.js +1614 -266
  73. package/dist/stripe-multichain/index.js.map +1 -1
  74. package/dist/stripe-multichain/index.mjs +1614 -266
  75. package/dist/stripe-multichain/index.mjs.map +1 -1
  76. package/dist/types-D1slMt0H.d.mts +137 -0
  77. package/dist/types-D1slMt0H.d.ts +137 -0
  78. package/dist/{wwwauthenticate-CVaGUMjU.d.mts → wwwauthenticate-Dgm-_af9.d.mts} +11 -1
  79. package/dist/{wwwauthenticate-CVaGUMjU.d.ts → wwwauthenticate-Dgm-_af9.d.ts} +11 -1
  80. package/package.json +26 -21
@@ -21,12 +21,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var express_exports = {};
22
22
  __export(express_exports, {
23
23
  agentscoreGate: () => agentscoreGate,
24
+ aipGate: () => aipGate,
24
25
  captureWallet: () => captureWallet,
25
26
  conditionalAgentscoreGate: () => conditionalAgentscoreGate,
27
+ conditionalAipGate: () => conditionalAipGate,
26
28
  getAgentScoreData: () => getAgentScoreData,
27
29
  getGateDegradedState: () => getGateDegradedState,
28
30
  getGateQuotaInfo: () => getGateQuotaInfo,
29
- getSignerVerdict: () => getSignerVerdict
31
+ getSignerVerdict: () => getSignerVerdict,
32
+ getVerifiedAit: () => getVerifiedAit
30
33
  });
31
34
  module.exports = __toCommonJS(express_exports);
32
35
 
@@ -76,7 +79,7 @@ var IDENTITY_VERIFICATION_REQUIRED_FALLBACK_INSTRUCTIONS = JSON.stringify({
76
79
  var API_ERROR_INSTRUCTIONS = JSON.stringify({
77
80
  action: "retry_with_backoff",
78
81
  steps: [
79
- "Verification is temporarily unavailable. Retry the request after 5\u201330 seconds with exponential backoff.",
82
+ "Verification is temporarily unavailable. Retry the request after 5-30 seconds with exponential backoff.",
80
83
  "This is NOT a compliance denial \u2014 the user does not need to re-verify their identity. Send the same identity headers (X-Wallet-Address or X-Operator-Token) on retry.",
81
84
  "If the request continues to fail after 3+ retries (~60 seconds total), surface the error to the user with the merchant's support contact."
82
85
  ],
@@ -163,7 +166,624 @@ function denialReasonToBody(reason) {
163
166
  return body;
164
167
  }
165
168
 
169
+ // src/aip/verify.ts
170
+ var import_jose2 = require("jose");
171
+
172
+ // src/aip/http-signature.ts
173
+ var import_jose = require("jose");
174
+ var { subtle } = globalThis.crypto;
175
+ var b64ToBytes = (b64) => {
176
+ const bin = atob(b64);
177
+ const out = new Uint8Array(bin.length);
178
+ for (let i = 0; i < bin.length; i++) {
179
+ out[i] = bin.charCodeAt(i);
180
+ }
181
+ return out;
182
+ };
183
+ var AIP_COVERED_COMPONENTS = ["@method", "@authority", "@path", "agent-identity"];
184
+ var AIP_SIGNATURE_TAG = "agent-identity";
185
+ var DEFAULT_MAX_SKEW_SECONDS = 60;
186
+ var MAX_POP_WINDOW_SECONDS = 120;
187
+ var normalizeAuthority = (authority) => {
188
+ const lower = authority.trim().toLowerCase();
189
+ const colon = lower.lastIndexOf(":");
190
+ if (colon === -1) {
191
+ return lower;
192
+ }
193
+ if (lower.includes("]") && colon < lower.indexOf("]")) {
194
+ return lower;
195
+ }
196
+ const host = lower.slice(0, colon);
197
+ const port = lower.slice(colon + 1);
198
+ if (port === "80" || port === "443") {
199
+ return host;
200
+ }
201
+ return lower;
202
+ };
203
+ var componentValue = (name, input) => {
204
+ switch (name) {
205
+ case "@method":
206
+ return input.method.toUpperCase();
207
+ case "@authority":
208
+ return normalizeAuthority(input.authority);
209
+ case "@path":
210
+ return input.path;
211
+ case "agent-identity":
212
+ return input.agentIdentity.trim();
213
+ default:
214
+ return input.extra?.[name] ?? null;
215
+ }
216
+ };
217
+ var serializeComponentList = (components) => `(${components.map((c) => `"${c}"`).join(" ")})`;
218
+ var serializeParams = (p) => {
219
+ const parts = [];
220
+ if (p.created !== void 0) {
221
+ parts.push(`created=${p.created}`);
222
+ }
223
+ if (p.expires !== void 0) {
224
+ parts.push(`expires=${p.expires}`);
225
+ }
226
+ if (p.keyid !== void 0) {
227
+ parts.push(`keyid="${p.keyid}"`);
228
+ }
229
+ if (p.alg !== void 0) {
230
+ parts.push(`alg="${p.alg}"`);
231
+ }
232
+ if (p.tag !== void 0) {
233
+ parts.push(`tag="${p.tag}"`);
234
+ }
235
+ return parts.map((s) => `;${s}`).join("");
236
+ };
237
+ var buildSignatureBase = (params, input, rawSignatureParams) => {
238
+ const lines = [];
239
+ for (const name of params.components) {
240
+ const value = componentValue(name, input);
241
+ if (value === null) {
242
+ throw new MissingComponentError(name);
243
+ }
244
+ lines.push(`"${name}": ${value}`);
245
+ }
246
+ const paramsValue = rawSignatureParams ?? serializeComponentList(params.components) + serializeParams(params);
247
+ lines.push(`"@signature-params": ${paramsValue}`);
248
+ return lines.join("\n");
249
+ };
250
+ var MissingComponentError = class extends Error {
251
+ constructor(component) {
252
+ super(`signature base missing covered component: ${component}`);
253
+ this.component = component;
254
+ this.name = "MissingComponentError";
255
+ }
256
+ component;
257
+ };
258
+ var parseSignatureInput = (header, tag = AIP_SIGNATURE_TAG) => {
259
+ const members = splitDictionary(header);
260
+ if (members.length === 0) {
261
+ return null;
262
+ }
263
+ const parsed = members.map((m) => {
264
+ const params = parseInnerListMember(m.value);
265
+ return params ? { label: m.label, params, rawParams: m.value } : null;
266
+ }).filter((x) => x !== null);
267
+ if (parsed.length === 0) {
268
+ return null;
269
+ }
270
+ return parsed.find((p) => p.params.tag === tag) ?? null;
271
+ };
272
+ var parseSignatureValue = (header, label) => {
273
+ const members = splitDictionary(header);
274
+ const member = members.find((m) => m.label === label);
275
+ if (!member) {
276
+ return null;
277
+ }
278
+ const v = member.value.trim();
279
+ if (!v.startsWith(":") || !v.endsWith(":") || v.length < 2) {
280
+ return null;
281
+ }
282
+ const b64 = v.slice(1, -1);
283
+ try {
284
+ return b64ToBytes(b64);
285
+ } catch {
286
+ return null;
287
+ }
288
+ };
289
+ var splitDictionary = (header) => {
290
+ const out = [];
291
+ let depth = 0;
292
+ let inBytes = false;
293
+ let inString = false;
294
+ let current = "";
295
+ for (let i = 0; i < header.length; i++) {
296
+ const ch = header[i];
297
+ if (inString) {
298
+ current += ch;
299
+ if (ch === '"' && header[i - 1] !== "\\") {
300
+ inString = false;
301
+ }
302
+ continue;
303
+ }
304
+ if (ch === '"') {
305
+ inString = true;
306
+ current += ch;
307
+ continue;
308
+ }
309
+ if (ch === ":") {
310
+ inBytes = !inBytes;
311
+ current += ch;
312
+ continue;
313
+ }
314
+ if (!inBytes && ch === "(") {
315
+ depth++;
316
+ current += ch;
317
+ continue;
318
+ }
319
+ if (!inBytes && ch === ")") {
320
+ depth = Math.max(0, depth - 1);
321
+ current += ch;
322
+ continue;
323
+ }
324
+ if (!inBytes && depth === 0 && ch === ",") {
325
+ pushMember(out, current);
326
+ current = "";
327
+ continue;
328
+ }
329
+ current += ch;
330
+ }
331
+ pushMember(out, current);
332
+ return out;
333
+ };
334
+ var pushMember = (out, raw) => {
335
+ const trimmed = raw.trim();
336
+ if (!trimmed) {
337
+ return;
338
+ }
339
+ const eq = trimmed.indexOf("=");
340
+ if (eq === -1) {
341
+ return;
342
+ }
343
+ const label = trimmed.slice(0, eq).trim();
344
+ const value = trimmed.slice(eq + 1).trim();
345
+ if (label) {
346
+ out.push({ label, value });
347
+ }
348
+ };
349
+ var parseInnerListMember = (value) => {
350
+ const open = value.indexOf("(");
351
+ const close = value.indexOf(")", open + 1);
352
+ if (open === -1 || close === -1) {
353
+ return null;
354
+ }
355
+ const listBody = value.slice(open + 1, close).trim();
356
+ const components = listBody.length === 0 ? [] : (listBody.match(/"[^"]*"/g) ?? []).map((s) => s.slice(1, -1));
357
+ const params = { components };
358
+ const paramStr = value.slice(close + 1);
359
+ const re = /;\s*([a-zA-Z][a-zA-Z0-9_-]*)\s*=\s*("(?:[^"\\]|\\.)*"|-?\d+)/g;
360
+ let match;
361
+ while ((match = re.exec(paramStr)) !== null) {
362
+ const key = match[1];
363
+ const raw = match[2];
364
+ const val = raw.startsWith('"') ? raw.slice(1, -1) : Number(raw);
365
+ if (key === "created") {
366
+ params.created = val;
367
+ } else if (key === "expires") {
368
+ params.expires = val;
369
+ } else if (key === "keyid") {
370
+ params.keyid = val;
371
+ } else if (key === "tag") {
372
+ params.tag = val;
373
+ } else if (key === "alg") {
374
+ params.alg = val;
375
+ }
376
+ }
377
+ return params;
378
+ };
379
+ var verifyMessageSignature = async (input) => {
380
+ const selected = parseSignatureInput(input.signatureInput);
381
+ if (!selected) {
382
+ return { ok: false, reason: "no_aip_signature" };
383
+ }
384
+ const { label, params, rawParams } = selected;
385
+ if (params.alg !== void 0 && !["ed25519", "eddsa"].includes(params.alg.toLowerCase())) {
386
+ return { ok: false, reason: "unsupported_alg" };
387
+ }
388
+ for (const required of AIP_COVERED_COMPONENTS) {
389
+ if (!params.components.includes(required)) {
390
+ return { ok: false, reason: "missing_covered_component" };
391
+ }
392
+ }
393
+ if (params.created === void 0) {
394
+ return { ok: false, reason: "created_missing" };
395
+ }
396
+ if (params.expires === void 0) {
397
+ return { ok: false, reason: "expires_missing" };
398
+ }
399
+ if (params.expires < params.created || params.expires - params.created > MAX_POP_WINDOW_SECONDS) {
400
+ return { ok: false, reason: "pop_window_too_long" };
401
+ }
402
+ const now = input.now ?? Math.floor(Date.now() / 1e3);
403
+ const skew = input.maxSkewSeconds ?? DEFAULT_MAX_SKEW_SECONDS;
404
+ if (params.created > now + skew) {
405
+ return { ok: false, reason: "created_in_future" };
406
+ }
407
+ if (params.expires < now - skew) {
408
+ return { ok: false, reason: "expired" };
409
+ }
410
+ if (!params.keyid) {
411
+ return { ok: false, reason: "missing_keyid" };
412
+ }
413
+ const cnf = input.cnfJwk;
414
+ if (cnf.kty !== "OKP" || cnf.crv !== "Ed25519" || typeof cnf.x !== "string" || cnf.x.length === 0) {
415
+ return { ok: false, reason: "unsupported_cnf_key" };
416
+ }
417
+ let thumbprint;
418
+ try {
419
+ thumbprint = await (0, import_jose.calculateJwkThumbprint)(input.cnfJwk, "sha256");
420
+ } catch {
421
+ return { ok: false, reason: "unsupported_cnf_key" };
422
+ }
423
+ if (params.keyid !== thumbprint) {
424
+ return { ok: false, reason: "keyid_mismatch" };
425
+ }
426
+ const sig = parseSignatureValue(input.signature, label);
427
+ if (!sig) {
428
+ return { ok: false, reason: "malformed_signature" };
429
+ }
430
+ let base;
431
+ try {
432
+ base = buildSignatureBase(params, {
433
+ method: input.method,
434
+ authority: input.authority,
435
+ path: input.path,
436
+ agentIdentity: input.agentIdentity,
437
+ extra: input.extraComponents
438
+ }, rawParams);
439
+ } catch (err) {
440
+ if (err instanceof MissingComponentError) {
441
+ return { ok: false, reason: "missing_covered_component" };
442
+ }
443
+ throw err;
444
+ }
445
+ let valid;
446
+ try {
447
+ const key = await (0, import_jose.importJWK)(input.cnfJwk, "EdDSA");
448
+ if (!(key instanceof CryptoKey)) {
449
+ return { ok: false, reason: "signature_invalid" };
450
+ }
451
+ valid = await subtle.verify(
452
+ { name: "Ed25519" },
453
+ key,
454
+ sig,
455
+ new TextEncoder().encode(base)
456
+ );
457
+ } catch {
458
+ return { ok: false, reason: "signature_invalid" };
459
+ }
460
+ return valid ? { ok: true, params } : { ok: false, reason: "signature_invalid" };
461
+ };
462
+
463
+ // src/aip/types.ts
464
+ var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
465
+ var isNonEmptyString = (v) => typeof v === "string" && v.length > 0;
466
+ var isAitShape = (payload) => isObject(payload) && isObject(payload.cnf) && isObject(payload.agent);
467
+ var validateAitPayload = (payload) => {
468
+ if (!isObject(payload)) {
469
+ return { ok: false, reason: "not_an_object" };
470
+ }
471
+ if (!isNonEmptyString(payload.aip_version)) {
472
+ return { ok: false, reason: "missing_aip_version" };
473
+ }
474
+ if (!isNonEmptyString(payload.iss)) {
475
+ return { ok: false, reason: "missing_iss" };
476
+ }
477
+ if (!isNonEmptyString(payload.sub)) {
478
+ return { ok: false, reason: "missing_sub" };
479
+ }
480
+ if (typeof payload.iat !== "number") {
481
+ return { ok: false, reason: "missing_iat" };
482
+ }
483
+ if (typeof payload.exp !== "number") {
484
+ return { ok: false, reason: "missing_exp" };
485
+ }
486
+ if (!isObject(payload.cnf) || !isObject(payload.cnf.jwk)) {
487
+ return { ok: false, reason: "missing_cnf" };
488
+ }
489
+ if (!isObject(payload.agent) || !isNonEmptyString(payload.agent.provider)) {
490
+ return { ok: false, reason: "missing_agent_provider" };
491
+ }
492
+ if (payload.trust_level === "human_confirmed") {
493
+ const auth = payload.auth;
494
+ const amr = isObject(auth) ? auth.amr : void 0;
495
+ if (!Array.isArray(amr) || amr.length === 0) {
496
+ return { ok: false, reason: "human_confirmed_without_amr" };
497
+ }
498
+ }
499
+ return { ok: true, payload };
500
+ };
501
+
502
+ // src/aip/verify.ts
503
+ var verifyAit = async (ctx, opts) => {
504
+ if (ctx.agentIdentityHeaders.length === 0) {
505
+ return { ok: false, reason: "no_token" };
506
+ }
507
+ if (!ctx.signatureInput || !ctx.signature) {
508
+ return { ok: false, reason: "pop_signature_missing" };
509
+ }
510
+ const signatureInput = ctx.signatureInput;
511
+ const signature = ctx.signature;
512
+ let lastFailure = "malformed_token";
513
+ for (const raw of ctx.agentIdentityHeaders) {
514
+ const token = stripBearer(raw);
515
+ let header;
516
+ let payload;
517
+ try {
518
+ header = (0, import_jose2.decodeProtectedHeader)(token);
519
+ payload = (0, import_jose2.decodeJwt)(token);
520
+ } catch {
521
+ lastFailure = "malformed_token";
522
+ continue;
523
+ }
524
+ if (header.alg === void 0 || header.alg.toLowerCase() === "none") {
525
+ lastFailure = "malformed_token";
526
+ continue;
527
+ }
528
+ if (!isAitShape(payload)) {
529
+ lastFailure = "malformed_token";
530
+ continue;
531
+ }
532
+ const validated = validateAitPayload(payload);
533
+ if (!validated.ok) {
534
+ lastFailure = "invalid_claims";
535
+ continue;
536
+ }
537
+ const claims = validated.payload;
538
+ const keyLookup = await opts.jwks.getKey(claims.iss, header.kid);
539
+ if (!keyLookup.ok) {
540
+ lastFailure = keyLookup.reason === "untrusted_issuer" || keyLookup.reason === "insecure_issuer" ? "untrusted_issuer" : "key_unavailable";
541
+ continue;
542
+ }
543
+ const jwtClockTolerance = opts.maxSkewSeconds ?? 60;
544
+ try {
545
+ const idpKey = await (0, import_jose2.importJWK)(keyLookup.key, normalizeAlg(header.alg));
546
+ await (0, import_jose2.jwtVerify)(token, idpKey, {
547
+ // Pin the signature algorithm allowlist (RFC 8725 §3.1) — also rejects `alg:none`. Without
548
+ // this, jose accepts whatever alg the resolved JWK supports, so a trusted IdP publishing a
549
+ // non-Ed25519 (e.g. RSA/EC) `use:sig` key would let an attacker present an RS256/ES256
550
+ // token that verifies. Matches the server-side allowlist in the AgentScore API verifier.
551
+ algorithms: AIT_SIGNING_ALGS,
552
+ clockTolerance: jwtClockTolerance,
553
+ currentDate: opts.now !== void 0 ? new Date(opts.now * 1e3) : void 0
554
+ });
555
+ } catch (err) {
556
+ lastFailure = isExpiry(err) ? "expired_token" : "idp_signature_invalid";
557
+ continue;
558
+ }
559
+ const nowSec = opts.now ?? Math.floor(Date.now() / 1e3);
560
+ if (claims.iat > nowSec + jwtClockTolerance) {
561
+ lastFailure = "expired_token";
562
+ continue;
563
+ }
564
+ if (claims.exp - claims.iat > (opts.maxLifetimeSeconds ?? 300)) {
565
+ lastFailure = "expired_token";
566
+ continue;
567
+ }
568
+ const popResult = await verifyMessageSignature({
569
+ method: ctx.method,
570
+ authority: ctx.authority,
571
+ path: ctx.path,
572
+ // The agent-identity covered component is the BARE AIT (a Bearer prefix, if present, is
573
+ // transport that `stripBearer` removed above). Verify over `token`, not `raw`, so the edge and
574
+ // the API — which verifies over the forwarded bare aip_token — reconstruct the identical base.
575
+ agentIdentity: token,
576
+ signatureInput,
577
+ signature,
578
+ cnfJwk: claims.cnf.jwk,
579
+ now: opts.now,
580
+ maxSkewSeconds: opts.maxSkewSeconds
581
+ });
582
+ if (!popResult.ok) {
583
+ lastFailure = "pop_signature_invalid";
584
+ continue;
585
+ }
586
+ return {
587
+ ok: true,
588
+ ait: {
589
+ payload: claims,
590
+ iss: claims.iss,
591
+ cnfJwk: claims.cnf.jwk,
592
+ token,
593
+ signatureMaterial: {
594
+ method: ctx.method,
595
+ authority: ctx.authority,
596
+ path: ctx.path,
597
+ signature_input: signatureInput,
598
+ signature
599
+ }
600
+ }
601
+ };
602
+ }
603
+ return { ok: false, reason: lastFailure };
604
+ };
605
+ var stripBearer = (value) => {
606
+ const trimmed = value.trim();
607
+ return /^bearer\s+/i.test(trimmed) ? trimmed.replace(/^bearer\s+/i, "") : trimmed;
608
+ };
609
+ var AIT_SIGNING_ALGS = ["EdDSA", "ES256"];
610
+ var normalizeAlg = (alg) => alg.toLowerCase() === "eddsa" ? "EdDSA" : alg;
611
+ var isExpiry = (err) => typeof err === "object" && err !== null && err.code === "ERR_JWT_EXPIRED";
612
+
613
+ // src/aip/request.ts
614
+ var readNodeHeader = (headers, name) => {
615
+ const v = headers[name] ?? headers[name.toLowerCase()];
616
+ if (v === void 0) {
617
+ return void 0;
618
+ }
619
+ return Array.isArray(v) ? v.join(", ") : v;
620
+ };
621
+ var hasAgentIdentityHeaderNode = (headers) => {
622
+ const raw = readNodeHeader(headers, "agent-identity");
623
+ return raw !== void 0 && raw.split(",").some((s) => s.trim().length > 0);
624
+ };
625
+ var buildVerifyContextFromParts = (parts) => {
626
+ const agentIdentityRaw = readNodeHeader(parts.headers, "agent-identity");
627
+ const agentIdentityHeaders = agentIdentityRaw ? agentIdentityRaw.split(",").map((s) => s.trim()).filter((s) => s.length > 0) : [];
628
+ const host = parts.authority ?? readNodeHeader(parts.headers, "host") ?? "";
629
+ let path;
630
+ try {
631
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(parts.url)) {
632
+ path = new URL(parts.url).pathname;
633
+ } else {
634
+ const target = parts.url.startsWith("/") ? parts.url : `/${parts.url}`;
635
+ path = new URL(`http://${host || "localhost"}${target}`).pathname;
636
+ }
637
+ } catch {
638
+ const q = parts.url.indexOf("?");
639
+ path = q === -1 ? parts.url : parts.url.slice(0, q);
640
+ }
641
+ return {
642
+ method: parts.method,
643
+ authority: host,
644
+ path,
645
+ agentIdentityHeaders,
646
+ signatureInput: readNodeHeader(parts.headers, "signature-input") ?? null,
647
+ signature: readNodeHeader(parts.headers, "signature") ?? null
648
+ };
649
+ };
650
+
651
+ // src/aip/gate.ts
652
+ var partsWithAuthority = (parts, opts) => {
653
+ const authority = parts.authority ?? opts.authority;
654
+ return authority !== void 0 ? { ...parts, authority } : parts;
655
+ };
656
+ var aipErrorCode = (failure) => {
657
+ switch (failure) {
658
+ case "no_token":
659
+ case "pop_signature_missing":
660
+ return "agent_identity_required";
661
+ case "untrusted_issuer":
662
+ return "untrusted_issuer";
663
+ case "expired_token":
664
+ return "expired_token";
665
+ case "invalid_claims":
666
+ return "insufficient_claims";
667
+ case "key_unavailable":
668
+ return "idp_unavailable";
669
+ case "malformed_token":
670
+ case "idp_signature_invalid":
671
+ case "pop_signature_invalid":
672
+ return "invalid_signature";
673
+ default:
674
+ return "invalid_signature";
675
+ }
676
+ };
677
+ var aipErrorStatus = (failure) => {
678
+ switch (failure) {
679
+ case "key_unavailable":
680
+ return 503;
681
+ case "untrusted_issuer":
682
+ case "invalid_claims":
683
+ return 403;
684
+ default:
685
+ return 401;
686
+ }
687
+ };
688
+ var aipErrorDetail = (failure) => {
689
+ switch (failure) {
690
+ case "no_token":
691
+ return "No Agent-Identity token was presented.";
692
+ case "pop_signature_missing":
693
+ return "The request is missing the RFC 9421 HTTP Message Signature that proves possession of the token-bound key.";
694
+ case "untrusted_issuer":
695
+ return "The token's issuer is not in this service's trusted-issuer list.";
696
+ case "expired_token":
697
+ return "The Agent Identity Token has expired.";
698
+ case "invalid_claims":
699
+ return "The token is missing required claims for this endpoint.";
700
+ case "malformed_token":
701
+ return "The Agent-Identity header could not be parsed as an Agent Identity Token.";
702
+ case "idp_signature_invalid":
703
+ return "The identity provider's signature on the token failed verification.";
704
+ case "pop_signature_invalid":
705
+ return "The request signature did not match the key bound to the token.";
706
+ case "key_unavailable":
707
+ return "The identity provider's signing key could not be resolved.";
708
+ default:
709
+ return "Token verification failed.";
710
+ }
711
+ };
712
+ var buildAipErrorBody = (failure, requirements) => {
713
+ const code = aipErrorCode(failure);
714
+ const body = {
715
+ type: `urn:aip:error:${code}`,
716
+ title: code.replace(/_/g, " "),
717
+ status: aipErrorStatus(failure),
718
+ detail: aipErrorDetail(failure)
719
+ };
720
+ if (requirements) {
721
+ if (code === "untrusted_issuer" && requirements.trustedIssuers?.length) {
722
+ body.trusted_issuers = requirements.trustedIssuers;
723
+ }
724
+ if (code === "insufficient_claims") {
725
+ if (requirements.requiredClaims?.length) body.required_claims = requirements.requiredClaims;
726
+ if (requirements.requiredTrustLevel !== void 0) body.required_trust_level = requirements.requiredTrustLevel;
727
+ if (requirements.requiredAmr?.length) body.required_amr = requirements.requiredAmr;
728
+ }
729
+ }
730
+ return body;
731
+ };
732
+ var TRUST_RANK = { autonomous: 0, human_present: 1, human_confirmed: 2 };
733
+ var checkTrustRequirements = (payload, requiredTrustLevel, requiredAmr) => {
734
+ if (requiredTrustLevel !== void 0) {
735
+ const have = TRUST_RANK[payload.trust_level ?? "autonomous"] ?? 0;
736
+ const need = TRUST_RANK[requiredTrustLevel] ?? 0;
737
+ if (have < need) {
738
+ return `This endpoint requires trust_level '${requiredTrustLevel}'; the token asserts '${payload.trust_level ?? "autonomous"}'. Re-mint an AIT at the required trust level (human confirmation).`;
739
+ }
740
+ }
741
+ if (requiredAmr !== void 0 && requiredAmr.length > 0) {
742
+ const amr = Array.isArray(payload.auth?.amr) ? payload.auth.amr : [];
743
+ if (!amr.some((m) => requiredAmr.includes(m))) {
744
+ return `This endpoint requires an authentication method in [${requiredAmr.join(", ")}]; the token carries [${amr.join(", ") || "none"}].`;
745
+ }
746
+ }
747
+ return null;
748
+ };
749
+ var buildAipWeakAuthBody = (opts) => ({
750
+ type: "urn:aip:error:weak_auth",
751
+ title: "weak auth",
752
+ status: 403,
753
+ detail: opts.detail,
754
+ ...opts.requiredTrustLevel !== void 0 && { required_trust_level: opts.requiredTrustLevel },
755
+ ...opts.requiredAmr !== void 0 && opts.requiredAmr.length > 0 && { required_amr: opts.requiredAmr },
756
+ ...opts.trustedIssuers !== void 0 && opts.trustedIssuers.length > 0 && { trusted_issuers: opts.trustedIssuers }
757
+ });
758
+ var requirementsFromOptions = (opts) => ({
759
+ ...opts.trustedIssuers !== void 0 && { trustedIssuers: opts.trustedIssuers },
760
+ ...opts.requiredClaims !== void 0 && { requiredClaims: opts.requiredClaims },
761
+ ...opts.requireTrustLevel !== void 0 && { requiredTrustLevel: opts.requireTrustLevel },
762
+ ...opts.requireAmr !== void 0 && { requiredAmr: opts.requireAmr }
763
+ });
764
+ var evaluateFromContext = async (ctx, opts) => {
765
+ const result = await verifyAit(ctx, { jwks: opts.jwks, now: opts.now, maxSkewSeconds: opts.maxSkewSeconds });
766
+ if (!result.ok) {
767
+ return { ok: false, body: buildAipErrorBody(result.reason, requirementsFromOptions(opts)) };
768
+ }
769
+ const weak = checkTrustRequirements(result.ait.payload, opts.requireTrustLevel, opts.requireAmr);
770
+ if (weak !== null) {
771
+ return {
772
+ ok: false,
773
+ body: buildAipWeakAuthBody({
774
+ detail: weak,
775
+ ...opts.requireTrustLevel !== void 0 && { requiredTrustLevel: opts.requireTrustLevel },
776
+ ...opts.requireAmr !== void 0 && { requiredAmr: opts.requireAmr },
777
+ ...opts.trustedIssuers !== void 0 && { trustedIssuers: opts.trustedIssuers }
778
+ })
779
+ };
780
+ }
781
+ return { ok: true, ait: result.ait };
782
+ };
783
+ var evaluateAipParts = (parts, opts) => evaluateFromContext(buildVerifyContextFromParts(partsWithAuthority(parts, opts)), opts);
784
+
166
785
  // src/core.ts
786
+ var import_node_crypto = require("crypto");
167
787
  var import_sdk = require("@agent-score/sdk");
168
788
 
169
789
  // src/address.ts
@@ -232,7 +852,7 @@ function stripTrailingSlashes(s) {
232
852
  while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
233
853
  return end === s.length ? s : s.slice(0, end);
234
854
  }
235
- var CANONICAL_AGENTSCORE_API = "https://api.agentscore.sh";
855
+ var CANONICAL_AGENTSCORE_API = "https://api.agentscore.com";
236
856
  var WALLET_SIGNER_MISMATCH_INSTRUCTIONS = JSON.stringify({
237
857
  action: "resign_or_switch_to_operator_token",
238
858
  steps: [
@@ -258,17 +878,22 @@ var INVALID_CREDENTIAL_INSTRUCTIONS = JSON.stringify({
258
878
  ],
259
879
  user_message: "The operator_token is not recognized. Use a different stored token, or restart the verification session flow to mint a new one."
260
880
  });
261
- function buildAgentMemoryHint() {
881
+ function buildAgentMemoryHint(aipTrustedIssuers) {
262
882
  const api = CANONICAL_AGENTSCORE_API;
883
+ const acceptsAip = aipTrustedIssuers !== void 0 && aipTrustedIssuers.length > 0;
263
884
  return {
264
885
  save_for_future_agentscore_gates: true,
265
886
  pattern_summary: "AgentScore is a cross-merchant identity substrate for agent commerce. Any endpoint that returns 403 missing_identity / identity_verification_required or 402 challenges referencing AgentScore uses the same identity system. One KYC works across all AgentScore merchants \u2014 no re-verification per site. Save this pattern (and the endpoints below) to persistent memory so future AgentScore encounters skip the cold-start session flow.",
266
- quickstart: "https://docs.agentscore.sh/guides/agent-identity",
887
+ quickstart: "https://docs.agentscore.com/guides/agent-identity",
267
888
  identity_check_endpoint: `${api}/v1/credentials`,
268
889
  identity_paths: {
269
890
  wallet: "If paying from a crypto wallet you have used before on any AgentScore merchant, send `X-Wallet-Address: 0x...`. Shortest path; no token lifecycle to manage.",
270
- operator_token: "For any rail (Stripe SPT, card, or a wallet you have not linked yet), send `X-Operator-Token: opc_...`. Reusable across merchants until the token expires."
891
+ operator_token: "For any rail (Stripe SPT, card, or a wallet you have not linked yet), send `X-Operator-Token: opc_...`. Reusable across merchants until the token expires.",
892
+ ...acceptsAip && {
893
+ agent_identity: 'If you hold an AIP Agent Identity Token from a trusted issuer (see aip_trusted_issuers), present it: send the JWT in an `Agent-Identity` header plus an RFC 9421 HTTP Message Signature (Signature-Input + Signature over @method @authority @path agent-identity, tag="agent-identity") signed with the token-bound cnf key. The merchant verifies it and applies its policy \u2014 no separate AgentScore credential needed.'
894
+ }
271
895
  },
896
+ ...acceptsAip && { aip_trusted_issuers: aipTrustedIssuers },
272
897
  bootstrap: "If you have neither a linked wallet nor a valid operator_token, follow the session/verify flow in the per-request `agent_instructions` block. This happens at most once per agent identity \u2014 after first verification, the operator_token and any subsequently used wallet are reusable everywhere.",
273
898
  do_not_persist_in_memory: ["operator_token", "poll_secret"],
274
899
  persist_in_credential_store: ["operator_token"]
@@ -276,7 +901,7 @@ function buildAgentMemoryHint() {
276
901
  }
277
902
  function createAgentScoreCore(options) {
278
903
  if (!options.apiKey) {
279
- throw new Error("AgentScore API key is required. Get one at https://agentscore.sh/sign-up");
904
+ throw new Error("AgentScore API key is required. Get one at https://www.agentscore.com/sign-up");
280
905
  }
281
906
  const {
282
907
  apiKey,
@@ -287,14 +912,15 @@ function createAgentScoreCore(options) {
287
912
  allowedJurisdictions,
288
913
  failOpen = false,
289
914
  cacheSeconds = 300,
290
- baseUrl: rawBaseUrl = "https://api.agentscore.sh",
915
+ baseUrl: rawBaseUrl = "https://api.agentscore.com",
291
916
  chain: gateChain,
292
917
  userAgent,
293
- createSessionOnMissing
918
+ createSessionOnMissing,
919
+ aipTrustedIssuers
294
920
  } = options;
295
921
  const baseUrl = stripTrailingSlashes(rawBaseUrl);
296
- const agentMemoryHint = buildAgentMemoryHint();
297
- const defaultUa = `@agent-score/commerce@${"2.4.0"}`;
922
+ const agentMemoryHint = buildAgentMemoryHint(aipTrustedIssuers);
923
+ const defaultUa = `@agent-score/commerce@${"2.6.0"}`;
298
924
  const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
299
925
  const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
300
926
  const sessionSdkCache = /* @__PURE__ */ new Map();
@@ -369,16 +995,21 @@ function createAgentScoreCore(options) {
369
995
  }
370
996
  }
371
997
  async function evaluate(identity, ctx, signer) {
372
- if (!identity || !identity.address && !identity.operatorToken) {
998
+ if (!identity || !identity.address?.trim() && !identity.operatorToken?.trim() && !identity.aipToken?.trim()) {
373
999
  if (failOpen) return { kind: "allow" };
374
1000
  const sessionReason = await tryMintSessionDenial(ctx);
375
1001
  if (sessionReason) return { kind: "deny", reason: sessionReason };
1002
+ const acceptsAip = aipTrustedIssuers !== void 0 && aipTrustedIssuers.length > 0;
1003
+ const aipStep = acceptsAip ? [
1004
+ `If you hold an AIP Agent Identity Token from a trusted issuer (${aipTrustedIssuers.join(", ")}): present it \u2014 send the JWT in an Agent-Identity header plus an RFC 9421 HTTP Message Signature (Signature-Input + Signature over @method @authority @path agent-identity, tag="agent-identity") signed with the token-bound cnf key. This satisfies identity in one round trip without an AgentScore credential.`
1005
+ ] : [];
376
1006
  const missingIdentityInstructions = JSON.stringify({
377
1007
  action: "probe_identity_then_session",
378
1008
  steps: [
1009
+ ...aipStep,
379
1010
  "If you have a wallet AND this merchant accepts a wallet-signing rail (Tempo MPP or x402 \u2014 see openapi.json x-payment-info): send X-Wallet-Address and retry. If the wallet is already linked to an AgentScore operator (via prior SIWE claim or prior captureWallet), this passes in one round trip. If the wallet is unlinked or the account has no KYC, the 403 will include a verify_url \u2014 share it with the user to claim the wallet + complete KYC, then retry.",
380
1011
  "If step 1 is denied or you already have a stored operator_token (valid + not expired): send X-Operator-Token: opc_... and retry.",
381
- "If neither applies: retry with NO identity header. Merchants that auto-create verification sessions (most AgentScore merchants do) return verify_url + session_id + poll_secret in the 403 body \u2014 share verify_url with the user, then poll poll_url every 5s with the X-Poll-Secret header until status=verified (the poll returns a one-time operator_token). If the retry returns the same bare 403, this merchant does not support self-service session bootstrapping \u2014 direct the user to https://agentscore.sh/sign-up to create an AgentScore identity and mint an operator_token from their dashboard (https://agentscore.sh/dashboard/verify). The user hands the opc_... to you, and you retry with X-Operator-Token."
1012
+ "If neither applies: retry with NO identity header. Merchants that auto-create verification sessions (most AgentScore merchants do) return verify_url + session_id + poll_secret in the 403 body \u2014 share verify_url with the user, then poll poll_url every 5s with the X-Poll-Secret header until status=verified (the poll returns a one-time operator_token). If the retry returns the same bare 403, this merchant does not support self-service session bootstrapping \u2014 direct the user to https://www.agentscore.com/sign-up to create an AgentScore identity and mint an operator_token from their dashboard (https://www.agentscore.com/dashboard/verify). The user hands the opc_... to you, and you retry with X-Operator-Token."
382
1013
  ],
383
1014
  user_message: "Try X-Wallet-Address first if you have a wallet and the merchant accepts Tempo/x402; fall back to a stored X-Operator-Token, then to the session/verify flow described in agent_memory.bootstrap."
384
1015
  });
@@ -391,21 +1022,26 @@ function createAgentScoreCore(options) {
391
1022
  }
392
1023
  };
393
1024
  }
394
- const cacheKey = identity.operatorToken?.toLowerCase() ?? (identity.address ? normalizeAddress(identity.address) : "");
1025
+ const identityKey = identity.aipToken ? `aip:${(0, import_node_crypto.createHash)("sha256").update(identity.aipToken).digest("hex")}` : identity.operatorToken?.toLowerCase() ?? (identity.address ? normalizeAddress(identity.address) : "");
1026
+ const cacheKey = signer ? JSON.stringify([identityKey, signer.network, normalizeAddress(signer.address)]) : JSON.stringify([identityKey]);
395
1027
  const cached = cache.get(cacheKey);
396
1028
  if (cached) {
1029
+ const cachedVerdict = cached.raw ? buildSignerVerdict(identity, cached.raw) : void 0;
397
1030
  if (cached.allow) {
398
1031
  const cachedRaw = cached.raw;
399
1032
  const cachedQuota = cachedRaw?.quota;
400
1033
  return {
401
1034
  kind: "allow",
402
1035
  data: cachedRaw,
403
- ...cachedQuota !== void 0 && { quota: cachedQuota }
1036
+ ...cachedQuota !== void 0 && { quota: cachedQuota },
1037
+ ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict }
404
1038
  };
405
1039
  }
406
1040
  if (isFixableDenial(cached.reasons)) {
407
1041
  const sessionReason = await tryMintSessionDenial(ctx);
408
- if (sessionReason) return { kind: "deny", reason: sessionReason };
1042
+ if (sessionReason) {
1043
+ return { kind: "deny", reason: sessionReason, ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict } };
1044
+ }
409
1045
  }
410
1046
  return {
411
1047
  kind: "deny",
@@ -415,7 +1051,8 @@ function createAgentScoreCore(options) {
415
1051
  reasons: cached.reasons,
416
1052
  verify_url: cached.raw?.verify_url,
417
1053
  data: cached.raw
418
- }
1054
+ },
1055
+ ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict }
419
1056
  };
420
1057
  }
421
1058
  const policy = {};
@@ -436,7 +1073,10 @@ function createAgentScoreCore(options) {
436
1073
  // regardless of policy.require_sanctions_clear (which gates the separate NAME screen).
437
1074
  ...signer && { signer: { address: signer.address, network: signer.network } }
438
1075
  };
439
- const result = identity.address ? await sdk.assess(identity.address, { ...opts, operatorToken: identity.operatorToken }) : await sdk.assess(null, { ...opts, operatorToken: identity.operatorToken });
1076
+ if (identity.aipToken !== void 0 && identity.aipSignature === void 0) {
1077
+ throw new Error("AgentScoreCore.evaluate: aipToken requires aipSignature (RFC 9421 proof-of-possession material).");
1078
+ }
1079
+ const result = identity.aipToken !== void 0 && identity.aipSignature !== void 0 ? await sdk.assess(null, { ...opts, aipToken: identity.aipToken, aipSignature: identity.aipSignature }) : identity.address ? await sdk.assess(identity.address, { ...opts, operatorToken: identity.operatorToken }) : await sdk.assess(null, { ...opts, operatorToken: identity.operatorToken });
440
1080
  data = result;
441
1081
  } catch (err) {
442
1082
  if (err instanceof import_sdk.PaymentRequiredError) {
@@ -507,17 +1147,21 @@ function createAgentScoreCore(options) {
507
1147
  const decisionReasons = data.decision_reasons ?? [];
508
1148
  const allow = decision === "allow" || decision == null;
509
1149
  cache.set(cacheKey, { allow, decision: decision ?? void 0, reasons: decisionReasons, raw: data });
1150
+ const signerVerdict = buildSignerVerdict(identity, data);
510
1151
  if (allow) {
511
1152
  const quota = data.quota;
512
1153
  return {
513
1154
  kind: "allow",
514
1155
  data,
515
- ...quota !== void 0 && { quota }
1156
+ ...quota !== void 0 && { quota },
1157
+ ...signerVerdict !== void 0 && { signerVerdict }
516
1158
  };
517
1159
  }
518
1160
  if (isFixableDenial(decisionReasons)) {
519
1161
  const sessionReason = await tryMintSessionDenial(ctx);
520
- if (sessionReason) return { kind: "deny", reason: sessionReason };
1162
+ if (sessionReason) {
1163
+ return { kind: "deny", reason: sessionReason, ...signerVerdict !== void 0 && { signerVerdict } };
1164
+ }
521
1165
  }
522
1166
  return {
523
1167
  kind: "deny",
@@ -527,7 +1171,8 @@ function createAgentScoreCore(options) {
527
1171
  reasons: decisionReasons,
528
1172
  verify_url: data.verify_url,
529
1173
  data
530
- }
1174
+ },
1175
+ ...signerVerdict !== void 0 && { signerVerdict }
531
1176
  };
532
1177
  }
533
1178
  async function captureWallet2(options2) {
@@ -569,22 +1214,21 @@ function createAgentScoreCore(options) {
569
1214
  agentInstructions: sm.agent_instructions ?? WALLET_SIGNER_MISMATCH_INSTRUCTIONS
570
1215
  };
571
1216
  }
572
- function getSignerVerdict2(claimedAddress) {
573
- const claimedNorm = normalizeAddress(claimedAddress);
574
- const cached = cache.get(claimedNorm);
575
- if (!cached) return void 0;
576
- const raw = cached.raw;
577
- if (!raw) return void 0;
1217
+ function buildSignerVerdict(identity, raw) {
1218
+ if (identity.address === void 0 || identity.operatorToken !== void 0 || identity.aipToken !== void 0) {
1219
+ return void 0;
1220
+ }
578
1221
  const rawMatch = raw.signer_match;
579
1222
  const rawSanctions = raw.signer_sanctions;
580
1223
  if (!rawMatch && !rawSanctions) return void 0;
1224
+ const claimedNorm = normalizeAddress(identity.address);
581
1225
  const signerNorm = rawMatch?.actual_signer ?? claimedNorm;
582
1226
  return {
583
1227
  signer_match: rawMatch ? projectSignerMatch(rawMatch, claimedNorm, signerNorm) : null,
584
1228
  signer_sanctions: rawSanctions ?? null
585
1229
  };
586
1230
  }
587
- return { evaluate, captureWallet: captureWallet2, getSignerVerdict: getSignerVerdict2 };
1231
+ return { evaluate, captureWallet: captureWallet2 };
588
1232
  }
589
1233
 
590
1234
  // src/payment/payment_header.ts
@@ -727,11 +1371,16 @@ function agentscoreGate(options) {
727
1371
  state.infraReason = outcome.infraReason;
728
1372
  }
729
1373
  if (outcome.quota) state.quota = outcome.quota;
1374
+ if (outcome.signerVerdict) state.signerVerdict = outcome.signerVerdict;
730
1375
  }
731
1376
  if (outcome.data) req.agentscore = outcome.data;
732
1377
  next();
733
1378
  return;
734
1379
  }
1380
+ if (outcome.signerVerdict) {
1381
+ const state = req[GATE_STATE_KEY];
1382
+ if (state) state.signerVerdict = outcome.signerVerdict;
1383
+ }
735
1384
  onDenied(req, res, outcome.reason);
736
1385
  };
737
1386
  }
@@ -758,8 +1407,7 @@ async function captureWallet(req, options) {
758
1407
  }
759
1408
  function getSignerVerdict(req) {
760
1409
  const state = req[GATE_STATE_KEY];
761
- if (!state?.walletAddress) return void 0;
762
- return state.core.getSignerVerdict(state.walletAddress);
1410
+ return state?.signerVerdict;
763
1411
  }
764
1412
  function conditionalAgentscoreGate(options) {
765
1413
  const gate = agentscoreGate(options);
@@ -771,14 +1419,49 @@ function conditionalAgentscoreGate(options) {
771
1419
  return gate(req, res, next);
772
1420
  };
773
1421
  }
1422
+ var AIT_STATE_KEY = "__agentscoreAit";
1423
+ function defaultAipOnDenied(_req, res, body) {
1424
+ res.status(body.status).type("application/problem+json").json(body);
1425
+ }
1426
+ function aipGate(options) {
1427
+ const { onDenied = defaultAipOnDenied, ...gateOpts } = options;
1428
+ return async function aipGateMiddleware(req, res, next) {
1429
+ const result = await evaluateAipParts(
1430
+ { method: req.method, url: req.url, headers: req.headers },
1431
+ gateOpts
1432
+ );
1433
+ if (!result.ok) {
1434
+ onDenied(req, res, result.body);
1435
+ return;
1436
+ }
1437
+ req[AIT_STATE_KEY] = result.ait;
1438
+ next();
1439
+ };
1440
+ }
1441
+ function conditionalAipGate(options) {
1442
+ const gate = aipGate(options);
1443
+ return async function conditionalAipMiddleware(req, res, next) {
1444
+ if (!hasAgentIdentityHeaderNode(req.headers)) {
1445
+ next();
1446
+ return;
1447
+ }
1448
+ return gate(req, res, next);
1449
+ };
1450
+ }
1451
+ function getVerifiedAit(req) {
1452
+ return req[AIT_STATE_KEY];
1453
+ }
774
1454
  // Annotate the CommonJS export names for ESM import in node:
775
1455
  0 && (module.exports = {
776
1456
  agentscoreGate,
1457
+ aipGate,
777
1458
  captureWallet,
778
1459
  conditionalAgentscoreGate,
1460
+ conditionalAipGate,
779
1461
  getAgentScoreData,
780
1462
  getGateDegradedState,
781
1463
  getGateQuotaInfo,
782
- getSignerVerdict
1464
+ getSignerVerdict,
1465
+ getVerifiedAit
783
1466
  });
784
1467
  //# sourceMappingURL=express.js.map