@onekeyfe/hd-core 1.2.0-alpha.0 → 1.2.0-alpha.1
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 +147 -264
- 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/GetPassphraseState.d.ts +4 -4
- 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/protocol-v2/helpers.d.ts +2 -3
- package/dist/api/protocol-v2/helpers.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/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +11 -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 +579 -502
- package/dist/index.js +881 -931
- package/dist/protocols/protocol-v2/features.d.ts +2 -2
- 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/api/getPassphraseState.d.ts +4 -4
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +3 -3
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +87 -8
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/settings.d.ts +1 -0
- package/dist/types/settings.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/dist/utils/patch.d.ts.map +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 +4 -4
- 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/protocol-v2/DeviceReboot.ts +3 -3
- package/src/api/protocol-v2/helpers.ts +1 -26
- package/src/constants/index.ts +10 -1
- package/src/core/index.ts +5 -7
- package/src/data/messages/messages-protocol-v2.json +329 -323
- package/src/data-manager/DataManager.ts +4 -4
- package/src/data-manager/connectSettings.ts +6 -0
- package/src/device/Device.ts +86 -241
- package/src/device/DevicePool.ts +9 -9
- package/src/deviceProfile/buildDeviceFeatures.ts +368 -0
- package/src/deviceProfile/buildDeviceProfile.ts +101 -155
- package/src/deviceProfile/index.ts +4 -1
- package/src/protocols/protocol-v2/features.ts +14 -16
- package/src/types/api/getDeviceInfo.ts +2 -2
- package/src/types/api/getPassphraseState.ts +4 -4
- package/src/types/api/protocolV2.ts +2 -3
- package/src/types/device.ts +97 -34
- package/src/types/settings.ts +5 -0
- 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,9 @@ 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 ||
|
|
307
|
+
const deviceId = deviceInfo?.hw?.device_id || '';
|
|
308
|
+
const serialNo = deviceInfo?.hw?.serial_no || '';
|
|
359
309
|
const label = deviceInfo?.status?.label ?? null;
|
|
360
310
|
const bleName = deviceInfo?.bt?.adv_name ?? null;
|
|
361
311
|
const verify = normalizeV2Verify(deviceInfo);
|
|
@@ -365,11 +315,7 @@ export function buildProfileFromProtocolV2({
|
|
|
365
315
|
sources,
|
|
366
316
|
deviceType: EDeviceType.Pro2,
|
|
367
317
|
firmwareType: EFirmwareType.Universal,
|
|
368
|
-
|
|
369
|
-
// 这里只能回退 serialNo。注意语义差异:V1 的 device_id 随擦除/换种子轮换,serialNo 永不变化。
|
|
370
|
-
// 固件在 DevStatus 暴露 device_id 后,此处必须改为读取它,否则 wipe 后基于 deviceId 的
|
|
371
|
-
// session 缓存(deviceSessionCache)不会自然失效。
|
|
372
|
-
deviceId: serialNo,
|
|
318
|
+
deviceId,
|
|
373
319
|
serialNo,
|
|
374
320
|
label,
|
|
375
321
|
bleName,
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export { buildProfileFromProtocolV1, buildProfileFromProtocolV2 } from './buildDeviceProfile';
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
buildProtocolV1FeaturesPayload,
|
|
4
|
+
buildProtocolV2FeaturesPayload,
|
|
5
|
+
} from './buildDeviceFeatures';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DevSEState, DevSeType } from '@onekeyfe/hd-transport';
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { DevGetDeviceInfo, DevSEInfo, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
|
|
4
4
|
import type { DeviceCommands } from '../../device/DeviceCommands';
|
|
5
5
|
|
|
6
6
|
// 单源类型:直接使用 hd-transport 生成的 ProtocolV2DeviceInfo / DevSEInfo /
|
|
@@ -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: {
|
|
@@ -123,16 +121,16 @@ export const PROTOCOL_V2_DEVICE_INFO_REQUEST = PROTOCOL_V2_FULL_DEVICE_INFO_REQU
|
|
|
123
121
|
export const PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS = 10 * 1000;
|
|
124
122
|
|
|
125
123
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
124
|
+
* 临时开关(默认关闭):当前正式链路直接调用 DevGetDeviceInfo。
|
|
125
|
+
* 仅当 Pro2 测试固件 / 早期工程板尚未实现 DevGetDeviceInfo 时,才显式开启 mock。
|
|
126
|
+
* 开启时跳过 wire 调用,直接返回 mock DeviceInfo;
|
|
127
|
+
* DevGetDeviceInfo 尚未返回的字段保持为空,不再用 transport path 兜底成设备身份。
|
|
130
128
|
*
|
|
131
|
-
* 固件实现 DevGetDeviceInfo
|
|
129
|
+
* 固件实现 DevGetDeviceInfo 稳定后:删除开关与 mock。
|
|
132
130
|
* 注意:开启期间 FirmwareUpdateV4 的“升级完成版本比对”拿到的也是 mock 版本,
|
|
133
131
|
* 不能作为升级成功的依据。
|
|
134
132
|
*/
|
|
135
|
-
let protocolV2DeviceInfoMockEnabled =
|
|
133
|
+
let protocolV2DeviceInfoMockEnabled = false;
|
|
136
134
|
|
|
137
135
|
export const setProtocolV2DeviceInfoMock = (enabled: boolean) => {
|
|
138
136
|
protocolV2DeviceInfoMockEnabled = enabled;
|
|
@@ -144,7 +142,7 @@ export const isProtocolV2DeviceInfoMockEnabled = () => protocolV2DeviceInfoMockE
|
|
|
144
142
|
export const buildMockProtocolV2DeviceInfo = (): ProtocolV2DeviceInfo => ({
|
|
145
143
|
protocol_version: 2,
|
|
146
144
|
hw: {
|
|
147
|
-
//
|
|
145
|
+
// 留空:协议未上报时 SDK 不再用 transport path 伪造身份字段
|
|
148
146
|
serial_no: '',
|
|
149
147
|
},
|
|
150
148
|
fw: {
|
|
@@ -166,9 +164,9 @@ export async function requestProtocolV2DeviceInfo({
|
|
|
166
164
|
}: {
|
|
167
165
|
commands: DeviceCommands;
|
|
168
166
|
timeoutMs?: number;
|
|
169
|
-
request?:
|
|
167
|
+
request?: DevGetDeviceInfo;
|
|
170
168
|
}): Promise<ProtocolV2DeviceInfo> {
|
|
171
|
-
if (
|
|
169
|
+
if (isProtocolV2DeviceInfoMockEnabled()) {
|
|
172
170
|
return buildMockProtocolV2DeviceInfo();
|
|
173
171
|
}
|
|
174
172
|
const { message } = await commands.typedCall('DevGetDeviceInfo', 'DeviceInfo', request, {
|
|
@@ -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
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { CommonParams, Response } from '../params';
|
|
2
2
|
|
|
3
3
|
export type GetPassphraseStatePayload = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
passphraseState?: string;
|
|
5
|
+
sessionId?: string;
|
|
6
|
+
unlockedAttachPin?: boolean;
|
|
7
|
+
passphraseProtection?: boolean | null;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export type GetPassphraseStateParams = CommonParams & {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { CommonParams, Response } from '../params';
|
|
2
2
|
import type {
|
|
3
|
-
DeviceFirmwareUpdateStatus,
|
|
4
3
|
DevFirmwareUpdateStatus,
|
|
5
4
|
FactoryDeviceInfo,
|
|
6
5
|
OnboardingStatus,
|
|
@@ -96,12 +95,12 @@ export declare function deviceGetOnboardingStatus(
|
|
|
96
95
|
export declare function deviceFirmwareUpdate(
|
|
97
96
|
connectId: string,
|
|
98
97
|
params: CommonParams & DeviceFirmwareUpdateParams
|
|
99
|
-
): Response<Success | DevFirmwareUpdateStatus
|
|
98
|
+
): Response<Success | DevFirmwareUpdateStatus>;
|
|
100
99
|
|
|
101
100
|
export declare function deviceGetFirmwareUpdateStatus(
|
|
102
101
|
connectId: string,
|
|
103
102
|
params?: CommonParams
|
|
104
|
-
): Response<DevFirmwareUpdateStatus
|
|
103
|
+
): Response<DevFirmwareUpdateStatus>;
|
|
105
104
|
|
|
106
105
|
export declare function devReboot(
|
|
107
106
|
connectId: string,
|