@tonconnect/sdk 3.0.3-beta.0 → 3.0.3-beta.1

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.
@@ -18,6 +18,8 @@ export declare interface Account {
18
18
  publicKey?: string;
19
19
  }
20
20
 
21
+ export declare type AddTonConnectPrefix<T extends string> = `ton-connect-${T}` | `ton-connect-ui-${T}`;
22
+
21
23
  /**
22
24
  * Requested authentication type: 'ton_addr' or 'ton_proof'.
23
25
  */
@@ -34,7 +36,9 @@ export declare class BadRequestError extends TonConnectError {
34
36
  /**
35
37
  * A concrete implementation of EventDispatcher that dispatches events to the browser window.
36
38
  */
37
- export declare class BrowserEventDispatcher<T> implements EventDispatcher<T> {
39
+ export declare class BrowserEventDispatcher<T extends {
40
+ type: string;
41
+ }> implements EventDispatcher<T> {
38
42
  /**
39
43
  * The window object, possibly undefined in a server environment.
40
44
  * @private
@@ -46,7 +50,19 @@ export declare class BrowserEventDispatcher<T> implements EventDispatcher<T> {
46
50
  * @param eventDetails - The details of the event to dispatch.
47
51
  * @returns A promise that resolves when the event has been dispatched.
48
52
  */
49
- dispatchEvent(eventName: string, eventDetails: T): Promise<void>;
53
+ dispatchEvent<P extends AddTonConnectPrefix<T['type']>>(eventName: P, eventDetails: T & {
54
+ type: RemoveTonConnectPrefix<P>;
55
+ }): Promise<void>;
56
+ /**
57
+ * Adds an event listener to the browser window.
58
+ * @param eventName - The name of the event to listen for.
59
+ * @param listener - The listener to add.
60
+ * @param options - The options for the listener.
61
+ * @returns A function that removes the listener.
62
+ */
63
+ addEventListener<P extends AddTonConnectPrefix<T['type']>>(eventName: P, listener: (event: CustomEvent<T & {
64
+ type: RemoveTonConnectPrefix<P>;
65
+ }>) => void, options?: AddEventListenerOptions): Promise<() => void>;
50
66
  }
51
67
 
52
68
  export declare enum CHAIN {
@@ -84,6 +100,10 @@ export declare type ConnectionCompletedEvent = {
84
100
  * Event type.
85
101
  */
86
102
  type: 'connection-completed';
103
+ /**
104
+ * Connection success flag.
105
+ */
106
+ is_success: true;
87
107
  } & ConnectionInfo;
88
108
 
89
109
  /**
@@ -94,6 +114,10 @@ export declare type ConnectionErrorEvent = {
94
114
  * Event type.
95
115
  */
96
116
  type: 'connection-error';
117
+ /**
118
+ * Connection success flag.
119
+ */
120
+ is_success: false;
97
121
  /**
98
122
  * Reason for the error.
99
123
  */
@@ -102,6 +126,10 @@ export declare type ConnectionErrorEvent = {
102
126
  * Error code.
103
127
  */
104
128
  error_code: CONNECT_EVENT_ERROR_CODES | null;
129
+ /**
130
+ * Custom data for the connection.
131
+ */
132
+ custom_data: Version;
105
133
  };
106
134
 
107
135
  /**
@@ -141,7 +169,7 @@ export declare type ConnectionInfo = {
141
169
  * Wallet provider.
142
170
  */
143
171
  provider: 'http' | 'injected' | null;
144
- };
172
+ } & Version;
145
173
  };
146
174
 
147
175
  /**
@@ -152,6 +180,10 @@ export declare type ConnectionRestoringCompletedEvent = {
152
180
  * Event type.
153
181
  */
154
182
  type: 'connection-restoring-completed';
183
+ /**
184
+ * Connection success flag.
185
+ */
186
+ is_success: true;
155
187
  } & ConnectionInfo;
156
188
 
157
189
  /**
@@ -162,10 +194,18 @@ export declare type ConnectionRestoringErrorEvent = {
162
194
  * Event type.
163
195
  */
164
196
  type: 'connection-restoring-error';
