@trezor/connect 9.1.3 → 9.1.5
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 +36 -0
- package/README.md +3 -1
- package/lib/api/authenticateDevice.d.ts +7 -0
- package/lib/api/authenticateDevice.js +51 -0
- package/lib/api/bitcoin/TransactionComposer.js +1 -9
- package/lib/api/bitcoin/inputs.d.ts +2 -2
- package/lib/api/bitcoin/outputs.d.ts +2 -2
- package/lib/api/cardanoGetPublicKey.d.ts +6 -2
- package/lib/api/cardanoGetPublicKey.js +7 -1
- package/lib/api/checkFirmwareAuthenticity.js +9 -8
- package/lib/api/common/paramsValidator.js +46 -52
- package/lib/api/eos/eosSignTx.js +1 -1
- package/lib/api/ethereum/ethereumDefinitions.js +3 -2
- package/lib/api/firmware/getBinary.js +1 -1
- package/lib/api/firmware/verifyAuthenticityProof.d.ts +14 -0
- package/lib/api/firmware/verifyAuthenticityProof.js +103 -0
- package/lib/api/firmware/x509certificate.d.ts +73 -0
- package/lib/api/firmware/x509certificate.js +203 -0
- package/lib/api/firmwareUpdate.js +4 -4
- package/lib/api/getAccountInfo.d.ts +1 -1
- package/lib/api/getAccountInfo.js +6 -6
- package/lib/api/getFirmwareHash.js +1 -4
- package/lib/api/getPublicKey.d.ts +2 -1
- package/lib/api/getPublicKey.js +7 -1
- package/lib/api/index.d.ts +1 -0
- package/lib/api/index.js +4 -2
- package/lib/api/rebootToBootloader.js +1 -4
- package/lib/api/signTransaction.js +1 -1
- package/lib/core/AbstractMethod.d.ts +5 -4
- package/lib/core/AbstractMethod.js +13 -11
- package/lib/core/index.d.ts +3 -2
- package/lib/core/index.js +23 -12
- package/lib/core/method.d.ts +1 -1
- package/lib/data/DataManager.d.ts +53 -7
- package/lib/data/DataManager.js +4 -2
- package/lib/data/coinInfo.d.ts +5 -5
- package/lib/data/coinInfo.js +1 -1
- package/lib/data/config.d.ts +52 -6
- package/lib/data/config.js +39 -28
- package/lib/data/connectSettings.js +3 -0
- package/lib/data/deviceAuthenticityConfig.d.ts +15 -0
- package/lib/data/deviceAuthenticityConfig.js +26 -0
- package/lib/data/firmwareInfo.d.ts +3 -2
- package/lib/data/firmwareInfo.js +19 -11
- package/lib/data/models.d.ts +21 -0
- package/lib/data/models.js +24 -0
- package/lib/data/version.d.ts +1 -1
- package/lib/data/version.js +1 -1
- package/lib/device/Device.d.ts +5 -3
- package/lib/device/Device.js +37 -22
- package/lib/device/DeviceCommands.js +4 -4
- package/lib/device/DeviceList.d.ts +2 -1
- package/lib/device/DeviceList.js +10 -3
- package/lib/events/iframe.d.ts +7 -1
- package/lib/events/iframe.js +1 -0
- package/lib/events/ui-promise.d.ts +10 -2
- package/lib/factory.js +1 -0
- package/lib/types/api/authenticateDevice.d.ts +21 -0
- package/lib/types/api/authenticateDevice.js +3 -0
- package/lib/types/api/authorizeCoinjoin.d.ts +2 -2
- package/lib/types/api/binance/index.d.ts +2 -1
- package/lib/types/api/bitcoin/index.d.ts +6 -5
- package/lib/types/api/cardano/index.d.ts +12 -12
- package/lib/types/api/cipherKeyValue.d.ts +2 -2
- package/lib/types/api/eos/index.d.ts +3 -2
- package/lib/types/api/ethereum/index.d.ts +5 -4
- package/lib/types/api/getAccountInfo.d.ts +1 -0
- package/lib/types/api/getOwnershipId.d.ts +2 -2
- package/lib/types/api/getOwnershipProof.d.ts +2 -2
- package/lib/types/api/index.d.ts +2 -0
- package/lib/types/api/nem/index.d.ts +2 -1
- package/lib/types/api/ripple/index.d.ts +2 -1
- package/lib/types/api/stellar/index.d.ts +2 -1
- package/lib/types/api/tezos/index.d.ts +3 -2
- package/lib/types/api/unlockPath.d.ts +2 -2
- package/lib/types/coinInfo.d.ts +3 -2
- package/lib/types/device.d.ts +6 -0
- package/lib/types/firmware.d.ts +8 -4
- package/lib/types/index.d.ts +1 -0
- package/lib/types/params.d.ts +14 -2
- package/lib/utils/assetUtils.js +6 -4
- package/lib/utils/debug.d.ts +9 -3
- package/lib/utils/debug.js +50 -17
- package/lib/utils/deviceFeaturesUtils.js +7 -7
- package/lib/utils/pathUtils.d.ts +3 -3
- package/package.json +14 -13
- package/lib/utils/deferred.d.ts +0 -18
- package/lib/utils/deferred.js +0 -66
- package/lib/utils/versionUtils.d.ts +0 -8
- package/lib/utils/versionUtils.js +0 -75
package/lib/device/Device.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter';
|
|
2
|
+
import { Deferred } from '@trezor/utils';
|
|
2
3
|
import { DeviceCommands } from './DeviceCommands';
|
|
3
4
|
import { PROTO, NETWORK } from '../constants';
|
|
4
5
|
import { DEVICE, DeviceButtonRequestPayload } from '../events';
|
|
5
|
-
import { Deferred } from '../utils/deferred';
|
|
6
6
|
import type { Transport, Descriptor } from '@trezor/transport';
|
|
7
7
|
import { Device as DeviceTyped, DeviceFirmwareStatus, Features, ReleaseInfo, UnavailableCapabilities, FirmwareType } from '../types';
|
|
8
8
|
export type RunOptions = {
|
|
@@ -32,7 +32,7 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
32
32
|
featuresNeedsReload: boolean;
|
|
33
33
|
acquirePromise?: ReturnType<Transport['acquire']>;
|
|
34
34
|
releasePromise?: ReturnType<Transport['release']>;
|
|
35
|
-
runPromise?: Deferred<void
|
|
35
|
+
runPromise?: Deferred<void>;
|
|
36
36
|
loaded: boolean;
|
|
37
37
|
inconsistent: boolean;
|
|
38
38
|
firstRunPromise: Deferred<boolean>;
|
|
@@ -45,6 +45,8 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
45
45
|
unavailableCapabilities: UnavailableCapabilities;
|
|
46
46
|
networkTypeState: NETWORK.NetworkType[];
|
|
47
47
|
firmwareType?: FirmwareType;
|
|
48
|
+
name: string;
|
|
49
|
+
color?: string;
|
|
48
50
|
constructor(transport: Transport, descriptor: Descriptor);
|
|
49
51
|
static fromDescriptor(transport: Transport, originalDescriptor: Descriptor): Device;
|
|
50
52
|
static createUnacquired(transport: Transport, descriptor: Descriptor, unreadableError?: string): Device;
|
|
@@ -74,7 +76,7 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
74
76
|
isInitialized(): boolean;
|
|
75
77
|
isSeedless(): boolean;
|
|
76
78
|
isInconsistent(): boolean;
|
|
77
|
-
getVersion():
|
|
79
|
+
getVersion(): never[] | [number, number, number];
|
|
78
80
|
atLeast(versions: string[] | string): boolean;
|
|
79
81
|
isUsed(): boolean;
|
|
80
82
|
isUsedHere(): boolean;
|
package/lib/device/Device.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Device = void 0;
|
|
4
4
|
const typedEventEmitter_1 = require("@trezor/utils/lib/typedEventEmitter");
|
|
5
|
+
const utils_1 = require("@trezor/utils");
|
|
5
6
|
const DeviceCommands_1 = require("./DeviceCommands");
|
|
6
7
|
const constants_1 = require("../constants");
|
|
7
8
|
const events_1 = require("../events");
|
|
8
9
|
const coinInfo_1 = require("../data/coinInfo");
|
|
9
10
|
const firmwareInfo_1 = require("../data/firmwareInfo");
|
|
10
11
|
const deviceFeaturesUtils_1 = require("../utils/deviceFeaturesUtils");
|
|
11
|
-
const versionUtils_1 = require("../utils/versionUtils");
|
|
12
|
-
const deferred_1 = require("../utils/deferred");
|
|
13
12
|
const debug_1 = require("../utils/debug");
|
|
14
13
|
const types_1 = require("../types");
|
|
14
|
+
const models_1 = require("../data/models");
|
|
15
15
|
const _log = (0, debug_1.initLog)('Device');
|
|
16
16
|
const parseRunOptions = (options) => {
|
|
17
17
|
if (!options)
|
|
@@ -32,9 +32,10 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
32
32
|
this.externalState = [];
|
|
33
33
|
this.unavailableCapabilities = {};
|
|
34
34
|
this.networkTypeState = [];
|
|
35
|
+
this.name = 'Trezor';
|
|
35
36
|
this.transport = transport;
|
|
36
37
|
this.originalDescriptor = descriptor;
|
|
37
|
-
this.firstRunPromise = (0,
|
|
38
|
+
this.firstRunPromise = (0, utils_1.createDeferred)();
|
|
38
39
|
}
|
|
39
40
|
static fromDescriptor(transport, originalDescriptor) {
|
|
40
41
|
const descriptor = { ...originalDescriptor, session: null };
|
|
@@ -64,7 +65,7 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
64
65
|
if (!acquireResult.success) {
|
|
65
66
|
if (this.runPromise) {
|
|
66
67
|
this.runPromise.reject(new Error(acquireResult.error));
|
|
67
|
-
this.runPromise
|
|
68
|
+
delete this.runPromise;
|
|
68
69
|
}
|
|
69
70
|
throw acquireResult.error;
|
|
70
71
|
}
|
|
@@ -105,7 +106,7 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
105
106
|
}
|
|
106
107
|
async cleanup() {
|
|
107
108
|
this.removeAllListeners();
|
|
108
|
-
this.runPromise
|
|
109
|
+
delete this.runPromise;
|
|
109
110
|
await this.release();
|
|
110
111
|
}
|
|
111
112
|
run(fn, options) {
|
|
@@ -114,8 +115,9 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
114
115
|
throw constants_1.ERRORS.TypedError('Device_CallInProgress');
|
|
115
116
|
}
|
|
116
117
|
options = parseRunOptions(options);
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
const runPromise = (0, utils_1.createDeferred)();
|
|
119
|
+
this.runPromise = runPromise;
|
|
120
|
+
return Promise.race([this._runInner(fn, options), runPromise.promise]);
|
|
119
121
|
}
|
|
120
122
|
async override(error) {
|
|
121
123
|
if (this.acquirePromise) {
|
|
@@ -132,7 +134,7 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
132
134
|
_log.debug('interruptionFromUser');
|
|
133
135
|
if (this.runPromise) {
|
|
134
136
|
this.runPromise.reject(error);
|
|
135
|
-
this.runPromise
|
|
137
|
+
delete this.runPromise;
|
|
136
138
|
}
|
|
137
139
|
if (this.commands) {
|
|
138
140
|
await this.commands.cancel();
|
|
@@ -145,7 +147,7 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
145
147
|
}
|
|
146
148
|
if (this.runPromise) {
|
|
147
149
|
this.runPromise.reject(constants_1.ERRORS.TypedError('Device_UsedElsewhere'));
|
|
148
|
-
this.runPromise
|
|
150
|
+
delete this.runPromise;
|
|
149
151
|
}
|
|
150
152
|
this.transport.releaseDevice(this.originalDescriptor.path);
|
|
151
153
|
}
|
|
@@ -173,7 +175,7 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
173
175
|
return this._runInner(() => Promise.resolve({}), options);
|
|
174
176
|
}
|
|
175
177
|
this.inconsistent = true;
|
|
176
|
-
this.runPromise
|
|
178
|
+
delete this.runPromise;
|
|
177
179
|
return Promise.reject(constants_1.ERRORS.TypedError('Device_InitializeFailed', `Initialize failed: ${error.message} ${error.code ? `, code: ${error.code}` : ''}`));
|
|
178
180
|
}
|
|
179
181
|
}
|
|
@@ -197,7 +199,7 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
197
199
|
if (this.runPromise) {
|
|
198
200
|
this.runPromise.resolve();
|
|
199
201
|
}
|
|
200
|
-
this.runPromise
|
|
202
|
+
delete this.runPromise;
|
|
201
203
|
if (!this.loaded) {
|
|
202
204
|
this.loaded = true;
|
|
203
205
|
this.firstRunPromise.resolve(true);
|
|
@@ -301,15 +303,6 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
301
303
|
var _a;
|
|
302
304
|
const capabilities = (0, deviceFeaturesUtils_1.parseCapabilities)(feat);
|
|
303
305
|
feat.capabilities = capabilities;
|
|
304
|
-
const version = [feat.major_version, feat.minor_version, feat.patch_version];
|
|
305
|
-
const capabilitiesDidChange = this.features &&
|
|
306
|
-
this.features.capabilities &&
|
|
307
|
-
this.features.capabilities.join('') !== capabilities.join('');
|
|
308
|
-
if ((0, versionUtils_1.versionCompare)(version, this.getVersion()) !== 0 || capabilitiesDidChange) {
|
|
309
|
-
this.unavailableCapabilities = (0, deviceFeaturesUtils_1.getUnavailableCapabilities)(feat, (0, coinInfo_1.getAllNetworks)());
|
|
310
|
-
this.firmwareStatus = (0, firmwareInfo_1.getFirmwareStatus)(feat);
|
|
311
|
-
this.firmwareRelease = (0, firmwareInfo_1.getRelease)(feat);
|
|
312
|
-
}
|
|
313
306
|
if (this.features && this.features.session_id && !feat.session_id) {
|
|
314
307
|
feat.session_id = this.features.session_id;
|
|
315
308
|
}
|
|
@@ -322,6 +315,16 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
322
315
|
if (!feat.internal_model) {
|
|
323
316
|
feat.internal_model = (0, deviceFeaturesUtils_1.ensureInternalModelFeature)(feat.model);
|
|
324
317
|
}
|
|
318
|
+
const version = [
|
|
319
|
+
feat.major_version,
|
|
320
|
+
feat.minor_version,
|
|
321
|
+
feat.patch_version,
|
|
322
|
+
];
|
|
323
|
+
if (!utils_1.versionUtils.isEqual(version, this.getVersion())) {
|
|
324
|
+
this.unavailableCapabilities = (0, deviceFeaturesUtils_1.getUnavailableCapabilities)(feat, (0, coinInfo_1.getAllNetworks)());
|
|
325
|
+
this.firmwareStatus = (0, firmwareInfo_1.getFirmwareStatus)(feat);
|
|
326
|
+
this.firmwareRelease = (0, firmwareInfo_1.getRelease)(feat);
|
|
327
|
+
}
|
|
325
328
|
this.features = feat;
|
|
326
329
|
this.featuresNeedsReload = false;
|
|
327
330
|
if (this.getMode() !== 'bootloader') {
|
|
@@ -332,6 +335,14 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
332
335
|
? types_1.FirmwareType.BitcoinOnly
|
|
333
336
|
: types_1.FirmwareType.Regular;
|
|
334
337
|
}
|
|
338
|
+
const deviceInfo = models_1.models[feat.internal_model];
|
|
339
|
+
this.name = deviceInfo.name;
|
|
340
|
+
if (feat === null || feat === void 0 ? void 0 : feat.unit_color) {
|
|
341
|
+
const deviceUnitColor = feat.unit_color.toString();
|
|
342
|
+
if (deviceUnitColor in deviceInfo.colors) {
|
|
343
|
+
this.color = deviceInfo.colors[deviceUnitColor];
|
|
344
|
+
}
|
|
345
|
+
}
|
|
335
346
|
}
|
|
336
347
|
isUnacquired() {
|
|
337
348
|
return this.features === undefined;
|
|
@@ -340,7 +351,7 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
340
351
|
_log.debug('Disconnect cleanup');
|
|
341
352
|
this.activitySessionID = null;
|
|
342
353
|
this.interruptionFromUser(constants_1.ERRORS.TypedError('Device_Disconnected'));
|
|
343
|
-
this.runPromise
|
|
354
|
+
delete this.runPromise;
|
|
344
355
|
}
|
|
345
356
|
isBootloader() {
|
|
346
357
|
return this.features && !!this.features.bootloader_mode;
|
|
@@ -367,7 +378,7 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
367
378
|
if (!this.features)
|
|
368
379
|
return false;
|
|
369
380
|
const modelVersion = typeof versions === 'string' ? versions : versions[this.features.major_version - 1];
|
|
370
|
-
return
|
|
381
|
+
return utils_1.versionUtils.isNewerOrEqual(this.getVersion().join('.'), modelVersion);
|
|
371
382
|
}
|
|
372
383
|
isUsed() {
|
|
373
384
|
return typeof this.originalDescriptor.session === 'string';
|
|
@@ -443,6 +454,7 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
443
454
|
path: this.originalDescriptor.path,
|
|
444
455
|
error: this.unreadableError,
|
|
445
456
|
label: 'Unreadable device',
|
|
457
|
+
name: this.name,
|
|
446
458
|
};
|
|
447
459
|
}
|
|
448
460
|
if (this.isUnacquired()) {
|
|
@@ -450,6 +462,7 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
450
462
|
type: 'unacquired',
|
|
451
463
|
path: this.originalDescriptor.path,
|
|
452
464
|
label: 'Unacquired device',
|
|
465
|
+
name: this.name,
|
|
453
466
|
};
|
|
454
467
|
}
|
|
455
468
|
const defaultLabel = 'My Trezor';
|
|
@@ -465,6 +478,8 @@ class Device extends typedEventEmitter_1.TypedEmitter {
|
|
|
465
478
|
state: this.getExternalState(),
|
|
466
479
|
status,
|
|
467
480
|
mode: this.getMode(),
|
|
481
|
+
name: this.name,
|
|
482
|
+
color: this.color,
|
|
468
483
|
firmware: this.firmwareStatus,
|
|
469
484
|
firmwareRelease: this.firmwareRelease,
|
|
470
485
|
firmwareType: this.firmwareType,
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DeviceCommands = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
const utils_1 = require("@trezor/utils");
|
|
6
7
|
const constants_1 = require("../constants");
|
|
7
8
|
const events_1 = require("../events");
|
|
8
9
|
const hdnodeUtils = tslib_1.__importStar(require("../utils/hdnodeUtils"));
|
|
9
10
|
const pathUtils_1 = require("../utils/pathUtils");
|
|
10
11
|
const accountUtils_1 = require("../utils/accountUtils");
|
|
11
|
-
const versionUtils_1 = require("../utils/versionUtils");
|
|
12
12
|
const coinInfo_1 = require("../data/coinInfo");
|
|
13
13
|
const debug_1 = require("../utils/debug");
|
|
14
14
|
const logger = (0, debug_1.initLog)('DeviceCommands');
|
|
@@ -20,7 +20,7 @@ const assertType = (res, resType) => {
|
|
|
20
20
|
};
|
|
21
21
|
const generateEntropy = (len) => {
|
|
22
22
|
try {
|
|
23
|
-
return (0,
|
|
23
|
+
return (0, crypto_1.randomBytes)(len);
|
|
24
24
|
}
|
|
25
25
|
catch (err) {
|
|
26
26
|
throw constants_1.ERRORS.TypedError('Runtime', 'generateEntropy: Environment does not support crypto random');
|
|
@@ -493,7 +493,7 @@ class DeviceCommands {
|
|
|
493
493
|
return;
|
|
494
494
|
}
|
|
495
495
|
const { name, version } = this.transport;
|
|
496
|
-
if (name === 'BridgeTransport' &&
|
|
496
|
+
if (name === 'BridgeTransport' && !utils_1.versionUtils.isNewer(version, '2.0.28')) {
|
|
497
497
|
try {
|
|
498
498
|
await this.device.legacyForceRelease();
|
|
499
499
|
}
|
|
@@ -27,6 +27,7 @@ export declare class DeviceList extends TypedEmitter<DeviceListEvents> {
|
|
|
27
27
|
penalizedDevices: {
|
|
28
28
|
[deviceID: string]: number;
|
|
29
29
|
};
|
|
30
|
+
transportFirstEventPromise: Promise<void> | undefined;
|
|
30
31
|
constructor();
|
|
31
32
|
init(): Promise<void>;
|
|
32
33
|
private resolveTransportEvent;
|
|
@@ -39,7 +40,7 @@ export declare class DeviceList extends TypedEmitter<DeviceListEvents> {
|
|
|
39
40
|
asArray(): DeviceTyped[];
|
|
40
41
|
allDevices(): Device[];
|
|
41
42
|
length(): number;
|
|
42
|
-
transportType(): "BridgeTransport" | "NodeUsbTransport" | "WebUsbTransport";
|
|
43
|
+
transportType(): "BridgeTransport" | "NodeUsbTransport" | "WebUsbTransport" | "UdpTransport";
|
|
43
44
|
getTransportInfo(): TransportInfo;
|
|
44
45
|
dispose(): Promise<void>;
|
|
45
46
|
disconnectDevices(): void;
|
package/lib/device/DeviceList.js
CHANGED
|
@@ -49,6 +49,12 @@ class DeviceList extends typedEventEmitter_1.TypedEmitter {
|
|
|
49
49
|
logger: transportLogger,
|
|
50
50
|
}));
|
|
51
51
|
break;
|
|
52
|
+
case 'UdpTransport':
|
|
53
|
+
this.transports.push(new transport_1.UdpTransport({
|
|
54
|
+
logger: transportLogger,
|
|
55
|
+
messages: this.messages,
|
|
56
|
+
}));
|
|
57
|
+
break;
|
|
52
58
|
default:
|
|
53
59
|
throw constants_1.ERRORS.TypedError('Runtime', `DeviceList.init: transports[] of unexpected type: ${transportType}`);
|
|
54
60
|
}
|
|
@@ -120,7 +126,7 @@ class DeviceList extends typedEventEmitter_1.TypedEmitter {
|
|
|
120
126
|
await (0, promiseUtils_1.resolveAfter)(1000, null).promise;
|
|
121
127
|
if (device) {
|
|
122
128
|
if (!device.isUsed() && device.isUnacquired() && !device.isInconsistent()) {
|
|
123
|
-
_log.debug('Create device from unacquired', device);
|
|
129
|
+
_log.debug('Create device from unacquired', device.toMessageObject());
|
|
124
130
|
await this._createAndSaveDevice(descriptor);
|
|
125
131
|
}
|
|
126
132
|
}
|
|
@@ -143,7 +149,7 @@ class DeviceList extends typedEventEmitter_1.TypedEmitter {
|
|
|
143
149
|
d.forEach(descriptor => {
|
|
144
150
|
const path = descriptor.path.toString();
|
|
145
151
|
const device = this.devices[path];
|
|
146
|
-
_log.debug('Event', e, device);
|
|
152
|
+
_log.debug('Event', e, device.toMessageObject());
|
|
147
153
|
if (device) {
|
|
148
154
|
this.emit(e, device.toMessageObject());
|
|
149
155
|
}
|
|
@@ -204,7 +210,7 @@ class DeviceList extends typedEventEmitter_1.TypedEmitter {
|
|
|
204
210
|
}
|
|
205
211
|
}
|
|
206
212
|
async waitForTransportFirstEvent() {
|
|
207
|
-
|
|
213
|
+
this.transportFirstEventPromise = new Promise(resolve => {
|
|
208
214
|
const handler = () => {
|
|
209
215
|
this.removeListener(transport_1.TRANSPORT.START, handler);
|
|
210
216
|
this.removeListener(transport_1.TRANSPORT.ERROR, handler);
|
|
@@ -213,6 +219,7 @@ class DeviceList extends typedEventEmitter_1.TypedEmitter {
|
|
|
213
219
|
this.on(transport_1.TRANSPORT.START, handler);
|
|
214
220
|
this.on(transport_1.TRANSPORT.ERROR, handler);
|
|
215
221
|
});
|
|
222
|
+
await this.transportFirstEventPromise;
|
|
216
223
|
}
|
|
217
224
|
async _createAndSaveDevice(descriptor) {
|
|
218
225
|
_log.debug('Creating Device', descriptor);
|
package/lib/events/iframe.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { UI_EVENT } from './ui-request';
|
|
2
2
|
import type { ConnectSettings, SystemInfo } from '../types';
|
|
3
3
|
import type { MessageFactoryFn } from '../types/utils';
|
|
4
|
+
import { LogMessage } from '../utils/debug';
|
|
4
5
|
export declare const IFRAME: {
|
|
5
6
|
readonly BOOTSTRAP: "iframe-bootstrap";
|
|
6
7
|
readonly LOADED: "iframe-loaded";
|
|
7
8
|
readonly INIT: "iframe-init";
|
|
8
9
|
readonly ERROR: "iframe-error";
|
|
9
10
|
readonly CALL: "iframe-call";
|
|
11
|
+
readonly LOG: "iframe-log";
|
|
10
12
|
};
|
|
11
13
|
export interface IFrameError {
|
|
12
14
|
type: typeof IFRAME.ERROR;
|
|
@@ -29,10 +31,14 @@ export interface IFrameInit {
|
|
|
29
31
|
extension?: string;
|
|
30
32
|
};
|
|
31
33
|
}
|
|
34
|
+
export interface IFrameLogRequest {
|
|
35
|
+
type: typeof IFRAME.LOG;
|
|
36
|
+
payload: LogMessage;
|
|
37
|
+
}
|
|
32
38
|
export type IFrameEvent = {
|
|
33
39
|
type: typeof IFRAME.BOOTSTRAP;
|
|
34
40
|
payload?: typeof undefined;
|
|
35
|
-
} | IFrameLoaded | IFrameInit | IFrameError;
|
|
41
|
+
} | IFrameLoaded | IFrameInit | IFrameLogRequest | IFrameError;
|
|
36
42
|
export type IFrameEventMessage = IFrameEvent & {
|
|
37
43
|
event: typeof UI_EVENT;
|
|
38
44
|
};
|
package/lib/events/iframe.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
import type { Deferred } from '@trezor/utils';
|
|
1
2
|
import type { DEVICE } from './device';
|
|
2
3
|
import type { Device } from '../device/Device';
|
|
3
4
|
import type { UiResponseEvent } from './ui-response';
|
|
4
|
-
import type { Deferred } from '../utils/deferred';
|
|
5
5
|
export type UiPromiseResponse = UiResponseEvent | {
|
|
6
6
|
type: typeof DEVICE.DISCONNECT;
|
|
7
7
|
payload?: undefined;
|
|
8
8
|
};
|
|
9
9
|
export type UiPromise<T extends UiPromiseResponse['type']> = Deferred<Extract<UiPromiseResponse, {
|
|
10
10
|
type: T;
|
|
11
|
-
}>, T
|
|
11
|
+
}>, T> & {
|
|
12
|
+
device?: Device;
|
|
13
|
+
};
|
|
14
|
+
type UiPromiseMap = {
|
|
15
|
+
[T in UiPromiseResponse['type']]: UiPromise<T>;
|
|
16
|
+
};
|
|
17
|
+
export type AnyUiPromise = UiPromiseMap[UiPromiseResponse['type']];
|
|
18
|
+
export type UiPromiseCreator = <T extends UiPromiseResponse['type']>(type: T, device?: Device) => UiPromise<T>;
|
|
19
|
+
export {};
|
|
12
20
|
//# sourceMappingURL=ui-promise.d.ts.map
|
package/lib/factory.js
CHANGED
|
@@ -110,6 +110,7 @@ const factory = ({ eventEmitter, manifest, init, call, requestLogin, uiResponse,
|
|
|
110
110
|
checkFirmwareAuthenticity: params => call({ ...params, method: 'checkFirmwareAuthenticity' }),
|
|
111
111
|
applyFlags: params => call({ ...params, method: 'applyFlags' }),
|
|
112
112
|
applySettings: params => call({ ...params, method: 'applySettings' }),
|
|
113
|
+
authenticateDevice: params => call({ ...params, method: 'authenticateDevice' }),
|
|
113
114
|
authorizeCoinjoin: params => call({ ...params, method: 'authorizeCoinjoin' }),
|
|
114
115
|
cancelCoinjoinAuthorization: params => call({ ...params, method: 'cancelCoinjoinAuthorization' }),
|
|
115
116
|
showDeviceTutorial: params => call({ ...params, method: 'showDeviceTutorial' }),
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DeviceAuthenticityConfig } from '../../data/deviceAuthenticityConfig';
|
|
2
|
+
import type { Params, Response } from '../params';
|
|
3
|
+
export interface AuthenticateDeviceParams {
|
|
4
|
+
config?: DeviceAuthenticityConfig;
|
|
5
|
+
allowDebugKeys?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export type AuthenticateDeviceResult = {
|
|
8
|
+
valid: true;
|
|
9
|
+
caPubKey: string;
|
|
10
|
+
debugKey?: boolean;
|
|
11
|
+
configExpired?: typeof undefined;
|
|
12
|
+
error?: typeof undefined;
|
|
13
|
+
} | {
|
|
14
|
+
valid: false;
|
|
15
|
+
caPubKey: string;
|
|
16
|
+
debugKey?: boolean;
|
|
17
|
+
configExpired?: boolean;
|
|
18
|
+
error: 'ROOT_PUBKEY_NOT_FOUND' | 'CA_PUBKEY_NOT_FOUND' | 'INVALID_DEVICE_MODEL' | 'INVALID_DEVICE_CERTIFICATE' | 'INVALID_DEVICE_SIGNATURE';
|
|
19
|
+
};
|
|
20
|
+
export declare function authenticateDevice(params: Params<AuthenticateDeviceParams>): Response<AuthenticateDeviceResult>;
|
|
21
|
+
//# sourceMappingURL=authenticateDevice.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PROTO } from '../../constants';
|
|
2
|
-
import type { Params, Response } from '../params';
|
|
2
|
+
import type { Params, Response, DerivationPath } from '../params';
|
|
3
3
|
export interface AuthorizeCoinjoin {
|
|
4
|
-
path:
|
|
4
|
+
path: DerivationPath;
|
|
5
5
|
coordinator: string;
|
|
6
6
|
maxRounds: number;
|
|
7
7
|
maxCoordinatorFeeRate: number;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PROTO } from '../../../constants';
|
|
2
|
+
import type { DerivationPath } from '../../params';
|
|
2
3
|
export interface BinanceSDKTransaction {
|
|
3
4
|
chain_id: string;
|
|
4
5
|
account_number?: number;
|
|
@@ -23,7 +24,7 @@ export interface BinancePreparedTransaction extends BinanceSDKTransaction {
|
|
|
23
24
|
source: number;
|
|
24
25
|
}
|
|
25
26
|
export interface BinanceSignTransaction {
|
|
26
|
-
path:
|
|
27
|
+
path: DerivationPath;
|
|
27
28
|
transaction: BinanceSDKTransaction;
|
|
28
29
|
}
|
|
29
30
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { PROTO } from '../../../constants';
|
|
2
1
|
import type { AccountAddresses } from '@trezor/blockchain-link';
|
|
3
2
|
import type { Transaction as BlockbookTransaction } from '@trezor/blockchain-link-types/lib/blockbook';
|
|
4
|
-
import {
|
|
3
|
+
import type { PROTO } from '../../../constants';
|
|
4
|
+
import type { AccountTransaction } from '../../account';
|
|
5
|
+
import type { DerivationPath, ProtoWithDerivationPath } from '../../params';
|
|
5
6
|
export interface SignMessage {
|
|
6
|
-
path:
|
|
7
|
+
path: DerivationPath;
|
|
7
8
|
coin: string;
|
|
8
9
|
message: string;
|
|
9
10
|
hex?: boolean;
|
|
@@ -50,8 +51,8 @@ export interface TransactionOptions {
|
|
|
50
51
|
coinjoin_request?: PROTO.CoinJoinRequest;
|
|
51
52
|
}
|
|
52
53
|
export interface SignTransaction {
|
|
53
|
-
inputs: PROTO.TxInputType[];
|
|
54
|
-
outputs: PROTO.TxOutputType[];
|
|
54
|
+
inputs: ProtoWithDerivationPath<PROTO.TxInputType>[];
|
|
55
|
+
outputs: ProtoWithDerivationPath<PROTO.TxOutputType>[];
|
|
55
56
|
paymentRequests?: PROTO.TxAckPaymentRequest[];
|
|
56
57
|
refTxs?: RefTransaction[];
|
|
57
58
|
account?: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PROTO } from '../../../constants';
|
|
2
|
-
import type { GetPublicKey, PublicKey } from '../../params';
|
|
2
|
+
import type { GetPublicKey, PublicKey, DerivationPath } from '../../params';
|
|
3
3
|
export interface CardanoCertificatePointer {
|
|
4
4
|
blockIndex: number;
|
|
5
5
|
txIndex: number;
|
|
@@ -7,8 +7,8 @@ export interface CardanoCertificatePointer {
|
|
|
7
7
|
}
|
|
8
8
|
export interface CardanoAddressParameters {
|
|
9
9
|
addressType: PROTO.CardanoAddressType;
|
|
10
|
-
path?:
|
|
11
|
-
stakingPath?:
|
|
10
|
+
path?: DerivationPath;
|
|
11
|
+
stakingPath?: DerivationPath;
|
|
12
12
|
stakingKeyHash?: string;
|
|
13
13
|
certificatePointer?: CardanoCertificatePointer;
|
|
14
14
|
paymentScriptHash?: string;
|
|
@@ -34,7 +34,7 @@ export interface CardanoNativeScript {
|
|
|
34
34
|
type: PROTO.CardanoNativeScriptType;
|
|
35
35
|
scripts?: CardanoNativeScript[];
|
|
36
36
|
keyHash?: string;
|
|
37
|
-
keyPath?:
|
|
37
|
+
keyPath?: DerivationPath;
|
|
38
38
|
requiredSignaturesCount?: number;
|
|
39
39
|
invalidBefore?: string;
|
|
40
40
|
invalidHereafter?: string;
|
|
@@ -54,7 +54,7 @@ export interface CardanoPublicKey extends PublicKey {
|
|
|
54
54
|
node: PROTO.HDNodeType;
|
|
55
55
|
}
|
|
56
56
|
export interface CardanoInput {
|
|
57
|
-
path?:
|
|
57
|
+
path?: DerivationPath;
|
|
58
58
|
prev_hash: string;
|
|
59
59
|
prev_index: number;
|
|
60
60
|
}
|
|
@@ -80,7 +80,7 @@ export type CardanoOutput = ({
|
|
|
80
80
|
referenceScript?: string;
|
|
81
81
|
};
|
|
82
82
|
export interface CardanoPoolOwner {
|
|
83
|
-
stakingKeyPath?:
|
|
83
|
+
stakingKeyPath?: DerivationPath;
|
|
84
84
|
stakingKeyHash?: string;
|
|
85
85
|
}
|
|
86
86
|
export interface CardanoPoolRelay {
|
|
@@ -111,26 +111,26 @@ export interface CardanoPoolParameters {
|
|
|
111
111
|
}
|
|
112
112
|
export interface CardanoCertificate {
|
|
113
113
|
type: PROTO.CardanoCertificateType;
|
|
114
|
-
path?:
|
|
114
|
+
path?: DerivationPath;
|
|
115
115
|
pool?: string;
|
|
116
116
|
poolParameters?: CardanoPoolParameters;
|
|
117
117
|
scriptHash?: string;
|
|
118
118
|
keyHash?: string;
|
|
119
119
|
}
|
|
120
120
|
export interface CardanoWithdrawal {
|
|
121
|
-
path?:
|
|
121
|
+
path?: DerivationPath;
|
|
122
122
|
amount: string;
|
|
123
123
|
scriptHash?: string;
|
|
124
124
|
keyHash?: string;
|
|
125
125
|
}
|
|
126
126
|
export type CardanoMint = CardanoAssetGroup[];
|
|
127
127
|
export interface CardanoCollateralInput {
|
|
128
|
-
path?:
|
|
128
|
+
path?: DerivationPath;
|
|
129
129
|
prev_hash: string;
|
|
130
130
|
prev_index: number;
|
|
131
131
|
}
|
|
132
132
|
export interface CardanoRequiredSigner {
|
|
133
|
-
keyPath?:
|
|
133
|
+
keyPath?: DerivationPath;
|
|
134
134
|
keyHash?: string;
|
|
135
135
|
}
|
|
136
136
|
export interface CardanoReferenceInput {
|
|
@@ -143,7 +143,7 @@ export interface CardanoCVoteRegistrationDelegation {
|
|
|
143
143
|
}
|
|
144
144
|
export interface CardanoCVoteRegistrationParameters {
|
|
145
145
|
votePublicKey?: string;
|
|
146
|
-
stakingPath:
|
|
146
|
+
stakingPath: DerivationPath;
|
|
147
147
|
paymentAddressParameters?: CardanoAddressParameters;
|
|
148
148
|
nonce: string;
|
|
149
149
|
format?: PROTO.CardanoCVoteRegistrationFormat;
|
|
@@ -171,7 +171,7 @@ export interface CardanoSignTransaction {
|
|
|
171
171
|
collateralReturn?: CardanoOutput;
|
|
172
172
|
totalCollateral?: string;
|
|
173
173
|
referenceInputs?: CardanoReferenceInput[];
|
|
174
|
-
additionalWitnessRequests?:
|
|
174
|
+
additionalWitnessRequests?: DerivationPath[];
|
|
175
175
|
protocolMagic: number;
|
|
176
176
|
networkId: number;
|
|
177
177
|
signingMode: PROTO.CardanoTxSigningMode;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { Params, BundledParams, Response } from '../params';
|
|
2
|
+
import type { Params, BundledParams, Response, DerivationPath } from '../params';
|
|
3
3
|
export interface CipherKeyValue {
|
|
4
|
-
path:
|
|
4
|
+
path: DerivationPath;
|
|
5
5
|
key: string;
|
|
6
6
|
value: string | Buffer;
|
|
7
7
|
encrypt?: boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { PROTO } from '../../../constants';
|
|
1
|
+
import type { PROTO } from '../../../constants';
|
|
2
|
+
import type { DerivationPath } from '../../params';
|
|
2
3
|
export interface EosPublicKey {
|
|
3
4
|
wifPublicKey: string;
|
|
4
5
|
rawPublicKey: string;
|
|
@@ -109,7 +110,7 @@ export interface EosSDKTransaction {
|
|
|
109
110
|
})>;
|
|
110
111
|
}
|
|
111
112
|
export interface EosSignTransaction {
|
|
112
|
-
path:
|
|
113
|
+
path: DerivationPath;
|
|
113
114
|
transaction: EosSDKTransaction;
|
|
114
115
|
}
|
|
115
116
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { DerivationPath } from '../../params';
|
|
1
2
|
export interface EthereumSignMessage {
|
|
2
|
-
path:
|
|
3
|
+
path: DerivationPath;
|
|
3
4
|
message: string;
|
|
4
5
|
hex?: boolean;
|
|
5
6
|
}
|
|
@@ -32,7 +33,7 @@ export interface EthereumTransactionEIP1559 {
|
|
|
32
33
|
accessList?: EthereumAccessList[];
|
|
33
34
|
}
|
|
34
35
|
export interface EthereumSignTransaction {
|
|
35
|
-
path:
|
|
36
|
+
path: DerivationPath;
|
|
36
37
|
transaction: EthereumTransaction | EthereumTransactionEIP1559;
|
|
37
38
|
}
|
|
38
39
|
export interface EthereumSignedTx {
|
|
@@ -63,14 +64,14 @@ export interface EthereumSignTypedDataMessage<T extends EthereumSignTypedDataTyp
|
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
export interface EthereumSignTypedData<T extends EthereumSignTypedDataTypes> {
|
|
66
|
-
path:
|
|
67
|
+
path: DerivationPath;
|
|
67
68
|
data: EthereumSignTypedDataMessage<T>;
|
|
68
69
|
metamask_v4_compat: boolean;
|
|
69
70
|
domain_separator_hash?: undefined;
|
|
70
71
|
message_hash?: undefined;
|
|
71
72
|
}
|
|
72
73
|
export interface EthereumSignTypedHash<T extends EthereumSignTypedDataTypes> {
|
|
73
|
-
path:
|
|
74
|
+
path: DerivationPath;
|
|
74
75
|
data: EthereumSignTypedDataMessage<T>;
|
|
75
76
|
metamask_v4_compat: boolean;
|
|
76
77
|
domain_separator_hash: string;
|
|
@@ -8,6 +8,7 @@ export interface GetAccountInfo extends Omit<BlockchainLinkParams<'getAccountInf
|
|
|
8
8
|
descriptor?: string;
|
|
9
9
|
defaultAccountType?: DiscoveryAccountType;
|
|
10
10
|
derivationType?: PROTO.CardanoDerivationType;
|
|
11
|
+
suppressBackupWarning?: boolean;
|
|
11
12
|
}
|
|
12
13
|
export declare function getAccountInfo(params: Params<GetAccountInfo>): Response<AccountInfo>;
|
|
13
14
|
export declare function getAccountInfo(params: BundledParams<GetAccountInfo>): Response<(AccountInfo | null)[]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PROTO } from '../../constants';
|
|
2
|
-
import type { Params, BundledParams, Response } from '../params';
|
|
2
|
+
import type { Params, BundledParams, Response, DerivationPath } from '../params';
|
|
3
3
|
export interface GetOwnershipId {
|
|
4
|
-
path:
|
|
4
|
+
path: DerivationPath;
|
|
5
5
|
coin?: string;
|
|
6
6
|
multisig?: PROTO.MultisigRedeemScriptType;
|
|
7
7
|
scriptType?: PROTO.InternalInputScriptType;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PROTO } from '../../constants';
|
|
2
|
-
import type { Params, BundledParams, Response } from '../params';
|
|
2
|
+
import type { Params, BundledParams, Response, DerivationPath } from '../params';
|
|
3
3
|
export interface GetOwnershipProof {
|
|
4
|
-
path:
|
|
4
|
+
path: DerivationPath;
|
|
5
5
|
coin?: string;
|
|
6
6
|
multisig?: PROTO.MultisigRedeemScriptType;
|
|
7
7
|
scriptType?: PROTO.InternalInputScriptType;
|