@bankofai/x402-evm 2.6.0-beta.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 (65) hide show
  1. package/README.md +184 -0
  2. package/dist/cjs/exact/client/index.d.ts +53 -0
  3. package/dist/cjs/exact/client/index.js +661 -0
  4. package/dist/cjs/exact/client/index.js.map +1 -0
  5. package/dist/cjs/exact/facilitator/index.d.ts +121 -0
  6. package/dist/cjs/exact/facilitator/index.js +1458 -0
  7. package/dist/cjs/exact/facilitator/index.js.map +1 -0
  8. package/dist/cjs/exact/server/index.d.ts +125 -0
  9. package/dist/cjs/exact/server/index.js +229 -0
  10. package/dist/cjs/exact/server/index.js.map +1 -0
  11. package/dist/cjs/exact/v1/client/index.d.ts +37 -0
  12. package/dist/cjs/exact/v1/client/index.js +175 -0
  13. package/dist/cjs/exact/v1/client/index.js.map +1 -0
  14. package/dist/cjs/exact/v1/facilitator/index.d.ts +62 -0
  15. package/dist/cjs/exact/v1/facilitator/index.js +436 -0
  16. package/dist/cjs/exact/v1/facilitator/index.js.map +1 -0
  17. package/dist/cjs/exact_permit/client/index.d.ts +57 -0
  18. package/dist/cjs/exact_permit/client/index.js +223 -0
  19. package/dist/cjs/exact_permit/client/index.js.map +1 -0
  20. package/dist/cjs/exact_permit/facilitator/index.d.ts +82 -0
  21. package/dist/cjs/exact_permit/facilitator/index.js +437 -0
  22. package/dist/cjs/exact_permit/facilitator/index.js.map +1 -0
  23. package/dist/cjs/exact_permit/server/index.d.ts +71 -0
  24. package/dist/cjs/exact_permit/server/index.js +186 -0
  25. package/dist/cjs/exact_permit/server/index.js.map +1 -0
  26. package/dist/cjs/index.d.ts +76 -0
  27. package/dist/cjs/index.js +779 -0
  28. package/dist/cjs/index.js.map +1 -0
  29. package/dist/cjs/permit2-CpuKY2-F.d.ts +509 -0
  30. package/dist/cjs/permit2-D65OQ5yU.d.ts +517 -0
  31. package/dist/cjs/permit2-DvsTlAyj.d.ts +531 -0
  32. package/dist/cjs/signer-DC81R8wQ.d.ts +161 -0
  33. package/dist/cjs/v1/index.d.ts +39 -0
  34. package/dist/cjs/v1/index.js +181 -0
  35. package/dist/cjs/v1/index.js.map +1 -0
  36. package/dist/esm/chunk-4JGB4GDD.mjs +425 -0
  37. package/dist/esm/chunk-4JGB4GDD.mjs.map +1 -0
  38. package/dist/esm/chunk-TKN5V2BV.mjs +13 -0
  39. package/dist/esm/chunk-TKN5V2BV.mjs.map +1 -0
  40. package/dist/esm/chunk-UDKSVWSE.mjs +716 -0
  41. package/dist/esm/chunk-UDKSVWSE.mjs.map +1 -0
  42. package/dist/esm/exact/client/index.d.mts +53 -0
  43. package/dist/esm/exact/client/index.mjs +17 -0
  44. package/dist/esm/exact/client/index.mjs.map +1 -0
  45. package/dist/esm/exact/facilitator/index.d.mts +121 -0
  46. package/dist/esm/exact/facilitator/index.mjs +876 -0
  47. package/dist/esm/exact/facilitator/index.mjs.map +1 -0
  48. package/dist/esm/exact/server/index.d.mts +125 -0
  49. package/dist/esm/exact/server/index.mjs +201 -0
  50. package/dist/esm/exact/server/index.mjs.map +1 -0
  51. package/dist/esm/exact/v1/client/index.d.mts +37 -0
  52. package/dist/esm/exact/v1/client/index.mjs +7 -0
  53. package/dist/esm/exact/v1/client/index.mjs.map +1 -0
  54. package/dist/esm/exact/v1/facilitator/index.d.mts +62 -0
  55. package/dist/esm/exact/v1/facilitator/index.mjs +7 -0
  56. package/dist/esm/exact/v1/facilitator/index.mjs.map +1 -0
  57. package/dist/esm/index.d.mts +76 -0
  58. package/dist/esm/index.mjs +71 -0
  59. package/dist/esm/index.mjs.map +1 -0
  60. package/dist/esm/permit2-D7ni3g6s.d.mts +509 -0
  61. package/dist/esm/signer-DC81R8wQ.d.mts +161 -0
  62. package/dist/esm/v1/index.d.mts +39 -0
  63. package/dist/esm/v1/index.mjs +13 -0
  64. package/dist/esm/v1/index.mjs.map +1 -0
  65. package/package.json +128 -0
