@trezor/connect 9.4.0 → 9.4.1-beta.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 (114) hide show
  1. package/CHANGELOG.md +83 -8
  2. package/README.md +1 -1
  3. package/lib/api/binance/api/index.js +4 -6
  4. package/lib/api/bitcoin/Fees.d.ts +2 -2
  5. package/lib/api/bitcoin/outputs.d.ts +1 -1
  6. package/lib/api/bitcoin/refTx.d.ts +2 -2
  7. package/lib/api/cardano/api/index.js +6 -8
  8. package/lib/api/cardano/cardanoInputs.d.ts +10 -10
  9. package/lib/api/cardano/cardanoOutputs.d.ts +23 -23
  10. package/lib/api/cardano/cardanoTokenBundle.d.ts +6 -6
  11. package/lib/api/common/Discovery.d.ts +0 -1
  12. package/lib/api/common/paramsValidator.js +2 -2
  13. package/lib/api/composeTransaction.js +3 -0
  14. package/lib/api/eos/api/index.js +3 -5
  15. package/lib/api/eos/eosSignTx.d.ts +4 -4
  16. package/lib/api/eos/eosSignTx.js +2 -2
  17. package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +68 -68
  18. package/lib/api/ethereum/api/index.js +7 -9
  19. package/lib/api/ethereum/ethereumDefinitions.d.ts +23 -23
  20. package/lib/api/ethereum/ethereumSignTypedData.js +3 -4
  21. package/lib/api/firmware/calculateFirmwareHash.d.ts +0 -1
  22. package/lib/api/firmware/parseFirmwareHeaders.d.ts +0 -1
  23. package/lib/api/firmware/uploadFirmware.d.ts +6 -1
  24. package/lib/api/firmware/verifyAuthenticityProof.d.ts +0 -1
  25. package/lib/api/getAccountInfo.d.ts +38 -38
  26. package/lib/api/getCoinInfo.d.ts +3 -3
  27. package/lib/api/getDeviceState.d.ts +2 -1
  28. package/lib/api/getDeviceState.js +6 -3
  29. package/lib/api/getFeatures.d.ts +10 -10
  30. package/lib/api/index.js +49 -51
  31. package/lib/api/nem/api/index.js +3 -5
  32. package/lib/api/pushTransaction.js +1 -1
  33. package/lib/api/ripple/api/index.js +3 -5
  34. package/lib/api/signTransaction.js +3 -0
  35. package/lib/api/solana/api/index.js +4 -6
  36. package/lib/api/stellar/api/index.js +3 -5
  37. package/lib/api/tezos/api/index.js +4 -6
  38. package/lib/api/tezos/tezosSignTx.js +2 -2
  39. package/lib/backend/Blockchain.d.ts +2 -2
  40. package/lib/backend/BlockchainLink.d.ts +2 -2
  41. package/lib/constants/nem.d.ts +3 -3
  42. package/lib/core/AbstractMethod.d.ts +8 -6
  43. package/lib/core/AbstractMethod.js +26 -3
  44. package/lib/core/index.d.ts +0 -1
  45. package/lib/core/index.js +45 -54
  46. package/lib/core/onCallFirmwareUpdate.js +7 -2
  47. package/lib/data/DataManager.d.ts +5 -31
  48. package/lib/data/coinInfo.d.ts +15 -21
  49. package/lib/data/config.d.ts +5 -31
  50. package/lib/data/config.js +8 -5
  51. package/lib/data/deviceAuthenticityConfig.js +32 -14
  52. package/lib/data/deviceAuthenticityConfigTypes.d.ts +28 -28
  53. package/lib/data/firmwareInfo.d.ts +2 -2
  54. package/lib/data/firmwareInfo.js +8 -7
  55. package/lib/data/models.js +3 -3
  56. package/lib/data/version.d.ts +1 -1
  57. package/lib/data/version.js +1 -1
  58. package/lib/device/Device.d.ts +52 -19
  59. package/lib/device/Device.js +87 -73
  60. package/lib/device/DeviceCommands.d.ts +9 -9
  61. package/lib/device/DeviceCommands.js +10 -10
  62. package/lib/device/DeviceList.js +60 -83
  63. package/lib/device/StateStorage.d.ts +15 -0
  64. package/lib/device/StateStorage.js +40 -0
  65. package/lib/device/checkFirmwareRevision.js +0 -4
  66. package/lib/events/device.d.ts +0 -1
  67. package/lib/events/device.js +0 -1
  68. package/lib/events/ui-request.d.ts +2 -1
  69. package/lib/factory.d.ts +0 -1
  70. package/lib/index.d.ts +0 -1
  71. package/lib/types/api/applySettings.d.ts +14 -14
  72. package/lib/types/api/authenticateDevice.d.ts +30 -30
  73. package/lib/types/api/authorizeCoinjoin.d.ts +10 -10
  74. package/lib/types/api/binance/index.d.ts +152 -152
  75. package/lib/types/api/bitcoin/index.d.ts +12 -12
  76. package/lib/types/api/cancelCoinjoinAuthorization.d.ts +2 -2
  77. package/lib/types/api/cardano/index.d.ts +556 -556
  78. package/lib/types/api/changeLanguage.d.ts +7 -7
  79. package/lib/types/api/cipherKeyValue.d.ts +8 -8
  80. package/lib/types/api/eos/index.d.ts +633 -633
  81. package/lib/types/api/ethereum/index.d.ts +124 -124
  82. package/lib/types/api/firmwareUpdate.d.ts +6 -6
  83. package/lib/types/api/getAccountDescriptor.d.ts +5 -5
  84. package/lib/types/api/getAddress.d.ts +33 -33
  85. package/lib/types/api/getDeviceState.d.ts +3 -1
  86. package/lib/types/api/getOwnershipId.d.ts +25 -25
  87. package/lib/types/api/getOwnershipProof.d.ts +29 -29
  88. package/lib/types/api/getPublicKey.d.ts +25 -25
  89. package/lib/types/api/nem/index.d.ts +707 -707
  90. package/lib/types/api/nemGetAddress.d.ts +7 -7
  91. package/lib/types/api/pushTransaction.d.ts +4 -4
  92. package/lib/types/api/recoveryDevice.d.ts +10 -10
  93. package/lib/types/api/requestLogin.d.ts +28 -28
  94. package/lib/types/api/ripple/index.d.ts +28 -28
  95. package/lib/types/api/solana/index.d.ts +28 -28
  96. package/lib/types/api/stellar/index.d.ts +745 -745
  97. package/lib/types/api/tezos/index.d.ts +129 -129
  98. package/lib/types/api/unlockPath.d.ts +3 -3
  99. package/lib/types/coinInfo.d.ts +246 -246
  100. package/lib/types/device.d.ts +9 -1
  101. package/lib/types/fees.d.ts +22 -22
  102. package/lib/types/firmware.d.ts +1 -1
  103. package/lib/types/params.d.ts +20 -19
  104. package/lib/utils/assetUtils.js +1 -1
  105. package/lib/utils/assets-browser.d.ts +1 -1
  106. package/lib/utils/assets.js +1 -2
  107. package/lib/utils/debug.d.ts +2 -2
  108. package/lib/utils/deviceFeaturesUtils.d.ts +1 -1
  109. package/lib/utils/hdnodeUtils.d.ts +1 -191
  110. package/lib/utils/hdnodeUtils.js +2 -2
  111. package/lib/utils/pathUtils.d.ts +1 -191
  112. package/lib/utils/promiseUtils.d.ts +1 -1
  113. package/lib/utils/uiPromiseManager.d.ts +2 -2
  114. package/package.json +15 -13
