uvd-x402-sdk 2.6.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 (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 +78 -1
  5. package/dist/adapters/index.js.map +1 -1
  6. package/dist/adapters/index.mjs +78 -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-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 +93 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +92 -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 +78 -1
  57. package/dist/react/index.js.map +1 -1
  58. package/dist/react/index.mjs +78 -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 +78 -1
  63. package/dist/utils/index.js.map +1 -1
  64. package/dist/utils/index.mjs +78 -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 +94 -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,898 @@
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
+ x402: {
474
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
475
+ enabled: true
476
+ }
477
+ },
478
+ fogo: {
479
+ chainId: 0,
480
+ // Non-EVM (SVM)
481
+ chainIdHex: "0x0",
482
+ name: "fogo",
483
+ displayName: "Fogo",
484
+ networkType: "svm",
485
+ rpcUrl: "https://rpc.fogo.nightly.app/",
486
+ explorerUrl: "https://explorer.fogo.nightly.app",
487
+ nativeCurrency: {
488
+ name: "Fogo",
489
+ symbol: "FOGO",
490
+ decimals: 9
491
+ },
492
+ usdc: {
493
+ address: "uSd2czE61Evaf76RNbq4KPpXnkiL3irdzgLFUMe3NoG",
494
+ // Fogo USDC mint
495
+ decimals: 6,
496
+ name: "USDC",
497
+ version: "1"
498
+ },
499
+ x402: {
500
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
501
+ enabled: true
502
+ }
503
+ },
504
+ // ============================================================================
505
+ // STELLAR (1 network)
506
+ // ============================================================================
507
+ stellar: {
508
+ chainId: 0,
509
+ // Non-EVM
510
+ chainIdHex: "0x0",
511
+ name: "stellar",
512
+ displayName: "Stellar",
513
+ networkType: "stellar",
514
+ rpcUrl: "https://horizon.stellar.org",
515
+ explorerUrl: "https://stellar.expert/explorer/public",
516
+ nativeCurrency: {
517
+ name: "Lumens",
518
+ symbol: "XLM",
519
+ decimals: 7
520
+ // Stellar uses 7 decimals (stroops)
521
+ },
522
+ usdc: {
523
+ address: "CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75",
524
+ // Soroban Asset Contract
525
+ decimals: 7,
526
+ // Stellar USDC uses 7 decimals
527
+ name: "USDC",
528
+ version: "1"
529
+ },
530
+ x402: {
531
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
532
+ enabled: true
533
+ }
534
+ },
535
+ // ============================================================================
536
+ // NEAR (1 network) - Uses NEP-366 meta-transactions
537
+ // ============================================================================
538
+ near: {
539
+ chainId: 0,
540
+ // Non-EVM
541
+ chainIdHex: "0x0",
542
+ name: "near",
543
+ displayName: "NEAR Protocol",
544
+ networkType: "near",
545
+ rpcUrl: "https://rpc.mainnet.near.org",
546
+ explorerUrl: "https://nearblocks.io",
547
+ nativeCurrency: {
548
+ name: "NEAR",
549
+ symbol: "NEAR",
550
+ decimals: 24
551
+ // NEAR uses 24 decimals (yoctoNEAR)
552
+ },
553
+ usdc: {
554
+ address: "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1",
555
+ // Native Circle USDC
556
+ decimals: 6,
557
+ name: "USDC",
558
+ version: "1"
559
+ },
560
+ x402: {
561
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
562
+ enabled: true
563
+ // NEP-366 meta-transactions supported
564
+ }
565
+ },
566
+ // ============================================================================
567
+ // ALGORAND (2 networks) - Uses ASA transfers with atomic transaction groups
568
+ // ============================================================================
569
+ algorand: {
570
+ chainId: 0,
571
+ // Non-EVM (Algorand uses genesis hash for network identification)
572
+ chainIdHex: "0x0",
573
+ name: "algorand",
574
+ displayName: "Algorand",
575
+ networkType: "algorand",
576
+ rpcUrl: "https://mainnet-api.algonode.cloud",
577
+ explorerUrl: "https://allo.info",
578
+ nativeCurrency: {
579
+ name: "Algo",
580
+ symbol: "ALGO",
581
+ decimals: 6
582
+ // Algorand uses 6 decimals (microAlgos)
583
+ },
584
+ usdc: {
585
+ address: "31566704",
586
+ // USDC ASA ID on Algorand mainnet
587
+ decimals: 6,
588
+ name: "USDC",
589
+ version: "1"
590
+ },
591
+ tokens: {
592
+ usdc: {
593
+ address: "31566704",
594
+ // USDC ASA ID on Algorand mainnet
595
+ decimals: 6,
596
+ name: "USDC",
597
+ version: "1"
598
+ }
599
+ },
600
+ x402: {
601
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
602
+ enabled: true
603
+ }
604
+ },
605
+ "algorand-testnet": {
606
+ chainId: 0,
607
+ // Non-EVM
608
+ chainIdHex: "0x0",
609
+ name: "algorand-testnet",
610
+ displayName: "Algorand Testnet",
611
+ networkType: "algorand",
612
+ rpcUrl: "https://testnet-api.algonode.cloud",
613
+ explorerUrl: "https://testnet.allo.info",
614
+ nativeCurrency: {
615
+ name: "Algo",
616
+ symbol: "ALGO",
617
+ decimals: 6
618
+ },
619
+ usdc: {
620
+ address: "10458941",
621
+ // USDC ASA ID on Algorand testnet
622
+ decimals: 6,
623
+ name: "USDC",
624
+ version: "1"
625
+ },
626
+ tokens: {
627
+ usdc: {
628
+ address: "10458941",
629
+ // USDC ASA ID on Algorand testnet
630
+ decimals: 6,
631
+ name: "USDC",
632
+ version: "1"
633
+ }
634
+ },
635
+ x402: {
636
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
637
+ enabled: true
638
+ }
639
+ }
640
+ };
641
+ function getChainByName(name) {
642
+ return SUPPORTED_CHAINS[name.toLowerCase()];
643
+ }
644
+
645
+ // src/utils/x402.ts
646
+ function chainToCAIP2(chainName) {
647
+ const caip2 = CAIP2_IDENTIFIERS[chainName.toLowerCase()];
648
+ if (caip2) {
649
+ return caip2;
650
+ }
651
+ const chain = getChainByName(chainName);
652
+ if (chain) {
653
+ if (chain.networkType === "evm") {
654
+ return `eip155:${chain.chainId}`;
655
+ }
656
+ return `${chain.networkType}:${chainName}`;
657
+ }
658
+ return chainName;
659
+ }
660
+
661
+ // src/providers/algorand/index.ts
662
+ function uint8ArrayToBase64(bytes) {
663
+ let binary = "";
664
+ for (let i = 0; i < bytes.length; i++) {
665
+ binary += String.fromCharCode(bytes[i]);
666
+ }
667
+ return btoa(binary);
668
+ }
669
+ var algosdk = null;
670
+ var PeraWalletConnect = null;
671
+ async function loadAlgorandDeps() {
672
+ if (!algosdk) {
673
+ algosdk = await import('algosdk');
674
+ }
675
+ if (!PeraWalletConnect) {
676
+ const peraModule = await import('@perawallet/connect');
677
+ PeraWalletConnect = peraModule.PeraWalletConnect;
678
+ }
679
+ }
680
+ var AlgorandProvider = class {
681
+ id = "pera";
682
+ name = "Pera Wallet";
683
+ networkType = "algorand";
684
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
685
+ peraWallet = null;
686
+ address = null;
687
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
688
+ algodClients = /* @__PURE__ */ new Map();
689
+ /**
690
+ * Check if Pera Wallet is available
691
+ * Note: Pera works as a WalletConnect modal, so it's always "available"
692
+ */
693
+ isAvailable() {
694
+ return typeof window !== "undefined";
695
+ }
696
+ /**
697
+ * Connect to Pera Wallet
698
+ */
699
+ async connect(_chainName) {
700
+ await loadAlgorandDeps();
701
+ if (!PeraWalletConnect) {
702
+ throw new X402Error("Failed to load Pera Wallet SDK", "WALLET_NOT_FOUND");
703
+ }
704
+ try {
705
+ this.peraWallet = new PeraWalletConnect();
706
+ const accounts = await this.peraWallet.reconnectSession();
707
+ if (accounts.length > 0) {
708
+ this.address = accounts[0];
709
+ return accounts[0];
710
+ }
711
+ const newAccounts = await this.peraWallet.connect();
712
+ if (newAccounts.length === 0) {
713
+ throw new X402Error("No accounts returned from Pera Wallet", "WALLET_CONNECTION_REJECTED");
714
+ }
715
+ this.address = newAccounts[0];
716
+ this.peraWallet.connector?.on("disconnect", () => {
717
+ this.address = null;
718
+ });
719
+ return newAccounts[0];
720
+ } catch (error) {
721
+ if (error instanceof Error) {
722
+ if (error.message.includes("rejected") || error.message.includes("cancelled")) {
723
+ throw new X402Error("Connection rejected by user", "WALLET_CONNECTION_REJECTED");
724
+ }
725
+ }
726
+ throw new X402Error(
727
+ `Failed to connect Pera Wallet: ${error instanceof Error ? error.message : "Unknown error"}`,
728
+ "UNKNOWN_ERROR",
729
+ error
730
+ );
731
+ }
732
+ }
733
+ /**
734
+ * Disconnect from Pera Wallet
735
+ */
736
+ async disconnect() {
737
+ if (this.peraWallet) {
738
+ try {
739
+ await this.peraWallet.disconnect();
740
+ } catch {
741
+ }
742
+ }
743
+ this.peraWallet = null;
744
+ this.address = null;
745
+ this.algodClients.clear();
746
+ }
747
+ /**
748
+ * Get current address
749
+ */
750
+ getAddress() {
751
+ return this.address;
752
+ }
753
+ /**
754
+ * Get USDC (ASA) balance
755
+ */
756
+ async getBalance(chainConfig) {
757
+ await loadAlgorandDeps();
758
+ if (!this.address) {
759
+ throw new X402Error("Wallet not connected", "WALLET_NOT_CONNECTED");
760
+ }
761
+ const algodClient = await this.getAlgodClient(chainConfig);
762
+ const assetId = parseInt(chainConfig.usdc.address, 10);
763
+ try {
764
+ const accountInfo = await algodClient.accountInformation(this.address).do();
765
+ const assets = accountInfo.assets || accountInfo["assets"] || [];
766
+ const usdcAsset = assets.find(
767
+ (asset) => (asset.assetId || asset["asset-id"]) === assetId
768
+ );
769
+ if (!usdcAsset) {
770
+ return "0.00";
771
+ }
772
+ const amount = Number(usdcAsset.amount || usdcAsset["amount"]);
773
+ const balance = amount / Math.pow(10, chainConfig.usdc.decimals);
774
+ return balance.toFixed(2);
775
+ } catch {
776
+ return "0.00";
777
+ }
778
+ }
779
+ /**
780
+ * Create Algorand ASA transfer payment
781
+ *
782
+ * Transaction structure:
783
+ * 1. ASA Transfer from user to recipient
784
+ * 2. Facilitator pays transaction fees
785
+ */
786
+ async signPayment(paymentInfo, chainConfig) {
787
+ await loadAlgorandDeps();
788
+ if (!this.peraWallet || !this.address) {
789
+ throw new X402Error("Wallet not connected", "WALLET_NOT_CONNECTED");
790
+ }
791
+ if (!algosdk) {
792
+ throw new X402Error("Algorand SDK not loaded", "UNKNOWN_ERROR");
793
+ }
794
+ const algodClient = await this.getAlgodClient(chainConfig);
795
+ const recipient = paymentInfo.recipients?.algorand || paymentInfo.recipient;
796
+ const assetId = parseInt(chainConfig.usdc.address, 10);
797
+ const amount = Math.floor(parseFloat(paymentInfo.amount) * 1e6);
798
+ try {
799
+ const suggestedParams = await algodClient.getTransactionParams().do();
800
+ const txn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
801
+ sender: this.address,
802
+ receiver: recipient,
803
+ amount: BigInt(amount),
804
+ assetIndex: assetId,
805
+ suggestedParams,
806
+ note: new TextEncoder().encode("x402 payment via uvd-x402-sdk")
807
+ });
808
+ const signedTxns = await this.peraWallet.signTransaction([[{ txn }]]);
809
+ if (!signedTxns || signedTxns.length === 0) {
810
+ throw new X402Error("No signed transaction returned", "SIGNATURE_REJECTED");
811
+ }
812
+ const signedTxn = signedTxns[0];
813
+ const payload = {
814
+ from: this.address,
815
+ to: recipient,
816
+ amount: amount.toString(),
817
+ assetId,
818
+ signedTxn: uint8ArrayToBase64(signedTxn)
819
+ };
820
+ return JSON.stringify(payload);
821
+ } catch (error) {
822
+ if (error instanceof X402Error) {
823
+ throw error;
824
+ }
825
+ if (error instanceof Error) {
826
+ if (error.message.includes("rejected") || error.message.includes("cancelled")) {
827
+ throw new X402Error("Signature rejected by user", "SIGNATURE_REJECTED");
828
+ }
829
+ }
830
+ throw new X402Error(
831
+ `Failed to sign transaction: ${error instanceof Error ? error.message : "Unknown error"}`,
832
+ "PAYMENT_FAILED",
833
+ error
834
+ );
835
+ }
836
+ }
837
+ /**
838
+ * Encode Algorand payment as X-PAYMENT header
839
+ *
840
+ * @param paymentPayload - JSON-encoded payment payload from signPayment()
841
+ * @param chainConfig - Chain configuration
842
+ * @param version - x402 protocol version (1 or 2, defaults to 1)
843
+ * @returns Base64-encoded X-PAYMENT header value
844
+ */
845
+ encodePaymentHeader(paymentPayload, chainConfig, version = 1) {
846
+ const payload = JSON.parse(paymentPayload);
847
+ const networkName = chainConfig?.name || "algorand";
848
+ const payloadData = {
849
+ from: payload.from,
850
+ to: payload.to,
851
+ amount: payload.amount,
852
+ assetId: payload.assetId,
853
+ signedTxn: payload.signedTxn,
854
+ ...payload.note && { note: payload.note }
855
+ };
856
+ const x402Payload = version === 2 ? {
857
+ x402Version: 2,
858
+ scheme: "exact",
859
+ network: chainToCAIP2(networkName),
860
+ // CAIP-2 format for v2
861
+ payload: payloadData
862
+ } : {
863
+ x402Version: 1,
864
+ scheme: "exact",
865
+ network: networkName,
866
+ // Plain chain name for v1
867
+ payload: payloadData
868
+ };
869
+ return btoa(JSON.stringify(x402Payload));
870
+ }
871
+ // Private helpers
872
+ /**
873
+ * Get or create an Algod client for a specific chain
874
+ */
875
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
876
+ async getAlgodClient(chainConfig) {
877
+ await loadAlgorandDeps();
878
+ if (!algosdk) {
879
+ throw new X402Error("Algorand SDK not loaded", "UNKNOWN_ERROR");
880
+ }
881
+ const config = chainConfig || getChainByName("algorand");
882
+ if (!config) {
883
+ throw new X402Error("Chain config not found", "CHAIN_NOT_SUPPORTED");
884
+ }
885
+ const cacheKey = config.rpcUrl;
886
+ if (this.algodClients.has(cacheKey)) {
887
+ return this.algodClients.get(cacheKey);
888
+ }
889
+ const client = new algosdk.Algodv2("", config.rpcUrl, "");
890
+ this.algodClients.set(cacheKey, client);
891
+ return client;
892
+ }
893
+ };
894
+ var algorand_default = AlgorandProvider;
895
+
896
+ export { AlgorandProvider, algorand_default as default };
897
+ //# sourceMappingURL=index.mjs.map
898
+ //# sourceMappingURL=index.mjs.map