@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.
Files changed (48) hide show
  1. package/dist/cjs/exact/client/index.d.ts +2 -2
  2. package/dist/cjs/exact/client/index.js +264 -119
  3. package/dist/cjs/exact/client/index.js.map +1 -1
  4. package/dist/cjs/exact/facilitator/index.d.ts +3 -0
  5. package/dist/cjs/exact/facilitator/index.js +691 -281
  6. package/dist/cjs/exact/facilitator/index.js.map +1 -1
  7. package/dist/cjs/exact/v1/client/index.js +43 -17
  8. package/dist/cjs/exact/v1/client/index.js.map +1 -1
  9. package/dist/cjs/exact/v1/facilitator/index.js +59 -26
  10. package/dist/cjs/exact/v1/facilitator/index.js.map +1 -1
  11. package/dist/cjs/index.d.ts +458 -31
  12. package/dist/cjs/index.js +438 -63
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/permit2-BYv82va2.d.ts +103 -0
  15. package/dist/cjs/v1/index.d.ts +21 -1
  16. package/dist/cjs/v1/index.js +33 -29
  17. package/dist/cjs/v1/index.js.map +1 -1
  18. package/dist/esm/chunk-DSSJHWGT.mjs +658 -0
  19. package/dist/esm/chunk-DSSJHWGT.mjs.map +1 -0
  20. package/dist/esm/chunk-PFULIQAE.mjs +13 -0
  21. package/dist/esm/chunk-PFULIQAE.mjs.map +1 -0
  22. package/dist/esm/chunk-U4H6Q62Q.mjs +229 -0
  23. package/dist/esm/chunk-U4H6Q62Q.mjs.map +1 -0
  24. package/dist/esm/exact/client/index.d.mts +2 -2
  25. package/dist/esm/exact/client/index.mjs +10 -30
  26. package/dist/esm/exact/client/index.mjs.map +1 -1
  27. package/dist/esm/exact/facilitator/index.d.mts +3 -0
  28. package/dist/esm/exact/facilitator/index.mjs +491 -241
  29. package/dist/esm/exact/facilitator/index.mjs.map +1 -1
  30. package/dist/esm/exact/v1/client/index.mjs +1 -2
  31. package/dist/esm/exact/v1/facilitator/index.mjs +2 -3
  32. package/dist/esm/index.d.mts +458 -31
  33. package/dist/esm/index.mjs +31 -4
  34. package/dist/esm/index.mjs.map +1 -1
  35. package/dist/esm/permit2-BsAoJiWD.d.mts +103 -0
  36. package/dist/esm/v1/index.d.mts +21 -1
  37. package/dist/esm/v1/index.mjs +4 -6
  38. package/package.json +2 -2
  39. package/dist/esm/chunk-FOUXRQAV.mjs +0 -88
  40. package/dist/esm/chunk-FOUXRQAV.mjs.map +0 -1
  41. package/dist/esm/chunk-JYZWCLMP.mjs +0 -305
  42. package/dist/esm/chunk-JYZWCLMP.mjs.map +0 -1
  43. package/dist/esm/chunk-PSA4YVU2.mjs +0 -92
  44. package/dist/esm/chunk-PSA4YVU2.mjs.map +0 -1
  45. package/dist/esm/chunk-QLXM7BIB.mjs +0 -23
  46. package/dist/esm/chunk-QLXM7BIB.mjs.map +0 -1
  47. package/dist/esm/chunk-ZYXTTU74.mjs +0 -88
  48. package/dist/esm/chunk-ZYXTTU74.mjs.map +0 -1
@@ -1,7 +1,22 @@
1
1
  import {
2
- ExactEvmScheme
3
- } from "./chunk-FOUXRQAV.mjs";
4
- import "./chunk-ZYXTTU74.mjs";
2
+ ExactEvmScheme,
3
+ createPermit2ApprovalTx,
4
+ erc20AllowanceAbi,
5
+ getPermit2AllowanceReadParams
6
+ } from "./chunk-U4H6Q62Q.mjs";
7
+ import {
8
+ isEIP3009Payload,
9
+ isPermit2Payload
10
+ } from "./chunk-PFULIQAE.mjs";
11
+ import {
12
+ PERMIT2_ADDRESS,
13
+ authorizationTypes,
14
+ eip3009ABI,
15
+ permit2WitnessTypes,
16
+ x402ExactPermit2ProxyABI,
17
+ x402ExactPermit2ProxyAddress,
18
+ x402UptoPermit2ProxyAddress
19
+ } from "./chunk-DSSJHWGT.mjs";
5
20
 
