@agent-score/commerce 2.5.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 +26 -2
  3. package/dist/challenge/index.d.ts +26 -2
  4. package/dist/challenge/index.js +14 -5
  5. package/dist/challenge/index.js.map +1 -1
  6. package/dist/challenge/index.mjs +14 -5
  7. package/dist/challenge/index.mjs.map +1 -1
  8. package/dist/{checkout-McfNpZJf.d.ts → checkout-C4RD7M0Z.d.ts} +46 -13
  9. package/dist/{checkout-o17dIxHi.d.mts → checkout-CzB9f_jf.d.mts} +46 -13
  10. package/dist/core.d.mts +20 -9
  11. package/dist/core.d.ts +20 -9
  12. package/dist/core.js +35 -24
  13. package/dist/core.js.map +1 -1
  14. package/dist/core.mjs +35 -24
  15. package/dist/core.mjs.map +1 -1
  16. package/dist/discovery/index.d.mts +17 -2
  17. package/dist/discovery/index.d.ts +17 -2
  18. package/dist/discovery/index.js +36 -12
  19. package/dist/discovery/index.js.map +1 -1
  20. package/dist/discovery/index.mjs +35 -12
  21. package/dist/discovery/index.mjs.map +1 -1
  22. package/dist/{gate-CWP10xPQ.d.mts → gate-D2RP6bZg.d.ts} +109 -141
  23. package/dist/{gate-CWP10xPQ.d.ts → gate-GCXy4FHI.d.mts} +109 -141
  24. package/dist/identity/express.d.mts +3 -1
  25. package/dist/identity/express.d.ts +3 -1
  26. package/dist/identity/express.js +164 -55
  27. package/dist/identity/express.js.map +1 -1
  28. package/dist/identity/express.mjs +164 -55
  29. package/dist/identity/express.mjs.map +1 -1
  30. package/dist/identity/fastify.d.mts +3 -1
  31. package/dist/identity/fastify.d.ts +3 -1
  32. package/dist/identity/fastify.js +171 -57
  33. package/dist/identity/fastify.js.map +1 -1
  34. package/dist/identity/fastify.mjs +171 -57
  35. package/dist/identity/fastify.mjs.map +1 -1
  36. package/dist/identity/hono.d.mts +3 -1
  37. package/dist/identity/hono.d.ts +3 -1
  38. package/dist/identity/hono.js +159 -59
  39. package/dist/identity/hono.js.map +1 -1
  40. package/dist/identity/hono.mjs +159 -59
  41. package/dist/identity/hono.mjs.map +1 -1
  42. package/dist/identity/nextjs.d.mts +3 -1
  43. package/dist/identity/nextjs.d.ts +3 -1
  44. package/dist/identity/nextjs.js +153 -56
  45. package/dist/identity/nextjs.js.map +1 -1
  46. package/dist/identity/nextjs.mjs +153 -56
  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 +3 -1
  55. package/dist/identity/web.d.ts +3 -1
  56. package/dist/identity/web.js +153 -56
  57. package/dist/identity/web.js.map +1 -1
  58. package/dist/identity/web.mjs +153 -56
  59. package/dist/identity/web.mjs.map +1 -1
  60. package/dist/index.d.mts +55 -10
  61. package/dist/index.d.ts +55 -10
  62. package/dist/index.js +2211 -500
  63. package/dist/index.js.map +1 -1
  64. package/dist/index.mjs +2203 -500
  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 +23 -18
@@ -1,7 +1,9 @@
1
- import { b as AipGateOptions, r as buildAipErrorBody, V as VerifiedAit } from '../gate-CWP10xPQ.mjs';
1
+ import { d as AipGateOptions, o as buildAipErrorBody, V as VerifiedAit } from '../gate-GCXy4FHI.mjs';
2
2
  import { AgentScoreCoreOptions, AgentIdentity, DenialReason, CreateSessionOnMissing, AssessResult, FailOpenInfraReason, GateQuotaInfo, SignerVerdict } from '../core.mjs';
3
3
  import { Context, MiddlewareHandler } from 'hono';
4
+ import '../types-D1slMt0H.mjs';
4
5
  import 'jose';
6
+ import '@agent-score/sdk';
5
7
  import '../signer-3FAit11j.mjs';
6
8
 
