@tonconnect/sdk 2.0.3 → 2.0.5

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.
@@ -15,7 +15,8 @@ const bridge_connection_storage_1 = require("../../storage/bridge-connection-sto
15
15
  const web_api_1 = require("../../utils/web-api");
16
16
  const protocol_1 = require("../../resources/protocol");
17
17
  class InjectedProvider {
18
- constructor(injectedWalletKey) {
18
+ constructor(storage, injectedWalletKey) {
19
+ this.injectedWalletKey = injectedWalletKey;
19
20
  this.type = 'injected';
20
21
  this.unsubscribeCallback = null;
21
22
  this.listenSubscriptions = false;
@@ -24,13 +25,14 @@ class InjectedProvider {
24
25
  if (!InjectedProvider.isWindowContainsWallet(window, injectedWalletKey)) {
25
26
  throw new wallet_not_injected_error_1.WalletNotInjectedError();
26
27
  }
28
+ this.connectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(storage);
27
29
  this.injectedWallet = window[injectedWalletKey].tonconnect;
28
30
  }
29
31
  static fromStorage(storage) {
30
32
  return __awaiter(this, void 0, void 0, function* () {
31
33
  const bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(storage);
32
34
  const connection = yield bridgeConnectionStorage.getInjectedConnection();
33
- return new InjectedProvider(connection.jsBridgeKey);
35
+ return new InjectedProvider(storage, connection.jsBridgeKey);
34
36
  });
35
37
  }
36
38
  static isWalletInjected(injectedWalletKey) {
@@ -48,26 +50,8 @@ class InjectedProvider {
48
50
  typeof window[injectedWalletKey] === 'object' &&
49
51
  'tonconnect' in window[injectedWalletKey]);
50
52
  }
51
- connect(message, auto = false) {
52
- this.injectedWallet
53
- .connect(protocol_1.PROTOCOL_VERSION, message, auto)
54
- .then(connectEvent => {
55
- if (connectEvent.event === 'connect') {
56
- this.makeSubscriptions();
57
- this.listenSubscriptions = true;
58
- }
59
- this.listeners.forEach(listener => listener(connectEvent));
60
- })
61
- .catch(e => {
62
- const connectEventError = {
63
- event: 'connect_error',
64
- payload: {
65
- code: 0,
66
- message: e === null || e === void 0 ? void 0 : e.toString()
67
- }
68
- };
69
- this.listeners.forEach(listener => listener(connectEventError));
70
- });
53
+ connect(message) {
54
+ this._connect(protocol_1.PROTOCOL_VERSION, message);
71
55
  }
72
56
  restoreConnection() {
73
57
  return __awaiter(this, void 0, void 0, function* () {
@@ -75,11 +59,14 @@ class InjectedProvider {
75
59
  const connectEvent = yield this.injectedWallet.restoreConnection();
76
60
  if (connectEvent.event === 'connect') {
77
61
  this.makeSubscriptions();
78
- this.listenSubscriptions = true;
79
62
  this.listeners.forEach(listener => listener(connectEvent));
80
63
  }
64
+ else {
65
+ yield this.connectionStorage.removeConnection();
66
+ }
81
67
  }
82
68
  catch (e) {
69
+ yield this.connectionStorage.removeConnection();
83
70
  console.error(e);
84
71
  }
85
72
  });
@@ -93,7 +80,7 @@ class InjectedProvider {
93
80
  disconnect() {
94
81
  this.closeAllListeners();
95
82
  this.injectedWallet.disconnect();
96
- return Promise.resolve();
83
+ return this.connectionStorage.removeConnection();
97
84
  }
98
85
  closeAllListeners() {
99
86
  var _a;
@@ -110,7 +97,31 @@ class InjectedProvider {
110
97
  return this.injectedWallet.send(Object.assign(Object.assign({}, request), { id: '0' }));
111
98
  });
112
99
  }
100
+ _connect(protocolVersion, message) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ try {
103
+ const connectEvent = yield this.injectedWallet.connect(protocolVersion, message);
104
+ if (connectEvent.event === 'connect') {
105
+ yield this.updateSession();
106
+ this.makeSubscriptions();
107
+ }
108
+ this.listeners.forEach(listener => listener(connectEvent));
109
+ }
110
+ catch (e) {
111
+ console.debug(e);
112
+ const connectEventError = {
113
+ event: 'connect_error',
114
+ payload: {
115
+ code: 0,
116
+ message: e === null || e === void 0 ? void 0 : e.toString()
117
+ }
118
+ };
119
+ this.listeners.forEach(listener => listener(connectEventError));
120
+ }
121
+ });
122
+ }
113
123
  makeSubscriptions() {
124
+ this.listenSubscriptions = true;
114
125
  this.unsubscribeCallback = this.injectedWallet.listen(e => {
115
126
  if (this.listenSubscriptions) {
116
127
  this.listeners.forEach(listener => listener(e));
@@ -120,6 +131,12 @@ class InjectedProvider {
120
131
  }
121
132
  });
122
133
  }
134
+ updateSession() {
135
+ return this.connectionStorage.storeConnection({
136
+ type: 'injected',
137
+ jsBridgeKey: this.injectedWalletKey
138
+ });
139
+ }
123
140
  }
124
141
  exports.InjectedProvider = InjectedProvider;
125
142
  InjectedProvider.window = (0, web_api_1.getWindow)();
@@ -19,7 +19,6 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  }
20
20
  return t;
21
21
  };
22
- var _a;
23
22
  Object.defineProperty(exports, "__esModule", { value: true });
24
23
  exports.TonConnect = void 0;
25
24
  const dapp_metadata_error_1 = require("./errors/dapp/dapp-metadata.error");
@@ -49,11 +48,18 @@ class TonConnect {
49
48
  manifestUrl: (options === null || options === void 0 ? void 0 : options.manifestUrl) || (0, web_api_1.getWebPageManifest)(),
50
49
  storage: (options === null || options === void 0 ? void 0 : options.storage) || new default_storage_1.DefaultStorage()
51
50
  };
51
+ this.walletsList = new wallets_list_manager_1.WalletsListManager(options === null || options === void 0 ? void 0 : options.walletsListSource);
52
52
  if (!this.dappSettings.manifestUrl) {
53
53
  throw new dapp_metadata_error_1.DappMetadataError('Dapp tonconnect-manifest.json must be specified if window.location.origin is undefined. See more https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest');
54
54
  }
55
55
  this.bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(this.dappSettings.storage);
56
56
  }
