@devlab.group/agent-commerce 2.7.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 (59) hide show
  1. package/dist/ap2.js +1 -1
  2. package/dist/{chunk-EMKITGVV.js → chunk-5AO5N2XY.js} +9 -3
  3. package/dist/chunk-5AO5N2XY.js.map +1 -0
  4. package/dist/{chunk-ZSIUZPNB.js → chunk-5VW32JPV.js} +30 -18
  5. package/dist/chunk-5VW32JPV.js.map +1 -0
  6. package/dist/chunk-IGXQMAKM.js +8 -0
  7. package/dist/{chunk-O3ACF45K.js.map → chunk-IGXQMAKM.js.map} +1 -1
  8. package/dist/cli/{ap2-5FFGSW6F.js → ap2-NTYL7H4I.js} +3 -3
  9. package/dist/cli/{ap2-5FFGSW6F.js.map → ap2-NTYL7H4I.js.map} +1 -1
  10. package/dist/cli/chunk-2M2RF3CT.js +8 -0
  11. package/dist/cli/{chunk-ZCW56PZ3.js.map → chunk-2M2RF3CT.js.map} +1 -1
  12. package/dist/cli/{chunk-5TID36YG.js → chunk-A42BCWZ2.js} +3 -3
  13. package/dist/cli/{chunk-5TID36YG.js.map → chunk-A42BCWZ2.js.map} +1 -1
  14. package/dist/cli/{chunk-5K2JDM4G.js → chunk-EVCIEKHN.js} +30 -18
  15. package/dist/cli/chunk-EVCIEKHN.js.map +1 -0
  16. package/dist/cli/{chunk-AGQ4U7IN.js → chunk-FETTSOMT.js} +9 -3
  17. package/dist/cli/chunk-FETTSOMT.js.map +1 -0
  18. package/dist/cli/{chunk-ZFVQWOGG.js → chunk-GBBG66O6.js} +18 -5
  19. package/dist/cli/chunk-GBBG66O6.js.map +1 -0
  20. package/dist/cli/{chunk-PLHPKXAT.js → chunk-MBPOKPQM.js} +5 -5
  21. package/dist/cli/{chunk-PLHPKXAT.js.map → chunk-MBPOKPQM.js.map} +1 -1
  22. package/dist/cli/{config-WT5HHDRR.js → config-ODN4IEMZ.js} +4 -4
  23. package/dist/cli/{config-WT5HHDRR.js.map → config-ODN4IEMZ.js.map} +1 -1
  24. package/dist/cli/index.js +7 -7
  25. package/dist/cli/index.js.map +1 -1
  26. package/dist/cli/{mcp-HHGNOUKE.js → mcp-V27OKTOV.js} +3 -3
  27. package/dist/cli/{mcp-HHGNOUKE.js.map → mcp-V27OKTOV.js.map} +1 -1
  28. package/dist/cli/payment-providers-SUATT75K.js +6 -0
  29. package/dist/cli/{payment-providers-EWXZFBIE.js.map → payment-providers-SUATT75K.js.map} +1 -1
  30. package/dist/cli/{provider-XUPLYNQ7.js → provider-C3QDAXMR.js} +5 -5
  31. package/dist/cli/{provider-XUPLYNQ7.js.map → provider-C3QDAXMR.js.map} +1 -1
  32. package/dist/cli/{receipts-3DSV4DIK.js → receipts-ZS3VZ2D4.js} +4 -4
  33. package/dist/cli/{receipts-3DSV4DIK.js.map → receipts-ZS3VZ2D4.js.map} +1 -1
  34. package/dist/cli/{run-7KLKW3HE.js → run-WYFZUO5D.js} +44 -20
  35. package/dist/cli/{run-7KLKW3HE.js.map → run-WYFZUO5D.js.map} +1 -1
  36. package/dist/cli/{svm-KDSPDFJG.js → svm-NBZY7H6W.js} +9 -6
  37. package/dist/cli/svm-NBZY7H6W.js.map +1 -0
  38. package/dist/cli/{x402-HP4E3QET.js → x402-UGLZ3LA7.js} +6 -6
  39. package/dist/cli/{x402-HP4E3QET.js.map → x402-UGLZ3LA7.js.map} +1 -1
  40. package/dist/index.d.ts +3 -3
  41. package/dist/index.js +52 -15
  42. package/dist/index.js.map +1 -1
  43. package/dist/mcp.js +1 -1
  44. package/dist/mpp.js +3 -3
  45. package/dist/{store-BVvMzpuV.d.ts → store-DQwbKhnc.d.ts} +1 -1
  46. package/dist/{svm-KNC3PHMS.js → svm-4HR5OEP7.js} +9 -6
  47. package/dist/svm-4HR5OEP7.js.map +1 -0
  48. package/dist/x402.js +4 -4
  49. package/package.json +1 -1
  50. package/dist/chunk-EMKITGVV.js.map +0 -1
  51. package/dist/chunk-O3ACF45K.js +0 -8
  52. package/dist/chunk-ZSIUZPNB.js.map +0 -1
  53. package/dist/cli/chunk-5K2JDM4G.js.map +0 -1
  54. package/dist/cli/chunk-AGQ4U7IN.js.map +0 -1
  55. package/dist/cli/chunk-ZCW56PZ3.js +0 -8
  56. package/dist/cli/chunk-ZFVQWOGG.js.map +0 -1
  57. package/dist/cli/payment-providers-EWXZFBIE.js +0 -6
  58. package/dist/cli/svm-KDSPDFJG.js.map +0 -1
  59. package/dist/svm-KNC3PHMS.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import { LOCATOR_VERSION, computeSvmReplayKey } from './chunk-663ALDZA.js';
