@tonconnect/sdk 0.0.21 → 0.0.22

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.
Files changed (31) hide show
  1. package/lib/errors/dapp/dapp-metadata.error.js +6 -14
  2. package/lib/errors/index.js +18 -5
  3. package/lib/errors/protocol/events/connect/user-rejects.error.js +6 -14
  4. package/lib/errors/protocol/events/index.js +15 -2
  5. package/lib/errors/protocol/index.js +16 -3
  6. package/lib/errors/protocol/responses/bad-request.error.js +6 -14
  7. package/lib/errors/protocol/responses/unknown-app.error.js +6 -14
  8. package/lib/errors/storage/localstorage-not-found.error.js +6 -14
  9. package/lib/errors/ton-connect.error.js +5 -13
  10. package/lib/errors/unknown.error.js +6 -14
  11. package/lib/errors/wallet/wallet-already-connected.error.js +6 -14
  12. package/lib/errors/wallet/wallet-not-connected.error.js +6 -14
  13. package/lib/errors/wallet/wallet-not-injected.error.js +6 -14
  14. package/lib/errors/wallets-manager/fetch-wallets.error.js +6 -14
  15. package/lib/index.js +17 -4
  16. package/lib/models/index.js +16 -3
  17. package/lib/models/methods/index.js +16 -3
  18. package/lib/parsers/connect-errors-parser.js +14 -18
  19. package/lib/parsers/rpc-parser.js +4 -7
  20. package/lib/parsers/send-transaction-parser.js +19 -26
  21. package/lib/provider/bridge/bridge-gateway.js +60 -79
  22. package/lib/provider/bridge/bridge-provider.js +118 -138
  23. package/lib/provider/injected/injected-provider.js +93 -89
  24. package/lib/storage/bridge-connection-storage.js +86 -112
  25. package/lib/storage/default-storage.js +24 -21
  26. package/lib/storage/http-bridge-gateway-storage.js +28 -32
  27. package/lib/ton-connect.js +123 -165
  28. package/lib/utils/options.js +5 -5
  29. package/lib/utils/web-api.js +10 -10
  30. package/lib/wallets-list-manager.js +59 -73
  31. package/package.json +2 -2
@@ -1,143 +1,147 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
2
34
  Object.defineProperty(exports, "__esModule", { value: true });
3
35
  exports.InjectedProvider = void 0;
