uvd-x402-sdk 2.15.2 → 2.16.2
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 +247 -6
- package/dist/adapters/index.d.mts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js +82 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +82 -1
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/backend/index.d.mts +1 -1
- package/dist/backend/index.d.ts +1 -1
- package/dist/backend/index.js +82 -1
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/index.mjs +82 -1
- package/dist/backend/index.mjs.map +1 -1
- package/dist/{index-Cwi_VM05.d.ts → index-B2cQzyKa.d.ts} +10 -2
- package/dist/{index-BYIugZlE.d.mts → index-BE5cH7oS.d.mts} +48 -5
- package/dist/{index-BYIugZlE.d.ts → index-BE5cH7oS.d.ts} +48 -5
- package/dist/{index-D3PO3jLW.d.mts → index-oE4dj05k.d.mts} +10 -2
- package/dist/index.d.mts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +111 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +110 -3
- package/dist/index.mjs.map +1 -1
- package/dist/providers/algorand/index.d.mts +1 -1
- package/dist/providers/algorand/index.d.ts +1 -1
- package/dist/providers/algorand/index.js +95 -2
- package/dist/providers/algorand/index.js.map +1 -1
- package/dist/providers/algorand/index.mjs +95 -2
- package/dist/providers/algorand/index.mjs.map +1 -1
- package/dist/providers/evm/index.d.mts +1 -1
- package/dist/providers/evm/index.d.ts +1 -1
- package/dist/providers/evm/index.js +82 -1
- package/dist/providers/evm/index.js.map +1 -1
- package/dist/providers/evm/index.mjs +82 -1
- package/dist/providers/evm/index.mjs.map +1 -1
- package/dist/providers/near/index.d.mts +1 -1
- package/dist/providers/near/index.d.ts +1 -1
- package/dist/providers/near/index.js +82 -1
- package/dist/providers/near/index.js.map +1 -1
- package/dist/providers/near/index.mjs +82 -1
- package/dist/providers/near/index.mjs.map +1 -1
- package/dist/providers/solana/index.d.mts +1 -1
- package/dist/providers/solana/index.d.ts +1 -1
- package/dist/providers/solana/index.js +82 -1
- package/dist/providers/solana/index.js.map +1 -1
- package/dist/providers/solana/index.mjs +82 -1
- package/dist/providers/solana/index.mjs.map +1 -1
- package/dist/providers/stellar/index.d.mts +1 -1
- package/dist/providers/stellar/index.d.ts +1 -1
- package/dist/providers/stellar/index.js +82 -1
- package/dist/providers/stellar/index.js.map +1 -1
- package/dist/providers/stellar/index.mjs +82 -1
- package/dist/providers/stellar/index.mjs.map +1 -1
- package/dist/providers/sui/index.d.mts +105 -0
- package/dist/providers/sui/index.d.ts +105 -0
- package/dist/providers/sui/index.js +1027 -0
- package/dist/providers/sui/index.js.map +1 -0
- package/dist/providers/sui/index.mjs +1022 -0
- package/dist/providers/sui/index.mjs.map +1 -0
- package/dist/react/index.d.mts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +82 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +82 -1
- package/dist/react/index.mjs.map +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +82 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +82 -1
- package/dist/utils/index.mjs.map +1 -1
- package/package.json +15 -4
- package/src/chains/index.ts +98 -0
- package/src/facilitator.ts +18 -0
- package/src/index.ts +20 -1
- package/src/providers/sui/index.ts +431 -0
- package/src/types/index.ts +55 -3
|
@@ -0,0 +1,1022 @@
|
|
|
1
|
+
// src/types/index.ts
|
|
2
|
+
var CAIP2_IDENTIFIERS = {
|
|
3
|
+
// EVM chains
|
|
4
|
+
base: "eip155:8453",
|
|
5
|
+
ethereum: "eip155:1",
|
|
6
|
+
polygon: "eip155:137",
|
|
7
|
+
arbitrum: "eip155:42161",
|
|
8
|
+
optimism: "eip155:10",
|
|
9
|
+
avalanche: "eip155:43114",
|
|
10
|
+
celo: "eip155:42220",
|
|
11
|
+
hyperevm: "eip155:999",
|
|
12
|
+
unichain: "eip155:130",
|
|
13
|
+
monad: "eip155:143",
|
|
14
|
+
// SVM chains
|
|
15
|
+
solana: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
16
|
+
fogo: "svm:fogo",
|
|
17
|
+
// Stellar
|
|
18
|
+
stellar: "stellar:pubnet",
|
|
19
|
+
// NEAR
|
|
20
|
+
near: "near:mainnet",
|
|
21
|
+
// Algorand
|
|
22
|
+
algorand: "algorand:mainnet",
|
|
23
|
+
"algorand-testnet": "algorand:testnet",
|
|
24
|
+
// Sui
|
|
25
|
+
sui: "sui:mainnet",
|
|
26
|
+
"sui-testnet": "sui:testnet"
|
|
27
|
+
};
|
|
28
|
+
Object.fromEntries(
|
|
29
|
+
Object.entries(CAIP2_IDENTIFIERS).map(([k, v]) => [v, k])
|
|
30
|
+
);
|
|
31
|
+
var X402Error = class _X402Error extends Error {
|
|
32
|
+
code;
|
|
33
|
+
details;
|
|
34
|
+
constructor(message, code, details) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = "X402Error";
|
|
37
|
+
this.code = code;
|
|
38
|
+
this.details = details;
|
|
39
|
+
if (Error.captureStackTrace) {
|
|
40
|
+
Error.captureStackTrace(this, _X402Error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/chains/index.ts
|
|
46
|
+
var DEFAULT_FACILITATOR_URL = "https://facilitator.ultravioletadao.xyz";
|
|
47
|
+
var SUPPORTED_CHAINS = {
|
|
48
|
+
// ============================================================================
|
|
49
|
+
// EVM CHAINS (10 networks)
|
|
50
|
+
// ============================================================================
|
|
51
|
+
base: {
|
|
52
|
+
chainId: 8453,
|
|
53
|
+
chainIdHex: "0x2105",
|
|
54
|
+
name: "base",
|
|
55
|
+
displayName: "Base",
|
|
56
|
+
networkType: "evm",
|
|
57
|
+
rpcUrl: "https://mainnet.base.org",
|
|
58
|
+
explorerUrl: "https://basescan.org",
|
|
59
|
+
nativeCurrency: {
|
|
60
|
+
name: "Ethereum",
|
|
61
|
+
symbol: "ETH",
|
|
62
|
+
decimals: 18
|
|
63
|
+
},
|
|
64
|
+
usdc: {
|
|
65
|
+
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
66
|
+
decimals: 6,
|
|
67
|
+
name: "USD Coin",
|
|
68
|
+
version: "2"
|
|
69
|
+
},
|
|
70
|
+
tokens: {
|
|
71
|
+
usdc: {
|
|
72
|
+
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
73
|
+
decimals: 6,
|
|
74
|
+
name: "USD Coin",
|
|
75
|
+
version: "2"
|
|
76
|
+
},
|
|
77
|
+
eurc: {
|
|
78
|
+
address: "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42",
|
|
79
|
+
decimals: 6,
|
|
80
|
+
name: "EURC",
|
|
81
|
+
version: "2"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
x402: {
|
|
85
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
86
|
+
enabled: true
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
avalanche: {
|
|
90
|
+
chainId: 43114,
|
|
91
|
+
chainIdHex: "0xa86a",
|
|
92
|
+
name: "avalanche",
|
|
93
|
+
displayName: "Avalanche C-Chain",
|
|
94
|
+
networkType: "evm",
|
|
95
|
+
rpcUrl: "https://avalanche-c-chain-rpc.publicnode.com",
|
|
96
|
+
explorerUrl: "https://snowtrace.io",
|
|
97
|
+
nativeCurrency: {
|
|
98
|
+
name: "Avalanche",
|
|
99
|
+
symbol: "AVAX",
|
|
100
|
+
decimals: 18
|
|
101
|
+
},
|
|
102
|
+
usdc: {
|
|
103
|
+
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
104
|
+
decimals: 6,
|
|
105
|
+
name: "USD Coin",
|
|
106
|
+
version: "2"
|
|
107
|
+
},
|
|
108
|
+
tokens: {
|
|
109
|
+
usdc: {
|
|
110
|
+
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
111
|
+
decimals: 6,
|
|
112
|
+
name: "USD Coin",
|
|
113
|
+
version: "2"
|
|
114
|
+
},
|
|
115
|
+
eurc: {
|
|
116
|
+
address: "0xC891EB4cbdEFf6e073e859e987815Ed1505c2ACD",
|
|
117
|
+
decimals: 6,
|
|
118
|
+
name: "EURC",
|
|
119
|
+
version: "2"
|
|
120
|
+
},
|
|
121
|
+
ausd: {
|
|
122
|
+
address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
|
|
123
|
+
decimals: 6,
|
|
124
|
+
name: "Agora Dollar",
|
|
125
|
+
version: "1"
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
x402: {
|
|
129
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
130
|
+
enabled: true
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
ethereum: {
|
|
134
|
+
chainId: 1,
|
|
135
|
+
chainIdHex: "0x1",
|
|
136
|
+
name: "ethereum",
|
|
137
|
+
displayName: "Ethereum",
|
|
138
|
+
networkType: "evm",
|
|
139
|
+
rpcUrl: "https://eth.llamarpc.com",
|
|
140
|
+
explorerUrl: "https://etherscan.io",
|
|
141
|
+
nativeCurrency: {
|
|
142
|
+
name: "Ethereum",
|
|
143
|
+
symbol: "ETH",
|
|
144
|
+
decimals: 18
|
|
145
|
+
},
|
|
146
|
+
usdc: {
|
|
147
|
+
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
148
|
+
decimals: 6,
|
|
149
|
+
name: "USD Coin",
|
|
150
|
+
version: "2"
|
|
151
|
+
},
|
|
152
|
+
tokens: {
|
|
153
|
+
usdc: {
|
|
154
|
+
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
155
|
+
decimals: 6,
|
|
156
|
+
name: "USD Coin",
|
|
157
|
+
version: "2"
|
|
158
|
+
},
|
|
159
|
+
eurc: {
|
|
160
|
+
address: "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
|
|
161
|
+
decimals: 6,
|
|
162
|
+
name: "Euro Coin",
|
|
163
|
+
version: "2"
|
|
164
|
+
},
|
|
165
|
+
ausd: {
|
|
166
|
+
address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
|
|
167
|
+
decimals: 6,
|
|
168
|
+
name: "Agora Dollar",
|
|
169
|
+
version: "1"
|
|
170
|
+
},
|
|
171
|
+
pyusd: {
|
|
172
|
+
address: "0x6c3ea9036406852006290770BEdFcAbA0e23A0e8",
|
|
173
|
+
decimals: 6,
|
|
174
|
+
name: "PayPal USD",
|
|
175
|
+
version: "1"
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
x402: {
|
|
179
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
180
|
+
enabled: true
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
polygon: {
|
|
184
|
+
chainId: 137,
|
|
185
|
+
chainIdHex: "0x89",
|
|
186
|
+
name: "polygon",
|
|
187
|
+
displayName: "Polygon",
|
|
188
|
+
networkType: "evm",
|
|
189
|
+
rpcUrl: "https://polygon-rpc.com",
|
|
190
|
+
explorerUrl: "https://polygonscan.com",
|
|
191
|
+
nativeCurrency: {
|
|
192
|
+
name: "Polygon",
|
|
193
|
+
symbol: "POL",
|
|
194
|
+
decimals: 18
|
|
195
|
+
},
|
|
196
|
+
usdc: {
|
|
197
|
+
address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
|
|
198
|
+
decimals: 6,
|
|
199
|
+
name: "USD Coin",
|
|
200
|
+
version: "2"
|
|
201
|
+
},
|
|
202
|
+
tokens: {
|
|
203
|
+
usdc: {
|
|
204
|
+
address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
|
|
205
|
+
decimals: 6,
|
|
206
|
+
name: "USD Coin",
|
|
207
|
+
version: "2"
|
|
208
|
+
},
|
|
209
|
+
ausd: {
|
|
210
|
+
address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
|
|
211
|
+
decimals: 6,
|
|
212
|
+
name: "Agora Dollar",
|
|
213
|
+
version: "1"
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
x402: {
|
|
217
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
218
|
+
enabled: true
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
arbitrum: {
|
|
222
|
+
chainId: 42161,
|
|
223
|
+
chainIdHex: "0xa4b1",
|
|
224
|
+
name: "arbitrum",
|
|
225
|
+
displayName: "Arbitrum One",
|
|
226
|
+
networkType: "evm",
|
|
227
|
+
rpcUrl: "https://arb1.arbitrum.io/rpc",
|
|
228
|
+
explorerUrl: "https://arbiscan.io",
|
|
229
|
+
nativeCurrency: {
|
|
230
|
+
name: "Ethereum",
|
|
231
|
+
symbol: "ETH",
|
|
232
|
+
decimals: 18
|
|
233
|
+
},
|
|
234
|
+
usdc: {
|
|
235
|
+
address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
236
|
+
decimals: 6,
|
|
237
|
+
name: "USD Coin",
|
|
238
|
+
version: "2"
|
|
239
|
+
},
|
|
240
|
+
tokens: {
|
|
241
|
+
usdc: {
|
|
242
|
+
address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
243
|
+
decimals: 6,
|
|
244
|
+
name: "USD Coin",
|
|
245
|
+
version: "2"
|
|
246
|
+
},
|
|
247
|
+
ausd: {
|
|
248
|
+
address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
|
|
249
|
+
decimals: 6,
|
|
250
|
+
name: "Agora Dollar",
|
|
251
|
+
version: "1"
|
|
252
|
+
},
|
|
253
|
+
usdt: {
|
|
254
|
+
address: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
|
|
255
|
+
decimals: 6,
|
|
256
|
+
name: "USD\u20AE0",
|
|
257
|
+
version: "1"
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
x402: {
|
|
261
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
262
|
+
enabled: true
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
optimism: {
|
|
266
|
+
chainId: 10,
|
|
267
|
+
chainIdHex: "0xa",
|
|
268
|
+
name: "optimism",
|
|
269
|
+
displayName: "Optimism",
|
|
270
|
+
networkType: "evm",
|
|
271
|
+
rpcUrl: "https://mainnet.optimism.io",
|
|
272
|
+
explorerUrl: "https://optimistic.etherscan.io",
|
|
273
|
+
nativeCurrency: {
|
|
274
|
+
name: "Ethereum",
|
|
275
|
+
symbol: "ETH",
|
|
276
|
+
decimals: 18
|
|
277
|
+
},
|
|
278
|
+
usdc: {
|
|
279
|
+
address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
|
|
280
|
+
decimals: 6,
|
|
281
|
+
name: "USD Coin",
|
|
282
|
+
version: "2"
|
|
283
|
+
},
|
|
284
|
+
tokens: {
|
|
285
|
+
usdc: {
|
|
286
|
+
address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
|
|
287
|
+
decimals: 6,
|
|
288
|
+
name: "USD Coin",
|
|
289
|
+
version: "2"
|
|
290
|
+
},
|
|
291
|
+
usdt: {
|
|
292
|
+
address: "0x01bff41798a0bcf287b996046ca68b395dbc1071",
|
|
293
|
+
decimals: 6,
|
|
294
|
+
name: "USD\u20AE0",
|
|
295
|
+
version: "1"
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
x402: {
|
|
299
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
300
|
+
enabled: true
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
celo: {
|
|
304
|
+
chainId: 42220,
|
|
305
|
+
chainIdHex: "0xa4ec",
|
|
306
|
+
name: "celo",
|
|
307
|
+
displayName: "Celo",
|
|
308
|
+
networkType: "evm",
|
|
309
|
+
rpcUrl: "https://forno.celo.org",
|
|
310
|
+
explorerUrl: "https://celoscan.io",
|
|
311
|
+
nativeCurrency: {
|
|
312
|
+
name: "Celo",
|
|
313
|
+
symbol: "CELO",
|
|
314
|
+
decimals: 18
|
|
315
|
+
},
|
|
316
|
+
usdc: {
|
|
317
|
+
address: "0xcebA9300f2b948710d2653dD7B07f33A8B32118C",
|
|
318
|
+
decimals: 6,
|
|
319
|
+
name: "USDC",
|
|
320
|
+
// Celo uses "USDC" not "USD Coin" for EIP-712
|
|
321
|
+
version: "2"
|
|
322
|
+
},
|
|
323
|
+
tokens: {
|
|
324
|
+
usdc: {
|
|
325
|
+
address: "0xcebA9300f2b948710d2653dD7B07f33A8B32118C",
|
|
326
|
+
decimals: 6,
|
|
327
|
+
name: "USDC",
|
|
328
|
+
// Celo uses "USDC" not "USD Coin" for EIP-712
|
|
329
|
+
version: "2"
|
|
330
|
+
},
|
|
331
|
+
usdt: {
|
|
332
|
+
address: "0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e",
|
|
333
|
+
decimals: 6,
|
|
334
|
+
name: "Tether USD",
|
|
335
|
+
// Celo USDT uses "Tether USD" for EIP-712
|
|
336
|
+
version: "1"
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
x402: {
|
|
340
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
341
|
+
enabled: true
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
hyperevm: {
|
|
345
|
+
chainId: 999,
|
|
346
|
+
chainIdHex: "0x3e7",
|
|
347
|
+
name: "hyperevm",
|
|
348
|
+
displayName: "HyperEVM",
|
|
349
|
+
networkType: "evm",
|
|
350
|
+
rpcUrl: "https://rpc.hyperliquid.xyz/evm",
|
|
351
|
+
explorerUrl: "https://hyperevmscan.io",
|
|
352
|
+
nativeCurrency: {
|
|
353
|
+
name: "Ethereum",
|
|
354
|
+
symbol: "ETH",
|
|
355
|
+
decimals: 18
|
|
356
|
+
},
|
|
357
|
+
usdc: {
|
|
358
|
+
address: "0xb88339CB7199b77E23DB6E890353E22632Ba630f",
|
|
359
|
+
decimals: 6,
|
|
360
|
+
name: "USDC",
|
|
361
|
+
// HyperEVM uses "USDC" not "USD Coin"
|
|
362
|
+
version: "2"
|
|
363
|
+
},
|
|
364
|
+
tokens: {
|
|
365
|
+
usdc: {
|
|
366
|
+
address: "0xb88339CB7199b77E23DB6E890353E22632Ba630f",
|
|
367
|
+
decimals: 6,
|
|
368
|
+
name: "USDC",
|
|
369
|
+
// HyperEVM uses "USDC" not "USD Coin"
|
|
370
|
+
version: "2"
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
x402: {
|
|
374
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
375
|
+
enabled: true
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
unichain: {
|
|
379
|
+
chainId: 130,
|
|
380
|
+
chainIdHex: "0x82",
|
|
381
|
+
name: "unichain",
|
|
382
|
+
displayName: "Unichain",
|
|
383
|
+
networkType: "evm",
|
|
384
|
+
rpcUrl: "https://unichain-rpc.publicnode.com",
|
|
385
|
+
explorerUrl: "https://uniscan.xyz",
|
|
386
|
+
nativeCurrency: {
|
|
387
|
+
name: "Ethereum",
|
|
388
|
+
symbol: "ETH",
|
|
389
|
+
decimals: 18
|
|
390
|
+
},
|
|
391
|
+
usdc: {
|
|
392
|
+
address: "0x078d782b760474a361dda0af3839290b0ef57ad6",
|
|
393
|
+
decimals: 6,
|
|
394
|
+
name: "USDC",
|
|
395
|
+
// Unichain uses "USDC" not "USD Coin"
|
|
396
|
+
version: "2"
|
|
397
|
+
},
|
|
398
|
+
tokens: {
|
|
399
|
+
usdc: {
|
|
400
|
+
address: "0x078d782b760474a361dda0af3839290b0ef57ad6",
|
|
401
|
+
decimals: 6,
|
|
402
|
+
name: "USDC",
|
|
403
|
+
// Unichain uses "USDC" not "USD Coin"
|
|
404
|
+
version: "2"
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
x402: {
|
|
408
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
409
|
+
enabled: true
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
monad: {
|
|
413
|
+
chainId: 143,
|
|
414
|
+
chainIdHex: "0x8f",
|
|
415
|
+
name: "monad",
|
|
416
|
+
displayName: "Monad",
|
|
417
|
+
networkType: "evm",
|
|
418
|
+
rpcUrl: "https://rpc.monad.xyz",
|
|
419
|
+
explorerUrl: "https://monad.socialscan.io",
|
|
420
|
+
nativeCurrency: {
|
|
421
|
+
name: "Monad",
|
|
422
|
+
symbol: "MON",
|
|
423
|
+
decimals: 18
|
|
424
|
+
},
|
|
425
|
+
usdc: {
|
|
426
|
+
address: "0x754704bc059f8c67012fed69bc8a327a5aafb603",
|
|
427
|
+
decimals: 6,
|
|
428
|
+
name: "USDC",
|
|
429
|
+
// Monad uses "USDC" not "USD Coin"
|
|
430
|
+
version: "2"
|
|
431
|
+
},
|
|
432
|
+
tokens: {
|
|
433
|
+
usdc: {
|
|
434
|
+
address: "0x754704bc059f8c67012fed69bc8a327a5aafb603",
|
|
435
|
+
decimals: 6,
|
|
436
|
+
name: "USDC",
|
|
437
|
+
// Monad uses "USDC" not "USD Coin"
|
|
438
|
+
version: "2"
|
|
439
|
+
},
|
|
440
|
+
ausd: {
|
|
441
|
+
address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
|
|
442
|
+
decimals: 6,
|
|
443
|
+
name: "Agora Dollar",
|
|
444
|
+
version: "1"
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
x402: {
|
|
448
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
449
|
+
enabled: true
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
// ============================================================================
|
|
453
|
+
// SVM CHAINS (2 networks) - Solana Virtual Machine
|
|
454
|
+
// ============================================================================
|
|
455
|
+
solana: {
|
|
456
|
+
chainId: 0,
|
|
457
|
+
// Non-EVM
|
|
458
|
+
chainIdHex: "0x0",
|
|
459
|
+
name: "solana",
|
|
460
|
+
displayName: "Solana",
|
|
461
|
+
networkType: "svm",
|
|
462
|
+
rpcUrl: "https://api.mainnet-beta.solana.com",
|
|
463
|
+
explorerUrl: "https://solscan.io",
|
|
464
|
+
nativeCurrency: {
|
|
465
|
+
name: "Solana",
|
|
466
|
+
symbol: "SOL",
|
|
467
|
+
decimals: 9
|
|
468
|
+
},
|
|
469
|
+
usdc: {
|
|
470
|
+
address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
471
|
+
// USDC SPL token mint
|
|
472
|
+
decimals: 6,
|
|
473
|
+
name: "USD Coin",
|
|
474
|
+
version: "1"
|
|
475
|
+
},
|
|
476
|
+
tokens: {
|
|
477
|
+
usdc: {
|
|
478
|
+
address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
479
|
+
// USDC SPL token mint
|
|
480
|
+
decimals: 6,
|
|
481
|
+
name: "USD Coin",
|
|
482
|
+
version: "1"
|
|
483
|
+
},
|
|
484
|
+
ausd: {
|
|
485
|
+
address: "AUSD1jCcCyPLybk1YnvPWsHQSrZ46dxwoMniN4N2UEB9",
|
|
486
|
+
// AUSD Token2022 mint
|
|
487
|
+
decimals: 6,
|
|
488
|
+
name: "Agora Dollar",
|
|
489
|
+
version: "1"
|
|
490
|
+
}
|
|
491
|
+
},
|
|
492
|
+
x402: {
|
|
493
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
494
|
+
enabled: true
|
|
495
|
+
}
|
|
496
|
+
},
|
|
497
|
+
fogo: {
|
|
498
|
+
chainId: 0,
|
|
499
|
+
// Non-EVM (SVM)
|
|
500
|
+
chainIdHex: "0x0",
|
|
501
|
+
name: "fogo",
|
|
502
|
+
displayName: "Fogo",
|
|
503
|
+
networkType: "svm",
|
|
504
|
+
rpcUrl: "https://rpc.fogo.nightly.app/",
|
|
505
|
+
explorerUrl: "https://explorer.fogo.nightly.app",
|
|
506
|
+
nativeCurrency: {
|
|
507
|
+
name: "Fogo",
|
|
508
|
+
symbol: "FOGO",
|
|
509
|
+
decimals: 9
|
|
510
|
+
},
|
|
511
|
+
usdc: {
|
|
512
|
+
address: "uSd2czE61Evaf76RNbq4KPpXnkiL3irdzgLFUMe3NoG",
|
|
513
|
+
// Fogo USDC mint
|
|
514
|
+
decimals: 6,
|
|
515
|
+
name: "USDC",
|
|
516
|
+
version: "1"
|
|
517
|
+
},
|
|
518
|
+
x402: {
|
|
519
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
520
|
+
enabled: true
|
|
521
|
+
}
|
|
522
|
+
},
|
|
523
|
+
// ============================================================================
|
|
524
|
+
// STELLAR (1 network)
|
|
525
|
+
// ============================================================================
|
|
526
|
+
stellar: {
|
|
527
|
+
chainId: 0,
|
|
528
|
+
// Non-EVM
|
|
529
|
+
chainIdHex: "0x0",
|
|
530
|
+
name: "stellar",
|
|
531
|
+
displayName: "Stellar",
|
|
532
|
+
networkType: "stellar",
|
|
533
|
+
rpcUrl: "https://horizon.stellar.org",
|
|
534
|
+
explorerUrl: "https://stellar.expert/explorer/public",
|
|
535
|
+
nativeCurrency: {
|
|
536
|
+
name: "Lumens",
|
|
537
|
+
symbol: "XLM",
|
|
538
|
+
decimals: 7
|
|
539
|
+
// Stellar uses 7 decimals (stroops)
|
|
540
|
+
},
|
|
541
|
+
usdc: {
|
|
542
|
+
address: "CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75",
|
|
543
|
+
// Soroban Asset Contract
|
|
544
|
+
decimals: 7,
|
|
545
|
+
// Stellar USDC uses 7 decimals
|
|
546
|
+
name: "USDC",
|
|
547
|
+
version: "1"
|
|
548
|
+
},
|
|
549
|
+
x402: {
|
|
550
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
551
|
+
enabled: true
|
|
552
|
+
}
|
|
553
|
+
},
|
|
554
|
+
// ============================================================================
|
|
555
|
+
// NEAR (1 network) - Uses NEP-366 meta-transactions
|
|
556
|
+
// ============================================================================
|
|
557
|
+
near: {
|
|
558
|
+
chainId: 0,
|
|
559
|
+
// Non-EVM
|
|
560
|
+
chainIdHex: "0x0",
|
|
561
|
+
name: "near",
|
|
562
|
+
displayName: "NEAR Protocol",
|
|
563
|
+
networkType: "near",
|
|
564
|
+
rpcUrl: "https://rpc.mainnet.near.org",
|
|
565
|
+
explorerUrl: "https://nearblocks.io",
|
|
566
|
+
nativeCurrency: {
|
|
567
|
+
name: "NEAR",
|
|
568
|
+
symbol: "NEAR",
|
|
569
|
+
decimals: 24
|
|
570
|
+
// NEAR uses 24 decimals (yoctoNEAR)
|
|
571
|
+
},
|
|
572
|
+
usdc: {
|
|
573
|
+
address: "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1",
|
|
574
|
+
// Native Circle USDC
|
|
575
|
+
decimals: 6,
|
|
576
|
+
name: "USDC",
|
|
577
|
+
version: "1"
|
|
578
|
+
},
|
|
579
|
+
x402: {
|
|
580
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
581
|
+
enabled: true
|
|
582
|
+
// NEP-366 meta-transactions supported
|
|
583
|
+
}
|
|
584
|
+
},
|
|
585
|
+
// ============================================================================
|
|
586
|
+
// ALGORAND (2 networks) - Uses ASA transfers with atomic transaction groups
|
|
587
|
+
// ============================================================================
|
|
588
|
+
algorand: {
|
|
589
|
+
chainId: 0,
|
|
590
|
+
// Non-EVM (Algorand uses genesis hash for network identification)
|
|
591
|
+
chainIdHex: "0x0",
|
|
592
|
+
name: "algorand",
|
|
593
|
+
displayName: "Algorand",
|
|
594
|
+
networkType: "algorand",
|
|
595
|
+
rpcUrl: "https://mainnet-api.algonode.cloud",
|
|
596
|
+
explorerUrl: "https://allo.info",
|
|
597
|
+
nativeCurrency: {
|
|
598
|
+
name: "Algo",
|
|
599
|
+
symbol: "ALGO",
|
|
600
|
+
decimals: 6
|
|
601
|
+
// Algorand uses 6 decimals (microAlgos)
|
|
602
|
+
},
|
|
603
|
+
usdc: {
|
|
604
|
+
address: "31566704",
|
|
605
|
+
// USDC ASA ID on Algorand mainnet
|
|
606
|
+
decimals: 6,
|
|
607
|
+
name: "USDC",
|
|
608
|
+
version: "1"
|
|
609
|
+
},
|
|
610
|
+
tokens: {
|
|
611
|
+
usdc: {
|
|
612
|
+
address: "31566704",
|
|
613
|
+
// USDC ASA ID on Algorand mainnet
|
|
614
|
+
decimals: 6,
|
|
615
|
+
name: "USDC",
|
|
616
|
+
version: "1"
|
|
617
|
+
}
|
|
618
|
+
},
|
|
619
|
+
x402: {
|
|
620
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
621
|
+
enabled: true
|
|
622
|
+
}
|
|
623
|
+
},
|
|
624
|
+
"algorand-testnet": {
|
|
625
|
+
chainId: 0,
|
|
626
|
+
// Non-EVM
|
|
627
|
+
chainIdHex: "0x0",
|
|
628
|
+
name: "algorand-testnet",
|
|
629
|
+
displayName: "Algorand Testnet",
|
|
630
|
+
networkType: "algorand",
|
|
631
|
+
rpcUrl: "https://testnet-api.algonode.cloud",
|
|
632
|
+
explorerUrl: "https://testnet.allo.info",
|
|
633
|
+
nativeCurrency: {
|
|
634
|
+
name: "Algo",
|
|
635
|
+
symbol: "ALGO",
|
|
636
|
+
decimals: 6
|
|
637
|
+
},
|
|
638
|
+
usdc: {
|
|
639
|
+
address: "10458941",
|
|
640
|
+
// USDC ASA ID on Algorand testnet
|
|
641
|
+
decimals: 6,
|
|
642
|
+
name: "USDC",
|
|
643
|
+
version: "1"
|
|
644
|
+
},
|
|
645
|
+
tokens: {
|
|
646
|
+
usdc: {
|
|
647
|
+
address: "10458941",
|
|
648
|
+
// USDC ASA ID on Algorand testnet
|
|
649
|
+
decimals: 6,
|
|
650
|
+
name: "USDC",
|
|
651
|
+
version: "1"
|
|
652
|
+
}
|
|
653
|
+
},
|
|
654
|
+
x402: {
|
|
655
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
656
|
+
enabled: true
|
|
657
|
+
}
|
|
658
|
+
},
|
|
659
|
+
// ============================================================================
|
|
660
|
+
// SUI (2 networks) - Uses sponsored transactions (facilitator pays gas)
|
|
661
|
+
// ============================================================================
|
|
662
|
+
sui: {
|
|
663
|
+
chainId: 0,
|
|
664
|
+
// Non-EVM
|
|
665
|
+
chainIdHex: "0x0",
|
|
666
|
+
name: "sui",
|
|
667
|
+
displayName: "Sui",
|
|
668
|
+
networkType: "sui",
|
|
669
|
+
rpcUrl: "https://fullnode.mainnet.sui.io:443",
|
|
670
|
+
explorerUrl: "https://suiscan.xyz/mainnet",
|
|
671
|
+
nativeCurrency: {
|
|
672
|
+
name: "Sui",
|
|
673
|
+
symbol: "SUI",
|
|
674
|
+
decimals: 9
|
|
675
|
+
},
|
|
676
|
+
usdc: {
|
|
677
|
+
// USDC coin type on Sui mainnet
|
|
678
|
+
address: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
|
|
679
|
+
decimals: 6,
|
|
680
|
+
name: "USDC",
|
|
681
|
+
version: "1"
|
|
682
|
+
},
|
|
683
|
+
tokens: {
|
|
684
|
+
usdc: {
|
|
685
|
+
address: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
|
|
686
|
+
decimals: 6,
|
|
687
|
+
name: "USDC",
|
|
688
|
+
version: "1"
|
|
689
|
+
},
|
|
690
|
+
ausd: {
|
|
691
|
+
// AUSD (Agora USD) coin type on Sui mainnet
|
|
692
|
+
address: "0x2053d08c1e2bd02791056171aab0fd12bd7cd7efad2ab8f6b9c8902f14df2ff2::ausd::AUSD",
|
|
693
|
+
decimals: 6,
|
|
694
|
+
name: "AUSD",
|
|
695
|
+
version: "1"
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
x402: {
|
|
699
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
700
|
+
enabled: true
|
|
701
|
+
}
|
|
702
|
+
},
|
|
703
|
+
"sui-testnet": {
|
|
704
|
+
chainId: 0,
|
|
705
|
+
// Non-EVM
|
|
706
|
+
chainIdHex: "0x0",
|
|
707
|
+
name: "sui-testnet",
|
|
708
|
+
displayName: "Sui Testnet",
|
|
709
|
+
networkType: "sui",
|
|
710
|
+
rpcUrl: "https://fullnode.testnet.sui.io:443",
|
|
711
|
+
explorerUrl: "https://suiscan.xyz/testnet",
|
|
712
|
+
nativeCurrency: {
|
|
713
|
+
name: "Sui",
|
|
714
|
+
symbol: "SUI",
|
|
715
|
+
decimals: 9
|
|
716
|
+
},
|
|
717
|
+
usdc: {
|
|
718
|
+
// USDC coin type on Sui testnet
|
|
719
|
+
address: "0xa1ec7fc00a6f40db9693ad1415d0c193ad3906494428cf252621037bd7117e29::usdc::USDC",
|
|
720
|
+
decimals: 6,
|
|
721
|
+
name: "USDC",
|
|
722
|
+
version: "1"
|
|
723
|
+
},
|
|
724
|
+
tokens: {
|
|
725
|
+
usdc: {
|
|
726
|
+
address: "0xa1ec7fc00a6f40db9693ad1415d0c193ad3906494428cf252621037bd7117e29::usdc::USDC",
|
|
727
|
+
decimals: 6,
|
|
728
|
+
name: "USDC",
|
|
729
|
+
version: "1"
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
x402: {
|
|
733
|
+
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
734
|
+
enabled: true
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
function getChainByName(name) {
|
|
739
|
+
return SUPPORTED_CHAINS[name.toLowerCase()];
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// src/utils/x402.ts
|
|
743
|
+
function chainToCAIP2(chainName) {
|
|
744
|
+
const caip2 = CAIP2_IDENTIFIERS[chainName.toLowerCase()];
|
|
745
|
+
if (caip2) {
|
|
746
|
+
return caip2;
|
|
747
|
+
}
|
|
748
|
+
const chain = getChainByName(chainName);
|
|
749
|
+
if (chain) {
|
|
750
|
+
if (chain.networkType === "evm") {
|
|
751
|
+
return `eip155:${chain.chainId}`;
|
|
752
|
+
}
|
|
753
|
+
return `${chain.networkType}:${chainName}`;
|
|
754
|
+
}
|
|
755
|
+
return chainName;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/providers/sui/index.ts
|
|
759
|
+
var SuiClient;
|
|
760
|
+
var Transaction;
|
|
761
|
+
async function loadSuiDeps() {
|
|
762
|
+
if (!SuiClient) {
|
|
763
|
+
const clientModule = await import('@mysten/sui/client');
|
|
764
|
+
const txModule = await import('@mysten/sui/transactions');
|
|
765
|
+
SuiClient = clientModule.SuiClient;
|
|
766
|
+
Transaction = txModule.Transaction;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
var SuiProvider = class {
|
|
770
|
+
id = "sui-wallet";
|
|
771
|
+
name = "Sui Wallet";
|
|
772
|
+
networkType = "sui";
|
|
773
|
+
provider = null;
|
|
774
|
+
clients = /* @__PURE__ */ new Map();
|
|
775
|
+
address = null;
|
|
776
|
+
/**
|
|
777
|
+
* Check if Sui wallet is available
|
|
778
|
+
*/
|
|
779
|
+
isAvailable() {
|
|
780
|
+
if (typeof window === "undefined") return false;
|
|
781
|
+
const win = window;
|
|
782
|
+
return !!win.suiWallet;
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Connect to Sui wallet
|
|
786
|
+
*/
|
|
787
|
+
async connect() {
|
|
788
|
+
await loadSuiDeps();
|
|
789
|
+
this.provider = await this.getSuiWalletProvider();
|
|
790
|
+
if (!this.provider) {
|
|
791
|
+
throw new X402Error(
|
|
792
|
+
"Sui wallet not installed. Please install Sui Wallet or Suiet from Chrome Web Store",
|
|
793
|
+
"WALLET_NOT_FOUND"
|
|
794
|
+
);
|
|
795
|
+
}
|
|
796
|
+
try {
|
|
797
|
+
if (this.provider.requestPermissions) {
|
|
798
|
+
await this.provider.requestPermissions();
|
|
799
|
+
}
|
|
800
|
+
const accounts = await this.provider.getAccounts();
|
|
801
|
+
if (!accounts || accounts.length === 0) {
|
|
802
|
+
throw new X402Error("No Sui accounts found", "WALLET_CONNECTION_FAILED");
|
|
803
|
+
}
|
|
804
|
+
this.address = accounts[0];
|
|
805
|
+
return this.address;
|
|
806
|
+
} catch (error) {
|
|
807
|
+
if (error instanceof X402Error) throw error;
|
|
808
|
+
if (error instanceof Error) {
|
|
809
|
+
if (error.message.includes("User rejected") || error.message.includes("rejected")) {
|
|
810
|
+
throw new X402Error("Connection rejected by user", "WALLET_CONNECTION_REJECTED");
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
throw new X402Error(
|
|
814
|
+
`Failed to connect Sui wallet: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
815
|
+
"UNKNOWN_ERROR",
|
|
816
|
+
error
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Disconnect from Sui wallet
|
|
822
|
+
*/
|
|
823
|
+
async disconnect() {
|
|
824
|
+
this.provider = null;
|
|
825
|
+
this.clients.clear();
|
|
826
|
+
this.address = null;
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Get current address
|
|
830
|
+
*/
|
|
831
|
+
getAddress() {
|
|
832
|
+
return this.address;
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Get USDC balance
|
|
836
|
+
*/
|
|
837
|
+
async getBalance(chainConfig) {
|
|
838
|
+
await loadSuiDeps();
|
|
839
|
+
if (!this.address) {
|
|
840
|
+
throw new X402Error("Wallet not connected", "WALLET_NOT_CONNECTED");
|
|
841
|
+
}
|
|
842
|
+
const client = await this.getClient(chainConfig);
|
|
843
|
+
try {
|
|
844
|
+
const coins = await client.getCoins({
|
|
845
|
+
owner: this.address,
|
|
846
|
+
coinType: chainConfig.usdc.address
|
|
847
|
+
});
|
|
848
|
+
if (!coins.data || coins.data.length === 0) {
|
|
849
|
+
return "0.00";
|
|
850
|
+
}
|
|
851
|
+
const totalBalance = coins.data.reduce((sum, coin) => {
|
|
852
|
+
return sum + BigInt(coin.balance);
|
|
853
|
+
}, BigInt(0));
|
|
854
|
+
const balance = Number(totalBalance) / Math.pow(10, chainConfig.usdc.decimals);
|
|
855
|
+
return balance.toFixed(2);
|
|
856
|
+
} catch {
|
|
857
|
+
return "0.00";
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Create Sui payment (sponsored transaction)
|
|
862
|
+
*
|
|
863
|
+
* Transaction structure:
|
|
864
|
+
* 1. User creates a programmable transaction for USDC transfer
|
|
865
|
+
* 2. Transaction is signed by the user
|
|
866
|
+
* 3. Facilitator sponsors the transaction (pays gas in SUI)
|
|
867
|
+
* 4. Facilitator adds sponsor signature and submits
|
|
868
|
+
*
|
|
869
|
+
* User pays: ZERO SUI
|
|
870
|
+
*/
|
|
871
|
+
async signPayment(paymentInfo, chainConfig) {
|
|
872
|
+
await loadSuiDeps();
|
|
873
|
+
if (!this.provider || !this.address) {
|
|
874
|
+
throw new X402Error("Wallet not connected", "WALLET_NOT_CONNECTED");
|
|
875
|
+
}
|
|
876
|
+
const client = await this.getClient(chainConfig);
|
|
877
|
+
const recipient = paymentInfo.recipients?.sui || paymentInfo.recipient;
|
|
878
|
+
const facilitatorAddress = paymentInfo.facilitator;
|
|
879
|
+
if (!facilitatorAddress) {
|
|
880
|
+
throw new X402Error("Facilitator address not provided", "INVALID_CONFIG");
|
|
881
|
+
}
|
|
882
|
+
const amount = BigInt(Math.floor(parseFloat(paymentInfo.amount) * 1e6));
|
|
883
|
+
const usdcCoins = await client.getCoins({
|
|
884
|
+
owner: this.address,
|
|
885
|
+
coinType: chainConfig.usdc.address
|
|
886
|
+
});
|
|
887
|
+
if (!usdcCoins.data || usdcCoins.data.length === 0) {
|
|
888
|
+
throw new X402Error("No USDC coins found in wallet", "INSUFFICIENT_BALANCE");
|
|
889
|
+
}
|
|
890
|
+
const totalBalance = usdcCoins.data.reduce((sum, coin) => sum + BigInt(coin.balance), BigInt(0));
|
|
891
|
+
if (totalBalance < amount) {
|
|
892
|
+
throw new X402Error(
|
|
893
|
+
`Insufficient USDC balance. Have: ${Number(totalBalance) / 1e6}, Need: ${Number(amount) / 1e6}`,
|
|
894
|
+
"INSUFFICIENT_BALANCE"
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
const tx = new Transaction();
|
|
898
|
+
tx.setSender(this.address);
|
|
899
|
+
tx.setGasOwner(facilitatorAddress);
|
|
900
|
+
let coinToUse;
|
|
901
|
+
const sufficientCoin = usdcCoins.data.find((c) => BigInt(c.balance) >= amount);
|
|
902
|
+
if (sufficientCoin) {
|
|
903
|
+
coinToUse = sufficientCoin.coinObjectId;
|
|
904
|
+
} else {
|
|
905
|
+
const baseCoin = usdcCoins.data[0];
|
|
906
|
+
coinToUse = baseCoin.coinObjectId;
|
|
907
|
+
const otherCoins = usdcCoins.data.slice(1).map((c) => c.coinObjectId);
|
|
908
|
+
if (otherCoins.length > 0) {
|
|
909
|
+
tx.mergeCoins(tx.object(coinToUse), otherCoins.map((id) => tx.object(id)));
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
const [paymentCoin] = tx.splitCoins(tx.object(coinToUse), [amount]);
|
|
913
|
+
tx.transferObjects([paymentCoin], recipient);
|
|
914
|
+
const txBytes = await tx.build({ client });
|
|
915
|
+
let signedTx;
|
|
916
|
+
try {
|
|
917
|
+
if (this.provider.signTransaction) {
|
|
918
|
+
signedTx = await this.provider.signTransaction({
|
|
919
|
+
transaction: txBytes,
|
|
920
|
+
account: this.address,
|
|
921
|
+
chain: chainConfig.name === "sui-testnet" ? "sui:testnet" : "sui:mainnet"
|
|
922
|
+
});
|
|
923
|
+
} else if (this.provider.signTransactionBlock) {
|
|
924
|
+
const result = await this.provider.signTransactionBlock({
|
|
925
|
+
transactionBlock: txBytes,
|
|
926
|
+
account: this.address,
|
|
927
|
+
chain: chainConfig.name === "sui-testnet" ? "sui:testnet" : "sui:mainnet"
|
|
928
|
+
});
|
|
929
|
+
signedTx = {
|
|
930
|
+
signature: result.signature,
|
|
931
|
+
bytes: result.transactionBlockBytes
|
|
932
|
+
};
|
|
933
|
+
} else {
|
|
934
|
+
throw new X402Error("Wallet does not support transaction signing", "WALLET_NOT_SUPPORTED");
|
|
935
|
+
}
|
|
936
|
+
} catch (error) {
|
|
937
|
+
if (error instanceof X402Error) throw error;
|
|
938
|
+
if (error instanceof Error) {
|
|
939
|
+
if (error.message.includes("User rejected") || error.message.includes("rejected")) {
|
|
940
|
+
throw new X402Error("Signature rejected by user", "SIGNATURE_REJECTED");
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
throw new X402Error(
|
|
944
|
+
`Failed to sign transaction: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
945
|
+
"PAYMENT_FAILED",
|
|
946
|
+
error
|
|
947
|
+
);
|
|
948
|
+
}
|
|
949
|
+
const payload = {
|
|
950
|
+
transactionBytes: signedTx.bytes,
|
|
951
|
+
senderSignature: signedTx.signature,
|
|
952
|
+
from: this.address,
|
|
953
|
+
to: recipient,
|
|
954
|
+
amount: amount.toString(),
|
|
955
|
+
coinObjectId: coinToUse
|
|
956
|
+
};
|
|
957
|
+
return JSON.stringify(payload);
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Encode Sui payment as X-PAYMENT header
|
|
961
|
+
*
|
|
962
|
+
* @param paymentPayload - JSON-encoded payment payload from signPayment()
|
|
963
|
+
* @param chainConfig - Chain configuration (optional, defaults to 'sui')
|
|
964
|
+
* @param version - x402 protocol version (1 or 2, defaults to 1)
|
|
965
|
+
* @returns Base64-encoded X-PAYMENT header value
|
|
966
|
+
*/
|
|
967
|
+
encodePaymentHeader(paymentPayload, chainConfig, version = 1) {
|
|
968
|
+
const payload = JSON.parse(paymentPayload);
|
|
969
|
+
const networkName = chainConfig?.name || "sui";
|
|
970
|
+
const x402Payload = version === 2 ? {
|
|
971
|
+
x402Version: 2,
|
|
972
|
+
scheme: "exact",
|
|
973
|
+
network: chainToCAIP2(networkName),
|
|
974
|
+
// CAIP-2 format for v2
|
|
975
|
+
payload
|
|
976
|
+
} : {
|
|
977
|
+
x402Version: 1,
|
|
978
|
+
scheme: "exact",
|
|
979
|
+
network: networkName,
|
|
980
|
+
// Plain chain name for v1
|
|
981
|
+
payload
|
|
982
|
+
};
|
|
983
|
+
return btoa(JSON.stringify(x402Payload));
|
|
984
|
+
}
|
|
985
|
+
// Private helpers
|
|
986
|
+
async getSuiWalletProvider() {
|
|
987
|
+
if (typeof window === "undefined") return null;
|
|
988
|
+
const win = window;
|
|
989
|
+
if (win.suiWallet) {
|
|
990
|
+
return win.suiWallet;
|
|
991
|
+
}
|
|
992
|
+
for (let i = 0; i < 5; i++) {
|
|
993
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
994
|
+
if (win.suiWallet) {
|
|
995
|
+
return win.suiWallet;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
return null;
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Get or create a Sui client for a specific chain
|
|
1002
|
+
*/
|
|
1003
|
+
async getClient(chainConfig) {
|
|
1004
|
+
await loadSuiDeps();
|
|
1005
|
+
const config = chainConfig || getChainByName("sui");
|
|
1006
|
+
if (!config) {
|
|
1007
|
+
throw new X402Error("Chain config not found", "CHAIN_NOT_SUPPORTED");
|
|
1008
|
+
}
|
|
1009
|
+
const cacheKey = config.rpcUrl;
|
|
1010
|
+
if (this.clients.has(cacheKey)) {
|
|
1011
|
+
return this.clients.get(cacheKey);
|
|
1012
|
+
}
|
|
1013
|
+
const client = new SuiClient({ url: config.rpcUrl });
|
|
1014
|
+
this.clients.set(cacheKey, client);
|
|
1015
|
+
return client;
|
|
1016
|
+
}
|
|
1017
|
+
};
|
|
1018
|
+
var sui_default = SuiProvider;
|
|
1019
|
+
|
|
1020
|
+
export { SuiProvider, sui_default as default };
|
|
1021
|
+
//# sourceMappingURL=index.mjs.map
|
|
1022
|
+
//# sourceMappingURL=index.mjs.map
|