@tonconnect/ui-react 0.0.2 → 0.0.3
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/README.md +1 -1
- package/lib/components/TonConnectUIProvider.d.ts +2 -2
- package/lib/hooks/useTonConnectUI.d.ts +2 -2
- package/lib/index.js +358 -1240
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +358 -1240
- package/lib/index.umd.js.map +1 -1
- package/lib/utils/errors.d.ts +2 -2
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
+
var __defProp2 = Object.defineProperty;
|
|
1
2
|
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
2
3
|
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
3
4
|
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues2 = (a2, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp2.call(b, prop))
|
|
9
|
+
__defNormalProp2(a2, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols2)
|
|
11
|
+
for (var prop of __getOwnPropSymbols2(b)) {
|
|
12
|
+
if (__propIsEnum2.call(b, prop))
|
|
13
|
+
__defNormalProp2(a2, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a2;
|
|
16
|
+
};
|
|
4
17
|
var __objRest = (source, exclude) => {
|
|
5
18
|
var target = {};
|
|
6
19
|
for (var prop in source)
|
|
@@ -1015,12 +1028,12 @@ let TonConnectError$1 = class TonConnectError2 extends Error {
|
|
|
1015
1028
|
}
|
|
1016
1029
|
};
|
|
1017
1030
|
TonConnectError$1.prefix = "[TON_CONNECT_SDK_ERROR]";
|
|
1018
|
-
|
|
1031
|
+
class DappMetadataError extends TonConnectError$1 {
|
|
1019
1032
|
constructor(...args) {
|
|
1020
1033
|
super(...args);
|
|
1021
|
-
Object.setPrototypeOf(this, DappMetadataError
|
|
1034
|
+
Object.setPrototypeOf(this, DappMetadataError.prototype);
|
|
1022
1035
|
}
|
|
1023
|
-
}
|
|
1036
|
+
}
|
|
1024
1037
|
let ManifestContentErrorError$1 = class ManifestContentErrorError2 extends TonConnectError$1 {
|
|
1025
1038
|
constructor(message) {
|
|
1026
1039
|
super(message || "" + ManifestContentErrorError$1.additionalMessage);
|
|
@@ -1035,25 +1048,25 @@ let ManifestNotFoundError$1 = class ManifestNotFoundError2 extends TonConnectErr
|
|
|
1035
1048
|
}
|
|
1036
1049
|
};
|
|
1037
1050
|
ManifestNotFoundError$1.additionalMessage = "\nManifest not found. Make sure you added `tonconnect-manifest.json` to the root of your app or passed correct manifestUrl. See more https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest";
|
|
1038
|
-
|
|
1051
|
+
class WalletAlreadyConnectedError extends TonConnectError$1 {
|
|
1039
1052
|
constructor(...args) {
|
|
1040
1053
|
super(...args);
|
|
1041
|
-
Object.setPrototypeOf(this, WalletAlreadyConnectedError
|
|
1054
|
+
Object.setPrototypeOf(this, WalletAlreadyConnectedError.prototype);
|
|
1042
1055
|
}
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1056
|
+
}
|
|
1057
|
+
class WalletNotConnectedError extends TonConnectError$1 {
|
|
1045
1058
|
constructor(...args) {
|
|
1046
1059
|
super(...args);
|
|
1047
|
-
Object.setPrototypeOf(this, WalletNotConnectedError
|
|
1060
|
+
Object.setPrototypeOf(this, WalletNotConnectedError.prototype);
|
|
1048
1061
|
}
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1062
|
+
}
|
|
1063
|
+
class WalletNotSupportFeatureError extends TonConnectError$1 {
|
|
1051
1064
|
constructor(...args) {
|
|
1052
1065
|
super(...args);
|
|
1053
|
-
Object.setPrototypeOf(this, WalletNotSupportFeatureError
|
|
1066
|
+
Object.setPrototypeOf(this, WalletNotSupportFeatureError.prototype);
|
|
1054
1067
|
}
|
|
1055
|
-
}
|
|
1056
|
-
function isWalletConnectionSourceJS
|
|
1068
|
+
}
|
|
1069
|
+
function isWalletConnectionSourceJS(value) {
|
|
1057
1070
|
return "jsBridgeKey" in value;
|
|
1058
1071
|
}
|
|
1059
1072
|
let UserRejectsError$1 = class UserRejectsError2 extends TonConnectError$1 {
|
|
@@ -1074,24 +1087,24 @@ let UnknownAppError$1 = class UnknownAppError2 extends TonConnectError$1 {
|
|
|
1074
1087
|
Object.setPrototypeOf(this, UnknownAppError$1.prototype);
|
|
1075
1088
|
}
|
|
1076
1089
|
};
|
|
1077
|
-
|
|
1090
|
+
class WalletNotInjectedError extends TonConnectError$1 {
|
|
1078
1091
|
constructor(...args) {
|
|
1079
1092
|
super(...args);
|
|
1080
|
-
Object.setPrototypeOf(this, WalletNotInjectedError
|
|
1093
|
+
Object.setPrototypeOf(this, WalletNotInjectedError.prototype);
|
|
1081
1094
|
}
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1095
|
+
}
|
|
1096
|
+
class LocalstorageNotFoundError extends TonConnectError$1 {
|
|
1084
1097
|
constructor(...args) {
|
|
1085
1098
|
super(...args);
|
|
1086
|
-
Object.setPrototypeOf(this, LocalstorageNotFoundError
|
|
1099
|
+
Object.setPrototypeOf(this, LocalstorageNotFoundError.prototype);
|
|
1087
1100
|
}
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1101
|
+
}
|
|
1102
|
+
class FetchWalletsError extends TonConnectError$1 {
|
|
1090
1103
|
constructor(...args) {
|
|
1091
1104
|
super(...args);
|
|
1092
|
-
Object.setPrototypeOf(this, FetchWalletsError
|
|
1105
|
+
Object.setPrototypeOf(this, FetchWalletsError.prototype);
|
|
1093
1106
|
}
|
|
1094
|
-
}
|
|
1107
|
+
}
|
|
1095
1108
|
let WrongAddressError$1 = class WrongAddressError2 extends TonConnectError$1 {
|
|
1096
1109
|
constructor(...args) {
|
|
1097
1110
|
super(...args);
|
|
@@ -1228,9 +1241,9 @@ var naclUtil$1 = { exports: {} };
|
|
|
1228
1241
|
return util;
|
|
1229
1242
|
});
|
|
1230
1243
|
})(naclUtil$1);
|
|
1231
|
-
const nacl$1
|
|
1244
|
+
const nacl$1 = naclUtil$1.exports;
|
|
1232
1245
|
function encodeUint8Array$1(value, urlSafe) {
|
|
1233
|
-
const encoded = nacl$1
|
|
1246
|
+
const encoded = nacl$1.encodeBase64(value);
|
|
1234
1247
|
if (!urlSafe) {
|
|
1235
1248
|
return encoded;
|
|
1236
1249
|
}
|
|
@@ -1240,7 +1253,7 @@ function decodeToUint8Array$1(value, urlSafe) {
|
|
|
1240
1253
|
if (urlSafe) {
|
|
1241
1254
|
value = decodeURIComponent(value);
|
|
1242
1255
|
}
|
|
1243
|
-
return nacl$1
|
|
1256
|
+
return nacl$1.decodeBase64(value);
|
|
1244
1257
|
}
|
|
1245
1258
|
function encode$1(value, urlSafe = false) {
|
|
1246
1259
|
let uint8Array;
|
|
@@ -1250,7 +1263,7 @@ function encode$1(value, urlSafe = false) {
|
|
|
1250
1263
|
if (typeof value !== "string") {
|
|
1251
1264
|
value = JSON.stringify(value);
|
|
1252
1265
|
}
|
|
1253
|
-
uint8Array = nacl$1
|
|
1266
|
+
uint8Array = nacl$1.decodeUTF8(value);
|
|
1254
1267
|
}
|
|
1255
1268
|
return encodeUint8Array$1(uint8Array, urlSafe);
|
|
1256
1269
|
}
|
|
@@ -1258,11 +1271,11 @@ function decode$1(value, urlSafe = false) {
|
|
|
1258
1271
|
const decodedUint8Array = decodeToUint8Array$1(value, urlSafe);
|
|
1259
1272
|
return {
|
|
1260
1273
|
toString() {
|
|
1261
|
-
return nacl$1
|
|
1274
|
+
return nacl$1.encodeUTF8(decodedUint8Array);
|
|
1262
1275
|
},
|
|
1263
1276
|
toObject() {
|
|
1264
1277
|
try {
|
|
1265
|
-
return JSON.parse(nacl$1
|
|
1278
|
+
return JSON.parse(nacl$1.encodeUTF8(decodedUint8Array));
|
|
1266
1279
|
} catch (e2) {
|
|
1267
1280
|
return null;
|
|
1268
1281
|
}
|
|
@@ -1276,13 +1289,13 @@ const Base64$1 = {
|
|
|
1276
1289
|
encode: encode$1,
|
|
1277
1290
|
decode: decode$1
|
|
1278
1291
|
};
|
|
1279
|
-
function concatUint8Arrays
|
|
1292
|
+
function concatUint8Arrays(buffer1, buffer2) {
|
|
1280
1293
|
const mergedArray = new Uint8Array(buffer1.length + buffer2.length);
|
|
1281
1294
|
mergedArray.set(buffer1);
|
|
1282
1295
|
mergedArray.set(buffer2, buffer1.length);
|
|
1283
1296
|
return mergedArray;
|
|
1284
1297
|
}
|
|
1285
|
-
function splitToUint8Arrays
|
|
1298
|
+
function splitToUint8Arrays(array, index) {
|
|
1286
1299
|
if (index >= array.length) {
|
|
1287
1300
|
throw new Error("Index is out of buffer");
|
|
1288
1301
|
}
|
|
@@ -1290,14 +1303,14 @@ function splitToUint8Arrays$1(array, index) {
|
|
|
1290
1303
|
const subArray2 = array.slice(index);
|
|
1291
1304
|
return [subArray1, subArray2];
|
|
1292
1305
|
}
|
|
1293
|
-
function toHexString
|
|
1306
|
+
function toHexString(byteArray) {
|
|
1294
1307
|
let hexString = "";
|
|
1295
1308
|
byteArray.forEach((byte) => {
|
|
1296
1309
|
hexString += ("0" + (byte & 255).toString(16)).slice(-2);
|
|
1297
1310
|
});
|
|
1298
1311
|
return hexString;
|
|
1299
1312
|
}
|
|
1300
|
-
function hexToByteArray
|
|
1313
|
+
function hexToByteArray(hexString) {
|
|
1301
1314
|
if (hexString.length % 2 !== 0) {
|
|
1302
1315
|
throw new Error(`Cannot convert ${hexString} to bytesArray`);
|
|
1303
1316
|
}
|
|
@@ -3623,19 +3636,19 @@ if (isNode$1()) {
|
|
|
3623
3636
|
} catch (err) {
|
|
3624
3637
|
}
|
|
3625
3638
|
}
|
|
3626
|
-
|
|
3639
|
+
class SessionCrypto {
|
|
3627
3640
|
constructor(keyPair) {
|
|
3628
3641
|
this.nonceLength = 24;
|
|
3629
3642
|
this.keyPair = keyPair ? this.createKeypairFromString(keyPair) : this.createKeypair();
|
|
3630
|
-
this.sessionId = toHexString
|
|
3643
|
+
this.sessionId = toHexString(this.keyPair.publicKey);
|
|
3631
3644
|
}
|
|
3632
3645
|
createKeypair() {
|
|
3633
3646
|
return nacl$2.box.keyPair();
|
|
3634
3647
|
}
|
|
3635
3648
|
createKeypairFromString(keyPair) {
|
|
3636
3649
|
return {
|
|
3637
|
-
publicKey: hexToByteArray
|
|
3638
|
-
secretKey: hexToByteArray
|
|
3650
|
+
publicKey: hexToByteArray(keyPair.publicKey),
|
|
3651
|
+
secretKey: hexToByteArray(keyPair.secretKey)
|
|
3639
3652
|
};
|
|
3640
3653
|
}
|
|
3641
3654
|
createNonce() {
|
|
@@ -3646,24 +3659,28 @@ let SessionCrypto$1 = class SessionCrypto2 {
|
|
|
3646
3659
|
const encodedMessage = new TextEncoder().encode(message);
|
|
3647
3660
|
const nonce = this.createNonce();
|
|
3648
3661
|
const encrypted = nacl$2.box(encodedMessage, nonce, receiverPublicKey, this.keyPair.secretKey);
|
|
3649
|
-
return concatUint8Arrays
|
|
3662
|
+
return concatUint8Arrays(nonce, encrypted);
|
|
3650
3663
|
}
|
|
3651
3664
|
decrypt(message, senderPublicKey) {
|
|
3652
|
-
const [nonce, internalMessage] = splitToUint8Arrays
|
|
3665
|
+
const [nonce, internalMessage] = splitToUint8Arrays(message, this.nonceLength);
|
|
3653
3666
|
const decrypted = nacl$2.box.open(internalMessage, nonce, senderPublicKey, this.keyPair.secretKey);
|
|
3654
3667
|
if (!decrypted) {
|
|
3655
|
-
throw new Error(
|
|
3668
|
+
throw new Error(`Decryption error:
|
|
3669
|
+
message: ${message.toString()}
|
|
3670
|
+
sender pubkey: ${senderPublicKey.toString()}
|
|
3671
|
+
keypair pubkey: ${this.keyPair.publicKey.toString()}
|
|
3672
|
+
keypair secretkey: ${this.keyPair.secretKey.toString()}`);
|
|
3656
3673
|
}
|
|
3657
3674
|
return new TextDecoder().decode(decrypted);
|
|
3658
3675
|
}
|
|
3659
3676
|
stringifyKeypair() {
|
|
3660
3677
|
return {
|
|
3661
|
-
publicKey: toHexString
|
|
3662
|
-
secretKey: toHexString
|
|
3678
|
+
publicKey: toHexString(this.keyPair.publicKey),
|
|
3679
|
+
secretKey: toHexString(this.keyPair.secretKey)
|
|
3663
3680
|
};
|
|
3664
3681
|
}
|
|
3665
|
-
}
|
|
3666
|
-
const connectEventErrorsCodes
|
|
3682
|
+
}
|
|
3683
|
+
const connectEventErrorsCodes = {
|
|
3667
3684
|
[CONNECT_EVENT_ERROR_CODES$1.UNKNOWN_ERROR]: UnknownError$1,
|
|
3668
3685
|
[CONNECT_EVENT_ERROR_CODES$1.USER_REJECTS_ERROR]: UserRejectsError$1,
|
|
3669
3686
|
[CONNECT_EVENT_ERROR_CODES$1.BAD_REQUEST_ERROR]: BadRequestError$1,
|
|
@@ -3671,28 +3688,28 @@ const connectEventErrorsCodes$1 = {
|
|
|
3671
3688
|
[CONNECT_EVENT_ERROR_CODES$1.MANIFEST_NOT_FOUND_ERROR]: ManifestNotFoundError$1,
|
|
3672
3689
|
[CONNECT_EVENT_ERROR_CODES$1.MANIFEST_CONTENT_ERROR]: ManifestContentErrorError$1
|
|
3673
3690
|
};
|
|
3674
|
-
|
|
3691
|
+
class ConnectErrorsParser {
|
|
3675
3692
|
parseError(error) {
|
|
3676
3693
|
let ErrorConstructor = UnknownError$1;
|
|
3677
|
-
if (error.code in connectEventErrorsCodes
|
|
3678
|
-
ErrorConstructor = connectEventErrorsCodes
|
|
3694
|
+
if (error.code in connectEventErrorsCodes) {
|
|
3695
|
+
ErrorConstructor = connectEventErrorsCodes[error.code] || UnknownError$1;
|
|
3679
3696
|
}
|
|
3680
3697
|
return new ErrorConstructor(error.message);
|
|
3681
3698
|
}
|
|
3682
|
-
}
|
|
3683
|
-
const connectErrorsParser
|
|
3684
|
-
|
|
3699
|
+
}
|
|
3700
|
+
const connectErrorsParser = new ConnectErrorsParser();
|
|
3701
|
+
class RpcParser {
|
|
3685
3702
|
isError(response) {
|
|
3686
3703
|
return "error" in response;
|
|
3687
3704
|
}
|
|
3688
|
-
}
|
|
3689
|
-
const sendTransactionErrors
|
|
3705
|
+
}
|
|
3706
|
+
const sendTransactionErrors = {
|
|
3690
3707
|
[SEND_TRANSACTION_ERROR_CODES$1.UNKNOWN_ERROR]: UnknownError$1,
|
|
3691
3708
|
[SEND_TRANSACTION_ERROR_CODES$1.USER_REJECTS_ERROR]: UserRejectsError$1,
|
|
3692
3709
|
[SEND_TRANSACTION_ERROR_CODES$1.BAD_REQUEST_ERROR]: BadRequestError$1,
|
|
3693
3710
|
[SEND_TRANSACTION_ERROR_CODES$1.UNKNOWN_APP_ERROR]: UnknownAppError$1
|
|
3694
3711
|
};
|
|
3695
|
-
|
|
3712
|
+
class SendTransactionParser extends RpcParser {
|
|
3696
3713
|
convertToRpcRequest(request) {
|
|
3697
3714
|
return {
|
|
3698
3715
|
method: "sendTransaction",
|
|
@@ -3701,8 +3718,8 @@ let SendTransactionParser$1 = class SendTransactionParser2 extends RpcParser$1 {
|
|
|
3701
3718
|
}
|
|
3702
3719
|
parseAndThrowError(response) {
|
|
3703
3720
|
let ErrorConstructor = UnknownError$1;
|
|
3704
|
-
if (response.error.code in sendTransactionErrors
|
|
3705
|
-
ErrorConstructor = sendTransactionErrors
|
|
3721
|
+
if (response.error.code in sendTransactionErrors) {
|
|
3722
|
+
ErrorConstructor = sendTransactionErrors[response.error.code] || UnknownError$1;
|
|
3706
3723
|
}
|
|
3707
3724
|
throw new ErrorConstructor(response.error.message);
|
|
3708
3725
|
}
|
|
@@ -3711,9 +3728,9 @@ let SendTransactionParser$1 = class SendTransactionParser2 extends RpcParser$1 {
|
|
|
3711
3728
|
boc: rpcResponse.result
|
|
3712
3729
|
};
|
|
3713
3730
|
}
|
|
3714
|
-
}
|
|
3715
|
-
const sendTransactionParser
|
|
3716
|
-
var __awaiter$7
|
|
3731
|
+
}
|
|
3732
|
+
const sendTransactionParser = new SendTransactionParser();
|
|
3733
|
+
var __awaiter$7 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
3717
3734
|
function adopt(value) {
|
|
3718
3735
|
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
3719
3736
|
resolve(value);
|
|
@@ -3740,23 +3757,23 @@ var __awaiter$7$1 = globalThis && globalThis.__awaiter || function(thisArg, _arg
|
|
|
3740
3757
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
3741
3758
|
});
|
|
3742
3759
|
};
|
|
3743
|
-
|
|
3760
|
+
class HttpBridgeGatewayStorage {
|
|
3744
3761
|
constructor(storage) {
|
|
3745
3762
|
this.storage = storage;
|
|
3746
3763
|
this.storeKey = "ton-connect-storage_http-bridge-gateway";
|
|
3747
3764
|
}
|
|
3748
3765
|
storeLastEventId(lastEventId) {
|
|
3749
|
-
return __awaiter$7
|
|
3766
|
+
return __awaiter$7(this, void 0, void 0, function* () {
|
|
3750
3767
|
return this.storage.setItem(this.storeKey, lastEventId);
|
|
3751
3768
|
});
|
|
3752
3769
|
}
|
|
3753
3770
|
removeLastEventId() {
|
|
3754
|
-
return __awaiter$7
|
|
3771
|
+
return __awaiter$7(this, void 0, void 0, function* () {
|
|
3755
3772
|
return this.storage.removeItem(this.storeKey);
|
|
3756
3773
|
});
|
|
3757
3774
|
}
|
|
3758
3775
|
getLastEventId() {
|
|
3759
|
-
return __awaiter$7
|
|
3776
|
+
return __awaiter$7(this, void 0, void 0, function* () {
|
|
3760
3777
|
const stored = yield this.storage.getItem(this.storeKey);
|
|
3761
3778
|
if (!stored) {
|
|
3762
3779
|
return null;
|
|
@@ -3764,17 +3781,17 @@ let HttpBridgeGatewayStorage$1 = class HttpBridgeGatewayStorage2 {
|
|
|
3764
3781
|
return stored;
|
|
3765
3782
|
});
|
|
3766
3783
|
}
|
|
3767
|
-
}
|
|
3768
|
-
function removeUrlLastSlash
|
|
3784
|
+
}
|
|
3785
|
+
function removeUrlLastSlash(url) {
|
|
3769
3786
|
if (url.slice(-1) === "/") {
|
|
3770
3787
|
return url.slice(0, -1);
|
|
3771
3788
|
}
|
|
3772
3789
|
return url;
|
|
3773
3790
|
}
|
|
3774
|
-
function addPathToUrl
|
|
3775
|
-
return removeUrlLastSlash
|
|
3791
|
+
function addPathToUrl(url, path) {
|
|
3792
|
+
return removeUrlLastSlash(url) + "/" + path;
|
|
3776
3793
|
}
|
|
3777
|
-
var __awaiter$6
|
|
3794
|
+
var __awaiter$6 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
3778
3795
|
function adopt(value) {
|
|
3779
3796
|
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
3780
3797
|
resolve(value);
|
|
@@ -3809,7 +3826,7 @@ if (isNode$1()) {
|
|
|
3809
3826
|
console.error(err);
|
|
3810
3827
|
}
|
|
3811
3828
|
}
|
|
3812
|
-
|
|
3829
|
+
class BridgeGateway {
|
|
3813
3830
|
constructor(storage, bridgeUrl, sessionId, listener, errorsListener) {
|
|
3814
3831
|
this.bridgeUrl = bridgeUrl;
|
|
3815
3832
|
this.sessionId = sessionId;
|
|
@@ -3820,11 +3837,11 @@ let BridgeGateway$1 = class BridgeGateway2 {
|
|
|
3820
3837
|
this.heartbeatMessage = "heartbeat";
|
|
3821
3838
|
this.defaultTtl = 300;
|
|
3822
3839
|
this.isClosed = false;
|
|
3823
|
-
this.bridgeGatewayStorage = new HttpBridgeGatewayStorage
|
|
3840
|
+
this.bridgeGatewayStorage = new HttpBridgeGatewayStorage(storage);
|
|
3824
3841
|
}
|
|
3825
3842
|
registerSession() {
|
|
3826
|
-
return __awaiter$6
|
|
3827
|
-
const url = new URL(addPathToUrl
|
|
3843
|
+
return __awaiter$6(this, void 0, void 0, function* () {
|
|
3844
|
+
const url = new URL(addPathToUrl(this.bridgeUrl, this.ssePath));
|
|
3828
3845
|
url.searchParams.append("client_id", this.sessionId);
|
|
3829
3846
|
const lastEventId = yield this.bridgeGatewayStorage.getLastEventId();
|
|
3830
3847
|
if (lastEventId) {
|
|
@@ -3842,8 +3859,8 @@ let BridgeGateway$1 = class BridgeGateway2 {
|
|
|
3842
3859
|
});
|
|
3843
3860
|
}
|
|
3844
3861
|
send(message, receiver, ttl) {
|
|
3845
|
-
return __awaiter$6
|
|
3846
|
-
const url = new URL(addPathToUrl
|
|
3862
|
+
return __awaiter$6(this, void 0, void 0, function* () {
|
|
3863
|
+
const url = new URL(addPathToUrl(this.bridgeUrl, this.postPath));
|
|
3847
3864
|
url.searchParams.append("client_id", this.sessionId);
|
|
3848
3865
|
url.searchParams.append("to", receiver);
|
|
3849
3866
|
url.searchParams.append("ttl", (ttl || this.defaultTtl).toString());
|
|
@@ -3854,14 +3871,14 @@ let BridgeGateway$1 = class BridgeGateway2 {
|
|
|
3854
3871
|
});
|
|
3855
3872
|
}
|
|
3856
3873
|
close() {
|
|
3857
|
-
var
|
|
3874
|
+
var _a;
|
|
3858
3875
|
this.isClosed = true;
|
|
3859
|
-
(
|
|
3876
|
+
(_a = this.eventSource) === null || _a === void 0 ? void 0 : _a.close();
|
|
3860
3877
|
}
|
|
3861
3878
|
errorsHandler(e2) {
|
|
3862
|
-
var
|
|
3879
|
+
var _a, _b;
|
|
3863
3880
|
if (!this.isClosed) {
|
|
3864
|
-
if (((
|
|
3881
|
+
if (((_a = this.eventSource) === null || _a === void 0 ? void 0 : _a.readyState) === EventSource.CLOSED) {
|
|
3865
3882
|
this.eventSource.close();
|
|
3866
3883
|
this.registerSession();
|
|
3867
3884
|
return;
|
|
@@ -3874,7 +3891,7 @@ let BridgeGateway$1 = class BridgeGateway2 {
|
|
|
3874
3891
|
}
|
|
3875
3892
|
}
|
|
3876
3893
|
messagesHandler(e2) {
|
|
3877
|
-
return __awaiter$6
|
|
3894
|
+
return __awaiter$6(this, void 0, void 0, function* () {
|
|
3878
3895
|
if (e2.data === this.heartbeatMessage) {
|
|
3879
3896
|
return;
|
|
3880
3897
|
}
|
|
@@ -3890,8 +3907,8 @@ let BridgeGateway$1 = class BridgeGateway2 {
|
|
|
3890
3907
|
}
|
|
3891
3908
|
});
|
|
3892
3909
|
}
|
|
3893
|
-
}
|
|
3894
|
-
var __awaiter$5
|
|
3910
|
+
}
|
|
3911
|
+
var __awaiter$5 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
3895
3912
|
function adopt(value) {
|
|
3896
3913
|
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
3897
3914
|
resolve(value);
|
|
@@ -3918,13 +3935,13 @@ var __awaiter$5$1 = globalThis && globalThis.__awaiter || function(thisArg, _arg
|
|
|
3918
3935
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
3919
3936
|
});
|
|
3920
3937
|
};
|
|
3921
|
-
|
|
3938
|
+
class BridgeConnectionStorage {
|
|
3922
3939
|
constructor(storage) {
|
|
3923
3940
|
this.storage = storage;
|
|
3924
3941
|
this.storeKey = "ton-connect-storage_bridge-connection";
|
|
3925
3942
|
}
|
|
3926
3943
|
storeConnection(connection) {
|
|
3927
|
-
return __awaiter$5
|
|
3944
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3928
3945
|
if (connection.type === "injected") {
|
|
3929
3946
|
return this.storage.setItem(this.storeKey, JSON.stringify(connection));
|
|
3930
3947
|
}
|
|
@@ -3942,12 +3959,12 @@ let BridgeConnectionStorage$1 = class BridgeConnectionStorage2 {
|
|
|
3942
3959
|
});
|
|
3943
3960
|
}
|
|
3944
3961
|
removeConnection() {
|
|
3945
|
-
return __awaiter$5
|
|
3962
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3946
3963
|
return this.storage.removeItem(this.storeKey);
|
|
3947
3964
|
});
|
|
3948
3965
|
}
|
|
3949
3966
|
getConnection() {
|
|
3950
|
-
return __awaiter$5
|
|
3967
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3951
3968
|
const stored = yield this.storage.getItem(this.storeKey);
|
|
3952
3969
|
if (!stored) {
|
|
3953
3970
|
return null;
|
|
@@ -3956,7 +3973,7 @@ let BridgeConnectionStorage$1 = class BridgeConnectionStorage2 {
|
|
|
3956
3973
|
if (connection.type === "injected") {
|
|
3957
3974
|
return connection;
|
|
3958
3975
|
}
|
|
3959
|
-
const sessionCrypto = new SessionCrypto
|
|
3976
|
+
const sessionCrypto = new SessionCrypto(connection.session.sessionKeyPair);
|
|
3960
3977
|
return {
|
|
3961
3978
|
type: "http",
|
|
3962
3979
|
connectEvent: connection.connectEvent,
|
|
@@ -3969,7 +3986,7 @@ let BridgeConnectionStorage$1 = class BridgeConnectionStorage2 {
|
|
|
3969
3986
|
});
|
|
3970
3987
|
}
|
|
3971
3988
|
getHttpConnection() {
|
|
3972
|
-
return __awaiter$5
|
|
3989
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3973
3990
|
const connection = yield this.getConnection();
|
|
3974
3991
|
if (!connection) {
|
|
3975
3992
|
throw new TonConnectError$1("Trying to read HTTP connection source while nothing is stored");
|
|
@@ -3981,7 +3998,7 @@ let BridgeConnectionStorage$1 = class BridgeConnectionStorage2 {
|
|
|
3981
3998
|
});
|
|
3982
3999
|
}
|
|
3983
4000
|
getInjectedConnection() {
|
|
3984
|
-
return __awaiter$5
|
|
4001
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3985
4002
|
const connection = yield this.getConnection();
|
|
3986
4003
|
if (!connection) {
|
|
3987
4004
|
throw new TonConnectError$1("Trying to read Injected bridge connection source while nothing is stored");
|
|
@@ -3993,7 +4010,7 @@ let BridgeConnectionStorage$1 = class BridgeConnectionStorage2 {
|
|
|
3993
4010
|
});
|
|
3994
4011
|
}
|
|
3995
4012
|
storedConnectionType() {
|
|
3996
|
-
return __awaiter$5
|
|
4013
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3997
4014
|
const stored = yield this.storage.getItem(this.storeKey);
|
|
3998
4015
|
if (!stored) {
|
|
3999
4016
|
return null;
|
|
@@ -4002,9 +4019,9 @@ let BridgeConnectionStorage$1 = class BridgeConnectionStorage2 {
|
|
|
4002
4019
|
return connection.type;
|
|
4003
4020
|
});
|
|
4004
4021
|
}
|
|
4005
|
-
}
|
|
4006
|
-
const PROTOCOL_VERSION
|
|
4007
|
-
var __awaiter$4
|
|
4022
|
+
}
|
|
4023
|
+
const PROTOCOL_VERSION = 2;
|
|
4024
|
+
var __awaiter$4 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
4008
4025
|
function adopt(value) {
|
|
4009
4026
|
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
4010
4027
|
resolve(value);
|
|
@@ -4031,7 +4048,7 @@ var __awaiter$4$1 = globalThis && globalThis.__awaiter || function(thisArg, _arg
|
|
|
4031
4048
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
4032
4049
|
});
|
|
4033
4050
|
};
|
|
4034
|
-
|
|
4051
|
+
class BridgeProvider {
|
|
4035
4052
|
constructor(storage, walletConnectionSource) {
|
|
4036
4053
|
this.storage = storage;
|
|
4037
4054
|
this.walletConnectionSource = walletConnectionSource;
|
|
@@ -4041,37 +4058,37 @@ let BridgeProvider$1 = class BridgeProvider2 {
|
|
|
4041
4058
|
this.session = null;
|
|
4042
4059
|
this.bridge = null;
|
|
4043
4060
|
this.listeners = [];
|
|
4044
|
-
this.connectionStorage = new BridgeConnectionStorage
|
|
4061
|
+
this.connectionStorage = new BridgeConnectionStorage(storage);
|
|
4045
4062
|
}
|
|
4046
4063
|
static fromStorage(storage) {
|
|
4047
|
-
return __awaiter$4
|
|
4048
|
-
const bridgeConnectionStorage = new BridgeConnectionStorage
|
|
4064
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4065
|
+
const bridgeConnectionStorage = new BridgeConnectionStorage(storage);
|
|
4049
4066
|
const connection = yield bridgeConnectionStorage.getHttpConnection();
|
|
4050
|
-
return new BridgeProvider
|
|
4067
|
+
return new BridgeProvider(storage, connection.session.walletConnectionSource);
|
|
4051
4068
|
});
|
|
4052
4069
|
}
|
|
4053
4070
|
connect(message) {
|
|
4054
|
-
var
|
|
4055
|
-
(
|
|
4056
|
-
const sessionCrypto = new SessionCrypto
|
|
4071
|
+
var _a;
|
|
4072
|
+
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
|
|
4073
|
+
const sessionCrypto = new SessionCrypto();
|
|
4057
4074
|
this.session = {
|
|
4058
4075
|
sessionCrypto,
|
|
4059
4076
|
walletConnectionSource: this.walletConnectionSource
|
|
4060
4077
|
};
|
|
4061
|
-
this.bridge = new BridgeGateway
|
|
4078
|
+
this.bridge = new BridgeGateway(this.storage, this.walletConnectionSource.bridgeUrl, sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this));
|
|
4062
4079
|
this.bridge.registerSession();
|
|
4063
4080
|
return this.generateUniversalLink(message);
|
|
4064
4081
|
}
|
|
4065
4082
|
restoreConnection() {
|
|
4066
|
-
var
|
|
4067
|
-
return __awaiter$4
|
|
4068
|
-
(
|
|
4083
|
+
var _a;
|
|
4084
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4085
|
+
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
|
|
4069
4086
|
const storedConnection = yield this.connectionStorage.getHttpConnection();
|
|
4070
4087
|
if (!storedConnection) {
|
|
4071
4088
|
return;
|
|
4072
4089
|
}
|
|
4073
4090
|
this.session = storedConnection.session;
|
|
4074
|
-
this.bridge = new BridgeGateway
|
|
4091
|
+
this.bridge = new BridgeGateway(this.storage, this.walletConnectionSource.bridgeUrl, storedConnection.session.sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this));
|
|
4075
4092
|
yield this.bridge.registerSession();
|
|
4076
4093
|
this.listeners.forEach((listener) => listener(storedConnection.connectEvent));
|
|
4077
4094
|
});
|
|
@@ -4083,21 +4100,21 @@ let BridgeProvider$1 = class BridgeProvider2 {
|
|
|
4083
4100
|
if (!this.bridge || !this.session || !("walletPublicKey" in this.session)) {
|
|
4084
4101
|
throw new TonConnectError$1("Trying to send bridge request without session");
|
|
4085
4102
|
}
|
|
4086
|
-
const encodedRequest = this.session.sessionCrypto.encrypt(JSON.stringify(Object.assign(Object.assign({}, request), { id })), hexToByteArray
|
|
4103
|
+
const encodedRequest = this.session.sessionCrypto.encrypt(JSON.stringify(Object.assign(Object.assign({}, request), { id })), hexToByteArray(this.session.walletPublicKey));
|
|
4087
4104
|
this.bridge.send(encodedRequest, this.session.walletPublicKey).catch(reject);
|
|
4088
4105
|
this.pendingRequests.set(id.toString(), resolve);
|
|
4089
4106
|
});
|
|
4090
4107
|
}
|
|
4091
4108
|
closeConnection() {
|
|
4092
|
-
var
|
|
4093
|
-
(
|
|
4109
|
+
var _a;
|
|
4110
|
+
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
|
|
4094
4111
|
this.listeners = [];
|
|
4095
4112
|
this.session = null;
|
|
4096
4113
|
this.bridge = null;
|
|
4097
4114
|
}
|
|
4098
4115
|
disconnect() {
|
|
4099
|
-
var
|
|
4100
|
-
(
|
|
4116
|
+
var _a;
|
|
4117
|
+
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
|
|
4101
4118
|
this.listeners = [];
|
|
4102
4119
|
return this.removeBridgeAndSession();
|
|
4103
4120
|
}
|
|
@@ -4106,8 +4123,8 @@ let BridgeProvider$1 = class BridgeProvider2 {
|
|
|
4106
4123
|
return () => this.listeners = this.listeners.filter((listener) => listener !== callback);
|
|
4107
4124
|
}
|
|
4108
4125
|
gatewayListener(bridgeIncomingMessage) {
|
|
4109
|
-
return __awaiter$4
|
|
4110
|
-
const walletMessage = JSON.parse(this.session.sessionCrypto.decrypt(Base64$1.decode(bridgeIncomingMessage.message).toUint8Array(), hexToByteArray
|
|
4126
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4127
|
+
const walletMessage = JSON.parse(this.session.sessionCrypto.decrypt(Base64$1.decode(bridgeIncomingMessage.message).toUint8Array(), hexToByteArray(bridgeIncomingMessage.from)));
|
|
4111
4128
|
if (!("event" in walletMessage)) {
|
|
4112
4129
|
const id = walletMessage.id.toString();
|
|
4113
4130
|
const resolve = this.pendingRequests.get(id);
|
|
@@ -4128,12 +4145,12 @@ let BridgeProvider$1 = class BridgeProvider2 {
|
|
|
4128
4145
|
});
|
|
4129
4146
|
}
|
|
4130
4147
|
gatewayErrorsListener(e2) {
|
|
4131
|
-
return __awaiter$4
|
|
4148
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4132
4149
|
throw new TonConnectError$1(`Bridge error ${JSON.stringify(e2)}`);
|
|
4133
4150
|
});
|
|
4134
4151
|
}
|
|
4135
4152
|
updateSession(connectEvent, walletPublicKey) {
|
|
4136
|
-
return __awaiter$4
|
|
4153
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4137
4154
|
this.session = Object.assign(Object.assign({}, this.session), { walletPublicKey });
|
|
4138
4155
|
const tonAddrItem = connectEvent.payload.items.find((item) => item.name === "ton_addr");
|
|
4139
4156
|
const connectEventToSave = Object.assign(Object.assign({}, connectEvent), { payload: Object.assign(Object.assign({}, connectEvent.payload), { items: [tonAddrItem] }) });
|
|
@@ -4145,7 +4162,7 @@ let BridgeProvider$1 = class BridgeProvider2 {
|
|
|
4145
4162
|
});
|
|
4146
4163
|
}
|
|
4147
4164
|
removeBridgeAndSession() {
|
|
4148
|
-
return __awaiter$4
|
|
4165
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4149
4166
|
this.session = null;
|
|
4150
4167
|
this.bridge = null;
|
|
4151
4168
|
yield this.connectionStorage.removeConnection();
|
|
@@ -4153,27 +4170,27 @@ let BridgeProvider$1 = class BridgeProvider2 {
|
|
|
4153
4170
|
}
|
|
4154
4171
|
generateUniversalLink(message) {
|
|
4155
4172
|
const url = new URL(this.walletConnectionSource.universalLink);
|
|
4156
|
-
url.searchParams.append("v", PROTOCOL_VERSION
|
|
4173
|
+
url.searchParams.append("v", PROTOCOL_VERSION.toString());
|
|
4157
4174
|
url.searchParams.append("id", this.session.sessionCrypto.sessionId);
|
|
4158
4175
|
url.searchParams.append("r", JSON.stringify(message));
|
|
4159
4176
|
return url.toString();
|
|
4160
4177
|
}
|
|
4161
|
-
}
|
|
4178
|
+
}
|
|
4162
4179
|
function getWindow$1() {
|
|
4163
4180
|
if (typeof window === "undefined") {
|
|
4164
4181
|
return void 0;
|
|
4165
4182
|
}
|
|
4166
4183
|
return window;
|
|
4167
4184
|
}
|
|
4168
|
-
function getWebPageManifest
|
|
4169
|
-
var
|
|
4170
|
-
const origin = (
|
|
4185
|
+
function getWebPageManifest() {
|
|
4186
|
+
var _a;
|
|
4187
|
+
const origin = (_a = getWindow$1()) === null || _a === void 0 ? void 0 : _a.location.origin;
|
|
4171
4188
|
if (origin) {
|
|
4172
4189
|
return origin + "/tonconnect-manifest.json";
|
|
4173
4190
|
}
|
|
4174
4191
|
return "";
|
|
4175
4192
|
}
|
|
4176
|
-
var __awaiter$3
|
|
4193
|
+
var __awaiter$3 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
4177
4194
|
function adopt(value) {
|
|
4178
4195
|
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
4179
4196
|
resolve(value);
|
|
@@ -4200,30 +4217,30 @@ var __awaiter$3$1 = globalThis && globalThis.__awaiter || function(thisArg, _arg
|
|
|
4200
4217
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
4201
4218
|
});
|
|
4202
4219
|
};
|
|
4203
|
-
|
|
4220
|
+
class InjectedProvider {
|
|
4204
4221
|
constructor(injectedWalletKey) {
|
|
4205
4222
|
this.type = "injected";
|
|
4206
4223
|
this.unsubscribeCallback = null;
|
|
4207
4224
|
this.listenSubscriptions = false;
|
|
4208
4225
|
this.listeners = [];
|
|
4209
|
-
const window2 = InjectedProvider
|
|
4210
|
-
if (!InjectedProvider
|
|
4211
|
-
throw new WalletNotInjectedError
|
|
4226
|
+
const window2 = InjectedProvider.window;
|
|
4227
|
+
if (!InjectedProvider.isWindowContainsWallet(window2, injectedWalletKey)) {
|
|
4228
|
+
throw new WalletNotInjectedError();
|
|
4212
4229
|
}
|
|
4213
4230
|
this.injectedWallet = window2[injectedWalletKey].tonconnect;
|
|
4214
4231
|
}
|
|
4215
4232
|
static fromStorage(storage) {
|
|
4216
|
-
return __awaiter$3
|
|
4217
|
-
const bridgeConnectionStorage = new BridgeConnectionStorage
|
|
4233
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
4234
|
+
const bridgeConnectionStorage = new BridgeConnectionStorage(storage);
|
|
4218
4235
|
const connection = yield bridgeConnectionStorage.getInjectedConnection();
|
|
4219
|
-
return new InjectedProvider
|
|
4236
|
+
return new InjectedProvider(connection.jsBridgeKey);
|
|
4220
4237
|
});
|
|
4221
4238
|
}
|
|
4222
4239
|
static isWalletInjected(injectedWalletKey) {
|
|
4223
|
-
return InjectedProvider
|
|
4240
|
+
return InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey);
|
|
4224
4241
|
}
|
|
4225
4242
|
static isInsideWalletBrowser(injectedWalletKey) {
|
|
4226
|
-
if (InjectedProvider
|
|
4243
|
+
if (InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey)) {
|
|
4227
4244
|
return this.window[injectedWalletKey].tonconnect.isWalletBrowser;
|
|
4228
4245
|
}
|
|
4229
4246
|
return false;
|
|
@@ -4232,7 +4249,7 @@ let InjectedProvider$1 = class InjectedProvider2 {
|
|
|
4232
4249
|
return !!window2 && injectedWalletKey in window2 && typeof window2[injectedWalletKey] === "object" && "tonconnect" in window2[injectedWalletKey];
|
|
4233
4250
|
}
|
|
4234
4251
|
connect(message, auto = false) {
|
|
4235
|
-
this.injectedWallet.connect(PROTOCOL_VERSION
|
|
4252
|
+
this.injectedWallet.connect(PROTOCOL_VERSION, message, auto).then((connectEvent) => {
|
|
4236
4253
|
if (connectEvent.event === "connect") {
|
|
4237
4254
|
this.makeSubscriptions();
|
|
4238
4255
|
this.listenSubscriptions = true;
|
|
@@ -4250,7 +4267,7 @@ let InjectedProvider$1 = class InjectedProvider2 {
|
|
|
4250
4267
|
});
|
|
4251
4268
|
}
|
|
4252
4269
|
restoreConnection() {
|
|
4253
|
-
return __awaiter$3
|
|
4270
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
4254
4271
|
try {
|
|
4255
4272
|
const connectEvent = yield this.injectedWallet.restoreConnection();
|
|
4256
4273
|
if (connectEvent.event === "connect") {
|
|
@@ -4275,17 +4292,17 @@ let InjectedProvider$1 = class InjectedProvider2 {
|
|
|
4275
4292
|
return Promise.resolve();
|
|
4276
4293
|
}
|
|
4277
4294
|
closeAllListeners() {
|
|
4278
|
-
var
|
|
4295
|
+
var _a;
|
|
4279
4296
|
this.listenSubscriptions = false;
|
|
4280
4297
|
this.listeners = [];
|
|
4281
|
-
(
|
|
4298
|
+
(_a = this.unsubscribeCallback) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
4282
4299
|
}
|
|
4283
4300
|
listen(eventsCallback) {
|
|
4284
4301
|
this.listeners.push(eventsCallback);
|
|
4285
4302
|
return () => this.listeners = this.listeners.filter((listener) => listener !== eventsCallback);
|
|
4286
4303
|
}
|
|
4287
4304
|
sendRequest(request) {
|
|
4288
|
-
return __awaiter$3
|
|
4305
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
4289
4306
|
return this.injectedWallet.send(Object.assign(Object.assign({}, request), { id: "0" }));
|
|
4290
4307
|
});
|
|
4291
4308
|
}
|
|
@@ -4299,9 +4316,9 @@ let InjectedProvider$1 = class InjectedProvider2 {
|
|
|
4299
4316
|
}
|
|
4300
4317
|
});
|
|
4301
4318
|
}
|
|
4302
|
-
}
|
|
4303
|
-
InjectedProvider
|
|
4304
|
-
var __awaiter$2
|
|
4319
|
+
}
|
|
4320
|
+
InjectedProvider.window = getWindow$1();
|
|
4321
|
+
var __awaiter$2 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
4305
4322
|
function adopt(value) {
|
|
4306
4323
|
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
4307
4324
|
resolve(value);
|
|
@@ -4328,21 +4345,21 @@ var __awaiter$2$1 = globalThis && globalThis.__awaiter || function(thisArg, _arg
|
|
|
4328
4345
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
4329
4346
|
});
|
|
4330
4347
|
};
|
|
4331
|
-
|
|
4348
|
+
class DefaultStorage {
|
|
4332
4349
|
constructor() {
|
|
4333
4350
|
const window2 = getWindow$1();
|
|
4334
4351
|
if (!(window2 === null || window2 === void 0 ? void 0 : window2.localStorage)) {
|
|
4335
|
-
throw new LocalstorageNotFoundError
|
|
4352
|
+
throw new LocalstorageNotFoundError();
|
|
4336
4353
|
}
|
|
4337
4354
|
this.window = window2;
|
|
4338
4355
|
}
|
|
4339
4356
|
getItem(key) {
|
|
4340
|
-
return __awaiter$2
|
|
4357
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
4341
4358
|
return Promise.resolve(this.window.localStorage.getItem(key));
|
|
4342
4359
|
});
|
|
4343
4360
|
}
|
|
4344
4361
|
removeItem(key) {
|
|
4345
|
-
return __awaiter$2
|
|
4362
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
4346
4363
|
this.window.localStorage.removeItem(key);
|
|
4347
4364
|
return Promise.resolve();
|
|
4348
4365
|
});
|
|
@@ -4351,11 +4368,11 @@ let DefaultStorage$1 = class DefaultStorage2 {
|
|
|
4351
4368
|
this.window.localStorage.setItem(key, value);
|
|
4352
4369
|
return Promise.resolve();
|
|
4353
4370
|
}
|
|
4354
|
-
}
|
|
4355
|
-
function isWalletInfoInjected
|
|
4371
|
+
}
|
|
4372
|
+
function isWalletInfoInjected(value) {
|
|
4356
4373
|
return "jsBridgeKey" in value;
|
|
4357
4374
|
}
|
|
4358
|
-
var __awaiter$1
|
|
4375
|
+
var __awaiter$1 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
4359
4376
|
function adopt(value) {
|
|
4360
4377
|
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
4361
4378
|
resolve(value);
|
|
@@ -4382,13 +4399,13 @@ var __awaiter$1$1 = globalThis && globalThis.__awaiter || function(thisArg, _arg
|
|
|
4382
4399
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
4383
4400
|
});
|
|
4384
4401
|
};
|
|
4385
|
-
|
|
4402
|
+
class WalletsListManager {
|
|
4386
4403
|
constructor() {
|
|
4387
4404
|
this.walletsListCache = null;
|
|
4388
4405
|
this.walletsListSource = "https://raw.githubusercontent.com/ton-connect/wallets-list/main/wallets.json";
|
|
4389
4406
|
}
|
|
4390
4407
|
getWallets() {
|
|
4391
|
-
return __awaiter$1
|
|
4408
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
4392
4409
|
if (!this.walletsListCache) {
|
|
4393
4410
|
this.walletsListCache = this.fetchWalletsList();
|
|
4394
4411
|
this.walletsListCache.catch(() => this.walletsListCache = null);
|
|
@@ -4397,9 +4414,9 @@ let WalletsListManager$1 = class WalletsListManager2 {
|
|
|
4397
4414
|
});
|
|
4398
4415
|
}
|
|
4399
4416
|
getEmbeddedWallet() {
|
|
4400
|
-
return __awaiter$1
|
|
4417
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
4401
4418
|
const walletsList = yield this.getWallets();
|
|
4402
|
-
const injectedWallets = walletsList.filter(isWalletInfoInjected
|
|
4419
|
+
const injectedWallets = walletsList.filter(isWalletInfoInjected);
|
|
4403
4420
|
if (injectedWallets.length !== 1) {
|
|
4404
4421
|
return null;
|
|
4405
4422
|
}
|
|
@@ -4407,16 +4424,16 @@ let WalletsListManager$1 = class WalletsListManager2 {
|
|
|
4407
4424
|
});
|
|
4408
4425
|
}
|
|
4409
4426
|
fetchWalletsList() {
|
|
4410
|
-
return __awaiter$1
|
|
4427
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
4411
4428
|
try {
|
|
4412
4429
|
const walletsResponse = yield fetch(this.walletsListSource);
|
|
4413
4430
|
const walletsList = yield walletsResponse.json();
|
|
4414
4431
|
if (!Array.isArray(walletsList) || !walletsList.every((wallet) => this.isCorrectWalletConfigDTO(wallet))) {
|
|
4415
|
-
throw new FetchWalletsError
|
|
4432
|
+
throw new FetchWalletsError("Wrong wallets list format");
|
|
4416
4433
|
}
|
|
4417
4434
|
return this.walletConfigDTOListToWalletConfigList(walletsList);
|
|
4418
4435
|
} catch (e2) {
|
|
4419
|
-
throw new FetchWalletsError
|
|
4436
|
+
throw new FetchWalletsError(e2);
|
|
4420
4437
|
}
|
|
4421
4438
|
});
|
|
4422
4439
|
}
|
|
@@ -4437,8 +4454,8 @@ let WalletsListManager$1 = class WalletsListManager2 {
|
|
|
4437
4454
|
if (bridge.type === "js") {
|
|
4438
4455
|
const jsBridgeKey = bridge.key;
|
|
4439
4456
|
walletConfig.jsBridgeKey = jsBridgeKey;
|
|
4440
|
-
walletConfig.injected = InjectedProvider
|
|
4441
|
-
walletConfig.embedded = InjectedProvider
|
|
4457
|
+
walletConfig.injected = InjectedProvider.isWalletInjected(jsBridgeKey);
|
|
4458
|
+
walletConfig.embedded = InjectedProvider.isInsideWalletBrowser(jsBridgeKey);
|
|
4442
4459
|
}
|
|
4443
4460
|
});
|
|
4444
4461
|
return walletConfig;
|
|
@@ -4475,8 +4492,8 @@ let WalletsListManager$1 = class WalletsListManager2 {
|
|
|
4475
4492
|
}
|
|
4476
4493
|
return true;
|
|
4477
4494
|
}
|
|
4478
|
-
}
|
|
4479
|
-
var __awaiter
|
|
4495
|
+
}
|
|
4496
|
+
var __awaiter = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
4480
4497
|
function adopt(value) {
|
|
4481
4498
|
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
4482
4499
|
resolve(value);
|
|
@@ -4503,7 +4520,7 @@ var __awaiter$8 = globalThis && globalThis.__awaiter || function(thisArg, _argum
|
|
|
4503
4520
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
4504
4521
|
});
|
|
4505
4522
|
};
|
|
4506
|
-
var __rest
|
|
4523
|
+
var __rest = globalThis && globalThis.__rest || function(s2, e2) {
|
|
4507
4524
|
var t2 = {};
|
|
4508
4525
|
for (var p2 in s2)
|
|
4509
4526
|
if (Object.prototype.hasOwnProperty.call(s2, p2) && e2.indexOf(p2) < 0)
|
|
@@ -4515,29 +4532,31 @@ var __rest$1 = globalThis && globalThis.__rest || function(s2, e2) {
|
|
|
4515
4532
|
}
|
|
4516
4533
|
return t2;
|
|
4517
4534
|
};
|
|
4518
|
-
|
|
4519
|
-
let TonConnect$1 = class TonConnect2 {
|
|
4535
|
+
class TonConnect {
|
|
4520
4536
|
constructor(options) {
|
|
4521
|
-
this.walletsList = new WalletsListManager
|
|
4537
|
+
this.walletsList = new WalletsListManager();
|
|
4522
4538
|
this._wallet = null;
|
|
4523
4539
|
this.provider = null;
|
|
4524
4540
|
this.statusChangeSubscriptions = [];
|
|
4525
4541
|
this.statusChangeErrorSubscriptions = [];
|
|
4526
4542
|
this.dappSettings = {
|
|
4527
|
-
manifestUrl: (options === null || options === void 0 ? void 0 : options.manifestUrl) || getWebPageManifest
|
|
4528
|
-
storage: (options === null || options === void 0 ? void 0 : options.storage) || new DefaultStorage
|
|
4543
|
+
manifestUrl: (options === null || options === void 0 ? void 0 : options.manifestUrl) || getWebPageManifest(),
|
|
4544
|
+
storage: (options === null || options === void 0 ? void 0 : options.storage) || new DefaultStorage()
|
|
4529
4545
|
};
|
|
4530
4546
|
if (!this.dappSettings.manifestUrl) {
|
|
4531
|
-
throw new DappMetadataError
|
|
4547
|
+
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");
|
|
4532
4548
|
}
|
|
4533
|
-
this.bridgeConnectionStorage = new BridgeConnectionStorage
|
|
4549
|
+
this.bridgeConnectionStorage = new BridgeConnectionStorage(this.dappSettings.storage);
|
|
4550
|
+
}
|
|
4551
|
+
static getWallets() {
|
|
4552
|
+
return this.walletsList.getWallets();
|
|
4534
4553
|
}
|
|
4535
4554
|
get connected() {
|
|
4536
4555
|
return this._wallet !== null;
|
|
4537
4556
|
}
|
|
4538
4557
|
get account() {
|
|
4539
|
-
var
|
|
4540
|
-
return ((
|
|
4558
|
+
var _a;
|
|
4559
|
+
return ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.account) || null;
|
|
4541
4560
|
}
|
|
4542
4561
|
get wallet() {
|
|
4543
4562
|
return this._wallet;
|
|
@@ -4562,26 +4581,26 @@ let TonConnect$1 = class TonConnect2 {
|
|
|
4562
4581
|
};
|
|
4563
4582
|
}
|
|
4564
4583
|
connect(wallet, request) {
|
|
4565
|
-
var
|
|
4584
|
+
var _a;
|
|
4566
4585
|
if (this.connected) {
|
|
4567
|
-
throw new WalletAlreadyConnectedError
|
|
4586
|
+
throw new WalletAlreadyConnectedError();
|
|
4568
4587
|
}
|
|
4569
|
-
(
|
|
4588
|
+
(_a = this.provider) === null || _a === void 0 ? void 0 : _a.closeConnection();
|
|
4570
4589
|
this.provider = this.createProvider(wallet);
|
|
4571
4590
|
return this.provider.connect(this.createConnectRequest(request));
|
|
4572
4591
|
}
|
|
4573
4592
|
restoreConnection() {
|
|
4574
|
-
return __awaiter
|
|
4593
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4575
4594
|
const [bridgeConnectionType, embeddedWallet] = yield Promise.all([
|
|
4576
4595
|
this.bridgeConnectionStorage.storedConnectionType(),
|
|
4577
4596
|
this.walletsList.getEmbeddedWallet()
|
|
4578
4597
|
]);
|
|
4579
4598
|
switch (bridgeConnectionType) {
|
|
4580
4599
|
case "http":
|
|
4581
|
-
this.provider = yield BridgeProvider
|
|
4600
|
+
this.provider = yield BridgeProvider.fromStorage(this.dappSettings.storage);
|
|
4582
4601
|
break;
|
|
4583
4602
|
case "injected":
|
|
4584
|
-
this.provider = yield InjectedProvider
|
|
4603
|
+
this.provider = yield InjectedProvider.fromStorage(this.dappSettings.storage);
|
|
4585
4604
|
break;
|
|
4586
4605
|
default:
|
|
4587
4606
|
if (embeddedWallet) {
|
|
@@ -4595,21 +4614,21 @@ let TonConnect$1 = class TonConnect2 {
|
|
|
4595
4614
|
});
|
|
4596
4615
|
}
|
|
4597
4616
|
sendTransaction(transaction) {
|
|
4598
|
-
return __awaiter
|
|
4617
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4599
4618
|
this.checkConnection();
|
|
4600
4619
|
this.checkFeatureSupport("SendTransaction");
|
|
4601
|
-
const { validUntil } = transaction, tx = __rest
|
|
4602
|
-
const response = yield this.provider.sendRequest(sendTransactionParser
|
|
4603
|
-
if (sendTransactionParser
|
|
4604
|
-
return sendTransactionParser
|
|
4620
|
+
const { validUntil } = transaction, tx = __rest(transaction, ["validUntil"]);
|
|
4621
|
+
const response = yield this.provider.sendRequest(sendTransactionParser.convertToRpcRequest(Object.assign(Object.assign({}, tx), { valid_until: validUntil })));
|
|
4622
|
+
if (sendTransactionParser.isError(response)) {
|
|
4623
|
+
return sendTransactionParser.parseAndThrowError(response);
|
|
4605
4624
|
}
|
|
4606
|
-
return sendTransactionParser
|
|
4625
|
+
return sendTransactionParser.convertFromRpcResponse(response);
|
|
4607
4626
|
});
|
|
4608
4627
|
}
|
|
4609
4628
|
disconnect() {
|
|
4610
|
-
return __awaiter
|
|
4629
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4611
4630
|
if (!this.connected) {
|
|
4612
|
-
throw new WalletNotConnectedError
|
|
4631
|
+
throw new WalletNotConnectedError();
|
|
4613
4632
|
}
|
|
4614
4633
|
yield this.provider.disconnect();
|
|
4615
4634
|
this.onWalletDisconnected();
|
|
@@ -4617,10 +4636,10 @@ let TonConnect$1 = class TonConnect2 {
|
|
|
4617
4636
|
}
|
|
4618
4637
|
createProvider(wallet) {
|
|
4619
4638
|
let provider;
|
|
4620
|
-
if (isWalletConnectionSourceJS
|
|
4621
|
-
provider = new InjectedProvider
|
|
4639
|
+
if (isWalletConnectionSourceJS(wallet)) {
|
|
4640
|
+
provider = new InjectedProvider(wallet.jsBridgeKey);
|
|
4622
4641
|
} else {
|
|
4623
|
-
provider = new BridgeProvider
|
|
4642
|
+
provider = new BridgeProvider(this.dappSettings.storage, wallet);
|
|
4624
4643
|
}
|
|
4625
4644
|
provider.listen(this.walletEventsListener.bind(this));
|
|
4626
4645
|
return provider;
|
|
@@ -4660,7 +4679,7 @@ let TonConnect$1 = class TonConnect2 {
|
|
|
4660
4679
|
this.wallet = wallet;
|
|
4661
4680
|
}
|
|
4662
4681
|
onWalletConnectError(connectEventError) {
|
|
4663
|
-
const error = connectErrorsParser
|
|
4682
|
+
const error = connectErrorsParser.parseError(connectEventError);
|
|
4664
4683
|
this.statusChangeErrorSubscriptions.forEach((errorsHandler) => errorsHandler(error));
|
|
4665
4684
|
console.debug(error);
|
|
4666
4685
|
if (error instanceof ManifestNotFoundError$1 || error instanceof ManifestContentErrorError$1) {
|
|
@@ -4673,13 +4692,13 @@ let TonConnect$1 = class TonConnect2 {
|
|
|
4673
4692
|
}
|
|
4674
4693
|
checkConnection() {
|
|
4675
4694
|
if (!this.connected) {
|
|
4676
|
-
throw new WalletNotConnectedError
|
|
4695
|
+
throw new WalletNotConnectedError();
|
|
4677
4696
|
}
|
|
4678
4697
|
}
|
|
4679
4698
|
checkFeatureSupport(feature) {
|
|
4680
|
-
var
|
|
4681
|
-
if (!((
|
|
4682
|
-
throw new WalletNotSupportFeatureError
|
|
4699
|
+
var _a;
|
|
4700
|
+
if (!((_a = this.wallet) === null || _a === void 0 ? void 0 : _a.device.features.includes(feature))) {
|
|
4701
|
+
throw new WalletNotSupportFeatureError();
|
|
4683
4702
|
}
|
|
4684
4703
|
}
|
|
4685
4704
|
createConnectRequest(request) {
|
|
@@ -4699,10 +4718,8 @@ let TonConnect$1 = class TonConnect2 {
|
|
|
4699
4718
|
items
|
|
4700
4719
|
};
|
|
4701
4720
|
}
|
|
4702
|
-
}
|
|
4703
|
-
|
|
4704
|
-
TonConnect$1.walletsList = new WalletsListManager$1();
|
|
4705
|
-
TonConnect$1.getWallets = _a$1.walletsList.getWallets();
|
|
4721
|
+
}
|
|
4722
|
+
TonConnect.walletsList = new WalletsListManager();
|
|
4706
4723
|
function toUserFriendlyAddress$1(hexAddress) {
|
|
4707
4724
|
const { wc, hex } = parseHexAddress$1(hexAddress);
|
|
4708
4725
|
const bounceableTag = 17;
|
|
@@ -7170,17 +7187,17 @@ const TransitionGroup = (props) => {
|
|
|
7170
7187
|
};
|
|
7171
7188
|
function clickOutside$1(el, accessor) {
|
|
7172
7189
|
const onClick = (e2) => {
|
|
7173
|
-
var
|
|
7174
|
-
return !el.contains(e2.target) && ((
|
|
7190
|
+
var _a;
|
|
7191
|
+
return !el.contains(e2.target) && ((_a = accessor()) == null ? void 0 : _a());
|
|
7175
7192
|
};
|
|
7176
7193
|
document.body.addEventListener("click", onClick);
|
|
7177
7194
|
onCleanup(() => document.body.removeEventListener("click", onClick));
|
|
7178
7195
|
}
|
|
7179
7196
|
function escPressed(_, accessor) {
|
|
7180
7197
|
const onKeyPress = (e2) => {
|
|
7181
|
-
var
|
|
7198
|
+
var _a, _b;
|
|
7182
7199
|
if (e2.key === "Escape") {
|
|
7183
|
-
(
|
|
7200
|
+
(_a = document.activeElement) == null ? void 0 : _a.blur();
|
|
7184
7201
|
(_b = accessor()) == null ? void 0 : _b();
|
|
7185
7202
|
}
|
|
7186
7203
|
};
|
|
@@ -7485,8 +7502,8 @@ const H1 = (props) => {
|
|
|
7485
7502
|
return props.class;
|
|
7486
7503
|
},
|
|
7487
7504
|
get children() {
|
|
7488
|
-
var
|
|
7489
|
-
return memo(() => !!props.translationKey, true)() ? t2(props.translationKey, props.translationValues, (
|
|
7505
|
+
var _a;
|
|
7506
|
+
return memo(() => !!props.translationKey, true)() ? t2(props.translationKey, props.translationValues, (_a = props.children) == null ? void 0 : _a.toString()) : props.children;
|
|
7490
7507
|
}
|
|
7491
7508
|
});
|
|
7492
7509
|
};
|
|
@@ -7511,8 +7528,8 @@ const H2 = (props) => {
|
|
|
7511
7528
|
return props.class;
|
|
7512
7529
|
},
|
|
7513
7530
|
get children() {
|
|
7514
|
-
var
|
|
7515
|
-
return memo(() => !!props.translationKey, true)() ? t2(props.translationKey, props.translationValues, (
|
|
7531
|
+
var _a;
|
|
7532
|
+
return memo(() => !!props.translationKey, true)() ? t2(props.translationKey, props.translationValues, (_a = props.children) == null ? void 0 : _a.toString()) : props.children;
|
|
7516
7533
|
}
|
|
7517
7534
|
});
|
|
7518
7535
|
};
|
|
@@ -7533,8 +7550,8 @@ const H3 = (props) => {
|
|
|
7533
7550
|
const [t2] = useI18n();
|
|
7534
7551
|
return createComponent(H3Styled, {
|
|
7535
7552
|
get children() {
|
|
7536
|
-
var
|
|
7537
|
-
return memo(() => !!props.translationKey, true)() ? t2(props.translationKey, props.translationValues, (
|
|
7553
|
+
var _a;
|
|
7554
|
+
return memo(() => !!props.translationKey, true)() ? t2(props.translationKey, props.translationValues, (_a = props.children) == null ? void 0 : _a.toString()) : props.children;
|
|
7538
7555
|
}
|
|
7539
7556
|
});
|
|
7540
7557
|
};
|
|
@@ -7577,8 +7594,8 @@ const Text = (inputs) => {
|
|
|
7577
7594
|
return props.class;
|
|
7578
7595
|
},
|
|
7579
7596
|
get children() {
|
|
7580
|
-
var
|
|
7581
|
-
return memo(() => !!props.translationKey, true)() ? t2(props.translationKey, props.translationValues, (
|
|
7597
|
+
var _a;
|
|
7598
|
+
return memo(() => !!props.translationKey, true)() ? t2(props.translationKey, props.translationValues, (_a = props.children) == null ? void 0 : _a.toString()) : props.children;
|
|
7582
7599
|
}
|
|
7583
7600
|
});
|
|
7584
7601
|
};
|
|
@@ -8237,12 +8254,12 @@ function rectToClientRect(rect) {
|
|
|
8237
8254
|
bottom: rect.y + rect.height
|
|
8238
8255
|
});
|
|
8239
8256
|
}
|
|
8240
|
-
function getWindow
|
|
8257
|
+
function getWindow(node) {
|
|
8241
8258
|
var _node$ownerDocument;
|
|
8242
8259
|
return ((_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
|
|
8243
8260
|
}
|
|
8244
8261
|
function getComputedStyle(element) {
|
|
8245
|
-
return getWindow
|
|
8262
|
+
return getWindow(element).getComputedStyle(element);
|
|
8246
8263
|
}
|
|
8247
8264
|
function getNodeName(node) {
|
|
8248
8265
|
return isNode$2(node) ? (node.nodeName || "").toLowerCase() : "";
|
|
@@ -8260,19 +8277,19 @@ function getUAString() {
|
|
|
8260
8277
|
return navigator.userAgent;
|
|
8261
8278
|
}
|
|
8262
8279
|
function isHTMLElement(value) {
|
|
8263
|
-
return value instanceof getWindow
|
|
8280
|
+
return value instanceof getWindow(value).HTMLElement;
|
|
8264
8281
|
}
|
|
8265
8282
|
function isElement(value) {
|
|
8266
|
-
return value instanceof getWindow
|
|
8283
|
+
return value instanceof getWindow(value).Element;
|
|
8267
8284
|
}
|
|
8268
8285
|
function isNode$2(value) {
|
|
8269
|
-
return value instanceof getWindow
|
|
8286
|
+
return value instanceof getWindow(value).Node;
|
|
8270
8287
|
}
|
|
8271
8288
|
function isShadowRoot(node) {
|
|
8272
8289
|
if (typeof ShadowRoot === "undefined") {
|
|
8273
8290
|
return false;
|
|
8274
8291
|
}
|
|
8275
|
-
const OwnElement = getWindow
|
|
8292
|
+
const OwnElement = getWindow(node).ShadowRoot;
|
|
8276
8293
|
return node instanceof OwnElement || node instanceof ShadowRoot;
|
|
8277
8294
|
}
|
|
8278
8295
|
function isOverflowElement(element) {
|
|
@@ -8359,7 +8376,7 @@ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetPar
|
|
|
8359
8376
|
scale = getScale(element);
|
|
8360
8377
|
}
|
|
8361
8378
|
}
|
|
8362
|
-
const win = isElement(element) ? getWindow
|
|
8379
|
+
const win = isElement(element) ? getWindow(element) : window;
|
|
8363
8380
|
const addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
|
|
8364
8381
|
const x = (clientRect.left + (addVisualOffsets ? (_win$visualViewport$o = (_win$visualViewport = win.visualViewport) == null ? void 0 : _win$visualViewport.offsetLeft) != null ? _win$visualViewport$o : 0 : 0)) / scale.x;
|
|
8365
8382
|
const y = (clientRect.top + (addVisualOffsets ? (_win$visualViewport$o2 = (_win$visualViewport2 = win.visualViewport) == null ? void 0 : _win$visualViewport2.offsetTop) != null ? _win$visualViewport$o2 : 0 : 0)) / scale.y;
|
|
@@ -8450,7 +8467,7 @@ function getContainingBlock(element) {
|
|
|
8450
8467
|
return null;
|
|
8451
8468
|
}
|
|
8452
8469
|
function getOffsetParent(element) {
|
|
8453
|
-
const window2 = getWindow
|
|
8470
|
+
const window2 = getWindow(element);
|
|
8454
8471
|
let offsetParent = getTrueOffsetParent(element);
|
|
8455
8472
|
while (offsetParent && isTableElement(offsetParent) && getComputedStyle(offsetParent).position === "static") {
|
|
8456
8473
|
offsetParent = getTrueOffsetParent(offsetParent);
|
|
@@ -8515,7 +8532,7 @@ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
|
|
|
8515
8532
|
};
|
|
8516
8533
|
}
|
|
8517
8534
|
function getViewportRect(element, strategy) {
|
|
8518
|
-
const win = getWindow
|
|
8535
|
+
const win = getWindow(element);
|
|
8519
8536
|
const html = getDocumentElement(element);
|
|
8520
8537
|
const visualViewport = win.visualViewport;
|
|
8521
8538
|
let width = html.clientWidth;
|
|
@@ -8574,7 +8591,7 @@ function getOverflowAncestors(node, list) {
|
|
|
8574
8591
|
}
|
|
8575
8592
|
const scrollableAncestor = getNearestOverflowAncestor(node);
|
|
8576
8593
|
const isBody = scrollableAncestor === ((_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.body);
|
|
8577
|
-
const win = getWindow
|
|
8594
|
+
const win = getWindow(scrollableAncestor);
|
|
8578
8595
|
if (isBody) {
|
|
8579
8596
|
return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : []);
|
|
8580
8597
|
}
|
|
@@ -8944,8 +8961,8 @@ const AccountButton = () => {
|
|
|
8944
8961
|
}), null);
|
|
8945
8962
|
insert(_el$, createComponent(NotificationsStyled, {}), null);
|
|
8946
8963
|
createRenderEffect((_p$) => {
|
|
8947
|
-
var
|
|
8948
|
-
const _v$ = position.strategy, _v$2 = `${(
|
|
8964
|
+
var _a, _b;
|
|
8965
|
+
const _v$ = position.strategy, _v$2 = `${(_a = position.y) != null ? _a : 0}px`, _v$3 = `${(_b = position.x) != null ? _b : 0}px`;
|
|
8949
8966
|
_v$ !== _p$._v$ && _el$.style.setProperty("position", _p$._v$ = _v$);
|
|
8950
8967
|
_v$2 !== _p$._v$2 && _el$.style.setProperty("top", _p$._v$2 = _v$2);
|
|
8951
8968
|
_v$3 !== _p$._v$3 && _el$.style.setProperty("left", _p$._v$3 = _v$3);
|
|
@@ -10676,9 +10693,9 @@ const QRCode = (props) => {
|
|
|
10676
10693
|
});
|
|
10677
10694
|
};
|
|
10678
10695
|
const Translation = (props) => {
|
|
10679
|
-
var
|
|
10696
|
+
var _a;
|
|
10680
10697
|
const [t2] = useI18n();
|
|
10681
|
-
return t2(props.translationKey, props.translationValues, (
|
|
10698
|
+
return t2(props.translationKey, props.translationValues, (_a = props.children) == null ? void 0 : _a.toString());
|
|
10682
10699
|
};
|
|
10683
10700
|
const QrCodeModalStyled = styled.div`
|
|
10684
10701
|
padding: 0 24px;
|
|
@@ -10795,7 +10812,7 @@ const QrCodeModal = (props) => {
|
|
|
10795
10812
|
}
|
|
10796
10813
|
}), createComponent(Show, {
|
|
10797
10814
|
get when() {
|
|
10798
|
-
return isWalletInfoInjected
|
|
10815
|
+
return isWalletInfoInjected(props.wallet) && props.wallet.injected;
|
|
10799
10816
|
},
|
|
10800
10817
|
get children() {
|
|
10801
10818
|
return createComponent(ActionButtonStyled, {
|
|
@@ -10987,8 +11004,8 @@ const SelectWalletModal = (props) => {
|
|
|
10987
11004
|
};
|
|
10988
11005
|
const ModalWrapper = styled.div`
|
|
10989
11006
|
color: ${(props) => {
|
|
10990
|
-
var
|
|
10991
|
-
return ((
|
|
11007
|
+
var _a;
|
|
11008
|
+
return ((_a = props.theme) == null ? void 0 : _a.accentColor) || "blue";
|
|
10992
11009
|
}};
|
|
10993
11010
|
`;
|
|
10994
11011
|
const StyledModal = styled(Modal)`
|
|
@@ -11043,7 +11060,7 @@ const WalletsModal = () => {
|
|
|
11043
11060
|
if (isDevice("mobile") && "universalLink" in walletInfo) {
|
|
11044
11061
|
return onSelectIfMobile(walletInfo);
|
|
11045
11062
|
}
|
|
11046
|
-
if (isWalletInfoInjected
|
|
11063
|
+
if (isWalletInfoInjected(walletInfo) && walletInfo.injected) {
|
|
11047
11064
|
return onSelectIfInjected(walletInfo);
|
|
11048
11065
|
}
|
|
11049
11066
|
setSelectedWalletInfo(walletInfo);
|
|
@@ -11230,8 +11247,8 @@ const TransactionSentModal = (props) => {
|
|
|
11230
11247
|
const ActionsModal = () => {
|
|
11231
11248
|
return createComponent(Modal, {
|
|
11232
11249
|
get opened() {
|
|
11233
|
-
var
|
|
11234
|
-
return memo(() => action() !== null, true)() && ((
|
|
11250
|
+
var _a;
|
|
11251
|
+
return memo(() => action() !== null, true)() && ((_a = action()) == null ? void 0 : _a.openModal) === true;
|
|
11235
11252
|
},
|
|
11236
11253
|
onClose: () => setAction(null),
|
|
11237
11254
|
get children() {
|
|
@@ -11483,7 +11500,7 @@ function mergeOptions(options, defaultOptions) {
|
|
|
11483
11500
|
isMergeableObject: isPlainObject
|
|
11484
11501
|
});
|
|
11485
11502
|
}
|
|
11486
|
-
class
|
|
11503
|
+
class TonConnectUI {
|
|
11487
11504
|
constructor(options) {
|
|
11488
11505
|
__publicField(this, "walletInfoStorage", new WalletInfoStorage());
|
|
11489
11506
|
__publicField(this, "connector");
|
|
@@ -11492,7 +11509,7 @@ class TonConnectUi {
|
|
|
11492
11509
|
if (options && "connector" in options && options.connector) {
|
|
11493
11510
|
this.connector = options.connector;
|
|
11494
11511
|
} else if (options && "manifestUrl" in options && options.manifestUrl) {
|
|
11495
|
-
this.connector = new TonConnect
|
|
11512
|
+
this.connector = new TonConnect({ manifestUrl: options.manifestUrl });
|
|
11496
11513
|
} else {
|
|
11497
11514
|
throw new TonConnectUIError(
|
|
11498
11515
|
"You have to specify a `manifestUrl` or a `connector` in the options."
|
|
@@ -11508,6 +11525,9 @@ class TonConnectUi {
|
|
|
11508
11525
|
setAppState({ connector: this.connector });
|
|
11509
11526
|
widgetController.renderApp(rootId, this);
|
|
11510
11527
|
}
|
|
11528
|
+
static getWallets() {
|
|
11529
|
+
return TonConnect.getWallets();
|
|
11530
|
+
}
|
|
11511
11531
|
get connected() {
|
|
11512
11532
|
return this.connector.connected;
|
|
11513
11533
|
}
|
|
@@ -11521,7 +11541,7 @@ class TonConnectUi {
|
|
|
11521
11541
|
return this._walletInfo;
|
|
11522
11542
|
}
|
|
11523
11543
|
set uiOptions(options) {
|
|
11524
|
-
var
|
|
11544
|
+
var _a;
|
|
11525
11545
|
this.checkButtonRootExist(options.buttonRootId);
|
|
11526
11546
|
if (options.theme === "SYSTEM") {
|
|
11527
11547
|
setTheme(getSystemTheme());
|
|
@@ -11532,7 +11552,7 @@ class TonConnectUi {
|
|
|
11532
11552
|
}
|
|
11533
11553
|
} else {
|
|
11534
11554
|
if (options.theme) {
|
|
11535
|
-
(
|
|
11555
|
+
(_a = this.systemThemeChangeUnsubscribe) == null ? void 0 : _a.call(this);
|
|
11536
11556
|
setTheme(options.theme);
|
|
11537
11557
|
}
|
|
11538
11558
|
}
|
|
@@ -11670,13 +11690,13 @@ class TonConnectUi {
|
|
|
11670
11690
|
}
|
|
11671
11691
|
}
|
|
11672
11692
|
const TonConnectUIContext = createContext$1(null);
|
|
11673
|
-
const TonConnectUIProvider = (
|
|
11674
|
-
var _b =
|
|
11693
|
+
const TonConnectUIProvider = (_a) => {
|
|
11694
|
+
var _b = _a, {
|
|
11675
11695
|
children: children2
|
|
11676
11696
|
} = _b, options = __objRest(_b, [
|
|
11677
11697
|
"children"
|
|
11678
11698
|
]);
|
|
11679
|
-
const tonConnectUI = new
|
|
11699
|
+
const tonConnectUI = new TonConnectUI(options);
|
|
11680
11700
|
return /* @__PURE__ */ jsx(TonConnectUIContext.Provider, { value: tonConnectUI, children: children2 });
|
|
11681
11701
|
};
|
|
11682
11702
|
const TonConnectUIProvider$1 = memo$1(TonConnectUIProvider);
|
|
@@ -11717,10 +11737,15 @@ const TonConnectButton = ({ className: className2, style: style2 }) => {
|
|
|
11717
11737
|
const TonConnectButton$1 = memo$1(TonConnectButton);
|
|
11718
11738
|
function useTonWallet() {
|
|
11719
11739
|
const [tonConnectUI] = useTonConnectUI();
|
|
11720
|
-
const [wallet, setWallet] = useState(
|
|
11721
|
-
|
|
11722
|
-
|
|
11723
|
-
|
|
11740
|
+
const [wallet, setWallet] = useState(
|
|
11741
|
+
() => tonConnectUI.wallet && __spreadValues2(__spreadValues2({}, tonConnectUI.wallet), tonConnectUI.walletInfo)
|
|
11742
|
+
);
|
|
11743
|
+
useEffect(
|
|
11744
|
+
() => tonConnectUI.onStatusChange((value) => {
|
|
11745
|
+
setWallet(value);
|
|
11746
|
+
}),
|
|
11747
|
+
[tonConnectUI]
|
|
11748
|
+
);
|
|
11724
11749
|
return wallet;
|
|
11725
11750
|
}
|
|
11726
11751
|
class TonConnectError extends Error {
|
|
@@ -11733,12 +11758,6 @@ class TonConnectError extends Error {
|
|
|
11733
11758
|
}
|
|
11734
11759
|
}
|
|
11735
11760
|
TonConnectError.prefix = "[TON_CONNECT_SDK_ERROR]";
|
|
11736
|
-
class DappMetadataError extends TonConnectError {
|
|
11737
|
-
constructor(...args) {
|
|
11738
|
-
super(...args);
|
|
11739
|
-
Object.setPrototypeOf(this, DappMetadataError.prototype);
|
|
11740
|
-
}
|
|
11741
|
-
}
|
|
11742
11761
|
class ManifestContentErrorError extends TonConnectError {
|
|
11743
11762
|
constructor(message) {
|
|
11744
11763
|
super(message || "" + ManifestContentErrorError.additionalMessage);
|
|
@@ -11753,27 +11772,6 @@ class ManifestNotFoundError extends TonConnectError {
|
|
|
11753
11772
|
}
|
|
11754
11773
|
}
|
|
11755
11774
|
ManifestNotFoundError.additionalMessage = "\nManifest not found. Make sure you added `tonconnect-manifest.json` to the root of your app or passed correct manifestUrl. See more https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest";
|
|
11756
|
-
class WalletAlreadyConnectedError extends TonConnectError {
|
|
11757
|
-
constructor(...args) {
|
|
11758
|
-
super(...args);
|
|
11759
|
-
Object.setPrototypeOf(this, WalletAlreadyConnectedError.prototype);
|
|
11760
|
-
}
|
|
11761
|
-
}
|
|
11762
|
-
class WalletNotConnectedError extends TonConnectError {
|
|
11763
|
-
constructor(...args) {
|
|
11764
|
-
super(...args);
|
|
11765
|
-
Object.setPrototypeOf(this, WalletNotConnectedError.prototype);
|
|
11766
|
-
}
|
|
11767
|
-
}
|
|
11768
|
-
class WalletNotSupportFeatureError extends TonConnectError {
|
|
11769
|
-
constructor(...args) {
|
|
11770
|
-
super(...args);
|
|
11771
|
-
Object.setPrototypeOf(this, WalletNotSupportFeatureError.prototype);
|
|
11772
|
-
}
|
|
11773
|
-
}
|
|
11774
|
-
function isWalletConnectionSourceJS(value) {
|
|
11775
|
-
return "jsBridgeKey" in value;
|
|
11776
|
-
}
|
|
11777
11775
|
class UserRejectsError extends TonConnectError {
|
|
11778
11776
|
constructor(...args) {
|
|
11779
11777
|
super(...args);
|
|
@@ -11792,24 +11790,6 @@ class UnknownAppError extends TonConnectError {
|
|
|
11792
11790
|
Object.setPrototypeOf(this, UnknownAppError.prototype);
|
|
11793
11791
|
}
|
|
11794
11792
|
}
|
|
11795
|
-
class WalletNotInjectedError extends TonConnectError {
|
|
11796
|
-
constructor(...args) {
|
|
11797
|
-
super(...args);
|
|
11798
|
-
Object.setPrototypeOf(this, WalletNotInjectedError.prototype);
|
|
11799
|
-
}
|
|
11800
|
-
}
|
|
11801
|
-
class LocalstorageNotFoundError extends TonConnectError {
|
|
11802
|
-
constructor(...args) {
|
|
11803
|
-
super(...args);
|
|
11804
|
-
Object.setPrototypeOf(this, LocalstorageNotFoundError.prototype);
|
|
11805
|
-
}
|
|
11806
|
-
}
|
|
11807
|
-
class FetchWalletsError extends TonConnectError {
|
|
11808
|
-
constructor(...args) {
|
|
11809
|
-
super(...args);
|
|
11810
|
-
Object.setPrototypeOf(this, FetchWalletsError.prototype);
|
|
11811
|
-
}
|
|
11812
|
-
}
|
|
11813
11793
|
class WrongAddressError extends TonConnectError {
|
|
11814
11794
|
constructor(...args) {
|
|
11815
11795
|
super(...args);
|
|
@@ -11924,9 +11904,9 @@ var naclUtil = { exports: {} };
|
|
|
11924
11904
|
return util;
|
|
11925
11905
|
});
|
|
11926
11906
|
})(naclUtil);
|
|
11927
|
-
const nacl
|
|
11907
|
+
const nacl = naclUtil.exports;
|
|
11928
11908
|
function encodeUint8Array(value, urlSafe) {
|
|
11929
|
-
const encoded = nacl
|
|
11909
|
+
const encoded = nacl.encodeBase64(value);
|
|
11930
11910
|
if (!urlSafe) {
|
|
11931
11911
|
return encoded;
|
|
11932
11912
|
}
|
|
@@ -11936,7 +11916,7 @@ function decodeToUint8Array(value, urlSafe) {
|
|
|
11936
11916
|
if (urlSafe) {
|
|
11937
11917
|
value = decodeURIComponent(value);
|
|
11938
11918
|
}
|
|
11939
|
-
return nacl
|
|
11919
|
+
return nacl.decodeBase64(value);
|
|
11940
11920
|
}
|
|
11941
11921
|
function encode(value, urlSafe = false) {
|
|
11942
11922
|
let uint8Array;
|
|
@@ -11946,7 +11926,7 @@ function encode(value, urlSafe = false) {
|
|
|
11946
11926
|
if (typeof value !== "string") {
|
|
11947
11927
|
value = JSON.stringify(value);
|
|
11948
11928
|
}
|
|
11949
|
-
uint8Array = nacl
|
|
11929
|
+
uint8Array = nacl.decodeUTF8(value);
|
|
11950
11930
|
}
|
|
11951
11931
|
return encodeUint8Array(uint8Array, urlSafe);
|
|
11952
11932
|
}
|
|
@@ -11954,11 +11934,11 @@ function decode(value, urlSafe = false) {
|
|
|
11954
11934
|
const decodedUint8Array = decodeToUint8Array(value, urlSafe);
|
|
11955
11935
|
return {
|
|
11956
11936
|
toString() {
|
|
11957
|
-
return nacl
|
|
11937
|
+
return nacl.encodeUTF8(decodedUint8Array);
|
|
11958
11938
|
},
|
|
11959
11939
|
toObject() {
|
|
11960
11940
|
try {
|
|
11961
|
-
return JSON.parse(nacl
|
|
11941
|
+
return JSON.parse(nacl.encodeUTF8(decodedUint8Array));
|
|
11962
11942
|
} catch (e2) {
|
|
11963
11943
|
return null;
|
|
11964
11944
|
}
|
|
@@ -11972,37 +11952,6 @@ const Base64 = {
|
|
|
11972
11952
|
encode,
|
|
11973
11953
|
decode
|
|
11974
11954
|
};
|
|
11975
|
-
function concatUint8Arrays(buffer1, buffer2) {
|
|
11976
|
-
const mergedArray = new Uint8Array(buffer1.length + buffer2.length);
|
|
11977
|
-
mergedArray.set(buffer1);
|
|
11978
|
-
mergedArray.set(buffer2, buffer1.length);
|
|
11979
|
-
return mergedArray;
|
|
11980
|
-
}
|
|
11981
|
-
function splitToUint8Arrays(array, index) {
|
|
11982
|
-
if (index >= array.length) {
|
|
11983
|
-
throw new Error("Index is out of buffer");
|
|
11984
|
-
}
|
|
11985
|
-
const subArray1 = array.slice(0, index);
|
|
11986
|
-
const subArray2 = array.slice(index);
|
|
11987
|
-
return [subArray1, subArray2];
|
|
11988
|
-
}
|
|
11989
|
-
function toHexString(byteArray) {
|
|
11990
|
-
let hexString = "";
|
|
11991
|
-
byteArray.forEach((byte) => {
|
|
11992
|
-
hexString += ("0" + (byte & 255).toString(16)).slice(-2);
|
|
11993
|
-
});
|
|
11994
|
-
return hexString;
|
|
11995
|
-
}
|
|
11996
|
-
function hexToByteArray(hexString) {
|
|
11997
|
-
if (hexString.length % 2 !== 0) {
|
|
11998
|
-
throw new Error(`Cannot convert ${hexString} to bytesArray`);
|
|
11999
|
-
}
|
|
12000
|
-
const result = new Uint8Array(hexString.length / 2);
|
|
12001
|
-
for (let i2 = 0; i2 < hexString.length; i2 += 2) {
|
|
12002
|
-
result[i2 / 2] = parseInt(hexString.slice(i2, i2 + 2), 16);
|
|
12003
|
-
}
|
|
12004
|
-
return result;
|
|
12005
|
-
}
|
|
12006
11955
|
function isNode() {
|
|
12007
11956
|
return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
12008
11957
|
}
|
|
@@ -14312,104 +14261,27 @@ const require$$0 = /* @__PURE__ */ getAugmentedNamespace$1(__viteBrowserExternal
|
|
|
14312
14261
|
})();
|
|
14313
14262
|
})(module.exports ? module.exports : self.nacl = self.nacl || {});
|
|
14314
14263
|
})(naclFast);
|
|
14315
|
-
const nacl = naclFast.exports;
|
|
14316
14264
|
if (isNode()) {
|
|
14317
14265
|
try {
|
|
14318
14266
|
eval("global.crypto = require('crypto').webcrypto");
|
|
14319
14267
|
} catch (err) {
|
|
14320
14268
|
}
|
|
14321
14269
|
}
|
|
14322
|
-
|
|
14323
|
-
constructor(keyPair) {
|
|
14324
|
-
this.nonceLength = 24;
|
|
14325
|
-
this.keyPair = keyPair ? this.createKeypairFromString(keyPair) : this.createKeypair();
|
|
14326
|
-
this.sessionId = toHexString(this.keyPair.publicKey);
|
|
14327
|
-
}
|
|
14328
|
-
createKeypair() {
|
|
14329
|
-
return nacl.box.keyPair();
|
|
14330
|
-
}
|
|
14331
|
-
createKeypairFromString(keyPair) {
|
|
14332
|
-
return {
|
|
14333
|
-
publicKey: hexToByteArray(keyPair.publicKey),
|
|
14334
|
-
secretKey: hexToByteArray(keyPair.secretKey)
|
|
14335
|
-
};
|
|
14336
|
-
}
|
|
14337
|
-
createNonce() {
|
|
14338
|
-
const buffer = new Uint8Array(this.nonceLength);
|
|
14339
|
-
return crypto.getRandomValues(buffer);
|
|
14340
|
-
}
|
|
14341
|
-
encrypt(message, receiverPublicKey) {
|
|
14342
|
-
const encodedMessage = new TextEncoder().encode(message);
|
|
14343
|
-
const nonce = this.createNonce();
|
|
14344
|
-
const encrypted = nacl.box(encodedMessage, nonce, receiverPublicKey, this.keyPair.secretKey);
|
|
14345
|
-
return concatUint8Arrays(nonce, encrypted);
|
|
14346
|
-
}
|
|
14347
|
-
decrypt(message, senderPublicKey) {
|
|
14348
|
-
const [nonce, internalMessage] = splitToUint8Arrays(message, this.nonceLength);
|
|
14349
|
-
const decrypted = nacl.box.open(internalMessage, nonce, senderPublicKey, this.keyPair.secretKey);
|
|
14350
|
-
if (!decrypted) {
|
|
14351
|
-
throw new Error("Decryption error");
|
|
14352
|
-
}
|
|
14353
|
-
return new TextDecoder().decode(decrypted);
|
|
14354
|
-
}
|
|
14355
|
-
stringifyKeypair() {
|
|
14356
|
-
return {
|
|
14357
|
-
publicKey: toHexString(this.keyPair.publicKey),
|
|
14358
|
-
secretKey: toHexString(this.keyPair.secretKey)
|
|
14359
|
-
};
|
|
14360
|
-
}
|
|
14361
|
-
}
|
|
14362
|
-
const connectEventErrorsCodes = {
|
|
14270
|
+
({
|
|
14363
14271
|
[CONNECT_EVENT_ERROR_CODES.UNKNOWN_ERROR]: UnknownError,
|
|
14364
14272
|
[CONNECT_EVENT_ERROR_CODES.USER_REJECTS_ERROR]: UserRejectsError,
|
|
14365
14273
|
[CONNECT_EVENT_ERROR_CODES.BAD_REQUEST_ERROR]: BadRequestError,
|
|
14366
14274
|
[CONNECT_EVENT_ERROR_CODES.UNKNOWN_APP_ERROR]: UnknownAppError,
|
|
14367
14275
|
[CONNECT_EVENT_ERROR_CODES.MANIFEST_NOT_FOUND_ERROR]: ManifestNotFoundError,
|
|
14368
14276
|
[CONNECT_EVENT_ERROR_CODES.MANIFEST_CONTENT_ERROR]: ManifestContentErrorError
|
|
14369
|
-
};
|
|
14370
|
-
|
|
14371
|
-
parseError(error) {
|
|
14372
|
-
let ErrorConstructor = UnknownError;
|
|
14373
|
-
if (error.code in connectEventErrorsCodes) {
|
|
14374
|
-
ErrorConstructor = connectEventErrorsCodes[error.code] || UnknownError;
|
|
14375
|
-
}
|
|
14376
|
-
return new ErrorConstructor(error.message);
|
|
14377
|
-
}
|
|
14378
|
-
}
|
|
14379
|
-
const connectErrorsParser = new ConnectErrorsParser();
|
|
14380
|
-
class RpcParser {
|
|
14381
|
-
isError(response) {
|
|
14382
|
-
return "error" in response;
|
|
14383
|
-
}
|
|
14384
|
-
}
|
|
14385
|
-
const sendTransactionErrors = {
|
|
14277
|
+
});
|
|
14278
|
+
({
|
|
14386
14279
|
[SEND_TRANSACTION_ERROR_CODES.UNKNOWN_ERROR]: UnknownError,
|
|
14387
14280
|
[SEND_TRANSACTION_ERROR_CODES.USER_REJECTS_ERROR]: UserRejectsError,
|
|
14388
14281
|
[SEND_TRANSACTION_ERROR_CODES.BAD_REQUEST_ERROR]: BadRequestError,
|
|
14389
14282
|
[SEND_TRANSACTION_ERROR_CODES.UNKNOWN_APP_ERROR]: UnknownAppError
|
|
14390
|
-
};
|
|
14391
|
-
|
|
14392
|
-
convertToRpcRequest(request) {
|
|
14393
|
-
return {
|
|
14394
|
-
method: "sendTransaction",
|
|
14395
|
-
params: [JSON.stringify(request)]
|
|
14396
|
-
};
|
|
14397
|
-
}
|
|
14398
|
-
parseAndThrowError(response) {
|
|
14399
|
-
let ErrorConstructor = UnknownError;
|
|
14400
|
-
if (response.error.code in sendTransactionErrors) {
|
|
14401
|
-
ErrorConstructor = sendTransactionErrors[response.error.code] || UnknownError;
|
|
14402
|
-
}
|
|
14403
|
-
throw new ErrorConstructor(response.error.message);
|
|
14404
|
-
}
|
|
14405
|
-
convertFromRpcResponse(rpcResponse) {
|
|
14406
|
-
return {
|
|
14407
|
-
boc: rpcResponse.result
|
|
14408
|
-
};
|
|
14409
|
-
}
|
|
14410
|
-
}
|
|
14411
|
-
const sendTransactionParser = new SendTransactionParser();
|
|
14412
|
-
var __awaiter$7 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
14283
|
+
});
|
|
14284
|
+
globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
14413
14285
|
function adopt(value) {
|
|
14414
14286
|
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
14415
14287
|
resolve(value);
|
|
@@ -14436,41 +14308,7 @@ var __awaiter$7 = globalThis && globalThis.__awaiter || function(thisArg, _argum
|
|
|
14436
14308
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14437
14309
|
});
|
|
14438
14310
|
};
|
|
14439
|
-
|
|
14440
|
-
constructor(storage) {
|
|
14441
|
-
this.storage = storage;
|
|
14442
|
-
this.storeKey = "ton-connect-storage_http-bridge-gateway";
|
|
14443
|
-
}
|
|
14444
|
-
storeLastEventId(lastEventId) {
|
|
14445
|
-
return __awaiter$7(this, void 0, void 0, function* () {
|
|
14446
|
-
return this.storage.setItem(this.storeKey, lastEventId);
|
|
14447
|
-
});
|
|
14448
|
-
}
|
|
14449
|
-
removeLastEventId() {
|
|
14450
|
-
return __awaiter$7(this, void 0, void 0, function* () {
|
|
14451
|
-
return this.storage.removeItem(this.storeKey);
|
|
14452
|
-
});
|
|
14453
|
-
}
|
|
14454
|
-
getLastEventId() {
|
|
14455
|
-
return __awaiter$7(this, void 0, void 0, function* () {
|
|
14456
|
-
const stored = yield this.storage.getItem(this.storeKey);
|
|
14457
|
-
if (!stored) {
|
|
14458
|
-
return null;
|
|
14459
|
-
}
|
|
14460
|
-
return stored;
|
|
14461
|
-
});
|
|
14462
|
-
}
|
|
14463
|
-
}
|
|
14464
|
-
function removeUrlLastSlash(url) {
|
|
14465
|
-
if (url.slice(-1) === "/") {
|
|
14466
|
-
return url.slice(0, -1);
|
|
14467
|
-
}
|
|
14468
|
-
return url;
|
|
14469
|
-
}
|
|
14470
|
-
function addPathToUrl(url, path) {
|
|
14471
|
-
return removeUrlLastSlash(url) + "/" + path;
|
|
14472
|
-
}
|
|
14473
|
-
var __awaiter$6 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
14311
|
+
globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
14474
14312
|
function adopt(value) {
|
|
14475
14313
|
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
14476
14314
|
resolve(value);
|
|
@@ -14505,89 +14343,88 @@ if (isNode()) {
|
|
|
14505
14343
|
console.error(err);
|
|
14506
14344
|
}
|
|
14507
14345
|
}
|
|
14508
|
-
|
|
14509
|
-
|
|
14510
|
-
|
|
14511
|
-
|
|
14512
|
-
this.listener = listener;
|
|
14513
|
-
this.errorsListener = errorsListener;
|
|
14514
|
-
this.ssePath = "events";
|
|
14515
|
-
this.postPath = "message";
|
|
14516
|
-
this.heartbeatMessage = "heartbeat";
|
|
14517
|
-
this.defaultTtl = 300;
|
|
14518
|
-
this.isClosed = false;
|
|
14519
|
-
this.bridgeGatewayStorage = new HttpBridgeGatewayStorage(storage);
|
|
14520
|
-
}
|
|
14521
|
-
registerSession() {
|
|
14522
|
-
return __awaiter$6(this, void 0, void 0, function* () {
|
|
14523
|
-
const url = new URL(addPathToUrl(this.bridgeUrl, this.ssePath));
|
|
14524
|
-
url.searchParams.append("client_id", this.sessionId);
|
|
14525
|
-
const lastEventId = yield this.bridgeGatewayStorage.getLastEventId();
|
|
14526
|
-
if (lastEventId) {
|
|
14527
|
-
url.searchParams.append("last_event_id", lastEventId);
|
|
14528
|
-
}
|
|
14529
|
-
this.eventSource = new EventSource(url.toString());
|
|
14530
|
-
return new Promise((resolve, reject) => {
|
|
14531
|
-
this.eventSource.onerror = reject;
|
|
14532
|
-
this.eventSource.onopen = () => {
|
|
14533
|
-
this.eventSource.onerror = this.errorsHandler.bind(this);
|
|
14534
|
-
this.eventSource.onmessage = this.messagesHandler.bind(this);
|
|
14535
|
-
resolve();
|
|
14536
|
-
};
|
|
14537
|
-
});
|
|
14538
|
-
});
|
|
14539
|
-
}
|
|
14540
|
-
send(message, receiver, ttl) {
|
|
14541
|
-
return __awaiter$6(this, void 0, void 0, function* () {
|
|
14542
|
-
const url = new URL(addPathToUrl(this.bridgeUrl, this.postPath));
|
|
14543
|
-
url.searchParams.append("client_id", this.sessionId);
|
|
14544
|
-
url.searchParams.append("to", receiver);
|
|
14545
|
-
url.searchParams.append("ttl", (ttl || this.defaultTtl).toString());
|
|
14546
|
-
yield fetch(url, {
|
|
14547
|
-
method: "post",
|
|
14548
|
-
body: Base64.encode(message)
|
|
14549
|
-
});
|
|
14346
|
+
globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
14347
|
+
function adopt(value) {
|
|
14348
|
+
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
14349
|
+
resolve(value);
|
|
14550
14350
|
});
|
|
14551
14351
|
}
|
|
14552
|
-
|
|
14553
|
-
|
|
14554
|
-
|
|
14555
|
-
|
|
14556
|
-
|
|
14557
|
-
|
|
14558
|
-
var _a2, _b;
|
|
14559
|
-
if (!this.isClosed) {
|
|
14560
|
-
if (((_a2 = this.eventSource) === null || _a2 === void 0 ? void 0 : _a2.readyState) === EventSource.CLOSED) {
|
|
14561
|
-
this.eventSource.close();
|
|
14562
|
-
this.registerSession();
|
|
14563
|
-
return;
|
|
14352
|
+
return new (P2 || (P2 = Promise))(function(resolve, reject) {
|
|
14353
|
+
function fulfilled(value) {
|
|
14354
|
+
try {
|
|
14355
|
+
step(generator.next(value));
|
|
14356
|
+
} catch (e2) {
|
|
14357
|
+
reject(e2);
|
|
14564
14358
|
}
|
|
14565
|
-
|
|
14566
|
-
|
|
14567
|
-
|
|
14359
|
+
}
|
|
14360
|
+
function rejected(value) {
|
|
14361
|
+
try {
|
|
14362
|
+
step(generator["throw"](value));
|
|
14363
|
+
} catch (e2) {
|
|
14364
|
+
reject(e2);
|
|
14568
14365
|
}
|
|
14569
|
-
this.errorsListener(e2);
|
|
14570
14366
|
}
|
|
14367
|
+
function step(result) {
|
|
14368
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
14369
|
+
}
|
|
14370
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14371
|
+
});
|
|
14372
|
+
};
|
|
14373
|
+
globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
14374
|
+
function adopt(value) {
|
|
14375
|
+
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
14376
|
+
resolve(value);
|
|
14377
|
+
});
|
|
14571
14378
|
}
|
|
14572
|
-
|
|
14573
|
-
|
|
14574
|
-
|
|
14575
|
-
|
|
14379
|
+
return new (P2 || (P2 = Promise))(function(resolve, reject) {
|
|
14380
|
+
function fulfilled(value) {
|
|
14381
|
+
try {
|
|
14382
|
+
step(generator.next(value));
|
|
14383
|
+
} catch (e2) {
|
|
14384
|
+
reject(e2);
|
|
14576
14385
|
}
|
|
14577
|
-
|
|
14578
|
-
|
|
14579
|
-
|
|
14580
|
-
|
|
14581
|
-
|
|
14582
|
-
|
|
14583
|
-
throw new TonConnectError(`Bridge message parse failed, message ${e3.data}`);
|
|
14584
|
-
}
|
|
14585
|
-
this.listener(bridgeIncomingMessage);
|
|
14386
|
+
}
|
|
14387
|
+
function rejected(value) {
|
|
14388
|
+
try {
|
|
14389
|
+
step(generator["throw"](value));
|
|
14390
|
+
} catch (e2) {
|
|
14391
|
+
reject(e2);
|
|
14586
14392
|
}
|
|
14393
|
+
}
|
|
14394
|
+
function step(result) {
|
|
14395
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
14396
|
+
}
|
|
14397
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14398
|
+
});
|
|
14399
|
+
};
|
|
14400
|
+
globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
14401
|
+
function adopt(value) {
|
|
14402
|
+
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
14403
|
+
resolve(value);
|
|
14587
14404
|
});
|
|
14588
14405
|
}
|
|
14589
|
-
|
|
14590
|
-
|
|
14406
|
+
return new (P2 || (P2 = Promise))(function(resolve, reject) {
|
|
14407
|
+
function fulfilled(value) {
|
|
14408
|
+
try {
|
|
14409
|
+
step(generator.next(value));
|
|
14410
|
+
} catch (e2) {
|
|
14411
|
+
reject(e2);
|
|
14412
|
+
}
|
|
14413
|
+
}
|
|
14414
|
+
function rejected(value) {
|
|
14415
|
+
try {
|
|
14416
|
+
step(generator["throw"](value));
|
|
14417
|
+
} catch (e2) {
|
|
14418
|
+
reject(e2);
|
|
14419
|
+
}
|
|
14420
|
+
}
|
|
14421
|
+
function step(result) {
|
|
14422
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
14423
|
+
}
|
|
14424
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14425
|
+
});
|
|
14426
|
+
};
|
|
14427
|
+
globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
14591
14428
|
function adopt(value) {
|
|
14592
14429
|
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
14593
14430
|
resolve(value);
|
|
@@ -14614,97 +14451,11 @@ var __awaiter$5 = globalThis && globalThis.__awaiter || function(thisArg, _argum
|
|
|
14614
14451
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14615
14452
|
});
|
|
14616
14453
|
};
|
|
14617
|
-
|
|
14618
|
-
|
|
14619
|
-
|
|
14620
|
-
|
|
14621
|
-
|
|
14622
|
-
storeConnection(connection) {
|
|
14623
|
-
return __awaiter$5(this, void 0, void 0, function* () {
|
|
14624
|
-
if (connection.type === "injected") {
|
|
14625
|
-
return this.storage.setItem(this.storeKey, JSON.stringify(connection));
|
|
14626
|
-
}
|
|
14627
|
-
const rawSession = {
|
|
14628
|
-
sessionKeyPair: connection.session.sessionCrypto.stringifyKeypair(),
|
|
14629
|
-
walletPublicKey: connection.session.walletPublicKey,
|
|
14630
|
-
walletConnectionSource: connection.session.walletConnectionSource
|
|
14631
|
-
};
|
|
14632
|
-
const rawConnection = {
|
|
14633
|
-
type: "http",
|
|
14634
|
-
connectEvent: connection.connectEvent,
|
|
14635
|
-
session: rawSession
|
|
14636
|
-
};
|
|
14637
|
-
return this.storage.setItem(this.storeKey, JSON.stringify(rawConnection));
|
|
14638
|
-
});
|
|
14639
|
-
}
|
|
14640
|
-
removeConnection() {
|
|
14641
|
-
return __awaiter$5(this, void 0, void 0, function* () {
|
|
14642
|
-
return this.storage.removeItem(this.storeKey);
|
|
14643
|
-
});
|
|
14644
|
-
}
|
|
14645
|
-
getConnection() {
|
|
14646
|
-
return __awaiter$5(this, void 0, void 0, function* () {
|
|
14647
|
-
const stored = yield this.storage.getItem(this.storeKey);
|
|
14648
|
-
if (!stored) {
|
|
14649
|
-
return null;
|
|
14650
|
-
}
|
|
14651
|
-
const connection = JSON.parse(stored);
|
|
14652
|
-
if (connection.type === "injected") {
|
|
14653
|
-
return connection;
|
|
14654
|
-
}
|
|
14655
|
-
const sessionCrypto = new SessionCrypto(connection.session.sessionKeyPair);
|
|
14656
|
-
return {
|
|
14657
|
-
type: "http",
|
|
14658
|
-
connectEvent: connection.connectEvent,
|
|
14659
|
-
session: {
|
|
14660
|
-
sessionCrypto,
|
|
14661
|
-
walletConnectionSource: connection.session.walletConnectionSource,
|
|
14662
|
-
walletPublicKey: connection.session.walletPublicKey
|
|
14663
|
-
}
|
|
14664
|
-
};
|
|
14665
|
-
});
|
|
14666
|
-
}
|
|
14667
|
-
getHttpConnection() {
|
|
14668
|
-
return __awaiter$5(this, void 0, void 0, function* () {
|
|
14669
|
-
const connection = yield this.getConnection();
|
|
14670
|
-
if (!connection) {
|
|
14671
|
-
throw new TonConnectError("Trying to read HTTP connection source while nothing is stored");
|
|
14672
|
-
}
|
|
14673
|
-
if (connection.type === "injected") {
|
|
14674
|
-
throw new TonConnectError("Trying to read HTTP connection source while injected connection is stored");
|
|
14675
|
-
}
|
|
14676
|
-
return connection;
|
|
14677
|
-
});
|
|
14678
|
-
}
|
|
14679
|
-
getInjectedConnection() {
|
|
14680
|
-
return __awaiter$5(this, void 0, void 0, function* () {
|
|
14681
|
-
const connection = yield this.getConnection();
|
|
14682
|
-
if (!connection) {
|
|
14683
|
-
throw new TonConnectError("Trying to read Injected bridge connection source while nothing is stored");
|
|
14684
|
-
}
|
|
14685
|
-
if ((connection === null || connection === void 0 ? void 0 : connection.type) === "http") {
|
|
14686
|
-
throw new TonConnectError("Trying to read Injected bridge connection source while HTTP connection is stored");
|
|
14687
|
-
}
|
|
14688
|
-
return connection;
|
|
14689
|
-
});
|
|
14690
|
-
}
|
|
14691
|
-
storedConnectionType() {
|
|
14692
|
-
return __awaiter$5(this, void 0, void 0, function* () {
|
|
14693
|
-
const stored = yield this.storage.getItem(this.storeKey);
|
|
14694
|
-
if (!stored) {
|
|
14695
|
-
return null;
|
|
14696
|
-
}
|
|
14697
|
-
const connection = JSON.parse(stored);
|
|
14698
|
-
return connection.type;
|
|
14699
|
-
});
|
|
14700
|
-
}
|
|
14701
|
-
}
|
|
14702
|
-
const PROTOCOL_VERSION = 2;
|
|
14703
|
-
var __awaiter$4 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
14704
|
-
function adopt(value) {
|
|
14705
|
-
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
14706
|
-
resolve(value);
|
|
14707
|
-
});
|
|
14454
|
+
globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
14455
|
+
function adopt(value) {
|
|
14456
|
+
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
14457
|
+
resolve(value);
|
|
14458
|
+
});
|
|
14708
14459
|
}
|
|
14709
14460
|
return new (P2 || (P2 = Promise))(function(resolve, reject) {
|
|
14710
14461
|
function fulfilled(value) {
|
|
@@ -14727,149 +14478,7 @@ var __awaiter$4 = globalThis && globalThis.__awaiter || function(thisArg, _argum
|
|
|
14727
14478
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14728
14479
|
});
|
|
14729
14480
|
};
|
|
14730
|
-
|
|
14731
|
-
constructor(storage, walletConnectionSource) {
|
|
14732
|
-
this.storage = storage;
|
|
14733
|
-
this.walletConnectionSource = walletConnectionSource;
|
|
14734
|
-
this.type = "http";
|
|
14735
|
-
this.pendingRequests = /* @__PURE__ */ new Map();
|
|
14736
|
-
this.nextRequestId = 0;
|
|
14737
|
-
this.session = null;
|
|
14738
|
-
this.bridge = null;
|
|
14739
|
-
this.listeners = [];
|
|
14740
|
-
this.connectionStorage = new BridgeConnectionStorage(storage);
|
|
14741
|
-
}
|
|
14742
|
-
static fromStorage(storage) {
|
|
14743
|
-
return __awaiter$4(this, void 0, void 0, function* () {
|
|
14744
|
-
const bridgeConnectionStorage = new BridgeConnectionStorage(storage);
|
|
14745
|
-
const connection = yield bridgeConnectionStorage.getHttpConnection();
|
|
14746
|
-
return new BridgeProvider(storage, connection.session.walletConnectionSource);
|
|
14747
|
-
});
|
|
14748
|
-
}
|
|
14749
|
-
connect(message) {
|
|
14750
|
-
var _a2;
|
|
14751
|
-
(_a2 = this.bridge) === null || _a2 === void 0 ? void 0 : _a2.close();
|
|
14752
|
-
const sessionCrypto = new SessionCrypto();
|
|
14753
|
-
this.session = {
|
|
14754
|
-
sessionCrypto,
|
|
14755
|
-
walletConnectionSource: this.walletConnectionSource
|
|
14756
|
-
};
|
|
14757
|
-
this.bridge = new BridgeGateway(this.storage, this.walletConnectionSource.bridgeUrl, sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this));
|
|
14758
|
-
this.bridge.registerSession();
|
|
14759
|
-
return this.generateUniversalLink(message);
|
|
14760
|
-
}
|
|
14761
|
-
restoreConnection() {
|
|
14762
|
-
var _a2;
|
|
14763
|
-
return __awaiter$4(this, void 0, void 0, function* () {
|
|
14764
|
-
(_a2 = this.bridge) === null || _a2 === void 0 ? void 0 : _a2.close();
|
|
14765
|
-
const storedConnection = yield this.connectionStorage.getHttpConnection();
|
|
14766
|
-
if (!storedConnection) {
|
|
14767
|
-
return;
|
|
14768
|
-
}
|
|
14769
|
-
this.session = storedConnection.session;
|
|
14770
|
-
this.bridge = new BridgeGateway(this.storage, this.walletConnectionSource.bridgeUrl, storedConnection.session.sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this));
|
|
14771
|
-
yield this.bridge.registerSession();
|
|
14772
|
-
this.listeners.forEach((listener) => listener(storedConnection.connectEvent));
|
|
14773
|
-
});
|
|
14774
|
-
}
|
|
14775
|
-
sendRequest(request) {
|
|
14776
|
-
return new Promise((resolve, reject) => {
|
|
14777
|
-
const id = this.nextRequestId;
|
|
14778
|
-
this.nextRequestId++;
|
|
14779
|
-
if (!this.bridge || !this.session || !("walletPublicKey" in this.session)) {
|
|
14780
|
-
throw new TonConnectError("Trying to send bridge request without session");
|
|
14781
|
-
}
|
|
14782
|
-
const encodedRequest = this.session.sessionCrypto.encrypt(JSON.stringify(Object.assign(Object.assign({}, request), { id })), hexToByteArray(this.session.walletPublicKey));
|
|
14783
|
-
this.bridge.send(encodedRequest, this.session.walletPublicKey).catch(reject);
|
|
14784
|
-
this.pendingRequests.set(id.toString(), resolve);
|
|
14785
|
-
});
|
|
14786
|
-
}
|
|
14787
|
-
closeConnection() {
|
|
14788
|
-
var _a2;
|
|
14789
|
-
(_a2 = this.bridge) === null || _a2 === void 0 ? void 0 : _a2.close();
|
|
14790
|
-
this.listeners = [];
|
|
14791
|
-
this.session = null;
|
|
14792
|
-
this.bridge = null;
|
|
14793
|
-
}
|
|
14794
|
-
disconnect() {
|
|
14795
|
-
var _a2;
|
|
14796
|
-
(_a2 = this.bridge) === null || _a2 === void 0 ? void 0 : _a2.close();
|
|
14797
|
-
this.listeners = [];
|
|
14798
|
-
return this.removeBridgeAndSession();
|
|
14799
|
-
}
|
|
14800
|
-
listen(callback) {
|
|
14801
|
-
this.listeners.push(callback);
|
|
14802
|
-
return () => this.listeners = this.listeners.filter((listener) => listener !== callback);
|
|
14803
|
-
}
|
|
14804
|
-
gatewayListener(bridgeIncomingMessage) {
|
|
14805
|
-
return __awaiter$4(this, void 0, void 0, function* () {
|
|
14806
|
-
const walletMessage = JSON.parse(this.session.sessionCrypto.decrypt(Base64.decode(bridgeIncomingMessage.message).toUint8Array(), hexToByteArray(bridgeIncomingMessage.from)));
|
|
14807
|
-
if (!("event" in walletMessage)) {
|
|
14808
|
-
const id = walletMessage.id.toString();
|
|
14809
|
-
const resolve = this.pendingRequests.get(id);
|
|
14810
|
-
if (!resolve) {
|
|
14811
|
-
throw new TonConnectError(`Response id ${id} doesn't match any request's id`);
|
|
14812
|
-
}
|
|
14813
|
-
resolve(walletMessage);
|
|
14814
|
-
this.pendingRequests.delete(id);
|
|
14815
|
-
return;
|
|
14816
|
-
}
|
|
14817
|
-
if (walletMessage.event === "connect") {
|
|
14818
|
-
yield this.updateSession(walletMessage, bridgeIncomingMessage.from);
|
|
14819
|
-
}
|
|
14820
|
-
if (walletMessage.event === "disconnect") {
|
|
14821
|
-
yield this.removeBridgeAndSession();
|
|
14822
|
-
}
|
|
14823
|
-
this.listeners.forEach((listener) => listener(walletMessage));
|
|
14824
|
-
});
|
|
14825
|
-
}
|
|
14826
|
-
gatewayErrorsListener(e2) {
|
|
14827
|
-
return __awaiter$4(this, void 0, void 0, function* () {
|
|
14828
|
-
throw new TonConnectError(`Bridge error ${JSON.stringify(e2)}`);
|
|
14829
|
-
});
|
|
14830
|
-
}
|
|
14831
|
-
updateSession(connectEvent, walletPublicKey) {
|
|
14832
|
-
return __awaiter$4(this, void 0, void 0, function* () {
|
|
14833
|
-
this.session = Object.assign(Object.assign({}, this.session), { walletPublicKey });
|
|
14834
|
-
const tonAddrItem = connectEvent.payload.items.find((item) => item.name === "ton_addr");
|
|
14835
|
-
const connectEventToSave = Object.assign(Object.assign({}, connectEvent), { payload: Object.assign(Object.assign({}, connectEvent.payload), { items: [tonAddrItem] }) });
|
|
14836
|
-
yield this.connectionStorage.storeConnection({
|
|
14837
|
-
type: "http",
|
|
14838
|
-
session: this.session,
|
|
14839
|
-
connectEvent: connectEventToSave
|
|
14840
|
-
});
|
|
14841
|
-
});
|
|
14842
|
-
}
|
|
14843
|
-
removeBridgeAndSession() {
|
|
14844
|
-
return __awaiter$4(this, void 0, void 0, function* () {
|
|
14845
|
-
this.session = null;
|
|
14846
|
-
this.bridge = null;
|
|
14847
|
-
yield this.connectionStorage.removeConnection();
|
|
14848
|
-
});
|
|
14849
|
-
}
|
|
14850
|
-
generateUniversalLink(message) {
|
|
14851
|
-
const url = new URL(this.walletConnectionSource.universalLink);
|
|
14852
|
-
url.searchParams.append("v", PROTOCOL_VERSION.toString());
|
|
14853
|
-
url.searchParams.append("id", this.session.sessionCrypto.sessionId);
|
|
14854
|
-
url.searchParams.append("r", JSON.stringify(message));
|
|
14855
|
-
return url.toString();
|
|
14856
|
-
}
|
|
14857
|
-
}
|
|
14858
|
-
function getWindow() {
|
|
14859
|
-
if (typeof window === "undefined") {
|
|
14860
|
-
return void 0;
|
|
14861
|
-
}
|
|
14862
|
-
return window;
|
|
14863
|
-
}
|
|
14864
|
-
function getWebPageManifest() {
|
|
14865
|
-
var _a2;
|
|
14866
|
-
const origin = (_a2 = getWindow()) === null || _a2 === void 0 ? void 0 : _a2.location.origin;
|
|
14867
|
-
if (origin) {
|
|
14868
|
-
return origin + "/tonconnect-manifest.json";
|
|
14869
|
-
}
|
|
14870
|
-
return "";
|
|
14871
|
-
}
|
|
14872
|
-
var __awaiter$3 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
14481
|
+
globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
14873
14482
|
function adopt(value) {
|
|
14874
14483
|
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
14875
14484
|
resolve(value);
|
|
@@ -14896,509 +14505,18 @@ var __awaiter$3 = globalThis && globalThis.__awaiter || function(thisArg, _argum
|
|
|
14896
14505
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14897
14506
|
});
|
|
14898
14507
|
};
|
|
14899
|
-
|
|
14900
|
-
|
|
14901
|
-
|
|
14902
|
-
|
|
14903
|
-
|
|
14904
|
-
|
|
14905
|
-
|
|
14906
|
-
|
|
14907
|
-
|
|
14908
|
-
}
|
|
14909
|
-
this.injectedWallet = window2[injectedWalletKey].tonconnect;
|
|
14910
|
-
}
|
|
14911
|
-
static fromStorage(storage) {
|
|
14912
|
-
return __awaiter$3(this, void 0, void 0, function* () {
|
|
14913
|
-
const bridgeConnectionStorage = new BridgeConnectionStorage(storage);
|
|
14914
|
-
const connection = yield bridgeConnectionStorage.getInjectedConnection();
|
|
14915
|
-
return new InjectedProvider(connection.jsBridgeKey);
|
|
14916
|
-
});
|
|
14917
|
-
}
|
|
14918
|
-
static isWalletInjected(injectedWalletKey) {
|
|
14919
|
-
return InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey);
|
|
14920
|
-
}
|
|
14921
|
-
static isInsideWalletBrowser(injectedWalletKey) {
|
|
14922
|
-
if (InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey)) {
|
|
14923
|
-
return this.window[injectedWalletKey].tonconnect.isWalletBrowser;
|
|
14924
|
-
}
|
|
14925
|
-
return false;
|
|
14926
|
-
}
|
|
14927
|
-
static isWindowContainsWallet(window2, injectedWalletKey) {
|
|
14928
|
-
return !!window2 && injectedWalletKey in window2 && typeof window2[injectedWalletKey] === "object" && "tonconnect" in window2[injectedWalletKey];
|
|
14929
|
-
}
|
|
14930
|
-
connect(message, auto = false) {
|
|
14931
|
-
this.injectedWallet.connect(PROTOCOL_VERSION, message, auto).then((connectEvent) => {
|
|
14932
|
-
if (connectEvent.event === "connect") {
|
|
14933
|
-
this.makeSubscriptions();
|
|
14934
|
-
this.listenSubscriptions = true;
|
|
14935
|
-
}
|
|
14936
|
-
this.listeners.forEach((listener) => listener(connectEvent));
|
|
14937
|
-
}).catch((e2) => {
|
|
14938
|
-
const connectEventError = {
|
|
14939
|
-
event: "connect_error",
|
|
14940
|
-
payload: {
|
|
14941
|
-
code: 0,
|
|
14942
|
-
message: e2 === null || e2 === void 0 ? void 0 : e2.toString()
|
|
14943
|
-
}
|
|
14944
|
-
};
|
|
14945
|
-
this.listeners.forEach((listener) => listener(connectEventError));
|
|
14946
|
-
});
|
|
14947
|
-
}
|
|
14948
|
-
restoreConnection() {
|
|
14949
|
-
return __awaiter$3(this, void 0, void 0, function* () {
|
|
14950
|
-
try {
|
|
14951
|
-
const connectEvent = yield this.injectedWallet.restoreConnection();
|
|
14952
|
-
if (connectEvent.event === "connect") {
|
|
14953
|
-
this.makeSubscriptions();
|
|
14954
|
-
this.listenSubscriptions = true;
|
|
14955
|
-
this.listeners.forEach((listener) => listener(connectEvent));
|
|
14956
|
-
}
|
|
14957
|
-
} catch (e2) {
|
|
14958
|
-
console.error(e2);
|
|
14959
|
-
}
|
|
14960
|
-
});
|
|
14961
|
-
}
|
|
14962
|
-
closeConnection() {
|
|
14963
|
-
if (this.listenSubscriptions) {
|
|
14964
|
-
this.injectedWallet.disconnect();
|
|
14965
|
-
}
|
|
14966
|
-
this.closeAllListeners();
|
|
14967
|
-
}
|
|
14968
|
-
disconnect() {
|
|
14969
|
-
this.closeAllListeners();
|
|
14970
|
-
this.injectedWallet.disconnect();
|
|
14971
|
-
return Promise.resolve();
|
|
14972
|
-
}
|
|
14973
|
-
closeAllListeners() {
|
|
14974
|
-
var _a2;
|
|
14975
|
-
this.listenSubscriptions = false;
|
|
14976
|
-
this.listeners = [];
|
|
14977
|
-
(_a2 = this.unsubscribeCallback) === null || _a2 === void 0 ? void 0 : _a2.call(this);
|
|
14978
|
-
}
|
|
14979
|
-
listen(eventsCallback) {
|
|
14980
|
-
this.listeners.push(eventsCallback);
|
|
14981
|
-
return () => this.listeners = this.listeners.filter((listener) => listener !== eventsCallback);
|
|
14982
|
-
}
|
|
14983
|
-
sendRequest(request) {
|
|
14984
|
-
return __awaiter$3(this, void 0, void 0, function* () {
|
|
14985
|
-
return this.injectedWallet.send(Object.assign(Object.assign({}, request), { id: "0" }));
|
|
14986
|
-
});
|
|
14987
|
-
}
|
|
14988
|
-
makeSubscriptions() {
|
|
14989
|
-
this.unsubscribeCallback = this.injectedWallet.listen((e2) => {
|
|
14990
|
-
if (this.listenSubscriptions) {
|
|
14991
|
-
this.listeners.forEach((listener) => listener(e2));
|
|
14992
|
-
}
|
|
14993
|
-
if (e2.event === "disconnect") {
|
|
14994
|
-
this.disconnect();
|
|
14995
|
-
}
|
|
14996
|
-
});
|
|
14997
|
-
}
|
|
14998
|
-
}
|
|
14999
|
-
InjectedProvider.window = getWindow();
|
|
15000
|
-
var __awaiter$2 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
15001
|
-
function adopt(value) {
|
|
15002
|
-
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
15003
|
-
resolve(value);
|
|
15004
|
-
});
|
|
15005
|
-
}
|
|
15006
|
-
return new (P2 || (P2 = Promise))(function(resolve, reject) {
|
|
15007
|
-
function fulfilled(value) {
|
|
15008
|
-
try {
|
|
15009
|
-
step(generator.next(value));
|
|
15010
|
-
} catch (e2) {
|
|
15011
|
-
reject(e2);
|
|
15012
|
-
}
|
|
15013
|
-
}
|
|
15014
|
-
function rejected(value) {
|
|
15015
|
-
try {
|
|
15016
|
-
step(generator["throw"](value));
|
|
15017
|
-
} catch (e2) {
|
|
15018
|
-
reject(e2);
|
|
15019
|
-
}
|
|
15020
|
-
}
|
|
15021
|
-
function step(result) {
|
|
15022
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
15023
|
-
}
|
|
15024
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15025
|
-
});
|
|
15026
|
-
};
|
|
15027
|
-
class DefaultStorage {
|
|
15028
|
-
constructor() {
|
|
15029
|
-
const window2 = getWindow();
|
|
15030
|
-
if (!(window2 === null || window2 === void 0 ? void 0 : window2.localStorage)) {
|
|
15031
|
-
throw new LocalstorageNotFoundError();
|
|
15032
|
-
}
|
|
15033
|
-
this.window = window2;
|
|
15034
|
-
}
|
|
15035
|
-
getItem(key) {
|
|
15036
|
-
return __awaiter$2(this, void 0, void 0, function* () {
|
|
15037
|
-
return Promise.resolve(this.window.localStorage.getItem(key));
|
|
15038
|
-
});
|
|
15039
|
-
}
|
|
15040
|
-
removeItem(key) {
|
|
15041
|
-
return __awaiter$2(this, void 0, void 0, function* () {
|
|
15042
|
-
this.window.localStorage.removeItem(key);
|
|
15043
|
-
return Promise.resolve();
|
|
15044
|
-
});
|
|
15045
|
-
}
|
|
15046
|
-
setItem(key, value) {
|
|
15047
|
-
this.window.localStorage.setItem(key, value);
|
|
15048
|
-
return Promise.resolve();
|
|
15049
|
-
}
|
|
15050
|
-
}
|
|
15051
|
-
function isWalletInfoInjected(value) {
|
|
15052
|
-
return "jsBridgeKey" in value;
|
|
15053
|
-
}
|
|
15054
|
-
var __awaiter$1 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
15055
|
-
function adopt(value) {
|
|
15056
|
-
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
15057
|
-
resolve(value);
|
|
15058
|
-
});
|
|
15059
|
-
}
|
|
15060
|
-
return new (P2 || (P2 = Promise))(function(resolve, reject) {
|
|
15061
|
-
function fulfilled(value) {
|
|
15062
|
-
try {
|
|
15063
|
-
step(generator.next(value));
|
|
15064
|
-
} catch (e2) {
|
|
15065
|
-
reject(e2);
|
|
15066
|
-
}
|
|
15067
|
-
}
|
|
15068
|
-
function rejected(value) {
|
|
15069
|
-
try {
|
|
15070
|
-
step(generator["throw"](value));
|
|
15071
|
-
} catch (e2) {
|
|
15072
|
-
reject(e2);
|
|
15073
|
-
}
|
|
15074
|
-
}
|
|
15075
|
-
function step(result) {
|
|
15076
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
15077
|
-
}
|
|
15078
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15079
|
-
});
|
|
15080
|
-
};
|
|
15081
|
-
class WalletsListManager {
|
|
15082
|
-
constructor() {
|
|
15083
|
-
this.walletsListCache = null;
|
|
15084
|
-
this.walletsListSource = "https://raw.githubusercontent.com/ton-connect/wallets-list/main/wallets.json";
|
|
15085
|
-
}
|
|
15086
|
-
getWallets() {
|
|
15087
|
-
return __awaiter$1(this, void 0, void 0, function* () {
|
|
15088
|
-
if (!this.walletsListCache) {
|
|
15089
|
-
this.walletsListCache = this.fetchWalletsList();
|
|
15090
|
-
this.walletsListCache.catch(() => this.walletsListCache = null);
|
|
15091
|
-
}
|
|
15092
|
-
return this.walletsListCache;
|
|
15093
|
-
});
|
|
15094
|
-
}
|
|
15095
|
-
getEmbeddedWallet() {
|
|
15096
|
-
return __awaiter$1(this, void 0, void 0, function* () {
|
|
15097
|
-
const walletsList = yield this.getWallets();
|
|
15098
|
-
const injectedWallets = walletsList.filter(isWalletInfoInjected);
|
|
15099
|
-
if (injectedWallets.length !== 1) {
|
|
15100
|
-
return null;
|
|
15101
|
-
}
|
|
15102
|
-
return injectedWallets[0].embedded ? injectedWallets[0] : null;
|
|
15103
|
-
});
|
|
15104
|
-
}
|
|
15105
|
-
fetchWalletsList() {
|
|
15106
|
-
return __awaiter$1(this, void 0, void 0, function* () {
|
|
15107
|
-
try {
|
|
15108
|
-
const walletsResponse = yield fetch(this.walletsListSource);
|
|
15109
|
-
const walletsList = yield walletsResponse.json();
|
|
15110
|
-
if (!Array.isArray(walletsList) || !walletsList.every((wallet) => this.isCorrectWalletConfigDTO(wallet))) {
|
|
15111
|
-
throw new FetchWalletsError("Wrong wallets list format");
|
|
15112
|
-
}
|
|
15113
|
-
return this.walletConfigDTOListToWalletConfigList(walletsList);
|
|
15114
|
-
} catch (e2) {
|
|
15115
|
-
throw new FetchWalletsError(e2);
|
|
15116
|
-
}
|
|
15117
|
-
});
|
|
15118
|
-
}
|
|
15119
|
-
walletConfigDTOListToWalletConfigList(walletConfigDTO) {
|
|
15120
|
-
return walletConfigDTO.map((walletConfigDTO2) => {
|
|
15121
|
-
const walletConfig = {
|
|
15122
|
-
name: walletConfigDTO2.name,
|
|
15123
|
-
imageUrl: walletConfigDTO2.image,
|
|
15124
|
-
aboutUrl: walletConfigDTO2.about_url,
|
|
15125
|
-
tondns: walletConfigDTO2.tondns
|
|
15126
|
-
};
|
|
15127
|
-
walletConfigDTO2.bridge.forEach((bridge) => {
|
|
15128
|
-
if (bridge.type === "sse") {
|
|
15129
|
-
walletConfig.bridgeUrl = bridge.url;
|
|
15130
|
-
walletConfig.universalLink = walletConfigDTO2.universal_url;
|
|
15131
|
-
walletConfig.deepLink = walletConfigDTO2.deepLink;
|
|
15132
|
-
}
|
|
15133
|
-
if (bridge.type === "js") {
|
|
15134
|
-
const jsBridgeKey = bridge.key;
|
|
15135
|
-
walletConfig.jsBridgeKey = jsBridgeKey;
|
|
15136
|
-
walletConfig.injected = InjectedProvider.isWalletInjected(jsBridgeKey);
|
|
15137
|
-
walletConfig.embedded = InjectedProvider.isInsideWalletBrowser(jsBridgeKey);
|
|
15138
|
-
}
|
|
15139
|
-
});
|
|
15140
|
-
return walletConfig;
|
|
15141
|
-
});
|
|
15142
|
-
}
|
|
15143
|
-
isCorrectWalletConfigDTO(value) {
|
|
15144
|
-
if (!value || !(typeof value === "object")) {
|
|
15145
|
-
return false;
|
|
15146
|
-
}
|
|
15147
|
-
const containsName = "name" in value;
|
|
15148
|
-
const containsImage = "image" in value;
|
|
15149
|
-
const containsAbout = "about_url" in value;
|
|
15150
|
-
if (!containsName || !containsImage || !containsAbout) {
|
|
15151
|
-
return false;
|
|
15152
|
-
}
|
|
15153
|
-
if (!("bridge" in value) || !Array.isArray(value.bridge) || !value.bridge.length) {
|
|
15154
|
-
return false;
|
|
15155
|
-
}
|
|
15156
|
-
const bridge = value.bridge;
|
|
15157
|
-
if (bridge.some((item) => !item || typeof item !== "object" || !("type" in item))) {
|
|
15158
|
-
return false;
|
|
15159
|
-
}
|
|
15160
|
-
const sseBridge = bridge.find((item) => item.type === "sse");
|
|
15161
|
-
if (sseBridge) {
|
|
15162
|
-
if (!("url" in sseBridge) || !sseBridge.url || !value.universal_url) {
|
|
15163
|
-
return false;
|
|
15164
|
-
}
|
|
15165
|
-
}
|
|
15166
|
-
const jsBridge = bridge.find((item) => item.type === "js");
|
|
15167
|
-
if (jsBridge) {
|
|
15168
|
-
if (!("key" in jsBridge) || !jsBridge.key) {
|
|
15169
|
-
return false;
|
|
15170
|
-
}
|
|
15171
|
-
}
|
|
15172
|
-
return true;
|
|
15173
|
-
}
|
|
15174
|
-
}
|
|
15175
|
-
var __awaiter = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
|
|
15176
|
-
function adopt(value) {
|
|
15177
|
-
return value instanceof P2 ? value : new P2(function(resolve) {
|
|
15178
|
-
resolve(value);
|
|
15179
|
-
});
|
|
15180
|
-
}
|
|
15181
|
-
return new (P2 || (P2 = Promise))(function(resolve, reject) {
|
|
15182
|
-
function fulfilled(value) {
|
|
15183
|
-
try {
|
|
15184
|
-
step(generator.next(value));
|
|
15185
|
-
} catch (e2) {
|
|
15186
|
-
reject(e2);
|
|
15187
|
-
}
|
|
15188
|
-
}
|
|
15189
|
-
function rejected(value) {
|
|
15190
|
-
try {
|
|
15191
|
-
step(generator["throw"](value));
|
|
15192
|
-
} catch (e2) {
|
|
15193
|
-
reject(e2);
|
|
15194
|
-
}
|
|
15195
|
-
}
|
|
15196
|
-
function step(result) {
|
|
15197
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
15198
|
-
}
|
|
15199
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15200
|
-
});
|
|
15201
|
-
};
|
|
15202
|
-
var __rest = globalThis && globalThis.__rest || function(s2, e2) {
|
|
15203
|
-
var t2 = {};
|
|
15204
|
-
for (var p2 in s2)
|
|
15205
|
-
if (Object.prototype.hasOwnProperty.call(s2, p2) && e2.indexOf(p2) < 0)
|
|
15206
|
-
t2[p2] = s2[p2];
|
|
15207
|
-
if (s2 != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15208
|
-
for (var i2 = 0, p2 = Object.getOwnPropertySymbols(s2); i2 < p2.length; i2++) {
|
|
15209
|
-
if (e2.indexOf(p2[i2]) < 0 && Object.prototype.propertyIsEnumerable.call(s2, p2[i2]))
|
|
15210
|
-
t2[p2[i2]] = s2[p2[i2]];
|
|
14508
|
+
globalThis && globalThis.__rest || function(s2, e2) {
|
|
14509
|
+
var t2 = {};
|
|
14510
|
+
for (var p2 in s2)
|
|
14511
|
+
if (Object.prototype.hasOwnProperty.call(s2, p2) && e2.indexOf(p2) < 0)
|
|
14512
|
+
t2[p2] = s2[p2];
|
|
14513
|
+
if (s2 != null && typeof Object.getOwnPropertySymbols === "function")
|
|
14514
|
+
for (var i2 = 0, p2 = Object.getOwnPropertySymbols(s2); i2 < p2.length; i2++) {
|
|
14515
|
+
if (e2.indexOf(p2[i2]) < 0 && Object.prototype.propertyIsEnumerable.call(s2, p2[i2]))
|
|
14516
|
+
t2[p2[i2]] = s2[p2[i2]];
|
|
15211
14517
|
}
|
|
15212
14518
|
return t2;
|
|
15213
14519
|
};
|
|
15214
|
-
var _a;
|
|
15215
|
-
class TonConnect {
|
|
15216
|
-
constructor(options) {
|
|
15217
|
-
this.walletsList = new WalletsListManager();
|
|
15218
|
-
this._wallet = null;
|
|
15219
|
-
this.provider = null;
|
|
15220
|
-
this.statusChangeSubscriptions = [];
|
|
15221
|
-
this.statusChangeErrorSubscriptions = [];
|
|
15222
|
-
this.dappSettings = {
|
|
15223
|
-
manifestUrl: (options === null || options === void 0 ? void 0 : options.manifestUrl) || getWebPageManifest(),
|
|
15224
|
-
storage: (options === null || options === void 0 ? void 0 : options.storage) || new DefaultStorage()
|
|
15225
|
-
};
|
|
15226
|
-
if (!this.dappSettings.manifestUrl) {
|
|
15227
|
-
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");
|
|
15228
|
-
}
|
|
15229
|
-
this.bridgeConnectionStorage = new BridgeConnectionStorage(this.dappSettings.storage);
|
|
15230
|
-
}
|
|
15231
|
-
get connected() {
|
|
15232
|
-
return this._wallet !== null;
|
|
15233
|
-
}
|
|
15234
|
-
get account() {
|
|
15235
|
-
var _b;
|
|
15236
|
-
return ((_b = this._wallet) === null || _b === void 0 ? void 0 : _b.account) || null;
|
|
15237
|
-
}
|
|
15238
|
-
get wallet() {
|
|
15239
|
-
return this._wallet;
|
|
15240
|
-
}
|
|
15241
|
-
set wallet(value) {
|
|
15242
|
-
this._wallet = value;
|
|
15243
|
-
this.statusChangeSubscriptions.forEach((callback) => callback(this._wallet));
|
|
15244
|
-
}
|
|
15245
|
-
getWallets() {
|
|
15246
|
-
return this.walletsList.getWallets();
|
|
15247
|
-
}
|
|
15248
|
-
onStatusChange(callback, errorsHandler) {
|
|
15249
|
-
this.statusChangeSubscriptions.push(callback);
|
|
15250
|
-
if (errorsHandler) {
|
|
15251
|
-
this.statusChangeErrorSubscriptions.push(errorsHandler);
|
|
15252
|
-
}
|
|
15253
|
-
return () => {
|
|
15254
|
-
this.statusChangeSubscriptions = this.statusChangeSubscriptions.filter((item) => item !== callback);
|
|
15255
|
-
if (errorsHandler) {
|
|
15256
|
-
this.statusChangeErrorSubscriptions = this.statusChangeErrorSubscriptions.filter((item) => item !== errorsHandler);
|
|
15257
|
-
}
|
|
15258
|
-
};
|
|
15259
|
-
}
|
|
15260
|
-
connect(wallet, request) {
|
|
15261
|
-
var _b;
|
|
15262
|
-
if (this.connected) {
|
|
15263
|
-
throw new WalletAlreadyConnectedError();
|
|
15264
|
-
}
|
|
15265
|
-
(_b = this.provider) === null || _b === void 0 ? void 0 : _b.closeConnection();
|
|
15266
|
-
this.provider = this.createProvider(wallet);
|
|
15267
|
-
return this.provider.connect(this.createConnectRequest(request));
|
|
15268
|
-
}
|
|
15269
|
-
restoreConnection() {
|
|
15270
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15271
|
-
const [bridgeConnectionType, embeddedWallet] = yield Promise.all([
|
|
15272
|
-
this.bridgeConnectionStorage.storedConnectionType(),
|
|
15273
|
-
this.walletsList.getEmbeddedWallet()
|
|
15274
|
-
]);
|
|
15275
|
-
switch (bridgeConnectionType) {
|
|
15276
|
-
case "http":
|
|
15277
|
-
this.provider = yield BridgeProvider.fromStorage(this.dappSettings.storage);
|
|
15278
|
-
break;
|
|
15279
|
-
case "injected":
|
|
15280
|
-
this.provider = yield InjectedProvider.fromStorage(this.dappSettings.storage);
|
|
15281
|
-
break;
|
|
15282
|
-
default:
|
|
15283
|
-
if (embeddedWallet) {
|
|
15284
|
-
this.provider = yield this.createProvider(embeddedWallet);
|
|
15285
|
-
} else {
|
|
15286
|
-
return;
|
|
15287
|
-
}
|
|
15288
|
-
}
|
|
15289
|
-
this.provider.listen(this.walletEventsListener.bind(this));
|
|
15290
|
-
return this.provider.restoreConnection();
|
|
15291
|
-
});
|
|
15292
|
-
}
|
|
15293
|
-
sendTransaction(transaction) {
|
|
15294
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15295
|
-
this.checkConnection();
|
|
15296
|
-
this.checkFeatureSupport("SendTransaction");
|
|
15297
|
-
const { validUntil } = transaction, tx = __rest(transaction, ["validUntil"]);
|
|
15298
|
-
const response = yield this.provider.sendRequest(sendTransactionParser.convertToRpcRequest(Object.assign(Object.assign({}, tx), { valid_until: validUntil })));
|
|
15299
|
-
if (sendTransactionParser.isError(response)) {
|
|
15300
|
-
return sendTransactionParser.parseAndThrowError(response);
|
|
15301
|
-
}
|
|
15302
|
-
return sendTransactionParser.convertFromRpcResponse(response);
|
|
15303
|
-
});
|
|
15304
|
-
}
|
|
15305
|
-
disconnect() {
|
|
15306
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15307
|
-
if (!this.connected) {
|
|
15308
|
-
throw new WalletNotConnectedError();
|
|
15309
|
-
}
|
|
15310
|
-
yield this.provider.disconnect();
|
|
15311
|
-
this.onWalletDisconnected();
|
|
15312
|
-
});
|
|
15313
|
-
}
|
|
15314
|
-
createProvider(wallet) {
|
|
15315
|
-
let provider;
|
|
15316
|
-
if (isWalletConnectionSourceJS(wallet)) {
|
|
15317
|
-
provider = new InjectedProvider(wallet.jsBridgeKey);
|
|
15318
|
-
} else {
|
|
15319
|
-
provider = new BridgeProvider(this.dappSettings.storage, wallet);
|
|
15320
|
-
}
|
|
15321
|
-
provider.listen(this.walletEventsListener.bind(this));
|
|
15322
|
-
return provider;
|
|
15323
|
-
}
|
|
15324
|
-
walletEventsListener(e2) {
|
|
15325
|
-
switch (e2.event) {
|
|
15326
|
-
case "connect":
|
|
15327
|
-
this.onWalletConnected(e2.payload);
|
|
15328
|
-
break;
|
|
15329
|
-
case "connect_error":
|
|
15330
|
-
this.onWalletConnectError(e2.payload);
|
|
15331
|
-
break;
|
|
15332
|
-
case "disconnect":
|
|
15333
|
-
this.onWalletDisconnected();
|
|
15334
|
-
}
|
|
15335
|
-
}
|
|
15336
|
-
onWalletConnected(connectEvent) {
|
|
15337
|
-
const tonAccountItem = connectEvent.items.find((item) => item.name === "ton_addr");
|
|
15338
|
-
const tonProofItem = connectEvent.items.find((item) => item.name === "ton_proof");
|
|
15339
|
-
if (!tonAccountItem) {
|
|
15340
|
-
throw new TonConnectError("ton_addr connection item was not found");
|
|
15341
|
-
}
|
|
15342
|
-
const wallet = {
|
|
15343
|
-
device: connectEvent.device,
|
|
15344
|
-
provider: this.provider.type,
|
|
15345
|
-
account: {
|
|
15346
|
-
address: tonAccountItem.address,
|
|
15347
|
-
chain: tonAccountItem.network,
|
|
15348
|
-
walletStateInit: tonAccountItem.walletStateInit
|
|
15349
|
-
}
|
|
15350
|
-
};
|
|
15351
|
-
if (tonProofItem) {
|
|
15352
|
-
wallet.connectItems = {
|
|
15353
|
-
tonProof: tonProofItem
|
|
15354
|
-
};
|
|
15355
|
-
}
|
|
15356
|
-
this.wallet = wallet;
|
|
15357
|
-
}
|
|
15358
|
-
onWalletConnectError(connectEventError) {
|
|
15359
|
-
const error = connectErrorsParser.parseError(connectEventError);
|
|
15360
|
-
this.statusChangeErrorSubscriptions.forEach((errorsHandler) => errorsHandler(error));
|
|
15361
|
-
console.debug(error);
|
|
15362
|
-
if (error instanceof ManifestNotFoundError || error instanceof ManifestContentErrorError) {
|
|
15363
|
-
console.error(error);
|
|
15364
|
-
throw error;
|
|
15365
|
-
}
|
|
15366
|
-
}
|
|
15367
|
-
onWalletDisconnected() {
|
|
15368
|
-
this.wallet = null;
|
|
15369
|
-
}
|
|
15370
|
-
checkConnection() {
|
|
15371
|
-
if (!this.connected) {
|
|
15372
|
-
throw new WalletNotConnectedError();
|
|
15373
|
-
}
|
|
15374
|
-
}
|
|
15375
|
-
checkFeatureSupport(feature) {
|
|
15376
|
-
var _b;
|
|
15377
|
-
if (!((_b = this.wallet) === null || _b === void 0 ? void 0 : _b.device.features.includes(feature))) {
|
|
15378
|
-
throw new WalletNotSupportFeatureError();
|
|
15379
|
-
}
|
|
15380
|
-
}
|
|
15381
|
-
createConnectRequest(request) {
|
|
15382
|
-
const items = [
|
|
15383
|
-
{
|
|
15384
|
-
name: "ton_addr"
|
|
15385
|
-
}
|
|
15386
|
-
];
|
|
15387
|
-
if (request === null || request === void 0 ? void 0 : request.tonProof) {
|
|
15388
|
-
items.push({
|
|
15389
|
-
name: "ton_proof",
|
|
15390
|
-
payload: request.tonProof
|
|
15391
|
-
});
|
|
15392
|
-
}
|
|
15393
|
-
return {
|
|
15394
|
-
manifestUrl: this.dappSettings.manifestUrl,
|
|
15395
|
-
items
|
|
15396
|
-
};
|
|
15397
|
-
}
|
|
15398
|
-
}
|
|
15399
|
-
_a = TonConnect;
|
|
15400
|
-
TonConnect.walletsList = new WalletsListManager();
|
|
15401
|
-
TonConnect.getWallets = _a.walletsList.getWallets();
|
|
15402
14520
|
function toUserFriendlyAddress(hexAddress) {
|
|
15403
14521
|
const { wc, hex } = parseHexAddress(hexAddress);
|
|
15404
14522
|
const bounceableTag = 17;
|
|
@@ -15492,9 +14610,9 @@ export {
|
|
|
15492
14610
|
THEME,
|
|
15493
14611
|
TonConnectButton$1 as TonConnectButton,
|
|
15494
14612
|
TonConnectProviderNotSetError,
|
|
14613
|
+
TonConnectUI,
|
|
15495
14614
|
TonConnectUIError,
|
|
15496
14615
|
TonConnectUIProvider$1 as TonConnectUIProvider,
|
|
15497
|
-
TonConnectUi,
|
|
15498
14616
|
TonConnectUiReactError,
|
|
15499
14617
|
useTonAddress,
|
|
15500
14618
|
useTonConnectUI,
|