@trezor/connect 9.5.4 → 9.5.5-beta.2

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 (87) hide show
  1. package/CHANGELOG.md +800 -775
  2. package/README.md +5 -5
  3. package/lib/api/bitcoin/TransactionComposer.d.ts +3 -1
  4. package/lib/api/bitcoin/TransactionComposer.js +6 -3
  5. package/lib/api/bitcoin/index.d.ts +0 -1
  6. package/lib/api/bitcoin/index.js +0 -1
  7. package/lib/api/bitcoin/transactionBytes.d.ts +5 -0
  8. package/lib/api/bitcoin/transactionBytes.js +74 -0
  9. package/lib/api/bleUnpair.d.ts +9 -0
  10. package/lib/api/bleUnpair.js +36 -0
  11. package/lib/api/blockchainEstimateFee.js +4 -16
  12. package/lib/api/common/Discovery.d.ts +12 -10
  13. package/lib/api/common/Discovery.js +2 -4
  14. package/lib/api/composeTransaction.js +1 -1
  15. package/lib/api/ethereum/api/ethereumSignMessage.d.ts +6 -0
  16. package/lib/api/ethereum/api/ethereumSignMessage.js +10 -0
  17. package/lib/api/ethereum/api/ethereumSignTransaction.d.ts +21 -1
  18. package/lib/api/ethereum/api/ethereumSignTransaction.js +66 -0
  19. package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +6 -0
  20. package/lib/api/ethereum/api/ethereumSignTypedData.js +10 -0
  21. package/lib/api/getFeatures.js +1 -0
  22. package/lib/api/index.d.ts +1 -0
  23. package/lib/api/index.js +3 -1
  24. package/lib/api/signMessage.d.ts +8 -0
  25. package/lib/api/signMessage.js +16 -6
  26. package/lib/api/signTransaction.d.ts +205 -0
  27. package/lib/api/signTransaction.js +43 -0
  28. package/lib/api/solana/api/solanaSignTransaction.d.ts +20 -0
  29. package/lib/api/solana/api/solanaSignTransaction.js +132 -0
  30. package/lib/api/solana/solanaUtils.d.ts +1 -0
  31. package/lib/api/solana/solanaUtils.js +2 -1
  32. package/lib/backend/BackendManager.js +1 -1
  33. package/lib/backend/Blockchain.d.ts +1 -3
  34. package/lib/backend/Blockchain.js +1 -21
  35. package/lib/{api/bitcoin/BitcoinFees.d.ts → backend/fees/BitcoinFeeLevels.d.ts} +5 -6
  36. package/lib/{api/bitcoin/BitcoinFees.js → backend/fees/BitcoinFeeLevels.js} +5 -4
  37. package/lib/{api/ethereum/EthereumFees.d.ts → backend/fees/EthereumFeeLevels.d.ts} +4 -5
  38. package/lib/{api/ethereum/EthereumFees.js → backend/fees/EthereumFeeLevels.js} +4 -5
  39. package/lib/{api/common/MiscFees.d.ts → backend/fees/MiscFeeLevels.d.ts} +3 -3
  40. package/lib/{api/common/MiscFees.js → backend/fees/MiscFeeLevels.js} +3 -2
  41. package/lib/backend/fees/index.d.ts +6 -0
  42. package/lib/backend/fees/index.js +33 -0
  43. package/lib/constants/firmware.d.ts +0 -1
  44. package/lib/constants/firmware.js +1 -2
  45. package/lib/core/AbstractMethod.d.ts +7 -4
  46. package/lib/core/AbstractMethod.js +8 -1
  47. package/lib/core/index.d.ts +0 -1
  48. package/lib/core/index.js +22 -27
  49. package/lib/core/onCallFirmwareUpdate.js +1 -1
  50. package/lib/data/DataManager.d.ts +4 -1
  51. package/lib/data/DataManager.js +7 -0
  52. package/lib/data/config.d.ts +0 -14
  53. package/lib/data/config.js +4 -12
  54. package/lib/data/connectSettings.d.ts +5 -1
  55. package/lib/data/connectSettings.js +26 -2
  56. package/lib/data/defaultFeeLevels.js +3 -3
  57. package/lib/data/deviceAuthenticityConfig.js +22 -7
  58. package/lib/data/thpSettings.d.ts +3 -0
  59. package/lib/data/thpSettings.js +37 -0
  60. package/lib/data/version.d.ts +1 -1
  61. package/lib/data/version.js +1 -1
  62. package/lib/device/Device.d.ts +8 -11
  63. package/lib/device/Device.js +40 -80
  64. package/lib/device/DeviceCurrentSession.d.ts +9 -1
  65. package/lib/device/DeviceList.js +1 -1
  66. package/lib/events/index.d.ts +2 -0
  67. package/lib/events/ui-request.d.ts +18 -4
  68. package/lib/events/ui-request.js +1 -0
  69. package/lib/events/ui-response.d.ts +7 -1
  70. package/lib/events/ui-response.js +1 -0
  71. package/lib/factory.js +1 -0
  72. package/lib/tsconfig.lib.tsbuildinfo +1 -1
  73. package/lib/types/api/bleUnpair.d.ts +4 -0
  74. package/lib/types/api/bleUnpair.js +3 -0
  75. package/lib/types/api/index.d.ts +2 -0
  76. package/lib/types/api/solana/index.d.ts +4 -0
  77. package/lib/types/api/solana/index.js +1 -0
  78. package/lib/types/device.d.ts +4 -0
  79. package/lib/types/fees.d.ts +2 -0
  80. package/lib/types/fees.js +2 -0
  81. package/lib/types/firmware.d.ts +5 -0
  82. package/lib/types/settings.d.ts +20 -2
  83. package/lib/utils/firmwareUtils.d.ts +3 -1
  84. package/lib/utils/firmwareUtils.js +7 -1
  85. package/lib/utils/uiPromiseManager.d.ts +2 -0
  86. package/lib/utils/versionCheck.js +1 -1
  87. package/package.json +17 -16
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @trezor/connect
2
2
 
