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