@dexterai/x402 1.9.4 → 2.1.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 +27 -0
- package/dist/adapters/index.cjs +375 -3
- package/dist/adapters/index.d.cts +4 -5
- package/dist/adapters/index.d.ts +4 -5
- package/dist/adapters/index.js +369 -3
- package/dist/client/index.cjs +570 -10
- package/dist/client/index.d.cts +200 -36
- package/dist/client/index.d.ts +200 -36
- package/dist/client/index.js +568 -10
- package/dist/react/index.cjs +404 -8
- package/dist/react/index.d.cts +5 -5
- package/dist/react/index.d.ts +5 -5
- package/dist/react/index.js +404 -8
- package/dist/server/index.cjs +3 -4
- package/dist/server/index.d.cts +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +3 -4
- package/dist/{sponsored-access-D1_mINs4.d.ts → sponsored-access-DAVzu4x6.d.cts} +13 -2
- package/dist/{sponsored-access-Br6YPA-m.d.cts → sponsored-access-Lxa11w_X.d.ts} +13 -2
- package/dist/types-D1u7iu8n.d.cts +304 -0
- package/dist/types-YQlJI5E3.d.ts +304 -0
- package/dist/{types-CjLMR7qs.d.cts → types-_iT11DL0.d.cts} +2 -2
- package/dist/{types-CjLMR7qs.d.ts → types-_iT11DL0.d.ts} +2 -2
- package/dist/utils/index.cjs +0 -1
- package/dist/utils/index.js +0 -1
- package/package.json +1 -1
- package/dist/adapters/index.cjs.map +0 -1
- package/dist/adapters/index.js.map +0 -1
- package/dist/client/index.cjs.map +0 -1
- package/dist/client/index.js.map +0 -1
- package/dist/react/index.cjs.map +0 -1
- package/dist/react/index.js.map +0 -1
- package/dist/server/index.cjs.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/solana-BcOfK6Eq.d.cts +0 -132
- package/dist/solana-Cxr5byPa.d.ts +0 -132
- package/dist/types-BIHhO2-I.d.ts +0 -123
- package/dist/types-CfKflCZO.d.cts +0 -123
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.js.map +0 -1
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { P as PaymentAccept } from './types-_iT11DL0.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* EVM Chain Adapter
|
|
5
|
+
*
|
|
6
|
+
* Implements the ChainAdapter interface for EVM networks (Base, Ethereum, Arbitrum, etc.)
|
|
7
|
+
* Uses EIP-712 typed data signing for x402 v2 payments.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Permit2 constants (Uniswap canonical deployment, same address on every EVM chain)
|
|
12
|
+
*/
|
|
13
|
+
declare const PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
14
|
+
declare const X402_EXACT_PERMIT2_PROXY = "0x402085c248EeA27D92E8b30b2C58ed07f9E20001";
|
|
15
|
+
/**
|
|
16
|
+
* CAIP-2 network identifiers for EVM chains.
|
|
17
|
+
* Mirrors dexter-facilitator/src/config/chains.ts — update both when adding chains.
|
|
18
|
+
*/
|
|
19
|
+
declare const BASE_MAINNET = "eip155:8453";
|
|
20
|
+
declare const BASE_SEPOLIA = "eip155:84532";
|
|
21
|
+
declare const ARBITRUM_ONE = "eip155:42161";
|
|
22
|
+
declare const POLYGON = "eip155:137";
|
|
23
|
+
declare const OPTIMISM = "eip155:10";
|
|
24
|
+
declare const AVALANCHE = "eip155:43114";
|
|
25
|
+
declare const BSC_MAINNET = "eip155:56";
|
|
26
|
+
declare const SKALE_BASE = "eip155:1187947933";
|
|
27
|
+
declare const SKALE_BASE_SEPOLIA = "eip155:324705682";
|
|
28
|
+
/** @deprecated Not supported by the Dexter facilitator. Use BASE_MAINNET for EVM payments. */
|
|
29
|
+
declare const ETHEREUM_MAINNET = "eip155:1";
|
|
30
|
+
/**
|
|
31
|
+
* BSC stablecoin addresses (18 decimals — unlike 6 on every other chain)
|
|
32
|
+
*/
|
|
33
|
+
declare const BSC_USDT = "0x55d398326f99059fF775485246999027B3197955";
|
|
34
|
+
declare const BSC_USDC = "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d";
|
|
35
|
+
/**
|
|
36
|
+
* USDC contract addresses by chain.
|
|
37
|
+
* Source of truth: dexter-facilitator/src/config/chains.ts
|
|
38
|
+
*/
|
|
39
|
+
declare const USDC_ADDRESSES: Record<string, string>;
|
|
40
|
+
/**
|
|
41
|
+
* Known BSC stablecoin addresses (for isKnownStablecoin checks).
|
|
42
|
+
* Both use 18 decimals on BSC, unlike the 6 decimals on all other chains.
|
|
43
|
+
*/
|
|
44
|
+
declare const BSC_STABLECOIN_ADDRESSES: Record<string, {
|
|
45
|
+
symbol: string;
|
|
46
|
+
decimals: number;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* EVM wallet interface (compatible with wagmi, ethers, viem)
|
|
50
|
+
*/
|
|
51
|
+
interface EvmWallet {
|
|
52
|
+
/** Wallet address */
|
|
53
|
+
address: string;
|
|
54
|
+
/** Chain ID currently connected to */
|
|
55
|
+
chainId?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Sign typed data (EIP-712)
|
|
58
|
+
* This is the primary signing method for x402 EVM payments
|
|
59
|
+
*/
|
|
60
|
+
signTypedData?(params: {
|
|
61
|
+
domain: Record<string, unknown>;
|
|
62
|
+
types: Record<string, unknown[]>;
|
|
63
|
+
primaryType: string;
|
|
64
|
+
message: Record<string, unknown>;
|
|
65
|
+
}): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Alternative: Send transaction directly
|
|
68
|
+
* Used if signTypedData is not available
|
|
69
|
+
*/
|
|
70
|
+
sendTransaction?(params: {
|
|
71
|
+
to: string;
|
|
72
|
+
data: string;
|
|
73
|
+
value?: bigint;
|
|
74
|
+
}): Promise<string>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Check if an object is a valid EVM wallet
|
|
78
|
+
*/
|
|
79
|
+
declare function isEvmWallet(wallet: unknown): wallet is EvmWallet;
|
|
80
|
+
/**
|
|
81
|
+
* EVM Chain Adapter
|
|
82
|
+
*/
|
|
83
|
+
declare class EvmAdapter implements ChainAdapter {
|
|
84
|
+
readonly name = "EVM";
|
|
85
|
+
readonly networks: string[];
|
|
86
|
+
private config;
|
|
87
|
+
private log;
|
|
88
|
+
constructor(config?: AdapterConfig);
|
|
89
|
+
canHandle(network: string): boolean;
|
|
90
|
+
getDefaultRpcUrl(network: string): string;
|
|
91
|
+
getAddress(wallet: unknown): string | null;
|
|
92
|
+
isConnected(wallet: unknown): boolean;
|
|
93
|
+
private getChainId;
|
|
94
|
+
getBalance(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<number>;
|
|
95
|
+
private encodeBalanceOf;
|
|
96
|
+
buildTransaction(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<SignedTransaction>;
|
|
97
|
+
/**
|
|
98
|
+
* Build a payment transaction for chains that use the approval-based scheme.
|
|
99
|
+
* The facilitator's /supported response provides the EIP-712 domain and types
|
|
100
|
+
* in accept.extra, so the client doesn't hardcode any contract addresses.
|
|
101
|
+
*/
|
|
102
|
+
private buildApprovalTransaction;
|
|
103
|
+
/**
|
|
104
|
+
* Build a Permit2 payment transaction. Used when the facilitator signals
|
|
105
|
+
* assetTransferMethod: "permit2" in extra (e.g., BSC where EIP-3009 is unavailable).
|
|
106
|
+
*
|
|
107
|
+
* Flow:
|
|
108
|
+
* 1. Check if token has approved the Permit2 contract. If not, approve(Permit2, maxUint256).
|
|
109
|
+
* 2. Sign EIP-712 PermitWitnessTransferFrom against the Permit2 contract.
|
|
110
|
+
* 3. Return { permit2Authorization, signature } payload for the facilitator.
|
|
111
|
+
*/
|
|
112
|
+
private buildPermit2Transaction;
|
|
113
|
+
/**
|
|
114
|
+
* Read ERC-20 allowance via raw eth_call (no viem dependency needed).
|
|
115
|
+
*/
|
|
116
|
+
private readAllowance;
|
|
117
|
+
/**
|
|
118
|
+
* Encode ERC-20 approve(address,uint256) calldata.
|
|
119
|
+
*/
|
|
120
|
+
private encodeApprove;
|
|
121
|
+
/**
|
|
122
|
+
* Wait for a transaction receipt by polling eth_getTransactionReceipt.
|
|
123
|
+
*/
|
|
124
|
+
private waitForReceipt;
|
|
125
|
+
/**
|
|
126
|
+
* Calculate how much to approve based on the facilitator's approval strategy.
|
|
127
|
+
* Buffered approvals reduce the number of on-chain approval txs for micropayments.
|
|
128
|
+
*/
|
|
129
|
+
private calculateApprovalAmount;
|
|
130
|
+
/**
|
|
131
|
+
* Infer token decimals from payment amount magnitude.
|
|
132
|
+
* BSC stablecoins use 18 decimals, all others use 6.
|
|
133
|
+
* A $1 payment is 1000000 (6 dec) or 1000000000000000000 (18 dec).
|
|
134
|
+
* If the amount has > 12 digits, it's almost certainly 18 decimals.
|
|
135
|
+
*/
|
|
136
|
+
private inferDecimals;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Create an EVM adapter instance
|
|
140
|
+
*/
|
|
141
|
+
declare function createEvmAdapter(config?: AdapterConfig): EvmAdapter;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Solana Chain Adapter
|
|
145
|
+
*
|
|
146
|
+
* Implements the ChainAdapter interface for Solana networks.
|
|
147
|
+
* Handles transaction building, signing, and balance queries.
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* CAIP-2 network identifiers for Solana
|
|
152
|
+
*/
|
|
153
|
+
declare const SOLANA_MAINNET = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
154
|
+
declare const SOLANA_DEVNET = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
155
|
+
declare const SOLANA_TESTNET = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
|
|
156
|
+
/**
|
|
157
|
+
* Solana wallet interface (compatible with @solana/wallet-adapter)
|
|
158
|
+
*/
|
|
159
|
+
interface SolanaWallet {
|
|
160
|
+
publicKey: {
|
|
161
|
+
toBase58(): string;
|
|
162
|
+
} | null;
|
|
163
|
+
signTransaction<T>(tx: T): Promise<T>;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Check if an object is a valid Solana wallet
|
|
167
|
+
*/
|
|
168
|
+
declare function isSolanaWallet(wallet: unknown): wallet is SolanaWallet;
|
|
169
|
+
/**
|
|
170
|
+
* Solana Chain Adapter
|
|
171
|
+
*/
|
|
172
|
+
declare class SolanaAdapter implements ChainAdapter {
|
|
173
|
+
readonly name = "Solana";
|
|
174
|
+
readonly networks: string[];
|
|
175
|
+
private config;
|
|
176
|
+
private log;
|
|
177
|
+
constructor(config?: AdapterConfig);
|
|
178
|
+
canHandle(network: string): boolean;
|
|
179
|
+
getDefaultRpcUrl(network: string): string;
|
|
180
|
+
getAddress(wallet: unknown): string | null;
|
|
181
|
+
isConnected(wallet: unknown): boolean;
|
|
182
|
+
getBalance(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<number>;
|
|
183
|
+
buildTransaction(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<SignedTransaction>;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Create a Solana adapter instance
|
|
187
|
+
*/
|
|
188
|
+
declare function createSolanaAdapter(config?: AdapterConfig): SolanaAdapter;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Generic wallet interface that works across chains.
|
|
192
|
+
* Each chain adapter will cast to its specific wallet type.
|
|
193
|
+
*/
|
|
194
|
+
interface GenericWallet {
|
|
195
|
+
/** Chain-specific identifier (address or public key) */
|
|
196
|
+
address: string;
|
|
197
|
+
/** Whether the wallet is connected and ready */
|
|
198
|
+
connected: boolean;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Result of building and signing a transaction.
|
|
202
|
+
*
|
|
203
|
+
* **Internal adapter return type.** The client remaps these fields before
|
|
204
|
+
* sending to the facilitator — the wire payload uses `payload.transaction`
|
|
205
|
+
* (Solana) or `payload.authorization + payload.signature` (EVM), not
|
|
206
|
+
* `serialized` directly. See {@link ../client/x402-client.ts} for the mapping.
|
|
207
|
+
*/
|
|
208
|
+
interface SignedTransaction {
|
|
209
|
+
/** Base64 (Solana) or JSON-stringified (EVM) transaction — internal only, not the wire field name */
|
|
210
|
+
serialized: string;
|
|
211
|
+
/** Transaction signature/hash if available before broadcast */
|
|
212
|
+
signature?: string;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Chain adapter interface - each chain implements this
|
|
216
|
+
*/
|
|
217
|
+
interface ChainAdapter {
|
|
218
|
+
/**
|
|
219
|
+
* Human-readable chain name
|
|
220
|
+
*/
|
|
221
|
+
readonly name: string;
|
|
222
|
+
/**
|
|
223
|
+
* CAIP-2 network identifiers this adapter handles
|
|
224
|
+
* e.g., ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'] for Solana mainnet
|
|
225
|
+
* e.g., ['eip155:8453'] for Base
|
|
226
|
+
*/
|
|
227
|
+
readonly networks: string[];
|
|
228
|
+
/**
|
|
229
|
+
* Check if this adapter can handle a given network
|
|
230
|
+
* @param network - CAIP-2 network identifier
|
|
231
|
+
*/
|
|
232
|
+
canHandle(network: string): boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Build and sign a payment transaction
|
|
235
|
+
*
|
|
236
|
+
* @param accept - The payment option from server's accepts[]
|
|
237
|
+
* @param wallet - Chain-specific wallet (will be cast internally)
|
|
238
|
+
* @param rpcUrl - Optional RPC URL override
|
|
239
|
+
* @returns Signed transaction ready for PAYMENT-SIGNATURE payload
|
|
240
|
+
*/
|
|
241
|
+
buildTransaction(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<SignedTransaction>;
|
|
242
|
+
/**
|
|
243
|
+
* Get the wallet's balance for the payment asset
|
|
244
|
+
*
|
|
245
|
+
* @param accept - Payment option (contains asset info)
|
|
246
|
+
* @param wallet - Chain-specific wallet
|
|
247
|
+
* @param rpcUrl - Optional RPC URL override
|
|
248
|
+
* @returns Balance in human-readable units (e.g., 12.50 for $12.50 USDC)
|
|
249
|
+
*/
|
|
250
|
+
getBalance(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<number>;
|
|
251
|
+
/**
|
|
252
|
+
* Get the wallet's address as a string
|
|
253
|
+
* @param wallet - Chain-specific wallet
|
|
254
|
+
*/
|
|
255
|
+
getAddress(wallet: unknown): string | null;
|
|
256
|
+
/**
|
|
257
|
+
* Check if wallet is connected
|
|
258
|
+
* @param wallet - Chain-specific wallet
|
|
259
|
+
*/
|
|
260
|
+
isConnected(wallet: unknown): boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Get default RPC URL for a network
|
|
263
|
+
* @param network - CAIP-2 network identifier
|
|
264
|
+
*/
|
|
265
|
+
getDefaultRpcUrl(network: string): string;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Configuration for creating a chain adapter
|
|
269
|
+
*/
|
|
270
|
+
interface AdapterConfig {
|
|
271
|
+
/** Custom RPC URLs by network */
|
|
272
|
+
rpcUrls?: Record<string, string>;
|
|
273
|
+
/** Enable verbose logging */
|
|
274
|
+
verbose?: boolean;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Multi-wallet container for different chains.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```typescript
|
|
281
|
+
* import type { SolanaWallet, EvmWallet } from '@dexterai/x402/adapters';
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
interface WalletSet {
|
|
285
|
+
/** Solana wallet (from @solana/wallet-adapter or createKeypairWallet) */
|
|
286
|
+
solana?: SolanaWallet;
|
|
287
|
+
/** EVM wallet (from wagmi, createEvmKeypairWallet, or any { address, signTypedData } object) */
|
|
288
|
+
evm?: EvmWallet;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Balance info across chains
|
|
292
|
+
*/
|
|
293
|
+
interface BalanceInfo {
|
|
294
|
+
/** CAIP-2 network identifier */
|
|
295
|
+
network: string;
|
|
296
|
+
/** Human-readable chain name */
|
|
297
|
+
chainName: string;
|
|
298
|
+
/** Balance in human units */
|
|
299
|
+
balance: number;
|
|
300
|
+
/** Asset symbol (e.g., 'USDC') */
|
|
301
|
+
asset: string;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export { type AdapterConfig as A, BASE_MAINNET as B, type ChainAdapter as C, type EvmWallet as E, type GenericWallet as G, OPTIMISM as O, PERMIT2_ADDRESS as P, type SolanaWallet as S, USDC_ADDRESSES as U, type WalletSet as W, X402_EXACT_PERMIT2_PROXY as X, createEvmAdapter as a, SOLANA_MAINNET as b, createSolanaAdapter as c, type BalanceInfo as d, SolanaAdapter as e, EvmAdapter as f, type SignedTransaction as g, SOLANA_DEVNET as h, isSolanaWallet as i, SOLANA_TESTNET as j, isEvmWallet as k, BSC_MAINNET as l, BSC_USDT as m, BSC_USDC as n, BSC_STABLECOIN_ADDRESSES as o, BASE_SEPOLIA as p, ARBITRUM_ONE as q, POLYGON as r, AVALANCHE as s, SKALE_BASE as t, SKALE_BASE_SEPOLIA as u, ETHEREUM_MAINNET as v };
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { P as PaymentAccept } from './types-_iT11DL0.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* EVM Chain Adapter
|
|
5
|
+
*
|
|
6
|
+
* Implements the ChainAdapter interface for EVM networks (Base, Ethereum, Arbitrum, etc.)
|
|
7
|
+
* Uses EIP-712 typed data signing for x402 v2 payments.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Permit2 constants (Uniswap canonical deployment, same address on every EVM chain)
|
|
12
|
+
*/
|
|
13
|
+
declare const PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
14
|
+
declare const X402_EXACT_PERMIT2_PROXY = "0x402085c248EeA27D92E8b30b2C58ed07f9E20001";
|
|
15
|
+
/**
|
|
16
|
+
* CAIP-2 network identifiers for EVM chains.
|
|
17
|
+
* Mirrors dexter-facilitator/src/config/chains.ts — update both when adding chains.
|
|
18
|
+
*/
|
|
19
|
+
declare const BASE_MAINNET = "eip155:8453";
|
|
20
|
+
declare const BASE_SEPOLIA = "eip155:84532";
|
|
21
|
+
declare const ARBITRUM_ONE = "eip155:42161";
|
|
22
|
+
declare const POLYGON = "eip155:137";
|
|
23
|
+
declare const OPTIMISM = "eip155:10";
|
|
24
|
+
declare const AVALANCHE = "eip155:43114";
|
|
25
|
+
declare const BSC_MAINNET = "eip155:56";
|
|
26
|
+
declare const SKALE_BASE = "eip155:1187947933";
|
|
27
|
+
declare const SKALE_BASE_SEPOLIA = "eip155:324705682";
|
|
28
|
+
/** @deprecated Not supported by the Dexter facilitator. Use BASE_MAINNET for EVM payments. */
|
|
29
|
+
declare const ETHEREUM_MAINNET = "eip155:1";
|
|
30
|
+
/**
|
|
31
|
+
* BSC stablecoin addresses (18 decimals — unlike 6 on every other chain)
|
|
32
|
+
*/
|
|
33
|
+
declare const BSC_USDT = "0x55d398326f99059fF775485246999027B3197955";
|
|
34
|
+
declare const BSC_USDC = "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d";
|
|
35
|
+
/**
|
|
36
|
+
* USDC contract addresses by chain.
|
|
37
|
+
* Source of truth: dexter-facilitator/src/config/chains.ts
|
|
38
|
+
*/
|
|
39
|
+
declare const USDC_ADDRESSES: Record<string, string>;
|
|
40
|
+
/**
|
|
41
|
+
* Known BSC stablecoin addresses (for isKnownStablecoin checks).
|
|
42
|
+
* Both use 18 decimals on BSC, unlike the 6 decimals on all other chains.
|
|
43
|
+
*/
|
|
44
|
+
declare const BSC_STABLECOIN_ADDRESSES: Record<string, {
|
|
45
|
+
symbol: string;
|
|
46
|
+
decimals: number;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* EVM wallet interface (compatible with wagmi, ethers, viem)
|
|
50
|
+
*/
|
|
51
|
+
interface EvmWallet {
|
|
52
|
+
/** Wallet address */
|
|
53
|
+
address: string;
|
|
54
|
+
/** Chain ID currently connected to */
|
|
55
|
+
chainId?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Sign typed data (EIP-712)
|
|
58
|
+
* This is the primary signing method for x402 EVM payments
|
|
59
|
+
*/
|
|
60
|
+
signTypedData?(params: {
|
|
61
|
+
domain: Record<string, unknown>;
|
|
62
|
+
types: Record<string, unknown[]>;
|
|
63
|
+
primaryType: string;
|
|
64
|
+
message: Record<string, unknown>;
|
|
65
|
+
}): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Alternative: Send transaction directly
|
|
68
|
+
* Used if signTypedData is not available
|
|
69
|
+
*/
|
|
70
|
+
sendTransaction?(params: {
|
|
71
|
+
to: string;
|
|
72
|
+
data: string;
|
|
73
|
+
value?: bigint;
|
|
74
|
+
}): Promise<string>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Check if an object is a valid EVM wallet
|
|
78
|
+
*/
|
|
79
|
+
declare function isEvmWallet(wallet: unknown): wallet is EvmWallet;
|
|
80
|
+
/**
|
|
81
|
+
* EVM Chain Adapter
|
|
82
|
+
*/
|
|
83
|
+
declare class EvmAdapter implements ChainAdapter {
|
|
84
|
+
readonly name = "EVM";
|
|
85
|
+
readonly networks: string[];
|
|
86
|
+
private config;
|
|
87
|
+
private log;
|
|
88
|
+
constructor(config?: AdapterConfig);
|
|
89
|
+
canHandle(network: string): boolean;
|
|
90
|
+
getDefaultRpcUrl(network: string): string;
|
|
91
|
+
getAddress(wallet: unknown): string | null;
|
|
92
|
+
isConnected(wallet: unknown): boolean;
|
|
93
|
+
private getChainId;
|
|
94
|
+
getBalance(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<number>;
|
|
95
|
+
private encodeBalanceOf;
|
|
96
|
+
buildTransaction(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<SignedTransaction>;
|
|
97
|
+
/**
|
|
98
|
+
* Build a payment transaction for chains that use the approval-based scheme.
|
|
99
|
+
* The facilitator's /supported response provides the EIP-712 domain and types
|
|
100
|
+
* in accept.extra, so the client doesn't hardcode any contract addresses.
|
|
101
|
+
*/
|
|
102
|
+
private buildApprovalTransaction;
|
|
103
|
+
/**
|
|
104
|
+
* Build a Permit2 payment transaction. Used when the facilitator signals
|
|
105
|
+
* assetTransferMethod: "permit2" in extra (e.g., BSC where EIP-3009 is unavailable).
|
|
106
|
+
*
|
|
107
|
+
* Flow:
|
|
108
|
+
* 1. Check if token has approved the Permit2 contract. If not, approve(Permit2, maxUint256).
|
|
109
|
+
* 2. Sign EIP-712 PermitWitnessTransferFrom against the Permit2 contract.
|
|
110
|
+
* 3. Return { permit2Authorization, signature } payload for the facilitator.
|
|
111
|
+
*/
|
|
112
|
+
private buildPermit2Transaction;
|
|
113
|
+
/**
|
|
114
|
+
* Read ERC-20 allowance via raw eth_call (no viem dependency needed).
|
|
115
|
+
*/
|
|
116
|
+
private readAllowance;
|
|
117
|
+
/**
|
|
118
|
+
* Encode ERC-20 approve(address,uint256) calldata.
|
|
119
|
+
*/
|
|
120
|
+
private encodeApprove;
|
|
121
|
+
/**
|
|
122
|
+
* Wait for a transaction receipt by polling eth_getTransactionReceipt.
|
|
123
|
+
*/
|
|
124
|
+
private waitForReceipt;
|
|
125
|
+
/**
|
|
126
|
+
* Calculate how much to approve based on the facilitator's approval strategy.
|
|
127
|
+
* Buffered approvals reduce the number of on-chain approval txs for micropayments.
|
|
128
|
+
*/
|
|
129
|
+
private calculateApprovalAmount;
|
|
130
|
+
/**
|
|
131
|
+
* Infer token decimals from payment amount magnitude.
|
|
132
|
+
* BSC stablecoins use 18 decimals, all others use 6.
|
|
133
|
+
* A $1 payment is 1000000 (6 dec) or 1000000000000000000 (18 dec).
|
|
134
|
+
* If the amount has > 12 digits, it's almost certainly 18 decimals.
|
|
135
|
+
*/
|
|
136
|
+
private inferDecimals;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Create an EVM adapter instance
|
|
140
|
+
*/
|
|
141
|
+
declare function createEvmAdapter(config?: AdapterConfig): EvmAdapter;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Solana Chain Adapter
|
|
145
|
+
*
|
|
146
|
+
* Implements the ChainAdapter interface for Solana networks.
|
|
147
|
+
* Handles transaction building, signing, and balance queries.
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* CAIP-2 network identifiers for Solana
|
|
152
|
+
*/
|
|
153
|
+
declare const SOLANA_MAINNET = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
154
|
+
declare const SOLANA_DEVNET = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
155
|
+
declare const SOLANA_TESTNET = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
|
|
156
|
+
/**
|
|
157
|
+
* Solana wallet interface (compatible with @solana/wallet-adapter)
|
|
158
|
+
*/
|
|
159
|
+
interface SolanaWallet {
|
|
160
|
+
publicKey: {
|
|
161
|
+
toBase58(): string;
|
|
162
|
+
} | null;
|
|
163
|
+
signTransaction<T>(tx: T): Promise<T>;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Check if an object is a valid Solana wallet
|
|
167
|
+
*/
|
|
168
|
+
declare function isSolanaWallet(wallet: unknown): wallet is SolanaWallet;
|
|
169
|
+
/**
|
|
170
|
+
* Solana Chain Adapter
|
|
171
|
+
*/
|
|
172
|
+
declare class SolanaAdapter implements ChainAdapter {
|
|
173
|
+
readonly name = "Solana";
|
|
174
|
+
readonly networks: string[];
|
|
175
|
+
private config;
|
|
176
|
+
private log;
|
|
177
|
+
constructor(config?: AdapterConfig);
|
|
178
|
+
canHandle(network: string): boolean;
|
|
179
|
+
getDefaultRpcUrl(network: string): string;
|
|
180
|
+
getAddress(wallet: unknown): string | null;
|
|
181
|
+
isConnected(wallet: unknown): boolean;
|
|
182
|
+
getBalance(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<number>;
|
|
183
|
+
buildTransaction(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<SignedTransaction>;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Create a Solana adapter instance
|
|
187
|
+
*/
|
|
188
|
+
declare function createSolanaAdapter(config?: AdapterConfig): SolanaAdapter;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Generic wallet interface that works across chains.
|
|
192
|
+
* Each chain adapter will cast to its specific wallet type.
|
|
193
|
+
*/
|
|
194
|
+
interface GenericWallet {
|
|
195
|
+
/** Chain-specific identifier (address or public key) */
|
|
196
|
+
address: string;
|
|
197
|
+
/** Whether the wallet is connected and ready */
|
|
198
|
+
connected: boolean;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Result of building and signing a transaction.
|
|
202
|
+
*
|
|
203
|
+
* **Internal adapter return type.** The client remaps these fields before
|
|
204
|
+
* sending to the facilitator — the wire payload uses `payload.transaction`
|
|
205
|
+
* (Solana) or `payload.authorization + payload.signature` (EVM), not
|
|
206
|
+
* `serialized` directly. See {@link ../client/x402-client.ts} for the mapping.
|
|
207
|
+
*/
|
|
208
|
+
interface SignedTransaction {
|
|
209
|
+
/** Base64 (Solana) or JSON-stringified (EVM) transaction — internal only, not the wire field name */
|
|
210
|
+
serialized: string;
|
|
211
|
+
/** Transaction signature/hash if available before broadcast */
|
|
212
|
+
signature?: string;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Chain adapter interface - each chain implements this
|
|
216
|
+
*/
|
|
217
|
+
interface ChainAdapter {
|
|
218
|
+
/**
|
|
219
|
+
* Human-readable chain name
|
|
220
|
+
*/
|
|
221
|
+
readonly name: string;
|
|
222
|
+
/**
|
|
223
|
+
* CAIP-2 network identifiers this adapter handles
|
|
224
|
+
* e.g., ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'] for Solana mainnet
|
|
225
|
+
* e.g., ['eip155:8453'] for Base
|
|
226
|
+
*/
|
|
227
|
+
readonly networks: string[];
|
|
228
|
+
/**
|
|
229
|
+
* Check if this adapter can handle a given network
|
|
230
|
+
* @param network - CAIP-2 network identifier
|
|
231
|
+
*/
|
|
232
|
+
canHandle(network: string): boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Build and sign a payment transaction
|
|
235
|
+
*
|
|
236
|
+
* @param accept - The payment option from server's accepts[]
|
|
237
|
+
* @param wallet - Chain-specific wallet (will be cast internally)
|
|
238
|
+
* @param rpcUrl - Optional RPC URL override
|
|
239
|
+
* @returns Signed transaction ready for PAYMENT-SIGNATURE payload
|
|
240
|
+
*/
|
|
241
|
+
buildTransaction(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<SignedTransaction>;
|
|
242
|
+
/**
|
|
243
|
+
* Get the wallet's balance for the payment asset
|
|
244
|
+
*
|
|
245
|
+
* @param accept - Payment option (contains asset info)
|
|
246
|
+
* @param wallet - Chain-specific wallet
|
|
247
|
+
* @param rpcUrl - Optional RPC URL override
|
|
248
|
+
* @returns Balance in human-readable units (e.g., 12.50 for $12.50 USDC)
|
|
249
|
+
*/
|
|
250
|
+
getBalance(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<number>;
|
|
251
|
+
/**
|
|
252
|
+
* Get the wallet's address as a string
|
|
253
|
+
* @param wallet - Chain-specific wallet
|
|
254
|
+
*/
|
|
255
|
+
getAddress(wallet: unknown): string | null;
|
|
256
|
+
/**
|
|
257
|
+
* Check if wallet is connected
|
|
258
|
+
* @param wallet - Chain-specific wallet
|
|
259
|
+
*/
|
|
260
|
+
isConnected(wallet: unknown): boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Get default RPC URL for a network
|
|
263
|
+
* @param network - CAIP-2 network identifier
|
|
264
|
+
*/
|
|
265
|
+
getDefaultRpcUrl(network: string): string;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Configuration for creating a chain adapter
|
|
269
|
+
*/
|
|
270
|
+
interface AdapterConfig {
|
|
271
|
+
/** Custom RPC URLs by network */
|
|
272
|
+
rpcUrls?: Record<string, string>;
|
|
273
|
+
/** Enable verbose logging */
|
|
274
|
+
verbose?: boolean;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Multi-wallet container for different chains.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```typescript
|
|
281
|
+
* import type { SolanaWallet, EvmWallet } from '@dexterai/x402/adapters';
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
interface WalletSet {
|
|
285
|
+
/** Solana wallet (from @solana/wallet-adapter or createKeypairWallet) */
|
|
286
|
+
solana?: SolanaWallet;
|
|
287
|
+
/** EVM wallet (from wagmi, createEvmKeypairWallet, or any { address, signTypedData } object) */
|
|
288
|
+
evm?: EvmWallet;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Balance info across chains
|
|
292
|
+
*/
|
|
293
|
+
interface BalanceInfo {
|
|
294
|
+
/** CAIP-2 network identifier */
|
|
295
|
+
network: string;
|
|
296
|
+
/** Human-readable chain name */
|
|
297
|
+
chainName: string;
|
|
298
|
+
/** Balance in human units */
|
|
299
|
+
balance: number;
|
|
300
|
+
/** Asset symbol (e.g., 'USDC') */
|
|
301
|
+
asset: string;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export { type AdapterConfig as A, BASE_MAINNET as B, type ChainAdapter as C, type EvmWallet as E, type GenericWallet as G, OPTIMISM as O, PERMIT2_ADDRESS as P, type SolanaWallet as S, USDC_ADDRESSES as U, type WalletSet as W, X402_EXACT_PERMIT2_PROXY as X, createEvmAdapter as a, SOLANA_MAINNET as b, createSolanaAdapter as c, type BalanceInfo as d, SolanaAdapter as e, EvmAdapter as f, type SignedTransaction as g, SOLANA_DEVNET as h, isSolanaWallet as i, SOLANA_TESTNET as j, isEvmWallet as k, BSC_MAINNET as l, BSC_USDT as m, BSC_USDC as n, BSC_STABLECOIN_ADDRESSES as o, BASE_SEPOLIA as p, ARBITRUM_ONE as q, POLYGON as r, AVALANCHE as s, SKALE_BASE as t, SKALE_BASE_SEPOLIA as u, ETHEREUM_MAINNET as v };
|
|
@@ -85,8 +85,8 @@ interface AcceptsExtra {
|
|
|
85
85
|
interface PaymentAccept {
|
|
86
86
|
/** x402 version (1 or 2, defaults to 2 if not specified) */
|
|
87
87
|
x402Version?: 1 | 2;
|
|
88
|
-
/** Payment scheme (
|
|
89
|
-
scheme: 'exact';
|
|
88
|
+
/** Payment scheme ('exact' for EIP-3009 chains, 'exact-approval' for approval-based chains like BSC) */
|
|
89
|
+
scheme: 'exact' | 'exact-approval';
|
|
90
90
|
/** CAIP-2 network identifier (v1: 'solana', v2: 'solana:5eykt...') */
|
|
91
91
|
network: string;
|
|
92
92
|
/** Payment amount in atomic units (x402 v2 spec field) */
|
|
@@ -85,8 +85,8 @@ interface AcceptsExtra {
|
|
|
85
85
|
interface PaymentAccept {
|
|
86
86
|
/** x402 version (1 or 2, defaults to 2 if not specified) */
|
|
87
87
|
x402Version?: 1 | 2;
|
|
88
|
-
/** Payment scheme (
|
|
89
|
-
scheme: 'exact';
|
|
88
|
+
/** Payment scheme ('exact' for EIP-3009 chains, 'exact-approval' for approval-based chains like BSC) */
|
|
89
|
+
scheme: 'exact' | 'exact-approval';
|
|
90
90
|
/** CAIP-2 network identifier (v1: 'solana', v2: 'solana:5eykt...') */
|
|
91
91
|
network: string;
|
|
92
92
|
/** Payment amount in atomic units (x402 v2 spec field) */
|
package/dist/utils/index.cjs
CHANGED
package/dist/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dexterai/x402",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Full-stack x402 SDK - add paid API monetization to any endpoint. Express middleware, React hooks, Access Pass, dynamic pricing. Solana, Base, Polygon, Arbitrum, Optimism, Avalanche, SKALE.",
|
|
5
5
|
"author": "Dexter",
|
|
6
6
|
"license": "MIT",
|