4
- var tslib_1 = require("tslib");
5
- var wallet_not_injected_error_1 = require("../../errors/wallet/wallet-not-injected.error");
6
- var protocol = tslib_1.__importStar(require("../../resources/protocol.json"));
7
- var bridge_connection_storage_1 = require("../../storage/bridge-connection-storage");
8
- var InjectedProvider = /** @class */ (function () {
9
- function InjectedProvider(injectedWalletKey) {
36
+ const wallet_not_injected_error_1 = require("../../errors/wallet/wallet-not-injected.error");
37
+ const protocol = __importStar(require("../../resources/protocol.json"));
38
+ const bridge_connection_storage_1 = require("../../storage/bridge-connection-storage");
39
+ class InjectedProvider {
40
+ constructor(injectedWalletKey) {
10
41
  this.type = 'injected';
11
42
  this.unsubscribeCallback = null;
12
43
  this.listenSubscriptions = false;
13
44
  this.listeners = [];
14
- var window = InjectedProvider.window;
45
+ const window = InjectedProvider.window;
15
46
  if (!InjectedProvider.isWindowContainsWallet(window, injectedWalletKey)) {
16
47
  throw new wallet_not_injected_error_1.WalletNotInjectedError();
17
48
  }
18
49
  this.injectedWallet = window[injectedWalletKey].tonconnect;
19
50
  }
20
- InjectedProvider.fromStorage = function (storage) {
21
- return tslib_1.__awaiter(this, void 0, void 0, function () {
22
- var bridgeConnectionStorage, connection;
23
- return tslib_1.__generator(this, function (_a) {
24
- switch (_a.label) {
25
- case 0:
26
- bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(storage);
27
- return [4 /*yield*/, bridgeConnectionStorage.getInjectedConnection()];
28
- case 1:
29
- connection = _a.sent();
30
- return [2 /*return*/, new InjectedProvider(connection.jsBridgeKey)];
31
- }
32
- });
51
+ static fromStorage(storage) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(storage);
54
+ const connection = yield bridgeConnectionStorage.getInjectedConnection();
55
+ return new InjectedProvider(connection.jsBridgeKey);
33
56
  });
34
- };
35
- InjectedProvider.isWalletInjected = function (injectedWalletKey) {
57
+ }
58
+ static isWalletInjected(injectedWalletKey) {
36
59
  return InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey);
37
- };
38
- InjectedProvider.isInsideWalletBrowser = function (injectedWalletKey) {
60
+ }
61
+ static isInsideWalletBrowser(injectedWalletKey) {
39
62
  if (InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey)) {
40
63
  return this.window[injectedWalletKey].tonconnect.isWalletBrowser;
41
64
  }
42
65
  return false;
43
- };
44
- InjectedProvider.isWindowContainsWallet = function (window, injectedWalletKey) {
66
+ }
67
+ static isWindowContainsWallet(window, injectedWalletKey) {
45
68
  return (window &&
46
69
  injectedWalletKey in window &&
47
70
  typeof window[injectedWalletKey] === 'object' &&
48
71
  'tonconnect' in window[injectedWalletKey]);
49
- };
50
- InjectedProvider.prototype.connect = function (message, auto) {
51
- var _this = this;
52
- if (auto === void 0) { auto = false; }
72
+ }
73
+ connect(message, auto = false) {
53
74
  this.injectedWallet
54
75
  .connect(protocol.version, message, auto)
55
- .then(function (connectEvent) {
76
+ .then(connectEvent => {
56
77
  if (connectEvent.event === 'connect') {
57
- _this.makeSubscriptions();
58
- _this.listenSubscriptions = true;
78
+ this.makeSubscriptions();
79
+ this.listenSubscriptions = true;
59
80
  }
60
- _this.listeners.forEach(function (listener) { return listener(connectEvent); });
81
+ this.listeners.forEach(listener => listener(connectEvent));
61
82
  })
62
- .catch(function (e) {
63
- var connectEventError = {
83
+ .catch(e => {
84
+ const connectEventError = {
64
85
  event: 'connect_error',
65
86
  payload: {
66
87
  code: 0,
67
88
  message: e === null || e === void 0 ? void 0 : e.toString()
68
89
  }
69
90
  };
70
- _this.listeners.forEach(function (listener) { return listener(connectEventError); });
91
+ this.listeners.forEach(listener => listener(connectEventError));
71
92
  });
72
- };
73
- InjectedProvider.prototype.restoreConnection = function () {
74
- return tslib_1.__awaiter(this, void 0, void 0, function () {
75
- var connectEvent_1, e_1;
76
- return tslib_1.__generator(this, function (_a) {
77
- switch (_a.label) {
78
- case 0:
79
- _a.trys.push([0, 2, , 3]);
80
- return [4 /*yield*/, this.injectedWallet.restoreConnection()];
81
- case 1:
82
- connectEvent_1 = _a.sent();
83
- if (connectEvent_1.event === 'connect') {
84
- this.makeSubscriptions();
85
- this.listenSubscriptions = true;
86
- this.listeners.forEach(function (listener) { return listener(connectEvent_1); });
87
- }
88
- return [3 /*break*/, 3];
89
- case 2:
90
- e_1 = _a.sent();
91
- console.error(e_1);
92
- return [3 /*break*/, 3];
93
- case 3: return [2 /*return*/];
93
+ }
94
+ restoreConnection() {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ try {
97
+ const connectEvent = yield this.injectedWallet.restoreConnection();
98
+ if (connectEvent.event === 'connect') {
99
+ this.makeSubscriptions();
100
+ this.listenSubscriptions = true;
101
+ this.listeners.forEach(listener => listener(connectEvent));
94
102
  }
95
- });
103
+ }
104
+ catch (e) {
105
+ console.error(e);
106
+ }
96
107
  });
97
- };
98
- InjectedProvider.prototype.closeConnection = function () {
108
+ }
109
+ closeConnection() {
99
110
  if (this.listenSubscriptions) {
100
111
  this.injectedWallet.disconnect();
101
112
  }
102
113
  this.closeAllListeners();
103
- };
104
- InjectedProvider.prototype.disconnect = function () {
114
+ }
115
+ disconnect() {
105
116
  this.closeAllListeners();
106
117
  this.injectedWallet.disconnect();
107
118
  return Promise.resolve();
108
- };
109
- InjectedProvider.prototype.closeAllListeners = function () {
119
+ }
120
+ closeAllListeners() {
110
121
  var _a;
111
122
  this.listenSubscriptions = false;
112
123
  this.listeners = [];
113
124
  (_a = this.unsubscribeCallback) === null || _a === void 0 ? void 0 : _a.call(this);
114
- };
115
- InjectedProvider.prototype.listen = function (eventsCallback) {
116
- var _this = this;
125
+ }
126
+ listen(eventsCallback) {
117
127
  this.listeners.push(eventsCallback);
118
- return function () {
119
- return (_this.listeners = _this.listeners.filter(function (listener) { return listener !== eventsCallback; }));
120
- };
121
- };
122
- InjectedProvider.prototype.sendRequest = function (request) {
123
- return tslib_1.__awaiter(this, void 0, void 0, function () {
124
- return tslib_1.__generator(this, function (_a) {
125
- return [2 /*return*/, this.injectedWallet.send(tslib_1.__assign(tslib_1.__assign({}, request), { id: '0' }))];
126
- });
128
+ return () => (this.listeners = this.listeners.filter(listener => listener !== eventsCallback));
129
+ }
130
+ sendRequest(request) {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ return this.injectedWallet.send(Object.assign(Object.assign({}, request), { id: '0' }));
127
133
  });
128
- };
129
- InjectedProvider.prototype.makeSubscriptions = function () {
130
- var _this = this;
131
- this.unsubscribeCallback = this.injectedWallet.listen(function (e) {
132
- if (_this.listenSubscriptions) {
133
- _this.listeners.forEach(function (listener) { return listener(e); });
134
+ }
135
+ makeSubscriptions() {
136
+ this.unsubscribeCallback = this.injectedWallet.listen(e => {
137
+ if (this.listenSubscriptions) {
138
+ this.listeners.forEach(listener => listener(e));
134
139
  }
135
140
  if (e.event === 'disconnect') {
136
- _this.disconnect();
141
+ this.disconnect();
137
142
  }
138
143
  });
139
- };
140
- InjectedProvider.window = window;
141
- return InjectedProvider;
142
- }());
144
+ }
145
+ }
143
146
  exports.InjectedProvider = InjectedProvider;
147
+ InjectedProvider.window = window;
@@ -1,126 +1,100 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.BridgeConnectionStorage = void 0;
4
- var tslib_1 = require("tslib");
5
- var protocol_1 = require("@tonconnect/protocol");
6
- var errors_1 = require("../errors");
7
- var BridgeConnectionStorage = /** @class */ (function () {
8
- function BridgeConnectionStorage(storage) {
13
+ const protocol_1 = require("@tonconnect/protocol");
14
+ const errors_1 = require("../errors");
15
+ class BridgeConnectionStorage {
16
+ constructor(storage) {
9
17
  this.storage = storage;
10
18
  this.storeKey = 'ton-connect-storage_bridge-connection';
11
19
  }
12
- BridgeConnectionStorage.prototype.storeConnection = function (connection) {
13
- return tslib_1.__awaiter(this, void 0, void 0, function () {
14
- var rawSession, rawConnection;
15
- return tslib_1.__generator(this, function (_a) {
16
- if (connection.type === 'injected') {
17
- return [2 /*return*/, this.storage.setItem(this.storeKey, JSON.stringify(connection))];
18
- }
19
- rawSession = {
20
- sessionKeyPair: connection.session.sessionCrypto.stringifyKeypair(),
21
- walletPublicKey: connection.session.walletPublicKey,
22
- walletConnectionSource: connection.session.walletConnectionSource
23
- };
24
- rawConnection = {
25
- type: 'http',
26
- connectEvent: connection.connectEvent,
27
- session: rawSession
28
- };
29
- return [2 /*return*/, this.storage.setItem(this.storeKey, JSON.stringify(rawConnection))];
30
- });
20
+ storeConnection(connection) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ if (connection.type === 'injected') {
23
+ return this.storage.setItem(this.storeKey, JSON.stringify(connection));
24
+ }
25
+ const rawSession = {
26
+ sessionKeyPair: connection.session.sessionCrypto.stringifyKeypair(),
27
+ walletPublicKey: connection.session.walletPublicKey,
28
+ walletConnectionSource: connection.session.walletConnectionSource
29
+ };
30
+ const rawConnection = {
31
+ type: 'http',
32
+ connectEvent: connection.connectEvent,
33
+ session: rawSession
34
+ };
35
+ return this.storage.setItem(this.storeKey, JSON.stringify(rawConnection));
31
36
  });
32
- };
33
- BridgeConnectionStorage.prototype.removeConnection = function () {
34
- return tslib_1.__awaiter(this, void 0, void 0, function () {
35
- return tslib_1.__generator(this, function (_a) {
36
- return [2 /*return*/, this.storage.removeItem(this.storeKey)];
37
- });
37
+ }
38
+ removeConnection() {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return this.storage.removeItem(this.storeKey);
38
41
  });
39
- };
40
- BridgeConnectionStorage.prototype.getConnection = function () {
41
- return tslib_1.__awaiter(this, void 0, void 0, function () {
42
- var stored, connection, sessionCrypto;
43
- return tslib_1.__generator(this, function (_a) {
44
- switch (_a.label) {
45
- case 0: return [4 /*yield*/, this.storage.getItem(this.storeKey)];
46
- case 1:
47
- stored = _a.sent();
48
- if (!stored) {
49
- return [2 /*return*/, null];
50
- }
51
- connection = JSON.parse(stored);
52
- if (connection.type === 'injected') {
53
- return [2 /*return*/, connection];
54
- }
55
- sessionCrypto = new protocol_1.SessionCrypto(connection.session.sessionKeyPair);
56
- return [2 /*return*/, {
57
- type: 'http',
58
- connectEvent: connection.connectEvent,
59
- session: {
60
- sessionCrypto: sessionCrypto,
61
- walletConnectionSource: connection.session.walletConnectionSource,
62
- walletPublicKey: connection.session.walletPublicKey
63
- }
64
- }];
42
+ }
43
+ getConnection() {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const stored = yield this.storage.getItem(this.storeKey);
46
+ if (!stored) {
47
+ return null;
48
+ }
49
+ const connection = JSON.parse(stored);
50
+ if (connection.type === 'injected') {
51
+ return connection;
52
+ }
53
+ const sessionCrypto = new protocol_1.SessionCrypto(connection.session.sessionKeyPair);
54
+ return {
55
+ type: 'http',
56
+ connectEvent: connection.connectEvent,
57
+ session: {
58
+ sessionCrypto,
59
+ walletConnectionSource: connection.session.walletConnectionSource,
60
+ walletPublicKey: connection.session.walletPublicKey
65
61
  }
66
- });
62
+ };
67
63
  });
68
- };
69
- BridgeConnectionStorage.prototype.getHttpConnection = function () {
70
- return tslib_1.__awaiter(this, void 0, void 0, function () {
71
- var connection;
72
- return tslib_1.__generator(this, function (_a) {
73
- switch (_a.label) {
74
- case 0: return [4 /*yield*/, this.getConnection()];
75
- case 1:
76
- connection = _a.sent();
77
- if (!connection) {
78
- throw new errors_1.TonConnectError('Trying to read HTTP connection source while nothing is stored');
79
- }
80
- if (connection.type === 'injected') {
81
- throw new errors_1.TonConnectError('Trying to read HTTP connection source while injected connection is stored');
82
- }
83
- return [2 /*return*/, connection];
84
- }
85
- });
64
+ }
65
+ getHttpConnection() {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const connection = yield this.getConnection();
68
+ if (!connection) {
69
+ throw new errors_1.TonConnectError('Trying to read HTTP connection source while nothing is stored');
70
+ }
71
+ if (connection.type === 'injected') {
72
+ throw new errors_1.TonConnectError('Trying to read HTTP connection source while injected connection is stored');
73
+ }
74
+ return connection;
86
75
  });
87
- };
88
- BridgeConnectionStorage.prototype.getInjectedConnection = function () {
89
- return tslib_1.__awaiter(this, void 0, void 0, function () {
90
- var connection;
91
- return tslib_1.__generator(this, function (_a) {
92
- switch (_a.label) {
93
- case 0: return [4 /*yield*/, this.getConnection()];
94
- case 1:
95
- connection = _a.sent();
96
- if (!connection) {
97
- throw new errors_1.TonConnectError('Trying to read Injected bridge connection source while nothing is stored');
98
- }
99
- if ((connection === null || connection === void 0 ? void 0 : connection.type) === 'http') {
100
- throw new errors_1.TonConnectError('Trying to read Injected bridge connection source while HTTP connection is stored');
101
- }
102
- return [2 /*return*/, connection];
103
- }
104
- });
76
+ }
77
+ getInjectedConnection() {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const connection = yield this.getConnection();
80
+ if (!connection) {
81
+ throw new errors_1.TonConnectError('Trying to read Injected bridge connection source while nothing is stored');
82
+ }
83
+ if ((connection === null || connection === void 0 ? void 0 : connection.type) === 'http') {
84
+ throw new errors_1.TonConnectError('Trying to read Injected bridge connection source while HTTP connection is stored');
85
+ }
86
+ return connection;
105
87
  });
106
- };
107
- BridgeConnectionStorage.prototype.storedConnectionType = function () {
108
- return tslib_1.__awaiter(this, void 0, void 0, function () {
109
- var stored, connection;
110
- return tslib_1.__generator(this, function (_a) {
111
- switch (_a.label) {
112
- case 0: return [4 /*yield*/, this.storage.getItem(this.storeKey)];
113
- case 1:
114
- stored = _a.sent();
115
- if (!stored) {
116
- return [2 /*return*/, null];
117
- }
118
- connection = JSON.parse(stored);
119
- return [2 /*return*/, connection.type];
120
- }
121
- });
88
+ }
89
+ storedConnectionType() {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ const stored = yield this.storage.getItem(this.storeKey);
92
+ if (!stored) {
93
+ return null;
94
+ }
95
+ const connection = JSON.parse(stored);
96
+ return connection.type;
122
97
  });
123
- };
124
- return BridgeConnectionStorage;
125
- }());
98
+ }
99
+ }
126
100
  exports.BridgeConnectionStorage = BridgeConnectionStorage;
@@ -1,33 +1,36 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.DefaultStorage = void 0;
4
- var tslib_1 = require("tslib");
5
- var localstorage_not_found_error_1 = require("../errors/storage/localstorage-not-found.error");
6
- var DefaultStorage = /** @class */ (function () {
7
- function DefaultStorage() {
13
+ const localstorage_not_found_error_1 = require("../errors/storage/localstorage-not-found.error");
14
+ class DefaultStorage {
15
+ constructor() {
8
16
  if (!(window === null || window === void 0 ? void 0 : window.localStorage)) {
9
17
  throw new localstorage_not_found_error_1.LocalstorageNotFoundError();
10
18
  }
11
19
  }
12
- DefaultStorage.prototype.getItem = function (key) {
13
- return tslib_1.__awaiter(this, void 0, void 0, function () {
14
- return tslib_1.__generator(this, function (_a) {
15
- return [2 /*return*/, Promise.resolve(window.localStorage.getItem(key))];
16
- });
20
+ getItem(key) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return Promise.resolve(window.localStorage.getItem(key));
17
23
  });
18
- };
19
- DefaultStorage.prototype.removeItem = function (key) {
20
- return tslib_1.__awaiter(this, void 0, void 0, function () {
21
- return tslib_1.__generator(this, function (_a) {
22
- window.localStorage.removeItem(key);
23
- return [2 /*return*/, Promise.resolve()];
24
- });
24
+ }
25
+ removeItem(key) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ window.localStorage.removeItem(key);
28
+ return Promise.resolve();
25
29
  });
26
- };
27
- DefaultStorage.prototype.setItem = function (key, value) {
30
+ }
31
+ setItem(key, value) {
28
32
  window.localStorage.setItem(key, value);
29
33
  return Promise.resolve();
30
- };
31
- return DefaultStorage;
32
- }());
34
+ }
35
+ }
33
36
  exports.DefaultStorage = DefaultStorage;
@@ -1,42 +1,38 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.HttpBridgeGatewayStorage = void 0;
4
- var tslib_1 = require("tslib");
5
- var HttpBridgeGatewayStorage = /** @class */ (function () {
6
- function HttpBridgeGatewayStorage(storage) {
13
+ class HttpBridgeGatewayStorage {
14
+ constructor(storage) {
7
15
  this.storage = storage;
8
16
  this.storeKey = 'ton-connect-storage_http-bridge-gateway';
9
17
  }
10
- HttpBridgeGatewayStorage.prototype.storeLastEventId = function (lastEventId) {
11
- return tslib_1.__awaiter(this, void 0, void 0, function () {
12
- return tslib_1.__generator(this, function (_a) {
13
- return [2 /*return*/, this.storage.setItem(this.storeKey, lastEventId)];
14
- });
18
+ storeLastEventId(lastEventId) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ return this.storage.setItem(this.storeKey, lastEventId);
15
21
  });
16
- };
17
- HttpBridgeGatewayStorage.prototype.removeLastEventId = function () {
18
- return tslib_1.__awaiter(this, void 0, void 0, function () {
19
- return tslib_1.__generator(this, function (_a) {
20
- return [2 /*return*/, this.storage.removeItem(this.storeKey)];
21
- });
22
+ }
23
+ removeLastEventId() {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ return this.storage.removeItem(this.storeKey);
22
26
  });
23
- };
24
- HttpBridgeGatewayStorage.prototype.getLastEventId = function () {
25
- return tslib_1.__awaiter(this, void 0, void 0, function () {
26
- var stored;
27
- return tslib_1.__generator(this, function (_a) {
28
- switch (_a.label) {
29
- case 0: return [4 /*yield*/, this.storage.getItem(this.storeKey)];
30
- case 1:
31
- stored = _a.sent();
32
- if (!stored) {
33
- return [2 /*return*/, null];
34
- }
35
- return [2 /*return*/, stored];
36
- }
37
- });
27
+ }
28
+ getLastEventId() {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const stored = yield this.storage.getItem(this.storeKey);
31
+ if (!stored) {
32
+ return null;
33
+ }
34
+ return stored;
38
35
  });
39
- };
40
- return HttpBridgeGatewayStorage;
41
- }());
36
+ }
37
+ }
42
38
  exports.HttpBridgeGatewayStorage = HttpBridgeGatewayStorage;