@tonconnect/sdk 0.0.21 → 0.0.23

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 (33) 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 +71 -79
  22. package/lib/provider/bridge/bridge-provider.js +118 -138
  23. package/lib/provider/injected/injected-provider.js +95 -90
  24. package/lib/storage/bridge-connection-storage.js +86 -112
  25. package/lib/storage/default-storage.d.ts +1 -0
  26. package/lib/storage/default-storage.js +28 -22
  27. package/lib/storage/http-bridge-gateway-storage.js +28 -32
  28. package/lib/ton-connect.js +123 -165
  29. package/lib/utils/options.js +5 -5
  30. package/lib/utils/web-api.d.ts +3 -0
  31. package/lib/utils/web-api.js +36 -13
  32. package/lib/wallets-list-manager.js +59 -73
  33. package/package.json +4 -2
@@ -1,143 +1,148 @@
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
+ const web_api_1 = require("../../utils/web-api");
40
+ class InjectedProvider {
41
+ constructor(injectedWalletKey) {
10
42
  this.type = 'injected';
11
43
  this.unsubscribeCallback = null;
12
44
  this.listenSubscriptions = false;
13
45
  this.listeners = [];
14
- var window = InjectedProvider.window;
46
+ const window = InjectedProvider.window;
15
47
  if (!InjectedProvider.isWindowContainsWallet(window, injectedWalletKey)) {
16
48
  throw new wallet_not_injected_error_1.WalletNotInjectedError();
17
49
  }
18
50
  this.injectedWallet = window[injectedWalletKey].tonconnect;
19
51
  }
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
- });
52
+ static fromStorage(storage) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(storage);
55
+ const connection = yield bridgeConnectionStorage.getInjectedConnection();
56
+ return new InjectedProvider(connection.jsBridgeKey);
33
57
  });
34
- };
35
- InjectedProvider.isWalletInjected = function (injectedWalletKey) {
58
+ }
59
+ static isWalletInjected(injectedWalletKey) {
36
60
  return InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey);
37
- };
38
- InjectedProvider.isInsideWalletBrowser = function (injectedWalletKey) {
61
+ }
62
+ static isInsideWalletBrowser(injectedWalletKey) {
39
63
  if (InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey)) {
40
64
  return this.window[injectedWalletKey].tonconnect.isWalletBrowser;
41
65
  }
42
66
  return false;
