@x402/evm 2.2.0 → 2.3.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.
- package/dist/cjs/exact/client/index.d.ts +2 -2
- package/dist/cjs/exact/client/index.js +264 -119
- package/dist/cjs/exact/client/index.js.map +1 -1
- package/dist/cjs/exact/facilitator/index.d.ts +3 -0
- package/dist/cjs/exact/facilitator/index.js +691 -281
- package/dist/cjs/exact/facilitator/index.js.map +1 -1
- package/dist/cjs/exact/v1/client/index.js +43 -17
- package/dist/cjs/exact/v1/client/index.js.map +1 -1
- package/dist/cjs/exact/v1/facilitator/index.js +59 -26
- package/dist/cjs/exact/v1/facilitator/index.js.map +1 -1
- package/dist/cjs/index.d.ts +458 -31
- package/dist/cjs/index.js +438 -63
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/permit2-BYv82va2.d.ts +103 -0
- package/dist/cjs/v1/index.d.ts +21 -1
- package/dist/cjs/v1/index.js +33 -29
- package/dist/cjs/v1/index.js.map +1 -1
- package/dist/esm/chunk-DSSJHWGT.mjs +658 -0
- package/dist/esm/chunk-DSSJHWGT.mjs.map +1 -0
- package/dist/esm/chunk-PFULIQAE.mjs +13 -0
- package/dist/esm/chunk-PFULIQAE.mjs.map +1 -0
- package/dist/esm/chunk-U4H6Q62Q.mjs +229 -0
- package/dist/esm/chunk-U4H6Q62Q.mjs.map +1 -0
- package/dist/esm/exact/client/index.d.mts +2 -2
- package/dist/esm/exact/client/index.mjs +10 -30
- package/dist/esm/exact/client/index.mjs.map +1 -1
- package/dist/esm/exact/facilitator/index.d.mts +3 -0
- package/dist/esm/exact/facilitator/index.mjs +491 -241
- package/dist/esm/exact/facilitator/index.mjs.map +1 -1
- package/dist/esm/exact/v1/client/index.mjs +1 -2
- package/dist/esm/exact/v1/facilitator/index.mjs +2 -3
- package/dist/esm/index.d.mts +458 -31
- package/dist/esm/index.mjs +31 -4
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/permit2-BsAoJiWD.d.mts +103 -0
- package/dist/esm/v1/index.d.mts +21 -1
- package/dist/esm/v1/index.mjs +4 -6
- package/package.json +2 -2
- package/dist/esm/chunk-FOUXRQAV.mjs +0 -88
- package/dist/esm/chunk-FOUXRQAV.mjs.map +0 -1
- package/dist/esm/chunk-JYZWCLMP.mjs +0 -305
- package/dist/esm/chunk-JYZWCLMP.mjs.map +0 -1
- package/dist/esm/chunk-PSA4YVU2.mjs +0 -92
- package/dist/esm/chunk-PSA4YVU2.mjs.map +0 -1
- package/dist/esm/chunk-QLXM7BIB.mjs +0 -23
- package/dist/esm/chunk-QLXM7BIB.mjs.map +0 -1
- package/dist/esm/chunk-ZYXTTU74.mjs +0 -88
- package/dist/esm/chunk-ZYXTTU74.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/exact/facilitator/scheme.ts","../../../../src/exact/facilitator/register.ts"],"sourcesContent":["import {\n PaymentPayload,\n PaymentRequirements,\n SchemeNetworkFacilitator,\n SettleResponse,\n VerifyResponse,\n} from \"@x402/core/types\";\nimport { getAddress, Hex, isAddressEqual, parseErc6492Signature, parseSignature } from \"viem\";\nimport { authorizationTypes, eip3009ABI } from \"../../constants\";\nimport { FacilitatorEvmSigner } from \"../../signer\";\nimport { ExactEvmPayloadV2 } from \"../../types\";\n\nexport interface ExactEvmSchemeConfig {\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.\n */\nexport class ExactEvmScheme implements SchemeNetworkFacilitator {\n readonly scheme = \"exact\";\n readonly caipFamily = \"eip155:*\";\n private readonly config: Required<ExactEvmSchemeConfig>;\n\n /**\n * Creates a new ExactEvmFacilitator 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?: ExactEvmSchemeConfig,\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.\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 exactEvmPayload = payload.payload as ExactEvmPayloadV2;\n\n // Verify scheme matches\n if (payload.accepted.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 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 (payload.accepted.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: parseInt(requirements.network.split(\":\")[1]),\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(requirements.amount)) {\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(requirements.amount)) {\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.\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 exactEvmPayload = payload.payload as ExactEvmPayloadV2;\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: payload.accepted.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: payload.accepted.network,\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n return {\n success: true,\n transaction: tx,\n network: payload.accepted.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: payload.accepted.network,\n payer: exactEvmPayload.authorization.from,\n };\n }\n }\n}\n","import { x402Facilitator } from \"@x402/core/facilitator\";\nimport { Network } from \"@x402/core/types\";\nimport { FacilitatorEvmSigner } from \"../../signer\";\nimport { ExactEvmScheme } from \"./scheme\";\nimport { ExactEvmSchemeV1 } from \"../v1/facilitator/scheme\";\nimport { NETWORKS } from \"../../v1\";\n\n/**\n * Configuration options for registering EVM schemes to an x402Facilitator\n */\nexport interface EvmFacilitatorConfig {\n /**\n * The EVM signer for facilitator operations (verify and settle)\n */\n signer: FacilitatorEvmSigner;\n\n /**\n * Networks to register (single network or array of networks)\n * Examples: \"eip155:84532\", [\"eip155:84532\", \"eip155:1\"]\n */\n networks: Network | Network[];\n\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 * Registers EVM exact payment schemes to an x402Facilitator instance.\n *\n * This function registers:\n * - V2: Specified networks with ExactEvmScheme\n * - V1: All supported EVM networks with ExactEvmSchemeV1\n *\n * @param facilitator - The x402Facilitator instance to register schemes to\n * @param config - Configuration for EVM facilitator registration\n * @returns The facilitator instance for chaining\n *\n * @example\n * ```typescript\n * import { registerExactEvmScheme } from \"@x402/evm/exact/facilitator/register\";\n * import { x402Facilitator } from \"@x402/core/facilitator\";\n * import { createPublicClient, createWalletClient } from \"viem\";\n *\n * const facilitator = new x402Facilitator();\n *\n * // Single network\n * registerExactEvmScheme(facilitator, {\n * signer: combinedClient,\n * networks: \"eip155:84532\" // Base Sepolia\n * });\n *\n * // Multiple networks (will auto-derive eip155:* pattern)\n * registerExactEvmScheme(facilitator, {\n * signer: combinedClient,\n * networks: [\"eip155:84532\", \"eip155:1\"] // Base Sepolia and Mainnet\n * });\n * ```\n */\nexport function registerExactEvmScheme(\n facilitator: x402Facilitator,\n config: EvmFacilitatorConfig,\n): x402Facilitator {\n // Register V2 scheme with specified networks\n facilitator.register(\n config.networks,\n new ExactEvmScheme(config.signer, {\n deployERC4337WithEIP6492: config.deployERC4337WithEIP6492,\n }),\n );\n\n // Register all V1 networks\n facilitator.registerV1(\n NETWORKS as Network[],\n new ExactEvmSchemeV1(config.signer, {\n deployERC4337WithEIP6492: config.deployERC4337WithEIP6492,\n }),\n );\n\n return facilitator;\n}\n"],"mappings":";;;;;;;;;;;;;AAOA,SAAS,YAAiB,gBAAgB,uBAAuB,sBAAsB;AAkBhF,IAAM,iBAAN,MAAyD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA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AAc;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,QAAQ,SAAS;AAAA,QAC1B,OAAO,gBAAgB,cAAc;AAAA,MACvC;AAAA,IACF;AAAA,EACF;AACF;;;ACjVO,SAAS,uBACd,aACA,QACiB;AAEjB,cAAY;AAAA,IACV,OAAO;AAAA,IACP,IAAI,eAAe,OAAO,QAAQ;AAAA,MAChC,0BAA0B,OAAO;AAAA,IACnC,CAAC;AAAA,EACH;AAGA,cAAY;AAAA,IACV;AAAA,IACA,IAAI,iBAAiB,OAAO,QAAQ;AAAA,MAClC,0BAA0B,OAAO;AAAA,IACnC,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/exact/facilitator/eip3009.ts","../../../../src/exact/facilitator/permit2.ts","../../../../src/exact/facilitator/scheme.ts","../../../../src/exact/facilitator/register.ts"],"sourcesContent":["import {\n PaymentPayload,\n PaymentRequirements,\n SettleResponse,\n VerifyResponse,\n} from \"@x402/core/types\";\nimport { getAddress, Hex, isAddressEqual, parseErc6492Signature, parseSignature } from \"viem\";\nimport { authorizationTypes, eip3009ABI } from \"../../constants\";\nimport { FacilitatorEvmSigner } from \"../../signer\";\nimport { ExactEIP3009Payload } from \"../../types\";\n\nexport interface EIP3009FacilitatorConfig {\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 * Verifies an EIP-3009 payment payload.\n *\n * @param signer - The facilitator signer for contract reads\n * @param payload - The payment payload to verify\n * @param requirements - The payment requirements\n * @param eip3009Payload - The EIP-3009 specific payload\n * @returns Promise resolving to verification response\n */\nexport async function verifyEIP3009(\n signer: FacilitatorEvmSigner,\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n eip3009Payload: ExactEIP3009Payload,\n): Promise<VerifyResponse> {\n const payer = eip3009Payload.authorization.from;\n\n // Verify scheme matches\n if (payload.accepted.scheme !== \"exact\" || requirements.scheme !== \"exact\") {\n return {\n isValid: false,\n invalidReason: \"unsupported_scheme\",\n payer,\n };\n }\n\n // Get chain configuration\n if (!requirements.extra?.name || !requirements.extra?.version) {\n return {\n isValid: false,\n invalidReason: \"missing_eip712_domain\",\n payer,\n };\n }\n\n const { name, version } = requirements.extra;\n const erc20Address = getAddress(requirements.asset);\n\n // Verify network matches\n if (payload.accepted.network !== requirements.network) {\n return {\n isValid: false,\n invalidReason: \"network_mismatch\",\n payer,\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: parseInt(requirements.network.split(\":\")[1]),\n verifyingContract: erc20Address,\n },\n message: {\n from: eip3009Payload.authorization.from,\n to: eip3009Payload.authorization.to,\n value: BigInt(eip3009Payload.authorization.value),\n validAfter: BigInt(eip3009Payload.authorization.validAfter),\n validBefore: BigInt(eip3009Payload.authorization.validBefore),\n nonce: eip3009Payload.authorization.nonce,\n },\n };\n\n // Verify signature\n try {\n const recoveredAddress = await signer.verifyTypedData({\n address: eip3009Payload.authorization.from,\n ...permitTypedData,\n signature: eip3009Payload.signature!,\n });\n\n if (!recoveredAddress) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_signature\",\n payer,\n };\n }\n } catch {\n // Signature verification failed - could be an undeployed smart wallet\n // Check if smart wallet is deployed\n const signature = eip3009Payload.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 = eip3009Payload.authorization.from;\n const bytecode = await 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 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 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 } 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,\n };\n }\n } else {\n // EOA signature failed\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_signature\",\n payer,\n };\n }\n }\n\n // Verify payment recipient matches\n if (getAddress(eip3009Payload.authorization.to) !== getAddress(requirements.payTo)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_recipient_mismatch\",\n payer,\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(eip3009Payload.authorization.validBefore) < BigInt(now + 6)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_authorization_valid_before\",\n payer,\n };\n }\n\n // Verify validAfter is not in the future\n if (BigInt(eip3009Payload.authorization.validAfter) > BigInt(now)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_authorization_valid_after\",\n payer,\n };\n }\n\n // Check balance\n try {\n const balance = (await signer.readContract({\n address: erc20Address,\n abi: eip3009ABI,\n functionName: \"balanceOf\",\n args: [eip3009Payload.authorization.from],\n })) as bigint;\n\n if (BigInt(balance) < BigInt(requirements.amount)) {\n return {\n isValid: false,\n invalidReason: \"insufficient_funds\",\n invalidMessage: `Insufficient funds to complete the payment. Required: ${requirements.amount} ${requirements.asset}, Available: ${balance.toString()} ${requirements.asset}. Please add funds to your wallet and try again.`,\n payer,\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(eip3009Payload.authorization.value) < BigInt(requirements.amount)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_authorization_value\",\n payer,\n };\n }\n\n return {\n isValid: true,\n invalidReason: undefined,\n payer,\n };\n}\n\n/**\n * Settles an EIP-3009 payment by executing transferWithAuthorization.\n *\n * @param signer - The facilitator signer for contract writes\n * @param payload - The payment payload to settle\n * @param requirements - The payment requirements\n * @param eip3009Payload - The EIP-3009 specific payload\n * @param config - Facilitator configuration\n * @returns Promise resolving to settlement response\n */\nexport async function settleEIP3009(\n signer: FacilitatorEvmSigner,\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n eip3009Payload: ExactEIP3009Payload,\n config: EIP3009FacilitatorConfig,\n): Promise<SettleResponse> {\n const payer = eip3009Payload.authorization.from;\n\n // Re-verify before settling\n const valid = await verifyEIP3009(signer, payload, requirements, eip3009Payload);\n if (!valid.isValid) {\n return {\n success: false,\n network: payload.accepted.network,\n transaction: \"\",\n errorReason: valid.invalidReason ?? \"invalid_scheme\",\n payer,\n };\n }\n\n try {\n // Parse ERC-6492 signature if applicable\n const parseResult = parseErc6492Signature(eip3009Payload.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 config.deployERC4337WithEIP6492 &&\n factoryAddress &&\n factoryCalldata &&\n !isAddressEqual(factoryAddress, \"0x0000000000000000000000000000000000000000\")\n ) {\n // Check if smart wallet is already deployed\n const bytecode = await signer.getCode({ address: payer });\n\n if (!bytecode || bytecode === \"0x\") {\n // Wallet not deployed - attempt deployment\n const deployTx = await signer.sendTransaction({\n to: factoryAddress as Hex,\n data: factoryCalldata as Hex,\n });\n\n // Wait for deployment transaction\n await signer.waitForTransactionReceipt({ hash: deployTx });\n }\n }\n\n // Determine if this is an ECDSA signature (EOA) or smart wallet signature\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 signer.writeContract({\n address: getAddress(requirements.asset),\n abi: eip3009ABI,\n functionName: \"transferWithAuthorization\",\n args: [\n getAddress(eip3009Payload.authorization.from),\n getAddress(eip3009Payload.authorization.to),\n BigInt(eip3009Payload.authorization.value),\n BigInt(eip3009Payload.authorization.validAfter),\n BigInt(eip3009Payload.authorization.validBefore),\n eip3009Payload.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 tx = await signer.writeContract({\n address: getAddress(requirements.asset),\n abi: eip3009ABI,\n functionName: \"transferWithAuthorization\",\n args: [\n getAddress(eip3009Payload.authorization.from),\n getAddress(eip3009Payload.authorization.to),\n BigInt(eip3009Payload.authorization.value),\n BigInt(eip3009Payload.authorization.validAfter),\n BigInt(eip3009Payload.authorization.validBefore),\n eip3009Payload.authorization.nonce,\n signature,\n ],\n });\n }\n\n // Wait for transaction confirmation\n const receipt = await 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: payload.accepted.network,\n payer,\n };\n }\n\n return {\n success: true,\n transaction: tx,\n network: payload.accepted.network,\n payer,\n };\n } catch {\n return {\n success: false,\n errorReason: \"transaction_failed\",\n transaction: \"\",\n network: payload.accepted.network,\n payer,\n };\n }\n}\n","import {\n PaymentPayload,\n PaymentRequirements,\n SettleResponse,\n VerifyResponse,\n} from \"@x402/core/types\";\nimport { getAddress } from \"viem\";\nimport {\n eip3009ABI,\n PERMIT2_ADDRESS,\n permit2WitnessTypes,\n x402ExactPermit2ProxyABI,\n x402ExactPermit2ProxyAddress,\n} from \"../../constants\";\nimport { FacilitatorEvmSigner } from \"../../signer\";\nimport { ExactPermit2Payload } from \"../../types\";\n\n// ERC20 allowance ABI for checking Permit2 approval\nconst erc20AllowanceABI = [\n {\n type: \"function\",\n name: \"allowance\",\n inputs: [\n { name: \"owner\", type: \"address\" },\n { name: \"spender\", type: \"address\" },\n ],\n outputs: [{ type: \"uint256\" }],\n stateMutability: \"view\",\n },\n] as const;\n\n/**\n * Verifies a Permit2 payment payload.\n *\n * @param signer - The facilitator signer for contract reads\n * @param payload - The payment payload to verify\n * @param requirements - The payment requirements\n * @param permit2Payload - The Permit2 specific payload\n * @returns Promise resolving to verification response\n */\nexport async function verifyPermit2(\n signer: FacilitatorEvmSigner,\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n permit2Payload: ExactPermit2Payload,\n): Promise<VerifyResponse> {\n const payer = permit2Payload.permit2Authorization.from;\n\n // Verify scheme matches\n if (payload.accepted.scheme !== \"exact\" || requirements.scheme !== \"exact\") {\n return {\n isValid: false,\n invalidReason: \"unsupported_scheme\",\n payer,\n };\n }\n\n // Verify network matches\n if (payload.accepted.network !== requirements.network) {\n return {\n isValid: false,\n invalidReason: \"network_mismatch\",\n payer,\n };\n }\n\n const chainId = parseInt(requirements.network.split(\":\")[1]);\n const tokenAddress = getAddress(requirements.asset);\n\n // Verify spender is the x402ExactPermit2Proxy\n if (\n getAddress(permit2Payload.permit2Authorization.spender) !==\n getAddress(x402ExactPermit2ProxyAddress)\n ) {\n return {\n isValid: false,\n invalidReason: \"invalid_permit2_spender\",\n payer,\n };\n }\n\n // Verify witness.to matches payTo\n if (\n getAddress(permit2Payload.permit2Authorization.witness.to) !== getAddress(requirements.payTo)\n ) {\n return {\n isValid: false,\n invalidReason: \"invalid_permit2_recipient_mismatch\",\n payer,\n };\n }\n\n // Verify deadline not expired (with 6 second buffer for block time)\n const now = Math.floor(Date.now() / 1000);\n if (BigInt(permit2Payload.permit2Authorization.deadline) < BigInt(now + 6)) {\n return {\n isValid: false,\n invalidReason: \"permit2_deadline_expired\",\n payer,\n };\n }\n\n // Verify validAfter is not in the future\n if (BigInt(permit2Payload.permit2Authorization.witness.validAfter) > BigInt(now)) {\n return {\n isValid: false,\n invalidReason: \"permit2_not_yet_valid\",\n payer,\n };\n }\n\n // Verify amount is sufficient\n if (BigInt(permit2Payload.permit2Authorization.permitted.amount) < BigInt(requirements.amount)) {\n return {\n isValid: false,\n invalidReason: \"permit2_insufficient_amount\",\n payer,\n };\n }\n\n // Verify token matches\n if (getAddress(permit2Payload.permit2Authorization.permitted.token) !== tokenAddress) {\n return {\n isValid: false,\n invalidReason: \"permit2_token_mismatch\",\n payer,\n };\n }\n\n // Build typed data for Permit2 signature verification\n const permit2TypedData = {\n types: permit2WitnessTypes,\n primaryType: \"PermitWitnessTransferFrom\" as const,\n domain: {\n name: \"Permit2\",\n chainId,\n verifyingContract: PERMIT2_ADDRESS,\n },\n message: {\n permitted: {\n token: getAddress(permit2Payload.permit2Authorization.permitted.token),\n amount: BigInt(permit2Payload.permit2Authorization.permitted.amount),\n },\n spender: getAddress(permit2Payload.permit2Authorization.spender),\n nonce: BigInt(permit2Payload.permit2Authorization.nonce),\n deadline: BigInt(permit2Payload.permit2Authorization.deadline),\n witness: {\n to: getAddress(permit2Payload.permit2Authorization.witness.to),\n validAfter: BigInt(permit2Payload.permit2Authorization.witness.validAfter),\n extra: permit2Payload.permit2Authorization.witness.extra,\n },\n },\n };\n\n // Verify signature\n try {\n const isValid = await signer.verifyTypedData({\n address: payer,\n ...permit2TypedData,\n signature: permit2Payload.signature,\n });\n\n if (!isValid) {\n return {\n isValid: false,\n invalidReason: \"invalid_permit2_signature\",\n payer,\n };\n }\n } catch {\n return {\n isValid: false,\n invalidReason: \"invalid_permit2_signature\",\n payer,\n };\n }\n\n // Check Permit2 allowance\n try {\n const allowance = (await signer.readContract({\n address: tokenAddress,\n abi: erc20AllowanceABI,\n functionName: \"allowance\",\n args: [payer, PERMIT2_ADDRESS],\n })) as bigint;\n\n if (allowance < BigInt(requirements.amount)) {\n return {\n isValid: false,\n invalidReason: \"permit2_allowance_required\",\n payer,\n };\n }\n } catch {\n // If we can't check allowance, continue - settlement will fail if insufficient\n }\n\n // Check balance\n try {\n const balance = (await signer.readContract({\n address: tokenAddress,\n abi: eip3009ABI,\n functionName: \"balanceOf\",\n args: [payer],\n })) as bigint;\n\n if (balance < BigInt(requirements.amount)) {\n return {\n isValid: false,\n invalidReason: \"insufficient_funds\",\n invalidMessage: `Insufficient funds to complete the payment. Required: ${requirements.amount} ${requirements.asset}, Available: ${balance.toString()} ${requirements.asset}. Please add funds to your wallet and try again.`,\n payer,\n };\n }\n } catch {\n // If we can't check balance, continue with other validations\n }\n\n return {\n isValid: true,\n invalidReason: undefined,\n payer,\n };\n}\n\n/**\n * Settles a Permit2 payment by calling the x402ExactPermit2Proxy.\n *\n * @param signer - The facilitator signer for contract writes\n * @param payload - The payment payload to settle\n * @param requirements - The payment requirements\n * @param permit2Payload - The Permit2 specific payload\n * @returns Promise resolving to settlement response\n */\nexport async function settlePermit2(\n signer: FacilitatorEvmSigner,\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n permit2Payload: ExactPermit2Payload,\n): Promise<SettleResponse> {\n const payer = permit2Payload.permit2Authorization.from;\n\n // Re-verify before settling\n const valid = await verifyPermit2(signer, payload, requirements, permit2Payload);\n if (!valid.isValid) {\n return {\n success: false,\n network: payload.accepted.network,\n transaction: \"\",\n errorReason: valid.invalidReason ?? \"invalid_scheme\",\n payer,\n };\n }\n\n try {\n // Call x402ExactPermit2Proxy.settle()\n const tx = await signer.writeContract({\n address: x402ExactPermit2ProxyAddress,\n abi: x402ExactPermit2ProxyABI,\n functionName: \"settle\",\n args: [\n {\n permitted: {\n token: getAddress(permit2Payload.permit2Authorization.permitted.token),\n amount: BigInt(permit2Payload.permit2Authorization.permitted.amount),\n },\n nonce: BigInt(permit2Payload.permit2Authorization.nonce),\n deadline: BigInt(permit2Payload.permit2Authorization.deadline),\n },\n getAddress(payer),\n {\n to: getAddress(permit2Payload.permit2Authorization.witness.to),\n validAfter: BigInt(permit2Payload.permit2Authorization.witness.validAfter),\n extra: permit2Payload.permit2Authorization.witness.extra as `0x${string}`,\n },\n permit2Payload.signature,\n ],\n });\n\n // Wait for transaction confirmation\n const receipt = await 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: payload.accepted.network,\n payer,\n };\n }\n\n return {\n success: true,\n transaction: tx,\n network: payload.accepted.network,\n payer,\n };\n } catch (error) {\n // Extract meaningful error message from the contract revert\n let errorReason = \"transaction_failed\";\n if (error instanceof Error) {\n // Check for common contract revert patterns\n const message = error.message;\n if (message.includes(\"AmountExceedsPermitted\")) {\n errorReason = \"permit2_amount_exceeds_permitted\";\n } else if (message.includes(\"InvalidDestination\")) {\n errorReason = \"permit2_invalid_destination\";\n } else if (message.includes(\"InvalidOwner\")) {\n errorReason = \"permit2_invalid_owner\";\n } else if (message.includes(\"PaymentTooEarly\")) {\n errorReason = \"permit2_payment_too_early\";\n } else if (message.includes(\"InvalidSignature\") || message.includes(\"SignatureExpired\")) {\n errorReason = \"permit2_invalid_signature\";\n } else if (message.includes(\"InvalidNonce\")) {\n errorReason = \"permit2_invalid_nonce\";\n } else {\n // Include error message for debugging (longer for better visibility)\n errorReason = `transaction_failed: ${message.slice(0, 500)}`;\n }\n }\n return {\n success: false,\n errorReason,\n transaction: \"\",\n network: payload.accepted.network,\n payer,\n };\n }\n}\n","import {\n PaymentPayload,\n PaymentRequirements,\n SchemeNetworkFacilitator,\n SettleResponse,\n VerifyResponse,\n} from \"@x402/core/types\";\nimport { FacilitatorEvmSigner } from \"../../signer\";\nimport { ExactEvmPayloadV2, ExactEIP3009Payload, isPermit2Payload } from \"../../types\";\nimport { verifyEIP3009, settleEIP3009 } from \"./eip3009\";\nimport { verifyPermit2, settlePermit2 } from \"./permit2\";\n\nexport interface ExactEvmSchemeConfig {\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.\n * Routes between EIP-3009 and Permit2 based on payload type.\n */\nexport class ExactEvmScheme implements SchemeNetworkFacilitator {\n readonly scheme = \"exact\";\n readonly caipFamily = \"eip155:*\";\n private readonly config: Required<ExactEvmSchemeConfig>;\n\n /**\n * Creates a new ExactEvmFacilitator 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?: ExactEvmSchemeConfig,\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.\n * Routes to the appropriate verification logic based on payload type.\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 rawPayload = payload.payload as ExactEvmPayloadV2;\n\n // Route based on payload type\n if (isPermit2Payload(rawPayload)) {\n return verifyPermit2(this.signer, payload, requirements, rawPayload);\n }\n\n // Type-narrowed to EIP-3009 payload\n const eip3009Payload: ExactEIP3009Payload = rawPayload;\n return verifyEIP3009(this.signer, payload, requirements, eip3009Payload);\n }\n\n /**\n * Settles a payment by executing the transfer.\n * Routes to the appropriate settlement logic based on payload type.\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 rawPayload = payload.payload as ExactEvmPayloadV2;\n\n // Route based on payload type\n if (isPermit2Payload(rawPayload)) {\n return settlePermit2(this.signer, payload, requirements, rawPayload);\n }\n\n // Type-narrowed to EIP-3009 payload\n const eip3009Payload: ExactEIP3009Payload = rawPayload;\n return settleEIP3009(this.signer, payload, requirements, eip3009Payload, this.config);\n }\n}\n","import { x402Facilitator } from \"@x402/core/facilitator\";\nimport { Network } from \"@x402/core/types\";\nimport { FacilitatorEvmSigner } from \"../../signer\";\nimport { ExactEvmScheme } from \"./scheme\";\nimport { ExactEvmSchemeV1 } from \"../v1/facilitator/scheme\";\nimport { NETWORKS } from \"../../v1\";\n\n/**\n * Configuration options for registering EVM schemes to an x402Facilitator\n */\nexport interface EvmFacilitatorConfig {\n /**\n * The EVM signer for facilitator operations (verify and settle)\n */\n signer: FacilitatorEvmSigner;\n\n /**\n * Networks to register (single network or array of networks)\n * Examples: \"eip155:84532\", [\"eip155:84532\", \"eip155:1\"]\n */\n networks: Network | Network[];\n\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 * Registers EVM exact payment schemes to an x402Facilitator instance.\n *\n * This function registers:\n * - V2: Specified networks with ExactEvmScheme\n * - V1: All supported EVM networks with ExactEvmSchemeV1\n *\n * @param facilitator - The x402Facilitator instance to register schemes to\n * @param config - Configuration for EVM facilitator registration\n * @returns The facilitator instance for chaining\n *\n * @example\n * ```typescript\n * import { registerExactEvmScheme } from \"@x402/evm/exact/facilitator/register\";\n * import { x402Facilitator } from \"@x402/core/facilitator\";\n * import { createPublicClient, createWalletClient } from \"viem\";\n *\n * const facilitator = new x402Facilitator();\n *\n * // Single network\n * registerExactEvmScheme(facilitator, {\n * signer: combinedClient,\n * networks: \"eip155:84532\" // Base Sepolia\n * });\n *\n * // Multiple networks (will auto-derive eip155:* pattern)\n * registerExactEvmScheme(facilitator, {\n * signer: combinedClient,\n * networks: [\"eip155:84532\", \"eip155:1\"] // Base Sepolia and Mainnet\n * });\n * ```\n */\nexport function registerExactEvmScheme(\n facilitator: x402Facilitator,\n config: EvmFacilitatorConfig,\n): x402Facilitator {\n // Register V2 scheme with specified networks\n facilitator.register(\n config.networks,\n new ExactEvmScheme(config.signer, {\n deployERC4337WithEIP6492: config.deployERC4337WithEIP6492,\n }),\n );\n\n // Register all V1 networks\n facilitator.registerV1(\n NETWORKS as Network[],\n new ExactEvmSchemeV1(config.signer, {\n deployERC4337WithEIP6492: config.deployERC4337WithEIP6492,\n }),\n );\n\n return facilitator;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAMA,SAAS,YAAiB,gBAAgB,uBAAuB,sBAAsB;AAwBvF,eAAsB,cACpB,QACA,SACA,cACA,gBACyB;AACzB,QAAM,QAAQ,eAAe,cAAc;AAG3C,MAAI,QAAQ,SAAS,WAAW,WAAW,aAAa,WAAW,SAAS;AAC1E,WAAO;AAAA,MACL,SAAS;AAAA,MACT,eAAe;AAAA,MACf;AAAA,IACF;AAAA,EACF;AAGA,MAAI,CAAC,aAAa,OAAO,QAAQ,CAAC,aAAa,OAAO,SAAS;AAC7D,WAAO;AAAA,MACL,SAAS;AAAA,MACT,eAAe;AAAA,MACf;AAAA,IACF;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,QAAQ,IAAI,aAAa;AACvC,QAAM,eAAe,WAAW,aAAa,KAAK;AAGlD,MAAI,QAAQ,SAAS,YAAY,aAAa,SAAS;AACrD,WAAO;AAAA,MACL,SAAS;AAAA,MACT,eAAe;AAAA,MACf;AAAA,IACF;AAAA,EACF;AAGA,QAAM,kBAAkB;AAAA,IACtB,OAAO;AAAA,IACP,aAAa;AAAA,IACb,QAAQ;AAA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;AAAA,MAChC,0BAA0B,OAAO;AAAA,IACnC,CAAC;AAAA,EACH;AAGA,cAAY;AAAA,IACV;AAAA,IACA,IAAI,iBAAiB,OAAO,QAAQ;AAAA,MAClC,0BAA0B,OAAO;AAAA,IACnC,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":["getAddress","getAddress"]}
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,36 +1,463 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export { E as ExactEvmScheme, P as Permit2AllowanceParams, c as createPermit2ApprovalTx, e as erc20AllowanceAbi, g as getPermit2AllowanceReadParams } from './permit2-BsAoJiWD.mjs';
|
|
2
|
+
export { C as ClientEvmSigner, F as FacilitatorEvmSigner, t as toClientEvmSigner, a as toFacilitatorEvmSigner } from './signer-5OVDxViv.mjs';
|
|
3
|
+
import '@x402/core/types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Asset transfer methods for the exact EVM scheme.
|
|
7
|
+
* - eip3009: Uses transferWithAuthorization (USDC, etc.) - recommended for compatible tokens
|
|
8
|
+
* - permit2: Uses Permit2 + x402Permit2Proxy - universal fallback for any ERC-20
|
|
9
|
+
*/
|
|
10
|
+
type AssetTransferMethod = "eip3009" | "permit2";
|
|
11
|
+
/**
|
|
12
|
+
* EIP-3009 payload for tokens with native transferWithAuthorization support.
|
|
13
|
+
*/
|
|
14
|
+
type ExactEIP3009Payload = {
|
|
15
|
+
signature?: `0x${string}`;
|
|
16
|
+
authorization: {
|
|
17
|
+
from: `0x${string}`;
|
|
18
|
+
to: `0x${string}`;
|
|
19
|
+
value: string;
|
|
20
|
+
validAfter: string;
|
|
21
|
+
validBefore: string;
|
|
22
|
+
nonce: `0x${string}`;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Permit2 witness data structure.
|
|
27
|
+
* Matches the Witness struct in x402Permit2Proxy contract.
|
|
28
|
+
* Note: Upper time bound is enforced by Permit2's `deadline` field, not a witness field.
|
|
29
|
+
*/
|
|
30
|
+
type Permit2Witness = {
|
|
31
|
+
to: `0x${string}`;
|
|
32
|
+
validAfter: string;
|
|
33
|
+
extra: `0x${string}`;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Permit2 authorization parameters.
|
|
37
|
+
* Used to reconstruct the signed message for verification.
|
|
38
|
+
*/
|
|
39
|
+
type Permit2Authorization = {
|
|
40
|
+
permitted: {
|
|
41
|
+
token: `0x${string}`;
|
|
42
|
+
amount: string;
|
|
43
|
+
};
|
|
44
|
+
spender: `0x${string}`;
|
|
45
|
+
nonce: string;
|
|
46
|
+
deadline: string;
|
|
47
|
+
witness: Permit2Witness;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Permit2 payload for tokens using the Permit2 + x402Permit2Proxy flow.
|
|
51
|
+
*/
|
|
52
|
+
type ExactPermit2Payload = {
|
|
53
|
+
signature: `0x${string}`;
|
|
54
|
+
permit2Authorization: Permit2Authorization & {
|
|
55
|
+
from: `0x${string}`;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
type ExactEvmPayloadV1 = ExactEIP3009Payload;
|
|
59
|
+
type ExactEvmPayloadV2 = ExactEIP3009Payload | ExactPermit2Payload;
|
|
60
|
+
/**
|
|
61
|
+
* Type guard to check if a payload is a Permit2 payload.
|
|
62
|
+
* Permit2 payloads have a `permit2Authorization` field.
|
|
63
|
+
*
|
|
64
|
+
* @param payload - The payload to check.
|
|
65
|
+
* @returns True if the payload is a Permit2 payload, false otherwise.
|
|
66
|
+
*/
|
|
67
|
+
declare function isPermit2Payload(payload: ExactEvmPayloadV2): payload is ExactPermit2Payload;
|
|
68
|
+
/**
|
|
69
|
+
* Type guard to check if a payload is an EIP-3009 payload.
|
|
70
|
+
* EIP-3009 payloads have an `authorization` field.
|
|
7
71
|
*
|
|
72
|
+
* @param payload - The payload to check.
|
|
73
|
+
* @returns True if the payload is an EIP-3009 payload, false otherwise.
|
|
74
|
+
*/
|
|
75
|
+
declare function isEIP3009Payload(payload: ExactEvmPayloadV2): payload is ExactEIP3009Payload;
|
|
76
|
+
|
|
77
|
+
declare const authorizationTypes: {
|
|
78
|
+
readonly TransferWithAuthorization: readonly [{
|
|
79
|
+
readonly name: "from";
|
|
80
|
+
readonly type: "address";
|
|
81
|
+
}, {
|
|
82
|
+
readonly name: "to";
|
|
83
|
+
readonly type: "address";
|
|
84
|
+
}, {
|
|
85
|
+
readonly name: "value";
|
|
86
|
+
readonly type: "uint256";
|
|
87
|
+
}, {
|
|
88
|
+
readonly name: "validAfter";
|
|
89
|
+
readonly type: "uint256";
|
|
90
|
+
}, {
|
|
91
|
+
readonly name: "validBefore";
|
|
92
|
+
readonly type: "uint256";
|
|
93
|
+
}, {
|
|
94
|
+
readonly name: "nonce";
|
|
95
|
+
readonly type: "bytes32";
|
|
96
|
+
}];
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Permit2 EIP-712 types for signing PermitWitnessTransferFrom.
|
|
100
|
+
* Must match the exact format expected by the Permit2 contract.
|
|
101
|
+
* Note: Types must be in ALPHABETICAL order after the primary type (TokenPermissions < Witness).
|
|
102
|
+
*/
|
|
103
|
+
declare const permit2WitnessTypes: {
|
|
104
|
+
readonly PermitWitnessTransferFrom: readonly [{
|
|
105
|
+
readonly name: "permitted";
|
|
106
|
+
readonly type: "TokenPermissions";
|
|
107
|
+
}, {
|
|
108
|
+
readonly name: "spender";
|
|
109
|
+
readonly type: "address";
|
|
110
|
+
}, {
|
|
111
|
+
readonly name: "nonce";
|
|
112
|
+
readonly type: "uint256";
|
|
113
|
+
}, {
|
|
114
|
+
readonly name: "deadline";
|
|
115
|
+
readonly type: "uint256";
|
|
116
|
+
}, {
|
|
117
|
+
readonly name: "witness";
|
|
118
|
+
readonly type: "Witness";
|
|
119
|
+
}];
|
|
120
|
+
readonly TokenPermissions: readonly [{
|
|
121
|
+
readonly name: "token";
|
|
122
|
+
readonly type: "address";
|
|
123
|
+
}, {
|
|
124
|
+
readonly name: "amount";
|
|
125
|
+
readonly type: "uint256";
|
|
126
|
+
}];
|
|
127
|
+
readonly Witness: readonly [{
|
|
128
|
+
readonly name: "to";
|
|
129
|
+
readonly type: "address";
|
|
130
|
+
}, {
|
|
131
|
+
readonly name: "validAfter";
|
|
132
|
+
readonly type: "uint256";
|
|
133
|
+
}, {
|
|
134
|
+
readonly name: "extra";
|
|
135
|
+
readonly type: "bytes";
|
|
136
|
+
}];
|
|
137
|
+
};
|
|
138
|
+
declare const eip3009ABI: readonly [{
|
|
139
|
+
readonly inputs: readonly [{
|
|
140
|
+
readonly name: "from";
|
|
141
|
+
readonly type: "address";
|
|
142
|
+
}, {
|
|
143
|
+
readonly name: "to";
|
|
144
|
+
readonly type: "address";
|
|
145
|
+
}, {
|
|
146
|
+
readonly name: "value";
|
|
147
|
+
readonly type: "uint256";
|
|
148
|
+
}, {
|
|
149
|
+
readonly name: "validAfter";
|
|
150
|
+
readonly type: "uint256";
|
|
151
|
+
}, {
|
|
152
|
+
readonly name: "validBefore";
|
|
153
|
+
readonly type: "uint256";
|
|
154
|
+
}, {
|
|
155
|
+
readonly name: "nonce";
|
|
156
|
+
readonly type: "bytes32";
|
|
157
|
+
}, {
|
|
158
|
+
readonly name: "v";
|
|
159
|
+
readonly type: "uint8";
|
|
160
|
+
}, {
|
|
161
|
+
readonly name: "r";
|
|
162
|
+
readonly type: "bytes32";
|
|
163
|
+
}, {
|
|
164
|
+
readonly name: "s";
|
|
165
|
+
readonly type: "bytes32";
|
|
166
|
+
}];
|
|
167
|
+
readonly name: "transferWithAuthorization";
|
|
168
|
+
readonly outputs: readonly [];
|
|
169
|
+
readonly stateMutability: "nonpayable";
|
|
170
|
+
readonly type: "function";
|
|
171
|
+
}, {
|
|
172
|
+
readonly inputs: readonly [{
|
|
173
|
+
readonly name: "from";
|
|
174
|
+
readonly type: "address";
|
|
175
|
+
}, {
|
|
176
|
+
readonly name: "to";
|
|
177
|
+
readonly type: "address";
|
|
178
|
+
}, {
|
|
179
|
+
readonly name: "value";
|
|
180
|
+
readonly type: "uint256";
|
|
181
|
+
}, {
|
|
182
|
+
readonly name: "validAfter";
|
|
183
|
+
readonly type: "uint256";
|
|
184
|
+
}, {
|
|
185
|
+
readonly name: "validBefore";
|
|
186
|
+
readonly type: "uint256";
|
|
187
|
+
}, {
|
|
188
|
+
readonly name: "nonce";
|
|
189
|
+
readonly type: "bytes32";
|
|
190
|
+
}, {
|
|
191
|
+
readonly name: "signature";
|
|
192
|
+
readonly type: "bytes";
|
|
193
|
+
}];
|
|
194
|
+
readonly name: "transferWithAuthorization";
|
|
195
|
+
readonly outputs: readonly [];
|
|
196
|
+
readonly stateMutability: "nonpayable";
|
|
197
|
+
readonly type: "function";
|
|
198
|
+
}, {
|
|
199
|
+
readonly inputs: readonly [{
|
|
200
|
+
readonly name: "account";
|
|
201
|
+
readonly type: "address";
|
|
202
|
+
}];
|
|
203
|
+
readonly name: "balanceOf";
|
|
204
|
+
readonly outputs: readonly [{
|
|
205
|
+
readonly name: "";
|
|
206
|
+
readonly type: "uint256";
|
|
207
|
+
}];
|
|
208
|
+
readonly stateMutability: "view";
|
|
209
|
+
readonly type: "function";
|
|
210
|
+
}, {
|
|
211
|
+
readonly inputs: readonly [];
|
|
212
|
+
readonly name: "version";
|
|
213
|
+
readonly outputs: readonly [{
|
|
214
|
+
readonly name: "";
|
|
215
|
+
readonly type: "string";
|
|
216
|
+
}];
|
|
217
|
+
readonly stateMutability: "view";
|
|
218
|
+
readonly type: "function";
|
|
219
|
+
}];
|
|
220
|
+
/**
|
|
221
|
+
* Canonical Permit2 contract address.
|
|
222
|
+
* Same address on all EVM chains via CREATE2 deployment.
|
|
223
|
+
*
|
|
224
|
+
* @see https://github.com/Uniswap/permit2
|
|
225
|
+
*/
|
|
226
|
+
declare const PERMIT2_ADDRESS: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
227
|
+
/**
|
|
228
|
+
* x402ExactPermit2Proxy contract address.
|
|
229
|
+
* Vanity address: 0x4020...0001 for easy recognition.
|
|
230
|
+
* This address is deterministic based on:
|
|
231
|
+
* - Arachnid's deterministic deployer (0x4e59b44847b379578588920cA78FbF26c0B4956C)
|
|
232
|
+
* - Vanity-mined salt for prefix 0x4020 and suffix 0001
|
|
233
|
+
* - Contract bytecode + constructor args (PERMIT2_ADDRESS)
|
|
234
|
+
*/
|
|
235
|
+
declare const x402ExactPermit2ProxyAddress: "0x4020615294c913F045dc10f0a5cdEbd86c280001";
|
|
236
|
+
/**
|
|
237
|
+
* x402UptoPermit2Proxy contract address.
|
|
238
|
+
* Vanity address: 0x4020...0002 for easy recognition.
|
|
239
|
+
* This address is deterministic based on:
|
|
240
|
+
* - Arachnid's deterministic deployer (0x4e59b44847b379578588920cA78FbF26c0B4956C)
|
|
241
|
+
* - Vanity-mined salt for prefix 0x4020 and suffix 0002
|
|
242
|
+
* - Contract bytecode + constructor args (PERMIT2_ADDRESS)
|
|
243
|
+
*/
|
|
244
|
+
declare const x402UptoPermit2ProxyAddress: "0x4020633461b2895a48930Ff97eE8fCdE8E520002";
|
|
245
|
+
/**
|
|
246
|
+
* x402ExactPermit2Proxy ABI - settle function for exact payment scheme.
|
|
8
247
|
*/
|
|
9
|
-
declare
|
|
10
|
-
|
|
11
|
-
readonly
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
248
|
+
declare const x402ExactPermit2ProxyABI: readonly [{
|
|
249
|
+
readonly type: "function";
|
|
250
|
+
readonly name: "PERMIT2";
|
|
251
|
+
readonly inputs: readonly [];
|
|
252
|
+
readonly outputs: readonly [{
|
|
253
|
+
readonly name: "";
|
|
254
|
+
readonly type: "address";
|
|
255
|
+
readonly internalType: "contract ISignatureTransfer";
|
|
256
|
+
}];
|
|
257
|
+
readonly stateMutability: "view";
|
|
258
|
+
}, {
|
|
259
|
+
readonly type: "function";
|
|
260
|
+
readonly name: "WITNESS_TYPEHASH";
|
|
261
|
+
readonly inputs: readonly [];
|
|
262
|
+
readonly outputs: readonly [{
|
|
263
|
+
readonly name: "";
|
|
264
|
+
readonly type: "bytes32";
|
|
265
|
+
readonly internalType: "bytes32";
|
|
266
|
+
}];
|
|
267
|
+
readonly stateMutability: "view";
|
|
268
|
+
}, {
|
|
269
|
+
readonly type: "function";
|
|
270
|
+
readonly name: "WITNESS_TYPE_STRING";
|
|
271
|
+
readonly inputs: readonly [];
|
|
272
|
+
readonly outputs: readonly [{
|
|
273
|
+
readonly name: "";
|
|
274
|
+
readonly type: "string";
|
|
275
|
+
readonly internalType: "string";
|
|
276
|
+
}];
|
|
277
|
+
readonly stateMutability: "view";
|
|
278
|
+
}, {
|
|
279
|
+
readonly type: "function";
|
|
280
|
+
readonly name: "initialize";
|
|
281
|
+
readonly inputs: readonly [{
|
|
282
|
+
readonly name: "_permit2";
|
|
283
|
+
readonly type: "address";
|
|
284
|
+
readonly internalType: "address";
|
|
285
|
+
}];
|
|
286
|
+
readonly outputs: readonly [];
|
|
287
|
+
readonly stateMutability: "nonpayable";
|
|
288
|
+
}, {
|
|
289
|
+
readonly type: "function";
|
|
290
|
+
readonly name: "settle";
|
|
291
|
+
readonly inputs: readonly [{
|
|
292
|
+
readonly name: "permit";
|
|
293
|
+
readonly type: "tuple";
|
|
294
|
+
readonly internalType: "struct ISignatureTransfer.PermitTransferFrom";
|
|
295
|
+
readonly components: readonly [{
|
|
296
|
+
readonly name: "permitted";
|
|
297
|
+
readonly type: "tuple";
|
|
298
|
+
readonly internalType: "struct ISignatureTransfer.TokenPermissions";
|
|
299
|
+
readonly components: readonly [{
|
|
300
|
+
readonly name: "token";
|
|
301
|
+
readonly type: "address";
|
|
302
|
+
readonly internalType: "address";
|
|
303
|
+
}, {
|
|
304
|
+
readonly name: "amount";
|
|
305
|
+
readonly type: "uint256";
|
|
306
|
+
readonly internalType: "uint256";
|
|
307
|
+
}];
|
|
308
|
+
}, {
|
|
309
|
+
readonly name: "nonce";
|
|
310
|
+
readonly type: "uint256";
|
|
311
|
+
readonly internalType: "uint256";
|
|
312
|
+
}, {
|
|
313
|
+
readonly name: "deadline";
|
|
314
|
+
readonly type: "uint256";
|
|
315
|
+
readonly internalType: "uint256";
|
|
316
|
+
}];
|
|
317
|
+
}, {
|
|
318
|
+
readonly name: "owner";
|
|
319
|
+
readonly type: "address";
|
|
320
|
+
readonly internalType: "address";
|
|
321
|
+
}, {
|
|
322
|
+
readonly name: "witness";
|
|
323
|
+
readonly type: "tuple";
|
|
324
|
+
readonly internalType: "struct x402BasePermit2Proxy.Witness";
|
|
325
|
+
readonly components: readonly [{
|
|
326
|
+
readonly name: "to";
|
|
327
|
+
readonly type: "address";
|
|
328
|
+
readonly internalType: "address";
|
|
329
|
+
}, {
|
|
330
|
+
readonly name: "validAfter";
|
|
331
|
+
readonly type: "uint256";
|
|
332
|
+
readonly internalType: "uint256";
|
|
333
|
+
}, {
|
|
334
|
+
readonly name: "extra";
|
|
335
|
+
readonly type: "bytes";
|
|
336
|
+
readonly internalType: "bytes";
|
|
337
|
+
}];
|
|
338
|
+
}, {
|
|
339
|
+
readonly name: "signature";
|
|
340
|
+
readonly type: "bytes";
|
|
341
|
+
readonly internalType: "bytes";
|
|
342
|
+
}];
|
|
343
|
+
readonly outputs: readonly [];
|
|
344
|
+
readonly stateMutability: "nonpayable";
|
|
345
|
+
}, {
|
|
346
|
+
readonly type: "function";
|
|
347
|
+
readonly name: "settleWithPermit";
|
|
348
|
+
readonly inputs: readonly [{
|
|
349
|
+
readonly name: "permit2612";
|
|
350
|
+
readonly type: "tuple";
|
|
351
|
+
readonly internalType: "struct x402BasePermit2Proxy.EIP2612Permit";
|
|
352
|
+
readonly components: readonly [{
|
|
353
|
+
readonly name: "value";
|
|
354
|
+
readonly type: "uint256";
|
|
355
|
+
readonly internalType: "uint256";
|
|
356
|
+
}, {
|
|
357
|
+
readonly name: "deadline";
|
|
358
|
+
readonly type: "uint256";
|
|
359
|
+
readonly internalType: "uint256";
|
|
360
|
+
}, {
|
|
361
|
+
readonly name: "r";
|
|
362
|
+
readonly type: "bytes32";
|
|
363
|
+
readonly internalType: "bytes32";
|
|
364
|
+
}, {
|
|
365
|
+
readonly name: "s";
|
|
366
|
+
readonly type: "bytes32";
|
|
367
|
+
readonly internalType: "bytes32";
|
|
368
|
+
}, {
|
|
369
|
+
readonly name: "v";
|
|
370
|
+
readonly type: "uint8";
|
|
371
|
+
readonly internalType: "uint8";
|
|
372
|
+
}];
|
|
373
|
+
}, {
|
|
374
|
+
readonly name: "permit";
|
|
375
|
+
readonly type: "tuple";
|
|
376
|
+
readonly internalType: "struct ISignatureTransfer.PermitTransferFrom";
|
|
377
|
+
readonly components: readonly [{
|
|
378
|
+
readonly name: "permitted";
|
|
379
|
+
readonly type: "tuple";
|
|
380
|
+
readonly internalType: "struct ISignatureTransfer.TokenPermissions";
|
|
381
|
+
readonly components: readonly [{
|
|
382
|
+
readonly name: "token";
|
|
383
|
+
readonly type: "address";
|
|
384
|
+
readonly internalType: "address";
|
|
385
|
+
}, {
|
|
386
|
+
readonly name: "amount";
|
|
387
|
+
readonly type: "uint256";
|
|
388
|
+
readonly internalType: "uint256";
|
|
389
|
+
}];
|
|
390
|
+
}, {
|
|
391
|
+
readonly name: "nonce";
|
|
392
|
+
readonly type: "uint256";
|
|
393
|
+
readonly internalType: "uint256";
|
|
394
|
+
}, {
|
|
395
|
+
readonly name: "deadline";
|
|
396
|
+
readonly type: "uint256";
|
|
397
|
+
readonly internalType: "uint256";
|
|
398
|
+
}];
|
|
399
|
+
}, {
|
|
400
|
+
readonly name: "owner";
|
|
401
|
+
readonly type: "address";
|
|
402
|
+
readonly internalType: "address";
|
|
403
|
+
}, {
|
|
404
|
+
readonly name: "witness";
|
|
405
|
+
readonly type: "tuple";
|
|
406
|
+
readonly internalType: "struct x402BasePermit2Proxy.Witness";
|
|
407
|
+
readonly components: readonly [{
|
|
408
|
+
readonly name: "to";
|
|
409
|
+
readonly type: "address";
|
|
410
|
+
readonly internalType: "address";
|
|
411
|
+
}, {
|
|
412
|
+
readonly name: "validAfter";
|
|
413
|
+
readonly type: "uint256";
|
|
414
|
+
readonly internalType: "uint256";
|
|
415
|
+
}, {
|
|
416
|
+
readonly name: "extra";
|
|
417
|
+
readonly type: "bytes";
|
|
418
|
+
readonly internalType: "bytes";
|
|
419
|
+
}];
|
|
420
|
+
}, {
|
|
421
|
+
readonly name: "signature";
|
|
422
|
+
readonly type: "bytes";
|
|
423
|
+
readonly internalType: "bytes";
|
|
424
|
+
}];
|
|
425
|
+
readonly outputs: readonly [];
|
|
426
|
+
readonly stateMutability: "nonpayable";
|
|
427
|
+
}, {
|
|
428
|
+
readonly type: "event";
|
|
429
|
+
readonly name: "Settled";
|
|
430
|
+
readonly inputs: readonly [];
|
|
431
|
+
readonly anonymous: false;
|
|
432
|
+
}, {
|
|
433
|
+
readonly type: "event";
|
|
434
|
+
readonly name: "SettledWithPermit";
|
|
435
|
+
readonly inputs: readonly [];
|
|
436
|
+
readonly anonymous: false;
|
|
437
|
+
}, {
|
|
438
|
+
readonly type: "error";
|
|
439
|
+
readonly name: "AlreadyInitialized";
|
|
440
|
+
readonly inputs: readonly [];
|
|
441
|
+
}, {
|
|
442
|
+
readonly type: "error";
|
|
443
|
+
readonly name: "InvalidDestination";
|
|
444
|
+
readonly inputs: readonly [];
|
|
445
|
+
}, {
|
|
446
|
+
readonly type: "error";
|
|
447
|
+
readonly name: "InvalidOwner";
|
|
448
|
+
readonly inputs: readonly [];
|
|
449
|
+
}, {
|
|
450
|
+
readonly type: "error";
|
|
451
|
+
readonly name: "InvalidPermit2Address";
|
|
452
|
+
readonly inputs: readonly [];
|
|
453
|
+
}, {
|
|
454
|
+
readonly type: "error";
|
|
455
|
+
readonly name: "PaymentTooEarly";
|
|
456
|
+
readonly inputs: readonly [];
|
|
457
|
+
}, {
|
|
458
|
+
readonly type: "error";
|
|
459
|
+
readonly name: "ReentrancyGuardReentrantCall";
|
|
460
|
+
readonly inputs: readonly [];
|
|
461
|
+
}];
|
|
35
462
|
|
|
36
|
-
export {
|
|
463
|
+
export { type AssetTransferMethod, type ExactEIP3009Payload, type ExactEvmPayloadV1, type ExactEvmPayloadV2, type ExactPermit2Payload, PERMIT2_ADDRESS, type Permit2Authorization, type Permit2Witness, authorizationTypes, eip3009ABI, isEIP3009Payload, isPermit2Payload, permit2WitnessTypes, x402ExactPermit2ProxyABI, x402ExactPermit2ProxyAddress, x402UptoPermit2ProxyAddress };
|