@agent-score/commerce 2.7.5 → 2.7.7

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 (53) hide show
  1. package/dist/challenge/index.d.mts +3 -3
  2. package/dist/challenge/index.d.ts +3 -3
  3. package/dist/{checkout-DKq9gV3G.d.mts → checkout-B0jIzAEo.d.mts} +5 -5
  4. package/dist/{checkout-DW7GgRrl.d.ts → checkout-BRdpPSnc.d.ts} +5 -5
  5. package/dist/core.js +1 -1
  6. package/dist/core.mjs +1 -1
  7. package/dist/discovery/index.d.mts +6 -6
  8. package/dist/discovery/index.d.ts +6 -6
  9. package/dist/{gate-GCXy4FHI.d.mts → gate-BMUMi-P0.d.mts} +2 -2
  10. package/dist/{gate-D2RP6bZg.d.ts → gate-Bhbi5zvG.d.ts} +2 -2
  11. package/dist/identity/express.d.mts +2 -2
  12. package/dist/identity/express.d.ts +2 -2
  13. package/dist/identity/express.js +1 -1
  14. package/dist/identity/express.mjs +1 -1
  15. package/dist/identity/fastify.d.mts +2 -2
  16. package/dist/identity/fastify.d.ts +2 -2
  17. package/dist/identity/fastify.js +1 -1
  18. package/dist/identity/fastify.mjs +1 -1
  19. package/dist/identity/hono.d.mts +2 -2
  20. package/dist/identity/hono.d.ts +2 -2
  21. package/dist/identity/hono.js +1 -1
  22. package/dist/identity/hono.mjs +1 -1
  23. package/dist/identity/nextjs.d.mts +2 -2
  24. package/dist/identity/nextjs.d.ts +2 -2
  25. package/dist/identity/nextjs.js +1 -1
  26. package/dist/identity/nextjs.mjs +1 -1
  27. package/dist/identity/web.d.mts +2 -2
  28. package/dist/identity/web.d.ts +2 -2
  29. package/dist/identity/web.js +1 -1
  30. package/dist/identity/web.mjs +1 -1
  31. package/dist/index.d.mts +11 -11
  32. package/dist/index.d.ts +11 -11
  33. package/dist/index.js +179 -65
  34. package/dist/index.js.map +1 -1
  35. package/dist/index.mjs +179 -65
  36. package/dist/index.mjs.map +1 -1
  37. package/dist/{network_kind-toxNABqw.d.ts → network_kind-C3NA2wX2.d.ts} +2 -2
  38. package/dist/{network_kind-CLdLbqU5.d.mts → network_kind-DmHbQbOb.d.mts} +2 -2
  39. package/dist/payment/index.d.mts +5 -5
  40. package/dist/payment/index.d.ts +5 -5
  41. package/dist/{pricing-Dx3F1VAv.d.ts → pricing-DUYE2hIy.d.ts} +1 -1
  42. package/dist/{pricing-sfv3CPiY.d.mts → pricing-Wqbq6xIR.d.mts} +1 -1
  43. package/dist/{rail_spec-DGdb4Gnd.d.mts → rail_spec-C-jTQ7g6.d.mts} +1 -1
  44. package/dist/{rail_spec-DGdb4Gnd.d.ts → rail_spec-C-jTQ7g6.d.ts} +1 -1
  45. package/dist/stripe-multichain/index.js +175 -61
  46. package/dist/stripe-multichain/index.js.map +1 -1
  47. package/dist/stripe-multichain/index.mjs +175 -61
  48. package/dist/stripe-multichain/index.mjs.map +1 -1
  49. package/dist/{types-D1slMt0H.d.mts → types-1Mr5ZDas.d.mts} +1 -1
  50. package/dist/{types-D1slMt0H.d.ts → types-1Mr5ZDas.d.ts} +1 -1
  51. package/dist/{x402_server-Ciz2mls2.d.mts → x402_server-hgQzWQwB.d.mts} +1 -1
  52. package/dist/{x402_server-Ciz2mls2.d.ts → x402_server-hgQzWQwB.d.ts} +1 -1
  53. package/package.json +15 -14
