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

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,11 @@ export declare interface Account {
18
18
  publicKey?: string;
19
19
  }
20
20
 
21
+ /**
22
+ * Requested authentication type: 'ton_addr' or 'ton_proof'.
23
+ */
24
+ export declare type AuthType = ConnectItem['name'];
25
+
21
26
  /**
22
27
  * Thrown when request to the wallet contains errors.
23
28
  */
@@ -26,11 +31,39 @@ export declare class BadRequestError extends TonConnectError {
26
31
  constructor(...args: ConstructorParameters<typeof TonConnectError>);
27
32
  }
28
33
 
34
+ /**
35
+ * A concrete implementation of EventDispatcher that dispatches events to the browser window.
36
+ */
37
+ export declare class BrowserEventDispatcher<T> implements EventDispatcher<T> {
38
+ /**
39
+ * The window object, possibly undefined in a server environment.
40
+ * @private
41
+ */
42
+ private readonly window;
43
+ /**
44
+ * Dispatches an event with the given name and details to the browser window.
45
+ * @param eventName - The name of the event to dispatch.
46
+ * @param eventDetails - The details of the event to dispatch.
47
+ * @returns A promise that resolves when the event has been dispatched.
48
+ */
49
+ dispatchEvent(eventName: string, eventDetails: T): Promise<void>;
50
+ }
51
+
29
52
  export declare enum CHAIN {
30
53
  MAINNET = "-239",
31
54
  TESTNET = "-3"
32
55
  }
33
56
 
