@trezor/connect 9.0.11 → 9.1.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 (171) hide show
  1. package/CHANGELOG.md +22 -3
  2. package/README.md +20 -3
  3. package/lib/api/backupDevice.d.ts +1 -1
  4. package/lib/api/binanceGetAddress.d.ts +1 -0
  5. package/lib/api/binanceGetAddress.js +4 -4
  6. package/lib/api/binanceGetPublicKey.d.ts +1 -0
  7. package/lib/api/binanceGetPublicKey.js +3 -1
  8. package/lib/api/binanceSignTransaction.d.ts +2 -1
  9. package/lib/api/binanceSignTransaction.js +3 -1
  10. package/lib/api/bitcoin/Fees.d.ts +2 -2
  11. package/lib/api/bitcoin/Fees.js +32 -90
  12. package/lib/api/bitcoin/TransactionComposer.d.ts +1 -2
  13. package/lib/api/bitcoin/TransactionComposer.js +3 -2
  14. package/lib/api/bitcoin/createPendingTx.d.ts +1 -0
  15. package/lib/api/bitcoin/createPendingTx.js +1 -0
  16. package/lib/api/bitcoin/refTx.d.ts +10 -2
  17. package/lib/api/bitcoin/refTx.js +46 -19
  18. package/lib/api/blockchainDisconnect.d.ts +1 -0
  19. package/lib/api/blockchainDisconnect.js +3 -1
  20. package/lib/api/blockchainEstimateFee.js +1 -1
  21. package/lib/api/blockchainSetCustomBackend.d.ts +1 -0
  22. package/lib/api/blockchainSetCustomBackend.js +3 -1
  23. package/lib/api/cancelCoinjoinAuthorization.d.ts +8 -0
  24. package/lib/api/cancelCoinjoinAuthorization.js +27 -0
  25. package/lib/api/cardanoGetAddress.d.ts +1 -0
  26. package/lib/api/cardanoGetAddress.js +4 -4
  27. package/lib/api/cardanoGetNativeScriptHash.d.ts +1 -0
  28. package/lib/api/cardanoGetNativeScriptHash.js +3 -1
  29. package/lib/api/cardanoGetPublicKey.d.ts +2 -0
  30. package/lib/api/cardanoGetPublicKey.js +12 -1
  31. package/lib/api/cardanoSignTransaction.d.ts +1 -0
  32. package/lib/api/cardanoSignTransaction.js +3 -1
  33. package/lib/api/checkFirmwareAuthenticity.js +2 -1
  34. package/lib/api/cipherKeyValue.d.ts +1 -0
  35. package/lib/api/cipherKeyValue.js +5 -2
  36. package/lib/api/composeTransaction.d.ts +3 -0
  37. package/lib/api/composeTransaction.js +9 -7
  38. package/lib/api/eosGetPublicKey.d.ts +1 -0
  39. package/lib/api/eosGetPublicKey.js +3 -1
  40. package/lib/api/eosSignTransaction.d.ts +1 -0
  41. package/lib/api/eosSignTransaction.js +3 -1
  42. package/lib/api/ethereum/ethereumDefinitions.d.ts +28 -6
  43. package/lib/api/ethereum/ethereumDefinitions.js +60 -1
  44. package/lib/api/ethereum/ethereumSignTx.d.ts +1 -1
  45. package/lib/api/ethereumGetAddress.d.ts +2 -0
  46. package/lib/api/ethereumGetAddress.js +28 -26
  47. package/lib/api/ethereumGetPublicKey.d.ts +1 -0
  48. package/lib/api/ethereumGetPublicKey.js +8 -10
  49. package/lib/api/ethereumSignMessage.d.ts +10 -1
  50. package/lib/api/ethereumSignMessage.js +14 -13
  51. package/lib/api/ethereumSignTransaction.d.ts +6 -0
  52. package/lib/api/ethereumSignTransaction.js +18 -5
  53. package/lib/api/ethereumSignTypedData.d.ts +6 -0
  54. package/lib/api/ethereumSignTypedData.js +15 -13
  55. package/lib/api/ethereumVerifyMessage.d.ts +1 -0
  56. package/lib/api/ethereumVerifyMessage.js +3 -1
  57. package/lib/api/getAccountInfo.d.ts +3 -0
  58. package/lib/api/getAccountInfo.js +3 -1
  59. package/lib/api/getAddress.d.ts +1 -0
  60. package/lib/api/getAddress.js +8 -10
  61. package/lib/api/getFeatures.d.ts +1 -1
  62. package/lib/api/getOwnershipId.d.ts +1 -0
  63. package/lib/api/getOwnershipId.js +3 -1
  64. package/lib/api/getOwnershipProof.d.ts +1 -0
  65. package/lib/api/getOwnershipProof.js +3 -1
  66. package/lib/api/getPublicKey.d.ts +2 -0
  67. package/lib/api/getPublicKey.js +12 -1
  68. package/lib/api/index.d.ts +2 -0
  69. package/lib/api/index.js +6 -2
  70. package/lib/api/nemGetAddress.d.ts +1 -0
  71. package/lib/api/nemGetAddress.js +4 -4
  72. package/lib/api/nemSignTransaction.d.ts +1 -0
  73. package/lib/api/nemSignTransaction.js +3 -1
  74. package/lib/api/rebootToBootloader.d.ts +2 -1
  75. package/lib/api/rebootToBootloader.js +4 -2
  76. package/lib/api/requestLogin.d.ts +1 -0
  77. package/lib/api/requestLogin.js +3 -1
  78. package/lib/api/resetDevice.d.ts +1 -0
  79. package/lib/api/resetDevice.js +3 -1
  80. package/lib/api/rippleGetAddress.d.ts +1 -0
  81. package/lib/api/rippleGetAddress.js +4 -4
  82. package/lib/api/rippleSignTransaction.d.ts +1 -0
  83. package/lib/api/rippleSignTransaction.js +3 -1
  84. package/lib/api/showDeviceTutorial.d.ts +8 -0
  85. package/lib/api/showDeviceTutorial.js +23 -0
  86. package/lib/api/signMessage.d.ts +1 -0
  87. package/lib/api/signMessage.js +5 -1
  88. package/lib/api/signTransaction.d.ts +1 -0
  89. package/lib/api/signTransaction.js +16 -4
  90. package/lib/api/stellarGetAddress.d.ts +1 -0
  91. package/lib/api/stellarGetAddress.js +4 -4
  92. package/lib/api/stellarSignTransaction.d.ts +1 -0
  93. package/lib/api/stellarSignTransaction.js +3 -1
  94. package/lib/api/tezosGetAddress.d.ts +1 -0
  95. package/lib/api/tezosGetAddress.js +4 -4
  96. package/lib/api/tezosGetPublicKey.d.ts +1 -0
  97. package/lib/api/tezosGetPublicKey.js +3 -1
  98. package/lib/api/tezosSignTransaction.d.ts +1 -0
  99. package/lib/api/tezosSignTransaction.js +3 -1
  100. package/lib/api/verifyMessage.d.ts +1 -0
  101. package/lib/api/verifyMessage.js +7 -2
  102. package/lib/api/wipeDevice.d.ts +2 -1
  103. package/lib/api/wipeDevice.js +3 -1
  104. package/lib/backend/Blockchain.d.ts +1 -3
  105. package/lib/backend/Blockchain.js +10 -6
  106. package/lib/constants/errors.d.ts +0 -3
  107. package/lib/constants/errors.js +1 -4
  108. package/lib/constants/index.d.ts +1 -1
  109. package/lib/constants/index.js +1 -1
  110. package/lib/core/AbstractMethod.d.ts +3 -1
  111. package/lib/core/AbstractMethod.js +3 -1
  112. package/lib/core/index.d.ts +5 -6
  113. package/lib/core/index.js +53 -51
  114. package/lib/core/method.d.ts +1 -1
  115. package/lib/data/DataManager.js +4 -1
  116. package/lib/data/analyticsInfo.js +1 -1
  117. package/lib/data/coinInfo.d.ts +9 -1
  118. package/lib/data/coinInfo.js +16 -54
  119. package/lib/data/config.js +12 -2
  120. package/lib/data/defaultFeeLevels.d.ts +17 -0
  121. package/lib/data/defaultFeeLevels.js +84 -0
  122. package/lib/data/version.d.ts +1 -1
  123. package/lib/data/version.js +1 -1
  124. package/lib/device/Device.d.ts +10 -12
  125. package/lib/device/Device.js +69 -102
  126. package/lib/device/DeviceCommands.d.ts +4 -3
  127. package/lib/device/DeviceCommands.js +46 -19
  128. package/lib/device/DeviceList.d.ts +15 -25
  129. package/lib/device/DeviceList.js +224 -258
  130. package/lib/events/popup.d.ts +8 -1
  131. package/lib/events/popup.js +1 -0
  132. package/lib/events/transport.d.ts +2 -9
  133. package/lib/events/transport.js +3 -10
  134. package/lib/events/ui-request.d.ts +2 -2
  135. package/lib/factory.js +2 -0
  136. package/lib/index.js +7 -7
  137. package/lib/types/account.d.ts +1 -20
  138. package/lib/types/api/bitcoin/index.d.ts +2 -0
  139. package/lib/types/api/blockchainEstimateFee.d.ts +2 -5
  140. package/lib/types/api/cancelCoinjoinAuthorization.d.ts +8 -0
  141. package/lib/types/api/cancelCoinjoinAuthorization.js +3 -0
  142. package/lib/types/api/index.d.ts +4 -0
  143. package/lib/types/api/showDeviceTutorial.d.ts +4 -0
  144. package/lib/types/api/showDeviceTutorial.js +3 -0
  145. package/lib/types/coinInfo.d.ts +5 -17
  146. package/lib/types/device.d.ts +5 -2
  147. package/lib/types/device.js +8 -0
  148. package/lib/types/fees.d.ts +26 -0
  149. package/lib/types/fees.js +3 -0
  150. package/lib/types/index.d.ts +2 -1
  151. package/lib/types/index.js +1 -0
  152. package/lib/types/settings.d.ts +1 -1
  153. package/lib/utils/assetUtils.js +3 -1
  154. package/lib/utils/debug.js +2 -1
  155. package/lib/utils/deviceFeaturesUtils.d.ts +2 -1
  156. package/lib/utils/deviceFeaturesUtils.js +12 -1
  157. package/lib/utils/urlUtils.d.ts +10 -3
  158. package/lib/utils/urlUtils.js +5 -9
  159. package/lib/workers/workers-browser.d.ts +1 -3
  160. package/lib/workers/workers-browser.js +1 -7
  161. package/lib/workers/workers-react-native.d.ts +1 -3
  162. package/lib/workers/workers-react-native.js +1 -7
  163. package/lib/workers/workers.d.ts +1 -5
  164. package/lib/workers/workers.js +1 -5
  165. package/package.json +17 -12
  166. package/lib/device/DescriptorStream.d.ts +0 -28
  167. package/lib/device/DescriptorStream.js +0 -139
  168. package/lib/utils/objectUtils.d.ts +0 -10
  169. package/lib/utils/objectUtils.js +0 -37
  170. package/lib/workers/RNUsbPlugin.d.ts +0 -31
  171. package/lib/workers/RNUsbPlugin.js +0 -65
