@trezor/connect 9.5.1-beta.1 → 9.5.2-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 +29 -5
- package/README.md +1 -1
- package/lib/api/ethereum/api/ethereumSignTypedData.js +2 -1
- package/lib/api/firmware/getBinaryForFirmwareUpgrade.d.ts +2 -1
- package/lib/api/firmware/parseFirmwareHeaders.d.ts +1 -1
- package/lib/api/firmware/uploadFirmware.js +1 -1
- package/lib/api/getFeatures.d.ts +1 -1
- package/lib/api/resetDevice.js +16 -10
- package/lib/api/solana/solanaUtils.d.ts +4 -4
- package/lib/api/solana/solanaUtils.js +1 -1
- package/lib/api/wipeDevice.js +4 -1
- package/lib/core/index.js +31 -20
- package/lib/core/method.js +1 -1
- package/lib/core/onCallFirmwareUpdate.d.ts +2 -1
- package/lib/core/onCallFirmwareUpdate.js +10 -16
- package/lib/data/DataManager.js +4 -4
- package/lib/data/deviceAuthenticityConfig.js +4 -1
- package/lib/data/firmwareInfo.d.ts +4 -3
- package/lib/data/firmwareInfo.js +10 -6
- package/lib/data/models.d.ts +1 -1
- package/lib/data/transportInfo.d.ts +0 -1
- package/lib/data/transportInfo.js +2 -3
- package/lib/data/version.d.ts +1 -1
- package/lib/data/version.js +1 -1
- package/lib/device/Device.d.ts +22 -8
- package/lib/device/Device.js +17 -10
- package/lib/device/DeviceCommands.d.ts +3 -3
- package/lib/device/DeviceCommands.js +17 -13
- package/lib/device/TransportList.js +1 -5
- package/lib/device/calculateRevisionForDevice.d.ts +1 -1
- package/lib/device/checkFirmwareRevision.js +8 -4
- package/lib/device/prompts.d.ts +26 -12
- package/lib/device/prompts.js +19 -13
- package/lib/events/device.d.ts +1 -1
- package/lib/types/api/device.d.ts +1 -0
- package/lib/types/api/device.js +2 -0
- package/lib/types/api/firmwareUpdate.d.ts +1 -1
- package/lib/types/coinInfo.js +2 -2
- package/lib/types/device.d.ts +3 -41
- package/lib/types/device.js +1 -8
- package/lib/types/firmware.d.ts +1 -2
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +3 -0
- package/lib/utils/assetUtils.d.ts +1 -1
- package/lib/utils/assetUtils.js +9 -9
- package/lib/utils/deviceFeaturesUtils.d.ts +2 -1
- package/lib/utils/deviceFeaturesUtils.js +4 -4
- package/package.json +19 -18
package/lib/device/Device.d.ts
CHANGED
|
@@ -19,12 +19,26 @@ export declare const CANCEL_TIMEOUT = 1000;
|
|
|
19
19
|
export declare const GET_FEATURES_TIMEOUT = 3000;
|
|
20
20
|
export declare const GET_FEATURES_TIMEOUT_REACT_NATIVE = 20000;
|
|
21
21
|
export interface DeviceEvents {
|
|
22
|
-
[DEVICE.PIN]:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
[DEVICE.
|
|
22
|
+
[DEVICE.PIN]: {
|
|
23
|
+
device: Device;
|
|
24
|
+
type: PROTO.PinMatrixRequestType | undefined;
|
|
25
|
+
callback: PromptCallback<UiResponsePin['payload']>;
|
|
26
|
+
};
|
|
27
|
+
[DEVICE.WORD]: {
|
|
28
|
+
device: Device;
|
|
29
|
+
type: PROTO.WordRequestType;
|
|
30
|
+
callback: PromptCallback<UiResponseWord['payload']>;
|
|
31
|
+
};
|
|
32
|
+
[DEVICE.PASSPHRASE]: {
|
|
33
|
+
device: Device;
|
|
34
|
+
callback: PromptCallback<UiResponsePassphrase['payload']>;
|
|
35
|
+
};
|
|
36
|
+
[DEVICE.PASSPHRASE_ON_DEVICE]: void;
|
|
37
|
+
[DEVICE.BUTTON]: {
|
|
38
|
+
device: Device;
|
|
39
|
+
payload: DeviceButtonRequestPayload;
|
|
40
|
+
};
|
|
41
|
+
[DEVICE.FIRMWARE_VERSION_CHANGED]: DeviceVersionChanged['payload'];
|
|
28
42
|
}
|
|
29
43
|
type DeviceLifecycle = typeof DEVICE.CONNECT | typeof DEVICE.CONNECT_UNACQUIRED | typeof DEVICE.DISCONNECT | typeof DEVICE.CHANGED;
|
|
30
44
|
type DeviceLifecycleListener = (lifecycle: DeviceLifecycle) => void;
|
|
@@ -134,7 +148,7 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
134
148
|
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" | "descriptor not found" | "wrong previous session" | "LIBUSB_ERROR_ACCESS">;
|
|
135
149
|
release(): Promise<import("@trezor/transport/lib/types").Success<null> | {
|
|
136
150
|
success: false;
|
|
137
|
-
error: "
|
|
151
|
+
error: "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";
|
|
138
152
|
message?: string;
|
|
139
153
|
} | undefined>;
|
|
140
154
|
releaseTransportSession(): void;
|
|
@@ -191,7 +205,7 @@ export declare class Device extends TypedEmitter<DeviceEvents> {
|
|
|
191
205
|
getUniquePath(): DeviceUniquePath;
|
|
192
206
|
isT1(): boolean;
|
|
193
207
|
hasUnexpectedMode(allow: string[], require: string[]): "ui-device_bootloader_mode" | "ui-device_not_in_bootloader_mode" | "ui-device_not_initialized" | "ui-device_seedless" | null;
|
|
194
|
-
dispose(): import("@trezor/transport/lib/types").AsyncResultWithTypedError<null, "
|
|
208
|
+
dispose(): 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;
|
|
195
209
|
private getMode;
|
|
196
210
|
toMessageObject(): DeviceTyped;
|
|
197
211
|
}
|
package/lib/device/Device.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Device = exports.GET_FEATURES_TIMEOUT_REACT_NATIVE = exports.GET_FEATURES_TIMEOUT = exports.CANCEL_TIMEOUT = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
|
+
const device_utils_1 = require("@trezor/device-utils");
|
|
5
6
|
const protocol_1 = require("@trezor/protocol");
|
|
6
7
|
const transport_1 = require("@trezor/transport");
|
|
7
8
|
const utils_1 = require("@trezor/utils");
|
|
@@ -289,7 +290,7 @@ class Device extends utils_1.TypedEmitter {
|
|
|
289
290
|
}
|
|
290
291
|
async interruptionFromUser(error) {
|
|
291
292
|
_log.debug('interruptionFromUser');
|
|
292
|
-
await this.cancelableAction?.(error);
|
|
293
|
+
await this.cancelableAction?.(error.toString());
|
|
293
294
|
await this.commands?.cancel();
|
|
294
295
|
if (this.runPromise) {
|
|
295
296
|
this.runPromise.reject(error);
|
|
@@ -503,7 +504,10 @@ class Device extends utils_1.TypedEmitter {
|
|
|
503
504
|
const lastErrorPayload = wasError ? lastResult?.errorPayload : null;
|
|
504
505
|
if (notDoneYet || wasErrorRetriable) {
|
|
505
506
|
const result = await this.checkFirmwareHash();
|
|
506
|
-
this.authenticityChecks
|
|
507
|
+
this.authenticityChecks = {
|
|
508
|
+
...this.authenticityChecks,
|
|
509
|
+
firmwareHash: result,
|
|
510
|
+
};
|
|
507
511
|
if (result === null)
|
|
508
512
|
return;
|
|
509
513
|
result.attemptCount = attemptsDone + 1;
|
|
@@ -574,16 +578,17 @@ class Device extends utils_1.TypedEmitter {
|
|
|
574
578
|
if (this.features.bootloader_mode === true) {
|
|
575
579
|
return;
|
|
576
580
|
}
|
|
577
|
-
const
|
|
578
|
-
const
|
|
579
|
-
utils_1.versionUtils.isVersionArray(firmwareVersion) &&
|
|
580
|
-
utils_1.versionUtils.isEqual(r.version, firmwareVersion));
|
|
581
|
-
this.authenticityChecks.firmwareRevision = await (0, checkFirmwareRevision_1.checkFirmwareRevision)({
|
|
581
|
+
const release = (0, firmwareInfo_1.getRelease)(this.features.internal_model, firmwareVersion);
|
|
582
|
+
const result = await (0, checkFirmwareRevision_1.checkFirmwareRevision)({
|
|
582
583
|
internalModel: this.features.internal_model,
|
|
583
584
|
deviceRevision: this.features.revision,
|
|
584
585
|
firmwareVersion,
|
|
585
586
|
expectedRevision: release?.firmware_revision,
|
|
586
587
|
});
|
|
588
|
+
this.authenticityChecks = {
|
|
589
|
+
...this.authenticityChecks,
|
|
590
|
+
firmwareRevision: result,
|
|
591
|
+
};
|
|
587
592
|
}
|
|
588
593
|
async changeLanguage({ language, binary, }) {
|
|
589
594
|
if (language === 'en-US') {
|
|
@@ -638,7 +643,7 @@ class Device extends utils_1.TypedEmitter {
|
|
|
638
643
|
if (!feat.model && feat.major_version === 1) {
|
|
639
644
|
feat.model = '1';
|
|
640
645
|
}
|
|
641
|
-
if (!feat.internal_model || !
|
|
646
|
+
if (!feat.internal_model || !device_utils_1.DeviceModelInternal[feat.internal_model]) {
|
|
642
647
|
feat.internal_model = (0, deviceFeaturesUtils_1.ensureInternalModelFeature)(feat.model);
|
|
643
648
|
}
|
|
644
649
|
const version = this.getVersion();
|
|
@@ -657,7 +662,7 @@ class Device extends utils_1.TypedEmitter {
|
|
|
657
662
|
}
|
|
658
663
|
this._unavailableCapabilities = (0, deviceFeaturesUtils_1.getUnavailableCapabilities)(feat, (0, coinInfo_1.getAllNetworks)());
|
|
659
664
|
this._firmwareStatus = (0, firmwareInfo_1.getFirmwareStatus)(feat);
|
|
660
|
-
this._firmwareRelease = (0, firmwareInfo_1.
|
|
665
|
+
this._firmwareRelease = (0, firmwareInfo_1.getReleaseInfo)(feat);
|
|
661
666
|
this.availableTranslations = this.firmwareRelease?.translations ?? [];
|
|
662
667
|
}
|
|
663
668
|
this._features = feat;
|
|
@@ -810,7 +815,9 @@ class Device extends utils_1.TypedEmitter {
|
|
|
810
815
|
type: 'unacquired',
|
|
811
816
|
label: 'Unacquired device',
|
|
812
817
|
name: this.name,
|
|
813
|
-
transportSessionOwner: this.
|
|
818
|
+
transportSessionOwner: this.lastAcquiredHere
|
|
819
|
+
? undefined
|
|
820
|
+
: this.transportSessionOwner,
|
|
814
821
|
bluetoothProps: this.bluetoothProps,
|
|
815
822
|
};
|
|
816
823
|
}
|
|
@@ -78,11 +78,11 @@ export declare class DeviceCommands {
|
|
|
78
78
|
descriptorChecksum?: string;
|
|
79
79
|
}>;
|
|
80
80
|
cancelWithFallback(): Promise<{
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
success: false;
|
|
82
|
+
error: "session not found";
|
|
83
83
|
} | import("@trezor/transport/lib/types").Success<import("@trezor/protobuf").MessageFromTrezor> | {
|
|
84
84
|
success: false;
|
|
85
|
-
error: "
|
|
85
|
+
error: import("@trezor/transport/lib/transports/abstract").ReadWriteError;
|
|
86
86
|
message?: string;
|
|
87
87
|
} | import("@trezor/transport/lib/types").Success<undefined> | undefined>;
|
|
88
88
|
cancel(): Promise<void>;
|
|
@@ -229,8 +229,8 @@ class DeviceCommands {
|
|
|
229
229
|
const res = await this.callPromise;
|
|
230
230
|
this.callPromise = undefined;
|
|
231
231
|
if (!res.success) {
|
|
232
|
-
logger.warn('Received error', res.error, res.message);
|
|
233
|
-
throw new Error(res.error);
|
|
232
|
+
logger.warn('Received transport error', res.error, res.message);
|
|
233
|
+
throw new Error(res.error, { cause: 'transport-error' });
|
|
234
234
|
}
|
|
235
235
|
logger.debug('Received', res.payload.type, filterForLog(res.payload.type, res.payload.message));
|
|
236
236
|
return res.payload;
|
|
@@ -291,25 +291,29 @@ class DeviceCommands {
|
|
|
291
291
|
this.device.emit(events_1.DEVICE.PASSPHRASE_ON_DEVICE);
|
|
292
292
|
}
|
|
293
293
|
else {
|
|
294
|
-
this.device.emit(events_1.DEVICE.BUTTON, this.device, res.message);
|
|
294
|
+
this.device.emit(events_1.DEVICE.BUTTON, { device: this.device, payload: res.message });
|
|
295
295
|
}
|
|
296
296
|
return this._commonCall('ButtonAck', {});
|
|
297
297
|
}
|
|
298
298
|
if (res.type === 'PinMatrixRequest') {
|
|
299
|
-
return (0, prompts_1.promptPin)(this.device, res.message.type).then(
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
299
|
+
return (0, prompts_1.promptPin)(this.device, res.message.type).then(promptRes => !promptRes.success
|
|
300
|
+
? Promise.reject(promptRes.error)
|
|
301
|
+
: this._commonCall('PinMatrixAck', { pin: promptRes.payload }).then(response => (this.device.features.unlocked
|
|
302
|
+
? Promise.resolve()
|
|
303
|
+
:
|
|
304
|
+
this.device.getFeatures()).then(() => response)));
|
|
305
305
|
}
|
|
306
306
|
if (res.type === 'PassphraseRequest') {
|
|
307
|
-
return (0, prompts_1.promptPassphrase)(this.device).then(
|
|
308
|
-
?
|
|
309
|
-
: this._commonCall('PassphraseAck',
|
|
307
|
+
return (0, prompts_1.promptPassphrase)(this.device).then(promptRes => !promptRes.success
|
|
308
|
+
? Promise.reject(promptRes.error)
|
|
309
|
+
: this._commonCall('PassphraseAck', promptRes.payload.passphraseOnDevice
|
|
310
|
+
? { on_device: true }
|
|
311
|
+
: { passphrase: promptRes.payload.value.normalize('NFKD') }));
|
|
310
312
|
}
|
|
311
313
|
if (res.type === 'WordRequest') {
|
|
312
|
-
return (0, prompts_1.promptWord)(this.device, res.message.type).then(
|
|
314
|
+
return (0, prompts_1.promptWord)(this.device, res.message.type).then(promptRes => !promptRes.success
|
|
315
|
+
? Promise.reject(promptRes.error)
|
|
316
|
+
: this._commonCall('WordAck', { word: promptRes.payload }));
|
|
313
317
|
}
|
|
314
318
|
return Promise.resolve(res);
|
|
315
319
|
}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createTransportList = void 0;
|
|
4
4
|
const transport_1 = require("@trezor/transport");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
|
-
const transportInfo_1 = require("../data/transportInfo");
|
|
7
6
|
const tryGetTransport = (transports, name) => transports.find(t => t.name === name);
|
|
8
7
|
const getOrCreateTransport = (transports, transportType, params) => {
|
|
9
8
|
if (typeof transportType === 'string') {
|
|
@@ -16,10 +15,7 @@ const getOrCreateTransport = (transports, transportType, params) => {
|
|
|
16
15
|
case 'NodeUsbTransport':
|
|
17
16
|
return new transport_1.NodeUsbTransport(params);
|
|
18
17
|
case 'BridgeTransport':
|
|
19
|
-
return new transport_1.BridgeTransport(
|
|
20
|
-
latestVersion: (0, transportInfo_1.getBridgeInfo)().version.join('.'),
|
|
21
|
-
...params,
|
|
22
|
-
});
|
|
18
|
+
return new transport_1.BridgeTransport(params);
|
|
23
19
|
case 'UdpTransport':
|
|
24
20
|
return new transport_1.UdpTransport(params);
|
|
25
21
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkFirmwareRevision = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_1 = require("@trezor/utils");
|
|
5
5
|
const downloadReleasesMetadata_1 = require("../data/downloadReleasesMetadata");
|
|
6
6
|
const calculateRevisionForDevice_1 = require("./calculateRevisionForDevice");
|
|
7
7
|
const assets_browser_1 = require("../utils/assets-browser");
|
|
@@ -15,9 +15,13 @@ const isOfflineError = (e) => {
|
|
|
15
15
|
};
|
|
16
16
|
const getOnlineReleaseMetadata = async ({ firmwareVersion, internalModel, }) => {
|
|
17
17
|
const onlineReleases = await (0, downloadReleasesMetadata_1.downloadReleasesMetadata)({ internal_model: internalModel });
|
|
18
|
-
return onlineReleases.find(onlineRelease =>
|
|
18
|
+
return onlineReleases.find(onlineRelease => utils_1.versionUtils.isEqual(onlineRelease.version, firmwareVersion));
|
|
19
19
|
};
|
|
20
|
-
const failFirmwareRevisionCheck = (error) => ({
|
|
20
|
+
const failFirmwareRevisionCheck = (error, errorPayload) => ({
|
|
21
|
+
success: false,
|
|
22
|
+
error,
|
|
23
|
+
...(errorPayload ? { errorPayload } : null),
|
|
24
|
+
});
|
|
21
25
|
const doRevisionsMatch = ({ deviceRevision, expectedCommitRevision, firmwareVersion, }) => {
|
|
22
26
|
if (deviceRevision === null) {
|
|
23
27
|
return false;
|
|
@@ -55,7 +59,7 @@ const checkFirmwareRevision = async ({ firmwareVersion, internalModel, deviceRev
|
|
|
55
59
|
return failFirmwareRevisionCheck('firmware-version-unknown');
|
|
56
60
|
return isOfflineError(e)
|
|
57
61
|
? failFirmwareRevisionCheck('cannot-perform-check-offline')
|
|
58
|
-
: failFirmwareRevisionCheck('other-error');
|
|
62
|
+
: failFirmwareRevisionCheck('other-error', (0, utils_1.serializeError)(e));
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
65
|
if (!doRevisionsMatch({
|
package/lib/device/prompts.d.ts
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import { Messages } from '@trezor/transport';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type { ReadWriteError } from '@trezor/transport/lib/transports/abstract';
|
|
3
|
+
import { DEVICE } from '../events';
|
|
4
|
+
import type { Device, DeviceEvents } from './Device';
|
|
5
|
+
type PromptEvents = typeof DEVICE.PIN | typeof DEVICE.PASSPHRASE | typeof DEVICE.WORD;
|
|
6
|
+
type DeviceEventCallback<K extends PromptEvents> = DeviceEvents[K]['callback'];
|
|
7
|
+
type PromptReturnType<E extends PromptEvents> = {
|
|
8
|
+
success: true;
|
|
9
|
+
payload: NonNullable<Parameters<DeviceEventCallback<E>>[0]>;
|
|
10
|
+
} | {
|
|
11
|
+
success: false;
|
|
12
|
+
isTransportError: false;
|
|
13
|
+
error: string;
|
|
14
|
+
message: string;
|
|
15
|
+
} | {
|
|
16
|
+
success: false;
|
|
17
|
+
isTransportError: true;
|
|
18
|
+
error: ReadWriteError;
|
|
19
|
+
};
|
|
20
|
+
export type PromptCallback<T> = (response: T | null, error?: string) => void;
|
|
4
21
|
export declare const cancelPrompt: (device: Device, expectResponse?: boolean) => Promise<{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}> | import("@trezor/transport/lib/types").AsyncResultWithTypedError<import("@trezor/protobuf").MessageFromTrezor,
|
|
8
|
-
export declare const promptPassphrase: (device: Device) => Promise<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}>;
|
|
13
|
-
export declare const promptPin: (device: Device, type?: Messages.PinMatrixRequestType) => Promise<string>;
|
|
14
|
-
export declare const promptWord: (device: Device, type: Messages.WordRequestType) => Promise<string>;
|
|
22
|
+
success: false;
|
|
23
|
+
error: "session not found";
|
|
24
|
+
}> | import("@trezor/transport/lib/types").AsyncResultWithTypedError<import("@trezor/protobuf").MessageFromTrezor, ReadWriteError> | import("@trezor/transport/lib/types").AsyncResultWithTypedError<undefined, ReadWriteError>;
|
|
25
|
+
export declare const promptPassphrase: (device: Device) => Promise<PromptReturnType<"passphrase">>;
|
|
26
|
+
export declare const promptPin: (device: Device, type?: Messages.PinMatrixRequestType) => Promise<PromptReturnType<"pin">>;
|
|
27
|
+
export declare const promptWord: (device: Device, type: Messages.WordRequestType) => Promise<PromptReturnType<"word">>;
|
|
28
|
+
export {};
|
|
15
29
|
//# sourceMappingURL=prompts.d.ts.map
|
package/lib/device/prompts.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.promptWord = exports.promptPin = exports.promptPassphrase = exports.cancelPrompt = void 0;
|
|
4
4
|
const transport_1 = require("@trezor/transport");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
5
|
const events_1 = require("../events");
|
|
7
6
|
const cancelPrompt = (device, expectResponse = true) => {
|
|
8
7
|
const session = device.getLocalSession();
|
|
@@ -21,11 +20,19 @@ const cancelPrompt = (device, expectResponse = true) => {
|
|
|
21
20
|
return expectResponse ? device.transport.call(cancelArgs) : device.transport.send(cancelArgs);
|
|
22
21
|
};
|
|
23
22
|
exports.cancelPrompt = cancelPrompt;
|
|
24
|
-
const prompt = (event,
|
|
25
|
-
const cancelAndReject = (error) => (0, exports.cancelPrompt)(device).then(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
:
|
|
23
|
+
const prompt = (event, { device, ...rest }) => new Promise(resolve => {
|
|
24
|
+
const cancelAndReject = (error) => (0, exports.cancelPrompt)(device).then(response => response.success
|
|
25
|
+
? resolve({
|
|
26
|
+
success: false,
|
|
27
|
+
error: error || response.payload?.message.message,
|
|
28
|
+
message: response.payload?.message.message,
|
|
29
|
+
isTransportError: !response.success,
|
|
30
|
+
})
|
|
31
|
+
: resolve({
|
|
32
|
+
success: false,
|
|
33
|
+
error: response.error,
|
|
34
|
+
isTransportError: true,
|
|
35
|
+
}));
|
|
29
36
|
if (device.listenerCount(event) > 0) {
|
|
30
37
|
device.setCancelableAction(cancelAndReject);
|
|
31
38
|
const callback = (...[response, error]) => {
|
|
@@ -34,20 +41,19 @@ const prompt = (event, ...[device, ...args]) => new Promise((resolve, reject) =>
|
|
|
34
41
|
cancelAndReject(error);
|
|
35
42
|
}
|
|
36
43
|
else {
|
|
37
|
-
resolve(response);
|
|
44
|
+
resolve({ success: true, payload: response });
|
|
38
45
|
}
|
|
39
46
|
};
|
|
40
|
-
|
|
41
|
-
device.emit(...emitArgs);
|
|
47
|
+
device.emit(event, { device, callback, ...rest });
|
|
42
48
|
}
|
|
43
49
|
else {
|
|
44
|
-
cancelAndReject(
|
|
50
|
+
cancelAndReject(`${event} callback not configured`);
|
|
45
51
|
}
|
|
46
52
|
});
|
|
47
|
-
const promptPassphrase = (device) => prompt(events_1.DEVICE.PASSPHRASE, device);
|
|
53
|
+
const promptPassphrase = (device) => prompt(events_1.DEVICE.PASSPHRASE, { device });
|
|
48
54
|
exports.promptPassphrase = promptPassphrase;
|
|
49
|
-
const promptPin = (device, type) => prompt(events_1.DEVICE.PIN, device, type);
|
|
55
|
+
const promptPin = (device, type) => prompt(events_1.DEVICE.PIN, { device, type });
|
|
50
56
|
exports.promptPin = promptPin;
|
|
51
|
-
const promptWord = (device, type) => prompt(events_1.DEVICE.WORD, device, type);
|
|
57
|
+
const promptWord = (device, type) => prompt(events_1.DEVICE.WORD, { device, type });
|
|
52
58
|
exports.promptWord = promptWord;
|
|
53
59
|
//# sourceMappingURL=prompts.js.map
|
package/lib/events/device.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { VersionArray } from '@trezor/device-utils';
|
|
1
2
|
import type { PROTO } from '../constants';
|
|
2
3
|
import type { Device } from '../types/device';
|
|
3
|
-
import type { VersionArray } from '../types/firmware';
|
|
4
4
|
import type { MessageFactoryFn } from '../types/utils';
|
|
5
5
|
export declare const DEVICE_EVENT = "DEVICE_EVENT";
|
|
6
6
|
export declare const DEVICE: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=device.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { VersionArray } from '@trezor/device-utils';
|
|
1
2
|
import { Static } from '@trezor/schema-utils';
|
|
2
|
-
import type { VersionArray } from '../firmware';
|
|
3
3
|
import type { Params, Response } from '../params';
|
|
4
4
|
export type FirmwareUpdate = Static<typeof FirmwareUpdate>;
|
|
5
5
|
export declare const FirmwareUpdate: import("@trezor/schema-utils").TUnion<[import("@trezor/schema-utils").TObject<{
|
package/lib/types/coinInfo.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CoinInfo = exports.MiscNetworkInfo = exports.EthereumNetworkInfoDefinitionValues = exports.EthereumNetworkInfo = exports.BitcoinNetworkInfo = exports.BlockchainLink = exports.CoinSupport = exports.CoinObj = exports.Network = exports.Bip32 = void 0;
|
|
4
|
+
const device_utils_1 = require("@trezor/device-utils");
|
|
4
5
|
const schema_utils_1 = require("@trezor/schema-utils");
|
|
5
|
-
const device_1 = require("./device");
|
|
6
6
|
const fees_1 = require("./fees");
|
|
7
7
|
exports.Bip32 = schema_utils_1.Type.Object({
|
|
8
8
|
public: schema_utils_1.Type.Number(),
|
|
@@ -25,7 +25,7 @@ exports.CoinSupport = schema_utils_1.Type.Composite([
|
|
|
25
25
|
schema_utils_1.Type.Object({
|
|
26
26
|
connect: schema_utils_1.Type.Boolean(),
|
|
27
27
|
}),
|
|
28
|
-
schema_utils_1.Type.Record(schema_utils_1.Type.KeyOfEnum(
|
|
28
|
+
schema_utils_1.Type.Record(schema_utils_1.Type.KeyOfEnum(device_utils_1.DeviceModelInternal), schema_utils_1.Type.Union([schema_utils_1.Type.String(), schema_utils_1.Type.Literal(false)])),
|
|
29
29
|
]);
|
|
30
30
|
exports.BlockchainLink = schema_utils_1.Type.Object({
|
|
31
31
|
type: schema_utils_1.Type.String(),
|
package/lib/types/device.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FeaturesNarrowing, FirmwareType } from '@trezor/device-utils';
|
|
1
2
|
import { Descriptor } from '@trezor/transport';
|
|
2
3
|
import type { PROTO } from '../constants';
|
|
3
4
|
import type { ReleaseInfo } from './firmware';
|
|
@@ -5,10 +6,6 @@ export type DeviceStatus = 'available' | 'occupied' | 'used';
|
|
|
5
6
|
export type DeviceMode = 'normal' | 'bootloader' | 'initialize' | 'seedless';
|
|
6
7
|
export type DeviceFirmwareStatus = 'valid' | 'outdated' | 'required' | 'unknown' | 'custom' | 'none';
|
|
7
8
|
export type UnavailableCapability = 'no-capability' | 'no-support' | 'update-required' | 'trezor-connect-outdated';
|
|
8
|
-
export declare enum FirmwareType {
|
|
9
|
-
BitcoinOnly = "bitcoin-only",
|
|
10
|
-
Regular = "regular"
|
|
11
|
-
}
|
|
12
9
|
export type StaticSessionId = `${string}@${string}:${number}`;
|
|
13
10
|
export type DeviceState = {
|
|
14
11
|
sessionId?: string;
|
|
@@ -24,6 +21,7 @@ export type FirmwareRevisionCheckResult = {
|
|
|
24
21
|
} | {
|
|
25
22
|
success: false;
|
|
26
23
|
error: FirmwareRevisionCheckError;
|
|
24
|
+
errorPayload?: unknown;
|
|
27
25
|
};
|
|
28
26
|
export type FirmwareHashCheckError = 'hash-mismatch' | 'check-skipped' | 'check-unsupported' | 'unknown-release' | 'other-error';
|
|
29
27
|
export type FirmwareHashCheckResult = {
|
|
@@ -113,43 +111,7 @@ export type UnreadableDevice = BaseDevice & {
|
|
|
113
111
|
};
|
|
114
112
|
export type Device = KnownDevice | UnknownDevice | UnreadableDevice;
|
|
115
113
|
export type Features = PROTO.Features;
|
|
116
|
-
export { DeviceModelInternal } from '@trezor/protobuf';
|
|
117
114
|
export type DisplayRotation = PROTO.DisplayRotation;
|
|
118
|
-
type FeaturesNarrowing = {
|
|
119
|
-
major_version: 2;
|
|
120
|
-
fw_major: null;
|
|
121
|
-
fw_minor: null;
|
|
122
|
-
fw_patch: null;
|
|
123
|
-
bootloader_mode: true;
|
|
124
|
-
firmware_present: false;
|
|
125
|
-
} | {
|
|
126
|
-
major_version: 2;
|
|
127
|
-
fw_major: null;
|
|
128
|
-
fw_minor: null;
|
|
129
|
-
fw_patch: null;
|
|
130
|
-
bootloader_mode: null;
|
|
131
|
-
firmware_present: null;
|
|
132
|
-
} | {
|
|
133
|
-
major_version: 2;
|
|
134
|
-
fw_major: 2;
|
|
135
|
-
fw_minor: number;
|
|
136
|
-
fw_patch: number;
|
|
137
|
-
bootloader_mode: true;
|
|
138
|
-
firmware_present: true;
|
|
139
|
-
} | {
|
|
140
|
-
major_version: 1;
|
|
141
|
-
fw_major: null;
|
|
142
|
-
fw_minor: null;
|
|
143
|
-
fw_patch: null;
|
|
144
|
-
bootloader_mode: true;
|
|
145
|
-
firmware_present: false;
|
|
146
|
-
} | {
|
|
147
|
-
major_version: 1;
|
|
148
|
-
fw_major: null;
|
|
149
|
-
fw_minor: null;
|
|
150
|
-
fw_patch: null;
|
|
151
|
-
bootloader_mode: true;
|
|
152
|
-
firmware_present: true;
|
|
153
|
-
};
|
|
154
115
|
export type StrictFeatures = Features & FeaturesNarrowing;
|
|
116
|
+
export {};
|
|
155
117
|
//# sourceMappingURL=device.d.ts.map
|
package/lib/types/device.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var FirmwareType;
|
|
5
|
-
(function (FirmwareType) {
|
|
6
|
-
FirmwareType["BitcoinOnly"] = "bitcoin-only";
|
|
7
|
-
FirmwareType["Regular"] = "regular";
|
|
8
|
-
})(FirmwareType || (exports.FirmwareType = FirmwareType = {}));
|
|
3
|
+
exports.DeviceUniquePath = void 0;
|
|
9
4
|
const DeviceUniquePath = (id) => id;
|
|
10
5
|
exports.DeviceUniquePath = DeviceUniquePath;
|
|
11
|
-
var protobuf_1 = require("@trezor/protobuf");
|
|
12
|
-
Object.defineProperty(exports, "DeviceModelInternal", { enumerable: true, get: function () { return protobuf_1.DeviceModelInternal; } });
|
|
13
6
|
//# sourceMappingURL=device.js.map
|
package/lib/types/firmware.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { DeviceModelInternal } from '@trezor/
|
|
1
|
+
import { DeviceModelInternal, VersionArray } from '@trezor/device-utils';
|
|
2
2
|
export type FirmwareRange = Record<DeviceModelInternal, {
|
|
3
3
|
min: string;
|
|
4
4
|
max: string;
|
|
5
5
|
}>;
|
|
6
|
-
export type VersionArray = [number, number, number];
|
|
7
6
|
export type FirmwareRelease = {
|
|
8
7
|
required: boolean;
|
|
9
8
|
url: string;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -20,4 +20,5 @@ export type { PrecomposedTransactionCardano, PrecomposedTransactionErrorCardano,
|
|
|
20
20
|
export type { RecoveryDevice } from './api/recoveryDevice';
|
|
21
21
|
export type { AuthenticateDeviceResult } from './api/authenticateDevice';
|
|
22
22
|
export type { TokenInfo, TokenTransfer, InternalTransfer, FiatRatesBySymbol, Target as TransactionTarget, AccountBalanceHistory as BlockchainAccountBalanceHistory, } from '@trezor/blockchain-link';
|
|
23
|
+
export { FirmwareType, type VersionArray } from '@trezor/device-utils';
|
|
23
24
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/types/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FirmwareType = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
tslib_1.__exportStar(require("./api"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./account"), exports);
|
|
@@ -18,4 +19,6 @@ tslib_1.__exportStar(require("./api/ethereum"), exports);
|
|
|
18
19
|
tslib_1.__exportStar(require("./api/solana"), exports);
|
|
19
20
|
tslib_1.__exportStar(require("./api/stellar"), exports);
|
|
20
21
|
tslib_1.__exportStar(require("./api/tezos"), exports);
|
|
22
|
+
var device_utils_1 = require("@trezor/device-utils");
|
|
23
|
+
Object.defineProperty(exports, "FirmwareType", { enumerable: true, get: function () { return device_utils_1.FirmwareType; } });
|
|
21
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DeviceModelInternal } from '
|
|
1
|
+
import { DeviceModelInternal } from '@trezor/device-utils';
|
|
2
2
|
export declare const firmwareAssets: Record<DeviceModelInternal, NodeRequire>;
|
|
3
3
|
export declare const tryLocalAssetRequire: (url: string) => any;
|
|
4
4
|
//# sourceMappingURL=assetUtils.d.ts.map
|
package/lib/utils/assetUtils.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tryLocalAssetRequire = exports.firmwareAssets = void 0;
|
|
4
|
+
const device_utils_1 = require("@trezor/device-utils");
|
|
4
5
|
const utils_1 = require("@trezor/utils");
|
|
5
|
-
const
|
|
6
|
-
const isDeviceModel = (model) => (0, utils_1.isArrayMember)(model, Object.values(types_1.DeviceModelInternal));
|
|
6
|
+
const isDeviceModel = (model) => (0, utils_1.isArrayMember)(model, Object.values(device_utils_1.DeviceModelInternal));
|
|
7
7
|
exports.firmwareAssets = {
|
|
8
|
-
[
|
|
9
|
-
[
|
|
10
|
-
[
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
8
|
+
[device_utils_1.DeviceModelInternal.UNKNOWN]: {},
|
|
9
|
+
[device_utils_1.DeviceModelInternal.T1B1]: require('@trezor/connect-common/files/firmware/t1b1/releases.json'),
|
|
10
|
+
[device_utils_1.DeviceModelInternal.T2T1]: require('@trezor/connect-common/files/firmware/t2t1/releases.json'),
|
|
11
|
+
[device_utils_1.DeviceModelInternal.T2B1]: require('@trezor/connect-common/files/firmware/t2b1/releases.json'),
|
|
12
|
+
[device_utils_1.DeviceModelInternal.T3B1]: require('@trezor/connect-common/files/firmware/t3b1/releases.json'),
|
|
13
|
+
[device_utils_1.DeviceModelInternal.T3T1]: require('@trezor/connect-common/files/firmware/t3t1/releases.json'),
|
|
14
|
+
[device_utils_1.DeviceModelInternal.T3W1]: require('@trezor/connect-common/files/firmware/t3w1/releases.json'),
|
|
15
15
|
};
|
|
16
16
|
const tryLocalAssetRequire = (url) => {
|
|
17
17
|
const fileUrl = url.split('?')[0];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { DeviceModelInternal } from '@trezor/device-utils';
|
|
1
2
|
import { PROTO } from '../constants';
|
|
2
|
-
import { CoinInfo,
|
|
3
|
+
import { CoinInfo, Features, UnavailableCapabilities } from '../types';
|
|
3
4
|
export declare const parseCapabilities: (features?: Features) => PROTO.Capability[];
|
|
4
5
|
export declare const getUnavailableCapabilities: (features: Features, coins: CoinInfo[]) => UnavailableCapabilities;
|
|
5
6
|
export declare const parseRevision: (features: Features) => string | null;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ensureInternalModelFeature = exports.parseRevision = exports.getUnavailableCapabilities = exports.parseCapabilities = void 0;
|
|
4
|
+
const device_utils_1 = require("@trezor/device-utils");
|
|
4
5
|
const utils_1 = require("@trezor/utils");
|
|
5
6
|
const config_1 = require("../data/config");
|
|
6
|
-
const types_1 = require("../types");
|
|
7
7
|
const DEFAULT_CAPABILITIES_T1 = [
|
|
8
8
|
'Capability_Bitcoin',
|
|
9
9
|
'Capability_Bitcoin_like',
|
|
@@ -128,11 +128,11 @@ exports.parseRevision = parseRevision;
|
|
|
128
128
|
const ensureInternalModelFeature = (model) => {
|
|
129
129
|
switch (model.toUpperCase()) {
|
|
130
130
|
case 'T':
|
|
131
|
-
return
|
|
131
|
+
return device_utils_1.DeviceModelInternal.T2T1;
|
|
132
132
|
case '1':
|
|
133
|
-
return
|
|
133
|
+
return device_utils_1.DeviceModelInternal.T1B1;
|
|
134
134
|
default:
|
|
135
|
-
return
|
|
135
|
+
return device_utils_1.DeviceModelInternal.UNKNOWN;
|
|
136
136
|
}
|
|
137
137
|
};
|
|
138
138
|
exports.ensureInternalModelFeature = ensureInternalModelFeature;
|