@onekeyfe/hd-core 1.1.26-alpha.9 → 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.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/alephium/AlephiumSignTransaction.d.ts +1 -1
- package/dist/api/alephium/AlephiumSignTransaction.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/api/ton/TonSignData.d.ts.map +1 -1
- 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 +15627 -699
- 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 +5 -5
- package/src/api/BaseMethod.ts +10 -0
- 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/alephium/AlephiumSignTransaction.ts +6 -5
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +10 -1
- 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/api/ton/TonSignData.ts +4 -1
- 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
|
@@ -4,6 +4,76 @@ import { UI_REQUEST } from '../constants/ui-request';
|
|
|
4
4
|
import { fixVersion } from '../utils/deviceFeaturesUtils';
|
|
5
5
|
import { BaseMethod } from './BaseMethod';
|
|
6
6
|
|
|
7
|
+
import type { OnekeyFeatures } from '../types';
|
|
8
|
+
|
|
9
|
+
const ONEKEY_FEATURE_KEYS: Array<keyof OnekeyFeatures> = [
|
|
10
|
+
'onekey_device_type',
|
|
11
|
+
'onekey_board_version',
|
|
12
|
+
'onekey_boot_version',
|
|
13
|
+
'onekey_firmware_version',
|
|
14
|
+
'onekey_board_hash',
|
|
15
|
+
'onekey_boot_hash',
|
|
16
|
+
'onekey_firmware_hash',
|
|
17
|
+
'onekey_board_build_id',
|
|
18
|
+
'onekey_boot_build_id',
|
|
19
|
+
'onekey_firmware_build_id',
|
|
20
|
+
'onekey_serial_no',
|
|
21
|
+
'onekey_ble_name',
|
|
22
|
+
'onekey_ble_version',
|
|
23
|
+
'onekey_ble_build_id',
|
|
24
|
+
'onekey_ble_hash',
|
|
25
|
+
'onekey_se_type',
|
|
26
|
+
'onekey_se01_state',
|
|
27
|
+
'onekey_se02_state',
|
|
28
|
+
'onekey_se03_state',
|
|
29
|
+
'onekey_se04_state',
|
|
30
|
+
'onekey_se01_version',
|
|
31
|
+
'onekey_se02_version',
|
|
32
|
+
'onekey_se03_version',
|
|
33
|
+
'onekey_se04_version',
|
|
34
|
+
'onekey_se01_hash',
|
|
35
|
+
'onekey_se02_hash',
|
|
36
|
+
'onekey_se03_hash',
|
|
37
|
+
'onekey_se04_hash',
|
|
38
|
+
'onekey_se01_build_id',
|
|
39
|
+
'onekey_se02_build_id',
|
|
40
|
+
'onekey_se03_build_id',
|
|
41
|
+
'onekey_se04_build_id',
|
|
42
|
+
'onekey_se01_boot_version',
|
|
43
|
+
'onekey_se02_boot_version',
|
|
44
|
+
'onekey_se03_boot_version',
|
|
45
|
+
'onekey_se04_boot_version',
|
|
46
|
+
'onekey_se01_boot_hash',
|
|
47
|
+
'onekey_se02_boot_hash',
|
|
48
|
+
'onekey_se03_boot_hash',
|
|
49
|
+
'onekey_se04_boot_hash',
|
|
50
|
+
'onekey_se01_boot_build_id',
|
|
51
|
+
'onekey_se02_boot_build_id',
|
|
52
|
+
'onekey_se03_boot_build_id',
|
|
53
|
+
'onekey_se04_boot_build_id',
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
function normalizeOnekeyFirmwareVersion(message: OnekeyFeatures) {
|
|
57
|
+
if (message.onekey_firmware_version && !semver.valid(message.onekey_firmware_version)) {
|
|
58
|
+
message.onekey_firmware_version = fixVersion(message.onekey_firmware_version);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function pickOnekeyFeatures(features?: OnekeyFeatures | null): OnekeyFeatures {
|
|
63
|
+
const message: OnekeyFeatures = {};
|
|
64
|
+
if (!features) return message;
|
|
65
|
+
|
|
66
|
+
for (const key of ONEKEY_FEATURE_KEYS) {
|
|
67
|
+
const value = features[key];
|
|
68
|
+
if (value !== undefined && value !== null) {
|
|
69
|
+
(message as Record<string, unknown>)[key] = value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
normalizeOnekeyFirmwareVersion(message);
|
|
74
|
+
return message;
|
|
75
|
+
}
|
|
76
|
+
|
|
7
77
|
export default class GetOnekeyFeatures extends BaseMethod {
|
|
8
78
|
init() {
|
|
9
79
|
this.allowDeviceMode = [
|
|
@@ -16,10 +86,12 @@ export default class GetOnekeyFeatures extends BaseMethod {
|
|
|
16
86
|
}
|
|
17
87
|
|
|
18
88
|
async run() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
message.onekey_firmware_version = fixVersion(message.onekey_firmware_version);
|
|
89
|
+
if (this.device.originalDescriptor?.protocolType === 'V2') {
|
|
90
|
+
return Promise.resolve(pickOnekeyFeatures(this.device.features as OnekeyFeatures));
|
|
22
91
|
}
|
|
92
|
+
|
|
93
|
+
const { message } = await this.device.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
|
|
94
|
+
normalizeOnekeyFirmwareVersion(message);
|
|
23
95
|
return Promise.resolve(message);
|
|
24
96
|
}
|
|
25
97
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseMethod } from './BaseMethod';
|
|
2
|
+
|
|
3
|
+
export type PathInfoParams = {
|
|
4
|
+
path: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export default class PathInfo extends BaseMethod<PathInfoParams> {
|
|
8
|
+
init() {
|
|
9
|
+
this.skipForceUpdateCheck = true;
|
|
10
|
+
this.useDevicePassphraseState = false;
|
|
11
|
+
this.params = { path: this.payload.path };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async run() {
|
|
15
|
+
const res = await this.device.commands.typedCall(
|
|
16
|
+
'FilesystemPathInfoQuery',
|
|
17
|
+
'FilesystemPathInfo',
|
|
18
|
+
{
|
|
19
|
+
path: this.params.path,
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
return Promise.resolve(res.message);
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/api/SearchDevices.ts
CHANGED
|
@@ -34,17 +34,22 @@ export default class SearchDevices extends BaseMethod {
|
|
|
34
34
|
const lowerId = device.id?.toLowerCase();
|
|
35
35
|
if (!seenIds.has(lowerId)) {
|
|
36
36
|
seenIds.add(lowerId);
|
|
37
|
+
const bleName =
|
|
38
|
+
device.name ?? (device as unknown as { localName?: string }).localName ?? '';
|
|
37
39
|
devices.push({
|
|
38
40
|
...device,
|
|
39
41
|
connectId: device.id,
|
|
40
|
-
|
|
42
|
+
name: bleName || device.name,
|
|
43
|
+
deviceType: getDeviceTypeByBleName(bleName),
|
|
41
44
|
});
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
return devices;
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
const { deviceList } = await DevicePool.getDevices(devicesDescriptor
|
|
50
|
+
const { deviceList } = await DevicePool.getDevices(devicesDescriptor, undefined, {
|
|
51
|
+
connectProtocol: this.payload.connectProtocol,
|
|
52
|
+
});
|
|
48
53
|
return deviceList.map(device => device.toMessageObject());
|
|
49
54
|
}
|
|
50
55
|
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AlephiumSignedTx,
|
|
3
|
-
type AlephiumSignTx as HardwareAlephiumSignTx,
|
|
4
|
-
TypedCall,
|
|
5
|
-
} from '@onekeyfe/hd-transport';
|
|
6
1
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
7
2
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
8
3
|
|
|
@@ -10,6 +5,12 @@ import { UI_REQUEST } from '../../constants/ui-request';
|
|
|
10
5
|
import { validatePath } from '../helpers/pathUtils';
|
|
11
6
|
import { BaseMethod } from '../BaseMethod';
|
|
12
7
|
import { validateParams } from '../helpers/paramsValidator';
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
AlephiumSignedTx,
|
|
11
|
+
AlephiumSignTx as HardwareAlephiumSignTx,
|
|
12
|
+
TypedCall,
|
|
13
|
+
} from '@onekeyfe/hd-transport';
|
|
13
14
|
import type { AlephiumSignTransactionParams } from '../../types';
|
|
14
15
|
import type { TypedResponseMessage } from '../../device/DeviceCommands';
|
|
15
16
|
|
|
@@ -12,7 +12,12 @@ import { validateParams } from '../helpers/paramsValidator';
|
|
|
12
12
|
import { PROTO } from '../../constants';
|
|
13
13
|
import { findMethod } from '../utils';
|
|
14
14
|
import { DEVICE, IFRAME, createUiMessage } from '../../events';
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
getDeviceFirmwareVersion,
|
|
17
|
+
getFirmwareType,
|
|
18
|
+
getMethodVersionRange,
|
|
19
|
+
shouldSkipMethodSupportCheck,
|
|
20
|
+
} from '../../utils';
|
|
16
21
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
17
22
|
import { onDeviceButtonHandler } from '../../core';
|
|
18
23
|
import {
|
|
@@ -455,6 +460,10 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
|
|
|
455
460
|
* @param method BaseMethod
|
|
456
461
|
*/
|
|
457
462
|
function preCheckDeviceSupport(device: Device, method: BaseMethod) {
|
|
463
|
+
if (shouldSkipMethodSupportCheck(device.features, device.originalDescriptor?.protocolType)) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
|
|
458
467
|
const versionRange = getMethodVersionRange(
|
|
459
468
|
device.features,
|
|
460
469
|
type => method.getVersionRange()[type]
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DevRebootType } from '@onekeyfe/hd-transport';
|
|
2
|
+
|
|
1
3
|
import { BaseMethod } from '../BaseMethod';
|
|
2
4
|
|
|
3
5
|
import type { RebootToBoardloaderParams } from '../../types/api/deviceRebootToBoardloader';
|
|
@@ -21,10 +23,17 @@ export default class DeviceRebootToBoardloader extends BaseMethod<RebootToBoardl
|
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
async run() {
|
|
26
|
+
// Protocol V2 uses DevReboot with reboot_type enum.
|
|
27
|
+
if (this.device.originalDescriptor?.protocolType === 'V2') {
|
|
28
|
+
const res = await this.device.commands.typedCall('DevReboot', 'Success', {
|
|
29
|
+
reboot_type: DevRebootType.Boardloader,
|
|
30
|
+
});
|
|
31
|
+
return Promise.resolve(res.message);
|
|
32
|
+
}
|
|
33
|
+
|
|
24
34
|
// On Touch devices, messsage code 904 is RebootToBoardloader
|
|
25
35
|
// so BininOutMessageSE message code 904 is used here
|
|
26
36
|
const res = await this.device.commands.typedCall('BixinOutMessageSE', 'Success');
|
|
27
|
-
|
|
28
37
|
return Promise.resolve(res.message);
|
|
29
38
|
}
|
|
30
39
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DevRebootType } from '@onekeyfe/hd-transport';
|
|
2
|
+
|
|
1
3
|
import { BaseMethod } from '../BaseMethod';
|
|
2
4
|
|
|
3
5
|
import type { RebootToBootloader } from '@onekeyfe/hd-transport';
|
|
@@ -21,8 +23,15 @@ export default class DeviceRebootToBootloader extends BaseMethod<RebootToBootloa
|
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
async run() {
|
|
24
|
-
|
|
26
|
+
// Protocol V2 uses DevReboot with reboot_type enum.
|
|
27
|
+
if (this.device.originalDescriptor?.protocolType === 'V2') {
|
|
28
|
+
const res = await this.device.commands.typedCall('DevReboot', 'Success', {
|
|
29
|
+
reboot_type: DevRebootType.Bootloader,
|
|
30
|
+
});
|
|
31
|
+
return Promise.resolve(res.message);
|
|
32
|
+
}
|
|
25
33
|
|
|
34
|
+
const res = await this.device.commands.typedCall('RebootToBootloader', 'Success');
|
|
26
35
|
return Promise.resolve(res.message);
|
|
27
36
|
}
|
|
28
37
|
}
|
|
@@ -28,6 +28,13 @@ const Log = getLogger(LoggerNames.Method);
|
|
|
28
28
|
const SESSION_ERROR = 'session not found';
|
|
29
29
|
const FIRMWARE_UPDATE_CONFIRM = 'Firmware install confirmed';
|
|
30
30
|
|
|
31
|
+
type FirmwareProgressMetadata = {
|
|
32
|
+
transferredBytes?: number;
|
|
33
|
+
totalBytes?: number;
|
|
34
|
+
rateBytesPerSecond?: number;
|
|
35
|
+
elapsedMs?: number;
|
|
36
|
+
};
|
|
37
|
+
|
|
31
38
|
const isDeviceDisconnectedError = (error: unknown) => {
|
|
32
39
|
const message = error instanceof Error ? error.message : String(error ?? '');
|
|
33
40
|
return (
|
|
@@ -82,12 +89,17 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
82
89
|
* @description Post the progress message
|
|
83
90
|
* @param progress Post the percentage of the progress
|
|
84
91
|
*/
|
|
85
|
-
postProgressMessage = (
|
|
92
|
+
postProgressMessage = (
|
|
93
|
+
progress: number,
|
|
94
|
+
progressType: IFirmwareUpdateProgressType,
|
|
95
|
+
metadata: FirmwareProgressMetadata = {}
|
|
96
|
+
) => {
|
|
86
97
|
this.postMessage(
|
|
87
98
|
createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
|
|
88
99
|
device: this.device.toMessageObject() as KnownDevice,
|
|
89
100
|
progress,
|
|
90
101
|
progressType,
|
|
102
|
+
...metadata,
|
|
91
103
|
})
|
|
92
104
|
);
|
|
93
105
|
};
|
|
@@ -325,10 +337,12 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
325
337
|
filePath,
|
|
326
338
|
processedSize,
|
|
327
339
|
totalSize,
|
|
340
|
+
transferStartTime = Date.now(),
|
|
328
341
|
}: PROTO.FirmwareUpload & {
|
|
329
342
|
filePath: string;
|
|
330
343
|
processedSize?: number;
|
|
331
344
|
totalSize?: number;
|
|
345
|
+
transferStartTime?: number;
|
|
332
346
|
}) {
|
|
333
347
|
if (!filePath.startsWith('0:')) {
|
|
334
348
|
throw new Error('filePath must start with 0:');
|
|
@@ -338,7 +352,6 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
338
352
|
const chunkSize = 1024 * perPackageSize;
|
|
339
353
|
const totalChunks = Math.ceil(payload.byteLength / chunkSize);
|
|
340
354
|
let offset = 0;
|
|
341
|
-
let currentFileProcessed = 0;
|
|
342
355
|
|
|
343
356
|
for (let i = 0; i < totalChunks; i++) {
|
|
344
357
|
const chunkStart = i * chunkSize;
|
|
@@ -350,7 +363,7 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
350
363
|
// Calculate progress based on whether we're tracking overall progress or single file progress
|
|
351
364
|
let progress: number;
|
|
352
365
|
if (totalSize !== undefined && processedSize !== undefined) {
|
|
353
|
-
currentFileProcessed = processedSize + chunkEnd;
|
|
366
|
+
const currentFileProcessed = processedSize + chunkEnd;
|
|
354
367
|
progress = Math.min(Math.ceil((currentFileProcessed / totalSize) * 100), 99);
|
|
355
368
|
} else {
|
|
356
369
|
progress = Math.min(Math.ceil(((i + 1) / totalChunks) * 100), 99);
|
|
@@ -366,7 +379,17 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
366
379
|
);
|
|
367
380
|
// @ts-expect-error
|
|
368
381
|
offset += writeRes.message.processed_byte;
|
|
369
|
-
|
|
382
|
+
const elapsedMs = Date.now() - transferStartTime;
|
|
383
|
+
const transferredBytes =
|
|
384
|
+
totalSize !== undefined && processedSize !== undefined ? processedSize + offset : offset;
|
|
385
|
+
const totalBytes = totalSize ?? payload.byteLength;
|
|
386
|
+
this.postProgressMessage(progress, 'transferData', {
|
|
387
|
+
transferredBytes,
|
|
388
|
+
totalBytes,
|
|
389
|
+
rateBytesPerSecond:
|
|
390
|
+
elapsedMs > 0 ? Math.round((transferredBytes / elapsedMs) * 1000) : undefined,
|
|
391
|
+
elapsedMs,
|
|
392
|
+
});
|
|
370
393
|
}
|
|
371
394
|
|
|
372
395
|
// Return processed size only if we're tracking overall progress
|
package/src/api/index.ts
CHANGED
|
@@ -37,8 +37,36 @@ export { default as getNextU2FCounter } from './u2f/GetNextU2FCounter';
|
|
|
37
37
|
export { default as firmwareUpdate } from './FirmwareUpdate';
|
|
38
38
|
export { default as firmwareUpdateV2 } from './FirmwareUpdateV2';
|
|
39
39
|
export { default as firmwareUpdateV3 } from './FirmwareUpdateV3';
|
|
40
|
+
export { default as firmwareUpdateV4 } from './FirmwareUpdateV4';
|
|
40
41
|
export { default as promptWebDeviceAccess } from './PromptWebDeviceAccess';
|
|
41
42
|
|
|
43
|
+
// File system & device control API (Protocol V2 only)
|
|
44
|
+
export { default as getProtoVersion } from './protocol-v2/GetProtoVersion';
|
|
45
|
+
export { default as ping } from './protocol-v2/Ping';
|
|
46
|
+
export { default as devReboot } from './protocol-v2/DevReboot';
|
|
47
|
+
export { default as devGetDeviceInfo } from './protocol-v2/DevGetDeviceInfo';
|
|
48
|
+
export { default as devGetOnboardingStatus } from './protocol-v2/DevGetOnboardingStatus';
|
|
49
|
+
export { default as devFirmwareUpdate } from './protocol-v2/DevFirmwareUpdate';
|
|
50
|
+
export { default as devGetFirmwareUpdateStatus } from './protocol-v2/DevGetFirmwareUpdateStatus';
|
|
51
|
+
export { default as factoryDeviceInfoSettings } from './protocol-v2/FactoryDeviceInfoSettings';
|
|
52
|
+
export { default as factoryGetDeviceInfo } from './protocol-v2/FactoryGetDeviceInfo';
|
|
53
|
+
export { default as filesystemFixPermission } from './protocol-v2/FilesystemFixPermission';
|
|
54
|
+
export { default as filesystemFormat } from './protocol-v2/FilesystemFormat';
|
|
55
|
+
export { default as fileRead } from './FileRead';
|
|
56
|
+
export { default as fileWrite } from './FileWrite';
|
|
57
|
+
export { default as fileDelete } from './FileDelete';
|
|
58
|
+
export { default as dirList } from './DirList';
|
|
59
|
+
export { default as dirMake } from './DirMake';
|
|
60
|
+
export { default as dirRemove } from './DirRemove';
|
|
61
|
+
export { default as pathInfo } from './PathInfo';
|
|
62
|
+
export { default as filesystemFileRead } from './FileRead';
|
|
63
|
+
export { default as filesystemFileWrite } from './FileWrite';
|
|
64
|
+
export { default as filesystemFileDelete } from './FileDelete';
|
|
65
|
+
export { default as filesystemDirList } from './DirList';
|
|
66
|
+
export { default as filesystemDirMake } from './DirMake';
|
|
67
|
+
export { default as filesystemDirRemove } from './DirRemove';
|
|
68
|
+
export { default as filesystemPathInfoQuery } from './PathInfo';
|
|
69
|
+
|
|
42
70
|
export { default as cipherKeyValue } from './CipherKeyValue';
|
|
43
71
|
|
|
44
72
|
export { default as allNetworkGetAddress } from './allnetwork/AllNetworkGetAddress';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
import {
|
|
3
|
+
PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS,
|
|
4
|
+
PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES,
|
|
5
|
+
normalizeFirmwareTargets,
|
|
6
|
+
} from './helpers';
|
|
7
|
+
|
|
8
|
+
import type { DevFirmwareUpdateParams } from './helpers';
|
|
9
|
+
|
|
10
|
+
export default class DevFirmwareUpdate extends BaseMethod<DevFirmwareUpdateParams> {
|
|
11
|
+
init() {
|
|
12
|
+
this.skipForceUpdateCheck = true;
|
|
13
|
+
this.useDevicePassphraseState = false;
|
|
14
|
+
this.params = {
|
|
15
|
+
targets: this.payload.targets,
|
|
16
|
+
targetId: this.payload.targetId,
|
|
17
|
+
target_id: this.payload.target_id,
|
|
18
|
+
path: this.payload.path,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async run() {
|
|
23
|
+
const res = await this.device.commands.typedCall(
|
|
24
|
+
'DevFirmwareUpdate',
|
|
25
|
+
PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES,
|
|
26
|
+
{
|
|
27
|
+
targets: normalizeFirmwareTargets(this.params),
|
|
28
|
+
},
|
|
29
|
+
PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS
|
|
30
|
+
);
|
|
31
|
+
return Promise.resolve(res.message);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
import { buildTargets, buildTypes } from './helpers';
|
|
3
|
+
|
|
4
|
+
import type { DevGetDeviceInfoParams } from './helpers';
|
|
5
|
+
|
|
6
|
+
export default class DevGetDeviceInfo extends BaseMethod<DevGetDeviceInfoParams> {
|
|
7
|
+
init() {
|
|
8
|
+
this.skipForceUpdateCheck = true;
|
|
9
|
+
this.useDevicePassphraseState = false;
|
|
10
|
+
this.params = {
|
|
11
|
+
targets: this.payload.targets,
|
|
12
|
+
types: this.payload.types,
|
|
13
|
+
targetHw: this.payload.targetHw,
|
|
14
|
+
targetFw: this.payload.targetFw,
|
|
15
|
+
targetBt: this.payload.targetBt,
|
|
16
|
+
targetSe1: this.payload.targetSe1,
|
|
17
|
+
targetSe2: this.payload.targetSe2,
|
|
18
|
+
targetSe3: this.payload.targetSe3,
|
|
19
|
+
targetSe4: this.payload.targetSe4,
|
|
20
|
+
targetStatus: this.payload.targetStatus,
|
|
21
|
+
includeVersion: this.payload.includeVersion,
|
|
22
|
+
includeBuildId: this.payload.includeBuildId,
|
|
23
|
+
includeHash: this.payload.includeHash,
|
|
24
|
+
includeSpecific: this.payload.includeSpecific,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async run() {
|
|
29
|
+
const res = await this.device.commands.typedCall('DevGetDeviceInfo', 'DeviceInfo', {
|
|
30
|
+
targets: buildTargets(this.params),
|
|
31
|
+
types: buildTypes(this.params),
|
|
32
|
+
});
|
|
33
|
+
return Promise.resolve(res.message);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
|
|
3
|
+
export default class DevGetFirmwareUpdateStatus extends BaseMethod {
|
|
4
|
+
init() {
|
|
5
|
+
this.skipForceUpdateCheck = true;
|
|
6
|
+
this.useDevicePassphraseState = false;
|
|
7
|
+
this.params = undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async run() {
|
|
11
|
+
const res = await this.device.commands.typedCall(
|
|
12
|
+
'DevGetFirmwareUpdateStatus',
|
|
13
|
+
'DevFirmwareUpdateStatus',
|
|
14
|
+
{}
|
|
15
|
+
);
|
|
16
|
+
return Promise.resolve(res.message);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
|
|
3
|
+
export default class DevGetOnboardingStatus extends BaseMethod {
|
|
4
|
+
init() {
|
|
5
|
+
this.skipForceUpdateCheck = true;
|
|
6
|
+
this.useDevicePassphraseState = false;
|
|
7
|
+
this.params = undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async run() {
|
|
11
|
+
const res = await this.device.commands.typedCall(
|
|
12
|
+
'DevGetOnboardingStatus',
|
|
13
|
+
'DevOnboardingStatus',
|
|
14
|
+
{}
|
|
15
|
+
);
|
|
16
|
+
return Promise.resolve(res.message);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
import { normalizeRebootType } from './helpers';
|
|
3
|
+
|
|
4
|
+
import type { DevRebootParams } from './helpers';
|
|
5
|
+
|
|
6
|
+
export default class DevReboot extends BaseMethod<DevRebootParams> {
|
|
7
|
+
init() {
|
|
8
|
+
this.skipForceUpdateCheck = true;
|
|
9
|
+
this.useDevicePassphraseState = false;
|
|
10
|
+
this.params = {
|
|
11
|
+
rebootType: this.payload.rebootType,
|
|
12
|
+
reboot_type: this.payload.reboot_type,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async run() {
|
|
17
|
+
const res = await this.device.commands.typedCall('DevReboot', 'Success', {
|
|
18
|
+
reboot_type: normalizeRebootType(this.params.reboot_type ?? this.params.rebootType),
|
|
19
|
+
});
|
|
20
|
+
return Promise.resolve(res.message);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
|
|
3
|
+
import type { FactoryDeviceInfoSettingsParams } from './helpers';
|
|
4
|
+
|
|
5
|
+
export default class FactoryDeviceInfoSettings extends BaseMethod<FactoryDeviceInfoSettingsParams> {
|
|
6
|
+
init() {
|
|
7
|
+
this.skipForceUpdateCheck = true;
|
|
8
|
+
this.useDevicePassphraseState = false;
|
|
9
|
+
this.params = {
|
|
10
|
+
serial_no: this.payload.serial_no,
|
|
11
|
+
serialNo: this.payload.serialNo,
|
|
12
|
+
cpu_info: this.payload.cpu_info,
|
|
13
|
+
cpuInfo: this.payload.cpuInfo,
|
|
14
|
+
pre_firmware: this.payload.pre_firmware,
|
|
15
|
+
preFirmware: this.payload.preFirmware,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async run() {
|
|
20
|
+
const res = await this.device.commands.typedCall('FactoryDeviceInfoSettings', 'Success', {
|
|
21
|
+
serial_no: this.params.serial_no ?? this.params.serialNo,
|
|
22
|
+
cpu_info: this.params.cpu_info ?? this.params.cpuInfo,
|
|
23
|
+
pre_firmware: this.params.pre_firmware ?? this.params.preFirmware,
|
|
24
|
+
});
|
|
25
|
+
return Promise.resolve(res.message);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
|
|
3
|
+
export default class FactoryGetDeviceInfo extends BaseMethod {
|
|
4
|
+
init() {
|
|
5
|
+
this.skipForceUpdateCheck = true;
|
|
6
|
+
this.useDevicePassphraseState = false;
|
|
7
|
+
this.params = undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async run() {
|
|
11
|
+
const res = await this.device.commands.typedCall(
|
|
12
|
+
'FactoryGetDeviceInfo',
|
|
13
|
+
'FactoryDeviceInfo',
|
|
14
|
+
{}
|
|
15
|
+
);
|
|
16
|
+
return Promise.resolve(res.message);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
|
|
3
|
+
export default class FilesystemFixPermission extends BaseMethod {
|
|
4
|
+
init() {
|
|
5
|
+
this.skipForceUpdateCheck = true;
|
|
6
|
+
this.useDevicePassphraseState = false;
|
|
7
|
+
this.params = undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async run() {
|
|
11
|
+
const res = await this.device.commands.typedCall('FilesystemFixPermission', 'Success', {});
|
|
12
|
+
return Promise.resolve(res.message);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
|
|
3
|
+
export default class FilesystemFormat extends BaseMethod {
|
|
4
|
+
init() {
|
|
5
|
+
this.skipForceUpdateCheck = true;
|
|
6
|
+
this.useDevicePassphraseState = false;
|
|
7
|
+
this.params = undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async run() {
|
|
11
|
+
const res = await this.device.commands.typedCall('FilesystemFormat', 'Success', {});
|
|
12
|
+
return Promise.resolve(res.message);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
|
|
3
|
+
export default class GetProtoVersion extends BaseMethod {
|
|
4
|
+
init() {
|
|
5
|
+
this.skipForceUpdateCheck = true;
|
|
6
|
+
this.useDevicePassphraseState = false;
|
|
7
|
+
this.params = undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async run() {
|
|
11
|
+
const res = await this.device.commands.typedCall('GetProtoVersion', 'ProtoVersion', {});
|
|
12
|
+
return Promise.resolve(res.message);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
|
|
3
|
+
export default class Ping extends BaseMethod<{ message?: string }> {
|
|
4
|
+
init() {
|
|
5
|
+
this.skipForceUpdateCheck = true;
|
|
6
|
+
this.useDevicePassphraseState = false;
|
|
7
|
+
this.params = { message: this.payload.message };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async run() {
|
|
11
|
+
const res = await this.device.commands.typedCall('Ping', 'Success', {
|
|
12
|
+
message: this.params.message ?? '',
|
|
13
|
+
});
|
|
14
|
+
return Promise.resolve(res.message);
|
|
15
|
+
}
|
|
16
|
+
}
|