@dexterai/x402 2.0.0 → 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 -2
- package/dist/adapters/index.d.cts +4 -3
- package/dist/adapters/index.d.ts +4 -3
- package/dist/adapters/index.js +369 -2
- package/dist/client/index.cjs +378 -4
- package/dist/client/index.d.cts +5 -5
- package/dist/client/index.d.ts +5 -5
- package/dist/client/index.js +378 -4
- package/dist/react/index.cjs +378 -4
- package/dist/react/index.d.cts +5 -5
- package/dist/react/index.d.ts +5 -5
- package/dist/react/index.js +378 -4
- package/dist/server/index.cjs +3 -3
- package/dist/server/index.d.cts +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +3 -3
- package/dist/{sponsored-access-BgEDLg_H.d.cts → sponsored-access-DAVzu4x6.d.cts} +2 -2
- package/dist/{sponsored-access-DjLEKhOV.d.ts → sponsored-access-Lxa11w_X.d.ts} +2 -2
- package/dist/{types-DWhpiOBD.d.cts → types-D1u7iu8n.d.cts} +62 -3
- package/dist/{types-D1TGACsL.d.ts → types-YQlJI5E3.d.ts} +62 -3
- 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/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as PaymentAccept } from './types-
|
|
1
|
+
import { P as PaymentAccept } from './types-_iT11DL0.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* EVM Chain Adapter
|
|
@@ -7,6 +7,11 @@ import { P as PaymentAccept } from './types-CjLMR7qs.js';
|
|
|
7
7
|
* Uses EIP-712 typed data signing for x402 v2 payments.
|
|
8
8
|
*/
|
|
9
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";
|
|
10
15
|
/**
|
|
11
16
|
* CAIP-2 network identifiers for EVM chains.
|
|
12
17
|
* Mirrors dexter-facilitator/src/config/chains.ts — update both when adding chains.
|
|
@@ -17,15 +22,29 @@ declare const ARBITRUM_ONE = "eip155:42161";
|
|
|
17
22
|
declare const POLYGON = "eip155:137";
|
|
18
23
|
declare const OPTIMISM = "eip155:10";
|
|
19
24
|
declare const AVALANCHE = "eip155:43114";
|
|
25
|
+
declare const BSC_MAINNET = "eip155:56";
|
|
20
26
|
declare const SKALE_BASE = "eip155:1187947933";
|
|
21
27
|
declare const SKALE_BASE_SEPOLIA = "eip155:324705682";
|
|
22
28
|
/** @deprecated Not supported by the Dexter facilitator. Use BASE_MAINNET for EVM payments. */
|
|
23
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";
|
|
24
35
|
/**
|
|
25
36
|
* USDC contract addresses by chain.
|
|
26
37
|
* Source of truth: dexter-facilitator/src/config/chains.ts
|
|
27
38
|
*/
|
|
28
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
|
+
}>;
|
|
29
48
|
/**
|
|
30
49
|
* EVM wallet interface (compatible with wagmi, ethers, viem)
|
|
31
50
|
*/
|
|
@@ -74,7 +93,47 @@ declare class EvmAdapter implements ChainAdapter {
|
|
|
74
93
|
private getChainId;
|
|
75
94
|
getBalance(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<number>;
|
|
76
95
|
private encodeBalanceOf;
|
|
77
|
-
buildTransaction(accept: PaymentAccept, wallet: unknown,
|
|
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;
|
|
78
137
|
}
|
|
79
138
|
/**
|
|
80
139
|
* Create an EVM adapter instance
|
|
@@ -242,4 +301,4 @@ interface BalanceInfo {
|
|
|
242
301
|
asset: string;
|
|
243
302
|
}
|
|
244
303
|
|
|
245
|
-
export { type AdapterConfig as A, BASE_MAINNET as B, type ChainAdapter as C, type EvmWallet as E, type GenericWallet as G, OPTIMISM as O,
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dexterai/x402",
|
|
3
|
-
"version": "2.
|
|
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",
|