uvd-x402-sdk 2.0.3 → 2.2.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.
Files changed (56) hide show
  1. package/README.md +282 -15
  2. package/dist/adapters/index.d.mts +139 -0
  3. package/dist/adapters/index.d.ts +139 -0
  4. package/dist/adapters/index.js +724 -0
  5. package/dist/adapters/index.js.map +1 -0
  6. package/dist/adapters/index.mjs +720 -0
  7. package/dist/adapters/index.mjs.map +1 -0
  8. package/dist/{index-MTBgC_SL.d.mts → index-BHwtdJrt.d.mts} +45 -4
  9. package/dist/{index-MTBgC_SL.d.ts → index-BHwtdJrt.d.ts} +45 -4
  10. package/dist/{index-Db8dWNam.d.ts → index-CkDdnSNx.d.mts} +33 -2
  11. package/dist/{index-D0N_SYpK.d.mts → index-UTj85ZDJ.d.ts} +33 -2
  12. package/dist/index.d.mts +2 -2
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.js +210 -0
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +207 -1
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/providers/evm/index.d.mts +19 -3
  19. package/dist/providers/evm/index.d.ts +19 -3
  20. package/dist/providers/evm/index.js +228 -12
  21. package/dist/providers/evm/index.js.map +1 -1
  22. package/dist/providers/evm/index.mjs +228 -12
  23. package/dist/providers/evm/index.mjs.map +1 -1
  24. package/dist/providers/near/index.d.mts +1 -1
  25. package/dist/providers/near/index.d.ts +1 -1
  26. package/dist/providers/near/index.js.map +1 -1
  27. package/dist/providers/near/index.mjs.map +1 -1
  28. package/dist/providers/solana/index.d.mts +1 -1
  29. package/dist/providers/solana/index.d.ts +1 -1
  30. package/dist/providers/solana/index.js +168 -0
  31. package/dist/providers/solana/index.js.map +1 -1
  32. package/dist/providers/solana/index.mjs +168 -0
  33. package/dist/providers/solana/index.mjs.map +1 -1
  34. package/dist/providers/stellar/index.d.mts +1 -1
  35. package/dist/providers/stellar/index.d.ts +1 -1
  36. package/dist/providers/stellar/index.js.map +1 -1
  37. package/dist/providers/stellar/index.mjs.map +1 -1
  38. package/dist/react/index.d.mts +3 -3
  39. package/dist/react/index.d.ts +3 -3
  40. package/dist/react/index.js +168 -0
  41. package/dist/react/index.js.map +1 -1
  42. package/dist/react/index.mjs +168 -0
  43. package/dist/react/index.mjs.map +1 -1
  44. package/dist/utils/index.d.mts +1 -1
  45. package/dist/utils/index.d.ts +1 -1
  46. package/dist/utils/index.js +168 -0
  47. package/dist/utils/index.js.map +1 -1
  48. package/dist/utils/index.mjs +168 -0
  49. package/dist/utils/index.mjs.map +1 -1
  50. package/package.json +10 -2
  51. package/src/adapters/index.ts +13 -0
  52. package/src/adapters/wagmi.ts +294 -0
  53. package/src/chains/index.ts +255 -1
  54. package/src/index.ts +9 -0
  55. package/src/providers/evm/index.ts +64 -16
  56. package/src/types/index.ts +46 -3
