@devlab.group/agent-commerce 2.6.0 → 2.7.1

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 (129) 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-M6MQ3FYS.js → chunk-5AO5N2XY.js} +11 -5
  5. package/dist/chunk-5AO5N2XY.js.map +1 -0
  6. package/dist/{chunk-DRLBML7Z.js → chunk-5VW32JPV.js} +191 -78
  7. package/dist/chunk-5VW32JPV.js.map +1 -0
  8. package/dist/{chunk-ES3V6ECS.js → chunk-77HLISG4.js} +3 -2
  9. package/dist/chunk-77HLISG4.js.map +1 -0
  10. package/dist/{chunk-5ZYXBCDX.js → chunk-D7FPSGUQ.js} +25 -4
  11. package/dist/chunk-D7FPSGUQ.js.map +1 -0
  12. package/dist/{chunk-G3EYYHKF.js → chunk-DJRWYDKJ.js} +3 -3
  13. package/dist/{chunk-G3EYYHKF.js.map → chunk-DJRWYDKJ.js.map} +1 -1
  14. package/dist/chunk-IGXQMAKM.js +8 -0
  15. package/dist/{chunk-M6BSXXTF.js.map → chunk-IGXQMAKM.js.map} +1 -1
  16. package/dist/chunk-IWXVQYG5.js +6 -0
  17. package/dist/chunk-IWXVQYG5.js.map +1 -0
  18. package/dist/{chunk-M6WW6QIT.js → chunk-WDD2ZUR3.js} +5 -3
  19. package/dist/chunk-WDD2ZUR3.js.map +1 -0
  20. package/dist/{chunk-M52FBNJX.js → chunk-YHNTTMED.js} +6 -4
  21. package/dist/chunk-YHNTTMED.js.map +1 -0
  22. package/dist/cli/{ap2-2YMYA2H6.js → ap2-NTYL7H4I.js} +10 -11
  23. package/dist/cli/ap2-NTYL7H4I.js.map +1 -0
  24. package/dist/cli/chunk-2M2RF3CT.js +8 -0
  25. package/dist/cli/{chunk-4KLYFXMW.js.map → chunk-2M2RF3CT.js.map} +1 -1
  26. package/dist/cli/{chunk-5K4XEAZV.js → chunk-3IEXJ7I3.js} +25 -4
  27. package/dist/cli/chunk-3IEXJ7I3.js.map +1 -0
  28. package/dist/cli/{chunk-VJH6RYRK.js → chunk-3NVJAQRO.js} +3 -3
  29. package/dist/cli/{chunk-VJH6RYRK.js.map → chunk-3NVJAQRO.js.map} +1 -1
  30. package/dist/cli/{chunk-GET3CZGR.js → chunk-55AI6CLW.js} +6 -4
  31. package/dist/cli/chunk-55AI6CLW.js.map +1 -0
  32. package/dist/cli/{chunk-3NOMLMJW.js → chunk-66NTYSXI.js} +3 -3
  33. package/dist/cli/{chunk-3NOMLMJW.js.map → chunk-66NTYSXI.js.map} +1 -1
  34. package/dist/cli/{chunk-VJ4EO4LE.js → chunk-6EBDOH37.js} +3 -3
  35. package/dist/cli/{chunk-VJ4EO4LE.js.map → chunk-6EBDOH37.js.map} +1 -1
  36. package/dist/cli/{chunk-NSYSMDQN.js → chunk-A42BCWZ2.js} +57 -29
  37. package/dist/cli/chunk-A42BCWZ2.js.map +1 -0
  38. package/dist/cli/chunk-APC5BTQM.js +6 -0
  39. package/dist/cli/chunk-APC5BTQM.js.map +1 -0
  40. package/dist/cli/{chunk-SYQLJXIU.js → chunk-C5YISPT6.js} +3 -3
  41. package/dist/cli/chunk-C5YISPT6.js.map +1 -0
  42. package/dist/cli/chunk-DKWO6LLX.js +34 -0
  43. package/dist/cli/chunk-DKWO6LLX.js.map +1 -0
  44. package/dist/cli/{chunk-YOF7IK4V.js → chunk-EVCIEKHN.js} +193 -80
  45. package/dist/cli/chunk-EVCIEKHN.js.map +1 -0
  46. package/dist/cli/{chunk-YWG2ZN3L.js → chunk-FETTSOMT.js} +12 -6
  47. package/dist/cli/chunk-FETTSOMT.js.map +1 -0
  48. package/dist/cli/{chunk-SPAYKVUP.js → chunk-FL4HPCD4.js} +3 -2
  49. package/dist/cli/chunk-FL4HPCD4.js.map +1 -0
  50. package/dist/cli/{chunk-AZL7RPFU.js → chunk-GBBG66O6.js} +77 -16
  51. package/dist/cli/chunk-GBBG66O6.js.map +1 -0
  52. package/dist/cli/{chunk-3EQBCFZY.js → chunk-H7EBJ4I3.js} +3 -3
  53. package/dist/cli/{chunk-3EQBCFZY.js.map → chunk-H7EBJ4I3.js.map} +1 -1
  54. package/dist/cli/{chunk-DHFMIBPG.js → chunk-MBPOKPQM.js} +6 -6
  55. package/dist/cli/{chunk-DHFMIBPG.js.map → chunk-MBPOKPQM.js.map} +1 -1
  56. package/dist/cli/{chunk-PTL7SNOI.js → chunk-OETKXDGA.js} +467 -122
  57. package/dist/cli/chunk-OETKXDGA.js.map +1 -0
  58. package/dist/cli/{chunk-TFV3K6YS.js → chunk-VSSSU4AU.js} +3 -3
  59. package/dist/cli/{chunk-TFV3K6YS.js.map → chunk-VSSSU4AU.js.map} +1 -1
  60. package/dist/cli/config-ODN4IEMZ.js +13 -0
  61. package/dist/cli/{config-3K65QJ22.js.map → config-ODN4IEMZ.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-V27OKTOV.js} +7 -7
  65. package/dist/cli/{mcp-6F64A7KE.js.map → mcp-V27OKTOV.js.map} +1 -1
  66. package/dist/cli/payment-providers-SUATT75K.js +6 -0
  67. package/dist/cli/{payment-providers-2ITS6KNR.js.map → payment-providers-SUATT75K.js.map} +1 -1
  68. package/dist/cli/{provider-5BGG5YKQ.js → provider-C3QDAXMR.js} +9 -9
  69. package/dist/cli/{provider-5BGG5YKQ.js.map → provider-C3QDAXMR.js.map} +1 -1
  70. package/dist/cli/receipts-ZS3VZ2D4.js +9 -0
  71. package/dist/cli/{receipts-I4IIE7U6.js.map → receipts-ZS3VZ2D4.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-WYFZUO5D.js} +142 -46
  75. package/dist/cli/run-WYFZUO5D.js.map +1 -0
  76. package/dist/cli/{svm-KDSPDFJG.js → svm-NBZY7H6W.js} +9 -6
  77. package/dist/cli/svm-NBZY7H6W.js.map +1 -0
  78. package/dist/cli/{x402-4LPIIELI.js → x402-UGLZ3LA7.js} +11 -10
  79. package/dist/cli/x402-UGLZ3LA7.js.map +1 -0
  80. package/dist/{guardrails-CX_jYXvZ.d.ts → guardrails-CeyLS1ou.d.ts} +2 -2
  81. package/dist/index.d.ts +23 -13
  82. package/dist/index.js +708 -181
  83. package/dist/index.js.map +1 -1
  84. package/dist/mcp.d.ts +2 -2
  85. package/dist/mcp.js +4 -4
  86. package/dist/mpp.js +5 -5
  87. package/dist/{protocol-adapter-1WbtM3xG.d.ts → protocol-adapter-DdFL5LBU.d.ts} +12 -2
  88. package/dist/{runtime-B-kARa2f.d.ts → runtime-BmaSp2Ce.d.ts} +31 -3
  89. package/dist/{store-kIIMpUA-.d.ts → store-DQwbKhnc.d.ts} +25 -8
  90. package/dist/{svm-KNC3PHMS.js → svm-4HR5OEP7.js} +9 -6
  91. package/dist/svm-4HR5OEP7.js.map +1 -0
  92. package/dist/testing.d.ts +1 -1
  93. package/dist/testing.js +156 -2
  94. package/dist/testing.js.map +1 -1
  95. package/dist/{transaction-Dv0UFGg5.d.ts → transaction-BXXJltZ-.d.ts} +1 -1
  96. package/dist/x402.d.ts +7 -2
  97. package/dist/x402.js +7 -6
  98. package/dist/x402.js.map +1 -1
  99. package/package.json +13 -29
  100. package/dist/chunk-5ZYXBCDX.js.map +0 -1
  101. package/dist/chunk-DRLBML7Z.js.map +0 -1
  102. package/dist/chunk-ES3V6ECS.js.map +0 -1
  103. package/dist/chunk-M52FBNJX.js.map +0 -1
  104. package/dist/chunk-M6BSXXTF.js +0 -8
  105. package/dist/chunk-M6MQ3FYS.js.map +0 -1
  106. package/dist/chunk-M6WW6QIT.js.map +0 -1
  107. package/dist/cli/ap2-2YMYA2H6.js.map +0 -1
  108. package/dist/cli/chunk-4KLYFXMW.js +0 -8
  109. package/dist/cli/chunk-5K4XEAZV.js.map +0 -1
  110. package/dist/cli/chunk-6R6WJ4FD.js +0 -18
  111. package/dist/cli/chunk-6R6WJ4FD.js.map +0 -1
  112. package/dist/cli/chunk-AZL7RPFU.js.map +0 -1
  113. package/dist/cli/chunk-FHCFR2GS.js +0 -17
  114. package/dist/cli/chunk-FHCFR2GS.js.map +0 -1
  115. package/dist/cli/chunk-GET3CZGR.js.map +0 -1
  116. package/dist/cli/chunk-NSYSMDQN.js.map +0 -1
  117. package/dist/cli/chunk-PTL7SNOI.js.map +0 -1
  118. package/dist/cli/chunk-SPAYKVUP.js.map +0 -1
  119. package/dist/cli/chunk-SYQLJXIU.js.map +0 -1
  120. package/dist/cli/chunk-YOF7IK4V.js.map +0 -1
  121. package/dist/cli/chunk-YWG2ZN3L.js.map +0 -1
  122. package/dist/cli/config-3K65QJ22.js +0 -12
  123. package/dist/cli/payment-providers-2ITS6KNR.js +0 -6
  124. package/dist/cli/receipts-I4IIE7U6.js +0 -8
  125. package/dist/cli/reconcile-55WNCSFC.js +0 -4
  126. package/dist/cli/run-2P6ZGFUE.js.map +0 -1
  127. package/dist/cli/svm-KDSPDFJG.js.map +0 -1
  128. package/dist/cli/x402-4LPIIELI.js.map +0 -1
  129. package/dist/svm-KNC3PHMS.js.map +0 -1