package/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ # 9.1.2
2
+
3
+ - feat(connect): analytics method name and method param names (23df6d8)
4
+ - feat(connect): improve calculation of fees and dust limit. (d726aab, 9d1ef05, 60f1e26, 2187c34, d84e3ca)
5
+ - fix(connect): device.firmwareType can't be safely determined in bootloader mode so we set it to undefined (c3d33a0)
6
+ - feat(connect): signTransaction with refTxs passed as AccountTransaction interface (d7ec435)
7
+ - feat(connect): decoding ethereum definitions which allows richer UI in connect-popup (0e9356f)
8
+ - feat(connect-explorer): updated examples ethereum (b025834, e58c416), applySettings (1a28816)
9
+ - feat(connect-explorer): render docs from docs folder on index page (93fddc4)
10
+
11
+ # 9.1.1
12
+
13
+ - feat(connect-popup): added device model_internal in features
14
+ - feat(connect): add cancelCoinjoinAuthorization method
15
+ - feat(connect): added nodeusb transport. TrezorConnect is now capable of communicating with Trezor devices without using TrezorBridge (in node.js environment).
16
+ - feat(connect-popup): when a call to TrezorConnect returns `success: false` popup remains opened and displays error page instead.
17
+ - feat(connect-popup): add no-backup warning to getPublicKey method
18
+ - fix(connect): respect useEmptyPassphrase param in cipherKeyValue method
19
+
1
20
  # 9.0.11
