@tonconnect/sdk 3.0.8-beta.0 → 3.1.1-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
@@ -807,9 +807,17 @@ function createEventSource(config) {
807
807
  });
808
808
  }
809
809
 
810
+ const CONNECTION_HTTP_EXPIRATION_TIME = 5 * 60 * 1000;
810
811
  function isPendingConnectionHttp(connection) {
811
812
  return !('connectEvent' in connection);
812
813
  }
814
+ function isPendingConnectionHttpRaw(connection) {
815
+ return !('connectEvent' in connection);
816
+ }
817
+ function isExpiredPendingConnectionHttpRaw(connection) {
818
+ var _a;
819
+ return Date.now() - ((_a = connection.createdAt) !== null && _a !== void 0 ? _a : 0) > CONNECTION_HTTP_EXPIRATION_TIME;
820
+ }
813
821
 
814
822
  class BridgeConnectionStorage {
815
823
  constructor(storage) {
@@ -839,7 +847,8 @@ class BridgeConnectionStorage {
839
847
  const rawConnection = {
840
848
  type: 'http',
841
849
  connectionSource: connection.connectionSource,
842
- sessionCrypto: connection.sessionCrypto.stringifyKeypair()
850
+ sessionCrypto: connection.sessionCrypto.stringifyKeypair(),
851
+ createdAt: Date.now()
843
852
  };
844
853
  return this.storage.setItem(this.storeKey, JSON.stringify(rawConnection));
845
854
  });
@@ -859,7 +868,7 @@ class BridgeConnectionStorage {
859
868
  if (connection.type === 'injected') {
860
869
  return connection;
861
870
  }
862
- if ('connectEvent' in connection) {
871
+ if (!isPendingConnectionHttpRaw(connection)) {
863
872
  const sessionCrypto = new SessionCrypto(connection.session.sessionKeyPair);
864
873
  return {
865
874
  type: 'http',
@@ -873,6 +882,10 @@ class BridgeConnectionStorage {
873
882
  }
874
883
  };
875
884
  }
885
+ if (isExpiredPendingConnectionHttpRaw(connection)) {
886
+ yield this.removeConnection();
887
+ return null;
888
+ }
876
889
  return {
877
890
  type: 'http',
878
891
  sessionCrypto: new SessionCrypto(connection.sessionCrypto),
@@ -2042,50 +2055,6 @@ const FALLBACK_WALLETS_LIST = [
2042
2055
  }
2043
2056
  ];
2044
2057
 
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
-
2089
2058
  class WalletsListManager {
2090
2059
  constructor(options) {
2091
2060
  var _a;
@@ -2094,9 +2063,6 @@ class WalletsListManager {
2094
2063
  this.walletsListSource =
2095
2064
  (_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
2065
  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;
2100
2066
  }
2101
2067
  getWallets() {
2102
2068
  return __awaiter(this, void 0, void 0, function* () {
@@ -2246,6 +2212,51 @@ class WalletsListManager {
2246
2212
  }
2247
2213
  }
2248
2214
 
2215
+ function checkSendTransactionSupport(features, options) {
2216
+ const supportsDeprecatedSendTransactionFeature = features.includes('SendTransaction');
2217
+ const sendTransactionFeature = findFeature(features, 'SendTransaction');
2218
+ if (!supportsDeprecatedSendTransactionFeature && !sendTransactionFeature) {
2219
+ throw new WalletNotSupportFeatureError("Wallet doesn't support SendTransaction feature.");
2220
+ }
2221
+ if (options.requireExtraCurrencies) {
2222
+ if (!sendTransactionFeature || !sendTransactionFeature.extraCurrencySupported) {
2223
+ throw new WalletNotSupportFeatureError(`Wallet is not able to handle such SendTransaction request. Extra currencies support is required.`);
2224
+ }
2225
+ }
2226
+ if (sendTransactionFeature && sendTransactionFeature.maxMessages !== undefined) {
2227
+ if (sendTransactionFeature.maxMessages < options.requiredMessagesNumber) {
2228
+ throw new WalletNotSupportFeatureError(`Wallet is not able to handle such SendTransaction request. Max support messages number is ${sendTransactionFeature.maxMessages}, but ${options.requiredMessagesNumber} is required.`);
2229
+ }
2230
+ return;
2231
+ }
2232
+ logWarning("Connected wallet didn't provide information about max allowed messages in the SendTransaction request. Request may be rejected by the wallet.");
2233
+ }
2234
+ function checkRequiredWalletFeatures(features, walletsRequiredFeatures) {
2235
+ if (typeof walletsRequiredFeatures !== 'object') {
2236
+ return true;
2237
+ }
2238
+ const { sendTransaction } = walletsRequiredFeatures;
2239
+ if (sendTransaction) {
2240
+ const feature = findFeature(features, 'SendTransaction');
2241
+ if (!feature) {
2242
+ return false;
2243
+ }
2244
+ if (!checkSendTransaction(feature, sendTransaction)) {
2245
+ return false;
2246
+ }
2247
+ }
2248
+ return true;
2249
+ }
2250
+ function findFeature(features, requiredFeatureName) {
2251
+ return features.find(f => f && typeof f === 'object' && f.name === requiredFeatureName);
2252
+ }
2253
+ function checkSendTransaction(feature, requiredFeature) {
2254
+ const correctMessagesNumber = requiredFeature.minMessages === undefined ||
2255
+ requiredFeature.minMessages <= feature.maxMessages;
2256
+ const correctExtraCurrency = !requiredFeature.extraCurrencyRequired || feature.extraCurrencySupported;
2257
+ return !!(correctMessagesNumber && correctExtraCurrency);
2258
+ }
2259
+
2249
2260
  /**
2250
2261
  * Create a request version event.
2251
2262
  */
@@ -2662,7 +2673,7 @@ class TonConnectTracker {
2662
2673
  }
2663
2674
  }
2664
2675
 
2665
- const tonConnectSdkVersion = "3.0.8-beta.0";
2676
+ const tonConnectSdkVersion = "3.1.1-beta.0";
2666
2677
 
2667
2678
  class TonConnect {
2668
2679
  constructor(options) {
@@ -2678,8 +2689,7 @@ class TonConnect {
2678
2689
  this.walletsRequiredFeatures = options === null || options === void 0 ? void 0 : options.walletsRequiredFeatures;
2679
2690
  this.walletsList = new WalletsListManager({
2680
2691
  walletsListSource: options === null || options === void 0 ? void 0 : options.walletsListSource,
2681
- cacheTTLMs: options === null || options === void 0 ? void 0 : options.walletsListCacheTTLMs,
2682
- walletsRequiredFeatures: options === null || options === void 0 ? void 0 : options.walletsRequiredFeatures
2692
+ cacheTTLMs: options === null || options === void 0 ? void 0 : options.walletsListCacheTTLMs
2683
2693
  });
2684
2694
  this.tracker = new TonConnectTracker({
2685
2695
  eventDispatcher: options === null || options === void 0 ? void 0 : options.eventDispatcher,
@@ -3000,15 +3010,15 @@ class TonConnect {
3000
3010
  }
3001
3011
  }
3002
3012
  onWalletConnected(connectEvent) {
3003
- var _a, _b;
3013
+ var _a;
3004
3014
  const tonAccountItem = connectEvent.items.find(item => item.name === 'ton_addr');
3005
3015
  const tonProofItem = connectEvent.items.find(item => item.name === 'ton_proof');
3006
3016
  if (!tonAccountItem) {
3007
3017
  throw new TonConnectError('ton_addr connection item was not found');
3008
3018
  }
3009
- const hasRequiredFeatures = checkRequiredWalletFeatures(connectEvent.device.features, (_a = this.walletsRequiredFeatures) !== null && _a !== void 0 ? _a : []);
3019
+ const hasRequiredFeatures = checkRequiredWalletFeatures(connectEvent.device.features, this.walletsRequiredFeatures);
3010
3020
  if (!hasRequiredFeatures) {
3011
- (_b = this.provider) === null || _b === void 0 ? void 0 : _b.disconnect();
3021
+ (_a = this.provider) === null || _a === void 0 ? void 0 : _a.disconnect();
3012
3022
  this.onWalletConnectError(new WalletMissingRequiredFeaturesError('Wallet does not support required features', { cause: { connectEvent } }));
3013
3023
  return;
3014
3024
  }