@devlab.group/agent-commerce 2.4.1 → 2.5.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 (108) hide show
  1. package/README.md +115 -15
  2. package/dist/ap2.d.ts +24 -12
  3. package/dist/ap2.js +31 -13
  4. package/dist/ap2.js.map +1 -1
  5. package/dist/{chunk-DTKU3Z2M.js → chunk-3OTCFFFT.js} +37 -4
  6. package/dist/chunk-3OTCFFFT.js.map +1 -0
  7. package/dist/{chunk-QPV3EGJO.js → chunk-4K7FIBJM.js} +25 -4
  8. package/dist/chunk-4K7FIBJM.js.map +1 -0
  9. package/dist/{chunk-CXWC5LWM.js → chunk-FKQK5XZA.js} +652 -68
  10. package/dist/chunk-FKQK5XZA.js.map +1 -0
  11. package/dist/chunk-GA3O2A7R.js +92 -0
  12. package/dist/chunk-GA3O2A7R.js.map +1 -0
  13. package/dist/{chunk-WZW5ORZH.js → chunk-VUCMBGUR.js} +3 -3
  14. package/dist/{chunk-WZW5ORZH.js.map → chunk-VUCMBGUR.js.map} +1 -1
  15. package/dist/cli/{ap2-GWSP4LYY.js → ap2-YAPLERSC.js} +34 -15
  16. package/dist/cli/ap2-YAPLERSC.js.map +1 -0
  17. package/dist/cli/{chunk-G2JEY7MB.js → chunk-2J2IQQ4X.js} +8 -7
  18. package/dist/cli/chunk-2J2IQQ4X.js.map +1 -0
  19. package/dist/cli/chunk-2UPPX3FJ.js +311 -0
  20. package/dist/cli/chunk-2UPPX3FJ.js.map +1 -0
  21. package/dist/cli/{chunk-WYOGIANL.js → chunk-4H2QLHQI.js} +4 -4
  22. package/dist/cli/{chunk-WYOGIANL.js.map → chunk-4H2QLHQI.js.map} +1 -1
  23. package/dist/cli/{chunk-OZ4LAWBK.js → chunk-5R7DM5LM.js} +25 -4
  24. package/dist/cli/chunk-5R7DM5LM.js.map +1 -0
  25. package/dist/cli/chunk-663ALDZA.js +92 -0
  26. package/dist/cli/chunk-663ALDZA.js.map +1 -0
  27. package/dist/cli/{chunk-QQ3WY5L3.js → chunk-IDY2735M.js} +36 -104
  28. package/dist/cli/chunk-IDY2735M.js.map +1 -0
  29. package/dist/cli/chunk-JFVRG2HH.js +107 -0
  30. package/dist/cli/chunk-JFVRG2HH.js.map +1 -0
  31. package/dist/cli/chunk-M7NXVRU5.js +8 -0
  32. package/dist/cli/{chunk-ITWNSS2B.js.map → chunk-M7NXVRU5.js.map} +1 -1
  33. package/dist/cli/chunk-NIU5EMSB.js +119 -0
  34. package/dist/cli/chunk-NIU5EMSB.js.map +1 -0
  35. package/dist/cli/{chunk-TNMLDPUO.js → chunk-QA2OPHBF.js} +655 -70
  36. package/dist/cli/chunk-QA2OPHBF.js.map +1 -0
  37. package/dist/cli/{chunk-GJIMDMYT.js → chunk-QLUCNPRT.js} +404 -161
  38. package/dist/cli/chunk-QLUCNPRT.js.map +1 -0
  39. package/dist/cli/chunk-SYQLJXIU.js +105 -0
  40. package/dist/cli/chunk-SYQLJXIU.js.map +1 -0
  41. package/dist/cli/{chunk-3MGAJ5FX.js → chunk-VJ4EO4LE.js} +3 -3
  42. package/dist/cli/{chunk-3MGAJ5FX.js.map → chunk-VJ4EO4LE.js.map} +1 -1
  43. package/dist/cli/{chunk-PIMFPCNZ.js → chunk-Z34UMZBB.js} +234 -85
  44. package/dist/cli/chunk-Z34UMZBB.js.map +1 -0
  45. package/dist/cli/config-BWFMN2ZB.js +12 -0
  46. package/dist/cli/{config-UI4EDG4L.js.map → config-BWFMN2ZB.js.map} +1 -1
  47. package/dist/cli/index.js +258 -11
  48. package/dist/cli/index.js.map +1 -1
  49. package/dist/cli/{mcp-PGBRWZVA.js → mcp-KZEMXLHR.js} +5 -4
  50. package/dist/cli/mcp-KZEMXLHR.js.map +1 -0
  51. package/dist/cli/{near-5AY3HWYF.js → near-U6365VFX.js} +15 -4
  52. package/dist/cli/near-U6365VFX.js.map +1 -0
  53. package/dist/cli/payment-providers-SZL36H3Y.js +6 -0
  54. package/dist/cli/payment-providers-SZL36H3Y.js.map +1 -0
  55. package/dist/cli/{provider-I2ESL6RS.js → provider-6TKB5ADJ.js} +26 -15
  56. package/dist/cli/provider-6TKB5ADJ.js.map +1 -0
  57. package/dist/cli/receipts-ZGLJWMQG.js +8 -0
  58. package/dist/cli/receipts-ZGLJWMQG.js.map +1 -0
  59. package/dist/cli/reconcile-IC22MJD5.js +4 -0
  60. package/dist/cli/reconcile-IC22MJD5.js.map +1 -0
  61. package/dist/cli/{run-JK4ERPJV.js → run-ZTYPQI4D.js} +151 -115
  62. package/dist/cli/run-ZTYPQI4D.js.map +1 -0
  63. package/dist/cli/svm-KDSPDFJG.js +48 -0
  64. package/dist/cli/svm-KDSPDFJG.js.map +1 -0
  65. package/dist/cli/{x402-7WBFZQXV.js → x402-WLYBLODI.js} +10 -9
  66. package/dist/cli/x402-WLYBLODI.js.map +1 -0
  67. package/dist/index.d.ts +112 -12
  68. package/dist/index.js +948 -157
  69. package/dist/index.js.map +1 -1
  70. package/dist/mcp.d.ts +1 -2
  71. package/dist/mcp.js +1 -1
  72. package/dist/mpp.js +20 -10
  73. package/dist/mpp.js.map +1 -1
  74. package/dist/{near-D6C42VPE.js → near-FH7HPZV3.js} +15 -4
  75. package/dist/near-FH7HPZV3.js.map +1 -0
  76. package/dist/{protocol-adapter-C9odYl6l.d.ts → protocol-adapter-DEXpdp8m.d.ts} +102 -48
  77. package/dist/{runtime-Cl_BLVZV.d.ts → runtime-Dz2fSO-P.d.ts} +220 -2
  78. package/dist/svm-KNC3PHMS.js +48 -0
  79. package/dist/svm-KNC3PHMS.js.map +1 -0
  80. package/dist/x402.js +5 -5
  81. package/package.json +1 -1
  82. package/dist/authorization-DjAecwuW.d.ts +0 -115
  83. package/dist/chunk-CXWC5LWM.js.map +0 -1
  84. package/dist/chunk-DTKU3Z2M.js.map +0 -1
  85. package/dist/chunk-KA2AX5FH.js +0 -44
  86. package/dist/chunk-KA2AX5FH.js.map +0 -1
  87. package/dist/chunk-QPV3EGJO.js.map +0 -1
  88. package/dist/cli/ap2-GWSP4LYY.js.map +0 -1
  89. package/dist/cli/chunk-G2JEY7MB.js.map +0 -1
  90. package/dist/cli/chunk-GJIMDMYT.js.map +0 -1
  91. package/dist/cli/chunk-ITWNSS2B.js +0 -8
  92. package/dist/cli/chunk-OSTCU6ZK.js +0 -44
  93. package/dist/cli/chunk-OSTCU6ZK.js.map +0 -1
  94. package/dist/cli/chunk-OZ4LAWBK.js.map +0 -1
  95. package/dist/cli/chunk-PIMFPCNZ.js.map +0 -1
  96. package/dist/cli/chunk-QQ3WY5L3.js.map +0 -1
  97. package/dist/cli/chunk-TNMLDPUO.js.map +0 -1
  98. package/dist/cli/config-UI4EDG4L.js +0 -11
  99. package/dist/cli/mcp-PGBRWZVA.js.map +0 -1
  100. package/dist/cli/near-5AY3HWYF.js.map +0 -1
  101. package/dist/cli/provider-I2ESL6RS.js.map +0 -1
  102. package/dist/cli/run-JK4ERPJV.js.map +0 -1
  103. package/dist/cli/svm-3MMYFPC7.js +0 -33
  104. package/dist/cli/svm-3MMYFPC7.js.map +0 -1
  105. package/dist/cli/x402-7WBFZQXV.js.map +0 -1
  106. package/dist/near-D6C42VPE.js.map +0 -1
  107. package/dist/svm-QEUAUNPQ.js +0 -33
  108. package/dist/svm-QEUAUNPQ.js.map +0 -1
