@trezor/connect 9.0.2 → 9.0.4

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 (84) hide show
  1. package/README.md +5 -5
  2. package/lib/api/authorizeCoinJoin.js +6 -2
  3. package/lib/api/bitcoin/TransactionComposer.js +2 -1
  4. package/lib/api/bitcoin/enhanceSignTx.js +1 -1
  5. package/lib/api/bitcoin/inputs.js +3 -2
  6. package/lib/api/bitcoin/outputs.js +2 -4
  7. package/lib/api/bitcoin/refTx.js +3 -3
  8. package/lib/api/bitcoin/signtxVerify.d.ts +3 -3
  9. package/lib/api/bitcoin/signtxVerify.js +16 -15
  10. package/lib/api/blockchainDisconnect.js +1 -1
  11. package/lib/api/blockchainSetCustomBackend.js +1 -1
  12. package/lib/api/cardano/cardanoAuxiliaryData.d.ts +1 -1
  13. package/lib/api/cardano/cardanoAuxiliaryData.js +38 -16
  14. package/lib/api/cardanoSignTransaction.d.ts +1 -0
  15. package/lib/api/cardanoSignTransaction.js +23 -3
  16. package/lib/api/getAddress.d.ts +2 -1
  17. package/lib/api/getAddress.js +12 -1
  18. package/lib/api/getOwnershipProof.d.ts +1 -5
  19. package/lib/api/getOwnershipProof.js +5 -3
  20. package/lib/api/getPublicKey.d.ts +1 -0
  21. package/lib/api/getPublicKey.js +22 -7
  22. package/lib/api/index.d.ts +2 -0
  23. package/lib/api/index.js +5 -1
  24. package/lib/api/setBusy.d.ts +7 -0
  25. package/lib/api/setBusy.js +27 -0
  26. package/lib/api/signTransaction.d.ts +2 -1
  27. package/lib/api/signTransaction.js +24 -5
  28. package/lib/api/unlockPath.d.ts +10 -0
  29. package/lib/api/unlockPath.js +35 -0
  30. package/lib/backend/BackendManager.d.ts +21 -0
  31. package/lib/backend/BackendManager.js +91 -0
  32. package/lib/backend/Blockchain.d.ts +72 -0
  33. package/lib/backend/Blockchain.js +204 -0
  34. package/lib/backend/BlockchainLink.d.ts +6 -71
  35. package/lib/backend/BlockchainLink.js +12 -288
  36. package/lib/constants/cardano.d.ts +3 -1
  37. package/lib/constants/cardano.js +3 -1
  38. package/lib/core/AbstractMethod.d.ts +1 -0
  39. package/lib/core/index.d.ts +1 -1
  40. package/lib/core/index.js +1 -1
  41. package/lib/core/method.d.ts +1 -1
  42. package/lib/data/config.js +2 -2
  43. package/lib/data/version.d.ts +1 -1
  44. package/lib/data/version.js +1 -1
  45. package/lib/device/Device.d.ts +1 -1
  46. package/lib/device/Device.js +8 -2
  47. package/lib/device/DeviceCommands.d.ts +8 -2
  48. package/lib/device/DeviceCommands.js +48 -25
  49. package/lib/factory.js +2 -0
  50. package/lib/types/api/authorizeCoinJoin.d.ts +1 -0
  51. package/lib/types/api/bitcoin/index.d.ts +5 -0
  52. package/lib/types/api/cardano/index.d.ts +13 -10
  53. package/lib/types/api/eos/index.d.ts +0 -4
  54. package/lib/types/api/eosGetPublicKey.d.ts +4 -4
  55. package/lib/types/api/getAddress.d.ts +1 -0
  56. package/lib/types/api/getPublicKey.d.ts +5 -0
  57. package/lib/types/api/index.d.ts +4 -0
  58. package/lib/types/api/setBusy.d.ts +4 -0
  59. package/lib/types/api/setBusy.js +3 -0
  60. package/lib/types/api/unlockPath.d.ts +8 -0
  61. package/lib/types/api/unlockPath.js +3 -0
  62. package/lib/utils/pathUtils.d.ts +2 -3
  63. package/lib/utils/pathUtils.js +42 -15
  64. package/package.json +19 -7
  65. package/lib/api/bitcoin/__fixtures__/inputs.d.ts +0 -112
  66. package/lib/api/bitcoin/__fixtures__/inputs.js +0 -102
  67. package/lib/api/bitcoin/__fixtures__/signtxVerify.d.ts +0 -147
  68. package/lib/api/bitcoin/__fixtures__/signtxVerify.js +0 -216
  69. package/lib/api/common/__fixtures__/paramsValidator.d.ts +0 -596
  70. package/lib/api/common/__fixtures__/paramsValidator.js +0 -355
  71. package/lib/api/ethereum/__fixtures__/ethereumSignTypedData.d.ts +0 -225
  72. package/lib/api/ethereum/__fixtures__/ethereumSignTypedData.js +0 -341
  73. package/lib/utils/__fixtures__/accountUtils.d.ts +0 -4
  74. package/lib/utils/__fixtures__/accountUtils.js +0 -32
  75. package/lib/utils/__fixtures__/addressUtils.d.ts +0 -10
  76. package/lib/utils/__fixtures__/addressUtils.js +0 -214
  77. package/lib/utils/__fixtures__/ethereumUtils.d.ts +0 -3
  78. package/lib/utils/__fixtures__/ethereumUtils.js +0 -20
  79. package/lib/utils/__fixtures__/formatUtils.d.ts +0 -3
  80. package/lib/utils/__fixtures__/formatUtils.js +0 -15
  81. package/lib/utils/__fixtures__/hdnodeUtils.d.ts +0 -186
  82. package/lib/utils/__fixtures__/hdnodeUtils.js +0 -206
  83. package/lib/utils/bufferUtils.d.ts +0 -3
  84. package/lib/utils/bufferUtils.js +0 -11
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @trezor/connect
2
2
 
