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.13 to 0.0.14

lib/errors/wallets-manager/fetch-wallets.error.d.ts

1

lib/errors/index.d.ts
export * from './protocol';
export * from './wallet';
export * from './storage';
export * from './wallets-manager';
export { TonConnectError } from './ton-connect.error';
export { UnknownError } from './unknown.error';

@@ -8,2 +8,3 @@ "use strict";

tslib_1.__exportStar(require("./storage"), exports);
tslib_1.__exportStar(require("./wallets-manager"), exports);
var ton_connect_error_1 = require("./ton-connect.error");

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

export type { Account } from './account';
export type { Wallet } from './wallet';
export type { WalletConnectionSource } from './wallet-connection-source';
export type { WalletConfig, JSBridgeWalletConfig, HTTPBridgeWalletConfig } from './wallet-config';

@@ -1,4 +0,9 @@

export interface WalletConnectionSource {
export declare type WalletConnectionSource = WalletConnectionSourceHTTP | WalletConnectionSourceJS;
export interface WalletConnectionSourceHTTP {
universalLinkBase: string;
bridgeUrl: string;
}
export interface WalletConnectionSourceJS {
jsBridgeKey: string;
}
export declare function isWalletConnectionSourceJS(value: WalletConnectionSource): value is WalletConnectionSourceJS;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isWalletConnectionSourceJS = void 0;
function isWalletConnectionSourceJS(value) {
return 'jsBridgeKey' in value;
}
exports.isWalletConnectionSourceJS = isWalletConnectionSourceJS;

4

lib/provider/bridge/bridge-gateway.js

@@ -7,3 +7,3 @@ "use strict";

var errors_1 = require("../../errors");
var bridge_gateway_storage_1 = require("../../storage/bridge-gateway-storage");
var http_bridge_gateway_storage_1 = require("../../storage/http-bridge-gateway-storage");
var url_1 = require("../../utils/url");

@@ -20,3 +20,3 @@ var BridgeGateway = /** @class */ (function () {

this.isClosed = false;
this.bridgeGatewayStorage = new bridge_gateway_storage_1.BridgeGatewayStorage(storage);
this.bridgeGatewayStorage = new http_bridge_gateway_storage_1.HttpBridgeGatewayStorage(storage);
}

@@ -23,0 +23,0 @@ BridgeGateway.prototype.registerSession = function () {

import { AppRequest, ConnectRequest, RpcMethod, WalletEvent, WalletResponse } from '@tonconnect/protocol';
import { WalletConnectionSource } from "../../models";
import { WalletConnectionSourceHTTP } from "../../models/wallet/wallet-connection-source";
import { HTTPProvider } from "../provider";

@@ -9,2 +9,3 @@ import { IStorage } from "../../storage/models/storage.interface";

private readonly walletConnectionSource;
static fromStorage(storage: IStorage): Promise<BridgeProvider>;
readonly type = "http";

@@ -18,5 +19,5 @@ private readonly universalLinkPath;

private listeners;
constructor(storage: IStorage, walletConnectionSource: WalletConnectionSource);
constructor(storage: IStorage, walletConnectionSource: WalletConnectionSourceHTTP);
connect(message: ConnectRequest): string;
autoConnect(): Promise<void>;
restoreConnection(): Promise<void>;
sendRequest<T extends RpcMethod>(request: WithoutId<AppRequest<T>>): Promise<WithoutId<WalletResponse<T>>>;

@@ -23,0 +24,0 @@ closeConnection(): void;

@@ -24,2 +24,17 @@ "use strict";

}
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)];
}
});
});
};
BridgeProvider.prototype.connect = function (message) {

@@ -37,3 +52,3 @@ var _a;

};
BridgeProvider.prototype.autoConnect = function () {
BridgeProvider.prototype.restoreConnection = function () {
var _a;

@@ -46,3 +61,3 @@ return tslib_1.__awaiter(this, void 0, void 0, function () {

(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
return [4 /*yield*/, this.connectionStorage.getConnection()];
return [4 /*yield*/, this.connectionStorage.getHttpConnection()];
case 1:

@@ -131,2 +146,3 @@ storedConnection = _b.sent();

return tslib_1.__awaiter(this, void 0, void 0, function () {
var tonAddrItem, connectEventToSave;
return tslib_1.__generator(this, function (_a) {

@@ -136,3 +152,9 @@ switch (_a.label) {

this.session = tslib_1.__assign(tslib_1.__assign({}, this.session), { walletPublicKey: walletPublicKey });
return [4 /*yield*/, this.connectionStorage.storeConnection({ session: this.session, connectEvent: connectEvent })];
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:

@@ -139,0 +161,0 @@ _a.sent();

@@ -1,11 +0,23 @@

import { ConnectEventSuccess } from '@tonconnect/protocol';
import { BridgeSessionRaw } from './bridge-session-raw';
import { DeviceInfo, TonAddressItemReply } from '@tonconnect/protocol';
import { BridgeSessionRaw } from "./bridge-session-raw";
import { BridgeSession } from './bridge-session';
export interface BridgeConnection {
connectEvent: ConnectEventSuccess;
export declare type BridgeConnection = BridgeConnectionHttp | BridgeConnectionInjected;
export interface BridgeConnectionInjected {
type: 'injected';
jsBridgeKey: string;
}
export interface BridgeConnectionHttp {
type: 'http';
connectEvent: {
event: 'connect';
payload: {
items: [TonAddressItemReply];
device: DeviceInfo;
};
};
session: BridgeSession;
}
export interface BridgeConnectionRaw {
connectEvent: ConnectEventSuccess;
export declare type BridgeConnectionHttpRaw = Omit<BridgeConnectionHttp, 'session'> & {
session: BridgeSessionRaw;
}
};
export declare type BridgeConnectionRaw = BridgeConnectionHttpRaw | BridgeConnectionInjected;
import { SessionCrypto } from '@tonconnect/protocol';
import { WalletConnectionSource } from "../../../models";
import { WalletConnectionSourceHTTP } from "../../../models/wallet/wallet-connection-source";
export interface BridgeSession {
sessionCrypto: SessionCrypto;
walletPublicKey: string;
walletConnectionSource: WalletConnectionSource;
walletConnectionSource: WalletConnectionSourceHTTP;
}
export declare type BridgePartialSession = Omit<BridgeSession, 'walletPublicKey'>;

@@ -1,8 +0,11 @@

import { AppRequest, RpcMethod, WalletResponse, DeviceInfo, ConnectRequest, WalletEvent } from '@tonconnect/protocol';
import { AppRequest, RpcMethod, WalletResponse, ConnectRequest, WalletEvent } from '@tonconnect/protocol';
import { InternalProvider } from "../provider";
import { IStorage } from "../../storage/models/storage.interface";
import { WithoutId } from "../../utils/types";
export declare class InjectedProvider implements InternalProvider {
export declare class InjectedProvider<T extends string = string> implements InternalProvider {
private static window;
static isWalletInjected(): boolean;
static deviceInfo(): DeviceInfo | undefined;
static fromStorage(storage: IStorage): Promise<InjectedProvider>;
static isWalletInjected(injectedWalletKey: string): boolean;
static isInsideWalletBrowser(injectedWalletKey: string): boolean;
private static isWindowContainsWallet;
readonly type = "injected";

@@ -13,5 +16,5 @@ private unsubscribeCallback;

private listeners;
constructor();
constructor(injectedWalletKey: T);
connect(message: ConnectRequest, auto?: boolean): void;
autoConnect(): Promise<void>;
restoreConnection(): Promise<void>;
closeConnection(): void;

@@ -18,0 +21,0 @@ disconnect(): Promise<void>;

@@ -7,4 +7,5 @@ "use strict";

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() {
function InjectedProvider(injectedWalletKey) {
this.type = 'injected';

@@ -14,17 +15,38 @@ this.unsubscribeCallback = null;

this.listeners = [];
if (!InjectedProvider.isWalletInjected()) {
var window = InjectedProvider.window;
if (!InjectedProvider.isWindowContainsWallet(window, injectedWalletKey)) {
throw new wallet_not_injected_error_1.WalletNotInjectedError();
}
this.injectedWallet = InjectedProvider.window.tonconnect;
this.injectedWallet = window[injectedWalletKey].tonconnect;
}
InjectedProvider.isWalletInjected = function () {
return (InjectedProvider.window &&
'tonconnect' in InjectedProvider.window &&
typeof InjectedProvider.window.tonconnect === 'object');
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)];
}
});
});
};
InjectedProvider.deviceInfo = function () {
return InjectedProvider.isWalletInjected()
? InjectedProvider.window.tonconnect.deviceInfo
: undefined;
InjectedProvider.isWalletInjected = function (injectedWalletKey) {
return InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey);
};
InjectedProvider.isInsideWalletBrowser = function (injectedWalletKey) {
if (InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey)) {
return this.window[injectedWalletKey].tonconnect.isWalletBrowser;
}
return false;
};
InjectedProvider.isWindowContainsWallet = function (window, injectedWalletKey) {
return (window &&
injectedWalletKey in window &&
typeof window[injectedWalletKey] === 'object' &&
'tonconnect' in window[injectedWalletKey]);
};
InjectedProvider.prototype.connect = function (message, auto) {

@@ -53,3 +75,3 @@ var _this = this;

};
InjectedProvider.prototype.autoConnect = function () {
InjectedProvider.prototype.restoreConnection = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {

@@ -61,3 +83,3 @@ var connectEvent_1, e_1;

_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, this.injectedWallet.autoConnect()];
return [4 /*yield*/, this.injectedWallet.restoreConnection()];
case 1:

@@ -64,0 +86,0 @@ connectEvent_1 = _a.sent();

@@ -5,6 +5,7 @@ import { AppRequest, ConnectEvent, ConnectRequest, DeviceInfo, RpcMethod, WalletEvent, WalletResponse } from '@tonconnect/protocol';

protocolVersion: number;
isWalletBrowser: boolean;
connect(protocolVersion: number, message: ConnectRequest, auto: boolean): Promise<ConnectEvent>;
autoConnect(): Promise<ConnectEvent>;
restoreConnection(): Promise<ConnectEvent>;
send<T extends RpcMethod>(message: AppRequest<T>): Promise<WalletResponse<T>>;
listen(callback: (event: WalletEvent) => void): () => void;
}

@@ -14,3 +14,3 @@ import { AppRequest, ConnectRequest, RpcMethod, WalletEvent, WalletResponse } from '@tonconnect/protocol';

interface BaseProvider {
autoConnect(): Promise<void>;
restoreConnection(): Promise<void>;
closeConnection(): void;

@@ -17,0 +17,0 @@ disconnect(): Promise<void>;

@@ -1,2 +0,2 @@

import { BridgeConnection } from "../provider/bridge/models/bridge-connection";
import { BridgeConnection, BridgeConnectionHttp, BridgeConnectionInjected } from "../provider/bridge/models/bridge-connection";
import { IStorage } from "./models/storage.interface";

@@ -10,3 +10,5 @@ export declare class BridgeConnectionStorage {

getConnection(): Promise<BridgeConnection | null>;
storedConnectionExists(): Promise<boolean>;
getHttpConnection(): Promise<BridgeConnectionHttp>;
getInjectedConnection(): Promise<BridgeConnectionInjected>;
storedConnectionType(): Promise<BridgeConnection['type'] | null>;
}

@@ -6,6 +6,7 @@ "use strict";

var protocol_1 = require("@tonconnect/protocol");
var errors_1 = require("../errors");
var BridgeConnectionStorage = /** @class */ (function () {
function BridgeConnectionStorage(storage) {
this.storage = storage;
this.storeKey = 'ton-connect-storage_http-bridge-connection';
this.storeKey = 'ton-connect-storage_bridge-connection';
}

@@ -16,2 +17,5 @@ BridgeConnectionStorage.prototype.storeConnection = function (connection) {

return tslib_1.__generator(this, function (_a) {
if (connection.type === 'injected') {
return [2 /*return*/, this.storage.setItem(this.storeKey, JSON.stringify(connection))];
}
rawSession = {

@@ -23,4 +27,5 @@ sessionKeyPair: connection.session.sessionCrypto.stringifyKeypair(),

rawConnection = {
session: rawSession,
connectEvent: connection.connectEvent
type: 'http',
connectEvent: connection.connectEvent,
session: rawSession
};

@@ -40,3 +45,3 @@ return [2 /*return*/, this.storage.setItem(this.storeKey, JSON.stringify(rawConnection))];

return tslib_1.__awaiter(this, void 0, void 0, function () {
var stored, rawConnection, sessionCrypto;
var stored, connection, sessionCrypto;
return tslib_1.__generator(this, function (_a) {

@@ -50,10 +55,14 @@ switch (_a.label) {

}
rawConnection = JSON.parse(stored);
sessionCrypto = new protocol_1.SessionCrypto(rawConnection.session.sessionKeyPair);
connection = JSON.parse(stored);
if (connection.type === 'injected') {
return [2 /*return*/, connection];
}
sessionCrypto = new protocol_1.SessionCrypto(connection.session.sessionKeyPair);
return [2 /*return*/, {
connectEvent: rawConnection.connectEvent,
type: 'http',
connectEvent: connection.connectEvent,
session: {
sessionCrypto: sessionCrypto,
walletConnectionSource: rawConnection.session.walletConnectionSource,
walletPublicKey: rawConnection.session.walletPublicKey
walletConnectionSource: connection.session.walletConnectionSource,
walletPublicKey: connection.session.walletPublicKey
}

@@ -65,11 +74,53 @@ }];

};
BridgeConnectionStorage.prototype.storedConnectionExists = function () {
BridgeConnectionStorage.prototype.getHttpConnection = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var stored;
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];
}
});
});
};
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];
}
});
});
};
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();
return [2 /*return*/, !!stored];
if (!stored) {
return [2 /*return*/, null];
}
connection = JSON.parse(stored);
return [2 /*return*/, connection.type];
}

@@ -76,0 +127,0 @@ });

@@ -5,6 +5,9 @@ import { TonConnectError } from "./errors/ton-connect.error";

import { ConnectAdditionalRequest } from "./models/methods/connect/connect-additional-request";
import { InjectedProvider } from "./provider/injected/injected-provider";
import { JSBridgeWalletConfig } from "./models/wallet/wallet-config";
import { WalletConnectionSourceJS } from "./models/wallet/wallet-connection-source";
import { IStorage } from "./storage/models/storage.interface";
import { ITonConnect } from "./ton-connect.interface";
import { WalletsListManager } from "./wallets-list-manager";
export declare class TonConnect implements ITonConnect {
walletsList: WalletsListManager;
private readonly dappSettings;

@@ -36,3 +39,3 @@ private readonly bridgeConnectionStorage;

*/
isInjectedProviderAvailable: typeof InjectedProvider.isWalletInjected;
inWhichWalletBrowser(): Promise<JSBridgeWalletConfig | null>;
/**

@@ -47,11 +50,11 @@ * Allows to subscribe to connection status changes and handle connection errors.

* Generates universal link for an external wallet and subscribes to the wallet's bridge, or sends connect request to the injected wallet.
* @param wallet wallet's bridge url and universal link for an external wallet or 'injected' for the injected wallet.
* @param wallet wallet's bridge url and universal link for an external wallet or jsBridge key for the injected wallet.
* @param request (optional) additional request to pass to the wallet while connect (currently only ton_proof is available).
* @returns universal link if external wallet was passed or void for the injected wallet.
*/
connect<T extends WalletConnectionSource | 'injected'>(wallet: T, request?: ConnectAdditionalRequest): T extends 'injected' ? void : string;
connect<T extends WalletConnectionSource>(wallet: T, request?: ConnectAdditionalRequest): T extends WalletConnectionSourceJS ? void : string;
/**
* Try to restore existing session and reconnect to the corresponding wallet. Call it immediately when your app is loaded.
*/
autoConnect(): void;
restoreConnection(): Promise<void>;
/**

@@ -68,3 +71,2 @@ * Asks connected wallet to sign and send the transaction.

disconnect(): Promise<void>;
private _autoConnect;
private createProvider;

@@ -71,0 +73,0 @@ private walletEventsListener;

@@ -5,2 +5,4 @@ import { TonConnectError } from "./errors";

import { ConnectAdditionalRequest } from "./models/methods/connect/connect-additional-request";
import { JSBridgeWalletConfig, WalletConfig } from "./models/wallet/wallet-config";
import { WalletConnectionSourceJS } from "./models/wallet/wallet-connection-source";
export interface ITonConnect {

@@ -20,6 +22,13 @@ /**

/**
* Indicates if the injected wallet is available.
* Allows to get information about supported wallets
*/
isInjectedProviderAvailable(): boolean;
walletsList: {
getWalletsList: () => Promise<WalletConfig[]>;
getInjectedWalletsList: () => Promise<JSBridgeWalletConfig[]>;
};
/**
* If app is opened in some wallet's browser returns that wallet config. Else returns null;
*/
inWhichWalletBrowser(): Promise<JSBridgeWalletConfig | null>;
/**
* Allows to subscribe to connection status changes and handle connection errors.

@@ -33,11 +42,11 @@ * @param callback will be called after connections status changes with actual wallet or null.

* Generates universal link for an external wallet and subscribes to the wallet's bridge, or sends connect request to the injected wallet.
* @param wallet wallet's bridge url and universal link for an external wallet or 'injected' for the injected wallet.
* @param wallet wallet's bridge url and universal link for an external wallet or jsBridge key for the injected wallet.
* @param request (optional) additional request to pass to the wallet while connect (currently only ton_proof is available).
* @returns universal link if external wallet was passed or void for the injected wallet.
*/
connect<T extends WalletConnectionSource | 'injected'>(wallet: T, request?: ConnectAdditionalRequest): T extends 'injected' ? void : string;
connect<T extends WalletConnectionSource>(wallet: T, request?: ConnectAdditionalRequest): T extends WalletConnectionSourceJS ? void : string;
/**
* Try to restore existing session and reconnect to the corresponding wallet. Call it immediately when your app is loaded.
*/
autoConnect(): void;
restoreConnection(): Promise<void>;
/**

@@ -44,0 +53,0 @@ * Disconnect form thw connected wallet and drop current session.

@@ -8,2 +8,3 @@ "use strict";

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");

@@ -17,4 +18,6 @@ var send_transaction_parser_1 = require("./parsers/send-transaction-parser");

var web_api_1 = require("./utils/web-api");
var wallets_list_manager_1 = require("./wallets-list-manager");
var TonConnect = /** @class */ (function () {
function TonConnect(options) {
this.walletsList = new wallets_list_manager_1.WalletsListManager();
this._wallet = null;

@@ -24,6 +27,2 @@ this.provider = null;

this.statusChangeErrorSubscriptions = [];
/**
* Indicates if the injected wallet is available.
*/
this.isInjectedProviderAvailable = injected_provider_1.InjectedProvider.isWalletInjected;
this.dappSettings = {

@@ -72,2 +71,24 @@ metadata: (0, options_1.mergeOptions)(options === null || options === void 0 ? void 0 : options.dappMetedata, (0, web_api_1.getWebPageMetadata)()),

/**
* Indicates if the injected wallet is available.
*/
TonConnect.prototype.inWhichWalletBrowser = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var injectedWalletsList;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.walletsList.getInjectedWalletsList()];
case 1:
injectedWalletsList = _a.sent();
if (injectedWalletsList.length !== 1) {
return [2 /*return*/, null];
}
if (!injected_provider_1.InjectedProvider.isInsideWalletBrowser(injectedWalletsList[0].jsBridgeKey)) {
return [2 /*return*/, null];
}
return [2 /*return*/, injectedWalletsList[0]];
}
});
});
};
/**
* Allows to subscribe to connection status changes and handle connection errors.

@@ -103,4 +124,47 @@ * @param callback will be called after connections status changes with actual wallet or null.

*/
TonConnect.prototype.autoConnect = function () {
this._autoConnect();
TonConnect.prototype.restoreConnection = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _a, bridgeConnectionType, injectedWalletsList, _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.getInjectedWalletsList()
])];
case 1:
_a = _f.sent(), bridgeConnectionType = _a[0], injectedWalletsList = _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 (!(injectedWalletsList.length === 1)) return [3 /*break*/, 8];
// DApp probably opened in the wallet's browser. Should try smart auto connect
_e = this;
return [4 /*yield*/, this.createProvider(injectedWalletsList[0])];
case 7:
// DApp probably opened in the wallet's browser. Should try smart auto connect
_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()];
}
});
});
};