package/README.md ADDED
@@ -0,0 +1,184 @@
1
+ # @x402/evm
2
+
3
+ EVM (Ethereum Virtual Machine) implementation of the x402 payment protocol using the **Exact** payment scheme with EIP-3009 TransferWithAuthorization.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @x402/evm
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ This package provides three main components for handling x402 payments on EVM-compatible blockchains:
14
+
15
+ - **Client** - For applications that need to make payments (have wallets/signers)
16
+ - **Facilitator** - For payment processors that verify and execute on-chain transactions
17
+ - **Service** - For resource servers that accept payments and build payment requirements
18
+
19
+ ## Package Exports
20
+
21
+ ### Main Package (`@x402/evm`)
22
+
23
+ **V2 Protocol Support** - Modern x402 protocol with CAIP-2 network identifiers
24
+
25
+ **Client:**
26
+ - `ExactEvmClient` - V2 client implementation using EIP-3009
27
+ - `toClientEvmSigner(account)` - Converts viem accounts to x402 signers
28
+ - `ClientEvmSigner` - TypeScript type for client signers
29
+
30
+ **Facilitator:**
31
+ - `ExactEvmFacilitator` - V2 facilitator for payment verification and settlement
32
+ - `toFacilitatorEvmSigner(wallet)` - Converts viem wallets to facilitator signers
33
+ - `FacilitatorEvmSigner` - TypeScript type for facilitator signers
34
+
35
+ **Service:**
36
+ - `ExactEvmServer` - V2 service for building payment requirements
37
+
38
+ ### V1 Package (`@x402/evm/v1`)
39
+
40
+ **V1 Protocol Support** - Legacy x402 protocol with simple network names
41
+
42
+ **Exports:**
43
+ - `ExactEvmClientV1` - V1 client implementation
44
+ - `ExactEvmFacilitatorV1` - V1 facilitator implementation
45
+ - `NETWORKS` - Array of all supported V1 network names
46
+
47
+ **Supported V1 Networks:**
48
+ ```typescript
49
+ [
50
+ "abstract", "abstract-testnet",
51
+ "base-sepolia", "base",
52
+ "avalanche-fuji", "avalanche",
53
+ "iotex", "sei", "sei-testnet",
54
+ "polygon", "polygon-amoy",
55
+ "peaq", "story", "educhain",
56
+ "skale-base-sepolia"
57
+ ]
58
+ ```
59
+
60
+ ### Client Builder (`@x402/evm/client`)
61
+
62
+ **Convenience builder** for creating fully-configured EVM clients
63
+
64
+ **Exports:**
65
+ - `createEvmClient(config)` - Creates x402Client with EVM support
66
+ - `EvmClientConfig` - Configuration interface
67
+
68
+ **What it does:**
69
+ - Automatically registers V2 wildcard scheme (`eip155:*`)
70
+ - Automatically registers all V1 networks from `NETWORKS`
71
+ - Optionally applies payment policies
72
+ - Optionally uses custom payment selector
73
+
74
+ **Example:**
75
+ ```typescript
76
+ import { createEvmClient } from "@x402/evm/client";
77
+ import { toClientEvmSigner } from "@x402/evm";
78
+ import { privateKeyToAccount } from "viem/accounts";
79
+
80
+ const account = privateKeyToAccount("0x...");
81
+ const signer = toClientEvmSigner(account);
82
+
83
+ const client = createEvmClient({ signer });
84
+ // Ready to use with both V1 and V2!
85
+ ```
86
+
87
+ ## Version Differences
88
+
89
+ ### V2 (Main Package)
90
+ - Network format: CAIP-2 (`eip155:8453`)
91
+ - Wildcard support: Yes (`eip155:*`)
92
+ - Payload structure: Partial (core wraps with metadata)
93
+ - Extensions: Full support
94
+ - Validity window: 1 hour (default)
95
+
96
+ ### V1 (V1 Package)
97
+ - Network format: Simple names (`base-sepolia`)
98
+ - Wildcard support: No (fixed list)
99
+ - Payload structure: Complete
100
+ - Extensions: Limited
101
+ - Validity window: 10 minutes with buffer
102
+
103
+ ## Usage Patterns
104
+
105
+ ### 1. Using Pre-built Builder (Recommended)
106
+
107
+ ```typescript
108
+ import { createEvmClient } from "@x402/evm/client";
109
+ import { wrapFetchWithPayment } from "@x402/fetch";
110
+
111
+ const client = createEvmClient({ signer: myEvmSigner });
112
+ const paidFetch = wrapFetchWithPayment(fetch, client);
113
+ ```
114
+
115
+ ### 2. Direct Registration (Full Control)
116
+
117
+ ```typescript
118
+ import { x402Client } from "@x402/core/client";
119
+ import { ExactEvmClient } from "@x402/evm";
120
+ import { ExactEvmClientV1 } from "@x402/evm/v1";
121
+
122
+ const client = new x402Client()
123
+ .register("eip155:*", new ExactEvmClient(signer))
124
+ .registerSchemeV1("base-sepolia", new ExactEvmClientV1(signer))
125
+ .registerSchemeV1("base", new ExactEvmClientV1(signer));
126
+ ```
127
+
128
+ ### 3. Using Config (Flexible)
129
+
130
+ ```typescript
131
+ import { x402Client } from "@x402/core/client";
132
+ import { ExactEvmClient } from "@x402/evm";
133
+
134
+ const client = x402Client.fromConfig({
135
+ schemes: [
136
+ { network: "eip155:*", client: new ExactEvmClient(signer) },
137
+ { network: "base-sepolia", client: new ExactEvmClientV1(signer), x402Version: 1 }
138
+ ],
139
+ policies: [myCustomPolicy]
140
+ });
141
+ ```
142
+
143
+ ## Supported Networks
144
+
145
+ **V2 Networks** (via CAIP-2):
146
+ - `eip155:1` - Ethereum Mainnet
147
+ - `eip155:8453` - Base Mainnet
148
+ - `eip155:84532` - Base Sepolia
149
+ - `eip155:*` - Wildcard (matches all EVM chains)
150
+ - Any `eip155:<chainId>` network
151
+
152
+ **V1 Networks** (simple names):
153
+ See `NETWORKS` constant in `@x402/evm/v1`
154
+
155
+ ## Asset Support
156
+
157
+ Supports any ERC-3009 compatible token:
158
+ - USDC (primary)
159
+ - EURC
160
+ - Any token implementing `transferWithAuthorization()`
161
+
162
+ ## Development
163
+
164
+ ```bash
165
+ # Build
166
+ npm run build
167
+
168
+ # Test
169
+ npm run test
170
+
171
+ # Integration tests
172
+ npm run test:integration
173
+
174
+ # Lint & Format
175
+ npm run lint
176
+ npm run format
177
+ ```
178
+
179
+ ## Related Packages
180
+
181
+ - `@x402/core` - Core protocol types and client
182
+ - `@x402/fetch` - HTTP wrapper with automatic payment handling
183
+ - `@x402/svm` - Solana/SVM implementation
184
+ - `@x402/stellar` - Stellar implementation
@@ -0,0 +1,53 @@
1
+ export { E as ExactEvmScheme, a as Permit2AllowanceParams, c as createPermit2ApprovalTx, d as erc20AllowanceAbi, g as getPermit2AllowanceReadParams } from '../../permit2-CpuKY2-F.js';
2
+ import { SelectPaymentRequirements, PaymentPolicy, x402Client } from '@bankofai/x402-core/client';
3
+ import { Network } from '@bankofai/x402-core/types';
4
+ import { C as ClientEvmSigner } from '../../signer-DC81R8wQ.js';
5
+
6
+ /**
7
+ * Configuration options for registering EVM schemes to an x402Client
8
+ */
9
+ interface EvmClientConfig {
10
+ /**
11
+ * The EVM signer to use for creating payment payloads
12
+ */
13
+ signer: ClientEvmSigner;
14
+ /**
15
+ * Optional payment requirements selector function
16
+ * If not provided, uses the default selector (first available option)
17
+ */
18
+ paymentRequirementsSelector?: SelectPaymentRequirements;
19
+ /**
20
+ * Optional policies to apply to the client
21
+ */
22
+ policies?: PaymentPolicy[];
23
+ /**
24
+ * Optional specific networks to register
25
+ * If not provided, registers wildcard support (eip155:*)
26
+ */
27
+ networks?: Network[];
28
+ }
29
+ /**
30
+ * Registers EVM exact payment schemes to an x402Client instance.
31
+ *
32
+ * This function registers:
33
+ * - V2: eip155:* wildcard scheme with ExactEvmScheme (or specific networks if provided)
34
+ * - V1: All supported EVM networks with ExactEvmSchemeV1
35
+ *
36
+ * @param client - The x402Client instance to register schemes to
37
+ * @param config - Configuration for EVM client registration
38
+ * @returns The client instance for chaining
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * import { registerExactEvmScheme } from "@bankofai/x402-evm/exact/client/register";
43
+ * import { x402Client } from "@bankofai/x402-core/client";
44
+ * import { privateKeyToAccount } from "viem/accounts";
45
+ *
46
+ * const account = privateKeyToAccount("0x...");
47
+ * const client = new x402Client();
48
+ * registerExactEvmScheme(client, { signer: account });
49
+ * ```
50
+ */
51
+ declare function registerExactEvmScheme(client: x402Client, config: EvmClientConfig): x402Client;
52
+
53
+ export { type EvmClientConfig, registerExactEvmScheme };