@@ -1,6 +1,6 @@
1
- import { isWellKnownDevKey, findX402Network, normalizeAddress, assertPayToIsNotDevAddress, resolveX402Deployment, assertDevKeyIsLocalOnly, describeRpc, canonicalJson, X402_DEFAULT_PAYMENT_FLOW, REUSE_REJECTED_AUTHORIZATION_METADATA_KEY, SETTLE_AFTER_BACKEND_METADATA_KEY, sameAddress, LOCAL_CHAIN_ID, isTransactionReference, x402OfferName, isEvmAddress, describeDeploymentMode } from './chunk-M6MQ3FYS.js';
2
- import { PACKAGE_VERSION } from './chunk-M6BSXXTF.js';
3
- import { CommerceError, systemClock, NOOP_LOGGER, redactedErrorText, RECONCILIATION_METADATA_KEY, isCommerceError } from './chunk-M52FBNJX.js';
1
+ import { isWellKnownDevKey, findX402Network, normalizeAddress, assertPayToIsNotDevAddress, resolveX402Deployment, assertDevKeyIsLocalOnly, describeRpc, canonicalJson, X402_DEFAULT_PAYMENT_FLOW, REUSE_REJECTED_AUTHORIZATION_METADATA_KEY, SETTLE_AFTER_BACKEND_METADATA_KEY, sameAddress, LOCAL_CHAIN_ID, isTransactionReference, x402OfferName, CDP_FACILITATOR_URL, isEvmAddress, describeDeploymentMode } from './chunk-5AO5N2XY.js';
2
+ import { PACKAGE_VERSION } from './chunk-IGXQMAKM.js';
3
+ import { CommerceError, systemClock, NOOP_LOGGER, redactedErrorText, RECONCILIATION_METADATA_KEY, isCommerceError } from './chunk-YHNTTMED.js';
4
4
  import { LOCATOR_VERSION, eip3009Locator, computeReplayKey, permit2Locator, computePermit2ReplayKey, isoFromSeconds } from './chunk-GA3O2A7R.js';