@@ -0,0 +1,724 @@
1
+ 'use strict';
2
+
3
+ // src/chains/index.ts
4
+ var DEFAULT_FACILITATOR_URL = "https://facilitator.ultravioletadao.xyz";
5
+ var SUPPORTED_CHAINS = {
6
+ // ============================================================================
7
+ // EVM CHAINS (10 networks)
8
+ // ============================================================================
9
+ base: {
10
+ chainId: 8453,
11
+ chainIdHex: "0x2105",
12
+ name: "base",
13
+ displayName: "Base",
14
+ networkType: "evm",
15
+ rpcUrl: "https://mainnet.base.org",
16
+ explorerUrl: "https://basescan.org",
17
+ nativeCurrency: {
18
+ name: "Ethereum",
19
+ symbol: "ETH",
20
+ decimals: 18
21
+ },
22
+ usdc: {
23
+ address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
24
+ decimals: 6,
25
+ name: "USD Coin",
26
+ version: "2"
27
+ },
28
+ tokens: {
29
+ usdc: {
30
+ address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
31
+ decimals: 6,
32
+ name: "USD Coin",
33
+ version: "2"
34
+ },
35
+ eurc: {
36
+ address: "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42",
37
+ decimals: 6,
38
+ name: "EURC",
39
+ version: "2"
40
+ },
41
+ gho: {
42
+ address: "0x6Bb7a212910682DCFdbd5BCBb3e28FB4E8da10Ee",
43
+ decimals: 18,
44
+ name: "Gho Token",
45
+ version: "1"
46
+ }
47
+ },
48
+ x402: {
49
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
50
+ enabled: true
51
+ }
52
+ },
53
+ avalanche: {
54
+ chainId: 43114,
55
+ chainIdHex: "0xa86a",
56
+ name: "avalanche",
57
+ displayName: "Avalanche C-Chain",
58
+ networkType: "evm",
59
+ rpcUrl: "https://avalanche-c-chain-rpc.publicnode.com",
60
+ explorerUrl: "https://snowtrace.io",
61
+ nativeCurrency: {
62
+ name: "Avalanche",
63
+ symbol: "AVAX",
64
+ decimals: 18
65
+ },
66
+ usdc: {
67
+ address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
68
+ decimals: 6,
69
+ name: "USD Coin",
70
+ version: "2"
71
+ },
72
+ tokens: {
73
+ usdc: {
74
+ address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
75
+ decimals: 6,
76
+ name: "USD Coin",
77
+ version: "2"
78
+ },
79
+ eurc: {
80
+ address: "0xC891EB4cbdEFf6e073e859e987815Ed1505c2ACD",
81
+ decimals: 6,
82
+ name: "EURC",
83
+ version: "2"
84
+ },
85
+ ausd: {
86
+ address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
87
+ decimals: 6,
88
+ name: "Agora USD",
89
+ version: "1"
90
+ }
91
+ },
92
+ x402: {
93
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
94
+ enabled: true
95
+ }
96
+ },
97
+ ethereum: {
98
+ chainId: 1,
99
+ chainIdHex: "0x1",
100
+ name: "ethereum",
101
+ displayName: "Ethereum",
102
+ networkType: "evm",
103
+ rpcUrl: "https://eth.llamarpc.com",
104
+ explorerUrl: "https://etherscan.io",
105
+ nativeCurrency: {
106
+ name: "Ethereum",
107
+ symbol: "ETH",
108
+ decimals: 18
109
+ },
110
+ usdc: {
111
+ address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
112
+ decimals: 6,
113
+ name: "USD Coin",
114
+ version: "2"
115
+ },
116
+ tokens: {
117
+ usdc: {
118
+ address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
119
+ decimals: 6,
120
+ name: "USD Coin",
121
+ version: "2"
122
+ },
123
+ eurc: {
124
+ address: "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
125
+ decimals: 6,
126
+ name: "EURC",
127
+ version: "2"
128
+ },
129
+ ausd: {
130
+ address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
131
+ decimals: 6,
132
+ name: "Agora USD",
133
+ version: "1"
134
+ },
135
+ pyusd: {
136
+ address: "0x6c3ea9036406852006290770BEdFcAbA0e23A0e8",
137
+ decimals: 6,
138
+ name: "PayPal USD",
139
+ version: "1"
140
+ },
141
+ gho: {
142
+ address: "0x40D16FC0246aD3160Ccc09B8D0D3A2cD28aE6C2f",
143
+ decimals: 18,
144
+ name: "Gho Token",
145
+ version: "1"
146
+ },
147
+ crvusd: {
148
+ address: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
149
+ decimals: 18,
150
+ name: "Curve.Fi USD Stablecoin",
151
+ version: "1"
152
+ }
153
+ },
154
+ x402: {
155
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
156
+ enabled: true
157
+ }
158
+ },
159
+ polygon: {
160
+ chainId: 137,
161
+ chainIdHex: "0x89",
162
+ name: "polygon",
163
+ displayName: "Polygon",
164
+ networkType: "evm",
165
+ rpcUrl: "https://polygon-rpc.com",
166
+ explorerUrl: "https://polygonscan.com",
167
+ nativeCurrency: {
168
+ name: "Polygon",
169
+ symbol: "POL",
170
+ decimals: 18
171
+ },
172
+ usdc: {
173
+ address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
174
+ decimals: 6,
175
+ name: "USD Coin",
176
+ version: "2"
177
+ },
178
+ tokens: {
179
+ usdc: {
180
+ address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
181
+ decimals: 6,
182
+ name: "USD Coin",
183
+ version: "2"
184
+ },
185
+ ausd: {
186
+ address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
187
+ decimals: 6,
188
+ name: "Agora USD",
189
+ version: "1"
190
+ }
191
+ },
192
+ x402: {
193
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
194
+ enabled: true
195
+ }
196
+ },
197
+ arbitrum: {
198
+ chainId: 42161,
199
+ chainIdHex: "0xa4b1",
200
+ name: "arbitrum",
201
+ displayName: "Arbitrum One",
202
+ networkType: "evm",
203
+ rpcUrl: "https://arb1.arbitrum.io/rpc",
204
+ explorerUrl: "https://arbiscan.io",
205
+ nativeCurrency: {
206
+ name: "Ethereum",
207
+ symbol: "ETH",
208
+ decimals: 18
209
+ },
210
+ usdc: {
211
+ address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
212
+ decimals: 6,
213
+ name: "USD Coin",
214
+ version: "2"
215
+ },
216
+ tokens: {
217
+ usdc: {
218
+ address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
219
+ decimals: 6,
220
+ name: "USD Coin",
221
+ version: "2"
222
+ },
223
+ ausd: {
224
+ address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
225
+ decimals: 6,
226
+ name: "Agora USD",
227
+ version: "1"
228
+ },
229
+ gho: {
230
+ address: "0x7dfF72693f6A4149b17e7C6314655f6A9F7c8B33",
231
+ decimals: 18,
232
+ name: "Gho Token",
233
+ version: "1"
234
+ },
235
+ crvusd: {
236
+ address: "0x498Bf2B1e120FeD3ad3D42EA2165E9b73f99C1e5",
237
+ decimals: 18,
238
+ name: "Curve.Fi USD Stablecoin",
239
+ version: "1"
240
+ }
241
+ },
242
+ x402: {
243
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
244
+ enabled: true
245
+ }
246
+ },
247
+ optimism: {
248
+ chainId: 10,
249
+ chainIdHex: "0xa",
250
+ name: "optimism",
251
+ displayName: "Optimism",
252
+ networkType: "evm",
253
+ rpcUrl: "https://mainnet.optimism.io",
254
+ explorerUrl: "https://optimistic.etherscan.io",
255
+ nativeCurrency: {
256
+ name: "Ethereum",
257
+ symbol: "ETH",
258
+ decimals: 18
259
+ },
260
+ usdc: {
261
+ address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
262
+ decimals: 6,
263
+ name: "USD Coin",
264
+ version: "2"
265
+ },
266
+ tokens: {
267
+ usdc: {
268
+ address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
269
+ decimals: 6,
270
+ name: "USD Coin",
271
+ version: "2"
272
+ }
273
+ },
274
+ x402: {
275
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
276
+ enabled: true
277
+ }
278
+ },
279
+ celo: {
280
+ chainId: 42220,
281
+ chainIdHex: "0xa4ec",
282
+ name: "celo",
283
+ displayName: "Celo",
284
+ networkType: "evm",
285
+ rpcUrl: "https://forno.celo.org",
286
+ explorerUrl: "https://celoscan.io",
287
+ nativeCurrency: {
288
+ name: "Celo",
289
+ symbol: "CELO",
290
+ decimals: 18
291
+ },
292
+ usdc: {
293
+ address: "0xcebA9300f2b948710d2653dD7B07f33A8B32118C",
294
+ decimals: 6,
295
+ name: "USDC",
296
+ // Celo uses "USDC" not "USD Coin" for EIP-712
297
+ version: "2"
298
+ },
299
+ tokens: {
300
+ usdc: {
301
+ address: "0xcebA9300f2b948710d2653dD7B07f33A8B32118C",
302
+ decimals: 6,
303
+ name: "USDC",
304
+ // Celo uses "USDC" not "USD Coin" for EIP-712
305
+ version: "2"
306
+ }
307
+ },
308
+ x402: {
309
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
310
+ enabled: true
311
+ }
312
+ },
313
+ hyperevm: {
314
+ chainId: 999,
315
+ chainIdHex: "0x3e7",
316
+ name: "hyperevm",
317
+ displayName: "HyperEVM",
318
+ networkType: "evm",
319
+ rpcUrl: "https://rpc.hyperliquid.xyz/evm",
320
+ explorerUrl: "https://hyperevmscan.io",
321
+ nativeCurrency: {
322
+ name: "Ethereum",
323
+ symbol: "ETH",
324
+ decimals: 18
325
+ },
326
+ usdc: {
327
+ address: "0xb88339CB7199b77E23DB6E890353E22632Ba630f",
328
+ decimals: 6,
329
+ name: "USDC",
330
+ // HyperEVM uses "USDC" not "USD Coin"
331
+ version: "2"
332
+ },
333
+ tokens: {
334
+ usdc: {
335
+ address: "0xb88339CB7199b77E23DB6E890353E22632Ba630f",
336
+ decimals: 6,
337
+ name: "USDC",
338
+ // HyperEVM uses "USDC" not "USD Coin"
339
+ version: "2"
340
+ }
341
+ },
342
+ x402: {
343
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
344
+ enabled: true
345
+ }
346
+ },
347
+ unichain: {
348
+ chainId: 130,
349
+ chainIdHex: "0x82",
350
+ name: "unichain",
351
+ displayName: "Unichain",
352
+ networkType: "evm",
353
+ rpcUrl: "https://unichain-rpc.publicnode.com",
354
+ explorerUrl: "https://uniscan.xyz",
355
+ nativeCurrency: {
356
+ name: "Ethereum",
357
+ symbol: "ETH",
358
+ decimals: 18
359
+ },
360
+ usdc: {
361
+ address: "0x078d782b760474a361dda0af3839290b0ef57ad6",
362
+ decimals: 6,
363
+ name: "USDC",
364
+ // Unichain uses "USDC" not "USD Coin"
365
+ version: "2"
366
+ },
367
+ tokens: {
368
+ usdc: {
369
+ address: "0x078d782b760474a361dda0af3839290b0ef57ad6",
370
+ decimals: 6,
371
+ name: "USDC",
372
+ // Unichain uses "USDC" not "USD Coin"
373
+ version: "2"
374
+ }
375
+ },
376
+ x402: {
377
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
378
+ enabled: true
379
+ }
380
+ },
381
+ monad: {
382
+ chainId: 143,
383
+ chainIdHex: "0x8f",
384
+ name: "monad",
385
+ displayName: "Monad",
386
+ networkType: "evm",
387
+ rpcUrl: "https://rpc.monad.xyz",
388
+ explorerUrl: "https://monad.socialscan.io",
389
+ nativeCurrency: {
390
+ name: "Monad",
391
+ symbol: "MON",
392
+ decimals: 18
393
+ },
394
+ usdc: {
395
+ address: "0x754704bc059f8c67012fed69bc8a327a5aafb603",
396
+ decimals: 6,
397
+ name: "USDC",
398
+ // Monad uses "USDC" not "USD Coin"
399
+ version: "2"
400
+ },
401
+ tokens: {
402
+ usdc: {
403
+ address: "0x754704bc059f8c67012fed69bc8a327a5aafb603",
404
+ decimals: 6,
405
+ name: "USDC",
406
+ // Monad uses "USDC" not "USD Coin"
407
+ version: "2"
408
+ },
409
+ ausd: {
410
+ address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
411
+ decimals: 6,
412
+ name: "Agora USD",
413
+ version: "1"
414
+ }
415
+ },
416
+ x402: {
417
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
418
+ enabled: true
419
+ }
420
+ },
421
+ // ============================================================================
422
+ // SVM CHAINS (2 networks) - Solana Virtual Machine
423
+ // ============================================================================
424
+ solana: {
425
+ chainId: 0,
426
+ // Non-EVM
427
+ chainIdHex: "0x0",
428
+ name: "solana",
429
+ displayName: "Solana",
430
+ networkType: "svm",
431
+ rpcUrl: "https://api.mainnet-beta.solana.com",
432
+ explorerUrl: "https://solscan.io",
433
+ nativeCurrency: {
434
+ name: "Solana",
435
+ symbol: "SOL",
436
+ decimals: 9
437
+ },
438
+ usdc: {
439
+ address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
440
+ // USDC SPL token mint
441
+ decimals: 6,
442
+ name: "USD Coin",
443
+ version: "1"
444
+ },
445
+ x402: {
446
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
447
+ enabled: true
448
+ }
449
+ },
450
+ fogo: {
451
+ chainId: 0,
452
+ // Non-EVM (SVM)
453
+ chainIdHex: "0x0",
454
+ name: "fogo",
455
+ displayName: "Fogo",
456
+ networkType: "svm",
457
+ rpcUrl: "https://rpc.fogo.nightly.app/",
458
+ explorerUrl: "https://explorer.fogo.nightly.app",
459
+ nativeCurrency: {
460
+ name: "Fogo",
461
+ symbol: "FOGO",
462
+ decimals: 9
463
+ },
464
+ usdc: {
465
+ address: "uSd2czE61Evaf76RNbq4KPpXnkiL3irdzgLFUMe3NoG",
466
+ // Fogo USDC mint
467
+ decimals: 6,
468
+ name: "USDC",
469
+ version: "1"
470
+ },
471
+ x402: {
472
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
473
+ enabled: true
474
+ }
475
+ },
476
+ // ============================================================================
477
+ // STELLAR (1 network)
478
+ // ============================================================================
479
+ stellar: {
480
+ chainId: 0,
481
+ // Non-EVM
482
+ chainIdHex: "0x0",
483
+ name: "stellar",
484
+ displayName: "Stellar",
485
+ networkType: "stellar",
486
+ rpcUrl: "https://horizon.stellar.org",
487
+ explorerUrl: "https://stellar.expert/explorer/public",
488
+ nativeCurrency: {
489
+ name: "Lumens",
490
+ symbol: "XLM",
491
+ decimals: 7
492
+ // Stellar uses 7 decimals (stroops)
493
+ },
494
+ usdc: {
495
+ address: "CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75",
496
+ // Soroban Asset Contract
497
+ decimals: 7,
498
+ // Stellar USDC uses 7 decimals
499
+ name: "USDC",
500
+ version: "1"
501
+ },
502
+ x402: {
503
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
504
+ enabled: true
505
+ }
506
+ },
507
+ // ============================================================================
508
+ // NEAR (1 network) - Uses NEP-366 meta-transactions
509
+ // ============================================================================
510
+ near: {
511
+ chainId: 0,
512
+ // Non-EVM
513
+ chainIdHex: "0x0",
514
+ name: "near",
515
+ displayName: "NEAR Protocol",
516
+ networkType: "near",
517
+ rpcUrl: "https://rpc.mainnet.near.org",
518
+ explorerUrl: "https://nearblocks.io",
519
+ nativeCurrency: {
520
+ name: "NEAR",
521
+ symbol: "NEAR",
522
+ decimals: 24
523
+ // NEAR uses 24 decimals (yoctoNEAR)
524
+ },
525
+ usdc: {
526
+ address: "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1",
527
+ // Native Circle USDC
528
+ decimals: 6,
529
+ name: "USDC",
530
+ version: "1"
531
+ },
532
+ x402: {
533
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
534
+ enabled: true
535
+ // NEP-366 meta-transactions supported
536
+ }
537
+ }
538
+ };
539
+ function getChainByName(name) {
540
+ return SUPPORTED_CHAINS[name.toLowerCase()];
541
+ }
542
+
543
+ // src/types/index.ts
544
+ var CAIP2_IDENTIFIERS = {
545
+ // EVM chains
546
+ base: "eip155:8453",
547
+ ethereum: "eip155:1",
548
+ polygon: "eip155:137",
549
+ arbitrum: "eip155:42161",
550
+ optimism: "eip155:10",
551
+ avalanche: "eip155:43114",
552
+ celo: "eip155:42220",
553
+ hyperevm: "eip155:999",
554
+ unichain: "eip155:130",
555
+ monad: "eip155:143",
556
+ // SVM chains
557
+ solana: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
558
+ fogo: "svm:fogo",
559
+ // Stellar
560
+ stellar: "stellar:pubnet",
561
+ // NEAR
562
+ near: "near:mainnet"
563
+ };
564
+ Object.fromEntries(
565
+ Object.entries(CAIP2_IDENTIFIERS).map(([k, v]) => [v, k])
566
+ );
567
+ var X402Error = class _X402Error extends Error {
568
+ code;
569
+ details;
570
+ constructor(message, code, details) {
571
+ super(message);
572
+ this.name = "X402Error";
573
+ this.code = code;
574
+ this.details = details;
575
+ if (Error.captureStackTrace) {
576
+ Error.captureStackTrace(this, _X402Error);
577
+ }
578
+ }
579
+ };
580
+
581
+ // src/utils/x402.ts
582
+ function encodeX402Header(header) {
583
+ return btoa(JSON.stringify(header));
584
+ }
585
+ function createX402V1Header(network, payload) {
586
+ return {
587
+ x402Version: 1,
588
+ scheme: "exact",
589
+ network,
590
+ payload
591
+ };
592
+ }
593
+
594
+ // src/adapters/wagmi.ts
595
+ function generateNonce() {
596
+ const bytes = new Uint8Array(32);
597
+ if (typeof globalThis !== "undefined" && globalThis.crypto?.getRandomValues) {
598
+ globalThis.crypto.getRandomValues(bytes);
599
+ } else if (typeof window !== "undefined" && window.crypto?.getRandomValues) {
600
+ window.crypto.getRandomValues(bytes);
601
+ } else {
602
+ for (let i = 0; i < 32; i++) {
603
+ bytes[i] = Math.floor(Math.random() * 256);
604
+ }
605
+ }
606
+ return "0x" + Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
607
+ }
608
+ function parseUnits(amount, decimals) {
609
+ const [integer, fraction = ""] = amount.split(".");
610
+ const paddedFraction = fraction.padEnd(decimals, "0").slice(0, decimals);
611
+ return BigInt(integer + paddedFraction);
612
+ }
613
+ async function createPaymentFromWalletClient(walletClient, options) {
614
+ if (!walletClient) {
615
+ throw new X402Error("WalletClient is not available. Make sure wallet is connected.", "WALLET_NOT_CONNECTED");
616
+ }
617
+ const {
618
+ recipient,
619
+ amount,
620
+ chainName = "base",
621
+ validitySeconds = 300
622
+ } = options;
623
+ const chain = getChainByName(chainName);
624
+ if (!chain) {
625
+ throw new X402Error(`Unsupported chain: ${chainName}`, "CHAIN_NOT_SUPPORTED");
626
+ }
627
+ if (chain.networkType !== "evm") {
628
+ throw new X402Error(
629
+ `wagmi adapter only supports EVM chains. For ${chain.networkType}, use the appropriate provider.`,
630
+ "CHAIN_NOT_SUPPORTED"
631
+ );
632
+ }
633
+ const from = walletClient.account.address;
634
+ const to = recipient;
635
+ const nonce = generateNonce();
636
+ const validAfter = 0;
637
+ const validBefore = Math.floor(Date.now() / 1e3) + validitySeconds;
638
+ const value = parseUnits(amount, chain.usdc.decimals);
639
+ const domain = {
640
+ name: chain.usdc.name,
641
+ version: chain.usdc.version,
642
+ chainId: chain.chainId,
643
+ verifyingContract: chain.usdc.address
644
+ };
645
+ const types = {
646
+ TransferWithAuthorization: [
647
+ { name: "from", type: "address" },
648
+ { name: "to", type: "address" },
649
+ { name: "value", type: "uint256" },
650
+ { name: "validAfter", type: "uint256" },
651
+ { name: "validBefore", type: "uint256" },
652
+ { name: "nonce", type: "bytes32" }
653
+ ]
654
+ };
655
+ const message = {
656
+ from,
657
+ to,
658
+ value,
659
+ validAfter: BigInt(validAfter),
660
+ validBefore: BigInt(validBefore),
661
+ nonce
662
+ };
663
+ let signature;
664
+ try {
665
+ signature = await walletClient.signTypedData({
666
+ domain,
667
+ types,
668
+ primaryType: "TransferWithAuthorization",
669
+ message
670
+ });
671
+ } catch (error) {
672
+ if (error instanceof Error) {
673
+ if (error.message.includes("User rejected") || error.message.includes("denied")) {
674
+ throw new X402Error("Signature rejected by user", "SIGNATURE_REJECTED");
675
+ }
676
+ }
677
+ throw new X402Error(
678
+ `Failed to sign payment: ${error instanceof Error ? error.message : "Unknown error"}`,
679
+ "PAYMENT_FAILED",
680
+ error
681
+ );
682
+ }
683
+ const header = createX402V1Header(chainName, {
684
+ signature,
685
+ authorization: {
686
+ from,
687
+ to: recipient,
688
+ value: value.toString(),
689
+ validAfter: validAfter.toString(),
690
+ validBefore: validBefore.toString(),
691
+ nonce
692
+ }
693
+ });
694
+ return encodeX402Header(header);
695
+ }
696
+ async function createPaymentWithResult(walletClient, options) {
697
+ const paymentHeader = await createPaymentFromWalletClient(walletClient, options);
698
+ return {
699
+ success: true,
700
+ paymentHeader,
701
+ network: options.chainName || "base",
702
+ payer: walletClient?.account.address
703
+ };
704
+ }
705
+ function useX402Wagmi(walletClient) {
706
+ const isReady = !!walletClient;
707
+ const createPayment = async (options) => {
708
+ return createPaymentFromWalletClient(walletClient, options);
709
+ };
710
+ const createPaymentFull = async (options) => {
711
+ return createPaymentWithResult(walletClient, options);
712
+ };
713
+ return {
714
+ isReady,
715
+ createPayment,
716
+ createPaymentFull
717
+ };
718
+ }
719
+
720
+ exports.createPaymentFromWalletClient = createPaymentFromWalletClient;
721
+ exports.createPaymentWithResult = createPaymentWithResult;
722
+ exports.useX402Wagmi = useX402Wagmi;
723
+ //# sourceMappingURL=index.js.map
724
+ //# sourceMappingURL=index.js.map