@trezor/connect 9.0.10 → 9.1.1

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 (61) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +19 -2
  3. package/lib/api/bitcoin/createPendingTx.d.ts +1 -0
  4. package/lib/api/bitcoin/createPendingTx.js +1 -0
  5. package/lib/api/cancelCoinjoinAuthorization.d.ts +7 -0
  6. package/lib/api/cancelCoinjoinAuthorization.js +25 -0
  7. package/lib/api/cardanoGetPublicKey.d.ts +1 -0
  8. package/lib/api/cardanoGetPublicKey.js +9 -0
  9. package/lib/api/cipherKeyValue.js +3 -2
  10. package/lib/api/getAccountInfo.d.ts +2 -0
  11. package/lib/api/getPublicKey.d.ts +1 -0
  12. package/lib/api/getPublicKey.js +9 -0
  13. package/lib/api/index.d.ts +2 -0
  14. package/lib/api/index.js +6 -2
  15. package/lib/api/rebootToBootloader.js +1 -1
  16. package/lib/api/showDeviceTutorial.d.ts +7 -0
  17. package/lib/api/showDeviceTutorial.js +21 -0
  18. package/lib/constants/errors.d.ts +0 -3
  19. package/lib/constants/errors.js +1 -4
  20. package/lib/core/index.d.ts +5 -6
  21. package/lib/core/index.js +44 -50
  22. package/lib/core/method.d.ts +1 -1
  23. package/lib/data/coinInfo.d.ts +0 -1
  24. package/lib/data/coinInfo.js +7 -14
  25. package/lib/data/config.js +7 -1
  26. package/lib/data/version.d.ts +1 -1
  27. package/lib/data/version.js +1 -1
  28. package/lib/device/Device.d.ts +16 -24
  29. package/lib/device/Device.js +71 -107
  30. package/lib/device/DeviceCommands.d.ts +4 -3
  31. package/lib/device/DeviceCommands.js +42 -20
  32. package/lib/device/DeviceList.d.ts +17 -33
  33. package/lib/device/DeviceList.js +230 -264
  34. package/lib/events/transport.d.ts +2 -9
  35. package/lib/events/transport.js +3 -10
  36. package/lib/factory.js +2 -0
  37. package/lib/index.js +7 -7
  38. package/lib/types/api/cancelCoinjoinAuthorization.d.ts +8 -0
  39. package/lib/types/api/cancelCoinjoinAuthorization.js +3 -0
  40. package/lib/types/api/index.d.ts +4 -0
  41. package/lib/types/api/showDeviceTutorial.d.ts +4 -0
  42. package/lib/types/api/showDeviceTutorial.js +3 -0
  43. package/lib/types/device.d.ts +1 -1
  44. package/lib/types/device.js +3 -0
  45. package/lib/types/settings.d.ts +1 -1
  46. package/lib/utils/debug.js +2 -1
  47. package/lib/utils/deviceFeaturesUtils.d.ts +2 -1
  48. package/lib/utils/deviceFeaturesUtils.js +12 -1
  49. package/lib/workers/workers-browser.d.ts +1 -3
  50. package/lib/workers/workers-browser.js +1 -7
  51. package/lib/workers/workers-react-native.d.ts +1 -3
  52. package/lib/workers/workers-react-native.js +1 -7
  53. package/lib/workers/workers.d.ts +1 -5
  54. package/lib/workers/workers.js +1 -5
  55. package/package.json +21 -18
  56. package/lib/device/DescriptorStream.d.ts +0 -28
  57. package/lib/device/DescriptorStream.js +0 -139
  58. package/lib/utils/objectUtils.d.ts +0 -10
  59. package/lib/utils/objectUtils.js +0 -37
  60. package/lib/workers/RNUsbPlugin.d.ts +0 -31
  61. package/lib/workers/RNUsbPlugin.js +0 -65
package/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # 9.1.1
2
+
3
+ - feat(connect-popup): added device model_internal in features
4
+ - feat(connect): add cancelCoinjoinAuthorization method
5
+ - feat(connect): added nodeusb transport. TrezorConnect is now capable of communicating with Trezor devices without using TrezorBridge (in node.js environment).
6
+ - feat(connect-popup): when a call to TrezorConnect returns `success: false` popup remains opened and displays error page instead.
7
+ - feat(connect-popup): add no-backup warning to getPublicKey method
8
+ - fix(connect): respect useEmptyPassphrase param in cipherKeyValue method
9
+
10
+ # 9.0.11
11
+
12
+ - fix(connect-web): fix imports from connect
13
+
1
14
  # 9.0.10
2
15
 
3
16
  - fix(connect-popup): fix connect-popup in firefox
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @trezor/connect
2
2
 
3
- API version 9.0.10
3
+ API version 9.1.1
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/#/
@@ -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 = [];
@@ -0,0 +1,7 @@
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
+ run(): Promise<PROTO.Success>;
6
+ }
7
+ //# sourceMappingURL=cancelCoinjoinAuthorization.d.ts.map
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const AbstractMethod_1 = require("../core/AbstractMethod");
4
+ const paramsValidator_1 = require("./common/paramsValidator");
5
+ class CancelCoinjoinAuthorization extends AbstractMethod_1.AbstractMethod {
6
+ init() {
7
+ const { payload } = this;
8
+ this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, null, this.firmwareRange);
9
+ this.preauthorized =
10
+ typeof payload.preauthorized === 'boolean' ? payload.preauthorized : true;
11
+ this.info = 'Cancel Coinjoin Authorization';
12
+ }
13
+ async run() {
14
+ const cmd = this.device.getCommands();
15
+ if (!this.preauthorized) {
16
+ if (!(await cmd.preauthorize(false))) {
17
+ return { message: 'Not authorized' };
18
+ }
19
+ }
20
+ const response = await cmd.typedCall('CancelAuthorization', 'Success');
21
+ return response.message;
22
+ }
23
+ }
24
+ exports.default = CancelCoinjoinAuthorization;
25
+ //# sourceMappingURL=cancelCoinjoinAuthorization.js.map
@@ -5,6 +5,7 @@ export default class CardanoGetPublicKey extends AbstractMethod<'cardanoGetPubli
5
5
  confirmed?: boolean;
