@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/dist/tonconnect-sdk.min.js +1 -1
- package/dist/tonconnect-sdk.min.js.map +1 -1
- package/lib/cjs/index.cjs +65 -55
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/index.mjs +65 -55
- package/lib/esm/index.mjs.map +1 -1
- package/lib/types/index.d.ts +21 -7
- package/package.json +1 -1
package/lib/cjs/index.cjs
CHANGED
|
@@ -810,9 +810,17 @@ function createEventSource(config) {
|
|
|
810
810
|
});
|
|
811
811
|
}
|
|
812
812
|
|
|
813
|
+
const CONNECTION_HTTP_EXPIRATION_TIME = 5 * 60 * 1000;
|
|
813
814
|
function isPendingConnectionHttp(connection) {
|
|
814
815
|
return !('connectEvent' in connection);
|
|
815
816
|
}
|
|
817
|
+
function isPendingConnectionHttpRaw(connection) {
|
|
818
|
+
return !('connectEvent' in connection);
|
|
819
|
+
}
|
|
820
|
+
function isExpiredPendingConnectionHttpRaw(connection) {
|
|
821
|
+
var _a;
|
|
822
|
+
return Date.now() - ((_a = connection.createdAt) !== null && _a !== void 0 ? _a : 0) > CONNECTION_HTTP_EXPIRATION_TIME;
|
|
823
|
+
}
|
|
816
824
|
|
|
817
825
|
class BridgeConnectionStorage {
|
|
818
826
|
constructor(storage) {
|
|
@@ -842,7 +850,8 @@ class BridgeConnectionStorage {
|
|
|
842
850
|
const rawConnection = {
|
|
843
851
|
type: 'http',
|
|
844
852
|
connectionSource: connection.connectionSource,
|
|
845
|
-
sessionCrypto: connection.sessionCrypto.stringifyKeypair()
|
|
853
|
+
sessionCrypto: connection.sessionCrypto.stringifyKeypair(),
|
|
854
|
+
createdAt: Date.now()
|
|
846
855
|
};
|
|
847
856
|
return this.storage.setItem(this.storeKey, JSON.stringify(rawConnection));
|
|
848
857
|
});
|
|
@@ -862,7 +871,7 @@ class BridgeConnectionStorage {
|
|
|
862
871
|
if (connection.type === 'injected') {
|
|
863
872
|
return connection;
|
|
864
873
|
}
|
|
865
|
-
if (
|
|
874
|
+
if (!isPendingConnectionHttpRaw(connection)) {
|
|
866
875
|
const sessionCrypto = new protocol.SessionCrypto(connection.session.sessionKeyPair);
|
|
867
876
|
return {
|
|
868
877
|
type: 'http',
|
|
@@ -876,6 +885,10 @@ class BridgeConnectionStorage {
|
|
|
876
885
|
}
|
|
877
886
|
};
|
|
878
887
|
}
|
|
888
|
+
if (isExpiredPendingConnectionHttpRaw(connection)) {
|
|
889
|
+
yield this.removeConnection();
|
|
890
|
+
return null;
|
|
891
|
+
}
|
|
879
892
|
return {
|
|
880
893
|
type: 'http',
|
|
881
894
|
sessionCrypto: new protocol.SessionCrypto(connection.sessionCrypto),
|
|
@@ -2045,50 +2058,6 @@ const FALLBACK_WALLETS_LIST = [
|
|
|
2045
2058
|
}
|
|
2046
2059
|
];
|
|
2047
2060
|
|
|
2048
|
-
function checkSendTransactionSupport(features, options) {
|
|
2049
|
-
const supportsDeprecatedSendTransactionFeature = features.includes('SendTransaction');
|
|
2050
|
-
const sendTransactionFeature = features.find(feature => feature && typeof feature === 'object' && feature.name === 'SendTransaction');
|
|
2051
|
-
if (!supportsDeprecatedSendTransactionFeature && !sendTransactionFeature) {
|
|
2052
|
-
throw new WalletNotSupportFeatureError("Wallet doesn't support SendTransaction feature.");
|
|
2053
|
-
}
|
|
2054
|
-
if (options.requireExtraCurrencies) {
|
|
2055
|
-
if (!sendTransactionFeature || !sendTransactionFeature.extraCurrencySupported) {
|
|
2056
|
-
throw new WalletNotSupportFeatureError(`Wallet is not able to handle such SendTransaction request. Extra currencies support is required.`);
|
|
2057
|
-
}
|
|
2058
|
-
}
|
|
2059
|
-
if (sendTransactionFeature && sendTransactionFeature.maxMessages !== undefined) {
|
|
2060
|
-
if (sendTransactionFeature.maxMessages < options.requiredMessagesNumber) {
|
|
2061
|
-
throw new WalletNotSupportFeatureError(`Wallet is not able to handle such SendTransaction request. Max support messages number is ${sendTransactionFeature.maxMessages}, but ${options.requiredMessagesNumber} is required.`);
|
|
2062
|
-
}
|
|
2063
|
-
return;
|
|
2064
|
-
}
|
|
2065
|
-
logWarning("Connected wallet didn't provide information about max allowed messages in the SendTransaction request. Request may be rejected by the wallet.");
|
|
2066
|
-
}
|
|
2067
|
-
function checkRequiredWalletFeatures(features, walletsRequiredFeatures) {
|
|
2068
|
-
if (typeof walletsRequiredFeatures === 'function') {
|
|
2069
|
-
return walletsRequiredFeatures(features);
|
|
2070
|
-
}
|
|
2071
|
-
const res = walletsRequiredFeatures.every(requiredFeature => {
|
|
2072
|
-
const feature = features.find(f => typeof f === 'object' && f.name === requiredFeature.name);
|
|
2073
|
-
if (!feature) {
|
|
2074
|
-
return false;
|
|
2075
|
-
}
|
|
2076
|
-
switch (requiredFeature.name) {
|
|
2077
|
-
case 'SendTransaction': {
|
|
2078
|
-
const sendTransactionFeature = feature;
|
|
2079
|
-
const correctMessagesNumber = requiredFeature.minMessages === undefined ||
|
|
2080
|
-
requiredFeature.minMessages <= sendTransactionFeature.maxMessages;
|
|
2081
|
-
const correctExtraCurrency = !requiredFeature.extraCurrencyRequired ||
|
|
2082
|
-
sendTransactionFeature.extraCurrencySupported;
|
|
2083
|
-
return correctMessagesNumber && correctExtraCurrency;
|
|
2084
|
-
}
|
|
2085
|
-
default:
|
|
2086
|
-
return false;
|
|
2087
|
-
}
|
|
2088
|
-
});
|
|
2089
|
-
return res;
|
|
2090
|
-
}
|
|
2091
|
-
|
|
2092
2061
|
class WalletsListManager {
|
|
2093
2062
|
constructor(options) {
|
|
2094
2063
|
var _a;
|
|
@@ -2097,9 +2066,6 @@ class WalletsListManager {
|
|
|
2097
2066
|
this.walletsListSource =
|
|
2098
2067
|
(_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';
|
|
2099
2068
|
this.cacheTTLMs = options === null || options === void 0 ? void 0 : options.cacheTTLMs;
|
|
2100
|
-
this.checkRequiredFeatures = (options === null || options === void 0 ? void 0 : options.walletsRequiredFeatures)
|
|
2101
|
-
? features => checkRequiredWalletFeatures(features !== null && features !== void 0 ? features : [], options.walletsRequiredFeatures)
|
|
2102
|
-
: () => true;
|
|
2103
2069
|
}
|
|
2104
2070
|
getWallets() {
|
|
2105
2071
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2249,6 +2215,51 @@ class WalletsListManager {
|
|
|
2249
2215
|
}
|
|
2250
2216
|
}
|
|
2251
2217
|
|
|
2218
|
+
function checkSendTransactionSupport(features, options) {
|
|
2219
|
+
const supportsDeprecatedSendTransactionFeature = features.includes('SendTransaction');
|
|
2220
|
+
const sendTransactionFeature = findFeature(features, 'SendTransaction');
|
|
2221
|
+
if (!supportsDeprecatedSendTransactionFeature && !sendTransactionFeature) {
|
|
2222
|
+
throw new WalletNotSupportFeatureError("Wallet doesn't support SendTransaction feature.");
|
|
2223
|
+
}
|
|
2224
|
+
if (options.requireExtraCurrencies) {
|
|
2225
|
+
if (!sendTransactionFeature || !sendTransactionFeature.extraCurrencySupported) {
|
|
2226
|
+
throw new WalletNotSupportFeatureError(`Wallet is not able to handle such SendTransaction request. Extra currencies support is required.`);
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
if (sendTransactionFeature && sendTransactionFeature.maxMessages !== undefined) {
|
|
2230
|
+
if (sendTransactionFeature.maxMessages < options.requiredMessagesNumber) {
|
|
2231
|
+
throw new WalletNotSupportFeatureError(`Wallet is not able to handle such SendTransaction request. Max support messages number is ${sendTransactionFeature.maxMessages}, but ${options.requiredMessagesNumber} is required.`);
|
|
2232
|
+
}
|
|
2233
|
+
return;
|
|
2234
|
+
}
|
|
2235
|
+
logWarning("Connected wallet didn't provide information about max allowed messages in the SendTransaction request. Request may be rejected by the wallet.");
|
|
2236
|
+
}
|
|
2237
|
+
function checkRequiredWalletFeatures(features, walletsRequiredFeatures) {
|
|
2238
|
+
if (typeof walletsRequiredFeatures !== 'object') {
|
|
2239
|
+
return true;
|
|
2240
|
+
}
|
|
2241
|
+
const { sendTransaction } = walletsRequiredFeatures;
|
|
2242
|
+
if (sendTransaction) {
|
|
2243
|
+
const feature = findFeature(features, 'SendTransaction');
|
|
2244
|
+
if (!feature) {
|
|
2245
|
+
return false;
|
|
2246
|
+
}
|
|
2247
|
+
if (!checkSendTransaction(feature, sendTransaction)) {
|
|
2248
|
+
return false;
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
return true;
|
|
2252
|
+
}
|
|
2253
|
+
function findFeature(features, requiredFeatureName) {
|
|
2254
|
+
return features.find(f => f && typeof f === 'object' && f.name === requiredFeatureName);
|
|
2255
|
+
}
|
|
2256
|
+
function checkSendTransaction(feature, requiredFeature) {
|
|
2257
|
+
const correctMessagesNumber = requiredFeature.minMessages === undefined ||
|
|
2258
|
+
requiredFeature.minMessages <= feature.maxMessages;
|
|
2259
|
+
const correctExtraCurrency = !requiredFeature.extraCurrencyRequired || feature.extraCurrencySupported;
|
|
2260
|
+
return !!(correctMessagesNumber && correctExtraCurrency);
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2252
2263
|
/**
|
|
2253
2264
|
* Create a request version event.
|
|
2254
2265
|
*/
|
|
@@ -2665,7 +2676,7 @@ class TonConnectTracker {
|
|
|
2665
2676
|
}
|
|
2666
2677
|
}
|
|
2667
2678
|
|
|
2668
|
-
const tonConnectSdkVersion = "3.
|
|
2679
|
+
const tonConnectSdkVersion = "3.1.1-beta.0";
|
|
2669
2680
|
|
|
2670
2681
|
class TonConnect {
|
|
2671
2682
|
constructor(options) {
|
|
@@ -2681,8 +2692,7 @@ class TonConnect {
|
|
|
2681
2692
|
this.walletsRequiredFeatures = options === null || options === void 0 ? void 0 : options.walletsRequiredFeatures;
|
|
2682
2693
|
this.walletsList = new WalletsListManager({
|
|
2683
2694
|
walletsListSource: options === null || options === void 0 ? void 0 : options.walletsListSource,
|
|
2684
|
-
cacheTTLMs: options === null || options === void 0 ? void 0 : options.walletsListCacheTTLMs
|
|
2685
|
-
walletsRequiredFeatures: options === null || options === void 0 ? void 0 : options.walletsRequiredFeatures
|
|
2695
|
+
cacheTTLMs: options === null || options === void 0 ? void 0 : options.walletsListCacheTTLMs
|
|
2686
2696
|
});
|
|
2687
2697
|
this.tracker = new TonConnectTracker({
|
|
2688
2698
|
eventDispatcher: options === null || options === void 0 ? void 0 : options.eventDispatcher,
|
|
@@ -3003,15 +3013,15 @@ class TonConnect {
|
|
|
3003
3013
|
}
|
|
3004
3014
|
}
|
|
3005
3015
|
onWalletConnected(connectEvent) {
|
|
3006
|
-
var _a
|
|
3016
|
+
var _a;
|
|
3007
3017
|
const tonAccountItem = connectEvent.items.find(item => item.name === 'ton_addr');
|
|
3008
3018
|
const tonProofItem = connectEvent.items.find(item => item.name === 'ton_proof');
|
|
3009
3019
|
if (!tonAccountItem) {
|
|
3010
3020
|
throw new TonConnectError('ton_addr connection item was not found');
|
|
3011
3021
|
}
|
|
3012
|
-
const hasRequiredFeatures = checkRequiredWalletFeatures(connectEvent.device.features,
|
|
3022
|
+
const hasRequiredFeatures = checkRequiredWalletFeatures(connectEvent.device.features, this.walletsRequiredFeatures);
|
|
3013
3023
|
if (!hasRequiredFeatures) {
|
|
3014
|
-
(
|
|
3024
|
+
(_a = this.provider) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
3015
3025
|
this.onWalletConnectError(new WalletMissingRequiredFeaturesError('Wallet does not support required features', { cause: { connectEvent } }));
|
|
3016
3026
|
return;
|
|
3017
3027
|
}
|