5
5
  import { isRecord } from './chunk-2CJNA7MS.js';
6
6
  import { x402ExactPermit2ProxyAddress, toFacilitatorEvmSigner, PERMIT2_ADDRESS, eip3009ABI, x402ExactPermit2ProxyABI } from '@x402/evm';
@@ -8,9 +8,9 @@ import { parseAbi, isAddress, keccak256, stringToBytes, isHash, getAddress, form
8
8
  import { privateKeyToAccount } from 'viem/accounts';
9
9
  import { HTTPFacilitatorClient } from '@x402/core/http';
10
10
  import { SettleError, VerifyError } from '@x402/core/types';
11
+ import { randomBytes, createPrivateKey, sign } from 'crypto';
11
12
  import { x402Facilitator } from '@x402/core/facilitator';
12
13
  import { registerExactEvmScheme } from '@x402/evm/exact/facilitator';
13
- import { randomBytes } from 'crypto';
14
14
  import { PaymentPayloadV2Schema } from '@x402/core/schemas';
15
15
 
16
16
  // src/payments/x402/provider/constants.ts
@@ -426,32 +426,83 @@ function createLocalFacilitatorClient(rpcUrl, signerPrivateKey, chainId) {
426
426
  transport: http(rpcUrl)
427
427
  }).extend(publicActions);