3
- API version 9.0.2
3
+ API version 9.0.4
4
4
 
5
5
  [![Build Status](https://github.com/trezor/trezor-suite/actions/workflows/connect-test.yml/badge.svg)](https://github.com/trezor/trezor-suite/actions/workflows/connect-test.yml)
6
6
  [![NPM](https://img.shields.io/npm/v/@trezor/connect.svg)](https://www.npmjs.org/package/@trezor/connect)
@@ -8,7 +8,7 @@ API version 9.0.2
8
8
 
9
9
  Trezor Connect is a platform for easy integration of Trezor into 3rd party services, as well as into Trezor Suite. It provides an API with functionality to access public keys, sign transactions and authenticate users.
10
10
 
11
- This package is intended to be used in node.js environment. If you wan't to build a web application please refer to [@trezor/connect-web package](../connect-web/README.md).
11
+ This package is intended to be used in node.js environment. If you wan't to build a web application please refer to [@trezor/connect-web package](https://github.com/trezor/trezor-suite/blob/develop/packages/connect-web/README.md).
12
12
 
13
13
  ## Installation
14
14
 
@@ -32,7 +32,7 @@ ES6
32
32
  import TrezorConnect from '@trezor/connect';
33
33
  ```
34
34
 
35
- For more instructions [refer to this document](../../docs/packages/connect/index.md)
35
+ For more instructions [refer to this document](https://github.com/trezor/trezor-suite/blob/develop/docs/packages/connect/index.md)
36
36
 
37
37
  ## Version 9 (stable)
38
38
 
@@ -61,11 +61,11 @@ For deployment process of trezor-connect v8 refer to [trezor/connect repository]
61
61
 
62
62
  Interactive API explorer is available on https://connect.trezor.io/9/#/
63
63
 
64
- Documentation is available [docs/packages/connect](../../docs/packages/connect/index.md)
64
+ Documentation is available [docs/packages/connect](https://github.com/trezor/trezor-suite/blob/develop/docs/packages/connect/index.md)
65
65
 
66
66
  ## Examples
67
67
 
68
- A collection of examples on how to implement @trezor/connect in various environments is available in [packages/connect-examples](../connect-examples/README.md)
68
+ A collection of examples on how to implement @trezor/connect in various environments is available in [packages/connect-examples](https://github.com/trezor/trezor-suite/tree/develop/packages/connect-examples)
69
69
 
70
70
  ## Tests
71
71
 
@@ -16,11 +16,13 @@ class AuthorizeCoinJoin extends AbstractMethod_1.AbstractMethod {
16
16
  { name: 'coin', type: 'string' },
17
17
  { name: 'scriptType', type: 'string' },
18
18
  { name: 'amountUnit', type: 'uint' },
19
+ { name: 'preauthorized', type: 'boolean' },
19
20
  ]);
20
21
  const address_n = (0, pathUtils_1.validatePath)(payload.path, 3);
21
22
  const script_type = payload.scriptType || (0, pathUtils_1.getScriptType)(address_n);
22
23
  const coinInfo = (0, coinInfo_1.getBitcoinNetwork)(payload.coin || address_n);
23
24
  this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, coinInfo, this.firmwareRange);
25
+ this.preauthorized = payload.preauthorized;
24
26
  this.params = {
25
27
  coordinator: payload.coordinator,
26
28
  max_rounds: payload.maxRounds,
@@ -34,8 +36,10 @@ class AuthorizeCoinJoin extends AbstractMethod_1.AbstractMethod {
34
36
  }
35
37
  async run() {
36
38
  const cmd = this.device.getCommands();
37
- if (!this.device.features.experimental_features) {
38
- await cmd.typedCall('ApplySettings', 'Success', { experimental_features: true });
39
+ if (this.preauthorized) {
40
+ if (await cmd.preauthorize(false)) {
41
+ return { message: 'Success' };
42
+ }
39
43
  }
40
44
  const response = await cmd.typedCall('AuthorizeCoinJoin', 'Success', this.params);
41
45
  return response.message;
@@ -28,11 +28,12 @@ class TransactionComposer {
28
28
  if (!u.required && new bignumber_js_1.default(u.amount).lte(this.coinInfo.dustLimit))
29
29
  return [];
30
30
  const addressPath = (0, pathUtils_1.getHDPath)(u.path);
31
+ const [chain, index] = addressPath.slice(addressPath.length - 2);
31
32
  return {
32
33
  index: u.vout,
33
34
  transactionHash: u.txid,
34
35
  value: u.amount,
35
- addressPath: [addressPath[3], addressPath[4]],
36
+ addressPath: [chain, index],
36
37
  height: u.blockHeight,
37
38
  tsize: 0,
38
39
  vsize: 0,
@@ -15,7 +15,7 @@ const enhanceSignTx = (options, coinInfo) => {
15
15
  options.version_group_id = 0x26a7270a;
16
16
  }
17
17
  if (typeof options.branch_id !== 'number') {
18
- const backend = (0, BlockchainLink_1.findBackend)(coinInfo.name);
18
+ const backend = (0, BlockchainLink_1.findBackend)(coinInfo.shortcut);
19
19
  if (backend && ((_a = backend.serverInfo) === null || _a === void 0 ? void 0 : _a.consensusBranchId)) {
20
20
  options.branch_id = backend.serverInfo.consensusBranchId;
21
21
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.inputToTrezor = exports.enhanceTrezorInputs = exports.validateTrezorInputs = void 0;
4
- const bufferUtils_1 = require("../../utils/bufferUtils");
4
+ const utils_1 = require("@trezor/utils");
5
5
  const pathUtils_1 = require("../../utils/pathUtils");
6
6
  const hdnodeUtils_1 = require("../../utils/hdnodeUtils");
7
7
  const paramsValidator_1 = require("../common/paramsValidator");
@@ -17,6 +17,7 @@ const validateTrezorInputs = (inputs, coinInfo) => inputs
17
17
  { name: 'script_type', type: 'string' },
18
18
  { name: 'sequence', type: 'number' },
19
19
  { name: 'multisig', type: 'object' },
20
+ { name: 'coinjoin_flags', type: 'number' },
20
21
  ]);
21
22
  if (input.script_type === 'EXTERNAL') {
22
23
  (0, paramsValidator_1.validateParams)(input, [
@@ -50,7 +51,7 @@ const inputToTrezor = (input, sequence) => {
50
51
  return {
51
52
  address_n,
52
53
  prev_index: input.index,
53
- prev_hash: (0, bufferUtils_1.reverseBuffer)(input.hash).toString('hex'),
54
+ prev_hash: utils_1.bufferUtils.reverseBuffer(input.hash).toString('hex'),
54
55
  script_type: (0, pathUtils_1.getScriptType)(address_n),
55
56
  amount: input.amount,
56
57
  sequence,
@@ -22,10 +22,8 @@ const validateTrezorOutputs = (outputs, coinInfo) => {
22
22
  Object.prototype.hasOwnProperty.call(output, 'address')) {
23
23
  throw constants_1.ERRORS.TypedError('Method_InvalidParameter', 'Cannot use address and address_n in one output');
24
24
  }
25
- if (output.address_n) {
26
- const scriptType = (0, pathUtils_1.getOutputScriptType)(output.address_n);
27
- if (output.script_type !== scriptType)
28
- throw constants_1.ERRORS.TypedError('Method_InvalidParameter', `Output change script_type should be set to ${scriptType}`);
25
+ if (output.address_n && !output.script_type) {
26
+ output.script_type = (0, pathUtils_1.getOutputScriptType)(output.address_n);
29
27
  }
30
28
  if ('address' in output &&
31
29
  typeof output.address === 'string' &&
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateReferencedTransactions = exports.transformReferencedTransactions = exports.transformOrigTransactions = exports.getOrigTransactions = exports.getReferencedTransactions = exports.requireReferencedTransactions = void 0;
4
4
  const utxo_lib_1 = require("@trezor/utxo-lib");
5
- const bufferUtils_1 = require("../../utils/bufferUtils");
5
+ const utils_1 = require("@trezor/utils");
6
6
  const pathUtils_1 = require("../../utils/pathUtils");
7
7
  const paramsValidator_1 = require("../common/paramsValidator");
8
8
  const errors_1 = require("../../constants/errors");
@@ -72,7 +72,7 @@ const transformOrigTransactions = (txs, coinInfo, addresses) => txs.flatMap(raw
72
72
  const address_n = (0, pathUtils_1.getHDPath)((inputAddress === null || inputAddress === void 0 ? void 0 : inputAddress.path) || '');
73
73
  return {
74
74
  address_n,
75
- prev_hash: (0, bufferUtils_1.reverseBuffer)(input.hash).toString('hex'),
75
+ prev_hash: utils_1.bufferUtils.reverseBuffer(input.hash).toString('hex'),
76
76
  prev_index: input.index,
77
77
  script_sig: input.script.toString('hex'),
78
78
  sequence: input.sequence,
@@ -139,7 +139,7 @@ const transformReferencedTransactions = (txs, coinInfo) => txs.flatMap(raw => {
139
139
  const inputsMap = (input) => ({
140
140
  prev_index: input.index,
141
141
  sequence: input.sequence,
142
- prev_hash: (0, bufferUtils_1.reverseBuffer)(input.hash).toString('hex'),
142
+ prev_hash: utils_1.bufferUtils.reverseBuffer(input.hash).toString('hex'),
143
143
  script_sig: input.script.toString('hex'),
144
144
  });
145
145
  const binOutputsMap = (output) => ({
@@ -1,8 +1,8 @@
1
1
  import { PROTO } from '../../constants';
2
2
  import type { BitcoinNetworkInfo } from '../../types';
3
- import type { HDNodeResponse } from '../../types/api/getPublicKey';
4
- declare type GetHDNode = (path: number[], coinInfo?: BitcoinNetworkInfo, validation?: boolean) => Promise<HDNodeResponse>;
5
- export declare const verifyTx: (getHDNode: GetHDNode, inputs: PROTO.TxInputType[], outputs: PROTO.TxOutputType[], serializedTx: string, coinInfo: BitcoinNetworkInfo) => Promise<import("packages/utxo-lib/lib/transaction/base").TransactionBase<undefined> | import("packages/utxo-lib/lib/transaction/base").TransactionBase<import("packages/utxo-lib/lib/transaction/dash").DashSpecific> | import("packages/utxo-lib/lib/transaction/base").TransactionBase<import("packages/utxo-lib/lib/transaction/zcash").ZcashSpecific>>;
3
+ import type { DeviceCommands } from '../../device/DeviceCommands';
4
+ declare type GetHDNode = DeviceCommands['getHDNode'];
5
+ export declare const verifyTx: (getHDNode: GetHDNode, inputs: PROTO.TxInputType[], outputs: PROTO.TxOutputType[], serializedTx: string, coinInfo: BitcoinNetworkInfo, unlockPath?: PROTO.UnlockPath) => Promise<import("packages/utxo-lib/lib/transaction/base").TransactionBase<undefined> | import("packages/utxo-lib/lib/transaction/base").TransactionBase<import("packages/utxo-lib/lib/transaction/dash").DashSpecific> | import("packages/utxo-lib/lib/transaction/base").TransactionBase<import("packages/utxo-lib/lib/transaction/zcash").ZcashSpecific>>;
6
6
  export declare const verifyTicketTx: (getHDNode: GetHDNode, inputs: PROTO.TxInputType[], outputs: PROTO.TxOutputType[], serializedTx: string, coinInfo: BitcoinNetworkInfo) => Promise<void>;
7
7
  export {};
8
8
  //# sourceMappingURL=signtxVerify.d.ts.map
@@ -3,17 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.verifyTicketTx = exports.verifyTx = void 0;
4
4
  const utxo_lib_1 = require("@trezor/utxo-lib");
5
5
  const constants_1 = require("../../constants");
6
- const pathUtils_1 = require("../../utils/pathUtils");
7
- const derivePubKeyHash = async (address_n, getHDNode, coinInfo) => {
6
+ const derivePubKeyHash = async (address_n, getHDNode, coinInfo, unlockPath) => {
8
7
  if (address_n.length === 5) {
9
- const response = await getHDNode(address_n.slice(0, 4), coinInfo);
8
+ const response = await getHDNode({ address_n: address_n.slice(0, 4) }, { coinInfo, unlockPath });
10
9
  const node = utxo_lib_1.bip32.fromBase58(response.xpub, coinInfo.network);
11
10
  return node.derive(address_n[address_n.length - 1]);
12
11
  }
13
- const response = await getHDNode(address_n, coinInfo);
12
+ const response = await getHDNode({ address_n }, { coinInfo, unlockPath });
14
13
  return utxo_lib_1.bip32.fromBase58(response.xpub, coinInfo.network);
15
14
  };
16
- const deriveOutputScript = async (getHDNode, output, coinInfo) => {
15
+ const deriveOutputScript = async (getHDNode, output, coinInfo, unlockPath) => {
17
16
  if ('multisig' in output)
18
17
  return;
19
18
  if ('op_return_data' in output) {
@@ -26,32 +25,34 @@ const deriveOutputScript = async (getHDNode, output, coinInfo) => {
26
25
  if (!output.address_n) {
27
26
  throw constants_1.ERRORS.TypedError('Runtime', 'deriveOutputScript: Neither address or address_n is set');
28
27
  }
29
- const scriptType = (0, pathUtils_1.getOutputScriptType)(output.address_n);
30
- const node = await derivePubKeyHash(output.address_n, getHDNode, coinInfo);
28
+ const node = await derivePubKeyHash(output.address_n, getHDNode, coinInfo, unlockPath);
31
29
  const payment = { hash: node.identifier, network: coinInfo.network };
32
- if (scriptType === 'PAYTOADDRESS') {
30
+ if (output.script_type === 'PAYTOADDRESS') {
33
31
  return utxo_lib_1.payments.p2pkh(payment).output;
34
32
  }
35
- if (scriptType === 'PAYTOSCRIPTHASH') {
33
+ if (output.script_type === 'PAYTOSCRIPTHASH') {
36
34
  return utxo_lib_1.payments.p2sh(payment).output;
37
35
  }
38
- if (scriptType === 'PAYTOP2SHWITNESS') {
36
+ if (output.script_type === 'PAYTOP2SHWITNESS') {
39
37
  return utxo_lib_1.payments.p2sh({
40
38
  redeem: utxo_lib_1.payments.p2wpkh(payment),
41
39
  }).output;
42
40
  }
43
- if (scriptType === 'PAYTOWITNESS') {
41
+ if (output.script_type === 'PAYTOWITNESS') {
44
42
  return utxo_lib_1.payments.p2wpkh(payment).output;
45
43
  }
46
- if (scriptType === 'PAYTOTAPROOT') {
44
+ if (output.script_type === 'PAYTOTAPROOT') {
47
45
  return utxo_lib_1.payments.p2tr({
48
46
  pubkey: node.publicKey,
49
47
  network: coinInfo.network,
50
48
  }).output;
51
49
  }
52
- throw constants_1.ERRORS.TypedError('Runtime', `deriveOutputScript: Unknown script type ${scriptType}`);
50
+ if (output.script_type === 'PAYTOMULTISIG') {
51
+ throw constants_1.ERRORS.TypedError('Runtime', `deriveOutputScript: script_type PAYTOMULTISIG not expected without multisig defined`);
52
+ }
53
+ throw constants_1.ERRORS.TypedError('Runtime', `deriveOutputScript: Unknown script type ${output.script_type}`);
53
54
  };
54
- const verifyTx = async (getHDNode, inputs, outputs, serializedTx, coinInfo) => {
55
+ const verifyTx = async (getHDNode, inputs, outputs, serializedTx, coinInfo, unlockPath) => {
55
56
  const bitcoinTx = utxo_lib_1.Transaction.fromHex(serializedTx, { network: coinInfo.network });
56
57
  if (inputs.length !== bitcoinTx.ins.length) {
57
58
  throw constants_1.ERRORS.TypedError('Runtime', 'verifyTx: Signed transaction inputs invalid length');
@@ -67,7 +68,7 @@ const verifyTx = async (getHDNode, inputs, outputs, serializedTx, coinInfo) => {
67
68
  throw constants_1.ERRORS.TypedError('Runtime', `verifyTx: Wrong output amount at output ${i}. Requested: ${amount}, signed: ${bitcoinTx.outs[i].value}`);
68
69
  }
69
70
  }
70
- const scriptA = await deriveOutputScript(getHDNode, outputs[i], coinInfo);
71
+ const scriptA = await deriveOutputScript(getHDNode, outputs[i], coinInfo, unlockPath);
71
72
  if (scriptA && scriptA.compare(scriptB) !== 0) {
72
73
  throw constants_1.ERRORS.TypedError('Runtime', `verifyTx: Output ${i} scripts differ`);
73
74
  }
@@ -23,7 +23,7 @@ class BlockchainDisconnect extends AbstractMethod_1.AbstractMethod {
23
23
  };
24
24
  }
25
25
  run() {
26
- const backend = (0, BlockchainLink_1.findBackend)(this.params.coinInfo.name);
26
+ const backend = (0, BlockchainLink_1.findBackend)(this.params.coinInfo.shortcut);
27
27
  if (backend) {
28
28
  backend.disconnect();
29
29
  }
@@ -26,7 +26,7 @@ class BlockchainSetCustomBackend extends AbstractMethod_1.AbstractMethod {
26
26
  };
27
27
  }
28
28
  async run() {
29
- const current = (0, BlockchainLink_1.findBackend)(this.params.coinInfo.name);
29
+ const current = (0, BlockchainLink_1.findBackend)(this.params.coinInfo.shortcut);
30
30
  if (current) {
31
31
  current.disconnect();
32
32
  await (0, BlockchainLink_1.initBlockchain)(this.params.coinInfo, this.postMessage);
@@ -1,5 +1,5 @@
1
1
  import type { Device } from '../../device/Device';
2
- import type { PROTO } from '../../constants';
2
+ import { PROTO } from '../../constants';
3
3
  import type { CardanoAuxiliaryData } from '../../types/api/cardano';
4
4
  export declare const transformAuxiliaryData: (auxiliaryData: CardanoAuxiliaryData) => PROTO.CardanoTxAuxiliaryData;
5
5
  export declare const modifyAuxiliaryDataForBackwardsCompatibility: (device: Device, auxiliary_data: PROTO.CardanoTxAuxiliaryData) => PROTO.CardanoTxAuxiliaryData;
@@ -4,18 +4,40 @@ exports.modifyAuxiliaryDataForBackwardsCompatibility = exports.transformAuxiliar
4
4
  const cardanoAddressParameters_1 = require("./cardanoAddressParameters");
5
5
  const paramsValidator_1 = require("../common/paramsValidator");
6
6
  const pathUtils_1 = require("../../utils/pathUtils");
7
- const transformCatalystRegistrationParameters = (catalystRegistrationParameters) => {
8
- (0, paramsValidator_1.validateParams)(catalystRegistrationParameters, [
7
+ const constants_1 = require("../../constants");
8
+ const MAX_DELEGATION_COUNT = 32;
9
+ const transformDelegation = (delegation) => {
10
+ (0, paramsValidator_1.validateParams)(delegation, [
9
11
  { name: 'votingPublicKey', type: 'string', required: true },
12
+ { name: 'weight', type: 'uint', required: true },
13
+ ]);
14
+ return {
15
+ voting_public_key: delegation.votingPublicKey,
16
+ weight: delegation.weight,
17
+ };
18
+ };
19
+ const transformGovernanceRegistrationParameters = (governanceRegistrationParameters) => {
20
+ (0, paramsValidator_1.validateParams)(governanceRegistrationParameters, [
21
+ { name: 'votingPublicKey', type: 'string' },
10
22
  { name: 'stakingPath', required: true },
11
23
  { name: 'nonce', type: 'uint', required: true },
24
+ { name: 'format', type: 'number' },
25
+ { name: 'delegations', type: 'array', allowEmpty: true },
26
+ { name: 'votingPurpose', type: 'uint' },
12
27
  ]);
13
- (0, cardanoAddressParameters_1.validateAddressParameters)(catalystRegistrationParameters.rewardAddressParameters);
28
+ (0, cardanoAddressParameters_1.validateAddressParameters)(governanceRegistrationParameters.rewardAddressParameters);
29
+ const { delegations } = governanceRegistrationParameters;
30
+ if (delegations && delegations.length > MAX_DELEGATION_COUNT) {
31
+ throw constants_1.ERRORS.TypedError('Method_InvalidParameter', `At most ${MAX_DELEGATION_COUNT} delegations are allowed in a governance registration`);
32
+ }
14
33
  return {
15
- voting_public_key: catalystRegistrationParameters.votingPublicKey,
16
- staking_path: (0, pathUtils_1.validatePath)(catalystRegistrationParameters.stakingPath, 3),
17
- reward_address_parameters: (0, cardanoAddressParameters_1.addressParametersToProto)(catalystRegistrationParameters.rewardAddressParameters),
18
- nonce: catalystRegistrationParameters.nonce,
34
+ voting_public_key: governanceRegistrationParameters.votingPublicKey,
35
+ staking_path: (0, pathUtils_1.validatePath)(governanceRegistrationParameters.stakingPath, 3),
36
+ reward_address_parameters: (0, cardanoAddressParameters_1.addressParametersToProto)(governanceRegistrationParameters.rewardAddressParameters),
37
+ nonce: governanceRegistrationParameters.nonce,
38
+ format: governanceRegistrationParameters.format,
39
+ delegations: delegations === null || delegations === void 0 ? void 0 : delegations.map(transformDelegation),
40
+ voting_purpose: governanceRegistrationParameters.votingPurpose,
19
41
  };
20
42
  };
21
43
  const transformAuxiliaryData = (auxiliaryData) => {
@@ -25,24 +47,24 @@ const transformAuxiliaryData = (auxiliaryData) => {
25
47
  type: 'string',
26
48
  },
27
49
  ]);
28
- let catalystRegistrationParameters;
29
- if (auxiliaryData.catalystRegistrationParameters) {
30
- catalystRegistrationParameters = transformCatalystRegistrationParameters(auxiliaryData.catalystRegistrationParameters);
50
+ let governanceRegistrationParameters;
51
+ if (auxiliaryData.governanceRegistrationParameters) {
52
+ governanceRegistrationParameters = transformGovernanceRegistrationParameters(auxiliaryData.governanceRegistrationParameters);
31
53
  }
32
54
  return {
33
55
  hash: auxiliaryData.hash,
34
- catalyst_registration_parameters: catalystRegistrationParameters,
56
+ governance_registration_parameters: governanceRegistrationParameters,
35
57
  };
36
58
  };
37
59
  exports.transformAuxiliaryData = transformAuxiliaryData;
38
60
  const modifyAuxiliaryDataForBackwardsCompatibility = (device, auxiliary_data) => {
39
- const { catalyst_registration_parameters } = auxiliary_data;
40
- if (catalyst_registration_parameters) {
41
- catalyst_registration_parameters.reward_address_parameters =
42
- (0, cardanoAddressParameters_1.modifyAddressParametersForBackwardsCompatibility)(device, catalyst_registration_parameters.reward_address_parameters);
61
+ const { governance_registration_parameters } = auxiliary_data;
62
+ if (governance_registration_parameters) {
63
+ governance_registration_parameters.reward_address_parameters =
64
+ (0, cardanoAddressParameters_1.modifyAddressParametersForBackwardsCompatibility)(device, governance_registration_parameters.reward_address_parameters);
43
65
  return {
44
66
  ...auxiliary_data,
45
- catalyst_registration_parameters,
67
+ governance_registration_parameters,
46
68
  };
47
69
  }
48
70
  return auxiliary_data;
@@ -15,6 +15,7 @@ declare const CardanoSignTransactionFeatures: Readonly<{
15
15
  Plutus: string[];
16
16
  KeyHashStakeCredential: string[];
17
17
  Babbage: string[];
18
+ GovernanceRegistrationCIP36: string[];
18
19
  }>;
19
20
  export declare type CardanoSignTransactionParams = {
20
21
  signingMode: PROTO.CardanoTxSigningMode;
@@ -21,6 +21,7 @@ const CardanoSignTransactionFeatures = Object.freeze({
21
21
  Plutus: ['0', '2.4.4'],
22
22
  KeyHashStakeCredential: ['0', '2.4.4'],
23
23
  Babbage: ['0', '2.5.2'],
24
+ GovernanceRegistrationCIP36: ['0', '2.5.3'],
24
25
  });
25
26
  class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
26
27
  init() {
@@ -34,6 +35,11 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
34
35
  if (payload.auxiliaryData && payload.auxiliaryData.blob) {
35
36
  throw constants_1.ERRORS.TypedError('Method_InvalidParameter', 'Auxiliary data can now only be sent as a hash.');
36
37
  }
38
+ if (payload.auxiliaryData && payload.auxiliaryData.catalystRegistrationParameters) {
39
+ console.warn('Please use governanceRegistrationParameters instead of catalystRegistrationParameters.');
40
+ payload.auxiliaryData.governanceRegistrationParameters =
41
+ payload.auxiliaryData.catalystRegistrationParameters;
42
+ }
37
43
  (0, paramsValidator_1.validateParams)(payload, [
38
44
  { name: 'signingMode', type: 'number', required: true },
39
45
  { name: 'inputs', type: 'array', required: true },
@@ -148,6 +154,7 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
148
154
  }
149
155
  }
150
156
  _ensureFirmwareSupportsParams() {
157
+ var _a;
151
158
  const { params } = this;
152
159
  this._ensureFeatureIsSupported('TransactionStreaming');
153
160
  params.certificatesWithPoolOwnersAndRelays.forEach(({ certificate }) => {
@@ -193,6 +200,18 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
193
200
  params.referenceInputs.length > 0) {
194
201
  this._ensureFeatureIsSupported('Babbage');
195
202
  }
203
+ if (params.requiredSigners.length > 0 &&
204
+ params.signingMode !== constants_1.PROTO.CardanoTxSigningMode.PLUTUS_TRANSACTION) {
205
+ this._ensureFeatureIsSupported('Babbage');
206
+ }
207
+ if ((_a = params.auxiliaryData) === null || _a === void 0 ? void 0 : _a.governance_registration_parameters) {
208
+ const { format, delegations, voting_purpose } = params.auxiliaryData.governance_registration_parameters;
209
+ if (format === constants_1.PROTO.CardanoGovernanceRegistrationFormat.CIP36 ||
210
+ (delegations === null || delegations === void 0 ? void 0 : delegations.length) ||
211
+ voting_purpose != null) {
212
+ this._ensureFeatureIsSupported('GovernanceRegistrationCIP36');
213
+ }
214
+ }
196
215
  }
197
216
  async _sign_tx() {
198
217
  const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
@@ -242,8 +261,8 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
242
261
  }
243
262
  let auxiliaryDataSupplement;
244
263
  if (this.params.auxiliaryData) {
245
- const { catalyst_registration_parameters } = this.params.auxiliaryData;
246
- if (catalyst_registration_parameters) {
264
+ const { governance_registration_parameters } = this.params.auxiliaryData;
265
+ if (governance_registration_parameters) {
247
266
  this.params.auxiliaryData = (0, cardanoAuxiliaryData_1.modifyAuxiliaryDataForBackwardsCompatibility)(this.device, this.params.auxiliaryData);
248
267
  }
249
268
  const { message } = await typedCall('CardanoTxAuxiliaryData', 'CardanoTxAuxiliaryDataSupplement', this.params.auxiliaryData);
@@ -252,7 +271,8 @@ class CardanoSignTransaction extends AbstractMethod_1.AbstractMethod {
252
271
  auxiliaryDataSupplement = {
253
272
  type: auxiliaryDataType,
254
273
  auxiliaryDataHash: message.auxiliary_data_hash,
255
- catalystSignature: message.catalyst_signature,
274
+ governanceSignature: message.governance_signature,
275
+ catalystSignature: message.governance_signature,
256
276
  };
257
277
  }
258
278
  await typedCall('CardanoTxHostAck', 'CardanoTxItemAck');
@@ -4,6 +4,7 @@ import type { BitcoinNetworkInfo } from '../types';
4
4
  declare type Params = PROTO.GetAddress & {
5
5
  address?: string;
6
6
  coinInfo: BitcoinNetworkInfo;
7
+ unlockPath?: PROTO.UnlockPath;
7
8
  };
8
9
  export default class GetAddress extends AbstractMethod<'getAddress', Params[]> {
9
10
  hasBundle?: boolean;
@@ -17,7 +18,7 @@ export default class GetAddress extends AbstractMethod<'getAddress', Params[]> {
17
18
  } | undefined;
18
19
  confirmation(): Promise<boolean>;
19
20
  noBackupConfirmation(): Promise<boolean>;
20
- _call({ address_n, show_display, multisig, script_type, coinInfo }: Params): Promise<{
21
+ _call({ address_n, show_display, multisig, script_type, coinInfo, unlockPath }: Params): Promise<{
21
22
  path: number[];
22
23
  serializedPath: string;
23
24
  address: string;
@@ -29,7 +29,14 @@ class GetAddress extends AbstractMethod_1.AbstractMethod {
29
29
  { name: 'showOnTrezor', type: 'boolean' },
30
30
  { name: 'multisig', type: 'object' },
31
31
  { name: 'scriptType', type: 'string' },
32
+ { name: 'unlockPath', type: 'object' },
32
33
  ]);
34
+ if (batch.unlockPath) {
35
+ (0, paramsValidator_1.validateParams)(batch.unlockPath, [
36
+ { name: 'address_n', required: true, type: 'array' },
37
+ { name: 'mac', required: true, type: 'string' },
38
+ ]);
39
+ }
33
40
  const path = (0, pathUtils_1.validatePath)(batch.path, 1);
34
41
  let coinInfo;
35
42
  if (batch.coin) {
@@ -55,6 +62,7 @@ class GetAddress extends AbstractMethod_1.AbstractMethod {
55
62
  multisig: batch.multisig,
56
63
  script_type: batch.scriptType,
57
64
  coinInfo,
65
+ unlockPath: batch.unlockPath,
58
66
  };
59
67
  });
60
68
  const useEventListener = payload.useEventListener &&
@@ -108,8 +116,11 @@ class GetAddress extends AbstractMethod_1.AbstractMethod {
108
116
  const uiResp = await uiPromise.promise;
109
117
  return uiResp.payload;
110
118
  }
111
- _call({ address_n, show_display, multisig, script_type, coinInfo }) {
119
+ async _call({ address_n, show_display, multisig, script_type, coinInfo, unlockPath }) {
112
120
  const cmd = this.device.getCommands();
121
+ if (unlockPath) {
122
+ await cmd.unlockPath(unlockPath);
123
+ }
113
124
  return cmd.getAddress({
114
125
  address_n,
115
126
  show_display,
@@ -1,14 +1,10 @@
1
1
  import { AbstractMethod } from '../core/AbstractMethod';
2
2
  import { PROTO } from '../constants';
3
- interface Params extends PROTO.GetOwnershipProof {
4
- preauthorized?: boolean;
5
- }
6
- export default class GetOwnershipProof extends AbstractMethod<'getOwnershipProof', Params[]> {
3
+ export default class GetOwnershipProof extends AbstractMethod<'getOwnershipProof', PROTO.GetOwnershipProof[]> {
7
4
  hasBundle?: boolean;
8
5
  confirmed?: boolean;
9
6
  init(): void;
10
7
  confirmation(): Promise<boolean>;
11
8
  run(): Promise<import("../types/api/getOwnershipProof").OwnershipProof | import("../types/api/getOwnershipProof").OwnershipProof[]>;
12
9
  }
13
- export {};
14
10
  //# sourceMappingURL=getOwnershipProof.d.ts.map
@@ -29,6 +29,9 @@ class GetOwnershipProof extends AbstractMethod_1.AbstractMethod {
29
29
  const coinInfo = (0, coinInfo_1.getBitcoinNetwork)(batch.coin || address_n);
30
30
  const script_type = batch.scriptType || (0, pathUtils_1.getScriptType)(address_n);
31
31
  this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, coinInfo, this.firmwareRange);
32
+ if (batch.preauthorized) {
33
+ this.preauthorized = batch.preauthorized;
34
+ }
32
35
  return {
33
36
  address_n,
34
37
  coin_name: coinInfo ? coinInfo.name : undefined,
@@ -37,7 +40,6 @@ class GetOwnershipProof extends AbstractMethod_1.AbstractMethod {
37
40
  user_confirmation: batch.userConfirmation,
38
41
  ownership_ids: batch.ownershipIds,
39
42
  commitment_data: batch.commitmentData,
40
- preauthorized: batch.preauthorized,
41
43
  };
42
44
  });
43
45
  }
@@ -63,8 +65,8 @@ class GetOwnershipProof extends AbstractMethod_1.AbstractMethod {
63
65
  const cmd = this.device.getCommands();
64
66
  for (let i = 0; i < this.params.length; i++) {
65
67
  const batch = this.params[i];
66
- if (batch.preauthorized) {
67
- await cmd.typedCall('DoPreauthorized', 'PreauthorizedRequest', {});
68
+ if (this.preauthorized) {
69
+ await cmd.preauthorize(true);
68
70
  }
69
71
  const { message } = await cmd.typedCall('GetOwnershipProof', 'OwnershipProof', batch);
70
72
  responses.push({
@@ -3,6 +3,7 @@ import type { BitcoinNetworkInfo } from '../types';
3
3
  import type { PROTO } from '../constants';
4
4
  declare type Params = PROTO.GetPublicKey & {
5
5
  coinInfo?: BitcoinNetworkInfo;
6
+ unlockPath?: PROTO.UnlockPath;
6
7
  };
7
8
  export default class GetPublicKey extends AbstractMethod<'getPublicKey', Params[]> {
8
9
  hasBundle?: boolean;
@@ -21,25 +21,40 @@ class GetPublicKey extends AbstractMethod_1.AbstractMethod {
21
21
  { name: 'coin', type: 'string' },
22
22
  { name: 'crossChain', type: 'boolean' },
23
23
  { name: 'showOnTrezor', type: 'boolean' },
24
+ { name: 'scriptType', type: ['string', 'number'] },
25
+ { name: 'ignoreXpubMagic', type: 'boolean' },
26
+ { name: 'ecdsaCurveName', type: 'boolean' },
27
+ { name: 'unlockPath', type: 'object' },
24
28
  ]);
29
+ if (batch.unlockPath) {
30
+ (0, paramsValidator_1.validateParams)(batch.unlockPath, [
31
+ { name: 'address_n', required: true, type: 'array' },
32
+ { name: 'mac', required: true, type: 'string' },
33
+ ]);
34
+ }
25
35
  let coinInfo;
26
36
  if (batch.coin) {
27
37
  coinInfo = (0, coinInfo_1.getBitcoinNetwork)(batch.coin);
28
38
  }
29
- const path = (0, pathUtils_1.validatePath)(batch.path, coinInfo ? 3 : 0);
39
+ const address_n = (0, pathUtils_1.validatePath)(batch.path, coinInfo ? 3 : 0);
30
40
  if (coinInfo && !batch.crossChain) {
31
- (0, paramsValidator_1.validateCoinPath)(path, coinInfo);
41
+ (0, paramsValidator_1.validateCoinPath)(address_n, coinInfo);
32
42
  }
33
43
  else if (!coinInfo) {
34
- coinInfo = (0, coinInfo_1.getBitcoinNetwork)(path);
44
+ coinInfo = (0, coinInfo_1.getBitcoinNetwork)(address_n);
35
45
  }
36
46
  if (coinInfo) {
37
47
  this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, coinInfo, this.firmwareRange);
38
48
  }
39
49
  return {
40
- address_n: path,
50
+ address_n,
51
+ coin_name: coinInfo === null || coinInfo === void 0 ? void 0 : coinInfo.name,
52
+ show_display: batch.showOnTrezor,
53
+ script_type: batch.scriptType,
54
+ ignore_xpub_magic: batch.ignoreXpubMagic,
55
+ ecdsa_curve_name: batch.ecdsaCurveName,
41
56
  coinInfo,
42
- show_display: typeof batch.showOnTrezor === 'boolean' ? batch.showOnTrezor : false,
57
+ unlockPath: batch.unlockPath,
43
58
  };
44
59
  });
45
60
  }
@@ -67,8 +82,8 @@ class GetPublicKey extends AbstractMethod_1.AbstractMethod {
67
82
  const responses = [];
68
83
  const cmd = this.device.getCommands();
69
84
  for (let i = 0; i < this.params.length; i++) {
70
- const batch = this.params[i];
71
- const response = await cmd.getHDNode(batch.address_n, batch.coinInfo, true, batch.show_display);
85
+ const { coinInfo, unlockPath, ...batch } = this.params[i];
86
+ const response = await cmd.getHDNode(batch, { coinInfo, unlockPath });
72
87
  responses.push(response);
73
88
  if (this.hasBundle) {
74
89
  this.postMessage((0, events_1.createUiMessage)(events_1.UI.BUNDLE_PROGRESS, {
@@ -51,6 +51,7 @@ export { default as requestLogin } from './requestLogin';
51
51
  export { default as resetDevice } from './resetDevice';
52
52
  export { default as rippleGetAddress } from './rippleGetAddress';
53
53
  export { default as rippleSignTransaction } from './rippleSignTransaction';
54
+ export { default as setBusy } from './setBusy';
54
55
  export { default as setProxy } from './setProxy';
55
56
  export { default as signMessage } from './signMessage';
56
57
  export { default as signTransaction } from './signTransaction';
@@ -59,6 +60,7 @@ export { default as stellarSignTransaction } from './stellarSignTransaction';
59
60
  export { default as tezosGetAddress } from './tezosGetAddress';
60
61
  export { default as tezosGetPublicKey } from './tezosGetPublicKey';
61
62
  export { default as tezosSignTransaction } from './tezosSignTransaction';
63
+ export { default as unlockPath } from './unlockPath';
62
64
  export { default as verifyMessage } from './verifyMessage';
63
65
  export { default as wipeDevice } from './wipeDevice';
64
66
  export { default as checkFirmwareAuthenticity } from './checkFirmwareAuthenticity';