@devlab.group/agent-commerce 2.6.0 → 2.7.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 (123) hide show
  1. package/README.md +17 -12
  2. package/dist/ap2.d.ts +1 -1
  3. package/dist/ap2.js +5 -5
  4. package/dist/{chunk-ES3V6ECS.js → chunk-77HLISG4.js} +3 -2
  5. package/dist/chunk-77HLISG4.js.map +1 -0
  6. package/dist/{chunk-5ZYXBCDX.js → chunk-D7FPSGUQ.js} +25 -4
  7. package/dist/chunk-D7FPSGUQ.js.map +1 -0
  8. package/dist/{chunk-G3EYYHKF.js → chunk-DJRWYDKJ.js} +3 -3
  9. package/dist/{chunk-G3EYYHKF.js.map → chunk-DJRWYDKJ.js.map} +1 -1
  10. package/dist/{chunk-M6MQ3FYS.js → chunk-EMKITGVV.js} +4 -4
  11. package/dist/chunk-EMKITGVV.js.map +1 -0
  12. package/dist/chunk-IWXVQYG5.js +6 -0
  13. package/dist/chunk-IWXVQYG5.js.map +1 -0
  14. package/dist/chunk-O3ACF45K.js +8 -0
  15. package/dist/{chunk-M6BSXXTF.js.map → chunk-O3ACF45K.js.map} +1 -1
  16. package/dist/{chunk-M6WW6QIT.js → chunk-WDD2ZUR3.js} +5 -3
  17. package/dist/chunk-WDD2ZUR3.js.map +1 -0
  18. package/dist/{chunk-M52FBNJX.js → chunk-YHNTTMED.js} +6 -4
  19. package/dist/chunk-YHNTTMED.js.map +1 -0
  20. package/dist/{chunk-DRLBML7Z.js → chunk-ZSIUZPNB.js} +175 -74
  21. package/dist/chunk-ZSIUZPNB.js.map +1 -0
  22. package/dist/cli/{ap2-2YMYA2H6.js → ap2-5FFGSW6F.js} +10 -11
  23. package/dist/cli/ap2-5FFGSW6F.js.map +1 -0
  24. package/dist/cli/{chunk-5K4XEAZV.js → chunk-3IEXJ7I3.js} +25 -4
  25. package/dist/cli/chunk-3IEXJ7I3.js.map +1 -0
  26. package/dist/cli/{chunk-VJH6RYRK.js → chunk-3NVJAQRO.js} +3 -3
  27. package/dist/cli/{chunk-VJH6RYRK.js.map → chunk-3NVJAQRO.js.map} +1 -1
  28. package/dist/cli/{chunk-GET3CZGR.js → chunk-55AI6CLW.js} +6 -4
  29. package/dist/cli/chunk-55AI6CLW.js.map +1 -0
  30. package/dist/cli/{chunk-YOF7IK4V.js → chunk-5K2JDM4G.js} +177 -76
  31. package/dist/cli/chunk-5K2JDM4G.js.map +1 -0
  32. package/dist/cli/{chunk-NSYSMDQN.js → chunk-5TID36YG.js} +57 -29
  33. package/dist/cli/chunk-5TID36YG.js.map +1 -0
  34. package/dist/cli/{chunk-3NOMLMJW.js → chunk-66NTYSXI.js} +3 -3
  35. package/dist/cli/{chunk-3NOMLMJW.js.map → chunk-66NTYSXI.js.map} +1 -1
  36. package/dist/cli/{chunk-VJ4EO4LE.js → chunk-6EBDOH37.js} +3 -3
  37. package/dist/cli/{chunk-VJ4EO4LE.js.map → chunk-6EBDOH37.js.map} +1 -1
  38. package/dist/cli/{chunk-YWG2ZN3L.js → chunk-AGQ4U7IN.js} +5 -5
  39. package/dist/cli/chunk-AGQ4U7IN.js.map +1 -0
  40. package/dist/cli/chunk-APC5BTQM.js +6 -0
  41. package/dist/cli/chunk-APC5BTQM.js.map +1 -0
  42. package/dist/cli/{chunk-SYQLJXIU.js → chunk-C5YISPT6.js} +3 -3
  43. package/dist/cli/chunk-C5YISPT6.js.map +1 -0
  44. package/dist/cli/chunk-DKWO6LLX.js +34 -0
  45. package/dist/cli/chunk-DKWO6LLX.js.map +1 -0
  46. package/dist/cli/{chunk-SPAYKVUP.js → chunk-FL4HPCD4.js} +3 -2
  47. package/dist/cli/chunk-FL4HPCD4.js.map +1 -0
  48. package/dist/cli/{chunk-3EQBCFZY.js → chunk-H7EBJ4I3.js} +3 -3
  49. package/dist/cli/{chunk-3EQBCFZY.js.map → chunk-H7EBJ4I3.js.map} +1 -1
  50. package/dist/cli/{chunk-PTL7SNOI.js → chunk-OETKXDGA.js} +467 -122
  51. package/dist/cli/chunk-OETKXDGA.js.map +1 -0
  52. package/dist/cli/{chunk-DHFMIBPG.js → chunk-PLHPKXAT.js} +6 -6
  53. package/dist/cli/{chunk-DHFMIBPG.js.map → chunk-PLHPKXAT.js.map} +1 -1
  54. package/dist/cli/{chunk-TFV3K6YS.js → chunk-VSSSU4AU.js} +3 -3
  55. package/dist/cli/{chunk-TFV3K6YS.js.map → chunk-VSSSU4AU.js.map} +1 -1
  56. package/dist/cli/chunk-ZCW56PZ3.js +8 -0
  57. package/dist/cli/{chunk-4KLYFXMW.js.map → chunk-ZCW56PZ3.js.map} +1 -1
  58. package/dist/cli/{chunk-AZL7RPFU.js → chunk-ZFVQWOGG.js} +64 -16
  59. package/dist/cli/chunk-ZFVQWOGG.js.map +1 -0
  60. package/dist/cli/config-WT5HHDRR.js +13 -0
  61. package/dist/cli/{config-3K65QJ22.js.map → config-WT5HHDRR.js.map} +1 -1
  62. package/dist/cli/index.js +51 -37
  63. package/dist/cli/index.js.map +1 -1
  64. package/dist/cli/{mcp-6F64A7KE.js → mcp-HHGNOUKE.js} +7 -7
  65. package/dist/cli/{mcp-6F64A7KE.js.map → mcp-HHGNOUKE.js.map} +1 -1
  66. package/dist/cli/payment-providers-EWXZFBIE.js +6 -0
  67. package/dist/cli/{payment-providers-2ITS6KNR.js.map → payment-providers-EWXZFBIE.js.map} +1 -1
  68. package/dist/cli/{provider-5BGG5YKQ.js → provider-XUPLYNQ7.js} +9 -9
  69. package/dist/cli/{provider-5BGG5YKQ.js.map → provider-XUPLYNQ7.js.map} +1 -1
  70. package/dist/cli/receipts-3DSV4DIK.js +9 -0
  71. package/dist/cli/{receipts-I4IIE7U6.js.map → receipts-3DSV4DIK.js.map} +1 -1
  72. package/dist/cli/reconcile-GS25MQ42.js +4 -0
  73. package/dist/cli/{reconcile-55WNCSFC.js.map → reconcile-GS25MQ42.js.map} +1 -1
  74. package/dist/cli/{run-2P6ZGFUE.js → run-7KLKW3HE.js} +107 -35
  75. package/dist/cli/run-7KLKW3HE.js.map +1 -0
  76. package/dist/cli/{x402-4LPIIELI.js → x402-HP4E3QET.js} +11 -10
  77. package/dist/cli/x402-HP4E3QET.js.map +1 -0
  78. package/dist/{guardrails-CX_jYXvZ.d.ts → guardrails-CeyLS1ou.d.ts} +2 -2
  79. package/dist/index.d.ts +23 -13
  80. package/dist/index.js +660 -170
  81. package/dist/index.js.map +1 -1
  82. package/dist/mcp.d.ts +2 -2
  83. package/dist/mcp.js +4 -4
  84. package/dist/mpp.js +5 -5
  85. package/dist/{protocol-adapter-1WbtM3xG.d.ts → protocol-adapter-DdFL5LBU.d.ts} +12 -2
  86. package/dist/{runtime-B-kARa2f.d.ts → runtime-BmaSp2Ce.d.ts} +31 -3
  87. package/dist/{store-kIIMpUA-.d.ts → store-BVvMzpuV.d.ts} +25 -8
  88. package/dist/testing.d.ts +1 -1
  89. package/dist/testing.js +156 -2
  90. package/dist/testing.js.map +1 -1
  91. package/dist/{transaction-Dv0UFGg5.d.ts → transaction-BXXJltZ-.d.ts} +1 -1
  92. package/dist/x402.d.ts +7 -2
  93. package/dist/x402.js +7 -6
  94. package/dist/x402.js.map +1 -1
  95. package/package.json +13 -29
  96. package/dist/chunk-5ZYXBCDX.js.map +0 -1
  97. package/dist/chunk-DRLBML7Z.js.map +0 -1
  98. package/dist/chunk-ES3V6ECS.js.map +0 -1
  99. package/dist/chunk-M52FBNJX.js.map +0 -1
  100. package/dist/chunk-M6BSXXTF.js +0 -8
  101. package/dist/chunk-M6MQ3FYS.js.map +0 -1
  102. package/dist/chunk-M6WW6QIT.js.map +0 -1
  103. package/dist/cli/ap2-2YMYA2H6.js.map +0 -1
  104. package/dist/cli/chunk-4KLYFXMW.js +0 -8
  105. package/dist/cli/chunk-5K4XEAZV.js.map +0 -1
  106. package/dist/cli/chunk-6R6WJ4FD.js +0 -18
  107. package/dist/cli/chunk-6R6WJ4FD.js.map +0 -1
  108. package/dist/cli/chunk-AZL7RPFU.js.map +0 -1
  109. package/dist/cli/chunk-FHCFR2GS.js +0 -17
  110. package/dist/cli/chunk-FHCFR2GS.js.map +0 -1
  111. package/dist/cli/chunk-GET3CZGR.js.map +0 -1
  112. package/dist/cli/chunk-NSYSMDQN.js.map +0 -1
  113. package/dist/cli/chunk-PTL7SNOI.js.map +0 -1
  114. package/dist/cli/chunk-SPAYKVUP.js.map +0 -1
  115. package/dist/cli/chunk-SYQLJXIU.js.map +0 -1
  116. package/dist/cli/chunk-YOF7IK4V.js.map +0 -1
  117. package/dist/cli/chunk-YWG2ZN3L.js.map +0 -1
  118. package/dist/cli/config-3K65QJ22.js +0 -12
  119. package/dist/cli/payment-providers-2ITS6KNR.js +0 -6
  120. package/dist/cli/receipts-I4IIE7U6.js +0 -8
  121. package/dist/cli/reconcile-55WNCSFC.js +0 -4
  122. package/dist/cli/run-2P6ZGFUE.js.map +0 -1
  123. package/dist/cli/x402-4LPIIELI.js.map +0 -1