@@ -0,0 +1,48 @@
1
+ import { LOCATOR_VERSION, computeSvmReplayKey } from './chunk-663ALDZA.js';
2
+ import { isRecord } from './chunk-3M6U7ILB.js';
3
+ import { getAddressEncoder, getProgramDerivedAddress, address, getCompiledTransactionMessageDecoder } from '@solana/kit';
4
+ import { decodeTransactionFromPayload, transactionMessageHash } from '@x402/svm';
5
+
6
+ var MAX_TRANSACTION_BASE64 = 1644;
7
+ var ASSOCIATED_TOKEN_PROGRAM = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
8
+ async function associatedTokenAccount(owner, mint, tokenProgram) {
9
+ const encoder = getAddressEncoder();
10
+ const [account] = await getProgramDerivedAddress({
11
+ programAddress: address(ASSOCIATED_TOKEN_PROGRAM),
12
+ seeds: [owner, tokenProgram, mint].map((key) => encoder.encode(address(key)))
13
+ });
14
+ return account;
15
+ }
16
+ function inspectSvmPayload(payload, network) {
17
+ if (!isRecord(payload)) return "invalid_exact_svm_payload_transaction";
18
+ const transaction = payload["transaction"];
19
+ if (typeof transaction !== "string" || transaction.length > MAX_TRANSACTION_BASE64) {
20
+ return "invalid_exact_svm_payload_transaction";
21
+ }
22
+ let messageHash;
23
+ let recentBlockhash;
24
+ try {
25
+ const decoded = decodeTransactionFromPayload({ transaction });
26
+ messageHash = transactionMessageHash(decoded);
27
+ recentBlockhash = getCompiledTransactionMessageDecoder().decode(
28
+ decoded.messageBytes
29
+ ).lifetimeToken;
30
+ } catch {
31
+ return "invalid_exact_svm_payload_transaction_could_not_be_decoded";
32
+ }
33
+ return {
34
+ replayKey: computeSvmReplayKey({ network, messageHash }),
35
+ locator: { v: LOCATOR_VERSION, network, messageHash, recentBlockhash }
36
+ };
37
+ }
38
+ function messageHashOf(transaction) {
39
+ try {
40
+ return transactionMessageHash(decodeTransactionFromPayload({ transaction }));
41
+ } catch {
42
+ return void 0;
43
+ }
44
+ }
45
+
46
+ export { associatedTokenAccount, inspectSvmPayload, messageHashOf };
47
+ //# sourceMappingURL=svm-KDSPDFJG.js.map
48
+ //# sourceMappingURL=svm-KDSPDFJG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/payments/x402/svm.ts"],"names":[],"mappings":";;;;;AAsBA,IAAM,sBAAA,GAAyB,IAAA;AAE/B,IAAM,wBAAA,GAA2B,8CAAA;AAMjC,eAAsB,sBAAA,CACpB,KAAA,EACA,IAAA,EACA,YAAA,EACiB;AACjB,EAAA,MAAM,UAAU,iBAAA,EAAkB;AAClC,EAAA,MAAM,CAAC,OAAO,CAAA,GAAI,MAAM,wBAAA,CAAyB;AAAA,IAC/C,cAAA,EAAgB,QAAQ,wBAAwB,CAAA;AAAA,IAChD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load inspection with bounded decoding, replay identity and\n * reconciliation coordinates. The provider loads this module, including its\n * `@x402/svm` and `@solana/kit` imports, when a Solana offer is configured.\n *\n * The facilitator checks the transaction itself: the fee payer, signatures,\n * instruction layout, mint, recipient token account and amount, and a\n * simulation. Its smart-wallet path accepts layouts the gateway could not\n * parse, so the gateway does not read the transfer.\n */\nimport {\n address,\n getAddressEncoder,\n getCompiledTransactionMessageDecoder,\n getProgramDerivedAddress,\n} from '@solana/kit';\nimport { decodeTransactionFromPayload, transactionMessageHash } from '@x402/svm';\nimport { isRecord } from '../../core/is-record';\nimport { LOCATOR_VERSION } from './locator';\nimport { computeSvmReplayKey } from './replay-key';\n\n// A Solana transaction fits a 1232-byte packet, which is 1644 base64 characters\nconst MAX_TRANSACTION_BASE64 = 1644;\n\nconst ASSOCIATED_TOKEN_PROGRAM = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';\n\n/**\n * The associated token account of `owner` for `mint`, where the SDK client\n * sends a Solana `exact` payment. Its transaction cannot create the account.\n */\nexport async function associatedTokenAccount(\n owner: string,\n mint: string,\n tokenProgram: string,\n): Promise<string> {\n const encoder = getAddressEncoder();\n const [account] = await getProgramDerivedAddress({\n programAddress: address(ASSOCIATED_TOKEN_PROGRAM),\n seeds: [owner, tokenProgram, mint].map((key) => encoder.encode(address(key))),\n });\n return account;\n}\n\n/**\n * Returns the Solana `exact` replay key and locator, or an SDK refusal reason\n * for a missing, oversized or undecodable transaction. The provider adds the\n * payer from the facilitator's verdict when a usable address is available.\n */\nexport function inspectSvmPayload(\n payload: unknown,\n network: string,\n): { readonly replayKey: string; readonly locator: Readonly<Record<string, unknown>> } | string {\n if (!isRecord(payload)) return 'invalid_exact_svm_payload_transaction';\n const transaction = payload['transaction'];\n if (typeof transaction !== 'string' || transaction.length > MAX_TRANSACTION_BASE64) {\n return 'invalid_exact_svm_payload_transaction';\n }\n let messageHash: string;\n let recentBlockhash: string;\n try {\n const decoded = decodeTransactionFromPayload({ transaction });\n messageHash = transactionMessageHash(decoded);\n recentBlockhash = getCompiledTransactionMessageDecoder().decode(\n decoded.messageBytes,\n ).lifetimeToken;\n } catch {\n return 'invalid_exact_svm_payload_transaction_could_not_be_decoded';\n }\n return {\n replayKey: computeSvmReplayKey({ network, messageHash }),\n locator: { v: LOCATOR_VERSION, network, messageHash, recentBlockhash },\n };\n}\n\n/**\n * Returns the message hash of base64 transaction bytes using the same decoder\n * as payment inspection, or undefined if decoding or hashing fails\n */\nexport function messageHashOf(transaction: string): string | undefined {\n try {\n return transactionMessageHash(decodeTransactionFromPayload({ transaction }));\n } catch {\n return undefined;\n }\n}\n"]}
@@ -1,10 +1,11 @@
1
- import { chainIdFromCaip2 } from './chunk-TNMLDPUO.js';
2
- export { createX402PaymentProvider } from './chunk-TNMLDPUO.js';
3
- import './chunk-WYOGIANL.js';
4
- export { SUPPORTED_NETWORK_IDS } from './chunk-OZ4LAWBK.js';
5
- import './chunk-OSTCU6ZK.js';
6
- import './chunk-ITWNSS2B.js';
7
- import { CommerceError } from './chunk-QQ3WY5L3.js';
1
+ import { chainIdFromCaip2 } from './chunk-QA2OPHBF.js';
2
+ export { createX402PaymentProvider } from './chunk-QA2OPHBF.js';
3
+ import './chunk-M7NXVRU5.js';
4
+ import './chunk-4H2QLHQI.js';
5
+ export { SUPPORTED_NETWORK_IDS } from './chunk-5R7DM5LM.js';
6
+ import './chunk-IDY2735M.js';
7
+ import { CommerceError } from './chunk-SYQLJXIU.js';
8
+ import './chunk-663ALDZA.js';
8
9
  import './chunk-3M6U7ILB.js';
