toncorp-wallet-connect-sdk 0.1.1 → 0.1.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.
- package/README.md +55 -71
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,6 +8,12 @@ Connect TonPass, OneDollar and more wallets from any DApp or website.
|
|
|
8
8
|
npm install toncorp-wallet-connect-sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
Or via CDN:
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<script src="https://cdn.jsdelivr.net/npm/toncorp-wallet-connect-sdk@latest/dist/index.umd.js"></script>
|
|
15
|
+
```
|
|
16
|
+
|
|
11
17
|
## Usage
|
|
12
18
|
|
|
13
19
|
### Specific wallet
|
|
@@ -15,25 +21,26 @@ npm install toncorp-wallet-connect-sdk
|
|
|
15
21
|
```typescript
|
|
16
22
|
import { TonPassConnect } from 'toncorp-wallet-connect-sdk';
|
|
17
23
|
|
|
18
|
-
const wallet = new TonPassConnect({
|
|
19
|
-
appId: 'your_app_id',
|
|
20
|
-
registryUrl: 'https://api.example.com/connect/wallets',
|
|
21
|
-
});
|
|
24
|
+
const wallet = new TonPassConnect({ appId: 'your_app_id' });
|
|
22
25
|
|
|
23
26
|
const result = await wallet.connect();
|
|
24
|
-
console.log(result.
|
|
27
|
+
console.log(result.wallet); // { address: 'UQ...', chain: 'TON' }
|
|
25
28
|
console.log(result.user); // { username: 'john', avatar: '...' }
|
|
29
|
+
|
|
30
|
+
// Access via window global
|
|
31
|
+
window.tonpass.isConnected() // true
|
|
32
|
+
window.tonpass.getWallet() // same result
|
|
26
33
|
```
|
|
27
34
|
|
|
28
35
|
```typescript
|
|
29
36
|
import { OneDollarConnect } from 'toncorp-wallet-connect-sdk';
|
|
30
37
|
|
|
31
|
-
const wallet = new OneDollarConnect({
|
|
32
|
-
appId: 'your_app_id',
|
|
33
|
-
registryUrl: 'https://api.example.com/connect/wallets',
|
|
34
|
-
});
|
|
35
|
-
|
|
38
|
+
const wallet = new OneDollarConnect({ appId: 'your_app_id' });
|
|
36
39
|
const result = await wallet.connect();
|
|
40
|
+
|
|
41
|
+
// Access via window global
|
|
42
|
+
window.onedollar.isConnected()
|
|
43
|
+
window.onedollar.getWallet()
|
|
37
44
|
```
|
|
38
45
|
|
|
39
46
|
### All wallets (show picker)
|
|
@@ -43,7 +50,6 @@ import { BaseWalletConnect } from 'toncorp-wallet-connect-sdk';
|
|
|
43
50
|
|
|
44
51
|
const wallet = new BaseWalletConnect({
|
|
45
52
|
appId: 'your_app_id',
|
|
46
|
-
registryUrl: 'https://api.example.com/connect/wallets',
|
|
47
53
|
// walletId: ['tonpass', 'onedollar'], // optional filter
|
|
48
54
|
});
|
|
49
55
|
|
|
@@ -53,17 +59,21 @@ const result = await wallet.connect();
|
|
|
53
59
|
### Script tag (UMD)
|
|
54
60
|
|
|
55
61
|
```html
|
|
56
|
-
<script src="https://
|
|
62
|
+
<script src="https://cdn.jsdelivr.net/npm/toncorp-wallet-connect-sdk@latest/dist/index.umd.js"></script>
|
|
57
63
|
<script>
|
|
58
|
-
const wallet = new WalletConnectSDK.
|
|
64
|
+
const wallet = new WalletConnectSDK.OneDollarConnect({
|
|
59
65
|
appId: 'your_app_id',
|
|
60
|
-
registryUrl: 'https://api.example.com/connect/wallets',
|
|
61
66
|
});
|
|
62
67
|
|
|
63
68
|
document.getElementById('connect-btn').onclick = async () => {
|
|
64
69
|
const result = await wallet.connect();
|
|
65
70
|
console.log(result);
|
|
66
71
|
};
|
|
72
|
+
|
|
73
|
+
// Available globally after instantiation
|
|
74
|
+
// window.onedollar.isConnected()
|
|
75
|
+
// window.onedollar.getWallet()
|
|
76
|
+
// window.onedollar.disconnect()
|
|
67
77
|
</script>
|
|
68
78
|
```
|
|
69
79
|
|
|
@@ -74,7 +84,7 @@ const result = await wallet.connect();
|
|
|
74
84
|
| Option | Type | Required | Description |
|
|
75
85
|
|--------|------|----------|-------------|
|
|
76
86
|
| `appId` | `string` | Yes | Your registered app ID |
|
|
77
|
-
| `registryUrl` | `string` |
|
|
87
|
+
| `registryUrl` | `string` | No | Override wallet registry URL (defaults to CDN) |
|
|
78
88
|
| `walletId` | `string \| string[]` | No | Filter wallets (only for `BaseWalletConnect`) |
|
|
79
89
|
| `theme` | `'light' \| 'dark'` | No | Modal theme (default: `light`) |
|
|
80
90
|
|
|
@@ -83,76 +93,50 @@ const result = await wallet.connect();
|
|
|
83
93
|
| Method | Returns | Description |
|
|
84
94
|
|--------|---------|-------------|
|
|
85
95
|
| `connect()` | `Promise<ConnectResult>` | Open modal and wait for user to approve |
|
|
86
|
-
| `disconnect()` | `void` | Disconnect
|
|
96
|
+
| `disconnect()` | `void` | Disconnect, clear session and call API |
|
|
87
97
|
| `isConnected()` | `boolean` | Check connection status |
|
|
88
98
|
| `getWallet()` | `ConnectResult \| null` | Get current connection info |
|
|
89
99
|
| `on(event, cb)` | `void` | Listen to events |
|
|
90
100
|
| `off(event, cb)` | `void` | Remove listener |
|
|
91
101
|
|
|
102
|
+
### ConnectResult
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
{
|
|
106
|
+
wallet: {
|
|
107
|
+
address: string; // friendly TON address
|
|
108
|
+
chain: string; // 'TON'
|
|
109
|
+
} | null;
|
|
110
|
+
user: {
|
|
111
|
+
username?: string;
|
|
112
|
+
avatar?: string;
|
|
113
|
+
};
|
|
114
|
+
session?: {
|
|
115
|
+
sessionToken: string;
|
|
116
|
+
walletId: string;
|
|
117
|
+
apiUrl: string;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
92
122
|
### Events
|
|
93
123
|
|
|
94
124
|
| Event | Data | Description |
|
|
95
125
|
|-------|------|-------------|
|
|
96
126
|
| `connect` | `ConnectResult` | Connected successfully |
|
|
97
|
-
| `disconnect` |
|
|
127
|
+
| `disconnect` | - | Disconnected |
|
|
98
128
|
| `error` | `string` | Transport error |
|
|
99
|
-
| `session_expired` |
|
|
100
|
-
|
|
101
|
-
## Publish to npm
|
|
102
|
-
|
|
103
|
-
### Prerequisites
|
|
129
|
+
| `session_expired` | - | Session timed out |
|
|
104
130
|
|
|
105
|
-
|
|
106
|
-
# Login to npm (one-time)
|
|
107
|
-
npm login
|
|
108
|
-
|
|
109
|
-
# If using scoped package (@aspect-wallet), make sure the org exists on npmjs.com
|
|
110
|
-
# Or change the name in package.json to an unscoped name
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### Build & Publish
|
|
114
|
-
|
|
115
|
-
```bash
|
|
116
|
-
# Navigate to SDK folder
|
|
117
|
-
cd src/blockchain/walletconnect/sdk
|
|
118
|
-
|
|
119
|
-
# Install build dependencies
|
|
120
|
-
npm install
|
|
121
|
-
|
|
122
|
-
# Build (outputs to dist/)
|
|
123
|
-
npm run build
|
|
124
|
-
|
|
125
|
-
# Check what will be published
|
|
126
|
-
npm pack --dry-run
|
|
127
|
-
|
|
128
|
-
# Publish (first time — scoped packages default to private)
|
|
129
|
-
npm publish --access public
|
|
131
|
+
### Window globals
|
|
130
132
|
|
|
131
|
-
|
|
132
|
-
# 1. Bump version first:
|
|
133
|
-
npm version patch # 0.1.0 → 0.1.1 (bug fixes)
|
|
134
|
-
npm version minor # 0.1.1 → 0.2.0 (new features)
|
|
135
|
-
npm version major # 0.2.0 → 1.0.0 (breaking changes)
|
|
136
|
-
# 2. Then publish:
|
|
137
|
-
npm publish --access public
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### Verify
|
|
141
|
-
|
|
142
|
-
```bash
|
|
143
|
-
# Check the published package
|
|
144
|
-
npm info toncorp-wallet-connect-sdk
|
|
145
|
-
|
|
146
|
-
# Install in another project to test
|
|
147
|
-
npm install toncorp-wallet-connect-sdk
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
### CDN (auto-available after publish)
|
|
133
|
+
Each wallet instance auto-registers on `window`:
|
|
151
134
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
135
|
+
| Class | Window global |
|
|
136
|
+
|-------|--------------|
|
|
137
|
+
| `TonPassConnect` | `window.tonpass` |
|
|
138
|
+
| `OneDollarConnect` | `window.onedollar` |
|
|
139
|
+
| `BaseWalletConnect` | `window.walletconnect` |
|
|
156
140
|
|
|
157
141
|
## License
|
|
158
142
|
|