2
2
  import { isRecord } from './chunk-3M6U7ILB.js';
3
- import { getAddressEncoder, getProgramDerivedAddress, address, getCompiledTransactionMessageDecoder } from '@solana/kit';
4
- import { decodeTransactionFromPayload, transactionMessageHash } from '@x402/svm';
3
+ import { getAddressEncoder, getProgramDerivedAddress, address, getCompiledTransactionMessageDecoder, getTransactionDecoder, getBase64Encoder } from '@solana/kit';
4
+ import { transactionMessageHash } from '@x402/svm';
5
5
 
6
6
  var MAX_TRANSACTION_BASE64 = 1644;
7
7
  var ASSOCIATED_TOKEN_PROGRAM = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
@@ -22,7 +22,7 @@ function inspectSvmPayload(payload, network) {
22
22
  let messageHash;
23
23
  let recentBlockhash;
24
24
  try {
25
- const decoded = decodeTransactionFromPayload({ transaction });
25
+ const decoded = decodeTransaction(transaction);
26
26
  messageHash = transactionMessageHash(decoded);
27
27
  recentBlockhash = getCompiledTransactionMessageDecoder().decode(
28
28
  decoded.messageBytes
@@ -37,12 +37,15 @@ function inspectSvmPayload(payload, network) {
37
37
  }
38
38
  function messageHashOf(transaction) {
39
39
  try {
40
- return transactionMessageHash(decodeTransactionFromPayload({ transaction }));
40
+ return transactionMessageHash(decodeTransaction(transaction));
41
41
  } catch {
42
42
  return void 0;
43
43
  }
44
44
  }
45
+ function decodeTransaction(base64) {
46
+ return getTransactionDecoder().decode(getBase64Encoder().encode(base64));
47
+ }
45
48
 
46
49
  export { associatedTokenAccount, inspectSvmPayload, messageHashOf };
47
- //# sourceMappingURL=svm-KDSPDFJG.js.map
48
- //# sourceMappingURL=svm-KDSPDFJG.js.map
50
+ //# sourceMappingURL=svm-NBZY7H6W.js.map
51
+ //# sourceMappingURL=svm-NBZY7H6W.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/payments/x402/svm.ts"],"names":[],"mappings":";;;;;AAyBA,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,KAAA,EAAO,CAAC,KAAA,EAAO,YAAA,EAAc,IAAI,CAAA,CAAE,GAAA,CAAI,CAAC,GAAA,KAAQ,OAAA,CAAQ,MAAA,CAAO,OAAA,CAAQ,GAAG,CAAC,CAAC;AAAA,GAC7E,CAAA;AACD,EAAA,OAAO,OAAA;AACT;AAOO,SAAS,iBAAA,CACd,SACA,OAAA,EAC8F;AAC9F,EAAA,IAAI,CAAC,QAAA,CAAS,OAAO,CAAA,EAAG,OAAO,uCAAA;AAC/B,EAAA,MAAM,WAAA,GAAc,QAAQ,aAAa,CAAA;AACzC,EAAA,IAAI,OAAO,WAAA,KAAgB,QAAA,IAAY,WAAA,CAAY,SAAS,sBAAA,EAAwB;AAClF,IAAA,OAAO,uCAAA;AAAA,EACT;AACA,EAAA,IAAI,WAAA;AACJ,EAAA,IAAI,eAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAM,OAAA,GAAU,kBAAkB,WAAW,CAAA;AAC7C,IAAA,WAAA,GAAc,uBAAuB,OAAO,CAAA;AAC5C,IAAA,eAAA,GAAkB,sCAAqC,CAAE,MAAA;AAAA,MACvD,OAAA,CAAQ;AAAA,KACV,CAAE,aAAA;AAAA,EACJ,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,4DAAA;AAAA,EACT;AACA,EAAA,OAAO;AAAA,IACL,SAAA,EAAW,mBAAA,CAAoB,EAAE,OAAA,EAAS,aAAa,CAAA;AAAA,IACvD,SAAS,EAAE,CAAA,EAAG,eAAA,EAAiB,OAAA,EAAS,aAAa,eAAA;AAAgB,GACvE;AACF;AAMO,SAAS,cAAc,WAAA,EAAyC;AACrE,EAAA,IAAI;AACF,IAAA,OAAO,sBAAA,CAAuB,iBAAA,CAAkB,WAAW,CAAC,CAAA;AAAA,EAC9D,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAIA,SAAS,kBAAkB,MAAA,EAA6B;AACtD,EAAA,OAAO,uBAAsB,CAAE,MAAA,CAAO,kBAAiB,CAAE,MAAA,CAAO,MAAM,CAAC,CAAA;AACzE","file":"svm-NBZY7H6W.js","sourcesContent":["/**\n * Solana `exact` payload 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 getBase64Encoder,\n getCompiledTransactionMessageDecoder,\n getProgramDerivedAddress,\n getTransactionDecoder,\n type Transaction,\n} from '@solana/kit';\nimport { 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 = decodeTransaction(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(decodeTransaction(transaction));\n } catch {\n return undefined;\n }\n}\n\n// Match decodeTransactionFromPayload without its failure logging, which exposes\n// caller input and a stack trace through console.error\nfunction decodeTransaction(base64: string): Transaction {\n return getTransactionDecoder().decode(getBase64Encoder().encode(base64));\n}\n"]}
@@ -1,8 +1,8 @@
1
- import { chainIdFromCaip2 } from './chunk-5K2JDM4G.js';
2
- export { createX402PaymentProvider } from './chunk-5K2JDM4G.js';
3
- import './chunk-AGQ4U7IN.js';
1
+ import { chainIdFromCaip2 } from './chunk-EVCIEKHN.js';
2
+ export { createX402PaymentProvider } from './chunk-EVCIEKHN.js';
3
+ import './chunk-FETTSOMT.js';
4
4
  export { SUPPORTED_NETWORK_IDS } from './chunk-66NTYSXI.js';
5
- import './chunk-ZCW56PZ3.js';
5
+ import './chunk-2M2RF3CT.js';
6
6
  import './chunk-55AI6CLW.js';
7
7
  import { CommerceError } from './chunk-C5YISPT6.js';
8
8
  import './chunk-663ALDZA.js';
@@ -94,5 +94,5 @@ function randomNonce() {
94
94
  }
95
95
 
96
96
  export { createPaymentProof };
97
- //# sourceMappingURL=x402-HP4E3QET.js.map
98
- //# sourceMappingURL=x402-HP4E3QET.js.map
97
+ //# sourceMappingURL=x402-UGLZ3LA7.js.map
98
+ //# sourceMappingURL=x402-UGLZ3LA7.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;AA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,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-HP4E3QET.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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A,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-UGLZ3LA7.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
@@ -7,8 +7,8 @@ import { C as CustomNetworks } from './networks-DDHYJLcg.js';
7
7
  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-BXXJltZ-.js';
8
8
  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-DdFL5LBU.js';
9
9
  export { C as CanonicalRequest, c as ExecutionOutcome, i as isHttpProtocolAdapter } from './protocol-adapter-DdFL5LBU.js';
10
- import { R as ReceiptStore } from './store-BVvMzpuV.js';
11
- 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-BVvMzpuV.js';
10
+ import { R as ReceiptStore } from './store-DQwbKhnc.js';
11
+ 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-DQwbKhnc.js';
12
12
  import { L as Logger } from './logger-CllGwQ8i.js';
13
13
  export { N as NOOP_LOGGER } from './logger-CllGwQ8i.js';
14
14
  import { FastifyInstance } from 'fastify';
@@ -740,7 +740,7 @@ interface SqliteReceiptStoreSummary {
740
740
  readonly orphanHolds: number;
741
741
  /** Unresolved claims whose endpoints do not start with `payment:` */
742
742
  readonly unresolvedIdempotencyKeys: number;
743
- /** Unresolved claims whose endpoints start with `payment:` */
743
+ /** Unexpired unresolved claims whose endpoints start with `payment:` */
744
744
  readonly unresolvedPaymentKeys: number;
745
745
  readonly unexpiredPendingTasks: number;
746
746
  readonly legacyImports: readonly SqliteLegacyImport[];
package/dist/index.js CHANGED
@@ -2,8 +2,8 @@ import { openSqliteDatabase, AP2_SPEC_VERSION, AP2_MODES, AP2_DEFAULT_CLOCK_SKEW
2
2
  import { readCappedBody, createBearerCheck, MCP_TOOL_NAME_PATTERN, settlementResponse, joinUrl, settlementResponseFromDetails, settlementFailure, x402ErrorCode, x402RefusalStatus } from './chunk-77HLISG4.js';
3
3
  import { MPP_DEFAULT_NETWORK, isMppNetwork, MPP_NETWORKS, MPP_DEFAULT_PAYMENT_FLOW, MPP_MIN_CHALLENGE_SECRET_LENGTH, MPP_PROFILE } from './chunk-6Z2H53CG.js';
4
4
  import { contentDigest, CONTENT_DIGEST_METADATA_KEY, mppProblem, mppProblemDetail } from './chunk-D7FPSGUQ.js';
5
- import { X402_PAYMENT_FLOWS, validateCustomNetworks, findX402Network, X402_DEFAULT_PAYMENT_FLOW, resolveX402Deployment, resolveDeploymentMode, requireX402Network, resolveX402Option, isEvmAddress, isEvmZeroAddress, SETTLE_AFTER_BACKEND_METADATA_KEY, x402OfferName, REUSE_REJECTED_AUTHORIZATION_METADATA_KEY, canonicalJson } from './chunk-EMKITGVV.js';
6
- import { PACKAGE_VERSION } from './chunk-O3ACF45K.js';
5
+ import { X402_PAYMENT_FLOWS, validateCustomNetworks, findX402Network, X402_DEFAULT_PAYMENT_FLOW, resolveX402Deployment, resolveDeploymentMode, requireX402Network, resolveX402Option, isEvmAddress, isEvmZeroAddress, SETTLE_AFTER_BACKEND_METADATA_KEY, x402OfferName, REUSE_REJECTED_AUTHORIZATION_METADATA_KEY, canonicalJson } from './chunk-5AO5N2XY.js';
6
+ import { PACKAGE_VERSION } from './chunk-IGXQMAKM.js';
7
7
  import { PAYMENT_KEY_ENDPOINT_PREFIX } from './chunk-IWXVQYG5.js';
8
8
  import { hasMethodGroup } from './chunk-WDD2ZUR3.js';
9
9
  import { RESERVED_INPUT_FIELDS, PROTOCOL_NAMES, PAYMENT_METHOD_NAMES, PAYMENT_HEADER, AUTHORIZATION_HEADER, CommerceError, systemClock, NOOP_LOGGER, transactionState, DEFAULT_BACKEND_TIMEOUT_MS, isCommerceError, describeError, isHttpProtocolAdapter, toLogInfo, toCommerceError, extractReservedInputFields, parseAuthorizationHeader, toPaymentRequiredEnvelope, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, toErrorEnvelope, DELIVERY_SUMMARY_META_KEY, toDeliverySummary, PAYMENT_INPUT_FIELD, AUTHORIZATION_INPUT_FIELD, parseAuthorizationSubmission, RECONCILIATION_METADATA_KEY, TRANSACTION_STATES, redactedErrorText } from './chunk-YHNTTMED.js';
@@ -3372,7 +3372,10 @@ function normalizeResource(id, entry, protocols, x402, mpp, ap2) {
3372
3372
  { details: { path: `resources.${id}.mimeType`, resourceId: id } }
3373
3373
  );
3374
3374
  }
3375
- const idempotency = normalizeResourceIdempotency(id, entry, paymentMethods);
3375
+ const servingRail = paymentMethods.find(
3376
+ (method) => method === "x402" && x402?.config.enabled === true || method === "mpp" && mpp?.enabled === true
3377
+ );
3378
+ const idempotency = normalizeResourceIdempotency(id, entry, paymentMethods, servingRail);
3376
3379
  const pricing = entry.pricing.type === "free" ? { type: "free" } : { type: "fixed", amount: entry.pricing.amount, currency: entry.pricing.currency };
3377
3380
  const authorization = normalizeResourceAuthorization(id, entry, pricing, ap2);
3378
3381
  return {
@@ -3400,7 +3403,7 @@ function normalizeResource(id, entry, protocols, x402, mpp, ap2) {
3400
3403
  ...idempotency !== void 0 ? { idempotency } : {}
3401
3404
  };
3402
3405
  }
3403
- function normalizeResourceIdempotency(id, entry, paymentMethods) {
3406
+ function normalizeResourceIdempotency(id, entry, paymentMethods, servingRail) {
3404
3407
  const raw = entry.idempotency;
3405
3408
  if (raw === void 0) return void 0;
3406
3409
  const path2 = `resources.${id}.idempotency`;
@@ -3422,6 +3425,11 @@ function normalizeResourceIdempotency(id, entry, paymentMethods) {
3422
3425
  `${path2}.redelivery.required`
3423
3426
  );
3424
3427
  }
3428
+ if (required && servingRail !== void 0 && servingRail !== "x402") {
3429
+ console.warn(
3430
+ `[agent-commerce] Resource "${id}" sets idempotency.redelivery.required, which applies to x402 only, but the gateway serves it on ${servingRail}, the first enabled rail in its payments. The setting has no effect; list "x402" first or remove it.`
3431
+ );
3432
+ }
3425
3433
  redelivery = {
3426
3434
  retentionHours: toNumber(
3427
3435
  raw.redelivery.retentionHours ?? DEFAULT_REDELIVERY_RETENTION_HOURS,
@@ -3522,6 +3530,11 @@ function normalize(raw) {
3522
3530
  { details: { path: "protocols.a2a.enabled" } }
3523
3531
  );
3524
3532
  }
3533
+ if (!isHttpUrl(raw.merchant.publicBaseUrl)) {
3534
+ console.warn(
3535
+ `[agent-commerce] merchant.publicBaseUrl ${JSON.stringify(raw.merchant.publicBaseUrl)} is not an http:// or https:// URL. The Host check may then refuse every caller but loopback, and the A2A Agent Card and ACP discovery publish broken URLs.`
3536
+ );
3537
+ }
3525
3538
  return {
3526
3539
  version: SUPPORTED_CONFIG_VERSION,
3527
3540
  merchant: {
@@ -4252,7 +4265,7 @@ var AUTHORIZATION_PROVIDER_DETAIL = {
4252
4265
  warn: "authorization-provider-degraded",
4253
4266
  fail: "authorization-provider-unreachable"
4254
4267
  };
4255
- async function probe(target, kind, details, options) {
4268
+ async function probe(target, kind, details, options, failing) {
4256
4269
  let health;
4257
4270
  let threw = false;
4258
4271
  try {
@@ -4263,7 +4276,16 @@ async function probe(target, kind, details, options) {
4263
4276
  health = { status: "fail", checkedAt: options.clock.nowIso() };
4264
4277
  threw = true;
4265
4278
  }
4266
- if (health.detail !== void 0) {
4279
+ const key = `${kind}:${target.name}`;
4280
+ const startsFailing = health.status === "fail" && !failing.has(key);
4281
+ if (health.status === "fail") failing.add(key);
4282
+ else failing.delete(key);
4283
+ if (startsFailing && !threw) {
4284
+ options.logger.warn(
4285
+ { name: target.name, ...health.detail !== void 0 ? { detail: health.detail } : {} },
4286
+ `${kind} health check failed (detail not sent to the client)`
4287
+ );
4288
+ } else if (health.detail !== void 0) {
4267
4289
  options.logger.debug(
4268
4290
  { name: target.name, detail: health.detail },
4269
4291
  `${kind} health detail (not sent to the client)`
@@ -4279,25 +4301,32 @@ async function probe(target, kind, details, options) {
4279
4301
  health
4280
4302
  };
4281
4303
  }
4282
- async function evaluate(options) {
4304
+ async function evaluate(options, failing) {
4283
4305
  const [store, adapters, paymentProviders, authorizationProviders] = await Promise.all([
4284
- probe({ name: "store", health: () => options.store.health() }, "store", STORE_DETAIL, options),
4306
+ probe(
4307
+ { name: "store", health: () => options.store.health() },
4308
+ "store",
4309
+ STORE_DETAIL,
4310
+ options,
4311
+ failing
4312
+ ),
4285
4313
  Promise.all(
4286
4314
  options.adapterRuntimes.map(async (runtime) => ({
4287
4315
  runtime,
4288
4316
  probed: await probe(
4289
- // getAdapterHealth turns a throw into a failed result, so an adapter
4290
- // failure is logged at debug as a detail rather than at error
4317
+ // getAdapterHealth converts throws to failed results, which use
4318
+ // the logging rules for returned results
4291
4319
  { name: runtime.adapter.name, health: () => getAdapterHealth(runtime, options.clock) },
4292
4320
  "adapter",
4293
4321
  ADAPTER_DETAIL,
4294
- options
4322
+ options,
4323
+ failing
4295
4324
  )
4296
4325
  }))
4297
4326
  ),
4298
4327
  Promise.all(
4299
4328
  options.paymentProviders.map(
4300
- (provider) => probe(provider, "payment provider", PAYMENT_PROVIDER_DETAIL, options)
4329
+ (provider) => probe(provider, "payment provider", PAYMENT_PROVIDER_DETAIL, options, failing)
4301
4330
  )
4302
4331
  ),
4303
4332
  // An unusable authorization provider blocks readiness on the same threshold
@@ -4305,7 +4334,7 @@ async function evaluate(options) {
4305
4334
  // without it, and serving the challenge anyway promises what we cannot honor
4306
4335
  Promise.all(
4307
4336
  options.authorizationProviders.map(
4308
- (provider) => probe(provider, "authorization provider", AUTHORIZATION_PROVIDER_DETAIL, options)
4337
+ (provider) => probe(provider, "authorization provider", AUTHORIZATION_PROVIDER_DETAIL, options, failing)
4309
4338
  )
4310
4339
  )
4311
4340
  ]);
@@ -4337,11 +4366,12 @@ var READINESS_TTL_MS = 2e3;
4337
4366
  function createReadinessProbe(options, ttlMs = READINESS_TTL_MS) {
4338
4367
  let cached;
4339
4368
  let inFlight;
4369
+ const failing = /* @__PURE__ */ new Set();
4340
4370
  const current = async () => {
4341
4371
  const now = options.clock.monotonicMs();
4342
4372
  if (cached && now - cached.at < ttlMs) return cached.evaluation;
4343
4373
  if (inFlight) return inFlight;
4344
- inFlight = evaluate(options).then((evaluation) => {
4374
+ inFlight = evaluate(options, failing).then((evaluation) => {
4345
4375
  cached = { evaluation, at: options.clock.monotonicMs() };
4346
4376
  return evaluation;
4347
4377
  }).finally(() => {
@@ -4766,7 +4796,14 @@ async function handleInvoke(request, reply, options) {
4766
4796
  }
4767
4797
  reply.status(outcome.backendStatus).send(outcome.body);
4768
4798
  } catch (error) {
4769
- sendInvokeError(reply, toCommerceError(error), paymentMethod);
4799
+ const commerceError = toCommerceError(error);
4800
+ const entry = { resourceId, requestId: request.id, err: toLogInfo(commerceError) };
4801
+ if (commerceError.httpStatus >= 500) {
4802
+ options.logger.warn(entry, "http adapter: execution failed");
4803
+ } else {
4804
+ options.logger.debug(entry, "http adapter: execution failed");
4805
+ }
4806
+ sendInvokeError(reply, commerceError, paymentMethod);
4770
4807
  }
4771
4808
  }
4772
4809
  function relayedContentType(header2, body) {