@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
@@ -0,0 +1,161 @@
1
+ /**
2
+ * ClientEvmSigner - Used by x402 clients to sign payment authorizations.
3
+ *
4
+ * Typically a viem WalletClient extended with publicActions:
5
+ * ```typescript
6
+ * const client = createWalletClient({
7
+ * account: privateKeyToAccount('0x...'),
8
+ * chain: baseSepolia,
9
+ * transport: http(),
10
+ * }).extend(publicActions);
11
+ * ```
12
+ *
13
+ * Or composed via `toClientEvmSigner(account, publicClient)`.
14
+ */
15
+ type ClientEvmSigner = {
16
+ readonly address: `0x${string}`;
17
+ signTypedData(message: {
18
+ domain: Record<string, unknown>;
19
+ types: Record<string, unknown>;
20
+ primaryType: string;
21
+ message: Record<string, unknown>;
22
+ }): Promise<`0x${string}`>;
23
+ readContract(args: {
24
+ address: `0x${string}`;
25
+ abi: readonly unknown[];
26
+ functionName: string;
27
+ args?: readonly unknown[];
28
+ }): Promise<unknown>;
29
+ /**
30
+ * Optional: Signs a raw EIP-1559 transaction without broadcasting.
31
+ * Required for ERC-20 approval gas sponsoring when the token lacks EIP-2612.
32
+ */
33
+ signTransaction?(args: {
34
+ to: `0x${string}`;
35
+ data: `0x${string}`;
36
+ nonce: number;
37
+ gas: bigint;
38
+ maxFeePerGas: bigint;
39
+ maxPriorityFeePerGas: bigint;
40
+ chainId: number;
41
+ }): Promise<`0x${string}`>;
42
+ /**
43
+ * Optional: Gets the current transaction count (nonce) for an address.
44
+ * Required for ERC-20 approval gas sponsoring.
45
+ */
46
+ getTransactionCount?(args: {
47
+ address: `0x${string}`;
48
+ }): Promise<number>;
49
+ /**
50
+ * Optional: Estimates current gas fees per gas.
51
+ * Required for ERC-20 approval gas sponsoring.
52
+ */
53
+ estimateFeesPerGas?(): Promise<{
54
+ maxFeePerGas: bigint;
55
+ maxPriorityFeePerGas: bigint;
56
+ }>;
57
+ };
58
+ /**
59
+ * FacilitatorEvmSigner - Used by x402 facilitators to verify and settle payments
60
+ * This is typically a viem PublicClient + WalletClient combination that can
61
+ * read contract state, verify signatures, write transactions, and wait for receipts
62
+ *
63
+ * Supports multiple addresses for load balancing, key rotation, and high availability
64
+ */
65
+ type FacilitatorEvmSigner = {
66
+ /**
67
+ * Get all addresses this facilitator can use for signing
68
+ * Enables dynamic address selection for load balancing and key rotation
69
+ */
70
+ getAddresses(): readonly `0x${string}`[];
71
+ readContract(args: {
72
+ address: `0x${string}`;
73
+ abi: readonly unknown[];
74
+ functionName: string;
75
+ args?: readonly unknown[];
76
+ }): Promise<unknown>;
77
+ verifyTypedData(args: {
78
+ address: `0x${string}`;
79
+ domain: Record<string, unknown>;
80
+ types: Record<string, unknown>;
81
+ primaryType: string;
82
+ message: Record<string, unknown>;
83
+ signature: `0x${string}`;
84
+ }): Promise<boolean>;
85
+ writeContract(args: {
86
+ address: `0x${string}`;
87
+ abi: readonly unknown[];
88
+ functionName: string;
89
+ args: readonly unknown[];
90
+ }): Promise<`0x${string}`>;
91
+ sendTransaction(args: {
92
+ to: `0x${string}`;
93
+ data: `0x${string}`;
94
+ }): Promise<`0x${string}`>;
95
+ waitForTransactionReceipt(args: {
96
+ hash: `0x${string}`;
97
+ }): Promise<{
98
+ status: string;
99
+ }>;
100
+ getCode(args: {
101
+ address: `0x${string}`;
102
+ }): Promise<`0x${string}` | undefined>;
103
+ };
104
+ /**
105
+ * Composes a ClientEvmSigner from a local account and a public client.
106
+ *
107
+ * Use this when your signer (e.g., `privateKeyToAccount`) doesn't have
108
+ * `readContract`. The `publicClient` provides the on-chain read capability.
109
+ *
110
+ * Alternatively, use a WalletClient extended with publicActions directly:
111
+ * ```typescript
112
+ * const signer = createWalletClient({
113
+ * account: privateKeyToAccount('0x...'),
114
+ * chain: baseSepolia,
115
+ * transport: http(),
116
+ * }).extend(publicActions);
117
+ * ```
118
+ *
119
+ * @param signer - A signer with `address` and `signTypedData` (and optionally `readContract`)
120
+ * @param publicClient - A client with `readContract` (required if signer lacks it)
121
+ * @param publicClient.readContract - The readContract method from the public client
122
+ * @param publicClient.getTransactionCount - Optional getTransactionCount for ERC-20 approval
123
+ * @param publicClient.estimateFeesPerGas - Optional estimateFeesPerGas for ERC-20 approval
124
+ * @returns A complete ClientEvmSigner
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * const account = privateKeyToAccount("0x...");
129
+ * const publicClient = createPublicClient({ chain: baseSepolia, transport: http() });
130
+ * const signer = toClientEvmSigner(account, publicClient);
131
+ * ```
132
+ */
133
+ declare function toClientEvmSigner(signer: Omit<ClientEvmSigner, "readContract"> & {
134
+ readContract?: ClientEvmSigner["readContract"];
135
+ }, publicClient?: {
136
+ readContract(args: {
137
+ address: `0x${string}`;
138
+ abi: readonly unknown[];
139
+ functionName: string;
140
+ args?: readonly unknown[];
141
+ }): Promise<unknown>;
142
+ getTransactionCount?(args: {
143
+ address: `0x${string}`;
144
+ }): Promise<number>;
145
+ estimateFeesPerGas?(): Promise<{
146
+ maxFeePerGas: bigint;
147
+ maxPriorityFeePerGas: bigint;
148
+ }>;
149
+ }): ClientEvmSigner;
150
+ /**
151
+ * Converts a viem client with single address to a FacilitatorEvmSigner
152
+ * Wraps the single address in a getAddresses() function for compatibility
153
+ *
154
+ * @param client - The client to convert (must have 'address' property)
155
+ * @returns FacilitatorEvmSigner with getAddresses() support
156
+ */
157
+ declare function toFacilitatorEvmSigner(client: Omit<FacilitatorEvmSigner, "getAddresses"> & {
158
+ address: `0x${string}`;
159
+ }): FacilitatorEvmSigner;
160
+
161
+ export { type ClientEvmSigner as C, type FacilitatorEvmSigner as F, toFacilitatorEvmSigner as a, toClientEvmSigner as t };
@@ -0,0 +1,39 @@
1
+ export { ExactEvmSchemeV1 } from '../exact/v1/client/index.mjs';
2
+ import '@bankofai/x402-core/types';
3
+ import '../signer-DC81R8wQ.mjs';
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
+ readonly megaeth: 4326;
24
+ readonly monad: 143;
25
+ readonly bsc: 56;
26
+ readonly "bsc-testnet": 97;
27
+ };
28
+ type EvmNetworkV1 = keyof typeof EVM_NETWORK_CHAIN_ID_MAP;
29
+ declare const NETWORKS: string[];
30
+ /**
31
+ * Extract chain ID from a v1 legacy network name.
32
+ *
33
+ * @param network - The v1 network name (e.g., "base-sepolia", "polygon")
34
+ * @returns The numeric chain ID
35
+ * @throws Error if the network name is not a known v1 network
36
+ */
37
+ declare function getEvmChainIdV1(network: string): number;
38
+
39
+ export { EVM_NETWORK_CHAIN_ID_MAP, type EvmNetworkV1, NETWORKS, getEvmChainIdV1 };
@@ -0,0 +1,13 @@
1
+ import {
2
+ EVM_NETWORK_CHAIN_ID_MAP,
3
+ ExactEvmSchemeV12 as ExactEvmSchemeV1,
4
+ NETWORKS,
5
+ getEvmChainIdV1
6
+ } from "../chunk-UDKSVWSE.mjs";
7
+ export {
8
+ EVM_NETWORK_CHAIN_ID_MAP,
9
+ ExactEvmSchemeV1,
10
+ NETWORKS,
11
+ getEvmChainIdV1
12
+ };
13
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json ADDED
@@ -0,0 +1,128 @@
1
+ {
2
+ "name": "@bankofai/x402-evm",
3
+ "version": "2.6.0-beta.0",
4
+ "main": "./dist/cjs/index.js",
5
+ "module": "./dist/esm/index.js",
6
+ "types": "./dist/cjs/index.d.ts",
7
+ "scripts": {
8
+ "start": "tsx --env-file=.env index.ts",
9
+ "build": "tsup",
10
+ "test": "vitest run",
11
+ "test:integration": "vitest run --config vitest.integration.config.ts",
12
+ "test:watch": "vitest",
13
+ "watch": "tsc --watch",
14
+ "format": "prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"",
15
+ "format:check": "prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"",
16
+ "lint": "eslint . --ext .ts --fix",
17
+ "lint:check": "eslint . --ext .ts"
18
+ },
19
+ "keywords": [
20
+ "@bankofai/x402",
21
+ "payment",
22
+ "protocol",
23
+ "evm",
24
+ "ethereum"
25
+ ],
26
+ "license": "Apache-2.0",
27
+ "author": "bankofai",
28
+ "repository": "https://github.com/bankofai/x402",
29
+ "description": "x402 Payment Protocol EVM Implementation",
30
+ "devDependencies": {
31
+ "@eslint/js": "^9.24.0",
32
+ "@types/node": "^22.13.4",
33
+ "@typescript-eslint/eslint-plugin": "^8.29.1",
34
+ "@typescript-eslint/parser": "^8.29.1",
35
+ "eslint": "^9.24.0",
36
+ "eslint-plugin-import": "^2.31.0",
37
+ "eslint-plugin-jsdoc": "^50.6.9",
38
+ "eslint-plugin-prettier": "^5.2.6",
39
+ "prettier": "3.5.2",
40
+ "tsup": "^8.4.0",
41
+ "tsx": "^4.19.2",
42
+ "typescript": "^5.7.3",
43
+ "vite": "^6.2.6",
44
+ "vite-tsconfig-paths": "^5.1.4",
45
+ "vitest": "^3.0.5"
46
+ },
47
+ "dependencies": {
48
+ "@bankofai/x402-core": "2.6.0-beta.0",
49
+ "@bankofai/x402-extensions": "2.6.0-beta.0",
50
+ "viem": "^2.39.3",
51
+ "zod": "^3.24.2"
52
+ },
53
+ "exports": {
54
+ ".": {
55
+ "import": {
56
+ "types": "./dist/esm/index.d.mts",
57
+ "default": "./dist/esm/index.mjs"
58
+ },
59
+ "require": {
60
+ "types": "./dist/cjs/index.d.ts",
61
+ "default": "./dist/cjs/index.js"
62
+ }
63
+ },
64
+ "./v1": {
65
+ "import": {
66
+ "types": "./dist/esm/v1/index.d.mts",
67
+ "default": "./dist/esm/v1/index.mjs"
68
+ },
69
+ "require": {
70
+ "types": "./dist/cjs/v1/index.d.ts",
71
+ "default": "./dist/cjs/v1/index.js"
72
+ }
73
+ },
74
+ "./exact/client": {
75
+ "import": {
76
+ "types": "./dist/esm/exact/client/index.d.mts",
77
+ "default": "./dist/esm/exact/client/index.mjs"
78
+ },
79
+ "require": {
80
+ "types": "./dist/cjs/exact/client/index.d.ts",
81
+ "default": "./dist/cjs/exact/client/index.js"
82
+ }
83
+ },
84
+ "./exact/server": {
85
+ "import": {
86
+ "types": "./dist/esm/exact/server/index.d.mts",
87
+ "default": "./dist/esm/exact/server/index.mjs"
88
+ },
89
+ "require": {
90
+ "types": "./dist/cjs/exact/server/index.d.ts",
91
+ "default": "./dist/cjs/exact/server/index.js"
92
+ }
93
+ },
94
+ "./exact/facilitator": {
95
+ "import": {
96
+ "types": "./dist/esm/exact/facilitator/index.d.mts",
97
+ "default": "./dist/esm/exact/facilitator/index.mjs"
98
+ },
99
+ "require": {
100
+ "types": "./dist/cjs/exact/facilitator/index.d.ts",
101
+ "default": "./dist/cjs/exact/facilitator/index.js"
102
+ }
103
+ },
104
+ "./exact/v1/client": {
105
+ "import": {
106
+ "types": "./dist/esm/exact/v1/client/index.d.mts",
107
+ "default": "./dist/esm/exact/v1/client/index.mjs"
108
+ },
109
+ "require": {
110
+ "types": "./dist/cjs/exact/v1/client/index.d.ts",
111
+ "default": "./dist/cjs/exact/v1/client/index.js"
112
+ }
113
+ },
114
+ "./exact/v1/facilitator": {
115
+ "import": {
116
+ "types": "./dist/esm/exact/v1/facilitator/index.d.mts",
117
+ "default": "./dist/esm/exact/v1/facilitator/index.mjs"
118
+ },
119
+ "require": {
120
+ "types": "./dist/cjs/exact/v1/facilitator/index.d.ts",
121
+ "default": "./dist/cjs/exact/v1/facilitator/index.js"
122
+ }
123
+ }
124
+ },
125
+ "files": [
126
+ "dist"
127
+ ]
128
+ }