6
6
  init(): void;
7
7
  confirmation(): Promise<boolean>;
8
+ noBackupConfirmation(): Promise<boolean>;
8
9
  run(): Promise<import("..").CardanoPublicKey | import("..").CardanoPublicKey[]>;
9
10
  }
10
11
  //# sourceMappingURL=cardanoGetPublicKey.d.ts.map
@@ -52,6 +52,15 @@ class CardanoGetPublicKey extends AbstractMethod_1.AbstractMethod {
52
52
  this.confirmed = uiResp.payload;
53
53
  return this.confirmed;
54
54
  }
55
+ async noBackupConfirmation() {
56
+ await this.getPopupPromise().promise;
57
+ const uiPromise = this.createUiPromise(events_1.UI.RECEIVE_CONFIRMATION);
58
+ this.postMessage((0, events_1.createUiMessage)(events_1.UI.REQUEST_CONFIRMATION, {
59
+ view: 'get-public-key-no-backup',
60
+ }));
61
+ const uiResp = await uiPromise.promise;
62
+ return uiResp.payload;
63
+ }
55
64
  async run() {
56
65
  const responses = [];
57
66
  const cmd = this.device.getCommands();
@@ -8,12 +8,13 @@ class CipherKeyValue extends AbstractMethod_1.AbstractMethod {
8
8
  init() {
9
9
  this.requiredPermissions = ['read', 'write'];
10
10
  this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, null, this.firmwareRange);
11
- this.info = 'Cypher key value';
12
- this.useEmptyPassphrase = true;
11
+ this.info = 'Cipher key value';
13
12
  this.hasBundle = !!this.payload.bundle;
14
13
  const payload = !this.payload.bundle
15
14
  ? { ...this.payload, bundle: [this.payload] }
16
15
  : this.payload;
16
+ this.useEmptyPassphrase =
17
+ typeof payload.useEmptyPassphrase === 'boolean' ? payload.useEmptyPassphrase : true;
17
18
  (0, paramsValidator_1.validateParams)(payload, [{ name: 'bundle', type: 'array' }]);
18
19
  this.params = payload.bundle.map(batch => {
19
20
  (0, paramsValidator_1.validateParams)(batch, [
@@ -28,6 +28,7 @@ export default class GetAccountInfo extends AbstractMethod<'getAccountInfo', Req
28
28
  unconfirmed: number;
29
29
  transactions?: import("packages/blockchain-link-types/lib/common").Transaction[] | undefined;
30
30
  txids?: string[] | undefined;
31
+ addrTxCount?: number | undefined;
31
32
  };
32
33
  misc?: {
33
34
  nonce?: string | undefined;
@@ -67,6 +68,7 @@ export default class GetAccountInfo extends AbstractMethod<'getAccountInfo', Req
67
68
  unconfirmed: number;
68
69
  transactions?: import("packages/blockchain-link-types/lib/common").Transaction[] | undefined;
69
70
  txids?: string[] | undefined;
71
+ addrTxCount?: number | undefined;
70
72
  };
71
73
  misc?: {
72
74
  nonce?: string | undefined;
@@ -10,6 +10,7 @@ export default class GetPublicKey extends AbstractMethod<'getPublicKey', Params[
10
10
  confirmed?: boolean;
11
11
  init(): void;
12
12
  confirmation(): Promise<boolean>;
13
+ noBackupConfirmation(): Promise<boolean>;
13
14
  run(): Promise<import("../types/api/getPublicKey").HDNodeResponse | import("../types/api/getPublicKey").HDNodeResponse[]>;
14
15
  }
15
16
  export {};
@@ -78,6 +78,15 @@ class GetPublicKey extends AbstractMethod_1.AbstractMethod {
78
78
  this.confirmed = uiResp.payload;
79
79
  return this.confirmed;
80
80
  }
81
+ async noBackupConfirmation() {
82
+ await this.getPopupPromise().promise;
83
+ const uiPromise = this.createUiPromise(events_1.UI.RECEIVE_CONFIRMATION);
84
+ this.postMessage((0, events_1.createUiMessage)(events_1.UI.REQUEST_CONFIRMATION, {
85
+ view: 'get-public-key-no-backup',
86
+ }));
87
+ const uiResp = await uiPromise.promise;
88
+ return uiResp.payload;
89
+ }
81
90
  async run() {
82
91
  const responses = [];
83
92
  const cmd = this.device.getCommands();
@@ -1,6 +1,8 @@
1
1
  export { default as applyFlags } from './applyFlags';
2
2
  export { default as applySettings } from './applySettings';
3
3
  export { default as authorizeCoinjoin } from './authorizeCoinjoin';
4
+ export { default as cancelCoinjoinAuthorization } from './cancelCoinjoinAuthorization';
5
+ export { default as showDeviceTutorial } from './showDeviceTutorial';
4
6
  export { default as backupDevice } from './backupDevice';
5
7
  export { default as binanceGetAddress } from './binanceGetAddress';
6
8
  export { default as binanceGetPublicKey } from './binanceGetPublicKey';
package/lib/api/index.js CHANGED
@@ -3,14 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.requestLogin = exports.recoveryDevice = exports.rebootToBootloader = exports.pushTransaction = exports.nemSignTransaction = exports.nemGetAddress = exports.getSettings = exports.getPublicKey = exports.getOwnershipProof = exports.getOwnershipId = exports.getFirmwareHash = exports.getFeatures = exports.getDeviceState = exports.getCoinInfo = exports.getAddress = exports.getAccountInfo = exports.firmwareUpdate = exports.ethereumVerifyMessage = exports.ethereumSignTypedData = exports.ethereumSignTransaction = exports.ethereumSignMessage = exports.ethereumGetPublicKey = exports.ethereumGetAddress = exports.eosSignTransaction = exports.eosGetPublicKey = exports.composeTransaction = exports.cipherKeyValue = exports.changePin = exports.cardanoSignTransaction = exports.cardanoGetPublicKey = exports.cardanoGetNativeScriptHash = exports.cardanoGetAddress = exports.blockchainUnsubscribeFiatRates = exports.blockchainUnsubscribe = exports.blockchainSubscribeFiatRates = exports.blockchainSubscribe = exports.blockchainSetCustomBackend = exports.blockchainGetTransactions = exports.blockchainGetFiatRatesForTimestamps = exports.blockchainGetCurrentFiatRates = exports.blockchainGetAccountBalanceHistory = exports.blockchainEstimateFee = exports.blockchainDisconnect = exports.binanceSignTransaction = exports.binanceGetPublicKey = exports.binanceGetAddress = exports.backupDevice = exports.authorizeCoinjoin = exports.applySettings = exports.applyFlags = void 0;
7
- exports.checkFirmwareAuthenticity = exports.wipeDevice = exports.verifyMessage = exports.unlockPath = exports.tezosSignTransaction = exports.tezosGetPublicKey = exports.tezosGetAddress = exports.stellarSignTransaction = exports.stellarGetAddress = exports.signTransaction = exports.signMessage = exports.setProxy = exports.setBusy = exports.rippleSignTransaction = exports.rippleGetAddress = exports.resetDevice = void 0;
6
+ exports.rebootToBootloader = exports.pushTransaction = exports.nemSignTransaction = exports.nemGetAddress = exports.getSettings = exports.getPublicKey = exports.getOwnershipProof = exports.getOwnershipId = exports.getFirmwareHash = exports.getFeatures = exports.getDeviceState = exports.getCoinInfo = exports.getAddress = exports.getAccountInfo = exports.firmwareUpdate = exports.ethereumVerifyMessage = exports.ethereumSignTypedData = exports.ethereumSignTransaction = exports.ethereumSignMessage = exports.ethereumGetPublicKey = exports.ethereumGetAddress = exports.eosSignTransaction = exports.eosGetPublicKey = exports.composeTransaction = exports.cipherKeyValue = exports.changePin = exports.cardanoSignTransaction = exports.cardanoGetPublicKey = exports.cardanoGetNativeScriptHash = exports.cardanoGetAddress = exports.blockchainUnsubscribeFiatRates = exports.blockchainUnsubscribe = exports.blockchainSubscribeFiatRates = exports.blockchainSubscribe = exports.blockchainSetCustomBackend = exports.blockchainGetTransactions = exports.blockchainGetFiatRatesForTimestamps = exports.blockchainGetCurrentFiatRates = exports.blockchainGetAccountBalanceHistory = exports.blockchainEstimateFee = exports.blockchainDisconnect = exports.binanceSignTransaction = exports.binanceGetPublicKey = exports.binanceGetAddress = exports.backupDevice = exports.showDeviceTutorial = exports.cancelCoinjoinAuthorization = exports.authorizeCoinjoin = exports.applySettings = exports.applyFlags = void 0;
7
+ exports.checkFirmwareAuthenticity = exports.wipeDevice = exports.verifyMessage = exports.unlockPath = exports.tezosSignTransaction = exports.tezosGetPublicKey = exports.tezosGetAddress = exports.stellarSignTransaction = exports.stellarGetAddress = exports.signTransaction = exports.signMessage = exports.setProxy = exports.setBusy = exports.rippleSignTransaction = exports.rippleGetAddress = exports.resetDevice = exports.requestLogin = exports.recoveryDevice = void 0;
8
8
  var applyFlags_1 = require("./applyFlags");
9
9
  Object.defineProperty(exports, "applyFlags", { enumerable: true, get: function () { return __importDefault(applyFlags_1).default; } });
10
10
  var applySettings_1 = require("./applySettings");
11
11
  Object.defineProperty(exports, "applySettings", { enumerable: true, get: function () { return __importDefault(applySettings_1).default; } });
12
12
  var authorizeCoinjoin_1 = require("./authorizeCoinjoin");
13
13
  Object.defineProperty(exports, "authorizeCoinjoin", { enumerable: true, get: function () { return __importDefault(authorizeCoinjoin_1).default; } });
14
+ var cancelCoinjoinAuthorization_1 = require("./cancelCoinjoinAuthorization");
15
+ Object.defineProperty(exports, "cancelCoinjoinAuthorization", { enumerable: true, get: function () { return __importDefault(cancelCoinjoinAuthorization_1).default; } });
16
+ var showDeviceTutorial_1 = require("./showDeviceTutorial");
17
+ Object.defineProperty(exports, "showDeviceTutorial", { enumerable: true, get: function () { return __importDefault(showDeviceTutorial_1).default; } });
14
18
  var backupDevice_1 = require("./backupDevice");
15
19
  Object.defineProperty(exports, "backupDevice", { enumerable: true, get: function () { return __importDefault(backupDevice_1).default; } });
16
20
  var binanceGetAddress_1 = require("./binanceGetAddress");
@@ -13,7 +13,7 @@ class RebootToBootloader extends AbstractMethod_1.AbstractMethod {
13
13
  this.useDeviceState = false;
14
14
  this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, null, {
15
15
  1: { min: '1.10.0', max: '0' },
16
- 2: { min: '0', max: '0' },
16
+ 2: { min: '2.6.0', max: '0' },
17
17
  });
18
18
  }
19
19
  async confirmation() {
@@ -0,0 +1,7 @@
1
+ import { AbstractMethod } from '../core/AbstractMethod';
2
+ import { PROTO } from '../constants';
3
+ export default class ShowDeviceTutorial extends AbstractMethod<'showDeviceTutorial', PROTO.ShowDeviceTutorial> {
4
+ init(): void;
5
+ run(): Promise<PROTO.Success>;
6
+ }
7
+ //# sourceMappingURL=showDeviceTutorial.d.ts.map
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const AbstractMethod_1 = require("../core/AbstractMethod");
4
+ const paramsValidator_1 = require("./common/paramsValidator");
5
+ const events_1 = require("../events");
6
+ class ShowDeviceTutorial extends AbstractMethod_1.AbstractMethod {
7
+ init() {
8
+ this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(this.name, null, this.firmwareRange);
9
+ this.info = 'Show device tutorial';
10
+ this.useEmptyPassphrase = true;
11
+ this.useDeviceState = false;
12
+ this.allowDeviceMode = [events_1.UI.INITIALIZE];
13
+ }
14
+ async run() {
15
+ const cmd = this.device.getCommands();
16
+ const response = await cmd.typedCall('ShowDeviceTutorial', 'Success');
17
+ return response.message;
18
+ }
19
+ }
20
+ exports.default = ShowDeviceTutorial;
21
+ //# sourceMappingURL=showDeviceTutorial.js.map
@@ -41,8 +41,5 @@ export declare class TrezorError extends Error {
41
41
  }
42
42
  export declare const TypedError: (id: keyof typeof ERROR_CODES, message?: string) => TrezorError;
43
43
  export declare const serializeError: (payload: any) => any;
44
- export declare const WRONG_PREVIOUS_SESSION_ERROR_MESSAGE = "wrong previous session";
45
- export declare const INVALID_PIN_ERROR_MESSAGE = "PIN invalid";
46
- export declare const WEBUSB_ERROR_MESSAGE = "NetworkError: Unable to claim interface.";
47
44
  export declare const LIBUSB_ERROR_MESSAGE = "LIBUSB_ERROR";
48
45
  //# sourceMappingURL=errors.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LIBUSB_ERROR_MESSAGE = exports.WEBUSB_ERROR_MESSAGE = exports.INVALID_PIN_ERROR_MESSAGE = exports.WRONG_PREVIOUS_SESSION_ERROR_MESSAGE = exports.serializeError = exports.TypedError = exports.TrezorError = exports.ERROR_CODES = void 0;
3
+ exports.LIBUSB_ERROR_MESSAGE = exports.serializeError = exports.TypedError = exports.TrezorError = exports.ERROR_CODES = void 0;
4
4
  exports.ERROR_CODES = {
5
5
  Init_NotInitialized: 'TrezorConnect not initialized',
6
6
  Init_AlreadyInitialized: 'TrezorConnect has been already initialized',
@@ -54,8 +54,5 @@ const serializeError = (payload) => {
54
54
  return payload;
55
55
  };
56
56
  exports.serializeError = serializeError;
57
- exports.WRONG_PREVIOUS_SESSION_ERROR_MESSAGE = 'wrong previous session';
58
- exports.INVALID_PIN_ERROR_MESSAGE = 'PIN invalid';
59
- exports.WEBUSB_ERROR_MESSAGE = 'NetworkError: Unable to claim interface.';
60
57
  exports.LIBUSB_ERROR_MESSAGE = 'LIBUSB_ERROR';
61
58
  //# sourceMappingURL=errors.js.map
@@ -2,15 +2,14 @@
2
2
  import EventEmitter from 'events';
3
3
  import { TransportInfo, CoreMessage } from '../events';
4
4
  import type { ConnectSettings } from '../types';
5
- export declare const handleMessage: (message: CoreMessage, isTrustedOrigin?: boolean) => void;
5
+ export declare const handleMessage: (message: CoreMessage) => void;
6
6
  export declare const onCall: (message: CoreMessage) => Promise<void>;
7
7
  export declare class Core extends EventEmitter {
8
- handleMessage(message: any, isTrustedOrigin: boolean): void;
8
+ handleMessage(message: any): void;
9
9
  dispose(): Promise<void>;
10
- getCurrentMethod(): (import("../api").applyFlags | import("../api").applySettings | import("../api").authorizeCoinjoin | import("../api").backupDevice | import("../api").binanceGetAddress | import("../api").binanceGetPublicKey | import("../api").binanceSignTransaction | import("../api").blockchainDisconnect | import("../api").blockchainEstimateFee | import("../api").blockchainGetAccountBalanceHistory | import("../api").blockchainGetCurrentFiatRates | import("../api").blockchainGetFiatRatesForTimestamps | import("../api").blockchainGetTransactions | import("../api").blockchainSetCustomBackend | import("../api").blockchainSubscribe | import("../api").blockchainSubscribeFiatRates | import("../api").blockchainUnsubscribe | import("../api").blockchainUnsubscribeFiatRates | import("../api").cardanoGetAddress | import("../api").cardanoGetNativeScriptHash | import("../api").cardanoGetPublicKey | import("../api").cardanoSignTransaction | import("../api").changePin | import("../api").cipherKeyValue | import("../api").composeTransaction | import("../api").eosGetPublicKey | import("../api").eosSignTransaction | import("../api").ethereumGetAddress | import("../api").ethereumGetPublicKey | import("../api").ethereumSignMessage | import("../api").ethereumSignTransaction | import("../api").ethereumSignTypedData | import("../api").ethereumVerifyMessage | import("../api").firmwareUpdate | import("../api").getAccountInfo | import("../api").getAddress | import("../api").getCoinInfo | import("../api").getDeviceState | import("../api").getFeatures | import("../api").getFirmwareHash | import("../api").getOwnershipId | import("../api").getOwnershipProof | import("../api").getPublicKey | import("../api").getSettings | import("../api").nemGetAddress | import("../api").nemSignTransaction | import("../api").pushTransaction | import("../api").rebootToBootloader | import("../api").recoveryDevice | import("../api").requestLogin | import("../api").resetDevice | import("../api").rippleGetAddress | import("../api").rippleSignTransaction | import("../api").setBusy | import("../api").setProxy | import("../api").signMessage | import("../api").signTransaction | import("../api").stellarGetAddress | import("../api").stellarSignTransaction | import("../api").tezosGetAddress | import("../api").tezosGetPublicKey | import("../api").tezosSignTransaction | import("../api").unlockPath | import("../api").verifyMessage | import("../api").wipeDevice | import("../api").checkFirmwareAuthenticity)[];
11
- getTransportInfo(): TransportInfo;
10
+ getCurrentMethod(): (import("../api").applyFlags | import("../api").applySettings | import("../api").authorizeCoinjoin | import("../api").cancelCoinjoinAuthorization | import("../api").showDeviceTutorial | import("../api").backupDevice | import("../api").binanceGetAddress | import("../api").binanceGetPublicKey | import("../api").binanceSignTransaction | import("../api").blockchainDisconnect | import("../api").blockchainEstimateFee | import("../api").blockchainGetAccountBalanceHistory | import("../api").blockchainGetCurrentFiatRates | import("../api").blockchainGetFiatRatesForTimestamps | import("../api").blockchainGetTransactions | import("../api").blockchainSetCustomBackend | import("../api").blockchainSubscribe | import("../api").blockchainSubscribeFiatRates | import("../api").blockchainUnsubscribe | import("../api").blockchainUnsubscribeFiatRates | import("../api").cardanoGetAddress | import("../api").cardanoGetNativeScriptHash | import("../api").cardanoGetPublicKey | import("../api").cardanoSignTransaction | import("../api").changePin | import("../api").cipherKeyValue | import("../api").composeTransaction | import("../api").eosGetPublicKey | import("../api").eosSignTransaction | import("../api").ethereumGetAddress | import("../api").ethereumGetPublicKey | import("../api").ethereumSignMessage | import("../api").ethereumSignTransaction | import("../api").ethereumSignTypedData | import("../api").ethereumVerifyMessage | import("../api").firmwareUpdate | import("../api").getAccountInfo | import("../api").getAddress | import("../api").getCoinInfo | import("../api").getDeviceState | import("../api").getFeatures | import("../api").getFirmwareHash | import("../api").getOwnershipId | import("../api").getOwnershipProof | import("../api").getPublicKey | import("../api").getSettings | import("../api").nemGetAddress | import("../api").nemSignTransaction | import("../api").pushTransaction | import("../api").rebootToBootloader | import("../api").recoveryDevice | import("../api").requestLogin | import("../api").resetDevice | import("../api").rippleGetAddress | import("../api").rippleSignTransaction | import("../api").setBusy | import("../api").setProxy | import("../api").signMessage | import("../api").signTransaction | import("../api").stellarGetAddress | import("../api").stellarSignTransaction | import("../api").tezosGetAddress | import("../api").tezosGetPublicKey | import("../api").tezosSignTransaction | import("../api").unlockPath | import("../api").verifyMessage | import("../api").wipeDevice | import("../api").checkFirmwareAuthenticity)[];
11
+ getTransportInfo(): TransportInfo | undefined;
12
12
  }
13
- export declare const initCore: () => Core;
14
- export declare const init: (settings: ConnectSettings) => Promise<Core>;
13
+ export declare const initCore: (settings: ConnectSettings) => Promise<Core>;
15
14
  export declare const initTransport: (settings: ConnectSettings) => Promise<void>;
16
15
  //# sourceMappingURL=index.d.ts.map
package/lib/core/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initTransport = exports.init = exports.initCore = exports.Core = exports.onCall = exports.handleMessage = void 0;
3
+ exports.initTransport = exports.initCore = exports.Core = exports.onCall = exports.handleMessage = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const events_1 = tslib_1.__importDefault(require("events"));
6
+ const transport_1 = require("@trezor/transport");
6
7
  const DataManager_1 = require("../data/DataManager");
7
8
  const DeviceList_1 = require("../device/DeviceList");
8
9
  const analyticsInfo_1 = require("../data/analyticsInfo");
@@ -22,6 +23,7 @@ const _callMethods = [];
22
23
  let _preferredDevice;
23
24
  let _interactionTimeout;
24
25
  let _deviceListInitTimeout;
26
+ let _overridePromise;
25
27
  const _log = (0, debug_1.initLog)('Core');
26
28
  const postMessage = (message) => {
27
29
  if (message.event === events_2.RESPONSE_EVENT) {
@@ -54,17 +56,8 @@ const findUiPromise = (promiseEvent) => _uiPromises.find(p => p.id === promiseEv
54
56
  const removeUiPromise = (promise) => {
55
57
  _uiPromises = _uiPromises.filter(p => p !== promise);
56
58
  };
57
- const handleMessage = (message, isTrustedOrigin = false) => {
58
- _log.debug('handleMessage', isTrustedOrigin, message);
59
- const safeMessages = [
60
- events_2.IFRAME.CALL,
61
- events_2.POPUP.CLOSED,
62
- events_2.UI.LOGIN_CHALLENGE_RESPONSE,
63
- events_2.TRANSPORT.DISABLE_WEBUSB,
64
- ];
65
- if (!isTrustedOrigin && safeMessages.indexOf(message.type) === -1) {
66
- return;
67
- }
59
+ const handleMessage = (message) => {
60
+ _log.debug('handleMessage', message);
68
61
  switch (message.type) {
69
62
  case events_2.POPUP.HANDSHAKE:
70
63
  getPopupPromise(false).resolve();
@@ -72,10 +65,10 @@ const handleMessage = (message, isTrustedOrigin = false) => {
72
65
  case events_2.POPUP.CLOSED:
73
66
  onPopupClosed(message.payload ? message.payload.error : null);
74
67
  break;
75
- case events_2.TRANSPORT.DISABLE_WEBUSB:
68
+ case transport_1.TRANSPORT.DISABLE_WEBUSB:
76
69
  disableWebUSBTransport();
77
70
  break;
78
- case events_2.TRANSPORT.REQUEST_DEVICE:
71
+ case transport_1.TRANSPORT.REQUEST_DEVICE:
79
72
  _deviceList === null || _deviceList === void 0 ? void 0 : _deviceList.enumerate();
80
73
  break;
81
74
  case events_2.UI.RECEIVE_DEVICE:
@@ -230,7 +223,8 @@ const onCall = async (message) => {
230
223
  call.overridden = true;
231
224
  });
232
225
  const overrideError = constants_1.ERRORS.TypedError('Method_Override');
233
- await device.override(overrideError);
226
+ _overridePromise = device.override(overrideError);
227
+ await _overridePromise;
234
228
  if (method.overridden) {
235
229
  postMessage((0, events_2.createResponseMessage)(method.responseID, false, { error: overrideError }));
236
230
  throw overrideError;
@@ -337,8 +331,7 @@ const onCall = async (message) => {
337
331
  }
338
332
  }
339
333
  catch (error) {
340
- if (error.message === constants_1.ERRORS.INVALID_PIN_ERROR_MESSAGE &&
341
- PIN_TRIES < MAX_PIN_TRIES) {
334
+ if (error.message === 'PIN invalid' && PIN_TRIES < MAX_PIN_TRIES) {
342
335
  PIN_TRIES++;
343
336
  postMessage((0, events_2.createUiMessage)(events_2.UI.INVALID_PIN, { device: device.toMessageObject() }));
344
337
  return inner();
@@ -360,6 +353,9 @@ const onCall = async (message) => {
360
353
  return Promise.reject(error);
361
354
  }
362
355
  };
356
+ if (_overridePromise) {
357
+ await _overridePromise;
358
+ }
363
359
  await device.run(inner, {
364
360
  keepSession: method.keepSession,
365
361
  useEmptyPassphrase: method.useEmptyPassphrase,
@@ -372,13 +368,16 @@ const onCall = async (message) => {
372
368
  _deviceList.addAuthPenalty(device);
373
369
  }
374
370
  if (method) {
375
- if (_deviceList && error.message === constants_1.ERRORS.WRONG_PREVIOUS_SESSION_ERROR_MESSAGE) {
376
- _deviceList.enumerate();
371
+ if (_deviceList && error.message === transport_1.TRANSPORT_ERROR.SESSION_WRONG_PREVIOUS) {
372
+ await _deviceList.enumerate();
377
373
  }
378
374
  messageResponse = (0, events_2.createResponseMessage)(method.responseID, false, { error });
379
375
  }
380
376
  }
381
377
  finally {
378
+ if (_overridePromise) {
379
+ await _overridePromise;
380
+ }
382
381
  const response = messageResponse;
383
382
  if (response) {
384
383
  if (method.name === 'rebootToBootloader' && response.success) {
@@ -469,7 +468,7 @@ const onPopupClosed = (customErrorMessage) => {
469
468
  _deviceList.allDevices().forEach(d => {
470
469
  d.keepSession = false;
471
470
  if (d.isUsedHere()) {
472
- d.interruptionFromUser(error);
471
+ _overridePromise = d.interruptionFromUser(error);
473
472
  }
474
473
  else {
475
474
  const uiPromise = findUiPromise(events_2.DEVICE.DISCONNECT);
@@ -557,30 +556,31 @@ const initDeviceList = async (settings) => {
557
556
  _deviceList.on(events_2.DEVICE.CHANGED, device => {
558
557
  postMessage((0, events_2.createDeviceMessage)(events_2.DEVICE.CHANGED, device));
559
558
  });
560
- _deviceList.on(events_2.TRANSPORT.ERROR, async (error) => {
559
+ _deviceList.on(transport_1.TRANSPORT.ERROR, error => {
561
560
  _log.warn('TRANSPORT.ERROR', error);
562
561
  if (_deviceList) {
563
562
  _deviceList.disconnectDevices();
564
563
  _deviceList.dispose();
565
564
  }
566
565
  _deviceList = undefined;
567
- postMessage((0, events_2.createTransportMessage)(events_2.TRANSPORT.ERROR, { error }));
566
+ postMessage((0, events_2.createTransportMessage)(transport_1.TRANSPORT.ERROR, { error }));
568
567
  if (settings.transportReconnect) {
569
568
  const { promise, timeout } = (0, promiseUtils_1.resolveAfter)(1000, null);
570
569
  _deviceListInitTimeout = timeout;
571
- await promise;
572
- initDeviceList(settings);
570
+ promise.then(() => {
571
+ initDeviceList(settings);
572
+ });
573
573
  }
574
574
  });
575
- _deviceList.on(events_2.TRANSPORT.START, transportType => postMessage((0, events_2.createTransportMessage)(events_2.TRANSPORT.START, transportType)));
576
- await _deviceList.init();
575
+ _deviceList.on(transport_1.TRANSPORT.START, transportType => postMessage((0, events_2.createTransportMessage)(transport_1.TRANSPORT.START, transportType)));
576
+ _deviceList.init();
577
577
  if (_deviceList) {
578
578
  await _deviceList.waitForTransportFirstEvent();
579
579
  }
580
580
  }
581
581
  catch (error) {
582
582
  _deviceList = undefined;
583
- postMessage((0, events_2.createTransportMessage)(events_2.TRANSPORT.ERROR, { error }));
583
+ postMessage((0, events_2.createTransportMessage)(transport_1.TRANSPORT.ERROR, { error }));
584
584
  if (!settings.transportReconnect) {
585
585
  throw error;
586
586
  }
@@ -593,8 +593,8 @@ const initDeviceList = async (settings) => {
593
593
  }
594
594
  };
595
595
  class Core extends events_1.default {
596
- handleMessage(message, isTrustedOrigin) {
597
- (0, exports.handleMessage)(message, isTrustedOrigin);
596
+ handleMessage(message) {
597
+ (0, exports.handleMessage)(message);
598
598
  }
599
599
  async dispose() {
600
600
  (0, BlockchainLink_1.dispose)();
@@ -610,27 +610,18 @@ class Core extends events_1.default {
610
610
  return _callMethods;
611
611
  }
612
612
  getTransportInfo() {
613
- if (_deviceList) {
614
- return _deviceList.getTransportInfo();
613
+ if (!_deviceList) {
614
+ return undefined;
615
615
  }
616
- return {
617
- type: '',
618
- version: '',
619
- outdated: true,
620
- };
616
+ return _deviceList.getTransportInfo();
621
617
  }
622
618
  }
623
619
  exports.Core = Core;
624
- const initCore = () => {
625
- _core = new Core();
626
- return _core;
627
- };
628
- exports.initCore = initCore;
629
- const init = async (settings) => {
620
+ const initCore = async (settings) => {
630
621
  try {
631
622
  await DataManager_1.DataManager.load(settings);
632
623
  (0, debug_1.enableLog)(DataManager_1.DataManager.getSettings('debug'));
633
- (0, exports.initCore)();
624
+ _core = new Core();
634
625
  _interactionTimeout = new interactionTimeout_1.InteractionTimeout(settings.popup ? settings.interactionTimeout : 0);
635
626
  return _core;
636
627
  }
@@ -639,7 +630,7 @@ const init = async (settings) => {
639
630
  throw error;
640
631
  }
641
632
  };
642
- exports.init = init;
633
+ exports.initCore = initCore;
643
634
  const initTransport = async (settings) => {
644
635
  try {
645
636
  if (!settings.transportReconnect) {
@@ -656,17 +647,20 @@ const initTransport = async (settings) => {
656
647
  };
657
648
  exports.initTransport = initTransport;
658
649
  const disableWebUSBTransport = async () => {
659
- var _a, _b;
650
+ var _a;
660
651
  if (!_deviceList)
661
652
  return;
662
653
  if (_deviceList.transportType() !== 'WebUsbTransport')
663
654
  return;
664
655
  const settings = DataManager_1.DataManager.getSettings();
665
- if ((_a = settings.transports) === null || _a === void 0 ? void 0 : _a.includes('WebUsbTransport')) {
666
- settings.transports.splice(settings.transports.indexOf('WebUsbTransport'), 1);
667
- }
668
- if (!((_b = settings.transports) === null || _b === void 0 ? void 0 : _b.includes('BridgeTransport'))) {
669
- settings.transports.unshift('BridgeTransport');
656
+ if (settings.transports) {
657
+ const transportStr = (_a = settings.transports) === null || _a === void 0 ? void 0 : _a.filter(transport => typeof transport !== 'object');
658
+ if (transportStr.includes('WebUsbTransport')) {
659
+ settings.transports.splice(settings.transports.indexOf('WebUsbTransport'), 1);
660
+ }
661
+ if (!transportStr.includes('BridgeTransport')) {
662
+ settings.transports.unshift('BridgeTransport');
663
+ }
670
664
  }
671
665
  try {
672
666
  await _deviceList.dispose();
@@ -2,5 +2,5 @@ import * as Methods from '../api';
2
2
  import type { IFrameCallMessage } from '../events';
3
3
  export declare const getMethod: (message: IFrameCallMessage & {
4
4
  id?: number;
5
- }) => Methods.applyFlags | Methods.applySettings | Methods.authorizeCoinjoin | Methods.backupDevice | Methods.binanceGetAddress | Methods.binanceGetPublicKey | Methods.binanceSignTransaction | Methods.blockchainDisconnect | Methods.blockchainEstimateFee | Methods.blockchainGetAccountBalanceHistory | Methods.blockchainGetCurrentFiatRates | Methods.blockchainGetFiatRatesForTimestamps | Methods.blockchainGetTransactions | Methods.blockchainSetCustomBackend | Methods.blockchainSubscribe | Methods.blockchainSubscribeFiatRates | Methods.blockchainUnsubscribe | Methods.blockchainUnsubscribeFiatRates | Methods.cardanoGetAddress | Methods.cardanoGetNativeScriptHash | Methods.cardanoGetPublicKey | Methods.cardanoSignTransaction | Methods.changePin | Methods.cipherKeyValue | Methods.composeTransaction | Methods.eosGetPublicKey | Methods.eosSignTransaction | Methods.ethereumGetAddress | Methods.ethereumGetPublicKey | Methods.ethereumSignMessage | Methods.ethereumSignTransaction | Methods.ethereumSignTypedData | Methods.ethereumVerifyMessage | Methods.firmwareUpdate | Methods.getAccountInfo | Methods.getAddress | Methods.getCoinInfo | Methods.getDeviceState | Methods.getFeatures | Methods.getFirmwareHash | Methods.getOwnershipId | Methods.getOwnershipProof | Methods.getPublicKey | Methods.getSettings | Methods.nemGetAddress | Methods.nemSignTransaction | Methods.pushTransaction | Methods.rebootToBootloader | Methods.recoveryDevice | Methods.requestLogin | Methods.resetDevice | Methods.rippleGetAddress | Methods.rippleSignTransaction | Methods.setBusy | Methods.setProxy | Methods.signMessage | Methods.signTransaction | Methods.stellarGetAddress | Methods.stellarSignTransaction | Methods.tezosGetAddress | Methods.tezosGetPublicKey | Methods.tezosSignTransaction | Methods.unlockPath | Methods.verifyMessage | Methods.wipeDevice | Methods.checkFirmwareAuthenticity;
5
+ }) => Methods.applyFlags | Methods.applySettings | Methods.authorizeCoinjoin | Methods.cancelCoinjoinAuthorization | Methods.showDeviceTutorial | Methods.backupDevice | Methods.binanceGetAddress | Methods.binanceGetPublicKey | Methods.binanceSignTransaction | Methods.blockchainDisconnect | Methods.blockchainEstimateFee | Methods.blockchainGetAccountBalanceHistory | Methods.blockchainGetCurrentFiatRates | Methods.blockchainGetFiatRatesForTimestamps | Methods.blockchainGetTransactions | Methods.blockchainSetCustomBackend | Methods.blockchainSubscribe | Methods.blockchainSubscribeFiatRates | Methods.blockchainUnsubscribe | Methods.blockchainUnsubscribeFiatRates | Methods.cardanoGetAddress | Methods.cardanoGetNativeScriptHash | Methods.cardanoGetPublicKey | Methods.cardanoSignTransaction | Methods.changePin | Methods.cipherKeyValue | Methods.composeTransaction | Methods.eosGetPublicKey | Methods.eosSignTransaction | Methods.ethereumGetAddress | Methods.ethereumGetPublicKey | Methods.ethereumSignMessage | Methods.ethereumSignTransaction | Methods.ethereumSignTypedData | Methods.ethereumVerifyMessage | Methods.firmwareUpdate | Methods.getAccountInfo | Methods.getAddress | Methods.getCoinInfo | Methods.getDeviceState | Methods.getFeatures | Methods.getFirmwareHash | Methods.getOwnershipId | Methods.getOwnershipProof | Methods.getPublicKey | Methods.getSettings | Methods.nemGetAddress | Methods.nemSignTransaction | Methods.pushTransaction | Methods.rebootToBootloader | Methods.recoveryDevice | Methods.requestLogin | Methods.resetDevice | Methods.rippleGetAddress | Methods.rippleSignTransaction | Methods.setBusy | Methods.setProxy | Methods.signMessage | Methods.signTransaction | Methods.stellarGetAddress | Methods.stellarSignTransaction | Methods.tezosGetAddress | Methods.tezosGetPublicKey | Methods.tezosSignTransaction | Methods.unlockPath | Methods.verifyMessage | Methods.wipeDevice | Methods.checkFirmwareAuthenticity;
6
6
  //# sourceMappingURL=method.d.ts.map
@@ -1,5 +1,4 @@
1
1
  import type { CoinInfo, BitcoinNetworkInfo, EthereumNetworkInfo, MiscNetworkInfo } from '../types/coinInfo';
2
- export declare function cloneCoinInfo<T>(info: T): T;
3
2
  export declare const getBitcoinNetwork: (pathOrName: number[] | string) => BitcoinNetworkInfo | undefined;
4
3
  export declare const getEthereumNetwork: (pathOrName: number[] | string) => EthereumNetworkInfo | undefined;
5
4
  export declare const getMiscNetwork: (pathOrName: number[] | string) => MiscNetworkInfo | undefined;