@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.
- package/README.md +184 -0
- package/dist/cjs/exact/client/index.d.ts +53 -0
- package/dist/cjs/exact/client/index.js +661 -0
- package/dist/cjs/exact/client/index.js.map +1 -0
- package/dist/cjs/exact/facilitator/index.d.ts +121 -0
- package/dist/cjs/exact/facilitator/index.js +1458 -0
- package/dist/cjs/exact/facilitator/index.js.map +1 -0
- package/dist/cjs/exact/server/index.d.ts +125 -0
- package/dist/cjs/exact/server/index.js +229 -0
- package/dist/cjs/exact/server/index.js.map +1 -0
- package/dist/cjs/exact/v1/client/index.d.ts +37 -0
- package/dist/cjs/exact/v1/client/index.js +175 -0
- package/dist/cjs/exact/v1/client/index.js.map +1 -0
- package/dist/cjs/exact/v1/facilitator/index.d.ts +62 -0
- package/dist/cjs/exact/v1/facilitator/index.js +436 -0
- package/dist/cjs/exact/v1/facilitator/index.js.map +1 -0
- package/dist/cjs/exact_permit/client/index.d.ts +57 -0
- package/dist/cjs/exact_permit/client/index.js +223 -0
- package/dist/cjs/exact_permit/client/index.js.map +1 -0
- package/dist/cjs/exact_permit/facilitator/index.d.ts +82 -0
- package/dist/cjs/exact_permit/facilitator/index.js +437 -0
- package/dist/cjs/exact_permit/facilitator/index.js.map +1 -0
- package/dist/cjs/exact_permit/server/index.d.ts +71 -0
- package/dist/cjs/exact_permit/server/index.js +186 -0
- package/dist/cjs/exact_permit/server/index.js.map +1 -0
- package/dist/cjs/index.d.ts +76 -0
- package/dist/cjs/index.js +779 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/permit2-CpuKY2-F.d.ts +509 -0
- package/dist/cjs/permit2-D65OQ5yU.d.ts +517 -0
- package/dist/cjs/permit2-DvsTlAyj.d.ts +531 -0
- package/dist/cjs/signer-DC81R8wQ.d.ts +161 -0
- package/dist/cjs/v1/index.d.ts +39 -0
- package/dist/cjs/v1/index.js +181 -0
- package/dist/cjs/v1/index.js.map +1 -0
- package/dist/esm/chunk-4JGB4GDD.mjs +425 -0
- package/dist/esm/chunk-4JGB4GDD.mjs.map +1 -0
- package/dist/esm/chunk-TKN5V2BV.mjs +13 -0
- package/dist/esm/chunk-TKN5V2BV.mjs.map +1 -0
- package/dist/esm/chunk-UDKSVWSE.mjs +716 -0
- package/dist/esm/chunk-UDKSVWSE.mjs.map +1 -0
- package/dist/esm/exact/client/index.d.mts +53 -0
- package/dist/esm/exact/client/index.mjs +17 -0
- package/dist/esm/exact/client/index.mjs.map +1 -0
- package/dist/esm/exact/facilitator/index.d.mts +121 -0
- package/dist/esm/exact/facilitator/index.mjs +876 -0
- package/dist/esm/exact/facilitator/index.mjs.map +1 -0
- package/dist/esm/exact/server/index.d.mts +125 -0
- package/dist/esm/exact/server/index.mjs +201 -0
- package/dist/esm/exact/server/index.mjs.map +1 -0
- package/dist/esm/exact/v1/client/index.d.mts +37 -0
- package/dist/esm/exact/v1/client/index.mjs +7 -0
- package/dist/esm/exact/v1/client/index.mjs.map +1 -0
- package/dist/esm/exact/v1/facilitator/index.d.mts +62 -0
- package/dist/esm/exact/v1/facilitator/index.mjs +7 -0
- package/dist/esm/exact/v1/facilitator/index.mjs.map +1 -0
- package/dist/esm/index.d.mts +76 -0
- package/dist/esm/index.mjs +71 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/permit2-D7ni3g6s.d.mts +509 -0
- package/dist/esm/signer-DC81R8wQ.d.mts +161 -0
- package/dist/esm/v1/index.d.mts +39 -0
- package/dist/esm/v1/index.mjs +13 -0
- package/dist/esm/v1/index.mjs.map +1 -0
- 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
|
+
}
|