@tonconnect/sdk 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/models/index.d.ts +1 -0
- package/lib/models/index.js +1 -0
- package/lib/provider/bridge/bridge-gateway.d.ts +1 -1
- package/lib/provider/bridge/bridge-gateway.js +4 -8
- package/lib/provider/bridge/bridge-provider.d.ts +1 -0
- package/lib/provider/bridge/bridge-provider.js +4 -1
- package/lib/ton-connect.js +15 -12
- package/lib/utils/url.d.ts +2 -0
- package/lib/utils/url.js +14 -0
- package/package.json +1 -1
package/lib/models/index.d.ts
CHANGED
package/lib/models/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BridgeIncomingMessage } from "./models/bridge-incomming-message";
|
|
2
2
|
export declare class BridgeGateway {
|
|
3
|
+
private readonly bridgeUrl;
|
|
3
4
|
readonly sessionId: string;
|
|
4
5
|
private readonly listener;
|
|
5
6
|
private readonly errorsListener;
|
|
@@ -8,7 +9,6 @@ export declare class BridgeGateway {
|
|
|
8
9
|
private readonly defaultTtl;
|
|
9
10
|
private eventSource;
|
|
10
11
|
private isClosed;
|
|
11
|
-
private readonly bridgeUrl;
|
|
12
12
|
constructor(bridgeUrl: string, sessionId: string, listener: (msg: BridgeIncomingMessage) => void, errorsListener: (err: Event) => void);
|
|
13
13
|
registerSession(): Promise<void>;
|
|
14
14
|
send(message: Uint8Array, receiver: string, ttl?: number): Promise<void>;
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BridgeGateway = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
+
var url_1 = require("../../utils/url");
|
|
5
6
|
var BridgeGateway = /** @class */ (function () {
|
|
6
7
|
function BridgeGateway(bridgeUrl, sessionId, listener, errorsListener) {
|
|
8
|
+
this.bridgeUrl = bridgeUrl;
|
|
7
9
|
this.sessionId = sessionId;
|
|
8
10
|
this.listener = listener;
|
|
9
11
|
this.errorsListener = errorsListener;
|
|
@@ -11,19 +13,13 @@ var BridgeGateway = /** @class */ (function () {
|
|
|
11
13
|
this.postPath = 'message';
|
|
12
14
|
this.defaultTtl = 300;
|
|
13
15
|
this.isClosed = false;
|
|
14
|
-
if (bridgeUrl.slice(-1) === '/') {
|
|
15
|
-
this.bridgeUrl = bridgeUrl.slice(0, -1);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
this.bridgeUrl = bridgeUrl;
|
|
19
|
-
}
|
|
20
16
|
}
|
|
21
17
|
BridgeGateway.prototype.registerSession = function () {
|
|
22
18
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
23
19
|
var url;
|
|
24
20
|
var _this = this;
|
|
25
21
|
return tslib_1.__generator(this, function (_a) {
|
|
26
|
-
url = new URL(
|
|
22
|
+
url = new URL((0, url_1.addPathToUrl)(this.bridgeUrl, this.ssePath));
|
|
27
23
|
url.searchParams.append('client_id', this.sessionId);
|
|
28
24
|
this.eventSource = new EventSource(url);
|
|
29
25
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
@@ -43,7 +39,7 @@ var BridgeGateway = /** @class */ (function () {
|
|
|
43
39
|
return tslib_1.__generator(this, function (_a) {
|
|
44
40
|
switch (_a.label) {
|
|
45
41
|
case 0:
|
|
46
|
-
url = new URL(
|
|
42
|
+
url = new URL((0, url_1.addPathToUrl)(this.bridgeUrl, this.postPath));
|
|
47
43
|
url.searchParams.append('client_id', this.sessionId);
|
|
48
44
|
url.searchParams.append('to', receiver);
|
|
49
45
|
url.searchParams.append('ttl', (ttl || this.defaultTtl).toString());
|
|
@@ -6,6 +6,7 @@ import { WithoutId } from "../../utils/types";
|
|
|
6
6
|
export declare class BridgeProvider implements HTTPProvider {
|
|
7
7
|
private readonly walletConnectionSource;
|
|
8
8
|
readonly type = "http";
|
|
9
|
+
private readonly universalLinkPath;
|
|
9
10
|
private readonly connectionStorage;
|
|
10
11
|
private readonly pendingRequests;
|
|
11
12
|
private nextRequestId;
|
|
@@ -7,10 +7,12 @@ var ton_connect_error_1 = require("../../errors/ton-connect.error");
|
|
|
7
7
|
var bridge_gateway_1 = require("./bridge-gateway");
|
|
8
8
|
var bridge_connection_storage_1 = require("../../storage/bridge-connection-storage");
|
|
9
9
|
var protocol = tslib_1.__importStar(require("../../resources/protocol.json"));
|
|
10
|
+
var url_1 = require("../../utils/url");
|
|
10
11
|
var BridgeProvider = /** @class */ (function () {
|
|
11
12
|
function BridgeProvider(storage, walletConnectionSource) {
|
|
12
13
|
this.walletConnectionSource = walletConnectionSource;
|
|
13
14
|
this.type = 'http';
|
|
15
|
+
this.universalLinkPath = 'ton-connect';
|
|
14
16
|
this.pendingRequests = new Map();
|
|
15
17
|
this.nextRequestId = 0;
|
|
16
18
|
this.session = null;
|
|
@@ -149,7 +151,8 @@ var BridgeProvider = /** @class */ (function () {
|
|
|
149
151
|
});
|
|
150
152
|
};
|
|
151
153
|
BridgeProvider.prototype.generateUniversalLink = function (message) {
|
|
152
|
-
var
|
|
154
|
+
var urlString = (0, url_1.addPathToUrl)(this.walletConnectionSource.universalLinkBase, this.universalLinkPath);
|
|
155
|
+
var url = new URL(urlString);
|
|
153
156
|
url.searchParams.append('v', protocol.version.toString());
|
|
154
157
|
url.searchParams.append('id', this.session.sessionCrypto.sessionId);
|
|
155
158
|
url.searchParams.append('r', protocol_1.Base64.encode(JSON.stringify(message), true));
|
package/lib/ton-connect.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TonConnect = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var protocol_1 = require("@tonconnect/protocol");
|
|
6
5
|
var ton_connect_error_1 = require("./errors/ton-connect.error");
|
|
7
6
|
var wallet_already_connected_error_1 = require("./errors/wallet/wallet-already-connected.error");
|
|
8
7
|
var wallet_not_connected_error_1 = require("./errors/wallet/wallet-not-connected.error");
|
|
@@ -81,22 +80,26 @@ var TonConnect = /** @class */ (function () {
|
|
|
81
80
|
};
|
|
82
81
|
TonConnect.prototype._autoConnect = function () {
|
|
83
82
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
84
|
-
var bridgeConnection,
|
|
85
|
-
return tslib_1.__generator(this, function (
|
|
86
|
-
switch (
|
|
83
|
+
var bridgeConnection, _a, _b;
|
|
84
|
+
return tslib_1.__generator(this, function (_c) {
|
|
85
|
+
switch (_c.label) {
|
|
87
86
|
case 0: return [4 /*yield*/, this.bridgeConnectionStorage.getConnection()];
|
|
88
87
|
case 1:
|
|
89
|
-
bridgeConnection =
|
|
88
|
+
bridgeConnection = _c.sent();
|
|
90
89
|
if (!bridgeConnection) return [3 /*break*/, 3];
|
|
90
|
+
_a = this;
|
|
91
91
|
return [4 /*yield*/, this.createProvider(bridgeConnection.session.walletConnectionSource)];
|
|
92
92
|
case 2:
|
|
93
|
-
provider =
|
|
94
|
-
return [
|
|
95
|
-
case 3:
|
|
93
|
+
_a.provider = _c.sent();
|
|
94
|
+
return [2 /*return*/, this.provider.autoConnect()];
|
|
95
|
+
case 3:
|
|
96
|
+
if (!injected_provider_1.InjectedProvider.isWalletInjected()) return [3 /*break*/, 5];
|
|
97
|
+
_b = this;
|
|
98
|
+
return [4 /*yield*/, this.createProvider('injected')];
|
|
96
99
|
case 4:
|
|
97
|
-
provider =
|
|
98
|
-
|
|
99
|
-
case 5: return [2 /*return
|
|
100
|
+
_b.provider = _c.sent();
|
|
101
|
+
return [2 /*return*/, this.provider.autoConnect()];
|
|
102
|
+
case 5: return [2 /*return*/];
|
|
100
103
|
}
|
|
101
104
|
});
|
|
102
105
|
});
|
|
@@ -170,7 +173,7 @@ var TonConnect = /** @class */ (function () {
|
|
|
170
173
|
provider: this.provider.type,
|
|
171
174
|
account: {
|
|
172
175
|
address: tonAccountItem.address,
|
|
173
|
-
chain:
|
|
176
|
+
chain: tonAccountItem.network
|
|
174
177
|
}
|
|
175
178
|
};
|
|
176
179
|
if (tonProofItem) {
|
package/lib/utils/url.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addPathToUrl = exports.removeUrlLastSlash = void 0;
|
|
4
|
+
function removeUrlLastSlash(url) {
|
|
5
|
+
if (url.slice(-1) === '/') {
|
|
6
|
+
return url.slice(0, -1);
|
|
7
|
+
}
|
|
8
|
+
return url;
|
|
9
|
+
}
|
|
10
|
+
exports.removeUrlLastSlash = removeUrlLastSlash;
|
|
11
|
+
function addPathToUrl(url, path) {
|
|
12
|
+
return removeUrlLastSlash(url) + '/' + path;
|
|
13
|
+
}
|
|
14
|
+
exports.addPathToUrl = addPathToUrl;
|