@trezor/connect 9.1.12 → 9.2.0
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.
- package/CHANGELOG.md +69 -0
- package/README.md +1 -1
- package/lib/api/binance/api/binanceSignTransaction.d.ts +1 -1
- package/lib/api/binance/binanceSignTx.d.ts +1 -1
- package/lib/api/bitcoin/Fees.d.ts +2 -2
- package/lib/api/bitcoin/TransactionComposer.d.ts +2 -2
- package/lib/api/bitcoin/refTx.js +3 -4
- package/lib/api/blockchainGetCurrentFiatRates.d.ts +1 -1
- package/lib/api/blockchainGetFiatRatesForTimestamps.d.ts +1 -1
- package/lib/api/cardano/cardanoOutputs.d.ts +1 -1
- package/lib/api/cardano/cardanoTokenBundle.d.ts +2 -2
- package/lib/api/changeLanguage.d.ts +11 -0
- package/lib/api/changeLanguage.js +73 -0
- package/lib/api/common/paramsValidator.js +4 -5
- package/lib/api/eos/eosSignTx.d.ts +58 -58
- package/lib/api/ethereum/api/ethereumGetPublicKey.d.ts +6 -6
- package/lib/api/ethereum/api/ethereumSignMessage.d.ts +2 -2
- package/lib/api/ethereum/api/ethereumSignTransaction.d.ts +2 -2
- package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +6 -6
- package/lib/api/ethereum/api/ethereumSignTypedData.js +2 -2
- package/lib/api/ethereum/ethereumDefinitions.d.ts +2 -2
- package/lib/api/ethereum/ethereumSignTx.d.ts +3 -3
- package/lib/api/firmware/getBinary.d.ts +1 -1
- package/lib/api/firmware/getBinary.js +4 -5
- package/lib/api/firmware/modifyFirmware.js +2 -3
- package/lib/api/firmware/verifyAuthenticityProof.js +3 -3
- package/lib/api/getAccountInfo.d.ts +2 -0
- package/lib/api/getCoinInfo.d.ts +22 -22
- package/lib/api/getFeatures.d.ts +11 -11
- package/lib/api/getPublicKey.d.ts +6 -6
- package/lib/api/index.d.ts +1 -0
- package/lib/api/index.js +3 -1
- package/lib/api/nem/nemSignTx.d.ts +13 -13
- package/lib/api/rebootToBootloader.d.ts +2 -1
- package/lib/api/rebootToBootloader.js +10 -1
- package/lib/api/recoveryDevice.d.ts +1 -0
- package/lib/api/recoveryDevice.js +3 -0
- package/lib/api/stellar/stellarSignTx.d.ts +1 -1
- package/lib/api/stellar/stellarSignTx.js +6 -0
- package/lib/api/tezos/tezosSignTx.d.ts +18 -18
- package/lib/backend/BackendManager.d.ts +5 -2
- package/lib/backend/BackendManager.js +54 -20
- package/lib/backend/Blockchain.d.ts +6 -6
- package/lib/backend/Blockchain.js +37 -27
- package/lib/constants/index.d.ts +1 -1
- package/lib/constants/index.js +2 -1
- package/lib/core/AbstractMethod.d.ts +1 -1
- package/lib/core/AbstractMethod.js +3 -4
- package/lib/core/index.js +23 -11
- package/lib/data/DataManager.d.ts +2 -2
- package/lib/data/coinInfo.d.ts +117 -117
- package/lib/data/coinInfo.js +6 -6
- package/lib/data/config.js +1 -1
- package/lib/data/connectSettings.js +3 -0
- package/lib/data/deviceAuthenticityConfig.js +4 -1
- package/lib/data/firmwareInfo.d.ts +1 -1
- package/lib/data/firmwareInfo.js +14 -12
- package/lib/data/version.d.ts +1 -1
- package/lib/data/version.js +1 -1
- package/lib/device/Device.d.ts +5 -4
- package/lib/device/Device.js +13 -11
- package/lib/device/DeviceCommands.d.ts +7 -7
- package/lib/device/DeviceCommands.js +4 -4
- package/lib/device/DeviceList.d.ts +1 -1
- package/lib/device/DeviceList.js +3 -3
- package/lib/events/blockchain.d.ts +10 -2
- package/lib/events/blockchain.js +1 -0
- package/lib/events/call.d.ts +2 -2
- package/lib/events/core.d.ts +4 -0
- package/lib/events/popup.d.ts +13 -1
- package/lib/events/ui-promise.d.ts +1 -1
- package/lib/events/webextension.d.ts +1 -0
- package/lib/events/webextension.js +1 -0
- package/lib/factory.js +1 -0
- package/lib/index.js +2 -2
- package/lib/types/api/applySettings.d.ts +6 -6
- package/lib/types/api/binance/index.d.ts +10 -10
- package/lib/types/api/cardano/index.d.ts +4 -4
- package/lib/types/api/changeLanguage.d.ts +15 -0
- package/lib/types/api/changeLanguage.js +17 -0
- package/lib/types/api/cipherKeyValue.d.ts +2 -2
- package/lib/types/api/eos/index.d.ts +3 -3
- package/lib/types/api/ethereum/index.d.ts +3 -3
- package/lib/types/api/firmwareUpdate.d.ts +1 -1
- package/lib/types/api/getAddress.d.ts +5 -5
- package/lib/types/api/index.d.ts +2 -0
- package/lib/types/api/nem/index.d.ts +7 -7
- package/lib/types/api/rebootToBootloader.d.ts +2 -2
- package/lib/types/api/recoveryDevice.d.ts +1 -1
- package/lib/types/api/stellar/index.d.ts +169 -146
- package/lib/types/api/stellar/index.js +13 -1
- package/lib/types/device.d.ts +4 -1
- package/lib/types/device.js +2 -2
- package/lib/types/firmware.d.ts +2 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/settings.d.ts +1 -0
- package/lib/utils/assets-browser.d.ts +1 -1
- package/lib/utils/assets.d.ts +3 -1
- package/lib/utils/assets.js +2 -2
- package/lib/utils/deviceFeaturesUtils.js +4 -5
- package/lib/utils/firmwareUtils.js +4 -5
- package/lib/utils/hdnodeUtils.d.ts +3 -3
- package/lib/utils/pathUtils.d.ts +3 -3
- package/lib/utils/urlUtils.js +3 -3
- package/package.json +26 -28
|
@@ -4,46 +4,51 @@ exports.BackendManager = void 0;
|
|
|
4
4
|
const DataManager_1 = require("../data/DataManager");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
const Blockchain_1 = require("./Blockchain");
|
|
7
|
+
const events_1 = require("../events");
|
|
7
8
|
class BackendManager {
|
|
8
9
|
constructor() {
|
|
9
10
|
this.instances = {};
|
|
10
11
|
this.custom = {};
|
|
11
12
|
this.preferred = {};
|
|
13
|
+
this.reconnect = {};
|
|
12
14
|
}
|
|
13
15
|
get(shortcut) {
|
|
14
16
|
var _a;
|
|
15
17
|
return (_a = this.instances[shortcut]) !== null && _a !== void 0 ? _a : null;
|
|
16
18
|
}
|
|
17
|
-
remove(shortcut) {
|
|
18
|
-
delete this.instances[shortcut];
|
|
19
|
-
}
|
|
20
19
|
async getOrConnect(coinInfo, postMessage) {
|
|
21
|
-
let backend = this.
|
|
20
|
+
let backend = this.instances[coinInfo.shortcut];
|
|
22
21
|
if (!backend) {
|
|
23
22
|
backend = new Blockchain_1.Blockchain({
|
|
24
23
|
coinInfo: this.patchCoinInfo(coinInfo),
|
|
25
24
|
postMessage,
|
|
26
25
|
debug: DataManager_1.DataManager.getSettings('debug'),
|
|
27
26
|
proxy: DataManager_1.DataManager.getSettings('proxy'),
|
|
28
|
-
|
|
29
|
-
onDisconnected: () => this.remove(coinInfo.shortcut),
|
|
27
|
+
onDisconnected: this.onDisconnected.bind(this),
|
|
30
28
|
});
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
this.setInstance(coinInfo.shortcut, backend);
|
|
30
|
+
}
|
|
31
|
+
const reconnect = this.clearReconnect(coinInfo.shortcut);
|
|
32
|
+
try {
|
|
33
|
+
const info = await backend.init();
|
|
34
|
+
this.setPreferred(coinInfo.shortcut, info.url);
|
|
35
|
+
return backend;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
this.setInstance(coinInfo.shortcut, undefined);
|
|
39
|
+
this.setPreferred(coinInfo.shortcut, undefined);
|
|
40
|
+
if (reconnect) {
|
|
41
|
+
this.planReconnect(backend.coinInfo, backend.postMessage, reconnect.attempts);
|
|
39
42
|
}
|
|
43
|
+
throw error;
|
|
40
44
|
}
|
|
41
|
-
return backend;
|
|
42
45
|
}
|
|
43
46
|
dispose() {
|
|
47
|
+
Object.keys(this.reconnect).forEach(this.clearReconnect, this);
|
|
44
48
|
Object.values(this.instances).forEach(i => i.disconnect());
|
|
45
49
|
}
|
|
46
50
|
reconnectAll() {
|
|
51
|
+
Object.keys(this.reconnect).forEach(this.clearReconnect, this);
|
|
47
52
|
const params = Object.values(this.instances).map(i => [i.coinInfo, i.postMessage]);
|
|
48
53
|
Object.values(this.instances).forEach(i => i.disconnect());
|
|
49
54
|
return Promise.all(params.map(p => this.getOrConnect(...p)));
|
|
@@ -55,18 +60,47 @@ class BackendManager {
|
|
|
55
60
|
}
|
|
56
61
|
}
|
|
57
62
|
setCustom(shortcut, blockchainLink) {
|
|
58
|
-
this.
|
|
63
|
+
this.setPreferred(shortcut, undefined);
|
|
59
64
|
this.custom[shortcut] = blockchainLink;
|
|
60
65
|
}
|
|
61
66
|
removeCustom(shortcut) {
|
|
62
|
-
this.
|
|
67
|
+
this.setPreferred(shortcut, undefined);
|
|
63
68
|
delete this.custom[shortcut];
|
|
64
69
|
}
|
|
70
|
+
setInstance(shortcut, instance) {
|
|
71
|
+
if (!instance)
|
|
72
|
+
delete this.instances[shortcut];
|
|
73
|
+
else
|
|
74
|
+
this.instances[shortcut] = instance;
|
|
75
|
+
}
|
|
65
76
|
setPreferred(shortcut, url) {
|
|
66
|
-
|
|
77
|
+
if (!url)
|
|
78
|
+
delete this.preferred[shortcut];
|
|
79
|
+
else
|
|
80
|
+
this.preferred[shortcut] = url;
|
|
67
81
|
}
|
|
68
|
-
|
|
69
|
-
|
|
82
|
+
planReconnect(coinInfo, postMessage, attempts) {
|
|
83
|
+
var _a;
|
|
84
|
+
const timeout = Math.min(2500 * attempts, 20000);
|
|
85
|
+
const time = Date.now() + timeout;
|
|
86
|
+
const handle = setTimeout(() => {
|
|
87
|
+
this.getOrConnect(coinInfo, postMessage).catch(() => { });
|
|
88
|
+
}, timeout);
|
|
89
|
+
clearTimeout((_a = this.reconnect[coinInfo.shortcut]) === null || _a === void 0 ? void 0 : _a.handle);
|
|
90
|
+
this.reconnect[coinInfo.shortcut] = { attempts: attempts + 1, handle };
|
|
91
|
+
postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.RECONNECTING, { coin: coinInfo, time }));
|
|
92
|
+
}
|
|
93
|
+
clearReconnect(shortcut) {
|
|
94
|
+
const reconnect = this.reconnect[shortcut];
|
|
95
|
+
clearTimeout(reconnect === null || reconnect === void 0 ? void 0 : reconnect.handle);
|
|
96
|
+
delete this.reconnect[shortcut];
|
|
97
|
+
return reconnect;
|
|
98
|
+
}
|
|
99
|
+
onDisconnected(backend, pendingSubscriptions) {
|
|
100
|
+
this.setInstance(backend.coinInfo.shortcut, undefined);
|
|
101
|
+
if (pendingSubscriptions) {
|
|
102
|
+
this.planReconnect(backend.coinInfo, backend.postMessage, 0);
|
|
103
|
+
}
|
|
70
104
|
}
|
|
71
105
|
patchCoinInfo(coinInfo) {
|
|
72
106
|
var _a, _b;
|
|
@@ -7,8 +7,7 @@ export type BlockchainOptions = {
|
|
|
7
7
|
postMessage: (message: CoreEventMessage) => void;
|
|
8
8
|
proxy?: Proxy;
|
|
9
9
|
debug?: boolean;
|
|
10
|
-
|
|
11
|
-
onDisconnected?: () => void;
|
|
10
|
+
onDisconnected?: (backend: Blockchain, pendingSubscriptions?: boolean) => void;
|
|
12
11
|
};
|
|
13
12
|
export declare class Blockchain {
|
|
14
13
|
link: BlockchainLink;
|
|
@@ -17,11 +16,12 @@ export declare class Blockchain {
|
|
|
17
16
|
postMessage: BlockchainOptions['postMessage'];
|
|
18
17
|
feeForBlock: BlockchainLinkResponse<'estimateFee'>;
|
|
19
18
|
feeTimestamp: number;
|
|
20
|
-
private onConnected;
|
|
21
19
|
private onDisconnected;
|
|
20
|
+
private initPromise?;
|
|
22
21
|
constructor(options: BlockchainOptions);
|
|
23
22
|
onError(error: ERRORS.TrezorError): void;
|
|
24
|
-
|
|
23
|
+
private initLink;
|
|
24
|
+
init(): Promise<ServerInfo>;
|
|
25
25
|
getTransactions(txs: string[]): Promise<import("@trezor/blockchain-link").Transaction[]>;
|
|
26
26
|
getTransactionHexes(txids: string[]): Promise<string[]>;
|
|
27
27
|
getCurrentFiatRates(params: {
|
|
@@ -29,7 +29,7 @@ export declare class Blockchain {
|
|
|
29
29
|
token?: string;
|
|
30
30
|
}): Promise<{
|
|
31
31
|
ts: number;
|
|
32
|
-
rates: import("@trezor/blockchain-link").
|
|
32
|
+
rates: import("@trezor/blockchain-link").FiatRatesLegacy;
|
|
33
33
|
}>;
|
|
34
34
|
getFiatRatesForTimestamps(params: {
|
|
35
35
|
currencies?: string[];
|
|
@@ -38,7 +38,7 @@ export declare class Blockchain {
|
|
|
38
38
|
}): Promise<{
|
|
39
39
|
tickers: {
|
|
40
40
|
ts: number;
|
|
41
|
-
rates: import("@trezor/blockchain-link").
|
|
41
|
+
rates: import("@trezor/blockchain-link").FiatRatesLegacy;
|
|
42
42
|
}[];
|
|
43
43
|
}>;
|
|
44
44
|
getAccountBalanceHistory(params: BlockchainLinkParams<'getAccountBalanceHistory'>): Promise<import("@trezor/blockchain-link").AccountBalanceHistory[]>;
|
|
@@ -28,7 +28,6 @@ class Blockchain {
|
|
|
28
28
|
this.feeTimestamp = 0;
|
|
29
29
|
this.coinInfo = options.coinInfo;
|
|
30
30
|
this.postMessage = options.postMessage;
|
|
31
|
-
this.onConnected = options.onConnected;
|
|
32
31
|
this.onDisconnected = options.onDisconnected;
|
|
33
32
|
const { blockchainLink } = options.coinInfo;
|
|
34
33
|
if (!blockchainLink) {
|
|
@@ -50,43 +49,54 @@ class Blockchain {
|
|
|
50
49
|
}
|
|
51
50
|
onError(error) {
|
|
52
51
|
var _a;
|
|
52
|
+
const pendingSubscriptions = this.link.listenerCount('block') ||
|
|
53
|
+
this.link.listenerCount('notification') ||
|
|
54
|
+
this.link.listenerCount('fiatRates');
|
|
53
55
|
this.link.dispose();
|
|
54
56
|
this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.ERROR, {
|
|
55
57
|
coin: this.coinInfo,
|
|
56
58
|
error: error.message,
|
|
57
59
|
code: error.code,
|
|
58
60
|
}));
|
|
59
|
-
(_a = this.onDisconnected) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
60
|
-
}
|
|
61
|
-
async
|
|
62
|
-
|
|
63
|
-
var _a;
|
|
64
|
-
const info = await this.link.getInfo();
|
|
65
|
-
this.serverInfo = info;
|
|
66
|
-
const shortcut = this.coinInfo.shortcut === 'tXRP' ? 'XRP' : this.coinInfo.shortcut;
|
|
67
|
-
if (info.shortcut.toLowerCase() !== shortcut.toLowerCase()) {
|
|
68
|
-
this.onError(constants_1.ERRORS.TypedError('Backend_Invalid'));
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
(_a = this.onConnected) === null || _a === void 0 ? void 0 : _a.call(this, info.url);
|
|
72
|
-
this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.CONNECT, {
|
|
73
|
-
coin: this.coinInfo,
|
|
74
|
-
...info,
|
|
75
|
-
}));
|
|
76
|
-
});
|
|
77
|
-
this.link.on('disconnected', () => {
|
|
78
|
-
this.onError(constants_1.ERRORS.TypedError('Backend_Disconnected'));
|
|
79
|
-
});
|
|
80
|
-
this.link.on('error', error => {
|
|
81
|
-
this.onError(constants_1.ERRORS.TypedError('Backend_Error', error.message));
|
|
82
|
-
});
|
|
61
|
+
(_a = this.onDisconnected) === null || _a === void 0 ? void 0 : _a.call(this, this, !!pendingSubscriptions);
|
|
62
|
+
}
|
|
63
|
+
async initLink() {
|
|
64
|
+
let info;
|
|
83
65
|
try {
|
|
84
66
|
await this.link.connect();
|
|
67
|
+
info = await this.link.getInfo();
|
|
85
68
|
}
|
|
86
69
|
catch (error) {
|
|
87
|
-
|
|
88
|
-
|
|
70
|
+
throw constants_1.ERRORS.TypedError('Backend_Error', error.message);
|
|
71
|
+
}
|
|
72
|
+
this.serverInfo = info;
|
|
73
|
+
const shortcut = this.coinInfo.shortcut === 'tXRP' ? 'XRP' : this.coinInfo.shortcut;
|
|
74
|
+
if (info.shortcut.toLowerCase() !== shortcut.toLowerCase()) {
|
|
75
|
+
throw constants_1.ERRORS.TypedError('Backend_Invalid');
|
|
76
|
+
}
|
|
77
|
+
this.postMessage((0, events_1.createBlockchainMessage)(events_1.BLOCKCHAIN.CONNECT, {
|
|
78
|
+
coin: this.coinInfo,
|
|
79
|
+
...info,
|
|
80
|
+
}));
|
|
81
|
+
this.link.on('disconnected', () => {
|
|
82
|
+
this.onError(constants_1.ERRORS.TypedError('Backend_Disconnected'));
|
|
83
|
+
});
|
|
84
|
+
return info;
|
|
85
|
+
}
|
|
86
|
+
init() {
|
|
87
|
+
if (!this.initPromise) {
|
|
88
|
+
this.initPromise = this.initLink()
|
|
89
|
+
.then(info => {
|
|
90
|
+
this.initPromise = Promise.resolve(info);
|
|
91
|
+
return info;
|
|
92
|
+
})
|
|
93
|
+
.catch(error => {
|
|
94
|
+
this.initPromise = Promise.reject(error);
|
|
95
|
+
this.link.dispose();
|
|
96
|
+
return this.initPromise;
|
|
97
|
+
});
|
|
89
98
|
}
|
|
99
|
+
return this.initPromise;
|
|
90
100
|
}
|
|
91
101
|
getTransactions(txs) {
|
|
92
102
|
return Promise.all(txs.map(id => this.link.getTransaction(id)));
|
package/lib/constants/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export * as ERRORS from './errors';
|
|
|
2
2
|
export * as NETWORK from './network';
|
|
3
3
|
export * as CARDANO from './cardano';
|
|
4
4
|
export * as NEM from './nem';
|
|
5
|
-
export
|
|
5
|
+
export { MessagesSchema as PROTO } from '@trezor/protobuf';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/constants/index.js
CHANGED
|
@@ -6,5 +6,6 @@ exports.ERRORS = tslib_1.__importStar(require("./errors"));
|
|
|
6
6
|
exports.NETWORK = tslib_1.__importStar(require("./network"));
|
|
7
7
|
exports.CARDANO = tslib_1.__importStar(require("./cardano"));
|
|
8
8
|
exports.NEM = tslib_1.__importStar(require("./nem"));
|
|
9
|
-
|
|
9
|
+
var protobuf_1 = require("@trezor/protobuf");
|
|
10
|
+
Object.defineProperty(exports, "PROTO", { enumerable: true, get: function () { return protobuf_1.MessagesSchema; } });
|
|
10
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Deferred } from '@trezor/utils
|
|
1
|
+
import { Deferred } from '@trezor/utils';
|
|
2
2
|
import { NETWORK } from '../constants';
|
|
3
3
|
import { CallMethodPayload, CallMethodResponse, UiRequestButtonData, UiPromiseCreator, CoreEventMessage } from '../events';
|
|
4
4
|
import type { Device } from '../device/Device';
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AbstractMethod = exports.DEFAULT_FIRMWARE_RANGE = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const connect_common_1 = require("@trezor/connect-common");
|
|
6
|
-
const
|
|
5
|
+
const utils_1 = require("@trezor/utils");
|
|
7
6
|
const DataManager_1 = require("../data/DataManager");
|
|
8
7
|
const constants_1 = require("../constants");
|
|
9
8
|
const events_1 = require("../events");
|
|
@@ -147,10 +146,10 @@ class AbstractMethod {
|
|
|
147
146
|
}
|
|
148
147
|
const version = device.getVersion().join('.');
|
|
149
148
|
if (device.firmwareStatus === 'required' ||
|
|
150
|
-
!versionUtils.isNewerOrEqual(version, range.min)) {
|
|
149
|
+
!utils_1.versionUtils.isNewerOrEqual(version, range.min)) {
|
|
151
150
|
return events_1.UI.FIRMWARE_OLD;
|
|
152
151
|
}
|
|
153
|
-
if (range.max !== '0' && versionUtils.isNewer(version, range.max)) {
|
|
152
|
+
if (range.max !== '0' && utils_1.versionUtils.isNewer(version, range.max)) {
|
|
154
153
|
if (isUsingPopup) {
|
|
155
154
|
await this.getPopupPromise().promise;
|
|
156
155
|
const uiPromise = this.createUiPromise(events_1.UI.RECEIVE_CONFIRMATION);
|
package/lib/core/index.js
CHANGED
|
@@ -4,8 +4,8 @@ exports.initCore = exports.Core = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const events_1 = tslib_1.__importDefault(require("events"));
|
|
6
6
|
const transport_1 = require("@trezor/transport");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const utils_1 = require("@trezor/utils");
|
|
8
|
+
const utils_2 = require("@trezor/utils");
|
|
9
9
|
const connect_common_1 = require("@trezor/connect-common");
|
|
10
10
|
const DataManager_1 = require("../data/DataManager");
|
|
11
11
|
const DeviceList_1 = require("../device/DeviceList");
|
|
@@ -25,13 +25,17 @@ const _callMethods = [];
|
|
|
25
25
|
let _interactionTimeout;
|
|
26
26
|
let _deviceListInitTimeout;
|
|
27
27
|
let _overridePromise;
|
|
28
|
-
const methodSynchronize = (0,
|
|
28
|
+
const methodSynchronize = (0, utils_2.getSynchronize)();
|
|
29
|
+
let waitForFirstMethod = (0, utils_1.createDeferred)();
|
|
29
30
|
const _log = (0, debug_1.initLog)('Core');
|
|
30
31
|
const postMessage = (message) => {
|
|
31
32
|
if (message.event === events_2.RESPONSE_EVENT) {
|
|
32
33
|
const index = _callMethods.findIndex(call => call && call.responseID === message.id);
|
|
33
34
|
if (index >= 0) {
|
|
34
35
|
_callMethods.splice(index, 1);
|
|
36
|
+
if (_callMethods.length === 0) {
|
|
37
|
+
waitForFirstMethod = (0, utils_1.createDeferred)();
|
|
38
|
+
}
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
_core.emit(events_2.CORE_EVENT, message);
|
|
@@ -41,7 +45,7 @@ const getPopupPromise = (requestWindow = true) => {
|
|
|
41
45
|
postMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_UI_WINDOW));
|
|
42
46
|
}
|
|
43
47
|
if (!_popupPromise) {
|
|
44
|
-
_popupPromise = (0,
|
|
48
|
+
_popupPromise = (0, utils_1.createDeferred)();
|
|
45
49
|
}
|
|
46
50
|
return _popupPromise;
|
|
47
51
|
};
|
|
@@ -50,7 +54,7 @@ const interactionTimeout = () => _interactionTimeout.start(() => {
|
|
|
50
54
|
});
|
|
51
55
|
const createUiPromise = (promiseEvent, device) => {
|
|
52
56
|
const uiPromise = {
|
|
53
|
-
...(0,
|
|
57
|
+
...(0, utils_1.createDeferred)(promiseEvent),
|
|
54
58
|
device,
|
|
55
59
|
};
|
|
56
60
|
_uiPromises.push(uiPromise);
|
|
@@ -108,6 +112,7 @@ const initDevice = async (method) => {
|
|
|
108
112
|
const isWebUsb = _deviceList.transportType() === 'WebUsbTransport';
|
|
109
113
|
let device;
|
|
110
114
|
let showDeviceSelection = isWebUsb;
|
|
115
|
+
const isUsingPopup = DataManager_1.DataManager.getSettings('popup');
|
|
111
116
|
const origin = DataManager_1.DataManager.getSettings('origin');
|
|
112
117
|
const { preferredDevice } = connect_common_1.storage.load().origin[origin] || {};
|
|
113
118
|
const preferredDeviceInList = preferredDevice && _deviceList.getDevice(preferredDevice.path);
|
|
@@ -119,13 +124,14 @@ const initDevice = async (method) => {
|
|
|
119
124
|
}
|
|
120
125
|
if (method.devicePath) {
|
|
121
126
|
device = _deviceList.getDevice(method.devicePath);
|
|
122
|
-
showDeviceSelection =
|
|
127
|
+
showDeviceSelection =
|
|
128
|
+
!device || !!(device === null || device === void 0 ? void 0 : device.unreadableError) || (device.isUnacquired() && !!isUsingPopup);
|
|
123
129
|
}
|
|
124
130
|
else {
|
|
125
131
|
const devices = _deviceList.asArray();
|
|
126
132
|
if (devices.length === 1 && !isWebUsb) {
|
|
127
133
|
device = _deviceList.getDevice(devices[0].path);
|
|
128
|
-
showDeviceSelection = !!(device === null || device === void 0 ? void 0 : device.unreadableError);
|
|
134
|
+
showDeviceSelection = !!(device === null || device === void 0 ? void 0 : device.unreadableError) || device.isUnacquired();
|
|
129
135
|
}
|
|
130
136
|
else {
|
|
131
137
|
showDeviceSelection = true;
|
|
@@ -138,7 +144,10 @@ const initDevice = async (method) => {
|
|
|
138
144
|
throw constants_1.ERRORS.TypedError('Transport_Missing');
|
|
139
145
|
}
|
|
140
146
|
const devices = _deviceList.asArray();
|
|
141
|
-
if (devices.length === 1 &&
|
|
147
|
+
if (devices.length === 1 &&
|
|
148
|
+
devices[0].type !== 'unreadable' &&
|
|
149
|
+
devices[0].features &&
|
|
150
|
+
!isWebUsb) {
|
|
142
151
|
device = _deviceList.getDevice(devices[0].path);
|
|
143
152
|
}
|
|
144
153
|
else {
|
|
@@ -196,6 +205,7 @@ const onCall = async (message) => {
|
|
|
196
205
|
await ((_a = method.initAsync) === null || _a === void 0 ? void 0 : _a.call(method));
|
|
197
206
|
return method;
|
|
198
207
|
});
|
|
208
|
+
waitForFirstMethod.resolve();
|
|
199
209
|
_callMethods.push(method);
|
|
200
210
|
}
|
|
201
211
|
catch (error) {
|
|
@@ -414,7 +424,7 @@ const onCall = async (message) => {
|
|
|
414
424
|
}
|
|
415
425
|
const response = messageResponse;
|
|
416
426
|
if (response) {
|
|
417
|
-
if (method.
|
|
427
|
+
if (method.name === 'rebootToBootloader' && response.success) {
|
|
418
428
|
await (0, promiseUtils_1.resolveAfter)(1000).promise;
|
|
419
429
|
try {
|
|
420
430
|
await device.run(() => Promise.resolve(), { skipFinalReload: true });
|
|
@@ -517,6 +527,7 @@ const onPopupClosed = (customErrorMessage) => {
|
|
|
517
527
|
postMessage((0, events_2.createResponseMessage)(m.responseID, false, { error }));
|
|
518
528
|
});
|
|
519
529
|
_callMethods.splice(0, _callMethods.length);
|
|
530
|
+
waitForFirstMethod = (0, utils_1.createDeferred)();
|
|
520
531
|
}
|
|
521
532
|
}
|
|
522
533
|
});
|
|
@@ -640,8 +651,9 @@ class Core extends events_1.default {
|
|
|
640
651
|
await _deviceList.dispose();
|
|
641
652
|
}
|
|
642
653
|
}
|
|
643
|
-
getCurrentMethod() {
|
|
644
|
-
|
|
654
|
+
async getCurrentMethod() {
|
|
655
|
+
await waitForFirstMethod.promise;
|
|
656
|
+
return await methodSynchronize(() => _callMethods[0]);
|
|
645
657
|
}
|
|
646
658
|
getTransportInfo() {
|
|
647
659
|
if (!_deviceList) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ConnectSettings } from '../types';
|
|
2
2
|
type AssetCollection = {
|
|
3
|
-
[key: string]:
|
|
3
|
+
[key: string]: Record<string, any>;
|
|
4
4
|
};
|
|
5
5
|
export declare class DataManager {
|
|
6
6
|
static assets: AssetCollection;
|
|
7
7
|
private static settings;
|
|
8
8
|
private static messages;
|
|
9
9
|
static load(settings: ConnectSettings, withAssets?: boolean): Promise<void>;
|
|
10
|
-
static getProtobufMessages():
|
|
10
|
+
static getProtobufMessages(): Record<string, any>;
|
|
11
11
|
static getSettings(key?: undefined): ConnectSettings;
|
|
12
12
|
static getSettings<T extends keyof ConnectSettings>(key: T): ConnectSettings[T];
|
|
13
13
|
static getConfig(): {
|