@tonconnect/sdk 3.0.7-alpha.1 → 3.0.8-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.
package/lib/esm/index.mjs CHANGED
@@ -120,6 +120,45 @@ class WalletNotConnectedError extends TonConnectError {
120
120
  }
121
121
  }
122
122
 
123
+ /**
124
+ * Thrown when there is an attempt to connect to the injected wallet while it is not exists in the webpage.
125
+ */
126
+ class WalletNotInjectedError extends TonConnectError {
127
+ get info() {
128
+ return 'There is an attempt to connect to the injected wallet while it is not exists in the webpage.';
129
+ }
130
+ constructor(...args) {
131
+ super(...args);
132
+ Object.setPrototypeOf(this, WalletNotInjectedError.prototype);
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Thrown when wallet doesn't support requested feature method.
138
+ */
139
+ class WalletNotSupportFeatureError extends TonConnectError {
140
+ get info() {
141
+ return "Wallet doesn't support requested feature method.";
142
+ }
143
+ constructor(...args) {
144
+ super(...args);
145
+ Object.setPrototypeOf(this, WalletNotSupportFeatureError.prototype);
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Thrown when wallet can't get manifest by passed manifestUrl.
151
+ */
152
+ class WalletMissingRequiredFeaturesError extends TonConnectError {
153
+ get info() {
154
+ return 'Missing required features. You need to update your wallet.';
155
+ }
156
+ constructor(message, options) {
157
+ super(message, options);
158
+ Object.setPrototypeOf(this, WalletMissingRequiredFeaturesError.prototype);
159
+ }
160
+ }
161
+
123
162
  function isWalletConnectionSourceJS(value) {
124
163
  return 'jsBridgeKey' in value;
125
164
  }
@@ -163,19 +202,6 @@ class UnknownAppError extends TonConnectError {
163
202
  }
164
203
  }
165
204
 
166
- /**
167
- * Thrown when there is an attempt to connect to the injected wallet while it is not exists in the webpage.
168
- */
169
- class WalletNotInjectedError extends TonConnectError {
170
- get info() {
171
- return 'There is an attempt to connect to the injected wallet while it is not exists in the webpage.';
172
- }
173
- constructor(...args) {
174
- super(...args);
175
- Object.setPrototypeOf(this, WalletNotInjectedError.prototype);
176
- }
177
- }
178
-
179
205
  /**
180
206
  * Thrown when `Storage` was not specified in the `DappMetadata` and default `localStorage` was not detected in the Node.js environment.
181
207
  */
@@ -1505,7 +1531,8 @@ class InjectedProvider {
1505
1531
  jsBridgeKey,
1506
1532
  injected: true,
1507
1533
  embedded: wallet.tonconnect.isWalletBrowser,
1508
- platforms: wallet.tonconnect.walletInfo.platforms
1534
+ platforms: wallet.tonconnect.walletInfo.platforms,
1535
+ features: wallet.tonconnect.walletInfo.features
1509
1536
  }));
1510
1537
  }
1511
1538
  static isWindowContainsWallet(window, injectedWalletKey) {
@@ -2015,17 +2042,61 @@ const FALLBACK_WALLETS_LIST = [
2015
2042
  }
2016
2043
  ];
2017
2044
 
