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