@trezor/connect 9.0.7 → 9.0.8

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 (83) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +1 -1
  3. package/lib/api/bitcoin/createPendingTx.d.ts +35 -0
  4. package/lib/api/bitcoin/createPendingTx.js +60 -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 +13 -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.d.ts +2 -1
  35. package/lib/api/signTransaction.js +12 -2
  36. package/lib/api/unlockPath.js +1 -4
  37. package/lib/backend/Blockchain.d.ts +3 -0
  38. package/lib/core/AbstractMethod.d.ts +1 -0
  39. package/lib/core/AbstractMethod.js +9 -0
  40. package/lib/core/index.js +13 -7
  41. package/lib/data/DataManager.d.ts +92 -15
  42. package/lib/data/DataManager.js +3 -54
  43. package/lib/data/config.js +9 -3
  44. package/lib/data/connectSettings.d.ts +0 -1
  45. package/lib/data/connectSettings.js +10 -57
  46. package/lib/data/firmwareInfo.js +48 -46
  47. package/lib/data/transportInfo.d.ts +1 -0
  48. package/lib/data/transportInfo.js +14 -1
  49. package/lib/data/udevInfo.d.ts +1 -0
  50. package/lib/data/udevInfo.js +14 -1
  51. package/lib/data/version.d.ts +1 -1
  52. package/lib/data/version.js +1 -1
  53. package/lib/device/DescriptorStream.js +1 -1
  54. package/lib/device/DeviceCommands.d.ts +1 -1
  55. package/lib/device/DeviceCommands.js +2 -1
  56. package/lib/device/DeviceList.d.ts +1 -2
  57. package/lib/device/DeviceList.js +20 -10
  58. package/lib/events/iframe.d.ts +2 -1
  59. package/lib/events/popup.d.ts +2 -1
  60. package/lib/index.js +1 -4
  61. package/lib/types/api/bitcoin/index.d.ts +4 -0
  62. package/lib/types/api/cardano/index.d.ts +10 -9
  63. package/lib/types/api/firmwareUpdate.d.ts +2 -1
  64. package/lib/types/firmware.d.ts +2 -3
  65. package/lib/types/index.d.ts +1 -1
  66. package/lib/types/settings.d.ts +10 -1
  67. package/lib/utils/firmwareUtils.d.ts +0 -1
  68. package/lib/utils/firmwareUtils.js +1 -9
  69. package/lib/utils/pathUtils.d.ts +1 -0
  70. package/lib/utils/pathUtils.js +3 -1
  71. package/lib/utils/promiseUtils.d.ts +5 -1
  72. package/lib/utils/promiseUtils.js +7 -3
  73. package/lib/utils/urlUtils.d.ts +2 -1
  74. package/lib/utils/urlUtils.js +18 -3
  75. package/lib/utils/versionUtils.d.ts +3 -1
  76. package/lib/utils/versionUtils.js +5 -2
  77. package/package.json +12 -13
  78. package/lib/device/AbortController.d.ts +0 -21
  79. package/lib/device/AbortController.js +0 -40
  80. package/lib/utils/browserUtils.d.ts +0 -21
  81. package/lib/utils/browserUtils.js +0 -100
  82. package/lib/utils/windowsUtils.d.ts +0 -2
  83. 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'];
@@ -59,10 +60,22 @@ class EthereumSignTypedData extends AbstractMethod_1.AbstractMethod {
59
60
  { name: 'message_hash', type: 'string' },
60
61
  ]);
61
62
  const { domain_separator_hash, message_hash } = this.params;
