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