@voyage_ai/v402-web-ts 0.3.0 → 1.0.2

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.
@@ -0,0 +1,633 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __esm = (fn, res) => function __init() {
6
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
+ };
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/types/common.ts
23
+ var PROD_BACK_URL;
24
+ var init_common = __esm({
25
+ "src/types/common.ts"() {
26
+ "use strict";
27
+ PROD_BACK_URL = true ? "https://v402pay.onvoyage.ai/api/pay" : "https://v402pay.onvoyage.ai/api/pay";
28
+ }
29
+ });
30
+
31
+ // src/types/svm.ts
32
+ import { z } from "zod";
33
+ import { ExactSvmPayloadSchema } from "x402/types";
34
+ var SolanaNetworkSchema, SolanaPaymentPayloadSchema;
35
+ var init_svm = __esm({
36
+ "src/types/svm.ts"() {
37
+ "use strict";
38
+ SolanaNetworkSchema = z.enum([
39
+ "solana-devnet",
40
+ "solana",
41
+ "solana-mainnet"
42
+ // Alias for mainnet
43
+ ]);
44
+ SolanaPaymentPayloadSchema = z.object({
45
+ x402Version: z.literal(1),
46
+ scheme: z.literal("exact"),
47
+ network: SolanaNetworkSchema,
48
+ payload: ExactSvmPayloadSchema
49
+ });
50
+ }
51
+ });
52
+
53
+ // src/types/evm.ts
54
+ import { z as z2 } from "zod";
55
+ import { ExactEvmPayloadSchema } from "x402/types";
56
+ var EvmNetworkSchema, EvmPaymentPayloadSchema;
57
+ var init_evm = __esm({
58
+ "src/types/evm.ts"() {
59
+ "use strict";
60
+ EvmNetworkSchema = z2.enum([
61
+ "ethereum",
62
+ "sepolia",
63
+ "base",
64
+ "base-sepolia",
65
+ "polygon",
66
+ "arbitrum",
67
+ "optimism"
68
+ ]);
69
+ EvmPaymentPayloadSchema = z2.object({
70
+ x402Version: z2.literal(1),
71
+ scheme: z2.literal("exact"),
72
+ network: EvmNetworkSchema,
73
+ payload: ExactEvmPayloadSchema
74
+ });
75
+ }
76
+ });
77
+
78
+ // src/types/index.ts
79
+ import {
80
+ PaymentRequirementsSchema,
81
+ x402ResponseSchema,
82
+ VerifyResponseSchema,
83
+ SettleResponseSchema,
84
+ SupportedPaymentKindSchema,
85
+ SupportedPaymentKindsResponseSchema,
86
+ SupportedSVMNetworks,
87
+ SvmNetworkToChainId
88
+ } from "x402/types";
89
+ var init_types = __esm({
90
+ "src/types/index.ts"() {
91
+ "use strict";
92
+ init_svm();
93
+ init_evm();
94
+ }
95
+ });
96
+
97
+ // src/utils/wallet.ts
98
+ var wallet_exports = {};
99
+ __export(wallet_exports, {
100
+ clearAllWalletAddresses: () => clearAllWalletAddresses,
101
+ clearWalletDisconnection: () => clearWalletDisconnection,
102
+ formatAddress: () => formatAddress,
103
+ getAllConnectedWalletIds: () => getAllConnectedWalletIds,
104
+ getAllWalletAddresses: () => getAllWalletAddresses,
105
+ getCachedWalletAddress: () => getCachedWalletAddress,
106
+ getConnectedNetworkType: () => getConnectedNetworkType,
107
+ getConnectedWalletId: () => getConnectedWalletId,
108
+ getWalletDisplayName: () => getWalletDisplayName,
109
+ getWalletInstallUrl: () => getWalletInstallUrl,
110
+ getWalletProvider: () => getWalletProvider,
111
+ isWalletInstalled: () => isWalletInstalled,
112
+ isWalletManuallyDisconnected: () => isWalletManuallyDisconnected,
113
+ markWalletDisconnected: () => markWalletDisconnected,
114
+ removeConnectedWalletId: () => removeConnectedWalletId,
115
+ removeWalletAddress: () => removeWalletAddress,
116
+ saveConnectedNetworkType: () => saveConnectedNetworkType,
117
+ saveConnectedWalletId: () => saveConnectedWalletId,
118
+ saveWalletAddress: () => saveWalletAddress
119
+ });
120
+ function isWalletInstalled(networkType) {
121
+ if (typeof window === "undefined") {
122
+ return false;
123
+ }
124
+ switch (networkType) {
125
+ case "evm" /* EVM */:
126
+ return !!window.ethereum;
127
+ case "solana" /* SOLANA */:
128
+ case "svm" /* SVM */:
129
+ return !!window.solana || !!window.phantom;
130
+ default:
131
+ return false;
132
+ }
133
+ }
134
+ function getWalletProvider(networkType) {
135
+ if (typeof window === "undefined") {
136
+ return null;
137
+ }
138
+ switch (networkType) {
139
+ case "evm" /* EVM */:
140
+ return window.ethereum;
141
+ case "solana" /* SOLANA */:
142
+ case "svm" /* SVM */:
143
+ return window.solana || window.phantom;
144
+ default:
145
+ return null;
146
+ }
147
+ }
148
+ function formatAddress(address) {
149
+ if (!address || address.length < 10) {
150
+ return address;
151
+ }
152
+ return `${address.slice(0, 6)}...${address.slice(-4)}`;
153
+ }
154
+ function getDisconnectedNetworks() {
155
+ if (typeof window === "undefined") {
156
+ return {};
157
+ }
158
+ try {
159
+ const cached = localStorage.getItem(WALLET_DISCONNECTED_NETWORKS_KEY);
160
+ return cached ? JSON.parse(cached) : {};
161
+ } catch (error) {
162
+ return {};
163
+ }
164
+ }
165
+ function markWalletDisconnected(networkType) {
166
+ if (typeof window !== "undefined") {
167
+ if (networkType) {
168
+ const disconnected = getDisconnectedNetworks();
169
+ disconnected[networkType] = true;
170
+ localStorage.setItem(WALLET_DISCONNECTED_NETWORKS_KEY, JSON.stringify(disconnected));
171
+ } else {
172
+ localStorage.setItem(WALLET_DISCONNECTED_KEY, "true");
173
+ localStorage.removeItem(CONNECTED_NETWORK_TYPE_KEY);
174
+ }
175
+ }
176
+ }
177
+ function clearWalletDisconnection(networkType) {
178
+ if (typeof window !== "undefined") {
179
+ if (networkType) {
180
+ const disconnected = getDisconnectedNetworks();
181
+ delete disconnected[networkType];
182
+ localStorage.setItem(WALLET_DISCONNECTED_NETWORKS_KEY, JSON.stringify(disconnected));
183
+ } else {
184
+ localStorage.removeItem(WALLET_DISCONNECTED_KEY);
185
+ }
186
+ }
187
+ }
188
+ function isWalletManuallyDisconnected(networkType) {
189
+ if (typeof window === "undefined") {
190
+ return false;
191
+ }
192
+ if (networkType) {
193
+ const disconnected = getDisconnectedNetworks();
194
+ return disconnected[networkType] === true;
195
+ } else {
196
+ return localStorage.getItem(WALLET_DISCONNECTED_KEY) === "true";
197
+ }
198
+ }
199
+ function saveConnectedNetworkType(networkType) {
200
+ if (typeof window !== "undefined") {
201
+ localStorage.setItem(CONNECTED_NETWORK_TYPE_KEY, networkType);
202
+ }
203
+ }
204
+ function getConnectedNetworkType() {
205
+ if (typeof window === "undefined") {
206
+ return null;
207
+ }
208
+ const type = localStorage.getItem(CONNECTED_NETWORK_TYPE_KEY);
209
+ return type || null;
210
+ }
211
+ function getWalletInstallUrl(networkType) {
212
+ switch (networkType) {
213
+ case "evm" /* EVM */:
214
+ return "https://metamask.io/download/";
215
+ case "solana" /* SOLANA */:
216
+ case "svm" /* SVM */:
217
+ return "https://phantom.app/download";
218
+ default:
219
+ return "#";
220
+ }
221
+ }
222
+ function getWalletDisplayName(networkType) {
223
+ switch (networkType) {
224
+ case "evm" /* EVM */:
225
+ return "MetaMask";
226
+ case "solana" /* SOLANA */:
227
+ case "svm" /* SVM */:
228
+ return "Phantom";
229
+ default:
230
+ return "Unknown Wallet";
231
+ }
232
+ }
233
+ function getAllWalletAddresses() {
234
+ if (typeof window === "undefined") {
235
+ return {};
236
+ }
237
+ try {
238
+ const cached = localStorage.getItem(WALLET_ADDRESSES_KEY);
239
+ return cached ? JSON.parse(cached) : {};
240
+ } catch (error) {
241
+ console.error("Failed to parse wallet addresses cache:", error);
242
+ return {};
243
+ }
244
+ }
245
+ function saveWalletAddress(networkType, address) {
246
+ if (typeof window === "undefined") {
247
+ return;
248
+ }
249
+ const addresses = getAllWalletAddresses();
250
+ addresses[networkType] = address;
251
+ localStorage.setItem(WALLET_ADDRESSES_KEY, JSON.stringify(addresses));
252
+ }
253
+ function getCachedWalletAddress(networkType) {
254
+ const addresses = getAllWalletAddresses();
255
+ return addresses[networkType] || null;
256
+ }
257
+ function removeWalletAddress(networkType) {
258
+ if (typeof window === "undefined") {
259
+ return;
260
+ }
261
+ const addresses = getAllWalletAddresses();
262
+ delete addresses[networkType];
263
+ localStorage.setItem(WALLET_ADDRESSES_KEY, JSON.stringify(addresses));
264
+ }
265
+ function clearAllWalletAddresses() {
266
+ if (typeof window !== "undefined") {
267
+ localStorage.removeItem(WALLET_ADDRESSES_KEY);
268
+ }
269
+ }
270
+ function getAllConnectedWalletIds() {
271
+ if (typeof window === "undefined") {
272
+ return {};
273
+ }
274
+ try {
275
+ const cached = localStorage.getItem(CONNECTED_WALLET_IDS_KEY);
276
+ return cached ? JSON.parse(cached) : {};
277
+ } catch (error) {
278
+ console.error("Failed to parse connected wallet IDs:", error);
279
+ return {};
280
+ }
281
+ }
282
+ function saveConnectedWalletId(networkType, walletId) {
283
+ if (typeof window === "undefined") {
284
+ return;
285
+ }
286
+ const walletIds = getAllConnectedWalletIds();
287
+ walletIds[networkType] = walletId;
288
+ localStorage.setItem(CONNECTED_WALLET_IDS_KEY, JSON.stringify(walletIds));
289
+ }
290
+ function getConnectedWalletId(networkType) {
291
+ const walletIds = getAllConnectedWalletIds();
292
+ return walletIds[networkType] || null;
293
+ }
294
+ function removeConnectedWalletId(networkType) {
295
+ if (typeof window === "undefined") {
296
+ return;
297
+ }
298
+ const walletIds = getAllConnectedWalletIds();
299
+ delete walletIds[networkType];
300
+ localStorage.setItem(CONNECTED_WALLET_IDS_KEY, JSON.stringify(walletIds));
301
+ }
302
+ var WALLET_DISCONNECTED_KEY, WALLET_DISCONNECTED_NETWORKS_KEY, CONNECTED_NETWORK_TYPE_KEY, WALLET_ADDRESSES_KEY, CONNECTED_WALLET_IDS_KEY;
303
+ var init_wallet = __esm({
304
+ "src/utils/wallet.ts"() {
305
+ "use strict";
306
+ WALLET_DISCONNECTED_KEY = "wallet_manually_disconnected";
307
+ WALLET_DISCONNECTED_NETWORKS_KEY = "wallet_disconnected_networks";
308
+ CONNECTED_NETWORK_TYPE_KEY = "connected_network_type";
309
+ WALLET_ADDRESSES_KEY = "wallet_addresses_cache";
310
+ CONNECTED_WALLET_IDS_KEY = "connected_wallet_ids";
311
+ }
312
+ });
313
+
314
+ // src/utils/wallet-discovery.ts
315
+ init_wallet();
316
+ var SOLANA_WALLETS = [
317
+ {
318
+ id: "phantom",
319
+ name: "Phantom",
320
+ // Phantom official icon
321
+ icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTI4IiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZD0iTTExMC41IDY0QzExMC41IDg5Ljk1NjggODkuMjAxIDExMSA2My41IDExMUg0MS41QzM2LjI1MzMgMTExIDMyIDEwNi43NDcgMzIgMTAxLjVWNTQuNUMzMiAzMS4wMjggNTEuMDI4IDEyIDc0LjUgMTJDOTcuOTcyIDEyIDExNyAzMS4wMjggMTE3IDU0LjVWNTUuNUMxMTcgNTguNTM3NiAxMTQuNTM4IDYxIDExMS41IDYxSDEwOS41QzEwNi40NjIgNjEgMTA0IDYzLjQ2MjQgMTA0IDY2LjVWNjhDMTA0IDcxLjg2NiAxMDcuMTM0IDc1IDExMSA3NUgxMTEuNUMxMTQ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LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4IiByeD0iMjYiIGZpbGw9IiNGQzZEMDEiLz4KPHBhdGggZD0iTTk2IDY0TDY0IDMyTDMyIDY0TDY0IDk2TDk2IDY0WiIgZmlsbD0id2hpdGUiLz4KPC9zdmc+",
329
+ detect: () => window.solflare
330
+ },
331
+ {
332
+ id: "backpack",
333
+ name: "Backpack",
334
+ // Backpack icon (red coral color)
335
+ icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTI4IiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4IiByeD0iMjYiIGZpbGw9IiNFMzM0MzAiLz4KPHBhdGggZD0iTTQwIDQ4SDg4VjgwQzg4IDg4LjgzNjYgODAuODM2NiA5NiA3MiA5Nkg1NkM0Ny4xNjM0IDk2IDQwIDg4LjgzNjYgNDAgODBWNDhaIiBmaWxsPSJ3aGl0ZSIvPgo8cGF0aCBkPSJNNTIgMzJINzZWNDhINTJWMzJaIiBmaWxsPSJ3aGl0ZSIvPgo8L3N2Zz4=",
336
+ detect: () => window.backpack
337
+ },
338
+ {
339
+ id: "okx-solana",
340
+ name: "OKX Wallet",
341
+ // OKX icon
342
+ icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTI4IiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4IiByeD0iMjYiIGZpbGw9ImJsYWNrIi8+CjxyZWN0IHg9IjI0IiB5PSIyNCIgd2lkdGg9IjI0IiBoZWln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8+CjxyZWN0IHg9IjQ4IiB5PSI1NiIgd2lkdGg9IjMyIiBoZWlnaHQ9IjE2IiByeD0iNCIgZmlsbD0iIzAwNTJGRiIvPgo8L3N2Zz4=",
350
+ detect: () => window.coinbaseSolana
351
+ },
352
+ {
353
+ id: "trust-solana",
354
+ name: "Trust Wallet",
355
+ // Trust Wallet icon
356
+ icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTI4IiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4IiByeD0iMjYiIGZpbGw9IiMwNTAwRkYiLz4KPHBhdGggZD0iTTY0IDI0QzY0IDI0IDk2IDQwIDk2IDY0Qzk2IDg4IDY0IDEwNCA2NCAxMDRDNjQgMTA0IDMyIDg4IDMyIDY0QzMyIDQwIDY0IDI0IDY0IDI0WiIgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLXdpZHRoPSI2IiBmaWxsPSJub25lIi8+Cjwvc3ZnPg==",
357
+ detect: () => window.trustwallet?.solana
358
+ }
359
+ ];
360
+ var evmWallets = /* @__PURE__ */ new Map();
361
+ var evmDiscoveryListeners = /* @__PURE__ */ new Set();
362
+ var evmDiscoveryInitialized = false;
363
+ var currentConnectedWallet = null;
364
+ function initEVMWalletDiscovery() {
365
+ if (typeof window === "undefined" || evmDiscoveryInitialized) return;
366
+ evmDiscoveryInitialized = true;
367
+ window.addEventListener("eip6963:announceProvider", ((event) => {
368
+ const { info, provider } = event.detail;
369
+ evmWallets.set(info.uuid, { info, provider });
370
+ evmDiscoveryListeners.forEach((listener) => listener());
371
+ }));
372
+ window.dispatchEvent(new Event("eip6963:requestProvider"));
373
+ }
374
+ function getEVMWallets() {
375
+ const wallets = [];
376
+ const detectedNames = /* @__PURE__ */ new Set();
377
+ evmWallets.forEach((detail, uuid) => {
378
+ if (!detectedNames.has(detail.info.name)) {
379
+ wallets.push({
380
+ id: uuid,
381
+ name: detail.info.name,
382
+ icon: detail.info.icon,
383
+ networkType: "evm" /* EVM */,
384
+ provider: detail.provider,
385
+ installed: true
386
+ });
387
+ detectedNames.add(detail.info.name);
388
+ }
389
+ });
390
+ if (wallets.length === 0 && typeof window !== "undefined" && window.ethereum) {
391
+ const ethereum = window.ethereum;
392
+ const walletName = ethereum.isMetaMask ? "MetaMask" : ethereum.isCoinbaseWallet ? "Coinbase Wallet" : ethereum.isOkxWallet ? "OKX Wallet" : "Browser Wallet";
393
+ if (!detectedNames.has(walletName)) {
394
+ wallets.push({
395
+ id: "injected",
396
+ name: walletName,
397
+ icon: "",
398
+ // Will use first letter as avatar
399
+ networkType: "evm" /* EVM */,
400
+ provider: ethereum,
401
+ installed: true
402
+ });
403
+ }
404
+ }
405
+ return wallets;
406
+ }
407
+ function onEVMWalletsChanged(callback) {
408
+ evmDiscoveryListeners.add(callback);
409
+ return () => {
410
+ evmDiscoveryListeners.delete(callback);
411
+ };
412
+ }
413
+ function getSolanaWallets() {
414
+ if (typeof window === "undefined") return [];
415
+ const wallets = [];
416
+ const detectedProviders = /* @__PURE__ */ new Set();
417
+ const detectedNames = /* @__PURE__ */ new Set();
418
+ for (const wallet of SOLANA_WALLETS) {
419
+ const provider = wallet.detect();
420
+ if (provider && !detectedNames.has(wallet.name)) {
421
+ wallets.push({
422
+ id: wallet.id,
423
+ name: wallet.name,
424
+ icon: wallet.icon,
425
+ networkType: "solana" /* SOLANA */,
426
+ provider,
427
+ installed: true
428
+ });
429
+ detectedProviders.add(provider);
430
+ detectedNames.add(wallet.name);
431
+ }
432
+ }
433
+ const windowSolana = window.solana;
434
+ if (windowSolana && !detectedProviders.has(windowSolana)) {
435
+ const walletName = windowSolana.isPhantom ? "Phantom" : windowSolana.isSolflare ? "Solflare" : windowSolana.isBackpack ? "Backpack" : windowSolana.walletName || "Solana Wallet";
436
+ if (!detectedNames.has(walletName)) {
437
+ wallets.push({
438
+ id: "solana-unknown",
439
+ name: walletName,
440
+ icon: "",
441
+ // Will use first letter as avatar
442
+ networkType: "solana" /* SOLANA */,
443
+ provider: windowSolana,
444
+ installed: true
445
+ });
446
+ }
447
+ }
448
+ return wallets;
449
+ }
450
+ function getWalletsForNetwork(networkType) {
451
+ switch (networkType) {
452
+ case "evm" /* EVM */:
453
+ return getEVMWallets();
454
+ case "solana" /* SOLANA */:
455
+ case "svm" /* SVM */:
456
+ return getSolanaWallets();
457
+ default:
458
+ return [];
459
+ }
460
+ }
461
+ function getWalletById(id, networkType) {
462
+ const wallets = getWalletsForNetwork(networkType);
463
+ return wallets.find((w) => w.id === id) || null;
464
+ }
465
+ function getWalletByName(name, networkType) {
466
+ const wallets = getWalletsForNetwork(networkType);
467
+ return wallets.find((w) => w.name === name) || null;
468
+ }
469
+ async function connectEVMWallet(wallet) {
470
+ if (!wallet.provider) {
471
+ throw new Error(`Wallet ${wallet.name} is not available`);
472
+ }
473
+ const accounts = await wallet.provider.request({
474
+ method: "eth_requestAccounts",
475
+ params: []
476
+ });
477
+ if (!accounts || accounts.length === 0) {
478
+ throw new Error("Failed to get wallet address");
479
+ }
480
+ return accounts[0];
481
+ }
482
+ async function connectSolanaWallet(wallet) {
483
+ if (!wallet.provider) {
484
+ throw new Error(`Wallet ${wallet.name} is not available`);
485
+ }
486
+ if (wallet.provider.isConnected) {
487
+ try {
488
+ await wallet.provider.disconnect();
489
+ } catch (err) {
490
+ console.warn("Failed to disconnect before connecting:", err);
491
+ }
492
+ }
493
+ const response = await wallet.provider.connect();
494
+ return response.publicKey.toString();
495
+ }
496
+ async function connectToWallet(wallet) {
497
+ let address;
498
+ switch (wallet.networkType) {
499
+ case "evm" /* EVM */:
500
+ address = await connectEVMWallet(wallet);
501
+ break;
502
+ case "solana" /* SOLANA */:
503
+ case "svm" /* SVM */:
504
+ address = await connectSolanaWallet(wallet);
505
+ break;
506
+ default:
507
+ throw new Error("Unsupported network type");
508
+ }
509
+ currentConnectedWallet = wallet;
510
+ saveConnectedWalletId(wallet.networkType, wallet.name);
511
+ return address;
512
+ }
513
+ function getCurrentConnectedWallet() {
514
+ return currentConnectedWallet;
515
+ }
516
+ function setCurrentConnectedWallet(wallet) {
517
+ currentConnectedWallet = wallet;
518
+ }
519
+ function clearConnectedWallet(networkType) {
520
+ if (networkType) {
521
+ removeConnectedWalletId(networkType);
522
+ }
523
+ currentConnectedWallet = null;
524
+ }
525
+ function restoreConnectedWallet(networkType) {
526
+ const savedWalletName = getConnectedWalletId(networkType);
527
+ if (!savedWalletName) {
528
+ return null;
529
+ }
530
+ const wallet = getWalletByName(savedWalletName, networkType);
531
+ if (wallet) {
532
+ currentConnectedWallet = wallet;
533
+ if ((networkType === "solana" /* SOLANA */ || networkType === "svm" /* SVM */) && wallet.provider) {
534
+ const providerPublicKey = wallet.provider.publicKey?.toString();
535
+ const cachedAddress = getCachedWalletAddress(networkType);
536
+ if (providerPublicKey && cachedAddress && providerPublicKey !== cachedAddress) {
537
+ saveWalletAddress(networkType, providerPublicKey);
538
+ }
539
+ }
540
+ return wallet;
541
+ }
542
+ return null;
543
+ }
544
+ function getWalletProviderForPayment(networkType) {
545
+ if (currentConnectedWallet && currentConnectedWallet.networkType === networkType) {
546
+ return currentConnectedWallet.provider;
547
+ }
548
+ const restoredWallet = restoreConnectedWallet(networkType);
549
+ if (restoredWallet) {
550
+ return restoredWallet.provider;
551
+ }
552
+ if (typeof window === "undefined") return null;
553
+ switch (networkType) {
554
+ case "evm" /* EVM */:
555
+ return window.ethereum;
556
+ case "solana" /* SOLANA */:
557
+ case "svm" /* SVM */:
558
+ return window.phantom?.solana || window.solana;
559
+ default:
560
+ return null;
561
+ }
562
+ }
563
+ async function getValidatedWalletProvider(networkType, expectedAddress) {
564
+ const provider = getWalletProviderForPayment(networkType);
565
+ if (!provider) {
566
+ return { provider: null, isValid: false };
567
+ }
568
+ if (networkType === "evm" /* EVM */) {
569
+ try {
570
+ const accounts = await provider.request({ method: "eth_accounts", params: [] });
571
+ const currentAddress = accounts?.[0];
572
+ const isValid = currentAddress?.toLowerCase() === expectedAddress?.toLowerCase();
573
+ if (!isValid) {
574
+ console.warn(`\u26A0\uFE0F Account mismatch: expected ${expectedAddress}, got ${currentAddress}`);
575
+ }
576
+ return { provider, isValid, currentAddress };
577
+ } catch (error) {
578
+ console.error("Failed to get current account:", error);
579
+ return { provider, isValid: false };
580
+ }
581
+ }
582
+ if (networkType === "solana" /* SOLANA */ || networkType === "svm" /* SVM */) {
583
+ if (provider.isConnected && provider.publicKey) {
584
+ const currentAddress = provider.publicKey.toString();
585
+ const isValid = currentAddress === expectedAddress;
586
+ if (!isValid) {
587
+ console.warn(`\u26A0\uFE0F Account mismatch: expected ${expectedAddress}, got ${currentAddress}`);
588
+ }
589
+ return { provider, isValid, currentAddress };
590
+ }
591
+ return { provider, isValid: false };
592
+ }
593
+ return { provider, isValid: true };
594
+ }
595
+ if (typeof window !== "undefined") {
596
+ initEVMWalletDiscovery();
597
+ }
598
+
599
+ export {
600
+ __toCommonJS,
601
+ PROD_BACK_URL,
602
+ init_common,
603
+ SolanaNetworkSchema,
604
+ EvmNetworkSchema,
605
+ init_types,
606
+ formatAddress,
607
+ markWalletDisconnected,
608
+ clearWalletDisconnection,
609
+ isWalletManuallyDisconnected,
610
+ saveConnectedNetworkType,
611
+ getConnectedNetworkType,
612
+ saveWalletAddress,
613
+ getCachedWalletAddress,
614
+ removeWalletAddress,
615
+ wallet_exports,
616
+ init_wallet,
617
+ initEVMWalletDiscovery,
618
+ getEVMWallets,
619
+ onEVMWalletsChanged,
620
+ getSolanaWallets,
621
+ getWalletsForNetwork,
622
+ getWalletById,
623
+ getWalletByName,
624
+ connectEVMWallet,
625
+ connectSolanaWallet,
626
+ connectToWallet,
627
+ getCurrentConnectedWallet,
628
+ setCurrentConnectedWallet,
629
+ clearConnectedWallet,
630
+ getWalletProviderForPayment,
631
+ getValidatedWalletProvider
632
+ };
633
+ //# sourceMappingURL=chunk-WDPIFLXY.mjs.map