@trezor/connect 9.6.3 → 9.6.4-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -9
- package/README.md +1 -1
- package/lib/api/applyFlags.d.ts +1 -1
- package/lib/api/applyFlags.js +2 -2
- package/lib/api/applySettings.d.ts +1 -1
- package/lib/api/authenticateDevice.js +4 -0
- package/lib/api/authorizeCoinjoin.d.ts +1 -1
- package/lib/api/backupDevice.d.ts +1 -1
- package/lib/api/backupDevice.js +2 -2
- package/lib/api/bitcoin/TransactionComposer.d.ts +1 -1
- package/lib/api/bitcoin/inputs.d.ts +1 -1
- package/lib/api/bitcoin/transactionBytes.d.ts +2 -2
- package/lib/api/bleUnpair.js +1 -1
- package/lib/api/cancelCoinjoinAuthorization.d.ts +1 -1
- package/lib/api/cardano/api/cardanoSignTransaction.d.ts +2 -2
- package/lib/api/cardano/cardanoInputs.js +2 -2
- package/lib/api/changePin.d.ts +1 -1
- package/lib/api/changePin.js +2 -2
- package/lib/api/changeWipeCode.d.ts +1 -1
- package/lib/api/cipherKeyValue.d.ts +1 -1
- package/lib/api/eos/api/eosGetPublicKey.d.ts +1 -1
- package/lib/api/eos/api/eosSignTransaction.d.ts +1 -1
- package/lib/api/eos/eosSignTx.d.ts +20 -20
- package/lib/api/ethereum/api/ethereumGetPublicKey.d.ts +5 -5
- package/lib/api/ethereum/api/ethereumSignMessage.d.ts +1 -2
- package/lib/api/ethereum/api/ethereumVerifyMessage.d.ts +1 -1
- package/lib/api/evoluGetNode.d.ts +1 -1
- package/lib/api/evoluGetNode.js +2 -2
- package/lib/api/firmware/calculateFirmwareHash.d.ts +9 -2
- package/lib/api/firmware/calculateFirmwareHash.js +11 -1
- package/lib/api/firmware/verifyAuthenticityProof.d.ts +3 -1
- package/lib/api/firmware/verifyAuthenticityProof.js +10 -15
- package/lib/api/getCoinInfo.d.ts +34 -34
- package/lib/api/getFeatures.d.ts +1 -0
- package/lib/api/getFirmwareHash.d.ts +1 -1
- package/lib/api/getFirmwareHash.js +2 -2
- package/lib/api/getNonce.d.ts +1 -1
- package/lib/api/getOwnershipId.d.ts +1 -1
- package/lib/api/getOwnershipId.js +2 -2
- package/lib/api/getOwnershipProof.d.ts +1 -1
- package/lib/api/getOwnershipProof.js +2 -2
- package/lib/api/getPublicKey.d.ts +5 -5
- package/lib/api/loadDevice.d.ts +1 -1
- package/lib/api/loadDevice.js +2 -2
- package/lib/api/nem/api/nemSignTransaction.d.ts +1 -1
- package/lib/api/nem/nemSignTx.d.ts +9 -9
- package/lib/api/recoveryDevice.d.ts +1 -1
- package/lib/api/requestLogin.d.ts +1 -1
- package/lib/api/ripple/api/rippleSignTransaction.d.ts +1 -1
- package/lib/api/setBrightness.d.ts +1 -1
- package/lib/api/setBrightness.js +2 -2
- package/lib/api/setBusy.d.ts +1 -1
- package/lib/api/setBusy.js +2 -2
- package/lib/api/showDeviceTutorial.d.ts +1 -1
- package/lib/api/signMessage.d.ts +1 -1
- package/lib/api/solana/api/solanaComposeTransaction.d.ts +6 -0
- package/lib/api/solana/api/solanaComposeTransaction.js +9 -0
- package/lib/api/solana/api/solanaSignTransaction.js +4 -4
- package/lib/api/tezos/api/tezosGetPublicKey.d.ts +1 -1
- package/lib/api/tezos/api/tezosSignTransaction.d.ts +1 -1
- package/lib/api/tezos/tezosSignTx.d.ts +17 -17
- package/lib/api/unlockPath.d.ts +1 -1
- package/lib/core/AbstractMethod.d.ts +4 -1
- package/lib/core/index.js +8 -1
- package/lib/core/onCallFirmwareUpdate.js +42 -51
- package/lib/data/coinInfo.d.ts +94 -93
- package/lib/data/config.js +9 -1
- package/lib/data/defaultFeeLevels.d.ts +1 -1
- package/lib/data/defaultFeeLevels.js +1 -1
- package/lib/data/deviceAuthenticityBlacklist.d.ts +3 -0
- package/lib/data/deviceAuthenticityBlacklist.js +11 -0
- package/lib/data/deviceAuthenticityBlacklistConfig.d.ts +11 -0
- package/lib/data/deviceAuthenticityBlacklistConfig.js +15 -0
- package/lib/data/deviceAuthenticityConfig.js +4 -140
- package/lib/data/deviceAuthenticityConfigTypes.d.ts +0 -9
- package/lib/data/deviceAuthenticityConfigTypes.js +3 -5
- package/lib/data/firmwareInfo.d.ts +12 -7
- package/lib/data/firmwareInfo.js +58 -15
- package/lib/data/transportInfo.d.ts +11 -1
- package/lib/data/udevInfo.d.ts +9 -1
- package/lib/data/version.d.ts +1 -1
- package/lib/data/version.js +1 -1
- package/lib/device/Device.d.ts +20 -10
- package/lib/device/Device.js +95 -23
- package/lib/device/DeviceCommands.d.ts +4 -4
- package/lib/device/DeviceCurrentSession.d.ts +242 -242
- package/lib/device/DeviceCurrentSession.js +1 -1
- package/lib/device/DeviceList.d.ts +7 -4
- package/lib/device/DeviceList.js +14 -4
- package/lib/device/StateStorage.d.ts +1 -1
- package/lib/device/checkFirmwareRevision.d.ts +1 -1
- package/lib/device/checkFirmwareRevision.js +2 -2
- package/lib/device/thp/handshake.d.ts +1 -1
- package/lib/device/thp/handshake.js +14 -3
- package/lib/device/thp/index.d.ts +1 -1
- package/lib/device/thp/index.js +29 -4
- package/lib/device/thp/pairing.js +1 -3
- package/lib/device/thp/session.js +1 -1
- package/lib/device/workflow/checkFirmwareHash.js +6 -1
- package/lib/device/workflow/handshake.js +3 -7
- package/lib/device/workflow/trezorPushNotification.d.ts +3 -0
- package/lib/device/workflow/trezorPushNotification.js +76 -0
- package/lib/device/workflow/validateState.js +3 -0
- package/lib/events/call.d.ts +1 -1
- package/lib/events/device.d.ts +11 -3
- package/lib/events/device.js +5 -1
- package/lib/events/popup.d.ts +1 -1
- package/lib/events/transport.d.ts +3 -21
- package/lib/events/ui-request.d.ts +15 -8
- package/lib/tsconfig.lib.tsbuildinfo +1 -1
- package/lib/types/api/applyFlags.d.ts +1 -1
- package/lib/types/api/applySettings.d.ts +1 -0
- package/lib/types/api/authenticateDevice.d.ts +9 -10
- package/lib/types/api/authenticateDevice.js +2 -0
- package/lib/types/api/backupDevice.d.ts +1 -1
- package/lib/types/api/bitcoin/index.d.ts +1 -1
- package/lib/types/api/bleUnpair.d.ts +1 -1
- package/lib/types/api/cancelCoinjoinAuthorization.d.ts +1 -1
- package/lib/types/api/cardanoComposeTransaction.d.ts +2 -2
- package/lib/types/api/cardanoComposeTransaction.js +2 -2
- package/lib/types/api/changePin.d.ts +1 -1
- package/lib/types/api/changeWipeCode.d.ts +1 -1
- package/lib/types/api/composeTransaction.d.ts +1 -1
- package/lib/types/api/discoverAccounts.d.ts +1 -1
- package/lib/types/api/discoverAccounts.js +1 -1
- package/lib/types/api/eosSignTransaction.d.ts +1 -1
- package/lib/types/api/ethereum/index.d.ts +8 -8
- package/lib/types/api/ethereumSignMessage.d.ts +1 -1
- package/lib/types/api/ethereumSignTypedData.d.ts +1 -1
- package/lib/types/api/ethereumVerifyMessage.d.ts +1 -1
- package/lib/types/api/getAccountInfo.d.ts +1 -1
- package/lib/types/api/getAddress.d.ts +6 -6
- package/lib/types/api/getFirmwareHash.d.ts +1 -1
- package/lib/types/api/nemGetAddress.d.ts +1 -1
- package/lib/types/api/nemSignTransaction.d.ts +1 -1
- package/lib/types/api/recoveryDevice.d.ts +2 -2
- package/lib/types/api/setBusy.d.ts +1 -1
- package/lib/types/api/setProxy.d.ts +1 -1
- package/lib/types/api/showDeviceTutorial.d.ts +1 -1
- package/lib/types/api/signMessage.d.ts +1 -1
- package/lib/types/api/solana/index.d.ts +26 -3
- package/lib/types/api/solana/index.js +19 -3
- package/lib/types/api/tezosSignTransaction.d.ts +1 -1
- package/lib/types/api/thpRemoveCredentials.d.ts +1 -1
- package/lib/types/api/unlockPath.d.ts +1 -1
- package/lib/types/api/verifyMessage.d.ts +1 -1
- package/lib/types/api/wipeDevice.d.ts +1 -1
- package/lib/types/device.d.ts +9 -4
- package/lib/types/device.js +5 -3
- package/lib/types/firmware.d.ts +1 -0
- package/lib/types/settings.d.ts +2 -2
- package/lib/types/workflow.d.ts +4 -0
- package/lib/utils/assetUtils.d.ts +6 -4
- package/lib/utils/assetUtils.js +13 -2
- package/lib/utils/assets-browser.d.ts +0 -4
- package/lib/utils/assets-browser.js +3 -11
- package/lib/utils/assets.native.js +1 -1
- package/lib/utils/deviceFeaturesUtils.d.ts +1 -1
- package/lib/utils/firmwareUtils.d.ts +7 -4
- package/lib/utils/firmwareUtils.js +21 -14
- package/lib/utils/pathUtils.d.ts +3 -2
- package/lib/utils/uiPromiseManager.d.ts +9 -9
- package/package.json +13 -12
package/lib/device/Device.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FirmwareRelease } from '@trezor/device-utils';
|
|
2
|
-
import { TransportProtocol, thp as protocolThp } from '@trezor/protocol';
|
|
2
|
+
import { type DecodedTrezorPushNotification, TransportProtocol, thp as protocolThp } from '@trezor/protocol';
|
|
3
3
|
import { Session } from '@trezor/transport';
|
|
4
4
|
import { type Descriptor, type Transport } from '@trezor/transport';
|
|
5
5
|
import { TypedEmitter } from '@trezor/utils';
|
|
@@ -7,7 +7,7 @@ import { PROTO } from '../constants';
|
|
|
7
7
|
import { TypedCallProvider } from './DeviceCurrentSession';
|
|
8
8
|
import { IStateStorage } from './StateStorage';
|
|
9
9
|
import { DEVICE, DeviceButtonRequestPayload, DeviceThpCredentialsChangedPayload, DeviceThpPairingPayload, DeviceVersionChanged, UiResponsePassphrase, UiResponsePin, UiResponseThpPairingTag, UiResponseWord } from '../events';
|
|
10
|
-
import { DeviceFirmwareStatus, DeviceState, Device as DeviceTyped, DeviceUniquePath, FirmwareHashCheckResult, FirmwareReleaseConfigInfo, FirmwareType, UnavailableCapabilities, VersionArray } from '../types';
|
|
10
|
+
import { DeviceBusyStatus, DeviceFirmwareStatus, DeviceState, Device as DeviceTyped, DeviceUniquePath, FirmwareHashCheckResult, FirmwareReleaseConfigInfo, FirmwareType, UnavailableCapabilities, VersionArray } from '../types';
|
|
11
11
|
type RunOptions = {
|
|
12
12
|
skipFinalReload?: boolean;
|
|
13
13
|
keepSession?: boolean;
|
|
@@ -40,6 +40,10 @@ export interface DeviceEvents {
|
|
|
40
40
|
payload: DeviceButtonRequestPayload;
|
|
41
41
|
};
|
|
42
42
|
[DEVICE.FIRMWARE_VERSION_CHANGED]: DeviceVersionChanged['payload'];
|
|
43
|
+
[DEVICE.TREZOR_PUSH_NOTIFICATION]: {
|
|
44
|
+
device: DeviceTyped;
|
|
45
|
+
payload: DecodedTrezorPushNotification;
|
|
46
|
+
};
|
|
43
47
|
[DEVICE.THP_PAIRING]: {
|
|
44
48
|
payload: DeviceThpPairingPayload;
|
|
45
49
|
callback: (response: Result<UiResponseThpPairingTag['payload']>) => void;
|
|
@@ -51,6 +55,7 @@ interface DeviceLifecycleEvents {
|
|
|
51
55
|
[DEVICE.CONNECT_UNACQUIRED]: void;
|
|
52
56
|
[DEVICE.CHANGED]: void;
|
|
53
57
|
[DEVICE.DISCONNECT]: void;
|
|
58
|
+
[DEVICE.TREZOR_PUSH_NOTIFICATION]: DecodedTrezorPushNotification;
|
|
54
59
|
}
|
|
55
60
|
type DeviceParams = {
|
|
56
61
|
id: DeviceUniquePath;
|
|
@@ -59,17 +64,14 @@ type DeviceParams = {
|
|
|
59
64
|
};
|
|
60
65
|
export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
61
66
|
readonly transport: Transport;
|
|
62
|
-
readonly transportPath: import("@trezor/transport/lib/types").PathPublic;
|
|
63
|
-
readonly bluetoothProps: {
|
|
64
|
-
id: string;
|
|
65
|
-
} | undefined;
|
|
66
67
|
private thp;
|
|
67
|
-
|
|
68
|
+
readonly descriptor: Pick<Descriptor, 'apiType' | 'id' | 'type' | 'path'>;
|
|
68
69
|
private sessionAcquired;
|
|
69
70
|
private _protocol;
|
|
70
71
|
get protocol(): TransportProtocol;
|
|
71
72
|
getThpState(): protocolThp.ThpState | undefined;
|
|
72
73
|
private unreadableError?;
|
|
74
|
+
private channels;
|
|
73
75
|
private _firmwareStatus;
|
|
74
76
|
get firmwareStatus(): DeviceFirmwareStatus;
|
|
75
77
|
private _currentRelease?;
|
|
@@ -93,6 +95,7 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
93
95
|
recovery_type?: "NormalRecovery" | "DryRun" | "UnlockRepeatedBackup" | undefined;
|
|
94
96
|
optiga_sec?: number | undefined;
|
|
95
97
|
soc?: number | undefined;
|
|
98
|
+
firmware_corrupted?: boolean | undefined;
|
|
96
99
|
vendor: string;
|
|
97
100
|
major_version: number;
|
|
98
101
|
minor_version: number;
|
|
@@ -147,6 +150,8 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
147
150
|
get unavailableCapabilities(): Readonly<UnavailableCapabilities>;
|
|
148
151
|
private _firmwareType?;
|
|
149
152
|
get firmwareType(): FirmwareType | undefined;
|
|
153
|
+
private get possibleHIDdevice();
|
|
154
|
+
get possibleT1(): boolean;
|
|
150
155
|
private name;
|
|
151
156
|
private color?;
|
|
152
157
|
private availableTranslations;
|
|
@@ -155,11 +160,15 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
155
160
|
readonly lifecycle: TypedEmitter<DeviceLifecycleEvents>;
|
|
156
161
|
private sessionDfd?;
|
|
157
162
|
constructor({ id, transport, descriptor }: DeviceParams);
|
|
163
|
+
get transportPath(): import("@trezor/transport/lib/types").PathPublic;
|
|
158
164
|
private readonly onTransportStopped;
|
|
159
165
|
private readonly onTransportDeviceEvent;
|
|
160
166
|
private getSessionChangePromise;
|
|
161
167
|
private waitAndCompareSession;
|
|
162
168
|
acquire(): import("@trezor/transport/lib/types").AsyncResultWithTypedError<Session, "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" | "LIBUSB_ERROR_ACCESS">;
|
|
169
|
+
reset(): void;
|
|
170
|
+
setBusy(value?: DeviceBusyStatus): void;
|
|
171
|
+
subscribe(): void;
|
|
163
172
|
release(): import("@trezor/transport/lib/types").AsyncResultWithTypedError<null, "Network request failed" | "Wrong result type." | "device disconnected during action" | "unexpected error" | "session not found" | "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"> | undefined;
|
|
164
173
|
setupThp(): Promise<void>;
|
|
165
174
|
handshake(): Promise<boolean>;
|
|
@@ -178,8 +187,8 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
178
187
|
};
|
|
179
188
|
}>;
|
|
180
189
|
getPublicKey: (params: PROTO.GetPublicKey, unlock?: PROTO.UnlockPath) => Promise<{
|
|
181
|
-
descriptor?: string | undefined;
|
|
182
190
|
root_fingerprint?: number | undefined;
|
|
191
|
+
descriptor?: string | undefined;
|
|
183
192
|
node: {
|
|
184
193
|
private_key?: string | undefined;
|
|
185
194
|
depth: number;
|
|
@@ -224,9 +233,9 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
224
233
|
descriptorChecksum?: string | undefined;
|
|
225
234
|
depth: number;
|
|
226
235
|
fingerprint: number;
|
|
227
|
-
chainCode: string;
|
|
228
|
-
childNum: number;
|
|
229
236
|
xpub: string;
|
|
237
|
+
childNum: number;
|
|
238
|
+
chainCode: string;
|
|
230
239
|
}>;
|
|
231
240
|
preauthorize: (throwError: boolean) => Promise<boolean>;
|
|
232
241
|
getAccountDescriptor: (coinInfo: import("../types").CoinInfo, address_n: number[], derivationType?: PROTO.CardanoDerivationType) => Promise<import("./DeviceCommands").AccountDescriptor>;
|
|
@@ -258,6 +267,7 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
258
267
|
private _uploadTranslationData;
|
|
259
268
|
private _updateCurrentRelease;
|
|
260
269
|
private _updateFeatures;
|
|
270
|
+
private _updateFeature;
|
|
261
271
|
prompt<T extends typeof DEVICE.PIN | typeof DEVICE.PASSPHRASE | typeof DEVICE.WORD | typeof DEVICE.THP_PAIRING>(type: T, args: Omit<DeviceEvents[T], 'callback'>): Promise<Parameters<DeviceEvents[T]["callback"]>[0]>;
|
|
262
272
|
isUnacquired(): boolean;
|
|
263
273
|
isUnreadable(): boolean;
|
package/lib/device/Device.js
CHANGED
|
@@ -14,18 +14,18 @@ const checkFirmwareHashWithRetries_1 = require("./workflow/checkFirmwareHashWith
|
|
|
14
14
|
const coinInfo_1 = require("../data/coinInfo");
|
|
15
15
|
const firmwareInfo_1 = require("../data/firmwareInfo");
|
|
16
16
|
const events_1 = require("../events");
|
|
17
|
+
const types_1 = require("../types");
|
|
17
18
|
const handshake_1 = require("./workflow/handshake");
|
|
18
19
|
const assetUtils_1 = require("../utils/assetUtils");
|
|
19
20
|
const debug_1 = require("../utils/debug");
|
|
20
21
|
const deviceFeaturesUtils_1 = require("../utils/deviceFeaturesUtils");
|
|
21
22
|
const firmwareUtils_1 = require("../utils/firmwareUtils");
|
|
23
|
+
const trezorPushNotification_1 = require("./workflow/trezorPushNotification");
|
|
22
24
|
const _log = (0, debug_1.initLog)('Device');
|
|
23
25
|
class Device extends utils_1.TypedEmitter {
|
|
24
26
|
transport;
|
|
25
|
-
transportPath;
|
|
26
|
-
bluetoothProps;
|
|
27
27
|
thp;
|
|
28
|
-
|
|
28
|
+
descriptor;
|
|
29
29
|
sessionAcquired;
|
|
30
30
|
_protocol;
|
|
31
31
|
get protocol() {
|
|
@@ -35,6 +35,10 @@ class Device extends utils_1.TypedEmitter {
|
|
|
35
35
|
return this.thp;
|
|
36
36
|
}
|
|
37
37
|
unreadableError;
|
|
38
|
+
channels = {
|
|
39
|
+
'battery-level': false,
|
|
40
|
+
'trezor-push-notification': false,
|
|
41
|
+
};
|
|
38
42
|
_firmwareStatus;
|
|
39
43
|
get firmwareStatus() {
|
|
40
44
|
return this._firmwareStatus;
|
|
@@ -70,6 +74,12 @@ class Device extends utils_1.TypedEmitter {
|
|
|
70
74
|
get firmwareType() {
|
|
71
75
|
return this._firmwareType;
|
|
72
76
|
}
|
|
77
|
+
get possibleHIDdevice() {
|
|
78
|
+
return this.descriptor.type === 0 || this.descriptor.type === 2;
|
|
79
|
+
}
|
|
80
|
+
get possibleT1() {
|
|
81
|
+
return (this.descriptor.type ?? 0) <= 2;
|
|
82
|
+
}
|
|
73
83
|
name = 'Trezor';
|
|
74
84
|
color;
|
|
75
85
|
availableTranslations = {};
|
|
@@ -85,12 +95,18 @@ class Device extends utils_1.TypedEmitter {
|
|
|
85
95
|
this._protocol = protocol_1.v1;
|
|
86
96
|
this.uniquePath = id;
|
|
87
97
|
this.transport = transport;
|
|
88
|
-
this.
|
|
89
|
-
|
|
90
|
-
|
|
98
|
+
this.descriptor = {
|
|
99
|
+
id: descriptor.id,
|
|
100
|
+
apiType: descriptor.apiType,
|
|
101
|
+
type: descriptor.type,
|
|
102
|
+
path: descriptor.path,
|
|
103
|
+
};
|
|
91
104
|
this.sessionAcquired = null;
|
|
92
105
|
transport.on(transport_1.TRANSPORT.STOPPED, this.onTransportStopped);
|
|
93
|
-
transport.deviceEvents.on(this.
|
|
106
|
+
transport.deviceEvents.on(this.descriptor.path, this.onTransportDeviceEvent);
|
|
107
|
+
}
|
|
108
|
+
get transportPath() {
|
|
109
|
+
return this.descriptor.path;
|
|
94
110
|
}
|
|
95
111
|
onTransportStopped = () => this.disconnect();
|
|
96
112
|
onTransportDeviceEvent = (event) => {
|
|
@@ -136,9 +152,9 @@ class Device extends utils_1.TypedEmitter {
|
|
|
136
152
|
}
|
|
137
153
|
acquire() {
|
|
138
154
|
const sessionPromise = this.getSessionChangePromise();
|
|
139
|
-
const previous = this.transport.getDescriptor(this.
|
|
155
|
+
const previous = this.transport.getDescriptor(this.descriptor.path)?.session ?? null;
|
|
140
156
|
this.acquirePromise = this.transport
|
|
141
|
-
.acquire({ input: { path: this.
|
|
157
|
+
.acquire({ input: { path: this.descriptor.path, previous } })
|
|
142
158
|
.then(result => this.waitAndCompareSession(result, sessionPromise))
|
|
143
159
|
.then(result => {
|
|
144
160
|
if (result.success) {
|
|
@@ -156,13 +172,51 @@ class Device extends utils_1.TypedEmitter {
|
|
|
156
172
|
});
|
|
157
173
|
return this.acquirePromise;
|
|
158
174
|
}
|
|
175
|
+
reset() {
|
|
176
|
+
_log.info(`Resetting Features and ThpState`);
|
|
177
|
+
this._features = undefined;
|
|
178
|
+
this._protocol = protocol_1.v1;
|
|
179
|
+
this.thp?.resetState();
|
|
180
|
+
this.thp = undefined;
|
|
181
|
+
}
|
|
182
|
+
setBusy(value) {
|
|
183
|
+
this.busy = value;
|
|
184
|
+
}
|
|
185
|
+
subscribe() {
|
|
186
|
+
if (this.descriptor.id && this.descriptor.apiType === 'bluetooth') {
|
|
187
|
+
this.transport
|
|
188
|
+
.subscribe({
|
|
189
|
+
path: this.descriptor.id,
|
|
190
|
+
channels: ['battery-level', 'trezor-push-notification'],
|
|
191
|
+
})
|
|
192
|
+
.then(result => {
|
|
193
|
+
if (result.success) {
|
|
194
|
+
this.channels = result.payload;
|
|
195
|
+
this.lifecycle.emit(events_1.DEVICE.CHANGED);
|
|
196
|
+
}
|
|
197
|
+
if (this.channels['battery-level']) {
|
|
198
|
+
this.transport.on('battery-level', event => {
|
|
199
|
+
this._updateFeature('soc', event.data[0]);
|
|
200
|
+
this.lifecycle.emit(events_1.DEVICE.CHANGED);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if (this.channels['trezor-push-notification']) {
|
|
204
|
+
this.transport.on('trezor-push-notification', ({ id, data }) => {
|
|
205
|
+
if (id === this.descriptor.id) {
|
|
206
|
+
(0, trezorPushNotification_1.trezorPushNotificationHandler)({ device: this, message: data });
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
159
213
|
release() {
|
|
160
214
|
if (!this.sessionAcquired || this.keepTransportSession || this.releasePromise) {
|
|
161
215
|
return;
|
|
162
216
|
}
|
|
163
217
|
const sessionPromise = this.getSessionChangePromise();
|
|
164
218
|
this.releasePromise = this.transport
|
|
165
|
-
.release({ session: this.sessionAcquired, path: this.
|
|
219
|
+
.release({ session: this.sessionAcquired, path: this.descriptor.path })
|
|
166
220
|
.then(result => this.waitAndCompareSession(result, sessionPromise))
|
|
167
221
|
.then(result => {
|
|
168
222
|
if (result.success) {
|
|
@@ -214,6 +268,7 @@ class Device extends utils_1.TypedEmitter {
|
|
|
214
268
|
this.unreadableError = error.message;
|
|
215
269
|
}
|
|
216
270
|
}
|
|
271
|
+
this.subscribe();
|
|
217
272
|
return true;
|
|
218
273
|
}
|
|
219
274
|
async updateDescriptor(descriptor) {
|
|
@@ -293,8 +348,8 @@ class Device extends utils_1.TypedEmitter {
|
|
|
293
348
|
await (0, handshake_1.handshakeCancel)({ device: this, logger: _log, signal: abortSignal });
|
|
294
349
|
if (this.protocol.name === 'v2') {
|
|
295
350
|
const withInteraction = !!fn;
|
|
296
|
-
await (0, thp_1.getThpChannel)(this, withInteraction);
|
|
297
|
-
if (this.
|
|
351
|
+
this.busy = await (0, thp_1.getThpChannel)(this, withInteraction);
|
|
352
|
+
if (!this.busy) {
|
|
298
353
|
await this.getFeatures();
|
|
299
354
|
}
|
|
300
355
|
}
|
|
@@ -304,12 +359,14 @@ class Device extends utils_1.TypedEmitter {
|
|
|
304
359
|
else {
|
|
305
360
|
await this.getFeatures();
|
|
306
361
|
}
|
|
307
|
-
this.busy = false;
|
|
308
362
|
}
|
|
309
363
|
catch (error) {
|
|
310
364
|
_log.warn('Device._runInner error: ', error.message);
|
|
311
365
|
if (error.code === 'Failure_Busy') {
|
|
312
|
-
this.busy =
|
|
366
|
+
this.busy = 'busy';
|
|
367
|
+
}
|
|
368
|
+
if (error.code === 'ThpDeviceLocked') {
|
|
369
|
+
this.busy = 'pin-locked';
|
|
313
370
|
}
|
|
314
371
|
if (error.code === 'Device_ThpPairingTagInvalid') {
|
|
315
372
|
return Promise.reject(error);
|
|
@@ -546,6 +603,7 @@ class Device extends utils_1.TypedEmitter {
|
|
|
546
603
|
colors: {},
|
|
547
604
|
};
|
|
548
605
|
this.name = deviceInfo.name;
|
|
606
|
+
this.busy = undefined;
|
|
549
607
|
if (feat?.unit_color) {
|
|
550
608
|
const deviceUnitColor = feat.unit_color.toString();
|
|
551
609
|
if (deviceUnitColor in deviceInfo.colors) {
|
|
@@ -553,6 +611,14 @@ class Device extends utils_1.TypedEmitter {
|
|
|
553
611
|
}
|
|
554
612
|
}
|
|
555
613
|
}
|
|
614
|
+
_updateFeature(key, value) {
|
|
615
|
+
if (this._features) {
|
|
616
|
+
this._features = {
|
|
617
|
+
...this._features,
|
|
618
|
+
[key]: value,
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
}
|
|
556
622
|
prompt(type, args) {
|
|
557
623
|
return new Promise(callback => {
|
|
558
624
|
if (!this.listenerCount(type)) {
|
|
@@ -576,7 +642,7 @@ class Device extends utils_1.TypedEmitter {
|
|
|
576
642
|
disconnect() {
|
|
577
643
|
_log.debug('Disconnect cleanup');
|
|
578
644
|
this.transport.off(transport_1.TRANSPORT.STOPPED, this.onTransportStopped);
|
|
579
|
-
this.transport.deviceEvents.off(this.
|
|
645
|
+
this.transport.deviceEvents.off(this.descriptor.path, this.onTransportDeviceEvent);
|
|
580
646
|
this.removeAllListeners();
|
|
581
647
|
this.sessionDfd?.reject(new Error());
|
|
582
648
|
if (this.sessionAcquired) {
|
|
@@ -612,7 +678,7 @@ class Device extends utils_1.TypedEmitter {
|
|
|
612
678
|
return utils_1.versionUtils.isNewerOrEqual(version, modelVersion);
|
|
613
679
|
}
|
|
614
680
|
isUsed() {
|
|
615
|
-
return !!this.transport.getDescriptor(this.
|
|
681
|
+
return !!this.transport.getDescriptor(this.descriptor.path)?.session;
|
|
616
682
|
}
|
|
617
683
|
isUsedHere() {
|
|
618
684
|
return !!this.sessionAcquired;
|
|
@@ -649,12 +715,18 @@ class Device extends utils_1.TypedEmitter {
|
|
|
649
715
|
if (this.wasUsedElsewhere)
|
|
650
716
|
return 'used';
|
|
651
717
|
if (this.busy)
|
|
652
|
-
return
|
|
718
|
+
return this.busy;
|
|
653
719
|
return 'available';
|
|
654
720
|
}
|
|
655
721
|
toMessageObject() {
|
|
656
|
-
const { name, uniquePath: path } = this;
|
|
657
|
-
const
|
|
722
|
+
const { name, uniquePath: path, descriptor } = this;
|
|
723
|
+
const { apiType, id } = descriptor;
|
|
724
|
+
const base = { path, name, descriptor: { apiType, id } };
|
|
725
|
+
const bluetoothProps = this.descriptor.id && this.descriptor.apiType === 'bluetooth'
|
|
726
|
+
? {
|
|
727
|
+
id: (0, types_1.asBluetoothDeviceId)(this.descriptor.id),
|
|
728
|
+
}
|
|
729
|
+
: undefined;
|
|
658
730
|
if (this.unreadableError) {
|
|
659
731
|
return {
|
|
660
732
|
...base,
|
|
@@ -665,16 +737,16 @@ class Device extends utils_1.TypedEmitter {
|
|
|
665
737
|
};
|
|
666
738
|
}
|
|
667
739
|
if (this.isUnacquired()) {
|
|
668
|
-
const sessionOwner = this.transport.getDescriptor(this.
|
|
740
|
+
const sessionOwner = this.transport.getDescriptor(this.descriptor.path)?.sessionOwner;
|
|
669
741
|
return {
|
|
670
742
|
...base,
|
|
671
743
|
type: 'unacquired',
|
|
672
744
|
label: 'Unacquired device',
|
|
673
745
|
name: this.name,
|
|
674
746
|
transportSessionOwner: this.sessionAcquired ? undefined : sessionOwner,
|
|
675
|
-
bluetoothProps
|
|
747
|
+
bluetoothProps,
|
|
676
748
|
thp: this.thp?.serialize(),
|
|
677
|
-
status: this.busy ?
|
|
749
|
+
status: this.busy ? this.busy : undefined,
|
|
678
750
|
};
|
|
679
751
|
}
|
|
680
752
|
const defaultLabel = 'My Trezor';
|
|
@@ -696,7 +768,7 @@ class Device extends utils_1.TypedEmitter {
|
|
|
696
768
|
unavailableCapabilities: this.unavailableCapabilities,
|
|
697
769
|
availableTranslations: this.availableTranslations,
|
|
698
770
|
authenticityChecks: this.authenticityChecks,
|
|
699
|
-
bluetoothProps
|
|
771
|
+
bluetoothProps,
|
|
700
772
|
thp: this.thp?.serialize(),
|
|
701
773
|
};
|
|
702
774
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MessagesSchema as Messages } from '@trezor/protobuf';
|
|
2
2
|
import type { TypedCallProvider } from '../device/DeviceCurrentSession';
|
|
3
|
-
import type { BitcoinNetworkInfo, CoinInfo } from '../types';
|
|
3
|
+
import type { BitcoinNetworkInfo, CoinInfo } from '../types/coinInfo';
|
|
4
4
|
type TypedCall = Messages.TypedCall;
|
|
5
5
|
export type { TypedCall };
|
|
6
6
|
export type AccountDescriptor = {
|
|
@@ -17,8 +17,8 @@ export declare const DeviceCommands: (deviceTypedCall: TypedCallProvider) => {
|
|
|
17
17
|
};
|
|
18
18
|
}>;
|
|
19
19
|
getPublicKey: (params: Messages.GetPublicKey, unlock?: Messages.UnlockPath) => Promise<{
|
|
20
|
-
descriptor?: string | undefined;
|
|
21
20
|
root_fingerprint?: number | undefined;
|
|
21
|
+
descriptor?: string | undefined;
|
|
22
22
|
node: {
|
|
23
23
|
private_key?: string | undefined;
|
|
24
24
|
depth: number;
|
|
@@ -63,9 +63,9 @@ export declare const DeviceCommands: (deviceTypedCall: TypedCallProvider) => {
|
|
|
63
63
|
descriptorChecksum?: string | undefined;
|
|
64
64
|
depth: number;
|
|
65
65
|
fingerprint: number;
|
|
66
|
-
chainCode: string;
|
|
67
|
-
childNum: number;
|
|
68
66
|
xpub: string;
|
|
67
|
+
childNum: number;
|
|
68
|
+
chainCode: string;
|
|
69
69
|
}>;
|
|
70
70
|
preauthorize: (throwError: boolean) => Promise<boolean>;
|
|
71
71
|
getAccountDescriptor: (coinInfo: CoinInfo, address_n: number[], derivationType?: Messages.CardanoDerivationType) => Promise<AccountDescriptor>;
|