428
428
  }
429
- var SETTLEMENT_CONFIRMATION_TIMEOUT_MS = 6e4;
430
- var SUPPORTED_TIMEOUT_MS = 1e4;
431
- function cdpAuthHeaders(apiKeyId, apiKeySecret) {
432
- const loading = import('@coinbase/x402').then(
433
- (mod) => mod.createCdpAuthHeaders(apiKeyId, apiKeySecret),
434
- (cause) => {
435
- throw new CommerceError(
436
- "CONFIG_INVALID",
437
- '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".',
438
- { cause }
439
- );
440
- }
441
- );
442
- loading.catch(() => {
443
- });
429
+ var TOKEN_LIFETIME_SECONDS = 120;
430
+ function createCdpAuthHeaders(apiKeyId, apiKeySecret, now = Date.now) {
431
+ const signingKey = readKey(apiKeySecret);
432
+ if (!signingKey) {
433
+ throw new CommerceError(
434
+ "CONFIG_INVALID",
435
+ "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."
436
+ );
437
+ }
438
+ const { host, pathname } = new URL(CDP_FACILITATOR_URL);
444
439
  return async () => {
445
- const create = await loading;
446
- if (!create) {
447
- throw new CommerceError(
448
- "PAYMENT_PROVIDER_UNAVAILABLE",
449
- "x402 provider: @coinbase/x402 returned no auth-header factory"
450
- );
451
- }
452
- return await create();
440
+ const issuedAt = Math.floor(now() / 1e3);
441
+ const header = (method, route) => {
442
+ let value;
443
+ return () => value ??= {
444
+ Authorization: `Bearer ${signJwt(signingKey, apiKeyId, `${method} ${host}${pathname}/${route}`, issuedAt)}`
445
+ };
446
+ };
447
+ const verify = header("POST", "verify");
448
+ const settle = header("POST", "settle");
449
+ const supported = header("GET", "supported");
450
+ return {
451
+ get verify() {
452
+ return verify();
453
+ },
454
+ get settle() {
455
+ return settle();
456
+ },
457
+ get supported() {
458
+ return supported();
459
+ }
460
+ };
453
461
  };
454
462
  }
463
+ function readKey(secret) {
464
+ try {
465
+ if (secret.includes("-----BEGIN")) {
466
+ const key2 = createPrivateKey(secret.replace(/\\n/g, "\n"));
467
+ const p256 = key2.asymmetricKeyType === "ec" && key2.asymmetricKeyDetails?.namedCurve === "prime256v1";
468
+ return p256 ? { alg: "ES256", key: key2 } : void 0;
469
+ }
470
+ const raw = Buffer.from(secret, "base64");
471
+ if (raw.length !== 64) return void 0;
472
+ const key = createPrivateKey({
473
+ format: "jwk",
474
+ key: {
475
+ kty: "OKP",
476
+ crv: "Ed25519",
477
+ d: raw.subarray(0, 32).toString("base64url"),
478
+ x: raw.subarray(32).toString("base64url")
479
+ }
480
+ });
481
+ return { alg: "EdDSA", key };
482
+ } catch {
483
+ return void 0;
484
+ }
485
+ }
486
+ function signJwt(signingKey, apiKeyId, uri, issuedAt) {
487
+ const { alg, key } = signingKey;
488
+ const header = { alg, kid: apiKeyId, typ: "JWT", nonce: randomBytes(16).toString("hex") };
489
+ const claims = {
490
+ sub: apiKeyId,
491
+ iss: "cdp",
492
+ uris: [uri],
493
+ iat: issuedAt,
494
+ nbf: issuedAt,
495
+ exp: issuedAt + TOKEN_LIFETIME_SECONDS
496
+ };
497
+ const input = `${base64url(header)}.${base64url(claims)}`;
498
+ const signature = alg === "ES256" ? sign("sha256", Buffer.from(input), { key, dsaEncoding: "ieee-p1363" }) : sign(null, Buffer.from(input), key);
499
+ return `${input}.${signature.toString("base64url")}`;
500
+ }
501
+ var base64url = (value) => Buffer.from(JSON.stringify(value)).toString("base64url");
502
+
503
+ // src/payments/x402/facilitator.ts
504
+ var SETTLEMENT_CONFIRMATION_TIMEOUT_MS = 6e4;
505
+ var SUPPORTED_TIMEOUT_MS = 1e4;
455
506
  function verdictFromVerifyError(err) {
456
507
  if (err instanceof VerifyError && err.statusCode === 400 && typeof err.invalidReason === "string") {
457
508
  return {
@@ -483,7 +534,7 @@ function createRemoteFacilitatorBinding(options) {
483
534
  return { verify: headers, settle: headers, supported: headers };
484
535
  };
485
536
  } else if (auth.type === "cdp") {
486
- createAuthHeaders = cdpAuthHeaders(auth.apiKeyId, auth.apiKeySecret);
537
+ createAuthHeaders = createCdpAuthHeaders(auth.apiKeyId, auth.apiKeySecret);
487
538
  }
488
539
  const client = new HTTPFacilitatorClient({
489
540
  url: options.url,
@@ -634,10 +685,10 @@ function resolveOffers(inputs, options) {
634
685
  let remoteBinding;
635
686
  let mode;
636
687
  const built = /* @__PURE__ */ new Map();
637
- const resolveList = (list, field) => {
688
+ const resolveList = (list, field2) => {
638
689
  const seen = /* @__PURE__ */ new Set();
639
690
  return list.map((input, index) => {
640
- const at = (name) => field(index, name);
691
+ const at = (name) => field2(index, name);
641
692
  const known = findX402Network(input.network, options.customNetworks);
642
693
  if (known !== void 0 && known.family !== "evm") {
643
694
  const shape = known.family === "svm" ? "a Solana address (base58, 32 bytes)" : "a NEAR account ID";
@@ -793,6 +844,104 @@ function offerCurrency(offer, quoted) {
793
844
  const canonical = offer.profile.canonicalAsset;
794
845
  return canonical !== void 0 && sameAddress(offer.profile, offer.asset, canonical.address) ? canonical.symbol : quoted;
795
846
  }
847
+ function decodePaymentSubmission(payloadBase64) {
848
+ const json = decodeJson(payloadBase64);
849
+ if (json === void 0) return void 0;
850
+ const result = PaymentPayloadV2Schema.safeParse(json);
851
+ return result.success ? result.data : void 0;
852
+ }
853
+ function declaredX402Version(payloadBase64) {
854
+ const json = decodeJson(payloadBase64);
855
+ return typeof json === "object" && json !== null ? json["x402Version"] : void 0;
856
+ }
857
+ function forFacilitator(payload) {
858
+ const { resource: _resource, extensions: _extensions, ...rest } = payload;
859
+ return rest;
860
+ }
861
+ function decodeJson(payloadBase64) {
862
+ try {
863
+ return JSON.parse(Buffer.from(payloadBase64, "base64").toString("utf8"));
864
+ } catch {
865
+ return void 0;
866
+ }
867
+ }
868
+ function isExactEvmPayload(payload) {
869
+ const inner = payload.payload;
870
+ return payload.accepted.scheme === "exact" && isRecord(inner) && isRecord(inner["authorization"]) && !("permit2Authorization" in inner) && typeof inner["signature"] === "string";
871
+ }
872
+ var UINT256 = /^(0|[1-9]\d{0,77})$/;
873
+ var UINT256_MAX = 2n ** 256n - 1n;
874
+ var BYTES32 = /^0x[0-9a-fA-F]{64}$/;
875
+ var isUint256 = (value) => typeof value === "string" && UINT256.test(value) && BigInt(value) <= UINT256_MAX;
876
+ function hasEip3009Fields(authorization) {
877
+ return isEvmAddress(authorization["from"]) && isEvmAddress(authorization["to"]) && isUint256(authorization["value"]) && isUint256(authorization["validAfter"]) && isUint256(authorization["validBefore"]) && typeof authorization["nonce"] === "string" && BYTES32.test(authorization["nonce"]);
878
+ }
879
+ function isExactPermit2Payload(payload) {
880
+ const inner = payload.payload;
881
+ if (payload.accepted.scheme !== "exact" || !isRecord(inner)) return false;
882
+ const auth = inner["permit2Authorization"];
883
+ if (!isRecord(auth) || "authorization" in inner || typeof inner["signature"] !== "string") {
884
+ return false;
885
+ }
886
+ const { permitted, witness } = auth;
887
+ 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"]);
888
+ }
889
+
890
+ // src/payments/x402/provider/payment-id.ts
891
+ var PAYMENT_IDENTIFIER = "payment-identifier";
892
+ var ID_PATTERN = /^[A-Za-z0-9_-]{16,128}$/;
893
+ var field = (value, key) => isRecord(value) ? value[key] : void 0;
894
+ function paymentIdentifierExtensions(resource) {
895
+ const redelivery = resource.idempotency?.redelivery;
896
+ if (redelivery === void 0) return void 0;
897
+ return {
898
+ [PAYMENT_IDENTIFIER]: {
899
+ info: { required: redelivery.required },
900
+ schema: {
901
+ $schema: "https://json-schema.org/draft/2020-12/schema",
902
+ type: "object",
903
+ properties: {
904
+ required: { type: "boolean" },
905
+ id: { type: "string", minLength: 16, maxLength: 128, pattern: "^[a-zA-Z0-9_-]+$" }
906
+ },
907
+ required: ["required"]
908
+ }
909
+ }
910
+ };
911
+ }
912
+ function paymentRetryKey(context) {
913
+ const { resource, submission } = context;
914
+ const redelivery = resource.idempotency?.redelivery;
915
+ if (redelivery === void 0) return void 0;
916
+ const payload = decodePaymentSubmission(submission.payload);
917
+ if (payload === void 0) return void 0;
918
+ const extension = payload.extensions?.[PAYMENT_IDENTIFIER];
919
+ const info = field(extension, "info");
920
+ if (extension !== void 0 && !isRecord(info)) throw invalid(resource);
921
+ const id = field(info, "id");
922
+ if (id === void 0) {
923
+ if (!redelivery.required) return void 0;
924
+ throw new CommerceError("INPUT_INVALID", "This resource requires a payment identifier", {
925
+ resourceId: resource.id,
926
+ details: { reason: "payment_identifier_required" }
927
+ });
928
+ }
929
+ if (typeof id !== "string" || !ID_PATTERN.test(id)) throw invalid(resource);
930
+ return id;
931
+ }
932
+ function paymentIdentifierEchoed(envelope, payload) {
933
+ const declared = field(field(field(envelope, "extensions"), PAYMENT_IDENTIFIER), "info");
934
+ const echoed = payload.extensions?.[PAYMENT_IDENTIFIER];
935
+ if (!isRecord(declared) || echoed === void 0) return true;
936
+ return field(field(echoed, "info"), "required") === declared["required"];
937
+ }
938
+ function invalid(resource) {
939
+ return new CommerceError(
940
+ "INPUT_INVALID",
941
+ 'A payment identifier must be 16 to 128 characters of A-Z, a-z, 0-9, "_" and "-"',
942
+ { resourceId: resource.id, details: { reason: "payment_identifier_invalid" } }
943
+ );
944
+ }
796
945
  var QUOTE_EXTENSION = "erc-8409";
797
946
  var QUOTE_REQUEST_SCHEME = "agent-commerce/request/v1";
798
947
  var QUOTE_DOMAIN = { name: "Signed Service Payment Quotes", version: "1" };
@@ -825,9 +974,9 @@ var QUOTE_INFO_SCHEMA = {
825
974
  // Every field is a string in the ERC's JSON encoding
826
975
  quote: {
827
976
  type: "object",
828
- required: QUOTE_TYPES.ServicePaymentQuote.map((field) => field.name),
977
+ required: QUOTE_TYPES.ServicePaymentQuote.map((field2) => field2.name),
829
978
  properties: Object.fromEntries(
830
- QUOTE_TYPES.ServicePaymentQuote.map((field) => [field.name, { type: "string" }])
979
+ QUOTE_TYPES.ServicePaymentQuote.map((field2) => [field2.name, { type: "string" }])
831
980
  )
832
981
  },
833
982
  signature: { type: "string" }
@@ -1511,48 +1660,6 @@ function parseCanonicalAmount(amount, decimals) {
1511
1660
  const combined = `${integerPart}${paddedFraction}`;
1512
1661
  return BigInt(combined);
1513
1662
  }
1514
- function decodePaymentSubmission(payloadBase64) {
1515
- const json = decodeJson(payloadBase64);
1516
- if (json === void 0) return void 0;
1517
- const result = PaymentPayloadV2Schema.safeParse(json);
1518
- return result.success ? result.data : void 0;
1519
- }
1520
- function declaredX402Version(payloadBase64) {
1521
- const json = decodeJson(payloadBase64);
1522
- return typeof json === "object" && json !== null ? json["x402Version"] : void 0;
1523
- }
1524
- function forFacilitator(payload) {
1525
- const { resource: _resource, extensions: _extensions, ...rest } = payload;
1526
- return rest;
1527
- }
1528
- function decodeJson(payloadBase64) {
1529
- try {
1530
- return JSON.parse(Buffer.from(payloadBase64, "base64").toString("utf8"));
1531
- } catch {
1532
- return void 0;
1533
- }
1534
- }
1535
- function isExactEvmPayload(payload) {
1536
- const inner = payload.payload;
1537
- return payload.accepted.scheme === "exact" && isRecord(inner) && isRecord(inner["authorization"]) && !("permit2Authorization" in inner) && typeof inner["signature"] === "string";
1538
- }
1539
- var UINT256 = /^(0|[1-9]\d{0,77})$/;
1540
- var UINT256_MAX = 2n ** 256n - 1n;
1541
- var BYTES32 = /^0x[0-9a-fA-F]{64}$/;
1542
- var isUint256 = (value) => typeof value === "string" && UINT256.test(value) && BigInt(value) <= UINT256_MAX;
1543
- function hasEip3009Fields(authorization) {
1544
- return isEvmAddress(authorization["from"]) && isEvmAddress(authorization["to"]) && isUint256(authorization["value"]) && isUint256(authorization["validAfter"]) && isUint256(authorization["validBefore"]) && typeof authorization["nonce"] === "string" && BYTES32.test(authorization["nonce"]);
1545
- }
1546
- function isExactPermit2Payload(payload) {
1547
- const inner = payload.payload;
1548
- if (payload.accepted.scheme !== "exact" || !isRecord(inner)) return false;
1549
- const auth = inner["permit2Authorization"];
1550
- if (!isRecord(auth) || "authorization" in inner || typeof inner["signature"] !== "string") {
1551
- return false;
1552
- }
1553
- const { permitted, witness } = auth;
1554
- 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"]);
1555
- }
1556
1663
 
1557
1664
  // src/payments/x402/provider/requirement.ts
1558
1665
  var SELECTED_OFFER_KEY = "x402.offer";
@@ -1597,7 +1704,7 @@ function createRequirementBuilders(ctx, svmFeePayer) {
1597
1704
  }))
1598
1705
  );
1599
1706
  const single = offers.length === 1 ? offers[0] : void 0;
1600
- const extensions = await ctx.quotes?.extensionsFor(
1707
+ const quoteExtensions = await ctx.quotes?.extensionsFor(
1601
1708
  context.resource.id,
1602
1709
  context.input,
1603
1710
  offers.flatMap((offer, index) => {
@@ -1605,6 +1712,8 @@ function createRequirementBuilders(ctx, svmFeePayer) {
1605
1712
  return offer.family === "evm" && accepted ? [{ offer, amount: accepted.amount }] : [];
1606
1713
  })
1607
1714
  );
1715
+ const identifier = paymentIdentifierExtensions(context.resource);
1716
+ const extensions = identifier === void 0 ? quoteExtensions : { ...quoteExtensions, ...identifier };
1608
1717
  const resourceId = encodeURIComponent(context.resource.id);
1609
1718
  const envelope = {
1610
1719
  x402Version: X402_VERSION,
@@ -1963,6 +2072,9 @@ function createVerify(ctx, nearRelayers) {
1963
2072
  if (!acceptedMatchesOffer(requirements, payload.accepted, offer.profile) || payload.resource !== void 0 && payload.resource.url !== offeredUrl) {
1964
2073
  return refused("invalid_payment_requirements");
1965
2074
  }
2075
+ if (!paymentIdentifierEchoed(requirement.challenge.envelope, payload)) {
2076
+ return refused("extension_echo_mismatch");
2077
+ }
1966
2078
  let required;
1967
2079
  try {
1968
2080
  required = BigInt(requirements.amount);
@@ -2120,7 +2232,7 @@ function createX402PaymentProvider(options) {
2120
2232
  "auth-capture scheme"
2121
2233
  ]
2122
2234
  };
2123
- const svmModule = hasSvm ? loadOptionalModule(() => import('./svm-KNC3PHMS.js'), "Solana offers need @x402/svm and @solana/kit") : void 0;
2235
+ const svmModule = hasSvm ? loadOptionalModule(() => import('./svm-4HR5OEP7.js'), "Solana offers need @x402/svm and @solana/kit") : void 0;
2124
2236
  const nearModule = hasNear ? loadOptionalModule(() => import('./near-FH7HPZV3.js'), "NEAR offers need @x402/near") : void 0;
2125
2237
  const svm = async () => {
2126
2238
  if (!svmModule)
@@ -2160,6 +2272,7 @@ function createX402PaymentProvider(options) {
2160
2272
  createRequirement,
2161
2273
  // A single offer needs no selection
2162
2274
  ...severalOffers ? { selectRequirement } : {},
2275
+ retryKey: paymentRetryKey,
2163
2276
  verify,
2164
2277
  settle,
2165
2278
  reconcile: createReconcile(ctx),
@@ -2185,5 +2298,5 @@ function loadOptionalModule(load, missing) {
2185
2298
  }
2186
2299
 
2187
2300
  export { DEFAULT_IDS, chainIdFromCaip2, createX402PaymentProvider, parseCanonicalAmount };
2188
- //# sourceMappingURL=chunk-DRLBML7Z.js.map
2189
- //# sourceMappingURL=chunk-DRLBML7Z.js.map
2301
+ //# sourceMappingURL=chunk-5VW32JPV.js.map
2302
+ //# sourceMappingURL=chunk-5VW32JPV.js.map