7
9
  interface AgentScoreGateOptions extends Omit<AgentScoreCoreOptions, 'createSessionOnMissing'> {
@@ -1,7 +1,9 @@
1
- import { b as AipGateOptions, r as buildAipErrorBody, V as VerifiedAit } from '../gate-CWP10xPQ.js';
1
+ import { d as AipGateOptions, o as buildAipErrorBody, V as VerifiedAit } from '../gate-D2RP6bZg.js';
2
2
  import { AgentScoreCoreOptions, AgentIdentity, DenialReason, CreateSessionOnMissing, AssessResult, FailOpenInfraReason, GateQuotaInfo, SignerVerdict } from '../core.js';
3
3
  import { Context, MiddlewareHandler } from 'hono';
4
+ import '../types-D1slMt0H.js';
4
5
  import 'jose';
6
+ import '@agent-score/sdk';
5
7
  import '../signer-3FAit11j.js';
6
8
 
7
9
  interface AgentScoreGateOptions extends Omit<AgentScoreCoreOptions, 'createSessionOnMissing'> {
@@ -79,7 +79,7 @@ var IDENTITY_VERIFICATION_REQUIRED_FALLBACK_INSTRUCTIONS = JSON.stringify({
79
79
  var API_ERROR_INSTRUCTIONS = JSON.stringify({
80
80
  action: "retry_with_backoff",
81
81
  steps: [
82
- "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.",
83
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.",
84
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."
85
85
  ],
@@ -183,6 +183,7 @@ var b64ToBytes = (b64) => {
183
183
  var AIP_COVERED_COMPONENTS = ["@method", "@authority", "@path", "agent-identity"];
184
184
  var AIP_SIGNATURE_TAG = "agent-identity";
185
185
  var DEFAULT_MAX_SKEW_SECONDS = 60;
186
+ var MAX_POP_WINDOW_SECONDS = 120;
186
187
  var normalizeAuthority = (authority) => {
187
188
  const lower = authority.trim().toLowerCase();
188
189
  const colon = lower.lastIndexOf(":");
@@ -233,7 +234,7 @@ var serializeParams = (p) => {
233
234
  }
234
235
  return parts.map((s) => `;${s}`).join("");
235
236
  };
236
- var buildSignatureBase = (params, input) => {
237
+ var buildSignatureBase = (params, input, rawSignatureParams) => {
237
238
  const lines = [];
238
239
  for (const name of params.components) {
239
240
  const value = componentValue(name, input);
@@ -242,7 +243,7 @@ var buildSignatureBase = (params, input) => {
242
243
  }
243
244
  lines.push(`"${name}": ${value}`);
244
245
  }
245
- const paramsValue = serializeComponentList(params.components) + serializeParams(params);
246
+ const paramsValue = rawSignatureParams ?? serializeComponentList(params.components) + serializeParams(params);
246
247
  lines.push(`"@signature-params": ${paramsValue}`);
247
248
  return lines.join("\n");
248
249
  };
@@ -261,19 +262,12 @@ var parseSignatureInput = (header, tag = AIP_SIGNATURE_TAG) => {
261
262
  }
262
263
  const parsed = members.map((m) => {
263
264
  const params = parseInnerListMember(m.value);
264
- return params ? { label: m.label, params } : null;
265
+ return params ? { label: m.label, params, rawParams: m.value } : null;
265
266
  }).filter((x) => x !== null);
266
267
  if (parsed.length === 0) {
267
268
  return null;
268
269
  }
269
- const tagged = parsed.find((p) => p.params.tag === tag);
270
- if (tagged) {
271
- return tagged;
272
- }
273
- if (parsed.length === 1 && parsed[0].params.tag === void 0) {
274
- return parsed[0];
275
- }
276
- return null;
270
+ return parsed.find((p) => p.params.tag === tag) ?? null;
277
271
  };
278
272
  var parseSignatureValue = (header, label) => {
279
273
  const members = splitDictionary(header);
@@ -387,7 +381,7 @@ var verifyMessageSignature = async (input) => {
387
381
  if (!selected) {
388
382
  return { ok: false, reason: "no_aip_signature" };
389
383
  }
390
- const { label, params } = selected;
384
+ const { label, params, rawParams } = selected;
391
385
  if (params.alg !== void 0 && !["ed25519", "eddsa"].includes(params.alg.toLowerCase())) {
392
386
  return { ok: false, reason: "unsupported_alg" };
393
387
  }
@@ -396,12 +390,21 @@ var verifyMessageSignature = async (input) => {
396
390
  return { ok: false, reason: "missing_covered_component" };
397
391
  }
398
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
+ }
399
402
  const now = input.now ?? Math.floor(Date.now() / 1e3);
400
403
  const skew = input.maxSkewSeconds ?? DEFAULT_MAX_SKEW_SECONDS;
401
- if (params.created !== void 0 && params.created > now + skew) {
404
+ if (params.created > now + skew) {
402
405
  return { ok: false, reason: "created_in_future" };
403
406
  }
404
- if (params.expires !== void 0 && params.expires < now - skew) {
407
+ if (params.expires < now - skew) {
405
408
  return { ok: false, reason: "expired" };
406
409
  }
407
410
  if (!params.keyid) {
@@ -432,7 +435,7 @@ var verifyMessageSignature = async (input) => {
432
435
  path: input.path,
433
436
  agentIdentity: input.agentIdentity,
434
437
  extra: input.extraComponents
435
- });
438
+ }, rawParams);
436
439
  } catch (err) {
437
440
  if (err instanceof MissingComponentError) {
438
441
  return { ok: false, reason: "missing_covered_component" };
@@ -505,6 +508,8 @@ var verifyAit = async (ctx, opts) => {
505
508
  if (!ctx.signatureInput || !ctx.signature) {
506
509
  return { ok: false, reason: "pop_signature_missing" };
507
510
  }
511
+ const signatureInput = ctx.signatureInput;
512
+ const signature = ctx.signature;
508
513
  let lastFailure = "malformed_token";
509
514
  for (const raw of ctx.agentIdentityHeaders) {
510
515
  const token = stripBearer(raw);
@@ -543,7 +548,7 @@ var verifyAit = async (ctx, opts) => {
543
548
  // Pin the signature algorithm allowlist (RFC 8725 §3.1) — also rejects `alg:none`. Without
544
549
  // this, jose accepts whatever alg the resolved JWK supports, so a trusted IdP publishing a
545
550
  // non-Ed25519 (e.g. RSA/EC) `use:sig` key would let an attacker present an RS256/ES256
546
- // token that verifies. Matches the server-side allowlist in core/api aip-verify.
551
+ // token that verifies. Matches the server-side allowlist in the AgentScore API verifier.
547
552
  algorithms: AIT_SIGNING_ALGS,
548
553
  clockTolerance: jwtClockTolerance,
549
554
  currentDate: opts.now !== void 0 ? new Date(opts.now * 1e3) : void 0
@@ -557,13 +562,20 @@ var verifyAit = async (ctx, opts) => {
557
562
  lastFailure = "expired_token";
558
563
  continue;
559
564
  }
565
+ if (claims.exp - claims.iat > (opts.maxLifetimeSeconds ?? 300)) {
566
+ lastFailure = "expired_token";
567
+ continue;
568
+ }
560
569
  const popResult = await verifyMessageSignature({
561
570
  method: ctx.method,
562
571
  authority: ctx.authority,
563
572
  path: ctx.path,
564
- agentIdentity: raw,
565
- signatureInput: ctx.signatureInput,
566
- signature: ctx.signature,
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,
567
579
  cnfJwk: claims.cnf.jwk,
568
580
  now: opts.now,
569
581
  maxSkewSeconds: opts.maxSkewSeconds
@@ -572,7 +584,22 @@ var verifyAit = async (ctx, opts) => {
572
584
  lastFailure = "pop_signature_invalid";
573
585
  continue;
574
586
  }
575
- return { ok: true, ait: { payload: claims, iss: claims.iss, cnfJwk: claims.cnf.jwk, token } };
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
+ };
576
603
  }
577
604
  return { ok: false, reason: lastFailure };
578
605
  };
@@ -593,11 +620,11 @@ var readAgentIdentityHeaders = (headers) => {
593
620
  return raw.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
594
621
  };
595
622
  var deriveAuthority = (req, url) => req.headers.get("host") ?? url.host;
596
- var buildVerifyContextFromRequest = (req) => {
623
+ var buildVerifyContextFromRequest = (req, authority) => {
597
624
  const url = new URL(req.url);
598
625
  return {
599
626
  method: req.method,
600
- authority: deriveAuthority(req, url),
627
+ authority: authority ?? deriveAuthority(req, url),
601
628
  path: url.pathname,
602
629
  agentIdentityHeaders: readAgentIdentityHeaders(req.headers),
603
630
  signatureInput: req.headers.get("signature-input"),
@@ -607,11 +634,6 @@ var buildVerifyContextFromRequest = (req) => {
607
634
  var hasAgentIdentityHeader = (req) => readAgentIdentityHeaders(req.headers).length > 0;
608
635
 
609
636
  // src/aip/gate.ts
610
- var verifyFromContext = async (ctx, opts) => {
611
- const result = await verifyAit(ctx, { jwks: opts.jwks, now: opts.now, maxSkewSeconds: opts.maxSkewSeconds });
612
- return result.ok ? { ok: true, ait: result.ait } : { ok: false, failure: result.reason };
613
- };
614
- var verifyAitRequest = (req, opts) => verifyFromContext(buildVerifyContextFromRequest(req), opts);
615
637
  var aipErrorCode = (failure) => {
616
638
  switch (failure) {
617
639
  case "no_token":
@@ -668,15 +690,78 @@ var aipErrorDetail = (failure) => {
668
690
  return "Token verification failed.";
669
691
  }
670
692
  };
671
- var buildAipErrorBody = (failure) => {
693
+ var buildAipErrorBody = (failure, requirements) => {
672
694
  const code = aipErrorCode(failure);
673
- return {
695
+ const body = {
674
696
  type: `urn:aip:error:${code}`,
675
697
  title: code.replace(/_/g, " "),
676
698
  status: aipErrorStatus(failure),
677
699
  detail: aipErrorDetail(failure)
678
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;
679
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);
680
765
 
681
766
  // src/core.ts
682
767
  var import_node_crypto = require("crypto");
@@ -748,7 +833,7 @@ function stripTrailingSlashes(s) {
748
833
  while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
749
834
  return end === s.length ? s : s.slice(0, end);
750
835
  }
751
- var CANONICAL_AGENTSCORE_API = "https://api.agentscore.sh";
836
+ var CANONICAL_AGENTSCORE_API = "https://api.agentscore.com";
752
837
  var WALLET_SIGNER_MISMATCH_INSTRUCTIONS = JSON.stringify({
753
838
  action: "resign_or_switch_to_operator_token",
754
839
  steps: [
@@ -780,7 +865,7 @@ function buildAgentMemoryHint(aipTrustedIssuers) {
780
865
  return {
781
866
  save_for_future_agentscore_gates: true,
782
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.",
783
- quickstart: "https://docs.agentscore.sh/guides/agent-identity",
868
+ quickstart: "https://docs.agentscore.com/guides/agent-identity",
784
869
  identity_check_endpoint: `${api}/v1/credentials`,
785
870
  identity_paths: {
786
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.",
@@ -797,7 +882,7 @@ function buildAgentMemoryHint(aipTrustedIssuers) {
797
882
  }
798
883
  function createAgentScoreCore(options) {
799
884
  if (!options.apiKey) {
800
- 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");
801
886
  }
802
887
  const {
803
888
  apiKey,
@@ -808,7 +893,7 @@ function createAgentScoreCore(options) {
808
893
  allowedJurisdictions,
809
894
  failOpen = false,
810
895
  cacheSeconds = 300,
811
- baseUrl: rawBaseUrl = "https://api.agentscore.sh",
896
+ baseUrl: rawBaseUrl = "https://api.agentscore.com",
812
897
  chain: gateChain,
813
898
  userAgent,
814
899
  createSessionOnMissing,
@@ -816,7 +901,7 @@ function createAgentScoreCore(options) {
816
901
  } = options;
817
902
  const baseUrl = stripTrailingSlashes(rawBaseUrl);
818
903
  const agentMemoryHint = buildAgentMemoryHint(aipTrustedIssuers);
819
- const defaultUa = `@agent-score/commerce@${"2.5.0"}`;
904
+ const defaultUa = `@agent-score/commerce@${"2.6.0"}`;
820
905
  const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
821
906
  const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
822
907
  const sessionSdkCache = /* @__PURE__ */ new Map();
@@ -834,7 +919,6 @@ function createAgentScoreCore(options) {
834
919
  return s;
835
920
  }
836
921
  const cache = new TTLCache(cacheSeconds * 1e3);
837
- const lastSignerRaw = /* @__PURE__ */ new Map();
838
922
  async function tryMintSessionDenial(ctx) {
839
923
  if (!createSessionOnMissing) return void 0;
840
924
  try {
@@ -906,7 +990,7 @@ function createAgentScoreCore(options) {
906
990
  ...aipStep,
907
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.",
908
992
  "If step 1 is denied or you already have a stored operator_token (valid + not expired): send X-Operator-Token: opc_... and retry.",
909
- "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."
910
994
  ],
911
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."
912
996
  });
@@ -919,21 +1003,26 @@ function createAgentScoreCore(options) {
919
1003
  }
920
1004
  };
921
1005
  }
922
- const cacheKey = identity.aipToken ? `aip:${(0, import_node_crypto.createHash)("sha256").update(identity.aipToken).digest("hex")}` : 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]);
923
1008
  const cached = cache.get(cacheKey);
924
1009
  if (cached) {
1010
+ const cachedVerdict = cached.raw ? buildSignerVerdict(identity, cached.raw) : void 0;
925
1011
  if (cached.allow) {
926
1012
  const cachedRaw = cached.raw;
927
1013
  const cachedQuota = cachedRaw?.quota;
928
1014
  return {
929
1015
  kind: "allow",
930
1016
  data: cachedRaw,
931
- ...cachedQuota !== void 0 && { quota: cachedQuota }
1017
+ ...cachedQuota !== void 0 && { quota: cachedQuota },
1018
+ ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict }
932
1019
  };
933
1020
  }
934
1021
  if (isFixableDenial(cached.reasons)) {
935
1022
  const sessionReason = await tryMintSessionDenial(ctx);
936
- if (sessionReason) return { kind: "deny", reason: sessionReason };
1023
+ if (sessionReason) {
1024
+ return { kind: "deny", reason: sessionReason, ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict } };
1025
+ }
937
1026
  }
938
1027
  return {
939
1028
  kind: "deny",
@@ -943,7 +1032,8 @@ function createAgentScoreCore(options) {
943
1032
  reasons: cached.reasons,
944
1033
  verify_url: cached.raw?.verify_url,
945
1034
  data: cached.raw
946
- }
1035
+ },
1036
+ ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict }
947
1037
  };
948
1038
  }
949
1039
  const policy = {};
@@ -964,7 +1054,10 @@ function createAgentScoreCore(options) {
964
1054
  // regardless of policy.require_sanctions_clear (which gates the separate NAME screen).
965
1055
  ...signer && { signer: { address: signer.address, network: signer.network } }
966
1056
  };
967
- const result = identity.aipToken ? await sdk.assess(null, { ...opts, aipToken: identity.aipToken }) : 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 });
968
1061
  data = result;
969
1062
  } catch (err) {
970
1063
  if (err instanceof import_sdk.PaymentRequiredError) {
@@ -1035,20 +1128,21 @@ function createAgentScoreCore(options) {
1035
1128
  const decisionReasons = data.decision_reasons ?? [];
1036
1129
  const allow = decision === "allow" || decision == null;
1037
1130
  cache.set(cacheKey, { allow, decision: decision ?? void 0, reasons: decisionReasons, raw: data });
1038
- if (identity.address !== void 0 && identity.operatorToken === void 0 && identity.aipToken === void 0 && (data.signer_match !== void 0 || data.signer_sanctions !== void 0)) {
1039
- lastSignerRaw.set(normalizeAddress(identity.address), data);
1040
- }
1131
+ const signerVerdict = buildSignerVerdict(identity, data);
1041
1132
  if (allow) {
1042
1133
  const quota = data.quota;
1043
1134
  return {
1044
1135
  kind: "allow",
1045
1136
  data,
1046
- ...quota !== void 0 && { quota }
1137
+ ...quota !== void 0 && { quota },
1138
+ ...signerVerdict !== void 0 && { signerVerdict }
1047
1139
  };
1048
1140
  }
1049
1141
  if (isFixableDenial(decisionReasons)) {
1050
1142
  const sessionReason = await tryMintSessionDenial(ctx);
1051
- if (sessionReason) return { kind: "deny", reason: sessionReason };
1143
+ if (sessionReason) {
1144
+ return { kind: "deny", reason: sessionReason, ...signerVerdict !== void 0 && { signerVerdict } };
1145
+ }
1052
1146
  }
1053
1147
  return {
1054
1148
  kind: "deny",
@@ -1058,7 +1152,8 @@ function createAgentScoreCore(options) {
1058
1152
  reasons: decisionReasons,
1059
1153
  verify_url: data.verify_url,
1060
1154
  data
1061
- }
1155
+ },
1156
+ ...signerVerdict !== void 0 && { signerVerdict }
1062
1157
  };
1063
1158
  }
1064
1159
  async function captureWallet2(options2) {
@@ -1100,20 +1195,21 @@ function createAgentScoreCore(options) {
1100
1195
  agentInstructions: sm.agent_instructions ?? WALLET_SIGNER_MISMATCH_INSTRUCTIONS
1101
1196
  };
1102
1197
  }
1103
- function getSignerVerdict2(claimedAddress) {
1104
- const claimedNorm = normalizeAddress(claimedAddress);
1105
- const raw = lastSignerRaw.get(claimedNorm) ?? cache.get(claimedNorm)?.raw;
1106
- 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
+ }
1107
1202
  const rawMatch = raw.signer_match;
1108
1203
  const rawSanctions = raw.signer_sanctions;
1109
1204
  if (!rawMatch && !rawSanctions) return void 0;
1205
+ const claimedNorm = normalizeAddress(identity.address);
1110
1206
  const signerNorm = rawMatch?.actual_signer ?? claimedNorm;
1111
1207
  return {
1112
1208
  signer_match: rawMatch ? projectSignerMatch(rawMatch, claimedNorm, signerNorm) : null,
1113
1209
  signer_sanctions: rawSanctions ?? null
1114
1210
  };
1115
1211
  }
1116
- return { evaluate, captureWallet: captureWallet2, getSignerVerdict: getSignerVerdict2 };
1212
+ return { evaluate, captureWallet: captureWallet2 };
1117
1213
  }
1118
1214
 
1119
1215
  // src/payment/payment_header.ts
@@ -1245,18 +1341,23 @@ function agentscoreGate(options) {
1245
1341
  const signer = await extractPaymentSigner(c.req.raw, readX402PaymentHeader(c.req.raw));
1246
1342
  const outcome = await core.evaluate(identity, c, signer);
1247
1343
  if (outcome.kind === "allow") {
1248
- if (outcome.degraded || outcome.quota) {
1344
+ if (outcome.degraded || outcome.quota || outcome.signerVerdict) {
1249
1345
  const prev = c.get(GATE_STATE_KEY);
1250
1346
  c.set(GATE_STATE_KEY, {
1251
1347
  ...prev,
1252
1348
  ...outcome.degraded && { degraded: true, infraReason: outcome.infraReason },
1253
- ...outcome.quota && { quota: outcome.quota }
1349
+ ...outcome.quota && { quota: outcome.quota },
1350
+ ...outcome.signerVerdict && { signerVerdict: outcome.signerVerdict }
1254
1351
  });
1255
1352
  }
1256
1353
  if (outcome.data) c.set(CONTEXT_KEY, outcome.data);
1257
1354
  await next();
1258
1355
  return;
1259
1356
  }
1357
+ if (outcome.signerVerdict) {
1358
+ const prev = c.get(GATE_STATE_KEY);
1359
+ c.set(GATE_STATE_KEY, { ...prev, signerVerdict: outcome.signerVerdict });
1360
+ }
1260
1361
  return onDenied(c, outcome.reason);
1261
1362
  };
1262
1363
  }
@@ -1283,8 +1384,7 @@ async function captureWallet(c, options) {
1283
1384
  }
1284
1385
  function getSignerVerdict(c) {
1285
1386
  const state = c.get(GATE_STATE_KEY);
1286
- if (!state?.walletAddress) return void 0;
1287
- return state.core.getSignerVerdict(state.walletAddress);
1387
+ return state?.signerVerdict;
1288
1388
  }
1289
1389
  function conditionalAgentscoreGate(options) {
1290
1390
  const gate = agentscoreGate(options);
@@ -1306,9 +1406,9 @@ function defaultAipOnDenied(_c, body) {
1306
1406
  function aipGate(options) {
1307
1407
  const { onDenied = defaultAipOnDenied, ...gateOpts } = options;
1308
1408
  return async (c, next) => {
1309
- const result = await verifyAitRequest(c.req.raw, gateOpts);
1409
+ const result = await evaluateAipRequest(c.req.raw, gateOpts);
1310
1410
  if (!result.ok) {
1311
- return onDenied(c, buildAipErrorBody(result.failure));
1411
+ return onDenied(c, result.body);
1312
1412
  }
1313
1413
  c.set(AIT_CONTEXT_KEY, result.ait);
1314
1414
  await next();