@tomo-inc/wallet-connect-protocol 0.0.5 → 0.0.6

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,828 @@
1
+ 'use strict';
2
+
3
+ var SignClient = require('@walletconnect/sign-client');
4
+ var QRCode = require('qrcode');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var SignClient__default = /*#__PURE__*/_interopDefault(SignClient);
9
+ var QRCode__default = /*#__PURE__*/_interopDefault(QRCode);
10
+
11
+ // src/client.ts
12
+ var WalletConnectClient = class {
13
+ signClient = null;
14
+ config;
15
+ eventHandlers = /* @__PURE__ */ new Map();
16
+ initialized = false;
17
+ constructor(config) {
18
+ this.config = config;
19
+ }
20
+ /**
21
+ * initialize WalletConnect client
22
+ */
23
+ async initialize() {
24
+ if (this.initialized) {
25
+ return;
26
+ }
27
+ try {
28
+ this.signClient = await SignClient__default.default.init({
29
+ projectId: this.config.projectId,
30
+ metadata: this.config.metadata,
31
+ relayUrl: this.config.relayUrl
32
+ });
33
+ this.setupEventListeners();
34
+ this.initialized = true;
35
+ } catch (error) {
36
+ throw error;
37
+ }
38
+ }
39
+ /**
40
+ * set event listeners
41
+ */
42
+ setupEventListeners() {
43
+ if (!this.signClient) return;
44
+ this.signClient.on("session_proposal", (proposal) => {
45
+ this.emit("session_proposal", proposal);
46
+ });
47
+ this.signClient.on("session_request", (request) => {
48
+ this.emit("session_request", request);
49
+ });
50
+ this.signClient.on("session_delete", (data) => {
51
+ this.emit("session_delete", data);
52
+ });
53
+ this.signClient.on("session_update", (data) => {
54
+ this.emit("session_update", data);
55
+ });
56
+ }
57
+ /**
58
+ * create pairing connection and generate URI
59
+ * @param params connection parameters
60
+ * @returns WalletConnect URI
61
+ */
62
+ async connect(params) {
63
+ if (!this.signClient) {
64
+ throw new Error("WalletConnect client not initialized. Call initialize() first.");
65
+ }
66
+ try {
67
+ const defaultNamespaces = {
68
+ eip155: {
69
+ methods: [
70
+ "eth_sendTransaction",
71
+ "eth_signTransaction",
72
+ "eth_sign",
73
+ "personal_sign",
74
+ "eth_signTypedData",
75
+ "eth_signTypedData_v4"
76
+ ],
77
+ chains: ["eip155:1"],
78
+ // Ethereum Mainnet
79
+ events: ["chainChanged", "accountsChanged"]
80
+ }
81
+ };
82
+ const defaultOptionalNamespaces = {
83
+ eip155: {
84
+ methods: [
85
+ "eth_sendTransaction",
86
+ "eth_signTransaction",
87
+ "eth_sign",
88
+ "personal_sign",
89
+ "eth_signTypedData",
90
+ "eth_signTypedData_v4"
91
+ ],
92
+ chains: [
93
+ "eip155:137",
94
+ // Polygon Mainnet
95
+ "eip155:56",
96
+ // BSC Mainnet
97
+ "eip155:42161",
98
+ // Arbitrum Mainnet
99
+ "eip155:10",
100
+ // Optimism Mainnet
101
+ "eip155:43114"
102
+ // Avalanche Mainnet
103
+ ],
104
+ events: ["chainChanged", "accountsChanged"]
105
+ },
106
+ solana: {
107
+ methods: ["solana_signTransaction", "solana_signMessage"],
108
+ chains: ["solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ"],
109
+ events: ["accountsChanged"]
110
+ }
111
+ };
112
+ const { uri, approval } = await this.signClient.connect({
113
+ requiredNamespaces: params?.requiredNamespaces || defaultNamespaces,
114
+ optionalNamespaces: params?.optionalNamespaces || defaultOptionalNamespaces
115
+ });
116
+ if (!uri) {
117
+ throw new Error("Failed to generate WalletConnect URI");
118
+ }
119
+ this.emit("display_uri", { uri });
120
+ approval().then((session) => {
121
+ this.emit("session_update", session);
122
+ }).catch((error) => {
123
+ });
124
+ return uri;
125
+ } catch (error) {
126
+ throw error;
127
+ }
128
+ }
129
+ /**
130
+ * generate QR code (Base64 format)
131
+ * @param uri WalletConnect URI
132
+ * @param options QR code options
133
+ * @returns Base64 formatted QR code image
134
+ */
135
+ async generateQRCode(uri, options) {
136
+ try {
137
+ const qrOptions = {
138
+ width: options?.width || 300,
139
+ margin: options?.margin || 4,
140
+ errorCorrectionLevel: options?.errorCorrectionLevel || "M",
141
+ color: {
142
+ dark: options?.color?.dark || "#000000",
143
+ light: options?.color?.light || "#ffffff"
144
+ }
145
+ };
146
+ const qrCodeDataUrl = await QRCode__default.default.toDataURL(uri, qrOptions);
147
+ return qrCodeDataUrl;
148
+ } catch (error) {
149
+ throw error;
150
+ }
151
+ }
152
+ /**
153
+ * generate QR code (Canvas format)
154
+ * @param canvas Canvas element
155
+ * @param uri WalletConnect URI
156
+ * @param options QR code options
157
+ */
158
+ async generateQRCodeToCanvas(canvas, uri, options) {
159
+ try {
160
+ const qrOptions = {
161
+ width: options?.width || 300,
162
+ margin: options?.margin || 4,
163
+ errorCorrectionLevel: options?.errorCorrectionLevel || "M",
164
+ color: {
165
+ dark: options?.color?.dark || "#000000",
166
+ light: options?.color?.light || "#ffffff"
167
+ }
168
+ };
169
+ await QRCode__default.default.toCanvas(canvas, uri, qrOptions);
170
+ } catch (error) {
171
+ throw error;
172
+ }
173
+ }
174
+ /**
175
+ * get all active sessions
176
+ * @returns session information array
177
+ */
178
+ getActiveSessions() {
179
+ if (!this.signClient) {
180
+ return [];
181
+ }
182
+ const sessions = this.signClient.session.getAll();
183
+ return sessions.map((session) => ({
184
+ topic: session.topic,
185
+ peer: session.peer,
186
+ namespaces: session.namespaces,
187
+ expiry: session.expiry
188
+ }));
189
+ }
190
+ /**
191
+ * disconnect specified session
192
+ * @param topic session topic/ID
193
+ */
194
+ async disconnectSession(topic) {
195
+ if (!this.signClient) {
196
+ throw new Error("WalletConnect client not initialized");
197
+ }
198
+ try {
199
+ await this.signClient.disconnect({
200
+ topic,
201
+ reason: {
202
+ code: 6e3,
203
+ message: "User disconnected"
204
+ }
205
+ });
206
+ } catch (error) {
207
+ throw error;
208
+ }
209
+ }
210
+ /**
211
+ * listen to events
212
+ * @param event event name
213
+ * @param handler event handler
214
+ */
215
+ on(event, handler) {
216
+ if (!this.eventHandlers.has(event)) {
217
+ this.eventHandlers.set(event, /* @__PURE__ */ new Set());
218
+ }
219
+ this.eventHandlers.get(event)?.add(handler);
220
+ }
221
+ /**
222
+ * remove event listener
223
+ * @param event event name
224
+ * @param handler event handler
225
+ */
226
+ off(event, handler) {
227
+ this.eventHandlers.get(event)?.delete(handler);
228
+ }
229
+ /**
230
+ * trigger event
231
+ * @param event event name
232
+ * @param data event data
233
+ */
234
+ emit(event, data) {
235
+ const handlers = this.eventHandlers.get(event);
236
+ if (handlers) {
237
+ handlers.forEach((handler) => {
238
+ try {
239
+ handler(data);
240
+ } catch (error) {
241
+ }
242
+ });
243
+ }
244
+ }
245
+ /**
246
+ * send JSON-RPC request to wallet
247
+ * @param params request parameters
248
+ * @returns request result
249
+ */
250
+ async sendRequest(params) {
251
+ if (!this.signClient) {
252
+ throw new Error("WalletConnect client not initialized");
253
+ }
254
+ try {
255
+ const result = await this.signClient.request({
256
+ topic: params.topic,
257
+ chainId: params.chainId,
258
+ request: params.request
259
+ });
260
+ return result;
261
+ } catch (error) {
262
+ throw error;
263
+ }
264
+ }
265
+ /**
266
+ * destroy client
267
+ */
268
+ async destroy() {
269
+ if (this.signClient) {
270
+ this.eventHandlers.clear();
271
+ this.signClient = null;
272
+ this.initialized = false;
273
+ }
274
+ }
275
+ /**
276
+ * get if client is initialized
277
+ */
278
+ isInitialized() {
279
+ return this.initialized;
280
+ }
281
+ /**
282
+ * get configuration information
283
+ */
284
+ getConfig() {
285
+ return { ...this.config };
286
+ }
287
+ };
288
+
289
+ // src/utils.ts
290
+ function isValidWalletConnectUri(uri) {
291
+ return uri.startsWith("wc:") || uri.startsWith("wc://");
292
+ }
293
+ function parseWalletConnectUri(uri) {
294
+ try {
295
+ const cleanUri = uri.replace(/^wc:\/?\/?/, "");
296
+ const [topicVersion, paramsString] = cleanUri.split("?");
297
+ const [topic, version] = topicVersion.split("@");
298
+ const params = new URLSearchParams(paramsString);
299
+ return {
300
+ topic,
301
+ version,
302
+ symKey: params.get("symKey") || void 0,
303
+ relay: params.get("relay-protocol") ? {
304
+ protocol: params.get("relay-protocol"),
305
+ data: params.get("relay-data") || void 0
306
+ } : void 0
307
+ };
308
+ } catch {
309
+ return null;
310
+ }
311
+ }
312
+ function formatAddress(address, startLength = 6, endLength = 4) {
313
+ if (!address || address.length < startLength + endLength) {
314
+ return address;
315
+ }
316
+ return `${address.slice(0, startLength)}...${address.slice(-endLength)}`;
317
+ }
318
+ function extractAddressFromAccount(account) {
319
+ const parts = account.split(":");
320
+ return parts.length > 1 ? parts[parts.length - 1] : account;
321
+ }
322
+ function extractChainIdFromAccount(account) {
323
+ const parts = account.split(":");
324
+ return parts.length > 2 ? `${parts[0]}:${parts[1]}` : "";
325
+ }
326
+ function isSessionExpired(expiry) {
327
+ return Date.now() / 1e3 > expiry;
328
+ }
329
+ function getSessionTimeRemaining(expiry) {
330
+ const remaining = expiry - Date.now() / 1e3;
331
+ return Math.max(0, remaining);
332
+ }
333
+ function formatTimestamp(timestamp) {
334
+ const date = new Date(timestamp * 1e3);
335
+ return date.toLocaleString();
336
+ }
337
+ function isMobile() {
338
+ if (typeof window === "undefined") return false;
339
+ return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
340
+ }
341
+ function generateDeepLink(uri, walletName) {
342
+ const encodedUri = encodeURIComponent(uri);
343
+ if (walletName) {
344
+ switch (walletName.toLowerCase()) {
345
+ case "metamask":
346
+ return `https://metamask.app.link/wc?uri=${encodedUri}`;
347
+ case "trust":
348
+ return `https://link.trustwallet.com/wc?uri=${encodedUri}`;
349
+ case "rainbow":
350
+ return `https://rnbwapp.com/wc?uri=${encodedUri}`;
351
+ default:
352
+ return `wc://wc?uri=${encodedUri}`;
353
+ }
354
+ }
355
+ return `wc://wc?uri=${encodedUri}`;
356
+ }
357
+ async function copyToClipboard(text) {
358
+ try {
359
+ if (navigator.clipboard) {
360
+ await navigator.clipboard.writeText(text);
361
+ return true;
362
+ } else {
363
+ const textarea = document.createElement("textarea");
364
+ textarea.value = text;
365
+ textarea.style.position = "fixed";
366
+ textarea.style.opacity = "0";
367
+ document.body.appendChild(textarea);
368
+ textarea.select();
369
+ const success = document.execCommand("copy");
370
+ document.body.removeChild(textarea);
371
+ return success;
372
+ }
373
+ } catch {
374
+ return false;
375
+ }
376
+ }
377
+ function formatError(error) {
378
+ if (typeof error === "string") return error;
379
+ if (error?.message) return error.message;
380
+ if (error?.error?.message) return error.error.message;
381
+ return "Unknown error occurred";
382
+ }
383
+ function isValidChainId(chainId) {
384
+ return /^[a-z]+:\d+$/.test(chainId);
385
+ }
386
+ function parseChainId(chainId) {
387
+ if (!isValidChainId(chainId)) return null;
388
+ const [namespace, reference] = chainId.split(":");
389
+ return { namespace, reference };
390
+ }
391
+
392
+ // src/chains.ts
393
+ var EIP155_NAMESPACE = {
394
+ chains: ["eip155:1"],
395
+ // Ethereum Mainnet
396
+ methods: [
397
+ "eth_sendTransaction",
398
+ "eth_signTransaction",
399
+ "eth_sign",
400
+ "personal_sign",
401
+ "eth_signTypedData",
402
+ "eth_signTypedData_v4",
403
+ "wallet_switchEthereumChain",
404
+ "wallet_addEthereumChain"
405
+ ],
406
+ events: ["chainChanged", "accountsChanged"]
407
+ };
408
+ var SOLANA_NAMESPACE = {
409
+ chains: ["solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ"],
410
+ // Solana Mainnet
411
+ methods: ["solana_signTransaction", "solana_signMessage", "solana_signAndSendTransaction"],
412
+ events: ["accountsChanged", "chainChanged"]
413
+ };
414
+ var APTOS_NAMESPACE = {
415
+ chains: ["aptos:1"],
416
+ // Aptos Mainnet
417
+ methods: ["aptos_signTransaction", "aptos_signMessage", "aptos_signAndSubmitTransaction"],
418
+ events: ["accountChanged", "networkChanged"]
419
+ };
420
+ var COSMOS_NAMESPACE = {
421
+ chains: ["cosmos:cosmoshub-4"],
422
+ // Cosmos Hub
423
+ methods: ["cosmos_signDirect", "cosmos_signAmino", "cosmos_getAccounts"],
424
+ events: ["chainChanged", "accountsChanged"]
425
+ };
426
+ var POLKADOT_NAMESPACE = {
427
+ chains: ["polkadot:91b171bb158e2d3848fa23a9f1c25182"],
428
+ // Polkadot Mainnet
429
+ methods: ["polkadot_signTransaction", "polkadot_signMessage"],
430
+ events: ["accountsChanged"]
431
+ };
432
+ var NEAR_NAMESPACE = {
433
+ chains: ["near:mainnet"],
434
+ methods: ["near_signTransaction", "near_signMessage"],
435
+ events: ["accountsChanged"]
436
+ };
437
+ var EVM_CHAINS = {
438
+ // Ethereum
439
+ ETHEREUM_MAINNET: "eip155:1",
440
+ ETHEREUM_GOERLI: "eip155:5",
441
+ ETHEREUM_SEPOLIA: "eip155:11155111",
442
+ // Layer 2 (L2)
443
+ POLYGON: "eip155:137",
444
+ POLYGON_MUMBAI: "eip155:80001",
445
+ ARBITRUM: "eip155:42161",
446
+ ARBITRUM_GOERLI: "eip155:421613",
447
+ OPTIMISM: "eip155:10",
448
+ OPTIMISM_GOERLI: "eip155:420",
449
+ // other EVM chains
450
+ BSC: "eip155:56",
451
+ BSC_TESTNET: "eip155:97",
452
+ AVALANCHE: "eip155:43114",
453
+ AVALANCHE_FUJI: "eip155:43113",
454
+ FANTOM: "eip155:250",
455
+ CRONOS: "eip155:25",
456
+ GNOSIS: "eip155:100",
457
+ BASE: "eip155:8453",
458
+ ZKSYNC: "eip155:324",
459
+ LINEA: "eip155:59144",
460
+ SCROLL: "eip155:534352"
461
+ };
462
+ var SOLANA_CHAINS = {
463
+ MAINNET: "solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ",
464
+ DEVNET: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
465
+ TESTNET: "solana:8E9rvCKLFQia2Y35HXjjpWzj8weVo44K"
466
+ };
467
+ var APTOS_CHAINS = {
468
+ MAINNET: "aptos:1",
469
+ TESTNET: "aptos:2",
470
+ DEVNET: "aptos:3"
471
+ };
472
+ function createMultiChainNamespaces(chains) {
473
+ const namespaces = {};
474
+ const evmChains = chains.filter((chain) => chain.startsWith("eip155:"));
475
+ if (evmChains.length > 0) {
476
+ namespaces.eip155 = {
477
+ ...EIP155_NAMESPACE,
478
+ chains: evmChains
479
+ };
480
+ }
481
+ const solanaChains = chains.filter((chain) => chain.startsWith("solana:"));
482
+ if (solanaChains.length > 0) {
483
+ namespaces.solana = {
484
+ ...SOLANA_NAMESPACE,
485
+ chains: solanaChains
486
+ };
487
+ }
488
+ const aptosChains = chains.filter((chain) => chain.startsWith("aptos:"));
489
+ if (aptosChains.length > 0) {
490
+ namespaces.aptos = {
491
+ ...APTOS_NAMESPACE,
492
+ chains: aptosChains
493
+ };
494
+ }
495
+ const cosmosChains = chains.filter((chain) => chain.startsWith("cosmos:"));
496
+ if (cosmosChains.length > 0) {
497
+ namespaces.cosmos = {
498
+ ...COSMOS_NAMESPACE,
499
+ chains: cosmosChains
500
+ };
501
+ }
502
+ return namespaces;
503
+ }
504
+
505
+ // src/siwe.ts
506
+ async function getChecksumAddress(address) {
507
+ try {
508
+ const ethers = await import('ethers');
509
+ return ethers.getAddress(address);
510
+ } catch {
511
+ return address;
512
+ }
513
+ }
514
+ async function createSiweMessage(config, address) {
515
+ const siweModule = await import('siwe');
516
+ const SiweMessage = siweModule.SiweMessage || siweModule.default?.SiweMessage;
517
+ const checksumAddress = await getChecksumAddress(address);
518
+ const siweMessage = new SiweMessage({
519
+ domain: config.domain,
520
+ address: checksumAddress,
521
+ statement: config.statement || "Sign in with Ethereum to the app.",
522
+ uri: config.uri,
523
+ version: config.version || "1",
524
+ chainId: config.chainId,
525
+ nonce: config.nonce || generateNonce(),
526
+ issuedAt: config.issuedAt || (/* @__PURE__ */ new Date()).toISOString(),
527
+ expirationTime: config.expirationTime,
528
+ notBefore: config.notBefore,
529
+ requestId: config.requestId,
530
+ resources: config.resources
531
+ });
532
+ return siweMessage.prepareMessage();
533
+ }
534
+ async function parseSiweMessage(message) {
535
+ const siweModule = await import('siwe');
536
+ const SiweMessage = siweModule.SiweMessage || siweModule.default?.SiweMessage;
537
+ return new SiweMessage(message);
538
+ }
539
+ async function verifySiweSignature(params) {
540
+ try {
541
+ const siweModule = await import('siwe');
542
+ const SiweMessage = siweModule.SiweMessage || siweModule.default?.SiweMessage;
543
+ const siweMessage = new SiweMessage(params.message);
544
+ const result = await siweMessage.verify(
545
+ {
546
+ signature: params.signature,
547
+ nonce: params.nonce,
548
+ domain: params.domain,
549
+ time: params.time
550
+ },
551
+ {
552
+ suppressExceptions: true
553
+ // Suppress exceptions to get error details
554
+ }
555
+ );
556
+ if (result.success) {
557
+ return {
558
+ success: true,
559
+ data: result.data
560
+ };
561
+ } else {
562
+ return {
563
+ success: false,
564
+ error: result.error?.type || "Verification failed"
565
+ };
566
+ }
567
+ } catch (error) {
568
+ return {
569
+ success: false,
570
+ error: error.type || error.message || "Unknown verification error"
571
+ };
572
+ }
573
+ }
574
+ function generateNonce(length = 16) {
575
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
576
+ let nonce = "";
577
+ const randomValues = new Uint8Array(length);
578
+ if (typeof window !== "undefined" && window.crypto) {
579
+ window.crypto.getRandomValues(randomValues);
580
+ } else if (typeof globalThis !== "undefined" && globalThis.crypto) {
581
+ globalThis.crypto.getRandomValues(randomValues);
582
+ } else {
583
+ for (let i = 0; i < length; i++) {
584
+ randomValues[i] = Math.floor(Math.random() * 256);
585
+ }
586
+ }
587
+ for (let i = 0; i < length; i++) {
588
+ nonce += chars[randomValues[i] % chars.length];
589
+ }
590
+ return nonce;
591
+ }
592
+ function createSiweConfigFromSession(params) {
593
+ return {
594
+ domain: params.domain,
595
+ uri: params.uri,
596
+ chainId: params.chainId,
597
+ statement: params.statement || "Sign in with Ethereum to authenticate your wallet.",
598
+ version: "1",
599
+ nonce: generateNonce(),
600
+ issuedAt: (/* @__PURE__ */ new Date()).toISOString(),
601
+ expirationTime: new Date(Date.now() + 5 * 60 * 1e3).toISOString(),
602
+ // 5 minutes
603
+ resources: params.resources
604
+ };
605
+ }
606
+ var SiweAuth = class {
607
+ config;
608
+ constructor(config) {
609
+ this.config = {
610
+ ...config,
611
+ nonce: generateNonce(),
612
+ issuedAt: (/* @__PURE__ */ new Date()).toISOString()
613
+ };
614
+ }
615
+ /**
616
+ * Create the message to sign
617
+ */
618
+ async createMessage(address) {
619
+ return createSiweMessage(this.config, address);
620
+ }
621
+ /**
622
+ * Verify the signature
623
+ */
624
+ async verify(message, signature) {
625
+ return verifySiweSignature({
626
+ message,
627
+ signature,
628
+ nonce: this.config.nonce,
629
+ domain: this.config.domain
630
+ });
631
+ }
632
+ /**
633
+ * Get the nonce
634
+ */
635
+ getNonce() {
636
+ return this.config.nonce || "";
637
+ }
638
+ /**
639
+ * Refresh nonce (for new sign-in attempts)
640
+ */
641
+ refreshNonce() {
642
+ this.config.nonce = generateNonce();
643
+ this.config.issuedAt = (/* @__PURE__ */ new Date()).toISOString();
644
+ }
645
+ };
646
+
647
+ // src/wallets.ts
648
+ var EXPLORER_API_URL = "https://explorer-api.walletconnect.com";
649
+ async function getWalletConnectWallets(options = {}) {
650
+ const { projectId, entries = 100, page = 1, search, chains, include, exclude, recommendedIds } = options;
651
+ const params = new URLSearchParams();
652
+ if (projectId) {
653
+ params.append("projectId", projectId);
654
+ }
655
+ params.append("entries", entries.toString());
656
+ params.append("page", page.toString());
657
+ if (search) {
658
+ params.append("search", search);
659
+ }
660
+ if (chains) {
661
+ params.append("chains", chains);
662
+ }
663
+ if (include) {
664
+ params.append("include", include);
665
+ }
666
+ if (exclude) {
667
+ params.append("exclude", exclude);
668
+ }
669
+ if (recommendedIds) {
670
+ params.append("recommendedIds", recommendedIds);
671
+ }
672
+ const url = `${EXPLORER_API_URL}/v3/wallets?${params.toString()}`;
673
+ try {
674
+ const response = await fetch(url);
675
+ if (!response.ok) {
676
+ throw new Error(`Failed to fetch wallets: ${response.statusText}`);
677
+ }
678
+ const data = await response.json();
679
+ return data;
680
+ } catch (error) {
681
+ throw error;
682
+ }
683
+ }
684
+ async function getAllWallets(options = {}) {
685
+ const allWallets = [];
686
+ let page = 1;
687
+ let hasMore = true;
688
+ while (hasMore) {
689
+ const response = await getWalletConnectWallets({
690
+ ...options,
691
+ page,
692
+ entries: 100
693
+ });
694
+ allWallets.push(...response.data);
695
+ hasMore = response.data.length === 100;
696
+ page++;
697
+ }
698
+ return allWallets;
699
+ }
700
+ async function getWalletById(walletId, projectId) {
701
+ const params = new URLSearchParams();
702
+ if (projectId) {
703
+ params.append("projectId", projectId);
704
+ }
705
+ const url = `${EXPLORER_API_URL}/v3/wallets/${walletId}?${params.toString()}`;
706
+ try {
707
+ const response = await fetch(url);
708
+ if (!response.ok) {
709
+ if (response.status === 404) {
710
+ return null;
711
+ }
712
+ throw new Error(`Failed to fetch wallet: ${response.statusText}`);
713
+ }
714
+ return await response.json();
715
+ } catch (error) {
716
+ return null;
717
+ }
718
+ }
719
+ async function searchWallets(query, options = {}) {
720
+ const response = await getWalletConnectWallets({
721
+ ...options,
722
+ search: query
723
+ });
724
+ return response.data;
725
+ }
726
+ async function getWalletsByChain(chainId, options = {}) {
727
+ const response = await getWalletConnectWallets({
728
+ ...options,
729
+ chains: chainId
730
+ });
731
+ return response.data;
732
+ }
733
+ async function getRecommendedWallets(walletIds, options = {}) {
734
+ const response = await getWalletConnectWallets({
735
+ ...options,
736
+ recommendedIds: walletIds.join(",")
737
+ });
738
+ return response.data;
739
+ }
740
+ async function getMobileWallets(options = {}) {
741
+ const response = await getWalletConnectWallets(options);
742
+ return response.data.filter((wallet) => wallet.mobile || wallet.app?.ios || wallet.app?.android);
743
+ }
744
+ async function getDesktopWallets(options = {}) {
745
+ const response = await getWalletConnectWallets(options);
746
+ return response.data.filter(
747
+ (wallet) => wallet.desktop || wallet.app?.mac || wallet.app?.windows || wallet.app?.linux
748
+ );
749
+ }
750
+ async function getBrowserWallets(options = {}) {
751
+ const response = await getWalletConnectWallets(options);
752
+ return response.data.filter(
753
+ (wallet) => wallet.app?.chrome || wallet.app?.firefox || wallet.app?.safari || wallet.app?.edge
754
+ );
755
+ }
756
+ var POPULAR_WALLET_IDS = {
757
+ METAMASK: "c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96",
758
+ TRUST: "4622a2b2d6af1c9844944291e5e7351a6aa24cd7b23099efac1b2fd875da31a0",
759
+ RAINBOW: "1ae92b26df02f0abca6304df07debccd18262fdf5fe82daa81593582dac9a369",
760
+ COINBASE: "fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa",
761
+ SAFE: "225affb176778569276e484e1b92637ad061b01e13a048b35a9d280c3b58970f",
762
+ ARGENT: "bc949c5d968ae81310268bf9193f9c9fb7bb4e1283e1284af8f2bd4992535fd6",
763
+ ZERION: "ecc4036f814562b41a5268adc86270fba1365471402006302e70169465b7ac18",
764
+ IMTOKEN: "ef333840daf915aafdc4a004525502d6d49d77bd9c65e0642dbaefb3c2893bef",
765
+ OKX: "971e689d0a5be527bac79629b4ee9b925e82208e5168b733496a09c0faed0709",
766
+ PHANTOM: "a797aa35c0fadbfc1a53e7f675162ed5226968b44a19ee3d24385c64d1d3c393",
767
+ TOKENPOCKET: "20459438007b75f4f4acb98bf29aa3b800550309646d375da5fd4aac6c2a2c66",
768
+ BITGET: "7674bb4e353bf52886768a3ddc2a4562ce2f4191c80831291218ebd90f5f5e26"
769
+ };
770
+
771
+ // src/types.ts
772
+ var ChainType = /* @__PURE__ */ ((ChainType2) => {
773
+ ChainType2["EIP155"] = "eip155";
774
+ ChainType2["SOLANA"] = "solana";
775
+ ChainType2["APTOS"] = "aptos";
776
+ ChainType2["COSMOS"] = "cosmos";
777
+ ChainType2["POLKADOT"] = "polkadot";
778
+ ChainType2["NEAR"] = "near";
779
+ return ChainType2;
780
+ })(ChainType || {});
781
+ var AuthMethod = /* @__PURE__ */ ((AuthMethod2) => {
782
+ AuthMethod2["STANDARD"] = "standard";
783
+ AuthMethod2["SIWE"] = "siwe";
784
+ return AuthMethod2;
785
+ })(AuthMethod || {});
786
+
787
+ exports.APTOS_CHAINS = APTOS_CHAINS;
788
+ exports.APTOS_NAMESPACE = APTOS_NAMESPACE;
789
+ exports.AuthMethod = AuthMethod;
790
+ exports.COSMOS_NAMESPACE = COSMOS_NAMESPACE;
791
+ exports.ChainType = ChainType;
792
+ exports.EIP155_NAMESPACE = EIP155_NAMESPACE;
793
+ exports.EVM_CHAINS = EVM_CHAINS;
794
+ exports.NEAR_NAMESPACE = NEAR_NAMESPACE;
795
+ exports.POLKADOT_NAMESPACE = POLKADOT_NAMESPACE;
796
+ exports.POPULAR_WALLET_IDS = POPULAR_WALLET_IDS;
797
+ exports.SOLANA_CHAINS = SOLANA_CHAINS;
798
+ exports.SOLANA_NAMESPACE = SOLANA_NAMESPACE;
799
+ exports.SiweAuth = SiweAuth;
800
+ exports.WalletConnectClient = WalletConnectClient;
801
+ exports.copyToClipboard = copyToClipboard;
802
+ exports.createMultiChainNamespaces = createMultiChainNamespaces;
803
+ exports.createSiweConfigFromSession = createSiweConfigFromSession;
804
+ exports.createSiweMessage = createSiweMessage;
805
+ exports.extractAddressFromAccount = extractAddressFromAccount;
806
+ exports.extractChainIdFromAccount = extractChainIdFromAccount;
807
+ exports.formatAddress = formatAddress;
808
+ exports.formatError = formatError;
809
+ exports.formatTimestamp = formatTimestamp;
810
+ exports.generateDeepLink = generateDeepLink;
811
+ exports.getAllWallets = getAllWallets;
812
+ exports.getBrowserWallets = getBrowserWallets;
813
+ exports.getDesktopWallets = getDesktopWallets;
814
+ exports.getMobileWallets = getMobileWallets;
815
+ exports.getRecommendedWallets = getRecommendedWallets;
816
+ exports.getSessionTimeRemaining = getSessionTimeRemaining;
817
+ exports.getWalletById = getWalletById;
818
+ exports.getWalletConnectWallets = getWalletConnectWallets;
819
+ exports.getWalletsByChain = getWalletsByChain;
820
+ exports.isMobile = isMobile;
821
+ exports.isSessionExpired = isSessionExpired;
822
+ exports.isValidChainId = isValidChainId;
823
+ exports.isValidWalletConnectUri = isValidWalletConnectUri;
824
+ exports.parseChainId = parseChainId;
825
+ exports.parseSiweMessage = parseSiweMessage;
826
+ exports.parseWalletConnectUri = parseWalletConnectUri;
827
+ exports.searchWallets = searchWallets;
828
+ exports.verifySiweSignature = verifySiweSignature;