6
21
  // src/signer.ts
7
22
  function toClientEvmSigner(signer) {
@@ -15,7 +30,19 @@ function toFacilitatorEvmSigner(client) {
15
30
  }
16
31
  export {
17
32
  ExactEvmScheme,
33
+ PERMIT2_ADDRESS,
34
+ authorizationTypes,
35
+ createPermit2ApprovalTx,
36
+ eip3009ABI,
37
+ erc20AllowanceAbi,
38
+ getPermit2AllowanceReadParams,
39
+ isEIP3009Payload,
40
+ isPermit2Payload,
41
+ permit2WitnessTypes,
18
42
  toClientEvmSigner,
19
- toFacilitatorEvmSigner
43
+ toFacilitatorEvmSigner,
44
+ x402ExactPermit2ProxyABI,
45
+ x402ExactPermit2ProxyAddress,
46
+ x402UptoPermit2ProxyAddress
20
47
  };
21
48
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/signer.ts"],"sourcesContent":["/**\n * ClientEvmSigner - Used by x402 clients to sign payment authorizations\n * This is typically a LocalAccount or wallet that holds private keys\n * and can sign EIP-712 typed data for payment authorizations\n */\nexport type ClientEvmSigner = {\n readonly address: `0x${string}`;\n signTypedData(message: {\n domain: Record<string, unknown>;\n types: Record<string, unknown>;\n primaryType: string;\n message: Record<string, unknown>;\n }): Promise<`0x${string}`>;\n};\n\n/**\n * FacilitatorEvmSigner - Used by x402 facilitators to verify and settle payments\n * This is typically a viem PublicClient + WalletClient combination that can\n * read contract state, verify signatures, write transactions, and wait for receipts\n *\n * Supports multiple addresses for load balancing, key rotation, and high availability\n */\nexport type FacilitatorEvmSigner = {\n /**\n * Get all addresses this facilitator can use for signing\n * Enables dynamic address selection for load balancing and key rotation\n */\n getAddresses(): readonly `0x${string}`[];\n\n readContract(args: {\n address: `0x${string}`;\n abi: readonly unknown[];\n functionName: string;\n args?: readonly unknown[];\n }): Promise<unknown>;\n verifyTypedData(args: {\n address: `0x${string}`;\n domain: Record<string, unknown>;\n types: Record<string, unknown>;\n primaryType: string;\n message: Record<string, unknown>;\n signature: `0x${string}`;\n }): Promise<boolean>;\n writeContract(args: {\n address: `0x${string}`;\n abi: readonly unknown[];\n functionName: string;\n args: readonly unknown[];\n }): Promise<`0x${string}`>;\n sendTransaction(args: { to: `0x${string}`; data: `0x${string}` }): Promise<`0x${string}`>;\n waitForTransactionReceipt(args: { hash: `0x${string}` }): Promise<{ status: string }>;\n getCode(args: { address: `0x${string}` }): Promise<`0x${string}` | undefined>;\n};\n\n/**\n * Converts a signer to a ClientEvmSigner\n *\n * @param signer - The signer to convert to a ClientEvmSigner\n * @returns The converted signer\n */\nexport function toClientEvmSigner(signer: ClientEvmSigner): ClientEvmSigner {\n return signer;\n}\n\n/**\n * Converts a viem client with single address to a FacilitatorEvmSigner\n * Wraps the single address in a getAddresses() function for compatibility\n *\n * @param client - The client to convert (must have 'address' property)\n * @returns FacilitatorEvmSigner with getAddresses() support\n */\nexport function toFacilitatorEvmSigner(\n client: Omit<FacilitatorEvmSigner, \"getAddresses\"> & { address: `0x${string}` },\n): FacilitatorEvmSigner {\n return {\n ...client,\n getAddresses: () => [client.address],\n };\n}\n"],"mappings":";;;;;;AA4DO,SAAS,kBAAkB,QAA0C;AAC1E,SAAO;AACT;AASO,SAAS,uBACd,QACsB;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,cAAc,MAAM,CAAC,OAAO,OAAO;AAAA,EACrC;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/signer.ts"],"sourcesContent":["/**\n * ClientEvmSigner - Used by x402 clients to sign payment authorizations\n * This is typically a LocalAccount or wallet that holds private keys\n * and can sign EIP-712 typed data for payment authorizations\n */\nexport type ClientEvmSigner = {\n readonly address: `0x${string}`;\n signTypedData(message: {\n domain: Record<string, unknown>;\n types: Record<string, unknown>;\n primaryType: string;\n message: Record<string, unknown>;\n }): Promise<`0x${string}`>;\n};\n\n/**\n * FacilitatorEvmSigner - Used by x402 facilitators to verify and settle payments\n * This is typically a viem PublicClient + WalletClient combination that can\n * read contract state, verify signatures, write transactions, and wait for receipts\n *\n * Supports multiple addresses for load balancing, key rotation, and high availability\n */\nexport type FacilitatorEvmSigner = {\n /**\n * Get all addresses this facilitator can use for signing\n * Enables dynamic address selection for load balancing and key rotation\n */\n getAddresses(): readonly `0x${string}`[];\n\n readContract(args: {\n address: `0x${string}`;\n abi: readonly unknown[];\n functionName: string;\n args?: readonly unknown[];\n }): Promise<unknown>;\n verifyTypedData(args: {\n address: `0x${string}`;\n domain: Record<string, unknown>;\n types: Record<string, unknown>;\n primaryType: string;\n message: Record<string, unknown>;\n signature: `0x${string}`;\n }): Promise<boolean>;\n writeContract(args: {\n address: `0x${string}`;\n abi: readonly unknown[];\n functionName: string;\n args: readonly unknown[];\n }): Promise<`0x${string}`>;\n sendTransaction(args: { to: `0x${string}`; data: `0x${string}` }): Promise<`0x${string}`>;\n waitForTransactionReceipt(args: { hash: `0x${string}` }): Promise<{ status: string }>;\n getCode(args: { address: `0x${string}` }): Promise<`0x${string}` | undefined>;\n};\n\n/**\n * Converts a signer to a ClientEvmSigner\n *\n * @param signer - The signer to convert to a ClientEvmSigner\n * @returns The converted signer\n */\nexport function toClientEvmSigner(signer: ClientEvmSigner): ClientEvmSigner {\n return signer;\n}\n\n/**\n * Converts a viem client with single address to a FacilitatorEvmSigner\n * Wraps the single address in a getAddresses() function for compatibility\n *\n * @param client - The client to convert (must have 'address' property)\n * @returns FacilitatorEvmSigner with getAddresses() support\n */\nexport function toFacilitatorEvmSigner(\n client: Omit<FacilitatorEvmSigner, \"getAddresses\"> & { address: `0x${string}` },\n): FacilitatorEvmSigner {\n return {\n ...client,\n getAddresses: () => [client.address],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4DO,SAAS,kBAAkB,QAA0C;AAC1E,SAAO;AACT;AASO,SAAS,uBACd,QACsB;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,cAAc,MAAM,CAAC,OAAO,OAAO;AAAA,EACrC;AACF;","names":[]}
@@ -0,0 +1,103 @@
1
+ import { SchemeNetworkClient, PaymentRequirements, PaymentPayloadResult } from '@x402/core/types';
2
+ import { C as ClientEvmSigner } from './signer-5OVDxViv.mjs';
3
+
4
+ /**
5
+ * EVM client implementation for the Exact payment scheme.
6
+ * Supports both EIP-3009 (transferWithAuthorization) and Permit2 flows.
7
+ *
8
+ * Routes to the appropriate authorization method based on
9
+ * `requirements.extra.assetTransferMethod`. Defaults to EIP-3009
10
+ * for backward compatibility with older facilitators.
11
+ */
12
+ declare class ExactEvmScheme implements SchemeNetworkClient {
13
+ private readonly signer;
14
+ readonly scheme = "exact";
15
+ /**
16
+ * Creates a new ExactEvmClient instance.
17
+ *
18
+ * @param signer - The EVM signer for client operations
19
+ */
20
+ constructor(signer: ClientEvmSigner);
21
+ /**
22
+ * Creates a payment payload for the Exact scheme.
23
+ * Routes to EIP-3009 or Permit2 based on requirements.extra.assetTransferMethod.
24
+ *
25
+ * @param x402Version - The x402 protocol version
26
+ * @param paymentRequirements - The payment requirements
27
+ * @returns Promise resolving to a payment payload result
28
+ */
29
+ createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<PaymentPayloadResult>;
30
+ }
31
+
32
+ /**
33
+ * ERC20 allowance ABI for checking approval status.
34
+ */
35
+ declare const erc20AllowanceAbi: readonly [{
36
+ readonly type: "function";
37
+ readonly name: "allowance";
38
+ readonly inputs: readonly [{
39
+ readonly name: "owner";
40
+ readonly type: "address";
41
+ }, {
42
+ readonly name: "spender";
43
+ readonly type: "address";
44
+ }];
45
+ readonly outputs: readonly [{
46
+ readonly type: "uint256";
47
+ }];
48
+ readonly stateMutability: "view";
49
+ }];
50
+ /**
51
+ * Creates transaction data to approve Permit2 to spend tokens.
52
+ * The user sends this transaction (paying gas) before using Permit2 flow.
53
+ *
54
+ * @param tokenAddress - The ERC20 token contract address
55
+ * @returns Transaction data to send for approval
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const tx = createPermit2ApprovalTx("0x...");
60
+ * await walletClient.sendTransaction({
61
+ * to: tx.to,
62
+ * data: tx.data,
63
+ * });
64
+ * ```
65
+ */
66
+ declare function createPermit2ApprovalTx(tokenAddress: `0x${string}`): {
67
+ to: `0x${string}`;
68
+ data: `0x${string}`;
69
+ };
70
+ /**
71
+ * Parameters for checking Permit2 allowance.
72
+ * Application provides these to check if approval is needed.
73
+ */
74
+ interface Permit2AllowanceParams {
75
+ tokenAddress: `0x${string}`;
76
+ ownerAddress: `0x${string}`;
77
+ }
78
+ /**
79
+ * Returns contract read parameters for checking Permit2 allowance.
80
+ * Use with a public client to check if the user has approved Permit2.
81
+ *
82
+ * @param params - The allowance check parameters
83
+ * @returns Contract read parameters for checking allowance
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const readParams = getPermit2AllowanceReadParams({
88
+ * tokenAddress: "0x...",
89
+ * ownerAddress: "0x...",
90
+ * });
91
+ *
92
+ * const allowance = await publicClient.readContract(readParams);
93
+ * const needsApproval = allowance < requiredAmount;
94
+ * ```
95
+ */
96
+ declare function getPermit2AllowanceReadParams(params: Permit2AllowanceParams): {
97
+ address: `0x${string}`;
98
+ abi: typeof erc20AllowanceAbi;
99
+ functionName: "allowance";
100
+ args: [`0x${string}`, `0x${string}`];
101
+ };
102
+
103
+ export { ExactEvmScheme as E, type Permit2AllowanceParams as P, createPermit2ApprovalTx as c, erc20AllowanceAbi as e, getPermit2AllowanceReadParams as g };
@@ -2,6 +2,26 @@ export { ExactEvmSchemeV1 } from '../exact/v1/client/index.mjs';
2
2
  import '@x402/core/types';
