@devlab.group/agent-commerce 2.8.0 → 2.9.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 (69) hide show
  1. package/README.md +28 -21
  2. package/dist/ap2.js +2 -2
  3. package/dist/{chunk-WDD2ZUR3.js → chunk-46Y5M7BA.js} +3 -2
  4. package/dist/chunk-46Y5M7BA.js.map +1 -0
  5. package/dist/{chunk-ENK63GKR.js → chunk-J3K7E4CA.js} +3 -3
  6. package/dist/{chunk-ENK63GKR.js.map → chunk-J3K7E4CA.js.map} +1 -1
  7. package/dist/{cli/chunk-APC5BTQM.js → chunk-RF3DFVXH.js} +2 -2
  8. package/dist/{chunk-IWXVQYG5.js.map → chunk-RF3DFVXH.js.map} +1 -1
  9. package/dist/{chunk-QZW5YL3G.js → chunk-TEI6GTUG.js} +7 -3
  10. package/dist/chunk-TEI6GTUG.js.map +1 -0
  11. package/dist/cli/{ap2-GYKFGE66.js → ap2-MUNB4HHC.js} +5 -5
  12. package/dist/cli/{ap2-GYKFGE66.js.map → ap2-MUNB4HHC.js.map} +1 -1
  13. package/dist/cli/{chunk-DKWO6LLX.js → chunk-4WPHZLVO.js} +3 -2
  14. package/dist/cli/chunk-4WPHZLVO.js.map +1 -0
  15. package/dist/cli/chunk-JP5NQ5II.js +8 -0
  16. package/dist/cli/{chunk-SAAT2XFX.js.map → chunk-JP5NQ5II.js.map} +1 -1
  17. package/dist/cli/chunk-KLKNFJTT.js +540 -0
  18. package/dist/cli/chunk-KLKNFJTT.js.map +1 -0
  19. package/dist/cli/{chunk-WFIR374D.js → chunk-L264N3ZV.js} +41 -5
  20. package/dist/cli/chunk-L264N3ZV.js.map +1 -0
  21. package/dist/cli/{chunk-VWQMSWDF.js → chunk-RAWPZIG6.js} +7 -3
  22. package/dist/cli/chunk-RAWPZIG6.js.map +1 -0
  23. package/dist/cli/{chunk-SYXLQ5BS.js → chunk-SEDRU2KV.js} +5 -5
  24. package/dist/cli/{chunk-SYXLQ5BS.js.map → chunk-SEDRU2KV.js.map} +1 -1
  25. package/dist/cli/{chunk-3PGFOEVJ.js → chunk-SHIA2B6G.js} +32 -6
  26. package/dist/cli/chunk-SHIA2B6G.js.map +1 -0
  27. package/dist/{chunk-IWXVQYG5.js → cli/chunk-UV23DWUY.js} +2 -2
  28. package/dist/cli/{chunk-APC5BTQM.js.map → chunk-UV23DWUY.js.map} +1 -1
  29. package/dist/cli/{chunk-YXXPZFWC.js → chunk-UX7GRVL4.js} +126 -18
  30. package/dist/cli/chunk-UX7GRVL4.js.map +1 -0
  31. package/dist/cli/{config-JWMHWVRT.js → config-IBG46HTQ.js} +6 -6
  32. package/dist/cli/{config-JWMHWVRT.js.map → config-IBG46HTQ.js.map} +1 -1
  33. package/dist/cli/index.js +34 -14
  34. package/dist/cli/index.js.map +1 -1
  35. package/dist/cli/{mcp-OW5GY7TT.js → mcp-55FLXKCC.js} +3 -3
  36. package/dist/cli/{mcp-OW5GY7TT.js.map → mcp-55FLXKCC.js.map} +1 -1
  37. package/dist/cli/payment-providers-4OC2TONC.js +6 -0
  38. package/dist/cli/{payment-providers-QL2BJYMD.js.map → payment-providers-4OC2TONC.js.map} +1 -1
  39. package/dist/cli/{provider-3A2LVEQS.js → provider-H57SJDEJ.js} +4 -4
  40. package/dist/cli/{provider-3A2LVEQS.js.map → provider-H57SJDEJ.js.map} +1 -1
  41. package/dist/cli/receipts-SMX4MFO5.js +9 -0
  42. package/dist/cli/{receipts-FQUFGEQD.js.map → receipts-SMX4MFO5.js.map} +1 -1
  43. package/dist/cli/{run-KF5OQYPL.js → run-BS7323JH.js} +830 -184
  44. package/dist/cli/run-BS7323JH.js.map +1 -0
  45. package/dist/cli/{x402-5A7CVCIJ.js → x402-RNV3VHJT.js} +5 -5
  46. package/dist/cli/{x402-5A7CVCIJ.js.map → x402-RNV3VHJT.js.map} +1 -1
  47. package/dist/index.d.ts +74 -31
  48. package/dist/index.js +1410 -270
  49. package/dist/index.js.map +1 -1
  50. package/dist/mcp.js +1 -1
  51. package/dist/mpp.js +2 -2
  52. package/dist/{store-BzgwHOPu.d.ts → store-04pazhFP.d.ts} +52 -1
  53. package/dist/testing.js +468 -273
  54. package/dist/testing.js.map +1 -1
  55. package/dist/x402.js +3 -3
  56. package/package.json +1 -1
  57. package/dist/chunk-QZW5YL3G.js.map +0 -1
  58. package/dist/chunk-WDD2ZUR3.js.map +0 -1
  59. package/dist/cli/chunk-3PGFOEVJ.js.map +0 -1
  60. package/dist/cli/chunk-6BWEHQPJ.js +0 -215
  61. package/dist/cli/chunk-6BWEHQPJ.js.map +0 -1
  62. package/dist/cli/chunk-DKWO6LLX.js.map +0 -1
  63. package/dist/cli/chunk-SAAT2XFX.js +0 -8
  64. package/dist/cli/chunk-VWQMSWDF.js.map +0 -1
  65. package/dist/cli/chunk-WFIR374D.js.map +0 -1
  66. package/dist/cli/chunk-YXXPZFWC.js.map +0 -1
  67. package/dist/cli/payment-providers-QL2BJYMD.js +0 -6
  68. package/dist/cli/receipts-FQUFGEQD.js +0 -9
  69. package/dist/cli/run-KF5OQYPL.js.map +0 -1
