@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
package/dist/core.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/core.ts
2
+ import { createHash } from "crypto";
2
3
  import {
3
4
  AgentScore,
4
5
  InvalidCredentialError,
@@ -49,7 +50,7 @@ var IDENTITY_VERIFICATION_REQUIRED_FALLBACK_INSTRUCTIONS = JSON.stringify({
49
50
  var API_ERROR_INSTRUCTIONS = JSON.stringify({
50
51
  action: "retry_with_backoff",
51
52
  steps: [
52
- "Verification is temporarily unavailable. Retry the request after 5\u201330 seconds with exponential backoff.",
53
+ "Verification is temporarily unavailable. Retry the request after 5-30 seconds with exponential backoff.",
53
54
  "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.",
54
55
  "If the request continues to fail after 3+ retries (~60 seconds total), surface the error to the user with the merchant's support contact."
55
56
  ],
@@ -140,7 +141,7 @@ function stripTrailingSlashes(s) {
140
141
  while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
141
142
  return end === s.length ? s : s.slice(0, end);
142
143
  }
143
- var CANONICAL_AGENTSCORE_API = "https://api.agentscore.sh";
144
+ var CANONICAL_AGENTSCORE_API = "https://api.agentscore.com";
144
145
  var WALLET_SIGNER_MISMATCH_INSTRUCTIONS = JSON.stringify({
145
146
  action: "resign_or_switch_to_operator_token",
146
147
  steps: [
@@ -166,17 +167,22 @@ var INVALID_CREDENTIAL_INSTRUCTIONS = JSON.stringify({
166
167
  ],
167
168
  user_message: "The operator_token is not recognized. Use a different stored token, or restart the verification session flow to mint a new one."
168
169
  });
169
- function buildAgentMemoryHint() {
170
+ function buildAgentMemoryHint(aipTrustedIssuers) {
170
171
  const api = CANONICAL_AGENTSCORE_API;
172
+ const acceptsAip = aipTrustedIssuers !== void 0 && aipTrustedIssuers.length > 0;
171
173
  return {
172
174
  save_for_future_agentscore_gates: true,
173
175
  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.",
174
- quickstart: "https://docs.agentscore.sh/guides/agent-identity",
176
+ quickstart: "https://docs.agentscore.com/guides/agent-identity",
175
177
  identity_check_endpoint: `${api}/v1/credentials`,
176
178
  identity_paths: {
177
179
  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.",
178
- 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."
180
+ 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.",
181
+ ...acceptsAip && {
182
+ 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.'
183
+ }
179
184
  },
185
+ ...acceptsAip && { aip_trusted_issuers: aipTrustedIssuers },
180
186
  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.",
181
187
  do_not_persist_in_memory: ["operator_token", "poll_secret"],
182
188
  persist_in_credential_store: ["operator_token"]
@@ -184,7 +190,7 @@ function buildAgentMemoryHint() {
184
190
  }
185
191
  function createAgentScoreCore(options) {
186
192
  if (!options.apiKey) {
187
- throw new Error("AgentScore API key is required. Get one at https://agentscore.sh/sign-up");
193
+ throw new Error("AgentScore API key is required. Get one at https://www.agentscore.com/sign-up");
188
194
  }
189
195
  const {
190
196
  apiKey,
@@ -195,14 +201,15 @@ function createAgentScoreCore(options) {
195
201
  allowedJurisdictions,
196
202
  failOpen = false,
197
203
  cacheSeconds = 300,
198
- baseUrl: rawBaseUrl = "https://api.agentscore.sh",
204
+ baseUrl: rawBaseUrl = "https://api.agentscore.com",
199
205
  chain: gateChain,
200
206
  userAgent,
201
- createSessionOnMissing
207
+ createSessionOnMissing,
208
+ aipTrustedIssuers
202
209
  } = options;
203
210
  const baseUrl = stripTrailingSlashes(rawBaseUrl);
204
- const agentMemoryHint = buildAgentMemoryHint();
205
- const defaultUa = `@agent-score/commerce@${"2.4.0"}`;
211
+ const agentMemoryHint = buildAgentMemoryHint(aipTrustedIssuers);
212
+ const defaultUa = `@agent-score/commerce@${"2.6.0"}`;
206
213
  const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
207
214
  const sdk = new AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
208
215
  const sessionSdkCache = /* @__PURE__ */ new Map();
@@ -277,16 +284,21 @@ function createAgentScoreCore(options) {
277
284
  }
278
285
  }
279
286
  async function evaluate(identity, ctx, signer) {
280
- if (!identity || !identity.address && !identity.operatorToken) {
287
+ if (!identity || !identity.address?.trim() && !identity.operatorToken?.trim() && !identity.aipToken?.trim()) {
281
288
  if (failOpen) return { kind: "allow" };
282
289
  const sessionReason = await tryMintSessionDenial(ctx);
283
290
  if (sessionReason) return { kind: "deny", reason: sessionReason };
291
+ const acceptsAip = aipTrustedIssuers !== void 0 && aipTrustedIssuers.length > 0;
292
+ const aipStep = acceptsAip ? [
293
+ `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.`
294
+ ] : [];
284
295
  const missingIdentityInstructions = JSON.stringify({
285
296
  action: "probe_identity_then_session",
286
297
  steps: [
298
+ ...aipStep,
287
299
  "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.",
288
300
  "If step 1 is denied or you already have a stored operator_token (valid + not expired): send X-Operator-Token: opc_... and retry.",
289
- "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."
301
+ "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."
290
302
  ],
291
303
  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."
292
304
  });
@@ -299,21 +311,26 @@ function createAgentScoreCore(options) {
299
311
  }
300
312
  };
301
313
  }
302
- const cacheKey = identity.operatorToken?.toLowerCase() ?? (identity.address ? normalizeAddress(identity.address) : "");
314
+ const identityKey = identity.aipToken ? `aip:${createHash("sha256").update(identity.aipToken).digest("hex")}` : identity.operatorToken?.toLowerCase() ?? (identity.address ? normalizeAddress(identity.address) : "");
315
+ const cacheKey = signer ? JSON.stringify([identityKey, signer.network, normalizeAddress(signer.address)]) : JSON.stringify([identityKey]);
303
316
  const cached = cache.get(cacheKey);
304
317
  if (cached) {
318
+ const cachedVerdict = cached.raw ? buildSignerVerdict(identity, cached.raw) : void 0;
305
319
  if (cached.allow) {
306
320
  const cachedRaw = cached.raw;
307
321
  const cachedQuota = cachedRaw?.quota;
308
322
  return {
309
323
  kind: "allow",
310
324
  data: cachedRaw,
311
- ...cachedQuota !== void 0 && { quota: cachedQuota }
325
+ ...cachedQuota !== void 0 && { quota: cachedQuota },
326
+ ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict }
312
327
  };
313
328
  }
314
329
  if (isFixableDenial(cached.reasons)) {
315
330
  const sessionReason = await tryMintSessionDenial(ctx);
316
- if (sessionReason) return { kind: "deny", reason: sessionReason };
331
+ if (sessionReason) {
332
+ return { kind: "deny", reason: sessionReason, ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict } };
333
+ }
317
334
  }
318
335
  return {
319
336
  kind: "deny",
@@ -323,7 +340,8 @@ function createAgentScoreCore(options) {
323
340
  reasons: cached.reasons,
324
341
  verify_url: cached.raw?.verify_url,
325
342
  data: cached.raw
326
- }
343
+ },
344
+ ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict }
327
345
  };
328
346
  }
329
347
  const policy = {};
@@ -344,7 +362,10 @@ function createAgentScoreCore(options) {
344
362
  // regardless of policy.require_sanctions_clear (which gates the separate NAME screen).
345
363
  ...signer && { signer: { address: signer.address, network: signer.network } }
346
364
  };
347
- const result = identity.address ? await sdk.assess(identity.address, { ...opts, operatorToken: identity.operatorToken }) : await sdk.assess(null, { ...opts, operatorToken: identity.operatorToken });
365
+ if (identity.aipToken !== void 0 && identity.aipSignature === void 0) {
366
+ throw new Error("AgentScoreCore.evaluate: aipToken requires aipSignature (RFC 9421 proof-of-possession material).");
367
+ }
368
+ 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 });
348
369
  data = result;
349
370
  } catch (err) {
350
371
  if (err instanceof PaymentRequiredError) {
@@ -415,17 +436,21 @@ function createAgentScoreCore(options) {
415
436
  const decisionReasons = data.decision_reasons ?? [];
416
437
  const allow = decision === "allow" || decision == null;
417
438
  cache.set(cacheKey, { allow, decision: decision ?? void 0, reasons: decisionReasons, raw: data });
439
+ const signerVerdict = buildSignerVerdict(identity, data);
418
440
  if (allow) {
419
441
  const quota = data.quota;
420
442
  return {
421
443
  kind: "allow",
422
444
  data,
423
- ...quota !== void 0 && { quota }
445
+ ...quota !== void 0 && { quota },
446
+ ...signerVerdict !== void 0 && { signerVerdict }
424
447
  };
425
448
  }
426
449
  if (isFixableDenial(decisionReasons)) {
427
450
  const sessionReason = await tryMintSessionDenial(ctx);
428
- if (sessionReason) return { kind: "deny", reason: sessionReason };
451
+ if (sessionReason) {
452
+ return { kind: "deny", reason: sessionReason, ...signerVerdict !== void 0 && { signerVerdict } };
453
+ }
429
454
  }
430
455
  return {
431
456
  kind: "deny",
@@ -435,7 +460,8 @@ function createAgentScoreCore(options) {
435
460
  reasons: decisionReasons,
436
461
  verify_url: data.verify_url,
437
462
  data
438
- }
463
+ },
464
+ ...signerVerdict !== void 0 && { signerVerdict }
439
465
  };
440
466
  }
441
467
  async function captureWallet(options2) {
@@ -477,22 +503,21 @@ function createAgentScoreCore(options) {
477
503
  agentInstructions: sm.agent_instructions ?? WALLET_SIGNER_MISMATCH_INSTRUCTIONS
478
504
  };
479
505
  }
480
- function getSignerVerdict(claimedAddress) {
481
- const claimedNorm = normalizeAddress(claimedAddress);
482
- const cached = cache.get(claimedNorm);
483
- if (!cached) return void 0;
484
- const raw = cached.raw;
485
- if (!raw) return void 0;
506
+ function buildSignerVerdict(identity, raw) {
507
+ if (identity.address === void 0 || identity.operatorToken !== void 0 || identity.aipToken !== void 0) {
508
+ return void 0;
509
+ }
486
510
  const rawMatch = raw.signer_match;
487
511
  const rawSanctions = raw.signer_sanctions;
488
512
  if (!rawMatch && !rawSanctions) return void 0;
513
+ const claimedNorm = normalizeAddress(identity.address);
489
514
  const signerNorm = rawMatch?.actual_signer ?? claimedNorm;
490
515
  return {
491
516
  signer_match: rawMatch ? projectSignerMatch(rawMatch, claimedNorm, signerNorm) : null,
492
517
  signer_sanctions: rawSanctions ?? null
493
518
  };
494
519
  }
495
- return { evaluate, captureWallet, getSignerVerdict };
520
+ return { evaluate, captureWallet };
496
521
  }
497
522
  export {
498
523
  buildAgentMemoryHint,