@blazium/ton-connect-mobile 1.2.4 → 1.2.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.
- package/README.md +7 -20
- package/dist/adapters/react-native.js +8 -1
- package/dist/core/bridge.d.ts +61 -0
- package/dist/core/bridge.js +237 -0
- package/dist/core/crypto.d.ts +8 -19
- package/dist/core/crypto.js +15 -141
- package/dist/core/index.d.ts +5 -3
- package/dist/core/index.js +20 -17
- package/dist/core/protocol.d.ts +35 -32
- package/dist/core/protocol.js +109 -285
- package/dist/core/session.d.ts +65 -0
- package/dist/core/session.js +235 -0
- package/dist/core/wallets.d.ts +6 -6
- package/dist/core/wallets.js +17 -18
- package/dist/index.d.ts +33 -72
- package/dist/index.js +322 -769
- package/dist/react/TonConnectUIProvider.d.ts +4 -52
- package/dist/react/TonConnectUIProvider.js +18 -122
- package/dist/react/index.d.ts +1 -2
- package/dist/react/index.js +0 -1
- package/dist/types/index.d.ts +84 -139
- package/dist/types/index.js +1 -1
- package/package.json +2 -3
- package/src/adapters/react-native.ts +7 -1
- package/src/core/bridge.ts +307 -0
- package/src/core/crypto.ts +62 -238
- package/src/core/index.ts +17 -7
- package/src/core/protocol.ts +217 -441
- package/src/core/session.ts +247 -0
- package/src/core/wallets.ts +90 -93
- package/src/index.ts +811 -1338
- package/src/react/TonConnectUIProvider.tsx +272 -441
- package/src/react/index.ts +23 -27
- package/src/types/index.ts +217 -272
package/src/react/index.ts
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* React integration exports
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} from './
|
|
22
|
-
export
|
|
23
|
-
export {
|
|
24
|
-
export type { TonConnectButtonProps } from './TonConnectButton';
|
|
25
|
-
export { WalletSelectionModal } from './WalletSelectionModal';
|
|
26
|
-
export type { WalletSelectionModalProps } from './WalletSelectionModal';
|
|
27
|
-
|
|
1
|
+
/**
|
|
2
|
+
* React integration exports
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
TonConnectUIProvider,
|
|
7
|
+
useTonConnectUI,
|
|
8
|
+
useTonWallet,
|
|
9
|
+
useTonConnectModal,
|
|
10
|
+
useTonConnectSDK,
|
|
11
|
+
} from './TonConnectUIProvider';
|
|
12
|
+
export type {
|
|
13
|
+
TonConnectUIProviderProps,
|
|
14
|
+
TonConnectUI,
|
|
15
|
+
WalletState,
|
|
16
|
+
Account,
|
|
17
|
+
TransactionResponse,
|
|
18
|
+
} from './TonConnectUIProvider';
|
|
19
|
+
export type { Network, BalanceResponse, TransactionStatusResponse, TransactionStatus } from '../types';
|
|
20
|
+
export { TonConnectButton } from './TonConnectButton';
|
|
21
|
+
export type { TonConnectButtonProps } from './TonConnectButton';
|
|
22
|
+
export { WalletSelectionModal } from './WalletSelectionModal';
|
|
23
|
+
export type { WalletSelectionModalProps } from './WalletSelectionModal';
|
package/src/types/index.ts
CHANGED
|
@@ -1,272 +1,217 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core types for TON Connect Mobile SDK
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Wallet information returned after successful connection
|
|
8
|
-
*/
|
|
9
|
-
export interface WalletInfo {
|
|
10
|
-
/** Wallet name (e.g., "Tonkeeper"
|
|
11
|
-
name: string;
|
|
12
|
-
/** Wallet app name */
|
|
13
|
-
appName: string;
|
|
14
|
-
/** Wallet app version */
|
|
15
|
-
version: string;
|
|
16
|
-
/** Platform
|
|
17
|
-
platform: 'ios' | 'android' | 'unknown';
|
|
18
|
-
/** TON address
|
|
19
|
-
address: string;
|
|
20
|
-
/** Public key in hex format */
|
|
21
|
-
publicKey: string;
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
/** Optional
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
/** Optional
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
/** TON
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
*
|
|
151
|
-
*/
|
|
152
|
-
export interface
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
preferredWallet?: string;
|
|
219
|
-
/** Network (mainnet/testnet) - default: 'mainnet' */
|
|
220
|
-
network?: Network;
|
|
221
|
-
/** TON API endpoint for balance checking (optional)
|
|
222
|
-
* Default: 'https://toncenter.com/api/v2' for mainnet, 'https://testnet.toncenter.com/api/v2' for testnet
|
|
223
|
-
*/
|
|
224
|
-
tonApiEndpoint?: string;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Event listener callback type
|
|
229
|
-
*/
|
|
230
|
-
export type StatusChangeCallback = (status: ConnectionStatus) => void;
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Event types for TonConnectMobile
|
|
234
|
-
*/
|
|
235
|
-
export type TonConnectEventType = 'connect' | 'disconnect' | 'transaction' | 'error' | 'statusChange';
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Event listener callback
|
|
239
|
-
*/
|
|
240
|
-
export type TonConnectEventListener<T = any> = (data: T) => void;
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Transaction status
|
|
244
|
-
*/
|
|
245
|
-
export type TransactionStatus = 'pending' | 'confirmed' | 'failed' | 'unknown';
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Transaction status response
|
|
249
|
-
*/
|
|
250
|
-
export interface TransactionStatusResponse {
|
|
251
|
-
/** Transaction status */
|
|
252
|
-
status: TransactionStatus;
|
|
253
|
-
/** Transaction hash (if available) */
|
|
254
|
-
hash?: string;
|
|
255
|
-
/** Block number (if confirmed) */
|
|
256
|
-
blockNumber?: number;
|
|
257
|
-
/** Error message (if failed) */
|
|
258
|
-
error?: string;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Balance response
|
|
263
|
-
*/
|
|
264
|
-
export interface BalanceResponse {
|
|
265
|
-
/** Balance in nanotons */
|
|
266
|
-
balance: string;
|
|
267
|
-
/** Balance in TON (formatted) */
|
|
268
|
-
balanceTon: string;
|
|
269
|
-
/** Network */
|
|
270
|
-
network: Network;
|
|
271
|
-
}
|
|
272
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Core types for TON Connect Mobile SDK
|
|
3
|
+
* Types for TON Connect v2 protocol
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Wallet information returned after successful connection
|
|
8
|
+
*/
|
|
9
|
+
export interface WalletInfo {
|
|
10
|
+
/** Wallet name (e.g., "Tonkeeper") */
|
|
11
|
+
name: string;
|
|
12
|
+
/** Wallet app name */
|
|
13
|
+
appName: string;
|
|
14
|
+
/** Wallet app version */
|
|
15
|
+
version: string;
|
|
16
|
+
/** Platform */
|
|
17
|
+
platform: 'ios' | 'android' | 'unknown';
|
|
18
|
+
/** TON address (raw format: workchain:hash) */
|
|
19
|
+
address: string;
|
|
20
|
+
/** Public key in hex format */
|
|
21
|
+
publicKey: string;
|
|
22
|
+
/** Network identifier ("-239" = mainnet, "-3" = testnet) */
|
|
23
|
+
network?: string;
|
|
24
|
+
/** Wallet state init (base64) */
|
|
25
|
+
walletStateInit?: string;
|
|
26
|
+
/** Wallet icon URL */
|
|
27
|
+
icon?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Connection status
|
|
32
|
+
*/
|
|
33
|
+
export interface ConnectionStatus {
|
|
34
|
+
connected: boolean;
|
|
35
|
+
wallet: WalletInfo | null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Transaction message to send
|
|
40
|
+
*/
|
|
41
|
+
export interface TransactionMessage {
|
|
42
|
+
/** Recipient address */
|
|
43
|
+
address: string;
|
|
44
|
+
/** Amount in nanotons */
|
|
45
|
+
amount: string;
|
|
46
|
+
/** Optional message payload (base64 encoded) */
|
|
47
|
+
payload?: string;
|
|
48
|
+
/** Optional state init (base64 encoded) */
|
|
49
|
+
stateInit?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Transaction request parameters
|
|
54
|
+
*/
|
|
55
|
+
export interface SendTransactionRequest {
|
|
56
|
+
/** Unix timestamp (ms) when the request expires */
|
|
57
|
+
validUntil: number;
|
|
58
|
+
/** Array of messages to send */
|
|
59
|
+
messages: TransactionMessage[];
|
|
60
|
+
/** Optional network */
|
|
61
|
+
network?: 'mainnet' | 'testnet';
|
|
62
|
+
/** Optional from address */
|
|
63
|
+
from?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Platform adapter interface
|
|
68
|
+
*/
|
|
69
|
+
export interface PlatformAdapter {
|
|
70
|
+
openURL(url: string, skipCanOpenURLCheck?: boolean): Promise<boolean>;
|
|
71
|
+
getInitialURL(): Promise<string | null>;
|
|
72
|
+
addURLListener(callback: (url: string) => void): () => void;
|
|
73
|
+
setItem(key: string, value: string): Promise<void>;
|
|
74
|
+
getItem(key: string): Promise<string | null>;
|
|
75
|
+
removeItem(key: string): Promise<void>;
|
|
76
|
+
randomBytes(length: number): Promise<Uint8Array>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Network type
|
|
81
|
+
*/
|
|
82
|
+
export type Network = 'mainnet' | 'testnet';
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* SDK configuration
|
|
86
|
+
*/
|
|
87
|
+
export interface TonConnectMobileConfig {
|
|
88
|
+
/** Manifest URL (required) */
|
|
89
|
+
manifestUrl: string;
|
|
90
|
+
/** Deep link scheme for callbacks (required for return strategy) */
|
|
91
|
+
scheme: string;
|
|
92
|
+
/** Optional storage key prefix */
|
|
93
|
+
storageKeyPrefix?: string;
|
|
94
|
+
/** Optional connection timeout in ms (default: 300000 = 5 minutes) */
|
|
95
|
+
connectionTimeout?: number;
|
|
96
|
+
/** Optional transaction timeout in ms (default: 300000 = 5 minutes) */
|
|
97
|
+
transactionTimeout?: number;
|
|
98
|
+
/** Skip canOpenURL check (default: true) */
|
|
99
|
+
skipCanOpenURLCheck?: boolean;
|
|
100
|
+
/** Preferred wallet name */
|
|
101
|
+
preferredWallet?: string;
|
|
102
|
+
/** Network (default: 'mainnet') */
|
|
103
|
+
network?: Network;
|
|
104
|
+
/** Custom TON API endpoint */
|
|
105
|
+
tonApiEndpoint?: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Status change callback
|
|
110
|
+
*/
|
|
111
|
+
export type StatusChangeCallback = (status: ConnectionStatus) => void;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Event types
|
|
115
|
+
*/
|
|
116
|
+
export type TonConnectEventType = 'connect' | 'disconnect' | 'transaction' | 'error' | 'statusChange';
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Event listener callback
|
|
120
|
+
*/
|
|
121
|
+
export type TonConnectEventListener<T = any> = (data: T) => void;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Transaction status
|
|
125
|
+
*/
|
|
126
|
+
export type TransactionStatus = 'pending' | 'confirmed' | 'failed' | 'unknown';
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Transaction status response
|
|
130
|
+
*/
|
|
131
|
+
export interface TransactionStatusResponse {
|
|
132
|
+
status: TransactionStatus;
|
|
133
|
+
hash?: string;
|
|
134
|
+
blockNumber?: number;
|
|
135
|
+
error?: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Balance response
|
|
140
|
+
*/
|
|
141
|
+
export interface BalanceResponse {
|
|
142
|
+
balance: string;
|
|
143
|
+
balanceTon: string;
|
|
144
|
+
network: Network;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ─── TON Connect v2 Bridge Protocol Types ───
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Connect event from wallet (received via bridge after decryption)
|
|
151
|
+
*/
|
|
152
|
+
export interface ConnectEvent {
|
|
153
|
+
event: 'connect';
|
|
154
|
+
id: number;
|
|
155
|
+
payload: {
|
|
156
|
+
items: Array<{
|
|
157
|
+
name: string;
|
|
158
|
+
address: string;
|
|
159
|
+
network: string;
|
|
160
|
+
publicKey: string;
|
|
161
|
+
walletStateInit?: string;
|
|
162
|
+
[key: string]: any;
|
|
163
|
+
}>;
|
|
164
|
+
device: {
|
|
165
|
+
platform: string;
|
|
166
|
+
appName: string;
|
|
167
|
+
appVersion: string;
|
|
168
|
+
maxProtocolVersion: number;
|
|
169
|
+
features: any[];
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Connect error event from wallet
|
|
176
|
+
*/
|
|
177
|
+
export interface ConnectErrorEvent {
|
|
178
|
+
event: 'connect_error';
|
|
179
|
+
id: number;
|
|
180
|
+
payload: {
|
|
181
|
+
code: number;
|
|
182
|
+
message: string;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* JSON-RPC response (success)
|
|
188
|
+
*/
|
|
189
|
+
export interface RpcResponse {
|
|
190
|
+
result: string;
|
|
191
|
+
id: number;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* JSON-RPC response (error)
|
|
196
|
+
*/
|
|
197
|
+
export interface RpcErrorResponse {
|
|
198
|
+
error: {
|
|
199
|
+
code: number;
|
|
200
|
+
message: string;
|
|
201
|
+
};
|
|
202
|
+
id: number;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Persisted session data
|
|
207
|
+
*/
|
|
208
|
+
export interface PersistedSession {
|
|
209
|
+
/** Hex-encoded session secret key */
|
|
210
|
+
sessionSecretKey: string;
|
|
211
|
+
/** Hex-encoded wallet public key (from bridge "from" field) */
|
|
212
|
+
walletPublicKey: string;
|
|
213
|
+
/** Wallet bridge URL */
|
|
214
|
+
bridgeUrl: string;
|
|
215
|
+
/** Wallet info */
|
|
216
|
+
wallet: WalletInfo;
|
|
217
|
+
}
|