@tonconnect/ui-react 0.0.1 → 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,19 +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 = [];
4115
+ this.session = null;
4116
+ this.bridge = null;
4098
4117
  }
4099
4118
  disconnect() {
4100
- var _a2;
4101
- (_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();
4102
4121
  this.listeners = [];
4103
4122
  return this.removeBridgeAndSession();
4104
4123
  }
@@ -4107,8 +4126,8 @@ var __objRest = (source, exclude) => {
4107
4126
  return () => this.listeners = this.listeners.filter((listener) => listener !== callback);
4108
4127
  }
4109
4128
  gatewayListener(bridgeIncomingMessage) {
4110
- return __awaiter$4$1(this, void 0, void 0, function* () {
4111
- 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)));
4112
4131
  if (!("event" in walletMessage)) {
4113
4132
  const id = walletMessage.id.toString();
4114
4133
  const resolve = this.pendingRequests.get(id);
@@ -4129,12 +4148,12 @@ var __objRest = (source, exclude) => {
4129
4148
  });
4130
4149
  }
4131
4150
  gatewayErrorsListener(e2) {
4132
- return __awaiter$4$1(this, void 0, void 0, function* () {
4151
+ return __awaiter$4(this, void 0, void 0, function* () {
4133
4152
  throw new TonConnectError$1(`Bridge error ${JSON.stringify(e2)}`);
4134
4153
  });
4135
4154
  }
4136
4155
  updateSession(connectEvent, walletPublicKey) {
4137
- return __awaiter$4$1(this, void 0, void 0, function* () {
4156
+ return __awaiter$4(this, void 0, void 0, function* () {
4138
4157
  this.session = Object.assign(Object.assign({}, this.session), { walletPublicKey });
4139
4158
  const tonAddrItem = connectEvent.payload.items.find((item) => item.name === "ton_addr");
4140
4159
  const connectEventToSave = Object.assign(Object.assign({}, connectEvent), { payload: Object.assign(Object.assign({}, connectEvent.payload), { items: [tonAddrItem] }) });
@@ -4146,7 +4165,7 @@ var __objRest = (source, exclude) => {
4146
4165
  });
4147
4166
  }
4148
4167
  removeBridgeAndSession() {
4149
- return __awaiter$4$1(this, void 0, void 0, function* () {
4168
+ return __awaiter$4(this, void 0, void 0, function* () {
4150
4169
  this.session = null;
4151
4170
  this.bridge = null;
4152
4171
  yield this.connectionStorage.removeConnection();
@@ -4154,27 +4173,27 @@ var __objRest = (source, exclude) => {
4154
4173
  }
4155
4174
  generateUniversalLink(message) {
4156
4175
  const url = new URL(this.walletConnectionSource.universalLink);
4157
- url.searchParams.append("v", PROTOCOL_VERSION$1.toString());
4176
+ url.searchParams.append("v", PROTOCOL_VERSION.toString());
4158
4177
  url.searchParams.append("id", this.session.sessionCrypto.sessionId);
4159
4178
  url.searchParams.append("r", JSON.stringify(message));
4160
4179
  return url.toString();
4161
4180
  }
4162
- };
4181
+ }
4163
4182
  function getWindow$1() {
4164
4183
  if (typeof window === "undefined") {
4165
4184
  return void 0;
4166
4185
  }
4167
4186
  return window;
4168
4187
  }
4169
- function getWebPageManifest$1() {
4170
- var _a2;
4171
- 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;
4172
4191
  if (origin) {
4173
4192
  return origin + "/tonconnect-manifest.json";
4174
4193
  }
4175
4194
  return "";
4176
4195
  }
4177
- var __awaiter$3$1 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
4196
+ var __awaiter$3 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
4178
4197
  function adopt(value) {
4179
4198
  return value instanceof P2 ? value : new P2(function(resolve) {
4180
4199
  resolve(value);
@@ -4201,30 +4220,30 @@ var __objRest = (source, exclude) => {
4201
4220
  step((generator = generator.apply(thisArg, _arguments || [])).next());
4202
4221
  });
4203
4222
  };
4204
- let InjectedProvider$1 = class InjectedProvider {
4223
+ class InjectedProvider {
4205
4224
  constructor(injectedWalletKey) {
4206
4225
  this.type = "injected";
4207
4226
  this.unsubscribeCallback = null;
4208
4227
  this.listenSubscriptions = false;
4209
4228
  this.listeners = [];
4210
- const window2 = InjectedProvider$1.window;
4211
- if (!InjectedProvider$1.isWindowContainsWallet(window2, injectedWalletKey)) {
4212
- throw new WalletNotInjectedError$1();
4229
+ const window2 = InjectedProvider.window;
4230
+ if (!InjectedProvider.isWindowContainsWallet(window2, injectedWalletKey)) {
4231
+ throw new WalletNotInjectedError();
4213
4232
  }
4214
4233
  this.injectedWallet = window2[injectedWalletKey].tonconnect;
4215
4234
  }
4216
4235
  static fromStorage(storage) {
4217
- return __awaiter$3$1(this, void 0, void 0, function* () {
4218
- const bridgeConnectionStorage = new BridgeConnectionStorage$1(storage);
4236
+ return __awaiter$3(this, void 0, void 0, function* () {
4237
+ const bridgeConnectionStorage = new BridgeConnectionStorage(storage);
4219
4238
  const connection = yield bridgeConnectionStorage.getInjectedConnection();
4220
- return new InjectedProvider$1(connection.jsBridgeKey);
4239
+ return new InjectedProvider(connection.jsBridgeKey);
4221
4240
  });
4222
4241
  }
4223
4242
  static isWalletInjected(injectedWalletKey) {
4224
- return InjectedProvider$1.isWindowContainsWallet(this.window, injectedWalletKey);
4243
+ return InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey);
4225
4244
  }
4226
4245
  static isInsideWalletBrowser(injectedWalletKey) {
4227
- if (InjectedProvider$1.isWindowContainsWallet(this.window, injectedWalletKey)) {
4246
+ if (InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey)) {
4228
4247
  return this.window[injectedWalletKey].tonconnect.isWalletBrowser;
4229
4248
  }
4230
4249
  return false;
@@ -4233,7 +4252,7 @@ var __objRest = (source, exclude) => {
4233
4252
  return !!window2 && injectedWalletKey in window2 && typeof window2[injectedWalletKey] === "object" && "tonconnect" in window2[injectedWalletKey];
4234
4253
  }
4235
4254
  connect(message, auto = false) {
4236
- this.injectedWallet.connect(PROTOCOL_VERSION$1, message, auto).then((connectEvent) => {
4255
+ this.injectedWallet.connect(PROTOCOL_VERSION, message, auto).then((connectEvent) => {
4237
4256
  if (connectEvent.event === "connect") {
4238
4257
  this.makeSubscriptions();
4239
4258
  this.listenSubscriptions = true;
@@ -4251,7 +4270,7 @@ var __objRest = (source, exclude) => {
4251
4270
  });
4252
4271
  }
4253
4272
  restoreConnection() {
4254
- return __awaiter$3$1(this, void 0, void 0, function* () {
4273
+ return __awaiter$3(this, void 0, void 0, function* () {
4255
4274
  try {
4256
4275
  const connectEvent = yield this.injectedWallet.restoreConnection();
4257
4276
  if (connectEvent.event === "connect") {
@@ -4276,17 +4295,17 @@ var __objRest = (source, exclude) => {
4276
4295
  return Promise.resolve();
4277
4296
  }
4278
4297
  closeAllListeners() {
4279
- var _a2;
4298
+ var _a;
4280
4299
  this.listenSubscriptions = false;
4281
4300
  this.listeners = [];
4282
- (_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);
4283
4302
  }
4284
4303
  listen(eventsCallback) {
4285
4304
  this.listeners.push(eventsCallback);
4286
4305
  return () => this.listeners = this.listeners.filter((listener) => listener !== eventsCallback);
4287
4306
  }
4288
4307
  sendRequest(request) {
4289
- return __awaiter$3$1(this, void 0, void 0, function* () {
4308
+ return __awaiter$3(this, void 0, void 0, function* () {
4290
4309
  return this.injectedWallet.send(Object.assign(Object.assign({}, request), { id: "0" }));
4291
4310
  });
4292
4311
  }
@@ -4300,9 +4319,9 @@ var __objRest = (source, exclude) => {
4300
4319
  }
4301
4320
  });
4302
4321
  }
4303
- };
4304
- InjectedProvider$1.window = getWindow$1();
4305
- 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) {
4306
4325
  function adopt(value) {
4307
4326
  return value instanceof P2 ? value : new P2(function(resolve) {
4308
4327
  resolve(value);
@@ -4329,21 +4348,21 @@ var __objRest = (source, exclude) => {
4329
4348
  step((generator = generator.apply(thisArg, _arguments || [])).next());
4330
4349
  });
4331
4350
  };
4332
- let DefaultStorage$1 = class DefaultStorage {
4351
+ class DefaultStorage {
4333
4352
  constructor() {
4334
4353
  const window2 = getWindow$1();
4335
4354
  if (!(window2 === null || window2 === void 0 ? void 0 : window2.localStorage)) {
4336
- throw new LocalstorageNotFoundError$1();
4355
+ throw new LocalstorageNotFoundError();
4337
4356
  }
4338
4357
  this.window = window2;
4339
4358
  }
4340
4359
  getItem(key) {
4341
- return __awaiter$2$1(this, void 0, void 0, function* () {
4360
+ return __awaiter$2(this, void 0, void 0, function* () {
4342
4361
  return Promise.resolve(this.window.localStorage.getItem(key));
4343
4362
  });
4344
4363
  }
4345
4364
  removeItem(key) {
4346
- return __awaiter$2$1(this, void 0, void 0, function* () {
4365
+ return __awaiter$2(this, void 0, void 0, function* () {
4347
4366
  this.window.localStorage.removeItem(key);
4348
4367
  return Promise.resolve();
4349
4368
  });
@@ -4352,11 +4371,11 @@ var __objRest = (source, exclude) => {
4352
4371
  this.window.localStorage.setItem(key, value);
4353
4372
  return Promise.resolve();
4354
4373
  }
4355
- };
4356
- function isWalletInfoInjected$1(value) {
4374
+ }
4375
+ function isWalletInfoInjected(value) {
4357
4376
  return "jsBridgeKey" in value;
4358
4377
  }
4359
- var __awaiter$1$1 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
4378
+ var __awaiter$1 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
4360
4379
  function adopt(value) {
4361
4380
  return value instanceof P2 ? value : new P2(function(resolve) {
4362
4381
  resolve(value);
@@ -4383,13 +4402,13 @@ var __objRest = (source, exclude) => {
4383
4402
  step((generator = generator.apply(thisArg, _arguments || [])).next());
4384
4403
  });
4385
4404
  };
4386
- let WalletsListManager$1 = class WalletsListManager {
4405
+ class WalletsListManager {
4387
4406
  constructor() {
4388
4407
  this.walletsListCache = null;
4389
4408
  this.walletsListSource = "https://raw.githubusercontent.com/ton-connect/wallets-list/main/wallets.json";
4390
4409
  }
4391
4410
  getWallets() {
4392
- return __awaiter$1$1(this, void 0, void 0, function* () {
4411
+ return __awaiter$1(this, void 0, void 0, function* () {
4393
4412
  if (!this.walletsListCache) {
4394
4413
  this.walletsListCache = this.fetchWalletsList();
4395
4414
  this.walletsListCache.catch(() => this.walletsListCache = null);
@@ -4398,9 +4417,9 @@ var __objRest = (source, exclude) => {
4398
4417
  });
4399
4418
  }
4400
4419
  getEmbeddedWallet() {
4401
- return __awaiter$1$1(this, void 0, void 0, function* () {
4420
+ return __awaiter$1(this, void 0, void 0, function* () {
4402
4421
  const walletsList = yield this.getWallets();
4403
- const injectedWallets = walletsList.filter(isWalletInfoInjected$1);
4422
+ const injectedWallets = walletsList.filter(isWalletInfoInjected);
4404
4423
  if (injectedWallets.length !== 1) {
4405
4424
  return null;
4406
4425
  }
@@ -4408,16 +4427,16 @@ var __objRest = (source, exclude) => {
4408
4427
  });
4409
4428
  }
4410
4429
  fetchWalletsList() {
4411
- return __awaiter$1$1(this, void 0, void 0, function* () {
4430
+ return __awaiter$1(this, void 0, void 0, function* () {
4412
4431
  try {
4413
4432
  const walletsResponse = yield fetch(this.walletsListSource);
4414
4433
  const walletsList = yield walletsResponse.json();
4415
4434
  if (!Array.isArray(walletsList) || !walletsList.every((wallet) => this.isCorrectWalletConfigDTO(wallet))) {
4416
- throw new FetchWalletsError$1("Wrong wallets list format");
4435
+ throw new FetchWalletsError("Wrong wallets list format");
4417
4436
  }
4418
4437
  return this.walletConfigDTOListToWalletConfigList(walletsList);
4419
4438
  } catch (e2) {
4420
- throw new FetchWalletsError$1(e2);
4439
+ throw new FetchWalletsError(e2);
4421
4440
  }
4422
4441
  });
4423
4442
  }
@@ -4438,8 +4457,8 @@ var __objRest = (source, exclude) => {
4438
4457
  if (bridge.type === "js") {
4439
4458
  const jsBridgeKey = bridge.key;
4440
4459
  walletConfig.jsBridgeKey = jsBridgeKey;
4441
- walletConfig.injected = InjectedProvider$1.isWalletInjected(jsBridgeKey);
4442
- walletConfig.embedded = InjectedProvider$1.isInsideWalletBrowser(jsBridgeKey);
4460
+ walletConfig.injected = InjectedProvider.isWalletInjected(jsBridgeKey);
4461
+ walletConfig.embedded = InjectedProvider.isInsideWalletBrowser(jsBridgeKey);
4443
4462
  }
4444
4463
  });
4445
4464
  return walletConfig;
@@ -4476,8 +4495,8 @@ var __objRest = (source, exclude) => {
4476
4495
  }
4477
4496
  return true;
4478
4497
  }
4479
- };
4480
- var __awaiter$8 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
4498
+ }
4499
+ var __awaiter = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
4481
4500
  function adopt(value) {
4482
4501
  return value instanceof P2 ? value : new P2(function(resolve) {
4483
4502
  resolve(value);
@@ -4504,7 +4523,7 @@ var __objRest = (source, exclude) => {
4504
4523
  step((generator = generator.apply(thisArg, _arguments || [])).next());
4505
4524
  });
4506
4525
  };
4507
- var __rest$1 = globalThis && globalThis.__rest || function(s2, e2) {
4526
+ var __rest = globalThis && globalThis.__rest || function(s2, e2) {
4508
4527
  var t2 = {};
4509
4528
  for (var p2 in s2)
4510
4529
  if (Object.prototype.hasOwnProperty.call(s2, p2) && e2.indexOf(p2) < 0)
@@ -4516,28 +4535,31 @@ var __objRest = (source, exclude) => {
4516
4535
  }
4517
4536
  return t2;
4518
4537
  };
4519
- let TonConnect$1 = class TonConnect {
4538
+ class TonConnect {
4520
4539
  constructor(options) {
4521
- this.walletsList = new WalletsListManager$1();
4540
+ this.walletsList = new WalletsListManager();
4522
4541
  this._wallet = null;
4523
4542
  this.provider = null;
4524
4543
  this.statusChangeSubscriptions = [];
4525
4544
  this.statusChangeErrorSubscriptions = [];
4526
4545
  this.dappSettings = {
4527
- manifestUrl: (options === null || options === void 0 ? void 0 : options.manifestUrl) || getWebPageManifest$1(),
4528
- 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()
4529
4548
  };
4530
4549
  if (!this.dappSettings.manifestUrl) {
4531
- 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");
4532
4551
  }
4533
- 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();
4534
4556
  }
4535
4557
  get connected() {
4536
4558
  return this._wallet !== null;
4537
4559
  }
4538
4560
  get account() {
4539
- var _a2;
4540
- return ((_a2 = this._wallet) === null || _a2 === void 0 ? void 0 : _a2.account) || null;
4561
+ var _a;
4562
+ return ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.account) || null;
4541
4563
  }
4542
4564
  get wallet() {
4543
4565
  return this._wallet;
@@ -4562,26 +4584,26 @@ var __objRest = (source, exclude) => {
4562
4584
  };
4563
4585
  }
4564
4586
  connect(wallet, request) {
4565
- var _a2;
4587
+ var _a;
4566
4588
  if (this.connected) {
4567
- throw new WalletAlreadyConnectedError$1();
4589
+ throw new WalletAlreadyConnectedError();
4568
4590
  }
4569
- (_a2 = this.provider) === null || _a2 === void 0 ? void 0 : _a2.closeConnection();
4591
+ (_a = this.provider) === null || _a === void 0 ? void 0 : _a.closeConnection();
4570
4592
  this.provider = this.createProvider(wallet);
4571
4593
  return this.provider.connect(this.createConnectRequest(request));
4572
4594
  }
4573
4595
  restoreConnection() {
4574
- return __awaiter$8(this, void 0, void 0, function* () {
4596
+ return __awaiter(this, void 0, void 0, function* () {
4575
4597
  const [bridgeConnectionType, embeddedWallet] = yield Promise.all([
4576
4598
  this.bridgeConnectionStorage.storedConnectionType(),
4577
4599
  this.walletsList.getEmbeddedWallet()
4578
4600
  ]);
4579
4601
  switch (bridgeConnectionType) {
4580
4602
  case "http":
4581
- this.provider = yield BridgeProvider$1.fromStorage(this.dappSettings.storage);
4603
+ this.provider = yield BridgeProvider.fromStorage(this.dappSettings.storage);
4582
4604
  break;
4583
4605
  case "injected":
4584
- this.provider = yield InjectedProvider$1.fromStorage(this.dappSettings.storage);
4606
+ this.provider = yield InjectedProvider.fromStorage(this.dappSettings.storage);
4585
4607
  break;
4586
4608
  default:
4587
4609
  if (embeddedWallet) {
@@ -4595,21 +4617,21 @@ var __objRest = (source, exclude) => {
4595
4617
  });
4596
4618
  }
4597
4619
  sendTransaction(transaction) {
4598
- return __awaiter$8(this, void 0, void 0, function* () {
4620
+ return __awaiter(this, void 0, void 0, function* () {
4599
4621
  this.checkConnection();
4600
4622
  this.checkFeatureSupport("SendTransaction");
4601
- const { validUntil } = transaction, tx = __rest$1(transaction, ["validUntil"]);
4602
- const response = yield this.provider.sendRequest(sendTransactionParser$1.convertToRpcRequest(Object.assign(Object.assign({}, tx), { valid_until: validUntil })));
4603
- if (sendTransactionParser$1.isError(response)) {
4604
- 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);
4605
4627
  }
4606
- return sendTransactionParser$1.convertFromRpcResponse(response);
4628
+ return sendTransactionParser.convertFromRpcResponse(response);
4607
4629
  });
4608
4630
  }
4609
4631
  disconnect() {
4610
- return __awaiter$8(this, void 0, void 0, function* () {
4632
+ return __awaiter(this, void 0, void 0, function* () {
4611
4633
  if (!this.connected) {
4612
- throw new WalletNotConnectedError$1();
4634
+ throw new WalletNotConnectedError();
4613
4635
  }
4614
4636
  yield this.provider.disconnect();
4615
4637
  this.onWalletDisconnected();
@@ -4617,10 +4639,10 @@ var __objRest = (source, exclude) => {
4617
4639
  }
4618
4640
  createProvider(wallet) {
4619
4641
  let provider;
4620
- if (isWalletConnectionSourceJS$1(wallet)) {
4621
- provider = new InjectedProvider$1(wallet.jsBridgeKey);
4642
+ if (isWalletConnectionSourceJS(wallet)) {
4643
+ provider = new InjectedProvider(wallet.jsBridgeKey);
4622
4644
  } else {
4623
- provider = new BridgeProvider$1(this.dappSettings.storage, wallet);
4645
+ provider = new BridgeProvider(this.dappSettings.storage, wallet);
4624
4646
  }
4625
4647
  provider.listen(this.walletEventsListener.bind(this));
4626
4648
  return provider;
@@ -4660,7 +4682,7 @@ var __objRest = (source, exclude) => {
4660
4682
  this.wallet = wallet;
4661
4683
  }
4662
4684
  onWalletConnectError(connectEventError) {
4663
- const error = connectErrorsParser$1.parseError(connectEventError);
4685
+ const error = connectErrorsParser.parseError(connectEventError);
4664
4686
  this.statusChangeErrorSubscriptions.forEach((errorsHandler) => errorsHandler(error));
4665
4687
  console.debug(error);
4666
4688
  if (error instanceof ManifestNotFoundError$1 || error instanceof ManifestContentErrorError$1) {
@@ -4673,13 +4695,13 @@ var __objRest = (source, exclude) => {
4673
4695
  }
4674
4696
  checkConnection() {
4675
4697
  if (!this.connected) {
4676
- throw new WalletNotConnectedError$1();
4698
+ throw new WalletNotConnectedError();
4677
4699
  }
4678
4700
  }
4679
4701
  checkFeatureSupport(feature) {
4680
- var _a2;
4681
- if (!((_a2 = this.wallet) === null || _a2 === void 0 ? void 0 : _a2.device.features.includes(feature))) {
4682
- 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();
4683
4705
  }
4684
4706
  }
4685
4707
  createConnectRequest(request) {
@@ -4699,7 +4721,8 @@ var __objRest = (source, exclude) => {
4699
4721
  items
4700
4722
  };
4701
4723
  }
4702
- };
4724
+ }
4725
+ TonConnect.walletsList = new WalletsListManager();
4703
4726
  function toUserFriendlyAddress$1(hexAddress) {
4704
4727
  const { wc, hex } = parseHexAddress$1(hexAddress);
4705
4728
  const bounceableTag = 17;
@@ -6894,12 +6917,12 @@ var __objRest = (source, exclude) => {
6894
6917
  const classnames2 = createMemo(() => {
6895
6918
  const name = props.name || "s";
6896
6919
  return {
6897
- enterActiveClass: name + "-enter-active",
6898
- enterClass: name + "-enter",
6899
- enterToClass: name + "-enter-to",
6900
- exitActiveClass: name + "-exit-active",
6901
- exitClass: name + "-exit",
6902
- exitToClass: name + "-exit-to"
6920
+ enterActiveClass: props.enterActiveClass || name + "-enter-active",
6921
+ enterClass: props.enterClass || name + "-enter",
6922
+ enterToClass: props.enterToClass || name + "-enter-to",
6923
+ exitActiveClass: props.exitActiveClass || name + "-exit-active",
6924
+ exitClass: props.exitClass || name + "-exit",
6925
+ exitToClass: props.exitToClass || name + "-exit-to"
6903
6926
  };
6904
6927
  });
6905
6928
  function enterTransition(el2, prev) {
@@ -7011,13 +7034,13 @@ var __objRest = (source, exclude) => {
7011
7034
  const classnames2 = createMemo(() => {
7012
7035
  const name = props.name || "s";
7013
7036
  return {
7014
- enterActiveClass: name + "-enter-active",
7015
- enterClass: name + "-enter",
7016
- enterToClass: name + "-enter-to",
7017
- exitActiveClass: name + "-exit-active",
7018
- exitClass: name + "-exit",
7019
- exitToClass: name + "-exit-to",
7020
- moveClass: name + "-move"
7037
+ enterActiveClass: props.enterActiveClass || name + "-enter-active",
7038
+ enterClass: props.enterClass || name + "-enter",
7039
+ enterToClass: props.enterToClass || name + "-enter-to",
7040
+ exitActiveClass: props.exitActiveClass || name + "-exit-active",
7041
+ exitClass: props.exitClass || name + "-exit",
7042
+ exitToClass: props.exitToClass || name + "-exit-to",
7043
+ moveClass: props.moveClass || name + "-move"
7021
7044
  };
7022
7045
  });
7023
7046
  const {
@@ -7167,17 +7190,17 @@ var __objRest = (source, exclude) => {
7167
7190
  };
7168
7191
  function clickOutside$1(el, accessor) {
7169
7192
  const onClick = (e2) => {
7170
- var _a2;
7171
- 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());
7172
7195
  };
7173
7196
  document.body.addEventListener("click", onClick);
7174
7197
  onCleanup(() => document.body.removeEventListener("click", onClick));
7175
7198
  }
7176
7199
  function escPressed(_, accessor) {
7177
7200
  const onKeyPress = (e2) => {
7178
- var _a2, _b;
7201
+ var _a, _b;
7179
7202
  if (e2.key === "Escape") {
7180
- (_a2 = document.activeElement) == null ? void 0 : _a2.blur();
7203
+ (_a = document.activeElement) == null ? void 0 : _a.blur();
7181
7204
  (_b = accessor()) == null ? void 0 : _b();
7182
7205
  }
7183
7206
  };
@@ -7482,8 +7505,8 @@ var __objRest = (source, exclude) => {
7482
7505
  return props.class;
7483
7506
  },
7484
7507
  get children() {
7485
- var _a2;
7486
- 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;
7487
7510
  }
7488
7511
  });
7489
7512
  };
@@ -7508,8 +7531,8 @@ var __objRest = (source, exclude) => {
7508
7531
  return props.class;
7509
7532
  },
7510
7533
  get children() {
7511
- var _a2;
7512
- 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;
7513
7536
  }
7514
7537
  });
7515
7538
  };
@@ -7530,8 +7553,8 @@ var __objRest = (source, exclude) => {
7530
7553
  const [t2] = useI18n();
7531
7554
  return createComponent(H3Styled, {
7532
7555
  get children() {
7533
- var _a2;
7534
- 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;
7535
7558
  }
7536
7559
  });
7537
7560
  };
@@ -7574,8 +7597,8 @@ var __objRest = (source, exclude) => {
7574
7597
  return props.class;
7575
7598
  },
7576
7599
  get children() {
7577
- var _a2;
7578
- 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;
7579
7602
  }
7580
7603
  });
7581
7604
  };
@@ -7952,7 +7975,7 @@ var __objRest = (source, exclude) => {
7952
7975
  if (action2 && action2.showNotification) {
7953
7976
  lastId++;
7954
7977
  const id = lastId;
7955
- setOpenedNotifications((notifications2) => notifications2.concat({
7978
+ setOpenedNotifications((notifications2) => notifications2.filter((notification) => notification.action !== "confirm-transaction").concat({
7956
7979
  id,
7957
7980
  action: action2.name
7958
7981
  }));
@@ -8234,12 +8257,12 @@ var __objRest = (source, exclude) => {
8234
8257
  bottom: rect.y + rect.height
8235
8258
  });
8236
8259
  }
8237
- function getWindow$2(node) {
8260
+ function getWindow(node) {
8238
8261
  var _node$ownerDocument;
8239
8262
  return ((_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
8240
8263
  }
8241
8264
  function getComputedStyle(element) {
8242
- return getWindow$2(element).getComputedStyle(element);
8265
+ return getWindow(element).getComputedStyle(element);
8243
8266
  }
8244
8267
  function getNodeName(node) {
8245
8268
  return isNode$2(node) ? (node.nodeName || "").toLowerCase() : "";
@@ -8257,19 +8280,19 @@ var __objRest = (source, exclude) => {
8257
8280
  return navigator.userAgent;
8258
8281
  }
8259
8282
  function isHTMLElement(value) {
8260
- return value instanceof getWindow$2(value).HTMLElement;
8283
+ return value instanceof getWindow(value).HTMLElement;
8261
8284
  }
8262
8285
  function isElement(value) {
8263
- return value instanceof getWindow$2(value).Element;
8286
+ return value instanceof getWindow(value).Element;
8264
8287
  }
8265
8288
  function isNode$2(value) {
8266
- return value instanceof getWindow$2(value).Node;
8289
+ return value instanceof getWindow(value).Node;
8267
8290
  }
8268
8291
  function isShadowRoot(node) {
8269
8292
  if (typeof ShadowRoot === "undefined") {
8270
8293
  return false;
8271
8294
  }
8272
- const OwnElement = getWindow$2(node).ShadowRoot;
8295
+ const OwnElement = getWindow(node).ShadowRoot;
8273
8296
  return node instanceof OwnElement || node instanceof ShadowRoot;
8274
8297
  }
8275
8298
  function isOverflowElement(element) {
@@ -8356,7 +8379,7 @@ var __objRest = (source, exclude) => {
8356
8379
  scale = getScale(element);
8357
8380
  }
8358
8381
  }
8359
- const win = isElement(element) ? getWindow$2(element) : window;
8382
+ const win = isElement(element) ? getWindow(element) : window;
8360
8383
  const addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
8361
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;
8362
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;
@@ -8447,7 +8470,7 @@ var __objRest = (source, exclude) => {
8447
8470
  return null;
8448
8471
  }
8449
8472
  function getOffsetParent(element) {
8450
- const window2 = getWindow$2(element);
8473
+ const window2 = getWindow(element);
8451
8474
  let offsetParent = getTrueOffsetParent(element);
8452
8475
  while (offsetParent && isTableElement(offsetParent) && getComputedStyle(offsetParent).position === "static") {
8453
8476
  offsetParent = getTrueOffsetParent(offsetParent);
@@ -8512,7 +8535,7 @@ var __objRest = (source, exclude) => {
8512
8535
  };
8513
8536
  }
8514
8537
  function getViewportRect(element, strategy) {
8515
- const win = getWindow$2(element);
8538
+ const win = getWindow(element);
8516
8539
  const html = getDocumentElement(element);
8517
8540
  const visualViewport = win.visualViewport;
8518
8541
  let width = html.clientWidth;
@@ -8571,7 +8594,7 @@ var __objRest = (source, exclude) => {
8571
8594
  }
8572
8595
  const scrollableAncestor = getNearestOverflowAncestor(node);
8573
8596
  const isBody = scrollableAncestor === ((_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.body);
8574
- const win = getWindow$2(scrollableAncestor);
8597
+ const win = getWindow(scrollableAncestor);
8575
8598
  if (isBody) {
8576
8599
  return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : []);
8577
8600
  }
@@ -8941,8 +8964,8 @@ var __objRest = (source, exclude) => {
8941
8964
  }), null);
8942
8965
  insert(_el$, createComponent(NotificationsStyled, {}), null);
8943
8966
  createRenderEffect((_p$) => {
8944
- var _a2, _b;
8945
- 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`;
8946
8969
  _v$ !== _p$._v$ && _el$.style.setProperty("position", _p$._v$ = _v$);
8947
8970
  _v$2 !== _p$._v$2 && _el$.style.setProperty("top", _p$._v$2 = _v$2);
8948
8971
  _v$3 !== _p$._v$3 && _el$.style.setProperty("left", _p$._v$3 = _v$3);
@@ -10673,9 +10696,9 @@ var __objRest = (source, exclude) => {
10673
10696
  });
10674
10697
  };
10675
10698
  const Translation = (props) => {
10676
- var _a2;
10699
+ var _a;
10677
10700
  const [t2] = useI18n();
10678
- 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());
10679
10702
  };
10680
10703
  const QrCodeModalStyled = styled.div`
10681
10704
  padding: 0 24px;
@@ -10792,7 +10815,7 @@ var __objRest = (source, exclude) => {
10792
10815
  }
10793
10816
  }), createComponent(Show, {
10794
10817
  get when() {
10795
- return isWalletInfoInjected$1(props.wallet) && props.wallet.injected;
10818
+ return isWalletInfoInjected(props.wallet) && props.wallet.injected;
10796
10819
  },
10797
10820
  get children() {
10798
10821
  return createComponent(ActionButtonStyled, {
@@ -10984,8 +11007,8 @@ var __objRest = (source, exclude) => {
10984
11007
  };
10985
11008
  const ModalWrapper = styled.div`
10986
11009
  color: ${(props) => {
10987
- var _a2;
10988
- return ((_a2 = props.theme) == null ? void 0 : _a2.accentColor) || "blue";
11010
+ var _a;
11011
+ return ((_a = props.theme) == null ? void 0 : _a.accentColor) || "blue";
10989
11012
  }};
10990
11013
  `;
10991
11014
  const StyledModal = styled(Modal)`
@@ -11040,7 +11063,7 @@ var __objRest = (source, exclude) => {
11040
11063
  if (isDevice("mobile") && "universalLink" in walletInfo) {
11041
11064
  return onSelectIfMobile(walletInfo);
11042
11065
  }
11043
- if (isWalletInfoInjected$1(walletInfo) && walletInfo.injected) {
11066
+ if (isWalletInfoInjected(walletInfo) && walletInfo.injected) {
11044
11067
  return onSelectIfInjected(walletInfo);
11045
11068
  }
11046
11069
  setSelectedWalletInfo(walletInfo);
@@ -11063,18 +11086,6 @@ var __objRest = (source, exclude) => {
11063
11086
  }
11064
11087
  });
11065
11088
  onCleanup(unsubscribe);
11066
- createEffect(() => {
11067
- if (walletsList()) {
11068
- const embeddedWallet = walletsList().find((wallet) => "embedded" in wallet && wallet.embedded);
11069
- if (embeddedWallet) {
11070
- setLastSelectedWalletInfo(embeddedWallet);
11071
- connector.connect({
11072
- jsBridgeKey: embeddedWallet.jsBridgeKey
11073
- });
11074
- onClose();
11075
- }
11076
- }
11077
- });
11078
11089
  return createComponent(ModalWrapper, {
11079
11090
  get children() {
11080
11091
  return createComponent(StyledModal, {
@@ -11239,8 +11250,8 @@ var __objRest = (source, exclude) => {
11239
11250
  const ActionsModal = () => {
11240
11251
  return createComponent(Modal, {
11241
11252
  get opened() {
11242
- var _a2;
11243
- 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;
11244
11255
  },
11245
11256
  onClose: () => setAction(null),
11246
11257
  get children() {
@@ -11492,7 +11503,7 @@ var __objRest = (source, exclude) => {
11492
11503
  isMergeableObject: isPlainObject
11493
11504
  });
11494
11505
  }
11495
- class TonConnectUi {
11506
+ class TonConnectUI {
11496
11507
  constructor(options) {
11497
11508
  __publicField(this, "walletInfoStorage", new WalletInfoStorage());
11498
11509
  __publicField(this, "connector");
@@ -11501,7 +11512,7 @@ var __objRest = (source, exclude) => {
11501
11512
  if (options && "connector" in options && options.connector) {
11502
11513
  this.connector = options.connector;
11503
11514
  } else if (options && "manifestUrl" in options && options.manifestUrl) {
11504
- this.connector = new TonConnect$1({ manifestUrl: options.manifestUrl });
11515
+ this.connector = new TonConnect({ manifestUrl: options.manifestUrl });
11505
11516
  } else {
11506
11517
  throw new TonConnectUIError(
11507
11518
  "You have to specify a `manifestUrl` or a `connector` in the options."
@@ -11517,6 +11528,9 @@ var __objRest = (source, exclude) => {
11517
11528
  setAppState({ connector: this.connector });
11518
11529
  widgetController.renderApp(rootId, this);
11519
11530
  }
11531
+ static getWallets() {
11532
+ return TonConnect.getWallets();
11533
+ }
11520
11534
  get connected() {
11521
11535
  return this.connector.connected;
11522
11536
  }
@@ -11530,7 +11544,7 @@ var __objRest = (source, exclude) => {
11530
11544
  return this._walletInfo;
11531
11545
  }
11532
11546
  set uiOptions(options) {
11533
- var _a2;
11547
+ var _a;
11534
11548
  this.checkButtonRootExist(options.buttonRootId);
11535
11549
  if (options.theme === "SYSTEM") {
11536
11550
  setTheme(getSystemTheme());
@@ -11541,7 +11555,7 @@ var __objRest = (source, exclude) => {
11541
11555
  }
11542
11556
  } else {
11543
11557
  if (options.theme) {
11544
- (_a2 = this.systemThemeChangeUnsubscribe) == null ? void 0 : _a2.call(this);
11558
+ (_a = this.systemThemeChangeUnsubscribe) == null ? void 0 : _a.call(this);
11545
11559
  setTheme(options.theme);
11546
11560
  }
11547
11561
  }
@@ -11576,16 +11590,28 @@ var __objRest = (source, exclude) => {
11576
11590
  }, errorsHandler);
11577
11591
  }
11578
11592
  connectWallet() {
11579
- widgetController.openWalletsModal();
11580
- return new Promise((resolve, reject) => {
11581
- const unsubscribe = this.connector.onStatusChange((wallet) => {
11582
- unsubscribe();
11583
- if (wallet) {
11584
- resolve(wallet);
11585
- } else {
11586
- reject(new TonConnectUIError("Wallet was not connected"));
11587
- }
11588
- }, reject);
11593
+ return __async(this, null, function* () {
11594
+ const walletsList = yield this.getWallets();
11595
+ const embeddedWallet = walletsList.find(
11596
+ (wallet) => "embedded" in wallet && wallet.embedded
11597
+ );
11598
+ if (embeddedWallet) {
11599
+ setLastSelectedWalletInfo(embeddedWallet);
11600
+ this.connector.connect({ jsBridgeKey: embeddedWallet.jsBridgeKey });
11601
+ } else {
11602
+ widgetController.openWalletsModal();
11603
+ }
11604
+ return new Promise((resolve, reject) => {
11605
+ const unsubscribe = this.connector.onStatusChange((wallet) => {
11606
+ unsubscribe();
11607
+ if (wallet) {
11608
+ const lastSelectedWalletInfo2 = widgetController.getSelectedWalletInfo() || this.walletInfoStorage.getWalletInfo();
11609
+ resolve(__spreadValues(__spreadValues({}, wallet), lastSelectedWalletInfo2));
11610
+ } else {
11611
+ reject(new TonConnectUIError("Wallet was not connected"));
11612
+ }
11613
+ }, reject);
11614
+ });
11589
11615
  });
11590
11616
  }
11591
11617
  disconnect() {
@@ -11667,13 +11693,13 @@ var __objRest = (source, exclude) => {
11667
11693
  }
11668
11694
  }
11669
11695
  const TonConnectUIContext = require$$0$2.createContext(null);
11670
- const TonConnectUIProvider = (_a2) => {
11671
- var _b = _a2, {
11696
+ const TonConnectUIProvider = (_a) => {
11697
+ var _b = _a, {
11672
11698
  children: children2
11673
11699
  } = _b, options = __objRest(_b, [
11674
11700
  "children"
11675
11701
  ]);
11676
- const tonConnectUI = new TonConnectUi(options);
11702
+ const tonConnectUI = new TonConnectUI(options);
11677
11703
  return /* @__PURE__ */ jsx(TonConnectUIContext.Provider, { value: tonConnectUI, children: children2 });
11678
11704
  };
11679
11705
  const TonConnectUIProvider$1 = require$$0$2.memo(TonConnectUIProvider);
@@ -11714,10 +11740,15 @@ var __objRest = (source, exclude) => {
11714
11740
  const TonConnectButton$1 = require$$0$2.memo(TonConnectButton);
11715
11741
  function useTonWallet() {
11716
11742
  const [tonConnectUI] = useTonConnectUI();
11717
- const [wallet, setWallet] = require$$0$2.useState(null);
11718
- tonConnectUI.onStatusChange((value) => {
11719
- setWallet(value);
11720
- });
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
+ );
11721
11752
  return wallet;
11722
11753
  }
11723
11754
  class TonConnectError extends Error {
@@ -11730,12 +11761,6 @@ var __objRest = (source, exclude) => {
11730
11761
  }
11731
11762
  }
11732
11763
  TonConnectError.prefix = "[TON_CONNECT_SDK_ERROR]";
11733
- class DappMetadataError extends TonConnectError {
11734
- constructor(...args) {
11735
- super(...args);
11736
- Object.setPrototypeOf(this, DappMetadataError.prototype);
11737
- }
11738
- }
11739
11764
  class ManifestContentErrorError extends TonConnectError {
11740
11765
  constructor(message) {
11741
11766
  super(message || "" + ManifestContentErrorError.additionalMessage);
@@ -11750,27 +11775,6 @@ var __objRest = (source, exclude) => {
11750
11775
  }
11751
11776
  }
11752
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";
11753
- class WalletAlreadyConnectedError extends TonConnectError {
11754
- constructor(...args) {
11755
- super(...args);
11756
- Object.setPrototypeOf(this, WalletAlreadyConnectedError.prototype);
11757
- }
11758
- }
11759
- class WalletNotConnectedError extends TonConnectError {
11760
- constructor(...args) {
11761
- super(...args);
11762
- Object.setPrototypeOf(this, WalletNotConnectedError.prototype);
11763
- }
11764
- }
11765
- class WalletNotSupportFeatureError extends TonConnectError {
11766
- constructor(...args) {
11767
- super(...args);
11768
- Object.setPrototypeOf(this, WalletNotSupportFeatureError.prototype);
11769
- }
11770
- }
11771
- function isWalletConnectionSourceJS(value) {
11772
- return "jsBridgeKey" in value;
11773
- }
11774
11778
  class UserRejectsError extends TonConnectError {
11775
11779
  constructor(...args) {
11776
11780
  super(...args);
@@ -11789,24 +11793,6 @@ var __objRest = (source, exclude) => {
11789
11793
  Object.setPrototypeOf(this, UnknownAppError.prototype);
11790
11794
  }
11791
11795
  }
11792
- class WalletNotInjectedError extends TonConnectError {
11793
- constructor(...args) {
11794
- super(...args);
11795
- Object.setPrototypeOf(this, WalletNotInjectedError.prototype);
11796
- }
11797
- }
11798
- class LocalstorageNotFoundError extends TonConnectError {
11799
- constructor(...args) {
11800
- super(...args);
11801
- Object.setPrototypeOf(this, LocalstorageNotFoundError.prototype);
11802
- }
11803
- }
11804
- class FetchWalletsError extends TonConnectError {
11805
- constructor(...args) {
11806
- super(...args);
11807
- Object.setPrototypeOf(this, FetchWalletsError.prototype);
11808
- }
11809
- }
11810
11796
  class WrongAddressError extends TonConnectError {
11811
11797
  constructor(...args) {
11812
11798
  super(...args);
@@ -11921,9 +11907,9 @@ var __objRest = (source, exclude) => {
11921
11907
  return util;
11922
11908
  });
11923
11909
  })(naclUtil);
11924
- const nacl$1 = naclUtil.exports;
11910
+ const nacl = naclUtil.exports;
11925
11911
  function encodeUint8Array(value, urlSafe) {
11926
- const encoded = nacl$1.encodeBase64(value);
11912
+ const encoded = nacl.encodeBase64(value);
11927
11913
  if (!urlSafe) {
11928
11914
  return encoded;
11929
11915
  }
@@ -11933,7 +11919,7 @@ var __objRest = (source, exclude) => {
11933
11919
  if (urlSafe) {
11934
11920
  value = decodeURIComponent(value);
11935
11921
  }
11936
- return nacl$1.decodeBase64(value);
11922
+ return nacl.decodeBase64(value);
11937
11923
  }
11938
11924
  function encode(value, urlSafe = false) {
11939
11925
  let uint8Array;
@@ -11943,7 +11929,7 @@ var __objRest = (source, exclude) => {
11943
11929
  if (typeof value !== "string") {
11944
11930
  value = JSON.stringify(value);
11945
11931
  }
11946
- uint8Array = nacl$1.decodeUTF8(value);
11932
+ uint8Array = nacl.decodeUTF8(value);
11947
11933
  }
11948
11934
  return encodeUint8Array(uint8Array, urlSafe);
11949
11935
  }
@@ -11951,11 +11937,11 @@ var __objRest = (source, exclude) => {
11951
11937
  const decodedUint8Array = decodeToUint8Array(value, urlSafe);
11952
11938
  return {
11953
11939
  toString() {
11954
- return nacl$1.encodeUTF8(decodedUint8Array);
11940
+ return nacl.encodeUTF8(decodedUint8Array);
11955
11941
  },
11956
11942
  toObject() {
11957
11943
  try {
11958
- return JSON.parse(nacl$1.encodeUTF8(decodedUint8Array));
11944
+ return JSON.parse(nacl.encodeUTF8(decodedUint8Array));
11959
11945
  } catch (e2) {
11960
11946
  return null;
11961
11947
  }
@@ -11969,39 +11955,8 @@ var __objRest = (source, exclude) => {
11969
11955
  encode,
11970
11956
  decode
11971
11957
  };
11972
- function concatUint8Arrays(buffer1, buffer2) {
11973
- const mergedArray = new Uint8Array(buffer1.length + buffer2.length);
11974
- mergedArray.set(buffer1);
11975
- mergedArray.set(buffer2, buffer1.length);
11976
- return mergedArray;
11977
- }
11978
- function splitToUint8Arrays(array, index) {
11979
- if (index >= array.length) {
11980
- throw new Error("Index is out of buffer");
11981
- }
11982
- const subArray1 = array.slice(0, index);
11983
- const subArray2 = array.slice(index);
11984
- return [subArray1, subArray2];
11985
- }
11986
- function toHexString(byteArray) {
11987
- let hexString = "";
11988
- byteArray.forEach((byte) => {
11989
- hexString += ("0" + (byte & 255).toString(16)).slice(-2);
11990
- });
11991
- return hexString;
11992
- }
11993
- function hexToByteArray(hexString) {
11994
- if (hexString.length % 2 !== 0) {
11995
- throw new Error(`Cannot convert ${hexString} to bytesArray`);
11996
- }
11997
- const result = new Uint8Array(hexString.length / 2);
11998
- for (let i2 = 0; i2 < hexString.length; i2 += 2) {
11999
- result[i2 / 2] = parseInt(hexString.slice(i2, i2 + 2), 16);
12000
- }
12001
- return result;
12002
- }
12003
- function isNode() {
12004
- return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
11958
+ function isNode() {
11959
+ return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
12005
11960
  }
12006
11961
  function commonjsRequire(path) {
12007
11962
  throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
@@ -14309,104 +14264,27 @@ var __objRest = (source, exclude) => {
14309
14264
  })();
14310
14265
  })(module2.exports ? module2.exports : self.nacl = self.nacl || {});
14311
14266
  })(naclFast);
14312
- const nacl = naclFast.exports;
14313
14267
  if (isNode()) {
14314
14268
  try {
14315
14269
  eval("global.crypto = require('crypto').webcrypto");
14316
14270
  } catch (err) {
14317
14271
  }
14318
14272
  }
14319
- class SessionCrypto {
14320
- constructor(keyPair) {
14321
- this.nonceLength = 24;
14322
- this.keyPair = keyPair ? this.createKeypairFromString(keyPair) : this.createKeypair();
14323
- this.sessionId = toHexString(this.keyPair.publicKey);
14324
- }
14325
- createKeypair() {
14326
- return nacl.box.keyPair();
14327
- }
14328
- createKeypairFromString(keyPair) {
14329
- return {
14330
- publicKey: hexToByteArray(keyPair.publicKey),
14331
- secretKey: hexToByteArray(keyPair.secretKey)
14332
- };
14333
- }
14334
- createNonce() {
14335
- const buffer = new Uint8Array(this.nonceLength);
14336
- return crypto.getRandomValues(buffer);
14337
- }
14338
- encrypt(message, receiverPublicKey) {
14339
- const encodedMessage = new TextEncoder().encode(message);
14340
- const nonce = this.createNonce();
14341
- const encrypted = nacl.box(encodedMessage, nonce, receiverPublicKey, this.keyPair.secretKey);
14342
- return concatUint8Arrays(nonce, encrypted);
14343
- }
14344
- decrypt(message, senderPublicKey) {
14345
- const [nonce, internalMessage] = splitToUint8Arrays(message, this.nonceLength);
14346
- const decrypted = nacl.box.open(internalMessage, nonce, senderPublicKey, this.keyPair.secretKey);
14347
- if (!decrypted) {
14348
- throw new Error("Decryption error");
14349
- }
14350
- return new TextDecoder().decode(decrypted);
14351
- }
14352
- stringifyKeypair() {
14353
- return {
14354
- publicKey: toHexString(this.keyPair.publicKey),
14355
- secretKey: toHexString(this.keyPair.secretKey)
14356
- };
14357
- }
14358
- }
14359
- const connectEventErrorsCodes = {
14273
+ ({
14360
14274
  [CONNECT_EVENT_ERROR_CODES.UNKNOWN_ERROR]: UnknownError,
14361
14275
  [CONNECT_EVENT_ERROR_CODES.USER_REJECTS_ERROR]: UserRejectsError,
14362
14276
  [CONNECT_EVENT_ERROR_CODES.BAD_REQUEST_ERROR]: BadRequestError,
14363
14277
  [CONNECT_EVENT_ERROR_CODES.UNKNOWN_APP_ERROR]: UnknownAppError,
14364
14278
  [CONNECT_EVENT_ERROR_CODES.MANIFEST_NOT_FOUND_ERROR]: ManifestNotFoundError,
14365
14279
  [CONNECT_EVENT_ERROR_CODES.MANIFEST_CONTENT_ERROR]: ManifestContentErrorError
14366
- };
14367
- class ConnectErrorsParser {
14368
- parseError(error) {
14369
- let ErrorConstructor = UnknownError;
14370
- if (error.code in connectEventErrorsCodes) {
14371
- ErrorConstructor = connectEventErrorsCodes[error.code] || UnknownError;
14372
- }
14373
- return new ErrorConstructor(error.message);
14374
- }
14375
- }
14376
- const connectErrorsParser = new ConnectErrorsParser();
14377
- class RpcParser {
14378
- isError(response) {
14379
- return "error" in response;
14380
- }
14381
- }
14382
- const sendTransactionErrors = {
14280
+ });
14281
+ ({
14383
14282
  [SEND_TRANSACTION_ERROR_CODES.UNKNOWN_ERROR]: UnknownError,
14384
14283
  [SEND_TRANSACTION_ERROR_CODES.USER_REJECTS_ERROR]: UserRejectsError,
14385
14284
  [SEND_TRANSACTION_ERROR_CODES.BAD_REQUEST_ERROR]: BadRequestError,
14386
14285
  [SEND_TRANSACTION_ERROR_CODES.UNKNOWN_APP_ERROR]: UnknownAppError
14387
- };
14388
- class SendTransactionParser extends RpcParser {
14389
- convertToRpcRequest(request) {
14390
- return {
14391
- method: "sendTransaction",
14392
- params: [JSON.stringify(request)]
14393
- };
14394
- }
14395
- parseAndThrowError(response) {
14396
- let ErrorConstructor = UnknownError;
14397
- if (response.error.code in sendTransactionErrors) {
14398
- ErrorConstructor = sendTransactionErrors[response.error.code] || UnknownError;
14399
- }
14400
- throw new ErrorConstructor(response.error.message);
14401
- }
14402
- convertFromRpcResponse(rpcResponse) {
14403
- return {
14404
- boc: rpcResponse.result
14405
- };
14406
- }
14407
- }
14408
- const sendTransactionParser = new SendTransactionParser();
14409
- var __awaiter$7 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
14286
+ });
14287
+ globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
14410
14288
  function adopt(value) {
14411
14289
  return value instanceof P2 ? value : new P2(function(resolve) {
14412
14290
  resolve(value);
@@ -14433,41 +14311,7 @@ var __objRest = (source, exclude) => {
14433
14311
  step((generator = generator.apply(thisArg, _arguments || [])).next());
14434
14312
  });
14435
14313
  };
14436
- class HttpBridgeGatewayStorage {
14437
- constructor(storage) {
14438
- this.storage = storage;
14439
- this.storeKey = "ton-connect-storage_http-bridge-gateway";
14440
- }
14441
- storeLastEventId(lastEventId) {
14442
- return __awaiter$7(this, void 0, void 0, function* () {
14443
- return this.storage.setItem(this.storeKey, lastEventId);
14444
- });
14445
- }
14446
- removeLastEventId() {
14447
- return __awaiter$7(this, void 0, void 0, function* () {
14448
- return this.storage.removeItem(this.storeKey);
14449
- });
14450
- }
14451
- getLastEventId() {
14452
- return __awaiter$7(this, void 0, void 0, function* () {
14453
- const stored = yield this.storage.getItem(this.storeKey);
14454
- if (!stored) {
14455
- return null;
14456
- }
14457
- return stored;
14458
- });
14459
- }
14460
- }
14461
- function removeUrlLastSlash(url) {
14462
- if (url.slice(-1) === "/") {
14463
- return url.slice(0, -1);
14464
- }
14465
- return url;
14466
- }
14467
- function addPathToUrl(url, path) {
14468
- return removeUrlLastSlash(url) + "/" + path;
14469
- }
14470
- var __awaiter$6 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
14314
+ globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
14471
14315
  function adopt(value) {
14472
14316
  return value instanceof P2 ? value : new P2(function(resolve) {
14473
14317
  resolve(value);
@@ -14502,89 +14346,61 @@ var __objRest = (source, exclude) => {
14502
14346
  console.error(err);
14503
14347
  }
14504
14348
  }
14505
- class BridgeGateway {
14506
- constructor(storage, bridgeUrl, sessionId, listener, errorsListener) {
14507
- this.bridgeUrl = bridgeUrl;
14508
- this.sessionId = sessionId;
14509
- this.listener = listener;
14510
- this.errorsListener = errorsListener;
14511
- this.ssePath = "events";
14512
- this.postPath = "message";
14513
- this.heartbeatMessage = "heartbeat";
14514
- this.defaultTtl = 300;
14515
- this.isClosed = false;
14516
- this.bridgeGatewayStorage = new HttpBridgeGatewayStorage(storage);
14517
- }
14518
- registerSession() {
14519
- return __awaiter$6(this, void 0, void 0, function* () {
14520
- const url = new URL(addPathToUrl(this.bridgeUrl, this.ssePath));
14521
- url.searchParams.append("client_id", this.sessionId);
14522
- const lastEventId = yield this.bridgeGatewayStorage.getLastEventId();
14523
- if (lastEventId) {
14524
- url.searchParams.append("last_event_id", lastEventId);
14525
- }
14526
- this.eventSource = new EventSource(url.toString());
14527
- return new Promise((resolve, reject) => {
14528
- this.eventSource.onerror = reject;
14529
- this.eventSource.onopen = () => {
14530
- this.eventSource.onerror = this.errorsHandler.bind(this);
14531
- this.eventSource.onmessage = this.messagesHandler.bind(this);
14532
- resolve();
14533
- };
14534
- });
14535
- });
14536
- }
14537
- send(message, receiver, ttl) {
14538
- return __awaiter$6(this, void 0, void 0, function* () {
14539
- const url = new URL(addPathToUrl(this.bridgeUrl, this.postPath));
14540
- url.searchParams.append("client_id", this.sessionId);
14541
- url.searchParams.append("to", receiver);
14542
- url.searchParams.append("ttl", (ttl || this.defaultTtl).toString());
14543
- yield fetch(url, {
14544
- method: "post",
14545
- body: Base64.encode(message)
14546
- });
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);
14547
14353
  });
14548
14354
  }
14549
- close() {
14550
- var _a2;
14551
- this.isClosed = true;
14552
- (_a2 = this.eventSource) === null || _a2 === void 0 ? void 0 : _a2.close();
14553
- }
14554
- errorsHandler(e2) {
14555
- var _a2, _b;
14556
- if (!this.isClosed) {
14557
- if (((_a2 = this.eventSource) === null || _a2 === void 0 ? void 0 : _a2.readyState) === EventSource.CLOSED) {
14558
- this.eventSource.close();
14559
- this.registerSession();
14560
- 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);
14561
14361
  }
14562
- if (((_b = this.eventSource) === null || _b === void 0 ? void 0 : _b.readyState) === EventSource.CONNECTING) {
14563
- console.debug("[TON_CONNET_SDK_ERROR]: Bridge error", JSON.stringify(e2));
14564
- return;
14362
+ }
14363
+ function rejected(value) {
14364
+ try {
14365
+ step(generator["throw"](value));
14366
+ } catch (e2) {
14367
+ reject(e2);
14565
14368
  }
14566
- this.errorsListener(e2);
14567
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
+ });
14568
14381
  }
14569
- messagesHandler(e2) {
14570
- return __awaiter$6(this, void 0, void 0, function* () {
14571
- if (e2.data === this.heartbeatMessage) {
14572
- 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);
14573
14388
  }
14574
- yield this.bridgeGatewayStorage.storeLastEventId(e2.lastEventId);
14575
- if (!this.isClosed) {
14576
- let bridgeIncomingMessage;
14577
- try {
14578
- bridgeIncomingMessage = JSON.parse(e2.data);
14579
- } catch (e3) {
14580
- throw new TonConnectError(`Bridge message parse failed, message ${e3.data}`);
14581
- }
14582
- this.listener(bridgeIncomingMessage);
14389
+ }
14390
+ function rejected(value) {
14391
+ try {
14392
+ step(generator["throw"](value));
14393
+ } catch (e2) {
14394
+ reject(e2);
14583
14395
  }
14584
- });
14585
- }
14586
- }
14587
- var __awaiter$5 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
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) {
14588
14404
  function adopt(value) {
14589
14405
  return value instanceof P2 ? value : new P2(function(resolve) {
14590
14406
  resolve(value);
@@ -14611,93 +14427,34 @@ var __objRest = (source, exclude) => {
14611
14427
  step((generator = generator.apply(thisArg, _arguments || [])).next());
14612
14428
  });
14613
14429
  };
14614
- class BridgeConnectionStorage {
14615
- constructor(storage) {
14616
- this.storage = storage;
14617
- this.storeKey = "ton-connect-storage_bridge-connection";
14430
+ globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
14431
+ function adopt(value) {
14432
+ return value instanceof P2 ? value : new P2(function(resolve) {
14433
+ resolve(value);
14434
+ });
14618
14435
  }
14619
- storeConnection(connection) {
14620
- return __awaiter$5(this, void 0, void 0, function* () {
14621
- if (connection.type === "injected") {
14622
- return this.storage.setItem(this.storeKey, JSON.stringify(connection));
14623
- }
14624
- const rawSession = {
14625
- sessionKeyPair: connection.session.sessionCrypto.stringifyKeypair(),
14626
- walletPublicKey: connection.session.walletPublicKey,
14627
- walletConnectionSource: connection.session.walletConnectionSource
14628
- };
14629
- const rawConnection = {
14630
- type: "http",
14631
- connectEvent: connection.connectEvent,
14632
- session: rawSession
14633
- };
14634
- return this.storage.setItem(this.storeKey, JSON.stringify(rawConnection));
14635
- });
14636
- }
14637
- removeConnection() {
14638
- return __awaiter$5(this, void 0, void 0, function* () {
14639
- return this.storage.removeItem(this.storeKey);
14640
- });
14641
- }
14642
- getConnection() {
14643
- return __awaiter$5(this, void 0, void 0, function* () {
14644
- const stored = yield this.storage.getItem(this.storeKey);
14645
- if (!stored) {
14646
- return null;
14647
- }
14648
- const connection = JSON.parse(stored);
14649
- if (connection.type === "injected") {
14650
- return connection;
14651
- }
14652
- const sessionCrypto = new SessionCrypto(connection.session.sessionKeyPair);
14653
- return {
14654
- type: "http",
14655
- connectEvent: connection.connectEvent,
14656
- session: {
14657
- sessionCrypto,
14658
- walletConnectionSource: connection.session.walletConnectionSource,
14659
- walletPublicKey: connection.session.walletPublicKey
14660
- }
14661
- };
14662
- });
14663
- }
14664
- getHttpConnection() {
14665
- return __awaiter$5(this, void 0, void 0, function* () {
14666
- const connection = yield this.getConnection();
14667
- if (!connection) {
14668
- throw new TonConnectError("Trying to read HTTP connection source while nothing is stored");
14669
- }
14670
- if (connection.type === "injected") {
14671
- throw new TonConnectError("Trying to read HTTP connection source while injected connection is stored");
14672
- }
14673
- return connection;
14674
- });
14675
- }
14676
- getInjectedConnection() {
14677
- return __awaiter$5(this, void 0, void 0, function* () {
14678
- const connection = yield this.getConnection();
14679
- if (!connection) {
14680
- throw new TonConnectError("Trying to read Injected bridge connection source while nothing is stored");
14681
- }
14682
- if ((connection === null || connection === void 0 ? void 0 : connection.type) === "http") {
14683
- throw new TonConnectError("Trying to read Injected bridge connection source while HTTP connection is stored");
14436
+ return new (P2 || (P2 = Promise))(function(resolve, reject) {
14437
+ function fulfilled(value) {
14438
+ try {
14439
+ step(generator.next(value));
14440
+ } catch (e2) {
14441
+ reject(e2);
14684
14442
  }
14685
- return connection;
14686
- });
14687
- }
14688
- storedConnectionType() {
14689
- return __awaiter$5(this, void 0, void 0, function* () {
14690
- const stored = yield this.storage.getItem(this.storeKey);
14691
- if (!stored) {
14692
- return null;
14443
+ }
14444
+ function rejected(value) {
14445
+ try {
14446
+ step(generator["throw"](value));
14447
+ } catch (e2) {
14448
+ reject(e2);
14693
14449
  }
14694
- const connection = JSON.parse(stored);
14695
- return connection.type;
14696
- });
14697
- }
14698
- }
14699
- const PROTOCOL_VERSION = 2;
14700
- var __awaiter$4 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
14450
+ }
14451
+ function step(result) {
14452
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
14453
+ }
14454
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14455
+ });
14456
+ };
14457
+ globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
14701
14458
  function adopt(value) {
14702
14459
  return value instanceof P2 ? value : new P2(function(resolve) {
14703
14460
  resolve(value);
@@ -14724,149 +14481,7 @@ var __objRest = (source, exclude) => {
14724
14481
  step((generator = generator.apply(thisArg, _arguments || [])).next());
14725
14482
  });
14726
14483
  };
14727
- class BridgeProvider {
14728
- constructor(storage, walletConnectionSource) {
14729
- this.storage = storage;
14730
- this.walletConnectionSource = walletConnectionSource;
14731
- this.type = "http";
14732
- this.pendingRequests = /* @__PURE__ */ new Map();
14733
- this.nextRequestId = 0;
14734
- this.session = null;
14735
- this.bridge = null;
14736
- this.listeners = [];
14737
- this.connectionStorage = new BridgeConnectionStorage(storage);
14738
- }
14739
- static fromStorage(storage) {
14740
- return __awaiter$4(this, void 0, void 0, function* () {
14741
- const bridgeConnectionStorage = new BridgeConnectionStorage(storage);
14742
- const connection = yield bridgeConnectionStorage.getHttpConnection();
14743
- return new BridgeProvider(storage, connection.session.walletConnectionSource);
14744
- });
14745
- }
14746
- connect(message) {
14747
- var _a2;
14748
- (_a2 = this.bridge) === null || _a2 === void 0 ? void 0 : _a2.close();
14749
- const sessionCrypto = new SessionCrypto();
14750
- this.session = {
14751
- sessionCrypto,
14752
- walletConnectionSource: this.walletConnectionSource
14753
- };
14754
- this.bridge = new BridgeGateway(this.storage, this.walletConnectionSource.bridgeUrl, sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this));
14755
- this.bridge.registerSession();
14756
- return this.generateUniversalLink(message);
14757
- }
14758
- restoreConnection() {
14759
- var _a2;
14760
- return __awaiter$4(this, void 0, void 0, function* () {
14761
- (_a2 = this.bridge) === null || _a2 === void 0 ? void 0 : _a2.close();
14762
- const storedConnection = yield this.connectionStorage.getHttpConnection();
14763
- if (!storedConnection) {
14764
- return;
14765
- }
14766
- this.session = storedConnection.session;
14767
- this.bridge = new BridgeGateway(this.storage, this.walletConnectionSource.bridgeUrl, storedConnection.session.sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this));
14768
- yield this.bridge.registerSession();
14769
- this.listeners.forEach((listener) => listener(storedConnection.connectEvent));
14770
- });
14771
- }
14772
- sendRequest(request) {
14773
- return new Promise((resolve, reject) => {
14774
- const id = this.nextRequestId;
14775
- this.nextRequestId++;
14776
- if (!this.bridge || !this.session || !("walletPublicKey" in this.session)) {
14777
- throw new TonConnectError("Trying to send bridge request without session");
14778
- }
14779
- const encodedRequest = this.session.sessionCrypto.encrypt(JSON.stringify(Object.assign(Object.assign({}, request), { id })), hexToByteArray(this.session.walletPublicKey));
14780
- this.bridge.send(encodedRequest, this.session.walletPublicKey).catch(reject);
14781
- this.pendingRequests.set(id.toString(), resolve);
14782
- });
14783
- }
14784
- closeConnection() {
14785
- var _a2;
14786
- (_a2 = this.bridge) === null || _a2 === void 0 ? void 0 : _a2.close();
14787
- this.listeners = [];
14788
- this.session = null;
14789
- this.bridge = null;
14790
- }
14791
- disconnect() {
14792
- var _a2;
14793
- (_a2 = this.bridge) === null || _a2 === void 0 ? void 0 : _a2.close();
14794
- this.listeners = [];
14795
- return this.removeBridgeAndSession();
14796
- }
14797
- listen(callback) {
14798
- this.listeners.push(callback);
14799
- return () => this.listeners = this.listeners.filter((listener) => listener !== callback);
14800
- }
14801
- gatewayListener(bridgeIncomingMessage) {
14802
- return __awaiter$4(this, void 0, void 0, function* () {
14803
- const walletMessage = JSON.parse(this.session.sessionCrypto.decrypt(Base64.decode(bridgeIncomingMessage.message).toUint8Array(), hexToByteArray(bridgeIncomingMessage.from)));
14804
- if (!("event" in walletMessage)) {
14805
- const id = walletMessage.id.toString();
14806
- const resolve = this.pendingRequests.get(id);
14807
- if (!resolve) {
14808
- throw new TonConnectError(`Response id ${id} doesn't match any request's id`);
14809
- }
14810
- resolve(walletMessage);
14811
- this.pendingRequests.delete(id);
14812
- return;
14813
- }
14814
- if (walletMessage.event === "connect") {
14815
- yield this.updateSession(walletMessage, bridgeIncomingMessage.from);
14816
- }
14817
- if (walletMessage.event === "disconnect") {
14818
- yield this.removeBridgeAndSession();
14819
- }
14820
- this.listeners.forEach((listener) => listener(walletMessage));
14821
- });
14822
- }
14823
- gatewayErrorsListener(e2) {
14824
- return __awaiter$4(this, void 0, void 0, function* () {
14825
- throw new TonConnectError(`Bridge error ${JSON.stringify(e2)}`);
14826
- });
14827
- }
14828
- updateSession(connectEvent, walletPublicKey) {
14829
- return __awaiter$4(this, void 0, void 0, function* () {
14830
- this.session = Object.assign(Object.assign({}, this.session), { walletPublicKey });
14831
- const tonAddrItem = connectEvent.payload.items.find((item) => item.name === "ton_addr");
14832
- const connectEventToSave = Object.assign(Object.assign({}, connectEvent), { payload: Object.assign(Object.assign({}, connectEvent.payload), { items: [tonAddrItem] }) });
14833
- yield this.connectionStorage.storeConnection({
14834
- type: "http",
14835
- session: this.session,
14836
- connectEvent: connectEventToSave
14837
- });
14838
- });
14839
- }
14840
- removeBridgeAndSession() {
14841
- return __awaiter$4(this, void 0, void 0, function* () {
14842
- this.session = null;
14843
- this.bridge = null;
14844
- yield this.connectionStorage.removeConnection();
14845
- });
14846
- }
14847
- generateUniversalLink(message) {
14848
- const url = new URL(this.walletConnectionSource.universalLink);
14849
- url.searchParams.append("v", PROTOCOL_VERSION.toString());
14850
- url.searchParams.append("id", this.session.sessionCrypto.sessionId);
14851
- url.searchParams.append("r", JSON.stringify(message));
14852
- return url.toString();
14853
- }
14854
- }
14855
- function getWindow() {
14856
- if (typeof window === "undefined") {
14857
- return void 0;
14858
- }
14859
- return window;
14860
- }
14861
- function getWebPageManifest() {
14862
- var _a2;
14863
- const origin = (_a2 = getWindow()) === null || _a2 === void 0 ? void 0 : _a2.location.origin;
14864
- if (origin) {
14865
- return origin + "/tonconnect-manifest.json";
14866
- }
14867
- return "";
14868
- }
14869
- var __awaiter$3 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
14484
+ globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
14870
14485
  function adopt(value) {
14871
14486
  return value instanceof P2 ? value : new P2(function(resolve) {
14872
14487
  resolve(value);
@@ -14893,509 +14508,18 @@ var __objRest = (source, exclude) => {
14893
14508
  step((generator = generator.apply(thisArg, _arguments || [])).next());
14894
14509
  });
14895
14510
  };
14896
- class InjectedProvider {
14897
- constructor(injectedWalletKey) {
14898
- this.type = "injected";
14899
- this.unsubscribeCallback = null;
14900
- this.listenSubscriptions = false;
14901
- this.listeners = [];
14902
- const window2 = InjectedProvider.window;
14903
- if (!InjectedProvider.isWindowContainsWallet(window2, injectedWalletKey)) {
14904
- throw new WalletNotInjectedError();
14905
- }
14906
- this.injectedWallet = window2[injectedWalletKey].tonconnect;
14907
- }
14908
- static fromStorage(storage) {
14909
- return __awaiter$3(this, void 0, void 0, function* () {
14910
- const bridgeConnectionStorage = new BridgeConnectionStorage(storage);
14911
- const connection = yield bridgeConnectionStorage.getInjectedConnection();
14912
- return new InjectedProvider(connection.jsBridgeKey);
14913
- });
14914
- }
14915
- static isWalletInjected(injectedWalletKey) {
14916
- return InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey);
14917
- }
14918
- static isInsideWalletBrowser(injectedWalletKey) {
14919
- if (InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey)) {
14920
- return this.window[injectedWalletKey].tonconnect.isWalletBrowser;
14921
- }
14922
- return false;
14923
- }
14924
- static isWindowContainsWallet(window2, injectedWalletKey) {
14925
- return !!window2 && injectedWalletKey in window2 && typeof window2[injectedWalletKey] === "object" && "tonconnect" in window2[injectedWalletKey];
14926
- }
14927
- connect(message, auto = false) {
14928
- this.injectedWallet.connect(PROTOCOL_VERSION, message, auto).then((connectEvent) => {
14929
- if (connectEvent.event === "connect") {
14930
- this.makeSubscriptions();
14931
- this.listenSubscriptions = true;
14932
- }
14933
- this.listeners.forEach((listener) => listener(connectEvent));
14934
- }).catch((e2) => {
14935
- const connectEventError = {
14936
- event: "connect_error",
14937
- payload: {
14938
- code: 0,
14939
- message: e2 === null || e2 === void 0 ? void 0 : e2.toString()
14940
- }
14941
- };
14942
- this.listeners.forEach((listener) => listener(connectEventError));
14943
- });
14944
- }
14945
- restoreConnection() {
14946
- return __awaiter$3(this, void 0, void 0, function* () {
14947
- try {
14948
- const connectEvent = yield this.injectedWallet.restoreConnection();
14949
- if (connectEvent.event === "connect") {
14950
- this.makeSubscriptions();
14951
- this.listenSubscriptions = true;
14952
- this.listeners.forEach((listener) => listener(connectEvent));
14953
- }
14954
- } catch (e2) {
14955
- console.error(e2);
14956
- }
14957
- });
14958
- }
14959
- closeConnection() {
14960
- if (this.listenSubscriptions) {
14961
- this.injectedWallet.disconnect();
14962
- }
14963
- this.closeAllListeners();
14964
- }
14965
- disconnect() {
14966
- this.closeAllListeners();
14967
- this.injectedWallet.disconnect();
14968
- return Promise.resolve();
14969
- }
14970
- closeAllListeners() {
14971
- var _a2;
14972
- this.listenSubscriptions = false;
14973
- this.listeners = [];
14974
- (_a2 = this.unsubscribeCallback) === null || _a2 === void 0 ? void 0 : _a2.call(this);
14975
- }
14976
- listen(eventsCallback) {
14977
- this.listeners.push(eventsCallback);
14978
- return () => this.listeners = this.listeners.filter((listener) => listener !== eventsCallback);
14979
- }
14980
- sendRequest(request) {
14981
- return __awaiter$3(this, void 0, void 0, function* () {
14982
- return this.injectedWallet.send(Object.assign(Object.assign({}, request), { id: "0" }));
14983
- });
14984
- }
14985
- makeSubscriptions() {
14986
- this.unsubscribeCallback = this.injectedWallet.listen((e2) => {
14987
- if (this.listenSubscriptions) {
14988
- this.listeners.forEach((listener) => listener(e2));
14989
- }
14990
- if (e2.event === "disconnect") {
14991
- this.disconnect();
14992
- }
14993
- });
14994
- }
14995
- }
14996
- InjectedProvider.window = getWindow();
14997
- var __awaiter$2 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
14998
- function adopt(value) {
14999
- return value instanceof P2 ? value : new P2(function(resolve) {
15000
- resolve(value);
15001
- });
15002
- }
15003
- return new (P2 || (P2 = Promise))(function(resolve, reject) {
15004
- function fulfilled(value) {
15005
- try {
15006
- step(generator.next(value));
15007
- } catch (e2) {
15008
- reject(e2);
15009
- }
15010
- }
15011
- function rejected(value) {
15012
- try {
15013
- step(generator["throw"](value));
15014
- } catch (e2) {
15015
- reject(e2);
15016
- }
15017
- }
15018
- function step(result) {
15019
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
15020
- }
15021
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15022
- });
15023
- };
15024
- class DefaultStorage {
15025
- constructor() {
15026
- const window2 = getWindow();
15027
- if (!(window2 === null || window2 === void 0 ? void 0 : window2.localStorage)) {
15028
- throw new LocalstorageNotFoundError();
15029
- }
15030
- this.window = window2;
15031
- }
15032
- getItem(key) {
15033
- return __awaiter$2(this, void 0, void 0, function* () {
15034
- return Promise.resolve(this.window.localStorage.getItem(key));
15035
- });
15036
- }
15037
- removeItem(key) {
15038
- return __awaiter$2(this, void 0, void 0, function* () {
15039
- this.window.localStorage.removeItem(key);
15040
- return Promise.resolve();
15041
- });
15042
- }
15043
- setItem(key, value) {
15044
- this.window.localStorage.setItem(key, value);
15045
- return Promise.resolve();
15046
- }
15047
- }
15048
- function isWalletInfoInjected(value) {
15049
- return "jsBridgeKey" in value;
15050
- }
15051
- var __awaiter$1 = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
15052
- function adopt(value) {
15053
- return value instanceof P2 ? value : new P2(function(resolve) {
15054
- resolve(value);
15055
- });
15056
- }
15057
- return new (P2 || (P2 = Promise))(function(resolve, reject) {
15058
- function fulfilled(value) {
15059
- try {
15060
- step(generator.next(value));
15061
- } catch (e2) {
15062
- reject(e2);
15063
- }
15064
- }
15065
- function rejected(value) {
15066
- try {
15067
- step(generator["throw"](value));
15068
- } catch (e2) {
15069
- reject(e2);
15070
- }
15071
- }
15072
- function step(result) {
15073
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
15074
- }
15075
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15076
- });
15077
- };
15078
- class WalletsListManager {
15079
- constructor() {
15080
- this.walletsListCache = null;
15081
- this.walletsListSource = "https://raw.githubusercontent.com/ton-connect/wallets-list/main/wallets.json";
15082
- }
15083
- getWallets() {
15084
- return __awaiter$1(this, void 0, void 0, function* () {
15085
- if (!this.walletsListCache) {
15086
- this.walletsListCache = this.fetchWalletsList();
15087
- this.walletsListCache.catch(() => this.walletsListCache = null);
15088
- }
15089
- return this.walletsListCache;
15090
- });
15091
- }
15092
- getEmbeddedWallet() {
15093
- return __awaiter$1(this, void 0, void 0, function* () {
15094
- const walletsList = yield this.getWallets();
15095
- const injectedWallets = walletsList.filter(isWalletInfoInjected);
15096
- if (injectedWallets.length !== 1) {
15097
- return null;
15098
- }
15099
- return injectedWallets[0].embedded ? injectedWallets[0] : null;
15100
- });
15101
- }
15102
- fetchWalletsList() {
15103
- return __awaiter$1(this, void 0, void 0, function* () {
15104
- try {
15105
- const walletsResponse = yield fetch(this.walletsListSource);
15106
- const walletsList = yield walletsResponse.json();
15107
- if (!Array.isArray(walletsList) || !walletsList.every((wallet) => this.isCorrectWalletConfigDTO(wallet))) {
15108
- throw new FetchWalletsError("Wrong wallets list format");
15109
- }
15110
- return this.walletConfigDTOListToWalletConfigList(walletsList);
15111
- } catch (e2) {
15112
- throw new FetchWalletsError(e2);
15113
- }
15114
- });
15115
- }
15116
- walletConfigDTOListToWalletConfigList(walletConfigDTO) {
15117
- return walletConfigDTO.map((walletConfigDTO2) => {
15118
- const walletConfig = {
15119
- name: walletConfigDTO2.name,
15120
- imageUrl: walletConfigDTO2.image,
15121
- aboutUrl: walletConfigDTO2.about_url,
15122
- tondns: walletConfigDTO2.tondns
15123
- };
15124
- walletConfigDTO2.bridge.forEach((bridge) => {
15125
- if (bridge.type === "sse") {
15126
- walletConfig.bridgeUrl = bridge.url;
15127
- walletConfig.universalLink = walletConfigDTO2.universal_url;
15128
- walletConfig.deepLink = walletConfigDTO2.deepLink;
15129
- }
15130
- if (bridge.type === "js") {
15131
- const jsBridgeKey = bridge.key;
15132
- walletConfig.jsBridgeKey = jsBridgeKey;
15133
- walletConfig.injected = InjectedProvider.isWalletInjected(jsBridgeKey);
15134
- walletConfig.embedded = InjectedProvider.isInsideWalletBrowser(jsBridgeKey);
15135
- }
15136
- });
15137
- return walletConfig;
15138
- });
15139
- }
15140
- isCorrectWalletConfigDTO(value) {
15141
- if (!value || !(typeof value === "object")) {
15142
- return false;
15143
- }
15144
- const containsName = "name" in value;
15145
- const containsImage = "image" in value;
15146
- const containsAbout = "about_url" in value;
15147
- if (!containsName || !containsImage || !containsAbout) {
15148
- return false;
15149
- }
15150
- if (!("bridge" in value) || !Array.isArray(value.bridge) || !value.bridge.length) {
15151
- return false;
15152
- }
15153
- const bridge = value.bridge;
15154
- if (bridge.some((item) => !item || typeof item !== "object" || !("type" in item))) {
15155
- return false;
15156
- }
15157
- const sseBridge = bridge.find((item) => item.type === "sse");
15158
- if (sseBridge) {
15159
- if (!("url" in sseBridge) || !sseBridge.url || !value.universal_url) {
15160
- return false;
15161
- }
15162
- }
15163
- const jsBridge = bridge.find((item) => item.type === "js");
15164
- if (jsBridge) {
15165
- if (!("key" in jsBridge) || !jsBridge.key) {
15166
- return false;
15167
- }
15168
- }
15169
- return true;
15170
- }
15171
- }
15172
- var __awaiter = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P2, generator) {
15173
- function adopt(value) {
15174
- return value instanceof P2 ? value : new P2(function(resolve) {
15175
- resolve(value);
15176
- });
15177
- }
15178
- return new (P2 || (P2 = Promise))(function(resolve, reject) {
15179
- function fulfilled(value) {
15180
- try {
15181
- step(generator.next(value));
15182
- } catch (e2) {
15183
- reject(e2);
15184
- }
15185
- }
15186
- function rejected(value) {
15187
- try {
15188
- step(generator["throw"](value));
15189
- } catch (e2) {
15190
- reject(e2);
15191
- }
15192
- }
15193
- function step(result) {
15194
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
15195
- }
15196
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15197
- });
15198
- };
15199
- var __rest = globalThis && globalThis.__rest || function(s2, e2) {
15200
- var t2 = {};
15201
- for (var p2 in s2)
15202
- if (Object.prototype.hasOwnProperty.call(s2, p2) && e2.indexOf(p2) < 0)
15203
- t2[p2] = s2[p2];
15204
- if (s2 != null && typeof Object.getOwnPropertySymbols === "function")
15205
- for (var i2 = 0, p2 = Object.getOwnPropertySymbols(s2); i2 < p2.length; i2++) {
15206
- if (e2.indexOf(p2[i2]) < 0 && Object.prototype.propertyIsEnumerable.call(s2, p2[i2]))
15207
- 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]];
15208
14520
  }
15209
14521
  return t2;
15210
14522
  };
15211
- var _a;
15212
- class TonConnect {
15213
- constructor(options) {
15214
- this.walletsList = new WalletsListManager();
15215
- this._wallet = null;
15216
- this.provider = null;
15217
- this.statusChangeSubscriptions = [];
15218
- this.statusChangeErrorSubscriptions = [];
15219
- this.dappSettings = {
15220
- manifestUrl: (options === null || options === void 0 ? void 0 : options.manifestUrl) || getWebPageManifest(),
15221
- storage: (options === null || options === void 0 ? void 0 : options.storage) || new DefaultStorage()
15222
- };
15223
- if (!this.dappSettings.manifestUrl) {
15224
- 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");
15225
- }
15226
- this.bridgeConnectionStorage = new BridgeConnectionStorage(this.dappSettings.storage);
15227
- }
15228
- get connected() {
15229
- return this._wallet !== null;
15230
- }
15231
- get account() {
15232
- var _b;
15233
- return ((_b = this._wallet) === null || _b === void 0 ? void 0 : _b.account) || null;
15234
- }
15235
- get wallet() {
15236
- return this._wallet;
15237
- }
15238
- set wallet(value) {
15239
- this._wallet = value;
15240
- this.statusChangeSubscriptions.forEach((callback) => callback(this._wallet));
15241
- }
15242
- getWallets() {
15243
- return this.walletsList.getWallets();
15244
- }
15245
- onStatusChange(callback, errorsHandler) {
15246
- this.statusChangeSubscriptions.push(callback);
15247
- if (errorsHandler) {
15248
- this.statusChangeErrorSubscriptions.push(errorsHandler);
15249
- }
15250
- return () => {
15251
- this.statusChangeSubscriptions = this.statusChangeSubscriptions.filter((item) => item !== callback);
15252
- if (errorsHandler) {
15253
- this.statusChangeErrorSubscriptions = this.statusChangeErrorSubscriptions.filter((item) => item !== errorsHandler);
15254
- }
15255
- };
15256
- }
15257
- connect(wallet, request) {
15258
- var _b;
15259
- if (this.connected) {
15260
- throw new WalletAlreadyConnectedError();
15261
- }
15262
- (_b = this.provider) === null || _b === void 0 ? void 0 : _b.closeConnection();
15263
- this.provider = this.createProvider(wallet);
15264
- return this.provider.connect(this.createConnectRequest(request));
15265
- }
15266
- restoreConnection() {
15267
- return __awaiter(this, void 0, void 0, function* () {
15268
- const [bridgeConnectionType, embeddedWallet] = yield Promise.all([
15269
- this.bridgeConnectionStorage.storedConnectionType(),
15270
- this.walletsList.getEmbeddedWallet()
15271
- ]);
15272
- switch (bridgeConnectionType) {
15273
- case "http":
15274
- this.provider = yield BridgeProvider.fromStorage(this.dappSettings.storage);
15275
- break;
15276
- case "injected":
15277
- this.provider = yield InjectedProvider.fromStorage(this.dappSettings.storage);
15278
- break;
15279
- default:
15280
- if (embeddedWallet) {
15281
- this.provider = yield this.createProvider(embeddedWallet);
15282
- } else {
15283
- return;
15284
- }
15285
- }
15286
- this.provider.listen(this.walletEventsListener.bind(this));
15287
- return this.provider.restoreConnection();
15288
- });
15289
- }
15290
- sendTransaction(transaction) {
15291
- return __awaiter(this, void 0, void 0, function* () {
15292
- this.checkConnection();
15293
- this.checkFeatureSupport("SendTransaction");
15294
- const { validUntil } = transaction, tx = __rest(transaction, ["validUntil"]);
15295
- const response = yield this.provider.sendRequest(sendTransactionParser.convertToRpcRequest(Object.assign(Object.assign({}, tx), { valid_until: validUntil })));
15296
- if (sendTransactionParser.isError(response)) {
15297
- return sendTransactionParser.parseAndThrowError(response);
15298
- }
15299
- return sendTransactionParser.convertFromRpcResponse(response);
15300
- });
15301
- }
15302
- disconnect() {
15303
- return __awaiter(this, void 0, void 0, function* () {
15304
- if (!this.connected) {
15305
- throw new WalletNotConnectedError();
15306
- }
15307
- yield this.provider.disconnect();
15308
- this.onWalletDisconnected();
15309
- });
15310
- }
15311
- createProvider(wallet) {
15312
- let provider;
15313
- if (isWalletConnectionSourceJS(wallet)) {
15314
- provider = new InjectedProvider(wallet.jsBridgeKey);
15315
- } else {
15316
- provider = new BridgeProvider(this.dappSettings.storage, wallet);
15317
- }
15318
- provider.listen(this.walletEventsListener.bind(this));
15319
- return provider;
15320
- }
15321
- walletEventsListener(e2) {
15322
- switch (e2.event) {
15323
- case "connect":
15324
- this.onWalletConnected(e2.payload);
15325
- break;
15326
- case "connect_error":
15327
- this.onWalletConnectError(e2.payload);
15328
- break;
15329
- case "disconnect":
15330
- this.onWalletDisconnected();
15331
- }
15332
- }
15333
- onWalletConnected(connectEvent) {
15334
- const tonAccountItem = connectEvent.items.find((item) => item.name === "ton_addr");
15335
- const tonProofItem = connectEvent.items.find((item) => item.name === "ton_proof");
15336
- if (!tonAccountItem) {
15337
- throw new TonConnectError("ton_addr connection item was not found");
15338
- }
15339
- const wallet = {
15340
- device: connectEvent.device,
15341
- provider: this.provider.type,
15342
- account: {
15343
- address: tonAccountItem.address,
15344
- chain: tonAccountItem.network,
15345
- walletStateInit: tonAccountItem.walletStateInit
15346
- }
15347
- };
15348
- if (tonProofItem) {
15349
- wallet.connectItems = {
15350
- tonProof: tonProofItem
15351
- };
15352
- }
15353
- this.wallet = wallet;
15354
- }
15355
- onWalletConnectError(connectEventError) {
15356
- const error = connectErrorsParser.parseError(connectEventError);
15357
- this.statusChangeErrorSubscriptions.forEach((errorsHandler) => errorsHandler(error));
15358
- console.debug(error);
15359
- if (error instanceof ManifestNotFoundError || error instanceof ManifestContentErrorError) {
15360
- console.error(error);
15361
- throw error;
15362
- }
15363
- }
15364
- onWalletDisconnected() {
15365
- this.wallet = null;
15366
- }
15367
- checkConnection() {
15368
- if (!this.connected) {
15369
- throw new WalletNotConnectedError();
15370
- }
15371
- }
15372
- checkFeatureSupport(feature) {
15373
- var _b;
15374
- if (!((_b = this.wallet) === null || _b === void 0 ? void 0 : _b.device.features.includes(feature))) {
15375
- throw new WalletNotSupportFeatureError();
15376
- }
15377
- }
15378
- createConnectRequest(request) {
15379
- const items = [
15380
- {
15381
- name: "ton_addr"
15382
- }
15383
- ];
15384
- if (request === null || request === void 0 ? void 0 : request.tonProof) {
15385
- items.push({
15386
- name: "ton_proof",
15387
- payload: request.tonProof
15388
- });
15389
- }
15390
- return {
15391
- manifestUrl: this.dappSettings.manifestUrl,
15392
- items
15393
- };
15394
- }
15395
- }
15396
- _a = TonConnect;
15397
- TonConnect.walletsList = new WalletsListManager();
15398
- TonConnect.getWallets = _a.walletsList.getWallets();
15399
14523
  function toUserFriendlyAddress(hexAddress) {
15400
14524
  const { wc, hex } = parseHexAddress(hexAddress);
15401
14525
  const bounceableTag = 17;
@@ -15488,9 +14612,9 @@ var __objRest = (source, exclude) => {
15488
14612
  exports.THEME = THEME;
15489
14613
  exports.TonConnectButton = TonConnectButton$1;
15490
14614
  exports.TonConnectProviderNotSetError = TonConnectProviderNotSetError;
14615
+ exports.TonConnectUI = TonConnectUI;
15491
14616
  exports.TonConnectUIError = TonConnectUIError;
15492
14617
  exports.TonConnectUIProvider = TonConnectUIProvider$1;
15493
- exports.TonConnectUi = TonConnectUi;
15494
14618
  exports.TonConnectUiReactError = TonConnectUiReactError;
15495
14619
  exports.useTonAddress = useTonAddress;
15496
14620
  exports.useTonConnectUI = useTonConnectUI;