Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tonconnect/sdk

Package Overview
Dependencies
Maintainers
3
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tonconnect/sdk - npm Package Compare versions

Comparing version 0.0.21 to 0.0.22

20

lib/errors/dapp/dapp-metadata.error.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DappMetadataError = void 0;
var tslib_1 = require("tslib");
var ton_connect_error_1 = require("../ton-connect.error");
var DappMetadataError = /** @class */ (function (_super) {
tslib_1.__extends(DappMetadataError, _super);
function DappMetadataError() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.setPrototypeOf(_this, DappMetadataError.prototype);
return _this;
const ton_connect_error_1 = require("../ton-connect.error");
class DappMetadataError extends ton_connect_error_1.TonConnectError {
constructor(...args) {
super(...args);
Object.setPrototypeOf(this, DappMetadataError.prototype);
}
return DappMetadataError;
}(ton_connect_error_1.TonConnectError));
}
exports.DappMetadataError = DappMetadataError;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnknownError = exports.TonConnectError = void 0;
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./protocol"), exports);
tslib_1.__exportStar(require("./wallet"), exports);
tslib_1.__exportStar(require("./storage"), exports);
tslib_1.__exportStar(require("./wallets-manager"), exports);
__exportStar(require("./protocol"), exports);
__exportStar(require("./wallet"), exports);
__exportStar(require("./storage"), exports);
__exportStar(require("./wallets-manager"), exports);
var ton_connect_error_1 = require("./ton-connect.error");

@@ -10,0 +23,0 @@ Object.defineProperty(exports, "TonConnectError", { enumerable: true, get: function () { return ton_connect_error_1.TonConnectError; } });

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserRejectsError = void 0;
var tslib_1 = require("tslib");
var ton_connect_error_1 = require("../../../ton-connect.error");
var UserRejectsError = /** @class */ (function (_super) {
tslib_1.__extends(UserRejectsError, _super);
function UserRejectsError() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.setPrototypeOf(_this, UserRejectsError.prototype);
return _this;
const ton_connect_error_1 = require("../../../ton-connect.error");
class UserRejectsError extends ton_connect_error_1.TonConnectError {
constructor(...args) {
super(...args);
Object.setPrototypeOf(this, UserRejectsError.prototype);
}
return UserRejectsError;
}(ton_connect_error_1.TonConnectError));
}
exports.UserRejectsError = UserRejectsError;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./connect"), exports);
__exportStar(require("./connect"), exports);
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./events"), exports);
tslib_1.__exportStar(require("./responses"), exports);
__exportStar(require("./events"), exports);
__exportStar(require("./responses"), exports);
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BadRequestError = void 0;
var tslib_1 = require("tslib");
var ton_connect_error_1 = require("../../ton-connect.error");
var BadRequestError = /** @class */ (function (_super) {
tslib_1.__extends(BadRequestError, _super);
function BadRequestError() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.setPrototypeOf(_this, BadRequestError.prototype);
return _this;
const ton_connect_error_1 = require("../../ton-connect.error");
class BadRequestError extends ton_connect_error_1.TonConnectError {
constructor(...args) {
super(...args);
Object.setPrototypeOf(this, BadRequestError.prototype);
}
return BadRequestError;
}(ton_connect_error_1.TonConnectError));
}
exports.BadRequestError = BadRequestError;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnknownAppError = void 0;
var tslib_1 = require("tslib");
var ton_connect_error_1 = require("../../ton-connect.error");
var UnknownAppError = /** @class */ (function (_super) {
tslib_1.__extends(UnknownAppError, _super);
function UnknownAppError() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.setPrototypeOf(_this, UnknownAppError.prototype);
return _this;
const ton_connect_error_1 = require("../../ton-connect.error");
class UnknownAppError extends ton_connect_error_1.TonConnectError {
constructor(...args) {
super(...args);
Object.setPrototypeOf(this, UnknownAppError.prototype);
}
return UnknownAppError;
}(ton_connect_error_1.TonConnectError));
}
exports.UnknownAppError = UnknownAppError;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalstorageNotFoundError = void 0;
var tslib_1 = require("tslib");
var ton_connect_error_1 = require("../ton-connect.error");
var LocalstorageNotFoundError = /** @class */ (function (_super) {
tslib_1.__extends(LocalstorageNotFoundError, _super);
function LocalstorageNotFoundError() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.setPrototypeOf(_this, LocalstorageNotFoundError.prototype);
return _this;
const ton_connect_error_1 = require("../ton-connect.error");
class LocalstorageNotFoundError extends ton_connect_error_1.TonConnectError {
constructor(...args) {
super(...args);
Object.setPrototypeOf(this, LocalstorageNotFoundError.prototype);
}
return LocalstorageNotFoundError;
}(ton_connect_error_1.TonConnectError));
}
exports.LocalstorageNotFoundError = LocalstorageNotFoundError;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TonConnectError = void 0;
var tslib_1 = require("tslib");
var TonConnectError = /** @class */ (function (_super) {
tslib_1.__extends(TonConnectError, _super);
function TonConnectError() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.setPrototypeOf(_this, TonConnectError.prototype);
return _this;
class TonConnectError extends Error {
constructor(...args) {
super(...args);
Object.setPrototypeOf(this, TonConnectError.prototype);
}
return TonConnectError;
}(Error));
}
exports.TonConnectError = TonConnectError;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnknownError = void 0;
var tslib_1 = require("tslib");
var ton_connect_error_1 = require("./ton-connect.error");
var UnknownError = /** @class */ (function (_super) {
tslib_1.__extends(UnknownError, _super);
function UnknownError() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.setPrototypeOf(_this, UnknownError.prototype);
return _this;
const ton_connect_error_1 = require("./ton-connect.error");
class UnknownError extends ton_connect_error_1.TonConnectError {
constructor(...args) {
super(...args);
Object.setPrototypeOf(this, UnknownError.prototype);
}
return UnknownError;
}(ton_connect_error_1.TonConnectError));
}
exports.UnknownError = UnknownError;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WalletAlreadyConnectedError = void 0;
var tslib_1 = require("tslib");
var ton_connect_error_1 = require("../ton-connect.error");
var WalletAlreadyConnectedError = /** @class */ (function (_super) {
tslib_1.__extends(WalletAlreadyConnectedError, _super);
function WalletAlreadyConnectedError() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.setPrototypeOf(_this, WalletAlreadyConnectedError.prototype);
return _this;
const ton_connect_error_1 = require("../ton-connect.error");
class WalletAlreadyConnectedError extends ton_connect_error_1.TonConnectError {
constructor(...args) {
super(...args);
Object.setPrototypeOf(this, WalletAlreadyConnectedError.prototype);
}
return WalletAlreadyConnectedError;
}(ton_connect_error_1.TonConnectError));
}
exports.WalletAlreadyConnectedError = WalletAlreadyConnectedError;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WalletNotConnectedError = void 0;
var tslib_1 = require("tslib");
var ton_connect_error_1 = require("../ton-connect.error");
var WalletNotConnectedError = /** @class */ (function (_super) {
tslib_1.__extends(WalletNotConnectedError, _super);
function WalletNotConnectedError() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.setPrototypeOf(_this, WalletNotConnectedError.prototype);
return _this;
const ton_connect_error_1 = require("../ton-connect.error");
class WalletNotConnectedError extends ton_connect_error_1.TonConnectError {
constructor(...args) {
super(...args);
Object.setPrototypeOf(this, WalletNotConnectedError.prototype);
}
return WalletNotConnectedError;
}(ton_connect_error_1.TonConnectError));
}
exports.WalletNotConnectedError = WalletNotConnectedError;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WalletNotInjectedError = void 0;
var tslib_1 = require("tslib");
var ton_connect_error_1 = require("../ton-connect.error");
var WalletNotInjectedError = /** @class */ (function (_super) {
tslib_1.__extends(WalletNotInjectedError, _super);
function WalletNotInjectedError() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.setPrototypeOf(_this, WalletNotInjectedError.prototype);
return _this;
const ton_connect_error_1 = require("../ton-connect.error");
class WalletNotInjectedError extends ton_connect_error_1.TonConnectError {
constructor(...args) {
super(...args);
Object.setPrototypeOf(this, WalletNotInjectedError.prototype);
}
return WalletNotInjectedError;
}(ton_connect_error_1.TonConnectError));
}
exports.WalletNotInjectedError = WalletNotInjectedError;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FetchWalletsError = void 0;
var tslib_1 = require("tslib");
var ton_connect_error_1 = require("../ton-connect.error");
var FetchWalletsError = /** @class */ (function (_super) {
tslib_1.__extends(FetchWalletsError, _super);
function FetchWalletsError() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.setPrototypeOf(_this, FetchWalletsError.prototype);
return _this;
const ton_connect_error_1 = require("../ton-connect.error");
class FetchWalletsError extends ton_connect_error_1.TonConnectError {
constructor(...args) {
super(...args);
Object.setPrototypeOf(this, FetchWalletsError.prototype);
}
return FetchWalletsError;
}(ton_connect_error_1.TonConnectError));
}
exports.FetchWalletsError = FetchWalletsError;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CHAIN = exports.default = void 0;
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./ton-connect"), exports);
tslib_1.__exportStar(require("./models"), exports);
tslib_1.__exportStar(require("./errors"), exports);
__exportStar(require("./ton-connect"), exports);
__exportStar(require("./models"), exports);
__exportStar(require("./errors"), exports);
var ton_connect_1 = require("./ton-connect");