3
- API version 9.5.4
3
+ API version 9.5.5-beta.2
4
4
 
5
5
  [![Build Status](https://github.com/trezor/trezor-suite/actions/workflows/test-connect.yml/badge.svg)](https://github.com/trezor/trezor-suite/actions/workflows/test-connect.yml)
6
6
  [![NPM](https://img.shields.io/npm/v/@trezor/connect.svg)](https://www.npmjs.org/package/@trezor/connect)
@@ -38,8 +38,8 @@ For more instructions [refer to this document](https://github.com/trezor/trezor-
38
38
 
39
39
  Since version 9 we are adopting a new versioning strategy. With every release, we are going to update two urls
40
40
 
41
- - A) The latest release will always be available on https://connect.trezor.io/9/trezor-connect.js.
42
- - B) For those who like to have more control over their dependencies, there will be also a new url created in form of https://connect.trezor.io/9.1../trezor-connect.js. Please note that these endpoints will not receive any further updates including security updates.
41
+ - A) The latest release will always be available on https://connect.trezor.io/9/trezor-connect.js.
42
+ - B) For those who like to have more control over their dependencies, there will be also a new url created in form of https://connect.trezor.io/9.1../trezor-connect.js. Please note that these endpoints will not receive any further updates including security updates.
43
43
 
44
44
  Version 9 is available as `@trezor/connect` and `@trezor/connect-web` npm packages.
45
45
 
@@ -53,8 +53,8 @@ Current major version 9 is being developed on top of `develop` branch. When ther
53
53
 
54
54
  Minor versions are released when there are:
55
55
 
56
- - considerable additions to API
57
- - changes in npm package
56
+ - considerable additions to API
57
+ - changes in npm package
58
58
 
59
59
  ### Patch version
60
60
 
@@ -1,6 +1,6 @@
1
1
  import { ComposeOutput, TransactionInputOutputSortingStrategy } from '@trezor/utxo-lib';
2
- import { BitcoinFeeLevels } from './BitcoinFees';
3
2
  import { Blockchain } from '../../backend/BlockchainLink';
3
+ import { BitcoinFeeLevels } from '../../backend/fees/BitcoinFeeLevels';
4
4
  import type { BitcoinNetworkInfo, DiscoveryAccount } from '../../types';
5
5
  import type { ComposeResult, ComposeUtxo, ComposedInputs } from '../../types/api/composeTransaction';
6
6
  type Options = {
@@ -28,11 +28,13 @@ export declare class TransactionComposer {
28
28
  composeAllFeeLevels(): boolean;
29
29
  composeCustomFee(fee: string): void;
30
30
  getFeeLevelList(): ({
31
+ blocks?: undefined;
31
32
  feePerByte?: undefined;
32
33
  name: string;
33
34
  fee: "0";
34
35
  disabled: true;
35
36
  } | {
37
+ blocks: number;
36
38
  name: string;
37
39
  fee: string;
38
40
  feePerByte: string;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TransactionComposer = void 0;
4
4
  const bigNumber_1 = require("@trezor/utils/lib/bigNumber");
5
5
  const utxo_lib_1 = require("@trezor/utxo-lib");
6
- const BitcoinFees_1 = require("./BitcoinFees");
6
+ const fees_1 = require("../../backend/fees");
7
7
  class TransactionComposer {
8
8
  account;
9
9
  utxos;
@@ -21,7 +21,7 @@ class TransactionComposer {
21
21
  this.blockHeight = 0;
22
22
  this.baseFee = options.baseFee || 0;
23
23
  this.sortingStrategy = options.sortingStrategy;
24
- this.feeLevels = new BitcoinFees_1.BitcoinFeeLevels(options.coinInfo);
24
+ this.feeLevels = (0, fees_1.getOrInitBitcoinFeeLevels)(options.coinInfo);
25
25
  const { addresses } = options.account;
26
26
  const allAddresses = !addresses
27
27
  ? []
@@ -42,7 +42,9 @@ class TransactionComposer {
42
42
  async init(blockchain) {
43
43
  const { blockHeight } = await blockchain.getNetworkInfo();
44
44
  this.blockHeight = blockHeight;
45
- await this.feeLevels.load(blockchain);
45
+ if (!this.feeLevels.wasFetchedSuccessfully) {
46
+ await this.feeLevels.load(blockchain);
47
+ }
46
48
  }
47
49
  composeAllFeeLevels() {
48
50
  const { levels } = this.feeLevels;
@@ -95,6 +97,7 @@ class TransactionComposer {
95
97
  name: level.label,
96
98
  fee: tx.fee,
97
99
  feePerByte: level.feePerUnit,
100
+ blocks: level.blocks,
98
101
  minutes: level.blocks * this.coinInfo.blockTime,
99
102
  total: tx.totalSpent,
100
103
  });
@@ -1,6 +1,5 @@
1
1
  export * from './createPendingTx';
2
2
  export * from './enhanceSignTx';
3
- export * from './BitcoinFees';
4
3
  export * from './inputs';
5
4
  export * from './outputs';
6
5
  export * from './refTx';
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./createPendingTx"), exports);
5
5
  tslib_1.__exportStar(require("./enhanceSignTx"), exports);
6
- tslib_1.__exportStar(require("./BitcoinFees"), exports);
7
6
  tslib_1.__exportStar(require("./inputs"), exports);
8
7
  tslib_1.__exportStar(require("./outputs"), exports);
9
8
  tslib_1.__exportStar(require("./refTx"), exports);
@@ -0,0 +1,5 @@
1
+ import { PROTO } from '../../constants';
2
+ import { BitcoinNetworkInfo } from '../../exports';
3
+ export declare function mapOutputScriptToKey(script_type: string): "p2pkh" | "p2sh" | "p2tr" | "p2wpkh" | undefined;
4
+ export declare const getTransactionVbytes: (inputs: PROTO.TxInputType[], outputs: PROTO.TxOutputType[], coinInfo: BitcoinNetworkInfo) => number | undefined;
5
+ //# sourceMappingURL=transactionBytes.d.ts.map
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTransactionVbytes = void 0;
4
+ exports.mapOutputScriptToKey = mapOutputScriptToKey;
5
+ const tslib_1 = require("tslib");
6
+ const baddress = tslib_1.__importStar(require("@trezor/utxo-lib/lib/address"));
7
+ const txWeightCalculator_1 = require("@trezor/utxo-lib/lib/txWeightCalculator");
8
+ const pathUtils_1 = require("../../utils/pathUtils");
9
+ function mapOutputScriptToKey(script_type) {
10
+ switch (script_type) {
11
+ case 'PAYTOADDRESS':
12
+ return 'p2pkh';
13
+ case 'PAYTOSCRIPTHASH':
14
+ return 'p2sh';
15
+ case 'PAYTOWITNESS':
16
+ return 'p2wpkh';
17
+ case 'PAYTOP2SHWITNESS':
18
+ return 'p2sh';
19
+ case 'PAYTOTAPROOT':
20
+ return 'p2tr';
21
+ default:
22
+ return undefined;
23
+ }
24
+ }
25
+ const getTransactionVbytes = (inputs, outputs, coinInfo) => {
26
+ const calc = new txWeightCalculator_1.TxWeightCalculator();
27
+ let cannotProcess = false;
28
+ inputs.forEach(input => {
29
+ const script_type = input.script_type ?? (0, pathUtils_1.getScriptType)(input.address_n);
30
+ if (script_type && !input.witness) {
31
+ calc.addInput({
32
+ script_type,
33
+ multisig: input.multisig,
34
+ ownership_proof: input.ownership_proof,
35
+ });
36
+ }
37
+ else {
38
+ cannotProcess = true;
39
+ }
40
+ });
41
+ outputs.forEach(out => {
42
+ if (out.script_type === 'PAYTOOPRETURN') {
43
+ if (!out.op_return_data) {
44
+ cannotProcess = true;
45
+ return;
46
+ }
47
+ calc.addOutput({ length: 2 + out.op_return_data.length / 2 });
48
+ return;
49
+ }
50
+ else if (out.address) {
51
+ calc.addOutput({
52
+ length: baddress.toOutputScript(out.address, coinInfo.network).length,
53
+ });
54
+ return;
55
+ }
56
+ else if (out.address_n || out.script_type) {
57
+ const script_type = out.script_type ?? (0, pathUtils_1.getOutputScriptType)(out.address_n);
58
+ if (script_type) {
59
+ const script_key = mapOutputScriptToKey(script_type);
60
+ if (script_key) {
61
+ calc.addOutputByKey(script_key);
62
+ return;
63
+ }
64
+ }
65
+ }
66
+ cannotProcess = true;
67
+ });
68
+ if (cannotProcess) {
69
+ return undefined;
70
+ }
71
+ return calc.getVirtualBytes();
72
+ };
73
+ exports.getTransactionVbytes = getTransactionVbytes;
74
+ //# sourceMappingURL=transactionBytes.js.map
@@ -0,0 +1,9 @@
1
+ import { PROTO } from '../constants';
2
+ import { AbstractMethod } from '../core/AbstractMethod';
3
+ export default class BleUnpair extends AbstractMethod<'bleUnpair', PROTO.BleUnpair> {
4
+ init(): void;
5
+ run(): Promise<{
6
+ message: string;
7
+ }>;
8
+ }
9
+ //# sourceMappingURL=bleUnpair.d.ts.map
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const schema_utils_1 = require("@trezor/schema-utils");
4
+ const transport_1 = require("@trezor/transport");
5
+ const constants_1 = require("../constants");
6
+ const AbstractMethod_1 = require("../core/AbstractMethod");
7
+ const events_1 = require("../events");
8
+ class BleUnpair extends AbstractMethod_1.AbstractMethod {
9
+ init() {
10
+ this.allowDeviceMode = [events_1.UI.INITIALIZE, events_1.UI.SEEDLESS];
11
+ this.requiredPermissions = ['management'];
12
+ this.useDeviceState = false;
13
+ this.skipFinalReload = true;
14
+ const { payload } = this;
15
+ this.params = {
16
+ all: payload.all,
17
+ };
18
+ (0, schema_utils_1.Assert)(constants_1.PROTO.BleUnpair, payload);
19
+ }
20
+ async run() {
21
+ const cmd = this.device.getCommands();
22
+ try {
23
+ const response = await cmd.typedCall('BleUnpair', 'Success', this.params);
24
+ return response.message;
25
+ }
26
+ catch (error) {
27
+ if (this.device.bluetoothProps &&
28
+ error.message === transport_1.TRANSPORT_ERROR.INTERFACE_DATA_TRANSFER) {
29
+ throw constants_1.ERRORS.TypedError('Device_Disconnected');
30
+ }
31
+ throw error;
32
+ }
33
+ }
34
+ }
35
+ exports.default = BleUnpair;
36
+ //# sourceMappingURL=bleUnpair.js.map
@@ -4,20 +4,8 @@ const constants_1 = require("../constants");
4
4
  const AbstractMethod_1 = require("../core/AbstractMethod");
5
5
  const paramsValidator_1 = require("./common/paramsValidator");
6
6
  const BlockchainLink_1 = require("../backend/BlockchainLink");
7
+ const fees_1 = require("../backend/fees");
7
8
  const coinInfo_1 = require("../data/coinInfo");
8
- const BitcoinFees_1 = require("./bitcoin/BitcoinFees");
9
- const MiscFees_1 = require("./common/MiscFees");
10
- const EthereumFees_1 = require("./ethereum/EthereumFees");
11
- const getFees = (coinInfo) => {
12
- switch (coinInfo.type) {
13
- case 'bitcoin':
14
- return new BitcoinFees_1.BitcoinFeeLevels(coinInfo);
15
- case 'ethereum':
16
- return new EthereumFees_1.EthereumFeeLevels(coinInfo);
17
- default:
18
- return new MiscFees_1.MiscFeeLevels(coinInfo);
19
- }
20
- };
21
9
  class BlockchainEstimateFee extends AbstractMethod_1.AbstractMethod {
22
10
  init() {
23
11
  this.useDevice = false;
@@ -67,12 +55,12 @@ class BlockchainEstimateFee extends AbstractMethod_1.AbstractMethod {
67
55
  levels: [],
68
56
  };
69
57
  if (request?.feeLevels) {
70
- const fees = getFees(coinInfo);
58
+ const feeLevelsInstance = (0, fees_1.getOrInitFeeLevels)(coinInfo);
71
59
  if (request.feeLevels === 'smart') {
72
60
  const backend = await (0, BlockchainLink_1.initBlockchain)(coinInfo, this.postMessage, identity);
73
- await fees.load(backend, request);
61
+ await feeLevelsInstance.load(backend, request);
74
62
  }
75
- feeInfo.levels = fees.levels;
63
+ feeInfo.levels = feeLevelsInstance.levels;
76
64
  }
77
65
  else {
78
66
  const backend = await (0, BlockchainLink_1.initBlockchain)(coinInfo, this.postMessage, identity);
@@ -1,8 +1,7 @@
1
- import EventEmitter from 'events';
1
+ import { TypedEmitter } from '@trezor/utils';
2
2
  import { Blockchain } from '../../backend/BlockchainLink';
3
- import { PROTO } from '../../constants';
4
3
  import type { DeviceCommands } from '../../device/DeviceCommands';
5
- import type { CoinInfo, DiscoveryAccount, DiscoveryAccountType } from '../../types';
4
+ import type { DiscoveryAccount, DiscoveryAccountType } from '../../types';
6
5
  import type { GetAccountInfo } from '../../types/api/getAccountInfo';
7
6
  type DiscoveryType = {
8
7
  type: DiscoveryAccountType;
@@ -14,17 +13,20 @@ type DiscoveryOptions = {
14
13
  getDescriptor: GetDescriptor;
15
14
  limit?: number;
16
15
  };
17
- export declare class Discovery extends EventEmitter {
16
+ interface Events {
17
+ progress: DiscoveryAccount[];
18
+ complete: void;
19
+ }
20
+ export declare class Discovery extends TypedEmitter<Events> {
18
21
  types: DiscoveryType[];
19
- typeIndex: number;
22
+ private typeIndex;
20
23
  accounts: DiscoveryAccount[];
21
- coinInfo: CoinInfo;
22
- blockchain: Blockchain;
24
+ private coinInfo;
25
+ private blockchain;
23
26
  getDescriptor: GetDescriptor;
24
- index: number;
25
- interrupted: boolean;
27
+ private index;
28
+ private interrupted;
26
29
  completed: boolean;
27
- derivationType?: PROTO.CardanoDerivationType;
28
30
  constructor(options: DiscoveryOptions);
29
31
  start(details?: GetAccountInfo['details']): Promise<void>;
30
32
  stop(): void;
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Discovery = void 0;
4
- const tslib_1 = require("tslib");
5
- const events_1 = tslib_1.__importDefault(require("events"));
4
+ const utils_1 = require("@trezor/utils");
6
5
  const constants_1 = require("../../constants");
7
6
  const accountUtils_1 = require("../../utils/accountUtils");
8
7
  const formatUtils_1 = require("../../utils/formatUtils");
9
- class Discovery extends events_1.default {
8
+ class Discovery extends utils_1.TypedEmitter {
10
9
  types = [];
11
10
  typeIndex;
12
11
  accounts;
@@ -16,7 +15,6 @@ class Discovery extends events_1.default {
16
15
  index;
17
16
  interrupted;
18
17
  completed;
19
- derivationType;
20
18
  constructor(options) {
21
19
  super();
22
20
  this.accounts = [];
@@ -197,7 +197,7 @@ class ComposeTransaction extends AbstractMethod_1.AbstractMethod {
197
197
  utxos,
198
198
  coinInfo,
199
199
  outputs,
200
- sortingStrategy: skipPermutation === true ? 'none' : sortingStrategy ?? utxo_1.DEFAULT_SORTING_STRATEGY,
200
+ sortingStrategy: skipPermutation === true ? 'none' : (sortingStrategy ?? utxo_1.DEFAULT_SORTING_STRATEGY),
201
201
  });
202
202
  await composer.init(blockchain);
203
203
  const hasFunds = composer.composeAllFeeLevels();
@@ -10,6 +10,12 @@ export default class EthereumSignMessage extends AbstractMethod<'ethereumSignMes
10
10
  init(): void;
11
11
  initAsync(): Promise<void>;
12
12
  get info(): string;
13
+ getButtonRequestData(code: string, name?: string): {
14
+ type: "message";
15
+ coin: string;
16
+ serializedPath: string;
17
+ message: string;
18
+ } | undefined;
13
19
  run(): Promise<{
14
20
  address: string;
15
21
  signature: string;
@@ -38,6 +38,16 @@ class EthereumSignMessage extends AbstractMethod_1.AbstractMethod {
38
38
  get info() {
39
39
  return (0, ethereumUtils_1.getNetworkLabel)('Sign #NETWORK message', (0, coinInfo_1.getEthereumNetwork)(this.params.address_n));
40
40
  }
41
+ getButtonRequestData(code, name) {
42
+ if (code === 'ButtonRequest_Other' && name === 'sign_message') {
43
+ return {
44
+ type: 'message',
45
+ coin: this.params.network?.shortcut ?? 'ETH',
46
+ serializedPath: (0, pathUtils_1.getSerializedPath)(this.params.address_n),
47
+ message: this.payload.message,
48
+ };
49
+ }
50
+ }
41
51
  async run() {
42
52
  const cmd = this.device.getCommands();
43
53
  const { address_n, message } = this.params;
@@ -1,6 +1,6 @@
1
1
  import { MessagesSchema } from '@trezor/protobuf';
2
2
  import { AbstractMethod } from '../../../core/AbstractMethod';
3
- import { EthereumNetworkInfoDefinitionValues } from '../../../types';
3
+ import { EthereumNetworkInfoDefinitionValues, TokenInfo } from '../../../types';
4
4
  import type { EthereumTransaction, EthereumTransactionEIP1559 } from '../../../types/api/ethereum';
5
5
  type Params = {
6
6
  path: number[];
@@ -18,6 +18,26 @@ export default class EthereumSignTransaction extends AbstractMethod<'ethereumSig
18
18
  init(): void;
19
19
  initAsync(): Promise<void>;
20
20
  get info(): string;
21
+ payloadToPrecomposed(): Promise<{
22
+ type: "final";
23
+ inputs: never[];
24
+ outputsPermutation: number[];
25
+ outputs: {
26
+ address: string;
27
+ amount: string;
28
+ script_type: "PAYTOADDRESS";
29
+ }[];
30
+ totalSpent: string;
31
+ fee: string;
32
+ feePerByte: string;
33
+ maxFeePerGas: string | undefined;
34
+ maxPriorityFeePerGas: string | undefined;
35
+ feeLimit: string;
36
+ bytes: number;
37
+ max: undefined;
38
+ isTokenKnown: boolean;
39
+ token: TokenInfo | undefined;
40
+ } | undefined>;
21
41
  run(): Promise<{
22
42
  serializedTx: string;
23
43
  v: `0x${string}`;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const schema_utils_1 = require("@trezor/schema-utils");
5
+ const utils_1 = require("@trezor/utils");
5
6
  const AbstractMethod_1 = require("../../../core/AbstractMethod");
6
7
  const coinInfo_1 = require("../../../data/coinInfo");
7
8
  const types_1 = require("../../../types");
@@ -59,6 +60,71 @@ class EthereumSignTransaction extends AbstractMethod_1.AbstractMethod {
59
60
  get info() {
60
61
  return (0, ethereumUtils_1.getNetworkLabel)('Sign #NETWORK transaction', this.params.network);
61
62
  }
63
+ async payloadToPrecomposed() {
64
+ try {
65
+ const feePerByte = new utils_1.BigNumber(this.payload.transaction.gasPrice || this.payload.transaction.maxFeePerGas);
66
+ const fee = feePerByte.multipliedBy(this.payload.transaction.gasLimit);
67
+ const data = this.payload.transaction.data?.replace(/^0x/, '');
68
+ let recipient = this.payload.transaction.to;
69
+ let amount = new utils_1.BigNumber(this.payload.transaction.value);
70
+ let totalSpent = amount.plus(fee);
71
+ let token;
72
+ if (this.payload.transaction.to && data?.startsWith('a9059cbb') && amount.eq(0)) {
73
+ const definitions = await (0, ethereumDefinitions_1.getEthereumDefinitions)({
74
+ chainId: this.payload.transaction.chainId,
75
+ contractAddress: this.payload.transaction.to.replace(/^0x/, ''),
76
+ });
77
+ const decoded = (0, ethereumDefinitions_1.decodeEthereumDefinition)(definitions);
78
+ if (decoded.token) {
79
+ recipient = '0x' + data.slice(32, 72);
80
+ amount = new utils_1.BigNumber(data.slice(72, 136), 16);
81
+ totalSpent = amount;
82
+ token = {
83
+ ...decoded.token,
84
+ type: 'ERC20',
85
+ standard: 'ERC20',
86
+ contract: decoded.token.address,
87
+ };
88
+ }
89
+ }
90
+ return {
91
+ type: 'final',
92
+ inputs: [],
93
+ outputsPermutation: [0],
94
+ outputs: [
95
+ {
96
+ address: recipient,
97
+ amount: amount.toString(),
98
+ script_type: 'PAYTOADDRESS',
99
+ },
100
+ ],
101
+ totalSpent: totalSpent.toString(),
102
+ fee: fee.toString(),
103
+ feePerByte: feePerByte
104
+ .dividedBy(1e9)
105
+ .toString(),
106
+ maxFeePerGas: this.payload.transaction.maxFeePerGas
107
+ ? new utils_1.BigNumber(this.payload.transaction.maxFeePerGas)
108
+ .dividedBy(1e9)
109
+ .toString()
110
+ : undefined,
111
+ maxPriorityFeePerGas: this.payload.transaction.maxPriorityFeePerGas
112
+ ? new utils_1.BigNumber(this.payload.transaction.maxPriorityFeePerGas)
113
+ .dividedBy(1e9)
114
+ .toString()
115
+ : undefined,
116
+ feeLimit: new utils_1.BigNumber(this.payload.transaction.gasLimit).toString(),
117
+ bytes: 0,
118
+ max: undefined,
119
+ isTokenKnown: !!token,
120
+ token,
121
+ };
122
+ }
123
+ catch (e) {
124
+ console.error('Error in payloadToPrecomposed', e);
125
+ return Promise.resolve(undefined);
126
+ }
127
+ }
62
128
  async run() {
63
129
  const { type, tx, definitions, chunkify } = this.params;
64
130
  const isLegacy = type === 'legacy';
@@ -99,6 +99,12 @@ export default class EthereumSignTypedData extends AbstractMethod<'ethereumSignT
99
99
  init(): void;
100
100
  initAsync(): Promise<void>;
101
101
  get info(): string;
102
+ getButtonRequestData(code: string): {
103
+ type: "message";
104
+ coin: string;
105
+ serializedPath: string;
106
+ message: string;
107
+ } | undefined;
102
108
  run(): Promise<{
103
109
  address: string;
104
110
  signature: string;
@@ -74,6 +74,16 @@ class EthereumSignTypedData extends AbstractMethod_1.AbstractMethod {
74
74
  get info() {
75
75
  return (0, ethereumUtils_1.getNetworkLabel)('Sign #NETWORK typed data', (0, coinInfo_1.getEthereumNetwork)(this.params.address_n));
76
76
  }
77
+ getButtonRequestData(code) {
78
+ if (code === 'ButtonRequest_Other') {
79
+ return {
80
+ type: 'message',
81
+ coin: this.params.network?.shortcut ?? 'ETH',
82
+ serializedPath: (0, pathUtils_1.getSerializedPath)(this.params.address_n),
83
+ message: JSON.stringify(this.params.data, null, 2),
84
+ };
85
+ }
86
+ }
77
87
  async run() {
78
88
  const cmd = this.device.getCommands();
79
89
  const { address_n, definitions } = this.params;
@@ -9,6 +9,7 @@ class GetFeatures extends AbstractMethod_1.AbstractMethod {
9
9
  this.allowDeviceMode = [...this.allowDeviceMode, events_1.UI.INITIALIZE, events_1.UI.BOOTLOADER];
10
10
  this.useDeviceState = false;
11
11
  this.skipFirmwareCheck = true;
12
+ this.skipFinalReload = true;
12
13
  }
13
14
  run() {
14
15
  return Promise.resolve(this.device.features);
@@ -5,6 +5,7 @@ export { default as authorizeCoinjoin } from './authorizeCoinjoin';
5
5
  export { default as cancelCoinjoinAuthorization } from './cancelCoinjoinAuthorization';
6
6
  export { default as showDeviceTutorial } from './showDeviceTutorial';
7
7
  export { default as backupDevice } from './backupDevice';
8
+ export { default as bleUnpair } from './bleUnpair';
8
9
  export { default as blockchainDisconnect } from './blockchainDisconnect';
9
10
  export { default as blockchainEstimateFee } from './blockchainEstimateFee';
10
11
  export { default as blockchainGetAccountBalanceHistory } from './blockchainGetAccountBalanceHistory';
package/lib/api/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wipeDevice = exports.verifyMessage = exports.unlockPath = exports.signTransaction = exports.signMessage = exports.setProxy = exports.setBusy = exports.setBrightness = exports.loadDevice = exports.resetDevice = exports.requestLogin = exports.recoveryDevice = exports.pushTransaction = exports.getSettings = exports.getPublicKey = exports.getOwnershipProof = exports.getOwnershipId = exports.getFirmwareHash = exports.getFeatures = exports.getDeviceState = exports.getCoinInfo = exports.getAddress = exports.getAccountInfo = exports.getAccountDescriptor = exports.composeTransaction = exports.cipherKeyValue = exports.changeWipeCode = exports.changePin = exports.changeLanguage = exports.blockchainUnsubscribeFiatRates = exports.blockchainUnsubscribe = exports.blockchainSubscribeFiatRates = exports.blockchainSubscribe = exports.blockchainSetCustomBackend = exports.blockchainGetTransactions = exports.blockchainGetFiatRatesForTimestamps = exports.blockchainEvmRpcCall = exports.blockchainGetInfo = exports.blockchainGetCurrentFiatRates = exports.blockchainGetAccountBalanceHistory = exports.blockchainEstimateFee = exports.blockchainDisconnect = exports.backupDevice = exports.showDeviceTutorial = exports.cancelCoinjoinAuthorization = exports.authorizeCoinjoin = exports.authenticateDevice = exports.applySettings = exports.applyFlags = void 0;
3
+ exports.wipeDevice = exports.verifyMessage = exports.unlockPath = exports.signTransaction = exports.signMessage = exports.setProxy = exports.setBusy = exports.setBrightness = exports.loadDevice = exports.resetDevice = exports.requestLogin = exports.recoveryDevice = exports.pushTransaction = exports.getSettings = exports.getPublicKey = exports.getOwnershipProof = exports.getOwnershipId = exports.getFirmwareHash = exports.getFeatures = exports.getDeviceState = exports.getCoinInfo = exports.getAddress = exports.getAccountInfo = exports.getAccountDescriptor = exports.composeTransaction = exports.cipherKeyValue = exports.changeWipeCode = exports.changePin = exports.changeLanguage = exports.blockchainUnsubscribeFiatRates = exports.blockchainUnsubscribe = exports.blockchainSubscribeFiatRates = exports.blockchainSubscribe = exports.blockchainSetCustomBackend = exports.blockchainGetTransactions = exports.blockchainGetFiatRatesForTimestamps = exports.blockchainEvmRpcCall = exports.blockchainGetInfo = exports.blockchainGetCurrentFiatRates = exports.blockchainGetAccountBalanceHistory = exports.blockchainEstimateFee = exports.blockchainDisconnect = exports.bleUnpair = exports.backupDevice = exports.showDeviceTutorial = exports.cancelCoinjoinAuthorization = exports.authorizeCoinjoin = exports.authenticateDevice = exports.applySettings = exports.applyFlags = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  var applyFlags_1 = require("./applyFlags");
6
6
  Object.defineProperty(exports, "applyFlags", { enumerable: true, get: function () { return tslib_1.__importDefault(applyFlags_1).default; } });
@@ -16,6 +16,8 @@ var showDeviceTutorial_1 = require("./showDeviceTutorial");
16
16
  Object.defineProperty(exports, "showDeviceTutorial", { enumerable: true, get: function () { return tslib_1.__importDefault(showDeviceTutorial_1).default; } });
17
17
  var backupDevice_1 = require("./backupDevice");
18
18
  Object.defineProperty(exports, "backupDevice", { enumerable: true, get: function () { return tslib_1.__importDefault(backupDevice_1).default; } });
19
+ var bleUnpair_1 = require("./bleUnpair");
20
+ Object.defineProperty(exports, "bleUnpair", { enumerable: true, get: function () { return tslib_1.__importDefault(bleUnpair_1).default; } });
19
21
  var blockchainDisconnect_1 = require("./blockchainDisconnect");
20
22
  Object.defineProperty(exports, "blockchainDisconnect", { enumerable: true, get: function () { return tslib_1.__importDefault(blockchainDisconnect_1).default; } });
21
23
  var blockchainEstimateFee_1 = require("./blockchainEstimateFee");
@@ -1,8 +1,16 @@
1
1
  import type { PROTO } from '../constants';
2
2
  import { AbstractMethod } from '../core/AbstractMethod';
3
+ import type { BitcoinNetworkInfo } from '../types';
3
4
  export default class SignMessage extends AbstractMethod<'signMessage', PROTO.SignMessage> {
5
+ coinInfo: BitcoinNetworkInfo | undefined;
4
6
  init(): void;
5
7
  get info(): string;
8
+ getButtonRequestData(code: string, name?: string): {
9
+ type: "message";
10
+ serializedPath: string;
11
+ coin: string;
12
+ message: string;
13
+ } | undefined;
6
14
  run(): Promise<{
7
15
  address: string;
8
16
  signature: string;
@@ -8,20 +8,20 @@ const coinInfo_1 = require("../data/coinInfo");
8
8
  const formatUtils_1 = require("../utils/formatUtils");
9
9
  const pathUtils_1 = require("../utils/pathUtils");
10
10
  class SignMessage extends AbstractMethod_1.AbstractMethod {
11
+ coinInfo;
11
12
  init() {
12
13
  this.requiredPermissions = ['read', 'write'];
13
14
  const { payload } = this;
14
15
  (0, schema_utils_1.Assert)(types_1.SignMessage, payload);
15
16
  const path = (0, pathUtils_1.validatePath)(payload.path);
16
- let coinInfo;
17
17
  if (payload.coin) {
18
- coinInfo = (0, coinInfo_1.getBitcoinNetwork)(payload.coin);
19
- (0, paramsValidator_1.validateCoinPath)(path, coinInfo);
18
+ this.coinInfo = (0, coinInfo_1.getBitcoinNetwork)(payload.coin);
19
+ (0, paramsValidator_1.validateCoinPath)(path, this.coinInfo);
20
20
  }
21
21
  else {
22
- coinInfo = (0, coinInfo_1.getBitcoinNetwork)(path);
22
+ this.coinInfo = (0, coinInfo_1.getBitcoinNetwork)(path);
23
23
  }
24
- this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(payload.no_script_type ? 'signMessageNoScriptType' : this.name, coinInfo, this.firmwareRange);
24
+ this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(payload.no_script_type ? 'signMessageNoScriptType' : this.name, this.coinInfo, this.firmwareRange);
25
25
  const messageHex = payload.hex
26
26
  ? (0, formatUtils_1.messageToHex)(payload.message)
27
27
  : Buffer.from(payload.message, 'utf8').toString('hex');
@@ -29,7 +29,7 @@ class SignMessage extends AbstractMethod_1.AbstractMethod {
29
29
  this.params = {
30
30
  address_n: path,
31
31
  message: messageHex,
32
- coin_name: coinInfo ? coinInfo.name : undefined,
32
+ coin_name: this.coinInfo ? this.coinInfo.name : undefined,
33
33
  script_type: scriptType && scriptType !== 'SPENDMULTISIG' ? scriptType : 'SPENDADDRESS',
34
34
  no_script_type: payload.no_script_type,
35
35
  };
@@ -38,6 +38,16 @@ class SignMessage extends AbstractMethod_1.AbstractMethod {
38
38
  const coinInfo = (0, coinInfo_1.getBitcoinNetwork)(this.payload.coin ?? this.params.address_n);
39
39
  return (0, pathUtils_1.getLabel)('Sign #NETWORK message', coinInfo);
40
40
  }
41
+ getButtonRequestData(code, name) {
42
+ if (code === 'ButtonRequest_Other' && name === 'sign_message') {
43
+ return {
44
+ type: 'message',
45
+ serializedPath: (0, pathUtils_1.getSerializedPath)(this.params.address_n.slice(0, 4)),
46
+ coin: this.coinInfo?.shortcut ?? 'BTC',
47
+ message: this.payload.message,
48
+ };
49
+ }
50
+ }
41
51
  async run() {
42
52
  const cmd = this.device.getCommands();
43
53
  const { message } = await cmd.typedCall('SignMessage', 'MessageSignature', this.params);