3
3
  import '../signer-5OVDxViv.mjs';
4
4
 
5
+ declare const EVM_NETWORK_CHAIN_ID_MAP: {
6
+ readonly ethereum: 1;
7
+ readonly sepolia: 11155111;
8
+ readonly abstract: 2741;
9
+ readonly "abstract-testnet": 11124;
10
+ readonly "base-sepolia": 84532;
11
+ readonly base: 8453;
12
+ readonly "avalanche-fuji": 43113;
13
+ readonly avalanche: 43114;
14
+ readonly iotex: 4689;
15
+ readonly sei: 1329;
16
+ readonly "sei-testnet": 1328;
17
+ readonly polygon: 137;
18
+ readonly "polygon-amoy": 80002;
19
+ readonly peaq: 3338;
20
+ readonly story: 1514;
21
+ readonly educhain: 41923;
22
+ readonly "skale-base-sepolia": 324705682;
23
+ };
24
+ type EvmNetworkV1 = keyof typeof EVM_NETWORK_CHAIN_ID_MAP;
5
25
  declare const NETWORKS: string[];
6
26
 
7
- export { NETWORKS };
27
+ export { EVM_NETWORK_CHAIN_ID_MAP, type EvmNetworkV1, NETWORKS };
@@ -1,12 +1,10 @@
1
1
  import {
2
+ EVM_NETWORK_CHAIN_ID_MAP,
3
+ ExactEvmSchemeV1,
2
4
  NETWORKS
3
- } from "../chunk-QLXM7BIB.mjs";
4
- import {
5
- ExactEvmSchemeV1
6
- } from "../chunk-PSA4YVU2.mjs";
7
- import "../chunk-JYZWCLMP.mjs";
8
- import "../chunk-ZYXTTU74.mjs";
5
+ } from "../chunk-DSSJHWGT.mjs";
9
6
  export {
7
+ EVM_NETWORK_CHAIN_ID_MAP,
10
8
  ExactEvmSchemeV1,
11
9
  NETWORKS
12
10
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x402/evm",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "main": "./dist/cjs/index.js",
5
5
  "module": "./dist/esm/index.js",
6
6
  "types": "./dist/cjs/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  "dependencies": {
36
36
  "viem": "^2.39.3",
37
37
  "zod": "^3.24.2",
38
- "@x402/core": "^2.2.0"
38
+ "@x402/core": "~2.3.0"
39
39
  },