57
+ /**
58
+ * Returns available wallets list.
59
+ */
60
+ static getWallets() {
61
+ return this.walletsList.getWallets();
62
+ }
57
63
  /**
58
64
  * Shows if the wallet is connected right now.
59
65
  */
@@ -64,8 +70,8 @@ class TonConnect {
64
70
  * Current connected account or null if no account is connected.
65
71
  */
66
72
  get account() {
67
- var _b;
68
- return ((_b = this._wallet) === null || _b === void 0 ? void 0 : _b.account) || null;
73
+ var _a;
74
+ return ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.account) || null;
69
75
  }
70
76
  /**
71
77
  * Current connected wallet or null if no account is connected.
@@ -102,11 +108,11 @@ class TonConnect {
102
108
  };
103
109
  }
104
110
  connect(wallet, request) {
105
- var _b;
111
+ var _a;
106
112
  if (this.connected) {
107
113
  throw new wallet_already_connected_error_1.WalletAlreadyConnectedError();
108
114
  }
109
- (_b = this.provider) === null || _b === void 0 ? void 0 : _b.closeConnection();
115
+ (_a = this.provider) === null || _a === void 0 ? void 0 : _a.closeConnection();
110
116
  this.provider = this.createProvider(wallet);
111
117
  return this.provider.connect(this.createConnectRequest(request));
112
118
  }
@@ -171,7 +177,7 @@ class TonConnect {
171
177
  createProvider(wallet) {
172
178
  let provider;
173
179
  if ((0, wallet_connection_source_1.isWalletConnectionSourceJS)(wallet)) {
174
- provider = new injected_provider_1.InjectedProvider(wallet.jsBridgeKey);
180
+ provider = new injected_provider_1.InjectedProvider(this.dappSettings.storage, wallet.jsBridgeKey);
175
181
  }
176
182
  else {
177
183
  provider = new bridge_provider_1.BridgeProvider(this.dappSettings.storage, wallet);
@@ -231,8 +237,8 @@ class TonConnect {
231
237
  }
232
238
  }
233
239
  checkFeatureSupport(feature) {
234
- var _b;
235
- if (!((_b = this.wallet) === null || _b === void 0 ? void 0 : _b.device.features.includes(feature))) {
240
+ var _a;
241
+ if (!((_a = this.wallet) === null || _a === void 0 ? void 0 : _a.device.features.includes(feature))) {
236
242
  throw new wallet_not_support_feature_error_1.WalletNotSupportFeatureError();
237
243
  }
238
244
  }
@@ -255,9 +261,14 @@ class TonConnect {
255
261
  }
256
262
  }
257
263
  exports.TonConnect = TonConnect;
258
- _a = TonConnect;
259
264
  TonConnect.walletsList = new wallets_list_manager_1.WalletsListManager();
260
265
  /**
261
- * Returns available wallets list.
266
+ * Check if specified wallet is injected and available to use with the app.
267
+ * @param walletJSKey target wallet's js bridge key.
268
+ */
269
+ TonConnect.isWalletInjected = (walletJSKey) => injected_provider_1.InjectedProvider.isWalletInjected(walletJSKey);
270
+ /**
271
+ * Check if the app is opened inside specified wallet's browser.
272
+ * @param walletJSKey target wallet's js bridge key.
262
273
  */