9
10
  import { PaymentRequirementsV2Schema } from '@x402/core/schemas';
10
11
  import { getAddress, toHex } from 'viem';
@@ -92,5 +93,5 @@ function randomNonce() {
92
93
  }
93
94
 
94
95
  export { createPaymentProof };
95
- //# sourceMappingURL=x402-7WBFZQXV.js.map
96
- //# sourceMappingURL=x402-7WBFZQXV.js.map
96
+ //# sourceMappingURL=x402-WLYBLODI.js.map
97
+ //# sourceMappingURL=x402-W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A;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;AACF,GACF;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-WLYBLODI.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 /** 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 };\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
@@ -1,13 +1,11 @@
1
1
  import { Ap2AuthorizationConfig } from './ap2.js';
2
- import { I as IsoTimestamp, D as DecimalAmount, P as PaymentMethodName, a as CommerceResource, b as PaymentSubmission, B as BackendHandler, A as AdapterDescriptor, c as AdapterHealth, R as ResourceRegistry, d as PaymentProvider, L as Logger, C as Clock, e as IdGenerator } from './runtime-Cl_BLVZV.js';
3
- export { f as AdapterHealthComponent, g as AuthorizationMethodName, h as BackendMethod, i as DEFAULT_BACKEND_TIMEOUT_MS, J as JsonSchema, N as NOOP_LOGGER, j as PAYMENT_METHOD_NAMES, k as PROTOCOL_NAMES, l as PaymentChallenge, m as PaymentContext, n as PaymentRequirement, o as PaymentResult, p as PaymentSettlementContext, q as PaymentVerificationContext, r as Pricing, s as ProtocolName, t as systemClock } from './runtime-Cl_BLVZV.js';
2
+ import { I as IsoTimestamp, D as DecimalAmount, P as PaymentMethodName, a as AuthorizationRequirement, b as CommerceResource, c as PaymentSubmission, d as AuthorizationSubmission, B as BackendHandler, e as ProtocolName, f as AuthorizationRecord, g as PaymentAttempt, h as CommerceReceipt, i as PaymentAttemptResolution, j as AdapterDescriptor, k as AdapterHealth, R as ResourceRegistry, l as PaymentProvider, A as AuthorizationProvider, L as Logger, C as Clock, m as IdGenerator } from './runtime-Dz2fSO-P.js';
3
+ export { n as AdapterHealthComponent, o as AuthorizationFinalizeContext, p as AuthorizationMethodName, q as AuthorizationVerification, r as AuthorizationVerificationContext, s as BackendMethod, t as DEFAULT_BACKEND_TIMEOUT_MS, J as JsonSchema, N as NOOP_LOGGER, u as PAYMENT_METHOD_NAMES, v as PROTOCOL_NAMES, w as PaymentChallenge, x as PaymentContext, y as PaymentReconciliationContext, z as PaymentReconciliationResult, E as PaymentRequirement, F as PaymentResult, G as PaymentSettlementContext, H as PaymentVerificationContext, K as Pricing, M as RECONCILIATION_METADATA_KEY, O as systemClock } from './runtime-Dz2fSO-P.js';
4
4
  import { M as MppNetwork } from './constants-BG22tE8S.js';
