@tomo-inc/wallet-connect-protocol 0.0.8 → 0.0.10

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.
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@tomo-inc/wallet-connect-protocol",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "author": "tomo.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "type": "module",
8
- "description": "WalletConnect protocol SDK for Tomo Wallet",
8
+ "description": "WalletConnect protocol SDK for Tomo Wallet - Pure JavaScript",
9
9
  "main": "./dist/index.cjs",
10
10
  "module": "./dist/index.js",
11
11
  "types": "./dist/index.d.ts",
@@ -14,11 +14,6 @@
14
14
  "types": "./dist/index.d.ts",
15
15
  "import": "./dist/index.js",
16
16
  "require": "./dist/index.cjs"
17
- },
18
- "./vanilla": {
19
- "types": "./dist/vanilla.d.ts",
20
- "import": "./dist/vanilla.js",
21
- "require": "./dist/vanilla.cjs"
22
17
  }
23
18
  },
24
19
  "dependencies": {
@@ -31,27 +26,19 @@
31
26
  "devDependencies": {
32
27
  "@types/node": "^20.0.0",
33
28
  "@types/qrcode": "^1.5.5",
34
- "@types/react": "^18.0.0",
35
29
  "ethers": "^6.13.5",
36
- "react": "^18.0.0",
37
30
  "tsup": "^8.0.0",
38
31
  "typescript": "^5.0.0"
39
32
  },
40
- "peerDependencies": {
41
- "react": ">=16.8.0"
42
- },
43
- "peerDependenciesMeta": {
44
- "react": {
45
- "optional": false
46
- }
47
- },
48
33
  "keywords": [
49
34
  "walletconnect",
50
35
  "wallet",
51
36
  "tomo",
52
37
  "sdk",
53
38
  "web3",
54
- "ethereum"
39
+ "ethereum",
40
+ "vanilla-js",
41
+ "framework-agnostic"
55
42
  ],
56
43
  "scripts": {
57
44
  "build": "tsup",
package/VANILLA_JS.md DELETED
@@ -1,491 +0,0 @@
1
- # Pure JavaScript / Non-React Usage Guide
2
-
3
- This guide shows how to use `@tomo-inc/wallet-connect-protocol` in vanilla JavaScript, Vue, Angular, Svelte, or any other non-React framework.
4
-
5
- ## 📦 Installation
6
-
7
- ```bash
8
- npm install @tomo-inc/wallet-connect-protocol
9
- # or
10
- pnpm add @tomo-inc/wallet-connect-protocol
11
- # or
12
- yarn add @tomo-inc/wallet-connect-protocol
13
- ```
14
-
15
- ## 🚀 Import Methods
16
-
17
- ### Method 1: Using `/vanilla` Export (Recommended)
18
-
19
- ```javascript
20
- // Import from the vanilla export (excludes React dependencies)
21
- import {
22
- WalletConnectClient,
23
- getAllWallets,
24
- } from "@tomo-inc/wallet-connect-protocol/vanilla";
25
- ```
26
-
27
- ### Method 2: Direct Import
28
-
29
- ```javascript
30
- // Import specific modules directly
31
- import { WalletConnectClient } from "@tomo-inc/wallet-connect-protocol";
32
- ```
33
-
34
- ## 💡 Basic Usage
35
-
36
- ### 1. Initialize WalletConnect Client
37
-
38
- ```javascript
39
- import { WalletConnectClient } from "@tomo-inc/wallet-connect-protocol/vanilla";
40
-
41
- // Create client instance
42
- const client = new WalletConnectClient({
43
- projectId: "YOUR_PROJECT_ID", // Get from https://cloud.walletconnect.com
44
- metadata: {
45
- name: "My App",
46
- description: "My awesome application",
47
- url: "https://myapp.com",
48
- icons: ["https://myapp.com/icon.png"],
49
- },
50
- });
51
-
52
- // Initialize the client
53
- await client.initialize();
54
- ```
55
-
56
- ### 2. Connect Wallet
57
-
58
- ```javascript
59
- // Create connection and get URI
60
- const uri = await client.connect({
61
- requiredNamespaces: {
62
- eip155: {
63
- methods: ["eth_sendTransaction", "personal_sign"],
64
- chains: ["eip155:1"], // Ethereum mainnet
65
- events: ["chainChanged", "accountsChanged"],
66
- },
67
- },
68
- });
69
-
70
- console.log("WalletConnect URI:", uri);
71
-
72
- // Generate QR code
73
- const qrCode = await client.generateQRCode(uri, {
74
- width: 400,
75
- margin: 2,
76
- });
77
-
78
- // Display QR code
79
- document.getElementById("qr-code").src = qrCode;
80
- ```
81
-
82
- ### 3. Listen to Events
83
-
84
- ```javascript
85
- // Listen for session events
86
- client.on("session_proposal", (proposal) => {
87
- console.log("New session proposal:", proposal);
88
- });
89
-
90
- client.on("session_delete", () => {
91
- console.log("Session disconnected");
92
- });
93
-
94
- client.on("session_update", (update) => {
95
- console.log("Session updated:", update);
96
- });
97
- ```
98
-
99
- ### 4. Get Active Sessions
100
-
101
- ```javascript
102
- const sessions = client.getActiveSessions();
103
- console.log("Active sessions:", sessions);
104
- ```
105
-
106
- ### 5. Send Requests
107
-
108
- ```javascript
109
- if (sessions.length > 0) {
110
- const session = sessions[0];
111
-
112
- // Send transaction
113
- const result = await client.request({
114
- topic: session.topic,
115
- chainId: "eip155:1",
116
- request: {
117
- method: "eth_sendTransaction",
118
- params: [
119
- {
120
- from: "0x...",
121
- to: "0x...",
122
- value: "0x0",
123
- data: "0x",
124
- },
125
- ],
126
- },
127
- });
128
-
129
- console.log("Transaction result:", result);
130
- }
131
- ```
132
-
133
- ### 6. Disconnect
134
-
135
- ```javascript
136
- // Disconnect specific session
137
- await client.disconnect(session.topic);
138
-
139
- // Or disconnect all sessions
140
- const sessions = client.getActiveSessions();
141
- for (const session of sessions) {
142
- await client.disconnect(session.topic);
143
- }
144
- ```
145
-
146
- ## 🔧 Complete Example
147
-
148
- ### Vanilla JavaScript
149
-
150
- ```html
151
- <!DOCTYPE html>
152
- <html>
153
- <head>
154
- <title>WalletConnect Vanilla JS Demo</title>
155
- </head>
156
- <body>
157
- <div id="app">
158
- <button id="connect-btn">Connect Wallet</button>
159
- <div id="qr-container" style="display: none;">
160
- <img id="qr-code" />
161
- </div>
162
- <div id="status"></div>
163
- </div>
164
-
165
- <script type="module">
166
- import { WalletConnectClient } from "@tomo-inc/wallet-connect-protocol/vanilla";
167
-
168
- const client = new WalletConnectClient({
169
- projectId: "YOUR_PROJECT_ID",
170
- metadata: {
171
- name: "Vanilla JS Demo",
172
- description: "WalletConnect Vanilla JS Demo",
173
- url: "https://example.com",
174
- icons: ["https://example.com/icon.png"],
175
- },
176
- });
177
-
178
- // Initialize
179
- await client.initialize();
180
-
181
- // Event handlers
182
- const connectBtn = document.getElementById("connect-btn");
183
- const qrContainer = document.getElementById("qr-container");
184
- const qrCode = document.getElementById("qr-code");
185
- const status = document.getElementById("status");
186
-
187
- connectBtn.addEventListener("click", async () => {
188
- try {
189
- status.textContent = "Connecting...";
190
-
191
- const uri = await client.connect();
192
- const qr = await client.generateQRCode(uri);
193
-
194
- qrCode.src = qr;
195
- qrContainer.style.display = "block";
196
- status.textContent = "Scan QR code with your wallet";
197
- } catch (error) {
198
- status.textContent = "Error: " + error.message;
199
- }
200
- });
201
-
202
- client.on("session_proposal", () => {
203
- qrContainer.style.display = "none";
204
- status.textContent = "Connected! ✓";
205
- });
206
- </script>
207
- </body>
208
- </html>
209
- ```
210
-
211
- ### Vue.js 3
212
-
213
- ```vue
214
- <template>
215
- <div>
216
- <button @click="connect">Connect Wallet</button>
217
- <img v-if="qrCode" :src="qrCode" alt="QR Code" />
218
- <div>{{ status }}</div>
219
- </div>
220
- </template>
221
-
222
- <script setup>
223
- import { ref, onMounted } from "vue";
224
- import { WalletConnectClient } from "@tomo-inc/wallet-connect-protocol/vanilla";
225
-
226
- const qrCode = ref(null);
227
- const status = ref("");
228
- let client = null;
229
-
230
- onMounted(async () => {
231
- client = new WalletConnectClient({
232
- projectId: "YOUR_PROJECT_ID",
233
- metadata: {
234
- name: "Vue App",
235
- description: "WalletConnect Vue Demo",
236
- url: "https://example.com",
237
- icons: ["https://example.com/icon.png"],
238
- },
239
- });
240
-
241
- await client.initialize();
242
-
243
- client.on("session_proposal", () => {
244
- qrCode.value = null;
245
- status.value = "Connected!";
246
- });
247
- });
248
-
249
- const connect = async () => {
250
- try {
251
- status.value = "Connecting...";
252
- const uri = await client.connect();
253
- qrCode.value = await client.generateQRCode(uri);
254
- } catch (error) {
255
- status.value = "Error: " + error.message;
256
- }
257
- };
258
- </script>
259
- ```
260
-
261
- ### Angular
262
-
263
- ```typescript
264
- import { Component, OnInit } from "@angular/core";
265
- import { WalletConnectClient } from "@tomo-inc/wallet-connect-protocol/vanilla";
266
-
267
- @Component({
268
- selector: "app-wallet-connect",
269
- template: `
270
- <button (click)="connect()">Connect Wallet</button>
271
- <img *ngIf="qrCode" [src]="qrCode" alt="QR Code" />
272
- <div>{{ status }}</div>
273
- `,
274
- })
275
- export class WalletConnectComponent implements OnInit {
276
- client: WalletConnectClient;
277
- qrCode: string | null = null;
278
- status: string = "";
279
-
280
- async ngOnInit() {
281
- this.client = new WalletConnectClient({
282
- projectId: "YOUR_PROJECT_ID",
283
- metadata: {
284
- name: "Angular App",
285
- description: "WalletConnect Angular Demo",
286
- url: "https://example.com",
287
- icons: ["https://example.com/icon.png"],
288
- },
289
- });
290
-
291
- await this.client.initialize();
292
-
293
- this.client.on("session_proposal", () => {
294
- this.qrCode = null;
295
- this.status = "Connected!";
296
- });
297
- }
298
-
299
- async connect() {
300
- try {
301
- this.status = "Connecting...";
302
- const uri = await this.client.connect();
303
- this.qrCode = await this.client.generateQRCode(uri);
304
- } catch (error) {
305
- this.status = "Error: " + error.message;
306
- }
307
- }
308
- }
309
- ```
310
-
311
- ### Svelte
312
-
313
- ```svelte
314
- <script>
315
- import { onMount } from 'svelte';
316
- import { WalletConnectClient } from '@tomo-inc/wallet-connect-protocol/vanilla';
317
-
318
- let client;
319
- let qrCode = null;
320
- let status = '';
321
-
322
- onMount(async () => {
323
- client = new WalletConnectClient({
324
- projectId: 'YOUR_PROJECT_ID',
325
- metadata: {
326
- name: 'Svelte App',
327
- description: 'WalletConnect Svelte Demo',
328
- url: 'https://example.com',
329
- icons: ['https://example.com/icon.png']
330
- }
331
- });
332
-
333
- await client.initialize();
334
-
335
- client.on('session_proposal', () => {
336
- qrCode = null;
337
- status = 'Connected!';
338
- });
339
- });
340
-
341
- async function connect() {
342
- try {
343
- status = 'Connecting...';
344
- const uri = await client.connect();
345
- qrCode = await client.generateQRCode(uri);
346
- } catch (error) {
347
- status = 'Error: ' + error.message;
348
- }
349
- }
350
- </script>
351
-
352
- <button on:click={connect}>Connect Wallet</button>
353
- {#if qrCode}
354
- <img src={qrCode} alt="QR Code" />
355
- {/if}
356
- <div>{status}</div>
357
- ```
358
-
359
- ## 🌐 Get Wallet List
360
-
361
- ```javascript
362
- import {
363
- getAllWallets,
364
- getWalletsByChain,
365
- } from "@tomo-inc/wallet-connect-protocol/vanilla";
366
-
367
- // Get all WalletConnect supported wallets
368
- const wallets = await getAllWallets();
369
- console.log(`Found ${wallets.length} wallets`);
370
-
371
- // Get wallets that support Ethereum
372
- const ethWallets = await getWalletsByChain("eip155:1");
373
- console.log(`Found ${ethWallets.length} Ethereum wallets`);
374
-
375
- // Display wallet options
376
- wallets.forEach((wallet) => {
377
- console.log(`${wallet.name}: ${wallet.homepage}`);
378
- });
379
- ```
380
-
381
- ## 🔐 SIWE (Sign-In with Ethereum)
382
-
383
- ```javascript
384
- import {
385
- SiweAuth,
386
- createSiweMessage,
387
- } from "@tomo-inc/wallet-connect-protocol/vanilla";
388
-
389
- // Create SIWE authenticator
390
- const siwe = new SiweAuth({
391
- domain: window.location.host,
392
- uri: window.location.origin,
393
- statement: "Sign in to my app",
394
- });
395
-
396
- // After wallet is connected, sign in
397
- const session = client.getActiveSessions()[0];
398
- const address = session.namespaces.eip155.accounts[0].split(":")[2];
399
-
400
- // Create SIWE message
401
- const message = createSiweMessage({
402
- domain: window.location.host,
403
- address: address,
404
- statement: "Sign in to my app",
405
- uri: window.location.origin,
406
- version: "1",
407
- chainId: "1",
408
- nonce: Math.random().toString(36).substring(7),
409
- });
410
-
411
- // Request signature
412
- const signature = await client.request({
413
- topic: session.topic,
414
- chainId: "eip155:1",
415
- request: {
416
- method: "personal_sign",
417
- params: [message, address],
418
- },
419
- });
420
-
421
- console.log("SIWE signature:", signature);
422
- ```
423
-
424
- ## 📚 Available Exports
425
-
426
- ### Core Client
427
-
428
- - `WalletConnectClient` - Main WalletConnect client class
429
-
430
- ### Utility Functions
431
-
432
- - `formatAddress` - Format Ethereum address
433
- - `extractAddressFromAccount` - Extract address from CAIP-10 account
434
- - `extractChainIdFromAccount` - Extract chain ID from CAIP-10 account
435
- - `generateDeepLink` - Generate wallet deep link
436
- - `parseWalletConnectUri` - Parse WalletConnect URI
437
- - `isValidWalletConnectUri` - Validate WalletConnect URI
438
- - `getChainName` - Get chain name from chain ID
439
- - `isMobile` - Detect mobile device
440
-
441
- ### Wallet List API
442
-
443
- - `getAllWallets` - Get all supported wallets
444
- - `getWalletsByChain` - Get wallets by chain
445
- - `getMobileWallets` - Get mobile wallets
446
- - `getDesktopWallets` - Get desktop wallets
447
- - `getBrowserWallets` - Get browser extension wallets
448
- - `searchWallets` - Search wallets by name
449
- - `getWalletById` - Get specific wallet by ID
450
- - `POPULAR_WALLET_IDS` - Popular wallet IDs constant
451
-
452
- ### Multi-Chain Support
453
-
454
- - `createMultiChainNamespaces` - Create multi-chain namespaces
455
- - `EVM_CHAINS` - EVM chain configurations
456
- - `SOLANA_CHAINS` - Solana chain configurations
457
- - `APTOS_CHAINS` - Aptos chain configurations
458
-
459
- ### SIWE Support
460
-
461
- - `SiweAuth` - SIWE authentication class
462
- - `createSiweMessage` - Create SIWE message
463
- - `verifySiweSignature` - Verify SIWE signature
464
- - `parseSiweMessage` - Parse SIWE message
465
-
466
- ## 🔍 Type Definitions
467
-
468
- All exports include full TypeScript type definitions:
469
-
470
- ```typescript
471
- import type {
472
- WalletConnectConfig,
473
- SessionInfo,
474
- ConnectParams,
475
- Wallet,
476
- WalletListOptions,
477
- } from "@tomo-inc/wallet-connect-protocol/vanilla";
478
- ```
479
-
480
- ## ⚠️ Important Notes
481
-
482
- 1. **No React Required**: The `/vanilla` export doesn't require React as a dependency
483
- 2. **Browser Only**: This SDK is designed for browser environments
484
- 3. **Project ID**: You need a project ID from [WalletConnect Cloud](https://cloud.walletconnect.com)
485
- 4. **ES Modules**: The package uses ES modules, make sure your build tool supports it
486
-
487
- ## 🔗 Resources
488
-
489
- - [WalletConnect Documentation](https://docs.walletconnect.com)
490
- - [Get Project ID](https://cloud.walletconnect.com)
491
- - [WalletConnect Explorer](https://walletconnect.com/explorer)