2
21
 
3
22
  - fix(connect-web): fix imports from connect
@@ -15,12 +34,12 @@
15
34
 
16
35
  # 9.0.8
17
36
 
18
- - feat: support multiple intermediary FWs for T1 and devkit binaries
37
+ - feat: support multiple intermediary FWs for T1B1 and devkit binaries
19
38
  - `FirmwareUpdate` now accepts `intermediaryVersion` param instead of `intermediary`
20
- - `getInfo` returns `intermediaryVersion` needed for T1 and removed `latest` param. 'release' always return latest version for T1 so it means abandoning the concept of incremental updates for T1.
39
+ - `getInfo` returns `intermediaryVersion` needed for T1B1 and removed `latest` param. 'release' always return latest version for T1B1 so it means abandoning the concept of incremental updates for T1B1.
21
40
  - feat: signTransaction now returns `signedTransaction` which can be used for visualization purposes before notification about pending transaction from blockchain is received.
22
41
  - feat(blockchain): `blockchainGetCurrentFiatRates` and `blockchainGetFiatRatesForTimestamps` now accept additional `token` parameter
23
- - feat: support coinjoin for T1
42
+ - feat: support coinjoin for T1B1
24
43
  - feat(transport): eth definitions
25
44
  - feat(webextension): Ignore port events if it is not port created by current popup
26
45
  - feat(cardano): allow external reward addresses in governance registrations
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @trezor/connect
2
2
 
3
- API version 9.0.11
3
+ API version 9.1.2
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)
@@ -34,7 +34,7 @@ import TrezorConnect from '@trezor/connect';
34
34
 
