@tonconnect/sdk 0.0.35 → 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.
@@ -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
- constructor(...args: ConstructorParameters<typeof Error>);
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(...args) {
9
- super(...args);
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]';
@@ -2,7 +2,7 @@ export interface SendTransactionRequest {
2
2
  /**
3
3
  * Sending transaction deadline in unix epoch seconds.
4
4
  */
5
- valid_until: number;
5
+ validUntil: number;
6
6
  /**
7
7
  * Messages to send: min is 1, max is 4.
8
8
  */
@@ -18,7 +18,7 @@ export interface SendTransactionRequest {
18
18
  /**
19
19
  * Contract specific data to add to the transaction.
20
20
  */
21
- initState?: string;
21
+ stateInit?: string;
22
22
  /**
23
23
  * Contract specific data to add to the transaction.
24
24
  */
@@ -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
- * Options will be merged with the [defaults]{@link ./dapp/dappMetedata.ts} if there are some empty fields.
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
- dappMetedata?: Partial<DappMetadata>;
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) {
@@ -3,7 +3,9 @@ import { SendTransactionRequest, SendTransactionResponse } from "../models/metho
3
3
  import { RpcParser } from "./rpc-parser";
4
4
  import { WithoutId } from "../utils/types";
5
5
  declare class SendTransactionParser extends RpcParser<'sendTransaction'> {
6
- convertToRpcRequest(request: SendTransactionRequest): WithoutId<SendTransactionRpcRequest>;
6
+ convertToRpcRequest(request: Omit<SendTransactionRequest, 'validUntil'> & {
7
+ valid_until: number;
8
+ }): WithoutId<SendTransactionRpcRequest>;
7
9
  parseAndThrowError(response: WithoutId<SendTransactionRpcResponseError>): never;
8
10
  convertFromRpcResponse(rpcResponse: WithoutId<SendTransactionRpcResponseSuccess>): SendTransactionResponse;
9
11
  }
@@ -8,9 +8,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.TonConnect = void 0;
13
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");
14
27
  const ton_connect_error_1 = require("./errors/ton-connect.error");
15
28
  const wallet_already_connected_error_1 = require("./errors/wallet/wallet-already-connected.error");
16
29
  const wallet_not_connected_error_1 = require("./errors/wallet/wallet-not-connected.error");
@@ -21,7 +34,6 @@ const bridge_provider_1 = require("./provider/bridge/bridge-provider");
21
34
  const injected_provider_1 = require("./provider/injected/injected-provider");
22
35
  const bridge_connection_storage_1 = require("./storage/bridge-connection-storage");
23
36
  const default_storage_1 = require("./storage/default-storage");
24
- const options_1 = require("./utils/options");
25
37
  const web_api_1 = require("./utils/web-api");
26
38
  const wallets_list_manager_1 = require("./wallets-list-manager");
27
39
  class TonConnect {
@@ -32,11 +44,11 @@ class TonConnect {
32
44
  this.statusChangeSubscriptions = [];
33
45
  this.statusChangeErrorSubscriptions = [];
34
46
  this.dappSettings = {
35
- dappMetedata: (0, options_1.mergeOptions)(options === null || options === void 0 ? void 0 : options.dappMetedata, (0, web_api_1.getWebPageMetadata)()),
47
+ manifestUrl: (options === null || options === void 0 ? void 0 : options.manifestUrl) || (0, web_api_1.getWebPageManifest)(),
36
48
  storage: (options === null || options === void 0 ? void 0 : options.storage) || new default_storage_1.DefaultStorage()
37
49
  };
38
- if (!this.dappSettings.dappMetedata.url) {
39
- throw new dapp_metadata_error_1.DappMetadataError('Dapp url must be specified if window.location.origin is undefined.');
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');
40
52
  }
41
53
  this.bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(this.dappSettings.storage);
42
54
  }
@@ -132,8 +144,9 @@ class TonConnect {
132
144
  */
133
145
  sendTransaction(transaction) {
134
146
  return __awaiter(this, void 0, void 0, function* () {
147
+ const { validUntil } = transaction, tx = __rest(transaction, ["validUntil"]);
135
148
  this.checkConnection();
136
- const response = yield this.provider.sendRequest(send_transaction_parser_1.sendTransactionParser.convertToRpcRequest(transaction));
149
+ const response = yield this.provider.sendRequest(send_transaction_parser_1.sendTransactionParser.convertToRpcRequest(Object.assign(Object.assign({}, tx), { valid_until: validUntil })));
137
150
  if (send_transaction_parser_1.sendTransactionParser.isError(response)) {
138
151
  return send_transaction_parser_1.sendTransactionParser.parseAndThrowError(response);
139
152
  }
@@ -186,7 +199,8 @@ class TonConnect {
186
199
  provider: this.provider.type,
187
200
  account: {
188
201
  address: tonAccountItem.address,
189
- chain: tonAccountItem.network
202
+ chain: tonAccountItem.network,
203
+ walletStateInit: tonAccountItem.walletStateInit
190
204
  }
191
205
  };
192
206
  if (tonProofItem) {
@@ -199,6 +213,10 @@ class TonConnect {
199
213
  onWalletConnectError(connectEventError) {
200
214
  const error = connect_errors_parser_1.connectErrorsParser.parseError(connectEventError);
201
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
+ }
202
220
  }
203
221
  onWalletDisconnected() {
204
222
  this.wallet = null;
@@ -209,8 +227,6 @@ class TonConnect {
209
227
  }
210
228
  }
211
229
  createConnectRequest(request) {
212
- const webPageMetadata = (0, web_api_1.getWebPageMetadata)();
213
- const metadata = (0, options_1.mergeOptions)(this.dappSettings.dappMetedata, webPageMetadata);
214
230
  const items = [
215
231
  {
216
232
  name: 'ton_addr'
@@ -222,7 +238,10 @@ class TonConnect {
222
238
  payload: request.tonProof
223
239
  });
224
240
  }
225
- return Object.assign(Object.assign({}, metadata), { items });
241
+ return {
242
+ manifestUrl: this.dappSettings.manifestUrl,
243
+ items
244
+ };
226
245
  }
227
246
  }
228
247
  exports.TonConnect = TonConnect;
@@ -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 getWebPageMetadata(): DappMetadata;
3
+ export declare function getWebPageManifest(): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getWebPageMetadata = exports.getDocument = exports.getWindow = void 0;
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 getWebPageMetadata() {
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
- if (!((_a = link.sizes) === null || _a === void 0 ? void 0 : _a.value)) {
52
- return {
53
- href: link.href,
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.35",
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.21"
31
+ "@tonconnect/protocol": "^0.0.22"
32
32
  },
33
33
  "files": [
34
34
  "lib",