@trezor/connect 9.0.7 → 9.0.9

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.
Files changed (82) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +1 -1
  3. package/lib/api/bitcoin/createPendingTx.d.ts +34 -0
  4. package/lib/api/bitcoin/createPendingTx.js +59 -0
  5. package/lib/api/bitcoin/index.d.ts +1 -0
  6. package/lib/api/bitcoin/index.js +1 -0
  7. package/lib/api/blockchainGetAccountBalanceHistory.d.ts +1 -1
  8. package/lib/api/blockchainGetCurrentFiatRates.d.ts +2 -1
  9. package/lib/api/blockchainGetCurrentFiatRates.js +6 -1
  10. package/lib/api/blockchainGetFiatRatesForTimestamps.d.ts +3 -1
  11. package/lib/api/blockchainGetFiatRatesForTimestamps.js +9 -1
  12. package/lib/api/blockchainGetTransactions.d.ts +1 -1
  13. package/lib/api/cardano/cardanoAuxiliaryData.js +43 -23
  14. package/lib/api/cardanoSignTransaction.d.ts +2 -1
  15. package/lib/api/cardanoSignTransaction.js +21 -11
  16. package/lib/api/composeTransaction.js +2 -2
  17. package/lib/api/ethereum/ethereumDefinitions.d.ts +7 -0
  18. package/lib/api/ethereum/ethereumDefinitions.js +43 -0
  19. package/lib/api/ethereum/ethereumSignTx.d.ts +3 -2
  20. package/lib/api/ethereum/ethereumSignTx.js +4 -2
  21. package/lib/api/ethereumGetAddress.d.ts +2 -1
  22. package/lib/api/ethereumGetAddress.js +19 -2
  23. package/lib/api/ethereumSignMessage.js +13 -0
  24. package/lib/api/ethereumSignTransaction.js +10 -3
  25. package/lib/api/ethereumSignTypedData.js +14 -0
  26. package/lib/api/firmware/getBinary.d.ts +3 -12
  27. package/lib/api/firmware/getBinary.js +5 -9
  28. package/lib/api/firmwareUpdate.d.ts +3 -2
  29. package/lib/api/firmwareUpdate.js +4 -5
  30. package/lib/api/getAccountInfo.d.ts +8 -8
  31. package/lib/api/getAccountInfo.js +1 -1
  32. package/lib/api/setBusy.js +1 -4
  33. package/lib/api/setProxy.js +1 -1
  34. package/lib/api/signTransaction.js +10 -2
  35. package/lib/api/unlockPath.js +1 -4
  36. package/lib/backend/Blockchain.d.ts +3 -0
  37. package/lib/core/AbstractMethod.d.ts +1 -0
  38. package/lib/core/AbstractMethod.js +9 -0
  39. package/lib/core/index.js +17 -8
  40. package/lib/data/DataManager.d.ts +92 -15
  41. package/lib/data/DataManager.js +3 -54
  42. package/lib/data/config.js +9 -3
  43. package/lib/data/connectSettings.d.ts +0 -1
  44. package/lib/data/connectSettings.js +10 -57
  45. package/lib/data/firmwareInfo.js +48 -46
  46. package/lib/data/transportInfo.d.ts +1 -0
  47. package/lib/data/transportInfo.js +14 -1
  48. package/lib/data/udevInfo.d.ts +1 -0
  49. package/lib/data/udevInfo.js +14 -1
  50. package/lib/data/version.d.ts +1 -1
  51. package/lib/data/version.js +1 -1
  52. package/lib/device/DescriptorStream.js +1 -1
  53. package/lib/device/DeviceCommands.d.ts +1 -1
  54. package/lib/device/DeviceCommands.js +2 -1
  55. package/lib/device/DeviceList.d.ts +1 -2
  56. package/lib/device/DeviceList.js +20 -10
  57. package/lib/events/iframe.d.ts +2 -1
  58. package/lib/events/popup.d.ts +2 -1
  59. package/lib/index.js +1 -4
  60. package/lib/types/api/bitcoin/index.d.ts +2 -0
  61. package/lib/types/api/cardano/index.d.ts +10 -9
  62. package/lib/types/api/firmwareUpdate.d.ts +2 -1
  63. package/lib/types/firmware.d.ts +2 -3
  64. package/lib/types/index.d.ts +1 -1
  65. package/lib/types/settings.d.ts +1 -1
  66. package/lib/utils/firmwareUtils.d.ts +0 -1
  67. package/lib/utils/firmwareUtils.js +1 -9
  68. package/lib/utils/pathUtils.d.ts +1 -0
  69. package/lib/utils/pathUtils.js +3 -1
  70. package/lib/utils/promiseUtils.d.ts +5 -1
  71. package/lib/utils/promiseUtils.js +7 -3
  72. package/lib/utils/urlUtils.d.ts +2 -1
  73. package/lib/utils/urlUtils.js +18 -3
  74. package/lib/utils/versionUtils.d.ts +3 -1
  75. package/lib/utils/versionUtils.js +5 -2
  76. package/package.json +12 -13
  77. package/lib/device/AbortController.d.ts +0 -21
  78. package/lib/device/AbortController.js +0 -40
  79. package/lib/utils/browserUtils.d.ts +0 -21
  80. package/lib/utils/browserUtils.js +0 -100
  81. package/lib/utils/windowsUtils.d.ts +0 -2
  82. package/lib/utils/windowsUtils.js +0 -6