5
5
  import { X402PaymentFlow, X402FacilitatorConfig } from './x402.js';
6
6
  import { C as CustomNetworks } from './networks-DDHYJLcg.js';
7
- import { a as AuthorizationRequirement, b as AuthorizationSubmission, A as AuthorizationProvider } from './authorization-DjAecwuW.js';
8
- export { c as AuthorizationFinalizeContext, d as AuthorizationRecord, e as AuthorizationVerification, f as AuthorizationVerificationContext } from './authorization-DjAecwuW.js';
9
- import { D as DeliveredOutcome, P as PaymentRequiredOutcome, C as CommerceEvent, a as PaymentAttempt, b as CommerceReceipt, E as ExecutionPipeline, c as ProtocolAdapter, H as HttpProtocolAdapter, A as AdapterHttpRoute, d as ProtocolAdapterContext } from './protocol-adapter-C9odYl6l.js';
10
- export { e as COMMERCE_EVENT_TYPES, f as CanonicalRequest, g as CommerceEventType, h as EventSink, i as ExecutionOutcome, j as isHttpProtocolAdapter } from './protocol-adapter-C9odYl6l.js';
7
+ import { D as DeliveredOutcome, P as PaymentRequiredOutcome, C as CommerceEvent, A as AuthorizationHoldState, a as PersistenceFailure, T as Transaction, b as TransactionState, E as ExecutionPipeline, c as ProtocolAdapter, H as HttpProtocolAdapter, d as AdapterHttpRoute, e as ProtocolAdapterContext } from './protocol-adapter-DEXpdp8m.js';
8
+ export { f as COMMERCE_EVENT_TYPES, g as CanonicalRequest, h as CommerceEventType, i as EventSink, j as ExecutionOutcome, k as TRANSACTION_STATES, l as TransactionFacts, m as isHttpProtocolAdapter, t as transactionState } from './protocol-adapter-DEXpdp8m.js';
11
9
  import { FastifyInstance } from 'fastify';
