@trezor/connect 9.4.3-beta.1 → 9.4.3-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 +43 -4
- package/README.md +1 -1
- package/lib/api/applyFlags.js +1 -1
- package/lib/api/applySettings.js +1 -1
- package/lib/api/authenticateDevice.js +1 -1
- package/lib/api/authorizeCoinjoin.js +1 -1
- package/lib/api/backupDevice.js +1 -1
- package/lib/api/binance/api/binanceGetAddress.js +2 -1
- package/lib/api/binance/api/binanceGetPublicKey.js +2 -1
- package/lib/api/binance/api/binanceSignTransaction.js +2 -1
- package/lib/api/binance/binanceSignTx.js +1 -1
- package/lib/api/bitcoin/Fees.js +2 -2
- package/lib/api/bitcoin/TransactionComposer.d.ts +3 -3
- package/lib/api/bitcoin/TransactionComposer.js +2 -2
- package/lib/api/bitcoin/refTx.js +1 -1
- package/lib/api/blockchainDisconnect.js +1 -1
- package/lib/api/blockchainEvmRpcCall.d.ts +16 -0
- package/lib/api/blockchainEvmRpcCall.js +45 -0
- package/lib/api/cancelCoinjoinAuthorization.js +1 -1
- package/lib/api/cardano/api/cardanoGetAddress.js +2 -1
- package/lib/api/cardano/api/cardanoGetNativeScriptHash.js +2 -1
- package/lib/api/cardano/api/cardanoGetPublicKey.js +2 -1
- package/lib/api/cardano/api/cardanoSignTransaction.js +2 -1
- package/lib/api/cardano/cardanoAddressParameters.js +1 -1
- package/lib/api/cardano/cardanoAuxiliaryData.js +1 -1
- package/lib/api/cardano/cardanoCertificate.js +1 -1
- package/lib/api/cardano/cardanoInputs.d.ts +8 -8
- package/lib/api/cardano/cardanoInputs.js +1 -1
- package/lib/api/cardano/cardanoOutputs.d.ts +22 -22
- package/lib/api/cardano/cardanoOutputs.js +1 -1
- package/lib/api/cardano/cardanoTokenBundle.d.ts +6 -6
- package/lib/api/cardano/cardanoTokenBundle.js +1 -1
- package/lib/api/changeLanguage.js +1 -1
- package/lib/api/changePin.js +1 -1
- package/lib/api/cipherKeyValue.js +1 -1
- package/lib/api/common/paramsValidator.js +1 -1
- package/lib/api/composeTransaction.d.ts +9 -3
- package/lib/api/composeTransaction.js +7 -4
- package/lib/api/eos/api/eosGetPublicKey.js +2 -1
- package/lib/api/eos/api/eosSignTransaction.js +2 -1
- package/lib/api/eos/eosSignTx.d.ts +3 -3
- package/lib/api/ethereum/api/ethereumGetAddress.js +2 -1
- package/lib/api/ethereum/api/ethereumGetPublicKey.js +2 -1
- package/lib/api/ethereum/api/ethereumSignMessage.d.ts +1 -1
- package/lib/api/ethereum/api/ethereumSignMessage.js +2 -1
- package/lib/api/ethereum/api/ethereumSignTransaction.d.ts +1 -1
- package/lib/api/ethereum/api/ethereumSignTransaction.js +13 -7
- package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +58 -57
- package/lib/api/ethereum/api/ethereumSignTypedData.js +3 -2
- package/lib/api/ethereum/api/ethereumVerifyMessage.js +2 -1
- package/lib/api/ethereum/ethereumDefinitions.d.ts +21 -21
- package/lib/api/ethereum/ethereumDefinitions.js +6 -5
- package/lib/api/firmware/getBinary.js +1 -1
- package/lib/api/firmware/x509certificate.js +3 -5
- package/lib/api/getAccountDescriptor.js +1 -1
- package/lib/api/getAddress.js +1 -1
- package/lib/api/getCoinInfo.d.ts +3 -0
- package/lib/api/getCoinInfo.js +1 -1
- package/lib/api/getFirmwareHash.js +1 -1
- package/lib/api/getOwnershipId.js +1 -1
- package/lib/api/getOwnershipProof.js +1 -1
- package/lib/api/getPublicKey.js +1 -1
- package/lib/api/index.d.ts +2 -1
- package/lib/api/index.js +5 -3
- package/lib/api/loadDevice.d.ts +14 -0
- package/lib/api/loadDevice.js +44 -0
- package/lib/api/nem/api/nemGetAddress.js +2 -1
- package/lib/api/nem/api/nemSignTransaction.js +2 -1
- package/lib/api/pushTransaction.js +1 -1
- package/lib/api/rebootToBootloader.js +1 -1
- package/lib/api/recoveryDevice.js +1 -1
- package/lib/api/requestLogin.js +1 -1
- package/lib/api/resetDevice.js +1 -1
- package/lib/api/ripple/api/rippleGetAddress.js +2 -1
- package/lib/api/ripple/api/rippleSignTransaction.js +2 -1
- package/lib/api/setBrightness.js +1 -1
- package/lib/api/setBusy.js +1 -1
- package/lib/api/signMessage.js +1 -1
- package/lib/api/solana/api/solanaGetAddress.js +2 -1
- package/lib/api/solana/api/solanaGetPublicKey.js +2 -1
- package/lib/api/solana/api/solanaSignTransaction.js +2 -1
- package/lib/api/stellar/api/stellarGetAddress.js +2 -1
- package/lib/api/stellar/api/stellarSignTransaction.js +2 -1
- package/lib/api/stellar/stellarSignTx.js +1 -1
- package/lib/api/tezos/api/tezosGetAddress.js +2 -1
- package/lib/api/tezos/api/tezosGetPublicKey.js +2 -1
- package/lib/api/tezos/api/tezosSignTransaction.js +2 -1
- package/lib/api/tezos/tezosSignTx.js +1 -1
- package/lib/api/unlockPath.js +1 -1
- package/lib/api/verifyMessage.js +1 -1
- package/lib/backend/Blockchain.d.ts +3 -0
- package/lib/backend/Blockchain.js +3 -0
- package/lib/constants/errors.d.ts +3 -0
- package/lib/constants/errors.js +3 -0
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.js +3 -1
- package/lib/constants/nem.d.ts +3 -3
- package/lib/constants/utxo.d.ts +3 -0
- package/lib/constants/utxo.js +5 -0
- package/lib/core/AbstractMethod.d.ts +13 -5
- package/lib/core/AbstractMethod.js +50 -24
- package/lib/core/index.js +41 -30
- package/lib/core/onCallFirmwareUpdate.d.ts +2 -2
- package/lib/core/onCallFirmwareUpdate.js +5 -5
- package/lib/data/DataManager.d.ts +0 -181
- package/lib/data/DataManager.js +40 -6
- package/lib/data/analyticsInfo.js +2 -1
- package/lib/data/coinInfo.d.ts +14 -0
- package/lib/data/config.d.ts +20 -22
- package/lib/data/config.js +15 -40
- package/lib/data/connectSettings.js +5 -4
- package/lib/data/deviceAuthenticityConfig.js +17 -0
- package/lib/data/deviceAuthenticityConfigTypes.d.ts +32 -23
- package/lib/data/firmwareInfo.d.ts +1 -1
- package/lib/data/models.d.ts +9 -0
- package/lib/data/models.js +9 -0
- package/lib/data/version.d.ts +1 -1
- package/lib/data/version.js +1 -1
- package/lib/device/Device.d.ts +143 -36
- package/lib/device/Device.js +226 -119
- package/lib/device/DeviceCommands.js +4 -4
- package/lib/device/DeviceList.d.ts +13 -21
- package/lib/device/DeviceList.js +54 -168
- package/lib/device/prompts.js +3 -2
- package/lib/device/resolveDescriptorForTaproot.d.ts +1 -1
- package/lib/events/call.d.ts +5 -5
- package/lib/events/call.js +2 -2
- package/lib/events/device.d.ts +0 -6
- package/lib/events/device.js +0 -6
- package/lib/events/transport.d.ts +1 -1
- package/lib/factory.d.ts +6 -6
- package/lib/factory.js +132 -136
- package/lib/impl/dynamic.d.ts +13 -19
- package/lib/impl/dynamic.js +0 -9
- package/lib/index-browser.d.ts +3 -1
- package/lib/index-browser.js +0 -3
- package/lib/index.d.ts +3 -1
- package/lib/index.js +1 -13
- package/lib/types/api/applySettings.d.ts +13 -13
- package/lib/types/api/authenticateDevice.d.ts +33 -24
- package/lib/types/api/authorizeCoinjoin.d.ts +10 -10
- package/lib/types/api/binance/index.d.ts +143 -143
- package/lib/types/api/binance/index.js +1 -1
- package/lib/types/api/bitcoin/index.d.ts +11 -11
- package/lib/types/api/bitcoin/index.js +1 -1
- package/lib/types/api/blockchainEvmRpcCall.d.ts +4 -0
- package/lib/types/api/{checkFirmwareAuthenticity.js → blockchainEvmRpcCall.js} +1 -1
- package/lib/types/api/cancelCoinjoinAuthorization.d.ts +1 -1
- package/lib/types/api/cardano/index.d.ts +507 -507
- package/lib/types/api/changeLanguage.d.ts +6 -6
- package/lib/types/api/cipherKeyValue.d.ts +8 -8
- package/lib/types/api/cipherKeyValue.js +1 -1
- package/lib/types/api/composeTransaction.d.ts +13 -7
- package/lib/types/api/eos/index.d.ts +525 -525
- package/lib/types/api/eos/index.js +1 -1
- package/lib/types/api/ethereum/index.d.ts +100 -100
- package/lib/types/api/firmwareUpdate.d.ts +5 -5
- package/lib/types/api/getAccountDescriptor.d.ts +4 -4
- package/lib/types/api/getAddress.d.ts +32 -32
- package/lib/types/api/getOwnershipId.d.ts +24 -24
- package/lib/types/api/getOwnershipProof.d.ts +28 -28
- package/lib/types/api/getPublicKey.d.ts +24 -24
- package/lib/types/api/getPublicKey.js +1 -1
- package/lib/types/api/index.d.ts +4 -8
- package/lib/types/api/init.d.ts +4 -2
- package/lib/types/api/loadDevice.d.ts +4 -0
- package/lib/types/api/loadDevice.js +3 -0
- package/lib/types/api/nem/index.d.ts +612 -612
- package/lib/types/api/nem/index.js +1 -1
- package/lib/types/api/nemGetAddress.d.ts +6 -6
- package/lib/types/api/pushTransaction.d.ts +3 -3
- package/lib/types/api/recoveryDevice.d.ts +9 -9
- package/lib/types/api/requestLogin.d.ts +25 -25
- package/lib/types/api/ripple/index.d.ts +21 -21
- package/lib/types/api/ripple/index.js +1 -1
- package/lib/types/api/solana/index.d.ts +23 -23
- package/lib/types/api/solana/index.js +1 -1
- package/lib/types/api/stellar/index.d.ts +582 -582
- package/lib/types/api/stellar/index.js +1 -1
- package/lib/types/api/tezos/index.d.ts +120 -120
- package/lib/types/api/tezos/index.js +1 -1
- package/lib/types/api/unlockPath.d.ts +2 -2
- package/lib/types/coinInfo.d.ts +231 -224
- package/lib/types/device.d.ts +13 -1
- package/lib/types/device.js +3 -1
- package/lib/types/fees.d.ts +19 -19
- package/lib/types/firmware.d.ts +1 -1
- package/lib/types/params.d.ts +21 -18
- package/lib/types/settings.d.ts +15 -9
- package/lib/types/utils.d.ts +1 -0
- package/lib/types/utils.js +3 -0
- package/lib/utils/addressUtils.js +2 -2
- package/lib/utils/assetUtils.js +3 -3
- package/lib/utils/deviceFeaturesUtils.js +1 -1
- package/lib/utils/uiPromiseManager.d.ts +2 -1
- package/lib/utils/uiPromiseManager.js +3 -3
- package/package.json +12 -12
- package/lib/api/checkFirmwareAuthenticity.d.ts +0 -11
- package/lib/api/checkFirmwareAuthenticity.js +0 -63
- package/lib/types/api/checkFirmwareAuthenticity.d.ts +0 -11
|
@@ -2,7 +2,7 @@ import { TypedEmitter } from '@trezor/utils';
|
|
|
2
2
|
import { Transport, TRANSPORT } from '@trezor/transport';
|
|
3
3
|
import { DEVICE, TransportInfo } from '../events';
|
|
4
4
|
import { Device } from './Device';
|
|
5
|
-
import
|
|
5
|
+
import { ConnectSettings, DeviceUniquePath, Device as DeviceTyped } from '../types';
|
|
6
6
|
interface DeviceListEvents {
|
|
7
7
|
[TRANSPORT.START]: TransportInfo;
|
|
8
8
|
[TRANSPORT.ERROR]: string;
|
|
@@ -10,8 +10,6 @@ interface DeviceListEvents {
|
|
|
10
10
|
[DEVICE.CONNECT_UNACQUIRED]: DeviceTyped;
|
|
11
11
|
[DEVICE.DISCONNECT]: DeviceTyped;
|
|
12
12
|
[DEVICE.CHANGED]: DeviceTyped;
|
|
13
|
-
[DEVICE.RELEASED]: DeviceTyped;
|
|
14
|
-
[DEVICE.ACQUIRED]: DeviceTyped;
|
|
15
13
|
}
|
|
16
14
|
export interface IDeviceList {
|
|
17
15
|
isConnected(): this is DeviceList;
|
|
@@ -25,7 +23,7 @@ export interface IDeviceList {
|
|
|
25
23
|
dispose: DeviceList['dispose'];
|
|
26
24
|
}
|
|
27
25
|
export declare const assertDeviceListConnected: (deviceList: IDeviceList) => asserts deviceList is DeviceList;
|
|
28
|
-
type ConstructorParams = Pick<ConnectSettings, 'priority' | 'debug' | '_sessionsBackgroundUrl'> & {
|
|
26
|
+
type ConstructorParams = Pick<ConnectSettings, 'priority' | 'debug' | '_sessionsBackgroundUrl' | 'manifest'> & {
|
|
29
27
|
messages: Record<string, any>;
|
|
30
28
|
};
|
|
31
29
|
type InitParams = Pick<ConnectSettings, 'pendingTransportEvent' | 'transportReconnect'>;
|
|
@@ -33,34 +31,31 @@ export declare class DeviceList extends TypedEmitter<DeviceListEvents> implement
|
|
|
33
31
|
private transport;
|
|
34
32
|
private transports;
|
|
35
33
|
private devices;
|
|
36
|
-
private
|
|
37
|
-
private
|
|
34
|
+
private deviceCounter;
|
|
35
|
+
private readonly handshakeLock;
|
|
38
36
|
private readonly authPenaltyManager;
|
|
39
37
|
private initPromise?;
|
|
40
38
|
private rejectPending?;
|
|
41
39
|
private transportCommonArgs;
|
|
42
40
|
isConnected(): this is DeviceList;
|
|
43
41
|
pendingConnection(): Promise<void> | undefined;
|
|
44
|
-
constructor({ messages, priority, debug, _sessionsBackgroundUrl }: ConstructorParams);
|
|
42
|
+
constructor({ messages, priority, debug, _sessionsBackgroundUrl, manifest, }: ConstructorParams);
|
|
45
43
|
private createTransport;
|
|
46
44
|
setTransports(transports: ConnectSettings['transports']): void;
|
|
47
|
-
private
|
|
48
|
-
private
|
|
49
|
-
private
|
|
45
|
+
private onDeviceConnected;
|
|
46
|
+
private onDeviceDisconnected;
|
|
47
|
+
private onDeviceSessionChanged;
|
|
48
|
+
private onDeviceRequestRelease;
|
|
50
49
|
init(initParams?: InitParams): Promise<void>;
|
|
51
50
|
private createInitPromise;
|
|
52
51
|
private createReconnectPromise;
|
|
53
52
|
private selectTransport;
|
|
54
53
|
private initializeTransport;
|
|
55
54
|
private waitForDevices;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
getFirstDevicePath(): string;
|
|
61
|
-
asArray(): DeviceTyped[];
|
|
62
|
-
allDevices(): Device[];
|
|
63
|
-
length(): number;
|
|
55
|
+
getDeviceCount(): number;
|
|
56
|
+
getAllDevices(): Device[];
|
|
57
|
+
getOnlyDevice(): Device | undefined;
|
|
58
|
+
getDeviceByPath(path: DeviceUniquePath): Device | undefined;
|
|
64
59
|
transportType(): "BridgeTransport" | "NodeUsbTransport" | "WebUsbTransport" | "UdpTransport";
|
|
65
60
|
getTransportInfo(): TransportInfo;
|
|
66
61
|
dispose(): Promise<void>;
|
|
@@ -68,9 +63,6 @@ export declare class DeviceList extends TypedEmitter<DeviceListEvents> implement
|
|
|
68
63
|
enumerate(transport?: Transport): Promise<void>;
|
|
69
64
|
addAuthPenalty(device: Device): void;
|
|
70
65
|
removeAuthPenalty(device: Device): void;
|
|
71
|
-
private handle;
|
|
72
|
-
private _takeAndCreateDevice;
|
|
73
|
-
private _handleUsedElsewhere;
|
|
74
66
|
}
|
|
75
67
|
export {};
|
|
76
68
|
//# sourceMappingURL=DeviceList.d.ts.map
|
package/lib/device/DeviceList.js
CHANGED
|
@@ -6,9 +6,11 @@ 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 types_1 = require("../types");
|
|
9
10
|
const transportInfo_1 = require("../data/transportInfo");
|
|
10
11
|
const debug_1 = require("../utils/debug");
|
|
11
12
|
const promiseUtils_1 = require("../utils/promiseUtils");
|
|
13
|
+
const utils_2 = require("../types/utils");
|
|
12
14
|
const _log = (0, debug_1.initLog)('DeviceList');
|
|
13
15
|
const createAuthPenaltyManager = (priority) => {
|
|
14
16
|
const penalizedDevices = {};
|
|
@@ -42,17 +44,18 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
42
44
|
pendingConnection() {
|
|
43
45
|
return this.initPromise;
|
|
44
46
|
}
|
|
45
|
-
constructor({ messages, priority, debug, _sessionsBackgroundUrl }) {
|
|
47
|
+
constructor({ messages, priority, debug, _sessionsBackgroundUrl, manifest, }) {
|
|
46
48
|
super();
|
|
47
49
|
this.devices = {};
|
|
48
|
-
this.
|
|
49
|
-
this.createDevicesQueue = [];
|
|
50
|
+
this.deviceCounter = Date.now();
|
|
50
51
|
const transportLogger = (0, debug_1.initLog)('@trezor/transport', debug);
|
|
52
|
+
this.handshakeLock = (0, utils_1.getSynchronize)();
|
|
51
53
|
this.authPenaltyManager = createAuthPenaltyManager(priority);
|
|
52
54
|
this.transportCommonArgs = {
|
|
53
55
|
messages,
|
|
54
56
|
logger: transportLogger,
|
|
55
57
|
sessionsBackgroundUrl: _sessionsBackgroundUrl,
|
|
58
|
+
id: (manifest === null || manifest === void 0 ? void 0 : manifest.appUrl) || 'unknown app',
|
|
56
59
|
};
|
|
57
60
|
this.transports = [
|
|
58
61
|
new transport_1.BridgeTransport({
|
|
@@ -96,91 +99,41 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
96
99
|
const transportTypes = (transports === null || transports === void 0 ? void 0 : transports.length) ? transports : ['BridgeTransport'];
|
|
97
100
|
this.transports = transportTypes.map(this.createTransport.bind(this));
|
|
98
101
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
break;
|
|
114
|
-
case 'connected':
|
|
115
|
-
if (!(await this.waitForCreateDevicesQueue(path))) {
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
const penalty = this.authPenaltyManager.get();
|
|
119
|
-
if (penalty) {
|
|
120
|
-
await (0, promiseUtils_1.resolveAfter)(501 + penalty, null).promise;
|
|
121
|
-
}
|
|
122
|
-
if (this.creatingDevicesDescriptors[path].session == null) {
|
|
123
|
-
await this._createAndSaveDevice(descriptor, transport);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
const device = this._createUnacquiredDevice(descriptor, transport);
|
|
127
|
-
this.devices[path] = device;
|
|
128
|
-
this.emit(events_1.DEVICE.CONNECT_UNACQUIRED, device.toMessageObject());
|
|
129
|
-
}
|
|
130
|
-
this.removeFromCreateDevicesQueue(path);
|
|
131
|
-
break;
|
|
132
|
-
case 'acquired':
|
|
133
|
-
if (category.subtype === 'elsewhere') {
|
|
134
|
-
this.removeFromCreateDevicesQueue(path);
|
|
135
|
-
if (device) {
|
|
136
|
-
device.featuresNeedsReload = true;
|
|
137
|
-
device.interruptionFromOutside();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (!device)
|
|
141
|
-
break;
|
|
142
|
-
_log.debug('Event', events_1.DEVICE.CHANGED, device.toMessageObject());
|
|
143
|
-
this.emit(events_1.DEVICE.CHANGED, device.toMessageObject());
|
|
144
|
-
_log.debug('Event', events_1.DEVICE.ACQUIRED, device.toMessageObject());
|
|
145
|
-
this.emit(events_1.DEVICE.ACQUIRED, device.toMessageObject());
|
|
146
|
-
break;
|
|
147
|
-
case 'released':
|
|
148
|
-
if (!device)
|
|
149
|
-
break;
|
|
150
|
-
const methodStillRunning = !((_a = device.commands) === null || _a === void 0 ? void 0 : _a.isDisposed());
|
|
151
|
-
if (methodStillRunning) {
|
|
152
|
-
device.keepTransportSession = false;
|
|
153
|
-
}
|
|
154
|
-
_log.debug('Event', events_1.DEVICE.CHANGED, device.toMessageObject());
|
|
155
|
-
this.emit(events_1.DEVICE.CHANGED, device.toMessageObject());
|
|
156
|
-
_log.debug('Event', events_1.DEVICE.RELEASED, device.toMessageObject());
|
|
157
|
-
this.emit(events_1.DEVICE.RELEASED, device.toMessageObject());
|
|
158
|
-
if (category.subtype === 'elsewhere') {
|
|
159
|
-
await (0, promiseUtils_1.resolveAfter)(1000, null).promise;
|
|
160
|
-
if (!device.isUsed() && device.isUnacquired() && !device.isInconsistent()) {
|
|
161
|
-
_log.debug('Create device from unacquired', device.toMessageObject());
|
|
162
|
-
await this._createAndSaveDevice(descriptor, transport);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
break;
|
|
102
|
+
onDeviceConnected(descriptor, transport) {
|
|
103
|
+
const { path } = descriptor;
|
|
104
|
+
const id = (this.deviceCounter++).toString(16).slice(-8);
|
|
105
|
+
const device = new Device_1.Device({
|
|
106
|
+
id: (0, types_1.DeviceUniquePath)(id),
|
|
107
|
+
transport,
|
|
108
|
+
descriptor,
|
|
109
|
+
listener: lifecycle => this.emit(lifecycle, device.toMessageObject()),
|
|
110
|
+
});
|
|
111
|
+
this.devices[path] = device;
|
|
112
|
+
const penalty = this.authPenaltyManager.get();
|
|
113
|
+
this.handshakeLock(async () => {
|
|
114
|
+
if (this.devices[path]) {
|
|
115
|
+
await device.handshake(penalty);
|
|
166
116
|
}
|
|
167
|
-
device === null || device === void 0 ? void 0 : device.updateDescriptor(descriptor);
|
|
168
117
|
});
|
|
169
118
|
}
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
119
|
+
onDeviceDisconnected(descriptor) {
|
|
120
|
+
const { path } = descriptor;
|
|
121
|
+
const device = this.devices[path];
|
|
122
|
+
if (device) {
|
|
123
|
+
device.disconnect();
|
|
124
|
+
delete this.devices[path];
|
|
125
|
+
}
|
|
176
126
|
}
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
dfd.resolve();
|
|
127
|
+
onDeviceSessionChanged(descriptor) {
|
|
128
|
+
const device = this.devices[descriptor.path];
|
|
129
|
+
if (device) {
|
|
130
|
+
device.updateDescriptor(descriptor);
|
|
182
131
|
}
|
|
183
132
|
}
|
|
133
|
+
onDeviceRequestRelease(descriptor) {
|
|
134
|
+
var _a;
|
|
135
|
+
(_a = this.devices[descriptor.path]) === null || _a === void 0 ? void 0 : _a.usedElsewhere();
|
|
136
|
+
}
|
|
184
137
|
init(initParams = {}) {
|
|
185
138
|
if (!this.initPromise) {
|
|
186
139
|
_log.debug('Initializing transports');
|
|
@@ -207,7 +160,9 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
207
160
|
createReconnectPromise(initParams) {
|
|
208
161
|
const { promise, reject } = (0, promiseUtils_1.resolveAfter)(1000, initParams);
|
|
209
162
|
this.rejectPending = reject;
|
|
210
|
-
return promise.then(this.createInitPromise.bind(this))
|
|
163
|
+
return promise.then(this.createInitPromise.bind(this)).finally(() => {
|
|
164
|
+
this.rejectPending = undefined;
|
|
165
|
+
});
|
|
211
166
|
}
|
|
212
167
|
async selectTransport([transport, ...rest]) {
|
|
213
168
|
const result = await transport.init();
|
|
@@ -219,7 +174,10 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
219
174
|
throw new Error(result.error);
|
|
220
175
|
}
|
|
221
176
|
async initializeTransport(transport, initParams) {
|
|
222
|
-
transport.on(transport_1.TRANSPORT.
|
|
177
|
+
transport.on(transport_1.TRANSPORT.DEVICE_CONNECTED, d => this.onDeviceConnected(d, transport));
|
|
178
|
+
transport.on(transport_1.TRANSPORT.DEVICE_DISCONNECTED, this.onDeviceDisconnected.bind(this));
|
|
179
|
+
transport.on(transport_1.TRANSPORT.DEVICE_SESSION_CHANGED, this.onDeviceSessionChanged.bind(this));
|
|
180
|
+
transport.on(transport_1.TRANSPORT.DEVICE_REQUEST_RELEASE, this.onDeviceRequestRelease.bind(this));
|
|
223
181
|
transport.on(transport_1.TRANSPORT.ERROR, error => {
|
|
224
182
|
this.cleanup();
|
|
225
183
|
this.emit(transport_1.TRANSPORT.ERROR, error);
|
|
@@ -260,36 +218,17 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
260
218
|
this.off(events_1.DEVICE.CONNECT_UNACQUIRED, onDeviceConnect);
|
|
261
219
|
});
|
|
262
220
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
await this.handle(descriptor, transport);
|
|
266
|
-
}
|
|
267
|
-
_createUnacquiredDevice(descriptor, transport) {
|
|
268
|
-
_log.debug('Creating Unacquired Device', descriptor);
|
|
269
|
-
const device = Device_1.Device.createUnacquired(transport, descriptor);
|
|
270
|
-
device.once(events_1.DEVICE.ACQUIRED, () => {
|
|
271
|
-
this.emit(events_1.DEVICE.CONNECT, device.toMessageObject());
|
|
272
|
-
});
|
|
273
|
-
return device;
|
|
274
|
-
}
|
|
275
|
-
_createUnreadableDevice(descriptor, transport, unreadableError) {
|
|
276
|
-
_log.debug('Creating Unreadable Device', descriptor, unreadableError);
|
|
277
|
-
return Device_1.Device.createUnacquired(transport, descriptor, unreadableError);
|
|
221
|
+
getDeviceCount() {
|
|
222
|
+
return Object.keys(this.devices).length;
|
|
278
223
|
}
|
|
279
|
-
|
|
280
|
-
return this.devices[
|
|
224
|
+
getAllDevices() {
|
|
225
|
+
return (0, utils_2.typedObjectKeys)(this.devices).map(key => this.devices[key]);
|
|
281
226
|
}
|
|
282
|
-
|
|
283
|
-
return this.
|
|
227
|
+
getOnlyDevice() {
|
|
228
|
+
return this.getDeviceCount() === 1 ? Object.values(this.devices)[0] : undefined;
|
|
284
229
|
}
|
|
285
|
-
|
|
286
|
-
return this.
|
|
287
|
-
}
|
|
288
|
-
allDevices() {
|
|
289
|
-
return Object.keys(this.devices).map(key => this.devices[key]);
|
|
290
|
-
}
|
|
291
|
-
length() {
|
|
292
|
-
return this.asArray().length;
|
|
230
|
+
getDeviceByPath(path) {
|
|
231
|
+
return this.getAllDevices().find(d => d.getUniquePath() === path);
|
|
293
232
|
}
|
|
294
233
|
transportType() {
|
|
295
234
|
return this.transport.name;
|
|
@@ -308,16 +247,14 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
308
247
|
async cleanup() {
|
|
309
248
|
var _a;
|
|
310
249
|
const { transport } = this;
|
|
311
|
-
const devices = this.
|
|
250
|
+
const devices = this.getAllDevices();
|
|
312
251
|
this.transport = undefined;
|
|
313
252
|
this.authPenaltyManager.clear();
|
|
314
|
-
|
|
253
|
+
(0, utils_2.typedObjectKeys)(this.devices).forEach(key => delete this.devices[key]);
|
|
315
254
|
(_a = this.rejectPending) === null || _a === void 0 ? void 0 : _a.call(this, new Error('Disposed'));
|
|
316
255
|
devices.forEach(device => {
|
|
317
256
|
this.emit(events_1.DEVICE.DISCONNECT, device.toMessageObject());
|
|
318
257
|
});
|
|
319
|
-
this.createDevicesQueue.forEach(dfd => dfd.resolve());
|
|
320
|
-
this.createDevicesQueue = [];
|
|
321
258
|
await Promise.all(devices.map(device => device.dispose()));
|
|
322
259
|
transport === null || transport === void 0 ? void 0 : transport.stop();
|
|
323
260
|
}
|
|
@@ -327,9 +264,8 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
327
264
|
return;
|
|
328
265
|
}
|
|
329
266
|
res.payload.forEach(d => {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}
|
|
267
|
+
var _a;
|
|
268
|
+
(_a = this.devices[d.path]) === null || _a === void 0 ? void 0 : _a.updateDescriptor(d);
|
|
333
269
|
});
|
|
334
270
|
}
|
|
335
271
|
addAuthPenalty(device) {
|
|
@@ -338,56 +274,6 @@ class DeviceList extends utils_1.TypedEmitter {
|
|
|
338
274
|
removeAuthPenalty(device) {
|
|
339
275
|
return this.authPenaltyManager.remove(device);
|
|
340
276
|
}
|
|
341
|
-
async handle(descriptor, transport) {
|
|
342
|
-
var _a;
|
|
343
|
-
const path = descriptor.path.toString();
|
|
344
|
-
try {
|
|
345
|
-
await this._takeAndCreateDevice(descriptor, transport);
|
|
346
|
-
}
|
|
347
|
-
catch (error) {
|
|
348
|
-
_log.debug('Cannot create device', error);
|
|
349
|
-
if (error.code === 'Device_NotFound' ||
|
|
350
|
-
error.message === transport_1.TRANSPORT_ERROR.DEVICE_NOT_FOUND ||
|
|
351
|
-
error.message === transport_1.TRANSPORT_ERROR.DEVICE_DISCONNECTED_DURING_ACTION ||
|
|
352
|
-
error.message === transport_1.TRANSPORT_ERROR.UNEXPECTED_ERROR ||
|
|
353
|
-
error.message === transport_1.TRANSPORT_ERROR.DESCRIPTOR_NOT_FOUND ||
|
|
354
|
-
error.message === transport_1.TRANSPORT_ERROR.HTTP_ERROR) {
|
|
355
|
-
delete this.devices[path];
|
|
356
|
-
}
|
|
357
|
-
else if (error.message === transport_1.TRANSPORT_ERROR.SESSION_WRONG_PREVIOUS) {
|
|
358
|
-
this.enumerate(transport);
|
|
359
|
-
this._handleUsedElsewhere(descriptor, transport);
|
|
360
|
-
}
|
|
361
|
-
else if (error.message === transport_1.TRANSPORT_ERROR.INTERFACE_UNABLE_TO_OPEN_DEVICE ||
|
|
362
|
-
((_a = error.message) === null || _a === void 0 ? void 0 : _a.indexOf(constants_1.ERRORS.LIBUSB_ERROR_MESSAGE)) >= 0 ||
|
|
363
|
-
error.code === 'Device_InitializeFailed') {
|
|
364
|
-
const device = this._createUnreadableDevice(this.creatingDevicesDescriptors[path], transport, error.message);
|
|
365
|
-
this.devices[path] = device;
|
|
366
|
-
this.emit(events_1.DEVICE.CONNECT_UNACQUIRED, device.toMessageObject());
|
|
367
|
-
}
|
|
368
|
-
else if (error.code === 'Device_UsedElsewhere') {
|
|
369
|
-
this._handleUsedElsewhere(descriptor, transport);
|
|
370
|
-
}
|
|
371
|
-
else {
|
|
372
|
-
await (0, promiseUtils_1.resolveAfter)(501, null).promise;
|
|
373
|
-
await this.handle(descriptor, transport);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
async _takeAndCreateDevice(descriptor, transport) {
|
|
378
|
-
const device = Device_1.Device.fromDescriptor(transport, descriptor);
|
|
379
|
-
const path = descriptor.path.toString();
|
|
380
|
-
this.devices[path] = device;
|
|
381
|
-
const promise = device.run();
|
|
382
|
-
await promise;
|
|
383
|
-
this.emit(events_1.DEVICE.CONNECT, device.toMessageObject());
|
|
384
|
-
}
|
|
385
|
-
_handleUsedElsewhere(descriptor, transport) {
|
|
386
|
-
const path = descriptor.path.toString();
|
|
387
|
-
const device = this._createUnacquiredDevice(this.creatingDevicesDescriptors[path], transport);
|
|
388
|
-
this.devices[path] = device;
|
|
389
|
-
this.emit(events_1.DEVICE.CONNECT_UNACQUIRED, device.toMessageObject());
|
|
390
|
-
}
|
|
391
277
|
}
|
|
392
278
|
exports.DeviceList = DeviceList;
|
|
393
279
|
//# sourceMappingURL=DeviceList.js.map
|
package/lib/device/prompts.js
CHANGED
|
@@ -5,14 +5,15 @@ const transport_1 = require("@trezor/transport");
|
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
const events_1 = require("../events");
|
|
7
7
|
const cancelPrompt = (device, expectResponse = true) => {
|
|
8
|
-
|
|
8
|
+
const session = device.getLocalSession();
|
|
9
|
+
if (!session) {
|
|
9
10
|
return Promise.resolve({
|
|
10
11
|
success: false,
|
|
11
12
|
error: transport_1.TRANSPORT_ERROR.SESSION_NOT_FOUND,
|
|
12
13
|
});
|
|
13
14
|
}
|
|
14
15
|
const cancelArgs = {
|
|
15
|
-
session
|
|
16
|
+
session,
|
|
16
17
|
name: 'Cancel',
|
|
17
18
|
data: {},
|
|
18
19
|
protocol: device.protocol,
|
package/lib/events/call.d.ts
CHANGED
|
@@ -2,15 +2,15 @@ import type { IFRAME } from './iframe';
|
|
|
2
2
|
import type { TrezorConnect } from '../types/api';
|
|
3
3
|
import type { CommonParams, DeviceIdentity } from '../types/params';
|
|
4
4
|
import { Device } from '../device/Device';
|
|
5
|
-
type UnwrappedResponse<
|
|
5
|
+
type UnwrappedResponse<Response> = Response extends Promise<infer R> ? R extends {
|
|
6
6
|
success: true;
|
|
7
7
|
payload: infer P;
|
|
8
|
-
} ? P : never
|
|
9
|
-
type OverloadedMethod<
|
|
8
|
+
} ? P : never : void;
|
|
9
|
+
type OverloadedMethod<Method, Params extends Record<string, string>> = Method extends {
|
|
10
10
|
(params: infer P1): infer R1;
|
|
11
11
|
(params: infer P2): infer R2;
|
|
12
|
-
} ? ((params: P1 &
|
|
13
|
-
type UnwrappedMethod<
|
|
12
|
+
} ? ((params: P1 & Params) => R1) | ((params: P2 & Params) => R2) : Method extends (...args: infer P) => infer R ? (params: Params & P[0]) => R : never;
|
|
13
|
+
type UnwrappedMethod<Method, Params extends Record<string, string>> = Method extends () => infer R ? (params: Params & CommonParams) => R : OverloadedMethod<Method, Params>;
|
|
14
14
|
type IsMethodCallable<T> = T extends (...args: any[]) => infer R ? R extends Promise<{
|
|
15
15
|
success: boolean;
|
|
16
16
|
}> ? R : never : never;
|
package/lib/events/call.js
CHANGED
|
@@ -11,9 +11,9 @@ const createResponseMessage = (id, success, payload, device) => ({
|
|
|
11
11
|
payload: success ? payload : (0, errors_1.serializeError)(payload),
|
|
12
12
|
device: device
|
|
13
13
|
? {
|
|
14
|
-
path: device === null || device === void 0 ? void 0 : device.
|
|
14
|
+
path: device === null || device === void 0 ? void 0 : device.getUniquePath(),
|
|
15
15
|
state: device === null || device === void 0 ? void 0 : device.getState(),
|
|
16
|
-
instance: device === null || device === void 0 ? void 0 : device.
|
|
16
|
+
instance: device === null || device === void 0 ? void 0 : device.getInstance(),
|
|
17
17
|
}
|
|
18
18
|
: undefined,
|
|
19
19
|
});
|
package/lib/events/device.d.ts
CHANGED
|
@@ -7,12 +7,6 @@ export declare const DEVICE: {
|
|
|
7
7
|
readonly CONNECT_UNACQUIRED: "device-connect_unacquired";
|
|
8
8
|
readonly DISCONNECT: "device-disconnect";
|
|
9
9
|
readonly CHANGED: "device-changed";
|
|
10
|
-
readonly ACQUIRE: "device-acquire";
|
|
11
|
-
readonly RELEASE: "device-release";
|
|
12
|
-
readonly ACQUIRED: "device-acquired";
|
|
13
|
-
readonly RELEASED: "device-released";
|
|
14
|
-
readonly USED_ELSEWHERE: "device-used_elsewhere";
|
|
15
|
-
readonly LOADING: "device-loading";
|
|
16
10
|
readonly BUTTON: "button";
|
|
17
11
|
readonly PIN: "pin";
|
|
18
12
|
readonly PASSPHRASE: "passphrase";
|
package/lib/events/device.js
CHANGED
|
@@ -7,12 +7,6 @@ exports.DEVICE = {
|
|
|
7
7
|
CONNECT_UNACQUIRED: 'device-connect_unacquired',
|
|
8
8
|
DISCONNECT: 'device-disconnect',
|
|
9
9
|
CHANGED: 'device-changed',
|
|
10
|
-
ACQUIRE: 'device-acquire',
|
|
11
|
-
RELEASE: 'device-release',
|
|
12
|
-
ACQUIRED: 'device-acquired',
|
|
13
|
-
RELEASED: 'device-released',
|
|
14
|
-
USED_ELSEWHERE: 'device-used_elsewhere',
|
|
15
|
-
LOADING: 'device-loading',
|
|
16
10
|
BUTTON: 'button',
|
|
17
11
|
PIN: 'pin',
|
|
18
12
|
PASSPHRASE: 'passphrase',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { MessageFactoryFn } from '../types/utils';
|
|
2
1
|
import type { Transport } from '@trezor/transport';
|
|
3
2
|
import { TRANSPORT } from '@trezor/transport/lib/constants';
|
|
3
|
+
import type { MessageFactoryFn } from '../types/utils';
|
|
4
4
|
export { TRANSPORT } from '@trezor/transport/lib/constants';
|
|
5
5
|
export declare const TRANSPORT_EVENT = "TRANSPORT_EVENT";
|
|
6
6
|
export interface BridgeInfo {
|
package/lib/factory.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { EventEmitter } from 'events';
|
|
2
2
|
import type { TrezorConnect } from './types';
|
|
3
3
|
import type { CallMethod } from './events/call';
|
|
4
|
-
|
|
4
|
+
import type { InitType } from './types/api/init';
|
|
5
|
+
export interface ConnectFactoryDependencies<SettingsType extends Record<string, any>> {
|
|
6
|
+
init: InitType<SettingsType>;
|
|
5
7
|
call: CallMethod;
|
|
6
8
|
eventEmitter: EventEmitter;
|
|
7
9
|
manifest: TrezorConnect['manifest'];
|
|
8
|
-
init: TrezorConnect['init'];
|
|
9
10
|
requestLogin: TrezorConnect['requestLogin'];
|
|
10
11
|
uiResponse: TrezorConnect['uiResponse'];
|
|
11
|
-
renderWebUSBButton: TrezorConnect['renderWebUSBButton'];
|
|
12
|
-
disableWebUSB: TrezorConnect['disableWebUSB'];
|
|
13
|
-
requestWebUSBDevice: TrezorConnect['requestWebUSBDevice'];
|
|
14
12
|
cancel: TrezorConnect['cancel'];
|
|
15
13
|
dispose: TrezorConnect['dispose'];
|
|
16
14
|
}
|
|
17
|
-
export declare const factory: ({ eventEmitter, manifest, init, call, requestLogin, uiResponse,
|
|
15
|
+
export declare const factory: <SettingsType extends Record<string, any>, ExtraMethodsType extends Record<string, any>>({ eventEmitter, manifest, init, call, requestLogin, uiResponse, cancel, dispose, }: ConnectFactoryDependencies<SettingsType>, extraMethods?: ExtraMethodsType) => Omit<TrezorConnect, "init"> & {
|
|
16
|
+
init: InitType<SettingsType>;
|
|
17
|
+
} & ExtraMethodsType;
|
|
18
18
|
//# sourceMappingURL=factory.d.ts.map
|