x402-evm-mantle 2.1.2-mantle → 2.1.4-mantle

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 (55) hide show
  1. package/dist/cjs/exact/client/index.d.ts +3 -3
  2. package/dist/cjs/exact/client/index.js +4 -3
  3. package/dist/cjs/exact/client/index.js.map +1 -1
  4. package/dist/cjs/exact/facilitator/index.d.ts +3 -3
  5. package/dist/cjs/exact/facilitator/index.js +8 -5
  6. package/dist/cjs/exact/facilitator/index.js.map +1 -1
  7. package/dist/cjs/exact/server/index.d.ts +3 -3
  8. package/dist/cjs/exact/server/index.js +4 -3
  9. package/dist/cjs/exact/server/index.js.map +1 -1
  10. package/dist/cjs/exact/v1/client/index.d.ts +1 -1
  11. package/dist/cjs/exact/v1/client/index.js +3 -2
  12. package/dist/cjs/exact/v1/client/index.js.map +1 -1
  13. package/dist/cjs/exact/v1/facilitator/index.d.ts +1 -1
  14. package/dist/cjs/exact/v1/facilitator/index.js +5 -3
  15. package/dist/cjs/exact/v1/facilitator/index.js.map +1 -1
  16. package/dist/cjs/index.d.ts +1 -1
  17. package/dist/cjs/index.js +3 -2
  18. package/dist/cjs/index.js.map +1 -1
  19. package/dist/cjs/v1/index.d.ts +1 -1
  20. package/dist/cjs/v1/index.js +3 -2
  21. package/dist/cjs/v1/index.js.map +1 -1
  22. package/dist/esm/{chunk-S5OEANGR.mjs → chunk-5LUDTJAO.mjs} +6 -3
  23. package/dist/esm/chunk-5LUDTJAO.mjs.map +1 -0
  24. package/dist/esm/{chunk-DI3EK7PR.mjs → chunk-7ZPC6XGA.mjs} +8 -4
  25. package/dist/esm/chunk-7ZPC6XGA.mjs.map +1 -0
  26. package/dist/esm/{chunk-T3FPOH7F.mjs → chunk-CB5UEAJV.mjs} +6 -3
  27. package/dist/esm/chunk-CB5UEAJV.mjs.map +1 -0
  28. package/dist/esm/chunk-NSSMTXJJ.mjs +8 -0
  29. package/dist/esm/chunk-NSSMTXJJ.mjs.map +1 -0
  30. package/dist/esm/{chunk-CYGMVQCG.mjs → chunk-ZYXTTU74.mjs} +1 -1
  31. package/dist/esm/chunk-ZYXTTU74.mjs.map +1 -0
  32. package/dist/esm/exact/client/index.mjs +5 -4
  33. package/dist/esm/exact/client/index.mjs.map +1 -1
  34. package/dist/esm/exact/facilitator/index.mjs +9 -5
  35. package/dist/esm/exact/facilitator/index.mjs.map +1 -1
  36. package/dist/esm/exact/server/index.mjs +6 -2
  37. package/dist/esm/exact/server/index.mjs.map +1 -1
  38. package/dist/esm/exact/v1/client/index.mjs +3 -2
  39. package/dist/esm/exact/v1/facilitator/index.mjs +3 -2
  40. package/dist/esm/index.mjs +3 -2
  41. package/dist/esm/index.mjs.map +1 -1
  42. package/dist/esm/v1/index.mjs +4 -3
  43. package/package.json +2 -2
  44. package/dist/esm/chunk-CYGMVQCG.mjs.map +0 -1
  45. package/dist/esm/chunk-DI3EK7PR.mjs.map +0 -1
  46. package/dist/esm/chunk-S5OEANGR.mjs.map +0 -1
  47. package/dist/esm/chunk-T3FPOH7F.mjs.map +0 -1
  48. package/dist/esm/exact/client/index.d.mts +0 -53
  49. package/dist/esm/exact/facilitator/index.d.mts +0 -118
  50. package/dist/esm/exact/server/index.d.mts +0 -140
  51. package/dist/esm/exact/v1/client/index.d.mts +0 -37
  52. package/dist/esm/exact/v1/facilitator/index.d.mts +0 -62
  53. package/dist/esm/index.d.mts +0 -36
  54. package/dist/esm/signer-5OVDxViv.d.mts +0 -79
  55. package/dist/esm/v1/index.d.mts +0 -7
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/exact/v1/facilitator/scheme.ts"],"sourcesContent":["import {\n PaymentPayload,\n PaymentPayloadV1,\n PaymentRequirements,\n SchemeNetworkFacilitator,\n SettleResponse,\n VerifyResponse,\n} from \"x402-core-mantle/types\";\nimport { PaymentRequirementsV1 } from \"x402-core-mantle/types/v1\";\nimport { getAddress, Hex, isAddressEqual, parseErc6492Signature, parseSignature } from \"viem\";\nimport { authorizationTypes, eip3009ABI } from \"../../../constants\";\nimport { FacilitatorEvmSigner } from \"../../../signer\";\nimport { ExactEvmPayloadV1 } from \"../../../types\";\nimport { getEvmChainId } from \"../../../utils\";\n\nexport interface ExactEvmSchemeV1Config {\n /**\n * If enabled, the facilitator will deploy ERC-4337 smart wallets\n * via EIP-6492 when encountering undeployed contract signatures.\n *\n * @default false\n */\n deployERC4337WithEIP6492?: boolean;\n}\n\n/**\n * EVM facilitator implementation for the Exact payment scheme (V1).\n */\nexport class ExactEvmSchemeV1 implements SchemeNetworkFacilitator {\n readonly scheme = \"exact\";\n readonly caipFamily = \"eip155:*\";\n private readonly config: Required<ExactEvmSchemeV1Config>;\n\n /**\n * Creates a new ExactEvmFacilitatorV1 instance.\n *\n * @param signer - The EVM signer for facilitator operations\n * @param config - Optional configuration for the facilitator\n */\n constructor(\n private readonly signer: FacilitatorEvmSigner,\n config?: ExactEvmSchemeV1Config,\n ) {\n this.config = {\n deployERC4337WithEIP6492: config?.deployERC4337WithEIP6492 ?? false,\n };\n }\n\n /**\n * Get mechanism-specific extra data for the supported kinds endpoint.\n * For EVM, no extra data is needed.\n *\n * @param _ - The network identifier (unused for EVM)\n * @returns undefined (EVM has no extra data)\n */\n getExtra(_: string): Record<string, unknown> | undefined {\n return undefined;\n }\n\n /**\n * Get signer addresses used by this facilitator.\n * Returns all addresses this facilitator can use for signing/settling transactions.\n *\n * @param _ - The network identifier (unused for EVM, addresses are network-agnostic)\n * @returns Array of facilitator wallet addresses\n */\n getSigners(_: string): string[] {\n return [...this.signer.getAddresses()];\n }\n\n /**\n * Verifies a payment payload (V1).\n *\n * @param payload - The payment payload to verify\n * @param requirements - The payment requirements\n * @returns Promise resolving to verification response\n */\n async verify(\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n ): Promise<VerifyResponse> {\n const requirementsV1 = requirements as unknown as PaymentRequirementsV1;\n const payloadV1 = payload as unknown as PaymentPayloadV1;\n const exactEvmPayload = payload.payload as ExactEvmPayloadV1;\n\n // Verify scheme matches\n if (payloadV1.scheme !== \"exact\" || requirements.scheme !== \"exact\") {\n return {\n isValid: false,\n invalidReason: \"unsupported_scheme\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Get chain configuration\n const chainId = getEvmChainId(payloadV1.network);\n\n if (!requirements.extra?.name || !requirements.extra?.version) {\n return {\n isValid: false,\n invalidReason: \"missing_eip712_domain\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n const { name, version } = requirements.extra;\n const erc20Address = getAddress(requirements.asset);\n\n // Verify network matches\n if (payloadV1.network !== requirements.network) {\n return {\n isValid: false,\n invalidReason: \"network_mismatch\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Build typed data for signature verification\n const permitTypedData = {\n types: authorizationTypes,\n primaryType: \"TransferWithAuthorization\" as const,\n domain: {\n name,\n version,\n chainId,\n verifyingContract: erc20Address,\n },\n message: {\n from: exactEvmPayload.authorization.from,\n to: exactEvmPayload.authorization.to,\n value: BigInt(exactEvmPayload.authorization.value),\n validAfter: BigInt(exactEvmPayload.authorization.validAfter),\n validBefore: BigInt(exactEvmPayload.authorization.validBefore),\n nonce: exactEvmPayload.authorization.nonce,\n },\n };\n\n // Verify signature\n try {\n const recoveredAddress = await this.signer.verifyTypedData({\n address: exactEvmPayload.authorization.from,\n ...permitTypedData,\n signature: exactEvmPayload.signature!,\n });\n\n if (!recoveredAddress) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_signature\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n } catch {\n // Signature verification failed - could be an undeployed smart wallet\n // Check if smart wallet is deployed\n const signature = exactEvmPayload.signature!;\n const signatureLength = signature.startsWith(\"0x\") ? signature.length - 2 : signature.length;\n const isSmartWallet = signatureLength > 130; // 65 bytes = 130 hex chars for EOA\n\n if (isSmartWallet) {\n const payerAddress = exactEvmPayload.authorization.from;\n const bytecode = await this.signer.getCode({ address: payerAddress });\n\n if (!bytecode || bytecode === \"0x\") {\n // Wallet is not deployed. Check if it's EIP-6492 with deployment info.\n // EIP-6492 signatures contain factory address and calldata needed for deployment.\n // Non-EIP-6492 undeployed wallets cannot succeed (no way to deploy them).\n const erc6492Data = parseErc6492Signature(signature);\n const hasDeploymentInfo =\n erc6492Data.address &&\n erc6492Data.data &&\n !isAddressEqual(erc6492Data.address, \"0x0000000000000000000000000000000000000000\");\n\n if (!hasDeploymentInfo) {\n // Non-EIP-6492 undeployed smart wallet - will always fail at settlement\n // since EIP-3009 requires on-chain EIP-1271 validation\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_undeployed_smart_wallet\",\n payer: payerAddress,\n };\n }\n // EIP-6492 signature with deployment info - allow through\n // Facilitators with sponsored deployment support can handle this in settle()\n } else {\n // Wallet is deployed but signature still failed - invalid signature\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_signature\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n } else {\n // EOA signature failed\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_signature\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n }\n\n // Verify payment recipient matches\n if (getAddress(exactEvmPayload.authorization.to) !== getAddress(requirements.payTo)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_recipient_mismatch\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Verify validBefore is in the future (with 6 second buffer for block time)\n const now = Math.floor(Date.now() / 1000);\n if (BigInt(exactEvmPayload.authorization.validBefore) < BigInt(now + 6)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_authorization_valid_before\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Verify validAfter is not in the future\n if (BigInt(exactEvmPayload.authorization.validAfter) > BigInt(now)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_authorization_valid_after\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Check balance\n try {\n const balance = (await this.signer.readContract({\n address: erc20Address,\n abi: eip3009ABI,\n functionName: \"balanceOf\",\n args: [exactEvmPayload.authorization.from],\n })) as bigint;\n\n if (BigInt(balance) < BigInt(requirementsV1.maxAmountRequired)) {\n return {\n isValid: false,\n invalidReason: \"insufficient_funds\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n } catch {\n // If we can't check balance, continue with other validations\n }\n\n // Verify amount is sufficient\n if (BigInt(exactEvmPayload.authorization.value) < BigInt(requirementsV1.maxAmountRequired)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_authorization_value\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n return {\n isValid: true,\n invalidReason: undefined,\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n /**\n * Settles a payment by executing the transfer (V1).\n *\n * @param payload - The payment payload to settle\n * @param requirements - The payment requirements\n * @returns Promise resolving to settlement response\n */\n async settle(\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n ): Promise<SettleResponse> {\n const payloadV1 = payload as unknown as PaymentPayloadV1;\n const exactEvmPayload = payload.payload as ExactEvmPayloadV1;\n\n // Re-verify before settling\n const valid = await this.verify(payload, requirements);\n if (!valid.isValid) {\n return {\n success: false,\n network: payloadV1.network,\n transaction: \"\",\n errorReason: valid.invalidReason ?? \"invalid_scheme\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n try {\n // Parse ERC-6492 signature if applicable\n const parseResult = parseErc6492Signature(exactEvmPayload.signature!);\n const { signature, address: factoryAddress, data: factoryCalldata } = parseResult;\n\n // Deploy ERC-4337 smart wallet via EIP-6492 if configured and needed\n if (\n this.config.deployERC4337WithEIP6492 &&\n factoryAddress &&\n factoryCalldata &&\n !isAddressEqual(factoryAddress, \"0x0000000000000000000000000000000000000000\")\n ) {\n // Check if smart wallet is already deployed\n const payerAddress = exactEvmPayload.authorization.from;\n const bytecode = await this.signer.getCode({ address: payerAddress });\n\n if (!bytecode || bytecode === \"0x\") {\n // Wallet not deployed - attempt deployment\n try {\n console.log(`Deploying ERC-4337 smart wallet for ${payerAddress} via EIP-6492`);\n\n // Send the factory calldata directly as a transaction\n // The factoryCalldata already contains the complete encoded function call\n const deployTx = await this.signer.sendTransaction({\n to: factoryAddress as Hex,\n data: factoryCalldata as Hex,\n });\n\n // Wait for deployment transaction\n await this.signer.waitForTransactionReceipt({ hash: deployTx });\n console.log(`Successfully deployed smart wallet for ${payerAddress}`);\n } catch (deployError) {\n console.error(\"Smart wallet deployment failed:\", deployError);\n // Deployment failed - cannot proceed\n throw deployError;\n }\n } else {\n console.log(`Smart wallet for ${payerAddress} already deployed, skipping deployment`);\n }\n }\n\n // Determine if this is an ECDSA signature (EOA) or smart wallet signature\n // ECDSA signatures are exactly 65 bytes (130 hex chars without 0x)\n const signatureLength = signature.startsWith(\"0x\") ? signature.length - 2 : signature.length;\n const isECDSA = signatureLength === 130;\n\n let tx: Hex;\n if (isECDSA) {\n // For EOA wallets, parse signature into v, r, s and use that overload\n const parsedSig = parseSignature(signature);\n\n tx = await this.signer.writeContract({\n address: getAddress(requirements.asset),\n abi: eip3009ABI,\n functionName: \"transferWithAuthorization\",\n args: [\n getAddress(exactEvmPayload.authorization.from),\n getAddress(exactEvmPayload.authorization.to),\n BigInt(exactEvmPayload.authorization.value),\n BigInt(exactEvmPayload.authorization.validAfter),\n BigInt(exactEvmPayload.authorization.validBefore),\n exactEvmPayload.authorization.nonce,\n (parsedSig.v as number | undefined) || parsedSig.yParity,\n parsedSig.r,\n parsedSig.s,\n ],\n });\n } else {\n // For smart wallets, use the bytes signature overload\n // The signature contains WebAuthn/P256 or other ERC-1271 compatible signature data\n tx = await this.signer.writeContract({\n address: getAddress(requirements.asset),\n abi: eip3009ABI,\n functionName: \"transferWithAuthorization\",\n args: [\n getAddress(exactEvmPayload.authorization.from),\n getAddress(exactEvmPayload.authorization.to),\n BigInt(exactEvmPayload.authorization.value),\n BigInt(exactEvmPayload.authorization.validAfter),\n BigInt(exactEvmPayload.authorization.validBefore),\n exactEvmPayload.authorization.nonce,\n signature,\n ],\n });\n }\n\n // Wait for transaction confirmation\n const receipt = await this.signer.waitForTransactionReceipt({ hash: tx });\n\n if (receipt.status !== \"success\") {\n return {\n success: false,\n errorReason: \"invalid_transaction_state\",\n transaction: tx,\n network: payloadV1.network,\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n return {\n success: true,\n transaction: tx,\n network: payloadV1.network,\n payer: exactEvmPayload.authorization.from,\n };\n } catch (error) {\n console.error(\"Failed to settle transaction:\", error);\n return {\n success: false,\n errorReason: \"transaction_failed\",\n transaction: \"\",\n network: payloadV1.network,\n payer: exactEvmPayload.authorization.from,\n };\n }\n }\n}\n"],"mappings":";;;;;;;AASA,SAAS,YAAiB,gBAAgB,uBAAuB,sBAAsB;AAmBhF,IAAM,mBAAN,MAA2D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWhE,YACmB,QACjB,QACA;AAFiB;AAXnB,SAAS,SAAS;AAClB,SAAS,aAAa;AAapB,SAAK,SAAS;AAAA,MACZ,0BAA0B,QAAQ,4BAA4B;AAAA,IAChE;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,SAAS,GAAgD;AACvD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,WAAW,GAAqB;AAC9B,WAAO,CAAC,GAAG,KAAK,OAAO,aAAa,CAAC;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,OACJ,SACA,cACyB;AACzB,UAAM,iBAAiB;AACvB,UAAM,YAAY;AAClB,UAAM,kBAAkB,QAAQ;AAGhC,QAAI,UAAU,WAAW,WAAW,aAAa,WAAW,SAAS;AACnE,aAAO;AAAA,QACL,SAAS;AAAA,QACT,eAAe;AAAA,QACf,OAAO,gBAAgB,cAAc;AAAA,MACvC;AAAA,IACF;AAGA,UAAM,UAAU,cAAc,UAAU,OAAO;AAE/C,QAAI,CAAC,aAAa,OAAO,QAAQ,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gB,cAAc,KAAK;AAAA,YAC1C,OAAO,gBAAgB,cAAc,UAAU;AAAA,YAC/C,OAAO,gBAAgB,cAAc,WAAW;AAAA,YAChD,gBAAgB,cAAc;AAAA,YAC9B;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH;AAGA,YAAM,UAAU,MAAM,KAAK,OAAO,0BAA0B,EAAE,MAAM,GAAG,CAAC;AAExE,UAAI,QAAQ,WAAW,WAAW;AAChC,eAAO;AAAA,UACL,SAAS;AAAA,UACT,aAAa;AAAA,UACb,aAAa;AAAA,UACb,SAAS,UAAU;AAAA,UACnB,OAAO,gBAAgB,cAAc;AAAA,QACvC;AAAA,MACF;AAEA,aAAO;AAAA,QACL,SAAS;AAAA,QACT,aAAa;AAAA,QACb,SAAS,UAAU;AAAA,QACnB,OAAO,gBAAgB,cAAc;AAAA,MACvC;AAAA,IACF,SAAS,OAAO;AACd,cAAQ,MAAM,iCAAiC,KAAK;AACpD,aAAO;AAAA,QACL,SAAS;AAAA,QACT,aAAa;AAAA,QACb,aAAa;AAAA,QACb,SAAS,UAAU;AAAA,QACnB,OAAO,gBAAgB,cAAc;AAAA,MACvC;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/exact/v1/client/scheme.ts"],"sourcesContent":["import {\n Network,\n PaymentPayload,\n PaymentRequirements,\n SchemeNetworkClient,\n} from \"x402-core-mantle/types\";\nimport { PaymentRequirementsV1 } from \"x402-core-mantle/types/v1\";\nimport { getAddress } from \"viem\";\nimport { authorizationTypes } from \"../../../constants\";\nimport { ClientEvmSigner } from \"../../../signer\";\nimport { ExactEvmPayloadV1 } from \"../../../types\";\nimport { createNonce, getEvmChainId } from \"../../../utils\";\n\n/**\n * EVM client implementation for the Exact payment scheme (V1).\n */\nexport class ExactEvmSchemeV1 implements SchemeNetworkClient {\n readonly scheme = \"exact\";\n\n /**\n * Creates a new ExactEvmClientV1 instance.\n *\n * @param signer - The EVM signer for client operations\n */\n constructor(private readonly signer: ClientEvmSigner) {}\n\n /**\n * Creates a payment payload for the Exact scheme (V1).\n *\n * @param x402Version - The x402 protocol version\n * @param paymentRequirements - The payment requirements\n * @returns Promise resolving to a payment payload\n */\n async createPaymentPayload(\n x402Version: number,\n paymentRequirements: PaymentRequirements,\n ): Promise<\n Pick<PaymentPayload, \"x402Version\" | \"payload\"> & { scheme: string; network: Network }\n > {\n const selectedV1 = paymentRequirements as unknown as PaymentRequirementsV1;\n const nonce = createNonce();\n const now = Math.floor(Date.now() / 1000);\n\n const authorization: ExactEvmPayloadV1[\"authorization\"] = {\n from: this.signer.address,\n to: getAddress(selectedV1.payTo),\n value: selectedV1.maxAmountRequired,\n validAfter: (now - 600).toString(), // 10 minutes before\n validBefore: (now + selectedV1.maxTimeoutSeconds).toString(),\n nonce,\n };\n\n // Sign the authorization\n const signature = await this.signAuthorization(authorization, selectedV1);\n\n const payload: ExactEvmPayloadV1 = {\n authorization,\n signature,\n };\n\n return {\n x402Version,\n scheme: selectedV1.scheme,\n network: selectedV1.network,\n payload,\n };\n }\n\n /**\n * Sign the EIP-3009 authorization using EIP-712\n *\n * @param authorization - The authorization to sign\n * @param requirements - The payment requirements\n * @returns Promise resolving to the signature\n */\n private async signAuthorization(\n authorization: ExactEvmPayloadV1[\"authorization\"],\n requirements: PaymentRequirementsV1,\n ): Promise<`0x${string}`> {\n const chainId = getEvmChainId(requirements.network);\n\n if (!requirements.extra?.name || !requirements.extra?.version) {\n throw new Error(\n `EIP-712 domain parameters (name, version) are required in payment requirements for asset ${requirements.asset}`,\n );\n }\n\n const { name, version } = requirements.extra;\n\n const domain = {\n name,\n version,\n chainId,\n verifyingContract: getAddress(requirements.asset),\n };\n\n const message = {\n from: getAddress(authorization.from),\n to: getAddress(authorization.to),\n value: BigInt(authorization.value),\n validAfter: BigInt(authorization.validAfter),\n validBefore: BigInt(authorization.validBefore),\n nonce: authorization.nonce,\n };\n\n return await this.signer.signTypedData({\n domain,\n types: authorizationTypes,\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,MAAM,WAAW,cAAc,IAAI;AAAA,MACnC,IAAI,WAAW,cAAc,EAAE;AAAA,MAC/B,OAAO,OAAO,cAAc,KAAK;AAAA,MACjC,YAAY,OAAO,cAAc,UAAU;AAAA,MAC3C,aAAa,OAAO,cAAc,WAAW;AAAA,MAC7C,OAAO,cAAc;AAAA,IACvB;AAEA,WAAO,MAAM,KAAK,OAAO,cAAc;AAAA,MACrC;AAAA,MACA,OAAO;AAAA,MACP,aAAa;AAAA,MACb;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/exact/client/scheme.ts"],"sourcesContent":["import { PaymentPayload, PaymentRequirements, SchemeNetworkClient } from \"x402-core-mantle/types\";\nimport { getAddress } from \"viem\";\nimport { authorizationTypes } from \"../../constants\";\nimport { ClientEvmSigner } from \"../../signer\";\nimport { ExactEvmPayloadV2 } from \"../../types\";\nimport { createNonce } from \"../../utils\";\n\n/**\n * EVM client implementation for the Exact payment scheme.\n *\n */\nexport class ExactEvmScheme implements SchemeNetworkClient {\n readonly scheme = \"exact\";\n\n /**\n * Creates a new ExactEvmClient instance.\n *\n * @param signer - The EVM signer for client operations\n */\n constructor(private readonly signer: ClientEvmSigner) {}\n\n /**\n * Creates a payment payload for the Exact scheme.\n *\n * @param x402Version - The x402 protocol version\n * @param paymentRequirements - The payment requirements\n * @returns Promise resolving to a payment payload\n */\n async createPaymentPayload(\n x402Version: number,\n paymentRequirements: PaymentRequirements,\n ): Promise<Pick<PaymentPayload, \"x402Version\" | \"payload\">> {\n const nonce = createNonce();\n const now = Math.floor(Date.now() / 1000);\n\n const authorization: ExactEvmPayloadV2[\"authorization\"] = {\n from: this.signer.address,\n to: getAddress(paymentRequirements.payTo),\n value: paymentRequirements.amount,\n validAfter: (now - 600).toString(), // 10 minutes before\n validBefore: (now + paymentRequirements.maxTimeoutSeconds).toString(),\n nonce,\n };\n\n // Sign the authorization\n const signature = await this.signAuthorization(authorization, paymentRequirements);\n\n const payload: ExactEvmPayloadV2 = {\n authorization,\n signature,\n };\n\n return {\n x402Version,\n payload,\n };\n }\n\n /**\n * Sign the EIP-3009 authorization using EIP-712\n *\n * @param authorization - The authorization to sign\n * @param requirements - The payment requirements\n * @returns Promise resolving to the signature\n */\n private async signAuthorization(\n authorization: ExactEvmPayloadV2[\"authorization\"],\n requirements: PaymentRequirements,\n ): Promise<`0x${string}`> {\n const chainId = parseInt(requirements.network.split(\":\")[1]);\n\n if (!requirements.extra?.name || !requirements.extra?.version) {\n throw new Error(\n `EIP-712 domain parameters (name, version) are required in payment requirements for asset ${requirements.asset}`,\n );\n }\n\n const { name, version } = requirements.extra;\n\n const domain = {\n name,\n version,\n chainId,\n verifyingContract: getAddress(requirements.asset),\n };\n\n const message = {\n from: getAddress(authorization.from),\n to: getAddress(authorization.to),\n value: BigInt(authorization.value),\n validAfter: BigInt(authorization.validAfter),\n validBefore: BigInt(authorization.validBefore),\n nonce: authorization.nonce,\n };\n\n return await this.signer.signTypedData({\n domain,\n types: authorizationTypes,\n primaryType: \"TransferWithAuthorization\",\n message,\n });\n }\n}\n"],"mappings":";;;;;;AACA,SAAS,kBAAkB;AAUpB,IAAM,iBAAN,MAAoD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQzD,YAA6B,QAAyB;AAAzB;AAP7B,SAAS,SAAS;AAAA,EAOqC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASvD,MAAM,qBACJ,aACA,qBAC0D;AAC1D,UAAM,QAAQ,YAAY;AAC1B,UAAM,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AAExC,UAAM,gBAAoD;AAAA,MACxD,MAAM,KAAK,OAAO;AAAA,MAClB,IAAI,WAAW,oBAAoB,KAAK;AAAA,MACxC,OAAO,oBAAoB;AAAA,MAC3B,aAAa,MAAM,KAAK,SAAS;AAAA;AAAA,MACjC,cAAc,MAAM,oBAAoB,mBAAmB,SAAS;AAAA,MACpE;AAAA,IACF;AAGA,UAAM,YAAY,MAAM,KAAK,kBAAkB,eAAe,mBAAmB;AAEjF,UAAM,UAA6B;AAAA,MACjC;AAAA,MACA;AAAA,IACF;AAEA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAc,kBACZ,eACA,cACwB;AACxB,UAAM,UAAU,SAAS,aAAa,QAAQ,MAAM,GAAG,EAAE,CAAC,CAAC;AAE3D,QAAI,CAAC,aAAa,OAAO,QAAQ,CAAC,aAAa,OAAO,SAAS;AAC7D,YAAM,IAAI;AAAA,QACR,4FAA4F,aAAa,KAAK;AAAA,MAChH;AAAA,IACF;AAEA,UAAM,EAAE,MAAM,QAAQ,IAAI,aAAa;AAEvC,UAAM,SAAS;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB,WAAW,aAAa,KAAK;AAAA,IAClD;AAEA,UAAM,UAAU;AAAA,MACd,MAAM,WAAW,cAAc,IAAI;AAAA,MACnC,IAAI,WAAW,cAAc,EAAE;AAAA,MAC/B,OAAO,OAAO,cAAc,KAAK;AAAA,MACjC,YAAY,OAAO,cAAc,UAAU;AAAA,MAC3C,aAAa,OAAO,cAAc,WAAW;AAAA,MAC7C,OAAO,cAAc;AAAA,IACvB;AAEA,WAAO,MAAM,KAAK,OAAO,cAAc;AAAA,MACrC;AAAA,MACA,OAAO;AAAA,MACP,aAAa;AAAA,MACb;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1,53 +0,0 @@
1
- export { ExactEvmScheme } from '../../index.mjs';
2
- import { x402Client, SelectPaymentRequirements, PaymentPolicy } from 'x402-core-mantle/client';
3
- import { Network } from 'x402-core-mantle/types';
4
- import { C as ClientEvmSigner } from '../../signer-5OVDxViv.mjs';
5
-
6
- /**
7
- * Configuration options for registering EVM schemes to an x402Client
8
- */
9
- interface EvmClientConfig {
10
- /**
11
- * The EVM signer to use for creating payment payloads
12
- */
13
- signer: ClientEvmSigner;
14
- /**
15
- * Optional payment requirements selector function
16
- * If not provided, uses the default selector (first available option)
17
- */
18
- paymentRequirementsSelector?: SelectPaymentRequirements;
19
- /**
20
- * Optional policies to apply to the client
21
- */
22
- policies?: PaymentPolicy[];
23
- /**
24
- * Optional specific networks to register
25
- * If not provided, registers wildcard support (eip155:*)
26
- */
27
- networks?: Network[];
28
- }
29
- /**
30
- * Registers EVM exact payment schemes to an x402Client instance.
31
- *
32
- * This function registers:
33
- * - V2: eip155:* wildcard scheme with ExactEvmScheme (or specific networks if provided)
34
- * - V1: All supported EVM networks with ExactEvmSchemeV1
35
- *
36
- * @param client - The x402Client instance to register schemes to
37
- * @param config - Configuration for EVM client registration
38
- * @returns The client instance for chaining
39
- *
40
- * @example
41
- * ```typescript
42
- * import { registerExactEvmScheme } from "@x402/evm/exact/client/register";
43
- * import { x402Client } from "x402-core-mantle/client";
44
- * import { privateKeyToAccount } from "viem/accounts";
45
- *
46
- * const account = privateKeyToAccount("0x...");
47
- * const client = new x402Client();
48
- * registerExactEvmScheme(client, { signer: account });
49
- * ```
50
- */
51
- declare function registerExactEvmScheme(client: x402Client, config: EvmClientConfig): x402Client;
52
-
53
- export { type EvmClientConfig, registerExactEvmScheme };
@@ -1,118 +0,0 @@
1
- import { SchemeNetworkFacilitator, PaymentPayload, PaymentRequirements, VerifyResponse, SettleResponse, Network } from 'x402-core-mantle/types';
2
- import { F as FacilitatorEvmSigner } from '../../signer-5OVDxViv.mjs';
3
- import { x402Facilitator } from 'x402-core-mantle/facilitator';
4
-
5
- interface ExactEvmSchemeConfig {
6
- /**
7
- * If enabled, the facilitator will deploy ERC-4337 smart wallets
8
- * via EIP-6492 when encountering undeployed contract signatures.
9
- *
10
- * @default false
11
- */
12
- deployERC4337WithEIP6492?: boolean;
13
- }
14
- /**
15
- * EVM facilitator implementation for the Exact payment scheme.
16
- */
17
- declare class ExactEvmScheme implements SchemeNetworkFacilitator {
18
- private readonly signer;
19
- readonly scheme = "exact";
20
- readonly caipFamily = "eip155:*";
21
- private readonly config;
22
- /**
23
- * Creates a new ExactEvmFacilitator instance.
24
- *
25
- * @param signer - The EVM signer for facilitator operations
26
- * @param config - Optional configuration for the facilitator
27
- */
28
- constructor(signer: FacilitatorEvmSigner, config?: ExactEvmSchemeConfig);
29
- /**
30
- * Get mechanism-specific extra data for the supported kinds endpoint.
31
- * For EVM, no extra data is needed.
32
- *
33
- * @param _ - The network identifier (unused for EVM)
34
- * @returns undefined (EVM has no extra data)
35
- */
36
- getExtra(_: string): Record<string, unknown> | undefined;
37
- /**
38
- * Get signer addresses used by this facilitator.
39
- * Returns all addresses this facilitator can use for signing/settling transactions.
40
- *
41
- * @param _ - The network identifier (unused for EVM, addresses are network-agnostic)
42
- * @returns Array of facilitator wallet addresses
43
- */
44
- getSigners(_: string): string[];
45
- /**
46
- * Verifies a payment payload.
47
- *
48
- * @param payload - The payment payload to verify
49
- * @param requirements - The payment requirements
50
- * @returns Promise resolving to verification response
51
- */
52
- verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
53
- /**
54
- * Settles a payment by executing the transfer.
55
- *
56
- * @param payload - The payment payload to settle
57
- * @param requirements - The payment requirements
58
- * @returns Promise resolving to settlement response
59
- */
60
- settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
61
- }
62
-
63
- /**
64
- * Configuration options for registering EVM schemes to an x402Facilitator
65
- */
66
- interface EvmFacilitatorConfig {
67
- /**
68
- * The EVM signer for facilitator operations (verify and settle)
69
- */
70
- signer: FacilitatorEvmSigner;
71
- /**
72
- * Networks to register (single network or array of networks)
73
- * Examples: "eip155:84532", ["eip155:84532", "eip155:1"]
74
- */
75
- networks: Network | Network[];
76
- /**
77
- * If enabled, the facilitator will deploy ERC-4337 smart wallets
78
- * via EIP-6492 when encountering undeployed contract signatures.
79
- *
80
- * @default false
81
- */
82
- deployERC4337WithEIP6492?: boolean;
83
- }
84
- /**
85
- * Registers EVM exact payment schemes to an x402Facilitator instance.
86
- *
87
- * This function registers:
88
- * - V2: Specified networks with ExactEvmScheme
89
- * - V1: All supported EVM networks with ExactEvmSchemeV1
90
- *
91
- * @param facilitator - The x402Facilitator instance to register schemes to
92
- * @param config - Configuration for EVM facilitator registration
93
- * @returns The facilitator instance for chaining
94
- *
95
- * @example
96
- * ```typescript
97
- * import { registerExactEvmScheme } from "@x402/evm/exact/facilitator/register";
98
- * import { x402Facilitator } from "x402-core-mantle/facilitator";
99
- * import { createPublicClient, createWalletClient } from "viem";
100
- *
101
- * const facilitator = new x402Facilitator();
102
- *
103
- * // Single network
104
- * registerExactEvmScheme(facilitator, {
105
- * signer: combinedClient,
106
- * networks: "eip155:84532" // Base Sepolia
107
- * });
108
- *
109
- * // Multiple networks (will auto-derive eip155:* pattern)
110
- * registerExactEvmScheme(facilitator, {
111
- * signer: combinedClient,
112
- * networks: ["eip155:84532", "eip155:1"] // Base Sepolia and Mainnet
113
- * });
114
- * ```
115
- */
116
- declare function registerExactEvmScheme(facilitator: x402Facilitator, config: EvmFacilitatorConfig): x402Facilitator;
117
-
118
- export { type EvmFacilitatorConfig, ExactEvmScheme, type ExactEvmSchemeConfig, registerExactEvmScheme };
@@ -1,140 +0,0 @@
1
- import { SchemeNetworkServer, MoneyParser, Price, Network, AssetAmount, PaymentRequirements } from 'x402-core-mantle/types';
2
- import { x402ResourceServer } from 'x402-core-mantle/server';
3
-
4
- /**
5
- * EVM server implementation for the Exact payment scheme.
6
- */
7
- declare class ExactEvmScheme implements SchemeNetworkServer {
8
- readonly scheme = "exact";
9
- private moneyParsers;
10
- /**
11
- * Register a custom money parser in the parser chain.
12
- * Multiple parsers can be registered - they will be tried in registration order.
13
- * Each parser receives a decimal amount (e.g., 1.50 for $1.50).
14
- * If a parser returns null, the next parser in the chain will be tried.
15
- * The default parser is always the final fallback.
16
- *
17
- * @param parser - Custom function to convert amount to AssetAmount (or null to skip)
18
- * @returns The server instance for chaining
19
- *
20
- * @example
21
- * evmServer.registerMoneyParser(async (amount, network) => {
22
- * // Custom conversion logic
23
- * if (amount > 100) {
24
- * // Use different token for large amounts
25
- * return { amount: (amount * 1e18).toString(), asset: "0xCustomToken" };
26
- * }
27
- * return null; // Use next parser
28
- * });
29
- */
30
- registerMoneyParser(parser: MoneyParser): ExactEvmScheme;
31
- /**
32
- * Parses a price into an asset amount.
33
- * If price is already an AssetAmount, returns it directly.
34
- * If price is Money (string | number), parses to decimal and tries custom parsers.
35
- * Falls back to default conversion if all custom parsers return null.
36
- *
37
- * @param price - The price to parse
38
- * @param network - The network to use
39
- * @returns Promise that resolves to the parsed asset amount
40
- */
41
- parsePrice(price: Price, network: Network): Promise<AssetAmount>;
42
- /**
43
- * Build payment requirements for this scheme/network combination
44
- *
45
- * @param paymentRequirements - The base payment requirements
46
- * @param supportedKind - The supported kind from facilitator (unused)
47
- * @param supportedKind.x402Version - The x402 version
48
- * @param supportedKind.scheme - The logical payment scheme
49
- * @param supportedKind.network - The network identifier in CAIP-2 format
50
- * @param supportedKind.extra - Optional extra metadata regarding scheme/network implementation details
51
- * @param extensionKeys - Extension keys supported by the facilitator (unused)
52
- * @returns Payment requirements ready to be sent to clients
53
- */
54
- enhancePaymentRequirements(paymentRequirements: PaymentRequirements, supportedKind: {
55
- x402Version: number;
56
- scheme: string;
57
- network: Network;
58
- extra?: Record<string, unknown>;
59
- }, extensionKeys: string[]): Promise<PaymentRequirements>;
60
- /**
61
- * Parse Money (string | number) to a decimal number.
62
- * Handles formats like "$1.50", "1.50", 1.50, etc.
63
- *
64
- * @param money - The money value to parse
65
- * @returns Decimal number
66
- */
67
- private parseMoneyToDecimal;
68
- /**
69
- * Default money conversion implementation.
70
- * Converts decimal amount to USDC on the specified network.
71
- *
72
- * @param amount - The decimal amount (e.g., 1.50)
73
- * @param network - The network to use
74
- * @returns The parsed asset amount in USDC
75
- */
76
- private defaultMoneyConversion;
77
- /**
78
- * Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal USDC)
79
- *
80
- * @param decimalAmount - The decimal amount to convert
81
- * @param network - The network to use
82
- * @returns The token amount as a string
83
- */
84
- private convertToTokenAmount;
85
- /**
86
- * Get the default asset info for a network (typically USDC)
87
- *
88
- * @param network - The network to get asset info for
89
- * @returns The asset information including address, name, and version
90
- */
91
- private getDefaultAsset;
92
- /**
93
- * Get asset info for a given symbol on a network
94
- *
95
- * @param symbol - The asset symbol
96
- * @param network - The network to use
97
- * @returns The asset information including address, name, and version
98
- */
99
- private getAssetInfo;
100
- /**
101
- * Get the number of decimals for the asset
102
- *
103
- * @param _ - The network to use (unused)
104
- * @returns The number of decimals for the asset
105
- */
106
- private getAssetDecimals;
107
- }
108
-
109
- /**
110
- * Configuration options for registering EVM schemes to an x402ResourceServer
111
- */
112
- interface EvmResourceServerConfig {
113
- /**
114
- * Optional specific networks to register
115
- * If not provided, registers wildcard support (eip155:*)
116
- */
117
- networks?: Network[];
118
- }
119
- /**
120
- * Registers EVM exact payment schemes to an x402ResourceServer instance.
121
- *
122
- * This function registers:
123
- * - V2: eip155:* wildcard scheme with ExactEvmScheme (or specific networks if provided)
124
- *
125
- * @param server - The x402ResourceServer instance to register schemes to
126
- * @param config - Configuration for EVM resource server registration
127
- * @returns The server instance for chaining
128
- *
129
- * @example
130
- * ```typescript
131
- * import { registerExactEvmScheme } from "@x402/evm/exact/server/register";
132
- * import { x402ResourceServer } from "x402-core-mantle/server";
133
- *
134
- * const server = new x402ResourceServer(facilitatorClient);
135
- * registerExactEvmScheme(server, {});
136
- * ```
137
- */
138
- declare function registerExactEvmScheme(server: x402ResourceServer, config?: EvmResourceServerConfig): x402ResourceServer;
139
-
140
- export { type EvmResourceServerConfig, ExactEvmScheme, registerExactEvmScheme };
@@ -1,37 +0,0 @@
1
- import { SchemeNetworkClient, PaymentRequirements, PaymentPayload, Network } from 'x402-core-mantle/types';
2
- import { C as ClientEvmSigner } from '../../../signer-5OVDxViv.mjs';
3
-
4
- /**
5
- * EVM client implementation for the Exact payment scheme (V1).
6
- */
7
- declare class ExactEvmSchemeV1 implements SchemeNetworkClient {
8
- private readonly signer;
9
- readonly scheme = "exact";
10
- /**
11
- * Creates a new ExactEvmClientV1 instance.
12
- *
13
- * @param signer - The EVM signer for client operations
14
- */
15
- constructor(signer: ClientEvmSigner);
16
- /**
17
- * Creates a payment payload for the Exact scheme (V1).
18
- *
19
- * @param x402Version - The x402 protocol version
20
- * @param paymentRequirements - The payment requirements
21
- * @returns Promise resolving to a payment payload
22
- */
23
- createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "x402Version" | "payload"> & {
24
- scheme: string;
25
- network: Network;
26
- }>;
27
- /**
28
- * Sign the EIP-3009 authorization using EIP-712
29
- *
30
- * @param authorization - The authorization to sign
31
- * @param requirements - The payment requirements
32
- * @returns Promise resolving to the signature
33
- */
34
- private signAuthorization;
35
- }
36
-
37
- export { ExactEvmSchemeV1 };
@@ -1,62 +0,0 @@
1
- import { SchemeNetworkFacilitator, PaymentPayload, PaymentRequirements, VerifyResponse, SettleResponse } from 'x402-core-mantle/types';
2
- import { F as FacilitatorEvmSigner } from '../../../signer-5OVDxViv.mjs';
3
-
4
- interface ExactEvmSchemeV1Config {
5
- /**
6
- * If enabled, the facilitator will deploy ERC-4337 smart wallets
7
- * via EIP-6492 when encountering undeployed contract signatures.
8
- *
9
- * @default false
10
- */
11
- deployERC4337WithEIP6492?: boolean;
12
- }
13
- /**
14
- * EVM facilitator implementation for the Exact payment scheme (V1).
15
- */
16
- declare class ExactEvmSchemeV1 implements SchemeNetworkFacilitator {
17
- private readonly signer;
18
- readonly scheme = "exact";
19
- readonly caipFamily = "eip155:*";
20
- private readonly config;
21
- /**
22
- * Creates a new ExactEvmFacilitatorV1 instance.
23
- *
24
- * @param signer - The EVM signer for facilitator operations
25
- * @param config - Optional configuration for the facilitator
26
- */
27
- constructor(signer: FacilitatorEvmSigner, config?: ExactEvmSchemeV1Config);
28
- /**
29
- * Get mechanism-specific extra data for the supported kinds endpoint.
30
- * For EVM, no extra data is needed.
31
- *
32
- * @param _ - The network identifier (unused for EVM)
33
- * @returns undefined (EVM has no extra data)
34
- */
35
- getExtra(_: string): Record<string, unknown> | undefined;
36
- /**
37
- * Get signer addresses used by this facilitator.
38
- * Returns all addresses this facilitator can use for signing/settling transactions.
39
- *
40
- * @param _ - The network identifier (unused for EVM, addresses are network-agnostic)
41
- * @returns Array of facilitator wallet addresses
42
- */
43
- getSigners(_: string): string[];
44
- /**
45
- * Verifies a payment payload (V1).
46
- *
47
- * @param payload - The payment payload to verify
48
- * @param requirements - The payment requirements
49
- * @returns Promise resolving to verification response
50
- */
51
- verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
52
- /**
53
- * Settles a payment by executing the transfer (V1).
54
- *
55
- * @param payload - The payment payload to settle
56
- * @param requirements - The payment requirements
57
- * @returns Promise resolving to settlement response
58
- */
59
- settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
60
- }
61
-
62
- export { ExactEvmSchemeV1, type ExactEvmSchemeV1Config };
@@ -1,36 +0,0 @@
1
- import { SchemeNetworkClient, PaymentRequirements, PaymentPayload } from 'x402-core-mantle/types';
2
- import { C as ClientEvmSigner } from './signer-5OVDxViv.mjs';
3
- export { F as FacilitatorEvmSigner, t as toClientEvmSigner, a as toFacilitatorEvmSigner } from './signer-5OVDxViv.mjs';
4
-
5
- /**
6
- * EVM client implementation for the Exact payment scheme.
7
- *
8
- */
9
- declare class ExactEvmScheme implements SchemeNetworkClient {
10
- private readonly signer;
11
- readonly scheme = "exact";
12
- /**
13
- * Creates a new ExactEvmClient instance.
14
- *
15
- * @param signer - The EVM signer for client operations
16
- */
17
- constructor(signer: ClientEvmSigner);
18
- /**
19
- * Creates a payment payload for the Exact scheme.
20
- *
21
- * @param x402Version - The x402 protocol version
22
- * @param paymentRequirements - The payment requirements
23
- * @returns Promise resolving to a payment payload
24
- */
25
- createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "x402Version" | "payload">>;
26
- /**
27
- * Sign the EIP-3009 authorization using EIP-712
28
- *
29
- * @param authorization - The authorization to sign
30
- * @param requirements - The payment requirements
31
- * @returns Promise resolving to the signature
32
- */
33
- private signAuthorization;
34
- }
35
-
36
- export { ClientEvmSigner, ExactEvmScheme };
@@ -1,79 +0,0 @@
1
- /**
2
- * ClientEvmSigner - Used by x402 clients to sign payment authorizations
3
- * This is typically a LocalAccount or wallet that holds private keys
4
- * and can sign EIP-712 typed data for payment authorizations
5
- */
6
- type ClientEvmSigner = {
7
- readonly address: `0x${string}`;
8
- signTypedData(message: {
9
- domain: Record<string, unknown>;
10
- types: Record<string, unknown>;
11
- primaryType: string;
12
- message: Record<string, unknown>;
13
- }): Promise<`0x${string}`>;
14
- };
15
- /**
16
- * FacilitatorEvmSigner - Used by x402 facilitators to verify and settle payments
17
- * This is typically a viem PublicClient + WalletClient combination that can
18
- * read contract state, verify signatures, write transactions, and wait for receipts
19
- *
20
- * Supports multiple addresses for load balancing, key rotation, and high availability
21
- */
22
- type FacilitatorEvmSigner = {
23
- /**
24
- * Get all addresses this facilitator can use for signing
25
- * Enables dynamic address selection for load balancing and key rotation
26
- */
27
- getAddresses(): readonly `0x${string}`[];
28
- readContract(args: {
29
- address: `0x${string}`;
30
- abi: readonly unknown[];
31
- functionName: string;
32
- args?: readonly unknown[];
33
- }): Promise<unknown>;
34
- verifyTypedData(args: {
35
- address: `0x${string}`;
36
- domain: Record<string, unknown>;
37
- types: Record<string, unknown>;
38
- primaryType: string;
39
- message: Record<string, unknown>;
40
- signature: `0x${string}`;
41
- }): Promise<boolean>;
42
- writeContract(args: {
43
- address: `0x${string}`;
44
- abi: readonly unknown[];
45
- functionName: string;
46
- args: readonly unknown[];
47
- }): Promise<`0x${string}`>;
48
- sendTransaction(args: {
49
- to: `0x${string}`;
50
- data: `0x${string}`;
51
- }): Promise<`0x${string}`>;
52
- waitForTransactionReceipt(args: {
53
- hash: `0x${string}`;
54
- }): Promise<{
55
- status: string;
56
- }>;
57
- getCode(args: {
58
- address: `0x${string}`;
59
- }): Promise<`0x${string}` | undefined>;
60
- };
61
- /**
62
- * Converts a signer to a ClientEvmSigner
63
- *
64
- * @param signer - The signer to convert to a ClientEvmSigner
65
- * @returns The converted signer
66
- */
67
- declare function toClientEvmSigner(signer: ClientEvmSigner): ClientEvmSigner;
68
- /**
69
- * Converts a viem client with single address to a FacilitatorEvmSigner
70
- * Wraps the single address in a getAddresses() function for compatibility
71
- *
72
- * @param client - The client to convert (must have 'address' property)
73
- * @returns FacilitatorEvmSigner with getAddresses() support
74
- */
75
- declare function toFacilitatorEvmSigner(client: Omit<FacilitatorEvmSigner, "getAddresses"> & {
76
- address: `0x${string}`;
77
- }): FacilitatorEvmSigner;
78
-
79
- export { type ClientEvmSigner as C, type FacilitatorEvmSigner as F, toFacilitatorEvmSigner as a, toClientEvmSigner as t };
@@ -1,7 +0,0 @@
1
- export { ExactEvmSchemeV1 } from '../exact/v1/client/index.mjs';
2
- import 'x402-core-mantle/types';
3
- import '../signer-5OVDxViv.mjs';
4
-
5
- declare const NETWORKS: string[];
6
-
7
- export { NETWORKS };