263
- TonConnect.getWallets = _a.walletsList.getWallets();
274
+ TonConnect.isInsideWalletBrowser = (walletJSKey) => injected_provider_1.InjectedProvider.isInsideWalletBrowser(walletJSKey);
@@ -14,9 +14,12 @@ const fetch_wallets_error_1 = require("./errors/wallets-manager/fetch-wallets.er
14
14
  const wallet_info_1 = require("./models/wallet/wallet-info");
15
15
  const injected_provider_1 = require("./provider/injected/injected-provider");
16
16
  class WalletsListManager {
17
- constructor() {
17
+ constructor(walletsListSource) {
18
18
  this.walletsListCache = null;
19
19
  this.walletsListSource = 'https://raw.githubusercontent.com/ton-connect/wallets-list/main/wallets.json';
20
+ if (walletsListSource) {
21
+ this.walletsListSource = walletsListSource;
22
+ }
20
23
  }
21
24
  getWallets() {
22
25
  return __awaiter(this, void 0, void 0, function* () {
@@ -30,11 +33,11 @@ class WalletsListManager {
30
33
  getEmbeddedWallet() {
31
34
  return __awaiter(this, void 0, void 0, function* () {
32
35
  const walletsList = yield this.getWallets();
33
- const injectedWallets = walletsList.filter(wallet_info_1.isWalletInfoInjected);
34
- if (injectedWallets.length !== 1) {
36
+ const embeddedWallets = walletsList.filter(item => (0, wallet_info_1.isWalletInfoInjected)(item) && item.embedded);
37
+ if (embeddedWallets.length !== 1) {
35
38
  return null;
36
39
  }
37
- return injectedWallets[0].embedded ? injectedWallets[0] : null;
40
+ return embeddedWallets[0];
38
41
  });
39
42
  }
40
43
  fetchWalletsList() {
@@ -12,7 +12,8 @@ import { BridgeConnectionStorage } from "../../storage/bridge-connection-storage
12
12
  import { getWindow } from "../../utils/web-api";
13
13
  import { PROTOCOL_VERSION } from "../../resources/protocol";
14
14
  export class InjectedProvider {
15
- constructor(injectedWalletKey) {
15
+ constructor(storage, injectedWalletKey) {
16
+ this.injectedWalletKey = injectedWalletKey;
16
17
  this.type = 'injected';
17
18
  this.unsubscribeCallback = null;
18
19
  this.listenSubscriptions = false;
@@ -21,13 +22,14 @@ export class InjectedProvider {
21
22
  if (!InjectedProvider.isWindowContainsWallet(window, injectedWalletKey)) {
22
23
  throw new WalletNotInjectedError();
23
24
  }
25
+ this.connectionStorage = new BridgeConnectionStorage(storage);
24
26
  this.injectedWallet = window[injectedWalletKey].tonconnect;
25
27
  }
26
28
  static fromStorage(storage) {
27
29
  return __awaiter(this, void 0, void 0, function* () {
28
30
  const bridgeConnectionStorage = new BridgeConnectionStorage(storage);
29
31
  const connection = yield bridgeConnectionStorage.getInjectedConnection();
30
- return new InjectedProvider(connection.jsBridgeKey);
32
+ return new InjectedProvider(storage, connection.jsBridgeKey);
31
33
  });
32
34
  }
33
35
  static isWalletInjected(injectedWalletKey) {
@@ -45,26 +47,8 @@ export class InjectedProvider {
45
47
  typeof window[injectedWalletKey] === 'object' &&
46
48
  'tonconnect' in window[injectedWalletKey]);
47
49
  }
48
- connect(message, auto = false) {
49
- this.injectedWallet
50
- .connect(PROTOCOL_VERSION, message, auto)
51
- .then(connectEvent => {
52
- if (connectEvent.event === 'connect') {
53
- this.makeSubscriptions();
54
- this.listenSubscriptions = true;
55
- }
56
- this.listeners.forEach(listener => listener(connectEvent));
57
- })
58
- .catch(e => {
59
- const connectEventError = {
60
- event: 'connect_error',
61
- payload: {
62
- code: 0,
63
- message: e === null || e === void 0 ? void 0 : e.toString()
64
- }
65
- };
66
- this.listeners.forEach(listener => listener(connectEventError));
67
- });
50
+ connect(message) {
51
+ this._connect(PROTOCOL_VERSION, message);
68
52
  }
69
53
  restoreConnection() {
70
54
  return __awaiter(this, void 0, void 0, function* () {
@@ -72,11 +56,14 @@ export class InjectedProvider {
72
56
  const connectEvent = yield this.injectedWallet.restoreConnection();
73
57
  if (connectEvent.event === 'connect') {
74
58
  this.makeSubscriptions();
75
- this.listenSubscriptions = true;
76
59
  this.listeners.forEach(listener => listener(connectEvent));
77
60
  }
61
+ else {
62
+ yield this.connectionStorage.removeConnection();
63
+ }
78
64
  }
79
65
  catch (e) {
66
+ yield this.connectionStorage.removeConnection();
80
67
  console.error(e);
81
68
  }
82
69
  });
@@ -90,7 +77,7 @@ export class InjectedProvider {
90
77
  disconnect() {
91
78
  this.closeAllListeners();
92
79
  this.injectedWallet.disconnect();
93
- return Promise.resolve();
80
+ return this.connectionStorage.removeConnection();
94
81
  }
95
82
  closeAllListeners() {
96
83
  var _a;
@@ -107,7 +94,31 @@ export class InjectedProvider {
107
94
  return this.injectedWallet.send(Object.assign(Object.assign({}, request), { id: '0' }));
108
95
  });
109
96
  }
97
+ _connect(protocolVersion, message) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ try {
100
+ const connectEvent = yield this.injectedWallet.connect(protocolVersion, message);
101
+ if (connectEvent.event === 'connect') {
102
+ yield this.updateSession();
103
+ this.makeSubscriptions();
104
+ }
105
+ this.listeners.forEach(listener => listener(connectEvent));
106
+ }
107
+ catch (e) {
108
+ console.debug(e);
109
+ const connectEventError = {
110
+ event: 'connect_error',
111
+ payload: {
112
+ code: 0,
113
+ message: e === null || e === void 0 ? void 0 : e.toString()
114
+ }
115
+ };
116
+ this.listeners.forEach(listener => listener(connectEventError));
117
+ }
118
+ });
119
+ }
110
120
  makeSubscriptions() {
121
+ this.listenSubscriptions = true;
111
122
  this.unsubscribeCallback = this.injectedWallet.listen(e => {
112
123
  if (this.listenSubscriptions) {
113
124
  this.listeners.forEach(listener => listener(e));
@@ -117,5 +128,11 @@ export class InjectedProvider {
117
128
  }
118
129
  });
119
130
  }
131
+ updateSession() {
132
+ return this.connectionStorage.storeConnection({
133
+ type: 'injected',
134
+ jsBridgeKey: this.injectedWalletKey
135
+ });
136
+ }
120
137
  }
121
138
  InjectedProvider.window = getWindow();
@@ -18,7 +18,6 @@ var __rest = (this && this.__rest) || function (s, e) {
18
18
  }
19
19
  return t;
20
20
  };
21
- var _a;
22
21
  import { DappMetadataError } from "./errors/dapp/dapp-metadata.error";
23
22
  import { ManifestContentErrorError } from "./errors/protocol/events/connect/manifest-content-error.error";
24
23
  import { ManifestNotFoundError } from "./errors/protocol/events/connect/manifest-not-found.error";
@@ -46,11 +45,18 @@ export class TonConnect {
46
45
  manifestUrl: (options === null || options === void 0 ? void 0 : options.manifestUrl) || getWebPageManifest(),
47
46
  storage: (options === null || options === void 0 ? void 0 : options.storage) || new DefaultStorage()
48
47
  };
48
+ this.walletsList = new WalletsListManager(options === null || options === void 0 ? void 0 : options.walletsListSource);
49
49
  if (!this.dappSettings.manifestUrl) {
50
50
  throw new DappMetadataError('Dapp tonconnect-manifest.json must be specified if window.location.origin is undefined. See more https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest');
51
51
  }
52
52
  this.bridgeConnectionStorage = new BridgeConnectionStorage(this.dappSettings.storage);
53
53
  }
54
+ /**
55
+ * Returns available wallets list.
56
+ */
57
+ static getWallets() {
58
+ return this.walletsList.getWallets();
59
+ }
54
60
  /**
55
61
  * Shows if the wallet is connected right now.
56
62
  */
@@ -61,8 +67,8 @@ export class TonConnect {
61
67
  * Current connected account or null if no account is connected.
62
68
  */
63
69
  get account() {
64
- var _b;
65
- return ((_b = this._wallet) === null || _b === void 0 ? void 0 : _b.account) || null;
70
+ var _a;
71
+ return ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.account) || null;
66
72
  }
67
73
  /**
68
74
  * Current connected wallet or null if no account is connected.
@@ -99,11 +105,11 @@ export class TonConnect {
99
105
  };
100
106
  }
101
107
  connect(wallet, request) {
102
- var _b;
108
+ var _a;
103
109
  if (this.connected) {
104
110
  throw new WalletAlreadyConnectedError();
105
111
  }
106
- (_b = this.provider) === null || _b === void 0 ? void 0 : _b.closeConnection();
112
+ (_a = this.provider) === null || _a === void 0 ? void 0 : _a.closeConnection();
107
113
  this.provider = this.createProvider(wallet);
108
114
  return this.provider.connect(this.createConnectRequest(request));
109
115
  }
@@ -168,7 +174,7 @@ export class TonConnect {
168
174
  createProvider(wallet) {
169
175
  let provider;
170
176
  if (isWalletConnectionSourceJS(wallet)) {
171
- provider = new InjectedProvider(wallet.jsBridgeKey);
177
+ provider = new InjectedProvider(this.dappSettings.storage, wallet.jsBridgeKey);
172
178
  }
173
179
  else {
174
180
  provider = new BridgeProvider(this.dappSettings.storage, wallet);
@@ -228,8 +234,8 @@ export class TonConnect {
228
234
  }
229
235
  }
230
236
  checkFeatureSupport(feature) {
231
- var _b;
232
- if (!((_b = this.wallet) === null || _b === void 0 ? void 0 : _b.device.features.includes(feature))) {
237
+ var _a;
238
+ if (!((_a = this.wallet) === null || _a === void 0 ? void 0 : _a.device.features.includes(feature))) {
233
239
  throw new WalletNotSupportFeatureError();
234
240
  }
235
241
  }
@@ -251,9 +257,14 @@ export class TonConnect {
251
257
  };
252
258
  }
253
259
  }
254
- _a = TonConnect;
255
260
  TonConnect.walletsList = new WalletsListManager();
256
261
  /**
257
- * Returns available wallets list.
262
+ * Check if specified wallet is injected and available to use with the app.
263
+ * @param walletJSKey target wallet's js bridge key.
264
+ */
265
+ TonConnect.isWalletInjected = (walletJSKey) => InjectedProvider.isWalletInjected(walletJSKey);
266
+ /**
267
+ * Check if the app is opened inside specified wallet's browser.
268
+ * @param walletJSKey target wallet's js bridge key.
258
269
  */
259
- TonConnect.getWallets = _a.walletsList.getWallets();
270
+ TonConnect.isInsideWalletBrowser = (walletJSKey) => InjectedProvider.isInsideWalletBrowser(walletJSKey);
@@ -11,9 +11,12 @@ import { FetchWalletsError } from "./errors/wallets-manager/fetch-wallets.error"
11
11
  import { isWalletInfoInjected } from "./models/wallet/wallet-info";
12
12
  import { InjectedProvider } from "./provider/injected/injected-provider";
13
13
  export class WalletsListManager {
14
- constructor() {
14
+ constructor(walletsListSource) {
15
15
  this.walletsListCache = null;
16
16
  this.walletsListSource = 'https://raw.githubusercontent.com/ton-connect/wallets-list/main/wallets.json';
17
+ if (walletsListSource) {
18
+ this.walletsListSource = walletsListSource;
19
+ }
17
20
  }
18
21
  getWallets() {
19
22
  return __awaiter(this, void 0, void 0, function* () {
@@ -27,11 +30,11 @@ export class WalletsListManager {
27
30
  getEmbeddedWallet() {
28
31
  return __awaiter(this, void 0, void 0, function* () {
29
32
  const walletsList = yield this.getWallets();
30
- const injectedWallets = walletsList.filter(isWalletInfoInjected);
31
- if (injectedWallets.length !== 1) {
33
+ const embeddedWallets = walletsList.filter(item => isWalletInfoInjected(item) && item.embedded);
34
+ if (embeddedWallets.length !== 1) {
32
35
  return null;
33
36
  }
34
- return injectedWallets[0].embedded ? injectedWallets[0] : null;
37
+ return embeddedWallets[0];
35
38
  });
36
39
  }
37
40
  fetchWalletsList() {
@@ -12,4 +12,8 @@ export interface TonConnectOptions {
12
12
  * Storage to save protocol data. For browser default is `localStorage`. If you use SDK with nodeJS, you have to specify this field.
13
13
  */
14
14
  storage?: IStorage;
15
+ /**
16
+ * @deprecated Don't use it
17
+ */
18
+ walletsListSource?: string;
15
19
  }
@@ -1,4 +1,4 @@
1
1
  export type { Account } from './account';
2
2
  export type { Wallet } from './wallet';
3
3
  export type { WalletConnectionSource, WalletConnectionSourceHTTP, WalletConnectionSourceJS } from './wallet-connection-source';
4
- export { WalletInfo, WalletInfoInjected, WalletInfoRemote, isWalletInfoInjected } from './wallet-info';
4
+ export { WalletInfo, WalletInfoBase, WalletInfoInjected, WalletInfoRemote, isWalletInfoInjected } from './wallet-info';
@@ -3,6 +3,7 @@ import { InternalProvider } from "../provider";
3
3
  import { IStorage } from "../../storage/models/storage.interface";
4
4
  import { WithoutId } from "../../utils/types";
5
5
  export declare class InjectedProvider<T extends string = string> implements InternalProvider {
6
+ private readonly injectedWalletKey;
6
7
  private static window;
7
8
  static fromStorage(storage: IStorage): Promise<InjectedProvider>;
8
9
  static isWalletInjected(injectedWalletKey: string): boolean;
@@ -11,15 +12,18 @@ export declare class InjectedProvider<T extends string = string> implements Inte
11
12
  readonly type = "injected";
12
13
  private unsubscribeCallback;
13
14
  private injectedWallet;
15
+ private readonly connectionStorage;
14
16
  private listenSubscriptions;
15
17
  private listeners;
16
- constructor(injectedWalletKey: T);
17
- connect(message: ConnectRequest, auto?: boolean): void;
18
+ constructor(storage: IStorage, injectedWalletKey: T);
19
+ connect(message: ConnectRequest): void;
18
20
  restoreConnection(): Promise<void>;
19
21
  closeConnection(): void;
20
22
  disconnect(): Promise<void>;
21
23
  private closeAllListeners;
22
24
  listen(eventsCallback: (e: WalletEvent) => void): () => void;
23
25
  sendRequest<T extends RpcMethod>(request: WithoutId<AppRequest<T>>): Promise<WithoutId<WalletResponse<T>>>;
26
+ private _connect;
24
27
  private makeSubscriptions;
28
+ private updateSession;
25
29
  }
@@ -3,7 +3,7 @@ export interface InjectedWalletApi {
3
3
  deviceInfo: DeviceInfo;
4
4
  protocolVersion: number;
5
5
  isWalletBrowser: boolean;
6
- connect(protocolVersion: number, message: ConnectRequest, auto: boolean): Promise<ConnectEvent>;
6
+ connect(protocolVersion: number, message: ConnectRequest): Promise<ConnectEvent>;
7
7
  restoreConnection(): Promise<ConnectEvent>;
8
8
  send<T extends RpcMethod>(message: AppRequest<T>): Promise<WalletResponse<T>>;
9
9
  listen(callback: (event: WalletEvent) => void): () => void;
@@ -7,10 +7,20 @@ import { WalletConnectionSourceJS } from "./models/wallet/wallet-connection-sour
7
7
  import { ITonConnect } from "./ton-connect.interface";
8
8
  export declare class TonConnect implements ITonConnect {
9
9
  private static readonly walletsList;
10
+ /**
11
+ * Check if specified wallet is injected and available to use with the app.
12
+ * @param walletJSKey target wallet's js bridge key.
13
+ */
14
+ static isWalletInjected: (walletJSKey: string) => boolean;
15
+ /**
16
+ * Check if the app is opened inside specified wallet's browser.
17
+ * @param walletJSKey target wallet's js bridge key.
18
+ */
19
+ static isInsideWalletBrowser: (walletJSKey: string) => boolean;
10
20
  /**
11
21
  * Returns available wallets list.
12
22
  */
13
- static getWallets: Promise<WalletInfo[]>;
23
+ static getWallets(): Promise<WalletInfo[]>;
14
24
  private readonly walletsList;
15
25
  private readonly dappSettings;
16
26
  private readonly bridgeConnectionStorage;
@@ -2,6 +2,7 @@ import { WalletInfoInjected, WalletInfo } from "./models/wallet/wallet-info";
2
2
  export declare class WalletsListManager {
3
3
  private walletsListCache;
4
4
  private readonly walletsListSource;
5
+ constructor(walletsListSource?: string);
5
6
  getWallets(): Promise<WalletInfo[]>;
6
7
  getEmbeddedWallet(): Promise<WalletInfoInjected | null>;
7
8
  private fetchWalletsList;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonconnect/sdk",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "scripts": {
5
5
  "build": "npx rimraf lib && ttsc --outDir ./lib/cjs && ttsc --module esnext --outDir ./lib/esm && npx rimraf dist && webpack --mode development",
6
6
  "build:production": "npx rimraf lib && ttsc --project tsconfig.cjs.json --sourceMap false && ttsc --project tsconfig.esm.json --sourceMap false && npx rimraf dist && webpack --mode production"