35
35
  For more instructions [refer to this document](https://github.com/trezor/trezor-suite/blob/develop/docs/packages/connect/index.md)
36
36
 
37
- ## Version 9 (stable)
37
+ ## Versioning
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
 
@@ -43,6 +43,21 @@ Since version 9 we are adopting a new versioning strategy. With every release, w
43
43
 
44
44
  Version 9 is available as `@trezor/connect` and `@trezor/connect-web` npm packages.
45
45
 
46
+ ### Major version
47
+
48
+ New major version is released when there are breaking changes on API level. Previous major version will be maintained for 12 months and after this period it can be taken down without notice.
49
+
50
+ ### Minor version
51
+
52
+ Minor versions are released when there are:
53
+
54
+ - considerable additions to API
55
+ - changes in npm package
56
+
57
+ ### Patch version
58
+
59
+ Everything else that does not fall under major or minor version.
60
+
46
61
  ## Version 8 (legacy)
47
62
 
48
63
  Legacy version 8 is accessible from url https://connect.trezor.io/8/trezor-connect.js.
@@ -57,6 +72,8 @@ With regards to this repo - All updates should go to current version branch, the
57
72
 
58
73
  For deployment process of trezor-connect v8 refer to [trezor/connect repository](https://github.com/trezor/connect/blob/develop/docs/deployment/index.md)
59
74
 
75
+ Version 8 will go offline by the end of 2023.
76
+
60
77
  ## Docs
61
78
 
62
79
  Interactive API explorer is available on https://connect.trezor.io/9/#/
@@ -69,4 +86,4 @@ A collection of examples on how to implement @trezor/connect in various environm
69
86
 
70
87
  ## Tests
71
88
 
72
- For integration testing against trezord and emulator refer to [this document](https://github.com/trezor/trezor-suite/blob/develop/packages/integration-tests/projects/connect/README.md).
89
+ For integration testing against trezord and emulator refer to [this document](https://github.com/trezor/trezor-suite/blob/develop/packages/connect/e2e/README.md).
@@ -2,6 +2,6 @@ import { AbstractMethod } from '../core/AbstractMethod';
2
2
  export default class BackupDevice extends AbstractMethod<'backupDevice'> {
3
3
  init(): void;
4
4
  confirmation(): Promise<boolean>;
5
- run(): Promise<import("packages/transport/lib/types/messages").Success>;
5
+ run(): Promise<import("packages/protobuf/lib/messages").Success>;
6
6
  }
7
7
  //# sourceMappingURL=backupDevice.d.ts.map
@@ -8,6 +8,7 @@ export default class BinanceGetAddress extends AbstractMethod<'binanceGetAddress
8
8
  progress: number;
9
9
  confirmed?: boolean;
10
10
  init(): void;
11
+ get info(): string;
11
12
  getButtonRequestData(code: string): {
12
13
  type: "address";
13
14
  serializedPath: string;
@@ -41,12 +41,12 @@ class BinanceGetAddress extends AbstractMethod_1.AbstractMethod {
41
41
  this.params[0].show_display;
42
42
  this.confirmed = useEventListener;
43
43
  this.useUi = !useEventListener;
44
+ }
45
+ get info() {
44
46
  if (this.params.length === 1) {
45
- this.info = `Export Binance address for account #${(0, pathUtils_1.fromHardened)(this.params[0].address_n[2]) + 1}`;
46
- }
47
- else {
48
- this.info = 'Export multiple Binance addresses';
47
+ return `Export Binance address for account #${(0, pathUtils_1.fromHardened)(this.params[0].address_n[2]) + 1}`;
49
48
  }
49
+ return 'Export multiple Binance addresses';
50
50
  }
51
51
  getButtonRequestData(code) {
52
52
  if (code === 'ButtonRequest_Address') {
@@ -4,6 +4,7 @@ export default class BinanceGetPublicKey extends AbstractMethod<'binanceGetPubli
4
4
  hasBundle?: boolean;
5
5
  confirmed?: boolean;
6
6
  init(): void;
7
+ get info(): string;
7
8
  confirmation(): Promise<boolean>;
8
9
  run(): Promise<import("..").PublicKey | import("..").PublicKey[]>;
9
10
  }
@@ -9,7 +9,6 @@ class BinanceGetPublicKey extends AbstractMethod_1.AbstractMethod {
9
9
  init() {
10
10
  this.requiredPermissions = ['read'];
11
11
  this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, (0, coinInfo_1.getMiscNetwork)('BNB'), this.firmwareRange);
12
- this.info = 'Export Binance public key';
13
12
  this.hasBundle = !!this.payload.bundle;
14
13
  const payload = !this.payload.bundle
15
14
  ? { ...this.payload, bundle: [this.payload] }
@@ -27,6 +26,9 @@ class BinanceGetPublicKey extends AbstractMethod_1.AbstractMethod {
27
26
  };
28
27
  });
29
28
  }
29
+ get info() {
30
+ return 'Export Binance public key';
31
+ }
30
32
  async confirmation() {
31
33
  if (this.confirmed)
32
34
  return true;
@@ -6,7 +6,8 @@ type Params = {
6
6
  };
7
7
  export default class BinanceSignTransaction extends AbstractMethod<'binanceSignTransaction', Params> {
8
8
  init(): void;
9
- run(): Promise<import("packages/transport/lib/types/messages").BinanceSignedTx>;
9
+ get info(): string;
10
+ run(): Promise<import("packages/protobuf/lib/messages").BinanceSignedTx>;
10
11
  }
11
12
  export {};
12
13
  //# sourceMappingURL=binanceSignTransaction.d.ts.map
@@ -10,7 +10,6 @@ class BinanceSignTransaction extends AbstractMethod_1.AbstractMethod {
10
10
  init() {
11
11
  this.requiredPermissions = ['read', 'write'];
12
12
  this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, (0, coinInfo_1.getMiscNetwork)('BNB'), this.firmwareRange);
13
- this.info = 'Sign Binance transaction';
14
13
  const { payload } = this;
15
14
  (0, paramsValidator_1.validateParams)(payload, [
16
15
  { name: 'path', type: 'string', required: true },
@@ -23,6 +22,9 @@ class BinanceSignTransaction extends AbstractMethod_1.AbstractMethod {
23
22
  transaction,
24
23
  };
25
24
  }
25
+ get info() {
26
+ return 'Sign Binance transaction';
27
+ }
26
28
  run() {
27
29
  return helper.signTx(this.device.getCommands().typedCall.bind(this.device.getCommands()), this.params.path, this.params.transaction);
28
30
  }
@@ -1,10 +1,10 @@
1
1
  import { Blockchain } from '../../backend/BlockchainLink';
2
- import type { CoinInfo } from '../../types';
3
- import type { FeeLevel } from '../../types/account';
2
+ import type { CoinInfo, FeeLevel } from '../../types';
4
3
  type Blocks = Array<string | undefined>;
5
4
  export declare class FeeLevels {
6
5
  coinInfo: CoinInfo;
7
6
  levels: FeeLevel[];
7
+ longTermFeeRate?: string;
8
8
  blocks: Blocks;
9
9
  constructor(coinInfo: CoinInfo);
10
10
  loadMisc(blockchain: Blockchain): Promise<FeeLevel[]>;
@@ -3,38 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FeeLevels = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const bignumber_js_1 = tslib_1.__importDefault(require("bignumber.js"));
6
- const BLOCKS = {
7
- btc: {
8
- high: 1,
9
- normal: 6,
10
- economy: 36,
11
- low: 144,
12
- },
13
- bch: {
14
- high: 1,
15
- normal: 5,
16
- economy: 10,
17
- low: 10,
18
- },
19
- btg: {
20
- high: 1,
21
- normal: 5,
22
- economy: 10,
23
- low: 10,
24
- },
25
- dgb: {
26
- high: 1,
27
- normal: 15,
28
- economy: 30,
29
- low: 60,
30
- },
31
- };
32
- const getDefaultBlocks = (shortcut, label) => BLOCKS[shortcut] && BLOCKS[shortcut][label] ? BLOCKS[shortcut][label] : -1;
33
- const feePerKB = (fee) => {
34
- const bn = new bignumber_js_1.default(fee);
35
- if (bn.isNaN() || bn.lte('0'))
6
+ const convertFeeRate = (fee, minFee) => {
7
+ const feePerKB = new bignumber_js_1.default(fee);
8
+ if (feePerKB.isNaN() || feePerKB.lte('0'))
36
9
  return;
37
- return bn.div(1000).integerValue(bignumber_js_1.default.ROUND_HALF_CEIL).toString();
10
+ const feePerB = feePerKB.div(1000);
11
+ if (feePerB.lt(minFee))
12
+ return minFee.toString();
13
+ return feePerB.isInteger() ? feePerB.toString() : feePerB.toFixed(2);
38
14
  };
39
15
  const fillGap = (from, step, size) => {
40
16
  const fill = [];
@@ -43,36 +19,27 @@ const fillGap = (from, step, size) => {
43
19
  }
44
20
  return fill;
45
21
  };
46
- const findLowest = (blocks) => {
47
- const unique = [];
48
- blocks.forEach(item => {
49
- if (typeof item === 'string' && unique.indexOf(item) < 0) {
50
- unique.push(item);
51
- }
52
- });
53
- return unique[unique.length - 1];
54
- };
55
22
  const findNearest = (requested, blocks) => {
23
+ if (typeof blocks[requested] === 'string')
24
+ return blocks[requested];
56
25
  const len = blocks.length;
57
- const knownValue = blocks[requested];
58
- if (typeof knownValue === 'string')
59
- return knownValue;
60
- const lastKnownValue = blocks
61
- .slice()
62
- .reverse()
63
- .find(item => typeof item === 'string');
64
- if (!lastKnownValue)
65
- return;
66
- const lastKnownIndex = blocks.indexOf(lastKnownValue);
67
- if (requested >= lastKnownIndex) {
68
- return lastKnownValue;
69
- }
70
26
  let index = requested;
71
27
  while (typeof blocks[index] !== 'string' && index < len) {
72
28
  index++;
73
29
  }
30
+ if (typeof blocks[index] === 'string') {
31
+ return blocks[index];
32
+ }
33
+ index = requested;
34
+ while (typeof blocks[index] !== 'string' && index > 0) {
35
+ index--;
36
+ }
74
37
  return blocks[index];
75
38
  };
39
+ const findLowest = (blocks) => blocks
40
+ .slice(0)
41
+ .reverse()
42
+ .find(item => typeof item === 'string');
76
43
  const findBlocksForFee = (feePerUnit, blocks) => {
77
44
  const bn = new bignumber_js_1.default(feePerUnit);
78
45
  const lower = blocks.find(b => typeof b === 'string' && bn.gte(b));
@@ -84,26 +51,7 @@ class FeeLevels {
84
51
  constructor(coinInfo) {
85
52
  this.blocks = [];
86
53
  this.coinInfo = coinInfo;
87
- const shortcut = coinInfo.shortcut.toLowerCase();
88
- if (coinInfo.type === 'ethereum') {
89
- this.levels = coinInfo.defaultFees.map(level => ({
90
- ...level,
91
- blocks: -1,
92
- }));
93
- return;
94
- }
95
- const keys = Object.keys(coinInfo.defaultFees);
96
- this.levels = keys
97
- .sort((levelA, levelB) => coinInfo.defaultFees[levelB] - coinInfo.defaultFees[levelA])
98
- .map(level => {
99
- const label = level.toLowerCase();
100
- const blocks = getDefaultBlocks(shortcut, label);
101
- return {
102
- label,
103
- feePerUnit: coinInfo.defaultFees[level].toString(),
104
- blocks,
105
- };
106
- });
54
+ this.levels = coinInfo.defaultFees;
107
55
  }
108
56
  async loadMisc(blockchain) {
109
57
  try {
@@ -135,27 +83,21 @@ class FeeLevels {
135
83
  return result.concat(fill);
136
84
  }, []);
137
85
  }
86
+ const oneDayBlocks = 6 * 24;
87
+ blocks.push(...fillGap(oneDayBlocks, oneDayBlocks / 2, oneDayBlocks * 6));
138
88
  try {
139
89
  const response = await blockchain.estimateFee({ blocks });
140
- response.forEach((r, i) => {
141
- this.blocks[blocks[i]] = feePerKB(r.feePerUnit);
90
+ response.forEach(({ feePerUnit }, index) => {
91
+ this.blocks[blocks[index]] = convertFeeRate(feePerUnit, this.coinInfo.minFee);
142
92
  });
143
- if (this.levels.length === 1) {
144
- const lowest = findLowest(this.blocks);
145
- if (typeof lowest === 'string') {
146
- this.levels[0].blocks = this.blocks.indexOf(lowest);
147
- this.levels[0].feePerUnit = lowest;
93
+ this.levels.forEach(level => {
94
+ const updatedValue = findNearest(level.blocks, this.blocks);
95
+ if (typeof updatedValue === 'string') {
96
+ level.blocks = this.blocks.indexOf(updatedValue);
97
+ level.feePerUnit = updatedValue;
148
98
  }
149
- }
150
- else {
151
- this.levels.forEach(l => {
152
- const updatedValue = findNearest(l.blocks, this.blocks);
153
- if (typeof updatedValue === 'string') {
154
- l.blocks = this.blocks.indexOf(updatedValue);
155
- l.feePerUnit = updatedValue;
156
- }
157
- });
158
- }
99
+ });
100
+ this.longTermFeeRate = findLowest(this.blocks);
159
101
  }
160
102
  catch (error) {
161
103
  }
@@ -1,8 +1,7 @@
1
1
  import { ComposeInput, ComposeOutput, ComposeResult } from '@trezor/utxo-lib';
2
2
  import { FeeLevels } from './Fees';
3
3
  import { Blockchain } from '../../backend/BlockchainLink';
4
- import type { BitcoinNetworkInfo } from '../../types';
5
- import type { DiscoveryAccount, SelectFeeLevel } from '../../types/account';
4
+ import type { BitcoinNetworkInfo, DiscoveryAccount, SelectFeeLevel } from '../../types';
6
5
  import type { PrecomposeParams } from '../../types/api/composeTransaction';
7
6
  type Options = {
8
7
  account: DiscoveryAccount;
@@ -25,7 +25,7 @@ class TransactionComposer {
25
25
  .concat(addresses.change)
26
26
  .map(a => a.address);
27
27
  this.utxos = options.utxo.flatMap(u => {
28
- if (!u.required && new bignumber_js_1.default(u.amount).lte(this.coinInfo.dustLimit))
28
+ if (!u.required && new bignumber_js_1.default(u.amount).lt(this.coinInfo.dustLimit))
29
29
  return [];
30
30
  const addressPath = (0, pathUtils_1.getHDPath)(u.path);
31
31
  const [chain, index] = addressPath.slice(addressPath.length - 2);
@@ -99,7 +99,7 @@ class TransactionComposer {
99
99
  name: level.label,
100
100
  fee: tx.fee,
101
101
  feePerByte: level.feePerUnit,
102
- minutes: level.blocks * this.coinInfo.blocktime,
102
+ minutes: level.blocks * this.coinInfo.blockTime,
103
103
  total: tx.totalSpent,
104
104
  });
105
105
  }
@@ -135,6 +135,7 @@ class TransactionComposer {
135
135
  outputs: this.outputs,
136
136
  height: this.blockHeight,
137
137
  feeRate,
138
+ longTermFeeRate: this.feeLevels.longTermFeeRate,
138
139
  skipPermutation: this.skipPermutation,
139
140
  basePath: account.address_n,
140
141
  network: coinInfo.network,
@@ -23,6 +23,7 @@ export declare const createPendingTransaction: (tx: BitcoinJsTransaction, { addr
23
23
  isAddress: boolean;
24
24
  addresses: string[];
25
25
  value: string;
26
+ sequence: number | undefined;
26
27
  }[];
27
28
  vout: {
28
29
  n: number;
@@ -32,6 +32,7 @@ const createPendingTransaction = (tx, { addresses, inputs, outputs, }) => {
32
32
  isAddress: true,
33
33
  addresses: findAddress(ins),
34
34
  value: ins.amount.toString(),
35
+ sequence: ins.sequence,
35
36
  })),
36
37
  vout: outputs.map((out, n) => {
37
38
  let transformedAddresses = [];
@@ -1,11 +1,19 @@
1
+ import { Transaction as BitcoinJsTransaction } from '@trezor/utxo-lib';
1
2
  import type { TypedRawTransaction } from '@trezor/blockchain-link';
2
- import type { CoinInfo, AccountAddresses } from '../../types';
3
+ import type { CoinInfo, AccountAddresses, AccountTransaction } from '../../types';
3
4
  import type { RefTransaction, TransactionOptions } from '../../types/api/bitcoin';
4
5
  import type { PROTO } from '../../constants';
5
6
  export declare const requireReferencedTransactions: (inputs: PROTO.TxInputType[], options?: TransactionOptions, coinInfo?: CoinInfo) => boolean;
6
7
  export declare const getReferencedTransactions: (inputs: PROTO.TxInputType[]) => string[];
7
8
  export declare const getOrigTransactions: (inputs: PROTO.TxInputType[], outputs: PROTO.TxOutputType[]) => string[];
8
9
  export declare const transformOrigTransactions: (txs: TypedRawTransaction[], coinInfo: CoinInfo, addresses?: AccountAddresses) => RefTransaction[];
10
+ export declare const transformReferencedTransaction: (tx: BitcoinJsTransaction) => RefTransaction;
9
11
  export declare const transformReferencedTransactions: (txs: TypedRawTransaction[], coinInfo: CoinInfo) => RefTransaction[];
10
- export declare const validateReferencedTransactions: (txs: RefTransaction[] | typeof undefined, inputs: PROTO.TxInputType[], outputs: PROTO.TxOutputType[]) => RefTransaction[] | undefined;
12
+ export declare const validateReferencedTransactions: ({ transactions, inputs, outputs, addresses, coinInfo, }: {
13
+ transactions?: (RefTransaction | AccountTransaction)[] | undefined;
14
+ inputs: PROTO.TxInputType[];
15
+ outputs: PROTO.TxOutputType[];
16
+ addresses?: AccountAddresses | undefined;
17
+ coinInfo: CoinInfo;
18
+ }) => RefTransaction[] | undefined;
11
19
  //# sourceMappingURL=refTx.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateReferencedTransactions = exports.transformReferencedTransactions = exports.transformOrigTransactions = exports.getOrigTransactions = exports.getReferencedTransactions = exports.requireReferencedTransactions = void 0;
3
+ exports.validateReferencedTransactions = exports.transformReferencedTransactions = exports.transformReferencedTransaction = exports.transformOrigTransactions = exports.getOrigTransactions = exports.getReferencedTransactions = exports.requireReferencedTransactions = void 0;
4
4
  const utxo_lib_1 = require("@trezor/utxo-lib");
5
5
  const utils_1 = require("@trezor/utils");
6
6
  const pathUtils_1 = require("../../utils/pathUtils");
@@ -55,17 +55,14 @@ const enhanceTransaction = (refTx, srcTx) => {
55
55
  }
56
56
  return refTx;
57
57
  };
58
- const transformOrigTransactions = (txs, coinInfo, addresses) => txs.flatMap(raw => {
59
- if (coinInfo.type !== 'bitcoin' || raw.type !== 'blockbook' || !addresses)
60
- return [];
61
- const { hex, vin, vout } = raw.tx;
62
- const tx = utxo_lib_1.Transaction.fromHex(hex, { network: coinInfo.network });
58
+ const transformOrigTransaction = (origTx, tx, addresses) => {
59
+ const { vin, vout, txid } = origTx;
63
60
  const inputAddresses = addresses.used.concat(addresses.change).concat(addresses.unused);
64
61
  const inputsMap = (input, i) => {
65
62
  var _a;
66
63
  const rawInput = vin[i];
67
64
  if (!(rawInput === null || rawInput === void 0 ? void 0 : rawInput.value) || !(rawInput === null || rawInput === void 0 ? void 0 : rawInput.addresses) || rawInput.addresses.length !== 1) {
68
- throw (0, errors_1.TypedError)('Method_InvalidParameter', `transformOrigTransactions: invalid input at ${raw.tx.txid} [${i}]`);
65
+ throw (0, errors_1.TypedError)('Method_InvalidParameter', `transformOrigTransactions: invalid input at ${txid} [${i}]`);
69
66
  }
70
67
  const [address] = rawInput.addresses;
71
68
  const inputAddress = inputAddresses.find(addr => addr.address === address);
@@ -92,7 +89,7 @@ const transformOrigTransactions = (txs, coinInfo, addresses) => txs.flatMap(raw
92
89
  const { data } = utxo_lib_1.payments.embed({ output: output.script });
93
90
  const op_return_data = (_a = data === null || data === void 0 ? void 0 : data.shift()) === null || _a === void 0 ? void 0 : _a.toString('hex');
94
91
  if (typeof op_return_data !== 'string') {
95
- throw (0, errors_1.TypedError)('Method_InvalidParameter', `transformOrigTransactions: invalid op_return_data at ${raw.tx.txid} [${i}]`);
92
+ throw (0, errors_1.TypedError)('Method_InvalidParameter', `transformOrigTransactions: invalid op_return_data at ${txid} [${i}]`);
96
93
  }
97
94
  return {
98
95
  script_type: 'PAYTOOPRETURN',
@@ -101,7 +98,7 @@ const transformOrigTransactions = (txs, coinInfo, addresses) => txs.flatMap(raw
101
98
  };
102
99
  }
103
100
  if (!rawOutput.addresses || rawOutput.addresses.length !== 1) {
104
- throw (0, errors_1.TypedError)('Method_InvalidParameter', `transformOrigTransactions: invalid output at ${raw.tx.txid} [${i}]`);
101
+ throw (0, errors_1.TypedError)('Method_InvalidParameter', `transformOrigTransactions: invalid output at ${txid} [${i}]`);
105
102
  }
106
103
  const [address] = rawOutput.addresses;
107
104
  const changeAddress = addresses.change.find(addr => addr.address === address);
@@ -129,13 +126,16 @@ const transformOrigTransactions = (txs, coinInfo, addresses) => txs.flatMap(raw
129
126
  expiry: tx.expiry,
130
127
  };
131
128
  return enhanceTransaction(refTx, tx);
132
- });
129
+ };
130
+ const isTransactionWithHex = (tx) => tx.type === 'blockbook' && !!tx.tx.hex;
131
+ const transformOrigTransactions = (txs, coinInfo, addresses) => coinInfo.type !== 'bitcoin' || !addresses
132
+ ? []
133
+ : txs.filter(isTransactionWithHex).map(raw => {
134
+ const tx = utxo_lib_1.Transaction.fromHex(raw.tx.hex, { network: coinInfo.network });
135
+ return transformOrigTransaction(raw.tx, tx, addresses);
136
+ });
133
137
  exports.transformOrigTransactions = transformOrigTransactions;
134
- const transformReferencedTransactions = (txs, coinInfo) => txs.flatMap(raw => {
135
- if (coinInfo.type !== 'bitcoin' || raw.type !== 'blockbook')
136
- return [];
137
- const { hex } = raw.tx;
138
- const tx = utxo_lib_1.Transaction.fromHex(hex, { network: coinInfo.network });
138
+ const transformReferencedTransaction = (tx) => {
139
139
  const inputsMap = (input) => ({
140
140
  prev_index: input.index,
141
141
  sequence: input.sequence,
@@ -156,14 +156,41 @@ const transformReferencedTransactions = (txs, coinInfo) => txs.flatMap(raw => {
156
156
  expiry: tx.expiry,
157
157
  };
158
158
  return enhanceTransaction(refTx, tx);
159
- });
159
+ };
160
+ exports.transformReferencedTransaction = transformReferencedTransaction;
161
+ const transformReferencedTransactions = (txs, coinInfo) => coinInfo.type !== 'bitcoin'
162
+ ? []
163
+ : txs.filter(isTransactionWithHex).map(raw => {
164
+ const tx = utxo_lib_1.Transaction.fromHex(raw.tx.hex, { network: coinInfo.network });
165
+ return (0, exports.transformReferencedTransaction)(tx);
166
+ });
160
167
  exports.transformReferencedTransactions = transformReferencedTransactions;
161
- const validateReferencedTransactions = (txs, inputs, outputs) => {
162
- if (!Array.isArray(txs) || txs.length === 0)
168
+ const transformAccountToOrigTransaction = ({ tx, addresses, coinInfo, }) => {
169
+ if (!tx.hex)
170
+ throw (0, errors_1.TypedError)('Method_InvalidParameter', `refTx: hex for ${tx.txid} not provided`);
171
+ if (!addresses)
172
+ throw (0, errors_1.TypedError)('Method_InvalidParameter', `refTx: addresses for ${tx.txid} not provided`);
173
+ const srcTx = utxo_lib_1.Transaction.fromHex(tx.hex, { network: coinInfo.network });
174
+ return transformOrigTransaction({ ...tx.details, txid: tx.txid }, srcTx, addresses);
175
+ };
176
+ const transformAccountToReferencedTransaction = ({ tx, coinInfo, }) => {
177
+ if (!tx.hex)
178
+ throw (0, errors_1.TypedError)('Method_InvalidParameter', `refTx: hex for ${tx.txid} not provided`);
179
+ const srcTx = utxo_lib_1.Transaction.fromHex(tx.hex, { network: coinInfo.network });
180
+ return (0, exports.transformReferencedTransaction)(srcTx);
181
+ };
182
+ const validateReferencedTransactions = ({ transactions, inputs, outputs, addresses, coinInfo, }) => {
183
+ if (!Array.isArray(transactions) || transactions.length === 0)
163
184
  return;
164
185
  const refTxs = (0, exports.requireReferencedTransactions)(inputs) ? (0, exports.getReferencedTransactions)(inputs) : [];
165
186
  const origTxs = (0, exports.getOrigTransactions)(inputs, outputs);
166
- const transformedTxs = txs.map(tx => {
187
+ const transformedTxs = transactions.map(tx => {
188
+ if ('details' in tx) {
189
+ if (origTxs.includes(tx.txid)) {
190
+ return transformAccountToOrigTransaction({ tx, addresses, coinInfo });
191
+ }
192
+ return transformAccountToReferencedTransaction({ tx, coinInfo });
193
+ }
167
194
  (0, paramsValidator_1.validateParams)(tx, [
168
195
  { name: 'hash', type: 'string', required: true },
169
196
  { name: 'inputs', type: 'array', required: true },
@@ -5,6 +5,7 @@ type Params = {
5
5
  };
6
6
  export default class BlockchainDisconnect extends AbstractMethod<'blockchainDisconnect', Params> {
7
7
  init(): void;
8
+ get info(): string;
8
9
  run(): Promise<{
9
10
  disconnected: boolean;
10
11
  }>;
@@ -8,7 +8,6 @@ const coinInfo_1 = require("../data/coinInfo");
8
8
  class BlockchainDisconnect extends AbstractMethod_1.AbstractMethod {
9
9
  init() {
10
10
  this.requiredPermissions = [];
11
- this.info = '';
12
11
  this.useDevice = false;
13
12
  this.useUi = false;
14
13
  const { payload } = this;
@@ -22,6 +21,9 @@ class BlockchainDisconnect extends AbstractMethod_1.AbstractMethod {
22
21
  coinInfo,
23
22
  };
24
23
  }
24
+ get info() {
25
+ return '';
26
+ }
25
27
  run() {
26
28
  const backend = (0, BlockchainLink_1.findBackend)(this.params.coinInfo.shortcut);
27
29
  if (backend) {
@@ -45,7 +45,7 @@ class BlockchainEstimateFee extends AbstractMethod_1.AbstractMethod {
45
45
  async run() {
46
46
  const { coinInfo, request } = this.params;
47
47
  const feeInfo = {
48
- blockTime: coinInfo.blocktime,
48
+ blockTime: coinInfo.blockTime,
49
49
  minFee: coinInfo.minFee,
50
50
  maxFee: coinInfo.maxFee,
51
51
  dustLimit: coinInfo.type === 'bitcoin' ? coinInfo.dustLimit : undefined,
@@ -5,6 +5,7 @@ type Params = {
5
5
  };
6
6
  export default class BlockchainSetCustomBackend extends AbstractMethod<'blockchainSetCustomBackend', Params> {
7
7
  init(): void;
8
+ get info(): string;
8
9
  run(): Promise<boolean>;
9
10
  }
10
11
  export {};
@@ -8,7 +8,6 @@ const coinInfo_1 = require("../data/coinInfo");
8
8
  class BlockchainSetCustomBackend extends AbstractMethod_1.AbstractMethod {
9
9
  init() {
10
10
  this.requiredPermissions = [];
11
- this.info = '';
12
11
  this.useDevice = false;
13
12
  this.useUi = false;
14
13
  const { payload } = this;
@@ -25,6 +24,9 @@ class BlockchainSetCustomBackend extends AbstractMethod_1.AbstractMethod {
25
24
  coinInfo,
26
25
  };
27
26
  }
27
+ get info() {
28
+ return '';
29
+ }
28
30
  async run() {
29
31
  const current = (0, BlockchainLink_1.findBackend)(this.params.coinInfo.shortcut);
30
32
  if (current) {
@@ -0,0 +1,8 @@
1
+ import { AbstractMethod } from '../core/AbstractMethod';
2
+ import { PROTO } from '../constants';
3
+ export default class CancelCoinjoinAuthorization extends AbstractMethod<'cancelCoinjoinAuthorization', PROTO.CancelAuthorization> {
4
+ init(): void;
5
+ get info(): string;
6
+ run(): Promise<PROTO.Success>;
7
+ }
8
+ //# sourceMappingURL=cancelCoinjoinAuthorization.d.ts.map