@@ -1,8 +1,8 @@
1
- import { isWellKnownDevKey, assertPayToIsNotDevAddress, resolveX402Deployment, assertDevKeyIsLocalOnly, describeRpc, x402OfferName } from './chunk-YWG2ZN3L.js';
2
- import { findX402Network, normalizeAddress, canonicalJson, X402_DEFAULT_PAYMENT_FLOW, REUSE_REJECTED_AUTHORIZATION_METADATA_KEY, SETTLE_AFTER_BACKEND_METADATA_KEY, sameAddress, LOCAL_CHAIN_ID, isTransactionReference, isEvmAddress, describeDeploymentMode } from './chunk-3NOMLMJW.js';
3
- import { PACKAGE_VERSION } from './chunk-4KLYFXMW.js';
4
- import { systemClock, NOOP_LOGGER, RECONCILIATION_METADATA_KEY } from './chunk-GET3CZGR.js';
5
- import { CommerceError, redactedErrorText, isCommerceError } from './chunk-SYQLJXIU.js';
1
+ import { isWellKnownDevKey, assertPayToIsNotDevAddress, resolveX402Deployment, assertDevKeyIsLocalOnly, describeRpc, x402OfferName, CDP_FACILITATOR_URL } from './chunk-AGQ4U7IN.js';
2
+ import { findX402Network, normalizeAddress, canonicalJson, X402_DEFAULT_PAYMENT_FLOW, REUSE_REJECTED_AUTHORIZATION_METADATA_KEY, SETTLE_AFTER_BACKEND_METADATA_KEY, sameAddress, LOCAL_CHAIN_ID, isTransactionReference, isEvmAddress, describeDeploymentMode } from './chunk-66NTYSXI.js';
3
+ import { PACKAGE_VERSION } from './chunk-ZCW56PZ3.js';
4
+ import { systemClock, NOOP_LOGGER, RECONCILIATION_METADATA_KEY } from './chunk-55AI6CLW.js';
5
+ import { CommerceError, redactedErrorText, isCommerceError } from './chunk-C5YISPT6.js';
6
6
  import { LOCATOR_VERSION, eip3009Locator, computeReplayKey, permit2Locator, computePermit2ReplayKey, isoFromSeconds } from './chunk-663ALDZA.js';