197
+ /**
198
+ * Connection success flag.
199
+ */
200
+ is_success: false;
165
201
  /**
166
202
  * Reason for the error.
167
203
  */
168
204
  error_message: string;
205
+ /**
206
+ * Custom data for the connection.
207
+ */
208
+ custom_data: Version;
169
209
  };
170
210
 
171
211
  /**
@@ -181,6 +221,10 @@ export declare type ConnectionRestoringStartedEvent = {
181
221
  * Event type.
182
222
  */
183
223
  type: 'connection-restoring-started';
224
+ /**
225
+ * Custom data for the connection.
226
+ */
227
+ custom_data: Version;
184
228
  };
185
229
 
186
230
  /**
@@ -191,6 +235,10 @@ export declare type ConnectionStartedEvent = {
191
235
  * Event type.
192
236
  */
193
237
  type: 'connection-started';
238
+ /**
239
+ * Custom data for the connection.
240
+ */
241
+ custom_data: Version;
194
242
  };
195
243
 
196
244
  export declare type ConnectItem = TonAddressItem | TonProofItem;
@@ -205,70 +253,95 @@ export declare type ConnectItemReplyError<T> = {
205
253
 
206
254
  /**
207
255
  * Create a connection completed event.
256
+ * @param version
208
257
  * @param wallet
209
258
  */
210
- export declare function createConnectionCompletedEvent(wallet: Wallet | null): ConnectionCompletedEvent;
259
+ export declare function createConnectionCompletedEvent(version: Version, wallet: Wallet | null): ConnectionCompletedEvent;
211
260
 
212
261
  /**
213
262
  * Create a connection error event.
263
+ * @param version
214
264
  * @param error_message
215
265
  * @param errorCode
216
266
  */
217
- export declare function createConnectionErrorEvent(error_message: string, errorCode: CONNECT_EVENT_ERROR_CODES | void): ConnectionErrorEvent;
267
+ export declare function createConnectionErrorEvent(version: Version, error_message: string, errorCode: CONNECT_EVENT_ERROR_CODES | void): ConnectionErrorEvent;
218
268
 
219
269
  /**
220
270
  * Create a connection restoring completed event.
271
+ * @param version
221
272
  * @param wallet
222
273
  */
223
- export declare function createConnectionRestoringCompletedEvent(wallet: Wallet | null): ConnectionRestoringCompletedEvent;
274
+ export declare function createConnectionRestoringCompletedEvent(version: Version, wallet: Wallet | null): ConnectionRestoringCompletedEvent;
224
275
 
225
276
  /**
226
277
  * Create a connection restoring error event.
278
+ * @param version
227
279
  * @param errorMessage
228
280
  */
229
- export declare function createConnectionRestoringErrorEvent(errorMessage: string): ConnectionRestoringErrorEvent;
281
+ export declare function createConnectionRestoringErrorEvent(version: Version, errorMessage: string): ConnectionRestoringErrorEvent;
230
282
 
231
283
  /**
232
284
  * Create a connection restoring started event.
233
285
  */
234
- export declare function createConnectionRestoringStartedEvent(): ConnectionRestoringStartedEvent;
286
+ export declare function createConnectionRestoringStartedEvent(version: Version): ConnectionRestoringStartedEvent;
235
287
 
236
288
  /**
237
289
  * Create a connection init event.
238
290
  */
239
- export declare function createConnectionStartedEvent(): ConnectionStartedEvent;
291
+ export declare function createConnectionStartedEvent(version: Version): ConnectionStartedEvent;
240
292
 
241
293
  /**
242
294
  * Create a disconnect event.
295
+ * @param version
243
296
  * @param wallet
244
297
  * @param scope
245
298
  * @returns
246
299
  */
247
- export declare function createDisconnectionEvent(wallet: Wallet | null, scope: 'dapp' | 'wallet'): DisconnectionEvent;
300
+ export declare function createDisconnectionEvent(version: Version, wallet: Wallet | null, scope: 'dapp' | 'wallet'): DisconnectionEvent;
301
+
302
+ /**
303
+ * Create a request version event.
304
+ */
305
+ export declare function createRequestVersionEvent(): RequestVersionEvent;
306
+
307
+ /**
308
+ * Create a response version event.
309
+ * @param version
310
+ */
311
+ export declare function createResponseVersionEvent(version: string): ResponseVersionEvent;
248
312
 
249
313
  /**
250
314
  * Create a transaction init event.
315
+ * @param version
251
316
  * @param wallet
252
317
  * @param transaction
253
318
  */
254
- export declare function createTransactionSentForSignatureEvent(wallet: Wallet | null, transaction: SendTransactionRequest): TransactionSentForSignatureEvent;
319
+ export declare function createTransactionSentForSignatureEvent(version: Version, wallet: Wallet | null, transaction: SendTransactionRequest): TransactionSentForSignatureEvent;
255
320
 
256
321
  /**
257
322
  * Create a transaction signed event.
323
+ * @param version
258
324
  * @param wallet
259
325
  * @param transaction
260
326
  * @param signedTransaction
261
327
  */
262
- export declare function createTransactionSignedEvent(wallet: Wallet | null, transaction: SendTransactionRequest, signedTransaction: SendTransactionResponse): TransactionSignedEvent;
328
+ export declare function createTransactionSignedEvent(version: Version, wallet: Wallet | null, transaction: SendTransactionRequest, signedTransaction: SendTransactionResponse): TransactionSignedEvent;
263
329
 
264
330
  /**
265
331
  * Create a transaction error event.
332
+ * @param version
266
333
  * @param wallet
267
334
  * @param transaction
268
335
  * @param errorMessage
269
336
  * @param errorCode
270
337
  */
271
- export declare function createTransactionSigningFailedEvent(wallet: Wallet | null, transaction: SendTransactionRequest, errorMessage: string, errorCode: SEND_TRANSACTION_ERROR_CODES | void): TransactionSigningFailedEvent;
338
+ export declare function createTransactionSigningFailedEvent(version: Version, wallet: Wallet | null, transaction: SendTransactionRequest, errorMessage: string, errorCode: SEND_TRANSACTION_ERROR_CODES | void): TransactionSigningFailedEvent;
339
+
340
+ /**
341
+ * Create a version info.
342
+ * @param version
343
+ */
344
+ export declare function createVersionInfo(version: Version): Version;
272
345
 
273
346
  export declare interface DappMetadata {
274
347
  /**
@@ -316,13 +389,27 @@ export declare function encodeTelegramUrlParameters(parameters: string): string;
316
389
  /**
317
390
  * Interface for an event dispatcher that sends events.
318
391
  */
319
- export declare interface EventDispatcher<T> {
392
+ export declare interface EventDispatcher<T extends {
393
+ type: string;
394
+ }> {
320
395
  /**
321
396
  * Dispatches an event with the given name and details.
322
397
  * @param eventName - The name of the event to dispatch.
323
398
  * @param eventDetails - The details of the event to dispatch.
324
399
  */
325
- dispatchEvent(eventName: string, eventDetails: T): Promise<void>;
400
+ dispatchEvent<P extends AddTonConnectPrefix<T['type']>>(eventName: P, eventDetails: T & {
401
+ type: RemoveTonConnectPrefix<P>;
402
+ }): Promise<void>;
403
+ /**
404
+ * Adds an event listener.
405
+ * @param eventName - The name of the event to listen for.
406
+ * @param listener - The listener to add.
407
+ * @param options - The options for the listener.
408
+ * @returns A function that removes the listener.
409
+ */
410
+ addEventListener<P extends AddTonConnectPrefix<T['type']>>(eventName: P, listener: (event: CustomEvent<T & {
411
+ type: RemoveTonConnectPrefix<P>;
412
+ }>) => void, options?: AddEventListenerOptions): Promise<() => void>;
326
413
  }
327
414
 
328
415
  export declare type Feature = SendTransactionFeatureDeprecated | SendTransactionFeature | SignDataFeature;
@@ -473,10 +560,39 @@ export declare class ParseHexError extends TonConnectError {
473
560
  constructor(...args: ConstructorParameters<typeof TonConnectError>);
474
561
  }
475
562
 
563
+ /**
564
+ * Removes the `ton-connect-` and `ton-connect-ui-` prefixes from the given string.
565
+ */
566
+ export declare type RemoveTonConnectPrefix<T> = T extends `ton-connect-ui-${infer Rest}` ? Rest : T extends `ton-connect-${infer Rest}` ? Rest : T;
567
+
568
+ /**
569
+ * Request TON Connect UI version.
570
+ */
571
+ export declare type RequestVersionEvent = {
572
+ /**
573
+ * Event type.
574
+ */
575
+ type: 'request-version';
576
+ };
577
+
578
+ /**
579
+ * Response TON Connect UI version.
580
+ */
581
+ export declare type ResponseVersionEvent = {
582
+ /**
583
+ * Event type.
584
+ */
585
+ type: 'response-version';
586
+ /**
587
+ * TON Connect UI version.
588
+ */
589
+ version: string;
590
+ };
591
+
476
592
  /**
477
593
  * User action events.
478
594
  */
479
- export declare type SdkActionEvent = ConnectionEvent | ConnectionRestoringEvent | DisconnectionEvent | TransactionSigningEvent;
595
+ export declare type SdkActionEvent = VersionEvent | ConnectionEvent | ConnectionRestoringEvent | DisconnectionEvent | TransactionSigningEvent;
480
596
 
481
597
  export declare enum SEND_TRANSACTION_ERROR_CODES {
482
598
  UNKNOWN_ERROR = 0,
@@ -786,6 +902,10 @@ export declare type TransactionSignedEvent = {
786
902
  * Event type.
787
903
  */
788
904
  type: 'transaction-signed';
905
+ /**
906
+ * Connection success flag.
907
+ */
908
+ is_success: true;
789
909
  /**
790
910
  * Signed transaction.
791
911
  */
@@ -805,6 +925,10 @@ export declare type TransactionSigningFailedEvent = {
805
925
  * Event type.
806
926
  */
807
927
  type: 'transaction-signing-failed';
928
+ /**
929
+ * Connection success flag.
930
+ */
931
+ is_success: false;
808
932
  /**
809
933
  * Reason for the error.
810
934
  */
@@ -838,6 +962,25 @@ export declare class UserRejectsError extends TonConnectError {
838
962
  constructor(...args: ConstructorParameters<typeof TonConnectError>);
839
963
  }
840
964
 
965
+ /**
966
+ * Version of the TON Connect SDK and TON Connect UI.
967
+ */
968
+ export declare type Version = {
969
+ /**
970
+ * TON Connect SDK version.
971
+ */
972
+ ton_connect_sdk_lib: string | null;
973
+ /**
974
+ * TON Connect UI version.
975
+ */
976
+ ton_connect_ui_lib: string | null;
977
+ };
978
+
979
+ /**
980
+ * Version events.
981
+ */
982
+ export declare type VersionEvent = RequestVersionEvent | ResponseVersionEvent;
983
+
841
984
  export declare interface Wallet {
842
985
  /**
843
986
  * Information about user's wallet's device.
@@ -1012,6 +1155,11 @@ export declare class WalletsListManager {
1012
1155
  private isCorrectWalletConfigDTO;
1013
1156
  }
1014
1157
 
1158
+ /**
1159
+ * Parameters without version field.
1160
+ */
1161
+ export declare type WithoutVersion<T> = T extends [Version, ...infer Rest] ? [...Rest] : never;
1162
+
1015
1163
  /**
1016
1164
  * Thrown when passed address is in incorrect format.
1017
1165
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonconnect/sdk",
3
- "version": "3.0.3-beta.0",
3
+ "version": "3.0.3-beta.1",
4
4
  "scripts": {
5
5
  "build": "npx rimraf types-dist && npx rimraf lib && npx rollup -c rollup.config.mjs && ttsc --project tsconfig.declarations.json && api-extractor run && npx rimraf types-dist && npx rimraf dist && npx webpack --config webpack.config.js",
6
6
  "test": "vitest run"
@@ -56,6 +56,7 @@
56
56
  "webpack-cli": "^5.0.0",
57
57
  "rollup": "^3.18.0",
58
58
  "@rollup/plugin-typescript": "^11.0.0",
59
+ "@rollup/plugin-replace": "5.0.5",
59
60
  "vite": "^4.2.1",
60
61
  "vite-tsconfig-paths": "^4.0.5",
61
62
  "vitest": "^0.29.2",