@onekeyfe/hd-core 1.2.0-alpha.0 → 1.2.0-alpha.10
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__/connectSettings.test.ts +19 -0
- package/__tests__/device-wallet-session-store.test.ts +131 -0
- package/__tests__/preInitialize.test.ts +33 -0
- package/__tests__/protocol-v2-firmware-targets.test.ts +19 -0
- package/__tests__/protocol-v2.test.ts +1930 -765
- package/dist/api/ClearSessionCache.d.ts +9 -0
- package/dist/api/ClearSessionCache.d.ts.map +1 -0
- package/dist/api/FileRead.d.ts.map +1 -1
- package/dist/api/FileWrite.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +26 -5
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetDeviceInfo.d.ts.map +1 -1
- package/dist/api/GetFeatures.d.ts +1 -1
- package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts +4 -4
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +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/bootloaderHelper.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/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/index.d.ts +8 -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/DeviceSessionGet.d.ts +9 -0
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -1
- 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 -19
- 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/api/tron/TronSignMessage.d.ts +0 -1
- package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
- package/dist/api/tron/TronSignTransaction.d.ts +0 -1
- package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
- package/dist/constants/index.d.ts +2 -1
- package/dist/constants/index.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 +17 -18
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceWalletSessionStore.d.ts +15 -0
- package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts +6 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceProfile.d.ts +3 -4
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
- package/dist/deviceProfile/index.d.ts +1 -1
- package/dist/deviceProfile/index.d.ts.map +1 -1
- package/dist/index.d.ts +657 -539
- package/dist/index.js +2579 -2161
- 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/protocols/protocol-v2/index.d.ts +1 -0
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +13 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdate.d.ts +4 -6
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/getDeviceInfo.d.ts +4 -2
- package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
- package/dist/types/api/getPassphraseState.d.ts +4 -4
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +11 -11
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +16 -17
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/api/sessionCache.d.ts +10 -0
- package/dist/types/api/sessionCache.d.ts.map +1 -0
- package/dist/types/device.d.ts +88 -8
- 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 +21 -1
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/capabilitieUtils.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +2 -0
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
- package/dist/utils/findDefectiveBatchDevice.d.ts +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/ClearSessionCache.ts +28 -0
- package/src/api/FileRead.ts +16 -3
- package/src/api/FileWrite.ts +14 -1
- package/src/api/FirmwareUpdateV2.ts +9 -2
- package/src/api/FirmwareUpdateV3.ts +2 -1
- package/src/api/FirmwareUpdateV4.ts +1089 -285
- package/src/api/GetDeviceInfo.ts +6 -13
- package/src/api/GetOnekeyFeatures.ts +3 -14
- package/src/api/GetPassphraseState.ts +7 -4
- 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/bootloaderHelper.ts +3 -2
- package/src/api/firmware/getBinary.ts +1 -1
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/firmware/releaseHelper.ts +3 -3
- package/src/api/firmware/uploadFirmware.ts +5 -2
- package/src/api/index.ts +8 -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 +2 -2
- package/src/api/protocol-v2/DeviceSessionGet.ts +26 -0
- package/src/api/protocol-v2/DeviceStatusGet.ts +14 -0
- package/src/api/protocol-v2/FilesystemFormat.ts +4 -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 +58 -59
- package/src/api/ton/TonSignData.ts +1 -5
- package/src/api/tron/TronSignMessage.ts +0 -1
- package/src/api/tron/TronSignTransaction.ts +0 -1
- package/src/constants/index.ts +10 -1
- package/src/core/index.ts +22 -10
- package/src/data/messages/messages-protocol-v2.json +992 -1420
- package/src/data/messages/messages.json +8 -0
- package/src/data-manager/DataManager.ts +11 -4
- package/src/data-manager/connectSettings.ts +4 -0
- package/src/device/Device.ts +158 -294
- package/src/device/DevicePool.ts +9 -9
- package/src/device/DeviceWalletSessionStore.ts +78 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +365 -0
- package/src/deviceProfile/buildDeviceProfile.ts +165 -200
- package/src/deviceProfile/index.ts +4 -1
- package/src/inject.ts +13 -16
- package/src/protocols/protocol-v2/features.ts +28 -67
- package/src/protocols/protocol-v2/firmware.ts +12 -36
- package/src/protocols/protocol-v2/index.ts +1 -0
- package/src/protocols/protocol-v2/walletSession.ts +83 -0
- package/src/types/api/firmwareUpdate.ts +16 -20
- package/src/types/api/getDeviceInfo.ts +4 -2
- package/src/types/api/getPassphraseState.ts +4 -4
- package/src/types/api/index.ts +17 -20
- package/src/types/api/protocolV2.ts +35 -40
- package/src/types/api/sessionCache.ts +14 -0
- package/src/types/device.ts +98 -34
- package/src/types/params.ts +4 -0
- package/src/types/settings.ts +42 -30
- package/src/utils/capabilitieUtils.ts +1 -2
- package/src/utils/deviceFeaturesUtils.ts +54 -29
- package/src/utils/deviceInfoUtils.ts +11 -29
- package/src/utils/deviceVersionUtils.ts +7 -25
- package/src/utils/findDefectiveBatchDevice.ts +6 -6
- 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/dist/deviceProfile/legacyFeaturesView.d.ts +0 -5
- package/dist/deviceProfile/legacyFeaturesView.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
- package/src/deviceProfile/legacyFeaturesView.ts +0 -123
|
@@ -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,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
import {
|
|
2
|
+
import { normalizeRebootType } from './helpers';
|
|
3
3
|
|
|
4
4
|
import type { DeviceRebootParams } from './helpers';
|
|
5
5
|
|
|
@@ -17,7 +17,7 @@ export default class DeviceReboot extends BaseMethod<DeviceRebootParams> {
|
|
|
17
17
|
|
|
18
18
|
async run() {
|
|
19
19
|
const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
20
|
-
reboot_type:
|
|
20
|
+
reboot_type: normalizeRebootType(this.params.reboot_type ?? this.params.rebootType),
|
|
21
21
|
});
|
|
22
22
|
return Promise.resolve(res.message);
|
|
23
23
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
|
|
3
|
+
export type DeviceSessionGetParams = {
|
|
4
|
+
sessionId?: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export default class DeviceSessionGet extends BaseMethod<DeviceSessionGetParams> {
|
|
8
|
+
init() {
|
|
9
|
+
this.requireProtocolV2 = true;
|
|
10
|
+
this.useDevicePassphraseState = false;
|
|
11
|
+
this.skipForceUpdateCheck = true;
|
|
12
|
+
this.params = {
|
|
13
|
+
sessionId: this.payload.sessionId,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async run() {
|
|
18
|
+
const payload = this.params.sessionId ? { session_id: this.params.sessionId } : {};
|
|
19
|
+
const { message } = await this.device.commands.typedCall(
|
|
20
|
+
'DeviceSessionGet',
|
|
21
|
+
'DeviceSession',
|
|
22
|
+
payload
|
|
23
|
+
);
|
|
24
|
+
return message;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
|
|
3
|
+
export default class DeviceStatusGet extends BaseMethod {
|
|
4
|
+
init() {
|
|
5
|
+
this.requireProtocolV2 = true;
|
|
6
|
+
this.useDevicePassphraseState = false;
|
|
7
|
+
this.skipForceUpdateCheck = true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async run() {
|
|
11
|
+
const { message } = await this.device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
|
|
12
|
+
return message;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -10,7 +10,10 @@ export default class FilesystemFormat extends BaseMethod {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
async run() {
|
|
13
|
-
const res = await this.device.commands.typedCall('FilesystemFormat', 'Success', {
|
|
13
|
+
const res = await this.device.commands.typedCall('FilesystemFormat', 'Success', {
|
|
14
|
+
data: true,
|
|
15
|
+
user: true,
|
|
16
|
+
});
|
|
14
17
|
return Promise.resolve(res.message);
|
|
15
18
|
}
|
|
16
19
|
}
|
|
@@ -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
|
}
|
|
@@ -1,20 +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
|
+
DeviceFirmwareTargetType,
|
|
9
|
+
DeviceFirmwareUpdateRecordFields,
|
|
8
10
|
TransportCallOptions,
|
|
9
11
|
} from '@onekeyfe/hd-transport';
|
|
10
12
|
|
|
11
|
-
export type RebootTypeInput =
|
|
12
|
-
| DevRebootType
|
|
13
|
-
| DeviceRebootType
|
|
14
|
-
| keyof typeof DevRebootType
|
|
15
|
-
| keyof typeof DeviceRebootType
|
|
16
|
-
| string
|
|
17
|
-
| number;
|
|
13
|
+
export type RebootTypeInput = DeviceRebootType | keyof typeof DeviceRebootType | string | number;
|
|
18
14
|
|
|
19
15
|
export type DeviceRebootParams = {
|
|
20
16
|
rebootType?: RebootTypeInput;
|
|
@@ -22,38 +18,37 @@ export type DeviceRebootParams = {
|
|
|
22
18
|
};
|
|
23
19
|
|
|
24
20
|
export type DeviceFirmwareTargetInput =
|
|
25
|
-
|
|
|
21
|
+
| DeviceFirmwareTarget
|
|
26
22
|
| {
|
|
27
|
-
targetId?:
|
|
28
|
-
target_id?:
|
|
23
|
+
targetId?: DeviceFirmwareTargetType | string | number;
|
|
24
|
+
target_id?: DeviceFirmwareTargetType | string | number;
|
|
29
25
|
path: string;
|
|
30
26
|
};
|
|
31
27
|
|
|
32
28
|
export type DeviceFirmwareUpdateParams = {
|
|
33
29
|
targets?: DeviceFirmwareTargetInput[];
|
|
34
|
-
targetId?:
|
|
35
|
-
target_id?:
|
|
30
|
+
targetId?: DeviceFirmwareTargetType | string | number;
|
|
31
|
+
target_id?: DeviceFirmwareTargetType | string | number;
|
|
36
32
|
path?: string;
|
|
37
33
|
};
|
|
38
34
|
|
|
39
|
-
export type
|
|
40
|
-
|
|
41
|
-
serialNo?: string;
|
|
42
|
-
cpu_info?: string;
|
|
43
|
-
cpuInfo?: string;
|
|
44
|
-
pre_firmware?: string;
|
|
45
|
-
preFirmware?: string;
|
|
35
|
+
export type DeviceFirmwareUpdateStatusGetParams = {
|
|
36
|
+
fields?: DeviceFirmwareUpdateRecordFields;
|
|
46
37
|
};
|
|
47
38
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
+
};
|
|
57
52
|
};
|
|
58
53
|
|
|
59
54
|
const DEVICE_REBOOT_TYPES: Record<string, DeviceRebootType> = {
|
|
@@ -68,13 +63,13 @@ const DEVICE_REBOOT_TYPES: Record<string, DeviceRebootType> = {
|
|
|
68
63
|
};
|
|
69
64
|
|
|
70
65
|
export const PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS: TransportCallOptions = {
|
|
71
|
-
intermediateTypes: ['
|
|
66
|
+
intermediateTypes: ['DeviceFirmwareUpdateStatus'],
|
|
72
67
|
};
|
|
73
68
|
|
|
74
69
|
export const PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES: (
|
|
75
70
|
| 'Success'
|
|
76
|
-
| '
|
|
77
|
-
)[] = ['Success', '
|
|
71
|
+
| 'DeviceFirmwareUpdateStatus'
|
|
72
|
+
)[] = ['Success', 'DeviceFirmwareUpdateStatus'];
|
|
78
73
|
|
|
79
74
|
export const getProtocolV2UnknownErrorText = (error: unknown) => {
|
|
80
75
|
if (!error) {
|
|
@@ -133,19 +128,7 @@ export const isProtocolV2DeviceDisconnectedError = (error: unknown) => {
|
|
|
133
128
|
);
|
|
134
129
|
};
|
|
135
130
|
|
|
136
|
-
export function normalizeRebootType(value: RebootTypeInput | undefined):
|
|
137
|
-
if (typeof value === 'number') return value;
|
|
138
|
-
if (typeof value === 'string') {
|
|
139
|
-
const numeric = Number(value);
|
|
140
|
-
if (Number.isFinite(numeric)) return numeric;
|
|
141
|
-
if (value in DEV_REBOOT_TYPES) return DEV_REBOOT_TYPES[value];
|
|
142
|
-
}
|
|
143
|
-
return DevRebootType.Normal;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function normalizeDeviceRebootType(
|
|
147
|
-
value: RebootTypeInput | undefined
|
|
148
|
-
): DeviceRebootType {
|
|
131
|
+
export function normalizeRebootType(value: RebootTypeInput | undefined): DeviceRebootType {
|
|
149
132
|
if (typeof value === 'number') return value;
|
|
150
133
|
if (typeof value === 'string') {
|
|
151
134
|
const numeric = Number(value);
|
|
@@ -155,30 +138,46 @@ export function normalizeDeviceRebootType(
|
|
|
155
138
|
return DeviceRebootType.Normal;
|
|
156
139
|
}
|
|
157
140
|
|
|
158
|
-
//
|
|
159
|
-
const
|
|
141
|
+
// 与 firmware-pro2 的 proto_target_to_firmware_target 安装白名单保持一致。
|
|
142
|
+
const INSTALLABLE_FIRMWARE_TARGET_IDS = new Set<number>([
|
|
143
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_CRATE,
|
|
144
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER,
|
|
145
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P1,
|
|
146
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P2,
|
|
147
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_COPROCESSOR,
|
|
148
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE01,
|
|
149
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE02,
|
|
150
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE03,
|
|
151
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE04,
|
|
152
|
+
]);
|
|
153
|
+
const FIRMWARE_TARGET_ID_BY_NAME = new Map<string, DeviceFirmwareTargetType>(
|
|
154
|
+
Object.entries(ProtocolV2FirmwareTargetType).flatMap(([key, value]) =>
|
|
155
|
+
INSTALLABLE_FIRMWARE_TARGET_IDS.has(value) ? [[key, value as DeviceFirmwareTargetType]] : []
|
|
156
|
+
)
|
|
157
|
+
);
|
|
160
158
|
|
|
161
159
|
function normalizeTargetId(
|
|
162
|
-
value:
|
|
160
|
+
value: DeviceFirmwareTargetType | string | number | undefined,
|
|
163
161
|
name: string
|
|
164
|
-
):
|
|
162
|
+
): DeviceFirmwareTargetType {
|
|
165
163
|
if (value === undefined || value === null) {
|
|
166
164
|
throw invalidParameter(`Missing required parameter: ${name}`);
|
|
167
165
|
}
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return numeric as DevFirmwareTargetType;
|
|
166
|
+
const named = typeof value === 'string' ? FIRMWARE_TARGET_ID_BY_NAME.get(value) : undefined;
|
|
167
|
+
const numeric = named ?? (typeof value === 'number' ? value : Number(value));
|
|
168
|
+
if (Number.isSafeInteger(numeric) && INSTALLABLE_FIRMWARE_TARGET_IDS.has(numeric)) {
|
|
169
|
+
return numeric as DeviceFirmwareTargetType;
|
|
173
170
|
}
|
|
174
171
|
throw invalidParameter(
|
|
175
|
-
`Parameter [${name}] must be
|
|
176
|
-
...
|
|
172
|
+
`Parameter [${name}] must be an installable firmware target id (one of ${[
|
|
173
|
+
...INSTALLABLE_FIRMWARE_TARGET_IDS,
|
|
177
174
|
].join(', ')}).`
|
|
178
175
|
);
|
|
179
176
|
}
|
|
180
177
|
|
|
181
|
-
export function normalizeFirmwareTargets(
|
|
178
|
+
export function normalizeFirmwareTargets(
|
|
179
|
+
params: DeviceFirmwareUpdateParams
|
|
180
|
+
): DeviceFirmwareTarget[] {
|
|
182
181
|
const targets =
|
|
183
182
|
params.targets ??
|
|
184
183
|
(params.path
|
package/src/constants/index.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
export { safeThrowError } from './errors';
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
Messages as PROTO,
|
|
4
|
+
ResourceType,
|
|
5
|
+
TonSignDataType,
|
|
6
|
+
TonWalletVersion,
|
|
7
|
+
} from '@onekeyfe/hd-transport';
|
|
8
|
+
export type {
|
|
9
|
+
HDNodeType,
|
|
10
|
+
Success as DeviceSuccess,
|
|
11
|
+
} from '@onekeyfe/hd-transport';
|
package/src/core/index.ts
CHANGED
|
@@ -57,16 +57,12 @@ import DeviceConnector from '../device/DeviceConnector';
|
|
|
57
57
|
import RequestQueue from './RequestQueue';
|
|
58
58
|
import { getSynchronize } from '../utils/getSynchronize';
|
|
59
59
|
|
|
60
|
-
import type { ConnectSettings, KnownDevice } from '../types';
|
|
60
|
+
import type { ConnectSettings, Features, KnownDevice } from '../types';
|
|
61
61
|
import type { CoreMessage, IFrameCallMessage, UiPromise, UiPromiseResponse } from '../events';
|
|
62
62
|
import type { DeviceEvents, InitOptions, RunOptions } from '../device/Device';
|
|
63
63
|
import type { SdkTracingContext } from '../utils/tracing';
|
|
64
64
|
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
65
|
-
import type {
|
|
66
|
-
Features,
|
|
67
|
-
LowlevelTransportSharedPlugin,
|
|
68
|
-
OneKeyDeviceInfo,
|
|
69
|
-
} from '@onekeyfe/hd-transport';
|
|
65
|
+
import type { LowlevelTransportSharedPlugin, OneKeyDeviceInfo } from '@onekeyfe/hd-transport';
|
|
70
66
|
import type { BaseMethod } from '../api/BaseMethod';
|
|
71
67
|
|
|
72
68
|
const Log = getLogger(LoggerNames.Core);
|
|
@@ -99,6 +95,7 @@ const parseInitOptions = (method?: BaseMethod): InitOptions => ({
|
|
|
99
95
|
deviceId: method?.payload.deviceId,
|
|
100
96
|
deriveCardano: method && hasDeriveCardano(method),
|
|
101
97
|
connectProtocol: method?.payload.connectProtocol,
|
|
98
|
+
protocolV2DeviceInfoTimeoutMs: method?.payload.protocolV2DeviceInfoTimeoutMs,
|
|
102
99
|
});
|
|
103
100
|
|
|
104
101
|
let _core: Core;
|
|
@@ -226,9 +223,15 @@ const handlePreWarmSignal = async (
|
|
|
226
223
|
message: CoreMessage,
|
|
227
224
|
method: BaseMethod
|
|
228
225
|
): Promise<any> => {
|
|
226
|
+
const createAckResponse = () => {
|
|
227
|
+
completeMethodRequestContext(method);
|
|
228
|
+
method.dispose();
|
|
229
|
+
return createResponseMessage(method.responseID, true, true);
|
|
230
|
+
};
|
|
231
|
+
|
|
229
232
|
// no connectId: can't target a device safely, skip pre-warm (ack only)
|
|
230
233
|
if (!method.connectId) {
|
|
231
|
-
return
|
|
234
|
+
return createAckResponse();
|
|
232
235
|
}
|
|
233
236
|
|
|
234
237
|
const key = method.getPreWarmKey();
|
|
@@ -241,12 +244,12 @@ const handlePreWarmSignal = async (
|
|
|
241
244
|
} catch {
|
|
242
245
|
// pre-warm is best-effort; ignore its failure for the coalesced caller
|
|
243
246
|
}
|
|
244
|
-
return
|
|
247
|
+
return createAckResponse();
|
|
245
248
|
}
|
|
246
249
|
|
|
247
250
|
const doneAt = preWarmDoneAt.get(key);
|
|
248
251
|
if (typeof doneAt === 'number' && Date.now() - doneAt <= method.preWarmTtl) {
|
|
249
|
-
return
|
|
252
|
+
return createAckResponse();
|
|
250
253
|
}
|
|
251
254
|
|
|
252
255
|
const run = onCallDevice(context, message, method);
|
|
@@ -735,6 +738,15 @@ function initDevice(method: BaseMethod) {
|
|
|
735
738
|
|
|
736
739
|
if (method.connectId) {
|
|
737
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
|
+
}
|
|
738
750
|
} else if (allDevices.length === 1) {
|
|
739
751
|
[device] = allDevices;
|
|
740
752
|
} else if (allDevices.length > 1) {
|
|
@@ -1115,7 +1127,7 @@ const checkPassphraseEnableState = (method: BaseMethod, features?: Features) =>
|
|
|
1115
1127
|
|
|
1116
1128
|
const passphraseProtection = method.device
|
|
1117
1129
|
? method.device.getCurrentPassphraseProtection()
|
|
1118
|
-
: features?.
|
|
1130
|
+
: features?.passphraseProtection;
|
|
1119
1131
|
|
|
1120
1132
|
if (passphraseProtection === true) {
|
|
1121
1133
|
const hasNoPassphraseState =
|