uvd-x402-sdk 2.6.0 → 2.10.1

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