@dexterai/x402 1.6.3 → 1.6.5
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/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/client/index.cjs +43 -2
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +73 -2
- package/dist/client/index.d.ts +73 -2
- package/dist/client/index.js +41 -2
- package/dist/client/index.js.map +1 -1
- package/dist/{evm-BYjwU6ZW.d.cts → solana-BYh8ehOi.d.cts} +48 -48
- package/dist/{evm-71SZ7cjW.d.ts → solana-Bve65qm4.d.ts} +48 -48
- package/package.json +1 -1
package/dist/client/index.d.cts
CHANGED
|
@@ -2,8 +2,9 @@ export { a as X402Client, X as X402ClientConfig, c as createX402Client } from '.
|
|
|
2
2
|
import { A as AccessPassClientConfig } from '../types-CcVAaoro.cjs';
|
|
3
3
|
export { b as AccessPassInfo, a as AccessPassTier, D as DEXTER_FACILITATOR_URL, U as USDC_MINT, X as X402Error } from '../types-CcVAaoro.cjs';
|
|
4
4
|
import { Transaction, VersionedTransaction, Keypair } from '@solana/web3.js';
|
|
5
|
+
import { E as EvmWallet } from '../solana-BYh8ehOi.cjs';
|
|
6
|
+
export { B as BASE_MAINNET, S as SOLANA_MAINNET, a as createEvmAdapter, c as createSolanaAdapter } from '../solana-BYh8ehOi.cjs';
|
|
5
7
|
export { C as ChainAdapter, W as WalletSet } from '../types--r7urkVI.cjs';
|
|
6
|
-
export { B as BASE_MAINNET, S as SOLANA_MAINNET, a as createEvmAdapter, c as createSolanaAdapter } from '../evm-BYjwU6ZW.cjs';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Simple Fetch Wrapper for Node.js
|
|
@@ -173,4 +174,74 @@ declare function createKeypairWallet(privateKey: string | number[] | Uint8Array)
|
|
|
173
174
|
*/
|
|
174
175
|
declare function isKeypairWallet(wallet: unknown): wallet is KeypairWallet;
|
|
175
176
|
|
|
176
|
-
|
|
177
|
+
/**
|
|
178
|
+
* EVM Keypair Wallet for Node.js
|
|
179
|
+
*
|
|
180
|
+
* Creates an EVM wallet interface from a private key.
|
|
181
|
+
* Enables Node.js scripts to use the x402 client for Base/EVM payments
|
|
182
|
+
* without a browser wallet (MetaMask, etc.).
|
|
183
|
+
*
|
|
184
|
+
* Requires `viem` as a peer dependency (`npm install viem`).
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* import { createX402Client, createEvmKeypairWallet } from '@dexterai/x402/client';
|
|
189
|
+
*
|
|
190
|
+
* // From hex private key (with or without 0x prefix)
|
|
191
|
+
* const wallet = await createEvmKeypairWallet('0xabc123...');
|
|
192
|
+
*
|
|
193
|
+
* const client = createX402Client({
|
|
194
|
+
* wallets: { evm: wallet },
|
|
195
|
+
* });
|
|
196
|
+
*
|
|
197
|
+
* const response = await client.fetch('https://api.example.com/protected');
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Create an EVM wallet from a private key
|
|
203
|
+
*
|
|
204
|
+
* Uses viem's `privateKeyToAccount` for EIP-712 typed data signing,
|
|
205
|
+
* which is chain-agnostic -- works for Base, Ethereum, Arbitrum, and
|
|
206
|
+
* any EVM chain without hardcoding a specific network.
|
|
207
|
+
*
|
|
208
|
+
* This function is async because viem is loaded via dynamic `import()`
|
|
209
|
+
* to ensure compatibility with both ESM and CJS consumers.
|
|
210
|
+
*
|
|
211
|
+
* @param privateKey - Hex-encoded private key (with or without 0x prefix)
|
|
212
|
+
* @returns Wallet interface compatible with createX402Client's `wallets.evm`
|
|
213
|
+
* @throws If viem is not installed or the private key is invalid
|
|
214
|
+
*
|
|
215
|
+
* @example From environment variable
|
|
216
|
+
* ```typescript
|
|
217
|
+
* const wallet = await createEvmKeypairWallet(process.env.BASE_PRIVATE_KEY!);
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* @example With createX402Client
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const client = createX402Client({
|
|
223
|
+
* wallets: {
|
|
224
|
+
* solana: createKeypairWallet(process.env.SOLANA_KEY!),
|
|
225
|
+
* evm: await createEvmKeypairWallet(process.env.BASE_KEY!),
|
|
226
|
+
* },
|
|
227
|
+
* });
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @example With wrapFetch (automatic -- you don't need this directly)
|
|
231
|
+
* ```typescript
|
|
232
|
+
* const x402Fetch = wrapFetch(fetch, {
|
|
233
|
+
* evmPrivateKey: process.env.BASE_PRIVATE_KEY!,
|
|
234
|
+
* });
|
|
235
|
+
* // wrapFetch calls createEvmKeypairWallet internally
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
declare function createEvmKeypairWallet(privateKey: string): Promise<EvmWallet>;
|
|
239
|
+
/**
|
|
240
|
+
* Check if an object is a wallet created by createEvmKeypairWallet
|
|
241
|
+
*
|
|
242
|
+
* Note: This also returns true for any valid EvmWallet -- use `isEvmWallet`
|
|
243
|
+
* from `@dexterai/x402/adapters` for the general check.
|
|
244
|
+
*/
|
|
245
|
+
declare function isEvmKeypairWallet(wallet: unknown): wallet is EvmWallet;
|
|
246
|
+
|
|
247
|
+
export { AccessPassClientConfig, type KeypairWallet, type WrapFetchOptions, createEvmKeypairWallet, createKeypairWallet, isEvmKeypairWallet, isKeypairWallet, wrapFetch };
|
package/dist/client/index.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ export { a as X402Client, X as X402ClientConfig, c as createX402Client } from '.
|
|
|
2
2
|
import { A as AccessPassClientConfig } from '../types-CcVAaoro.js';
|
|
3
3
|
export { b as AccessPassInfo, a as AccessPassTier, D as DEXTER_FACILITATOR_URL, U as USDC_MINT, X as X402Error } from '../types-CcVAaoro.js';
|
|
4
4
|
import { Transaction, VersionedTransaction, Keypair } from '@solana/web3.js';
|
|
5
|
+
import { E as EvmWallet } from '../solana-Bve65qm4.js';
|
|
6
|
+
export { B as BASE_MAINNET, S as SOLANA_MAINNET, a as createEvmAdapter, c as createSolanaAdapter } from '../solana-Bve65qm4.js';
|
|
5
7
|
export { C as ChainAdapter, W as WalletSet } from '../types-BtpD4ULe.js';
|
|
6
|
-
export { B as BASE_MAINNET, S as SOLANA_MAINNET, a as createEvmAdapter, c as createSolanaAdapter } from '../evm-71SZ7cjW.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Simple Fetch Wrapper for Node.js
|
|
@@ -173,4 +174,74 @@ declare function createKeypairWallet(privateKey: string | number[] | Uint8Array)
|
|
|
173
174
|
*/
|
|
174
175
|
declare function isKeypairWallet(wallet: unknown): wallet is KeypairWallet;
|
|
175
176
|
|
|
176
|
-
|
|
177
|
+
/**
|
|
178
|
+
* EVM Keypair Wallet for Node.js
|
|
179
|
+
*
|
|
180
|
+
* Creates an EVM wallet interface from a private key.
|
|
181
|
+
* Enables Node.js scripts to use the x402 client for Base/EVM payments
|
|
182
|
+
* without a browser wallet (MetaMask, etc.).
|
|
183
|
+
*
|
|
184
|
+
* Requires `viem` as a peer dependency (`npm install viem`).
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* import { createX402Client, createEvmKeypairWallet } from '@dexterai/x402/client';
|
|
189
|
+
*
|
|
190
|
+
* // From hex private key (with or without 0x prefix)
|
|
191
|
+
* const wallet = await createEvmKeypairWallet('0xabc123...');
|
|
192
|
+
*
|
|
193
|
+
* const client = createX402Client({
|
|
194
|
+
* wallets: { evm: wallet },
|
|
195
|
+
* });
|
|
196
|
+
*
|
|
197
|
+
* const response = await client.fetch('https://api.example.com/protected');
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Create an EVM wallet from a private key
|
|
203
|
+
*
|
|
204
|
+
* Uses viem's `privateKeyToAccount` for EIP-712 typed data signing,
|
|
205
|
+
* which is chain-agnostic -- works for Base, Ethereum, Arbitrum, and
|
|
206
|
+
* any EVM chain without hardcoding a specific network.
|
|
207
|
+
*
|
|
208
|
+
* This function is async because viem is loaded via dynamic `import()`
|
|
209
|
+
* to ensure compatibility with both ESM and CJS consumers.
|
|
210
|
+
*
|
|
211
|
+
* @param privateKey - Hex-encoded private key (with or without 0x prefix)
|
|
212
|
+
* @returns Wallet interface compatible with createX402Client's `wallets.evm`
|
|
213
|
+
* @throws If viem is not installed or the private key is invalid
|
|
214
|
+
*
|
|
215
|
+
* @example From environment variable
|
|
216
|
+
* ```typescript
|
|
217
|
+
* const wallet = await createEvmKeypairWallet(process.env.BASE_PRIVATE_KEY!);
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* @example With createX402Client
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const client = createX402Client({
|
|
223
|
+
* wallets: {
|
|
224
|
+
* solana: createKeypairWallet(process.env.SOLANA_KEY!),
|
|
225
|
+
* evm: await createEvmKeypairWallet(process.env.BASE_KEY!),
|
|
226
|
+
* },
|
|
227
|
+
* });
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @example With wrapFetch (automatic -- you don't need this directly)
|
|
231
|
+
* ```typescript
|
|
232
|
+
* const x402Fetch = wrapFetch(fetch, {
|
|
233
|
+
* evmPrivateKey: process.env.BASE_PRIVATE_KEY!,
|
|
234
|
+
* });
|
|
235
|
+
* // wrapFetch calls createEvmKeypairWallet internally
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
declare function createEvmKeypairWallet(privateKey: string): Promise<EvmWallet>;
|
|
239
|
+
/**
|
|
240
|
+
* Check if an object is a wallet created by createEvmKeypairWallet
|
|
241
|
+
*
|
|
242
|
+
* Note: This also returns true for any valid EvmWallet -- use `isEvmWallet`
|
|
243
|
+
* from `@dexterai/x402/adapters` for the general check.
|
|
244
|
+
*/
|
|
245
|
+
declare function isEvmKeypairWallet(wallet: unknown): wallet is EvmWallet;
|
|
246
|
+
|
|
247
|
+
export { AccessPassClientConfig, type KeypairWallet, type WrapFetchOptions, createEvmKeypairWallet, createKeypairWallet, isEvmKeypairWallet, isKeypairWallet, wrapFetch };
|
package/dist/client/index.js
CHANGED
|
@@ -1015,6 +1015,31 @@ function isKeypairWallet(wallet) {
|
|
|
1015
1015
|
return "keypair" in w && w.keypair instanceof Keypair && "publicKey" in w && "signTransaction" in w;
|
|
1016
1016
|
}
|
|
1017
1017
|
|
|
1018
|
+
// src/client/evm-wallet.ts
|
|
1019
|
+
async function createEvmKeypairWallet(privateKey) {
|
|
1020
|
+
let privateKeyToAccount;
|
|
1021
|
+
try {
|
|
1022
|
+
const viemAccountsPath = "viem/accounts";
|
|
1023
|
+
const viemAccounts = await import(viemAccountsPath);
|
|
1024
|
+
privateKeyToAccount = viemAccounts.privateKeyToAccount;
|
|
1025
|
+
} catch {
|
|
1026
|
+
throw new Error(
|
|
1027
|
+
"EVM wallet support requires viem as a peer dependency. Install with: npm install viem"
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
const normalizedKey = privateKey.startsWith("0x") ? privateKey : `0x${privateKey}`;
|
|
1031
|
+
const account = privateKeyToAccount(normalizedKey);
|
|
1032
|
+
return {
|
|
1033
|
+
address: account.address,
|
|
1034
|
+
signTypedData: (params) => account.signTypedData(params)
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
function isEvmKeypairWallet(wallet) {
|
|
1038
|
+
if (!wallet || typeof wallet !== "object") return false;
|
|
1039
|
+
const w = wallet;
|
|
1040
|
+
return "address" in w && typeof w.address === "string" && w.address.startsWith("0x") && "signTypedData" in w && typeof w.signTypedData === "function";
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1018
1043
|
// src/client/wrap-fetch.ts
|
|
1019
1044
|
function wrapFetch(fetchImpl, options) {
|
|
1020
1045
|
const {
|
|
@@ -1034,8 +1059,13 @@ function wrapFetch(fetchImpl, options) {
|
|
|
1034
1059
|
if (walletPrivateKey) {
|
|
1035
1060
|
wallets.solana = createKeypairWallet(walletPrivateKey);
|
|
1036
1061
|
}
|
|
1062
|
+
let evmReady = null;
|
|
1037
1063
|
if (evmPrivateKey) {
|
|
1038
|
-
|
|
1064
|
+
evmReady = createEvmKeypairWallet(evmPrivateKey).then((w) => {
|
|
1065
|
+
wallets.evm = w;
|
|
1066
|
+
}).catch((e) => {
|
|
1067
|
+
console.warn(`[x402] ${e.message}`);
|
|
1068
|
+
});
|
|
1039
1069
|
}
|
|
1040
1070
|
const clientConfig = {
|
|
1041
1071
|
wallets,
|
|
@@ -1047,7 +1077,14 @@ function wrapFetch(fetchImpl, options) {
|
|
|
1047
1077
|
accessPass
|
|
1048
1078
|
};
|
|
1049
1079
|
const client = createX402Client(clientConfig);
|
|
1050
|
-
|
|
1080
|
+
const clientFetch = client.fetch.bind(client);
|
|
1081
|
+
if (evmReady) {
|
|
1082
|
+
return (async (input, init) => {
|
|
1083
|
+
await evmReady;
|
|
1084
|
+
return clientFetch(input, init);
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
return clientFetch;
|
|
1051
1088
|
}
|
|
1052
1089
|
export {
|
|
1053
1090
|
BASE_MAINNET,
|
|
@@ -1056,9 +1093,11 @@ export {
|
|
|
1056
1093
|
USDC_MINT,
|
|
1057
1094
|
X402Error,
|
|
1058
1095
|
createEvmAdapter,
|
|
1096
|
+
createEvmKeypairWallet,
|
|
1059
1097
|
createKeypairWallet,
|
|
1060
1098
|
createSolanaAdapter,
|
|
1061
1099
|
createX402Client,
|
|
1100
|
+
isEvmKeypairWallet,
|
|
1062
1101
|
isKeypairWallet,
|
|
1063
1102
|
wrapFetch
|
|
1064
1103
|
};
|