@@ -151,32 +215,6 @@ /**

};
TonConnect.prototype._autoConnect = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var bridgeConnection, _a, _b;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, this.bridgeConnectionStorage.getConnection()];
case 1:
bridgeConnection = _c.sent();
if (!bridgeConnection) return [3 /*break*/, 3];
_a = this;
return [4 /*yield*/, this.createProvider(bridgeConnection.session.walletConnectionSource)];
case 2:
_a.provider = _c.sent();
return [2 /*return*/, this.provider.autoConnect()];
case 3:
if (!injected_provider_1.InjectedProvider.isWalletInjected()) return [3 /*break*/, 5];
_b = this;
return [4 /*yield*/, this.createProvider('injected')];
case 4:
_b.provider = _c.sent();
return [2 /*return*/, this.provider.autoConnect()];
case 5: return [2 /*return*/];
}
});
});
};
TonConnect.prototype.createProvider = function (wallet) {
var provider;
if (wallet === 'injected') {
provider = new injected_provider_1.InjectedProvider();
if ((0, wallet_connection_source_1.isWalletConnectionSourceJS)(wallet)) {
provider = new injected_provider_1.InjectedProvider(wallet.jsBridgeKey);
}

@@ -183,0 +221,0 @@ else {

{
"name": "@tonconnect/sdk",
"version": "0.0.13",
"version": "0.0.14",
"scripts": {

@@ -5,0 +5,0 @@ "build": "npx rimraf lib && ttsc",

@@ -7,2 +7,3 @@ # TON Connect SDK

You can find more details and the protocol specification in the [docs](https://github.com/ton-connect/docs).
See the example of sdk usage [here](https://github.com/ton-connect/demo-dapp).

@@ -19,3 +20,3 @@ ## Get started

connector.autoConnect();
connector.restoreConnection();
```

@@ -32,3 +33,50 @@

## Fetch wallets list
TonConnect is build to support different wallets. You can fetch all supported wallets list and show a custom wallet selection dialog for user
```ts
const { allWalletsList, injectedWalletsList, remoteConnectionWalletsList } = await connector.walletsList.getWalletsConfig();
/* allWalletsList is
{
name: string;
imageUrl: string;
tondns?: string;
aboutUrl: string;
universalLinkBase?: string;
bridgeUrl?: string;
jsBridgeKey?: string;
}[]
injectedWalletsList is (all injected to the page available wallets)
{
name: string;
imageUrl: string;
tondns?: string;
aboutUrl: string;
jsBridgeKey: string;
}[]
remoteConnectionWalletsList is (all wallets available via http bridge (QR code))
{
name: string;
imageUrl: string;
tondns?: string;
aboutUrl: string;
universalLinkBase: string;
bridgeUrl: string;
}[]
*/
```
### Check if your app is opened inside some wallet's browser
If your app is opened inside some wallet's browser you shouldn't show a wallet selection dialog. Just connect dapp to the host-wallet when 'connect' button is clicked
```ts
const walletConnectionSourceOrNull = await connector.inWhichWalletBrowser();
```
## Initialize a wallet connection when user clicks to 'connect' button in your app

@@ -50,5 +98,7 @@ ### Initialize a remote wallet connection via universal link

```ts
if (connector.isInjectedProviderAvailable()) {
connector.connect('injected');
const walletConnectionSource = {
jsBridgeKey: 'tonkeeper'
}
connector.connect(walletConnectionSource);
```

@@ -70,3 +120,3 @@

amount: "20000000",
initState: "base64bocblahblahblah=="
initState: "base64bocblahblahblah==" // just for instance. Replace with your transaction initState or remove
},

@@ -76,3 +126,3 @@ {

amount: "60000000",
payload: "base64bocblahblahblah=="
payload: "base64bocblahblahblah==" // just for instance. Replace with your transaction payload or remove
}

@@ -79,0 +129,0 @@ ]

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