@trezor/connect 9.2.3 → 9.2.4-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -5
- package/README.md +1 -1
- package/lib/api/applyFlags.d.ts +8 -1
- package/lib/api/applyFlags.js +3 -8
- package/lib/api/applySettings.d.ts +8 -1
- package/lib/api/applySettings.js +3 -8
- package/lib/api/backupDevice.d.ts +10 -2
- package/lib/api/backupDevice.js +12 -9
- package/lib/api/binance/api/binanceGetAddress.d.ts +4 -3
- package/lib/api/binance/api/binanceGetAddress.js +8 -22
- package/lib/api/binance/api/binanceGetPublicKey.d.ts +4 -2
- package/lib/api/binance/api/binanceGetPublicKey.js +6 -18
- package/lib/api/blockchainGetCurrentFiatRates.d.ts +1 -1
- package/lib/api/blockchainGetFiatRatesForTimestamps.d.ts +1 -1
- package/lib/api/cardano/api/cardanoGetAddress.d.ts +4 -4
- package/lib/api/cardano/api/cardanoGetAddress.js +9 -39
- package/lib/api/cardano/api/cardanoGetPublicKey.d.ts +4 -3
- package/lib/api/cardano/api/cardanoGetPublicKey.js +9 -31
- package/lib/api/cardano/api/cardanoSignTransaction.d.ts +1 -13
- package/lib/api/cardano/api/cardanoSignTransaction.js +2 -75
- package/lib/api/cardano/cardanoAddressParameters.d.ts +1 -2
- package/lib/api/cardano/cardanoAddressParameters.js +4 -10
- package/lib/api/cardano/cardanoAuxiliaryData.d.ts +1 -2
- package/lib/api/cardano/cardanoAuxiliaryData.js +2 -2
- package/lib/api/changeLanguage.d.ts +8 -1
- package/lib/api/changeLanguage.js +3 -7
- package/lib/api/eos/api/eosGetPublicKey.d.ts +4 -2
- package/lib/api/eos/api/eosGetPublicKey.js +6 -18
- package/lib/api/ethereum/api/ethereumGetAddress.d.ts +4 -3
- package/lib/api/ethereum/api/ethereumGetAddress.js +4 -20
- package/lib/api/ethereum/api/ethereumGetPublicKey.d.ts +4 -2
- package/lib/api/ethereum/api/ethereumGetPublicKey.js +3 -10
- package/lib/api/firmware/index.d.ts +2 -0
- package/lib/api/firmware/index.js +5 -1
- package/lib/api/firmware/parseFirmwareHeaders.d.ts +5 -0
- package/lib/api/firmware/parseFirmwareHeaders.js +35 -0
- package/lib/api/firmware/uploadFirmware.d.ts +1 -1
- package/lib/api/firmware/uploadFirmware.js +9 -1
- package/lib/api/getAccountDescriptor.d.ts +5 -3
- package/lib/api/getAccountDescriptor.js +8 -21
- package/lib/api/getAccountInfo.d.ts +23 -7
- package/lib/api/getAccountInfo.js +12 -25
- package/lib/api/getAddress.d.ts +4 -3
- package/lib/api/getAddress.js +8 -22
- package/lib/api/getFeatures.d.ts +1 -0
- package/lib/api/getOwnershipId.d.ts +4 -2
- package/lib/api/getOwnershipId.js +4 -15
- package/lib/api/getOwnershipProof.d.ts +4 -2
- package/lib/api/getOwnershipProof.js +4 -15
- package/lib/api/getPublicKey.d.ts +5 -4
- package/lib/api/getPublicKey.js +12 -35
- package/lib/api/index.d.ts +0 -1
- package/lib/api/index.js +1 -3
- package/lib/api/nem/api/nemGetAddress.d.ts +4 -3
- package/lib/api/nem/api/nemGetAddress.js +4 -20
- package/lib/api/rebootToBootloader.d.ts +8 -2
- package/lib/api/rebootToBootloader.js +3 -10
- package/lib/api/recoveryDevice.d.ts +8 -1
- package/lib/api/recoveryDevice.js +3 -7
- package/lib/api/resetDevice.d.ts +4 -2
- package/lib/api/resetDevice.js +3 -10
- package/lib/api/ripple/api/rippleGetAddress.d.ts +4 -3
- package/lib/api/ripple/api/rippleGetAddress.js +4 -20
- package/lib/api/solana/api/solanaGetAddress.d.ts +4 -3
- package/lib/api/solana/api/solanaGetAddress.js +7 -28
- package/lib/api/solana/api/solanaGetPublicKey.d.ts +4 -3
- package/lib/api/solana/api/solanaGetPublicKey.js +7 -27
- package/lib/api/stellar/api/stellarGetAddress.d.ts +4 -3
- package/lib/api/stellar/api/stellarGetAddress.js +4 -20
- package/lib/api/tezos/api/tezosGetAddress.d.ts +4 -3
- package/lib/api/tezos/api/tezosGetAddress.js +4 -20
- package/lib/api/tezos/api/tezosGetPublicKey.d.ts +4 -2
- package/lib/api/tezos/api/tezosGetPublicKey.js +6 -18
- package/lib/api/wipeDevice.d.ts +8 -2
- package/lib/api/wipeDevice.js +3 -10
- package/lib/backend/Blockchain.d.ts +2 -2
- package/lib/constants/errors.d.ts +1 -0
- package/lib/constants/errors.js +1 -0
- package/lib/core/AbstractMethod.d.ts +4 -8
- package/lib/core/AbstractMethod.js +6 -28
- package/lib/core/index.d.ts +2 -1
- package/lib/core/index.js +258 -226
- package/lib/core/onCallFirmwareUpdate.d.ts +31 -0
- package/lib/core/onCallFirmwareUpdate.js +266 -0
- package/lib/data/DataManager.d.ts +10 -0
- package/lib/data/analyticsInfo.d.ts +2 -2
- package/lib/data/analyticsInfo.js +6 -7
- package/lib/data/config.d.ts +10 -0
- package/lib/data/config.js +15 -5
- package/lib/data/deviceAuthenticityConfig.js +8 -4
- package/lib/data/firmwareInfo.js +1 -1
- package/lib/data/version.d.ts +1 -1
- package/lib/data/version.js +5 -2
- package/lib/device/Device.d.ts +2 -2
- package/lib/device/Device.js +4 -4
- package/lib/device/DeviceCommands.d.ts +4 -16
- package/lib/device/DeviceCommands.js +10 -72
- package/lib/device/DeviceList.d.ts +7 -4
- package/lib/device/DeviceList.js +46 -40
- package/lib/events/blockchain.d.ts +2 -2
- package/lib/events/index.d.ts +1 -0
- package/lib/events/ui-request.d.ts +13 -1
- package/lib/events/ui-request.js +1 -0
- package/lib/index.js +2 -2
- package/lib/types/api/backupDevice.d.ts +2 -2
- package/lib/types/api/dispose.d.ts +1 -1
- package/lib/types/api/firmwareUpdate.d.ts +7 -6
- package/lib/types/api/firmwareUpdate.js +1 -3
- package/lib/types/index.d.ts +1 -1
- package/lib/types/settings.d.ts +1 -1
- package/lib/utils/popupPromiseManager.d.ts +8 -0
- package/lib/utils/popupPromiseManager.js +21 -0
- package/lib/utils/uiPromiseManager.d.ts +38 -0
- package/lib/utils/uiPromiseManager.js +47 -0
- package/lib/workers/workers-browser.d.ts +3 -1
- package/lib/workers/workers-browser.js +2 -2
- package/package.json +9 -9
- package/lib/api/firmwareUpdate.d.ts +0 -19
- package/lib/api/firmwareUpdate.js +0 -78
|
@@ -67,13 +67,10 @@ class DeviceCommands {
|
|
|
67
67
|
});
|
|
68
68
|
return response.message;
|
|
69
69
|
}
|
|
70
|
-
async getHDNode(params, options
|
|
70
|
+
async getHDNode(params, options) {
|
|
71
71
|
const path = params.address_n;
|
|
72
72
|
const { coinInfo, unlockPath } = options;
|
|
73
73
|
const validation = typeof options.validation === 'boolean' ? options.validation : true;
|
|
74
|
-
if (!this.device.atLeast(['1.7.2', '2.0.10']) || !coinInfo) {
|
|
75
|
-
return this.getBitcoinHDNode(path, coinInfo);
|
|
76
|
-
}
|
|
77
74
|
let network = null;
|
|
78
75
|
if (!params.script_type) {
|
|
79
76
|
params.script_type = (0, pathUtils_1.getScriptType)(path);
|
|
@@ -125,42 +122,6 @@ class DeviceCommands {
|
|
|
125
122
|
}
|
|
126
123
|
return response;
|
|
127
124
|
}
|
|
128
|
-
async getBitcoinHDNode(path, coinInfo, validation = true) {
|
|
129
|
-
let publicKey;
|
|
130
|
-
if (!validation) {
|
|
131
|
-
publicKey = await this.getPublicKey({ address_n: path });
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
const suffix = 0;
|
|
135
|
-
const childPath = path.concat([suffix]);
|
|
136
|
-
const resKey = await this.getPublicKey({ address_n: path });
|
|
137
|
-
const childKey = await this.getPublicKey({ address_n: childPath });
|
|
138
|
-
publicKey = hdnodeUtils.xpubDerive(resKey, childKey, suffix);
|
|
139
|
-
}
|
|
140
|
-
const response = {
|
|
141
|
-
path,
|
|
142
|
-
serializedPath: (0, pathUtils_1.getSerializedPath)(path),
|
|
143
|
-
childNum: publicKey.node.child_num,
|
|
144
|
-
xpub: coinInfo
|
|
145
|
-
? hdnodeUtils.convertBitcoinXpub(publicKey.xpub, coinInfo.network)
|
|
146
|
-
: publicKey.xpub,
|
|
147
|
-
chainCode: publicKey.node.chain_code,
|
|
148
|
-
publicKey: publicKey.node.public_key,
|
|
149
|
-
fingerprint: publicKey.node.fingerprint,
|
|
150
|
-
depth: publicKey.node.depth,
|
|
151
|
-
};
|
|
152
|
-
if (coinInfo) {
|
|
153
|
-
const bech32Network = (0, coinInfo_1.getBech32Network)(coinInfo);
|
|
154
|
-
const segwitNetwork = (0, coinInfo_1.getSegwitNetwork)(coinInfo);
|
|
155
|
-
if (bech32Network && (0, pathUtils_1.isBech32Path)(path)) {
|
|
156
|
-
response.xpubSegwit = hdnodeUtils.convertBitcoinXpub(publicKey.xpub, bech32Network);
|
|
157
|
-
}
|
|
158
|
-
else if (segwitNetwork && (0, pathUtils_1.isSegwitPath)(path)) {
|
|
159
|
-
response.xpubSegwit = hdnodeUtils.convertBitcoinXpub(publicKey.xpub, segwitNetwork);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return response;
|
|
163
|
-
}
|
|
164
125
|
async getAddress({ address_n, show_display, multisig, script_type, chunkify }, coinInfo) {
|
|
165
126
|
if (!script_type) {
|
|
166
127
|
script_type = (0, pathUtils_1.getScriptType)(address_n);
|
|
@@ -203,9 +164,6 @@ class DeviceCommands {
|
|
|
203
164
|
};
|
|
204
165
|
}
|
|
205
166
|
async ethereumGetPublicKey({ address_n, show_display, }) {
|
|
206
|
-
if (!this.device.atLeast(['1.8.1', '2.1.0'])) {
|
|
207
|
-
return this.getHDNode({ address_n });
|
|
208
|
-
}
|
|
209
167
|
const suffix = 0;
|
|
210
168
|
const childPath = address_n.concat([suffix]);
|
|
211
169
|
const resKey = await this.typedCall('EthereumGetPublicKey', 'EthereumPublicKey', {
|
|
@@ -239,11 +197,8 @@ class DeviceCommands {
|
|
|
239
197
|
return false;
|
|
240
198
|
}
|
|
241
199
|
}
|
|
242
|
-
getDeviceState(
|
|
243
|
-
|
|
244
|
-
return this._getAddressForNetworkType(networkType);
|
|
245
|
-
}
|
|
246
|
-
return this._getAddressForNetworkType();
|
|
200
|
+
getDeviceState() {
|
|
201
|
+
return this._getAddress();
|
|
247
202
|
}
|
|
248
203
|
async call(type, msg = {}) {
|
|
249
204
|
logger.debug('Sending', type, filterForLog(type, msg));
|
|
@@ -366,30 +321,13 @@ class DeviceCommands {
|
|
|
366
321
|
}
|
|
367
322
|
return Promise.resolve(res);
|
|
368
323
|
}
|
|
369
|
-
async
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
address_n_staking: [],
|
|
377
|
-
},
|
|
378
|
-
protocol_magic: 42,
|
|
379
|
-
network_id: 0,
|
|
380
|
-
derivation_type: 2,
|
|
381
|
-
});
|
|
382
|
-
return message.address;
|
|
383
|
-
}
|
|
384
|
-
default: {
|
|
385
|
-
const { message } = await this.typedCall('GetAddress', 'Address', {
|
|
386
|
-
address_n: [(0, pathUtils_1.toHardened)(44), (0, pathUtils_1.toHardened)(1), (0, pathUtils_1.toHardened)(0), 0, 0],
|
|
387
|
-
coin_name: 'Testnet',
|
|
388
|
-
script_type: 'SPENDADDRESS',
|
|
389
|
-
});
|
|
390
|
-
return message.address;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
324
|
+
async _getAddress() {
|
|
325
|
+
const { message } = await this.typedCall('GetAddress', 'Address', {
|
|
326
|
+
address_n: [(0, pathUtils_1.toHardened)(44), (0, pathUtils_1.toHardened)(1), (0, pathUtils_1.toHardened)(0), 0, 0],
|
|
327
|
+
coin_name: 'Testnet',
|
|
328
|
+
script_type: 'SPENDADDRESS',
|
|
329
|
+
});
|
|
330
|
+
return message.address;
|
|
393
331
|
}
|
|
394
332
|
_promptPin(type) {
|
|
395
333
|
return new Promise((resolve, reject) => {
|
|
@@ -2,7 +2,7 @@ import { TypedEmitter } from '@trezor/utils';
|
|
|
2
2
|
import { Transport, TRANSPORT, Descriptor } from '@trezor/transport';
|
|
3
3
|
import { DEVICE, TransportInfo } from '../events';
|
|
4
4
|
import { Device } from './Device';
|
|
5
|
-
import type { Device as DeviceTyped } from '../types';
|
|
5
|
+
import type { ConnectSettings, Device as DeviceTyped } from '../types';
|
|
6
6
|
interface DeviceListEvents {
|
|
7
7
|
[TRANSPORT.START]: TransportInfo;
|
|
8
8
|
[TRANSPORT.ERROR]: string;
|
|
@@ -19,7 +19,6 @@ export declare class DeviceList extends TypedEmitter<DeviceListEvents> {
|
|
|
19
19
|
devices: {
|
|
20
20
|
[path: string]: Device;
|
|
21
21
|
};
|
|
22
|
-
messages: JSON | Record<string, any>;
|
|
23
22
|
creatingDevicesDescriptors: {
|
|
24
23
|
[k: string]: Descriptor;
|
|
25
24
|
};
|
|
@@ -28,7 +27,11 @@ export declare class DeviceList extends TypedEmitter<DeviceListEvents> {
|
|
|
28
27
|
[deviceID: string]: number;
|
|
29
28
|
};
|
|
30
29
|
transportFirstEventPromise: Promise<void> | undefined;
|
|
31
|
-
|
|
30
|
+
private settings;
|
|
31
|
+
constructor({ settings, messages, }: {
|
|
32
|
+
settings: ConnectSettings;
|
|
33
|
+
messages: Record<string, any>;
|
|
34
|
+
});
|
|
32
35
|
init(): Promise<void>;
|
|
33
36
|
private resolveTransportEvent;
|
|
34
37
|
waitForTransportFirstEvent(): Promise<void>;
|
|
@@ -42,7 +45,7 @@ export declare class DeviceList extends TypedEmitter<DeviceListEvents> {
|
|
|
42
45
|
length(): number;
|
|
43
46
|
transportType(): "BridgeTransport" | "NodeUsbTransport" | "WebUsbTransport" | "UdpTransport";
|
|
44
47
|
getTransportInfo(): TransportInfo;
|
|
45
|
-
dispose():
|
|
48
|
+
dispose(): void;
|
|
46
49
|
disconnectDevices(): void;
|
|
47
50
|
enumerate(): Promise<void>;
|
|
48
51
|
addAuthPenalty(device: Device): void;
|
package/lib/device/DeviceList.js
CHANGED
|
@@ -6,62 +6,62 @@ const transport_1 = require("@trezor/transport");
|
|
|
6
6
|
const constants_1 = require("../constants");
|
|
7
7
|
const events_1 = require("../events");
|
|
8
8
|
const Device_1 = require("./Device");
|
|
9
|
-
const DataManager_1 = require("../data/DataManager");
|
|
10
9
|
const transportInfo_1 = require("../data/transportInfo");
|
|
11
10
|
const debug_1 = require("../utils/debug");
|
|
12
11
|
const promiseUtils_1 = require("../utils/promiseUtils");
|
|
13
12
|
const _log = (0, debug_1.initLog)('DeviceList');
|
|
14
13
|
let autoResolveTransportEventTimeout;
|
|
15
14
|
class DeviceList extends utils_1.TypedEmitter {
|
|
16
|
-
constructor() {
|
|
15
|
+
constructor({ settings, messages, }) {
|
|
17
16
|
super();
|
|
18
17
|
this.transports = [];
|
|
19
18
|
this.devices = {};
|
|
20
19
|
this.creatingDevicesDescriptors = {};
|
|
21
20
|
this.transportStartPending = 0;
|
|
22
21
|
this.penalizedDevices = {};
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
transports = ['BridgeTransport'];
|
|
22
|
+
this.settings = settings;
|
|
23
|
+
const transports = [...(settings.transports || [])];
|
|
24
|
+
if (!transports.length) {
|
|
25
|
+
transports.push('BridgeTransport');
|
|
28
26
|
}
|
|
29
|
-
const transportLogger = (0, debug_1.initLog)('@trezor/transport', debug);
|
|
27
|
+
const transportLogger = (0, debug_1.initLog)('@trezor/transport', this.settings.debug);
|
|
28
|
+
const abortController = new AbortController();
|
|
29
|
+
const transportCommonArgs = {
|
|
30
|
+
messages,
|
|
31
|
+
logger: transportLogger,
|
|
32
|
+
signal: abortController.signal,
|
|
33
|
+
};
|
|
30
34
|
transports.forEach(transportType => {
|
|
31
35
|
if (typeof transportType === 'string') {
|
|
32
36
|
switch (transportType) {
|
|
33
37
|
case 'WebUsbTransport':
|
|
34
|
-
this.transports.push(new transport_1.WebUsbTransport(
|
|
35
|
-
messages: this.messages,
|
|
36
|
-
logger: transportLogger,
|
|
37
|
-
}));
|
|
38
|
+
this.transports.push(new transport_1.WebUsbTransport(transportCommonArgs));
|
|
38
39
|
break;
|
|
39
40
|
case 'NodeUsbTransport':
|
|
40
|
-
this.transports.push(new transport_1.NodeUsbTransport(
|
|
41
|
-
messages: this.messages,
|
|
42
|
-
logger: transportLogger,
|
|
43
|
-
}));
|
|
41
|
+
this.transports.push(new transport_1.NodeUsbTransport(transportCommonArgs));
|
|
44
42
|
break;
|
|
45
43
|
case 'BridgeTransport':
|
|
46
44
|
this.transports.push(new transport_1.BridgeTransport({
|
|
47
45
|
latestVersion: (0, transportInfo_1.getBridgeInfo)().version.join('.'),
|
|
48
|
-
|
|
49
|
-
logger: transportLogger,
|
|
46
|
+
...transportCommonArgs,
|
|
50
47
|
}));
|
|
51
48
|
break;
|
|
52
49
|
case 'UdpTransport':
|
|
53
|
-
this.transports.push(new transport_1.UdpTransport(
|
|
54
|
-
logger: transportLogger,
|
|
55
|
-
messages: this.messages,
|
|
56
|
-
}));
|
|
50
|
+
this.transports.push(new transport_1.UdpTransport(transportCommonArgs));
|
|
57
51
|
break;
|
|
58
52
|
default:
|
|
59
53
|
throw constants_1.ERRORS.TypedError('Runtime', `DeviceList.init: transports[] of unexpected type: ${transportType}`);
|
|
60
54
|
}
|
|
61
55
|
}
|
|
56
|
+
else if (typeof transportType === 'function' && 'prototype' in transportType) {
|
|
57
|
+
const transportInstance = new transportType(transportCommonArgs);
|
|
58
|
+
if ((0, transport_1.isTransportInstance)(transportInstance)) {
|
|
59
|
+
this.transports.push(transportInstance);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
62
|
else if ((0, transport_1.isTransportInstance)(transportType)) {
|
|
63
63
|
if (!transportType.getMessage()) {
|
|
64
|
-
transportType.updateMessages(
|
|
64
|
+
transportType.updateMessages(messages);
|
|
65
65
|
}
|
|
66
66
|
this.transports.push(transportType);
|
|
67
67
|
}
|
|
@@ -90,14 +90,24 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
92
|
this.transport.on(transport_1.TRANSPORT.UPDATE, diff => {
|
|
93
|
+
diff.disconnected.forEach(descriptor => {
|
|
94
|
+
const path = descriptor.path.toString();
|
|
95
|
+
const device = this.devices[path];
|
|
96
|
+
if (device) {
|
|
97
|
+
device.disconnect();
|
|
98
|
+
delete this.devices[path];
|
|
99
|
+
this.emit(events_1.DEVICE.DISCONNECT, device.toMessageObject());
|
|
100
|
+
}
|
|
101
|
+
});
|
|
93
102
|
diff.connected.forEach(async (descriptor) => {
|
|
94
103
|
const path = descriptor.path.toString();
|
|
95
|
-
|
|
104
|
+
this.creatingDevicesDescriptors[path] = descriptor;
|
|
105
|
+
const { priority } = this.settings;
|
|
96
106
|
const penalty = this.getAuthPenalty();
|
|
97
107
|
if (priority || penalty) {
|
|
98
108
|
await (0, promiseUtils_1.resolveAfter)(501 + penalty + 100 * priority, null).promise;
|
|
99
109
|
}
|
|
100
|
-
if (
|
|
110
|
+
if (this.creatingDevicesDescriptors[path].session == null) {
|
|
101
111
|
await this._createAndSaveDevice(descriptor);
|
|
102
112
|
}
|
|
103
113
|
else {
|
|
@@ -158,20 +168,13 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
158
168
|
}
|
|
159
169
|
});
|
|
160
170
|
});
|
|
161
|
-
diff.disconnected.forEach(descriptor => {
|
|
162
|
-
const path = descriptor.path.toString();
|
|
163
|
-
const device = this.devices[path];
|
|
164
|
-
if (device) {
|
|
165
|
-
device.disconnect();
|
|
166
|
-
delete this.devices[path];
|
|
167
|
-
this.emit(events_1.DEVICE.DISCONNECT, device.toMessageObject());
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
171
|
diff.descriptors.forEach(d => {
|
|
172
|
+
this.creatingDevicesDescriptors[d.path] = d;
|
|
171
173
|
if (this.devices[d.path]) {
|
|
172
174
|
this.devices[d.path].originalDescriptor = {
|
|
173
175
|
session: d.session,
|
|
174
176
|
path: d.path,
|
|
177
|
+
product: d.product,
|
|
175
178
|
};
|
|
176
179
|
}
|
|
177
180
|
});
|
|
@@ -185,7 +188,7 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
185
188
|
return;
|
|
186
189
|
}
|
|
187
190
|
const descriptors = enumerateResult.payload;
|
|
188
|
-
if (descriptors.length > 0 &&
|
|
191
|
+
if (descriptors.length > 0 && this.settings.pendingTransportEvent) {
|
|
189
192
|
this.transportStartPending = descriptors.length;
|
|
190
193
|
this.on(events_1.DEVICE.CONNECT, this.resolveTransportEvent.bind(this));
|
|
191
194
|
this.on(events_1.DEVICE.CONNECT_UNACQUIRED, this.resolveTransportEvent.bind(this));
|
|
@@ -265,13 +268,14 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
265
268
|
outdated: this.transport.isOutdated,
|
|
266
269
|
};
|
|
267
270
|
}
|
|
268
|
-
|
|
271
|
+
dispose() {
|
|
269
272
|
this.removeAllListeners();
|
|
270
273
|
if (autoResolveTransportEventTimeout) {
|
|
271
274
|
clearTimeout(autoResolveTransportEventTimeout);
|
|
272
275
|
}
|
|
273
|
-
|
|
274
|
-
|
|
276
|
+
Promise.all(this.allDevices().map(device => device.dispose())).then(() => {
|
|
277
|
+
this.transport.stop();
|
|
278
|
+
});
|
|
275
279
|
}
|
|
276
280
|
disconnectDevices() {
|
|
277
281
|
this.allDevices().forEach(device => {
|
|
@@ -288,6 +292,7 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
288
292
|
this.devices[d.path].originalDescriptor = {
|
|
289
293
|
session: d.session,
|
|
290
294
|
path: d.path,
|
|
295
|
+
product: d.product,
|
|
291
296
|
};
|
|
292
297
|
this.devices[d.path].activitySessionID = d.session;
|
|
293
298
|
}
|
|
@@ -315,7 +320,6 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
315
320
|
async handle(descriptor) {
|
|
316
321
|
var _a;
|
|
317
322
|
const path = descriptor.path.toString();
|
|
318
|
-
this.creatingDevicesDescriptors[path] = descriptor;
|
|
319
323
|
try {
|
|
320
324
|
await this._takeAndCreateDevice(descriptor);
|
|
321
325
|
}
|
|
@@ -324,7 +328,9 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
324
328
|
if (error.code === 'Device_NotFound' ||
|
|
325
329
|
error.message === transport_1.TRANSPORT_ERROR.DEVICE_NOT_FOUND ||
|
|
326
330
|
error.message === transport_1.TRANSPORT_ERROR.DEVICE_DISCONNECTED_DURING_ACTION ||
|
|
327
|
-
error.message === transport_1.TRANSPORT_ERROR.UNEXPECTED_ERROR
|
|
331
|
+
error.message === transport_1.TRANSPORT_ERROR.UNEXPECTED_ERROR ||
|
|
332
|
+
error.message === transport_1.TRANSPORT_ERROR.DESCRIPTOR_NOT_FOUND ||
|
|
333
|
+
error.message === transport_1.TRANSPORT_ERROR.HTTP_ERROR) {
|
|
328
334
|
delete this.devices[path];
|
|
329
335
|
}
|
|
330
336
|
else if (error.message === transport_1.TRANSPORT_ERROR.SESSION_WRONG_PREVIOUS) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ServerInfo, BlockEvent,
|
|
1
|
+
import type { ServerInfo, BlockEvent, FiatRatesBySymbol, NotificationEvent } from '@trezor/blockchain-link';
|
|
2
2
|
import type { CoinInfo } from '../types/coinInfo';
|
|
3
3
|
import type { MessageFactoryFn } from '../types/utils';
|
|
4
4
|
export declare const BLOCKCHAIN_EVENT = "BLOCKCHAIN_EVENT";
|
|
@@ -37,7 +37,7 @@ export interface BlockchainNotification {
|
|
|
37
37
|
}
|
|
38
38
|
export interface BlockchainFiatRatesUpdate {
|
|
39
39
|
coin: CoinInfo;
|
|
40
|
-
rates:
|
|
40
|
+
rates: FiatRatesBySymbol;
|
|
41
41
|
}
|
|
42
42
|
export type BlockchainEvent = {
|
|
43
43
|
type: typeof BLOCKCHAIN.CONNECT;
|
package/lib/events/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export declare const UI: {
|
|
|
33
33
|
readonly FIRMWARE_NOT_COMPATIBLE: "ui-device_firmware_not_compatible";
|
|
34
34
|
readonly FIRMWARE_NOT_INSTALLED: "ui-device_firmware_not_installed";
|
|
35
35
|
readonly FIRMWARE_PROGRESS: "ui-firmware-progress";
|
|
36
|
+
readonly FIRMWARE_RECONNECT: "ui-firmware_reconnect";
|
|
36
37
|
readonly DEVICE_NEEDS_BACKUP: "ui-device_needs_backup";
|
|
37
38
|
readonly REQUEST_UI_WINDOW: "ui-request_window";
|
|
38
39
|
readonly CLOSE_UI_WINDOW: "ui-close_window";
|
|
@@ -18,6 +18,7 @@ export declare const UI_REQUEST: {
|
|
|
18
18
|
readonly FIRMWARE_NOT_COMPATIBLE: "ui-device_firmware_not_compatible";
|
|
19
19
|
readonly FIRMWARE_NOT_INSTALLED: "ui-device_firmware_not_installed";
|
|
20
20
|
readonly FIRMWARE_PROGRESS: "ui-firmware-progress";
|
|
21
|
+
readonly FIRMWARE_RECONNECT: "ui-firmware_reconnect";
|
|
21
22
|
readonly DEVICE_NEEDS_BACKUP: "ui-device_needs_backup";
|
|
22
23
|
readonly REQUEST_UI_WINDOW: "ui-request_window";
|
|
23
24
|
readonly CLOSE_UI_WINDOW: "ui-close_window";
|
|
@@ -196,10 +197,21 @@ export interface FirmwareProgress {
|
|
|
196
197
|
type: typeof UI_REQUEST.FIRMWARE_PROGRESS;
|
|
197
198
|
payload: {
|
|
198
199
|
device: Device;
|
|
200
|
+
operation: 'downloading' | 'flashing' | 'validating';
|
|
199
201
|
progress: number;
|
|
200
202
|
};
|
|
201
203
|
}
|
|
202
|
-
export
|
|
204
|
+
export interface FirmwareReconnect {
|
|
205
|
+
type: typeof UI_REQUEST.FIRMWARE_RECONNECT;
|
|
206
|
+
payload: {
|
|
207
|
+
device: Device;
|
|
208
|
+
disconnected: boolean;
|
|
209
|
+
method: 'manual' | 'auto' | 'wait';
|
|
210
|
+
target: 'normal' | 'bootloader';
|
|
211
|
+
i: number;
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
export type UiEvent = UiRequestWithoutPayload | UiRequestDeviceAction | UiRequestButton | UiRequestPermission | UiRequestConfirmation | UiRequestSelectDevice | UiRequestUnexpectedDeviceMode | UiRequestSelectAccount | UiRequestSelectFee | UpdateCustomFee | BundleProgress<any> | FirmwareProgress | FirmwareException | FirmwareReconnect | UiRequestAddressValidation | UiRequestSetOperation;
|
|
203
215
|
export type UiEventMessage = UiEvent & {
|
|
204
216
|
event: typeof UI_EVENT;
|
|
205
217
|
};
|
package/lib/events/ui-request.js
CHANGED
|
@@ -15,6 +15,7 @@ exports.UI_REQUEST = {
|
|
|
15
15
|
FIRMWARE_NOT_COMPATIBLE: 'ui-device_firmware_not_compatible',
|
|
16
16
|
FIRMWARE_NOT_INSTALLED: 'ui-device_firmware_not_installed',
|
|
17
17
|
FIRMWARE_PROGRESS: 'ui-firmware-progress',
|
|
18
|
+
FIRMWARE_RECONNECT: 'ui-firmware_reconnect',
|
|
18
19
|
DEVICE_NEEDS_BACKUP: 'ui-device_needs_backup',
|
|
19
20
|
REQUEST_UI_WINDOW: 'ui-request_window',
|
|
20
21
|
CLOSE_UI_WINDOW: 'ui-close_window',
|
package/lib/index.js
CHANGED
|
@@ -21,11 +21,11 @@ const manifest = (data) => {
|
|
|
21
21
|
manifest: data,
|
|
22
22
|
});
|
|
23
23
|
};
|
|
24
|
-
const dispose =
|
|
24
|
+
const dispose = () => {
|
|
25
25
|
exports.eventEmitter.removeAllListeners();
|
|
26
26
|
_settings = (0, connectSettings_1.parseConnectSettings)();
|
|
27
27
|
if (_core) {
|
|
28
|
-
|
|
28
|
+
_core.dispose();
|
|
29
29
|
_core = null;
|
|
30
30
|
}
|
|
31
31
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { PROTO } from '../../constants';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function backupDevice(params?:
|
|
2
|
+
import type { Params, Response } from '../params';
|
|
3
|
+
export declare function backupDevice(params?: Params<PROTO.BackupDevice>): Response<PROTO.Success>;
|
|
4
4
|
//# sourceMappingURL=backupDevice.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function dispose():
|
|
1
|
+
export declare function dispose(): void;
|
|
2
2
|
//# sourceMappingURL=dispose.d.ts.map
|
|
@@ -3,16 +3,17 @@ import type { Params, Response } from '../params';
|
|
|
3
3
|
export type FirmwareUpdate = Static<typeof FirmwareUpdate>;
|
|
4
4
|
export declare const FirmwareUpdate: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
5
5
|
binary: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUndefined>;
|
|
6
|
-
version: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TNumber>;
|
|
7
6
|
btcOnly: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
8
7
|
baseUrl: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
9
|
-
|
|
8
|
+
language: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
10
9
|
}>, import("@sinclair/typebox").TObject<{
|
|
11
10
|
binary: import("@trezor/schema-utils/lib/custom-types/array-buffer").TArrayBuffer;
|
|
12
11
|
}>]>;
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
export type FirmwareUpdateResponse = {
|
|
13
|
+
check: 'mismatch' | 'valid' | 'omitted';
|
|
14
|
+
} | {
|
|
15
|
+
check: 'other-error';
|
|
16
|
+
checkError: string;
|
|
17
|
+
};
|
|
17
18
|
export declare function firmwareUpdate(params: Params<FirmwareUpdate>): Response<FirmwareUpdateResponse>;
|
|
18
19
|
//# sourceMappingURL=firmwareUpdate.d.ts.map
|
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FirmwareUpdate = void 0;
|
|
4
4
|
const schema_utils_1 = require("@trezor/schema-utils");
|
|
5
|
-
const firmware_1 = require("../firmware");
|
|
6
5
|
exports.FirmwareUpdate = schema_utils_1.Type.Union([
|
|
7
6
|
schema_utils_1.Type.Object({
|
|
8
7
|
binary: schema_utils_1.Type.Optional(schema_utils_1.Type.Undefined()),
|
|
9
|
-
version: schema_utils_1.Type.Array(schema_utils_1.Type.Number(), { minItems: 3, maxItems: 3 }),
|
|
10
8
|
btcOnly: schema_utils_1.Type.Optional(schema_utils_1.Type.Boolean()),
|
|
11
9
|
baseUrl: schema_utils_1.Type.Optional(schema_utils_1.Type.String()),
|
|
12
|
-
|
|
10
|
+
language: schema_utils_1.Type.Optional(schema_utils_1.Type.String()),
|
|
13
11
|
}),
|
|
14
12
|
schema_utils_1.Type.Object({
|
|
15
13
|
binary: schema_utils_1.Type.ArrayBuffer(),
|
package/lib/types/index.d.ts
CHANGED
|
@@ -19,5 +19,5 @@ export type { ComposeOutput, PrecomposeResultError, PrecomposeResultNonFinal, Pr
|
|
|
19
19
|
export type { PrecomposedTransactionCardano, PrecomposedTransactionErrorCardano, PrecomposedTransactionFinalCardano, PrecomposedTransactionNonFinalCardano, } from './api/cardanoComposeTransaction';
|
|
20
20
|
export type { RecoveryDevice } from './api/recoveryDevice';
|
|
21
21
|
export type { AuthenticateDeviceResult } from './api/authenticateDevice';
|
|
22
|
-
export type { TokenInfo, TokenTransfer, InternalTransfer,
|
|
22
|
+
export type { TokenInfo, TokenTransfer, InternalTransfer, FiatRatesBySymbol, Target as TransactionTarget, AccountBalanceHistory as BlockchainAccountBalanceHistory, } from '@trezor/blockchain-link';
|
|
23
23
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/types/settings.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface ConnectSettings {
|
|
|
15
15
|
popup?: boolean;
|
|
16
16
|
transportReconnect?: boolean;
|
|
17
17
|
webusb?: boolean;
|
|
18
|
-
transports?: (Transport['name'] | Transport)[];
|
|
18
|
+
transports?: (Transport['name'] | Transport | (new (...args: any[]) => Transport))[];
|
|
19
19
|
pendingTransportEvent?: boolean;
|
|
20
20
|
lazyLoad?: boolean;
|
|
21
21
|
interactionTimeout?: number;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPopupPromiseManager = void 0;
|
|
4
|
+
const utils_1 = require("@trezor/utils");
|
|
5
|
+
const createPopupPromiseManager = () => {
|
|
6
|
+
let _popupPromise;
|
|
7
|
+
const ensure = () => _popupPromise !== null && _popupPromise !== void 0 ? _popupPromise : (_popupPromise = (0, utils_1.createDeferred)());
|
|
8
|
+
const wait = () => ensure().promise;
|
|
9
|
+
const resolve = () => ensure().resolve();
|
|
10
|
+
const isWaiting = () => !!_popupPromise;
|
|
11
|
+
const reject = (error) => {
|
|
12
|
+
_popupPromise === null || _popupPromise === void 0 ? void 0 : _popupPromise.reject(error);
|
|
13
|
+
_popupPromise = undefined;
|
|
14
|
+
};
|
|
15
|
+
const clear = () => {
|
|
16
|
+
_popupPromise = undefined;
|
|
17
|
+
};
|
|
18
|
+
return { wait, isWaiting, clear, resolve, reject };
|
|
19
|
+
};
|
|
20
|
+
exports.createPopupPromiseManager = createPopupPromiseManager;
|
|
21
|
+
//# sourceMappingURL=popupPromiseManager.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { UiPromiseCreator, UiPromiseResponse } from '../events';
|
|
2
|
+
export declare const createUiPromiseManager: (interactionTimeout: () => void) => {
|
|
3
|
+
exists: (type: UiPromiseResponse['type']) => boolean;
|
|
4
|
+
create: UiPromiseCreator;
|
|
5
|
+
resolve: (event: UiPromiseResponse) => boolean;
|
|
6
|
+
rejectAll: (error: Error) => void;
|
|
7
|
+
disconnected: (devicePath: string) => boolean;
|
|
8
|
+
get: <T extends "device-disconnect" | "popup-handshake" | "ui-receive_permission" | "ui-receive_confirmation" | "ui-receive_pin" | "ui-receive_passphrase" | "ui-receive_device" | "ui-receive_account" | "ui-receive_fee" | "ui-receive_word" | "ui-invalid_passphrase_action" | "ui-login_challenge_response">(type: T) => Promise<Extract<import("../events").UiResponsePopupHandshake, {
|
|
9
|
+
type: T;
|
|
10
|
+
}> | Extract<import("../events").UiResponsePermission, {
|
|
11
|
+
type: T;
|
|
12
|
+
}> | Extract<import("../events").UiResponseConfirmation, {
|
|
13
|
+
type: T;
|
|
14
|
+
}> | Extract<import("../events").UiResponseDevice, {
|
|
15
|
+
type: T;
|
|
16
|
+
}> | Extract<import("../events").UiResponsePin, {
|
|
17
|
+
type: T;
|
|
18
|
+
}> | Extract<import("../events").UiResponseWord, {
|
|
19
|
+
type: T;
|
|
20
|
+
}> | Extract<import("../events").UiResponsePassphrase, {
|
|
21
|
+
type: T;
|
|
22
|
+
}> | Extract<import("../events").UiResponsePassphraseAction, {
|
|
23
|
+
type: T;
|
|
24
|
+
}> | Extract<import("../events").UiResponseAccount, {
|
|
25
|
+
type: T;
|
|
26
|
+
}> | Extract<import("../events").UiResponseFee, {
|
|
27
|
+
type: T;
|
|
28
|
+
}> | Extract<import("../events").UiResponseLoginChallenge, {
|
|
29
|
+
type: T;
|
|
30
|
+
}> | Extract<{
|
|
31
|
+
type: "device-disconnect";
|
|
32
|
+
payload?: undefined;
|
|
33
|
+
}, {
|
|
34
|
+
type: T;
|
|
35
|
+
}>>;
|
|
36
|
+
clear: () => void;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=uiPromiseManager.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createUiPromiseManager = void 0;
|
|
4
|
+
const events_1 = require("../events");
|
|
5
|
+
const utils_1 = require("@trezor/utils");
|
|
6
|
+
const createUiPromiseManager = (interactionTimeout) => {
|
|
7
|
+
let _uiPromises = [];
|
|
8
|
+
const exists = (type) => _uiPromises.some(p => p.id === type);
|
|
9
|
+
const create = (promiseEvent, device) => {
|
|
10
|
+
const uiPromise = {
|
|
11
|
+
...(0, utils_1.createDeferred)(promiseEvent),
|
|
12
|
+
device,
|
|
13
|
+
};
|
|
14
|
+
_uiPromises.push(uiPromise);
|
|
15
|
+
interactionTimeout();
|
|
16
|
+
return uiPromise;
|
|
17
|
+
};
|
|
18
|
+
const resolve = (event) => {
|
|
19
|
+
const uiPromise = _uiPromises.find(p => p.id === event.type);
|
|
20
|
+
if (!uiPromise)
|
|
21
|
+
return false;
|
|
22
|
+
uiPromise.resolve(event);
|
|
23
|
+
_uiPromises = _uiPromises.filter(p => p !== uiPromise);
|
|
24
|
+
return true;
|
|
25
|
+
};
|
|
26
|
+
const rejectAll = (error) => {
|
|
27
|
+
_uiPromises.forEach(p => p.reject(error));
|
|
28
|
+
_uiPromises = [];
|
|
29
|
+
};
|
|
30
|
+
const disconnected = (devicePath) => {
|
|
31
|
+
const [toResolve, toKeep] = (0, utils_1.arrayPartition)(_uiPromises, (p) => { var _a; return ((_a = p.device) === null || _a === void 0 ? void 0 : _a.getDevicePath()) === devicePath && p.id === events_1.DEVICE.DISCONNECT; });
|
|
32
|
+
toResolve.forEach(p => p.resolve({ type: events_1.DEVICE.DISCONNECT }));
|
|
33
|
+
_uiPromises = toKeep;
|
|
34
|
+
return !!toResolve.length || toKeep.some(p => { var _a; return ((_a = p.device) === null || _a === void 0 ? void 0 : _a.getDevicePath()) === devicePath; });
|
|
35
|
+
};
|
|
36
|
+
const get = (type) => {
|
|
37
|
+
var _a;
|
|
38
|
+
const uiPromise = _uiPromises.find(p => p.id === type);
|
|
39
|
+
return (_a = uiPromise === null || uiPromise === void 0 ? void 0 : uiPromise.promise) !== null && _a !== void 0 ? _a : Promise.reject(new Error(`UiPromise ${type} doesn't exist`));
|
|
40
|
+
};
|
|
41
|
+
const clear = () => {
|
|
42
|
+
_uiPromises = [];
|
|
43
|
+
};
|
|
44
|
+
return { exists, create, resolve, rejectAll, disconnected, get, clear };
|
|
45
|
+
};
|
|
46
|
+
exports.createUiPromiseManager = createUiPromiseManager;
|
|
47
|
+
//# sourceMappingURL=uiPromiseManager.js.map
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import BlockbookWorker from '@trezor/blockchain-link/lib/workers/blockbook';
|
|
2
2
|
import RippleWorker from '@trezor/blockchain-link/lib/workers/ripple';
|
|
3
3
|
import BlockfrostWorker from '@trezor/blockchain-link/lib/workers/blockfrost';
|
|
4
|
-
import
|
|
4
|
+
import type { BaseWorker } from '@trezor/blockchain-link/lib/workers/baseWorker';
|
|
5
|
+
type WorkerAsyncImporter = () => Promise<BaseWorker<unknown>>;
|
|
6
|
+
declare const SolanaWorker: WorkerAsyncImporter;
|
|
5
7
|
declare const ElectrumWorker: undefined;
|
|
6
8
|
export { BlockbookWorker, RippleWorker, BlockfrostWorker, ElectrumWorker, SolanaWorker };
|
|
7
9
|
//# sourceMappingURL=workers-browser.d.ts.map
|
|
@@ -8,8 +8,8 @@ const ripple_1 = tslib_1.__importDefault(require("@trezor/blockchain-link/lib/wo
|
|
|
8
8
|
exports.RippleWorker = ripple_1.default;
|
|
9
9
|
const blockfrost_1 = tslib_1.__importDefault(require("@trezor/blockchain-link/lib/workers/blockfrost"));
|
|
10
10
|
exports.BlockfrostWorker = blockfrost_1.default;
|
|
11
|
-
const
|
|
12
|
-
exports.SolanaWorker =
|
|
11
|
+
const SolanaWorker = () => Promise.resolve().then(() => tslib_1.__importStar(require('@trezor/blockchain-link/lib/workers/solana'))).then(w => w.default());
|
|
12
|
+
exports.SolanaWorker = SolanaWorker;
|
|
13
13
|
const ElectrumWorker = undefined;
|
|
14
14
|
exports.ElectrumWorker = ElectrumWorker;
|
|
15
15
|
//# sourceMappingURL=workers-browser.js.map
|