@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
|
@@ -90,7 +90,7 @@ export default class GetOnekeyFeatures extends BaseMethod {
|
|
|
90
90
|
async run() {
|
|
91
91
|
if (this.device.isProtocolV2()) {
|
|
92
92
|
// V2 没有 OnekeyGetFeatures 消息:
|
|
93
|
-
// 取完整
|
|
93
|
+
// 取完整 DeviceInfoGet(含 SE/hash/build_id)后刷新结构化 features 缓存。
|
|
94
94
|
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
95
95
|
commands: this.device.commands,
|
|
96
96
|
request: PROTOCOL_V2_DEVICE_INFO_REQUEST,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeviceRebootType } from '@onekeyfe/hd-transport';
|
|
2
2
|
|
|
3
3
|
import { BaseMethod } from '../BaseMethod';
|
|
4
4
|
|
|
@@ -23,10 +23,10 @@ export default class DeviceRebootToBoardloader extends BaseMethod<RebootToBoardl
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
async run() {
|
|
26
|
-
// Protocol V2 submodule firmware uses
|
|
26
|
+
// Protocol V2 submodule firmware uses DeviceReboot with reboot_type enum.
|
|
27
27
|
if (this.device.isProtocolV2()) {
|
|
28
|
-
const res = await this.device.commands.typedCall('
|
|
29
|
-
reboot_type:
|
|
28
|
+
const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
29
|
+
reboot_type: DeviceRebootType.Romloader,
|
|
30
30
|
});
|
|
31
31
|
return Promise.resolve(res.message);
|
|
32
32
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeviceRebootType } from '@onekeyfe/hd-transport';
|
|
2
2
|
|
|
3
3
|
import { BaseMethod } from '../BaseMethod';
|
|
4
4
|
|
|
@@ -23,10 +23,10 @@ export default class DeviceRebootToBootloader extends BaseMethod<RebootToBootloa
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
async run() {
|
|
26
|
-
// Protocol V2 submodule firmware uses
|
|
26
|
+
// Protocol V2 submodule firmware uses DeviceReboot with reboot_type enum.
|
|
27
27
|
if (this.device.isProtocolV2()) {
|
|
28
|
-
const res = await this.device.commands.typedCall('
|
|
29
|
-
reboot_type:
|
|
28
|
+
const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
29
|
+
reboot_type: DeviceRebootType.Bootloader,
|
|
30
30
|
});
|
|
31
31
|
return Promise.resolve(res.message);
|
|
32
32
|
}
|
|
@@ -13,6 +13,7 @@ import { DeviceModelToTypes } from '../../types';
|
|
|
13
13
|
import { DataManager } from '../../data-manager';
|
|
14
14
|
import { BaseMethod } from '../BaseMethod';
|
|
15
15
|
import { DEVICE } from '../../events';
|
|
16
|
+
import { createFirmwareProgressThrottle } from './progressThrottle';
|
|
16
17
|
|
|
17
18
|
import type {
|
|
18
19
|
IFirmwareUpdateProgressType,
|
|
@@ -40,6 +41,8 @@ const isDeviceDisconnectedError = (error: unknown) => {
|
|
|
40
41
|
export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
41
42
|
checkPromise: Deferred<any> | null = null;
|
|
42
43
|
|
|
44
|
+
private shouldPostFirmwareProgress = createFirmwareProgressThrottle();
|
|
45
|
+
|
|
43
46
|
init(): void {}
|
|
44
47
|
|
|
45
48
|
run(): Promise<any> {
|
|
@@ -83,6 +86,10 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
83
86
|
* @param progress Post the percentage of the progress
|
|
84
87
|
*/
|
|
85
88
|
postProgressMessage = (progress: number, progressType: IFirmwareUpdateProgressType) => {
|
|
89
|
+
if (!this.shouldPostFirmwareProgress(progress, progressType)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
86
93
|
this.postMessage(
|
|
87
94
|
createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
|
|
88
95
|
device: this.device.toMessageObject() as KnownDevice,
|
|
@@ -138,6 +145,8 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
138
145
|
// check device goto bootloader mode
|
|
139
146
|
let isFirstCheck = true;
|
|
140
147
|
let checkCount = 0;
|
|
148
|
+
let hasPromptedWebDevice = false;
|
|
149
|
+
let isPromptingWebDevice = false;
|
|
141
150
|
// eslint-disable-next-line prefer-const
|
|
142
151
|
let timeoutTimer: ReturnType<typeof setTimeout> | undefined;
|
|
143
152
|
|
|
@@ -158,23 +167,28 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
158
167
|
if (
|
|
159
168
|
checkCount > 4 &&
|
|
160
169
|
DataManager.isBrowserWebUsb(DataManager.getSettings('env')) &&
|
|
161
|
-
!this.payload.skipWebDevicePrompt
|
|
170
|
+
!this.payload.skipWebDevicePrompt &&
|
|
171
|
+
!hasPromptedWebDevice &&
|
|
172
|
+
!isPromptingWebDevice
|
|
162
173
|
) {
|
|
163
|
-
|
|
164
|
-
clearTimeout(timeoutTimer);
|
|
165
|
-
|
|
174
|
+
isPromptingWebDevice = true;
|
|
166
175
|
try {
|
|
167
176
|
this.postTipMessage(FirmwareUpdateTipMessage.SelectDeviceInBootloaderForWebDevice);
|
|
168
177
|
const confirmed = await this._promptDeviceInBootloaderForWebDevice();
|
|
178
|
+
hasPromptedWebDevice = true;
|
|
169
179
|
if (confirmed) {
|
|
170
180
|
await this._checkDeviceInBootloaderMode(connectId, intervalTimer, timeoutTimer);
|
|
171
181
|
}
|
|
172
182
|
} catch (e) {
|
|
183
|
+
clearInterval(intervalTimer);
|
|
184
|
+
clearTimeout(timeoutTimer);
|
|
173
185
|
Log.log(
|
|
174
186
|
'FirmwareUpdateBaseMethod [checkDeviceToBootloader] _promptDeviceInBootloaderForWebDevice failed: ',
|
|
175
187
|
e
|
|
176
188
|
);
|
|
177
189
|
this.checkPromise?.reject(e);
|
|
190
|
+
} finally {
|
|
191
|
+
isPromptingWebDevice = false;
|
|
178
192
|
}
|
|
179
193
|
return;
|
|
180
194
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { IFirmwareUpdateProgressType } from '../../events/ui-request';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_FIRMWARE_PROGRESS_INTERVAL_MS = 250;
|
|
4
|
+
|
|
5
|
+
type FirmwareProgressThrottleState = {
|
|
6
|
+
lastEmittedAt: number;
|
|
7
|
+
lastProgress?: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const createFirmwareProgressThrottle = (
|
|
11
|
+
intervalMs = DEFAULT_FIRMWARE_PROGRESS_INTERVAL_MS
|
|
12
|
+
) => {
|
|
13
|
+
const stateByType = new Map<IFirmwareUpdateProgressType, FirmwareProgressThrottleState>();
|
|
14
|
+
|
|
15
|
+
return (progress: number, progressType: IFirmwareUpdateProgressType) => {
|
|
16
|
+
if (progressType !== 'transferData') {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const normalizedProgress = Math.max(0, Math.min(100, Math.floor(progress)));
|
|
21
|
+
if (normalizedProgress === 0 || normalizedProgress === 100) {
|
|
22
|
+
stateByType.set(progressType, {
|
|
23
|
+
lastEmittedAt: Date.now(),
|
|
24
|
+
lastProgress: normalizedProgress,
|
|
25
|
+
});
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
const state = stateByType.get(progressType);
|
|
31
|
+
if (
|
|
32
|
+
state &&
|
|
33
|
+
(state.lastProgress === normalizedProgress || now - state.lastEmittedAt < intervalMs)
|
|
34
|
+
) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
stateByType.set(progressType, {
|
|
39
|
+
lastEmittedAt: now,
|
|
40
|
+
lastProgress: normalizedProgress,
|
|
41
|
+
});
|
|
42
|
+
return true;
|
|
43
|
+
};
|
|
44
|
+
};
|
package/src/api/index.ts
CHANGED
|
@@ -43,20 +43,15 @@ export { default as firmwareUpdateV4 } from './FirmwareUpdateV4';
|
|
|
43
43
|
export { default as promptWebDeviceAccess } from './PromptWebDeviceAccess';
|
|
44
44
|
|
|
45
45
|
// File system & device control API (Protocol V2 only)
|
|
46
|
-
export { default as
|
|
46
|
+
export { default as protocolInfoRequest } from './protocol-v2/ProtocolInfoRequest';
|
|
47
47
|
export { default as ping } from './protocol-v2/Ping';
|
|
48
48
|
export { default as deviceReboot } from './protocol-v2/DeviceReboot';
|
|
49
|
-
export { default as
|
|
50
|
-
export { default as deviceGetOnboardingStatus } from './protocol-v2/DeviceGetOnboardingStatus';
|
|
49
|
+
export { default as deviceInfoGet } from './protocol-v2/DeviceInfoGet';
|
|
51
50
|
export { default as deviceFirmwareUpdate } from './protocol-v2/DeviceFirmwareUpdate';
|
|
52
51
|
export { default as deviceGetFirmwareUpdateStatus } from './protocol-v2/DeviceGetFirmwareUpdateStatus';
|
|
53
|
-
export { default as
|
|
54
|
-
export { default as
|
|
55
|
-
export { default as
|
|
56
|
-
export { default as devGetFirmwareUpdateStatus } from './protocol-v2/DeviceGetFirmwareUpdateStatus';
|
|
57
|
-
export { default as factoryDeviceInfoSettings } from './protocol-v2/FactoryDeviceInfoSettings';
|
|
58
|
-
export { default as factoryGetDeviceInfo } from './protocol-v2/FactoryGetDeviceInfo';
|
|
59
|
-
export { default as filesystemFixPermission } from './protocol-v2/FilesystemFixPermission';
|
|
52
|
+
export { default as deviceFactoryInfoSet } from './protocol-v2/DeviceFactoryInfoSet';
|
|
53
|
+
export { default as deviceFactoryInfoGet } from './protocol-v2/DeviceFactoryInfoGet';
|
|
54
|
+
export { default as filesystemPermissionFix } from './protocol-v2/FilesystemPermissionFix';
|
|
60
55
|
export { default as filesystemFormat } from './protocol-v2/FilesystemFormat';
|
|
61
56
|
export { default as filesystemDiskControl } from './protocol-v2/FilesystemDiskControl';
|
|
62
57
|
export { default as fileRead } from './FileRead';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
2
|
|
|
3
|
-
export default class
|
|
3
|
+
export default class DeviceFactoryInfoGet extends BaseMethod {
|
|
4
4
|
init() {
|
|
5
5
|
// Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
|
|
6
6
|
this.requireProtocolV2 = true;
|
|
@@ -11,8 +11,8 @@ export default class FactoryGetDeviceInfo extends BaseMethod {
|
|
|
11
11
|
|
|
12
12
|
async run() {
|
|
13
13
|
const res = await this.device.commands.typedCall(
|
|
14
|
-
'
|
|
15
|
-
'
|
|
14
|
+
'DeviceFactoryInfoGet',
|
|
15
|
+
'DeviceFactoryInfo',
|
|
16
16
|
{}
|
|
17
17
|
);
|
|
18
18
|
return Promise.resolve(res.message);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
|
|
3
|
+
import type { DeviceFactoryInfoSetParams } from './helpers';
|
|
4
|
+
|
|
5
|
+
export default class DeviceFactoryInfoSet extends BaseMethod<DeviceFactoryInfoSetParams> {
|
|
6
|
+
init() {
|
|
7
|
+
// Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
|
|
8
|
+
this.requireProtocolV2 = true;
|
|
9
|
+
this.skipForceUpdateCheck = true;
|
|
10
|
+
this.useDevicePassphraseState = false;
|
|
11
|
+
this.params = {
|
|
12
|
+
version: this.payload.version,
|
|
13
|
+
serial_number: this.payload.serial_number,
|
|
14
|
+
burn_in_completed: this.payload.burn_in_completed,
|
|
15
|
+
factory_test_completed: this.payload.factory_test_completed,
|
|
16
|
+
manufacture_time: this.payload.manufacture_time,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async run() {
|
|
21
|
+
const res = await this.device.commands.typedCall('DeviceFactoryInfoSet', 'Success', {
|
|
22
|
+
info: {
|
|
23
|
+
version: this.params.version,
|
|
24
|
+
serial_number: this.params.serial_number,
|
|
25
|
+
burn_in_completed: this.params.burn_in_completed,
|
|
26
|
+
factory_test_completed: this.params.factory_test_completed,
|
|
27
|
+
manufacture_time: this.params.manufacture_time,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
return Promise.resolve(res.message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -29,7 +29,7 @@ export default class DeviceFirmwareUpdate extends BaseMethod<DeviceFirmwareUpdat
|
|
|
29
29
|
const targets = normalizeFirmwareTargets(this.params);
|
|
30
30
|
try {
|
|
31
31
|
const res = await this.device.commands.typedCall(
|
|
32
|
-
'
|
|
32
|
+
'DeviceFirmwareUpdateRequest',
|
|
33
33
|
PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES,
|
|
34
34
|
{
|
|
35
35
|
targets,
|
|
@@ -37,13 +37,11 @@ export default class DeviceFirmwareUpdate extends BaseMethod<DeviceFirmwareUpdat
|
|
|
37
37
|
{
|
|
38
38
|
...PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS,
|
|
39
39
|
onIntermediateResponse: (response: MessageFromOneKey) => {
|
|
40
|
-
if (response.type !== '
|
|
41
|
-
const progress = Number(response.message?.progress);
|
|
42
|
-
if (!Number.isFinite(progress)) return;
|
|
40
|
+
if (response.type !== 'DeviceFirmwareUpdateStatus') return;
|
|
43
41
|
this.postMessage(
|
|
44
42
|
createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
|
|
45
43
|
device: this.device.toMessageObject() as KnownDevice,
|
|
46
|
-
progress:
|
|
44
|
+
progress: 99,
|
|
47
45
|
progressType: 'installingFirmware',
|
|
48
46
|
})
|
|
49
47
|
);
|
|
@@ -1,19 +1,53 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
import { invalidParameter } from '../helpers/filesystemValidation';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import type { DeviceFirmwareUpdateStatusGetParams } from './helpers';
|
|
5
|
+
import type { DeviceFirmwareUpdateRecordFields } from '@onekeyfe/hd-transport';
|
|
6
|
+
|
|
7
|
+
const DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS = ['status', 'payload_version', 'path'] as const;
|
|
8
|
+
|
|
9
|
+
function normalizeStatusFields(
|
|
10
|
+
fields: DeviceFirmwareUpdateStatusGetParams['fields']
|
|
11
|
+
): DeviceFirmwareUpdateRecordFields | undefined {
|
|
12
|
+
if (fields === undefined || fields === null) return undefined;
|
|
13
|
+
if (typeof fields !== 'object' || Array.isArray(fields)) {
|
|
14
|
+
throw invalidParameter('Parameter [fields] must be an object.');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const unknownField = Object.keys(fields).find(
|
|
18
|
+
field => !DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS.includes(field as any)
|
|
19
|
+
);
|
|
20
|
+
if (unknownField) {
|
|
21
|
+
throw invalidParameter(`Unsupported firmware update status field: ${unknownField}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const normalized: DeviceFirmwareUpdateRecordFields = {};
|
|
25
|
+
for (const field of DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS) {
|
|
26
|
+
const value = fields[field];
|
|
27
|
+
if (value === undefined) continue;
|
|
28
|
+
if (typeof value !== 'boolean') {
|
|
29
|
+
throw invalidParameter(`Parameter [fields.${field}] must be a boolean.`);
|
|
30
|
+
}
|
|
31
|
+
normalized[field] = value;
|
|
32
|
+
}
|
|
33
|
+
return normalized;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default class DeviceGetFirmwareUpdateStatus extends BaseMethod<DeviceFirmwareUpdateStatusGetParams> {
|
|
4
37
|
init() {
|
|
5
38
|
// Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
|
|
6
39
|
this.requireProtocolV2 = true;
|
|
7
40
|
this.skipForceUpdateCheck = true;
|
|
8
41
|
this.useDevicePassphraseState = false;
|
|
9
|
-
|
|
42
|
+
const fields = normalizeStatusFields(this.payload.fields);
|
|
43
|
+
this.params = fields ? { fields } : {};
|
|
10
44
|
}
|
|
11
45
|
|
|
12
46
|
async run() {
|
|
13
47
|
const res = await this.device.commands.typedCall(
|
|
14
|
-
'
|
|
15
|
-
'
|
|
16
|
-
|
|
48
|
+
'DeviceFirmwareUpdateStatusGet',
|
|
49
|
+
'DeviceFirmwareUpdateStatus',
|
|
50
|
+
this.params
|
|
17
51
|
);
|
|
18
52
|
return Promise.resolve(res.message);
|
|
19
53
|
}
|
|
@@ -3,11 +3,12 @@ import { createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
|
|
|
3
3
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
4
4
|
import { PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS } from '../../protocols/protocol-v2';
|
|
5
5
|
import { BaseMethod } from '../BaseMethod';
|
|
6
|
+
import { invalidParameter } from '../helpers/filesystemValidation';
|
|
6
7
|
|
|
7
|
-
export type
|
|
8
|
+
export type DeviceInfoGetTargets = {
|
|
8
9
|
hw?: boolean;
|
|
9
10
|
fw?: boolean;
|
|
10
|
-
|
|
11
|
+
coprocessor?: boolean;
|
|
11
12
|
se1?: boolean;
|
|
12
13
|
se2?: boolean;
|
|
13
14
|
se3?: boolean;
|
|
@@ -15,22 +16,22 @@ export type DeviceGetDeviceInfoTargets = {
|
|
|
15
16
|
status?: boolean;
|
|
16
17
|
};
|
|
17
18
|
|
|
18
|
-
export type
|
|
19
|
+
export type DeviceInfoGetTypes = {
|
|
19
20
|
version?: boolean;
|
|
20
21
|
build_id?: boolean;
|
|
21
22
|
hash?: boolean;
|
|
22
23
|
specific?: boolean;
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
export type
|
|
26
|
-
targets?:
|
|
27
|
-
types?:
|
|
26
|
+
export type DeviceInfoGetParams = {
|
|
27
|
+
targets?: DeviceInfoGetTargets;
|
|
28
|
+
types?: DeviceInfoGetTypes;
|
|
28
29
|
};
|
|
29
30
|
|
|
30
|
-
const TARGET_KEYS: (keyof
|
|
31
|
+
const TARGET_KEYS: (keyof DeviceInfoGetTargets)[] = [
|
|
31
32
|
'hw',
|
|
32
33
|
'fw',
|
|
33
|
-
'
|
|
34
|
+
'coprocessor',
|
|
34
35
|
'se1',
|
|
35
36
|
'se2',
|
|
36
37
|
'se3',
|
|
@@ -38,16 +39,16 @@ const TARGET_KEYS: (keyof DeviceGetDeviceInfoTargets)[] = [
|
|
|
38
39
|
'status',
|
|
39
40
|
];
|
|
40
41
|
|
|
41
|
-
const TYPE_KEYS: (keyof
|
|
42
|
+
const TYPE_KEYS: (keyof DeviceInfoGetTypes)[] = ['version', 'build_id', 'hash', 'specific'];
|
|
42
43
|
|
|
43
|
-
const DEFAULT_TARGETS:
|
|
44
|
+
const DEFAULT_TARGETS: DeviceInfoGetTargets = {
|
|
44
45
|
hw: true,
|
|
45
46
|
fw: true,
|
|
46
|
-
|
|
47
|
+
coprocessor: true,
|
|
47
48
|
status: true,
|
|
48
49
|
};
|
|
49
50
|
|
|
50
|
-
const DEFAULT_TYPES:
|
|
51
|
+
const DEFAULT_TYPES: DeviceInfoGetTypes = {
|
|
51
52
|
version: true,
|
|
52
53
|
specific: true,
|
|
53
54
|
};
|
|
@@ -69,16 +70,48 @@ function pickBooleanKeys<T extends Record<string, boolean | undefined>>(
|
|
|
69
70
|
return hasKey ? result : undefined;
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
function assertKnownKeys(value: unknown, keys: string[], name: string) {
|
|
74
|
+
if (value == null) return;
|
|
75
|
+
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
76
|
+
throw invalidParameter(`Parameter [${name}] must be an object.`);
|
|
77
|
+
}
|
|
78
|
+
const allowed = new Set(keys);
|
|
79
|
+
const unknownKeys = Object.keys(value).filter(key => !allowed.has(key));
|
|
80
|
+
if (unknownKeys.length > 0) {
|
|
81
|
+
throw invalidParameter(
|
|
82
|
+
`Parameter [${name}] contains unsupported key(s): ${unknownKeys.join(', ')}.`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function normalizeTargets(value: unknown): DeviceInfoGetTargets | undefined {
|
|
88
|
+
assertKnownKeys(
|
|
89
|
+
value,
|
|
90
|
+
TARGET_KEYS.map(key => String(key)),
|
|
91
|
+
'targets'
|
|
92
|
+
);
|
|
93
|
+
return pickBooleanKeys<DeviceInfoGetTargets>(value, TARGET_KEYS);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function normalizeTypes(value: unknown): DeviceInfoGetTypes | undefined {
|
|
97
|
+
assertKnownKeys(
|
|
98
|
+
value,
|
|
99
|
+
TYPE_KEYS.map(key => String(key)),
|
|
100
|
+
'types'
|
|
101
|
+
);
|
|
102
|
+
return pickBooleanKeys<DeviceInfoGetTypes>(value, TYPE_KEYS);
|
|
103
|
+
}
|
|
104
|
+
|
|
72
105
|
/**
|
|
73
|
-
* 原生
|
|
106
|
+
* 原生 DeviceInfoGet(Protocol V2 only)。
|
|
74
107
|
*
|
|
75
108
|
* 与 getDeviceInfo 不同:不构建 DeviceProfile、不更新设备缓存,
|
|
76
109
|
* 按调用方给定的 targets/types 原样请求并返回未加工的 DeviceInfo 消息,
|
|
77
110
|
* 用于调试固件字段上报。
|
|
78
111
|
*/
|
|
79
|
-
export default class
|
|
80
|
-
targets:
|
|
81
|
-
types:
|
|
112
|
+
export default class DeviceInfoGet extends BaseMethod<{
|
|
113
|
+
targets: DeviceInfoGetTargets;
|
|
114
|
+
types: DeviceInfoGetTypes;
|
|
82
115
|
}> {
|
|
83
116
|
init() {
|
|
84
117
|
// Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
|
|
@@ -91,11 +124,8 @@ export default class DeviceGetDeviceInfo extends BaseMethod<{
|
|
|
91
124
|
this.useDevicePassphraseState = false;
|
|
92
125
|
this.skipForceUpdateCheck = true;
|
|
93
126
|
this.params = {
|
|
94
|
-
targets:
|
|
95
|
-
|
|
96
|
-
DEFAULT_TARGETS,
|
|
97
|
-
types:
|
|
98
|
-
pickBooleanKeys<DeviceGetDeviceInfoTypes>(this.payload.types, TYPE_KEYS) ?? DEFAULT_TYPES,
|
|
127
|
+
targets: normalizeTargets(this.payload.targets) ?? DEFAULT_TARGETS,
|
|
128
|
+
types: normalizeTypes(this.payload.types) ?? DEFAULT_TYPES,
|
|
99
129
|
};
|
|
100
130
|
}
|
|
101
131
|
|
|
@@ -105,7 +135,7 @@ export default class DeviceGetDeviceInfo extends BaseMethod<{
|
|
|
105
135
|
}
|
|
106
136
|
|
|
107
137
|
const res = await this.device.commands.typedCall(
|
|
108
|
-
'
|
|
138
|
+
'DeviceInfoGet',
|
|
109
139
|
'DeviceInfo',
|
|
110
140
|
{
|
|
111
141
|
targets: this.params.targets,
|
|
@@ -16,7 +16,7 @@ export default class DeviceReboot extends BaseMethod<DeviceRebootParams> {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
async run() {
|
|
19
|
-
const res = await this.device.commands.typedCall('
|
|
19
|
+
const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
20
20
|
reboot_type: normalizeRebootType(this.params.reboot_type ?? this.params.rebootType),
|
|
21
21
|
});
|
|
22
22
|
return Promise.resolve(res.message);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
2
|
|
|
3
|
-
export default class
|
|
3
|
+
export default class FilesystemPermissionFix extends BaseMethod {
|
|
4
4
|
init() {
|
|
5
5
|
// Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
|
|
6
6
|
this.requireProtocolV2 = true;
|
|
@@ -10,7 +10,7 @@ export default class FilesystemFixPermission extends BaseMethod {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
async run() {
|
|
13
|
-
const res = await this.device.commands.typedCall('
|
|
13
|
+
const res = await this.device.commands.typedCall('FilesystemPermissionFix', 'Success', {});
|
|
14
14
|
return Promise.resolve(res.message);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
2
|
|
|
3
|
-
export default class
|
|
3
|
+
export default class ProtocolInfoRequest extends BaseMethod {
|
|
4
4
|
init() {
|
|
5
5
|
// Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
|
|
6
6
|
this.requireProtocolV2 = true;
|
|
@@ -10,7 +10,7 @@ export default class GetProtoVersion extends BaseMethod {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
async run() {
|
|
13
|
-
const res = await this.device.commands.typedCall('
|
|
13
|
+
const res = await this.device.commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {});
|
|
14
14
|
return Promise.resolve(res.message);
|
|
15
15
|
}
|
|
16
16
|
}
|