7
7
  import { isRecord } from './chunk-3M6U7ILB.js';
8
8
  import { x402ExactPermit2ProxyAddress, toFacilitatorEvmSigner, PERMIT2_ADDRESS, eip3009ABI, x402ExactPermit2ProxyABI } from '@x402/evm';
@@ -10,9 +10,9 @@ import { parseAbi, isAddress, keccak256, stringToBytes, isHash, getAddress, form
10
10
  import { privateKeyToAccount } from 'viem/accounts';
11
11
  import { HTTPFacilitatorClient } from '@x402/core/http';
12
12
  import { SettleError, VerifyError } from '@x402/core/types';
13
+ import { randomBytes, createPrivateKey, sign } from 'crypto';
13
14
  import { x402Facilitator } from '@x402/core/facilitator';
14
15
  import { registerExactEvmScheme } from '@x402/evm/exact/facilitator';
15
- import { randomBytes } from 'crypto';
16
16
  import { PaymentPayloadV2Schema } from '@x402/core/schemas';
17
17
 
18
18
  // src/payments/x402/provider/constants.ts
@@ -456,32 +456,71 @@ function createLocalFacilitatorClient(rpcUrl, signerPrivateKey, chainId) {
456
456
  transport: http(rpcUrl)
457
457
  }).extend(publicActions);