40
40
  "exports": {
41
41
  ".": {
@@ -1,88 +0,0 @@
1
- import {
2
- authorizationTypes,
3
- createNonce
4
- } from "./chunk-ZYXTTU74.mjs";
5
-
6
- // src/exact/client/scheme.ts
7
- import { getAddress } from "viem";
8
- var ExactEvmScheme = class {
9
- /**
10
- * Creates a new ExactEvmClient instance.
11
- *
12
- * @param signer - The EVM signer for client operations
13
- */
14
- constructor(signer) {
15
- this.signer = signer;
16
- this.scheme = "exact";
17
- }
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
- async createPaymentPayload(x402Version, paymentRequirements) {
26
- const nonce = createNonce();
27
- const now = Math.floor(Date.now() / 1e3);
28
- const authorization = {
29
- from: this.signer.address,
30
- to: getAddress(paymentRequirements.payTo),
31
- value: paymentRequirements.amount,
32
- validAfter: (now - 600).toString(),
33
- // 10 minutes before
34
- validBefore: (now + paymentRequirements.maxTimeoutSeconds).toString(),
35
- nonce
36
- };
37
- const signature = await this.signAuthorization(authorization, paymentRequirements);
38
- const payload = {
39
- authorization,
40
- signature
41
- };
42
- return {
43
- x402Version,
44
- payload
45
- };
46
- }
47
- /**
48
- * Sign the EIP-3009 authorization using EIP-712
49
- *
50
- * @param authorization - The authorization to sign
51
- * @param requirements - The payment requirements
52
- * @returns Promise resolving to the signature
53
- */
54
- async signAuthorization(authorization, requirements) {
55
- const chainId = parseInt(requirements.network.split(":")[1]);
56
- if (!requirements.extra?.name || !requirements.extra?.version) {
57
- throw new Error(
58
- `EIP-712 domain parameters (name, version) are required in payment requirements for asset ${requirements.asset}`
59
- );
60
- }
61
- const { name, version } = requirements.extra;
62
- const domain = {
63
- name,
64
- version,
65
- chainId,
66
- verifyingContract: getAddress(requirements.asset)
67
- };
68
- const message = {
69
- from: getAddress(authorization.from),
70
- to: getAddress(authorization.to),
71
- value: BigInt(authorization.value),
72
- validAfter: BigInt(authorization.validAfter),
73
- validBefore: BigInt(authorization.validBefore),
74
- nonce: authorization.nonce
75
- };
76
- return await this.signer.signTypedData({
77
- domain,
78
- types: authorizationTypes,
79
- primaryType: "TransferWithAuthorization",
80
- message
81
- });
82
- }
83
- };
84
-
85
- export {
86
- ExactEvmScheme
87
- };
88
- //# sourceMappingURL=chunk-FOUXRQAV.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/exact/client/scheme.ts"],"sourcesContent":["import { PaymentPayload, PaymentRequirements, SchemeNetworkClient } from \"@x402/core/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,305 +0,0 @@
1
- import {
2
- authorizationTypes,
3
- eip3009ABI,
4
- getEvmChainId
5
- } from "./chunk-ZYXTTU74.mjs";
6
-
7
- // src/exact/v1/facilitator/scheme.ts
8
- import { getAddress, isAddressEqual, parseErc6492Signature, parseSignature } from "viem";
9
- var ExactEvmSchemeV1 = class {
10
- /**
11
- * Creates a new ExactEvmFacilitatorV1 instance.
12
- *
13
- * @param signer - The EVM signer for facilitator operations
14
- * @param config - Optional configuration for the facilitator
15
- */
16
- constructor(signer, config) {
17
- this.signer = signer;
18
- this.scheme = "exact";
19
- this.caipFamily = "eip155:*";
20
- this.config = {
21
- deployERC4337WithEIP6492: config?.deployERC4337WithEIP6492 ?? false
22
- };
23
- }
24
- /**
25
- * Get mechanism-specific extra data for the supported kinds endpoint.
26
- * For EVM, no extra data is needed.
27
- *
28
- * @param _ - The network identifier (unused for EVM)
29
- * @returns undefined (EVM has no extra data)
30
- */
31
- getExtra(_) {
32
- return void 0;
33
- }
34
- /**
35
- * Get signer addresses used by this facilitator.
36
- * Returns all addresses this facilitator can use for signing/settling transactions.
37
- *
38
- * @param _ - The network identifier (unused for EVM, addresses are network-agnostic)
39
- * @returns Array of facilitator wallet addresses
40
- */
41
- getSigners(_) {
42
- return [...this.signer.getAddresses()];
43
- }
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
- async verify(payload, requirements) {
52
- const requirementsV1 = requirements;
53
- const payloadV1 = payload;
54
- const exactEvmPayload = payload.payload;
55
- if (payloadV1.scheme !== "exact" || requirements.scheme !== "exact") {
56
- return {
57
- isValid: false,
58
- invalidReason: "unsupported_scheme",
59
- payer: exactEvmPayload.authorization.from
60
- };
61
- }
62
- const chainId = getEvmChainId(payloadV1.network);
63
- if (!requirements.extra?.name || !requirements.extra?.version) {
64
- return {
65
- isValid: false,
66
- invalidReason: "missing_eip712_domain",
67
- payer: exactEvmPayload.authorization.from
68
- };
69
- }
70
- const { name, version } = requirements.extra;
71
- const erc20Address = getAddress(requirements.asset);
72
- if (payloadV1.network !== requirements.network) {
73
- return {
74
- isValid: false,
75
- invalidReason: "network_mismatch",
76
- payer: exactEvmPayload.authorization.from
77
- };
78
- }
79
- const permitTypedData = {
80
- types: authorizationTypes,
81
- primaryType: "TransferWithAuthorization",
82
- domain: {
83
- name,
84
- version,
85
- chainId,
86
- verifyingContract: erc20Address
87
- },
88
- message: {
89
- from: exactEvmPayload.authorization.from,
90
- to: exactEvmPayload.authorization.to,
91
- value: BigInt(exactEvmPayload.authorization.value),
92
- validAfter: BigInt(exactEvmPayload.authorization.validAfter),
93
- validBefore: BigInt(exactEvmPayload.authorization.validBefore),
94
- nonce: exactEvmPayload.authorization.nonce
95
- }
96
- };
97
- try {
98
- const recoveredAddress = await this.signer.verifyTypedData({
99
- address: exactEvmPayload.authorization.from,
100
- ...permitTypedData,
101
- signature: exactEvmPayload.signature
102
- });
103
- if (!recoveredAddress) {
104
- return {
105
- isValid: false,
106
- invalidReason: "invalid_exact_evm_payload_signature",
107
- payer: exactEvmPayload.authorization.from
108
- };
109
- }
110
- } catch {
111
- const signature = exactEvmPayload.signature;
112
- const signatureLength = signature.startsWith("0x") ? signature.length - 2 : signature.length;
113
- const isSmartWallet = signatureLength > 130;
114
- if (isSmartWallet) {
115
- const payerAddress = exactEvmPayload.authorization.from;
116
- const bytecode = await this.signer.getCode({ address: payerAddress });
117
- if (!bytecode || bytecode === "0x") {
118
- const erc6492Data = parseErc6492Signature(signature);
119
- const hasDeploymentInfo = erc6492Data.address && erc6492Data.data && !isAddressEqual(erc6492Data.address, "0x0000000000000000000000000000000000000000");
120
- if (!hasDeploymentInfo) {
121
- return {
122
- isValid: false,
123
- invalidReason: "invalid_exact_evm_payload_undeployed_smart_wallet",
124
- payer: payerAddress
125
- };
126
- }
127
- } else {
128
- return {
129
- isValid: false,
130
- invalidReason: "invalid_exact_evm_payload_signature",
131
- payer: exactEvmPayload.authorization.from
132
- };
133
- }
134
- } else {
135
- return {
136
- isValid: false,
137
- invalidReason: "invalid_exact_evm_payload_signature",
138
- payer: exactEvmPayload.authorization.from
139
- };
140
- }
141
- }
142
- if (getAddress(exactEvmPayload.authorization.to) !== getAddress(requirements.payTo)) {
143
- return {
144
- isValid: false,
145
- invalidReason: "invalid_exact_evm_payload_recipient_mismatch",
146
- payer: exactEvmPayload.authorization.from
147
- };
148
- }
149
- const now = Math.floor(Date.now() / 1e3);
150
- if (BigInt(exactEvmPayload.authorization.validBefore) < BigInt(now + 6)) {
151
- return {
152
- isValid: false,
153
- invalidReason: "invalid_exact_evm_payload_authorization_valid_before",
154
- payer: exactEvmPayload.authorization.from
155
- };
156
- }
157
- if (BigInt(exactEvmPayload.authorization.validAfter) > BigInt(now)) {
158
- return {
159
- isValid: false,
160
- invalidReason: "invalid_exact_evm_payload_authorization_valid_after",
161
- payer: exactEvmPayload.authorization.from
162
- };
163
- }
164
- try {
165
- const balance = await this.signer.readContract({
166
- address: erc20Address,
167
- abi: eip3009ABI,
168
- functionName: "balanceOf",
169
- args: [exactEvmPayload.authorization.from]
170
- });
171
- if (BigInt(balance) < BigInt(requirementsV1.maxAmountRequired)) {
172
- return {
173
- isValid: false,
174
- invalidReason: "insufficient_funds",
175
- payer: exactEvmPayload.authorization.from
176
- };
177
- }
178
- } catch {
179
- }
180
- if (BigInt(exactEvmPayload.authorization.value) < BigInt(requirementsV1.maxAmountRequired)) {
181
- return {
182
- isValid: false,
183
- invalidReason: "invalid_exact_evm_payload_authorization_value",
184
- payer: exactEvmPayload.authorization.from
185
- };
186
- }
187
- return {
188
- isValid: true,
189
- invalidReason: void 0,
190
- payer: exactEvmPayload.authorization.from
191
- };
192
- }
193
- /**
194
- * Settles a payment by executing the transfer (V1).
195
- *
196
- * @param payload - The payment payload to settle
197
- * @param requirements - The payment requirements
198
- * @returns Promise resolving to settlement response
199
- */
200
- async settle(payload, requirements) {
201
- const payloadV1 = payload;
202
- const exactEvmPayload = payload.payload;
203
- const valid = await this.verify(payload, requirements);
204
- if (!valid.isValid) {
205
- return {
206
- success: false,
207
- network: payloadV1.network,
208
- transaction: "",
209
- errorReason: valid.invalidReason ?? "invalid_scheme",
210
- payer: exactEvmPayload.authorization.from
211
- };
212
- }
213
- try {
214
- const parseResult = parseErc6492Signature(exactEvmPayload.signature);
215
- const { signature, address: factoryAddress, data: factoryCalldata } = parseResult;
216
- if (this.config.deployERC4337WithEIP6492 && factoryAddress && factoryCalldata && !isAddressEqual(factoryAddress, "0x0000000000000000000000000000000000000000")) {
217
- const payerAddress = exactEvmPayload.authorization.from;
218
- const bytecode = await this.signer.getCode({ address: payerAddress });
219
- if (!bytecode || bytecode === "0x") {
220
- try {
221
- console.log(`Deploying ERC-4337 smart wallet for ${payerAddress} via EIP-6492`);
222
- const deployTx = await this.signer.sendTransaction({
223
- to: factoryAddress,
224
- data: factoryCalldata
225
- });
226
- await this.signer.waitForTransactionReceipt({ hash: deployTx });
227
- console.log(`Successfully deployed smart wallet for ${payerAddress}`);
228
- } catch (deployError) {
229
- console.error("Smart wallet deployment failed:", deployError);
230
- throw deployError;
231
- }
232
- } else {
233
- console.log(`Smart wallet for ${payerAddress} already deployed, skipping deployment`);
234
- }
235
- }
236
- const signatureLength = signature.startsWith("0x") ? signature.length - 2 : signature.length;
237
- const isECDSA = signatureLength === 130;
238
- let tx;
239
- if (isECDSA) {
240
- const parsedSig = parseSignature(signature);
241
- tx = await this.signer.writeContract({
242
- address: getAddress(requirements.asset),
243
- abi: eip3009ABI,
244
- functionName: "transferWithAuthorization",
245
- args: [
246
- getAddress(exactEvmPayload.authorization.from),
247
- getAddress(exactEvmPayload.authorization.to),
248
- BigInt(exactEvmPayload.authorization.value),
249
- BigInt(exactEvmPayload.authorization.validAfter),
250
- BigInt(exactEvmPayload.authorization.validBefore),
251
- exactEvmPayload.authorization.nonce,
252
- parsedSig.v || parsedSig.yParity,
253
- parsedSig.r,
254
- parsedSig.s
255
- ]
256
- });
257
- } else {
258
- tx = await this.signer.writeContract({
259
- address: getAddress(requirements.asset),
260
- abi: eip3009ABI,
261
- functionName: "transferWithAuthorization",
262
- args: [
263
- getAddress(exactEvmPayload.authorization.from),
264
- getAddress(exactEvmPayload.authorization.to),
265
- BigInt(exactEvmPayload.authorization.value),
266
- BigInt(exactEvmPayload.authorization.validAfter),
267
- BigInt(exactEvmPayload.authorization.validBefore),
268
- exactEvmPayload.authorization.nonce,
269
- signature
270
- ]
271
- });
272
- }
273
- const receipt = await this.signer.waitForTransactionReceipt({ hash: tx });
274
- if (receipt.status !== "success") {
275
- return {
276
- success: false,
277
- errorReason: "invalid_transaction_state",
278
- transaction: tx,
279
- network: payloadV1.network,
280
- payer: exactEvmPayload.authorization.from
281
- };
282
- }
283
- return {
284
- success: true,
285
- transaction: tx,
286
- network: payloadV1.network,
287
- payer: exactEvmPayload.authorization.from
288
- };
289
- } catch (error) {
290
- console.error("Failed to settle transaction:", error);
291
- return {
292
- success: false,
293
- errorReason: "transaction_failed",
294
- transaction: "",
295
- network: payloadV1.network,
296
- payer: exactEvmPayload.authorization.from
297
- };
298
- }
299
- }
300
- };
301
-
302
- export {
303
- ExactEvmSchemeV1
304
- };
305
- //# sourceMappingURL=chunk-JYZWCLMP.mjs.map