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.12 to 0.0.13

lib/storage/bridge-gateway-storage.d.ts

4

lib/provider/bridge/bridge-gateway.d.ts
import { BridgeIncomingMessage } from "./models/bridge-incomming-message";
import { IStorage } from "../../storage/models/storage.interface";
export declare class BridgeGateway {

@@ -12,3 +13,4 @@ private readonly bridgeUrl;

private isClosed;
constructor(bridgeUrl: string, sessionId: string, listener: (msg: BridgeIncomingMessage) => void, errorsListener: (err: Event) => void);
private readonly bridgeGatewayStorage;
constructor(storage: IStorage, bridgeUrl: string, sessionId: string, listener: (msg: BridgeIncomingMessage) => void, errorsListener: (err: Event) => void);
registerSession(): Promise<void>;

@@ -15,0 +17,0 @@ send(message: Uint8Array, receiver: string, ttl?: number): Promise<void>;

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

var errors_1 = require("../../errors");
var bridge_gateway_storage_1 = require("../../storage/bridge-gateway-storage");
var url_1 = require("../../utils/url");
var BridgeGateway = /** @class */ (function () {
function BridgeGateway(bridgeUrl, sessionId, listener, errorsListener) {
function BridgeGateway(storage, bridgeUrl, sessionId, listener, errorsListener) {
this.bridgeUrl = bridgeUrl;

@@ -19,19 +20,29 @@ this.sessionId = sessionId;

this.isClosed = false;
this.bridgeGatewayStorage = new bridge_gateway_storage_1.BridgeGatewayStorage(storage);
}
BridgeGateway.prototype.registerSession = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var url;
var url, lastEventId;
var _this = this;
return tslib_1.__generator(this, function (_a) {
url = new URL((0, url_1.addPathToUrl)(this.bridgeUrl, this.ssePath));
url.searchParams.append('client_id', this.sessionId);
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();
};
})];
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();
};
})];
}
});

@@ -72,12 +83,23 @@ });

BridgeGateway.prototype.messagesHandler = function (e) {
if (!this.isClosed) {
var 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 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*/];
}
});
});
};

@@ -84,0 +106,0 @@ return BridgeGateway;

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

export declare class BridgeProvider implements HTTPProvider {
private readonly storage;
private readonly walletConnectionSource;

@@ -9,0 +10,0 @@ readonly type = "http";

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

function BridgeProvider(storage, walletConnectionSource) {
this.storage = storage;
this.walletConnectionSource = walletConnectionSource;

@@ -32,3 +33,3 @@ this.type = 'http';

};
this.bridge = new bridge_gateway_1.BridgeGateway(this.walletConnectionSource.bridgeUrl, sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this));
this.bridge = new bridge_gateway_1.BridgeGateway(this.storage, this.walletConnectionSource.bridgeUrl, sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this));
this.bridge.registerSession();

@@ -52,3 +53,3 @@ return this.generateUniversalLink(message);

this.session = storedConnection.session;
this.bridge = new bridge_gateway_1.BridgeGateway(this.walletConnectionSource.bridgeUrl, storedConnection.session.sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this));
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()];

@@ -55,0 +56,0 @@ case 2:

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

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

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