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