@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 hono_exports = {};
22
22
  __export(hono_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(hono_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,605 @@ 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 AGENT_IDENTITY_HEADER = "agent-identity";
504
+ var verifyAit = async (ctx, opts) => {
505
+ if (ctx.agentIdentityHeaders.length === 0) {
506
+ return { ok: false, reason: "no_token" };
507
+ }
508
+ if (!ctx.signatureInput || !ctx.signature) {
509
+ return { ok: false, reason: "pop_signature_missing" };
510
+ }
511
+ const signatureInput = ctx.signatureInput;
512
+ const signature = ctx.signature;
513
+ let lastFailure = "malformed_token";
514
+ for (const raw of ctx.agentIdentityHeaders) {
515
+ const token = stripBearer(raw);
516
+ let header;
517
+ let payload;
518
+ try {
519
+ header = (0, import_jose2.decodeProtectedHeader)(token);
520
+ payload = (0, import_jose2.decodeJwt)(token);
521
+ } catch {
522
+ lastFailure = "malformed_token";
523
+ continue;
524
+ }
525
+ if (header.alg === void 0 || header.alg.toLowerCase() === "none") {
526
+ lastFailure = "malformed_token";
527
+ continue;
528
+ }
529
+ if (!isAitShape(payload)) {
530
+ lastFailure = "malformed_token";
531
+ continue;
532
+ }
533
+ const validated = validateAitPayload(payload);
534
+ if (!validated.ok) {
535
+ lastFailure = "invalid_claims";
536
+ continue;
537
+ }
538
+ const claims = validated.payload;
539
+ const keyLookup = await opts.jwks.getKey(claims.iss, header.kid);
540
+ if (!keyLookup.ok) {
541
+ lastFailure = keyLookup.reason === "untrusted_issuer" || keyLookup.reason === "insecure_issuer" ? "untrusted_issuer" : "key_unavailable";
542
+ continue;
543
+ }
544
+ const jwtClockTolerance = opts.maxSkewSeconds ?? 60;
545
+ try {
546
+ const idpKey = await (0, import_jose2.importJWK)(keyLookup.key, normalizeAlg(header.alg));
547
+ await (0, import_jose2.jwtVerify)(token, idpKey, {
548
+ // Pin the signature algorithm allowlist (RFC 8725 §3.1) — also rejects `alg:none`. Without
549
+ // this, jose accepts whatever alg the resolved JWK supports, so a trusted IdP publishing a
550
+ // non-Ed25519 (e.g. RSA/EC) `use:sig` key would let an attacker present an RS256/ES256
551
+ // token that verifies. Matches the server-side allowlist in the AgentScore API verifier.
552
+ algorithms: AIT_SIGNING_ALGS,
553
+ clockTolerance: jwtClockTolerance,
554
+ currentDate: opts.now !== void 0 ? new Date(opts.now * 1e3) : void 0
555
+ });
556
+ } catch (err) {
557
+ lastFailure = isExpiry(err) ? "expired_token" : "idp_signature_invalid";
558
+ continue;
559
+ }
560
+ const nowSec = opts.now ?? Math.floor(Date.now() / 1e3);
561
+ if (claims.iat > nowSec + jwtClockTolerance) {
562
+ lastFailure = "expired_token";
563
+ continue;
564
+ }
565
+ if (claims.exp - claims.iat > (opts.maxLifetimeSeconds ?? 300)) {
566
+ lastFailure = "expired_token";
567
+ continue;
568
+ }
569
+ const popResult = await verifyMessageSignature({
570
+ method: ctx.method,
571
+ authority: ctx.authority,
572
+ path: ctx.path,
573
+ // The agent-identity covered component is the BARE AIT (a Bearer prefix, if present, is
574
+ // transport that `stripBearer` removed above). Verify over `token`, not `raw`, so the edge and
575
+ // the API — which verifies over the forwarded bare aip_token — reconstruct the identical base.
576
+ agentIdentity: token,
577
+ signatureInput,
578
+ signature,
579
+ cnfJwk: claims.cnf.jwk,
580
+ now: opts.now,
581
+ maxSkewSeconds: opts.maxSkewSeconds
582
+ });
583
+ if (!popResult.ok) {
584
+ lastFailure = "pop_signature_invalid";
585
+ continue;
586
+ }
587
+ return {
588
+ ok: true,
589
+ ait: {
590
+ payload: claims,
591
+ iss: claims.iss,
592
+ cnfJwk: claims.cnf.jwk,
593
+ token,
594
+ signatureMaterial: {
595
+ method: ctx.method,
596
+ authority: ctx.authority,
597
+ path: ctx.path,
598
+ signature_input: signatureInput,
599
+ signature
600
+ }
601
+ }
602
+ };
603
+ }
604
+ return { ok: false, reason: lastFailure };
605
+ };
606
+ var stripBearer = (value) => {
607
+ const trimmed = value.trim();
608
+ return /^bearer\s+/i.test(trimmed) ? trimmed.replace(/^bearer\s+/i, "") : trimmed;
609
+ };
610
+ var AIT_SIGNING_ALGS = ["EdDSA", "ES256"];
611
+ var normalizeAlg = (alg) => alg.toLowerCase() === "eddsa" ? "EdDSA" : alg;
612
+ var isExpiry = (err) => typeof err === "object" && err !== null && err.code === "ERR_JWT_EXPIRED";
613
+
614
+ // src/aip/request.ts
615
+ var readAgentIdentityHeaders = (headers) => {
616
+ const raw = headers.get(AGENT_IDENTITY_HEADER);
617
+ if (!raw) {
618
+ return [];
619
+ }
620
+ return raw.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
621
+ };
622
+ var deriveAuthority = (req, url) => req.headers.get("host") ?? url.host;
623
+ var buildVerifyContextFromRequest = (req, authority) => {
624
+ const url = new URL(req.url);
625
+ return {
626
+ method: req.method,
627
+ authority: authority ?? deriveAuthority(req, url),
628
+ path: url.pathname,
629
+ agentIdentityHeaders: readAgentIdentityHeaders(req.headers),
630
+ signatureInput: req.headers.get("signature-input"),
631
+ signature: req.headers.get("signature")
632
+ };
633
+ };
634
+ var hasAgentIdentityHeader = (req) => readAgentIdentityHeaders(req.headers).length > 0;
635
+
636
+ // src/aip/gate.ts
637
+ var aipErrorCode = (failure) => {
638
+ switch (failure) {
639
+ case "no_token":
640
+ case "pop_signature_missing":
641
+ return "agent_identity_required";
642
+ case "untrusted_issuer":
643
+ return "untrusted_issuer";
644
+ case "expired_token":
645
+ return "expired_token";
646
+ case "invalid_claims":
647
+ return "insufficient_claims";
648
+ case "key_unavailable":
649
+ return "idp_unavailable";
650
+ case "malformed_token":
651
+ case "idp_signature_invalid":
652
+ case "pop_signature_invalid":
653
+ return "invalid_signature";
654
+ default:
655
+ return "invalid_signature";
656
+ }
657
+ };
658
+ var aipErrorStatus = (failure) => {
659
+ switch (failure) {
660
+ case "key_unavailable":
661
+ return 503;
662
+ case "untrusted_issuer":
663
+ case "invalid_claims":
664
+ return 403;
665
+ default:
666
+ return 401;
667
+ }
668
+ };
669
+ var aipErrorDetail = (failure) => {
670
+ switch (failure) {
671
+ case "no_token":
672
+ return "No Agent-Identity token was presented.";
673
+ case "pop_signature_missing":
674
+ return "The request is missing the RFC 9421 HTTP Message Signature that proves possession of the token-bound key.";
675
+ case "untrusted_issuer":
676
+ return "The token's issuer is not in this service's trusted-issuer list.";
677
+ case "expired_token":
678
+ return "The Agent Identity Token has expired.";
679
+ case "invalid_claims":
680
+ return "The token is missing required claims for this endpoint.";
681
+ case "malformed_token":
682
+ return "The Agent-Identity header could not be parsed as an Agent Identity Token.";
683
+ case "idp_signature_invalid":
684
+ return "The identity provider's signature on the token failed verification.";
685
+ case "pop_signature_invalid":
686
+ return "The request signature did not match the key bound to the token.";
687
+ case "key_unavailable":
688
+ return "The identity provider's signing key could not be resolved.";
689
+ default:
690
+ return "Token verification failed.";
691
+ }
692
+ };
693
+ var buildAipErrorBody = (failure, requirements) => {
694
+ const code = aipErrorCode(failure);
695
+ const body = {
696
+ type: `urn:aip:error:${code}`,
697
+ title: code.replace(/_/g, " "),
698
+ status: aipErrorStatus(failure),
699
+ detail: aipErrorDetail(failure)
700
+ };
701
+ if (requirements) {
702
+ if (code === "untrusted_issuer" && requirements.trustedIssuers?.length) {
703
+ body.trusted_issuers = requirements.trustedIssuers;
704
+ }
705
+ if (code === "insufficient_claims") {
706
+ if (requirements.requiredClaims?.length) body.required_claims = requirements.requiredClaims;
707
+ if (requirements.requiredTrustLevel !== void 0) body.required_trust_level = requirements.requiredTrustLevel;
708
+ if (requirements.requiredAmr?.length) body.required_amr = requirements.requiredAmr;
709
+ }
710
+ }
711
+ return body;
712
+ };
713
+ var TRUST_RANK = { autonomous: 0, human_present: 1, human_confirmed: 2 };
714
+ var checkTrustRequirements = (payload, requiredTrustLevel, requiredAmr) => {
715
+ if (requiredTrustLevel !== void 0) {
716
+ const have = TRUST_RANK[payload.trust_level ?? "autonomous"] ?? 0;
717
+ const need = TRUST_RANK[requiredTrustLevel] ?? 0;
718
+ if (have < need) {
719
+ 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).`;
720
+ }
721
+ }
722
+ if (requiredAmr !== void 0 && requiredAmr.length > 0) {
723
+ const amr = Array.isArray(payload.auth?.amr) ? payload.auth.amr : [];
724
+ if (!amr.some((m) => requiredAmr.includes(m))) {
725
+ return `This endpoint requires an authentication method in [${requiredAmr.join(", ")}]; the token carries [${amr.join(", ") || "none"}].`;
726
+ }
727
+ }
728
+ return null;
729
+ };
730
+ var buildAipWeakAuthBody = (opts) => ({
731
+ type: "urn:aip:error:weak_auth",
732
+ title: "weak auth",
733
+ status: 403,
734
+ detail: opts.detail,
735
+ ...opts.requiredTrustLevel !== void 0 && { required_trust_level: opts.requiredTrustLevel },
736
+ ...opts.requiredAmr !== void 0 && opts.requiredAmr.length > 0 && { required_amr: opts.requiredAmr },
737
+ ...opts.trustedIssuers !== void 0 && opts.trustedIssuers.length > 0 && { trusted_issuers: opts.trustedIssuers }
738
+ });
739
+ var requirementsFromOptions = (opts) => ({
740
+ ...opts.trustedIssuers !== void 0 && { trustedIssuers: opts.trustedIssuers },
741
+ ...opts.requiredClaims !== void 0 && { requiredClaims: opts.requiredClaims },
742
+ ...opts.requireTrustLevel !== void 0 && { requiredTrustLevel: opts.requireTrustLevel },
743
+ ...opts.requireAmr !== void 0 && { requiredAmr: opts.requireAmr }
744
+ });
745
+ var evaluateFromContext = async (ctx, opts) => {
746
+ const result = await verifyAit(ctx, { jwks: opts.jwks, now: opts.now, maxSkewSeconds: opts.maxSkewSeconds });
747
+ if (!result.ok) {
748
+ return { ok: false, body: buildAipErrorBody(result.reason, requirementsFromOptions(opts)) };
749
+ }
750
+ const weak = checkTrustRequirements(result.ait.payload, opts.requireTrustLevel, opts.requireAmr);
751
+ if (weak !== null) {
752
+ return {
753
+ ok: false,
754
+ body: buildAipWeakAuthBody({
755
+ detail: weak,
756
+ ...opts.requireTrustLevel !== void 0 && { requiredTrustLevel: opts.requireTrustLevel },
757
+ ...opts.requireAmr !== void 0 && { requiredAmr: opts.requireAmr },
758
+ ...opts.trustedIssuers !== void 0 && { trustedIssuers: opts.trustedIssuers }
759
+ })
760
+ };
761
+ }
762
+ return { ok: true, ait: result.ait };
763
+ };
764
+ var evaluateAipRequest = (req, opts) => evaluateFromContext(buildVerifyContextFromRequest(req, opts.authority), opts);
765
+
166
766
  // src/core.ts
767
+ var import_node_crypto = require("crypto");
167
768
  var import_sdk = require("@agent-score/sdk");
168
769
 
169
770
  // src/address.ts
@@ -232,7 +833,7 @@ function stripTrailingSlashes(s) {
232
833
  while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
233
834
  return end === s.length ? s : s.slice(0, end);
234
835
  }
235
- var CANONICAL_AGENTSCORE_API = "https://api.agentscore.sh";
836
+ var CANONICAL_AGENTSCORE_API = "https://api.agentscore.com";
236
837
  var WALLET_SIGNER_MISMATCH_INSTRUCTIONS = JSON.stringify({
237
838
  action: "resign_or_switch_to_operator_token",
238
839
  steps: [
@@ -258,17 +859,22 @@ var INVALID_CREDENTIAL_INSTRUCTIONS = JSON.stringify({
258
859
  ],
259
860
  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
861
  });
261
- function buildAgentMemoryHint() {
862
+ function buildAgentMemoryHint(aipTrustedIssuers) {
262
863
  const api = CANONICAL_AGENTSCORE_API;
864
+ const acceptsAip = aipTrustedIssuers !== void 0 && aipTrustedIssuers.length > 0;
263
865
  return {
264
866
  save_for_future_agentscore_gates: true,
265
867
  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",
868
+ quickstart: "https://docs.agentscore.com/guides/agent-identity",
267
869
  identity_check_endpoint: `${api}/v1/credentials`,
268
870
  identity_paths: {
269
871
  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."
872
+ 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.",
873
+ ...acceptsAip && {
874
+ 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.'
875
+ }
271
876
  },
877
+ ...acceptsAip && { aip_trusted_issuers: aipTrustedIssuers },
272
878
  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
879
  do_not_persist_in_memory: ["operator_token", "poll_secret"],
274
880
  persist_in_credential_store: ["operator_token"]
@@ -276,7 +882,7 @@ function buildAgentMemoryHint() {
276
882
  }
277
883
  function createAgentScoreCore(options) {
278
884
  if (!options.apiKey) {
279
- throw new Error("AgentScore API key is required. Get one at https://agentscore.sh/sign-up");
885
+ throw new Error("AgentScore API key is required. Get one at https://www.agentscore.com/sign-up");
280
886
  }
281
887
  const {
282
888
  apiKey,
@@ -287,14 +893,15 @@ function createAgentScoreCore(options) {
287
893
  allowedJurisdictions,
288
894
  failOpen = false,
289
895
  cacheSeconds = 300,
290
- baseUrl: rawBaseUrl = "https://api.agentscore.sh",
896
+ baseUrl: rawBaseUrl = "https://api.agentscore.com",
291
897
  chain: gateChain,
292
898
  userAgent,
293
- createSessionOnMissing
899
+ createSessionOnMissing,
900
+ aipTrustedIssuers
294
901
  } = options;
295
902
  const baseUrl = stripTrailingSlashes(rawBaseUrl);
296
- const agentMemoryHint = buildAgentMemoryHint();
297
- const defaultUa = `@agent-score/commerce@${"2.4.0"}`;
903
+ const agentMemoryHint = buildAgentMemoryHint(aipTrustedIssuers);
904
+ const defaultUa = `@agent-score/commerce@${"2.6.0"}`;
298
905
  const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
299
906
  const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
300
907
  const sessionSdkCache = /* @__PURE__ */ new Map();
@@ -369,16 +976,21 @@ function createAgentScoreCore(options) {
369
976
  }
370
977
  }
371
978
  async function evaluate(identity, ctx, signer) {
372
- if (!identity || !identity.address && !identity.operatorToken) {
979
+ if (!identity || !identity.address?.trim() && !identity.operatorToken?.trim() && !identity.aipToken?.trim()) {
373
980
  if (failOpen) return { kind: "allow" };
374
981
  const sessionReason = await tryMintSessionDenial(ctx);
375
982
  if (sessionReason) return { kind: "deny", reason: sessionReason };
983
+ const acceptsAip = aipTrustedIssuers !== void 0 && aipTrustedIssuers.length > 0;
984
+ const aipStep = acceptsAip ? [
985
+ `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.`
986
+ ] : [];
376
987
  const missingIdentityInstructions = JSON.stringify({
377
988
  action: "probe_identity_then_session",
378
989
  steps: [
990
+ ...aipStep,
379
991
  "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
992
  "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."
993
+ "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
994
  ],
383
995
  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
996
  });
@@ -391,21 +1003,26 @@ function createAgentScoreCore(options) {
391
1003
  }
392
1004
  };
393
1005
  }
394
- const cacheKey = identity.operatorToken?.toLowerCase() ?? (identity.address ? normalizeAddress(identity.address) : "");
1006
+ const identityKey = identity.aipToken ? `aip:${(0, import_node_crypto.createHash)("sha256").update(identity.aipToken).digest("hex")}` : identity.operatorToken?.toLowerCase() ?? (identity.address ? normalizeAddress(identity.address) : "");
1007
+ const cacheKey = signer ? JSON.stringify([identityKey, signer.network, normalizeAddress(signer.address)]) : JSON.stringify([identityKey]);
395
1008
  const cached = cache.get(cacheKey);
396
1009
  if (cached) {
1010
+ const cachedVerdict = cached.raw ? buildSignerVerdict(identity, cached.raw) : void 0;
397
1011
  if (cached.allow) {
398
1012
  const cachedRaw = cached.raw;
399
1013
  const cachedQuota = cachedRaw?.quota;
400
1014
  return {
401
1015
  kind: "allow",
402
1016
  data: cachedRaw,
403
- ...cachedQuota !== void 0 && { quota: cachedQuota }
1017
+ ...cachedQuota !== void 0 && { quota: cachedQuota },
1018
+ ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict }
404
1019
  };
405
1020
  }
406
1021
  if (isFixableDenial(cached.reasons)) {
407
1022
  const sessionReason = await tryMintSessionDenial(ctx);
408
- if (sessionReason) return { kind: "deny", reason: sessionReason };
1023
+ if (sessionReason) {
1024
+ return { kind: "deny", reason: sessionReason, ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict } };
1025
+ }
409
1026
  }
410
1027
  return {
411
1028
  kind: "deny",
@@ -415,7 +1032,8 @@ function createAgentScoreCore(options) {
415
1032
  reasons: cached.reasons,
416
1033
  verify_url: cached.raw?.verify_url,
417
1034
  data: cached.raw
418
- }
1035
+ },
1036
+ ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict }
419
1037
  };
420
1038
  }
421
1039
  const policy = {};
@@ -436,7 +1054,10 @@ function createAgentScoreCore(options) {
436
1054
  // regardless of policy.require_sanctions_clear (which gates the separate NAME screen).
437
1055
  ...signer && { signer: { address: signer.address, network: signer.network } }
438
1056
  };
439
- const result = identity.address ? await sdk.assess(identity.address, { ...opts, operatorToken: identity.operatorToken }) : await sdk.assess(null, { ...opts, operatorToken: identity.operatorToken });
1057
+ if (identity.aipToken !== void 0 && identity.aipSignature === void 0) {
1058
+ throw new Error("AgentScoreCore.evaluate: aipToken requires aipSignature (RFC 9421 proof-of-possession material).");
1059
+ }
1060
+ 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
1061
  data = result;
441
1062
  } catch (err) {
442
1063
  if (err instanceof import_sdk.PaymentRequiredError) {
@@ -507,17 +1128,21 @@ function createAgentScoreCore(options) {
507
1128
  const decisionReasons = data.decision_reasons ?? [];
508
1129
  const allow = decision === "allow" || decision == null;
509
1130
  cache.set(cacheKey, { allow, decision: decision ?? void 0, reasons: decisionReasons, raw: data });
1131
+ const signerVerdict = buildSignerVerdict(identity, data);
510
1132
  if (allow) {
511
1133
  const quota = data.quota;
512
1134
  return {
513
1135
  kind: "allow",
514
1136
  data,
515
- ...quota !== void 0 && { quota }
1137
+ ...quota !== void 0 && { quota },
1138
+ ...signerVerdict !== void 0 && { signerVerdict }
516
1139
  };
517
1140
  }
518
1141
  if (isFixableDenial(decisionReasons)) {
519
1142
  const sessionReason = await tryMintSessionDenial(ctx);
520
- if (sessionReason) return { kind: "deny", reason: sessionReason };
1143
+ if (sessionReason) {
1144
+ return { kind: "deny", reason: sessionReason, ...signerVerdict !== void 0 && { signerVerdict } };
1145
+ }
521
1146
  }
522
1147
  return {
523
1148
  kind: "deny",
@@ -527,7 +1152,8 @@ function createAgentScoreCore(options) {
527
1152
  reasons: decisionReasons,
528
1153
  verify_url: data.verify_url,
529
1154
  data
530
- }
1155
+ },
1156
+ ...signerVerdict !== void 0 && { signerVerdict }
531
1157
  };
532
1158
  }
533
1159
  async function captureWallet2(options2) {
@@ -569,22 +1195,21 @@ function createAgentScoreCore(options) {
569
1195
  agentInstructions: sm.agent_instructions ?? WALLET_SIGNER_MISMATCH_INSTRUCTIONS
570
1196
  };
571
1197
  }
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;
1198
+ function buildSignerVerdict(identity, raw) {
1199
+ if (identity.address === void 0 || identity.operatorToken !== void 0 || identity.aipToken !== void 0) {
1200
+ return void 0;
1201
+ }
578
1202
  const rawMatch = raw.signer_match;
579
1203
  const rawSanctions = raw.signer_sanctions;
580
1204
  if (!rawMatch && !rawSanctions) return void 0;
1205
+ const claimedNorm = normalizeAddress(identity.address);
581
1206
  const signerNorm = rawMatch?.actual_signer ?? claimedNorm;
582
1207
  return {
583
1208
  signer_match: rawMatch ? projectSignerMatch(rawMatch, claimedNorm, signerNorm) : null,
584
1209
  signer_sanctions: rawSanctions ?? null
585
1210
  };
586
1211
  }
587
- return { evaluate, captureWallet: captureWallet2, getSignerVerdict: getSignerVerdict2 };
1212
+ return { evaluate, captureWallet: captureWallet2 };
588
1213
  }
589
1214
 
590
1215
  // src/payment/payment_header.ts
@@ -716,18 +1341,23 @@ function agentscoreGate(options) {
716
1341
  const signer = await extractPaymentSigner(c.req.raw, readX402PaymentHeader(c.req.raw));
717
1342
  const outcome = await core.evaluate(identity, c, signer);
718
1343
  if (outcome.kind === "allow") {
719
- if (outcome.degraded || outcome.quota) {
1344
+ if (outcome.degraded || outcome.quota || outcome.signerVerdict) {
720
1345
  const prev = c.get(GATE_STATE_KEY);
721
1346
  c.set(GATE_STATE_KEY, {
722
1347
  ...prev,
723
1348
  ...outcome.degraded && { degraded: true, infraReason: outcome.infraReason },
724
- ...outcome.quota && { quota: outcome.quota }
1349
+ ...outcome.quota && { quota: outcome.quota },
1350
+ ...outcome.signerVerdict && { signerVerdict: outcome.signerVerdict }
725
1351
  });
726
1352
  }
727
1353
  if (outcome.data) c.set(CONTEXT_KEY, outcome.data);
728
1354
  await next();
729
1355
  return;
730
1356
  }
1357
+ if (outcome.signerVerdict) {
1358
+ const prev = c.get(GATE_STATE_KEY);
1359
+ c.set(GATE_STATE_KEY, { ...prev, signerVerdict: outcome.signerVerdict });
1360
+ }
731
1361
  return onDenied(c, outcome.reason);
732
1362
  };
733
1363
  }
@@ -754,8 +1384,7 @@ async function captureWallet(c, options) {
754
1384
  }
755
1385
  function getSignerVerdict(c) {
756
1386
  const state = c.get(GATE_STATE_KEY);
757
- if (!state?.walletAddress) return void 0;
758
- return state.core.getSignerVerdict(state.walletAddress);
1387
+ return state?.signerVerdict;
759
1388
  }
760
1389
  function conditionalAgentscoreGate(options) {
761
1390
  const gate = agentscoreGate(options);
@@ -767,14 +1396,48 @@ function conditionalAgentscoreGate(options) {
767
1396
  return gate(c, next);
768
1397
  };
769
1398
  }
1399
+ var AIT_CONTEXT_KEY = "__agentscoreAit";
1400
+ function defaultAipOnDenied(_c, body) {
1401
+ return new Response(JSON.stringify(body), {
1402
+ status: body.status,
1403
+ headers: { "content-type": "application/problem+json" }
1404
+ });
1405
+ }
1406
+ function aipGate(options) {
1407
+ const { onDenied = defaultAipOnDenied, ...gateOpts } = options;
1408
+ return async (c, next) => {
1409
+ const result = await evaluateAipRequest(c.req.raw, gateOpts);
1410
+ if (!result.ok) {
1411
+ return onDenied(c, result.body);
1412
+ }
1413
+ c.set(AIT_CONTEXT_KEY, result.ait);
1414
+ await next();
1415
+ };
1416
+ }
1417
+ function conditionalAipGate(options) {
1418
+ const gate = aipGate(options);
1419
+ return async (c, next) => {
1420
+ if (!hasAgentIdentityHeader(c.req.raw)) {
1421
+ await next();
1422
+ return;
1423
+ }
1424
+ return gate(c, next);
1425
+ };
1426
+ }
1427
+ function getVerifiedAit(c) {
1428
+ return c.get(AIT_CONTEXT_KEY);
1429
+ }
770
1430
  // Annotate the CommonJS export names for ESM import in node:
771
1431
  0 && (module.exports = {
772
1432
  agentscoreGate,
1433
+ aipGate,
773
1434
  captureWallet,
774
1435
  conditionalAgentscoreGate,
1436
+ conditionalAipGate,
775
1437
  getAgentScoreData,
776
1438
  getGateDegradedState,
777
1439
  getGateQuotaInfo,
778
- getSignerVerdict
1440
+ getSignerVerdict,
1441
+ getVerifiedAit
779
1442
  });
780
1443
  //# sourceMappingURL=hono.js.map