63
+ const network = (0, coinInfo_1.getEthereumNetwork)(address_n);
64
+ const slip44 = (0, pathUtils_1.getSlip44ByPath)(address_n);
65
+ const definitions = await (0, ethereumDefinitions_1.getEthereumDefinitions)({
66
+ chainId: network === null || network === void 0 ? void 0 : network.chainId,
67
+ slip44,
68
+ });
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 {
@@ -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' };
@@ -1,6 +1,6 @@
1
1
  import { AbstractMethod } from '../core/AbstractMethod';
2
2
  import { PROTO } from '../constants';
3
- import type { BitcoinNetworkInfo, AccountAddresses } from '../types';
3
+ import type { BitcoinNetworkInfo, AccountAddresses, AccountUtxo } from '../types';
4
4
  import type { RefTransaction, TransactionOptions } from '../types/api/bitcoin';
5
5
  type Params = {
6
6
  inputs: PROTO.TxInputType[];
@@ -9,6 +9,7 @@ type Params = {
9
9
  coinjoinRequest?: PROTO.CoinJoinRequest;
10
10
  refTxs?: RefTransaction[];
11
11
  addresses?: AccountAddresses;
12
+ utxo?: AccountUtxo[];
12
13
  options: TransactionOptions;
13
14
  coinInfo: BitcoinNetworkInfo;
14
15
  push: boolean;
@@ -66,6 +66,7 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
66
66
  paymentRequests: payload.paymentRequests || [],
67
67
  refTxs,
68
68
  addresses: payload.account ? payload.account.addresses : undefined,
69
+ utxo: payload.account ? payload.account.utxo : undefined,
69
70
  options: {
70
71
  lock_time: payload.locktime,
71
72
  timestamp: payload.timestamp,
@@ -143,15 +144,24 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
143
144
  if (!response.serializedTx) {
144
145
  return response;
145
146
  }
147
+ let bitcoinTx;
146
148
  if (params.options.decred_staking_ticket) {
147
149
  await (0, bitcoin_1.verifyTicketTx)(device.getCommands().getHDNode.bind(device.getCommands()), params.inputs, params.outputs, response.serializedTx, params.coinInfo);
148
150
  }
149
151
  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);
152
+ bitcoinTx = await (0, bitcoin_1.verifyTx)(device.getCommands().getHDNode.bind(device.getCommands()), params.inputs, params.outputs, response.serializedTx, params.coinInfo, params.unlockPath);
151
153
  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'); });
154
+ 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
155
  }
154
156
  }
157
+ if (bitcoinTx && params.addresses && params.utxo) {
158
+ response.signedTransaction = (0, bitcoin_1.createPendingTransaction)(bitcoinTx, {
159
+ utxo: params.utxo,
160
+ addresses: params.addresses,
161
+ inputs: params.inputs,
162
+ outputs: params.outputs,
163
+ });
164
+ }
155
165
  if (params.push) {
156
166
  (0, BlockchainLink_1.isBackendSupported)(params.coinInfo);
157
167
  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) {
@@ -196,9 +197,7 @@ const onCall = async (message) => {
196
197
  if (!_deviceList && !DataManager_1.DataManager.getSettings('transportReconnect')) {
197
198
  await (0, exports.initTransport)(DataManager_1.DataManager.getSettings());
198
199
  }
199
- if (isUsingPopup &&
200
- method.requiredPermissions.includes('management') &&
201
- !DataManager_1.DataManager.isManagementAllowed()) {
200
+ if (method.isManagementRestricted()) {
202
201
  postMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
203
202
  postMessage((0, events_2.createResponseMessage)(responseID, false, {
204
203
  error: constants_1.ERRORS.TypedError('Method_NotAllowed'),
@@ -380,7 +379,7 @@ const onCall = async (message) => {
380
379
  const response = messageResponse;
381
380
  if (response) {
382
381
  if (method.name === 'rebootToBootloader' && response.success) {
383
- await (0, promiseUtils_1.resolveAfter)(1000);
382
+ await (0, promiseUtils_1.resolveAfter)(1000).promise;
384
383
  await device.run(() => Promise.resolve(), { skipFinalReload: true });
385
384
  }
386
385
  await device.cleanup();
@@ -564,8 +563,10 @@ const initDeviceList = async (settings) => {
564
563
  _deviceList = undefined;
565
564
  postMessage((0, events_2.createTransportMessage)(events_2.TRANSPORT.ERROR, { error }));
566
565
  if (settings.transportReconnect) {
567
- await (0, promiseUtils_1.resolveAfter)(1000, null);
568
- await initDeviceList(settings);
566
+ const { promise, timeout } = (0, promiseUtils_1.resolveAfter)(1000, null);
567
+ _deviceListInitTimeout = timeout;
568
+ await promise;
569
+ initDeviceList(settings);
569
570
  }
570
571
  });
571
572
  _deviceList.on(events_2.TRANSPORT.START, transportType => postMessage((0, events_2.createTransportMessage)(events_2.TRANSPORT.START, transportType)));
@@ -581,7 +582,9 @@ const initDeviceList = async (settings) => {
581
582
  throw error;
582
583
  }
583
584
  else {
584
- await (0, promiseUtils_1.resolveAfter)(3000, null);
585
+ const { promise, timeout } = (0, promiseUtils_1.resolveAfter)(3000, null);
586
+ _deviceListInitTimeout = timeout;
587
+ await promise;
585
588
  await initDeviceList(settings);
586
589
  }
587
590
  }
@@ -592,6 +595,9 @@ class Core extends events_1.default {
592
595
  }
593
596
  async dispose() {
594
597
  (0, BlockchainLink_1.dispose)();
598
+ if (_deviceListInitTimeout) {
599
+ clearTimeout(_deviceListInitTimeout);
600
+ }
595
601
  this.removeAllListeners();
596
602
  if (_deviceList) {
597
603
  await _deviceList.dispose();
@@ -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
@@ -1,39 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DataManager = void 0;
4
- const tslib_1 = require("tslib");
5
- const parse_uri_1 = tslib_1.__importDefault(require("parse-uri"));
6
4
  const assets_1 = require("../utils/assets");
7
- const connectSettings_1 = require("./connectSettings");
8
5
  const coinInfo_1 = require("./coinInfo");
9
6
  const firmwareInfo_1 = require("./firmwareInfo");
10
7
  const transportInfo_1 = require("./transportInfo");
11
8
  const config_1 = require("./config");
12
9
  class DataManager {
13
10
  static async load(settings, withAssets = true) {
14
- var _a;
15
11
  const ts = settings.env === 'web' ? `?r=${settings.timestamp}` : '';
16
12
  this.settings = settings;
17
- const isLocalhost = typeof window !== 'undefined' && window.location
18
- ? window.location.hostname === 'localhost'
19
- : true;
20
- const whitelist = DataManager.isWhitelisted(this.settings.origin || '');
21
- this.settings.trustedHost = (isLocalhost || !!whitelist) && !this.settings.popup;
22
- if (!this.settings.trustedHost) {
23
- this.settings.popup = true;
24
- }
25
- if (!this.settings.trustedHost && !whitelist) {
26
- this.settings.debug = false;
27
- }
28
- this.settings.priority = DataManager.getPriority(whitelist);
29
- const knownHost = DataManager.getHostLabel(this.settings.extension || this.settings.origin || '');
30
- if (knownHost) {
31
- this.settings.hostLabel = knownHost.label;
32
- this.settings.hostIcon = knownHost.icon;
33
- }
34
- if (this.settings.popup && this.settings.env !== 'webextension') {
35
- this.settings.transports = (_a = this.settings.transports) === null || _a === void 0 ? void 0 : _a.filter((transport) => transport !== 'WebUsbTransport');
36
- }
37
13
  if (!withAssets)
38
14
  return;
39
15
  const assetPromises = config_1.config.assets.map(async (asset) => {
@@ -50,36 +26,6 @@ class DataManager {
50
26
  static getProtobufMessages() {
51
27
  return this.messages;
52
28
  }
53
- static isWhitelisted(origin) {
54
- const uri = (0, parse_uri_1.default)(origin);
55
- if (uri && typeof uri.host === 'string') {
56
- const parts = uri.host.split('.');
57
- if (parts.length > 2) {
58
- uri.host = parts.slice(parts.length - 2, parts.length).join('.');
59
- }
60
- return config_1.config.whitelist.find(item => item.origin === origin || item.origin === uri.host);
61
- }
62
- }
63
- static isManagementAllowed() {
64
- var _a;
65
- const uri = (0, parse_uri_1.default)((_a = this.settings.origin) !== null && _a !== void 0 ? _a : '');
66
- if (uri && typeof uri.host === 'string') {
67
- const parts = uri.host.split('.');
68
- if (parts.length > 2) {
69
- uri.host = parts.slice(parts.length - 2, parts.length).join('.');
70
- }
71
- return config_1.config.management.find(item => item.origin === this.settings.origin || item.origin === uri.host);
72
- }
73
- }
74
- static getPriority(whitelist) {
75
- if (whitelist) {
76
- return whitelist.priority;
77
- }
78
- return connectSettings_1.DEFAULT_PRIORITY;
79
- }
80
- static getHostLabel(origin) {
81
- return config_1.config.knownHosts.find(host => host.origin === origin);
82
- }
83
29
  static getSettings(key) {
84
30
  if (!this.settings)
85
31
  return null;
@@ -88,6 +34,9 @@ class DataManager {
88
34
  }
89
35
  return this.settings;
90
36
  }
37
+ static getConfig() {
38
+ return config_1.config;
39
+ }
91
40
  }
92
41
  exports.DataManager = DataManager;
93
42
  DataManager.assets = {};