@onekeyfe/hd-core 1.2.0-alpha.3 → 1.2.0-alpha.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/__tests__/preInitialize.test.ts +33 -0
- package/__tests__/protocol-v2.test.ts +1443 -480
- package/dist/api/FileRead.d.ts.map +1 -1
- package/dist/api/FileWrite.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +22 -2
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +4 -0
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/progressThrottle.d.ts +3 -0
- package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
- package/dist/api/index.d.ts +5 -10
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +3 -2
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/{DeviceGetDeviceInfo.d.ts → DeviceInfoGet.d.ts} +10 -10
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/{FilesystemFixPermission.d.ts → FilesystemPermissionFix.d.ts} +2 -2
- package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -0
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +6 -0
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -0
- package/dist/api/protocol-v2/helpers.d.ts +27 -18
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/ton/TonSignData.d.ts +1 -5
- package/dist/api/ton/TonSignData.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +1 -1
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +4 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
- package/dist/index.d.ts +82 -54
- package/dist/index.js +1615 -1537
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +12 -14
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts +11 -9
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +1 -6
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/getDeviceInfo.d.ts +2 -0
- package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +6 -11
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +12 -17
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +1 -0
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +1 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +29 -2
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FileRead.ts +14 -1
- package/src/api/FileWrite.ts +14 -1
- package/src/api/FirmwareUpdateV4.ts +975 -201
- package/src/api/GetOnekeyFeatures.ts +1 -1
- package/src/api/device/DeviceRebootToBoardloader.ts +4 -4
- package/src/api/device/DeviceRebootToBootloader.ts +4 -4
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +18 -4
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/index.ts +5 -10
- package/src/api/protocol-v2/{FactoryGetDeviceInfo.ts → DeviceFactoryInfoGet.ts} +3 -3
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +32 -0
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +3 -5
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +39 -5
- package/src/api/protocol-v2/{DeviceGetDeviceInfo.ts → DeviceInfoGet.ts} +52 -22
- package/src/api/protocol-v2/DeviceReboot.ts +1 -1
- package/src/api/protocol-v2/{FilesystemFixPermission.ts → FilesystemPermissionFix.ts} +2 -2
- package/src/api/protocol-v2/{GetProtoVersion.ts → ProtocolInfoRequest.ts} +2 -2
- package/src/api/protocol-v2/helpers.ts +64 -43
- package/src/api/ton/TonSignData.ts +1 -5
- package/src/core/index.ts +19 -5
- package/src/data/messages/messages-protocol-v2.json +485 -1069
- package/src/data-manager/DataManager.ts +7 -0
- package/src/data-manager/connectSettings.ts +0 -6
- package/src/device/Device.ts +25 -14
- package/src/deviceProfile/buildDeviceFeatures.ts +60 -63
- package/src/deviceProfile/buildDeviceProfile.ts +77 -58
- package/src/inject.ts +10 -16
- package/src/protocols/protocol-v2/features.ts +26 -63
- package/src/protocols/protocol-v2/firmware.ts +12 -36
- package/src/types/api/firmwareUpdate.ts +10 -20
- package/src/types/api/getDeviceInfo.ts +2 -0
- package/src/types/api/index.ts +10 -20
- package/src/types/api/protocolV2.ts +25 -43
- package/src/types/device.ts +1 -0
- package/src/types/params.ts +4 -0
- package/src/types/settings.ts +44 -35
- package/src/utils/deviceFeaturesUtils.ts +45 -10
- package/dist/api/protocol-v2/DevReboot.d.ts +0 -7
- package/dist/api/protocol-v2/DevReboot.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +0 -1
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +0 -7
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +0 -1
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +0 -6
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +0 -1
- package/dist/api/protocol-v2/GetProtoVersion.d.ts +0 -6
- package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +0 -1
- package/src/api/protocol-v2/DevReboot.ts +0 -24
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +0 -16
- package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +0 -29
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeviceRebootType } from '@onekeyfe/hd-transport';
|
|
2
2
|
|
|
3
3
|
import { invalidParameter, validateNonEmptyString } from '../helpers/filesystemValidation';
|
|
4
|
+
import { ProtocolV2FirmwareTargetType } from '../../protocols/protocol-v2/firmware';
|
|
4
5
|
|
|
5
6
|
import type {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
DeviceFirmwareTarget,
|
|
8
|
+
DeviceFirmwareUpdateRecordFields,
|
|
9
|
+
DeviceFirmwareTargetType,
|
|
8
10
|
TransportCallOptions,
|
|
9
11
|
} from '@onekeyfe/hd-transport';
|
|
10
12
|
|
|
11
|
-
export type RebootTypeInput =
|
|
12
|
-
| DevRebootType
|
|
13
|
-
| keyof typeof DevRebootType
|
|
14
|
-
| string
|
|
15
|
-
| number;
|
|
13
|
+
export type RebootTypeInput = DeviceRebootType | keyof typeof DeviceRebootType | string | number;
|
|
16
14
|
|
|
17
15
|
export type DeviceRebootParams = {
|
|
18
16
|
rebootType?: RebootTypeInput;
|
|
@@ -20,48 +18,58 @@ export type DeviceRebootParams = {
|
|
|
20
18
|
};
|
|
21
19
|
|
|
22
20
|
export type DeviceFirmwareTargetInput =
|
|
23
|
-
|
|
|
21
|
+
| DeviceFirmwareTarget
|
|
24
22
|
| {
|
|
25
|
-
targetId?:
|
|
26
|
-
target_id?:
|
|
23
|
+
targetId?: DeviceFirmwareTargetType | string | number;
|
|
24
|
+
target_id?: DeviceFirmwareTargetType | string | number;
|
|
27
25
|
path: string;
|
|
28
26
|
};
|
|
29
27
|
|
|
30
28
|
export type DeviceFirmwareUpdateParams = {
|
|
31
29
|
targets?: DeviceFirmwareTargetInput[];
|
|
32
|
-
targetId?:
|
|
33
|
-
target_id?:
|
|
30
|
+
targetId?: DeviceFirmwareTargetType | string | number;
|
|
31
|
+
target_id?: DeviceFirmwareTargetType | string | number;
|
|
34
32
|
path?: string;
|
|
35
33
|
};
|
|
36
34
|
|
|
37
|
-
export type
|
|
38
|
-
|
|
39
|
-
serialNo?: string;
|
|
40
|
-
cpu_info?: string;
|
|
41
|
-
cpuInfo?: string;
|
|
42
|
-
pre_firmware?: string;
|
|
43
|
-
preFirmware?: string;
|
|
35
|
+
export type DeviceFirmwareUpdateStatusGetParams = {
|
|
36
|
+
fields?: DeviceFirmwareUpdateRecordFields;
|
|
44
37
|
};
|
|
45
38
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
39
|
+
export type DeviceFactoryInfoSetParams = {
|
|
40
|
+
version?: number;
|
|
41
|
+
serial_number?: string;
|
|
42
|
+
burn_in_completed?: boolean;
|
|
43
|
+
factory_test_completed?: boolean;
|
|
44
|
+
manufacture_time?: {
|
|
45
|
+
year: number;
|
|
46
|
+
month: number;
|
|
47
|
+
day: number;
|
|
48
|
+
hour: number;
|
|
49
|
+
minute: number;
|
|
50
|
+
second: number;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const DEVICE_REBOOT_TYPES: Record<string, DeviceRebootType> = {
|
|
55
|
+
Normal: DeviceRebootType.Normal,
|
|
56
|
+
normal: DeviceRebootType.Normal,
|
|
57
|
+
Romloader: DeviceRebootType.Romloader,
|
|
58
|
+
romloader: DeviceRebootType.Romloader,
|
|
59
|
+
Boardloader: DeviceRebootType.Romloader,
|
|
60
|
+
boardloader: DeviceRebootType.Romloader,
|
|
61
|
+
Bootloader: DeviceRebootType.Bootloader,
|
|
62
|
+
bootloader: DeviceRebootType.Bootloader,
|
|
55
63
|
};
|
|
56
64
|
|
|
57
65
|
export const PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS: TransportCallOptions = {
|
|
58
|
-
intermediateTypes: ['
|
|
66
|
+
intermediateTypes: ['DeviceFirmwareUpdateStatus'],
|
|
59
67
|
};
|
|
60
68
|
|
|
61
69
|
export const PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES: (
|
|
62
70
|
| 'Success'
|
|
63
|
-
| '
|
|
64
|
-
)[] = ['Success', '
|
|
71
|
+
| 'DeviceFirmwareUpdateStatus'
|
|
72
|
+
)[] = ['Success', 'DeviceFirmwareUpdateStatus'];
|
|
65
73
|
|
|
66
74
|
export const getProtocolV2UnknownErrorText = (error: unknown) => {
|
|
67
75
|
if (!error) {
|
|
@@ -120,31 +128,42 @@ export const isProtocolV2DeviceDisconnectedError = (error: unknown) => {
|
|
|
120
128
|
);
|
|
121
129
|
};
|
|
122
130
|
|
|
123
|
-
export function normalizeRebootType(value: RebootTypeInput | undefined):
|
|
131
|
+
export function normalizeRebootType(value: RebootTypeInput | undefined): DeviceRebootType {
|
|
124
132
|
if (typeof value === 'number') return value;
|
|
125
133
|
if (typeof value === 'string') {
|
|
126
134
|
const numeric = Number(value);
|
|
127
135
|
if (Number.isFinite(numeric)) return numeric;
|
|
128
|
-
if (value in
|
|
136
|
+
if (value in DEVICE_REBOOT_TYPES) return DEVICE_REBOOT_TYPES[value];
|
|
129
137
|
}
|
|
130
|
-
return
|
|
138
|
+
return DeviceRebootType.Normal;
|
|
131
139
|
}
|
|
132
140
|
|
|
133
|
-
// 当前 firmware-pro2 子模块的
|
|
134
|
-
|
|
141
|
+
// 当前 firmware-pro2 子模块的 DeviceFirmwareTargetType 合法值从生成 enum 派生,
|
|
142
|
+
// 避免协议枚举增减时这里继续保留过期手写编号。
|
|
143
|
+
const VALID_FIRMWARE_TARGET_IDS = new Set<number>(
|
|
144
|
+
Object.values(ProtocolV2FirmwareTargetType).filter(value => typeof value === 'number') as number[]
|
|
145
|
+
);
|
|
146
|
+
const FIRMWARE_TARGET_ID_BY_NAME = new Map<string, DeviceFirmwareTargetType>(
|
|
147
|
+
Object.entries(ProtocolV2FirmwareTargetType).flatMap(([key, value]) =>
|
|
148
|
+
VALID_FIRMWARE_TARGET_IDS.has(value)
|
|
149
|
+
? [[key, value as DeviceFirmwareTargetType]]
|
|
150
|
+
: []
|
|
151
|
+
)
|
|
152
|
+
);
|
|
135
153
|
|
|
136
154
|
function normalizeTargetId(
|
|
137
|
-
value:
|
|
155
|
+
value: DeviceFirmwareTargetType | string | number | undefined,
|
|
138
156
|
name: string
|
|
139
|
-
):
|
|
157
|
+
): DeviceFirmwareTargetType {
|
|
140
158
|
if (value === undefined || value === null) {
|
|
141
159
|
throw invalidParameter(`Missing required parameter: ${name}`);
|
|
142
160
|
}
|
|
143
|
-
const
|
|
144
|
-
|
|
161
|
+
const named = typeof value === 'string' ? FIRMWARE_TARGET_ID_BY_NAME.get(value) : undefined;
|
|
162
|
+
const numeric = named ?? (typeof value === 'number' ? value : Number(value));
|
|
163
|
+
// 校验值域:仅接受 DeviceFirmwareTargetType 中定义的 target id,
|
|
145
164
|
// 不再放行任意非负整数。
|
|
146
165
|
if (Number.isSafeInteger(numeric) && VALID_FIRMWARE_TARGET_IDS.has(numeric)) {
|
|
147
|
-
return numeric as
|
|
166
|
+
return numeric as DeviceFirmwareTargetType;
|
|
148
167
|
}
|
|
149
168
|
throw invalidParameter(
|
|
150
169
|
`Parameter [${name}] must be a valid firmware target id (one of ${[
|
|
@@ -153,7 +172,9 @@ function normalizeTargetId(
|
|
|
153
172
|
);
|
|
154
173
|
}
|
|
155
174
|
|
|
156
|
-
export function normalizeFirmwareTargets(
|
|
175
|
+
export function normalizeFirmwareTargets(
|
|
176
|
+
params: DeviceFirmwareUpdateParams
|
|
177
|
+
): DeviceFirmwareTarget[] {
|
|
157
178
|
const targets =
|
|
158
179
|
params.targets ??
|
|
159
180
|
(params.path
|
package/src/core/index.ts
CHANGED
|
@@ -56,7 +56,6 @@ import TransportManager from '../data-manager/TransportManager';
|
|
|
56
56
|
import DeviceConnector from '../device/DeviceConnector';
|
|
57
57
|
import RequestQueue from './RequestQueue';
|
|
58
58
|
import { getSynchronize } from '../utils/getSynchronize';
|
|
59
|
-
import { setProtocolV2DeviceInfoMock } from '../protocols/protocol-v2/features';
|
|
60
59
|
|
|
61
60
|
import type { ConnectSettings, Features, KnownDevice } from '../types';
|
|
62
61
|
import type { CoreMessage, IFrameCallMessage, UiPromise, UiPromiseResponse } from '../events';
|
|
@@ -96,6 +95,7 @@ const parseInitOptions = (method?: BaseMethod): InitOptions => ({
|
|
|
96
95
|
deviceId: method?.payload.deviceId,
|
|
97
96
|
deriveCardano: method && hasDeriveCardano(method),
|
|
98
97
|
connectProtocol: method?.payload.connectProtocol,
|
|
98
|
+
protocolV2DeviceInfoTimeoutMs: method?.payload.protocolV2DeviceInfoTimeoutMs,
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
let _core: Core;
|
|
@@ -223,9 +223,15 @@ const handlePreWarmSignal = async (
|
|
|
223
223
|
message: CoreMessage,
|
|
224
224
|
method: BaseMethod
|
|
225
225
|
): Promise<any> => {
|
|
226
|
+
const createAckResponse = () => {
|
|
227
|
+
completeMethodRequestContext(method);
|
|
228
|
+
method.dispose();
|
|
229
|
+
return createResponseMessage(method.responseID, true, true);
|
|
230
|
+
};
|
|
231
|
+
|
|
226
232
|
// no connectId: can't target a device safely, skip pre-warm (ack only)
|
|
227
233
|
if (!method.connectId) {
|
|
228
|
-
return
|
|
234
|
+
return createAckResponse();
|
|
229
235
|
}
|
|
230
236
|
|
|
231
237
|
const key = method.getPreWarmKey();
|
|
@@ -238,12 +244,12 @@ const handlePreWarmSignal = async (
|
|
|
238
244
|
} catch {
|
|
239
245
|
// pre-warm is best-effort; ignore its failure for the coalesced caller
|
|
240
246
|
}
|
|
241
|
-
return
|
|
247
|
+
return createAckResponse();
|
|
242
248
|
}
|
|
243
249
|
|
|
244
250
|
const doneAt = preWarmDoneAt.get(key);
|
|
245
251
|
if (typeof doneAt === 'number' && Date.now() - doneAt <= method.preWarmTtl) {
|
|
246
|
-
return
|
|
252
|
+
return createAckResponse();
|
|
247
253
|
}
|
|
248
254
|
|
|
249
255
|
const run = onCallDevice(context, message, method);
|
|
@@ -732,6 +738,15 @@ function initDevice(method: BaseMethod) {
|
|
|
732
738
|
|
|
733
739
|
if (method.connectId) {
|
|
734
740
|
device = _deviceList.getDevice(method.connectId);
|
|
741
|
+
if (!device && method.name === 'firmwareUpdateV4' && allDevices.length === 1) {
|
|
742
|
+
const [singleDevice] = allDevices;
|
|
743
|
+
if (singleDevice.isBootloader()) {
|
|
744
|
+
Log.debug(
|
|
745
|
+
'firmwareUpdateV4 uses the only bootloader device when connectId changed after reboot'
|
|
746
|
+
);
|
|
747
|
+
device = singleDevice;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
735
750
|
} else if (allDevices.length === 1) {
|
|
736
751
|
[device] = allDevices;
|
|
737
752
|
} else if (allDevices.length > 1) {
|
|
@@ -1439,7 +1454,6 @@ export const init = async (
|
|
|
1439
1454
|
try {
|
|
1440
1455
|
try {
|
|
1441
1456
|
await DataManager.load(settings);
|
|
1442
|
-
setProtocolV2DeviceInfoMock(settings.protocolV2DeviceInfoMockEnabled ?? false);
|
|
1443
1457
|
initTransport(Transport, plugin);
|
|
1444
1458
|
} catch {
|
|
1445
1459
|
Log.error('DataManager.load error');
|