@@ -95,6 +95,9 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
95
95
  unlockPath: payload.unlockPath,
96
96
  };
97
97
  this.params.options = (0, bitcoin_1.enhanceSignTx)(this.params.options, coinInfo);
98
+ if (this.params.push) {
99
+ this.requiredPermissions.push('push_tx');
100
+ }
98
101
  }
99
102
  get info() {
100
103
  const coinInfo = (0, coinInfo_1.getBitcoinNetwork)(this.payload.coin);
@@ -1,13 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.solanaSignTransaction = exports.solanaGetPublicKey = exports.solanaGetAddress = void 0;
4
+ const tslib_1 = require("tslib");
7
5
  var solanaGetAddress_1 = require("./solanaGetAddress");
8
- Object.defineProperty(exports, "solanaGetAddress", { enumerable: true, get: function () { return __importDefault(solanaGetAddress_1).default; } });
6
+ Object.defineProperty(exports, "solanaGetAddress", { enumerable: true, get: function () { return tslib_1.__importDefault(solanaGetAddress_1).default; } });
9
7
  var solanaGetPublicKey_1 = require("./solanaGetPublicKey");
10
- Object.defineProperty(exports, "solanaGetPublicKey", { enumerable: true, get: function () { return __importDefault(solanaGetPublicKey_1).default; } });
8
+ Object.defineProperty(exports, "solanaGetPublicKey", { enumerable: true, get: function () { return tslib_1.__importDefault(solanaGetPublicKey_1).default; } });
11
9
  var solanaSignTransaction_1 = require("./solanaSignTransaction");
12
- Object.defineProperty(exports, "solanaSignTransaction", { enumerable: true, get: function () { return __importDefault(solanaSignTransaction_1).default; } });
10
+ Object.defineProperty(exports, "solanaSignTransaction", { enumerable: true, get: function () { return tslib_1.__importDefault(solanaSignTransaction_1).default; } });
13
11
  //# sourceMappingURL=index.js.map
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.stellarSignTransaction = exports.stellarGetAddress = void 0;
4
+ const tslib_1 = require("tslib");
7
5
  var stellarGetAddress_1 = require("./stellarGetAddress");
8
- Object.defineProperty(exports, "stellarGetAddress", { enumerable: true, get: function () { return __importDefault(stellarGetAddress_1).default; } });
6
+ Object.defineProperty(exports, "stellarGetAddress", { enumerable: true, get: function () { return tslib_1.__importDefault(stellarGetAddress_1).default; } });
9
7
  var stellarSignTransaction_1 = require("./stellarSignTransaction");
10
- Object.defineProperty(exports, "stellarSignTransaction", { enumerable: true, get: function () { return __importDefault(stellarSignTransaction_1).default; } });
8
+ Object.defineProperty(exports, "stellarSignTransaction", { enumerable: true, get: function () { return tslib_1.__importDefault(stellarSignTransaction_1).default; } });
11
9
  //# sourceMappingURL=index.js.map
@@ -1,13 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.tezosSignTransaction = exports.tezosGetPublicKey = exports.tezosGetAddress = void 0;
4
+ const tslib_1 = require("tslib");
7
5
  var tezosGetAddress_1 = require("./tezosGetAddress");
8
- Object.defineProperty(exports, "tezosGetAddress", { enumerable: true, get: function () { return __importDefault(tezosGetAddress_1).default; } });
6
+ Object.defineProperty(exports, "tezosGetAddress", { enumerable: true, get: function () { return tslib_1.__importDefault(tezosGetAddress_1).default; } });
9
7
  var tezosGetPublicKey_1 = require("./tezosGetPublicKey");
10
- Object.defineProperty(exports, "tezosGetPublicKey", { enumerable: true, get: function () { return __importDefault(tezosGetPublicKey_1).default; } });
8
+ Object.defineProperty(exports, "tezosGetPublicKey", { enumerable: true, get: function () { return tslib_1.__importDefault(tezosGetPublicKey_1).default; } });
11
9
  var tezosSignTransaction_1 = require("./tezosSignTransaction");
12
- Object.defineProperty(exports, "tezosSignTransaction", { enumerable: true, get: function () { return __importDefault(tezosSignTransaction_1).default; } });
10
+ Object.defineProperty(exports, "tezosSignTransaction", { enumerable: true, get: function () { return tslib_1.__importDefault(tezosSignTransaction_1).default; } });
13
11
  //# sourceMappingURL=index.js.map
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTx = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const bs58check = tslib_1.__importStar(require("bs58check"));
5
+ const bs58check_1 = tslib_1.__importDefault(require("bs58check"));
6
6
  const constants_1 = require("../../constants");
7
7
  const tezos_1 = require("../../types/api/tezos");
8
8
  const schema_utils_1 = require("@trezor/schema-utils");
@@ -16,7 +16,7 @@ const PREFIX = {
16
16
  sppk: new Uint8Array([3, 254, 226, 86]),
17
17
  p2pk: new Uint8Array([3, 178, 139, 127]),
18
18
  };
19
- const bs58checkDecode = (prefix, enc) => bs58check.decode(enc).slice(prefix.length);
19
+ const bs58checkDecode = (prefix, enc) => bs58check_1.default.decode(enc).slice(prefix.length);
20
20
  const concatArray = (first, second) => {
21
21
  const result = new Uint8Array(first.length + second.length);
22
22
  result.set(first);
@@ -49,8 +49,8 @@ export declare class Blockchain {
49
49
  getAccountUtxo(descriptor: string): Promise<import("@trezor/blockchain-link").Utxo[]>;
50
50
  estimateFee(request: Parameters<typeof this.link.estimateFee>[0]): Promise<{
51
51
  feePerUnit: string;
52
- feePerTx?: string | undefined;
53
- feeLimit?: string | undefined;
52
+ feePerTx?: string;
53
+ feeLimit?: string;
54
54
  }[]>;
55
55
  subscribeBlocks(): Promise<{
56
56
  subscribed: boolean;
@@ -2,9 +2,9 @@ import type { BlockchainOptions as Options } from './Blockchain';
2
2
  import type { CoinInfo } from '../types';
3
3
  export { Blockchain } from './Blockchain';
4
4
  export declare const findBackend: (coin: string, identity?: string) => import("./Blockchain").Blockchain | null;
5
- export declare const setCustomBackend: (coinInfo: CoinInfo, blockchainLink: CoinInfo['blockchainLink']) => void;
5
+ export declare const setCustomBackend: (coinInfo: CoinInfo, blockchainLink: CoinInfo["blockchainLink"]) => void;
6
6
  export declare const isBackendSupported: (coinInfo: CoinInfo) => void;
7
- export declare const initBlockchain: (coinInfo: CoinInfo, postMessage: Options['postMessage'], identity?: string) => Promise<import("./Blockchain").Blockchain>;
7
+ export declare const initBlockchain: (coinInfo: CoinInfo, postMessage: Options["postMessage"], identity?: string) => Promise<import("./Blockchain").Blockchain>;
8
8
  export declare const reconnectAllBackends: (coinInfo?: CoinInfo) => Promise<import("./Blockchain").Blockchain[]>;
9
9
  export declare const dispose: () => void;
10
10
  //# sourceMappingURL=BlockchainLink.d.ts.map
@@ -5,7 +5,7 @@ export declare enum Networks {
5
5
  mijin = 96
6
6
  }
7
7
  export type EnumNetworks = Static<typeof EnumNetworks>;
8
- export declare const EnumNetworks: import("@sinclair/typebox").TEnum<typeof Networks>;
8
+ export declare const EnumNetworks: import("@sinclair/typebox/build/esm/index.mjs").TEnum<typeof Networks>;
9
9
  export declare enum TxType {
10
10
  TRANSFER = 257,
11
11
  COSIGNING = 258,
@@ -18,12 +18,12 @@ export declare enum TxType {
18
18
  SUPPLY_CHANGE = 16386
19
19
  }
20
20
  export type EnumTxType = Static<typeof EnumTxType>;
21
- export declare const EnumTxType: import("@sinclair/typebox").TEnum<typeof TxType>;
21
+ export declare const EnumTxType: import("@sinclair/typebox/build/esm/index.mjs").TEnum<typeof TxType>;
22
22
  export declare enum TxVersion {
23
23
  mainnet = 1744830464,
24
24
  testnet = -1744830464,
25
25
  mijin = 1610612736
26
26
  }
27
27
  export type EnumTxVersion = Static<typeof EnumTxVersion>;
28
- export declare const EnumTxVersion: import("@sinclair/typebox").TEnum<typeof TxVersion>;
28
+ export declare const EnumTxVersion: import("@sinclair/typebox/build/esm/index.mjs").TEnum<typeof TxVersion>;
29
29
  //# sourceMappingURL=nem.d.ts.map
@@ -1,20 +1,22 @@
1
1
  import { NETWORK } from '../constants';
2
- import { CallMethodPayload, CallMethodResponse, UiRequestButtonData, UiPromiseCreator, CoreEventMessage, UiRequestConfirmation } from '../events';
2
+ import { UI, CallMethodPayload, CallMethodResponse, UiRequestButtonData, UiPromiseCreator, CoreEventMessage, UiRequestConfirmation } from '../events';
3
3
  import type { Device } from '../device/Device';
4
- import type { FirmwareRange } from '../types';
4
+ import type { FirmwareRange, DeviceState } from '../types';
5
5
  export type Payload<M> = Extract<CallMethodPayload, {
6
6
  method: M;
7
7
  }> & {
8
8
  override?: boolean;
9
9
  };
10
10
  export type MethodReturnType<M extends CallMethodPayload['method']> = CallMethodResponse<M>;
11
+ export type MethodPermission = 'read' | 'write' | 'management' | 'push_tx';
12
+ export type DeviceMode = typeof UI.SEEDLESS | typeof UI.BOOTLOADER | typeof UI.INITIALIZE;
11
13
  export declare const DEFAULT_FIRMWARE_RANGE: FirmwareRange;
12
14
  export declare abstract class AbstractMethod<Name extends CallMethodPayload['method'], Params = undefined> {
13
15
  responseID: number;
14
16
  device: Device;
15
17
  params: Params;
16
18
  devicePath?: string;
17
- deviceState?: string;
19
+ deviceState?: DeviceState;
18
20
  hasExpectedDeviceState: boolean;
19
21
  keepSession: boolean;
20
22
  skipFinalReload: boolean;
@@ -32,9 +34,9 @@ export declare abstract class AbstractMethod<Name extends CallMethodPayload['met
32
34
  useEmptyPassphrase: boolean;
33
35
  allowSeedlessDevice: boolean;
34
36
  firmwareRange: FirmwareRange;
35
- requiredPermissions: string[];
36
- allowDeviceMode: string[];
37
- requireDeviceMode: string[];
37
+ requiredPermissions: MethodPermission[];
38
+ allowDeviceMode: DeviceMode[];
39
+ requireDeviceMode: DeviceMode[];
38
40
  network: NETWORK.NetworkType;
39
41
  useCardanoDerivation: boolean;
40
42
  noBackupConfirmationMode: 'never' | 'always' | 'popup-only';
@@ -7,6 +7,7 @@ const DataManager_1 = require("../data/DataManager");
7
7
  const constants_1 = require("../constants");
8
8
  const events_1 = require("../events");
9
9
  const urlUtils_1 = require("../utils/urlUtils");
10
+ const constants_2 = require("../constants");
10
11
  exports.DEFAULT_FIRMWARE_RANGE = {
11
12
  T1B1: { min: '1.0.0', max: '0' },
12
13
  T2T1: { min: '2.0.0', max: '0' },
@@ -14,6 +15,19 @@ exports.DEFAULT_FIRMWARE_RANGE = {
14
15
  T3B1: { min: '2.8.1', max: '0' },
15
16
  T3T1: { min: '2.7.1', max: '0' },
16
17
  };
18
+ function validateStaticSessionId(input) {
19
+ if (typeof input !== 'string')
20
+ throw constants_2.ERRORS.TypedError('Method_InvalidParameter', 'DeviceState: invalid staticSessionId: ' + input);
21
+ const [firstTestnetAddress, rest] = input.split('@');
22
+ const [deviceId, instance] = rest.split(':');
23
+ if (typeof firstTestnetAddress === 'string' &&
24
+ typeof deviceId === 'string' &&
25
+ typeof instance === 'string' &&
26
+ Number.parseInt(instance) >= 0) {
27
+ return input;
28
+ }
29
+ throw constants_2.ERRORS.TypedError('Method_InvalidParameter', 'DeviceState: invalid staticSessionId: ' + input);
30
+ }
17
31
  class AbstractMethod {
18
32
  get info() {
19
33
  return '';
@@ -22,13 +36,20 @@ class AbstractMethod {
22
36
  return undefined;
23
37
  }
24
38
  constructor(message) {
25
- var _a, _b;
39
+ var _a, _b, _c, _d;
26
40
  const { payload } = message;
27
41
  this.name = payload.method;
28
42
  this.payload = payload;
29
43
  this.responseID = message.id || 0;
30
44
  this.devicePath = (_a = payload.device) === null || _a === void 0 ? void 0 : _a.path;
31
- this.deviceState = (_b = payload.device) === null || _b === void 0 ? void 0 : _b.state;
45
+ this.deviceState =
46
+ typeof ((_b = payload.device) === null || _b === void 0 ? void 0 : _b.state) === 'string'
47
+ ? { staticSessionId: validateStaticSessionId(payload.device.state) }
48
+ : ((_d = (_c = payload.device) === null || _c === void 0 ? void 0 : _c.state) === null || _d === void 0 ? void 0 : _d.staticSessionId)
49
+ ? {
50
+ staticSessionId: validateStaticSessionId(payload.device.state.staticSessionId),
51
+ }
52
+ : undefined;
32
53
  this.hasExpectedDeviceState = payload.device
33
54
  ? Object.prototype.hasOwnProperty.call(payload.device, 'state')
34
55
  : false;
@@ -135,7 +156,9 @@ class AbstractMethod {
135
156
  if (range.min === '0') {
136
157
  return events_1.UI.FIRMWARE_NOT_SUPPORTED;
137
158
  }
138
- const version = device.getVersion().join('.');
159
+ const version = device.getVersion();
160
+ if (!version)
161
+ return;
139
162
  if (device.firmwareStatus === 'required' ||
140
163
  !utils_1.versionUtils.isNewerOrEqual(version, range.min)) {
141
164
  return events_1.UI.FIRMWARE_OLD;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import EventEmitter from 'events';
3
2
  import { TransportInfo, CoreRequestMessage, CoreEventMessage } from '../events';
4
3
  import { AbstractMethod } from './AbstractMethod';
package/lib/core/index.js CHANGED
@@ -20,6 +20,7 @@ const debug_1 = require("../utils/debug");
20
20
  const BlockchainLink_1 = require("../backend/BlockchainLink");
21
21
  const interactionTimeout_1 = require("../utils/interactionTimeout");
22
22
  const onCallFirmwareUpdate_1 = require("./onCallFirmwareUpdate");
23
+ const StateStorage_1 = require("../device/StateStorage");
23
24
  const _log = (0, debug_1.initLog)('Core');
24
25
  const waitForPopup = ({ popupPromise, sendCoreMessage }) => {
25
26
  sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_UI_WINDOW));
@@ -30,7 +31,6 @@ const startInteractionTimeout = (context) => context.interactionTimeout.start(()
30
31
  });
31
32
  const initDevice = async (context, devicePath) => {
32
33
  const { uiPromises, deviceList, sendCoreMessage } = context;
33
- await deviceList.pendingConnection();
34
34
  (0, DeviceList_1.assertDeviceListConnected)(deviceList);
35
35
  const isWebUsb = deviceList.transportType() === 'WebUsbTransport';
36
36
  let device;
@@ -150,7 +150,7 @@ const inner = async (context, method, device) => {
150
150
  }
151
151
  const unexpectedMode = device.hasUnexpectedMode(method.allowDeviceMode, method.requireDeviceMode);
152
152
  if (unexpectedMode) {
153
- device.keepSession = false;
153
+ device.keepTransportSession = false;
154
154
  if (isUsingPopup) {
155
155
  await waitForPopup(context);
156
156
  sendCoreMessage((0, events_2.createUiMessage)(unexpectedMode, device.toMessageObject()));
@@ -220,12 +220,12 @@ const inner = async (context, method, device) => {
220
220
  }));
221
221
  const uiResp = await uiPromise.promise;
222
222
  if (uiResp.payload) {
223
- device.setInternalState(undefined);
223
+ device.setState({ sessionId: undefined });
224
224
  await device.initialize(method.useCardanoDerivation);
225
225
  invalidDeviceState = await getInvalidDeviceState(context, device, method.preauthorized);
226
226
  }
227
227
  else {
228
- device.setExternalState(invalidDeviceState);
228
+ device.setState({ staticSessionId: invalidDeviceState });
229
229
  break;
230
230
  }
231
231
  }
@@ -235,7 +235,7 @@ const inner = async (context, method, device) => {
235
235
  }
236
236
  }
237
237
  catch (error) {
238
- device.setInternalState(undefined);
238
+ device.setState({ sessionId: undefined });
239
239
  return Promise.reject(error);
240
240
  }
241
241
  }
@@ -257,21 +257,17 @@ const inner = async (context, method, device) => {
257
257
  }
258
258
  };
259
259
  const onCall = async (context, message) => {
260
- var _a;
261
260
  if (!message.id || !message.payload || message.type !== events_2.IFRAME.CALL) {
262
261
  throw constants_1.ERRORS.TypedError('Method_InvalidParameter', 'onCall: message.id or message.payload is missing');
263
262
  }
264
- const { uiPromises, deviceList, callMethods, methodSynchronize, resolveWaitForFirstMethod, getOverridePromise, setOverridePromise, sendCoreMessage, } = context;
263
+ const { uiPromises, callMethods, methodSynchronize, resolveWaitForFirstMethod, sendCoreMessage, } = context;
265
264
  const responseID = message.id;
266
265
  const origin = DataManager_1.DataManager.getSettings('origin');
267
- const env = DataManager_1.DataManager.getSettings('env');
268
- const useCoreInPopup = DataManager_1.DataManager.getSettings('useCoreInPopup');
269
266
  const { preferredDevice } = connect_common_1.storage.loadForOrigin(origin) || {};
270
267
  if (preferredDevice && !message.payload.device) {
271
268
  message.payload.device = preferredDevice;
272
269
  }
273
270
  let method;
274
- let messageResponse;
275
271
  try {
276
272
  method = await methodSynchronize(async () => {
277
273
  var _a;
@@ -301,19 +297,13 @@ const onCall = async (context, message) => {
301
297
  sendCoreMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
302
298
  }
303
299
  const response = await method.run();
304
- messageResponse = (0, events_2.createResponseMessage)(method.responseID, true, response);
300
+ sendCoreMessage((0, events_2.createResponseMessage)(method.responseID, true, response));
305
301
  }
306
302
  catch (error) {
307
- messageResponse = (0, events_2.createResponseMessage)(method.responseID, false, { error });
303
+ sendCoreMessage((0, events_2.createResponseMessage)(method.responseID, false, { error }));
308
304
  }
309
- sendCoreMessage(messageResponse);
310
305
  return Promise.resolve();
311
306
  }
312
- if (!deviceList.isConnected() && !deviceList.pendingConnection()) {
313
- const { transports, pendingTransportEvent } = DataManager_1.DataManager.getSettings();
314
- deviceList.setTransports(transports);
315
- await deviceList.init({ pendingTransportEvent });
316
- }
317
307
  if (method.isManagementRestricted()) {
318
308
  sendCoreMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
319
309
  sendCoreMessage((0, events_2.createResponseMessage)(responseID, false, {
@@ -321,21 +311,42 @@ const onCall = async (context, message) => {
321
311
  }));
322
312
  return Promise.resolve();
323
313
  }
324
- let device;
325
- try {
326
- device = await initDevice(context, method.devicePath);
314
+ return await onCallDevice(context, message, method);
315
+ };
316
+ const onCallDevice = async (context, message, method) => {
317
+ var _a;
318
+ const { deviceList, callMethods, getOverridePromise, setOverridePromise, sendCoreMessage } = context;
319
+ const responseID = message.id;
320
+ const { origin, env, useCoreInPopup } = DataManager_1.DataManager.getSettings();
321
+ if (!deviceList.isConnected() && !deviceList.pendingConnection()) {
322
+ deviceList.init();
327
323
  }
328
- catch (error) {
329
- if (error.code === 'Transport_Missing') {
330
- await waitForPopup(context);
331
- sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.TRANSPORT));
324
+ await deviceList.pendingConnection();
325
+ const shouldRetry = ['web', 'webextension'].includes(env);
326
+ let tempDevice;
327
+ while (!tempDevice) {
328
+ try {
329
+ tempDevice = await initDevice(context, method.devicePath);
332
330
  }
333
- else {
334
- sendCoreMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
331
+ catch (error) {
332
+ if (error.code === 'Transport_Missing') {
333
+ await waitForPopup(context);
334
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.TRANSPORT));
335
+ if (deviceList.pendingConnection() && shouldRetry) {
336
+ while (deviceList.pendingConnection()) {
337
+ await deviceList.pendingConnection();
338
+ }
339
+ continue;
340
+ }
341
+ }
342
+ else {
343
+ sendCoreMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
344
+ }
345
+ sendCoreMessage((0, events_2.createResponseMessage)(responseID, false, { error }));
346
+ throw error;
335
347
  }
336
- sendCoreMessage((0, events_2.createResponseMessage)(responseID, false, { error }));
337
- throw error;
338
348
  }
349
+ const device = tempDevice;
339
350
  method.setDevice(device);
340
351
  const previousCall = callMethods.filter(call => call && call !== method && call.devicePath === method.devicePath);
341
352
  if (previousCall.length > 0 && method.overridePreviousCall) {
@@ -363,7 +374,7 @@ const onCall = async (context, message) => {
363
374
  }
364
375
  device.setInstance((_a = message.payload.device) === null || _a === void 0 ? void 0 : _a.instance);
365
376
  if (method.hasExpectedDeviceState) {
366
- device.setExternalState(method.deviceState);
377
+ device.setState(method.deviceState);
367
378
  }
368
379
  device.on(events_2.DEVICE.BUTTON, onDeviceButtonHandler(context, method));
369
380
  device.on(events_2.DEVICE.PIN, onDevicePinHandler(context));
@@ -372,30 +383,10 @@ const onCall = async (context, message) => {
372
383
  device.on(events_2.DEVICE.PASSPHRASE_ON_DEVICE, () => {
373
384
  sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_PASSPHRASE_ON_DEVICE, { device: device.toMessageObject() }));
374
385
  });
375
- device.on(events_2.DEVICE.SAVE_STATE, (state) => {
376
- if (useCoreInPopup && env === 'webextension') {
377
- connect_common_1.storage.saveForOrigin(store => {
378
- return {
379
- ...store,
380
- preferredDevice: store.preferredDevice
381
- ? {
382
- ...store.preferredDevice,
383
- internalState: state,
384
- internalStateExpiration: Date.now() + 1000 * 60 * 15,
385
- }
386
- : undefined,
387
- };
388
- }, origin);
389
- }
390
- });
391
- if (!device.getInternalState() && useCoreInPopup && env === 'webextension') {
392
- const { preferredDevice } = connect_common_1.storage.loadForOrigin(origin) || {};
393
- if ((preferredDevice === null || preferredDevice === void 0 ? void 0 : preferredDevice.internalState) &&
394
- (preferredDevice === null || preferredDevice === void 0 ? void 0 : preferredDevice.internalStateExpiration) &&
395
- preferredDevice.internalStateExpiration > new Date().getTime()) {
396
- device.setInternalState(preferredDevice.internalState);
397
- }
386
+ if (useCoreInPopup && env === 'webextension' && origin) {
387
+ device.initStorage(new StateStorage_1.WebextensionStateStorage(origin));
398
388
  }
389
+ let messageResponse;
399
390
  try {
400
391
  if (getOverridePromise()) {
401
392
  await getOverridePromise();
@@ -524,7 +515,7 @@ const onPopupClosed = (context, customErrorMessage) => {
524
515
  : constants_1.ERRORS.TypedError('Method_Interrupted');
525
516
  if (deviceList.isConnected() && deviceList.asArray().length > 0) {
526
517
  deviceList.allDevices().forEach(d => {
527
- d.keepSession = false;
518
+ d.keepTransportSession = false;
528
519
  if (d.isUsedHere()) {
529
520
  setOverridePromise(d.interruptionFromUser(error));
530
521
  }
@@ -88,7 +88,8 @@ const getInstallationParams = (device, params) => {
88
88
  const isUpdatingToEqualFirmwareType = (device.firmwareType === 'bitcoin-only') === btcOnly;
89
89
  const upgrade = device.atLeast('2.6.3') && isUpdatingToNewerVersion && isUpdatingToEqualFirmwareType;
90
90
  const manual = !device.atLeast(['1.10.0', '2.6.0']) && !upgrade;
91
- const language = device.atLeast('2.7.0');
91
+ const language = device.atLeast('2.7.0') &&
92
+ device.features.internal_model !== constants_1.PROTO.DeviceModelInternal.T2T1;
92
93
  return {
93
94
  manual,
94
95
  upgrade,
@@ -207,6 +208,9 @@ const onCallFirmwareUpdate = async ({ params, context: { deviceList, postMessage
207
208
  }).catch(() => {
208
209
  })
209
210
  : null;
211
+ const disconnectedPromise = new Promise(resolve => {
212
+ deviceList.once('device-disconnect', resolve);
213
+ });
210
214
  if (!languageBlob) {
211
215
  await device.getCommands().typedCall('RebootToBootloader', 'Success', rebootParams);
212
216
  }
@@ -220,7 +224,8 @@ const onCallFirmwareUpdate = async ({ params, context: { deviceList, postMessage
220
224
  rebootResponse = await device.getCommands().typedCall('TranslationDataAck', ['TranslationDataRequest', 'Success'], { data_chunk: Buffer.from(chunk).toString('hex') });
221
225
  }
222
226
  }
223
- await device.release();
227
+ log.info('onCallFirmwareUpdate', 'waiting for disconnected event after rebootToBootloader...');
228
+ await disconnectedPromise;
224
229
  if (device.features.major_version === 1) {
225
230
  await (0, utils_1.createTimeoutPromise)(2000);
226
231
  }
@@ -156,21 +156,8 @@ export declare class DataManager {
156
156
  T1B1: string;
157
157
  T2T1: string;
158
158
  T2B1: string;
159
- T3B1?: undefined;
160
- T3T1?: undefined;
161
- };
162
- comment: string[];
163
- coin?: undefined;
164
- max?: undefined;
165
- capabilities?: undefined;
166
- } | {
167
- methods: string[];
168
- min: {
169
- T1B1: string;
170
- T2T1: string;
171
- T2B1?: undefined;
172
- T3B1?: undefined;
173
- T3T1?: undefined;
159
+ T3B1: string;
160
+ T3T1: string;
174
161
  };
175
162
  coin?: undefined;
176
163
  max?: undefined;
@@ -181,7 +168,7 @@ export declare class DataManager {
181
168
  min: {
182
169
  T1B1: string;
183
170
  T2T1: string;
184
- T2B1: string;
171
+ T2B1?: undefined;
185
172
  T3B1?: undefined;
186
173
  T3T1?: undefined;
187
174
  };
@@ -191,19 +178,6 @@ export declare class DataManager {
191
178
  capabilities?: undefined;
192
179
  } | {
193
180
  capabilities: string[];
194
- min: {
195
- T1B1: string;
196
- T2T1: string;
197
- T2B1: string;
198
- T3B1?: undefined;
199
- T3T1?: undefined;
200
- };
201
- comment: string[];
202
- coin?: undefined;
203
- methods?: undefined;
204
- max?: undefined;
205
- } | {
206
- methods: string[];
207
181
  min: {
208
182
  T1B1: string;
209
183
  T2T1: string;
@@ -211,10 +185,10 @@ export declare class DataManager {
211
185
  T3B1: string;
212
186
  T3T1: string;
213
187
  };
188
+ comment: string[];
214
189
  coin?: undefined;
190
+ methods?: undefined;
215
191
  max?: undefined;
216
- comment?: undefined;
217
- capabilities?: undefined;
218
192
  })[];
219
193
  };
220
194
  }