@@ -6,6 +6,7 @@ const pathUtils_1 = require("../utils/pathUtils");
6
6
  const coinInfo_1 = require("../data/coinInfo");
7
7
  const ethereumUtils_1 = require("../utils/ethereumUtils");
8
8
  const formatUtils_1 = require("../utils/formatUtils");
9
+ const ethereumDefinitions_1 = require("./ethereum/ethereumDefinitions");
9
10
  class EthereumSignMessage extends AbstractMethod_1.AbstractMethod {
10
11
  init() {
11
12
  this.requiredPermissions = ['read', 'write'];
@@ -30,7 +31,19 @@ class EthereumSignMessage extends AbstractMethod_1.AbstractMethod {
30
31
  async run() {
31
32
  const cmd = this.device.getCommands();
32
33
  const { address_n, message } = this.params;
34
+ const network = (0, coinInfo_1.getEthereumNetwork)(address_n);
35
+ const slip44 = (0, pathUtils_1.getSlip44ByPath)(address_n);
36
+ const definitions = await (0, ethereumDefinitions_1.getEthereumDefinitions)({
37
+ chainId: network === null || network === void 0 ? void 0 : network.chainId,
38
+ slip44,
39
+ });
40
+ const definitionParams = {
41
+ ...(definitions.encoded_network && {
42
+ encoded_network: definitions.encoded_network,
43
+ }),
44
+ };
33
45
  const response = await cmd.typedCall('EthereumSignMessage', 'EthereumMessageSignature', {
46
+ ...definitionParams,
34
47
  address_n,
35
48
  message,
36
49
  });
@@ -8,6 +8,7 @@ const coinInfo_1 = require("../data/coinInfo");
8
8
  const ethereumUtils_1 = require("../utils/ethereumUtils");
9
9
  const formatUtils_1 = require("../utils/formatUtils");
10
10
  const helper = tslib_1.__importStar(require("./ethereum/ethereumSignTx"));
11
+ const ethereumDefinitions_1 = require("./ethereum/ethereumDefinitions");
11
12
  const strip = value => {
12
13
  if (typeof value === 'string') {
13
14
  let stripped = (0, formatUtils_1.stripHexPrefix)(value);
@@ -71,11 +72,17 @@ class EthereumSignTransaction extends AbstractMethod_1.AbstractMethod {
71
72
  },
72
73
  };
73
74
  }
74
- run() {
75
+ async run() {
75
76
  const { tx } = this.params;
77
+ const slip44 = (0, pathUtils_1.getSlip44ByPath)(this.params.path);
78
+ const definitions = await (0, ethereumDefinitions_1.getEthereumDefinitions)({
79
+ chainId: tx.chainId,
80
+ slip44,
81
+ contractAddress: tx.data ? tx.to : undefined,
82
+ });
76
83
  return tx.type === 'eip1559'
77
- ? helper.ethereumSignTxEIP1559(this.device.getCommands().typedCall.bind(this.device.getCommands()), this.params.path, tx.to, tx.value, tx.gasLimit, tx.maxFeePerGas, tx.maxPriorityFeePerGas, tx.nonce, tx.chainId, tx.data, tx.accessList)
78
- : helper.ethereumSignTx(this.device.getCommands().typedCall.bind(this.device.getCommands()), this.params.path, tx.to, tx.value, tx.gasLimit, tx.gasPrice, tx.nonce, tx.chainId, tx.data, tx.txType);
84
+ ? helper.ethereumSignTxEIP1559(this.device.getCommands().typedCall.bind(this.device.getCommands()), this.params.path, tx.to, tx.value, tx.gasLimit, tx.maxFeePerGas, tx.maxPriorityFeePerGas, tx.nonce, tx.chainId, tx.data, tx.accessList, definitions)
85
+ : helper.ethereumSignTx(this.device.getCommands().typedCall.bind(this.device.getCommands()), this.params.path, tx.to, tx.value, tx.gasLimit, tx.gasPrice, tx.nonce, tx.chainId, tx.data, tx.txType, definitions);
79
86
  }
80
87
  }
81
88
  exports.default = EthereumSignTransaction;
@@ -8,6 +8,7 @@ const ethereumUtils_1 = require("../utils/ethereumUtils");
8
8
  const constants_1 = require("../constants");
9
9
  const ethereumSignTypedData_1 = require("./ethereum/ethereumSignTypedData");
10
10
  const formatUtils_1 = require("../utils/formatUtils");
11
+ const ethereumDefinitions_1 = require("./ethereum/ethereumDefinitions");
11
12
  class EthereumSignTypedData extends AbstractMethod_1.AbstractMethod {
12
13
  init() {
13
14
  this.requiredPermissions = ['read', 'write'];
@@ -53,16 +54,28 @@ class EthereumSignTypedData extends AbstractMethod_1.AbstractMethod {
53
54
  async run() {
54
55
  const cmd = this.device.getCommands();
55
56
  const { address_n } = this.params;
57
+ const network = (0, coinInfo_1.getEthereumNetwork)(address_n);
58
+ const slip44 = (0, pathUtils_1.getSlip44ByPath)(address_n);
59
+ const definitions = await (0, ethereumDefinitions_1.getEthereumDefinitions)({
60
+ chainId: network === null || network === void 0 ? void 0 : network.chainId,
61
+ slip44,
62
+ });
56
63
  if (this.device.features.model === '1') {
57
64
  (0, paramsValidator_1.validateParams)(this.params, [
58
65
  { name: 'domain_separator_hash', type: 'string', required: true },
59
66
  { name: 'message_hash', type: 'string' },
60
67
  ]);
61
68
  const { domain_separator_hash, message_hash } = this.params;
69
+ const definitionParams = {
70
+ ...(definitions.encoded_network && {
71
+ encoded_network: definitions.encoded_network,
72
+ }),
73
+ };
62
74
  const response = await cmd.typedCall('EthereumSignTypedHash', 'EthereumTypedDataSignature', {
63
75
  address_n,
64
76
  domain_separator_hash: domain_separator_hash,
65
77
  message_hash,
78
+ ...definitionParams,
66
79
  });
67
80
  const { address, signature } = response.message;
68
81
  return {
@@ -80,6 +93,7 @@ class EthereumSignTypedData extends AbstractMethod_1.AbstractMethod {
80
93
  address_n,
81
94
  primary_type: primaryType,
82
95
  metamask_v4_compat,
96
+ definitions,
83
97
  });
84
98
  while (response.type === 'EthereumTypedDataStructRequest') {
85
99
  const { name: typeDefinitionName } = response.message;
@@ -1,20 +1,11 @@
1
1
  import { GetInfoProps } from '../../data/firmwareInfo';
2
+ import { IntermediaryVersion } from '../../types';
2
3
  interface GetBinaryProps extends GetInfoProps {
3
4
  baseUrl: string;
4
5
  btcOnly?: boolean;
5
6
  version?: number[];
6
- intermediary?: boolean;
7
+ intermediaryVersion?: IntermediaryVersion;
7
8
  }
8
- export declare const getBinary: ({ features, releases, baseUrl, version, btcOnly, intermediary, }: GetBinaryProps) => Promise<{
9
- binary: any;
10
- } | {
11
- binary: any;
12
- changelog: import("../..").FirmwareRelease[] | null;
13
- release: import("../..").FirmwareRelease;
14
- isLatest: boolean;
15
- latest: import("../..").FirmwareRelease;
16
- isRequired: boolean | null;
17
- isNewer: boolean | null;
18
- }>;
9
+ export declare const getBinary: ({ features, releases, baseUrl, version, btcOnly, intermediaryVersion, }: GetBinaryProps) => any;
19
10
  export {};
20
11
  //# sourceMappingURL=getBinary.d.ts.map
@@ -5,13 +5,12 @@ const utils_1 = require("@trezor/utils");
5
5
  const assets_1 = require("../../utils/assets");
6
6
  const firmwareUtils_1 = require("../../utils/firmwareUtils");
7
7
  const firmwareInfo_1 = require("../../data/firmwareInfo");
8
- const getBinary = async ({ features, releases, baseUrl, version, btcOnly, intermediary = false, }) => {
8
+ const getBinary = ({ features, releases, baseUrl, version, btcOnly, intermediaryVersion, }) => {
9
9
  if (!(0, firmwareUtils_1.isStrictFeatures)(features)) {
10
10
  throw new Error('Features of unexpected shape provided');
11
11
  }
12
- if (intermediary && features.major_version !== 2) {
13
- const fw = await (0, assets_1.httpRequest)(`${baseUrl}/firmware/1/trezor-inter-1.10.0.bin`, 'binary');
14
- return { binary: fw };
12
+ if (intermediaryVersion) {
13
+ return (0, assets_1.httpRequest)(`${baseUrl}/firmware/1/trezor-inter-v${intermediaryVersion}.bin`, 'binary');
15
14
  }
16
15
  const infoByBootloader = (0, firmwareInfo_1.getInfo)({ features, releases });
17
16
  const releaseByFirmware = releases.find(r => version &&
@@ -26,11 +25,8 @@ const getBinary = async ({ features, releases, baseUrl, version, btcOnly, interm
26
25
  if (!utils_1.versionUtils.isEqual(releaseByFirmware.version, infoByBootloader.release.version)) {
27
26
  throw new Error('version provided as param does not match firmware version found by features in bootloader');
28
27
  }
29
- const fw = await (0, assets_1.httpRequest)(`${baseUrl}/${btcOnly ? releaseByFirmware.url_bitcoinonly : releaseByFirmware.url}`, 'binary');
30
- return {
31
- ...infoByBootloader,
32
- binary: fw,
33
- };
28
+ const fwUrl = releaseByFirmware[btcOnly ? 'url_bitcoinonly' : 'url'];
29
+ return (0, assets_1.httpRequest)(`${baseUrl}/${fwUrl}`, 'binary');
34
30
  };
35
31
  exports.getBinary = getBinary;
36
32
  //# sourceMappingURL=getBinary.js.map
@@ -1,10 +1,11 @@
1
1
  import { AbstractMethod } from '../core/AbstractMethod';
2
+ import { IntermediaryVersion } from '../types';
2
3
  type Params = {
3
4
  binary?: ArrayBuffer;
4
5
  version?: number[];
5
6
  btcOnly?: boolean;
6
- baseUrl?: string;
7
- intermediary?: boolean;
7
+ baseUrl: string;
8
+ intermediaryVersion?: IntermediaryVersion;
8
9
  };
9
10
  export default class FirmwareUpdate extends AbstractMethod<'firmwareUpdate', Params> {
10
11
  init(): void;
@@ -22,14 +22,14 @@ class FirmwareUpdate extends AbstractMethod_1.AbstractMethod {
22
22
  { name: 'btcOnly', type: 'boolean' },
23
23
  { name: 'baseUrl', type: 'string' },
24
24
  { name: 'binary', type: 'array-buffer' },
25
- { name: 'intermediary', type: 'boolean' },
25
+ { name: 'intermediaryVersion', type: 'number' },
26
26
  ]);
27
27
  if ('version' in payload) {
28
28
  this.params = {
29
29
  version: payload.version,
30
30
  btcOnly: payload.btcOnly,
31
31
  baseUrl: payload.baseUrl || 'https://data.trezor.io',
32
- intermediary: payload.intermediary,
32
+ intermediaryVersion: payload.intermediaryVersion,
33
33
  };
34
34
  }
35
35
  if ('binary' in payload) {
@@ -61,15 +61,14 @@ class FirmwareUpdate extends AbstractMethod_1.AbstractMethod {
61
61
  binary = params.binary;
62
62
  }
63
63
  else {
64
- const firmware = await (0, firmware_1.getBinary)({
64
+ binary = await (0, firmware_1.getBinary)({
65
65
  features: device.features,
66
66
  releases: (0, firmwareInfo_1.getReleases)(device.features.major_version),
67
67
  version: params.version,
68
68
  btcOnly: params.btcOnly,
69
69
  baseUrl: params.baseUrl,
70
- intermediary: params.intermediary,
70
+ intermediaryVersion: params.intermediaryVersion,
71
71
  });
72
- binary = firmware.binary;
73
72
  }
74
73
  }
75
74
  catch (err) {
@@ -20,18 +20,18 @@ export default class GetAccountInfo extends AbstractMethod<'getAccountInfo', Req
20
20
  balance: string;
21
21
  availableBalance: string;
22
22
  empty: boolean;
23
- tokens?: import("packages/blockchain-link/lib/types/common").TokenInfo[] | undefined;
24
- addresses?: import("packages/blockchain-link/lib/types/common").AccountAddresses | undefined;
23
+ tokens?: import("packages/blockchain-link-types/lib/common").TokenInfo[] | undefined;
24
+ addresses?: import("packages/blockchain-link-types/lib/common").AccountAddresses | undefined;
25
25
  history: {
26
26
  total: number;
27
27
  tokens?: number | undefined;
28
28
  unconfirmed: number;
29
- transactions?: import("packages/blockchain-link/lib/types/common").Transaction[] | undefined;
29
+ transactions?: import("packages/blockchain-link-types/lib/common").Transaction[] | undefined;
30
30
  txids?: string[] | undefined;
31
31
  };
32
32
  misc?: {
33
33
  nonce?: string | undefined;
34
- erc20Contract?: import("packages/blockchain-link/lib/types/common").TokenInfo | undefined;
34
+ erc20Contract?: import("packages/blockchain-link-types/lib/common").TokenInfo | undefined;
35
35
  sequence?: number | undefined;
36
36
  reserve?: string | undefined;
37
37
  rewards?: string | undefined;
@@ -59,18 +59,18 @@ export default class GetAccountInfo extends AbstractMethod<'getAccountInfo', Req
59
59
  balance: string;
60
60
  availableBalance: string;
61
61
  empty: boolean;
62
- tokens?: import("packages/blockchain-link/lib/types/common").TokenInfo[] | undefined;
63
- addresses?: import("packages/blockchain-link/lib/types/common").AccountAddresses | undefined;
62
+ tokens?: import("packages/blockchain-link-types/lib/common").TokenInfo[] | undefined;
63
+ addresses?: import("packages/blockchain-link-types/lib/common").AccountAddresses | undefined;
64
64
  history: {
65
65
  total: number;
66
66
  tokens?: number | undefined;
67
67
  unconfirmed: number;
68
- transactions?: import("packages/blockchain-link/lib/types/common").Transaction[] | undefined;
68
+ transactions?: import("packages/blockchain-link-types/lib/common").Transaction[] | undefined;
69
69
  txids?: string[] | undefined;
70
70
  };
71
71
  misc?: {
72
72
  nonce?: string | undefined;
73
- erc20Contract?: import("packages/blockchain-link/lib/types/common").TokenInfo | undefined;
73
+ erc20Contract?: import("packages/blockchain-link-types/lib/common").TokenInfo | undefined;
74
74
  sequence?: number | undefined;
75
75
  reserve?: string | undefined;
76
76
  rewards?: string | undefined;
@@ -287,7 +287,7 @@ class GetAccountInfo extends AbstractMethod_1.AbstractMethod {
287
287
  discovery.stop();
288
288
  const account = discovery.accounts[uiResp.payload];
289
289
  if (!discovery.completed) {
290
- await (0, promiseUtils_1.resolveAfter)(501);
290
+ await (0, promiseUtils_1.resolveAfter)(501).promise;
291
291
  }
292
292
  const info = await blockchain.getAccountInfo({
293
293
  descriptor: account.descriptor,
@@ -9,10 +9,7 @@ class SetBusy extends AbstractMethod_1.AbstractMethod {
9
9
  this.requiredPermissions = ['management'];
10
10
  const { payload } = this;
11
11
  (0, paramsValidator_1.validateParams)(payload, [{ name: 'expiry_ms', type: 'number' }]);
12
- this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, null, {
13
- 1: { min: '0', max: '0' },
14
- 2: { min: '2.5.3', max: '0' },
15
- });
12
+ this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, undefined, this.firmwareRange);
16
13
  this.params = {
17
14
  expiry_ms: payload.expiry_ms,
18
15
  };
@@ -15,7 +15,7 @@ class SetProxy extends AbstractMethod_1.AbstractMethod {
15
15
  const { proxy } = DataManager_1.DataManager.getSettings();
16
16
  const isChanged = proxy !== this.payload.proxy;
17
17
  if (isChanged) {
18
- DataManager_1.DataManager.settings.proxy = this.payload.proxy;
18
+ DataManager_1.DataManager.getSettings().proxy = this.payload.proxy;
19
19
  await (0, BlockchainLink_1.reconnectAllBackends)();
20
20
  }
21
21
  return { message: 'Success' };
@@ -143,15 +143,23 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
143
143
  if (!response.serializedTx) {
144
144
  return response;
145
145
  }
146
+ let bitcoinTx;
146
147
  if (params.options.decred_staking_ticket) {
147
148
  await (0, bitcoin_1.verifyTicketTx)(device.getCommands().getHDNode.bind(device.getCommands()), params.inputs, params.outputs, response.serializedTx, params.coinInfo);
148
149
  }
149
150
  else {
150
- const bitcoinTx = await (0, bitcoin_1.verifyTx)(device.getCommands().getHDNode.bind(device.getCommands()), params.inputs, params.outputs, response.serializedTx, params.coinInfo, params.unlockPath);
151
+ bitcoinTx = await (0, bitcoin_1.verifyTx)(device.getCommands().getHDNode.bind(device.getCommands()), params.inputs, params.outputs, response.serializedTx, params.coinInfo, params.unlockPath);
151
152
  if (bitcoinTx.hasWitnesses()) {
152
- response.witnesses = bitcoinTx.ins.map((_, i) => { var _a; return (_a = bitcoinTx.getWitness(i)) === null || _a === void 0 ? void 0 : _a.toString('hex'); });
153
+ response.witnesses = bitcoinTx.ins.map((_, i) => { var _a; return (_a = bitcoinTx === null || bitcoinTx === void 0 ? void 0 : bitcoinTx.getWitness(i)) === null || _a === void 0 ? void 0 : _a.toString('hex'); });
153
154
  }
154
155
  }
156
+ if (bitcoinTx && params.addresses) {
157
+ response.signedTransaction = (0, bitcoin_1.createPendingTransaction)(bitcoinTx, {
158
+ addresses: params.addresses,
159
+ inputs: params.inputs,
160
+ outputs: params.outputs,
161
+ });
162
+ }
155
163
  if (params.push) {
156
164
  (0, BlockchainLink_1.isBackendSupported)(params.coinInfo);
157
165
  const blockchain = await (0, BlockchainLink_1.initBlockchain)(params.coinInfo, this.postMessage);
@@ -7,10 +7,7 @@ class UnlockPath extends AbstractMethod_1.AbstractMethod {
7
7
  init() {
8
8
  this.requiredPermissions = ['read'];
9
9
  this.skipFinalReload = true;
10
- this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, null, {
11
- 1: { min: '0', max: '0' },
12
- 2: { min: '2.5.3', max: '0' },
13
- });
10
+ this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, undefined, this.firmwareRange);
14
11
  const { payload } = this;
15
12
  (0, paramsValidator_1.validateParams)(payload, [
16
13
  { name: 'path', required: true },
@@ -25,12 +25,15 @@ export declare class Blockchain {
25
25
  getTransactions(txs: string[]): Promise<import("@trezor/blockchain-link").TypedRawTransaction[]>;
26
26
  getCurrentFiatRates(params: {
27
27
  currencies?: string[];
28
+ token?: string;
28
29
  }): Promise<{
29
30
  ts: number;
30
31
  rates: import("@trezor/blockchain-link").FiatRates;
31
32
  }>;
32
33
  getFiatRatesForTimestamps(params: {
34
+ currencies?: string[];
33
35
  timestamps: number[];
36
+ token?: string;
34
37
  }): Promise<{
35
38
  tickers: {
36
39
  ts: number;
@@ -52,6 +52,7 @@ export declare abstract class AbstractMethod<Name extends CallMethodPayload['met
52
52
  checkPermissions(): void;
53
53
  savePermissions(temporary?: boolean): void;
54
54
  checkFirmwareRange(isUsingPopup?: boolean): Promise<"ui-device_firmware_old" | "ui-device_firmware_unsupported" | "ui-device_firmware_not_compatible" | "ui-device_firmware_not_installed" | undefined>;
55
+ isManagementRestricted(): boolean | undefined;
55
56
  abstract init(): void;
56
57
  abstract run(): Promise<MethodReturnType<Name>>;
57
58
  dispose(): void;
@@ -6,6 +6,7 @@ const DataManager_1 = require("../data/DataManager");
6
6
  const constants_1 = require("../constants");
7
7
  const events_1 = require("../events");
8
8
  const versionUtils_1 = require("../utils/versionUtils");
9
+ const urlUtils_1 = require("../utils/urlUtils");
9
10
  class AbstractMethod {
10
11
  constructor(message) {
11
12
  var _a, _b;
@@ -154,6 +155,14 @@ class AbstractMethod {
154
155
  }
155
156
  }
156
157
  }
158
+ isManagementRestricted() {
159
+ const { popup, origin } = DataManager_1.DataManager.getSettings();
160
+ if (popup && this.requiredPermissions.includes('management')) {
161
+ const host = (0, urlUtils_1.getHost)(origin);
162
+ const allowed = DataManager_1.DataManager.getConfig().management.find(item => item.origin === host || item.origin === origin);
163
+ return !allowed;
164
+ }
165
+ }
157
166
  dispose() { }
158
167
  }
159
168
  exports.AbstractMethod = AbstractMethod;
package/lib/core/index.js CHANGED
@@ -21,6 +21,7 @@ let _uiPromises = [];
21
21
  const _callMethods = [];
22
22
  let _preferredDevice;
23
23
  let _interactionTimeout;
24
+ let _deviceListInitTimeout;
24
25
  const _log = (0, debug_1.initLog)('Core');
25
26
  const postMessage = (message) => {
26
27
  if (message.event === events_2.RESPONSE_EVENT) {
@@ -126,6 +127,9 @@ const initDevice = async (method) => {
126
127
  if (showDeviceSelection) {
127
128
  createUiPromise(events_2.UI.RECEIVE_DEVICE);
128
129
  await getPopupPromise().promise;
130
+ if (!_deviceList) {
131
+ throw constants_1.ERRORS.TypedError('Transport_Missing');
132
+ }
129
133
  const devices = _deviceList.asArray();
130
134
  if (devices.length === 1 && devices[0].type !== 'unreadable' && !isWebUsb) {
131
135
  device = _deviceList.getDevice(devices[0].path);
@@ -196,9 +200,7 @@ const onCall = async (message) => {
196
200
  if (!_deviceList && !DataManager_1.DataManager.getSettings('transportReconnect')) {
197
201
  await (0, exports.initTransport)(DataManager_1.DataManager.getSettings());
198
202
  }
199
- if (isUsingPopup &&
200
- method.requiredPermissions.includes('management') &&
201
- !DataManager_1.DataManager.isManagementAllowed()) {
203
+ if (method.isManagementRestricted()) {
202
204
  postMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
203
205
  postMessage((0, events_2.createResponseMessage)(responseID, false, {
204
206
  error: constants_1.ERRORS.TypedError('Method_NotAllowed'),
@@ -380,7 +382,7 @@ const onCall = async (message) => {
380
382
  const response = messageResponse;
381
383
  if (response) {
382
384
  if (method.name === 'rebootToBootloader' && response.success) {
383
- await (0, promiseUtils_1.resolveAfter)(1000);
385
+ await (0, promiseUtils_1.resolveAfter)(1000).promise;
384
386
  await device.run(() => Promise.resolve(), { skipFinalReload: true });
385
387
  }
386
388
  await device.cleanup();
@@ -564,8 +566,10 @@ const initDeviceList = async (settings) => {
564
566
  _deviceList = undefined;
565
567
  postMessage((0, events_2.createTransportMessage)(events_2.TRANSPORT.ERROR, { error }));
566
568
  if (settings.transportReconnect) {
567
- await (0, promiseUtils_1.resolveAfter)(1000, null);
568
- await initDeviceList(settings);
569
+ const { promise, timeout } = (0, promiseUtils_1.resolveAfter)(1000, null);
570
+ _deviceListInitTimeout = timeout;
571
+ await promise;
572
+ initDeviceList(settings);
569
573
  }
570
574
  });
571
575
  _deviceList.on(events_2.TRANSPORT.START, transportType => postMessage((0, events_2.createTransportMessage)(events_2.TRANSPORT.START, transportType)));
@@ -581,7 +585,9 @@ const initDeviceList = async (settings) => {
581
585
  throw error;
582
586
  }
583
587
  else {
584
- await (0, promiseUtils_1.resolveAfter)(3000, null);
588
+ const { promise, timeout } = (0, promiseUtils_1.resolveAfter)(3000, null);
589
+ _deviceListInitTimeout = timeout;
590
+ await promise;
585
591
  await initDeviceList(settings);
586
592
  }
587
593
  }
@@ -592,6 +598,9 @@ class Core extends events_1.default {
592
598
  }
593
599
  async dispose() {
594
600
  (0, BlockchainLink_1.dispose)();
601
+ if (_deviceListInitTimeout) {
602
+ clearTimeout(_deviceListInitTimeout);
603
+ }
595
604
  this.removeAllListeners();
596
605
  if (_deviceList) {
597
606
  await _deviceList.dispose();
@@ -654,7 +663,7 @@ const disableWebUSBTransport = async () => {
654
663
  return;
655
664
  const settings = DataManager_1.DataManager.getSettings();
656
665
  if ((_a = settings.transports) === null || _a === void 0 ? void 0 : _a.includes('WebUsbTransport')) {
657
- settings.transports.splice(settings.transports.indexOf('WebUsbTransport'));
666
+ settings.transports.splice(settings.transports.indexOf('WebUsbTransport'), 1);
658
667
  }
659
668
  if (!((_b = settings.transports) === null || _b === void 0 ? void 0 : _b.includes('BridgeTransport'))) {
660
669
  settings.transports.unshift('BridgeTransport');
@@ -1,29 +1,106 @@
1
- import { config } from './config';
2
1
  import type { ConnectSettings } from '../types';
3
2
  type AssetCollection = {
4
3
  [key: string]: JSON;
5
4
  };
6
5
  export declare class DataManager {
7
6
  static assets: AssetCollection;
8
- static settings: ConnectSettings;
7
+ private static settings;
9
8
  private static messages;
10
9
  static load(settings: ConnectSettings, withAssets?: boolean): Promise<void>;
11
10
  static getProtobufMessages(): JSON;
12
- static isWhitelisted(origin: string): {
13
- origin: string;
14
- priority: number;
15
- } | undefined;
16
- static isManagementAllowed(): {
17
- origin: string;
18
- } | undefined;
19
- static getPriority(whitelist?: (typeof config)['whitelist'][0]): number;
20
- static getHostLabel(origin: string): {
21
- origin: string;
22
- label: string;
23
- icon: string;
24
- } | undefined;
25
11
  static getSettings(key?: undefined): ConnectSettings;
26
12
  static getSettings<T extends keyof ConnectSettings>(key: T): ConnectSettings[T];
13
+ static getConfig(): {
14
+ webusb: {
15
+ vendorId: number;
16
+ productId: number;
17
+ }[];
18
+ whitelist: {
19
+ origin: string;
20
+ priority: number;
21
+ }[];
22
+ management: {
23
+ origin: string;
24
+ }[];
25
+ knownHosts: {
26
+ origin: string;
27
+ label: string;
28
+ icon: string;
29
+ }[];
30
+ onionDomains: {
31
+ 'trezor.io': string;
32
+ };
33
+ assets: {
34
+ name: string;
35
+ url: string;
36
+ }[];
37
+ messages: string;
38
+ supportedBrowsers: {
39
+ chrome: {
40
+ version: number;
41
+ download: string;
42
+ update: string;
43
+ };
44
+ chromium: {
45
+ version: number;
46
+ download: string;
47
+ update: string;
48
+ };
49
+ electron: {
50
+ version: number;
51
+ download: string;
52
+ update: string;
53
+ };
54
+ firefox: {
55
+ version: number;
56
+ download: string;
57
+ update: string;
58
+ };
59
+ };
60
+ supportedFirmware: ({
61
+ coin: string[];
62
+ methods: string[];
63
+ min: string[];
64
+ max: undefined;
65
+ comment: string[];
66
+ capabilities?: undefined;
67
+ } | {
68
+ coin: string[];
69
+ min: string[];
70
+ comment: string[];
71
+ methods?: undefined;
72
+ max?: undefined;
73
+ capabilities?: undefined;
74
+ } | {
75
+ methods: string[];
76
+ min: string[];
77
+ comment: string[];
78
+ coin?: undefined;
79
+ max?: undefined;
80
+ capabilities?: undefined;
81
+ } | {
82
+ capabilities: string[];
83
+ min: string[];
84
+ comment: string[];
85
+ coin?: undefined;
86
+ methods?: undefined;
87
+ max?: undefined;
88
+ } | {
89
+ coin: string[];
90
+ methods: string[];
91
+ min: string[];
92
+ comment: string[];
93
+ max?: undefined;
94
+ capabilities?: undefined;
95
+ } | {
96
+ capabilities: string[];
97
+ methods: string[];
98
+ min: string[];
99
+ coin?: undefined;
100
+ max?: undefined;
101
+ comment?: undefined;
102
+ })[];
103
+ };
27
104
  }
28
105
  export {};
29
106
  //# sourceMappingURL=DataManager.d.ts.map