@@ -9,0 +22,0 @@ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return ton_connect_1.TonConnect; } });

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./wallet"), exports);
tslib_1.__exportStar(require("./methods"), exports);
__exportStar(require("./wallet"), exports);
__exportStar(require("./methods"), exports);
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./connect"), exports);
tslib_1.__exportStar(require("./send-transaction"), exports);
__exportStar(require("./connect"), exports);
__exportStar(require("./send-transaction"), exports);
"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.connectErrorsParser = void 0;
var errors_1 = require("../errors");
var unknown_error_1 = require("../errors/unknown.error");
var protocol_1 = require("@tonconnect/protocol");
var connectEventErrorsCodes = (_a = {},
_a[protocol_1.CONNECT_EVENT_ERROR_CODES.UNKNOWN_ERROR] = unknown_error_1.UnknownError,
_a[protocol_1.CONNECT_EVENT_ERROR_CODES.USER_REJECTS_ERROR] = errors_1.UserRejectsError,
_a[protocol_1.CONNECT_EVENT_ERROR_CODES.BAD_REQUEST_ERROR] = errors_1.BadRequestError,
_a[protocol_1.CONNECT_EVENT_ERROR_CODES.UNKNOWN_APP_ERROR] = errors_1.UnknownAppError,
_a);
var ConnectErrorsParser = /** @class */ (function () {
function ConnectErrorsParser() {
}
ConnectErrorsParser.prototype.parseError = function (error) {
var ErrorConstructor = unknown_error_1.UnknownError;
const errors_1 = require("../errors");
const unknown_error_1 = require("../errors/unknown.error");
const protocol_1 = require("@tonconnect/protocol");
const connectEventErrorsCodes = {
[protocol_1.CONNECT_EVENT_ERROR_CODES.UNKNOWN_ERROR]: unknown_error_1.UnknownError,
[protocol_1.CONNECT_EVENT_ERROR_CODES.USER_REJECTS_ERROR]: errors_1.UserRejectsError,
[protocol_1.CONNECT_EVENT_ERROR_CODES.BAD_REQUEST_ERROR]: errors_1.BadRequestError,
[protocol_1.CONNECT_EVENT_ERROR_CODES.UNKNOWN_APP_ERROR]: errors_1.UnknownAppError
};
class ConnectErrorsParser {
parseError(error) {
let ErrorConstructor = unknown_error_1.UnknownError;
if (error.code in connectEventErrorsCodes) {

@@ -23,5 +20,4 @@ ErrorConstructor = connectEventErrorsCodes[error.code] || unknown_error_1.UnknownError;

return new ErrorConstructor(error.message);
};
return ConnectErrorsParser;
}());
}
}
exports.connectErrorsParser = new ConnectErrorsParser();
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RpcParser = void 0;
var RpcParser = /** @class */ (function () {
function RpcParser() {
class RpcParser {
isError(response) {
return 'error' in response;
}
RpcParser.prototype.isError = function (response) {
return 'error' in response;
};
return RpcParser;
}());
}
exports.RpcParser = RpcParser;
"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendTransactionParser = void 0;
var tslib_1 = require("tslib");
var protocol_1 = require("@tonconnect/protocol");
var errors_1 = require("../errors");
var unknown_error_1 = require("../errors/unknown.error");
var rpc_parser_1 = require("./rpc-parser");
var sendTransactionErrors = (_a = {},
_a[protocol_1.SEND_TRANSACTION_ERROR_CODES.UNKNOWN_ERROR] = unknown_error_1.UnknownError,
_a[protocol_1.SEND_TRANSACTION_ERROR_CODES.USER_REJECTS_ERROR] = errors_1.UserRejectsError,
_a[protocol_1.SEND_TRANSACTION_ERROR_CODES.BAD_REQUEST_ERROR] = errors_1.BadRequestError,
_a[protocol_1.SEND_TRANSACTION_ERROR_CODES.UNKNOWN_APP_ERROR] = errors_1.UnknownAppError,
_a);
var SendTransactionParser = /** @class */ (function (_super) {
tslib_1.__extends(SendTransactionParser, _super);
function SendTransactionParser() {
return _super !== null && _super.apply(this, arguments) || this;
}
SendTransactionParser.prototype.convertToRpcRequest = function (request) {
const protocol_1 = require("@tonconnect/protocol");
const errors_1 = require("../errors");
const unknown_error_1 = require("../errors/unknown.error");
const rpc_parser_1 = require("./rpc-parser");
const sendTransactionErrors = {
[protocol_1.SEND_TRANSACTION_ERROR_CODES.UNKNOWN_ERROR]: unknown_error_1.UnknownError,
[protocol_1.SEND_TRANSACTION_ERROR_CODES.USER_REJECTS_ERROR]: errors_1.UserRejectsError,
[protocol_1.SEND_TRANSACTION_ERROR_CODES.BAD_REQUEST_ERROR]: errors_1.BadRequestError,
[protocol_1.SEND_TRANSACTION_ERROR_CODES.UNKNOWN_APP_ERROR]: errors_1.UnknownAppError
};
class SendTransactionParser extends rpc_parser_1.RpcParser {
convertToRpcRequest(request) {
return {

@@ -26,5 +20,5 @@ method: 'sendTransaction',

};
};
SendTransactionParser.prototype.parseAndThrowError = function (response) {
var ErrorConstructor = unknown_error_1.UnknownError;
}
parseAndThrowError(response) {
let ErrorConstructor = unknown_error_1.UnknownError;
if (response.error.code in sendTransactionErrors) {

@@ -34,10 +28,9 @@ ErrorConstructor = sendTransactionErrors[response.error.code] || unknown_error_1.UnknownError;

throw new ErrorConstructor(response.error.message);
};
SendTransactionParser.prototype.convertFromRpcResponse = function (rpcResponse) {
}
convertFromRpcResponse(rpcResponse) {
return {
boc: rpcResponse.result
};
};
return SendTransactionParser;
}(rpc_parser_1.RpcParser));
}
}
exports.sendTransactionParser = new SendTransactionParser();
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BridgeGateway = void 0;
var tslib_1 = require("tslib");
var protocol_1 = require("@tonconnect/protocol");
var errors_1 = require("../../errors");
var http_bridge_gateway_storage_1 = require("../../storage/http-bridge-gateway-storage");
var url_1 = require("../../utils/url");
var BridgeGateway = /** @class */ (function () {
function BridgeGateway(storage, bridgeUrl, sessionId, listener, errorsListener) {
const protocol_1 = require("@tonconnect/protocol");
const errors_1 = require("../../errors");
const http_bridge_gateway_storage_1 = require("../../storage/http-bridge-gateway-storage");
const url_1 = require("../../utils/url");
class BridgeGateway {
constructor(storage, bridgeUrl, sessionId, listener, errorsListener) {
this.bridgeUrl = bridgeUrl;

@@ -21,86 +29,59 @@ this.sessionId = sessionId;

}
BridgeGateway.prototype.registerSession = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var url, lastEventId;
var _this = this;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
url = new URL((0, url_1.addPathToUrl)(this.bridgeUrl, this.ssePath));
url.searchParams.append('client_id', this.sessionId);
return [4 /*yield*/, this.bridgeGatewayStorage.getLastEventId()];
case 1:
lastEventId = _a.sent();
if (lastEventId) {
url.searchParams.append('last_event_id', lastEventId);
}
this.eventSource = new EventSource(url);
return [2 /*return*/, new Promise(function (resolve, reject) {
_this.eventSource.onerror = reject;
_this.eventSource.onopen = function () {
_this.eventSource.onerror = _this.errorsHandler.bind(_this);
_this.eventSource.onmessage = _this.messagesHandler.bind(_this);
resolve();
};
})];
}
registerSession() {
return __awaiter(this, void 0, void 0, function* () {
const url = new URL((0, url_1.addPathToUrl)(this.bridgeUrl, this.ssePath));
url.searchParams.append('client_id', this.sessionId);
const lastEventId = yield this.bridgeGatewayStorage.getLastEventId();
if (lastEventId) {
url.searchParams.append('last_event_id', lastEventId);
}
this.eventSource = new EventSource(url);
return new Promise((resolve, reject) => {
this.eventSource.onerror = reject;
this.eventSource.onopen = () => {
this.eventSource.onerror = this.errorsHandler.bind(this);
this.eventSource.onmessage = this.messagesHandler.bind(this);
resolve();
};
});
});
};
BridgeGateway.prototype.send = function (message, receiver, ttl) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var url;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
url = new URL((0, url_1.addPathToUrl)(this.bridgeUrl, this.postPath));
url.searchParams.append('client_id', this.sessionId);
url.searchParams.append('to', receiver);
url.searchParams.append('ttl', (ttl || this.defaultTtl).toString());
return [4 /*yield*/, fetch(url, {
method: 'post',
body: protocol_1.Base64.encode(message)
})];
case 1:
_a.sent();
return [2 /*return*/];
}
}
send(message, receiver, ttl) {
return __awaiter(this, void 0, void 0, function* () {
const url = new URL((0, url_1.addPathToUrl)(this.bridgeUrl, this.postPath));
url.searchParams.append('client_id', this.sessionId);
url.searchParams.append('to', receiver);
url.searchParams.append('ttl', (ttl || this.defaultTtl).toString());
yield fetch(url, {
method: 'post',
body: protocol_1.Base64.encode(message)
});
});
};
BridgeGateway.prototype.close = function () {
}
close() {
var _a;
this.isClosed = true;
(_a = this.eventSource) === null || _a === void 0 ? void 0 : _a.close();
};
BridgeGateway.prototype.errorsHandler = function (e) {
}
errorsHandler(e) {
if (!this.isClosed) {
this.errorsListener(e);
}
};
BridgeGateway.prototype.messagesHandler = function (e) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var bridgeIncomingMessage;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.bridgeGatewayStorage.storeLastEventId(e.lastEventId)];
case 1:
_a.sent();
if (!this.isClosed) {
bridgeIncomingMessage = void 0;
try {
bridgeIncomingMessage = JSON.parse(e.data);
}
catch (e) {
throw new errors_1.TonConnectError("Bridge message parse failed, message ".concat(e.data));
}
this.listener(bridgeIncomingMessage);
}
return [2 /*return*/];
}
messagesHandler(e) {
return __awaiter(this, void 0, void 0, function* () {
yield this.bridgeGatewayStorage.storeLastEventId(e.lastEventId);
if (!this.isClosed) {
let bridgeIncomingMessage;
try {
bridgeIncomingMessage = JSON.parse(e.data);
}
});
catch (e) {
throw new errors_1.TonConnectError(`Bridge message parse failed, message ${e.data}`);
}
this.listener(bridgeIncomingMessage);
}
});
};
return BridgeGateway;
}());
}
}
exports.BridgeGateway = BridgeGateway;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BridgeProvider = void 0;
var tslib_1 = require("tslib");
var protocol_1 = require("@tonconnect/protocol");
var ton_connect_error_1 = require("../../errors/ton-connect.error");
var bridge_gateway_1 = require("./bridge-gateway");
var bridge_connection_storage_1 = require("../../storage/bridge-connection-storage");
var protocol = tslib_1.__importStar(require("../../resources/protocol.json"));
var BridgeProvider = /** @class */ (function () {
function BridgeProvider(storage, walletConnectionSource) {
const protocol_1 = require("@tonconnect/protocol");
const ton_connect_error_1 = require("../../errors/ton-connect.error");
const bridge_gateway_1 = require("./bridge-gateway");
const bridge_connection_storage_1 = require("../../storage/bridge-connection-storage");
const protocol = __importStar(require("../../resources/protocol.json"));
class BridgeProvider {
constructor(storage, walletConnectionSource) {
this.storage = storage;

@@ -22,23 +53,15 @@ this.walletConnectionSource = walletConnectionSource;

}
BridgeProvider.fromStorage = function (storage) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var bridgeConnectionStorage, connection;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(storage);
return [4 /*yield*/, bridgeConnectionStorage.getHttpConnection()];
case 1:
connection = _a.sent();
return [2 /*return*/, new BridgeProvider(storage, connection.session.walletConnectionSource)];
}
});
static fromStorage(storage) {
return __awaiter(this, void 0, void 0, function* () {
const bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(storage);
const connection = yield bridgeConnectionStorage.getHttpConnection();
return new BridgeProvider(storage, connection.session.walletConnectionSource);
});
};
BridgeProvider.prototype.connect = function (message) {
}
connect(message) {
var _a;
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
var sessionCrypto = new protocol_1.SessionCrypto();
const sessionCrypto = new protocol_1.SessionCrypto();
this.session = {
sessionCrypto: sessionCrypto,
sessionCrypto,
walletConnectionSource: this.walletConnectionSource

@@ -49,47 +72,35 @@ };

return this.generateUniversalLink(message);
};
BridgeProvider.prototype.restoreConnection = function () {
}
restoreConnection() {
var _a;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var storedConnection;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
return [4 /*yield*/, this.connectionStorage.getHttpConnection()];
case 1:
storedConnection = _b.sent();
if (!storedConnection) {
return [2 /*return*/];
}
this.session = storedConnection.session;
this.bridge = new bridge_gateway_1.BridgeGateway(this.storage, this.walletConnectionSource.bridgeUrl, storedConnection.session.sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this));
return [4 /*yield*/, this.bridge.registerSession()];
case 2:
_b.sent();
this.listeners.forEach(function (listener) { return listener(storedConnection.connectEvent); });
return [2 /*return*/];
}
});
return __awaiter(this, void 0, void 0, function* () {
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
const storedConnection = yield this.connectionStorage.getHttpConnection();
if (!storedConnection) {
return;
}
this.session = storedConnection.session;
this.bridge = new bridge_gateway_1.BridgeGateway(this.storage, this.walletConnectionSource.bridgeUrl, storedConnection.session.sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this));
yield this.bridge.registerSession();
this.listeners.forEach(listener => listener(storedConnection.connectEvent));
});
};
BridgeProvider.prototype.sendRequest = function (request) {
var _this = this;
return new Promise(function (resolve, reject) {
var id = _this.nextRequestId;
_this.nextRequestId++;
if (!_this.bridge || !_this.session || !('walletPublicKey' in _this.session)) {
}
sendRequest(request) {
return new Promise((resolve, reject) => {
const id = this.nextRequestId;
this.nextRequestId++;
if (!this.bridge || !this.session || !('walletPublicKey' in this.session)) {
throw new ton_connect_error_1.TonConnectError('Trying to send bridge request without session');
}
var encodedRequest = _this.session.sessionCrypto.encrypt(JSON.stringify(tslib_1.__assign(tslib_1.__assign({}, request), { id: id })), (0, protocol_1.hexToByteArray)(_this.session.walletPublicKey));
_this.bridge.send(encodedRequest, _this.session.walletPublicKey).catch(reject);
_this.pendingRequests.set(id.toString(), resolve);
const encodedRequest = this.session.sessionCrypto.encrypt(JSON.stringify(Object.assign(Object.assign({}, request), { id })), (0, protocol_1.hexToByteArray)(this.session.walletPublicKey));
this.bridge.send(encodedRequest, this.session.walletPublicKey).catch(reject);
this.pendingRequests.set(id.toString(), resolve);
});
};
BridgeProvider.prototype.closeConnection = function () {
}
closeConnection() {
var _a;
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
this.listeners = [];
};
BridgeProvider.prototype.disconnect = function () {
}
disconnect() {
var _a;

@@ -99,82 +110,52 @@ (_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();

return this.removeBridgeAndSession();
};
BridgeProvider.prototype.listen = function (callback) {
var _this = this;
}
listen(callback) {
this.listeners.push(callback);
return function () { return (_this.listeners = _this.listeners.filter(function (listener) { return listener !== callback; })); };
};
BridgeProvider.prototype.gatewayListener = function (bridgeIncomingMessage) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var walletMessage, id, resolve;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
walletMessage = JSON.parse(this.session.sessionCrypto.decrypt(protocol_1.Base64.decode(bridgeIncomingMessage.message).toUint8Array(), (0, protocol_1.hexToByteArray)(bridgeIncomingMessage.from)));
if (!('event' in walletMessage)) {
id = walletMessage.id.toString();
resolve = this.pendingRequests.get(id);
if (!resolve) {
throw new ton_connect_error_1.TonConnectError("Response id ".concat(id, " doesn't match any request's id"));
}
resolve(walletMessage);
this.pendingRequests.delete(id);
return [2 /*return*/];
}
if (!(walletMessage.event === 'connect')) return [3 /*break*/, 2];
return [4 /*yield*/, this.updateSession(walletMessage, bridgeIncomingMessage.from)];
case 1:
_a.sent();
_a.label = 2;
case 2:
this.listeners.forEach(function (listener) { return listener(walletMessage); });
return [2 /*return*/];
return () => (this.listeners = this.listeners.filter(listener => listener !== callback));
}
gatewayListener(bridgeIncomingMessage) {
return __awaiter(this, void 0, void 0, function* () {
const walletMessage = JSON.parse(this.session.sessionCrypto.decrypt(protocol_1.Base64.decode(bridgeIncomingMessage.message).toUint8Array(), (0, protocol_1.hexToByteArray)(bridgeIncomingMessage.from)));
if (!('event' in walletMessage)) {
const id = walletMessage.id.toString();
const resolve = this.pendingRequests.get(id);
if (!resolve) {
throw new ton_connect_error_1.TonConnectError(`Response id ${id} doesn't match any request's id`);
}
});
resolve(walletMessage);
this.pendingRequests.delete(id);
return;
}
if (walletMessage.event === 'connect') {
yield this.updateSession(walletMessage, bridgeIncomingMessage.from);
}
this.listeners.forEach(listener => listener(walletMessage));
});
};
BridgeProvider.prototype.gatewayErrorsListener = function (e) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
throw new ton_connect_error_1.TonConnectError("Bridge error ".concat(e));
});
}
gatewayErrorsListener(e) {
return __awaiter(this, void 0, void 0, function* () {
throw new ton_connect_error_1.TonConnectError(`Bridge error ${e}`);
});
};
BridgeProvider.prototype.updateSession = function (connectEvent, walletPublicKey) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var tonAddrItem, connectEventToSave;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
this.session = tslib_1.__assign(tslib_1.__assign({}, this.session), { walletPublicKey: walletPublicKey });
tonAddrItem = connectEvent.payload.items.find(function (item) { return item.name === 'ton_addr'; });
connectEventToSave = tslib_1.__assign(tslib_1.__assign({}, connectEvent), { payload: tslib_1.__assign(tslib_1.__assign({}, connectEvent.payload), { items: [tonAddrItem] }) });
return [4 /*yield*/, this.connectionStorage.storeConnection({
type: 'http',
session: this.session,
connectEvent: connectEventToSave
})];
case 1:
_a.sent();
return [2 /*return*/];
}
}
updateSession(connectEvent, walletPublicKey) {
return __awaiter(this, void 0, void 0, function* () {
this.session = Object.assign(Object.assign({}, this.session), { walletPublicKey });
const tonAddrItem = connectEvent.payload.items.find(item => item.name === 'ton_addr');
const connectEventToSave = Object.assign(Object.assign({}, connectEvent), { payload: Object.assign(Object.assign({}, connectEvent.payload), { items: [tonAddrItem] }) });
yield this.connectionStorage.storeConnection({
type: 'http',
session: this.session,
connectEvent: connectEventToSave
});
});
};
BridgeProvider.prototype.removeBridgeAndSession = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
this.session = null;
this.bridge = null;
return [4 /*yield*/, this.connectionStorage.removeConnection()];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}
removeBridgeAndSession() {
return __awaiter(this, void 0, void 0, function* () {
this.session = null;
this.bridge = null;
yield this.connectionStorage.removeConnection();
});
};
BridgeProvider.prototype.generateUniversalLink = function (message) {
var url = new URL(this.walletConnectionSource.universalLink);
}
generateUniversalLink(message) {
const url = new URL(this.walletConnectionSource.universalLink);
url.searchParams.append('v', protocol.version.toString());

@@ -184,5 +165,4 @@ url.searchParams.append('id', this.session.sessionCrypto.sessionId);

return url.toString();
};
return BridgeProvider;
}());
}
}
exports.BridgeProvider = BridgeProvider;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InjectedProvider = void 0;
var tslib_1 = require("tslib");
var wallet_not_injected_error_1 = require("../../errors/wallet/wallet-not-injected.error");
var protocol = tslib_1.__importStar(require("../../resources/protocol.json"));
var bridge_connection_storage_1 = require("../../storage/bridge-connection-storage");
var InjectedProvider = /** @class */ (function () {
function InjectedProvider(injectedWalletKey) {
const wallet_not_injected_error_1 = require("../../errors/wallet/wallet-not-injected.error");
const protocol = __importStar(require("../../resources/protocol.json"));
const bridge_connection_storage_1 = require("../../storage/bridge-connection-storage");
class InjectedProvider {
constructor(injectedWalletKey) {
this.type = 'injected';

@@ -14,3 +45,3 @@ this.unsubscribeCallback = null;

this.listeners = [];
var window = InjectedProvider.window;
const window = InjectedProvider.window;
if (!InjectedProvider.isWindowContainsWallet(window, injectedWalletKey)) {

@@ -21,21 +52,13 @@ throw new wallet_not_injected_error_1.WalletNotInjectedError();

}
InjectedProvider.fromStorage = function (storage) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var bridgeConnectionStorage, connection;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(storage);
return [4 /*yield*/, bridgeConnectionStorage.getInjectedConnection()];
case 1:
connection = _a.sent();
return [2 /*return*/, new InjectedProvider(connection.jsBridgeKey)];
}
});
static fromStorage(storage) {
return __awaiter(this, void 0, void 0, function* () {
const bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(storage);
const connection = yield bridgeConnectionStorage.getInjectedConnection();
return new InjectedProvider(connection.jsBridgeKey);
});
};
InjectedProvider.isWalletInjected = function (injectedWalletKey) {
}
static isWalletInjected(injectedWalletKey) {
return InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey);
};
InjectedProvider.isInsideWalletBrowser = function (injectedWalletKey) {
}
static isInsideWalletBrowser(injectedWalletKey) {
if (InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey)) {

@@ -45,4 +68,4 @@ return this.window[injectedWalletKey].tonconnect.isWalletBrowser;

return false;
};
InjectedProvider.isWindowContainsWallet = function (window, injectedWalletKey) {
}
static isWindowContainsWallet(window, injectedWalletKey) {
return (window &&

@@ -52,17 +75,15 @@ injectedWalletKey in window &&

'tonconnect' in window[injectedWalletKey]);
};
InjectedProvider.prototype.connect = function (message, auto) {
var _this = this;
if (auto === void 0) { auto = false; }
}
connect(message, auto = false) {
this.injectedWallet
.connect(protocol.version, message, auto)
.then(function (connectEvent) {
.then(connectEvent => {
if (connectEvent.event === 'connect') {
_this.makeSubscriptions();
_this.listenSubscriptions = true;
this.makeSubscriptions();
this.listenSubscriptions = true;
}
_this.listeners.forEach(function (listener) { return listener(connectEvent); });
this.listeners.forEach(listener => listener(connectEvent));
})
.catch(function (e) {
var connectEventError = {
.catch(e => {
const connectEventError = {
event: 'connect_error',

@@ -74,31 +95,21 @@ payload: {

};
_this.listeners.forEach(function (listener) { return listener(connectEventError); });
this.listeners.forEach(listener => listener(connectEventError));
});
};
InjectedProvider.prototype.restoreConnection = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var connectEvent_1, e_1;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, this.injectedWallet.restoreConnection()];
case 1:
connectEvent_1 = _a.sent();
if (connectEvent_1.event === 'connect') {
this.makeSubscriptions();
this.listenSubscriptions = true;
this.listeners.forEach(function (listener) { return listener(connectEvent_1); });
}
return [3 /*break*/, 3];
case 2:
e_1 = _a.sent();
console.error(e_1);
return [3 /*break*/, 3];
case 3: return [2 /*return*/];
}
restoreConnection() {
return __awaiter(this, void 0, void 0, function* () {
try {
const connectEvent = yield this.injectedWallet.restoreConnection();
if (connectEvent.event === 'connect') {
this.makeSubscriptions();
this.listenSubscriptions = true;
this.listeners.forEach(listener => listener(connectEvent));
}
});
}
catch (e) {
console.error(e);
}
});
};
InjectedProvider.prototype.closeConnection = function () {
}
closeConnection() {
if (this.listenSubscriptions) {

@@ -108,9 +119,9 @@ this.injectedWallet.disconnect();

this.closeAllListeners();
};
InjectedProvider.prototype.disconnect = function () {
}
disconnect() {
this.closeAllListeners();
this.injectedWallet.disconnect();
return Promise.resolve();
};
InjectedProvider.prototype.closeAllListeners = function () {
}
closeAllListeners() {
var _a;

@@ -120,31 +131,24 @@ this.listenSubscriptions = false;

(_a = this.unsubscribeCallback) === null || _a === void 0 ? void 0 : _a.call(this);
};
InjectedProvider.prototype.listen = function (eventsCallback) {
var _this = this;
}
listen(eventsCallback) {
this.listeners.push(eventsCallback);
return function () {
return (_this.listeners = _this.listeners.filter(function (listener) { return listener !== eventsCallback; }));
};
};
InjectedProvider.prototype.sendRequest = function (request) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, this.injectedWallet.send(tslib_1.__assign(tslib_1.__assign({}, request), { id: '0' }))];
});
return () => (this.listeners = this.listeners.filter(listener => listener !== eventsCallback));
}
sendRequest(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.injectedWallet.send(Object.assign(Object.assign({}, request), { id: '0' }));
});
};
InjectedProvider.prototype.makeSubscriptions = function () {
var _this = this;
this.unsubscribeCallback = this.injectedWallet.listen(function (e) {
if (_this.listenSubscriptions) {
_this.listeners.forEach(function (listener) { return listener(e); });
}
makeSubscriptions() {
this.unsubscribeCallback = this.injectedWallet.listen(e => {
if (this.listenSubscriptions) {
this.listeners.forEach(listener => listener(e));
}
if (e.event === 'disconnect') {
_this.disconnect();
this.disconnect();
}
});
};
InjectedProvider.window = window;
return InjectedProvider;
}());
}
}
exports.InjectedProvider = InjectedProvider;
InjectedProvider.window = window;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BridgeConnectionStorage = void 0;
var tslib_1 = require("tslib");
var protocol_1 = require("@tonconnect/protocol");
var errors_1 = require("../errors");
var BridgeConnectionStorage = /** @class */ (function () {
function BridgeConnectionStorage(storage) {
const protocol_1 = require("@tonconnect/protocol");
const errors_1 = require("../errors");
class BridgeConnectionStorage {
constructor(storage) {
this.storage = storage;
this.storeKey = 'ton-connect-storage_bridge-connection';
}
BridgeConnectionStorage.prototype.storeConnection = function (connection) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var rawSession, rawConnection;
return tslib_1.__generator(this, function (_a) {
if (connection.type === 'injected') {
return [2 /*return*/, this.storage.setItem(this.storeKey, JSON.stringify(connection))];
}
rawSession = {
sessionKeyPair: connection.session.sessionCrypto.stringifyKeypair(),
walletPublicKey: connection.session.walletPublicKey,
walletConnectionSource: connection.session.walletConnectionSource
};
rawConnection = {
type: 'http',
connectEvent: connection.connectEvent,
session: rawSession
};
return [2 /*return*/, this.storage.setItem(this.storeKey, JSON.stringify(rawConnection))];
});
storeConnection(connection) {
return __awaiter(this, void 0, void 0, function* () {
if (connection.type === 'injected') {
return this.storage.setItem(this.storeKey, JSON.stringify(connection));
}
const rawSession = {
sessionKeyPair: connection.session.sessionCrypto.stringifyKeypair(),
walletPublicKey: connection.session.walletPublicKey,
walletConnectionSource: connection.session.walletConnectionSource
};
const rawConnection = {
type: 'http',
connectEvent: connection.connectEvent,
session: rawSession
};
return this.storage.setItem(this.storeKey, JSON.stringify(rawConnection));
});
};
BridgeConnectionStorage.prototype.removeConnection = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, this.storage.removeItem(this.storeKey)];
});
}
removeConnection() {
return __awaiter(this, void 0, void 0, function* () {
return this.storage.removeItem(this.storeKey);
});
};
BridgeConnectionStorage.prototype.getConnection = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var stored, connection, sessionCrypto;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.storage.getItem(this.storeKey)];
case 1:
stored = _a.sent();
if (!stored) {
return [2 /*return*/, null];
}
connection = JSON.parse(stored);
if (connection.type === 'injected') {
return [2 /*return*/, connection];
}
sessionCrypto = new protocol_1.SessionCrypto(connection.session.sessionKeyPair);
return [2 /*return*/, {
type: 'http',
connectEvent: connection.connectEvent,
session: {
sessionCrypto: sessionCrypto,
walletConnectionSource: connection.session.walletConnectionSource,
walletPublicKey: connection.session.walletPublicKey
}
}];
}
getConnection() {
return __awaiter(this, void 0, void 0, function* () {
const stored = yield this.storage.getItem(this.storeKey);
if (!stored) {
return null;
}
const connection = JSON.parse(stored);
if (connection.type === 'injected') {
return connection;
}
const sessionCrypto = new protocol_1.SessionCrypto(connection.session.sessionKeyPair);
return {
type: 'http',
connectEvent: connection.connectEvent,
session: {
sessionCrypto,
walletConnectionSource: connection.session.walletConnectionSource,
walletPublicKey: connection.session.walletPublicKey
}
});
};
});
};
BridgeConnectionStorage.prototype.getHttpConnection = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var connection;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getConnection()];
case 1:
connection = _a.sent();
if (!connection) {
throw new errors_1.TonConnectError('Trying to read HTTP connection source while nothing is stored');
}
if (connection.type === 'injected') {
throw new errors_1.TonConnectError('Trying to read HTTP connection source while injected connection is stored');
}
return [2 /*return*/, connection];
}
});
}
getHttpConnection() {
return __awaiter(this, void 0, void 0, function* () {
const connection = yield this.getConnection();
if (!connection) {
throw new errors_1.TonConnectError('Trying to read HTTP connection source while nothing is stored');
}
if (connection.type === 'injected') {
throw new errors_1.TonConnectError('Trying to read HTTP connection source while injected connection is stored');
}
return connection;
});
};
BridgeConnectionStorage.prototype.getInjectedConnection = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var connection;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getConnection()];
case 1:
connection = _a.sent();
if (!connection) {
throw new errors_1.TonConnectError('Trying to read Injected bridge connection source while nothing is stored');
}
if ((connection === null || connection === void 0 ? void 0 : connection.type) === 'http') {
throw new errors_1.TonConnectError('Trying to read Injected bridge connection source while HTTP connection is stored');
}
return [2 /*return*/, connection];
}
});
}
getInjectedConnection() {
return __awaiter(this, void 0, void 0, function* () {
const connection = yield this.getConnection();
if (!connection) {
throw new errors_1.TonConnectError('Trying to read Injected bridge connection source while nothing is stored');
}
if ((connection === null || connection === void 0 ? void 0 : connection.type) === 'http') {
throw new errors_1.TonConnectError('Trying to read Injected bridge connection source while HTTP connection is stored');
}
return connection;
});
};
BridgeConnectionStorage.prototype.storedConnectionType = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var stored, connection;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.storage.getItem(this.storeKey)];
case 1:
stored = _a.sent();
if (!stored) {
return [2 /*return*/, null];
}
connection = JSON.parse(stored);
return [2 /*return*/, connection.type];
}
});
}
storedConnectionType() {
return __awaiter(this, void 0, void 0, function* () {
const stored = yield this.storage.getItem(this.storeKey);
if (!stored) {
return null;
}
const connection = JSON.parse(stored);
return connection.type;
});
};
return BridgeConnectionStorage;
}());
}
}
exports.BridgeConnectionStorage = BridgeConnectionStorage;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultStorage = void 0;
var tslib_1 = require("tslib");
var localstorage_not_found_error_1 = require("../errors/storage/localstorage-not-found.error");
var DefaultStorage = /** @class */ (function () {
function DefaultStorage() {
const localstorage_not_found_error_1 = require("../errors/storage/localstorage-not-found.error");
class DefaultStorage {
constructor() {
if (!(window === null || window === void 0 ? void 0 : window.localStorage)) {

@@ -12,23 +20,18 @@ throw new localstorage_not_found_error_1.LocalstorageNotFoundError();

}
DefaultStorage.prototype.getItem = function (key) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, Promise.resolve(window.localStorage.getItem(key))];
});
getItem(key) {
return __awaiter(this, void 0, void 0, function* () {
return Promise.resolve(window.localStorage.getItem(key));
});
};
DefaultStorage.prototype.removeItem = function (key) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
window.localStorage.removeItem(key);
return [2 /*return*/, Promise.resolve()];
});
}
removeItem(key) {
return __awaiter(this, void 0, void 0, function* () {
window.localStorage.removeItem(key);
return Promise.resolve();
});
};
DefaultStorage.prototype.setItem = function (key, value) {
}
setItem(key, value) {
window.localStorage.setItem(key, value);
return Promise.resolve();
};
return DefaultStorage;
}());
}
}
exports.DefaultStorage = DefaultStorage;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpBridgeGatewayStorage = void 0;
var tslib_1 = require("tslib");
var HttpBridgeGatewayStorage = /** @class */ (function () {
function HttpBridgeGatewayStorage(storage) {
class HttpBridgeGatewayStorage {
constructor(storage) {
this.storage = storage;
this.storeKey = 'ton-connect-storage_http-bridge-gateway';
}
HttpBridgeGatewayStorage.prototype.storeLastEventId = function (lastEventId) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, this.storage.setItem(this.storeKey, lastEventId)];
});
storeLastEventId(lastEventId) {
return __awaiter(this, void 0, void 0, function* () {
return this.storage.setItem(this.storeKey, lastEventId);
});
};
HttpBridgeGatewayStorage.prototype.removeLastEventId = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, this.storage.removeItem(this.storeKey)];
});
}
removeLastEventId() {
return __awaiter(this, void 0, void 0, function* () {
return this.storage.removeItem(this.storeKey);
});
};
HttpBridgeGatewayStorage.prototype.getLastEventId = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var stored;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.storage.getItem(this.storeKey)];
case 1:
stored = _a.sent();
if (!stored) {
return [2 /*return*/, null];
}
return [2 /*return*/, stored];
}
});
}
getLastEventId() {
return __awaiter(this, void 0, void 0, function* () {
const stored = yield this.storage.getItem(this.storeKey);
if (!stored) {
return null;
}
return stored;
});
};
return HttpBridgeGatewayStorage;
}());
}
}
exports.HttpBridgeGatewayStorage = HttpBridgeGatewayStorage;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TonConnect = void 0;
var tslib_1 = require("tslib");
var dapp_metadata_error_1 = require("./errors/dapp/dapp-metadata.error");
var ton_connect_error_1 = require("./errors/ton-connect.error");
var wallet_already_connected_error_1 = require("./errors/wallet/wallet-already-connected.error");
var wallet_not_connected_error_1 = require("./errors/wallet/wallet-not-connected.error");
var wallet_connection_source_1 = require("./models/wallet/wallet-connection-source");
var connect_errors_parser_1 = require("./parsers/connect-errors-parser");
var send_transaction_parser_1 = require("./parsers/send-transaction-parser");
var bridge_provider_1 = require("./provider/bridge/bridge-provider");
var injected_provider_1 = require("./provider/injected/injected-provider");
var bridge_connection_storage_1 = require("./storage/bridge-connection-storage");
var default_storage_1 = require("./storage/default-storage");
var options_1 = require("./utils/options");
var web_api_1 = require("./utils/web-api");
var wallets_list_manager_1 = require("./wallets-list-manager");
var TonConnect = /** @class */ (function () {
function TonConnect(options) {
const dapp_metadata_error_1 = require("./errors/dapp/dapp-metadata.error");
const ton_connect_error_1 = require("./errors/ton-connect.error");
const wallet_already_connected_error_1 = require("./errors/wallet/wallet-already-connected.error");
const wallet_not_connected_error_1 = require("./errors/wallet/wallet-not-connected.error");
const wallet_connection_source_1 = require("./models/wallet/wallet-connection-source");
const connect_errors_parser_1 = require("./parsers/connect-errors-parser");
const send_transaction_parser_1 = require("./parsers/send-transaction-parser");
const bridge_provider_1 = require("./provider/bridge/bridge-provider");
const injected_provider_1 = require("./provider/injected/injected-provider");
const bridge_connection_storage_1 = require("./storage/bridge-connection-storage");
const default_storage_1 = require("./storage/default-storage");
const options_1 = require("./utils/options");
const web_api_1 = require("./utils/web-api");
const wallets_list_manager_1 = require("./wallets-list-manager");
class TonConnect {
constructor(options) {
this.walletsList = new wallets_list_manager_1.WalletsListManager();

@@ -35,44 +43,31 @@ this._wallet = null;

}
Object.defineProperty(TonConnect.prototype, "connected", {
/**
* Shows if the wallet is connected right now.
*/
get: function () {
return this._wallet !== null;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TonConnect.prototype, "account", {
/**
* Current connected account or null if no account is connected.
*/
get: function () {
var _a;
return ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.account) || null;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TonConnect.prototype, "wallet", {
/**
* Current connected wallet or null if no account is connected.
*/
get: function () {
return this._wallet;
},
set: function (value) {
var _this = this;
this._wallet = value;
this.statusChangeSubscriptions.forEach(function (callback) { return callback(_this._wallet); });
},
enumerable: false,
configurable: true
});
/**
* Shows if the wallet is connected right now.
*/
get connected() {
return this._wallet !== null;
}
/**
* Current connected account or null if no account is connected.
*/
get account() {
var _a;
return ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.account) || null;
}
/**
* Current connected wallet or null if no account is connected.
*/
get wallet() {
return this._wallet;
}
set wallet(value) {
this._wallet = value;
this.statusChangeSubscriptions.forEach(callback => callback(this._wallet));
}
/**
* Returns available wallets list.
*/
TonConnect.prototype.getWallets = function () {
getWallets() {
return this.walletsList.getWallets();
};
}
/**

@@ -84,4 +79,3 @@ * Allows to subscribe to connection status changes and handle connection errors.

*/
TonConnect.prototype.onStatusChange = function (callback, errorsHandler) {
var _this = this;
onStatusChange(callback, errorsHandler) {
this.statusChangeSubscriptions.push(callback);

@@ -91,10 +85,10 @@ if (errorsHandler) {

}
return function () {
_this.statusChangeSubscriptions = _this.statusChangeSubscriptions.filter(function (item) { return item !== callback; });
return () => {
this.statusChangeSubscriptions = this.statusChangeSubscriptions.filter(item => item !== callback);
if (errorsHandler) {
_this.statusChangeErrorSubscriptions = _this.statusChangeErrorSubscriptions.filter(function (item) { return item !== errorsHandler; });
this.statusChangeErrorSubscriptions = this.statusChangeErrorSubscriptions.filter(item => item !== errorsHandler);
}
};
};
TonConnect.prototype.connect = function (wallet, request) {
}
connect(wallet, request) {
var _a;

@@ -107,50 +101,31 @@ if (this.connected) {

return this.provider.connect(this.createConnectRequest(request));
};
}
/**
* Try to restore existing session and reconnect to the corresponding wallet. Call it immediately when your app is loaded.
*/
TonConnect.prototype.restoreConnection = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _a, bridgeConnectionType, embeddedWallet, _b, _c, _d, _e;
return tslib_1.__generator(this, function (_f) {
switch (_f.label) {
case 0: return [4 /*yield*/, Promise.all([
this.bridgeConnectionStorage.storedConnectionType(),
this.walletsList.getEmbeddedWallet()
])];
case 1:
_a = _f.sent(), bridgeConnectionType = _a[0], embeddedWallet = _a[1];
_b = bridgeConnectionType;
switch (_b) {
case 'http': return [3 /*break*/, 2];
case 'injected': return [3 /*break*/, 4];
}
return [3 /*break*/, 6];
case 2:
_c = this;
return [4 /*yield*/, bridge_provider_1.BridgeProvider.fromStorage(this.dappSettings.storage)];
case 3:
_c.provider = _f.sent();
return [3 /*break*/, 9];
case 4:
_d = this;
return [4 /*yield*/, injected_provider_1.InjectedProvider.fromStorage(this.dappSettings.storage)];
case 5:
_d.provider = _f.sent();
return [3 /*break*/, 9];
case 6:
if (!embeddedWallet) return [3 /*break*/, 8];
_e = this;
return [4 /*yield*/, this.createProvider(embeddedWallet)];
case 7:
_e.provider = _f.sent();
return [3 /*break*/, 9];
case 8: return [2 /*return*/];
case 9:
this.provider.listen(this.walletEventsListener.bind(this));
return [2 /*return*/, this.provider.restoreConnection()];
}
});
restoreConnection() {
return __awaiter(this, void 0, void 0, function* () {
const [bridgeConnectionType, embeddedWallet] = yield Promise.all([
this.bridgeConnectionStorage.storedConnectionType(),
this.walletsList.getEmbeddedWallet()
]);
switch (bridgeConnectionType) {
case 'http':
this.provider = yield bridge_provider_1.BridgeProvider.fromStorage(this.dappSettings.storage);
break;
case 'injected':
this.provider = yield injected_provider_1.InjectedProvider.fromStorage(this.dappSettings.storage);
break;
default:
if (embeddedWallet) {
this.provider = yield this.createProvider(embeddedWallet);
}
else {
return;
}
}
this.provider.listen(this.walletEventsListener.bind(this));
return this.provider.restoreConnection();
});
};
}
/**

@@ -162,42 +137,26 @@ * Asks connected wallet to sign and send the transaction.

*/
TonConnect.prototype.sendTransaction = function (transaction) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var response;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
this.checkConnection();
return [4 /*yield*/, this.provider.sendRequest(send_transaction_parser_1.sendTransactionParser.convertToRpcRequest(transaction))];
case 1:
response = _a.sent();
if (send_transaction_parser_1.sendTransactionParser.isError(response)) {
return [2 /*return*/, send_transaction_parser_1.sendTransactionParser.parseAndThrowError(response)];
}
return [2 /*return*/, send_transaction_parser_1.sendTransactionParser.convertFromRpcResponse(response)];
}
});
sendTransaction(transaction) {
return __awaiter(this, void 0, void 0, function* () {
this.checkConnection();
const response = yield this.provider.sendRequest(send_transaction_parser_1.sendTransactionParser.convertToRpcRequest(transaction));
if (send_transaction_parser_1.sendTransactionParser.isError(response)) {
return send_transaction_parser_1.sendTransactionParser.parseAndThrowError(response);
}
return send_transaction_parser_1.sendTransactionParser.convertFromRpcResponse(response);
});
};
}
/**
* Disconnect form thw connected wallet and drop current session.
*/
TonConnect.prototype.disconnect = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.connected) {
throw new wallet_not_connected_error_1.WalletNotConnectedError();
}
return [4 /*yield*/, this.provider.disconnect()];
case 1:
_a.sent();
this.onWalletDisconnected();
return [2 /*return*/];
}
});
disconnect() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.connected) {
throw new wallet_not_connected_error_1.WalletNotConnectedError();
}
yield this.provider.disconnect();
this.onWalletDisconnected();
});
};
TonConnect.prototype.createProvider = function (wallet) {
var provider;
}
createProvider(wallet) {
let provider;
if ((0, wallet_connection_source_1.isWalletConnectionSourceJS)(wallet)) {

@@ -211,4 +170,4 @@ provider = new injected_provider_1.InjectedProvider(wallet.jsBridgeKey);

return provider;
};
TonConnect.prototype.walletEventsListener = function (e) {
}
walletEventsListener(e) {
switch (e.event) {

@@ -224,10 +183,10 @@ case 'connect':

}
};
TonConnect.prototype.onWalletConnected = function (connectEvent) {
var tonAccountItem = connectEvent.items.find(function (item) { return item.name === 'ton_addr'; });
var tonProofItem = connectEvent.items.find(function (item) { return item.name === 'ton_proof'; });
}
onWalletConnected(connectEvent) {
const tonAccountItem = connectEvent.items.find(item => item.name === 'ton_addr');
const tonProofItem = connectEvent.items.find(item => item.name === 'ton_proof');
if (!tonAccountItem) {
throw new ton_connect_error_1.TonConnectError('ton_addr connection item was not found');
}
var wallet = {
const wallet = {
device: connectEvent.device,

@@ -246,19 +205,19 @@ provider: this.provider.type,

this.wallet = wallet;
};
TonConnect.prototype.onWalletConnectError = function (connectEventError) {
var error = connect_errors_parser_1.connectErrorsParser.parseError(connectEventError);
this.statusChangeErrorSubscriptions.forEach(function (errorsHandler) { return errorsHandler(error); });
};
TonConnect.prototype.onWalletDisconnected = function () {
}
onWalletConnectError(connectEventError) {
const error = connect_errors_parser_1.connectErrorsParser.parseError(connectEventError);
this.statusChangeErrorSubscriptions.forEach(errorsHandler => errorsHandler(error));
}
onWalletDisconnected() {
this.wallet = null;
};
TonConnect.prototype.checkConnection = function () {
}
checkConnection() {
if (!this.connected) {
throw new wallet_not_connected_error_1.WalletNotConnectedError();
}
};
TonConnect.prototype.createConnectRequest = function (request) {
var webPageMetadata = (0, web_api_1.getWebPageMetadata)();
var metadata = (0, options_1.mergeOptions)(this.dappSettings.metadata, webPageMetadata);
var items = [
}
createConnectRequest(request) {
const webPageMetadata = (0, web_api_1.getWebPageMetadata)();
const metadata = (0, options_1.mergeOptions)(this.dappSettings.metadata, webPageMetadata);
const items = [
{

@@ -274,6 +233,5 @@ name: 'ton_addr'

}
return tslib_1.__assign(tslib_1.__assign({}, metadata), { items: items });
};
return TonConnect;
}());
return Object.assign(Object.assign({}, metadata), { items });
}
}
exports.TonConnect = TonConnect;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeOptions = void 0;
var tslib_1 = require("tslib");
var deepmerge_1 = tslib_1.__importDefault(require("deepmerge"));
const deepmerge_1 = __importDefault(require("deepmerge"));
function mergeOptions(options, defaultOptions) {

@@ -10,7 +12,5 @@ if (!options) {

}
var overwriteMerge = function (_, sourceArray, __) {
return sourceArray;
};
const overwriteMerge = (_, sourceArray, __) => sourceArray;
return (0, deepmerge_1.default)(defaultOptions, options, { arrayMerge: overwriteMerge });
}
exports.mergeOptions = mergeOptions;

@@ -13,17 +13,17 @@ "use strict";

function getIconUrl() {
var appleTouchIcons = document.querySelectorAll("link[rel='apple-touch-icon']");
const appleTouchIcons = document.querySelectorAll("link[rel='apple-touch-icon']");
if (appleTouchIcons === null || appleTouchIcons === void 0 ? void 0 : appleTouchIcons.length) {
return getLargestSizeIconUrl(Array.from(appleTouchIcons));
}
var links = Array.from(document.querySelectorAll("link[rel*='icon']"));
var pngLinks = links.filter(function (link) { return link.href.endsWith('.png'); });
const links = Array.from(document.querySelectorAll("link[rel*='icon']"));
const pngLinks = links.filter(link => link.href.endsWith('.png'));
if (pngLinks.length) {
return getLargestSizeIconUrl(pngLinks);
}
var icoIcon = links.filter(function (link) { return link.href.endsWith('.ico'); })[0];
const icoIcon = links.filter(link => link.href.endsWith('.ico'))[0];
return (icoIcon === null || icoIcon === void 0 ? void 0 : icoIcon.href) || '';
}
function getLargestSizeIconUrl(links) {
var parsedLinks = links.map(parseIconLink);
var maxSizeIcon = parsedLinks.sort(function (a, b) { return (b.size > a.size ? 1 : -1); })[0];
const parsedLinks = links.map(parseIconLink);
const maxSizeIcon = parsedLinks.sort((a, b) => (b.size > a.size ? 1 : -1))[0];
return (maxSizeIcon === null || maxSizeIcon === void 0 ? void 0 : maxSizeIcon.href) || '';

@@ -39,5 +39,5 @@ }

}
var sizes = Array.from(link.sizes)
.map(function (size) {
var groups = size.match(/(\d+)x(\d+)/i);
const sizes = Array.from(link.sizes)
.map(size => {
const groups = size.match(/(\d+)x(\d+)/i);
if (!groups || !groups[1] || !groups[2]) {

@@ -48,3 +48,3 @@ return undefined;

})
.filter(function (item) { return !!item; });
.filter(item => !!item);
if (sizes.length === 0) {

@@ -51,0 +51,0 @@ return {

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WalletsListManager = void 0;
var tslib_1 = require("tslib");
var fetch_wallets_error_1 = require("./errors/wallets-manager/fetch-wallets.error");
var wallet_info_1 = require("./models/wallet/wallet-info");
var injected_provider_1 = require("./provider/injected/injected-provider");
var WalletsListManager = /** @class */ (function () {
function WalletsListManager() {
const fetch_wallets_error_1 = require("./errors/wallets-manager/fetch-wallets.error");
const wallet_info_1 = require("./models/wallet/wallet-info");
const injected_provider_1 = require("./provider/injected/injected-provider");
class WalletsListManager {
constructor() {
this.walletsListCache = null;
this.walletsListSource = 'https://raw.githubusercontent.com/ton-connect/wallets-list/main/wallets.json';
}
WalletsListManager.prototype.getWallets = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _this = this;
return tslib_1.__generator(this, function (_a) {
if (!this.walletsListCache) {
this.walletsListCache = this.fetchWalletsList();
this.walletsListCache.catch(function () { return (_this.walletsListCache = null); });
}
return [2 /*return*/, this.walletsListCache];
});
getWallets() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.walletsListCache) {
this.walletsListCache = this.fetchWalletsList();
this.walletsListCache.catch(() => (this.walletsListCache = null));
}
return this.walletsListCache;
});
};
WalletsListManager.prototype.getEmbeddedWallet = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var walletsList, injectedWallets;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getWallets()];
case 1:
walletsList = _a.sent();
injectedWallets = walletsList.filter(wallet_info_1.isWalletInfoInjected);
if (injectedWallets.length !== 1) {
return [2 /*return*/, null];
}
return [2 /*return*/, injectedWallets[0].embedded ? injectedWallets[0] : null];
}
});
}
getEmbeddedWallet() {
return __awaiter(this, void 0, void 0, function* () {
const walletsList = yield this.getWallets();
const injectedWallets = walletsList.filter(wallet_info_1.isWalletInfoInjected);
if (injectedWallets.length !== 1) {
return null;
}
return injectedWallets[0].embedded ? injectedWallets[0] : null;
});
};
WalletsListManager.prototype.fetchWalletsList = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var walletsResponse, walletsList, e_1;
var _this = this;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
return [4 /*yield*/, fetch(this.walletsListSource)];
case 1:
walletsResponse = _a.sent();
return [4 /*yield*/, walletsResponse.json()];
case 2:
walletsList = _a.sent();
if (!Array.isArray(walletsList) ||
!walletsList.every(function (wallet) { return _this.isCorrectWalletConfigDTO(wallet); })) {
throw new fetch_wallets_error_1.FetchWalletsError('Wrong wallets list format');
}
return [2 /*return*/, this.walletConfigDTOListToWalletConfigList(walletsList)];
case 3:
e_1 = _a.sent();
throw new fetch_wallets_error_1.FetchWalletsError(e_1);
case 4: return [2 /*return*/];
}
fetchWalletsList() {
return __awaiter(this, void 0, void 0, function* () {
try {
const walletsResponse = yield fetch(this.walletsListSource);
const walletsList = yield walletsResponse.json();
if (!Array.isArray(walletsList) ||
!walletsList.every(wallet => this.isCorrectWalletConfigDTO(wallet))) {
throw new fetch_wallets_error_1.FetchWalletsError('Wrong wallets list format');
}
});
return this.walletConfigDTOListToWalletConfigList(walletsList);
}
catch (e) {
throw new fetch_wallets_error_1.FetchWalletsError(e);
}
});
};
WalletsListManager.prototype.walletConfigDTOListToWalletConfigList = function (walletConfigDTO) {
return walletConfigDTO.map(function (walletConfigDTO) {
var walletConfig = {
}
walletConfigDTOListToWalletConfigList(walletConfigDTO) {
return walletConfigDTO.map(walletConfigDTO => {
const walletConfig = {
name: walletConfigDTO.name,

@@ -82,3 +69,3 @@ imageUrl: walletConfigDTO.image,

if ('js_bridge_key' in walletConfigDTO) {
var jsBridgeKey = walletConfigDTO.js_bridge_key;
const jsBridgeKey = walletConfigDTO.js_bridge_key;
walletConfig.jsBridgeKey = jsBridgeKey;

@@ -92,20 +79,19 @@ walletConfig.injected =

});
};
WalletsListManager.prototype.isCorrectWalletConfigDTO = function (value) {
}
isCorrectWalletConfigDTO(value) {
if (!value || !(typeof value === 'object')) {
return false;
}
var containsName = 'name' in value;
var containsImage = 'image' in value;
var containsAbout = 'about_url' in value;
const containsName = 'name' in value;
const containsImage = 'image' in value;
const containsAbout = 'about_url' in value;
if (!containsName || !containsImage || !containsAbout) {
return false;
}
var containsUniversalUrl = 'universal_url' in value;
var containsHttpBridge = 'bridge_url' in value;
var containsJsBridge = 'js_bridge_key' in value;
const containsUniversalUrl = 'universal_url' in value;
const containsHttpBridge = 'bridge_url' in value;
const containsJsBridge = 'js_bridge_key' in value;
return (containsHttpBridge && containsUniversalUrl) || containsJsBridge;
};
return WalletsListManager;
}());
}
}
exports.WalletsListManager = WalletsListManager;
{
"name": "@tonconnect/sdk",
"version": "0.0.21",
"version": "0.0.22",
"scripts": {

@@ -29,3 +29,3 @@ "build": "npx rimraf lib && ttsc",

"tweetnacl": "^1.0.3",
"@tonconnect/protocol": "^0.0.10"
"@tonconnect/protocol": "^0.0.11"
},

@@ -32,0 +32,0 @@ "files": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc