@dexterai/x402 1.6.2 → 1.6.4
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 +33 -1
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +70 -2
- package/dist/client/index.d.ts +70 -2
- package/dist/client/index.js +38 -2
- package/dist/client/index.js.map +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.cjs +30 -5
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +30 -5
- package/dist/server/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/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js.map +1 -1
- 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,71 @@ 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 = 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
|
+
* @param privateKey - Hex-encoded private key (with or without 0x prefix)
|
|
209
|
+
* @returns Wallet interface compatible with createX402Client's `wallets.evm`
|
|
210
|
+
* @throws If viem is not installed or the private key is invalid
|
|
211
|
+
*
|
|
212
|
+
* @example From environment variable
|
|
213
|
+
* ```typescript
|
|
214
|
+
* const wallet = createEvmKeypairWallet(process.env.BASE_PRIVATE_KEY!);
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* @example With createX402Client
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const client = createX402Client({
|
|
220
|
+
* wallets: {
|
|
221
|
+
* solana: createKeypairWallet(process.env.SOLANA_KEY!),
|
|
222
|
+
* evm: createEvmKeypairWallet(process.env.BASE_KEY!),
|
|
223
|
+
* },
|
|
224
|
+
* });
|
|
225
|
+
* ```
|
|
226
|
+
*
|
|
227
|
+
* @example With wrapFetch (automatic -- you don't need this directly)
|
|
228
|
+
* ```typescript
|
|
229
|
+
* const x402Fetch = wrapFetch(fetch, {
|
|
230
|
+
* evmPrivateKey: process.env.BASE_PRIVATE_KEY!,
|
|
231
|
+
* });
|
|
232
|
+
* // wrapFetch calls createEvmKeypairWallet internally
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare function createEvmKeypairWallet(privateKey: string): EvmWallet;
|
|
236
|
+
/**
|
|
237
|
+
* Check if an object is a wallet created by createEvmKeypairWallet
|
|
238
|
+
*
|
|
239
|
+
* Note: This also returns true for any valid EvmWallet -- use `isEvmWallet`
|
|
240
|
+
* from `@dexterai/x402/adapters` for the general check.
|
|
241
|
+
*/
|
|
242
|
+
declare function isEvmKeypairWallet(wallet: unknown): wallet is EvmWallet;
|
|
243
|
+
|
|
244
|
+
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,71 @@ 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 = 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
|
+
* @param privateKey - Hex-encoded private key (with or without 0x prefix)
|
|
209
|
+
* @returns Wallet interface compatible with createX402Client's `wallets.evm`
|
|
210
|
+
* @throws If viem is not installed or the private key is invalid
|
|
211
|
+
*
|
|
212
|
+
* @example From environment variable
|
|
213
|
+
* ```typescript
|
|
214
|
+
* const wallet = createEvmKeypairWallet(process.env.BASE_PRIVATE_KEY!);
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* @example With createX402Client
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const client = createX402Client({
|
|
220
|
+
* wallets: {
|
|
221
|
+
* solana: createKeypairWallet(process.env.SOLANA_KEY!),
|
|
222
|
+
* evm: createEvmKeypairWallet(process.env.BASE_KEY!),
|
|
223
|
+
* },
|
|
224
|
+
* });
|
|
225
|
+
* ```
|
|
226
|
+
*
|
|
227
|
+
* @example With wrapFetch (automatic -- you don't need this directly)
|
|
228
|
+
* ```typescript
|
|
229
|
+
* const x402Fetch = wrapFetch(fetch, {
|
|
230
|
+
* evmPrivateKey: process.env.BASE_PRIVATE_KEY!,
|
|
231
|
+
* });
|
|
232
|
+
* // wrapFetch calls createEvmKeypairWallet internally
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare function createEvmKeypairWallet(privateKey: string): EvmWallet;
|
|
236
|
+
/**
|
|
237
|
+
* Check if an object is a wallet created by createEvmKeypairWallet
|
|
238
|
+
*
|
|
239
|
+
* Note: This also returns true for any valid EvmWallet -- use `isEvmWallet`
|
|
240
|
+
* from `@dexterai/x402/adapters` for the general check.
|
|
241
|
+
*/
|
|
242
|
+
declare function isEvmKeypairWallet(wallet: unknown): wallet is EvmWallet;
|
|
243
|
+
|
|
244
|
+
export { AccessPassClientConfig, type KeypairWallet, type WrapFetchOptions, createEvmKeypairWallet, createKeypairWallet, isEvmKeypairWallet, isKeypairWallet, wrapFetch };
|
package/dist/client/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
2
8
|
var __esm = (fn, res) => function __init() {
|
|
3
9
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
4
10
|
};
|
|
5
|
-
var __commonJS = (cb, mod) => function
|
|
11
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
6
12
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
7
13
|
};
|
|
8
14
|
|
|
@@ -1015,6 +1021,30 @@ function isKeypairWallet(wallet) {
|
|
|
1015
1021
|
return "keypair" in w && w.keypair instanceof Keypair && "publicKey" in w && "signTransaction" in w;
|
|
1016
1022
|
}
|
|
1017
1023
|
|
|
1024
|
+
// src/client/evm-wallet.ts
|
|
1025
|
+
function createEvmKeypairWallet(privateKey) {
|
|
1026
|
+
let privateKeyToAccount;
|
|
1027
|
+
try {
|
|
1028
|
+
const viemAccounts = __require("viem/accounts");
|
|
1029
|
+
privateKeyToAccount = viemAccounts.privateKeyToAccount;
|
|
1030
|
+
} catch {
|
|
1031
|
+
throw new Error(
|
|
1032
|
+
"EVM wallet support requires viem as a peer dependency. Install with: npm install viem"
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
const normalizedKey = privateKey.startsWith("0x") ? privateKey : `0x${privateKey}`;
|
|
1036
|
+
const account = privateKeyToAccount(normalizedKey);
|
|
1037
|
+
return {
|
|
1038
|
+
address: account.address,
|
|
1039
|
+
signTypedData: (params) => account.signTypedData(params)
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
function isEvmKeypairWallet(wallet) {
|
|
1043
|
+
if (!wallet || typeof wallet !== "object") return false;
|
|
1044
|
+
const w = wallet;
|
|
1045
|
+
return "address" in w && typeof w.address === "string" && w.address.startsWith("0x") && "signTypedData" in w && typeof w.signTypedData === "function";
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1018
1048
|
// src/client/wrap-fetch.ts
|
|
1019
1049
|
function wrapFetch(fetchImpl, options) {
|
|
1020
1050
|
const {
|
|
@@ -1035,7 +1065,11 @@ function wrapFetch(fetchImpl, options) {
|
|
|
1035
1065
|
wallets.solana = createKeypairWallet(walletPrivateKey);
|
|
1036
1066
|
}
|
|
1037
1067
|
if (evmPrivateKey) {
|
|
1038
|
-
|
|
1068
|
+
try {
|
|
1069
|
+
wallets.evm = createEvmKeypairWallet(evmPrivateKey);
|
|
1070
|
+
} catch (e) {
|
|
1071
|
+
console.warn(`[x402] ${e.message}`);
|
|
1072
|
+
}
|
|
1039
1073
|
}
|
|
1040
1074
|
const clientConfig = {
|
|
1041
1075
|
wallets,
|
|
@@ -1056,9 +1090,11 @@ export {
|
|
|
1056
1090
|
USDC_MINT,
|
|
1057
1091
|
X402Error,
|
|
1058
1092
|
createEvmAdapter,
|
|
1093
|
+
createEvmKeypairWallet,
|
|
1059
1094
|
createKeypairWallet,
|
|
1060
1095
|
createSolanaAdapter,
|
|
1061
1096
|
createX402Client,
|
|
1097
|
+
isEvmKeypairWallet,
|
|
1062
1098
|
isKeypairWallet,
|
|
1063
1099
|
wrapFetch
|
|
1064
1100
|
};
|