@@ -1,12 +1,12 @@
1
- import { chainIdFromCaip2 } from './chunk-VWQMSWDF.js';
2
- export { createX402PaymentProvider } from './chunk-VWQMSWDF.js';
1
+ import { chainIdFromCaip2 } from './chunk-RAWPZIG6.js';
2
+ export { createX402PaymentProvider } from './chunk-RAWPZIG6.js';
3
3
  import './chunk-MASLG557.js';
4
4
  import './chunk-RQ7W3NA5.js';
5
5
  import './chunk-GISJ73ML.js';
6
6
  import './chunk-5CH5VFC6.js';
7
7
  import './chunk-4YZULHX2.js';
8
8
  export { SUPPORTED_NETWORK_IDS } from './chunk-2PO65227.js';
9
- import './chunk-SAAT2XFX.js';
9
+ import './chunk-JP5NQ5II.js';
10
10
  import './chunk-USIXWAXZ.js';
11
11
  import { CommerceError } from './chunk-C5YISPT6.js';
12
12
  import './chunk-663ALDZA.js';
@@ -98,5 +98,5 @@ function randomNonce() {
98
98
  }
99
99
 
100
100
  export { createPaymentProof };
101
- //# sourceMappingURL=x402-5A7CVCIJ.js.map
102
- //# sourceMappingURL=x402-5A7CVCIJ.js.map
101
+ //# sourceMappingURL=x402-RNV3VHJT.js.map
102
+ //# sourceMappingURL=x402-RNV3VHJT.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/payments/x402/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAuCA,IAAM,YAAA,GAAe,CAAA;AAErB,IAAM,iCAAA,GAAoC;AAAA,EACxC,yBAAA,EAA2B;AAAA,IACzB,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAU;AAAA,IAChC,EAAE,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,SAAA,EAAU;AAAA,IAC9B,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA,EAAU;AAAA,IACjC,EAAE,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,SAAA,EAAU;AAAA,IACtC,EAAE,IAAA,EAAM,aAAA,EAAe,IAAA,EAAM,SAAA,EAAU;AAAA,IACvC,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA;AAAU;AAErC,CAAA;AAGA,eAAsB,mBAAmB,OAAA,EAAqD;AAC5F,EAAA,MAAM,YAAA,GAAe,2BAAA,CAA4B,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA;AACtE,EAAA,MAAM,MAAA,GAAS,YAAA,CAAa,KAAA,GAAQ,qBAAqB,CAAA;AACzD,EAAA,IAAI,MAAA,KAAW,MAAA,IAAa,MAAA,KAAW,SAAA,EAAW;AAChD,IAAA,MAAM,IAAI,aAAA;AAAA,MACR,eAAA;AAAA,MACA,CAAA,8DAAA,EAAiE,MAAA,CAAO,MAAM,CAAC,CAAA,oCAAA;AAAA,KACjF;AAAA,EACF;AACA,EAAA,IACE,CAAC,YAAA,CAAa,KAAA,IACd,OAAO,aAAa,KAAA,CAAM,MAAM,CAAA,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AW,YAAA,CAAa,KAAsB;AAAA,KACnE;AAAA,IACA,KAAA,EAAO,iCAAA;AAAA,IACP,WAAA,EAAa,2BAAA;AAAA,IACb,OAAA,EAAS;AAAA,MACP,MAAM,OAAA,CAAQ,OAAA;AAAA,MACd,EAAA;AAAA,MACA,KAAA;AAAA,MACA,UAAA,EAAY,OAAO,UAAU,CAAA;AAAA,MAC7B,WAAA,EAAa,OAAO,WAAW,CAAA;AAAA,MAC/B;AAAA;AACF,GACD,CAAA;AAKD,EAAA,MAAM,OAAA,GAA0B;AAAA,IAC9B,WAAA,EAAa,YAAA;AAAA,IACb,QAAA,EAAU,YAAA;AAAA,IACV,OAAA,EAAS;AAAA,MACP,SAAA;AAAA,MACA,aAAA,EAAe;AAAA,QACb,MAAM,OAAA,CAAQ,OAAA;AAAA,QACd,EAAA;AAAA,QACA,KAAA,EAAO,MAAM,QAAA,EAAS;AAAA,QACtB,UAAA,EAAY,WAAW,QAAA,EAAS;AAAA,QAChC,WAAA,EAAa,YAAY,QAAA,EAAS;AAAA,QAClC;AAAA;AACF,KACF;AAAA,IACA,GAAI,OAAA,CAAQ,UAAA,KAAe,MAAA,GAAY,EAAE,UAAA,EAAY,EAAE,GAAG,OAAA,CAAQ,UAAA,EAAW,EAAE,GAAI;AAAC,GACtF;AAEA,EAAA,OAAO,MAAA,CAAO,KAAK,IAAA,CAAK,SAAA,CAAU,OAAO,CAAA,EAAG,MAAM,CAAA,CAAE,QAAA,CAAS,QAAQ,CAAA;AACvE;AAEA,SAAS,WAAA,GAA6B;AACpC,EAAA,MAAM,KAAA,GAAQ,IAAI,UAAA,CAAW,EAAE,CAAA;AAC/B,EAAA,MAAA,CAAO,gBAAgB,KAAK,CAAA;AAC5B,EAAA,OAAO,MAAM,KAAK,CAAA;AACpB","file":"x402-5A7CVCIJ.js","sourcesContent":["/**\n * Client-side payment helper: builds and EIP-712-signs an x402 v2 `exact`/EVM\n * authorization on the buyer's side. The demo buyer agent and the test suites\n * use it, and the `/x402` entry exports it. The gateway never calls it and\n * never holds a buyer key.\n *\n * It signs directly rather than through the SDK's `x402Client` because of\n * `overrides`: negative tests need deliberately wrong authorizations that a\n * conforming client will not produce. The x402 settlement E2E suite also\n * settles a payment built by `x402Client` itself to cover interoperability.\n */\n\nimport { PaymentRequirementsV2Schema } from '@x402/core/schemas';\nimport type { PaymentPayload, PaymentRequirements } from '@x402/core/types';\nimport { getAddress, toHex } from 'viem';\nimport { privateKeyToAccount } from 'viem/accounts';\nimport { CommerceError } from '../../core';\nimport { chainIdFromCaip2 } from './chain';\n\nexport interface CreatePaymentProofOptions {\n /** The buyer's private key. It signs locally and is never sent anywhere */\n readonly buyerPrivateKey: `0x${string}`;\n /** One entry from PaymentRequiredEnvelope.payment.accepts, verbatim */\n readonly accepts: Readonly<Record<string, unknown>>;\n /**\n * `PaymentPayload.extensions`, sent outside the signature. Echo the challenge's\n * declarations; for `payment-identifier`, add the buyer's `id` to `info`.\n */\n readonly extensions?: Readonly<Record<string, unknown>>;\n /** For negative tests only: a wrong amount, recipient, nonce or validity window */\n readonly overrides?: {\n readonly value?: string;\n readonly payTo?: string;\n readonly nonce?: `0x${string}`;\n readonly validBefore?: number;\n readonly validAfter?: number;\n };\n}\n\nconst X402_VERSION = 2;\n\nconst TRANSFER_WITH_AUTHORIZATION_TYPES = {\n TransferWithAuthorization: [\n { name: 'from', type: 'address' },\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'validAfter', type: 'uint256' },\n { name: 'validBefore', type: 'uint256' },\n { name: 'nonce', type: 'bytes32' },\n ],\n} as const;\n\n/** Returns the base64 `PAYMENT-SIGNATURE` value to send back to the gateway */\nexport async function createPaymentProof(options: CreatePaymentProofOptions): Promise<string> {\n const requirements = PaymentRequirementsV2Schema.parse(options.accepts);\n const method = requirements.extra?.['assetTransferMethod'];\n if (method !== undefined && method !== 'eip3009') {\n throw new CommerceError(\n 'INPUT_INVALID',\n `createPaymentProof: signs EIP-3009 only, and this offer uses \"${String(method)}\"; sign it with the SDK's x402Client`,\n );\n }\n if (\n !requirements.extra ||\n typeof requirements.extra['name'] !== 'string' ||\n typeof requirements.extra['version'] !== 'string'\n ) {\n throw new CommerceError(\n 'INPUT_INVALID',\n 'createPaymentProof: payment requirement is missing extra.name/extra.version, so the EIP-712 domain cannot be built',\n );\n }\n\n const chainId = chainIdFromCaip2(requirements.network);\n if (chainId === undefined) {\n throw new CommerceError(\n 'INPUT_INVALID',\n `createPaymentProof: network \"${requirements.network}\" is not a CAIP-2 eip155 identifier, so there is no chain id to sign against`,\n );\n }\n\n const account = privateKeyToAccount(options.buyerPrivateKey);\n\n const nonce = options.overrides?.nonce ?? randomNonce();\n const nowSeconds = Math.floor(Date.now() / 1000);\n // 0, as in the SDK's own v2 client: nothing here wants the authorization\n // delayed\n const validAfter = options.overrides?.validAfter ?? 0;\n const validBefore = options.overrides?.validBefore ?? nowSeconds + requirements.maxTimeoutSeconds;\n const to = getAddress((options.overrides?.payTo ?? requirements.payTo) as `0x${string}`);\n const value = BigInt(options.overrides?.value ?? requirements.amount);\n\n const signature = await account.signTypedData({\n domain: {\n name: requirements.extra['name'],\n version: requirements.extra['version'],\n chainId,\n verifyingContract: getAddress(requirements.asset as `0x${string}`),\n },\n types: TRANSFER_WITH_AUTHORIZATION_TYPES,\n primaryType: 'TransferWithAuthorization',\n message: {\n from: account.address,\n to,\n value,\n validAfter: BigInt(validAfter),\n validBefore: BigInt(validBefore),\n nonce,\n },\n });\n\n // v2 echoes the chosen requirement back as `accepted` so a stateless\n // facilitator knows which offer was taken. The gateway verifies against its\n // own copy.\n const payload: PaymentPayload = {\n x402Version: X402_VERSION,\n accepted: requirements as PaymentRequirements,\n payload: {\n signature,\n authorization: {\n from: account.address,\n to,\n value: value.toString(),\n validAfter: validAfter.toString(),\n validBefore: validBefore.toString(),\n nonce,\n },\n },\n ...(options.extensions !== undefined ? { extensions: { ...options.extensions } } : {}),\n };\n\n return Buffer.from(JSON.stringify(payload), 'utf8').toString('base64');\n}\n\nfunction randomNonce(): `0x${string}` {\n const bytes = new Uint8Array(32);\n crypto.getRandomValues(bytes);\n return toHex(bytes);\n}\n"]}
1
+ {"version":3,"sources":["../../src/payments/x402/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAuCA,IAAM,YAAA,GAAe,CAAA;AAErB,IAAM,iCAAA,GAAoC;AAAA,EACxC,yBAAA,EAA2B;AAAA,IACzB,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAU;AAAA,IAChC,EAAE,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,SAAA,EAAU;AAAA,IAC9B,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA,EAAU;AAAA,IACjC,EAAE,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,SAAA,EAAU;AAAA,IACtC,EAAE,IAAA,EAAM,aAAA,EAAe,IAAA,EAAM,SAAA,EAAU;AAAA,IACvC,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA;AAAU;AAErC,CAAA;AAGA,eAAsB,mBAAmB,OAAA,EAAqD;AAC5F,EAAA,MAAM,YAAA,GAAe,2BAAA,CAA4B,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA;AACtE,EAAA,MAAM,MAAA,GAAS,YAAA,CAAa,KAAA,GAAQ,qBAAqB,CAAA;AACzD,EAAA,IAAI,MAAA,KAAW,MAAA,IAAa,MAAA,KAAW,SAAA,EAAW;AAChD,IAAA,MAAM,IAAI,aAAA;AAAA,MACR,eAAA;AAAA,MACA,CAAA,8DAAA,EAAiE,MAAA,CAAO,MAAM,CAAC,CAAA,oCAAA;AAAA,KACjF;AAAA,EACF;AACA,EAAA,IACE,CAAC,YAAA,CAAa,KAAA,IACd,OAAO,aAAa,KAAA,CAAM,MAAM,CAAA,KAAM,QAAA,IACtC,OAAO,YAAA,CAAa,KAAA,CAAM,SAAS,MAAM,QAAA,EACzC;AACA,IAAA,MAAM,IAAI,aAAA;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IACb,OAAA,EAAS;AAAA,MACP,MAAM,OAAA,CAAQ,OAAA;AAAA,MACd,EAAA;AAAA,MACA,KAAA;AAAA,MACA,UAAA,EAAY,OAAO,UAAU,CAAA;AAAA,MAC7B,WAAA,EAAa,OAAO,WAAW,CAAA;AAAA,MAC/B;AAAA;AACF,GACD,CAAA;AAKD,EAAA,MAAM,OAAA,GAA0B;AAAA,IAC9B,WAAA,EAAa,YAAA;AAAA,IACb,QAAA,EAAU,YAAA;AAAA,IACV,OAAA,EAAS;AAAA,MACP,SAAA;AAAA,MACA,aAAA,EAAe;AAAA,QACb,MAAM,OAAA,CAAQ,OAAA;AAAA,QACd,EAAA;AAAA,QACA,KAAA,EAAO,MAAM,QAAA,EAAS;AAAA,QACtB,UAAA,EAAY,WAAW,QAAA,EAAS;AAAA,QAChC,WAAA,EAAa,YAAY,QAAA,EAAS;AAAA,QAClC;AAAA;AACF,KACF;AAAA,IACA,GAAI,OAAA,CAAQ,UAAA,KAAe,MAAA,GAAY,EAAE,UAAA,EAAY,EAAE,GAAG,OAAA,CAAQ,UAAA,EAAW,EAAE,GAAI;AAAC,GACtF;AAEA,EAAA,OAAO,MAAA,CAAO,KAAK,IAAA,CAAK,SAAA,CAAU,OAAO,CAAA,EAAG,MAAM,CAAA,CAAE,QAAA,CAAS,QAAQ,CAAA;AACvE;AAEA,SAAS,WAAA,GAA6B;AACpC,EAAA,MAAM,KAAA,GAAQ,IAAI,UAAA,CAAW,EAAE,CAAA;AAC/B,EAAA,MAAA,CAAO,gBAAgB,KAAK,CAAA;AAC5B,EAAA,OAAO,MAAM,KAAK,CAAA;AACpB","file":"x402-RNV3VHJT.js","sourcesContent":["/**\n * Client-side payment helper: builds and EIP-712-signs an x402 v2 `exact`/EVM\n * authorization on the buyer's side. The demo buyer agent and the test suites\n * use it, and the `/x402` entry exports it. The gateway never calls it and\n * never holds a buyer key.\n *\n * It signs directly rather than through the SDK's `x402Client` because of\n * `overrides`: negative tests need deliberately wrong authorizations that a\n * conforming client will not produce. The x402 settlement E2E suite also\n * settles a payment built by `x402Client` itself to cover interoperability.\n */\n\nimport { PaymentRequirementsV2Schema } from '@x402/core/schemas';\nimport type { PaymentPayload, PaymentRequirements } from '@x402/core/types';\nimport { getAddress, toHex } from 'viem';\nimport { privateKeyToAccount } from 'viem/accounts';\nimport { CommerceError } from '../../core';\nimport { chainIdFromCaip2 } from './chain';\n\nexport interface CreatePaymentProofOptions {\n /** The buyer's private key. It signs locally and is never sent anywhere */\n readonly buyerPrivateKey: `0x${string}`;\n /** One entry from PaymentRequiredEnvelope.payment.accepts, verbatim */\n readonly accepts: Readonly<Record<string, unknown>>;\n /**\n * `PaymentPayload.extensions`, sent outside the signature. Echo the challenge's\n * declarations; for `payment-identifier`, add the buyer's `id` to `info`.\n */\n readonly extensions?: Readonly<Record<string, unknown>>;\n /** For negative tests only: a wrong amount, recipient, nonce or validity window */\n readonly overrides?: {\n readonly value?: string;\n readonly payTo?: string;\n readonly nonce?: `0x${string}`;\n readonly validBefore?: number;\n readonly validAfter?: number;\n };\n}\n\nconst X402_VERSION = 2;\n\nconst TRANSFER_WITH_AUTHORIZATION_TYPES = {\n TransferWithAuthorization: [\n { name: 'from', type: 'address' },\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'validAfter', type: 'uint256' },\n { name: 'validBefore', type: 'uint256' },\n { name: 'nonce', type: 'bytes32' },\n ],\n} as const;\n\n/** Returns the base64 `PAYMENT-SIGNATURE` value to send back to the gateway */\nexport async function createPaymentProof(options: CreatePaymentProofOptions): Promise<string> {\n const requirements = PaymentRequirementsV2Schema.parse(options.accepts);\n const method = requirements.extra?.['assetTransferMethod'];\n if (method !== undefined && method !== 'eip3009') {\n throw new CommerceError(\n 'INPUT_INVALID',\n `createPaymentProof: signs EIP-3009 only, and this offer uses \"${String(method)}\"; sign it with the SDK's x402Client`,\n );\n }\n if (\n !requirements.extra ||\n typeof requirements.extra['name'] !== 'string' ||\n typeof requirements.extra['version'] !== 'string'\n ) {\n throw new CommerceError(\n 'INPUT_INVALID',\n 'createPaymentProof: payment requirement is missing extra.name/extra.version, so the EIP-712 domain cannot be built',\n );\n }\n\n const chainId = chainIdFromCaip2(requirements.network);\n if (chainId === undefined) {\n throw new CommerceError(\n 'INPUT_INVALID',\n `createPaymentProof: network \"${requirements.network}\" is not a CAIP-2 eip155 identifier, so there is no chain id to sign against`,\n );\n }\n\n const account = privateKeyToAccount(options.buyerPrivateKey);\n\n const nonce = options.overrides?.nonce ?? randomNonce();\n const nowSeconds = Math.floor(Date.now() / 1000);\n // 0, as in the SDK's own v2 client: nothing here wants the authorization\n // delayed\n const validAfter = options.overrides?.validAfter ?? 0;\n const validBefore = options.overrides?.validBefore ?? nowSeconds + requirements.maxTimeoutSeconds;\n const to = getAddress((options.overrides?.payTo ?? requirements.payTo) as `0x${string}`);\n const value = BigInt(options.overrides?.value ?? requirements.amount);\n\n const signature = await account.signTypedData({\n domain: {\n name: requirements.extra['name'],\n version: requirements.extra['version'],\n chainId,\n verifyingContract: getAddress(requirements.asset as `0x${string}`),\n },\n types: TRANSFER_WITH_AUTHORIZATION_TYPES,\n primaryType: 'TransferWithAuthorization',\n message: {\n from: account.address,\n to,\n value,\n validAfter: BigInt(validAfter),\n validBefore: BigInt(validBefore),\n nonce,\n },\n });\n\n // v2 echoes the chosen requirement back as `accepted` so a stateless\n // facilitator knows which offer was taken. The gateway verifies against its\n // own copy.\n const payload: PaymentPayload = {\n x402Version: X402_VERSION,\n accepted: requirements as PaymentRequirements,\n payload: {\n signature,\n authorization: {\n from: account.address,\n to,\n value: value.toString(),\n validAfter: validAfter.toString(),\n validBefore: validBefore.toString(),\n nonce,\n },\n },\n ...(options.extensions !== undefined ? { extensions: { ...options.extensions } } : {}),\n };\n\n return Buffer.from(JSON.stringify(payload), 'utf8').toString('base64');\n}\n\nfunction randomNonce(): `0x${string}` {\n const bytes = new Uint8Array(32);\n crypto.getRandomValues(bytes);\n return toHex(bytes);\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -8,8 +8,8 @@ import { X402ProviderOptions } from './x402.js';
8
8
  export { A as AuthorizationHoldState, C as COMMERCE_EVENT_TYPES, a as CommerceEvent, b as CommerceEventType, E as EventSink, P as PersistenceFailure, T as TRANSACTION_STATES, c as Transaction, d as TransactionFacts, e as TransactionState, t as transactionState } from './transaction-F9ZvhokH.js';
9
9
  import { D as DeliveredOutcome, P as PaymentRequiredOutcome, E as ExecutionPipeline, a as ProtocolAdapter, H as HttpProtocolAdapter, A as AdapterHttpRoute, b as ProtocolAdapterContext } from './protocol-adapter-D6JH_kk-.js';
10
10
  export { C as CanonicalRequest, c as ExecutionOutcome, i as isHttpProtocolAdapter } from './protocol-adapter-D6JH_kk-.js';
11
- import { R as ReceiptStore } from './store-BzgwHOPu.js';
12
- export { A as AuthorizationHold, a as AuthorizationHoldReservation, b as AuthorizationHoldResult, I as IdempotencyClaim, c as IdempotencyScope, d as IdempotencyUpdate, L as ListOptions, N as NewTransaction, P as PaymentAttemptListOptions, e as PaymentAttemptReservation, f as PaymentAttemptResolveRequest, g as PaymentAttemptUpdate, h as PendingTask, i as ReceiptListOptions, T as TransactionListOptions, j as TransactionPage, k as TransactionStep } from './store-BzgwHOPu.js';
11
+ import { R as ReceiptStore } from './store-04pazhFP.js';
12
+ export { A as AuthorizationHold, a as AuthorizationHoldReservation, b as AuthorizationHoldResult, I as IdempotencyClaim, c as IdempotencyScope, d as IdempotencyUpdate, L as ListOptions, N as NewTransaction, P as PaymentAttemptListOptions, e as PaymentAttemptReservation, f as PaymentAttemptResolveRequest, g as PaymentAttemptUpdate, h as PendingTask, i as ReceiptListOptions, T as TaskRecord, j as TransactionListOptions, k as TransactionPage, l as TransactionStep } from './store-04pazhFP.js';
13
13
  import { L as Logger } from './logger-CllGwQ8i.js';
14
14
  export { N as NOOP_LOGGER } from './logger-CllGwQ8i.js';
15
15
  import { FastifyInstance } from 'fastify';
@@ -416,10 +416,7 @@ interface GatewayConfig {
416
416
  readonly enabled: boolean;
417
417
  };
418
418
  readonly mcp: McpProtocolConfig;
419
- readonly a2a: {
420
- readonly enabled: boolean;
421
- readonly mountPath: string;
422
- };
419
+ readonly a2a: A2aProtocolConfig;
423
420
  readonly acp: AcpProtocolConfig;
424
421
  };
425
422
  /** Canonical resources, already normalized */
@@ -504,6 +501,16 @@ interface GatewayConfig {
504
501
  readonly ap2: Ap2AuthorizationConfig;
505
502
  };
506
503
  }
504
+ /** `protocols.a2a` after normalization */
505
+ interface A2aProtocolConfig {
506
+ readonly enabled: boolean;
507
+ readonly mountPath: string;
508
+ /** Set only when `protocols.a2a.tasks` is configured; unset limits stay absent */
509
+ readonly tasks?: {
510
+ readonly retentionHours?: number;
511
+ readonly maxRetained?: number;
512
+ };
513
+ }
507
514
  /** `protocols.mcp` after normalization */
508
515
  interface McpProtocolConfig {
509
516
  readonly enabled: boolean;
@@ -565,11 +572,22 @@ interface A2aAdapterOptions {
565
572
  /** Version published on the card. Defaults to this package's version */
566
573
  readonly agentVersion?: string;
567
574
  /**
568
- * Stores x402 tasks awaiting payment when all pending-task methods are
569
- * present. Durable stores can preserve unexpired tasks across restarts;
570
- * otherwise tasks stay in memory. The adapter never closes this store.
575
+ * Store task responses through the complete `task_records` group and unpaid
576
+ * x402 purchases through the complete `pending_tasks` group. Each missing
577
+ * group falls back to process memory. A durable store can preserve unexpired
578
+ * records across restarts. The caller owns and closes the store.
571
579
  */
572
580
  readonly store?: ReceiptStore;
581
+ /**
582
+ * Task retention in hours (default 24, range 1 to 8760) and the limit on
583
+ * unexpired records when admitting new tasks (default 1000, range 1 to
584
+ * 1,000,000). At capacity, a new record evicts eligible uncharged responses
585
+ * or is refused if too few are available. Existing IDs can still be replaced.
586
+ */
587
+ readonly tasks?: {
588
+ readonly retentionHours?: number;
589
+ readonly maxRetained?: number;
590
+ };
573
591
  }
574
592
  declare class A2aProtocolAdapter implements HttpProtocolAdapter {
575
593
  readonly name: "a2a";
@@ -580,6 +598,8 @@ declare class A2aProtocolAdapter implements HttpProtocolAdapter {
580
598
  private readonly agentDescription;
581
599
  private readonly agentVersion;
582
600
  private readonly store;
601
+ private readonly retentionMs;
602
+ private readonly maxRetained;
583
603
  private context;
584
604
  private started;
585
605
  private skillsById;
@@ -587,6 +607,9 @@ declare class A2aProtocolAdapter implements HttpProtocolAdapter {
587
607
  private cardBody;
588
608
  private cardEtag;
589
609
  private pendingPayments;
610
+ private tasks;
611
+ private readonly running;
612
+ private background;
590
613
  constructor(options?: A2aAdapterOptions);
591
614
  start(context: ProtocolAdapterContext): Promise<void>;
592
615
  /** `GET /.well-known/agent-card.json` */
@@ -594,8 +617,28 @@ declare class A2aProtocolAdapter implements HttpProtocolAdapter {
594
617
  /** `POST <mountPath>`: the A2A JSON-RPC endpoint */
595
618
  handleHttp(req: IncomingMessage, res: ServerResponse): Promise<void>;
596
619
  private dispatch;
620
+ private operations;
621
+ private resume;
622
+ private retainedUntil;
623
+ private keep;
624
+ private recordWorking;
625
+ /**
626
+ * Reject further messages on a retained task after the pending-payment path
627
+ * declines it, including tasks taken by another call. Terminal tasks accept
628
+ * no further messages (A2A 1.0.1 section 3.1.1). Missing records fall through
629
+ * to `parseInvocation`, which returns `TaskNotFoundError`.
630
+ */
631
+ private answerKnownTask;
597
632
  private execute;
598
- private taskIdentity;
633
+ private purchase;
634
+ /**
635
+ * Record the input-required response before holding its pending purchase,
636
+ * using the same expiry. Refuse the purchase if the record does not fit.
637
+ * If pending storage throws, `execute` returns a failed task and attempts
638
+ * to replace the waiting response with it.
639
+ */
640
+ private awaitPayment;
641
+ private taskIds;
599
642
  health(): Promise<AdapterHealth>;
600
643
  stop(): Promise<void>;
601
644
  private writeJson;
@@ -712,27 +755,6 @@ declare class AcpProtocolAdapter implements HttpProtocolAdapter {
712
755
  }
713
756
  declare function createAcpAdapter(options: AcpAdapterOptions): AcpProtocolAdapter;
714
757
 
715
- /** Deprecated store files to import. Experimental: through 2.x only */
716
- interface LegacyStoreOptions {
717
- /** Deprecated `authorization.ap2.replay.path` */
718
- readonly ap2Replay?: string;
719
- /** Deprecated `protocols.acp.idempotency.path` */
720
- readonly acpIdempotency?: string;
721
- /**
722
- * Enabled features whose missing legacy history must be checked. Without a
723
- * recorded import or prior check, `init()` rejects an unset key or missing
724
- * file when the receipt database shows past use. `:memory:` explicitly
725
- * declares that no legacy file was retained. A passed check with no file
726
- * is recorded so later starts can omit the key.
727
- */
728
- readonly enabled?: {
729
- readonly ap2?: boolean;
730
- readonly acp?: boolean;
731
- };
732
- }
733
- /** A deprecated store file's name in `legacy_imports` */
734
- type LegacySource = 'ap2-replay' | 'acp-idempotency';
735
-
736
758
  interface SqliteReceiptStoreOptions {
737
759
  /** File path, or ':memory:' for tests. Parent directory is created if missing */
738
760
  readonly path: string;
@@ -784,5 +806,26 @@ interface SqliteReceiptStore extends Required<ReceiptStore> {
784
806
  }
785
807
  declare function createSqliteReceiptStore(options: SqliteReceiptStoreOptions): SqliteReceiptStore;
786
808
 
809
+ /** Deprecated store files to import. Experimental: through 2.x only */
810
+ interface LegacyStoreOptions {
811
+ /** Deprecated `authorization.ap2.replay.path` */
812
+ readonly ap2Replay?: string;
813
+ /** Deprecated `protocols.acp.idempotency.path` */
814
+ readonly acpIdempotency?: string;
815
+ /**
816
+ * Enabled features whose missing legacy history must be checked. Without a
817
+ * recorded import or prior check, `init()` rejects an unset key or missing
818
+ * file when the receipt database shows past use. `:memory:` explicitly
819
+ * declares that no legacy file was retained. A passed check with no file
820
+ * is recorded so later starts can omit the key.
821
+ */
822
+ readonly enabled?: {
823
+ readonly ap2?: boolean;
824
+ readonly acp?: boolean;
825
+ };
826
+ }
827
+ /** A deprecated store file's name in `legacy_imports` */
828
+ type LegacySource = 'ap2-replay' | 'acp-idempotency';
829
+
787
830
  export { A2A_AGENT_CARD_PATH, A2A_PROTOCOL_VERSION, A2A_SPEC_VERSION, ACP_API_VERSION, ACP_SPEC_VERSION, ACP_WELL_KNOWN_PATH, AUTHORIZATION_HEADER, AUTHORIZATION_INPUT_FIELD, AdapterDescriptor, AdapterHealth, AdapterHttpRoute, AuthorizationProvider, AuthorizationRequirement, AuthorizationSubmission, BackendHandler, COMMERCE_ERROR_CODES, COMMERCE_ERROR_HTTP_STATUS, Clock, CommerceError, CommerceResource, DELIVERY_SUMMARY_META_KEY, DecimalAmount, DeliveredOutcome, ExecutionPipeline, HttpProtocolAdapter, IdGenerator, IsoTimestamp, Logger, MAX_AUTHORIZATION_HEADER_BYTES, PAYMENT_HEADER, PAYMENT_INPUT_FIELD, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PaymentMethodName, PaymentProvider, PaymentRequiredOutcome, PaymentSubmission, ProtocolAdapter, ProtocolAdapterContext, RESERVED_INPUT_FIELDS, RETRYABLE_ERROR_CODES, ReceiptStore, ResourceRegistry, createA2aAdapter, createAcpAdapter, createGateway, createSqliteReceiptStore, extractReservedInputFields, isCommerceError, isPaymentRequiredEnvelope, loadConfig, parseAuthorizationHeader, parseAuthorizationSubmission, parseConfig, createSqliteReceiptStore as receipts, toCommerceError, toDeliverySummary, toErrorEnvelope, toPaymentRequiredEnvelope };
788
831
  export type { A2aAdapterOptions, AcpAdapterOptions, BackendExecutor, BackendRequest, BackendResponse, CommerceErrorCode, CommerceErrorInfo, CommerceErrorOptions, DeliverySummary, ErrorEnvelope, GatewayConfig, GatewayInstance, GatewayOptions, PaymentRequiredEnvelope };