@dexterai/x402 1.0.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/LICENSE +22 -0
- package/README.md +254 -0
- package/assets/dexter-wordmark.svg +30 -0
- package/dist/adapters/index.cjs +481 -0
- package/dist/adapters/index.cjs.map +1 -0
- package/dist/adapters/index.d.cts +15 -0
- package/dist/adapters/index.d.ts +15 -0
- package/dist/adapters/index.js +473 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/client/index.cjs +602 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +4 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/index.js +583 -0
- package/dist/client/index.js.map +1 -0
- package/dist/evm-B4mhmeNZ.d.cts +120 -0
- package/dist/evm-av6iEAW7.d.ts +120 -0
- package/dist/react/index.cjs +827 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +108 -0
- package/dist/react/index.d.ts +108 -0
- package/dist/react/index.js +814 -0
- package/dist/react/index.js.map +1 -0
- package/dist/server/index.cjs +295 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +191 -0
- package/dist/server/index.d.ts +191 -0
- package/dist/server/index.js +262 -0
- package/dist/server/index.js.map +1 -0
- package/dist/types-DkTxHOns.d.cts +119 -0
- package/dist/types-DkTxHOns.d.ts +119 -0
- package/dist/types-uljmYAuY.d.ts +118 -0
- package/dist/types-vWD8uj2B.d.cts +118 -0
- package/dist/x402-client-BSWNMJbm.d.ts +84 -0
- package/dist/x402-client-DUipGiRr.d.cts +84 -0
- package/package.json +99 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { C as ChainAdapter, W as WalletSet } from './types-vWD8uj2B.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* x402 v2 Client
|
|
5
|
+
*
|
|
6
|
+
* Chain-agnostic client for x402 v2 payments.
|
|
7
|
+
* Automatically detects 402 responses, finds a matching payment option,
|
|
8
|
+
* builds the transaction with the appropriate chain adapter, and retries.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { createX402Client } from '@dexterai/x402/client';
|
|
13
|
+
* import { createSolanaAdapter, createEvmAdapter } from '@dexterai/x402/adapters';
|
|
14
|
+
*
|
|
15
|
+
* const client = createX402Client({
|
|
16
|
+
* adapters: [createSolanaAdapter(), createEvmAdapter()],
|
|
17
|
+
* wallets: {
|
|
18
|
+
* solana: solanaWallet,
|
|
19
|
+
* evm: evmWallet,
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* const response = await client.fetch(url);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Client configuration
|
|
29
|
+
*/
|
|
30
|
+
interface X402ClientConfig {
|
|
31
|
+
/**
|
|
32
|
+
* Chain adapters to use for building transactions.
|
|
33
|
+
* If not provided, uses Solana and EVM adapters by default.
|
|
34
|
+
*/
|
|
35
|
+
adapters?: ChainAdapter[];
|
|
36
|
+
/**
|
|
37
|
+
* Wallets for each chain type.
|
|
38
|
+
* Can also pass a single wallet for backwards compatibility.
|
|
39
|
+
*/
|
|
40
|
+
wallets?: WalletSet;
|
|
41
|
+
/**
|
|
42
|
+
* Legacy: Single wallet (Solana).
|
|
43
|
+
* Use `wallets` for multi-chain support.
|
|
44
|
+
*/
|
|
45
|
+
wallet?: unknown;
|
|
46
|
+
/**
|
|
47
|
+
* Preferred network to use when multiple options are available.
|
|
48
|
+
* CAIP-2 format (e.g., 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp', 'eip155:8453')
|
|
49
|
+
*/
|
|
50
|
+
preferredNetwork?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Custom RPC URLs by network
|
|
53
|
+
*/
|
|
54
|
+
rpcUrls?: Record<string, string>;
|
|
55
|
+
/**
|
|
56
|
+
* Maximum payment amount allowed (in atomic units).
|
|
57
|
+
* Rejects payments exceeding this amount.
|
|
58
|
+
*/
|
|
59
|
+
maxAmountAtomic?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Custom fetch implementation
|
|
62
|
+
*/
|
|
63
|
+
fetch?: typeof globalThis.fetch;
|
|
64
|
+
/**
|
|
65
|
+
* Enable verbose logging
|
|
66
|
+
*/
|
|
67
|
+
verbose?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* x402 Client interface
|
|
71
|
+
*/
|
|
72
|
+
interface X402Client {
|
|
73
|
+
/**
|
|
74
|
+
* Fetch with automatic x402 payment handling.
|
|
75
|
+
* If the server returns 402, handles payment automatically and retries.
|
|
76
|
+
*/
|
|
77
|
+
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create an x402 v2 client
|
|
81
|
+
*/
|
|
82
|
+
declare function createX402Client(config: X402ClientConfig): X402Client;
|
|
83
|
+
|
|
84
|
+
export { type X402ClientConfig as X, type X402Client as a, createX402Client as c };
|
package/package.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dexterai/x402",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Chain-agnostic x402 v2 SDK for Solana, Base, and EVM payments",
|
|
5
|
+
"author": "Dexter",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./client": {
|
|
10
|
+
"types": "./dist/client/index.d.ts",
|
|
11
|
+
"import": "./dist/client/index.js",
|
|
12
|
+
"require": "./dist/client/index.cjs"
|
|
13
|
+
},
|
|
14
|
+
"./server": {
|
|
15
|
+
"types": "./dist/server/index.d.ts",
|
|
16
|
+
"import": "./dist/server/index.js",
|
|
17
|
+
"require": "./dist/server/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./react": {
|
|
20
|
+
"types": "./dist/react/index.d.ts",
|
|
21
|
+
"import": "./dist/react/index.js",
|
|
22
|
+
"require": "./dist/react/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./adapters": {
|
|
25
|
+
"types": "./dist/adapters/index.d.ts",
|
|
26
|
+
"import": "./dist/adapters/index.js",
|
|
27
|
+
"require": "./dist/adapters/index.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"assets"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup",
|
|
38
|
+
"dev": "tsup --watch",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"test:watch": "vitest",
|
|
42
|
+
"prepublishOnly": "npm run build",
|
|
43
|
+
"release": "npm version patch && npm publish --access public",
|
|
44
|
+
"release:minor": "npm version minor && npm publish --access public",
|
|
45
|
+
"release:major": "npm version major && npm publish --access public"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@solana/spl-token": "^0.4.9",
|
|
49
|
+
"@solana/web3.js": "^1.98.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/node": "^22.10.0",
|
|
53
|
+
"@types/react": "^18.0.0",
|
|
54
|
+
"bs58": "^6.0.0",
|
|
55
|
+
"ethers": "^6.13.0",
|
|
56
|
+
"react": "^18.0.0",
|
|
57
|
+
"tsup": "^8.3.5",
|
|
58
|
+
"typescript": "^5.7.2",
|
|
59
|
+
"vitest": "^2.1.8"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@solana/wallet-adapter-base": "^0.9.0",
|
|
63
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
64
|
+
"viem": "^2.0.0"
|
|
65
|
+
},
|
|
66
|
+
"peerDependenciesMeta": {
|
|
67
|
+
"@solana/wallet-adapter-base": {
|
|
68
|
+
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"react": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"viem": {
|
|
74
|
+
"optional": true
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"engines": {
|
|
78
|
+
"node": ">=18"
|
|
79
|
+
},
|
|
80
|
+
"keywords": [
|
|
81
|
+
"x402",
|
|
82
|
+
"solana",
|
|
83
|
+
"base",
|
|
84
|
+
"evm",
|
|
85
|
+
"ethereum",
|
|
86
|
+
"payments",
|
|
87
|
+
"dexter",
|
|
88
|
+
"web3",
|
|
89
|
+
"crypto"
|
|
90
|
+
],
|
|
91
|
+
"repository": {
|
|
92
|
+
"type": "git",
|
|
93
|
+
"url": "https://github.com/Dexter-DAO/x402-sdk"
|
|
94
|
+
},
|
|
95
|
+
"homepage": "https://dexter.cash/sdk",
|
|
96
|
+
"bugs": {
|
|
97
|
+
"url": "https://github.com/Dexter-DAO/x402-sdk/issues"
|
|
98
|
+
}
|
|
99
|
+
}
|