458
458
  }
459
- var SETTLEMENT_CONFIRMATION_TIMEOUT_MS = 6e4;
460
- var SUPPORTED_TIMEOUT_MS = 1e4;
461
- function cdpAuthHeaders(apiKeyId, apiKeySecret) {
462
- const loading = import('@coinbase/x402').then(
463
- (mod) => mod.createCdpAuthHeaders(apiKeyId, apiKeySecret),
464
- (cause) => {
465
- throw new CommerceError(
466
- "CONFIG_INVALID",
467
- 'x402 provider: facilitator.auth.type is "cdp", which needs the optional peer "@coinbase/x402". Install it (npm install @coinbase/x402), or use a facilitator that accepts a static token with auth.type "bearer".',
468
- { cause }
469
- );
470
- }
471
- );
472
- loading.catch(() => {
473
- });
459
+ var TOKEN_LIFETIME_SECONDS = 120;
460
+ function createCdpAuthHeaders(apiKeyId, apiKeySecret, now = Date.now) {
461
+ const signingKey = readKey(apiKeySecret);
462
+ const { host, pathname } = new URL(CDP_FACILITATOR_URL);
474
463
  return async () => {
475
- const create = await loading;
476
- if (!create) {
464
+ if (!signingKey) {
477
465
  throw new CommerceError(
478
- "PAYMENT_PROVIDER_UNAVAILABLE",
479
- "x402 provider: @coinbase/x402 returned no auth-header factory"
466
+ "CONFIG_INVALID",
467
+ "x402 provider: facilitator.auth.apiKeySecret is not a CDP API key secret. Use the PEM EC private key or the base64 Ed25519 key that CDP issued."
480
468
  );
481
469
  }
482
- return await create();
470
+ const issuedAt = Math.floor(now() / 1e3);
471
+ const header = (method, route) => ({
472
+ Authorization: `Bearer ${signJwt(signingKey, apiKeyId, `${method} ${host}${pathname}/${route}`, issuedAt)}`
473
+ });
474
+ return {
475
+ verify: header("POST", "verify"),
476
+ settle: header("POST", "settle"),
477
+ supported: header("GET", "supported")
478
+ };
479
+ };
480
+ }
481
+ function readKey(secret) {
482
+ try {
483
+ if (secret.includes("-----BEGIN")) {
484
+ const key2 = createPrivateKey(secret);
485
+ const p256 = key2.asymmetricKeyType === "ec" && key2.asymmetricKeyDetails?.namedCurve === "prime256v1";
486
+ return p256 ? { alg: "ES256", key: key2 } : void 0;
487
+ }
488
+ const raw = Buffer.from(secret, "base64");
489
+ if (raw.length !== 64) return void 0;
490
+ const key = createPrivateKey({
491
+ format: "jwk",
492
+ key: {
493
+ kty: "OKP",
494
+ crv: "Ed25519",
495
+ d: raw.subarray(0, 32).toString("base64url"),
496
+ x: raw.subarray(32).toString("base64url")
497
+ }
498
+ });
499
+ return { alg: "EdDSA", key };
500
+ } catch {
501
+ return void 0;
502
+ }
503
+ }
504
+ function signJwt(signingKey, apiKeyId, uri, issuedAt) {
505
+ const { alg, key } = signingKey;
506
+ const header = { alg, kid: apiKeyId, typ: "JWT", nonce: randomBytes(16).toString("hex") };
507
+ const claims = {
508
+ sub: apiKeyId,
509
+ iss: "cdp",
510
+ uris: [uri],
511
+ iat: issuedAt,
512
+ nbf: issuedAt,
513
+ exp: issuedAt + TOKEN_LIFETIME_SECONDS
483
514
  };
515
+ const input = `${base64url(header)}.${base64url(claims)}`;
516
+ const signature = alg === "ES256" ? sign("sha256", Buffer.from(input), { key, dsaEncoding: "ieee-p1363" }) : sign(null, Buffer.from(input), key);
517
+ return `${input}.${signature.toString("base64url")}`;
484
518
  }
519
+ var base64url = (value) => Buffer.from(JSON.stringify(value)).toString("base64url");
520
+
521
+ // src/payments/x402/facilitator.ts
522
+ var SETTLEMENT_CONFIRMATION_TIMEOUT_MS = 6e4;
523
+ var SUPPORTED_TIMEOUT_MS = 1e4;
485
524
  function verdictFromVerifyError(err) {
486
525
  if (err instanceof VerifyError && err.statusCode === 400 && typeof err.invalidReason === "string") {
487
526
  return {
@@ -513,7 +552,7 @@ function createRemoteFacilitatorBinding(options) {
513
552
  return { verify: headers, settle: headers, supported: headers };
514
553
  };
515
554
  } else if (auth.type === "cdp") {
516
- createAuthHeaders = cdpAuthHeaders(auth.apiKeyId, auth.apiKeySecret);
555
+ createAuthHeaders = createCdpAuthHeaders(auth.apiKeyId, auth.apiKeySecret);
517
556
  }
518
557
  const client = new HTTPFacilitatorClient({
519
558
  url: options.url,
@@ -664,10 +703,10 @@ function resolveOffers(inputs, options) {
664
703
  let remoteBinding;
665
704
  let mode;
666
705
  const built = /* @__PURE__ */ new Map();
667
- const resolveList = (list, field) => {
706
+ const resolveList = (list, field2) => {
668
707
  const seen = /* @__PURE__ */ new Set();
669
708
  return list.map((input, index) => {
670
- const at = (name) => field(index, name);
709
+ const at = (name) => field2(index, name);
671
710
  const known = findX402Network(input.network, options.customNetworks);
672
711
  if (known !== void 0 && known.family !== "evm") {
673
712
  const shape = known.family === "svm" ? "a Solana address (base58, 32 bytes)" : "a NEAR account ID";
@@ -823,6 +862,104 @@ function offerCurrency(offer, quoted) {
823
862
  const canonical = offer.profile.canonicalAsset;
824
863
  return canonical !== void 0 && sameAddress(offer.profile, offer.asset, canonical.address) ? canonical.symbol : quoted;
825
864
  }
865
+ function decodePaymentSubmission(payloadBase64) {
866
+ const json = decodeJson(payloadBase64);
867
+ if (json === void 0) return void 0;
868
+ const result = PaymentPayloadV2Schema.safeParse(json);
869
+ return result.success ? result.data : void 0;
870
+ }
871
+ function declaredX402Version(payloadBase64) {
872
+ const json = decodeJson(payloadBase64);
873
+ return typeof json === "object" && json !== null ? json["x402Version"] : void 0;
874
+ }
875
+ function forFacilitator(payload) {
876
+ const { resource: _resource, extensions: _extensions, ...rest } = payload;
877
+ return rest;
878
+ }
879
+ function decodeJson(payloadBase64) {
880
+ try {
881
+ return JSON.parse(Buffer.from(payloadBase64, "base64").toString("utf8"));
882
+ } catch {
883
+ return void 0;
884
+ }
885
+ }
886
+ function isExactEvmPayload(payload) {
887
+ const inner = payload.payload;
888
+ return payload.accepted.scheme === "exact" && isRecord(inner) && isRecord(inner["authorization"]) && !("permit2Authorization" in inner) && typeof inner["signature"] === "string";
889
+ }
890
+ var UINT256 = /^(0|[1-9]\d{0,77})$/;
891
+ var UINT256_MAX = 2n ** 256n - 1n;
892
+ var BYTES32 = /^0x[0-9a-fA-F]{64}$/;
893
+ var isUint256 = (value) => typeof value === "string" && UINT256.test(value) && BigInt(value) <= UINT256_MAX;
894
+ function hasEip3009Fields(authorization) {
895
+ return isEvmAddress(authorization["from"]) && isEvmAddress(authorization["to"]) && isUint256(authorization["value"]) && isUint256(authorization["validAfter"]) && isUint256(authorization["validBefore"]) && typeof authorization["nonce"] === "string" && BYTES32.test(authorization["nonce"]);
896
+ }
897
+ function isExactPermit2Payload(payload) {
898
+ const inner = payload.payload;
899
+ if (payload.accepted.scheme !== "exact" || !isRecord(inner)) return false;
900
+ const auth = inner["permit2Authorization"];
901
+ if (!isRecord(auth) || "authorization" in inner || typeof inner["signature"] !== "string") {
902
+ return false;
903
+ }
904
+ const { permitted, witness } = auth;
905
+ return isRecord(permitted) && isRecord(witness) && isEvmAddress(auth["from"]) && isEvmAddress(auth["spender"]) && isEvmAddress(permitted["token"]) && isEvmAddress(witness["to"]) && isUint256(permitted["amount"]) && isUint256(auth["nonce"]) && isUint256(auth["deadline"]) && isUint256(witness["validAfter"]);
906
+ }
907
+
908
+ // src/payments/x402/provider/payment-id.ts
909
+ var PAYMENT_IDENTIFIER = "payment-identifier";
910
+ var ID_PATTERN = /^[A-Za-z0-9_-]{16,128}$/;
911
+ var field = (value, key) => isRecord(value) ? value[key] : void 0;
912
+ function paymentIdentifierExtensions(resource) {
913
+ const redelivery = resource.idempotency?.redelivery;
914
+ if (redelivery === void 0) return void 0;
915
+ return {
916
+ [PAYMENT_IDENTIFIER]: {
917
+ info: { required: redelivery.required },
918
+ schema: {
919
+ $schema: "https://json-schema.org/draft/2020-12/schema",
920
+ type: "object",
921
+ properties: {
922
+ required: { type: "boolean" },
923
+ id: { type: "string", minLength: 16, maxLength: 128, pattern: "^[a-zA-Z0-9_-]+$" }
924
+ },
925
+ required: ["required"]
926
+ }
927
+ }
928
+ };
929
+ }
930
+ function paymentRetryKey(context) {
931
+ const { resource, submission } = context;
932
+ const redelivery = resource.idempotency?.redelivery;
933
+ if (redelivery === void 0) return void 0;
934
+ const payload = decodePaymentSubmission(submission.payload);
935
+ if (payload === void 0) return void 0;
936
+ const extension = payload.extensions?.[PAYMENT_IDENTIFIER];
937
+ const info = field(extension, "info");
938
+ if (extension !== void 0 && !isRecord(info)) throw invalid(resource);
939
+ const id = field(info, "id");
940
+ if (id === void 0) {
941
+ if (!redelivery.required) return void 0;
942
+ throw new CommerceError("INPUT_INVALID", "This resource requires a payment identifier", {
943
+ resourceId: resource.id,
944
+ details: { reason: "payment_identifier_required" }
945
+ });
946
+ }
947
+ if (typeof id !== "string" || !ID_PATTERN.test(id)) throw invalid(resource);
948
+ return id;
949
+ }
950
+ function paymentIdentifierEchoed(envelope, payload) {
951
+ const declared = field(field(field(envelope, "extensions"), PAYMENT_IDENTIFIER), "info");
952
+ const echoed = payload.extensions?.[PAYMENT_IDENTIFIER];
953
+ if (!isRecord(declared) || echoed === void 0) return true;
954
+ return field(field(echoed, "info"), "required") === declared["required"];
955
+ }
956
+ function invalid(resource) {
957
+ return new CommerceError(
958
+ "INPUT_INVALID",
959
+ 'A payment identifier must be 16 to 128 characters of A-Z, a-z, 0-9, "_" and "-"',
960
+ { resourceId: resource.id, details: { reason: "payment_identifier_invalid" } }
961
+ );
962
+ }
826
963
  var QUOTE_EXTENSION = "erc-8409";
827
964
  var QUOTE_REQUEST_SCHEME = "agent-commerce/request/v1";
828
965
  var QUOTE_DOMAIN = { name: "Signed Service Payment Quotes", version: "1" };
@@ -855,9 +992,9 @@ var QUOTE_INFO_SCHEMA = {
855
992
  // Every field is a string in the ERC's JSON encoding
856
993
  quote: {
857
994
  type: "object",
858
- required: QUOTE_TYPES.ServicePaymentQuote.map((field) => field.name),
995
+ required: QUOTE_TYPES.ServicePaymentQuote.map((field2) => field2.name),
859
996
  properties: Object.fromEntries(
860
- QUOTE_TYPES.ServicePaymentQuote.map((field) => [field.name, { type: "string" }])
997
+ QUOTE_TYPES.ServicePaymentQuote.map((field2) => [field2.name, { type: "string" }])
861
998
  )
862
999
  },
863
1000
  signature: { type: "string" }
@@ -1513,48 +1650,6 @@ function createReconcile(ctx) {
1513
1650
  return unknown("unsupported_family");
1514
1651
  };
1515
1652
  }
1516
- function decodePaymentSubmission(payloadBase64) {
1517
- const json = decodeJson(payloadBase64);
1518
- if (json === void 0) return void 0;
1519
- const result = PaymentPayloadV2Schema.safeParse(json);
1520
- return result.success ? result.data : void 0;
1521
- }
1522
- function declaredX402Version(payloadBase64) {
1523
- const json = decodeJson(payloadBase64);
1524
- return typeof json === "object" && json !== null ? json["x402Version"] : void 0;
1525
- }
1526
- function forFacilitator(payload) {
1527
- const { resource: _resource, extensions: _extensions, ...rest } = payload;
1528
- return rest;
1529
- }
1530
- function decodeJson(payloadBase64) {
1531
- try {
1532
- return JSON.parse(Buffer.from(payloadBase64, "base64").toString("utf8"));
1533
- } catch {
1534
- return void 0;
1535
- }
1536
- }
1537
- function isExactEvmPayload(payload) {
1538
- const inner = payload.payload;
1539
- return payload.accepted.scheme === "exact" && isRecord(inner) && isRecord(inner["authorization"]) && !("permit2Authorization" in inner) && typeof inner["signature"] === "string";
1540
- }
1541
- var UINT256 = /^(0|[1-9]\d{0,77})$/;
1542
- var UINT256_MAX = 2n ** 256n - 1n;
1543
- var BYTES32 = /^0x[0-9a-fA-F]{64}$/;
1544
- var isUint256 = (value) => typeof value === "string" && UINT256.test(value) && BigInt(value) <= UINT256_MAX;
1545
- function hasEip3009Fields(authorization) {
1546
- return isEvmAddress(authorization["from"]) && isEvmAddress(authorization["to"]) && isUint256(authorization["value"]) && isUint256(authorization["validAfter"]) && isUint256(authorization["validBefore"]) && typeof authorization["nonce"] === "string" && BYTES32.test(authorization["nonce"]);
1547
- }
1548
- function isExactPermit2Payload(payload) {
1549
- const inner = payload.payload;
1550
- if (payload.accepted.scheme !== "exact" || !isRecord(inner)) return false;
1551
- const auth = inner["permit2Authorization"];
1552
- if (!isRecord(auth) || "authorization" in inner || typeof inner["signature"] !== "string") {
1553
- return false;
1554
- }
1555
- const { permitted, witness } = auth;
1556
- return isRecord(permitted) && isRecord(witness) && isEvmAddress(auth["from"]) && isEvmAddress(auth["spender"]) && isEvmAddress(permitted["token"]) && isEvmAddress(witness["to"]) && isUint256(permitted["amount"]) && isUint256(auth["nonce"]) && isUint256(auth["deadline"]) && isUint256(witness["validAfter"]);
1557
- }
1558
1653
 
1559
1654
  // src/payments/x402/provider/requirement.ts
1560
1655
  var SELECTED_OFFER_KEY = "x402.offer";
@@ -1599,7 +1694,7 @@ function createRequirementBuilders(ctx, svmFeePayer) {
1599
1694
  }))
1600
1695
  );
1601
1696
  const single = offers.length === 1 ? offers[0] : void 0;
1602
- const extensions = await ctx.quotes?.extensionsFor(
1697
+ const quoteExtensions = await ctx.quotes?.extensionsFor(
1603
1698
  context.resource.id,
1604
1699
  context.input,
1605
1700
  offers.flatMap((offer, index) => {
@@ -1607,6 +1702,8 @@ function createRequirementBuilders(ctx, svmFeePayer) {
1607
1702
  return offer.family === "evm" && accepted ? [{ offer, amount: accepted.amount }] : [];
1608
1703
  })
1609
1704
  );
1705
+ const identifier = paymentIdentifierExtensions(context.resource);
1706
+ const extensions = identifier === void 0 ? quoteExtensions : { ...quoteExtensions, ...identifier };
1610
1707
  const resourceId = encodeURIComponent(context.resource.id);
1611
1708
  const envelope = {
1612
1709
  x402Version: X402_VERSION,
@@ -1965,6 +2062,9 @@ function createVerify(ctx, nearRelayers) {
1965
2062
  if (!acceptedMatchesOffer(requirements, payload.accepted, offer.profile) || payload.resource !== void 0 && payload.resource.url !== offeredUrl) {
1966
2063
  return refused("invalid_payment_requirements");
1967
2064
  }
2065
+ if (!paymentIdentifierEchoed(requirement.challenge.envelope, payload)) {
2066
+ return refused("extension_echo_mismatch");
2067
+ }
1968
2068
  let required;
1969
2069
  try {
1970
2070
  required = BigInt(requirements.amount);
@@ -2162,6 +2262,7 @@ function createX402PaymentProvider(options) {
2162
2262
  createRequirement,
2163
2263
  // A single offer needs no selection
2164
2264
  ...severalOffers ? { selectRequirement } : {},
2265
+ retryKey: paymentRetryKey,
2165
2266
  verify,
2166
2267
  settle,
2167
2268
  reconcile: createReconcile(ctx),
@@ -2187,5 +2288,5 @@ function loadOptionalModule(load, missing) {
2187
2288
  }
2188
2289
 
2189
2290
  export { DEFAULT_IDS, chainIdFromCaip2, createX402PaymentProvider, parseCanonicalAmount };
2190
- //# sourceMappingURL=chunk-YOF7IK4V.js.map
2191
- //# sourceMappingURL=chunk-YOF7IK4V.js.map
2291
+ //# sourceMappingURL=chunk-5K2JDM4G.js.map
2292
+ //# sourceMappingURL=chunk-5K2JDM4G.js.map