@tonconnect/sdk 0.0.36 → 0.0.37
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 +100 -3
- package/dist/tonconnect-sdk.min.js +1 -1
- package/dist/tonconnect-sdk.min.js.map +1 -1
- package/lib/errors/protocol/events/connect/manifest-content-error.error.d.ts +8 -0
- package/lib/errors/protocol/events/connect/manifest-content-error.error.js +15 -0
- package/lib/errors/protocol/events/connect/manifest-not-found.error.d.ts +8 -0
- package/lib/errors/protocol/events/connect/manifest-not-found.error.js +15 -0
- package/lib/errors/ton-connect.error.d.ts +2 -1
- package/lib/errors/ton-connect.error.js +6 -2
- package/lib/models/ton-connect-options.d.ts +3 -4
- package/lib/models/wallet/account.d.ts +5 -0
- package/lib/parsers/connect-errors-parser.js +5 -1
- package/lib/ton-connect.js +15 -8
- package/lib/utils/web-api.d.ts +1 -2
- package/lib/utils/web-api.js +7 -57
- package/package.json +2 -2
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TonConnectError } from "../../../ton-connect.error";
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when passed manifest contains errors.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ManifestContentErrorError extends TonConnectError {
|
|
6
|
+
private static additionalMessage;
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ManifestContentErrorError = void 0;
|
|
4
|
+
const ton_connect_error_1 = require("../../../ton-connect.error");
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when passed manifest contains errors.
|
|
7
|
+
*/
|
|
8
|
+
class ManifestContentErrorError extends ton_connect_error_1.TonConnectError {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message || '' + ManifestContentErrorError.additionalMessage);
|
|
11
|
+
Object.setPrototypeOf(this, ManifestContentErrorError.prototype);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ManifestContentErrorError = ManifestContentErrorError;
|
|
15
|
+
ManifestContentErrorError.additionalMessage = '\nPassed `tonconnect-manifest.json` contains errors. Check format of your manifest. See more https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TonConnectError } from "../../../ton-connect.error";
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when wallet can't get manifest by passed manifestUrl.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ManifestNotFoundError extends TonConnectError {
|
|
6
|
+
private static additionalMessage;
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ManifestNotFoundError = void 0;
|
|
4
|
+
const ton_connect_error_1 = require("../../../ton-connect.error");
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when wallet can't get manifest by passed manifestUrl.
|
|
7
|
+
*/
|
|
8
|
+
class ManifestNotFoundError extends ton_connect_error_1.TonConnectError {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message || '' + ManifestNotFoundError.additionalMessage);
|
|
11
|
+
Object.setPrototypeOf(this, ManifestNotFoundError.prototype);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ManifestNotFoundError = ManifestNotFoundError;
|
|
15
|
+
ManifestNotFoundError.additionalMessage = '\nManifest not found. Make sure you added `tonconnect-manifest.json` to the root of your app or passed correct manifestUrl. See more https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest';
|
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
* Base class for TonConnect errors. You can check if the error was triggered by the @tonconnect/sdk using `err instanceof TonConnectError`.
|
|
3
3
|
*/
|
|
4
4
|
export declare class TonConnectError extends Error {
|
|
5
|
-
|
|
5
|
+
private static prefix;
|
|
6
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
6
7
|
}
|
|
@@ -5,9 +5,13 @@ exports.TonConnectError = void 0;
|
|
|
5
5
|
* Base class for TonConnect errors. You can check if the error was triggered by the @tonconnect/sdk using `err instanceof TonConnectError`.
|
|
6
6
|
*/
|
|
7
7
|
class TonConnectError extends Error {
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
8
|
+
constructor(message, options) {
|
|
9
|
+
if (message) {
|
|
10
|
+
message = TonConnectError.prefix + ' ' + message;
|
|
11
|
+
}
|
|
12
|
+
super(message, options);
|
|
10
13
|
Object.setPrototypeOf(this, TonConnectError.prototype);
|
|
11
14
|
}
|
|
12
15
|
}
|
|
13
16
|
exports.TonConnectError = TonConnectError;
|
|
17
|
+
TonConnectError.prefix = '[TON_CONNECT_SDK_ERROR]';
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { DappMetadata } from "./dapp/dapp-metadata";
|
|
2
1
|
import { IStorage } from "../storage/models/storage.interface";
|
|
3
2
|
/**
|
|
4
3
|
* TonConnect constructor options
|
|
5
4
|
*/
|
|
6
5
|
export interface TonConnectOptions {
|
|
7
6
|
/**
|
|
8
|
-
* Dapp metadata that will be displayed in the user's wallet.
|
|
9
|
-
*
|
|
7
|
+
* Url to the [manifest]{@link https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest} with the Dapp metadata that will be displayed in the user's wallet.
|
|
8
|
+
* If not passed, manifest from `${window.location.origin}/tonconnect-manifest.json` will be taken.
|
|
10
9
|
*/
|
|
11
|
-
|
|
10
|
+
manifestUrl?: string;
|
|
12
11
|
/**
|
|
13
12
|
* Storage to save protocol data. For browser default is `localStorage`. If you use SDK with nodeJS, you have to specify this field.
|
|
14
13
|
*/
|
|
@@ -8,4 +8,9 @@ export interface Account {
|
|
|
8
8
|
* User's selected chain.
|
|
9
9
|
*/
|
|
10
10
|
chain: CHAIN;
|
|
11
|
+
/**
|
|
12
|
+
* Base64 (not url safe) encoded wallet contract stateInit.
|
|
13
|
+
* Can be used to get user's public key from the stateInit if the wallet contract doesn't support corresponding get method.
|
|
14
|
+
*/
|
|
15
|
+
walletStateInit: string;
|
|
11
16
|
}
|
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.connectErrorsParser = void 0;
|
|
4
4
|
const errors_1 = require("../errors");
|
|
5
|
+
const manifest_content_error_error_1 = require("../errors/protocol/events/connect/manifest-content-error.error");
|
|
6
|
+
const manifest_not_found_error_1 = require("../errors/protocol/events/connect/manifest-not-found.error");
|
|
5
7
|
const unknown_error_1 = require("../errors/unknown.error");
|
|
6
8
|
const protocol_1 = require("@tonconnect/protocol");
|
|
7
9
|
const connectEventErrorsCodes = {
|
|
8
10
|
[protocol_1.CONNECT_EVENT_ERROR_CODES.UNKNOWN_ERROR]: unknown_error_1.UnknownError,
|
|
9
11
|
[protocol_1.CONNECT_EVENT_ERROR_CODES.USER_REJECTS_ERROR]: errors_1.UserRejectsError,
|
|
10
12
|
[protocol_1.CONNECT_EVENT_ERROR_CODES.BAD_REQUEST_ERROR]: errors_1.BadRequestError,
|
|
11
|
-
[protocol_1.CONNECT_EVENT_ERROR_CODES.UNKNOWN_APP_ERROR]: errors_1.UnknownAppError
|
|
13
|
+
[protocol_1.CONNECT_EVENT_ERROR_CODES.UNKNOWN_APP_ERROR]: errors_1.UnknownAppError,
|
|
14
|
+
[protocol_1.CONNECT_EVENT_ERROR_CODES.MANIFEST_NOT_FOUND_ERROR]: manifest_not_found_error_1.ManifestNotFoundError,
|
|
15
|
+
[protocol_1.CONNECT_EVENT_ERROR_CODES.MANIFEST_CONTENT_ERROR]: manifest_content_error_error_1.ManifestContentErrorError
|
|
12
16
|
};
|
|
13
17
|
class ConnectErrorsParser {
|
|
14
18
|
parseError(error) {
|
package/lib/ton-connect.js
CHANGED
|
@@ -22,6 +22,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.TonConnect = void 0;
|
|
24
24
|
const dapp_metadata_error_1 = require("./errors/dapp/dapp-metadata.error");
|
|
25
|
+
const manifest_content_error_error_1 = require("./errors/protocol/events/connect/manifest-content-error.error");
|
|
26
|
+
const manifest_not_found_error_1 = require("./errors/protocol/events/connect/manifest-not-found.error");
|
|
25
27
|
const ton_connect_error_1 = require("./errors/ton-connect.error");
|
|
26
28
|
const wallet_already_connected_error_1 = require("./errors/wallet/wallet-already-connected.error");
|
|
27
29
|
const wallet_not_connected_error_1 = require("./errors/wallet/wallet-not-connected.error");
|
|
@@ -32,7 +34,6 @@ const bridge_provider_1 = require("./provider/bridge/bridge-provider");
|
|
|
32
34
|
const injected_provider_1 = require("./provider/injected/injected-provider");
|
|
33
35
|
const bridge_connection_storage_1 = require("./storage/bridge-connection-storage");
|
|
34
36
|
const default_storage_1 = require("./storage/default-storage");
|
|
35
|
-
const options_1 = require("./utils/options");
|
|
36
37
|
const web_api_1 = require("./utils/web-api");
|
|
37
38
|
const wallets_list_manager_1 = require("./wallets-list-manager");
|
|
38
39
|
class TonConnect {
|
|
@@ -43,11 +44,11 @@ class TonConnect {
|
|
|
43
44
|
this.statusChangeSubscriptions = [];
|
|
44
45
|
this.statusChangeErrorSubscriptions = [];
|
|
45
46
|
this.dappSettings = {
|
|
46
|
-
|
|
47
|
+
manifestUrl: (options === null || options === void 0 ? void 0 : options.manifestUrl) || (0, web_api_1.getWebPageManifest)(),
|
|
47
48
|
storage: (options === null || options === void 0 ? void 0 : options.storage) || new default_storage_1.DefaultStorage()
|
|
48
49
|
};
|
|
49
|
-
if (!this.dappSettings.
|
|
50
|
-
throw new dapp_metadata_error_1.DappMetadataError('Dapp
|
|
50
|
+
if (!this.dappSettings.manifestUrl) {
|
|
51
|
+
throw new dapp_metadata_error_1.DappMetadataError('Dapp tonconnect-manifest.json must be specified if window.location.origin is undefined. See more https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest');
|
|
51
52
|
}
|
|
52
53
|
this.bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(this.dappSettings.storage);
|
|
53
54
|
}
|
|
@@ -198,7 +199,8 @@ class TonConnect {
|
|
|
198
199
|
provider: this.provider.type,
|
|
199
200
|
account: {
|
|
200
201
|
address: tonAccountItem.address,
|
|
201
|
-
chain: tonAccountItem.network
|
|
202
|
+
chain: tonAccountItem.network,
|
|
203
|
+
walletStateInit: tonAccountItem.walletStateInit
|
|
202
204
|
}
|
|
203
205
|
};
|
|
204
206
|
if (tonProofItem) {
|
|
@@ -211,6 +213,10 @@ class TonConnect {
|
|
|
211
213
|
onWalletConnectError(connectEventError) {
|
|
212
214
|
const error = connect_errors_parser_1.connectErrorsParser.parseError(connectEventError);
|
|
213
215
|
this.statusChangeErrorSubscriptions.forEach(errorsHandler => errorsHandler(error));
|
|
216
|
+
if (error instanceof manifest_not_found_error_1.ManifestNotFoundError || error instanceof manifest_content_error_error_1.ManifestContentErrorError) {
|
|
217
|
+
console.error(error);
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
214
220
|
}
|
|
215
221
|
onWalletDisconnected() {
|
|
216
222
|
this.wallet = null;
|
|
@@ -221,8 +227,6 @@ class TonConnect {
|
|
|
221
227
|
}
|
|
222
228
|
}
|
|
223
229
|
createConnectRequest(request) {
|
|
224
|
-
const webPageMetadata = (0, web_api_1.getWebPageMetadata)();
|
|
225
|
-
const metadata = (0, options_1.mergeOptions)(this.dappSettings.dappMetedata, webPageMetadata);
|
|
226
230
|
const items = [
|
|
227
231
|
{
|
|
228
232
|
name: 'ton_addr'
|
|
@@ -234,7 +238,10 @@ class TonConnect {
|
|
|
234
238
|
payload: request.tonProof
|
|
235
239
|
});
|
|
236
240
|
}
|
|
237
|
-
return
|
|
241
|
+
return {
|
|
242
|
+
manifestUrl: this.dappSettings.manifestUrl,
|
|
243
|
+
items
|
|
244
|
+
};
|
|
238
245
|
}
|
|
239
246
|
}
|
|
240
247
|
exports.TonConnect = TonConnect;
|
package/lib/utils/web-api.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DappMetadata } from "../models";
|
|
2
1
|
export declare function getWindow(): Window | undefined;
|
|
3
2
|
export declare function getDocument(): Document | undefined;
|
|
4
|
-
export declare function
|
|
3
|
+
export declare function getWebPageManifest(): string;
|
package/lib/utils/web-api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getWebPageManifest = exports.getDocument = exports.getWindow = void 0;
|
|
4
4
|
function getWindow() {
|
|
5
5
|
if (typeof window === 'undefined') {
|
|
6
6
|
return undefined;
|
|
@@ -15,62 +15,12 @@ function getDocument() {
|
|
|
15
15
|
return document;
|
|
16
16
|
}
|
|
17
17
|
exports.getDocument = getDocument;
|
|
18
|
-
function
|
|
19
|
-
var _a, _b;
|
|
20
|
-
return {
|
|
21
|
-
url: ((_a = getWindow()) === null || _a === void 0 ? void 0 : _a.location.origin) || '',
|
|
22
|
-
icon: getIconUrl(),
|
|
23
|
-
name: ((_b = getDocument()) === null || _b === void 0 ? void 0 : _b.title) || 'Unknown dapp'
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
exports.getWebPageMetadata = getWebPageMetadata;
|
|
27
|
-
function getIconUrl() {
|
|
28
|
-
const document = getDocument();
|
|
29
|
-
if (!document) {
|
|
30
|
-
return '';
|
|
31
|
-
}
|
|
32
|
-
const appleTouchIcons = document.querySelectorAll("link[rel='apple-touch-icon']");
|
|
33
|
-
if (appleTouchIcons === null || appleTouchIcons === void 0 ? void 0 : appleTouchIcons.length) {
|
|
34
|
-
return getLargestSizeIconUrl(Array.from(appleTouchIcons));
|
|
35
|
-
}
|
|
36
|
-
const links = Array.from(document.querySelectorAll("link[rel*='icon']"));
|
|
37
|
-
const pngLinks = links.filter(link => link.href.endsWith('.png'));
|
|
38
|
-
if (pngLinks.length) {
|
|
39
|
-
return getLargestSizeIconUrl(pngLinks);
|
|
40
|
-
}
|
|
41
|
-
const icoIcon = links.filter(link => link.href.endsWith('.ico'))[0];
|
|
42
|
-
return (icoIcon === null || icoIcon === void 0 ? void 0 : icoIcon.href) || '';
|
|
43
|
-
}
|
|
44
|
-
function getLargestSizeIconUrl(links) {
|
|
45
|
-
const parsedLinks = links.map(parseIconLink);
|
|
46
|
-
const maxSizeIcon = parsedLinks.sort((a, b) => (b.size > a.size ? 1 : -1))[0];
|
|
47
|
-
return (maxSizeIcon === null || maxSizeIcon === void 0 ? void 0 : maxSizeIcon.href) || '';
|
|
48
|
-
}
|
|
49
|
-
function parseIconLink(link) {
|
|
18
|
+
function getWebPageManifest() {
|
|
50
19
|
var _a;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
size: 0
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
const sizes = Array.from(link.sizes)
|
|
58
|
-
.map(size => {
|
|
59
|
-
const groups = size.match(/(\d+)x(\d+)/i);
|
|
60
|
-
if (!groups || !groups[1] || !groups[2]) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
return parseInt(groups[1]) * parseInt(groups[2]);
|
|
64
|
-
})
|
|
65
|
-
.filter(item => !!item);
|
|
66
|
-
if (sizes.length === 0) {
|
|
67
|
-
return {
|
|
68
|
-
href: link.href,
|
|
69
|
-
size: 0
|
|
70
|
-
};
|
|
20
|
+
const origin = (_a = getWindow()) === null || _a === void 0 ? void 0 : _a.location.origin;
|
|
21
|
+
if (origin) {
|
|
22
|
+
return origin + '/tonconnect-manifest.json';
|
|
71
23
|
}
|
|
72
|
-
return
|
|
73
|
-
href: link.href,
|
|
74
|
-
size: Math.max.apply(Math, sizes)
|
|
75
|
-
};
|
|
24
|
+
return '';
|
|
76
25
|
}
|
|
26
|
+
exports.getWebPageManifest = getWebPageManifest;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tonconnect/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "npx rimraf lib && ttsc && npx rimraf dist && webpack --mode development",
|
|
6
6
|
"build:production": "npx rimraf lib && ttsc --sourceMap false && npx rimraf dist && webpack --mode production"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"tweetnacl": "^1.0.3",
|
|
29
29
|
"eventsource": "^2.0.2",
|
|
30
30
|
"node-fetch": "^2.6.7",
|
|
31
|
-
"@tonconnect/protocol": "^0.0.
|
|
31
|
+
"@tonconnect/protocol": "^0.0.22"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
34
|
"lib",
|