@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,9 +21,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var web_exports = {};
22
22
  __export(web_exports, {
23
23
  createAgentScoreGate: () => createAgentScoreGate,
24
+ createAipGate: () => createAipGate,
24
25
  createConditionalAgentScoreGate: () => createConditionalAgentScoreGate,
25
26
  withAgentScoreGate: () => withAgentScoreGate,
26
- withConditionalAgentScoreGate: () => withConditionalAgentScoreGate
27
+ withAipGate: () => withAipGate,
28
+ withConditionalAgentScoreGate: () => withConditionalAgentScoreGate,
29
+ withConditionalAipGate: () => withConditionalAipGate
27
30
  });
28
31
  module.exports = __toCommonJS(web_exports);
29
32
 
@@ -73,7 +76,7 @@ var IDENTITY_VERIFICATION_REQUIRED_FALLBACK_INSTRUCTIONS = JSON.stringify({
73
76
  var API_ERROR_INSTRUCTIONS = JSON.stringify({
74
77
  action: "retry_with_backoff",
75
78
  steps: [
76
- "Verification is temporarily unavailable. Retry the request after 5\u201330 seconds with exponential backoff.",
79
+ "Verification is temporarily unavailable. Retry the request after 5-30 seconds with exponential backoff.",
77
80
  "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.",
78
81
  "If the request continues to fail after 3+ retries (~60 seconds total), surface the error to the user with the merchant's support contact."
79
82
  ],
@@ -160,7 +163,605 @@ function denialReasonToBody(reason) {
160
163
  return body;
161
164
  }
162
165
 
166
+ // src/aip/verify.ts
167
+ var import_jose2 = require("jose");
168
+
169
+ // src/aip/http-signature.ts
170
+ var import_jose = require("jose");
171
+ var { subtle } = globalThis.crypto;
172
+ var b64ToBytes = (b64) => {
173
+ const bin = atob(b64);
174
+ const out = new Uint8Array(bin.length);
175
+ for (let i = 0; i < bin.length; i++) {
176
+ out[i] = bin.charCodeAt(i);
177
+ }
178
+ return out;
179
+ };
180
+ var AIP_COVERED_COMPONENTS = ["@method", "@authority", "@path", "agent-identity"];
181
+ var AIP_SIGNATURE_TAG = "agent-identity";
182
+ var DEFAULT_MAX_SKEW_SECONDS = 60;
183
+ var MAX_POP_WINDOW_SECONDS = 120;
184
+ var normalizeAuthority = (authority) => {
185
+ const lower = authority.trim().toLowerCase();
186
+ const colon = lower.lastIndexOf(":");
187
+ if (colon === -1) {
188
+ return lower;
189
+ }
190
+ if (lower.includes("]") && colon < lower.indexOf("]")) {
191
+ return lower;
192
+ }
193
+ const host = lower.slice(0, colon);
194
+ const port = lower.slice(colon + 1);
195
+ if (port === "80" || port === "443") {
196
+ return host;
197
+ }
198
+ return lower;
199
+ };
200
+ var componentValue = (name, input) => {
201
+ switch (name) {
202
+ case "@method":
203
+ return input.method.toUpperCase();
204
+ case "@authority":
205
+ return normalizeAuthority(input.authority);
206
+ case "@path":
207
+ return input.path;
208
+ case "agent-identity":
209
+ return input.agentIdentity.trim();
210
+ default:
211
+ return input.extra?.[name] ?? null;
212
+ }
213
+ };
214
+ var serializeComponentList = (components) => `(${components.map((c) => `"${c}"`).join(" ")})`;
215
+ var serializeParams = (p) => {
216
+ const parts = [];
217
+ if (p.created !== void 0) {
218
+ parts.push(`created=${p.created}`);
219
+ }
220
+ if (p.expires !== void 0) {
221
+ parts.push(`expires=${p.expires}`);
222
+ }
223
+ if (p.keyid !== void 0) {
224
+ parts.push(`keyid="${p.keyid}"`);
225
+ }
226
+ if (p.alg !== void 0) {
227
+ parts.push(`alg="${p.alg}"`);
228
+ }
229
+ if (p.tag !== void 0) {
230
+ parts.push(`tag="${p.tag}"`);
231
+ }
232
+ return parts.map((s) => `;${s}`).join("");
233
+ };
234
+ var buildSignatureBase = (params, input, rawSignatureParams) => {
235
+ const lines = [];
236
+ for (const name of params.components) {
237
+ const value = componentValue(name, input);
238
+ if (value === null) {
239
+ throw new MissingComponentError(name);
240
+ }
241
+ lines.push(`"${name}": ${value}`);
242
+ }
243
+ const paramsValue = rawSignatureParams ?? serializeComponentList(params.components) + serializeParams(params);
244
+ lines.push(`"@signature-params": ${paramsValue}`);
245
+ return lines.join("\n");
246
+ };
247
+ var MissingComponentError = class extends Error {
248
+ constructor(component) {
249
+ super(`signature base missing covered component: ${component}`);
250
+ this.component = component;
251
+ this.name = "MissingComponentError";
252
+ }
253
+ component;
254
+ };
255
+ var parseSignatureInput = (header, tag = AIP_SIGNATURE_TAG) => {
256
+ const members = splitDictionary(header);
257
+ if (members.length === 0) {
258
+ return null;
259
+ }
260
+ const parsed = members.map((m) => {
261
+ const params = parseInnerListMember(m.value);
262
+ return params ? { label: m.label, params, rawParams: m.value } : null;
263
+ }).filter((x) => x !== null);
264
+ if (parsed.length === 0) {
265
+ return null;
266
+ }
267
+ return parsed.find((p) => p.params.tag === tag) ?? null;
268
+ };
269
+ var parseSignatureValue = (header, label) => {
270
+ const members = splitDictionary(header);
271
+ const member = members.find((m) => m.label === label);
272
+ if (!member) {
273
+ return null;
274
+ }
275
+ const v = member.value.trim();
276
+ if (!v.startsWith(":") || !v.endsWith(":") || v.length < 2) {
277
+ return null;
278
+ }
279
+ const b64 = v.slice(1, -1);
280
+ try {
281
+ return b64ToBytes(b64);
282
+ } catch {
283
+ return null;
284
+ }
285
+ };
286
+ var splitDictionary = (header) => {
287
+ const out = [];
288
+ let depth = 0;
289
+ let inBytes = false;
290
+ let inString = false;
291
+ let current = "";
292
+ for (let i = 0; i < header.length; i++) {
293
+ const ch = header[i];
294
+ if (inString) {
295
+ current += ch;
296
+ if (ch === '"' && header[i - 1] !== "\\") {
297
+ inString = false;
298
+ }
299
+ continue;
300
+ }
301
+ if (ch === '"') {
302
+ inString = true;
303
+ current += ch;
304
+ continue;
305
+ }
306
+ if (ch === ":") {
307
+ inBytes = !inBytes;
308
+ current += ch;
309
+ continue;
310
+ }
311
+ if (!inBytes && ch === "(") {
312
+ depth++;
313
+ current += ch;
314
+ continue;
315
+ }
316
+ if (!inBytes && ch === ")") {
317
+ depth = Math.max(0, depth - 1);
318
+ current += ch;
319
+ continue;
320
+ }
321
+ if (!inBytes && depth === 0 && ch === ",") {
322
+ pushMember(out, current);
323
+ current = "";
324
+ continue;
325
+ }
326
+ current += ch;
327
+ }
328
+ pushMember(out, current);
329
+ return out;
330
+ };
331
+ var pushMember = (out, raw) => {
332
+ const trimmed = raw.trim();
333
+ if (!trimmed) {
334
+ return;
335
+ }
336
+ const eq = trimmed.indexOf("=");
337
+ if (eq === -1) {
338
+ return;
339
+ }
340
+ const label = trimmed.slice(0, eq).trim();
341
+ const value = trimmed.slice(eq + 1).trim();
342
+ if (label) {
343
+ out.push({ label, value });
344
+ }
345
+ };
346
+ var parseInnerListMember = (value) => {
347
+ const open = value.indexOf("(");
348
+ const close = value.indexOf(")", open + 1);
349
+ if (open === -1 || close === -1) {
350
+ return null;
351
+ }
352
+ const listBody = value.slice(open + 1, close).trim();
353
+ const components = listBody.length === 0 ? [] : (listBody.match(/"[^"]*"/g) ?? []).map((s) => s.slice(1, -1));
354
+ const params = { components };
355
+ const paramStr = value.slice(close + 1);
356
+ const re = /;\s*([a-zA-Z][a-zA-Z0-9_-]*)\s*=\s*("(?:[^"\\]|\\.)*"|-?\d+)/g;
357
+ let match;
358
+ while ((match = re.exec(paramStr)) !== null) {
359
+ const key = match[1];
360
+ const raw = match[2];
361
+ const val = raw.startsWith('"') ? raw.slice(1, -1) : Number(raw);
362
+ if (key === "created") {
363
+ params.created = val;
364
+ } else if (key === "expires") {
365
+ params.expires = val;
366
+ } else if (key === "keyid") {
367
+ params.keyid = val;
368
+ } else if (key === "tag") {
369
+ params.tag = val;
370
+ } else if (key === "alg") {
371
+ params.alg = val;
372
+ }
373
+ }
374
+ return params;
375
+ };
376
+ var verifyMessageSignature = async (input) => {
377
+ const selected = parseSignatureInput(input.signatureInput);
378
+ if (!selected) {
379
+ return { ok: false, reason: "no_aip_signature" };
380
+ }
381
+ const { label, params, rawParams } = selected;
382
+ if (params.alg !== void 0 && !["ed25519", "eddsa"].includes(params.alg.toLowerCase())) {
383
+ return { ok: false, reason: "unsupported_alg" };
384
+ }
385
+ for (const required of AIP_COVERED_COMPONENTS) {
386
+ if (!params.components.includes(required)) {
387
+ return { ok: false, reason: "missing_covered_component" };
388
+ }
389
+ }
390
+ if (params.created === void 0) {
391
+ return { ok: false, reason: "created_missing" };
392
+ }
393
+ if (params.expires === void 0) {
394
+ return { ok: false, reason: "expires_missing" };
395
+ }
396
+ if (params.expires < params.created || params.expires - params.created > MAX_POP_WINDOW_SECONDS) {
397
+ return { ok: false, reason: "pop_window_too_long" };
398
+ }
399
+ const now = input.now ?? Math.floor(Date.now() / 1e3);
400
+ const skew = input.maxSkewSeconds ?? DEFAULT_MAX_SKEW_SECONDS;
401
+ if (params.created > now + skew) {
402
+ return { ok: false, reason: "created_in_future" };
403
+ }
404
+ if (params.expires < now - skew) {
405
+ return { ok: false, reason: "expired" };
406
+ }
407
+ if (!params.keyid) {
408
+ return { ok: false, reason: "missing_keyid" };
409
+ }
410
+ const cnf = input.cnfJwk;
411
+ if (cnf.kty !== "OKP" || cnf.crv !== "Ed25519" || typeof cnf.x !== "string" || cnf.x.length === 0) {
412
+ return { ok: false, reason: "unsupported_cnf_key" };
413
+ }
414
+ let thumbprint;
415
+ try {
416
+ thumbprint = await (0, import_jose.calculateJwkThumbprint)(input.cnfJwk, "sha256");
417
+ } catch {
418
+ return { ok: false, reason: "unsupported_cnf_key" };
419
+ }
420
+ if (params.keyid !== thumbprint) {
421
+ return { ok: false, reason: "keyid_mismatch" };
422
+ }
423
+ const sig = parseSignatureValue(input.signature, label);
424
+ if (!sig) {
425
+ return { ok: false, reason: "malformed_signature" };
426
+ }
427
+ let base;
428
+ try {
429
+ base = buildSignatureBase(params, {
430
+ method: input.method,
431
+ authority: input.authority,
432
+ path: input.path,
433
+ agentIdentity: input.agentIdentity,
434
+ extra: input.extraComponents
435
+ }, rawParams);
436
+ } catch (err) {
437
+ if (err instanceof MissingComponentError) {
438
+ return { ok: false, reason: "missing_covered_component" };
439
+ }
440
+ throw err;
441
+ }
442
+ let valid;
443
+ try {
444
+ const key = await (0, import_jose.importJWK)(input.cnfJwk, "EdDSA");
445
+ if (!(key instanceof CryptoKey)) {
446
+ return { ok: false, reason: "signature_invalid" };
447
+ }
448
+ valid = await subtle.verify(
449
+ { name: "Ed25519" },
450
+ key,
451
+ sig,
452
+ new TextEncoder().encode(base)
453
+ );
454
+ } catch {
455
+ return { ok: false, reason: "signature_invalid" };
456
+ }
457
+ return valid ? { ok: true, params } : { ok: false, reason: "signature_invalid" };
458
+ };
459
+
460
+ // src/aip/types.ts
461
+ var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
462
+ var isNonEmptyString = (v) => typeof v === "string" && v.length > 0;
463
+ var isAitShape = (payload) => isObject(payload) && isObject(payload.cnf) && isObject(payload.agent);
464
+ var validateAitPayload = (payload) => {
465
+ if (!isObject(payload)) {
466
+ return { ok: false, reason: "not_an_object" };
467
+ }
468
+ if (!isNonEmptyString(payload.aip_version)) {
469
+ return { ok: false, reason: "missing_aip_version" };
470
+ }
471
+ if (!isNonEmptyString(payload.iss)) {
472
+ return { ok: false, reason: "missing_iss" };
473
+ }
474
+ if (!isNonEmptyString(payload.sub)) {
475
+ return { ok: false, reason: "missing_sub" };
476
+ }
477
+ if (typeof payload.iat !== "number") {
478
+ return { ok: false, reason: "missing_iat" };
479
+ }
480
+ if (typeof payload.exp !== "number") {
481
+ return { ok: false, reason: "missing_exp" };
482
+ }
483
+ if (!isObject(payload.cnf) || !isObject(payload.cnf.jwk)) {
484
+ return { ok: false, reason: "missing_cnf" };
485
+ }
486
+ if (!isObject(payload.agent) || !isNonEmptyString(payload.agent.provider)) {
487
+ return { ok: false, reason: "missing_agent_provider" };
488
+ }
489
+ if (payload.trust_level === "human_confirmed") {
490
+ const auth = payload.auth;
491
+ const amr = isObject(auth) ? auth.amr : void 0;
492
+ if (!Array.isArray(amr) || amr.length === 0) {
493
+ return { ok: false, reason: "human_confirmed_without_amr" };
494
+ }
495
+ }
496
+ return { ok: true, payload };
497
+ };
498
+
499
+ // src/aip/verify.ts
500
+ var AGENT_IDENTITY_HEADER = "agent-identity";
501
+ var verifyAit = async (ctx, opts) => {
502
+ if (ctx.agentIdentityHeaders.length === 0) {
503
+ return { ok: false, reason: "no_token" };
504
+ }
505
+ if (!ctx.signatureInput || !ctx.signature) {
506
+ return { ok: false, reason: "pop_signature_missing" };
507
+ }
508
+ const signatureInput = ctx.signatureInput;
509
+ const signature = ctx.signature;
510
+ let lastFailure = "malformed_token";
511
+ for (const raw of ctx.agentIdentityHeaders) {
512
+ const token = stripBearer(raw);
513
+ let header;
514
+ let payload;
515
+ try {
516
+ header = (0, import_jose2.decodeProtectedHeader)(token);
517
+ payload = (0, import_jose2.decodeJwt)(token);
518
+ } catch {
519
+ lastFailure = "malformed_token";
520
+ continue;
521
+ }
522
+ if (header.alg === void 0 || header.alg.toLowerCase() === "none") {
523
+ lastFailure = "malformed_token";
524
+ continue;
525
+ }
526
+ if (!isAitShape(payload)) {
527
+ lastFailure = "malformed_token";
528
+ continue;
529
+ }
530
+ const validated = validateAitPayload(payload);
531
+ if (!validated.ok) {
532
+ lastFailure = "invalid_claims";
533
+ continue;
534
+ }
535
+ const claims = validated.payload;
536
+ const keyLookup = await opts.jwks.getKey(claims.iss, header.kid);
537
+ if (!keyLookup.ok) {
538
+ lastFailure = keyLookup.reason === "untrusted_issuer" || keyLookup.reason === "insecure_issuer" ? "untrusted_issuer" : "key_unavailable";
539
+ continue;
540
+ }
541
+ const jwtClockTolerance = opts.maxSkewSeconds ?? 60;
542
+ try {
543
+ const idpKey = await (0, import_jose2.importJWK)(keyLookup.key, normalizeAlg(header.alg));
544
+ await (0, import_jose2.jwtVerify)(token, idpKey, {
545
+ // Pin the signature algorithm allowlist (RFC 8725 §3.1) — also rejects `alg:none`. Without
546
+ // this, jose accepts whatever alg the resolved JWK supports, so a trusted IdP publishing a
547
+ // non-Ed25519 (e.g. RSA/EC) `use:sig` key would let an attacker present an RS256/ES256
548
+ // token that verifies. Matches the server-side allowlist in the AgentScore API verifier.
549
+ algorithms: AIT_SIGNING_ALGS,
550
+ clockTolerance: jwtClockTolerance,
551
+ currentDate: opts.now !== void 0 ? new Date(opts.now * 1e3) : void 0
552
+ });
553
+ } catch (err) {
554
+ lastFailure = isExpiry(err) ? "expired_token" : "idp_signature_invalid";
555
+ continue;
556
+ }
557
+ const nowSec = opts.now ?? Math.floor(Date.now() / 1e3);
558
+ if (claims.iat > nowSec + jwtClockTolerance) {
559
+ lastFailure = "expired_token";
560
+ continue;
561
+ }
562
+ if (claims.exp - claims.iat > (opts.maxLifetimeSeconds ?? 300)) {
563
+ lastFailure = "expired_token";
564
+ continue;
565
+ }
566
+ const popResult = await verifyMessageSignature({
567
+ method: ctx.method,
568
+ authority: ctx.authority,
569
+ path: ctx.path,
570
+ // The agent-identity covered component is the BARE AIT (a Bearer prefix, if present, is
571
+ // transport that `stripBearer` removed above). Verify over `token`, not `raw`, so the edge and
572
+ // the API — which verifies over the forwarded bare aip_token — reconstruct the identical base.
573
+ agentIdentity: token,
574
+ signatureInput,
575
+ signature,
576
+ cnfJwk: claims.cnf.jwk,
577
+ now: opts.now,
578
+ maxSkewSeconds: opts.maxSkewSeconds
579
+ });
580
+ if (!popResult.ok) {
581
+ lastFailure = "pop_signature_invalid";
582
+ continue;
583
+ }
584
+ return {
585
+ ok: true,
586
+ ait: {
587
+ payload: claims,
588
+ iss: claims.iss,
589
+ cnfJwk: claims.cnf.jwk,
590
+ token,
591
+ signatureMaterial: {
592
+ method: ctx.method,
593
+ authority: ctx.authority,
594
+ path: ctx.path,
595
+ signature_input: signatureInput,
596
+ signature
597
+ }
598
+ }
599
+ };
600
+ }
601
+ return { ok: false, reason: lastFailure };
602
+ };
603
+ var stripBearer = (value) => {
604
+ const trimmed = value.trim();
605
+ return /^bearer\s+/i.test(trimmed) ? trimmed.replace(/^bearer\s+/i, "") : trimmed;
606
+ };
607
+ var AIT_SIGNING_ALGS = ["EdDSA", "ES256"];
608
+ var normalizeAlg = (alg) => alg.toLowerCase() === "eddsa" ? "EdDSA" : alg;
609
+ var isExpiry = (err) => typeof err === "object" && err !== null && err.code === "ERR_JWT_EXPIRED";
610
+
611
+ // src/aip/request.ts
612
+ var readAgentIdentityHeaders = (headers) => {
613
+ const raw = headers.get(AGENT_IDENTITY_HEADER);
614
+ if (!raw) {
615
+ return [];
616
+ }
617
+ return raw.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
618
+ };
619
+ var deriveAuthority = (req, url) => req.headers.get("host") ?? url.host;
620
+ var buildVerifyContextFromRequest = (req, authority) => {
621
+ const url = new URL(req.url);
622
+ return {
623
+ method: req.method,
624
+ authority: authority ?? deriveAuthority(req, url),
625
+ path: url.pathname,
626
+ agentIdentityHeaders: readAgentIdentityHeaders(req.headers),
627
+ signatureInput: req.headers.get("signature-input"),
628
+ signature: req.headers.get("signature")
629
+ };
630
+ };
631
+ var hasAgentIdentityHeader = (req) => readAgentIdentityHeaders(req.headers).length > 0;
632
+
633
+ // src/aip/gate.ts
634
+ var aipErrorCode = (failure) => {
635
+ switch (failure) {
636
+ case "no_token":
637
+ case "pop_signature_missing":
638
+ return "agent_identity_required";
639
+ case "untrusted_issuer":
640
+ return "untrusted_issuer";
641
+ case "expired_token":
642
+ return "expired_token";
643
+ case "invalid_claims":
644
+ return "insufficient_claims";
645
+ case "key_unavailable":
646
+ return "idp_unavailable";
647
+ case "malformed_token":
648
+ case "idp_signature_invalid":
649
+ case "pop_signature_invalid":
650
+ return "invalid_signature";
651
+ default:
652
+ return "invalid_signature";
653
+ }
654
+ };
655
+ var aipErrorStatus = (failure) => {
656
+ switch (failure) {
657
+ case "key_unavailable":
658
+ return 503;
659
+ case "untrusted_issuer":
660
+ case "invalid_claims":
661
+ return 403;
662
+ default:
663
+ return 401;
664
+ }
665
+ };
666
+ var aipErrorDetail = (failure) => {
667
+ switch (failure) {
668
+ case "no_token":
669
+ return "No Agent-Identity token was presented.";
670
+ case "pop_signature_missing":
671
+ return "The request is missing the RFC 9421 HTTP Message Signature that proves possession of the token-bound key.";
672
+ case "untrusted_issuer":
673
+ return "The token's issuer is not in this service's trusted-issuer list.";
674
+ case "expired_token":
675
+ return "The Agent Identity Token has expired.";
676
+ case "invalid_claims":
677
+ return "The token is missing required claims for this endpoint.";
678
+ case "malformed_token":
679
+ return "The Agent-Identity header could not be parsed as an Agent Identity Token.";
680
+ case "idp_signature_invalid":
681
+ return "The identity provider's signature on the token failed verification.";
682
+ case "pop_signature_invalid":
683
+ return "The request signature did not match the key bound to the token.";
684
+ case "key_unavailable":
685
+ return "The identity provider's signing key could not be resolved.";
686
+ default:
687
+ return "Token verification failed.";
688
+ }
689
+ };
690
+ var buildAipErrorBody = (failure, requirements) => {
691
+ const code = aipErrorCode(failure);
692
+ const body = {
693
+ type: `urn:aip:error:${code}`,
694
+ title: code.replace(/_/g, " "),
695
+ status: aipErrorStatus(failure),
696
+ detail: aipErrorDetail(failure)
697
+ };
698
+ if (requirements) {
699
+ if (code === "untrusted_issuer" && requirements.trustedIssuers?.length) {
700
+ body.trusted_issuers = requirements.trustedIssuers;
701
+ }
702
+ if (code === "insufficient_claims") {
703
+ if (requirements.requiredClaims?.length) body.required_claims = requirements.requiredClaims;
704
+ if (requirements.requiredTrustLevel !== void 0) body.required_trust_level = requirements.requiredTrustLevel;
705
+ if (requirements.requiredAmr?.length) body.required_amr = requirements.requiredAmr;
706
+ }
707
+ }
708
+ return body;
709
+ };
710
+ var TRUST_RANK = { autonomous: 0, human_present: 1, human_confirmed: 2 };
711
+ var checkTrustRequirements = (payload, requiredTrustLevel, requiredAmr) => {
712
+ if (requiredTrustLevel !== void 0) {
713
+ const have = TRUST_RANK[payload.trust_level ?? "autonomous"] ?? 0;
714
+ const need = TRUST_RANK[requiredTrustLevel] ?? 0;
715
+ if (have < need) {
716
+ 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).`;
717
+ }
718
+ }
719
+ if (requiredAmr !== void 0 && requiredAmr.length > 0) {
720
+ const amr = Array.isArray(payload.auth?.amr) ? payload.auth.amr : [];
721
+ if (!amr.some((m) => requiredAmr.includes(m))) {
722
+ return `This endpoint requires an authentication method in [${requiredAmr.join(", ")}]; the token carries [${amr.join(", ") || "none"}].`;
723
+ }
724
+ }
725
+ return null;
726
+ };
727
+ var buildAipWeakAuthBody = (opts) => ({
728
+ type: "urn:aip:error:weak_auth",
729
+ title: "weak auth",
730
+ status: 403,
731
+ detail: opts.detail,
732
+ ...opts.requiredTrustLevel !== void 0 && { required_trust_level: opts.requiredTrustLevel },
733
+ ...opts.requiredAmr !== void 0 && opts.requiredAmr.length > 0 && { required_amr: opts.requiredAmr },
734
+ ...opts.trustedIssuers !== void 0 && opts.trustedIssuers.length > 0 && { trusted_issuers: opts.trustedIssuers }
735
+ });
736
+ var requirementsFromOptions = (opts) => ({
737
+ ...opts.trustedIssuers !== void 0 && { trustedIssuers: opts.trustedIssuers },
738
+ ...opts.requiredClaims !== void 0 && { requiredClaims: opts.requiredClaims },
739
+ ...opts.requireTrustLevel !== void 0 && { requiredTrustLevel: opts.requireTrustLevel },
740
+ ...opts.requireAmr !== void 0 && { requiredAmr: opts.requireAmr }
741
+ });
742
+ var evaluateFromContext = async (ctx, opts) => {
743
+ const result = await verifyAit(ctx, { jwks: opts.jwks, now: opts.now, maxSkewSeconds: opts.maxSkewSeconds });
744
+ if (!result.ok) {
745
+ return { ok: false, body: buildAipErrorBody(result.reason, requirementsFromOptions(opts)) };
746
+ }
747
+ const weak = checkTrustRequirements(result.ait.payload, opts.requireTrustLevel, opts.requireAmr);
748
+ if (weak !== null) {
749
+ return {
750
+ ok: false,
751
+ body: buildAipWeakAuthBody({
752
+ detail: weak,
753
+ ...opts.requireTrustLevel !== void 0 && { requiredTrustLevel: opts.requireTrustLevel },
754
+ ...opts.requireAmr !== void 0 && { requiredAmr: opts.requireAmr },
755
+ ...opts.trustedIssuers !== void 0 && { trustedIssuers: opts.trustedIssuers }
756
+ })
757
+ };
758
+ }
759
+ return { ok: true, ait: result.ait };
760
+ };
761
+ var evaluateAipRequest = (req, opts) => evaluateFromContext(buildVerifyContextFromRequest(req, opts.authority), opts);
762
+
163
763
  // src/core.ts
764
+ var import_node_crypto = require("crypto");
164
765
  var import_sdk = require("@agent-score/sdk");
165
766
 
166
767
  // src/address.ts
@@ -229,7 +830,7 @@ function stripTrailingSlashes(s) {
229
830
  while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
230
831
  return end === s.length ? s : s.slice(0, end);
231
832
  }
232
- var CANONICAL_AGENTSCORE_API = "https://api.agentscore.sh";
833
+ var CANONICAL_AGENTSCORE_API = "https://api.agentscore.com";
233
834
  var WALLET_SIGNER_MISMATCH_INSTRUCTIONS = JSON.stringify({
234
835
  action: "resign_or_switch_to_operator_token",
235
836
  steps: [
@@ -255,17 +856,22 @@ var INVALID_CREDENTIAL_INSTRUCTIONS = JSON.stringify({
255
856
  ],
256
857
  user_message: "The operator_token is not recognized. Use a different stored token, or restart the verification session flow to mint a new one."
257
858
  });
258
- function buildAgentMemoryHint() {
859
+ function buildAgentMemoryHint(aipTrustedIssuers) {
259
860
  const api = CANONICAL_AGENTSCORE_API;
861
+ const acceptsAip = aipTrustedIssuers !== void 0 && aipTrustedIssuers.length > 0;
260
862
  return {
261
863
  save_for_future_agentscore_gates: true,
262
864
  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.",
263
- quickstart: "https://docs.agentscore.sh/guides/agent-identity",
865
+ quickstart: "https://docs.agentscore.com/guides/agent-identity",
264
866
  identity_check_endpoint: `${api}/v1/credentials`,
265
867
  identity_paths: {
266
868
  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.",
267
- 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."
869
+ 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.",
870
+ ...acceptsAip && {
871
+ 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.'
872
+ }
268
873
  },
874
+ ...acceptsAip && { aip_trusted_issuers: aipTrustedIssuers },
269
875
  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.",
270
876
  do_not_persist_in_memory: ["operator_token", "poll_secret"],
271
877
  persist_in_credential_store: ["operator_token"]
@@ -273,7 +879,7 @@ function buildAgentMemoryHint() {
273
879
  }
274
880
  function createAgentScoreCore(options) {
275
881
  if (!options.apiKey) {
276
- throw new Error("AgentScore API key is required. Get one at https://agentscore.sh/sign-up");
882
+ throw new Error("AgentScore API key is required. Get one at https://www.agentscore.com/sign-up");
277
883
  }
278
884
  const {
279
885
  apiKey,
@@ -284,14 +890,15 @@ function createAgentScoreCore(options) {
284
890
  allowedJurisdictions,
285
891
  failOpen = false,
286
892
  cacheSeconds = 300,
287
- baseUrl: rawBaseUrl = "https://api.agentscore.sh",
893
+ baseUrl: rawBaseUrl = "https://api.agentscore.com",
288
894
  chain: gateChain,
289
895
  userAgent,
290
- createSessionOnMissing
896
+ createSessionOnMissing,
897
+ aipTrustedIssuers
291
898
  } = options;
292
899
  const baseUrl = stripTrailingSlashes(rawBaseUrl);
293
- const agentMemoryHint = buildAgentMemoryHint();
294
- const defaultUa = `@agent-score/commerce@${"2.4.0"}`;
900
+ const agentMemoryHint = buildAgentMemoryHint(aipTrustedIssuers);
901
+ const defaultUa = `@agent-score/commerce@${"2.6.0"}`;
295
902
  const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
296
903
  const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
297
904
  const sessionSdkCache = /* @__PURE__ */ new Map();
@@ -366,16 +973,21 @@ function createAgentScoreCore(options) {
366
973
  }
367
974
  }
368
975
  async function evaluate(identity, ctx, signer) {
369
- if (!identity || !identity.address && !identity.operatorToken) {
976
+ if (!identity || !identity.address?.trim() && !identity.operatorToken?.trim() && !identity.aipToken?.trim()) {
370
977
  if (failOpen) return { kind: "allow" };
371
978
  const sessionReason = await tryMintSessionDenial(ctx);
372
979
  if (sessionReason) return { kind: "deny", reason: sessionReason };
980
+ const acceptsAip = aipTrustedIssuers !== void 0 && aipTrustedIssuers.length > 0;
981
+ const aipStep = acceptsAip ? [
982
+ `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.`
983
+ ] : [];
373
984
  const missingIdentityInstructions = JSON.stringify({
374
985
  action: "probe_identity_then_session",
375
986
  steps: [
987
+ ...aipStep,
376
988
  "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.",
377
989
  "If step 1 is denied or you already have a stored operator_token (valid + not expired): send X-Operator-Token: opc_... and retry.",
378
- "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."
990
+ "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."
379
991
  ],
380
992
  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."
381
993
  });
@@ -388,21 +1000,26 @@ function createAgentScoreCore(options) {
388
1000
  }
389
1001
  };
390
1002
  }
391
- const cacheKey = identity.operatorToken?.toLowerCase() ?? (identity.address ? normalizeAddress(identity.address) : "");
1003
+ const identityKey = identity.aipToken ? `aip:${(0, import_node_crypto.createHash)("sha256").update(identity.aipToken).digest("hex")}` : identity.operatorToken?.toLowerCase() ?? (identity.address ? normalizeAddress(identity.address) : "");
1004
+ const cacheKey = signer ? JSON.stringify([identityKey, signer.network, normalizeAddress(signer.address)]) : JSON.stringify([identityKey]);
392
1005
  const cached = cache.get(cacheKey);
393
1006
  if (cached) {
1007
+ const cachedVerdict = cached.raw ? buildSignerVerdict(identity, cached.raw) : void 0;
394
1008
  if (cached.allow) {
395
1009
  const cachedRaw = cached.raw;
396
1010
  const cachedQuota = cachedRaw?.quota;
397
1011
  return {
398
1012
  kind: "allow",
399
1013
  data: cachedRaw,
400
- ...cachedQuota !== void 0 && { quota: cachedQuota }
1014
+ ...cachedQuota !== void 0 && { quota: cachedQuota },
1015
+ ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict }
401
1016
  };
402
1017
  }
403
1018
  if (isFixableDenial(cached.reasons)) {
404
1019
  const sessionReason = await tryMintSessionDenial(ctx);
405
- if (sessionReason) return { kind: "deny", reason: sessionReason };
1020
+ if (sessionReason) {
1021
+ return { kind: "deny", reason: sessionReason, ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict } };
1022
+ }
406
1023
  }
407
1024
  return {
408
1025
  kind: "deny",
@@ -412,7 +1029,8 @@ function createAgentScoreCore(options) {
412
1029
  reasons: cached.reasons,
413
1030
  verify_url: cached.raw?.verify_url,
414
1031
  data: cached.raw
415
- }
1032
+ },
1033
+ ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict }
416
1034
  };
417
1035
  }
418
1036
  const policy = {};
@@ -433,7 +1051,10 @@ function createAgentScoreCore(options) {
433
1051
  // regardless of policy.require_sanctions_clear (which gates the separate NAME screen).
434
1052
  ...signer && { signer: { address: signer.address, network: signer.network } }
435
1053
  };
436
- const result = identity.address ? await sdk.assess(identity.address, { ...opts, operatorToken: identity.operatorToken }) : await sdk.assess(null, { ...opts, operatorToken: identity.operatorToken });
1054
+ if (identity.aipToken !== void 0 && identity.aipSignature === void 0) {
1055
+ throw new Error("AgentScoreCore.evaluate: aipToken requires aipSignature (RFC 9421 proof-of-possession material).");
1056
+ }
1057
+ 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 });
437
1058
  data = result;
438
1059
  } catch (err) {
439
1060
  if (err instanceof import_sdk.PaymentRequiredError) {
@@ -504,17 +1125,21 @@ function createAgentScoreCore(options) {
504
1125
  const decisionReasons = data.decision_reasons ?? [];
505
1126
  const allow = decision === "allow" || decision == null;
506
1127
  cache.set(cacheKey, { allow, decision: decision ?? void 0, reasons: decisionReasons, raw: data });
1128
+ const signerVerdict = buildSignerVerdict(identity, data);
507
1129
  if (allow) {
508
1130
  const quota = data.quota;
509
1131
  return {
510
1132
  kind: "allow",
511
1133
  data,
512
- ...quota !== void 0 && { quota }
1134
+ ...quota !== void 0 && { quota },
1135
+ ...signerVerdict !== void 0 && { signerVerdict }
513
1136
  };
514
1137
  }
515
1138
  if (isFixableDenial(decisionReasons)) {
516
1139
  const sessionReason = await tryMintSessionDenial(ctx);
517
- if (sessionReason) return { kind: "deny", reason: sessionReason };
1140
+ if (sessionReason) {
1141
+ return { kind: "deny", reason: sessionReason, ...signerVerdict !== void 0 && { signerVerdict } };
1142
+ }
518
1143
  }
519
1144
  return {
520
1145
  kind: "deny",
@@ -524,7 +1149,8 @@ function createAgentScoreCore(options) {
524
1149
  reasons: decisionReasons,
525
1150
  verify_url: data.verify_url,
526
1151
  data
527
- }
1152
+ },
1153
+ ...signerVerdict !== void 0 && { signerVerdict }
528
1154
  };
529
1155
  }
530
1156
  async function captureWallet(options2) {
@@ -566,22 +1192,21 @@ function createAgentScoreCore(options) {
566
1192
  agentInstructions: sm.agent_instructions ?? WALLET_SIGNER_MISMATCH_INSTRUCTIONS
567
1193
  };
568
1194
  }
569
- function getSignerVerdict(claimedAddress) {
570
- const claimedNorm = normalizeAddress(claimedAddress);
571
- const cached = cache.get(claimedNorm);
572
- if (!cached) return void 0;
573
- const raw = cached.raw;
574
- if (!raw) return void 0;
1195
+ function buildSignerVerdict(identity, raw) {
1196
+ if (identity.address === void 0 || identity.operatorToken !== void 0 || identity.aipToken !== void 0) {
1197
+ return void 0;
1198
+ }
575
1199
  const rawMatch = raw.signer_match;
576
1200
  const rawSanctions = raw.signer_sanctions;
577
1201
  if (!rawMatch && !rawSanctions) return void 0;
1202
+ const claimedNorm = normalizeAddress(identity.address);
578
1203
  const signerNorm = rawMatch?.actual_signer ?? claimedNorm;
579
1204
  return {
580
1205
  signer_match: rawMatch ? projectSignerMatch(rawMatch, claimedNorm, signerNorm) : null,
581
1206
  signer_sanctions: rawSanctions ?? null
582
1207
  };
583
1208
  }
584
- return { evaluate, captureWallet, getSignerVerdict };
1209
+ return { evaluate, captureWallet };
585
1210
  }
586
1211
 
587
1212
  // src/payment/payment_header.ts
@@ -710,7 +1335,8 @@ function createAgentScoreGate(options) {
710
1335
  const outcome = await core.evaluate(identity, req, signer);
711
1336
  if (outcome.kind === "allow") {
712
1337
  const captureWallet = identity?.operatorToken ? (opts) => core.captureWallet({ operatorToken: identity.operatorToken, ...opts }) : void 0;
713
- const getSignerVerdictBound = identity?.address && !identity?.operatorToken ? () => core.getSignerVerdict(identity.address) : void 0;
1338
+ const signerVerdict = outcome.signerVerdict;
1339
+ const getSignerVerdictBound = identity?.address && !identity?.operatorToken ? () => signerVerdict : void 0;
714
1340
  return {
715
1341
  allowed: true,
716
1342
  data: outcome.data,
@@ -756,11 +1382,50 @@ function withConditionalAgentScoreGate(options, handler) {
756
1382
  return wrapped(req, ctx);
757
1383
  };
758
1384
  }
1385
+ var defaultAipResponse = (body) => new Response(JSON.stringify(body), { status: body.status, headers: { "content-type": "application/problem+json" } });
1386
+ function createAipGate(options) {
1387
+ const { onDenied, ...gateOpts } = options;
1388
+ return async (req) => {
1389
+ const result = await evaluateAipRequest(req, gateOpts);
1390
+ if (result.ok) {
1391
+ return { allowed: true, ait: result.ait };
1392
+ }
1393
+ const body = result.body;
1394
+ const response = onDenied ? await onDenied(req, body) : defaultAipResponse(body);
1395
+ return { allowed: false, response };
1396
+ };
1397
+ }
1398
+ function withAipGate(options, handler) {
1399
+ const guard = createAipGate(options);
1400
+ return async (req, ctx) => {
1401
+ const result = await guard(req);
1402
+ if (!result.allowed) {
1403
+ return result.response;
1404
+ }
1405
+ return handler(req, { ait: result.ait }, ctx);
1406
+ };
1407
+ }
1408
+ function withConditionalAipGate(options, handler) {
1409
+ const guard = createAipGate(options);
1410
+ return async (req, ctx) => {
1411
+ if (!hasAgentIdentityHeader(req)) {
1412
+ return handler(req, {}, ctx);
1413
+ }
1414
+ const result = await guard(req);
1415
+ if (!result.allowed) {
1416
+ return result.response;
1417
+ }
1418
+ return handler(req, { ait: result.ait }, ctx);
1419
+ };
1420
+ }
759
1421
  // Annotate the CommonJS export names for ESM import in node:
760
1422
  0 && (module.exports = {
761
1423
  createAgentScoreGate,
1424
+ createAipGate,
762
1425
  createConditionalAgentScoreGate,
763
1426
  withAgentScoreGate,
764
- withConditionalAgentScoreGate
1427
+ withAipGate,
1428
+ withConditionalAgentScoreGate,
1429
+ withConditionalAipGate
765
1430
  });
766
1431
  //# sourceMappingURL=web.js.map