43
- };
44
- InjectedProvider.isWindowContainsWallet = function (window, injectedWalletKey) {
45
- return (window &&
67
+ }
68
+ static isWindowContainsWallet(window, injectedWalletKey) {
69
+ return (!!window &&
46
70
  injectedWalletKey in window &&
47
71
  typeof window[injectedWalletKey] === 'object' &&
48
72
  'tonconnect' in window[injectedWalletKey]);
49
- };
50
- InjectedProvider.prototype.connect = function (message, auto) {
51
- var _this = this;
52
- if (auto === void 0) { auto = false; }
73
+ }
74
+ connect(message, auto = false) {
53
75
  this.injectedWallet
54
76
  .connect(protocol.version, message, auto)
55
- .then(function (connectEvent) {
77
+ .then(connectEvent => {
56
78
  if (connectEvent.event === 'connect') {
57
- _this.makeSubscriptions();
58
- _this.listenSubscriptions = true;
79
+ this.makeSubscriptions();
80
+ this.listenSubscriptions = true;
59
81
  }
60
- _this.listeners.forEach(function (listener) { return listener(connectEvent); });
82
+ this.listeners.forEach(listener => listener(connectEvent));
61
83
  })
62
- .catch(function (e) {
63
- var connectEventError = {
84
+ .catch(e => {
85
+ const connectEventError = {
64
86
  event: 'connect_error',
65
87
  payload: {
66
88
  code: 0,
67
89
  message: e === null || e === void 0 ? void 0 : e.toString()
68
90
  }
69
91
  };
70
- _this.listeners.forEach(function (listener) { return listener(connectEventError); });
92
+ this.listeners.forEach(listener => listener(connectEventError));
71
93
  });
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*/];
94
+ }
95
+ restoreConnection() {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ try {
98
+ const connectEvent = yield this.injectedWallet.restoreConnection();
99
+ if (connectEvent.event === 'connect') {
100
+ this.makeSubscriptions();
101
+ this.listenSubscriptions = true;
102
+ this.listeners.forEach(listener => listener(connectEvent));
94
103
  }
95
- });
104
+ }
105
+ catch (e) {
106
+ console.error(e);
107
+ }
96
108
  });
97
- };
98
- InjectedProvider.prototype.closeConnection = function () {
109
+ }
110
+ closeConnection() {
99
111
  if (this.listenSubscriptions) {
100
112
  this.injectedWallet.disconnect();
101
113
  }
102
114
  this.closeAllListeners();
103
- };
104
- InjectedProvider.prototype.disconnect = function () {
115
+ }
116
+ disconnect() {
105
117
  this.closeAllListeners();
106
118
  this.injectedWallet.disconnect();
107
119
  return Promise.resolve();
108
- };
109
- InjectedProvider.prototype.closeAllListeners = function () {
120
+ }
121
+ closeAllListeners() {
110
122
  var _a;
111
123
  this.listenSubscriptions = false;
112
124
  this.listeners = [];
113
125
  (_a = this.unsubscribeCallback) === null || _a === void 0 ? void 0 : _a.call(this);
114
- };
115
- InjectedProvider.prototype.listen = function (eventsCallback) {
116
- var _this = this;
126
+ }
127
+ listen(eventsCallback) {
117
128
  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
- });
129
+ return () => (this.listeners = this.listeners.filter(listener => listener !== eventsCallback));
130
+ }
131
+ sendRequest(request) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ return this.injectedWallet.send(Object.assign(Object.assign({}, request), { id: '0' }));
127
134
  });
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); });
135
+ }
136
+ makeSubscriptions() {
137
+ this.unsubscribeCallback = this.injectedWallet.listen(e => {
138
+ if (this.listenSubscriptions) {
139
+ this.listeners.forEach(listener => listener(e));
134
140
  }
135
141
  if (e.event === 'disconnect') {
136
- _this.disconnect();
142
+ this.disconnect();
137
143
  }
138
144
  });
139
- };
140
- InjectedProvider.window = window;
141
- return InjectedProvider;
142
- }());
145
+ }
146
+ }
143
147
  exports.InjectedProvider = InjectedProvider;
148
+ InjectedProvider.window = (0, web_api_1.getWindow)();
@@ -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,5 +1,6 @@
1
1
  import { IStorage } from "./models/storage.interface";
2
2
  export declare class DefaultStorage implements IStorage {
3
+ private readonly window;
3
4
  constructor();
4
5
  getItem(key: string): Promise<string | null>;
5
6
  removeItem(key: string): Promise<void>;
@@ -1,33 +1,39 @@
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
+ const web_api_1 = require("../utils/web-api");
15
+ class DefaultStorage {
16
+ constructor() {
17
+ const window = (0, web_api_1.getWindow)();
8
18
  if (!(window === null || window === void 0 ? void 0 : window.localStorage)) {
9
19
  throw new localstorage_not_found_error_1.LocalstorageNotFoundError();
10
20
  }
21
+ this.window = window;
11
22
  }
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
- });
23
+ getItem(key) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ return Promise.resolve(this.window.localStorage.getItem(key));
17
26
  });
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
- });
27
+ }
28
+ removeItem(key) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ this.window.localStorage.removeItem(key);
31
+ return Promise.resolve();
25
32
  });
26
- };
27
- DefaultStorage.prototype.setItem = function (key, value) {
28
- window.localStorage.setItem(key, value);
33
+ }
34
+ setItem(key, value) {
35
+ this.window.localStorage.setItem(key, value);
29
36
  return Promise.resolve();
30
- };
31
- return DefaultStorage;
32
- }());
37
+ }
38
+ }
33
39
  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;