@onekeyfe/hd-core 1.2.0-alpha.0 → 1.2.0-alpha.2
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 +56 -178
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +2 -2
- 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/device/DeviceUnlock.d.ts +1 -1
- package/dist/api/firmware/bootloaderHelper.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.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/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +10 -15
- package/dist/device/Device.d.ts.map +1 -1
- 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 +571 -496
- package/dist/index.js +502 -571
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/types/api/getDeviceInfo.d.ts +2 -2
- package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
- package/dist/types/device.d.ts +87 -8
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/capabilitieUtils.d.ts.map +1 -1
- 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/package.json +4 -4
- package/src/api/FirmwareUpdateV2.ts +9 -2
- package/src/api/FirmwareUpdateV3.ts +2 -1
- package/src/api/FirmwareUpdateV4.ts +24 -31
- package/src/api/GetDeviceInfo.ts +6 -13
- package/src/api/GetOnekeyFeatures.ts +3 -14
- package/src/api/GetPassphraseState.ts +2 -2
- package/src/api/firmware/bootloaderHelper.ts +3 -2
- package/src/api/firmware/getBinary.ts +1 -1
- package/src/api/firmware/releaseHelper.ts +3 -3
- package/src/api/firmware/uploadFirmware.ts +5 -2
- package/src/api/tron/TronSignMessage.ts +0 -1
- package/src/api/tron/TronSignTransaction.ts +0 -1
- package/src/core/index.ts +3 -7
- package/src/data-manager/DataManager.ts +4 -4
- package/src/device/Device.ts +74 -240
- package/src/device/DevicePool.ts +3 -3
- package/src/deviceProfile/buildDeviceFeatures.ts +367 -0
- package/src/deviceProfile/buildDeviceProfile.ts +102 -155
- package/src/deviceProfile/index.ts +4 -1
- package/src/protocols/protocol-v2/features.ts +6 -9
- package/src/types/api/getDeviceInfo.ts +2 -2
- package/src/types/device.ts +97 -34
- package/src/utils/capabilitieUtils.ts +1 -2
- package/src/utils/deviceFeaturesUtils.ts +11 -17
- package/src/utils/deviceInfoUtils.ts +11 -29
- package/src/utils/deviceVersionUtils.ts +7 -25
- package/src/utils/findDefectiveBatchDevice.ts +6 -6
- package/dist/deviceProfile/legacyFeaturesView.d.ts +0 -5
- package/dist/deviceProfile/legacyFeaturesView.d.ts.map +0 -1
- package/src/deviceProfile/legacyFeaturesView.ts +0 -123
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
|
-
import { OneKeyDeviceType, OneKeySEState, OneKeySeType } from '@onekeyfe/hd-transport';
|
|
3
2
|
|
|
4
3
|
import {
|
|
5
4
|
getDeviceBLEFirmwareVersion,
|
|
@@ -31,7 +30,7 @@ import type { DevFirmwareImageInfo, ProtocolV2DeviceInfo } from '@onekeyfe/hd-tr
|
|
|
31
30
|
type BuildProtocolV1ProfileParams = {
|
|
32
31
|
protocol?: DeviceInfoProtocol;
|
|
33
32
|
features?: Features;
|
|
34
|
-
|
|
33
|
+
protocolV1OneKeyFeatures?: OnekeyFeatures;
|
|
35
34
|
sources?: DeviceInfoSource[];
|
|
36
35
|
scope?: GetDeviceInfoParams['scope'];
|
|
37
36
|
includeRaw?: boolean;
|
|
@@ -42,17 +41,11 @@ type BuildProtocolV2ProfileParams = {
|
|
|
42
41
|
sources?: DeviceInfoSource[];
|
|
43
42
|
scope?: GetDeviceInfoParams['scope'];
|
|
44
43
|
includeRaw?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* hw.serial_no 为空时的回退身份(通常传 transport 层的 device path)。
|
|
47
|
-
* 早期 Pro2 工程板没有烧录 serial_no,空 serialNo 会导致设备无法进入
|
|
48
|
-
* DevicePool 的 devices 字典,后续 getDevice(connectId) 必然失败。
|
|
49
|
-
*/
|
|
50
|
-
fallbackSerialNo?: string;
|
|
51
44
|
};
|
|
52
45
|
|
|
53
46
|
const isMeaningfulVersion = (version?: string | null) => Boolean(version && version !== '0.0.0');
|
|
54
47
|
|
|
55
|
-
const
|
|
48
|
+
const firstMeaningfulVersion = (...versions: Array<string | null | undefined>) =>
|
|
56
49
|
versions.find(isMeaningfulVersion) ?? null;
|
|
57
50
|
|
|
58
51
|
const versionArrayToString = (version?: Array<number | string | null> | null) => {
|
|
@@ -86,7 +79,7 @@ const shouldIncludeVerify = (scope?: GetDeviceInfoParams['scope']) =>
|
|
|
86
79
|
|
|
87
80
|
const getDeviceMode = (features?: Features): DeviceInfoStatus['mode'] => {
|
|
88
81
|
if (!features) return 'unknown';
|
|
89
|
-
if (features.
|
|
82
|
+
if (features.bootloaderMode === true) return 'bootloader';
|
|
90
83
|
if (features.initialized === false) return 'notInitialized';
|
|
91
84
|
if (features.initialized === true) return 'normal';
|
|
92
85
|
return 'unknown';
|
|
@@ -101,74 +94,85 @@ const getProtocolV2Mode = (deviceInfo?: ProtocolV2DeviceInfo): DeviceInfoStatus[
|
|
|
101
94
|
|
|
102
95
|
const normalizeV1Versions = (
|
|
103
96
|
features?: Features,
|
|
104
|
-
|
|
97
|
+
protocolV1OneKeyFeatures?: OnekeyFeatures
|
|
105
98
|
): DeviceProfileVersions => ({
|
|
106
|
-
firmware:
|
|
107
|
-
|
|
99
|
+
firmware: firstMeaningfulVersion(
|
|
100
|
+
protocolV1OneKeyFeatures?.onekey_firmware_version,
|
|
108
101
|
versionArrayToString(getDeviceFirmwareVersion(features))
|
|
109
102
|
),
|
|
110
|
-
bootloader:
|
|
111
|
-
|
|
103
|
+
bootloader: firstMeaningfulVersion(
|
|
104
|
+
protocolV1OneKeyFeatures?.onekey_boot_version,
|
|
112
105
|
versionArrayToString(getDeviceBootloaderVersion(features))
|
|
113
106
|
),
|
|
114
|
-
board:
|
|
115
|
-
|
|
107
|
+
board: firstMeaningfulVersion(
|
|
108
|
+
protocolV1OneKeyFeatures?.onekey_board_version,
|
|
116
109
|
versionArrayToString(features ? getDeviceBoardloaderVersion(features) : undefined)
|
|
117
110
|
),
|
|
118
|
-
ble:
|
|
119
|
-
|
|
120
|
-
features?.
|
|
121
|
-
features?.ble_ver,
|
|
111
|
+
ble: firstMeaningfulVersion(
|
|
112
|
+
protocolV1OneKeyFeatures?.onekey_ble_version,
|
|
113
|
+
features?.bleVersion,
|
|
122
114
|
versionArrayToString(features ? getDeviceBLEFirmwareVersion(features) : undefined)
|
|
123
115
|
),
|
|
124
|
-
se01:
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
se04: firstVersion(onekeyFeatures?.onekey_se04_version, features?.onekey_se04_version),
|
|
128
|
-
se01Boot: firstVersion(
|
|
129
|
-
onekeyFeatures?.onekey_se01_boot_version,
|
|
130
|
-
features?.onekey_se01_boot_version
|
|
116
|
+
se01: firstMeaningfulVersion(
|
|
117
|
+
protocolV1OneKeyFeatures?.onekey_se01_version,
|
|
118
|
+
features?.se01Version
|
|
131
119
|
),
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
features?.
|
|
120
|
+
se02: firstMeaningfulVersion(
|
|
121
|
+
protocolV1OneKeyFeatures?.onekey_se02_version,
|
|
122
|
+
features?.se02Version
|
|
135
123
|
),
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
features?.
|
|
124
|
+
se03: firstMeaningfulVersion(
|
|
125
|
+
protocolV1OneKeyFeatures?.onekey_se03_version,
|
|
126
|
+
features?.se03Version
|
|
139
127
|
),
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
features?.
|
|
128
|
+
se04: firstMeaningfulVersion(
|
|
129
|
+
protocolV1OneKeyFeatures?.onekey_se04_version,
|
|
130
|
+
features?.se04Version
|
|
131
|
+
),
|
|
132
|
+
se01Boot: firstMeaningfulVersion(
|
|
133
|
+
protocolV1OneKeyFeatures?.onekey_se01_boot_version,
|
|
134
|
+
features?.se01BootVersion
|
|
135
|
+
),
|
|
136
|
+
se02Boot: firstMeaningfulVersion(
|
|
137
|
+
protocolV1OneKeyFeatures?.onekey_se02_boot_version,
|
|
138
|
+
features?.se02BootVersion
|
|
139
|
+
),
|
|
140
|
+
se03Boot: firstMeaningfulVersion(
|
|
141
|
+
protocolV1OneKeyFeatures?.onekey_se03_boot_version,
|
|
142
|
+
features?.se03BootVersion
|
|
143
|
+
),
|
|
144
|
+
se04Boot: firstMeaningfulVersion(
|
|
145
|
+
protocolV1OneKeyFeatures?.onekey_se04_boot_version,
|
|
146
|
+
features?.se04BootVersion
|
|
143
147
|
),
|
|
144
148
|
});
|
|
145
149
|
|
|
146
150
|
const normalizeV2Versions = (deviceInfo?: ProtocolV2DeviceInfo): DeviceProfileVersions => ({
|
|
147
|
-
firmware:
|
|
148
|
-
bootloader:
|
|
149
|
-
board:
|
|
150
|
-
ble:
|
|
151
|
-
se01:
|
|
152
|
-
se02:
|
|
153
|
-
se03:
|
|
154
|
-
se04:
|
|
155
|
-
se01Boot:
|
|
156
|
-
se02Boot:
|
|
157
|
-
se03Boot:
|
|
158
|
-
se04Boot:
|
|
151
|
+
firmware: firstMeaningfulVersion(getImageVersion(deviceInfo?.fw?.app)),
|
|
152
|
+
bootloader: firstMeaningfulVersion(getImageVersion(deviceInfo?.fw?.boot)),
|
|
153
|
+
board: firstMeaningfulVersion(getImageVersion(deviceInfo?.fw?.board)),
|
|
154
|
+
ble: firstMeaningfulVersion(getImageVersion(deviceInfo?.bt?.app)),
|
|
155
|
+
se01: firstMeaningfulVersion(getImageVersion(deviceInfo?.se1?.app)),
|
|
156
|
+
se02: firstMeaningfulVersion(getImageVersion(deviceInfo?.se2?.app)),
|
|
157
|
+
se03: firstMeaningfulVersion(getImageVersion(deviceInfo?.se3?.app)),
|
|
158
|
+
se04: firstMeaningfulVersion(getImageVersion(deviceInfo?.se4?.app)),
|
|
159
|
+
se01Boot: firstMeaningfulVersion(getImageVersion(deviceInfo?.se1?.boot)),
|
|
160
|
+
se02Boot: firstMeaningfulVersion(getImageVersion(deviceInfo?.se2?.boot)),
|
|
161
|
+
se03Boot: firstMeaningfulVersion(getImageVersion(deviceInfo?.se3?.boot)),
|
|
162
|
+
se04Boot: firstMeaningfulVersion(getImageVersion(deviceInfo?.se4?.boot)),
|
|
159
163
|
});
|
|
160
164
|
|
|
161
165
|
// V2 状态由 normalizeV2Status 处理,这里只服务 buildProfileFromProtocolV1 的 V1 路径。
|
|
162
166
|
const normalizeV1Status = (features?: Features): DeviceInfoStatus => ({
|
|
163
167
|
mode: getDeviceMode(features),
|
|
164
168
|
initialized: features?.initialized ?? null,
|
|
165
|
-
bootloaderMode: features?.
|
|
169
|
+
bootloaderMode: features?.bootloaderMode ?? null,
|
|
166
170
|
unlocked: features?.unlocked ?? null,
|
|
167
|
-
passphraseProtection: features?.
|
|
168
|
-
backupRequired: features?.
|
|
169
|
-
noBackup: features?.
|
|
171
|
+
passphraseProtection: features?.passphraseProtection ?? null,
|
|
172
|
+
backupRequired: features?.backupRequired ?? null,
|
|
173
|
+
noBackup: features?.noBackup ?? null,
|
|
170
174
|
language: features?.language ?? null,
|
|
171
|
-
bleEnabled: features?.
|
|
175
|
+
bleEnabled: features?.bleEnabled ?? null,
|
|
172
176
|
});
|
|
173
177
|
|
|
174
178
|
const normalizeV2Status = (deviceInfo?: ProtocolV2DeviceInfo): DeviceInfoStatus => ({
|
|
@@ -185,32 +189,38 @@ const normalizeV2Status = (deviceInfo?: ProtocolV2DeviceInfo): DeviceInfoStatus
|
|
|
185
189
|
|
|
186
190
|
const normalizeV1Verify = (
|
|
187
191
|
features?: Features,
|
|
188
|
-
|
|
192
|
+
protocolV1OneKeyFeatures?: OnekeyFeatures
|
|
189
193
|
): DeviceProfileVerify => ({
|
|
190
|
-
firmwareBuildId:
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
194
|
+
firmwareBuildId:
|
|
195
|
+
protocolV1OneKeyFeatures?.onekey_firmware_build_id ?? features?.verify?.firmwareBuildId,
|
|
196
|
+
firmwareHash: protocolV1OneKeyFeatures?.onekey_firmware_hash ?? features?.verify?.firmwareHash,
|
|
197
|
+
bootloaderBuildId:
|
|
198
|
+
protocolV1OneKeyFeatures?.onekey_boot_build_id ?? features?.verify?.bootloaderBuildId,
|
|
199
|
+
bootloaderHash: protocolV1OneKeyFeatures?.onekey_boot_hash ?? features?.verify?.bootloaderHash,
|
|
200
|
+
boardBuildId: protocolV1OneKeyFeatures?.onekey_board_build_id ?? features?.verify?.boardBuildId,
|
|
201
|
+
boardHash: protocolV1OneKeyFeatures?.onekey_board_hash ?? features?.verify?.boardHash,
|
|
202
|
+
bleBuildId: protocolV1OneKeyFeatures?.onekey_ble_build_id ?? features?.verify?.bleBuildId,
|
|
203
|
+
bleHash: protocolV1OneKeyFeatures?.onekey_ble_hash ?? features?.verify?.bleHash,
|
|
204
|
+
se01BuildId: protocolV1OneKeyFeatures?.onekey_se01_build_id ?? features?.verify?.se01BuildId,
|
|
205
|
+
se01Hash: protocolV1OneKeyFeatures?.onekey_se01_hash ?? features?.verify?.se01Hash,
|
|
206
|
+
se02BuildId: protocolV1OneKeyFeatures?.onekey_se02_build_id ?? features?.verify?.se02BuildId,
|
|
207
|
+
se02Hash: protocolV1OneKeyFeatures?.onekey_se02_hash ?? features?.verify?.se02Hash,
|
|
208
|
+
se03BuildId: protocolV1OneKeyFeatures?.onekey_se03_build_id ?? features?.verify?.se03BuildId,
|
|
209
|
+
se03Hash: protocolV1OneKeyFeatures?.onekey_se03_hash ?? features?.verify?.se03Hash,
|
|
210
|
+
se04BuildId: protocolV1OneKeyFeatures?.onekey_se04_build_id ?? features?.verify?.se04BuildId,
|
|
211
|
+
se04Hash: protocolV1OneKeyFeatures?.onekey_se04_hash ?? features?.verify?.se04Hash,
|
|
212
|
+
se01BootBuildId:
|
|
213
|
+
protocolV1OneKeyFeatures?.onekey_se01_boot_build_id ?? features?.verify?.se01BootBuildId,
|
|
214
|
+
se01BootHash: protocolV1OneKeyFeatures?.onekey_se01_boot_hash ?? features?.verify?.se01BootHash,
|
|
215
|
+
se02BootBuildId:
|
|
216
|
+
protocolV1OneKeyFeatures?.onekey_se02_boot_build_id ?? features?.verify?.se02BootBuildId,
|
|
217
|
+
se02BootHash: protocolV1OneKeyFeatures?.onekey_se02_boot_hash ?? features?.verify?.se02BootHash,
|
|
218
|
+
se03BootBuildId:
|
|
219
|
+
protocolV1OneKeyFeatures?.onekey_se03_boot_build_id ?? features?.verify?.se03BootBuildId,
|
|
220
|
+
se03BootHash: protocolV1OneKeyFeatures?.onekey_se03_boot_hash ?? features?.verify?.se03BootHash,
|
|
221
|
+
se04BootBuildId:
|
|
222
|
+
protocolV1OneKeyFeatures?.onekey_se04_boot_build_id ?? features?.verify?.se04BootBuildId,
|
|
223
|
+
se04BootHash: protocolV1OneKeyFeatures?.onekey_se04_boot_hash ?? features?.verify?.se04BootHash,
|
|
214
224
|
});
|
|
215
225
|
|
|
216
226
|
const normalizeV2Verify = (deviceInfo?: ProtocolV2DeviceInfo): DeviceProfileVerify => ({
|
|
@@ -242,105 +252,46 @@ const normalizeV2Verify = (deviceInfo?: ProtocolV2DeviceInfo): DeviceProfileVeri
|
|
|
242
252
|
|
|
243
253
|
const normalizeRaw = ({
|
|
244
254
|
features,
|
|
245
|
-
|
|
255
|
+
protocolV1OneKeyFeatures,
|
|
246
256
|
protocolV2DeviceInfo,
|
|
247
257
|
}: {
|
|
248
258
|
features?: Features;
|
|
249
|
-
|
|
259
|
+
protocolV1OneKeyFeatures?: OnekeyFeatures;
|
|
250
260
|
protocolV2DeviceInfo?: ProtocolV2DeviceInfo;
|
|
251
261
|
}): DeviceProfileRaw => ({
|
|
252
262
|
...(features ? { features } : {}),
|
|
253
|
-
...(
|
|
263
|
+
...(protocolV1OneKeyFeatures ? { protocolV1OneKeyFeatures } : {}),
|
|
254
264
|
...(protocolV2DeviceInfo ? { protocolV2DeviceInfo } : {}),
|
|
255
265
|
});
|
|
256
266
|
|
|
257
|
-
/**
|
|
258
|
-
* V1 profile 构建用的 features 合并视图。
|
|
259
|
-
*
|
|
260
|
-
* OnekeyFeatures 与 Features 的同名字段(onekey_device_type / onekey_se_type /
|
|
261
|
-
* onekey_se0X_state)wire 同源:传输层解码会把 proto 枚举输出为名称字符串,与
|
|
262
|
-
* Features 侧的 string 声明一致,仅生成类型分别声明为枚举/字符串,这里按
|
|
263
|
-
* Features 的声明显式归一,避免整体 as Features 断言。
|
|
264
|
-
*/
|
|
265
|
-
const mergeV1Features = (
|
|
266
|
-
features?: Features,
|
|
267
|
-
onekeyFeatures?: OnekeyFeatures
|
|
268
|
-
): Features | undefined => {
|
|
269
|
-
if (!features && !onekeyFeatures) return undefined;
|
|
270
|
-
|
|
271
|
-
const {
|
|
272
|
-
onekey_device_type: onekeyDeviceType,
|
|
273
|
-
onekey_se_type: onekeySeType,
|
|
274
|
-
onekey_se01_state: onekeySe01State,
|
|
275
|
-
onekey_se02_state: onekeySe02State,
|
|
276
|
-
onekey_se03_state: onekeySe03State,
|
|
277
|
-
onekey_se04_state: onekeySe04State,
|
|
278
|
-
...restOnekeyFeatures
|
|
279
|
-
} = onekeyFeatures ?? {};
|
|
280
|
-
|
|
281
|
-
const toEnumName = (
|
|
282
|
-
enumObject: Record<string | number, string | number>,
|
|
283
|
-
value: number | string | null | undefined
|
|
284
|
-
): string | null | undefined => {
|
|
285
|
-
if (value == null || typeof value === 'string') return value;
|
|
286
|
-
const label = enumObject[value];
|
|
287
|
-
return typeof label === 'string' ? label : String(value);
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
return {
|
|
291
|
-
// 仅 onekeyFeatures 的场景没有完整 Features 底座(与历史 as Features 行为一致,
|
|
292
|
-
// 该路径目前没有调用方触达:两处调用都至少携带 features)。
|
|
293
|
-
...((features ?? {}) as Features),
|
|
294
|
-
...restOnekeyFeatures,
|
|
295
|
-
...(onekeyDeviceType !== undefined
|
|
296
|
-
? { onekey_device_type: toEnumName(OneKeyDeviceType, onekeyDeviceType) }
|
|
297
|
-
: {}),
|
|
298
|
-
...(onekeySeType !== undefined
|
|
299
|
-
? { onekey_se_type: toEnumName(OneKeySeType, onekeySeType) }
|
|
300
|
-
: {}),
|
|
301
|
-
...(onekeySe01State !== undefined
|
|
302
|
-
? { onekey_se01_state: toEnumName(OneKeySEState, onekeySe01State) }
|
|
303
|
-
: {}),
|
|
304
|
-
...(onekeySe02State !== undefined
|
|
305
|
-
? { onekey_se02_state: toEnumName(OneKeySEState, onekeySe02State) }
|
|
306
|
-
: {}),
|
|
307
|
-
...(onekeySe03State !== undefined
|
|
308
|
-
? { onekey_se03_state: toEnumName(OneKeySEState, onekeySe03State) }
|
|
309
|
-
: {}),
|
|
310
|
-
...(onekeySe04State !== undefined
|
|
311
|
-
? { onekey_se04_state: toEnumName(OneKeySEState, onekeySe04State) }
|
|
312
|
-
: {}),
|
|
313
|
-
};
|
|
314
|
-
};
|
|
315
|
-
|
|
316
267
|
export function buildProfileFromProtocolV1({
|
|
317
268
|
protocol = 'V1',
|
|
318
269
|
features,
|
|
319
|
-
|
|
270
|
+
protocolV1OneKeyFeatures,
|
|
320
271
|
sources = ['features'],
|
|
321
272
|
scope = 'basic',
|
|
322
273
|
includeRaw = false,
|
|
323
274
|
}: BuildProtocolV1ProfileParams): DeviceProfile {
|
|
324
|
-
const sourceFeatures =
|
|
325
|
-
const verify = normalizeV1Verify(sourceFeatures,
|
|
275
|
+
const sourceFeatures = features;
|
|
276
|
+
const verify = normalizeV1Verify(sourceFeatures, protocolV1OneKeyFeatures);
|
|
326
277
|
|
|
327
278
|
return {
|
|
328
279
|
protocol,
|
|
329
280
|
sources,
|
|
330
281
|
deviceType: getDeviceType(sourceFeatures),
|
|
331
282
|
firmwareType: getFirmwareType(sourceFeatures),
|
|
332
|
-
deviceId: sourceFeatures?.
|
|
283
|
+
deviceId: sourceFeatures?.deviceId || (sourceFeatures ? getDeviceUUID(sourceFeatures) : ''),
|
|
333
284
|
serialNo: sourceFeatures ? getDeviceUUID(sourceFeatures) : '',
|
|
334
285
|
label: getDeviceLabel(sourceFeatures),
|
|
335
286
|
bleName: getDeviceBleName(sourceFeatures),
|
|
336
287
|
status: normalizeV1Status(sourceFeatures),
|
|
337
|
-
versions: normalizeV1Versions(sourceFeatures,
|
|
288
|
+
versions: normalizeV1Versions(sourceFeatures, protocolV1OneKeyFeatures),
|
|
338
289
|
...(shouldIncludeVerify(scope) ? { verify } : {}),
|
|
339
290
|
...(includeRaw
|
|
340
291
|
? {
|
|
341
292
|
raw: normalizeRaw({
|
|
342
293
|
features,
|
|
343
|
-
|
|
294
|
+
protocolV1OneKeyFeatures,
|
|
344
295
|
}),
|
|
345
296
|
}
|
|
346
297
|
: {}),
|
|
@@ -352,10 +303,8 @@ export function buildProfileFromProtocolV2({
|
|
|
352
303
|
sources = ['deviceInfo'],
|
|
353
304
|
scope = 'basic',
|
|
354
305
|
includeRaw = false,
|
|
355
|
-
fallbackSerialNo,
|
|
356
306
|
}: BuildProtocolV2ProfileParams): DeviceProfile {
|
|
357
|
-
|
|
358
|
-
const serialNo = deviceInfo?.hw?.serial_no || fallbackSerialNo || '';
|
|
307
|
+
const serialNo = deviceInfo?.hw?.serial_no || '';
|
|
359
308
|
const label = deviceInfo?.status?.label ?? null;
|
|
360
309
|
const bleName = deviceInfo?.bt?.adv_name ?? null;
|
|
361
310
|
const verify = normalizeV2Verify(deviceInfo);
|
|
@@ -365,11 +314,9 @@ export function buildProfileFromProtocolV2({
|
|
|
365
314
|
sources,
|
|
366
315
|
deviceType: EDeviceType.Pro2,
|
|
367
316
|
firmwareType: EFirmwareType.Universal,
|
|
368
|
-
// Protocol V2 的 DevGetDeviceInfo 没有 device_id
|
|
369
|
-
//
|
|
370
|
-
|
|
371
|
-
// session 缓存(deviceSessionCache)不会自然失效。
|
|
372
|
-
deviceId: serialNo,
|
|
317
|
+
// Protocol V2 的 DevGetDeviceInfo 没有 device_id 字段;serialNo 与 deviceId
|
|
318
|
+
// 不是等价语义,这里保持空值,避免把稳定硬件序列号误当会随 wipe 轮换的身份。
|
|
319
|
+
deviceId: '',
|
|
373
320
|
serialNo,
|
|
374
321
|
label,
|
|
375
322
|
bleName,
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export { buildProfileFromProtocolV1, buildProfileFromProtocolV2 } from './buildDeviceProfile';
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
buildProtocolV1FeaturesPayload,
|
|
4
|
+
buildProtocolV2FeaturesPayload,
|
|
5
|
+
} from './buildDeviceFeatures';
|
|
@@ -27,7 +27,7 @@ const normalizeEnumValue = <T extends Record<string | number, string | number>>(
|
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* DevSEInfo.state → 可读标签。SDK 内唯一的 SE 状态映射实现,
|
|
30
|
-
*
|
|
30
|
+
* DeviceProfile 与标准 Features 构建都从这里取。
|
|
31
31
|
*/
|
|
32
32
|
export const getProtocolV2SeState = (se?: DevSEInfo): ProtocolV2SeStateLabel | null => {
|
|
33
33
|
const label = normalizeEnumValue(DevSEState, se?.state);
|
|
@@ -44,8 +44,8 @@ export const getProtocolV2SeState = (se?: DevSEInfo): ProtocolV2SeStateLabel | n
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
* DevSEInfo.type → 可读标签(如 'THD89')。
|
|
48
|
-
*
|
|
47
|
+
* DevSEInfo.type → 可读标签(如 'THD89')。DeviceProfile / Features
|
|
48
|
+
* 的 SE 类型归一化从这里取。
|
|
49
49
|
*/
|
|
50
50
|
export const getProtocolV2SeType = (se?: DevSEInfo): string | null =>
|
|
51
51
|
normalizeEnumValue(DevSeType, se?.type);
|
|
@@ -67,9 +67,7 @@ export const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
|
|
|
67
67
|
* 轻量状态刷新请求(每次 run 前使用)。
|
|
68
68
|
*
|
|
69
69
|
* status 提供 init_states / label / passphrase_protection 等会在设备端变化的字段;
|
|
70
|
-
* hw / bt 提供 serialNo / bleName
|
|
71
|
-
* 覆盖语义,缺少 hw/bt 会把已有 profile 的身份字段清空。不含 fw/SE targets,
|
|
72
|
-
* 单帧请求开销很小。
|
|
70
|
+
* hw / bt 提供 serialNo / bleName 等身份字段;不含 fw/SE targets,单帧请求开销很小。
|
|
73
71
|
*/
|
|
74
72
|
export const PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST = {
|
|
75
73
|
targets: {
|
|
@@ -125,8 +123,7 @@ export const PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS = 10 * 1000;
|
|
|
125
123
|
/**
|
|
126
124
|
* 临时开关(默认开启):当前 Pro2 测试固件 / 早期工程板尚未实现 DevGetDeviceInfo,
|
|
127
125
|
* 真实调用只会超时失败。开启时跳过 wire 调用,直接返回 mock DeviceInfo;
|
|
128
|
-
*
|
|
129
|
-
* fallbackSerialNo(transport path)兜底。
|
|
126
|
+
* DevGetDeviceInfo 尚未返回的字段保持为空,不再用 transport path 兜底成设备身份。
|
|
130
127
|
*
|
|
131
128
|
* 固件实现 DevGetDeviceInfo 后:把默认值改回 false(或直接删除开关与 mock)。
|
|
132
129
|
* 注意:开启期间 FirmwareUpdateV4 的“升级完成版本比对”拿到的也是 mock 版本,
|
|
@@ -144,7 +141,7 @@ export const isProtocolV2DeviceInfoMockEnabled = () => protocolV2DeviceInfoMockE
|
|
|
144
141
|
export const buildMockProtocolV2DeviceInfo = (): ProtocolV2DeviceInfo => ({
|
|
145
142
|
protocol_version: 2,
|
|
146
143
|
hw: {
|
|
147
|
-
//
|
|
144
|
+
// 留空:协议未上报时 SDK 不再用 transport path 伪造身份字段
|
|
148
145
|
serial_no: '',
|
|
149
146
|
},
|
|
150
147
|
fw: {
|
|
@@ -6,7 +6,7 @@ import type { ProtocolType, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport'
|
|
|
6
6
|
// 协议类型单源:从 hd-transport 的 ProtocolType 派生,只额外允许 'unknown'。
|
|
7
7
|
export type DeviceInfoProtocol = ProtocolType | 'unknown';
|
|
8
8
|
|
|
9
|
-
export type DeviceInfoSource = 'features' | '
|
|
9
|
+
export type DeviceInfoSource = 'features' | 'protocolV1OneKeyFeatures' | 'deviceInfo';
|
|
10
10
|
|
|
11
11
|
export type DeviceInfoScope = 'basic' | 'versions' | 'verify' | 'full';
|
|
12
12
|
|
|
@@ -74,7 +74,7 @@ export type DeviceProfileVerify = {
|
|
|
74
74
|
|
|
75
75
|
export type DeviceProfileRaw = {
|
|
76
76
|
features?: Features;
|
|
77
|
-
|
|
77
|
+
protocolV1OneKeyFeatures?: OnekeyFeatures;
|
|
78
78
|
protocolV2DeviceInfo?: ProtocolV2DeviceInfo;
|
|
79
79
|
};
|
|
80
80
|
|
package/src/types/device.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { EDeviceType } from '@onekeyfe/hd-shared';
|
|
1
|
+
import { EDeviceType, type EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import type { IVersionArray } from './settings';
|
|
4
4
|
import type { PROTO } from '../constants';
|
|
5
|
-
import type { OneKeyDeviceCommType } from '@onekeyfe/hd-transport';
|
|
6
|
-
import type { DeviceProfile } from './api/getDeviceInfo';
|
|
5
|
+
import type { OneKeyDeviceCommType, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
|
|
7
6
|
|
|
8
7
|
export type DeviceStatus = 'available' | 'occupied' | 'used';
|
|
9
8
|
|
|
@@ -34,8 +33,7 @@ export type KnownDevice = {
|
|
|
34
33
|
name: string;
|
|
35
34
|
error?: typeof undefined;
|
|
36
35
|
mode: EOneKeyDeviceMode;
|
|
37
|
-
|
|
38
|
-
features?: PROTO.Features;
|
|
36
|
+
features?: Features;
|
|
39
37
|
sessionId?: string | null;
|
|
40
38
|
unavailableCapabilities: UnavailableCapabilities;
|
|
41
39
|
bleFirmwareVersion: IVersionArray | null;
|
|
@@ -88,35 +86,100 @@ export type SearchDevice = {
|
|
|
88
86
|
|
|
89
87
|
export type Device = KnownDevice;
|
|
90
88
|
|
|
91
|
-
type
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
89
|
+
export type DeviceFeaturesProtocol = 'V1' | 'V2' | 'unknown';
|
|
90
|
+
|
|
91
|
+
export type DeviceFeaturesMode =
|
|
92
|
+
| 'normal'
|
|
93
|
+
| 'bootloader'
|
|
94
|
+
| 'notInitialized'
|
|
95
|
+
| 'backupMode'
|
|
96
|
+
| 'unknown';
|
|
97
|
+
|
|
98
|
+
export type DeviceFeaturesVerify = {
|
|
99
|
+
firmwareBuildId?: string;
|
|
100
|
+
firmwareHash?: string;
|
|
101
|
+
bootloaderBuildId?: string;
|
|
102
|
+
bootloaderHash?: string;
|
|
103
|
+
boardBuildId?: string;
|
|
104
|
+
boardHash?: string;
|
|
105
|
+
bleBuildId?: string;
|
|
106
|
+
bleHash?: string;
|
|
107
|
+
se01BuildId?: string;
|
|
108
|
+
se01Hash?: string;
|
|
109
|
+
se02BuildId?: string;
|
|
110
|
+
se02Hash?: string;
|
|
111
|
+
se03BuildId?: string;
|
|
112
|
+
se03Hash?: string;
|
|
113
|
+
se04BuildId?: string;
|
|
114
|
+
se04Hash?: string;
|
|
115
|
+
se01BootBuildId?: string;
|
|
116
|
+
se01BootHash?: string;
|
|
117
|
+
se02BootBuildId?: string;
|
|
118
|
+
se02BootHash?: string;
|
|
119
|
+
se03BootBuildId?: string;
|
|
120
|
+
se03BootHash?: string;
|
|
121
|
+
se04BootBuildId?: string;
|
|
122
|
+
se04BootHash?: string;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export type DeviceFeaturesRaw = {
|
|
126
|
+
protocolV1Features?: PROTO.Features;
|
|
127
|
+
protocolV1OneKeyFeatures?: OnekeyFeatures;
|
|
128
|
+
protocolV2DeviceInfo?: ProtocolV2DeviceInfo;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export type Features = {
|
|
132
|
+
protocol: DeviceFeaturesProtocol;
|
|
133
|
+
protocolVersion?: number | null;
|
|
134
|
+
deviceType: IDeviceType;
|
|
135
|
+
firmwareType: EFirmwareType;
|
|
136
|
+
model: string | null;
|
|
137
|
+
vendor: string | null;
|
|
138
|
+
deviceId: string | null;
|
|
139
|
+
serialNo: string;
|
|
140
|
+
label: string | null;
|
|
141
|
+
bleName: string | null;
|
|
142
|
+
capabilities: Array<number | string>;
|
|
143
|
+
mode: DeviceFeaturesMode;
|
|
144
|
+
initialized: boolean | null;
|
|
145
|
+
bootloaderMode: boolean | null;
|
|
146
|
+
unlocked: boolean | null;
|
|
147
|
+
firmwarePresent: boolean | null;
|
|
148
|
+
passphraseProtection: boolean | null;
|
|
149
|
+
pinProtection: boolean | null;
|
|
150
|
+
backupRequired: boolean | null;
|
|
151
|
+
noBackup: boolean | null;
|
|
152
|
+
unfinishedBackup: boolean | null;
|
|
153
|
+
recoveryMode: boolean | null;
|
|
154
|
+
language: string | null;
|
|
155
|
+
bleEnabled: boolean | null;
|
|
156
|
+
sdCardPresent: boolean | null;
|
|
157
|
+
sdProtection: boolean | null;
|
|
158
|
+
wipeCodeProtection: boolean | null;
|
|
159
|
+
passphraseAlwaysOnDevice: boolean | null;
|
|
160
|
+
safetyChecks: string | null;
|
|
161
|
+
autoLockDelayMs: number | null;
|
|
162
|
+
displayRotation: number | null;
|
|
163
|
+
experimentalFeatures: boolean | null;
|
|
164
|
+
firmwareVersion: string | null;
|
|
165
|
+
bootloaderVersion: string | null;
|
|
166
|
+
boardVersion: string | null;
|
|
167
|
+
bleVersion: string | null;
|
|
168
|
+
se01Version?: string | null;
|
|
169
|
+
se02Version?: string | null;
|
|
170
|
+
se03Version?: string | null;
|
|
171
|
+
se04Version?: string | null;
|
|
172
|
+
se01BootVersion?: string | null;
|
|
173
|
+
se02BootVersion?: string | null;
|
|
174
|
+
se03BootVersion?: string | null;
|
|
175
|
+
se04BootVersion?: string | null;
|
|
176
|
+
seVersion?: string | null;
|
|
177
|
+
verify?: DeviceFeaturesVerify;
|
|
178
|
+
sessionId: string | null;
|
|
179
|
+
passphraseState?: string;
|
|
180
|
+
unlockedAttachPin?: boolean;
|
|
181
|
+
raw?: DeviceFeaturesRaw;
|
|
182
|
+
};
|
|
120
183
|
|
|
121
184
|
export type OnekeyFeatures = PROTO.OnekeyFeatures;
|
|
122
185
|
|
|
@@ -2,8 +2,7 @@ import type { Enum_Capability } from '@onekeyfe/hd-transport';
|
|
|
2
2
|
import type { Features } from '../types/device';
|
|
3
3
|
|
|
4
4
|
export const existCapability = (features?: Features, capability?: Enum_Capability) =>
|
|
5
|
-
|
|
6
|
-
features?.capabilities?.includes(capability);
|
|
5
|
+
capability !== undefined && features?.capabilities?.includes(capability);
|
|
7
6
|
|
|
8
7
|
export const requireCapability = (features: Features, capability: Enum_Capability) => {
|
|
9
8
|
if (!existCapability(features, capability)) {
|