package/dist/index.mjs CHANGED
@@ -23,11 +23,11 @@ var __export = (target, all) => {
23
23
  for (var name in all)
24
24
  __defProp(target, name, { get: all[name], enumerable: true });
25
25
  };
26
- var __copyProps = (to, from9, except, desc) => {
27
- if (from9 && typeof from9 === "object" || typeof from9 === "function") {
28
- for (let key of __getOwnPropNames(from9))
26
+ var __copyProps = (to, from10, except, desc) => {
27
+ if (from10 && typeof from10 === "object" || typeof from10 === "function") {
28
+ for (let key of __getOwnPropNames(from10))
29
29
  if (!__hasOwnProp.call(to, key) && key !== except)
30
- __defProp(to, key, { get: () => from9[key], enumerable: !(desc = __getOwnPropDesc(from9, key)) || desc.enumerable });
30
+ __defProp(to, key, { get: () => from10[key], enumerable: !(desc = __getOwnPropDesc(from10, key)) || desc.enumerable });
31
31
  }
32
32
  return to;
33
33
  };
@@ -1633,7 +1633,7 @@ var init_sha256 = __esm({
1633
1633
  }
1634
1634
  });
1635
1635
 
1636
- // node_modules/@noble/curves/esm/abstract/utils.js
1636
+ // node_modules/ox/node_modules/@noble/curves/esm/abstract/utils.js
1637
1637
  function equalBytes(a, b) {
1638
1638
  if (a.length !== b.length)
1639
1639
  return false;
@@ -1644,7 +1644,7 @@ function equalBytes(a, b) {
1644
1644
  }
1645
1645
  var hasHexBuiltin;
1646
1646
  var init_utils2 = __esm({
1647
- "node_modules/@noble/curves/esm/abstract/utils.js"() {
1647
+ "node_modules/ox/node_modules/@noble/curves/esm/abstract/utils.js"() {
1648
1648
  "use strict";
1649
1649
  hasHexBuiltin = // @ts-ignore
1650
1650
  typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function";
@@ -19869,10 +19869,16 @@ var init_Errors2 = __esm({
19869
19869
  methodUnsupported: "Use a supported wallet to pay for this resource using one of the supported payment methods returned in the WWW-Authenticate header. See https://mpp.dev/tools/wallet.md"
19870
19870
  };
19871
19871
  PaymentError = class extends Error {
19872
+ /** Safe method-specific context for diagnostics and relay responses. */
19873
+ details;
19872
19874
  /** HTTP status code. */
19873
19875
  status = 402;
19874
19876
  /** Actionable hint for resolving the error (RFC 9457 extension member). */
19875
19877
  hint;
19878
+ constructor(message, options = {}) {
19879
+ super(message);
19880
+ this.details = options.details;
19881
+ }
19876
19882
  /** Converts the error to RFC 9457 Problem Details format. */
19877
19883
  toProblemDetails(challengeId) {
19878
19884
  return {
@@ -19880,6 +19886,7 @@ var init_Errors2 = __esm({
19880
19886
  title: this.title,
19881
19887
  status: this.status,
19882
19888
  detail: this.message,
19889
+ ...this.details && Object.keys(this.details).length > 0 && { details: this.details },
19883
19890
  ...this.hint && { hint: this.hint },
19884
19891
  ...challengeId && { challengeId }
19885
19892
  };
@@ -19913,8 +19920,10 @@ var init_Errors2 = __esm({
19913
19920
  title = "Verification Failed";
19914
19921
  type = "https://paymentauth.org/problems/verification-failed";
19915
19922
  constructor(options = {}) {
19916
- const { reason } = options;
19917
- super(reason ? `Payment verification failed: ${reason}.` : "Payment verification failed.");
19923
+ const { details, reason } = options;
19924
+ super(reason ? `Payment verification failed: ${reason}.` : "Payment verification failed.", {
19925
+ details
19926
+ });
19918
19927
  }
19919
19928
  };
19920
19929
  PaymentActionRequiredError = class extends PaymentError {
@@ -20146,7 +20155,7 @@ var version3;
20146
20155
  var init_version2 = __esm({
20147
20156
  "node_modules/viem/_esm/errors/version.js"() {
20148
20157
  "use strict";
20149
- version3 = "2.55.2";
20158
+ version3 = "2.55.8";
20150
20159
  }
20151
20160
  });
20152
20161
 
@@ -20631,60 +20640,93 @@ var init_isAddress = __esm({
20631
20640
  }
20632
20641
  });
20633
20642
 
20634
- // node_modules/viem/_esm/errors/unit.js
20635
- var InvalidDecimalNumberError;
20636
- var init_unit = __esm({
20637
- "node_modules/viem/_esm/errors/unit.js"() {
20638
- "use strict";
20639
- init_base();
20640
- InvalidDecimalNumberError = class extends BaseError3 {
20641
- constructor({ value }) {
20642
- super(`Number \`${value}\` is not a valid decimal number.`, {
20643
- name: "InvalidDecimalNumberError"
20644
- });
20645
- }
20646
- };
20647
- }
20648
- });
20649
-
20650
- // node_modules/viem/_esm/utils/unit/parseUnits.js
20651
- function parseUnits(value, decimals) {
20652
- if (!/^(-?)([0-9]*)\.?([0-9]*)$/.test(value))
20643
+ // node_modules/viem/_esm/utils/unit/Value.js
20644
+ function from6(value, decimals = 0) {
20645
+ if (!Number.isInteger(decimals) || decimals < 0)
20646
+ throw new InvalidDecimalsError({ decimals });
20647
+ if (!/^-?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)$/.test(value))
20653
20648
  throw new InvalidDecimalNumberError({ value });
20654
- let [integer2, fraction = "0"] = value.split(".");
20649
+ let [integer2 = "", fraction = "0"] = value.split(".");
20655
20650
  const negative = integer2.startsWith("-");
20656
20651
  if (negative)
20657
20652
  integer2 = integer2.slice(1);
20653
+ if (integer2 === "")
20654
+ integer2 = "0";
20658
20655
  fraction = fraction.replace(/(0+)$/, "");
20659
20656
  if (decimals === 0) {
20660
- if (Math.round(Number(`.${fraction}`)) === 1)
20657
+ if (fraction.length > 0 && Number.parseInt(fraction[0], 10) >= 5)
20661
20658
  integer2 = `${BigInt(integer2) + 1n}`;
20662
20659
  fraction = "";
20663
20660
  } else if (fraction.length > decimals) {
20664
- const [left, unit, right] = [
20665
- fraction.slice(0, decimals - 1),
20666
- fraction.slice(decimals - 1, decimals),
20667
- fraction.slice(decimals)
20668
- ];
20669
- const rounded = Math.round(Number(`${unit}.${right}`));
20670
- if (rounded > 9)
20671
- fraction = `${BigInt(left) + BigInt(1)}0`.padStart(left.length + 1, "0");
20672
- else
20673
- fraction = `${left}${rounded}`;
20674
- if (fraction.length > decimals) {
20675
- fraction = fraction.slice(1);
20676
- integer2 = `${BigInt(integer2) + 1n}`;
20661
+ const left = fraction.slice(0, decimals);
20662
+ const roundDigit = Number.parseInt(fraction.slice(decimals, decimals + 1), 10);
20663
+ if (roundDigit >= 5) {
20664
+ const carried = carry(left);
20665
+ if (carried.length > decimals) {
20666
+ fraction = carried.slice(1);
20667
+ integer2 = `${BigInt(integer2) + 1n}`;
20668
+ } else {
20669
+ fraction = carried;
20670
+ }
20671
+ } else {
20672
+ fraction = left;
20677
20673
  }
20678
- fraction = fraction.slice(0, decimals);
20679
20674
  } else {
20680
20675
  fraction = fraction.padEnd(decimals, "0");
20681
20676
  }
20682
20677
  return BigInt(`${negative ? "-" : ""}${integer2}${fraction}`);
20683
20678
  }
20679
+ function carry(digits) {
20680
+ const out = digits.split("");
20681
+ let i = out.length - 1;
20682
+ while (i >= 0) {
20683
+ const d = Number.parseInt(out[i], 10) + 1;
20684
+ if (d < 10) {
20685
+ out[i] = String(d);
20686
+ return out.join("");
20687
+ }
20688
+ out[i] = "0";
20689
+ i--;
20690
+ }
20691
+ return `1${out.join("")}`;
20692
+ }
20693
+ var InvalidDecimalNumberError, InvalidDecimalsError;
20694
+ var init_Value2 = __esm({
20695
+ "node_modules/viem/_esm/utils/unit/Value.js"() {
20696
+ "use strict";
20697
+ InvalidDecimalNumberError = class extends Error {
20698
+ constructor({ value }) {
20699
+ super(`Value \`${value}\` is not a valid decimal number.`);
20700
+ Object.defineProperty(this, "name", {
20701
+ enumerable: true,
20702
+ configurable: true,
20703
+ writable: true,
20704
+ value: "Value.InvalidDecimalNumberError"
20705
+ });
20706
+ }
20707
+ };
20708
+ InvalidDecimalsError = class extends Error {
20709
+ constructor({ decimals }) {
20710
+ super(`\`decimals\` must be a non-negative integer. Got \`${decimals}\`.`);
20711
+ Object.defineProperty(this, "name", {
20712
+ enumerable: true,
20713
+ configurable: true,
20714
+ writable: true,
20715
+ value: "Value.InvalidDecimalsError"
20716
+ });
20717
+ }
20718
+ };
20719
+ }
20720
+ });
20721
+
20722
+ // node_modules/viem/_esm/utils/unit/parseUnits.js
20723
+ function parseUnits(value, decimals) {
20724
+ return from6(value, decimals);
20725
+ }
20684
20726
  var init_parseUnits = __esm({
20685
20727
  "node_modules/viem/_esm/utils/unit/parseUnits.js"() {
20686
20728
  "use strict";
20687
- init_unit();
20729
+ init_Value2();
20688
20730
  }
20689
20731
  });
20690
20732
 
@@ -20908,13 +20950,70 @@ var init_Chains = __esm({
20908
20950
  // node_modules/mppx/dist/Method.js
20909
20951
  var Method_exports = {};
20910
20952
  __export(Method_exports, {
20911
- from: () => from6,
20953
+ broadcastCredential: () => broadcastCredential,
20954
+ from: () => from7,
20955
+ selectServerMethod: () => selectServerMethod,
20912
20956
  toClient: () => toClient,
20913
- toServer: () => toServer
20957
+ toServer: () => toServer,
20958
+ validateCredential: () => validateCredential
20914
20959
  });
20915
- function from6(method) {
20960
+ function from7(method) {
20916
20961
  return method;
20917
20962
  }
20963
+ async function validateCredential(methods, input) {
20964
+ const prepared = prepareCredential(methods, input);
20965
+ if (!prepared.method.validate)
20966
+ throw new VerificationFailedError({
20967
+ details: { intent: prepared.method.intent, method: prepared.method.name },
20968
+ reason: `${prepared.method.name}/${prepared.method.intent} does not support non-mutating credential validation`
20969
+ });
20970
+ return prepared.method.validate({
20971
+ credential: prepared.credential,
20972
+ request: prepared.request
20973
+ });
20974
+ }
20975
+ async function broadcastCredential(methods, input) {
20976
+ const prepared = prepareCredential(methods, input);
20977
+ const { method } = prepared;
20978
+ if (method.broadcast && method.validate)
20979
+ await method.validate({ credential: prepared.credential, request: prepared.request });
20980
+ const broadcast = method.broadcast ?? method.verify;
20981
+ return broadcast({ credential: prepared.credential, request: prepared.request });
20982
+ }
20983
+ function prepareCredential(methods, input) {
20984
+ const credential = typeof input === "string" ? deserialize3(input) : input;
20985
+ const candidates = methods.filter((method2) => method2.name === credential.challenge.method && method2.intent === credential.challenge.intent);
20986
+ const method = selectServerMethod(candidates, credential.challenge);
20987
+ if (!method)
20988
+ throw new InvalidChallengeError({
20989
+ id: credential.challenge.id,
20990
+ reason: `no registered method for ${credential.challenge.method}/${credential.challenge.intent}`
20991
+ });
20992
+ assert5(credential.challenge.expires, credential.challenge.id);
20993
+ let payload;
20994
+ try {
20995
+ payload = method.schema.credential.payload.parse(credential.payload);
20996
+ } catch (error51) {
20997
+ throw new InvalidPayloadError(error51 instanceof Error ? { reason: error51.message } : {});
20998
+ }
20999
+ return {
21000
+ credential: { ...credential, payload },
21001
+ method,
21002
+ request: credential.challenge.request
21003
+ };
21004
+ }
21005
+ function selectServerMethod(methods, challenge) {
21006
+ if (methods.length <= 1)
21007
+ return methods[0];
21008
+ if (challenge.method !== Methods.tempo || challenge.intent !== Intents.session)
21009
+ return methods[0];
21010
+ const sessionProtocol = getMethodDetail(challenge.request.methodDetails, MethodDetailKeys.sessionProtocol);
21011
+ if (sessionProtocol === void 0 || sessionProtocol === SessionProtocols.v1)
21012
+ return methods.find((method) => method.alias === "sessionLegacy") ?? methods[0];
21013
+ if (sessionProtocol === SessionProtocols.v2)
21014
+ return methods.find((method) => method.alias === void 0) ?? methods[0];
21015
+ return void 0;
21016
+ }
20918
21017
  function toClient(method, options) {
20919
21018
  const { canHandleChallenge, context, createCredential } = options;
20920
21019
  return {
@@ -20925,7 +21024,16 @@ function toClient(method, options) {
20925
21024
  };
20926
21025
  }
20927
21026
  function toServer(method, options) {
20928
- const { alias, authorize, defaults, extensions, html, preflight, request, respond, stableBinding, transport, verify: verify3 } = options;
21027
+ const { alias, authorize, defaults, extensions, html, preflight, request, respond, broadcast, stableBinding, transport, validate: validate4, verify: verify3 } = options;
21028
+ const effectiveVerify = verify3 ?? (async (parameters) => {
21029
+ if (validate4)
21030
+ await validate4(parameters);
21031
+ if (!broadcast)
21032
+ throw new VerificationFailedError({
21033
+ reason: `${method.name}/${method.intent} does not support credential broadcast`
21034
+ });
21035
+ return broadcast(parameters);
21036
+ });
20929
21037
  return {
20930
21038
  ...method,
20931
21039
  alias,
@@ -20936,14 +21044,20 @@ function toServer(method, options) {
20936
21044
  preflight,
20937
21045
  request,
20938
21046
  respond,
21047
+ broadcast,
20939
21048
  stableBinding,
20940
21049
  transport,
20941
- verify: verify3
21050
+ validate: validate4,
21051
+ verify: effectiveVerify
20942
21052
  };
20943
21053
  }
20944
21054
  var init_Method = __esm({
20945
21055
  "node_modules/mppx/dist/Method.js"() {
20946
21056
  "use strict";
21057
+ init_Constants();
21058
+ init_Credential();
21059
+ init_Errors2();
21060
+ init_Expires();
20947
21061
  }
20948
21062
  });
20949
21063
 
@@ -21072,7 +21186,7 @@ var init_Methods = __esm({
21072
21186
  init_Method();
21073
21187
  init_zod();
21074
21188
  init_Types();
21075
- charge = from6({
21189
+ charge = from7({
21076
21190
  name: paymentMethod,
21077
21191
  intent: chargeIntent,
21078
21192
  schema: {
@@ -21164,15 +21278,15 @@ var Receipt_exports = {};
21164
21278
  __export(Receipt_exports, {
21165
21279
  Schema: () => Schema2,
21166
21280
  deserialize: () => deserialize4,
21167
- from: () => from7,
21281
+ from: () => from8,
21168
21282
  fromResponse: () => fromResponse2,
21169
21283
  serialize: () => serialize4
21170
21284
  });
21171
21285
  function deserialize4(encoded) {
21172
21286
  const json2 = Base64_exports.toString(encoded);
21173
- return from7(JSON.parse(json2));
21287
+ return from8(JSON.parse(json2));
21174
21288
  }
21175
- function from7(parameters) {
21289
+ function from8(parameters) {
21176
21290
  return Schema2.parse(parameters);
21177
21291
  }
21178
21292
  function serialize4(receipt) {
@@ -21215,12 +21329,12 @@ var init_Receipt = __esm({
21215
21329
  var Store_exports = {};
21216
21330
  __export(Store_exports, {
21217
21331
  cloudflare: () => cloudflare,
21218
- from: () => from8,
21332
+ from: () => from9,
21219
21333
  memory: () => memory,
21220
21334
  redis: () => redis,
21221
21335
  upstash: () => upstash
21222
21336
  });
21223
- function from8(store, options) {
21337
+ function from9(store, options) {
21224
21338
  return withKeyPrefix(store, options?.keyPrefix);
21225
21339
  }
21226
21340
  function withKeyPrefix(store, keyPrefix = "") {
@@ -21231,7 +21345,7 @@ function withKeyPrefix(store, keyPrefix = "") {
21231
21345
  return cached2;
21232
21346
  const backing = store;
21233
21347
  const prefixedKey = (key) => `${keyPrefix}${key}`;
21234
- const prefixed = from8({
21348
+ const prefixed = from9({
21235
21349
  async get(key) {
21236
21350
  return backing.get(prefixedKey(key));
21237
21351
  },
@@ -21268,7 +21382,7 @@ function wrapJsonUpdate(update) {
21268
21382
  };
21269
21383
  }
21270
21384
  function cloudflare(kv, options) {
21271
- return from8({
21385
+ return from9({
21272
21386
  async get(key) {
21273
21387
  const raw = await kv.get(key);
21274
21388
  if (raw == null)
@@ -21286,7 +21400,7 @@ function cloudflare(kv, options) {
21286
21400
  }
21287
21401
  function memory(options) {
21288
21402
  const store = /* @__PURE__ */ new Map();
21289
- return from8({
21403
+ return from9({
21290
21404
  async get(key) {
21291
21405
  const raw = store.get(key);
21292
21406
  if (raw === void 0)
@@ -21311,7 +21425,7 @@ function memory(options) {
21311
21425
  }, options);
21312
21426
  }
21313
21427
  function redis(client, options) {
21314
- return from8({
21428
+ return from9({
21315
21429
  async get(key) {
21316
21430
  const raw = await client.get(key);
21317
21431
  if (raw == null)
@@ -21328,7 +21442,7 @@ function redis(client, options) {
21328
21442
  }, options);
21329
21443
  }
21330
21444
  function upstash(redis2, options) {
21331
- return from8({
21445
+ return from9({
21332
21446
  async get(key) {
21333
21447
  return await redis2.get(key);
21334
21448
  },
@@ -22618,7 +22732,7 @@ function createAgentScoreCore(options) {
22618
22732
  } = options;
22619
22733
  const baseUrl = stripTrailingSlashes(rawBaseUrl);
22620
22734
  const agentMemoryHint = buildAgentMemoryHint(aipTrustedIssuers);
22621
- const defaultUa = `@agent-score/commerce@${"2.7.5"}`;
22735
+ const defaultUa = `@agent-score/commerce@${"2.7.7"}`;
22622
22736
  const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
22623
22737
  const sdk = new AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
22624
22738
  const sessionSdkCache = /* @__PURE__ */ new Map();
@@ -22980,9 +23094,9 @@ async function extractPaymentSigner(request, x402PaymentHeader) {
22980
23094
  try {
22981
23095
  const decoded = atob(x402PaymentHeader);
22982
23096
  const parsed = JSON.parse(decoded);
22983
- const from9 = parsed?.payload?.authorization?.from;
22984
- if (typeof from9 === "string" && /^0x[0-9a-fA-F]{40}$/.test(from9)) {
22985
- return { address: from9.toLowerCase(), network: "evm" };
23097
+ const from10 = parsed?.payload?.authorization?.from;
23098
+ if (typeof from10 === "string" && /^0x[0-9a-fA-F]{40}$/.test(from10)) {
23099
+ return { address: from10.toLowerCase(), network: "evm" };
22986
23100
  }
22987
23101
  } catch (err) {
22988
23102
  console.warn("[gate] x402 signer extraction failed:", err instanceof Error ? err.message : err);