2045
+ function checkSendTransactionSupport(features, options) {
2046
+ const supportsDeprecatedSendTransactionFeature = features.includes('SendTransaction');
2047
+ const sendTransactionFeature = features.find(feature => feature && typeof feature === 'object' && feature.name === 'SendTransaction');
2048
+ if (!supportsDeprecatedSendTransactionFeature && !sendTransactionFeature) {
2049
+ throw new WalletNotSupportFeatureError("Wallet doesn't support SendTransaction feature.");
2050
+ }
2051
+ if (options.requireExtraCurrencies) {
2052
+ if (!sendTransactionFeature || !sendTransactionFeature.extraCurrencySupported) {
2053
+ throw new WalletNotSupportFeatureError(`Wallet is not able to handle such SendTransaction request. Extra currencies support is required.`);
2054
+ }
2055
+ }
2056
+ if (sendTransactionFeature && sendTransactionFeature.maxMessages !== undefined) {
2057
+ if (sendTransactionFeature.maxMessages < options.requiredMessagesNumber) {
2058
+ throw new WalletNotSupportFeatureError(`Wallet is not able to handle such SendTransaction request. Max support messages number is ${sendTransactionFeature.maxMessages}, but ${options.requiredMessagesNumber} is required.`);
2059
+ }
2060
+ return;
2061
+ }
2062
+ logWarning("Connected wallet didn't provide information about max allowed messages in the SendTransaction request. Request may be rejected by the wallet.");
2063
+ }
2064
+ function checkRequiredWalletFeatures(features, walletsRequiredFeatures) {
2065
+ if (typeof walletsRequiredFeatures === 'function') {
2066
+ return walletsRequiredFeatures(features);
2067
+ }
2068
+ const res = walletsRequiredFeatures.every(requiredFeature => {
2069
+ const feature = features.find(f => typeof f === 'object' && f.name === requiredFeature.name);
2070
+ if (!feature) {
2071
+ return false;
2072
+ }
2073
+ switch (requiredFeature.name) {
2074
+ case 'SendTransaction': {
2075
+ const sendTransactionFeature = feature;
2076
+ const correctMessagesNumber = requiredFeature.minMessages === undefined ||
2077
+ requiredFeature.minMessages <= sendTransactionFeature.maxMessages;
2078
+ const correctExtraCurrency = !requiredFeature.extraCurrencyRequired ||
2079
+ sendTransactionFeature.extraCurrencySupported;
2080
+ return correctMessagesNumber && correctExtraCurrency;
2081
+ }
2082
+ default:
2083
+ return false;
2084
+ }
2085
+ });
2086
+ return res;
2087
+ }
2088
+
2018
2089
  class WalletsListManager {
2019
2090
  constructor(options) {
2091
+ var _a;
2020
2092
  this.walletsListCache = null;
2021
2093
  this.walletsListCacheCreationTimestamp = null;
2022
- this.walletsListSource = 'https://raw.githubusercontent.com/ton-blockchain/wallets-list/main/wallets-v2.json';
2023
- if (options === null || options === void 0 ? void 0 : options.walletsListSource) {
2024
- this.walletsListSource = options.walletsListSource;
2025
- }
2026
- if (options === null || options === void 0 ? void 0 : options.cacheTTLMs) {
2027
- this.cacheTTLMs = options.cacheTTLMs;
2028
- }
2094
+ this.walletsListSource =
2095
+ (_a = options === null || options === void 0 ? void 0 : options.walletsListSource) !== null && _a !== void 0 ? _a : 'https://raw.githubusercontent.com/ton-blockchain/wallets-list/main/wallets-v2.json';
2096
+ this.cacheTTLMs = options === null || options === void 0 ? void 0 : options.cacheTTLMs;
2097
+ this.checkRequiredFeatures = (options === null || options === void 0 ? void 0 : options.walletsRequiredFeatures)
2098
+ ? features => checkRequiredWalletFeatures(features !== null && features !== void 0 ? features : [], options.walletsRequiredFeatures)
2099
+ : () => true;
2029
2100
  }
2030
2101
  getWallets() {
2031
2102
  return __awaiter(this, void 0, void 0, function* () {
@@ -2052,10 +2123,7 @@ class WalletsListManager {
2052
2123
  return __awaiter(this, void 0, void 0, function* () {
2053
2124
  const walletsList = yield this.getWallets();
2054
2125
  const embeddedWallets = walletsList.filter(isWalletInfoCurrentlyEmbedded);
2055
- if (embeddedWallets.length !== 1) {
2056
- return null;
2057
- }
2058
- return embeddedWallets[0];
2126
+ return embeddedWallets.length === 1 ? embeddedWallets[0] : null;
2059
2127
  });
2060
2128
  }
2061
2129
  fetchWalletsList() {
@@ -2070,7 +2138,7 @@ class WalletsListManager {
2070
2138
  const wrongFormatWallets = walletsList.filter(wallet => !this.isCorrectWalletConfigDTO(wallet));
2071
2139
  if (wrongFormatWallets.length) {
2072
2140
  logError(`Wallet(s) ${wrongFormatWallets
2073
- .map(wallet => wallet.name)
2141
+ .map(wallet => (wallet === null || wallet === void 0 ? void 0 : wallet.name) || 'unknown')
2074
2142
  .join(', ')} config format is wrong. They were removed from the wallets list.`);
2075
2143
  walletsList = walletsList.filter(wallet => this.isCorrectWalletConfigDTO(wallet));
2076
2144
  }
@@ -2091,15 +2159,15 @@ class WalletsListManager {
2091
2159
  }
2092
2160
  walletConfigDTOListToWalletConfigList(walletConfigDTO) {
2093
2161
  return walletConfigDTO.map(walletConfigDTO => {
2094
- const walletConfigBase = {
2162
+ const walletConfig = {
2095
2163
  name: walletConfigDTO.name,
2096
2164
  appName: walletConfigDTO.app_name,
2097
2165
  imageUrl: walletConfigDTO.image,
2098
2166
  aboutUrl: walletConfigDTO.about_url,
2099
2167
  tondns: walletConfigDTO.tondns,
2100
- platforms: walletConfigDTO.platforms
2168
+ platforms: walletConfigDTO.platforms,
2169
+ features: walletConfigDTO.features
2101
2170
  };
2102
- const walletConfig = walletConfigBase;
2103
2171
  walletConfigDTO.bridge.forEach(bridge => {
2104
2172
  if (bridge.type === 'sse') {
2105
2173
  walletConfig.bridgeUrl = bridge.url;
@@ -2160,7 +2228,7 @@ class WalletsListManager {
2160
2228
  }
2161
2229
  const sseBridge = bridge.find(item => item.type === 'sse');
2162
2230
  if (sseBridge) {
2163
- if (!('url' in sseBridge) ||
2231
+ if (!(typeof sseBridge === 'object' && 'url' in sseBridge) ||
2164
2232
  !sseBridge.url ||
2165
2233
  !value.universal_url) {
2166
2234
  return false;
@@ -2168,7 +2236,9 @@ class WalletsListManager {
2168
2236
  }
2169
2237
  const jsBridge = bridge.find(item => item.type === 'js');
2170
2238
  if (jsBridge) {
2171
- if (!('key' in jsBridge) || !jsBridge.key) {
2239
+ if (typeof jsBridge !== 'object' ||
2240
+ !('key' in jsBridge) ||
2241
+ !jsBridge.key) {
2172
2242
  return false;
2173
2243
  }
2174
2244
  }
@@ -2176,39 +2246,6 @@ class WalletsListManager {
2176
2246
  }
2177
2247
  }
2178
2248
 
2179
- /**
2180
- * Thrown when wallet doesn't support requested feature method.
2181
- */
2182
- class WalletNotSupportFeatureError extends TonConnectError {
2183
- get info() {
2184
- return "Wallet doesn't support requested feature method.";
2185
- }
2186
- constructor(...args) {
2187
- super(...args);
2188
- Object.setPrototypeOf(this, WalletNotSupportFeatureError.prototype);
2189
- }
2190
- }
2191
-
2192
- function checkSendTransactionSupport(features, options) {
2193
- const supportsDeprecatedSendTransactionFeature = features.includes('SendTransaction');
2194
- const sendTransactionFeature = features.find(feature => feature && typeof feature === 'object' && feature.name === 'SendTransaction');
2195
- if (!supportsDeprecatedSendTransactionFeature && !sendTransactionFeature) {
2196
- throw new WalletNotSupportFeatureError("Wallet doesn't support SendTransaction feature.");
2197
- }
2198
- if (options.requireExtraCurrencies) {
2199
- if (!sendTransactionFeature || !sendTransactionFeature.extraCurrencySupported) {
2200
- throw new WalletNotSupportFeatureError(`Wallet is not able to handle such SendTransaction request. Extra currencies support is required.`);
2201
- }
2202
- }
2203
- if (sendTransactionFeature && sendTransactionFeature.maxMessages !== undefined) {
2204
- if (sendTransactionFeature.maxMessages < options.requiredMessagesNumber) {
2205
- throw new WalletNotSupportFeatureError(`Wallet is not able to handle such SendTransaction request. Max support messages number is ${sendTransactionFeature.maxMessages}, but ${options.requiredMessagesNumber} is required.`);
2206
- }
2207
- return;
2208
- }
2209
- logWarning("Connected wallet didn't provide information about max allowed messages in the SendTransaction request. Request may be rejected by the wallet.");
2210
- }
2211
-
2212
2249
  /**
2213
2250
  * Create a request version event.
2214
2251
  */
@@ -2625,7 +2662,7 @@ class TonConnectTracker {
2625
2662
  }
2626
2663
  }
2627
2664
 
2628
- const tonConnectSdkVersion = "3.0.7-alpha.1";
2665
+ const tonConnectSdkVersion = "3.0.8-beta.0";
2629
2666
 
2630
2667
  class TonConnect {
2631
2668
  constructor(options) {
@@ -2638,9 +2675,11 @@ class TonConnect {
2638
2675
  manifestUrl: (options === null || options === void 0 ? void 0 : options.manifestUrl) || getWebPageManifest(),
2639
2676
  storage: (options === null || options === void 0 ? void 0 : options.storage) || new DefaultStorage()
2640
2677
  };
2678
+ this.walletsRequiredFeatures = options === null || options === void 0 ? void 0 : options.walletsRequiredFeatures;
2641
2679
  this.walletsList = new WalletsListManager({
2642
2680
  walletsListSource: options === null || options === void 0 ? void 0 : options.walletsListSource,
2643
- cacheTTLMs: options === null || options === void 0 ? void 0 : options.walletsListCacheTTLMs
2681
+ cacheTTLMs: options === null || options === void 0 ? void 0 : options.walletsListCacheTTLMs,
2682
+ walletsRequiredFeatures: options === null || options === void 0 ? void 0 : options.walletsRequiredFeatures
2644
2683
  });
2645
2684
  this.tracker = new TonConnectTracker({
2646
2685
  eventDispatcher: options === null || options === void 0 ? void 0 : options.eventDispatcher,
@@ -2952,18 +2991,27 @@ class TonConnect {
2952
2991
  this.onWalletConnected(e.payload);
2953
2992
  break;
2954
2993
  case 'connect_error':
2955
- this.onWalletConnectError(e.payload);
2994
+ this.tracker.trackConnectionError(e.payload.message, e.payload.code);
2995
+ const walletError = connectErrorsParser.parseError(e.payload);
2996
+ this.onWalletConnectError(walletError);
2956
2997
  break;
2957
2998
  case 'disconnect':
2958
2999
  this.onWalletDisconnected('wallet');
2959
3000
  }
2960
3001
  }
2961
3002
  onWalletConnected(connectEvent) {
3003
+ var _a, _b;
2962
3004
  const tonAccountItem = connectEvent.items.find(item => item.name === 'ton_addr');
2963
3005
  const tonProofItem = connectEvent.items.find(item => item.name === 'ton_proof');
2964
3006
  if (!tonAccountItem) {
2965
3007
  throw new TonConnectError('ton_addr connection item was not found');
2966
3008
  }
3009
+ const hasRequiredFeatures = checkRequiredWalletFeatures(connectEvent.device.features, (_a = this.walletsRequiredFeatures) !== null && _a !== void 0 ? _a : []);
3010
+ if (!hasRequiredFeatures) {
3011
+ (_b = this.provider) === null || _b === void 0 ? void 0 : _b.disconnect();
3012
+ this.onWalletConnectError(new WalletMissingRequiredFeaturesError('Wallet does not support required features', { cause: { connectEvent } }));
3013
+ return;
3014
+ }
2967
3015
  const wallet = {
2968
3016
  device: connectEvent.device,
2969
3017
  provider: this.provider.type,
@@ -2982,11 +3030,9 @@ class TonConnect {
2982
3030
  this.wallet = wallet;
2983
3031
  this.tracker.trackConnectionCompleted(wallet);
2984
3032
  }
2985
- onWalletConnectError(connectEventError) {
2986
- const error = connectErrorsParser.parseError(connectEventError);
3033
+ onWalletConnectError(error) {
2987
3034
  this.statusChangeErrorSubscriptions.forEach(errorsHandler => errorsHandler(error));
2988
3035
  logDebug(error);
2989
- this.tracker.trackConnectionError(connectEventError.message, connectEventError.code);
2990
3036
  if (error instanceof ManifestNotFoundError || error instanceof ManifestContentErrorError) {
2991
3037
  logError(error);
2992
3038
  throw error;
@@ -3123,5 +3169,5 @@ function hexToBytes(hex) {
3123
3169
  return result;
3124
3170
  }
3125
3171
 
3126
- export { BadRequestError, BrowserEventDispatcher, FetchWalletsError, LocalstorageNotFoundError, ParseHexError, TonConnect, TonConnectError, UnknownAppError, UnknownError, UserRejectsError, WalletAlreadyConnectedError, WalletNotConnectedError, WalletNotInjectedError, WalletsListManager, WrongAddressError, createConnectionCompletedEvent, createConnectionErrorEvent, createConnectionRestoringCompletedEvent, createConnectionRestoringErrorEvent, createConnectionRestoringStartedEvent, createConnectionStartedEvent, createDisconnectionEvent, createRequestVersionEvent, createResponseVersionEvent, createTransactionSentForSignatureEvent, createTransactionSignedEvent, createTransactionSigningFailedEvent, createVersionInfo, TonConnect as default, encodeTelegramUrlParameters, isTelegramUrl, isWalletInfoCurrentlyEmbedded, isWalletInfoCurrentlyInjected, isWalletInfoInjectable, isWalletInfoInjected, isWalletInfoRemote, toUserFriendlyAddress };
3172
+ export { BadRequestError, BrowserEventDispatcher, FetchWalletsError, LocalstorageNotFoundError, ParseHexError, TonConnect, TonConnectError, UnknownAppError, UnknownError, UserRejectsError, WalletAlreadyConnectedError, WalletMissingRequiredFeaturesError, WalletNotConnectedError, WalletNotInjectedError, WalletNotSupportFeatureError, WalletsListManager, WrongAddressError, checkRequiredWalletFeatures, createConnectionCompletedEvent, createConnectionErrorEvent, createConnectionRestoringCompletedEvent, createConnectionRestoringErrorEvent, createConnectionRestoringStartedEvent, createConnectionStartedEvent, createDisconnectionEvent, createRequestVersionEvent, createResponseVersionEvent, createTransactionSentForSignatureEvent, createTransactionSignedEvent, createTransactionSigningFailedEvent, createVersionInfo, TonConnect as default, encodeTelegramUrlParameters, isTelegramUrl, isWalletInfoCurrentlyEmbedded, isWalletInfoCurrentlyInjected, isWalletInfoInjectable, isWalletInfoInjected, isWalletInfoRemote, toUserFriendlyAddress };
3127
3173
  //# sourceMappingURL=index.mjs.map