@onekeyfe/hd-core 1.1.26 → 1.1.27-alpha.30
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/__tests__/protocol-v2.test.ts +940 -0
- package/dist/api/BaseMethod.d.ts +1 -3
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/DirList.d.ts +10 -0
- package/dist/api/DirList.d.ts.map +1 -0
- package/dist/api/DirMake.d.ts +9 -0
- package/dist/api/DirMake.d.ts.map +1 -0
- package/dist/api/DirRemove.d.ts +9 -0
- package/dist/api/DirRemove.d.ts.map +1 -0
- package/dist/api/FileDelete.d.ts +9 -0
- package/dist/api/FileDelete.d.ts.map +1 -0
- package/dist/api/FileRead.d.ts +19 -0
- package/dist/api/FileRead.d.ts.map +1 -0
- package/dist/api/FileWrite.d.ts +23 -0
- package/dist/api/FileWrite.d.ts.map +1 -0
- package/dist/api/FirmwareUpdateV3.d.ts +1 -0
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +32 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -0
- package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
- package/dist/api/PathInfo.d.ts +9 -0
- package/dist/api/PathInfo.d.ts.map +1 -0
- package/dist/api/SearchDevices.d.ts +2 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +10 -2
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/index.d.ts +26 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DevFirmwareUpdate.d.ts +7 -0
- package/dist/api/protocol-v2/DevFirmwareUpdate.d.ts.map +1 -0
- package/dist/api/protocol-v2/DevGetDeviceInfo.d.ts +7 -0
- package/dist/api/protocol-v2/DevGetDeviceInfo.d.ts.map +1 -0
- package/dist/api/protocol-v2/DevGetFirmwareUpdateStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DevGetFirmwareUpdateStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DevGetOnboardingStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DevGetOnboardingStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DevReboot.d.ts +7 -0
- package/dist/api/protocol-v2/DevReboot.d.ts.map +1 -0
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +7 -0
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +1 -0
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +6 -0
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +6 -0
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts +6 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
- package/dist/api/protocol-v2/GetProtoVersion.d.ts +6 -0
- package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +1 -0
- package/dist/api/protocol-v2/Ping.d.ts +8 -0
- package/dist/api/protocol-v2/Ping.d.ts.map +1 -0
- package/dist/api/protocol-v2/helpers.d.ts +49 -0
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +4 -2
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts +2 -1
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +5 -3
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +8 -8
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +2 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +8 -0
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +188 -20
- package/dist/index.js +15626 -753
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +56 -0
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/firmware.d.ts +12 -0
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/index.d.ts +3 -0
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
- package/dist/types/api/export.d.ts +1 -1
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +7 -0
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +28 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +123 -0
- package/dist/types/api/protocolV2.d.ts.map +1 -0
- package/dist/types/api/searchDevices.d.ts +2 -2
- package/dist/types/api/searchDevices.d.ts.map +1 -1
- package/dist/types/device.d.ts +1 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +2 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +1 -1
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts +1 -0
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/versionUtils.d.ts +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +12 -60
- package/src/api/DirList.ts +25 -0
- package/src/api/DirMake.ts +20 -0
- package/src/api/DirRemove.ts +20 -0
- package/src/api/FileDelete.ts +20 -0
- package/src/api/FileRead.ts +158 -0
- package/src/api/FileWrite.ts +191 -0
- package/src/api/FirmwareUpdateV3.ts +21 -4
- package/src/api/FirmwareUpdateV4.ts +810 -0
- package/src/api/GetOnekeyFeatures.ts +75 -3
- package/src/api/PathInfo.ts +24 -0
- package/src/api/SearchDevices.ts +7 -2
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +10 -9
- package/src/api/device/DeviceRebootToBoardloader.ts +10 -1
- package/src/api/device/DeviceRebootToBootloader.ts +10 -1
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -4
- package/src/api/index.ts +28 -0
- package/src/api/protocol-v2/DevFirmwareUpdate.ts +33 -0
- package/src/api/protocol-v2/DevGetDeviceInfo.ts +35 -0
- package/src/api/protocol-v2/DevGetFirmwareUpdateStatus.ts +18 -0
- package/src/api/protocol-v2/DevGetOnboardingStatus.ts +18 -0
- package/src/api/protocol-v2/DevReboot.ts +22 -0
- package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +27 -0
- package/src/api/protocol-v2/FactoryGetDeviceInfo.ts +18 -0
- package/src/api/protocol-v2/FilesystemFixPermission.ts +14 -0
- package/src/api/protocol-v2/FilesystemFormat.ts +14 -0
- package/src/api/protocol-v2/GetProtoVersion.ts +14 -0
- package/src/api/protocol-v2/Ping.ts +16 -0
- package/src/api/protocol-v2/helpers.ts +138 -0
- package/src/core/index.ts +26 -4
- package/src/data/messages/messages-pro2.json +13102 -0
- package/src/data-manager/DataManager.ts +6 -2
- package/src/data-manager/TransportManager.ts +29 -3
- package/src/device/Device.ts +68 -8
- package/src/device/DeviceCommands.ts +162 -26
- package/src/device/DeviceConnector.ts +29 -4
- package/src/device/DevicePool.ts +1 -1
- package/src/events/ui-request.ts +8 -0
- package/src/inject.ts +42 -1
- package/src/protocols/protocol-v2/features.ts +266 -0
- package/src/protocols/protocol-v2/firmware.ts +26 -0
- package/src/protocols/protocol-v2/index.ts +2 -0
- package/src/types/api/export.ts +1 -0
- package/src/types/api/firmwareUpdate.ts +12 -0
- package/src/types/api/index.ts +63 -1
- package/src/types/api/protocolV2.ts +221 -0
- package/src/types/api/searchDevices.ts +2 -2
- package/src/types/device.ts +3 -1
- package/src/types/params.ts +7 -0
- package/src/types/settings.ts +1 -1
- package/src/utils/deviceInfoUtils.ts +14 -5
- package/src/utils/index.ts +1 -0
- package/__tests__/DeviceCommands.test.ts +0 -99
- package/__tests__/evmLedgerLegacySafety.test.ts +0 -261
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { DevRebootType } from '@onekeyfe/hd-transport';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
DevFirmwareTarget,
|
|
5
|
+
DevFirmwareTargetType,
|
|
6
|
+
DevInfoTargets,
|
|
7
|
+
DevInfoTypes,
|
|
8
|
+
TransportCallOptions,
|
|
9
|
+
} from '@onekeyfe/hd-transport';
|
|
10
|
+
|
|
11
|
+
export type RebootTypeInput = DevRebootType | keyof typeof DevRebootType | string | number;
|
|
12
|
+
|
|
13
|
+
export type DevRebootParams = {
|
|
14
|
+
rebootType?: RebootTypeInput;
|
|
15
|
+
reboot_type?: RebootTypeInput;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type DevGetDeviceInfoParams = {
|
|
19
|
+
targets?: DevInfoTargets;
|
|
20
|
+
types?: DevInfoTypes;
|
|
21
|
+
targetHw?: boolean;
|
|
22
|
+
targetFw?: boolean;
|
|
23
|
+
targetBt?: boolean;
|
|
24
|
+
targetSe1?: boolean;
|
|
25
|
+
targetSe2?: boolean;
|
|
26
|
+
targetSe3?: boolean;
|
|
27
|
+
targetSe4?: boolean;
|
|
28
|
+
targetStatus?: boolean;
|
|
29
|
+
includeVersion?: boolean;
|
|
30
|
+
includeBuildId?: boolean;
|
|
31
|
+
includeHash?: boolean;
|
|
32
|
+
includeSpecific?: boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type DevFirmwareTargetInput =
|
|
36
|
+
| DevFirmwareTarget
|
|
37
|
+
| {
|
|
38
|
+
targetId?: DevFirmwareTargetType | string | number;
|
|
39
|
+
target_id?: DevFirmwareTargetType | string | number;
|
|
40
|
+
path: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type DevFirmwareUpdateParams = {
|
|
44
|
+
targets?: DevFirmwareTargetInput[];
|
|
45
|
+
targetId?: DevFirmwareTargetType | string | number;
|
|
46
|
+
target_id?: DevFirmwareTargetType | string | number;
|
|
47
|
+
path?: string;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type FactoryDeviceInfoSettingsParams = {
|
|
51
|
+
serial_no?: string;
|
|
52
|
+
serialNo?: string;
|
|
53
|
+
cpu_info?: string;
|
|
54
|
+
cpuInfo?: string;
|
|
55
|
+
pre_firmware?: string;
|
|
56
|
+
preFirmware?: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const DEV_REBOOT_TYPES: Record<string, DevRebootType> = {
|
|
60
|
+
Normal: DevRebootType.Normal,
|
|
61
|
+
normal: DevRebootType.Normal,
|
|
62
|
+
Boardloader: DevRebootType.Boardloader,
|
|
63
|
+
boardloader: DevRebootType.Boardloader,
|
|
64
|
+
Bootloader: DevRebootType.Bootloader,
|
|
65
|
+
bootloader: DevRebootType.Bootloader,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS: TransportCallOptions = {
|
|
69
|
+
intermediateTypes: ['DevFirmwareInstallProgress'],
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES: ('Success' | 'DevFirmwareUpdateStatus')[] =
|
|
73
|
+
['Success', 'DevFirmwareUpdateStatus'];
|
|
74
|
+
|
|
75
|
+
export function normalizeRebootType(value: RebootTypeInput | undefined): DevRebootType {
|
|
76
|
+
if (typeof value === 'number') return value;
|
|
77
|
+
if (typeof value === 'string') {
|
|
78
|
+
const numeric = Number(value);
|
|
79
|
+
if (Number.isFinite(numeric)) return numeric;
|
|
80
|
+
if (value in DEV_REBOOT_TYPES) return DEV_REBOOT_TYPES[value];
|
|
81
|
+
}
|
|
82
|
+
return DevRebootType.Normal;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function normalizeTargetId(
|
|
86
|
+
value: DevFirmwareTargetType | string | number | undefined
|
|
87
|
+
): DevFirmwareTargetType {
|
|
88
|
+
if (typeof value === 'number') return value;
|
|
89
|
+
const numeric = Number(value);
|
|
90
|
+
if (Number.isFinite(numeric)) return numeric;
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function normalizeFirmwareTargets(params: DevFirmwareUpdateParams): DevFirmwareTarget[] {
|
|
95
|
+
const targets =
|
|
96
|
+
params.targets ??
|
|
97
|
+
(params.path
|
|
98
|
+
? [
|
|
99
|
+
{
|
|
100
|
+
target_id: params.target_id ?? params.targetId ?? 0,
|
|
101
|
+
path: params.path,
|
|
102
|
+
},
|
|
103
|
+
]
|
|
104
|
+
: []);
|
|
105
|
+
|
|
106
|
+
return targets.map(target => ({
|
|
107
|
+
target_id: normalizeTargetId('target_id' in target ? target.target_id : target.targetId),
|
|
108
|
+
path: target.path,
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function buildTargets(params: DevGetDeviceInfoParams): DevInfoTargets | undefined {
|
|
113
|
+
if (params.targets) return params.targets;
|
|
114
|
+
|
|
115
|
+
const targets: DevInfoTargets = {
|
|
116
|
+
hw: params.targetHw,
|
|
117
|
+
fw: params.targetFw,
|
|
118
|
+
bt: params.targetBt,
|
|
119
|
+
se1: params.targetSe1,
|
|
120
|
+
se2: params.targetSe2,
|
|
121
|
+
se3: params.targetSe3,
|
|
122
|
+
se4: params.targetSe4,
|
|
123
|
+
status: params.targetStatus,
|
|
124
|
+
};
|
|
125
|
+
return Object.values(targets).some(value => value !== undefined) ? targets : undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function buildTypes(params: DevGetDeviceInfoParams): DevInfoTypes | undefined {
|
|
129
|
+
if (params.types) return params.types;
|
|
130
|
+
|
|
131
|
+
const types: DevInfoTypes = {
|
|
132
|
+
version: params.includeVersion,
|
|
133
|
+
build_id: params.includeBuildId,
|
|
134
|
+
hash: params.includeHash,
|
|
135
|
+
specific: params.includeSpecific,
|
|
136
|
+
};
|
|
137
|
+
return Object.values(types).some(value => value !== undefined) ? types : undefined;
|
|
138
|
+
}
|
package/src/core/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
getLogger,
|
|
24
24
|
getMethodVersionRange,
|
|
25
25
|
setLoggerPostMessage,
|
|
26
|
+
shouldSkipMethodSupportCheck,
|
|
26
27
|
wait,
|
|
27
28
|
} from '../utils';
|
|
28
29
|
import {
|
|
@@ -95,6 +96,7 @@ const parseInitOptions = (method?: BaseMethod): InitOptions => ({
|
|
|
95
96
|
passphraseState: method?.payload.passphraseState,
|
|
96
97
|
deviceId: method?.payload.deviceId,
|
|
97
98
|
deriveCardano: method && hasDeriveCardano(method),
|
|
99
|
+
connectProtocol: method?.payload.connectProtocol,
|
|
98
100
|
});
|
|
99
101
|
|
|
100
102
|
let _core: Core;
|
|
@@ -342,6 +344,10 @@ const onCallDevice = async (
|
|
|
342
344
|
device.features,
|
|
343
345
|
type => method.getVersionRange()[type]
|
|
344
346
|
);
|
|
347
|
+
const skipMethodSupportCheck = shouldSkipMethodSupportCheck(
|
|
348
|
+
device.features,
|
|
349
|
+
device.originalDescriptor?.protocolType
|
|
350
|
+
);
|
|
345
351
|
|
|
346
352
|
if (device.features) {
|
|
347
353
|
await DataManager.checkAndReloadData();
|
|
@@ -392,7 +398,7 @@ const onCallDevice = async (
|
|
|
392
398
|
);
|
|
393
399
|
}
|
|
394
400
|
|
|
395
|
-
if (versionRange) {
|
|
401
|
+
if (!skipMethodSupportCheck && versionRange) {
|
|
396
402
|
if (
|
|
397
403
|
semver.valid(versionRange.min) &&
|
|
398
404
|
semver.lt(currentFirmwareVersion, versionRange.min)
|
|
@@ -424,7 +430,7 @@ const onCallDevice = async (
|
|
|
424
430
|
createDeprecatedHardwareError(currentFirmwareVersion, versionRange.max, method.name)
|
|
425
431
|
);
|
|
426
432
|
}
|
|
427
|
-
} else if (method.strictCheckDeviceSupport) {
|
|
433
|
+
} else if (!skipMethodSupportCheck && method.strictCheckDeviceSupport) {
|
|
428
434
|
throw createDeviceNotSupportMethodError(method.name, getFirmwareType(device.features));
|
|
429
435
|
}
|
|
430
436
|
}
|
|
@@ -648,6 +654,7 @@ function initDevice(method: BaseMethod) {
|
|
|
648
654
|
} else if (allDevices.length > 1) {
|
|
649
655
|
throw ERRORS.TypedError(
|
|
650
656
|
[
|
|
657
|
+
'firmwareUpdateV4',
|
|
651
658
|
'firmwareUpdateV3',
|
|
652
659
|
'firmwareUpdateV2',
|
|
653
660
|
'checkFirmwareRelease',
|
|
@@ -702,15 +709,30 @@ function initDeviceForBle(method: BaseMethod) {
|
|
|
702
709
|
*/
|
|
703
710
|
let bleTimeoutRetry = 0;
|
|
704
711
|
|
|
712
|
+
function isRetryableBleProtocolV2ProbeError(method: BaseMethod, error: unknown) {
|
|
713
|
+
const message = error instanceof Error ? error.message : String(error ?? '');
|
|
714
|
+
return (
|
|
715
|
+
method.payload.connectProtocol === 'V2' &&
|
|
716
|
+
message.includes('Device protocol mismatch') &&
|
|
717
|
+
message.includes('expected V2') &&
|
|
718
|
+
message.includes('did not respond to expected protocol')
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
|
|
705
722
|
async function connectDeviceForBle(method: BaseMethod, device: Device) {
|
|
706
723
|
try {
|
|
707
|
-
await device.acquire();
|
|
724
|
+
await device.acquire(method.payload.connectProtocol);
|
|
708
725
|
if (method.payload?.onlyConnectBleDevice) {
|
|
709
726
|
return;
|
|
710
727
|
}
|
|
711
728
|
await device.initialize(parseInitOptions(method));
|
|
712
729
|
} catch (err) {
|
|
713
|
-
if (
|
|
730
|
+
if (
|
|
731
|
+
(err.errorCode === HardwareErrorCode.BleTimeoutError ||
|
|
732
|
+
err.errorCode === HardwareErrorCode.BleConnectedError ||
|
|
733
|
+
isRetryableBleProtocolV2ProbeError(method, err)) &&
|
|
734
|
+
bleTimeoutRetry <= 5
|
|
735
|
+
) {
|
|
714
736
|
bleTimeoutRetry += 1;
|
|
715
737
|
Log.debug(`Bletooth connect timeout and will retry, retry count: ${bleTimeoutRetry}`);
|
|
716
738
|
await wait(3000);
|