12
10
  import { IncomingMessage, ServerResponse } from 'node:http';
13
11
 
@@ -154,13 +152,19 @@ interface PaymentRequiredEnvelope {
154
152
  readonly amount: DecimalAmount;
155
153
  readonly currency: string;
156
154
  /**
157
- * @deprecated Read each offer's `payTo` in `accepts`. Absent when the
158
- * challenge offers several destinations.
155
+ * @deprecated Read `accepts`: x402 offers use `payTo`; MPP challenges use
156
+ * `request.recipient`. Omitted for multi-offer x402 challenges.
159
157
  */
160
158
  readonly destination?: string;
161
- /** @deprecated Read each offer's `network` in `accepts` */
159
+ /**
160
+ * @deprecated Read `accepts`: x402 offers use `network`; MPP challenges use
161
+ * the numeric `request.methodDetails.chainId`
162
+ */
162
163
  readonly network?: string;
163
- /** @deprecated Read each offer's `asset` in `accepts` */
164
+ /**
165
+ * @deprecated Read `accepts`: x402 offers use `asset`; MPP challenges use
166
+ * `request.currency`
167
+ */
164
168
  readonly asset?: string;
165
169
  readonly expiresAt?: IsoTimestamp;
166
170
  /** Provider-native requirement objects, passed through verbatim */
@@ -202,6 +206,8 @@ interface DeliverySummary {
202
206
  readonly requestId: string;
203
207
  readonly resourceId: string;
204
208
  readonly receiptId: string;
209
+ /** `false` marks a failed receipt write; do not treat `receiptId` as proof of persistence */
210
+ readonly receiptCommitted?: false;
205
211
  readonly deliveredAt: IsoTimestamp;
206
212
  readonly payment?: {
207
213
  readonly status: 'verified' | 'settled' | 'rejected';
@@ -318,6 +324,84 @@ interface PaymentAttemptReservation {
318
324
  * until settled.
319
325
  */
320
326
  readonly reclaimRejected?: boolean;
327
+ /**
328
+ * Journal data to write atomically with the reservation. Stores without
329
+ * journal support ignore it.
330
+ */
331
+ readonly transaction?: NewTransaction;
332
+ }
333
+ /**
334
+ * Data for a journal row opened with a replay reservation. Journal stores
335
+ * must initialize an included authorization hold as `reserved`. The reservation
336
+ * supplies the request, resource, provider, replay key, amount, currency and
337
+ * payee. Experimental: may change in a minor release.
338
+ */
339
+ interface NewTransaction {
340
+ readonly id: string;
341
+ readonly protocol: ProtocolName;
342
+ readonly network?: string;
343
+ readonly asset?: string;
344
+ readonly locator?: Readonly<Record<string, unknown>>;
345
+ readonly expiresAt?: IsoTimestamp;
346
+ readonly authorization?: AuthorizationRecord & {
347
+ readonly reservationId: string;
348
+ };
349
+ readonly inputDigest?: string;
350
+ readonly configDigest: string;
351
+ }
352
+ /**
353
+ * A journal update after replay reservation. Experimental: may change in a
354
+ * minor release.
355
+ */
356
+ type TransactionStep = {
357
+ readonly transactionId: string;
358
+ readonly at: IsoTimestamp;
359
+ } & ({
360
+ readonly kind: 'settling';
361
+ } | {
362
+ readonly kind: 'hold';
363
+ readonly hold: AuthorizationHoldState;
364
+ } | {
365
+ readonly kind: 'backend-dispatched';
366
+ readonly deadlineAt: IsoTimestamp;
367
+ } | {
368
+ readonly kind: 'backend-result';
369
+ readonly status: number;
370
+ readonly errorCode?: string;
371
+ } | {
372
+ readonly kind: 'receipt';
373
+ readonly receiptId: string;
374
+ } | {
375
+ readonly kind: 'completed';
376
+ readonly persistenceFailures?: readonly PersistenceFailure[];
377
+ });
378
+ /** Experimental: may change in a minor release */
379
+ interface TransactionListOptions extends ListOptions {
380
+ /** Opaque cursor from a previous page's `nextCursor` */
381
+ readonly cursor?: string;
382
+ readonly state?: TransactionState;
383
+ /** When true, exclude `delivered` and `payment-failed` states */
384
+ readonly unresolved?: boolean;
385
+ /** When true, filter for `reserved` or `uncertain` authorization holds */
386
+ readonly pendingHold?: boolean;
387
+ }
388
+ /** Transactions in newest-first order. Experimental: may change in a minor release */
389
+ interface TransactionPage {
390
+ readonly transactions: readonly Transaction[];
391
+ /**
392
+ * Continue with this cursor even when filtering returns fewer than `limit`
393
+ * transactions, including an empty page. Pagination ends when it is absent.
394
+ */
395
+ readonly nextCursor?: string;
396
+ }
397
+ /** Experimental: may change in a minor release */
398
+ interface PaymentAttemptResolveRequest {
399
+ readonly attemptId: string;
400
+ /** Update only if the attempt still has this status and no resolution */
401
+ readonly expectedStatus: PaymentAttempt['status'];
402
+ readonly status: 'settled' | 'rejected';
403
+ readonly rejectionReason?: string;
404
+ readonly resolution: PaymentAttemptResolution;
321
405
  }
322
406
  interface PaymentAttemptUpdate {
323
407
  readonly replayKey: string;
@@ -358,6 +442,7 @@ interface ReceiptStore {
358
442
  * new reservation.
359
443
  */
360
444
  reservePaymentAttempt(reservation: PaymentAttemptReservation): Promise<PaymentAttempt>;
445
+ /** Must not change an attempt that has a resolution; the SQLite store throws `STORAGE_ERROR` */
361
446
  updatePaymentAttempt(update: PaymentAttemptUpdate): Promise<void>;
362
447
  saveReceipt(receipt: CommerceReceipt): Promise<void>;
363
448
  getReceipt(id: string): Promise<CommerceReceipt | undefined>;
@@ -388,6 +473,21 @@ interface ReceiptStore {
388
473
  countUncertainPaymentAttempts(): Promise<number>;
389
474
  listEvents(options?: ListOptions): Promise<readonly CommerceEvent[]>;
390
475
  listPaymentAttempts(options?: PaymentAttemptListOptions): Promise<readonly PaymentAttempt[]>;
476
+ /**
477
+ * Record a journal step. Journal methods are optional for compatibility with
478
+ * stores that do not support the journal. Implementations must also recompute
479
+ * a transaction's cached state atomically with payment-attempt updates.
480
+ * Experimental: may change in a minor release.
481
+ */
482
+ recordTransactionStep?(step: TransactionStep): Promise<void>;
483
+ getTransaction?(id: string): Promise<Transaction | undefined>;
484
+ listTransactions?(options?: TransactionListOptions): Promise<TransactionPage>;
485
+ getPaymentAttempt?(id: string): Promise<PaymentAttempt | undefined>;
486
+ /**
487
+ * Compare-and-set: return `false` without writing if the attempt's status
488
+ * differs from `expectedStatus` or it already has a resolution
489
+ */
490
+ resolvePaymentAttempt?(request: PaymentAttemptResolveRequest): Promise<boolean>;
391
491
  readonly descriptor: AdapterDescriptor;
392
492
  health(): Promise<AdapterHealth>;
393
493
  close(): Promise<void>;
@@ -747,5 +847,5 @@ interface SqliteReceiptStoreOptions {
747
847
  }
748
848
  declare function createSqliteReceiptStore(options: SqliteReceiptStoreOptions): ReceiptStore;
749
849
 
750
- 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, CommerceEvent, CommerceReceipt, 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, PaymentAttempt, PaymentMethodName, PaymentProvider, PaymentRequiredOutcome, PaymentSubmission, ProtocolAdapter, ProtocolAdapterContext, RESERVED_INPUT_FIELDS, RETRYABLE_ERROR_CODES, ResourceRegistry, createA2aAdapter, createAcpAdapter, createGateway, createSqliteReceiptStore, extractReservedInputFields, isCommerceError, isPaymentRequiredEnvelope, loadConfig, parseAuthorizationHeader, parseAuthorizationSubmission, parseConfig, createSqliteReceiptStore as receipts, toCommerceError, toDeliverySummary, toErrorEnvelope, toPaymentRequiredEnvelope };
751
- export type { A2aAdapterOptions, AcpAdapterOptions, BackendExecutor, BackendRequest, BackendResponse, CommerceErrorCode, CommerceErrorInfo, CommerceErrorOptions, DeliverySummary, ErrorEnvelope, GatewayConfig, GatewayInstance, GatewayOptions, ListOptions, PaymentAttemptListOptions, PaymentAttemptReservation, PaymentAttemptUpdate, PaymentRequiredEnvelope, ReceiptListOptions, ReceiptStore };
850
+ 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, AuthorizationHoldState, AuthorizationProvider, AuthorizationRecord, AuthorizationRequirement, AuthorizationSubmission, BackendHandler, COMMERCE_ERROR_CODES, COMMERCE_ERROR_HTTP_STATUS, Clock, CommerceError, CommerceEvent, CommerceReceipt, 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, PaymentAttempt, PaymentAttemptResolution, PaymentMethodName, PaymentProvider, PaymentRequiredOutcome, PaymentSubmission, PersistenceFailure, ProtocolAdapter, ProtocolAdapterContext, ProtocolName, RESERVED_INPUT_FIELDS, RETRYABLE_ERROR_CODES, ResourceRegistry, Transaction, TransactionState, createA2aAdapter, createAcpAdapter, createGateway, createSqliteReceiptStore, extractReservedInputFields, isCommerceError, isPaymentRequiredEnvelope, loadConfig, parseAuthorizationHeader, parseAuthorizationSubmission, parseConfig, createSqliteReceiptStore as receipts, toCommerceError, toDeliverySummary, toErrorEnvelope, toPaymentRequiredEnvelope };
851
+ export type { A2aAdapterOptions, AcpAdapterOptions, BackendExecutor, BackendRequest, BackendResponse, CommerceErrorCode, CommerceErrorInfo, CommerceErrorOptions, DeliverySummary, ErrorEnvelope, GatewayConfig, GatewayInstance, GatewayOptions, ListOptions, NewTransaction, PaymentAttemptListOptions, PaymentAttemptReservation, PaymentAttemptResolveRequest, PaymentAttemptUpdate, PaymentRequiredEnvelope, ReceiptListOptions, ReceiptStore, TransactionListOptions, TransactionPage, TransactionStep };