@tonconnect/sdk 0.0.3 → 0.0.5
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/README.md +22 -16
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- 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.d.ts +39 -3
- package/lib/ton-connect.interface.d.ts +40 -3
- package/lib/ton-connect.js +59 -28
- package/lib/utils/url.d.ts +2 -0
- package/lib/utils/url.js +14 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
# TON Connect SDK
|
|
1
|
+
# TON Connect SDK
|
|
2
2
|
|
|
3
|
-
⚠️
|
|
3
|
+
⚠️ TonConnect is currently in beta testing. Use it at your own risk.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Use it to connect your app to TON wallets via TonConnect protocol.
|
|
6
|
+
You can find more details and the protocol specification in the [docs](https://github.com/ton-connect/docs).
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
## Get started
|
|
9
|
+
`npm i @tonconnect/sdk`
|
|
10
|
+
|
|
11
|
+
## Init connector and call autoConnect. If user connected his wallet before, connector will restore the connection
|
|
12
|
+
|
|
13
|
+
```ts
|
|
8
14
|
import TonConnect from '@tonconnect/sdk';
|
|
9
15
|
|
|
10
16
|
const connector = new TonConnect();
|
|
@@ -25,28 +31,28 @@ connector.onStatusChange(
|
|
|
25
31
|
## Initialize a wallet connection when user clicks to 'connect' button in your app
|
|
26
32
|
### Initialize a remote wallet connection via universal link
|
|
27
33
|
|
|
28
|
-
```
|
|
34
|
+
```ts
|
|
29
35
|
const walletConnectionSource = {
|
|
30
36
|
universalLinkBase: 'https://app.mycooltonwallet.com',
|
|
31
|
-
bridgeURL: 'https://bridge.mycooltonwallet.
|
|
37
|
+
bridgeURL: 'https://bridge.mycooltonwallet.com,'
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
const uniwersalLink = connector.connect(walletConnectionSource);
|
|
35
41
|
```
|
|
36
42
|
|
|
37
|
-
Then you have to show this link to user as QR code, or use it as a deeplink. You will receive update in `connector.onStatusChange` when user approves connection in the wallet
|
|
38
|
-
|
|
39
|
-
### Initialize injected wallet connection
|
|
43
|
+
Then you have to show this link to user as QR code, or use it as a deeplink. You will receive an update in `connector.onStatusChange` when user approves connection in the wallet
|
|
40
44
|
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
### Initialize injected wallet connection
|
|
46
|
+
```ts
|
|
47
|
+
if (connector.isInjectedProviderAvailable()) {
|
|
48
|
+
connector.connect('injected');
|
|
49
|
+
}
|
|
43
50
|
```
|
|
44
51
|
|
|
45
|
-
|
|
46
|
-
You will receive update in `connector.onStatusChange` when user approves connection in the wallet
|
|
52
|
+
You will receive an update in `connector.onStatusChange` when user approves connection in the wallet
|
|
47
53
|
|
|
48
54
|
## Send transaction
|
|
49
|
-
```
|
|
55
|
+
```ts
|
|
50
56
|
if (!connetor.connected) {
|
|
51
57
|
alert('Please connect wallet to send the transaction!');
|
|
52
58
|
}
|
|
@@ -57,12 +63,12 @@ const transaction = {
|
|
|
57
63
|
{
|
|
58
64
|
address: "0:412410771DA82CBA306A55FA9E0D43C9D245E38133CB58F1457DFB8D5CD8892F",
|
|
59
65
|
amount: "20000000",
|
|
60
|
-
initState: "base64bocblahblahblah=="
|
|
66
|
+
initState: "base64bocblahblahblah=="
|
|
61
67
|
},
|
|
62
68
|
{
|
|
63
69
|
address: "0:E69F10CC84877ABF539F83F879291E5CA169451BA7BCE91A37A5CED3AB8080D3",
|
|
64
70
|
amount: "60000000",
|
|
65
|
-
payload: "base64bocblahblahblah=="
|
|
71
|
+
payload: "base64bocblahblahblah=="
|
|
66
72
|
}
|
|
67
73
|
]
|
|
68
74
|
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = void 0;
|
|
3
|
+
exports.CHAIN = exports.default = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./ton-connect"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./models"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./errors"), exports);
|
|
8
8
|
var ton_connect_1 = require("./ton-connect");
|
|
9
9
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return ton_connect_1.TonConnect; } });
|
|
10
|
+
var protocol_1 = require("@tonconnect/protocol");
|
|
11
|
+
Object.defineProperty(exports, "CHAIN", { enumerable: true, get: function () { return protocol_1.CHAIN; } });
|
|
@@ -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.d.ts
CHANGED
|
@@ -12,21 +12,57 @@ export declare class TonConnect implements ITonConnect {
|
|
|
12
12
|
private provider;
|
|
13
13
|
private statusChangeSubscriptions;
|
|
14
14
|
private statusChangeErrorSubscriptions;
|
|
15
|
+
/**
|
|
16
|
+
* Shows if the wallet is connected right now.
|
|
17
|
+
*/
|
|
15
18
|
get connected(): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Current connected account or null if no account is connected.
|
|
21
|
+
*/
|
|
16
22
|
get account(): Account | null;
|
|
23
|
+
/**
|
|
24
|
+
* Current connected wallet or null if no account is connected.
|
|
25
|
+
*/
|
|
17
26
|
get wallet(): Wallet | null;
|
|
18
27
|
private set wallet(value);
|
|
19
28
|
constructor(options?: {
|
|
20
29
|
dappMetedata?: DappMetadata;
|
|
21
30
|
storage?: IStorage;
|
|
22
31
|
});
|
|
32
|
+
/**
|
|
33
|
+
* Indicates if the injected wallet is available.
|
|
34
|
+
*/
|
|
35
|
+
isInjectedProviderAvailable: typeof InjectedProvider.isWalletInjected;
|
|
36
|
+
/**
|
|
37
|
+
* Allows to subscribe to connection status changes and handle connection errors.
|
|
38
|
+
* @param callback will be called after connections status changes with actual wallet or null.
|
|
39
|
+
* @param errorsHandler (optional) will be called with some instance of TonConnectError when connect error is received.
|
|
40
|
+
* @returns unsubscribe callback.
|
|
41
|
+
*/
|
|
23
42
|
onStatusChange(callback: (wallet: Wallet | null) => void, errorsHandler?: (err: TonConnectError) => void): () => void;
|
|
43
|
+
/**
|
|
44
|
+
* Generates universal link for an external wallet and subscribes to the wallet's bridge, or sends connect request to the injected wallet.
|
|
45
|
+
* @param wallet wallet's bridge url and universal link for an external wallet or 'injected' for the injected wallet.
|
|
46
|
+
* @param request (optional) additional request to pass to the wallet while connect (currently only ton_proof is available).
|
|
47
|
+
* @returns universal link if external wallet was passed or void for the injected wallet.
|
|
48
|
+
*/
|
|
24
49
|
connect<T extends WalletConnectionSource | 'injected'>(wallet: T, request?: ConnectAdditionalRequest): T extends 'injected' ? void : string;
|
|
50
|
+
/**
|
|
51
|
+
* Try to restore existing session and reconnect to the corresponding wallet. Call it immediately when your app is loaded.
|
|
52
|
+
*/
|
|
25
53
|
autoConnect(): void;
|
|
26
|
-
|
|
27
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Asks connected wallet to sign and send the transaction.
|
|
56
|
+
* @param transaction transaction to send.
|
|
57
|
+
* @returns signed transaction boc that allows you to find the transaction in the blockchain.
|
|
58
|
+
* If user rejects transaction, method will throw the corresponding error.
|
|
59
|
+
*/
|
|
60
|
+
sendTransaction(transaction: SendTransactionRequest): Promise<SendTransactionResponse>;
|
|
61
|
+
/**
|
|
62
|
+
* Disconnect form thw connected wallet and drop current session.
|
|
63
|
+
*/
|
|
28
64
|
disconnect(): Promise<void>;
|
|
29
|
-
|
|
65
|
+
private _autoConnect;
|
|
30
66
|
private createProvider;
|
|
31
67
|
private walletEventsListener;
|
|
32
68
|
private onWalletConnected;
|
|
@@ -1,14 +1,51 @@
|
|
|
1
|
+
import { TonConnectError } from "./errors";
|
|
1
2
|
import { Account, WalletConnectionSource, Wallet } from "./models";
|
|
2
3
|
import { SendTransactionRequest, SendTransactionResponse } from "./models/methods";
|
|
3
4
|
import { ConnectAdditionalRequest } from "./models/methods/connect/connect-additional-request";
|
|
4
5
|
export interface ITonConnect {
|
|
6
|
+
/**
|
|
7
|
+
* Shows if the wallet is connected right now.
|
|
8
|
+
*/
|
|
5
9
|
connected: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Current connected account or null if no account is connected.
|
|
12
|
+
*/
|
|
6
13
|
account: Account | null;
|
|
14
|
+
/**
|
|
15
|
+
* Current connected wallet or null if no account is connected.
|
|
16
|
+
*/
|
|
7
17
|
wallet: Wallet | null;
|
|
8
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Indicates if the injected wallet is available.
|
|
20
|
+
*/
|
|
21
|
+
isInjectedProviderAvailable(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Allows to subscribe to connection status changes and handle connection errors.
|
|
24
|
+
* @param callback will be called after connections status changes with actual wallet or null.
|
|
25
|
+
* @param errorsHandler (optional) will be called with some instance of TonConnectError when connect error is received.
|
|
26
|
+
* @returns unsubscribe callback.
|
|
27
|
+
*/
|
|
28
|
+
onStatusChange(callback: (walletInfo: Wallet | null) => void, errorsHandler?: (err: TonConnectError) => void): () => void;
|
|
29
|
+
/**
|
|
30
|
+
* Generates universal link for an external wallet and subscribes to the wallet's bridge, or sends connect request to the injected wallet.
|
|
31
|
+
* @param wallet wallet's bridge url and universal link for an external wallet or 'injected' for the injected wallet.
|
|
32
|
+
* @param request (optional) additional request to pass to the wallet while connect (currently only ton_proof is available).
|
|
33
|
+
* @returns universal link if external wallet was passed or void for the injected wallet.
|
|
34
|
+
*/
|
|
9
35
|
connect<T extends WalletConnectionSource | 'injected'>(wallet: T, request?: ConnectAdditionalRequest): T extends 'injected' ? void : string;
|
|
36
|
+
/**
|
|
37
|
+
* Try to restore existing session and reconnect to the corresponding wallet. Call it immediately when your app is loaded.
|
|
38
|
+
*/
|
|
10
39
|
autoConnect(): void;
|
|
11
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Disconnect form thw connected wallet and drop current session.
|
|
42
|
+
*/
|
|
12
43
|
disconnect(): Promise<void>;
|
|
13
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Asks connected wallet to sign and send the transaction.
|
|
46
|
+
* @param transaction transaction to send.
|
|
47
|
+
* @returns signed transaction boc that allows you to find the transaction in the blockchain.
|
|
48
|
+
* If user rejects transaction, method will throw the corresponding error.
|
|
49
|
+
*/
|
|
50
|
+
sendTransaction(transaction: SendTransactionRequest): Promise<SendTransactionResponse>;
|
|
14
51
|
}
|
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");
|
|
@@ -20,6 +19,9 @@ var TonConnect = /** @class */ (function () {
|
|
|
20
19
|
this.provider = null;
|
|
21
20
|
this.statusChangeSubscriptions = [];
|
|
22
21
|
this.statusChangeErrorSubscriptions = [];
|
|
22
|
+
/**
|
|
23
|
+
* Indicates if the injected wallet is available.
|
|
24
|
+
*/
|
|
23
25
|
this.isInjectedProviderAvailable = injected_provider_1.InjectedProvider.isWalletInjected;
|
|
24
26
|
this.dappSettings = {
|
|
25
27
|
metadata: (options === null || options === void 0 ? void 0 : options.dappMetedata) || (0, web_api_1.getWebPageMetadata)(),
|
|
@@ -28,6 +30,9 @@ var TonConnect = /** @class */ (function () {
|
|
|
28
30
|
this.bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(this.dappSettings.storage);
|
|
29
31
|
}
|
|
30
32
|
Object.defineProperty(TonConnect.prototype, "connected", {
|
|
33
|
+
/**
|
|
34
|
+
* Shows if the wallet is connected right now.
|
|
35
|
+
*/
|
|
31
36
|
get: function () {
|
|
32
37
|
return this._wallet !== null;
|
|
33
38
|
},
|
|
@@ -35,6 +40,9 @@ var TonConnect = /** @class */ (function () {
|
|
|
35
40
|
configurable: true
|
|
36
41
|
});
|
|
37
42
|
Object.defineProperty(TonConnect.prototype, "account", {
|
|
43
|
+
/**
|
|
44
|
+
* Current connected account or null if no account is connected.
|
|
45
|
+
*/
|
|
38
46
|
get: function () {
|
|
39
47
|
var _a;
|
|
40
48
|
return ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.account) || null;
|
|
@@ -43,6 +51,9 @@ var TonConnect = /** @class */ (function () {
|
|
|
43
51
|
configurable: true
|
|
44
52
|
});
|
|
45
53
|
Object.defineProperty(TonConnect.prototype, "wallet", {
|
|
54
|
+
/**
|
|
55
|
+
* Current connected wallet or null if no account is connected.
|
|
56
|
+
*/
|
|
46
57
|
get: function () {
|
|
47
58
|
return this._wallet;
|
|
48
59
|
},
|
|
@@ -54,6 +65,12 @@ var TonConnect = /** @class */ (function () {
|
|
|
54
65
|
enumerable: false,
|
|
55
66
|
configurable: true
|
|
56
67
|
});
|
|
68
|
+
/**
|
|
69
|
+
* Allows to subscribe to connection status changes and handle connection errors.
|
|
70
|
+
* @param callback will be called after connections status changes with actual wallet or null.
|
|
71
|
+
* @param errorsHandler (optional) will be called with some instance of TonConnectError when connect error is received.
|
|
72
|
+
* @returns unsubscribe callback.
|
|
73
|
+
*/
|
|
57
74
|
TonConnect.prototype.onStatusChange = function (callback, errorsHandler) {
|
|
58
75
|
var _this = this;
|
|
59
76
|
this.statusChangeSubscriptions.push(callback);
|
|
@@ -76,41 +93,26 @@ var TonConnect = /** @class */ (function () {
|
|
|
76
93
|
this.provider = this.createProvider(wallet);
|
|
77
94
|
return this.provider.connect(this.createConnectRequest(request));
|
|
78
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* Try to restore existing session and reconnect to the corresponding wallet. Call it immediately when your app is loaded.
|
|
98
|
+
*/
|
|
79
99
|
TonConnect.prototype.autoConnect = function () {
|
|
80
100
|
this._autoConnect();
|
|
81
101
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
bridgeConnection = _a.sent();
|
|
90
|
-
if (!bridgeConnection) return [3 /*break*/, 3];
|
|
91
|
-
return [4 /*yield*/, this.createProvider(bridgeConnection.session.walletConnectionSource)];
|
|
92
|
-
case 2:
|
|
93
|
-
provider = _a.sent();
|
|
94
|
-
return [2 /*return*/, provider.autoConnect()];
|
|
95
|
-
case 3:
|
|
96
|
-
if (!injected_provider_1.InjectedProvider.isWalletInjected()) return [3 /*break*/, 5];
|
|
97
|
-
return [4 /*yield*/, this.createProvider('injected')];
|
|
98
|
-
case 4:
|
|
99
|
-
provider = _a.sent();
|
|
100
|
-
return [2 /*return*/, provider.autoConnect()];
|
|
101
|
-
case 5: return [2 /*return*/];
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
TonConnect.prototype.sendTransaction = function (tx) {
|
|
102
|
+
/**
|
|
103
|
+
* Asks connected wallet to sign and send the transaction.
|
|
104
|
+
* @param transaction transaction to send.
|
|
105
|
+
* @returns signed transaction boc that allows you to find the transaction in the blockchain.
|
|
106
|
+
* If user rejects transaction, method will throw the corresponding error.
|
|
107
|
+
*/
|
|
108
|
+
TonConnect.prototype.sendTransaction = function (transaction) {
|
|
107
109
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
108
110
|
var response;
|
|
109
111
|
return tslib_1.__generator(this, function (_a) {
|
|
110
112
|
switch (_a.label) {
|
|
111
113
|
case 0:
|
|
112
114
|
this.checkConnection();
|
|
113
|
-
return [4 /*yield*/, this.provider.sendRequest(send_transaction_parser_1.sendTransactionParser.convertToRpcRequest(
|
|
115
|
+
return [4 /*yield*/, this.provider.sendRequest(send_transaction_parser_1.sendTransactionParser.convertToRpcRequest(transaction))];
|
|
114
116
|
case 1:
|
|
115
117
|
response = _a.sent();
|
|
116
118
|
if (send_transaction_parser_1.sendTransactionParser.isError(response)) {
|
|
@@ -121,6 +123,9 @@ var TonConnect = /** @class */ (function () {
|
|
|
121
123
|
});
|
|
122
124
|
});
|
|
123
125
|
};
|
|
126
|
+
/**
|
|
127
|
+
* Disconnect form thw connected wallet and drop current session.
|
|
128
|
+
*/
|
|
124
129
|
TonConnect.prototype.disconnect = function () {
|
|
125
130
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
126
131
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -138,6 +143,32 @@ var TonConnect = /** @class */ (function () {
|
|
|
138
143
|
});
|
|
139
144
|
});
|
|
140
145
|
};
|
|
146
|
+
TonConnect.prototype._autoConnect = function () {
|
|
147
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
148
|
+
var bridgeConnection, _a, _b;
|
|
149
|
+
return tslib_1.__generator(this, function (_c) {
|
|
150
|
+
switch (_c.label) {
|
|
151
|
+
case 0: return [4 /*yield*/, this.bridgeConnectionStorage.getConnection()];
|
|
152
|
+
case 1:
|
|
153
|
+
bridgeConnection = _c.sent();
|
|
154
|
+
if (!bridgeConnection) return [3 /*break*/, 3];
|
|
155
|
+
_a = this;
|
|
156
|
+
return [4 /*yield*/, this.createProvider(bridgeConnection.session.walletConnectionSource)];
|
|
157
|
+
case 2:
|
|
158
|
+
_a.provider = _c.sent();
|
|
159
|
+
return [2 /*return*/, this.provider.autoConnect()];
|
|
160
|
+
case 3:
|
|
161
|
+
if (!injected_provider_1.InjectedProvider.isWalletInjected()) return [3 /*break*/, 5];
|
|
162
|
+
_b = this;
|
|
163
|
+
return [4 /*yield*/, this.createProvider('injected')];
|
|
164
|
+
case 4:
|
|
165
|
+
_b.provider = _c.sent();
|
|
166
|
+
return [2 /*return*/, this.provider.autoConnect()];
|
|
167
|
+
case 5: return [2 /*return*/];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
141
172
|
TonConnect.prototype.createProvider = function (wallet) {
|
|
142
173
|
var provider;
|
|
143
174
|
if (wallet === 'injected') {
|
|
@@ -172,7 +203,7 @@ var TonConnect = /** @class */ (function () {
|
|
|
172
203
|
provider: this.provider.type,
|
|
173
204
|
account: {
|
|
174
205
|
address: tonAccountItem.address,
|
|
175
|
-
chain:
|
|
206
|
+
chain: tonAccountItem.network
|
|
176
207
|
}
|
|
177
208
|
};
|
|
178
209
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tonconnect/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "npx rimraf lib && ttsc",
|
|
6
6
|
"build:production": "npx rimraf lib && ttsc --sourceMap false"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"deepmerge": "^4.2.2",
|
|
28
28
|
"tweetnacl": "^1.0.3",
|
|
29
|
-
"@tonconnect/protocol": "^0.0.
|
|
29
|
+
"@tonconnect/protocol": "^0.0.5"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
32
|
"lib"
|