57
+ export declare enum CONNECT_EVENT_ERROR_CODES {
58
+ UNKNOWN_ERROR = 0,
59
+ BAD_REQUEST_ERROR = 1,
60
+ MANIFEST_NOT_FOUND_ERROR = 2,
61
+ MANIFEST_CONTENT_ERROR = 3,
62
+ UNKNOWN_APP_ERROR = 100,
63
+ USER_REJECTS_ERROR = 300,
64
+ METHOD_NOT_SUPPORTED = 400
65
+ }
66
+
34
67
  export declare enum CONNECT_ITEM_ERROR_CODES {
35
68
  UNKNOWN_ERROR = 0,
36
69
  METHOD_NOT_SUPPORTED = 400
@@ -43,6 +76,125 @@ export declare interface ConnectAdditionalRequest {
43
76
  tonProof?: string;
44
77
  }
45
78
 
79
+ /**
80
+ * Successful connection event when a user successfully connected a wallet.
81
+ */
82
+ export declare type ConnectionCompletedEvent = {
83
+ /**
84
+ * Event type.
85
+ */
86
+ type: 'connection-completed';
87
+ } & ConnectionInfo;
88
+
89
+ /**
90
+ * Connection error event when a user cancels a connection or there is an error during the connection process.
91
+ */
92
+ export declare type ConnectionErrorEvent = {
93
+ /**
94
+ * Event type.
95
+ */
96
+ type: 'connection-error';
97
+ /**
98
+ * Reason for the error.
99
+ */
100
+ error_message: string;
101
+ /**
102
+ * Error code.
103
+ */
104
+ error_code: CONNECT_EVENT_ERROR_CODES | null;
105
+ };
106
+
107
+ /**
108
+ * Connection events.
109
+ */
110
+ export declare type ConnectionEvent = ConnectionStartedEvent | ConnectionCompletedEvent | ConnectionErrorEvent;
111
+
112
+ /**
113
+ * Information about a connected wallet.
114
+ */
115
+ export declare type ConnectionInfo = {
116
+ /**
117
+ * Connected wallet address.
118
+ */
119
+ wallet_address: string | null;
120
+ /**
121
+ * Wallet type: 'tonkeeper', 'tonhub', etc.
122
+ */
123
+ wallet_type: string | null;
124
+ /**
125
+ * Wallet version.
126
+ */
127
+ wallet_version: string | null;
128
+ /**
129
+ * Requested authentication types.
130
+ */
131
+ auth_type: AuthType;
132
+ /**
133
+ * Custom data for the connection.
134
+ */
135
+ custom_data: {
136
+ /**
137
+ * Connected chain ID.
138
+ */
139
+ chain_id: string | null;
140
+ /**
141
+ * Wallet provider.
142
+ */
143
+ provider: 'http' | 'injected' | null;
144
+ };
145
+ };
146
+
147
+ /**
148
+ * Connection restoring completed event when successfully restored a connection.
149
+ */
150
+ export declare type ConnectionRestoringCompletedEvent = {
151
+ /**
152
+ * Event type.
153
+ */
154
+ type: 'connection-restoring-completed';
155
+ } & ConnectionInfo;
156
+
157
+ /**
158
+ * Connection restoring error event when there is an error during the connection restoring process.
159
+ */
160
+ export declare type ConnectionRestoringErrorEvent = {
161
+ /**
162
+ * Event type.
163
+ */
164
+ type: 'connection-restoring-error';
165
+ /**
166
+ * Reason for the error.
167
+ */
168
+ error_message: string;
169
+ };
170
+
171
+ /**
172
+ * Connection restoring events.
173
+ */
174
+ export declare type ConnectionRestoringEvent = ConnectionRestoringStartedEvent | ConnectionRestoringCompletedEvent | ConnectionRestoringErrorEvent;
175
+
176
+ /**
177
+ * Connection restoring started event when initiates a connection restoring process.
178
+ */
179
+ export declare type ConnectionRestoringStartedEvent = {
180
+ /**
181
+ * Event type.
182
+ */
183
+ type: 'connection-restoring-started';
184
+ };
185
+
186
+ /**
187
+ * Initial connection event when a user initiates a connection.
188
+ */
189
+ export declare type ConnectionStartedEvent = {
190
+ /**
191
+ * Event type.
192
+ */
193
+ type: 'connection-started';
194
+ };
195
+
196
+ export declare type ConnectItem = TonAddressItem | TonProofItem;
197
+
46
198
  export declare type ConnectItemReplyError<T> = {
47
199
  name: T;
48
200
  error: {
@@ -51,6 +203,73 @@ export declare type ConnectItemReplyError<T> = {
51
203
  };
52
204
  };
53
205
 
206
+ /**
207
+ * Create a connection completed event.
208
+ * @param wallet
209
+ */
210
+ export declare function createConnectionCompletedEvent(wallet: Wallet | null): ConnectionCompletedEvent;
211
+
212
+ /**
213
+ * Create a connection error event.
214
+ * @param error_message
215
+ * @param errorCode
216
+ */
217
+ export declare function createConnectionErrorEvent(error_message: string, errorCode: CONNECT_EVENT_ERROR_CODES | void): ConnectionErrorEvent;
218
+
219
+ /**
220
+ * Create a connection restoring completed event.
221
+ * @param wallet
222
+ */
223
+ export declare function createConnectionRestoringCompletedEvent(wallet: Wallet | null): ConnectionRestoringCompletedEvent;
224
+
225
+ /**
226
+ * Create a connection restoring error event.
227
+ * @param errorMessage
228
+ */
229
+ export declare function createConnectionRestoringErrorEvent(errorMessage: string): ConnectionRestoringErrorEvent;
230
+
231
+ /**
232
+ * Create a connection restoring started event.
233
+ */
234
+ export declare function createConnectionRestoringStartedEvent(): ConnectionRestoringStartedEvent;
235
+
236
+ /**
237
+ * Create a connection init event.
238
+ */
239
+ export declare function createConnectionStartedEvent(): ConnectionStartedEvent;
240
+
241
+ /**
242
+ * Create a disconnect event.
243
+ * @param wallet
244
+ * @param scope
245
+ * @returns
246
+ */
247
+ export declare function createDisconnectionEvent(wallet: Wallet | null, scope: 'dapp' | 'wallet'): DisconnectionEvent;
248
+
249
+ /**
250
+ * Create a transaction init event.
251
+ * @param wallet
252
+ * @param transaction
253
+ */
254
+ export declare function createTransactionSentForSignatureEvent(wallet: Wallet | null, transaction: SendTransactionRequest): TransactionSentForSignatureEvent;
255
+
256
+ /**
257
+ * Create a transaction signed event.
258
+ * @param wallet
259
+ * @param transaction
260
+ * @param signedTransaction
261
+ */
262
+ export declare function createTransactionSignedEvent(wallet: Wallet | null, transaction: SendTransactionRequest, signedTransaction: SendTransactionResponse): TransactionSignedEvent;
263
+
264
+ /**
265
+ * Create a transaction error event.
266
+ * @param wallet
267
+ * @param transaction
268
+ * @param errorMessage
269
+ * @param errorCode
270
+ */
271
+ export declare function createTransactionSigningFailedEvent(wallet: Wallet | null, transaction: SendTransactionRequest, errorMessage: string, errorCode: SEND_TRANSACTION_ERROR_CODES | void): TransactionSigningFailedEvent;
272
+
54
273
  export declare interface DappMetadata {
55
274
  /**
56
275
  * Dapp name. Might be simple, will not be used as identifier.
@@ -78,8 +297,34 @@ export declare interface DeviceInfo {
78
297
  features: Feature[];
79
298
  }
80
299
 
300
+ /**
301
+ * Disconnect event when a user initiates a disconnection.
302
+ */
303
+ export declare type DisconnectionEvent = {
304
+ /**
305
+ * Event type.
306
+ */
307
+ type: 'disconnection';
308
+ /**
309
+ * Disconnect scope: 'dapp' or 'wallet'.
310
+ */
311
+ scope: 'dapp' | 'wallet';
312
+ } & ConnectionInfo;
313
+
81
314
  export declare function encodeTelegramUrlParameters(parameters: string): string;
82
315
 
316
+ /**
317
+ * Interface for an event dispatcher that sends events.
318
+ */
319
+ export declare interface EventDispatcher<T> {
320
+ /**
321
+ * Dispatches an event with the given name and details.
322
+ * @param eventName - The name of the event to dispatch.
323
+ * @param eventDetails - The details of the event to dispatch.
324
+ */
325
+ dispatchEvent(eventName: string, eventDetails: T): Promise<void>;
326
+ }
327
+
83
328
  export declare type Feature = SendTransactionFeatureDeprecated | SendTransactionFeature | SignDataFeature;
84
329
 
85
330
  /**
@@ -228,6 +473,19 @@ export declare class ParseHexError extends TonConnectError {
228
473
  constructor(...args: ConstructorParameters<typeof TonConnectError>);
229
474
  }
230
475
 
476
+ /**
477
+ * User action events.
478
+ */
479
+ export declare type SdkActionEvent = ConnectionEvent | ConnectionRestoringEvent | DisconnectionEvent | TransactionSigningEvent;
480
+
481
+ export declare enum SEND_TRANSACTION_ERROR_CODES {
482
+ UNKNOWN_ERROR = 0,
483
+ BAD_REQUEST_ERROR = 1,
484
+ UNKNOWN_APP_ERROR = 100,
485
+ USER_REJECTS_ERROR = 300,
486
+ METHOD_NOT_SUPPORTED = 400
487
+ }
488
+
231
489
  export declare type SendTransactionFeature = {
232
490
  name: 'SendTransaction';
233
491
  maxMessages: number;
@@ -282,6 +540,10 @@ export declare type SignDataFeature = {
282
540
  name: 'SignData';
283
541
  };
284
542
 
543
+ export declare interface TonAddressItem {
544
+ name: 'ton_addr';
545
+ }
546
+
285
547
  declare class TonConnect implements ITonConnect {
286
548
  private static readonly walletsList;
287
549
  /**
@@ -298,6 +560,11 @@ declare class TonConnect implements ITonConnect {
298
560
  * Returns available wallets list.
299
561
  */
300
562
  static getWallets(): Promise<WalletInfo[]>;
563
+ /**
564
+ * Emits user action event to the EventDispatcher. By default, it uses `window.dispatchEvent` for browser environment.
565
+ * @private
566
+ */
567
+ private readonly tracker;
301
568
  private readonly walletsList;
302
569
  private readonly dappSettings;
303
570
  private readonly bridgeConnectionStorage;
@@ -419,6 +686,10 @@ export declare interface TonConnectOptions {
419
686
  * Storage to save protocol data. For browser default is `localStorage`. If you use SDK with nodeJS, you have to specify this field.
420
687
  */
421
688
  storage?: IStorage;
689
+ /**
690
+ * Event dispatcher to track user actions. By default, it uses `window.dispatchEvent` for browser environment.
691
+ */
692
+ eventDispatcher?: EventDispatcher<SdkActionEvent>;
422
693
  /**
423
694
  * Redefine wallets list source URL. Must be a link to a json file with [following structure]{@link https://github.com/ton-connect/wallets-list}
424
695
  * @default https://raw.githubusercontent.com/ton-connect/wallets-list/main/wallets.json
@@ -436,6 +707,11 @@ export declare interface TonConnectOptions {
436
707
  disableAutoPauseConnection?: boolean;
437
708
  }
438
709
 
710
+ export declare interface TonProofItem {
711
+ name: 'ton_proof';
712
+ payload: string;
713
+ }
714
+
439
715
  export declare type TonProofItemReply = TonProofItemReplySuccess | TonProofItemReplyError;
440
716
 
441
717
  export declare type TonProofItemReplyError = ConnectItemReplyError<TonProofItemReplySuccess['name']>;
@@ -460,6 +736,85 @@ export declare interface TonProofItemReplySuccess {
460
736
  */
461
737
  export declare function toUserFriendlyAddress(hexAddress: string, testOnly?: boolean): string;
462
738
 
739
+ /**
740
+ * Transaction information.
741
+ */
742
+ export declare type TransactionInfo = {
743
+ /**
744
+ * Transaction validity time in unix timestamp.
745
+ */
746
+ valid_until: string | null;
747
+ /**
748
+ * Sender address.
749
+ */
750
+ from: string | null;
751
+ /**
752
+ * Transaction messages.
753
+ */
754
+ messages: TransactionMessage[];
755
+ };
756
+
757
+ /**
758
+ * Transaction message.
759
+ */
760
+ export declare type TransactionMessage = {
761
+ /**
762
+ * Recipient address.
763
+ */
764
+ address: string | null;
765
+ /**
766
+ * Transfer amount.
767
+ */
768
+ amount: string | null;
769
+ };
770
+
771
+ /**
772
+ * Initial transaction event when a user initiates a transaction.
773
+ */
774
+ export declare type TransactionSentForSignatureEvent = {
775
+ /**
776
+ * Event type.
777
+ */
778
+ type: 'transaction-sent-for-signature';
779
+ } & ConnectionInfo & TransactionInfo;
780
+
781
+ /**
782
+ * Transaction signed event when a user successfully signed a transaction.
783
+ */
784
+ export declare type TransactionSignedEvent = {
785
+ /**
786
+ * Event type.
787
+ */
788
+ type: 'transaction-signed';
789
+ /**
790
+ * Signed transaction.
791
+ */
792
+ signed_transaction: string;
793
+ } & ConnectionInfo & TransactionInfo;
794
+
795
+ /**
796
+ * Transaction events.
797
+ */
798
+ export declare type TransactionSigningEvent = TransactionSentForSignatureEvent | TransactionSignedEvent | TransactionSigningFailedEvent;
799
+
800
+ /**
801
+ * Transaction error event when a user cancels a transaction or there is an error during the transaction process.
802
+ */
803
+ export declare type TransactionSigningFailedEvent = {
804
+ /**
805
+ * Event type.
806
+ */
807
+ type: 'transaction-signing-failed';
808
+ /**
809
+ * Reason for the error.
810
+ */
811
+ error_message: string;
812
+ /**
813
+ * Error code.
814
+ */
815
+ error_code: SEND_TRANSACTION_ERROR_CODES | null;
816
+ } & ConnectionInfo & TransactionInfo;
817
+
463
818
  /**
464
819
  * Thrown when app tries to send rpc request to the injected wallet while not connected.
465
820
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonconnect/sdk",
3
- "version": "3.0.2-beta.0",
3
+ "version": "3.0.3-beta.0",
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"