@trezor/connect 9.0.11 → 9.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -3
- package/README.md +20 -3
- package/lib/api/backupDevice.d.ts +1 -1
- package/lib/api/binanceGetAddress.d.ts +1 -0
- package/lib/api/binanceGetAddress.js +4 -4
- package/lib/api/binanceGetPublicKey.d.ts +1 -0
- package/lib/api/binanceGetPublicKey.js +3 -1
- package/lib/api/binanceSignTransaction.d.ts +2 -1
- package/lib/api/binanceSignTransaction.js +3 -1
- package/lib/api/bitcoin/Fees.d.ts +2 -2
- package/lib/api/bitcoin/Fees.js +32 -90
- package/lib/api/bitcoin/TransactionComposer.d.ts +1 -2
- package/lib/api/bitcoin/TransactionComposer.js +3 -2
- package/lib/api/bitcoin/createPendingTx.d.ts +1 -0
- package/lib/api/bitcoin/createPendingTx.js +1 -0
- package/lib/api/bitcoin/refTx.d.ts +10 -2
- package/lib/api/bitcoin/refTx.js +46 -19
- package/lib/api/blockchainDisconnect.d.ts +1 -0
- package/lib/api/blockchainDisconnect.js +3 -1
- package/lib/api/blockchainEstimateFee.js +1 -1
- package/lib/api/blockchainSetCustomBackend.d.ts +1 -0
- package/lib/api/blockchainSetCustomBackend.js +3 -1
- package/lib/api/cancelCoinjoinAuthorization.d.ts +8 -0
- package/lib/api/cancelCoinjoinAuthorization.js +27 -0
- package/lib/api/cardanoGetAddress.d.ts +1 -0
- package/lib/api/cardanoGetAddress.js +4 -4
- package/lib/api/cardanoGetNativeScriptHash.d.ts +1 -0
- package/lib/api/cardanoGetNativeScriptHash.js +3 -1
- package/lib/api/cardanoGetPublicKey.d.ts +2 -0
- package/lib/api/cardanoGetPublicKey.js +12 -1
- package/lib/api/cardanoSignTransaction.d.ts +1 -0
- package/lib/api/cardanoSignTransaction.js +3 -1
- package/lib/api/checkFirmwareAuthenticity.js +2 -1
- package/lib/api/cipherKeyValue.d.ts +1 -0
- package/lib/api/cipherKeyValue.js +5 -2
- package/lib/api/composeTransaction.d.ts +3 -0
- package/lib/api/composeTransaction.js +9 -7
- package/lib/api/eosGetPublicKey.d.ts +1 -0
- package/lib/api/eosGetPublicKey.js +3 -1
- package/lib/api/eosSignTransaction.d.ts +1 -0
- package/lib/api/eosSignTransaction.js +3 -1
- package/lib/api/ethereum/ethereumDefinitions.d.ts +28 -6
- package/lib/api/ethereum/ethereumDefinitions.js +60 -1
- package/lib/api/ethereum/ethereumSignTx.d.ts +1 -1
- package/lib/api/ethereumGetAddress.d.ts +2 -0
- package/lib/api/ethereumGetAddress.js +28 -26
- package/lib/api/ethereumGetPublicKey.d.ts +1 -0
- package/lib/api/ethereumGetPublicKey.js +8 -10
- package/lib/api/ethereumSignMessage.d.ts +10 -1
- package/lib/api/ethereumSignMessage.js +14 -13
- package/lib/api/ethereumSignTransaction.d.ts +6 -0
- package/lib/api/ethereumSignTransaction.js +18 -5
- package/lib/api/ethereumSignTypedData.d.ts +6 -0
- package/lib/api/ethereumSignTypedData.js +15 -13
- package/lib/api/ethereumVerifyMessage.d.ts +1 -0
- package/lib/api/ethereumVerifyMessage.js +3 -1
- package/lib/api/getAccountInfo.d.ts +3 -0
- package/lib/api/getAccountInfo.js +3 -1
- package/lib/api/getAddress.d.ts +1 -0
- package/lib/api/getAddress.js +8 -10
- package/lib/api/getFeatures.d.ts +1 -1
- package/lib/api/getOwnershipId.d.ts +1 -0
- package/lib/api/getOwnershipId.js +3 -1
- package/lib/api/getOwnershipProof.d.ts +1 -0
- package/lib/api/getOwnershipProof.js +3 -1
- package/lib/api/getPublicKey.d.ts +2 -0
- package/lib/api/getPublicKey.js +12 -1
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.js +6 -2
- package/lib/api/nemGetAddress.d.ts +1 -0
- package/lib/api/nemGetAddress.js +4 -4
- package/lib/api/nemSignTransaction.d.ts +1 -0
- package/lib/api/nemSignTransaction.js +3 -1
- package/lib/api/rebootToBootloader.d.ts +2 -1
- package/lib/api/rebootToBootloader.js +4 -2
- package/lib/api/requestLogin.d.ts +1 -0
- package/lib/api/requestLogin.js +3 -1
- package/lib/api/resetDevice.d.ts +1 -0
- package/lib/api/resetDevice.js +3 -1
- package/lib/api/rippleGetAddress.d.ts +1 -0
- package/lib/api/rippleGetAddress.js +4 -4
- package/lib/api/rippleSignTransaction.d.ts +1 -0
- package/lib/api/rippleSignTransaction.js +3 -1
- package/lib/api/showDeviceTutorial.d.ts +8 -0
- package/lib/api/showDeviceTutorial.js +23 -0
- package/lib/api/signMessage.d.ts +1 -0
- package/lib/api/signMessage.js +5 -1
- package/lib/api/signTransaction.d.ts +1 -0
- package/lib/api/signTransaction.js +16 -4
- package/lib/api/stellarGetAddress.d.ts +1 -0
- package/lib/api/stellarGetAddress.js +4 -4
- package/lib/api/stellarSignTransaction.d.ts +1 -0
- package/lib/api/stellarSignTransaction.js +3 -1
- package/lib/api/tezosGetAddress.d.ts +1 -0
- package/lib/api/tezosGetAddress.js +4 -4
- package/lib/api/tezosGetPublicKey.d.ts +1 -0
- package/lib/api/tezosGetPublicKey.js +3 -1
- package/lib/api/tezosSignTransaction.d.ts +1 -0
- package/lib/api/tezosSignTransaction.js +3 -1
- package/lib/api/verifyMessage.d.ts +1 -0
- package/lib/api/verifyMessage.js +7 -2
- package/lib/api/wipeDevice.d.ts +2 -1
- package/lib/api/wipeDevice.js +3 -1
- package/lib/backend/Blockchain.d.ts +1 -3
- package/lib/backend/Blockchain.js +10 -6
- package/lib/constants/errors.d.ts +0 -3
- package/lib/constants/errors.js +1 -4
- package/lib/constants/index.d.ts +1 -1
- package/lib/constants/index.js +1 -1
- package/lib/core/AbstractMethod.d.ts +3 -1
- package/lib/core/AbstractMethod.js +3 -1
- package/lib/core/index.d.ts +5 -6
- package/lib/core/index.js +53 -51
- package/lib/core/method.d.ts +1 -1
- package/lib/data/DataManager.js +4 -1
- package/lib/data/analyticsInfo.js +1 -1
- package/lib/data/coinInfo.d.ts +9 -1
- package/lib/data/coinInfo.js +16 -54
- package/lib/data/config.js +12 -2
- package/lib/data/defaultFeeLevels.d.ts +17 -0
- package/lib/data/defaultFeeLevels.js +84 -0
- package/lib/data/version.d.ts +1 -1
- package/lib/data/version.js +1 -1
- package/lib/device/Device.d.ts +10 -12
- package/lib/device/Device.js +69 -102
- package/lib/device/DeviceCommands.d.ts +4 -3
- package/lib/device/DeviceCommands.js +46 -19
- package/lib/device/DeviceList.d.ts +15 -25
- package/lib/device/DeviceList.js +224 -258
- package/lib/events/popup.d.ts +8 -1
- package/lib/events/popup.js +1 -0
- package/lib/events/transport.d.ts +2 -9
- package/lib/events/transport.js +3 -10
- package/lib/events/ui-request.d.ts +2 -2
- package/lib/factory.js +2 -0
- package/lib/index.js +7 -7
- package/lib/types/account.d.ts +1 -20
- package/lib/types/api/bitcoin/index.d.ts +2 -0
- package/lib/types/api/blockchainEstimateFee.d.ts +2 -5
- package/lib/types/api/cancelCoinjoinAuthorization.d.ts +8 -0
- package/lib/types/api/cancelCoinjoinAuthorization.js +3 -0
- package/lib/types/api/index.d.ts +4 -0
- package/lib/types/api/showDeviceTutorial.d.ts +4 -0
- package/lib/types/api/showDeviceTutorial.js +3 -0
- package/lib/types/coinInfo.d.ts +5 -17
- package/lib/types/device.d.ts +5 -2
- package/lib/types/device.js +8 -0
- package/lib/types/fees.d.ts +26 -0
- package/lib/types/fees.js +3 -0
- package/lib/types/index.d.ts +2 -1
- package/lib/types/index.js +1 -0
- package/lib/types/settings.d.ts +1 -1
- package/lib/utils/assetUtils.js +3 -1
- package/lib/utils/debug.js +2 -1
- package/lib/utils/deviceFeaturesUtils.d.ts +2 -1
- package/lib/utils/deviceFeaturesUtils.js +12 -1
- package/lib/utils/urlUtils.d.ts +10 -3
- package/lib/utils/urlUtils.js +5 -9
- package/lib/workers/workers-browser.d.ts +1 -3
- package/lib/workers/workers-browser.js +1 -7
- package/lib/workers/workers-react-native.d.ts +1 -3
- package/lib/workers/workers-react-native.js +1 -7
- package/lib/workers/workers.d.ts +1 -5
- package/lib/workers/workers.js +1 -5
- package/package.json +17 -12
- package/lib/device/DescriptorStream.d.ts +0 -28
- package/lib/device/DescriptorStream.js +0 -139
- package/lib/utils/objectUtils.d.ts +0 -10
- package/lib/utils/objectUtils.js +0 -37
- package/lib/workers/RNUsbPlugin.d.ts +0 -31
- package/lib/workers/RNUsbPlugin.js +0 -65
package/lib/device/Device.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { DeviceCommands } from './DeviceCommands';
|
|
|
3
3
|
import { PROTO, NETWORK } from '../constants';
|
|
4
4
|
import { DEVICE, DeviceButtonRequestPayload } from '../events';
|
|
5
5
|
import { Deferred } from '../utils/deferred';
|
|
6
|
-
import type { Transport,
|
|
7
|
-
import
|
|
6
|
+
import type { Transport, Descriptor } from '@trezor/transport';
|
|
7
|
+
import { Device as DeviceTyped, DeviceFirmwareStatus, Features, ReleaseInfo, UnavailableCapabilities, FirmwareType } from '../types';
|
|
8
8
|
export type RunOptions = {
|
|
9
9
|
skipFinalReload?: boolean;
|
|
10
10
|
waiting?: boolean;
|
|
@@ -24,15 +24,14 @@ export interface DeviceEvents {
|
|
|
24
24
|
}
|
|
25
25
|
export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
26
26
|
transport: Transport;
|
|
27
|
-
originalDescriptor:
|
|
27
|
+
originalDescriptor: Descriptor;
|
|
28
28
|
unreadableError?: string;
|
|
29
29
|
firmwareStatus: DeviceFirmwareStatus;
|
|
30
30
|
firmwareRelease?: ReleaseInfo | null;
|
|
31
31
|
features: Features;
|
|
32
32
|
featuresNeedsReload: boolean;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
33
|
+
acquirePromise?: ReturnType<Transport['acquire']>;
|
|
34
|
+
releasePromise?: ReturnType<Transport['release']>;
|
|
36
35
|
runPromise?: Deferred<void> | null;
|
|
37
36
|
loaded: boolean;
|
|
38
37
|
inconsistent: boolean;
|
|
@@ -45,10 +44,10 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
45
44
|
externalState: string[];
|
|
46
45
|
unavailableCapabilities: UnavailableCapabilities;
|
|
47
46
|
networkTypeState: NETWORK.NetworkType[];
|
|
48
|
-
firmwareType
|
|
49
|
-
constructor(transport: Transport, descriptor:
|
|
50
|
-
static fromDescriptor(transport: Transport, originalDescriptor:
|
|
51
|
-
static createUnacquired(transport: Transport, descriptor:
|
|
47
|
+
firmwareType?: FirmwareType;
|
|
48
|
+
constructor(transport: Transport, descriptor: Descriptor);
|
|
49
|
+
static fromDescriptor(transport: Transport, originalDescriptor: Descriptor): Device;
|
|
50
|
+
static createUnacquired(transport: Transport, descriptor: Descriptor, unreadableError?: string): Device;
|
|
52
51
|
acquire(): Promise<void>;
|
|
53
52
|
release(): Promise<void>;
|
|
54
53
|
cleanup(): Promise<void>;
|
|
@@ -70,7 +69,6 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
70
69
|
getFeatures(): Promise<void>;
|
|
71
70
|
_updateFeatures(feat: Features): void;
|
|
72
71
|
isUnacquired(): boolean;
|
|
73
|
-
updateDescriptor(upcomingDescriptor: DeviceDescriptor): Promise<void>;
|
|
74
72
|
disconnect(): void;
|
|
75
73
|
isBootloader(): boolean;
|
|
76
74
|
isInitialized(): boolean;
|
|
@@ -87,7 +85,7 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
87
85
|
getDevicePath(): string;
|
|
88
86
|
isT1(): boolean;
|
|
89
87
|
hasUnexpectedMode(allow: string[], require: string[]): "ui-device_bootloader_mode" | "ui-device_not_in_bootloader_mode" | "ui-device_not_initialized" | "ui-device_seedless" | null;
|
|
90
|
-
dispose():
|
|
88
|
+
dispose(): import("packages/transport/lib/types").AbortableCall<void, "Network request failed" | "Wrong result type." | "device disconnected during action" | "unexpected error" | "Aborted by timeout" | "Aborted by signal" | "This transport can not be used in this environment" | "device not found" | "Unable to open device" | "wrong previous session" | "session not found"> | undefined;
|
|
91
89
|
getMode(): "normal" | "bootloader" | "initialize" | "seedless";
|
|
92
90
|
toMessageObject(): DeviceTyped;
|
|
93
91
|
_getNetworkTypeState(): "bitcoin" | "ethereum" | "nem" | "eos" | "stellar" | "cardano" | "ripple" | "tezos" | "binance";
|
package/lib/device/Device.js
CHANGED
|
@@ -11,6 +11,7 @@ const deviceFeaturesUtils_1 = require("../utils/deviceFeaturesUtils");
|
|
|
11
11
|
const versionUtils_1 = require("../utils/versionUtils");
|
|
12
12
|
const deferred_1 = require("../utils/deferred");
|
|
13
13
|
const debug_1 = require("../utils/debug");
|
|
14
|
+
const types_1 = require("../types");
|
|
14
15
|
const _log = (0, debug_1.initLog)('Device');
|
|
15
16
|
const parseRunOptions = (options) => {
|
|
16
17
|
if (!options)
|
|
@@ -21,7 +22,8 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
21
22
|
constructor(transport, descriptor) {
|
|
22
23
|
super();
|
|
23
24
|
this.featuresNeedsReload = false;
|
|
24
|
-
this.
|
|
25
|
+
this.acquirePromise = undefined;
|
|
26
|
+
this.releasePromise = undefined;
|
|
25
27
|
this.loaded = false;
|
|
26
28
|
this.inconsistent = false;
|
|
27
29
|
this.keepSession = false;
|
|
@@ -30,7 +32,6 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
30
32
|
this.externalState = [];
|
|
31
33
|
this.unavailableCapabilities = {};
|
|
32
34
|
this.networkTypeState = [];
|
|
33
|
-
this.firmwareType = 'regular';
|
|
34
35
|
this.transport = transport;
|
|
35
36
|
this.originalDescriptor = descriptor;
|
|
36
37
|
this.firstRunPromise = (0, deferred_1.create)();
|
|
@@ -52,54 +53,53 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
52
53
|
return device;
|
|
53
54
|
}
|
|
54
55
|
async acquire() {
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
const sessionID = await this.transport.acquire({
|
|
56
|
+
this.acquirePromise = this.transport.acquire({
|
|
57
|
+
input: {
|
|
59
58
|
path: this.originalDescriptor.path,
|
|
60
59
|
previous: this.originalDescriptor.session,
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (this.commands) {
|
|
67
|
-
this.commands.dispose();
|
|
68
|
-
}
|
|
69
|
-
this.commands = new DeviceCommands_1.DeviceCommands(this, this.transport, sessionID);
|
|
70
|
-
this.deferredActions[events_1.DEVICE.RELEASE] = (0, deferred_1.create)();
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
this.deferredActions[events_1.DEVICE.ACQUIRED].resolve();
|
|
74
|
-
delete this.deferredActions[events_1.DEVICE.ACQUIRED];
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
const acquireResult = await this.acquirePromise.promise;
|
|
63
|
+
this.acquirePromise = undefined;
|
|
64
|
+
if (!acquireResult.success) {
|
|
75
65
|
if (this.runPromise) {
|
|
76
|
-
this.runPromise.reject(error);
|
|
77
|
-
|
|
78
|
-
else {
|
|
79
|
-
throw error;
|
|
66
|
+
this.runPromise.reject(new Error(acquireResult.error));
|
|
67
|
+
this.runPromise = null;
|
|
80
68
|
}
|
|
81
|
-
|
|
69
|
+
throw acquireResult.error;
|
|
70
|
+
}
|
|
71
|
+
const sessionID = acquireResult.payload;
|
|
72
|
+
_log.debug('Expected session id:', sessionID);
|
|
73
|
+
this.activitySessionID = sessionID;
|
|
74
|
+
this.originalDescriptor.session = sessionID;
|
|
75
|
+
if (this.commands) {
|
|
76
|
+
this.commands.dispose();
|
|
82
77
|
}
|
|
78
|
+
this.commands = new DeviceCommands_1.DeviceCommands(this, this.transport, sessionID);
|
|
83
79
|
}
|
|
84
80
|
async release() {
|
|
85
|
-
if (this.isUsedHere() &&
|
|
81
|
+
if (this.isUsedHere() &&
|
|
82
|
+
!this.keepSession &&
|
|
83
|
+
this.activitySessionID &&
|
|
84
|
+
!this.releasePromise) {
|
|
86
85
|
if (this.commands) {
|
|
87
86
|
this.commands.dispose();
|
|
88
87
|
if (this.commands.callPromise) {
|
|
89
|
-
|
|
90
|
-
await this.commands.callPromise;
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
this.commands.callPromise = undefined;
|
|
94
|
-
}
|
|
88
|
+
await this.commands.callPromise.promise;
|
|
95
89
|
}
|
|
96
90
|
}
|
|
97
|
-
|
|
98
|
-
await this.
|
|
99
|
-
if (this.deferredActions[events_1.DEVICE.RELEASE])
|
|
100
|
-
await this.deferredActions[events_1.DEVICE.RELEASE].promise;
|
|
91
|
+
if (this.releasePromise) {
|
|
92
|
+
await this.releasePromise;
|
|
101
93
|
}
|
|
102
|
-
|
|
94
|
+
this.releasePromise = this.transport.release({
|
|
95
|
+
session: this.activitySessionID,
|
|
96
|
+
path: this.originalDescriptor.path,
|
|
97
|
+
});
|
|
98
|
+
const releaseResponse = await this.releasePromise.promise;
|
|
99
|
+
this.releasePromise = undefined;
|
|
100
|
+
if (releaseResponse.success) {
|
|
101
|
+
this.activitySessionID = null;
|
|
102
|
+
this.originalDescriptor.session = null;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -118,26 +118,25 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
118
118
|
return this.runPromise.promise;
|
|
119
119
|
}
|
|
120
120
|
async override(error) {
|
|
121
|
-
if (this.
|
|
122
|
-
await this.
|
|
121
|
+
if (this.acquirePromise) {
|
|
122
|
+
await this.acquirePromise.promise;
|
|
123
123
|
}
|
|
124
124
|
if (this.runPromise) {
|
|
125
125
|
await this.interruptionFromUser(error);
|
|
126
126
|
}
|
|
127
|
-
if (
|
|
128
|
-
await this.
|
|
127
|
+
if (this.releasePromise) {
|
|
128
|
+
await this.releasePromise.promise;
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
async interruptionFromUser(error) {
|
|
132
132
|
_log.debug('interruptionFromUser');
|
|
133
|
-
if (this.commands) {
|
|
134
|
-
await this.commands.cancel();
|
|
135
|
-
this.commands.dispose();
|
|
136
|
-
}
|
|
137
133
|
if (this.runPromise) {
|
|
138
134
|
this.runPromise.reject(error);
|
|
139
135
|
this.runPromise = null;
|
|
140
136
|
}
|
|
137
|
+
if (this.commands) {
|
|
138
|
+
await this.commands.cancel();
|
|
139
|
+
}
|
|
141
140
|
}
|
|
142
141
|
interruptionFromOutside() {
|
|
143
142
|
_log.debug('interruptionFromOutside');
|
|
@@ -148,9 +147,13 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
148
147
|
this.runPromise.reject(constants_1.ERRORS.TypedError('Device_UsedElsewhere'));
|
|
149
148
|
this.runPromise = null;
|
|
150
149
|
}
|
|
150
|
+
this.transport.releaseDevice(this.originalDescriptor.path);
|
|
151
151
|
}
|
|
152
152
|
async _runInner(fn, options) {
|
|
153
153
|
var _a;
|
|
154
|
+
if (this.releasePromise) {
|
|
155
|
+
await this.releasePromise.promise;
|
|
156
|
+
}
|
|
154
157
|
if (!this.isUsedHere() || ((_a = this.commands) === null || _a === void 0 ? void 0 : _a.disposed) || !this.getExternalState()) {
|
|
155
158
|
await this.acquire();
|
|
156
159
|
try {
|
|
@@ -170,15 +173,16 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
170
173
|
return this._runInner(() => Promise.resolve({}), options);
|
|
171
174
|
}
|
|
172
175
|
this.inconsistent = true;
|
|
173
|
-
await this.deferredActions[events_1.DEVICE.ACQUIRE].promise;
|
|
174
176
|
this.runPromise = null;
|
|
175
|
-
return Promise.reject(constants_1.ERRORS.TypedError('Device_InitializeFailed', `Initialize failed: ${error.message}
|
|
177
|
+
return Promise.reject(constants_1.ERRORS.TypedError('Device_InitializeFailed', `Initialize failed: ${error.message} ${error.code ? `, code: ${error.code}` : ''}`));
|
|
176
178
|
}
|
|
177
179
|
}
|
|
178
180
|
if (options.keepSession) {
|
|
179
181
|
this.keepSession = true;
|
|
180
182
|
}
|
|
181
|
-
|
|
183
|
+
if (this.listeners(events_1.DEVICE.ACQUIRED).length > 0) {
|
|
184
|
+
this.emit(events_1.DEVICE.ACQUIRED);
|
|
185
|
+
}
|
|
182
186
|
if (fn) {
|
|
183
187
|
await fn();
|
|
184
188
|
}
|
|
@@ -315,67 +319,26 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
315
319
|
if (!feat.model && feat.major_version === 1) {
|
|
316
320
|
feat.model = '1';
|
|
317
321
|
}
|
|
322
|
+
if (!feat.internal_model) {
|
|
323
|
+
feat.internal_model = (0, deviceFeaturesUtils_1.ensureInternalModelFeature)(feat.model);
|
|
324
|
+
}
|
|
318
325
|
this.features = feat;
|
|
319
326
|
this.featuresNeedsReload = false;
|
|
320
|
-
this.
|
|
321
|
-
|
|
322
|
-
feat.capabilities
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
327
|
+
if (this.getMode() !== 'bootloader') {
|
|
328
|
+
this.firmwareType =
|
|
329
|
+
feat.capabilities &&
|
|
330
|
+
feat.capabilities.length > 0 &&
|
|
331
|
+
!feat.capabilities.includes('Capability_Bitcoin_like')
|
|
332
|
+
? types_1.FirmwareType.BitcoinOnly
|
|
333
|
+
: types_1.FirmwareType.Regular;
|
|
334
|
+
}
|
|
326
335
|
}
|
|
327
336
|
isUnacquired() {
|
|
328
337
|
return this.features === undefined;
|
|
329
338
|
}
|
|
330
|
-
async updateDescriptor(upcomingDescriptor) {
|
|
331
|
-
const originalSession = this.originalDescriptor.session;
|
|
332
|
-
const upcomingSession = upcomingDescriptor.session;
|
|
333
|
-
_log.debug('updateDescriptor', 'currentSession', originalSession, 'upcoming', upcomingSession, 'lastUsedID', this.activitySessionID);
|
|
334
|
-
if (!originalSession && !upcomingSession && !this.activitySessionID) {
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
if (this.deferredActions[events_1.DEVICE.ACQUIRED]) {
|
|
338
|
-
await this.deferredActions[events_1.DEVICE.ACQUIRED].promise;
|
|
339
|
-
}
|
|
340
|
-
if (!upcomingSession) {
|
|
341
|
-
if (this.listeners(events_1.DEVICE.ACQUIRED).length > 0) {
|
|
342
|
-
this.emit(events_1.DEVICE.ACQUIRED);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
const methodStillRunning = this.commands && !this.commands.disposed;
|
|
346
|
-
if (!upcomingSession && !methodStillRunning) {
|
|
347
|
-
if (originalSession === this.activitySessionID) {
|
|
348
|
-
_log.debug('Session released by this app');
|
|
349
|
-
if (this.deferredActions[events_1.DEVICE.RELEASE]) {
|
|
350
|
-
this.deferredActions[events_1.DEVICE.RELEASE].resolve();
|
|
351
|
-
delete this.deferredActions[events_1.DEVICE.RELEASE];
|
|
352
|
-
}
|
|
353
|
-
this.activitySessionID = null;
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
_log.debug('Session released by other app');
|
|
357
|
-
this.featuresNeedsReload = true;
|
|
358
|
-
}
|
|
359
|
-
this.keepSession = false;
|
|
360
|
-
}
|
|
361
|
-
else if (upcomingSession === this.activitySessionID) {
|
|
362
|
-
_log.debug('Session acquired by this app');
|
|
363
|
-
if (this.deferredActions[events_1.DEVICE.ACQUIRE]) {
|
|
364
|
-
this.deferredActions[events_1.DEVICE.ACQUIRE].resolve();
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
else {
|
|
368
|
-
_log.debug('Session acquired by other app');
|
|
369
|
-
this.interruptionFromOutside();
|
|
370
|
-
}
|
|
371
|
-
this.originalDescriptor = upcomingDescriptor;
|
|
372
|
-
}
|
|
373
339
|
disconnect() {
|
|
374
340
|
_log.debug('Disconnect cleanup');
|
|
375
|
-
|
|
376
|
-
this.deferredActions[events_1.DEVICE.RELEASE].resolve();
|
|
377
|
-
delete this.deferredActions[events_1.DEVICE.RELEASE];
|
|
378
|
-
}
|
|
341
|
+
this.activitySessionID = null;
|
|
379
342
|
this.interruptionFromUser(constants_1.ERRORS.TypedError('Device_Disconnected'));
|
|
380
343
|
this.runPromise = null;
|
|
381
344
|
}
|
|
@@ -454,7 +417,11 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
454
417
|
if (this.commands) {
|
|
455
418
|
this.commands.cancel();
|
|
456
419
|
}
|
|
457
|
-
return this.transport.release(
|
|
420
|
+
return this.transport.release({
|
|
421
|
+
session: this.activitySessionID,
|
|
422
|
+
path: this.originalDescriptor.path,
|
|
423
|
+
onClose: true,
|
|
424
|
+
});
|
|
458
425
|
}
|
|
459
426
|
catch (err) {
|
|
460
427
|
}
|
|
@@ -11,7 +11,7 @@ export type TypedResponseMessage<T extends MessageKey> = {
|
|
|
11
11
|
type TypedCallResponseMap = {
|
|
12
12
|
[K in keyof MessageType]: TypedResponseMessage<K>;
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
type DefaultMessageResponse = TypedCallResponseMap[keyof MessageType];
|
|
15
15
|
export type PassphrasePromptResponse = {
|
|
16
16
|
passphrase?: string;
|
|
17
17
|
passphraseOnDevice?: boolean;
|
|
@@ -22,8 +22,9 @@ export declare class DeviceCommands {
|
|
|
22
22
|
transport: Transport;
|
|
23
23
|
sessionId: string;
|
|
24
24
|
disposed: boolean;
|
|
25
|
-
callPromise?:
|
|
25
|
+
callPromise?: ReturnType<Transport['call']>;
|
|
26
26
|
_cancelableRequest?: (error?: any) => void;
|
|
27
|
+
_cancelableRequestBySend?: boolean;
|
|
27
28
|
constructor(device: Device, transport: Transport, sessionId: string);
|
|
28
29
|
dispose(): void;
|
|
29
30
|
isDisposed(): boolean;
|
|
@@ -48,7 +49,7 @@ export declare class DeviceCommands {
|
|
|
48
49
|
ethereumGetPublicKey({ address_n, show_display, }: Messages.EthereumGetPublicKey): Promise<HDNodeResponse>;
|
|
49
50
|
preauthorize(throwError: boolean): Promise<boolean>;
|
|
50
51
|
getDeviceState(networkType?: string): Promise<string>;
|
|
51
|
-
call
|
|
52
|
+
private call;
|
|
52
53
|
typedCall<T extends MessageKey, R extends MessageKey[]>(type: T, resType: R, msg?: MessageType[T]): Promise<TypedCallResponseMap[R[number]]>;
|
|
53
54
|
typedCall<T extends MessageKey, R extends MessageKey>(type: T, resType: R, msg?: MessageType[T]): Promise<TypedResponseMessage<R>>;
|
|
54
55
|
_commonCall(type: MessageKey, msg?: DefaultMessageResponse['message']): Promise<DefaultMessageResponse>;
|
|
@@ -240,20 +240,20 @@ class DeviceCommands {
|
|
|
240
240
|
return this._getAddressForNetworkType();
|
|
241
241
|
}
|
|
242
242
|
async call(type, msg = {}) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
243
|
+
logger.debug('Sending', type, filterForLog(type, msg));
|
|
244
|
+
this.callPromise = this.transport.call({
|
|
245
|
+
session: this.sessionId,
|
|
246
|
+
name: type,
|
|
247
|
+
data: msg,
|
|
248
|
+
});
|
|
249
|
+
const res = await this.callPromise.promise;
|
|
250
|
+
this.callPromise = undefined;
|
|
251
|
+
if (!res.success) {
|
|
252
|
+
logger.warn('Received error', res.error);
|
|
253
|
+
throw new Error(res.error);
|
|
254
|
+
}
|
|
255
|
+
logger.debug('Received', res.payload.type, filterForLog(res.payload.type, res.payload.message));
|
|
256
|
+
return res.payload;
|
|
257
257
|
}
|
|
258
258
|
async typedCall(type, resType, msg) {
|
|
259
259
|
if (this.disposed) {
|
|
@@ -264,16 +264,20 @@ class DeviceCommands {
|
|
|
264
264
|
assertType(response, resType);
|
|
265
265
|
}
|
|
266
266
|
catch (error) {
|
|
267
|
-
await this.transport.
|
|
267
|
+
await this.transport.receive({ session: this.sessionId });
|
|
268
268
|
throw error;
|
|
269
269
|
}
|
|
270
270
|
return response;
|
|
271
271
|
}
|
|
272
272
|
async _commonCall(type, msg) {
|
|
273
273
|
const resp = await this.call(type, msg);
|
|
274
|
+
if (this.disposed) {
|
|
275
|
+
throw constants_1.ERRORS.TypedError('Runtime', 'typedCall: DeviceCommands already disposed');
|
|
276
|
+
}
|
|
274
277
|
return this._filterCommonTypes(resp);
|
|
275
278
|
}
|
|
276
279
|
_filterCommonTypes(res) {
|
|
280
|
+
this._cancelableRequestBySend = false;
|
|
277
281
|
if (res.type === 'Failure') {
|
|
278
282
|
const { code } = res.message;
|
|
279
283
|
let { message } = res.message;
|
|
@@ -289,6 +293,7 @@ class DeviceCommands {
|
|
|
289
293
|
return Promise.resolve(res);
|
|
290
294
|
}
|
|
291
295
|
if (res.type === 'ButtonRequest') {
|
|
296
|
+
this._cancelableRequestBySend = true;
|
|
292
297
|
if (res.message.code === '_Deprecated_ButtonRequest_PassphraseType') {
|
|
293
298
|
res.message.code = 'ButtonRequest_PassphraseType';
|
|
294
299
|
}
|
|
@@ -306,7 +311,12 @@ class DeviceCommands {
|
|
|
306
311
|
});
|
|
307
312
|
}
|
|
308
313
|
if (res.type === 'PinMatrixRequest') {
|
|
309
|
-
return this._promptPin(res.message.type).then(pin => this._commonCall('PinMatrixAck', { pin })
|
|
314
|
+
return this._promptPin(res.message.type).then(pin => this._commonCall('PinMatrixAck', { pin }).then(response => {
|
|
315
|
+
if (!this.device.features.unlocked) {
|
|
316
|
+
return this.device.getFeatures().then(() => response);
|
|
317
|
+
}
|
|
318
|
+
return response;
|
|
319
|
+
}), () => this._commonCall('Cancel', {}));
|
|
310
320
|
}
|
|
311
321
|
if (res.type === 'PassphraseRequest') {
|
|
312
322
|
const state = this.device.getInternalState();
|
|
@@ -475,13 +485,30 @@ class DeviceCommands {
|
|
|
475
485
|
if (this.disposed) {
|
|
476
486
|
return;
|
|
477
487
|
}
|
|
488
|
+
this.dispose();
|
|
489
|
+
if (!this._cancelableRequestBySend) {
|
|
490
|
+
if (this.callPromise) {
|
|
491
|
+
await this.callPromise.promise;
|
|
492
|
+
}
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
478
495
|
const { name, version } = this.transport;
|
|
479
496
|
if (name === 'BridgeTransport' && (0, versionUtils_1.versionCompare)(version, '2.0.28') < 1) {
|
|
480
|
-
|
|
497
|
+
try {
|
|
498
|
+
await this.device.legacyForceRelease();
|
|
499
|
+
}
|
|
500
|
+
catch (err) {
|
|
501
|
+
}
|
|
481
502
|
}
|
|
482
503
|
else {
|
|
483
|
-
await this.transport.
|
|
484
|
-
|
|
504
|
+
await this.transport.send({
|
|
505
|
+
session: this.sessionId,
|
|
506
|
+
name: 'Cancel',
|
|
507
|
+
data: {},
|
|
508
|
+
}).promise;
|
|
509
|
+
if (this.callPromise) {
|
|
510
|
+
await this.callPromise.promise;
|
|
511
|
+
}
|
|
485
512
|
}
|
|
486
513
|
}
|
|
487
514
|
}
|
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
|
2
|
-
import { Transport,
|
|
3
|
-
import {
|
|
4
|
-
import { DescriptorStream } from './DescriptorStream';
|
|
2
|
+
import { Transport, TRANSPORT, Descriptor } from '@trezor/transport';
|
|
3
|
+
import { DEVICE, TransportInfo } from '../events';
|
|
5
4
|
import { Device } from './Device';
|
|
6
5
|
import type { Device as DeviceTyped } from '../types';
|
|
7
|
-
type LowLevelPlugin = {
|
|
8
|
-
name: 'WebUsbPlugin' | 'ReactNativePlugin';
|
|
9
|
-
unreadableHidDeviceChange: {
|
|
10
|
-
on: (event: string, fn: any) => void;
|
|
11
|
-
};
|
|
12
|
-
unreadableHidDevice: boolean;
|
|
13
|
-
};
|
|
14
6
|
interface DeviceListEvents {
|
|
15
7
|
[TRANSPORT.START]: TransportInfo;
|
|
16
8
|
[TRANSPORT.ERROR]: string;
|
|
17
|
-
[TRANSPORT.STREAM]: DescriptorStream;
|
|
18
9
|
[DEVICE.CONNECT]: DeviceTyped;
|
|
19
10
|
[DEVICE.CONNECT_UNACQUIRED]: DeviceTyped;
|
|
20
11
|
[DEVICE.DISCONNECT]: DeviceTyped;
|
|
@@ -24,42 +15,41 @@ interface DeviceListEvents {
|
|
|
24
15
|
}
|
|
25
16
|
export declare class DeviceList extends TypedEmitter<DeviceListEvents> {
|
|
26
17
|
transport: Transport;
|
|
27
|
-
|
|
28
|
-
stream: DescriptorStream;
|
|
18
|
+
transports: Transport[];
|
|
29
19
|
devices: {
|
|
30
20
|
[path: string]: Device;
|
|
31
21
|
};
|
|
22
|
+
messages: JSON | Record<string, any>;
|
|
32
23
|
creatingDevicesDescriptors: {
|
|
33
|
-
[k: string]:
|
|
24
|
+
[k: string]: Descriptor;
|
|
34
25
|
};
|
|
35
|
-
messages: JSON | Record<string, any>;
|
|
36
26
|
transportStartPending: number;
|
|
37
27
|
penalizedDevices: {
|
|
38
28
|
[deviceID: string]: number;
|
|
39
29
|
};
|
|
40
|
-
fetchController?: AbortController | null;
|
|
41
30
|
constructor();
|
|
42
31
|
init(): Promise<void>;
|
|
43
|
-
resolveTransportEvent
|
|
32
|
+
private resolveTransportEvent;
|
|
44
33
|
waitForTransportFirstEvent(): Promise<void>;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
_createUnreadableDevice(descriptor: DeviceDescriptor, unreadableError: string): Device;
|
|
34
|
+
private _createAndSaveDevice;
|
|
35
|
+
private _createUnacquiredDevice;
|
|
36
|
+
private _createUnreadableDevice;
|
|
49
37
|
getDevice(path: string): Device;
|
|
50
38
|
getFirstDevicePath(): string;
|
|
51
39
|
asArray(): DeviceTyped[];
|
|
52
40
|
allDevices(): Device[];
|
|
53
41
|
length(): number;
|
|
54
|
-
transportType():
|
|
42
|
+
transportType(): "BridgeTransport" | "NodeUsbTransport" | "WebUsbTransport";
|
|
55
43
|
getTransportInfo(): TransportInfo;
|
|
56
44
|
dispose(): Promise<void>;
|
|
57
45
|
disconnectDevices(): void;
|
|
58
|
-
enumerate(): void
|
|
46
|
+
enumerate(): Promise<void>;
|
|
59
47
|
addAuthPenalty(device: Device): void;
|
|
60
|
-
getAuthPenalty
|
|
48
|
+
private getAuthPenalty;
|
|
61
49
|
removeAuthPenalty(device: Device): void;
|
|
50
|
+
private handle;
|
|
51
|
+
private _takeAndCreateDevice;
|
|
52
|
+
private _handleUsedElsewhere;
|
|
62
53
|
}
|
|
63
|
-
export declare const getDeviceList: () => Promise<DeviceList>;
|
|
64
54
|
export {};
|
|
65
55
|
//# sourceMappingURL=DeviceList.d.ts.map
|