@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
|
@@ -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,
|
|
@@ -26,12 +25,13 @@ import type {
|
|
|
26
25
|
GetDeviceInfoParams,
|
|
27
26
|
} from '../types/api/getDeviceInfo';
|
|
28
27
|
import type { Features, OnekeyFeatures } from '../types';
|
|
29
|
-
import type {
|
|
28
|
+
import type { DeviceFirmwareImageInfo, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
|
|
29
|
+
import { isProtocolV2BootloaderDeviceInfo } from '../protocols/protocol-v2/features';
|
|
30
30
|
|
|
31
31
|
type BuildProtocolV1ProfileParams = {
|
|
32
32
|
protocol?: DeviceInfoProtocol;
|
|
33
33
|
features?: Features;
|
|
34
|
-
|
|
34
|
+
protocolV1OneKeyFeatures?: OnekeyFeatures;
|
|
35
35
|
sources?: DeviceInfoSource[];
|
|
36
36
|
scope?: GetDeviceInfoParams['scope'];
|
|
37
37
|
includeRaw?: boolean;
|
|
@@ -42,17 +42,11 @@ type BuildProtocolV2ProfileParams = {
|
|
|
42
42
|
sources?: DeviceInfoSource[];
|
|
43
43
|
scope?: GetDeviceInfoParams['scope'];
|
|
44
44
|
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
45
|
};
|
|
52
46
|
|
|
53
47
|
const isMeaningfulVersion = (version?: string | null) => Boolean(version && version !== '0.0.0');
|
|
54
48
|
|
|
55
|
-
const
|
|
49
|
+
const firstMeaningfulVersion = (...versions: Array<string | null | undefined>) =>
|
|
56
50
|
versions.find(isMeaningfulVersion) ?? null;
|
|
57
51
|
|
|
58
52
|
const versionArrayToString = (version?: Array<number | string | null> | null) => {
|
|
@@ -75,24 +69,25 @@ const bytesToHex = (value: unknown): string | undefined => {
|
|
|
75
69
|
return undefined;
|
|
76
70
|
};
|
|
77
71
|
|
|
78
|
-
const getImageVersion = (image?:
|
|
72
|
+
const getImageVersion = (image?: DeviceFirmwareImageInfo | null) => image?.version ?? null;
|
|
79
73
|
|
|
80
|
-
const getImageBuildId = (image?:
|
|
74
|
+
const getImageBuildId = (image?: DeviceFirmwareImageInfo | null) => image?.build_id ?? undefined;
|
|
81
75
|
|
|
82
|
-
const getImageHash = (image?:
|
|
76
|
+
const getImageHash = (image?: DeviceFirmwareImageInfo | null) => bytesToHex(image?.hash);
|
|
83
77
|
|
|
84
78
|
const shouldIncludeVerify = (scope?: GetDeviceInfoParams['scope']) =>
|
|
85
79
|
scope === 'verify' || scope === 'full';
|
|
86
80
|
|
|
87
81
|
const getDeviceMode = (features?: Features): DeviceInfoStatus['mode'] => {
|
|
88
82
|
if (!features) return 'unknown';
|
|
89
|
-
if (features.
|
|
83
|
+
if (features.bootloaderMode === true) return 'bootloader';
|
|
90
84
|
if (features.initialized === false) return 'notInitialized';
|
|
91
85
|
if (features.initialized === true) return 'normal';
|
|
92
86
|
return 'unknown';
|
|
93
87
|
};
|
|
94
88
|
|
|
95
89
|
const getProtocolV2Mode = (deviceInfo?: ProtocolV2DeviceInfo): DeviceInfoStatus['mode'] => {
|
|
90
|
+
if (isProtocolV2BootloaderDeviceInfo(deviceInfo)) return 'bootloader';
|
|
96
91
|
const initialized = deviceInfo?.status?.init_states;
|
|
97
92
|
if (initialized === false) return 'notInitialized';
|
|
98
93
|
if (initialized === true) return 'normal';
|
|
@@ -101,246 +96,220 @@ const getProtocolV2Mode = (deviceInfo?: ProtocolV2DeviceInfo): DeviceInfoStatus[
|
|
|
101
96
|
|
|
102
97
|
const normalizeV1Versions = (
|
|
103
98
|
features?: Features,
|
|
104
|
-
|
|
99
|
+
protocolV1OneKeyFeatures?: OnekeyFeatures
|
|
105
100
|
): DeviceProfileVersions => ({
|
|
106
|
-
firmware:
|
|
107
|
-
|
|
101
|
+
firmware: firstMeaningfulVersion(
|
|
102
|
+
protocolV1OneKeyFeatures?.onekey_firmware_version,
|
|
108
103
|
versionArrayToString(getDeviceFirmwareVersion(features))
|
|
109
104
|
),
|
|
110
|
-
bootloader:
|
|
111
|
-
|
|
105
|
+
bootloader: firstMeaningfulVersion(
|
|
106
|
+
protocolV1OneKeyFeatures?.onekey_boot_version,
|
|
112
107
|
versionArrayToString(getDeviceBootloaderVersion(features))
|
|
113
108
|
),
|
|
114
|
-
board:
|
|
115
|
-
|
|
109
|
+
board: firstMeaningfulVersion(
|
|
110
|
+
protocolV1OneKeyFeatures?.onekey_board_version,
|
|
116
111
|
versionArrayToString(features ? getDeviceBoardloaderVersion(features) : undefined)
|
|
117
112
|
),
|
|
118
|
-
ble:
|
|
119
|
-
|
|
120
|
-
features?.
|
|
121
|
-
features?.ble_ver,
|
|
113
|
+
ble: firstMeaningfulVersion(
|
|
114
|
+
protocolV1OneKeyFeatures?.onekey_ble_version,
|
|
115
|
+
features?.bleVersion,
|
|
122
116
|
versionArrayToString(features ? getDeviceBLEFirmwareVersion(features) : undefined)
|
|
123
117
|
),
|
|
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
|
|
118
|
+
se01: firstMeaningfulVersion(
|
|
119
|
+
protocolV1OneKeyFeatures?.onekey_se01_version,
|
|
120
|
+
features?.se01Version
|
|
131
121
|
),
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
features?.
|
|
122
|
+
se02: firstMeaningfulVersion(
|
|
123
|
+
protocolV1OneKeyFeatures?.onekey_se02_version,
|
|
124
|
+
features?.se02Version
|
|
135
125
|
),
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
features?.
|
|
126
|
+
se03: firstMeaningfulVersion(
|
|
127
|
+
protocolV1OneKeyFeatures?.onekey_se03_version,
|
|
128
|
+
features?.se03Version
|
|
139
129
|
),
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
features?.
|
|
130
|
+
se04: firstMeaningfulVersion(
|
|
131
|
+
protocolV1OneKeyFeatures?.onekey_se04_version,
|
|
132
|
+
features?.se04Version
|
|
133
|
+
),
|
|
134
|
+
se01Boot: firstMeaningfulVersion(
|
|
135
|
+
protocolV1OneKeyFeatures?.onekey_se01_boot_version,
|
|
136
|
+
features?.se01BootVersion
|
|
137
|
+
),
|
|
138
|
+
se02Boot: firstMeaningfulVersion(
|
|
139
|
+
protocolV1OneKeyFeatures?.onekey_se02_boot_version,
|
|
140
|
+
features?.se02BootVersion
|
|
141
|
+
),
|
|
142
|
+
se03Boot: firstMeaningfulVersion(
|
|
143
|
+
protocolV1OneKeyFeatures?.onekey_se03_boot_version,
|
|
144
|
+
features?.se03BootVersion
|
|
145
|
+
),
|
|
146
|
+
se04Boot: firstMeaningfulVersion(
|
|
147
|
+
protocolV1OneKeyFeatures?.onekey_se04_boot_version,
|
|
148
|
+
features?.se04BootVersion
|
|
143
149
|
),
|
|
144
150
|
});
|
|
145
151
|
|
|
146
|
-
const normalizeV2Versions = (deviceInfo?: ProtocolV2DeviceInfo): DeviceProfileVersions =>
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
152
|
+
const normalizeV2Versions = (deviceInfo?: ProtocolV2DeviceInfo): DeviceProfileVersions => {
|
|
153
|
+
const info = deviceInfo;
|
|
154
|
+
return {
|
|
155
|
+
firmware: firstMeaningfulVersion(getImageVersion(info?.fw?.application)),
|
|
156
|
+
bootloader: firstMeaningfulVersion(getImageVersion(info?.fw?.bootloader)),
|
|
157
|
+
board: firstMeaningfulVersion(
|
|
158
|
+
getImageVersion(info?.fw?.application_data ?? info?.fw?.romloader)
|
|
159
|
+
),
|
|
160
|
+
ble: firstMeaningfulVersion(getImageVersion(info?.coprocessor?.application)),
|
|
161
|
+
se01: firstMeaningfulVersion(getImageVersion(info?.se1?.application)),
|
|
162
|
+
se02: firstMeaningfulVersion(getImageVersion(info?.se2?.application)),
|
|
163
|
+
se03: firstMeaningfulVersion(getImageVersion(info?.se3?.application)),
|
|
164
|
+
se04: firstMeaningfulVersion(getImageVersion(info?.se4?.application)),
|
|
165
|
+
se01Boot: firstMeaningfulVersion(getImageVersion(info?.se1?.bootloader)),
|
|
166
|
+
se02Boot: firstMeaningfulVersion(getImageVersion(info?.se2?.bootloader)),
|
|
167
|
+
se03Boot: firstMeaningfulVersion(getImageVersion(info?.se3?.bootloader)),
|
|
168
|
+
se04Boot: firstMeaningfulVersion(getImageVersion(info?.se4?.bootloader)),
|
|
169
|
+
};
|
|
170
|
+
};
|
|
160
171
|
|
|
161
172
|
// V2 状态由 normalizeV2Status 处理,这里只服务 buildProfileFromProtocolV1 的 V1 路径。
|
|
162
173
|
const normalizeV1Status = (features?: Features): DeviceInfoStatus => ({
|
|
163
174
|
mode: getDeviceMode(features),
|
|
164
175
|
initialized: features?.initialized ?? null,
|
|
165
|
-
bootloaderMode: features?.
|
|
176
|
+
bootloaderMode: features?.bootloaderMode ?? null,
|
|
166
177
|
unlocked: features?.unlocked ?? null,
|
|
167
|
-
passphraseProtection: features?.
|
|
168
|
-
|
|
169
|
-
|
|
178
|
+
passphraseProtection: features?.passphraseProtection ?? null,
|
|
179
|
+
attachToPinEnabled: features?.attachToPinEnabled ?? null,
|
|
180
|
+
unlockedAttachPin: features?.unlockedAttachPin ?? null,
|
|
181
|
+
backupRequired: features?.backupRequired ?? null,
|
|
182
|
+
noBackup: features?.noBackup ?? null,
|
|
170
183
|
language: features?.language ?? null,
|
|
171
|
-
bleEnabled: features?.
|
|
184
|
+
bleEnabled: features?.bleEnabled ?? null,
|
|
172
185
|
});
|
|
173
186
|
|
|
174
|
-
const normalizeV2Status = (deviceInfo?: ProtocolV2DeviceInfo): DeviceInfoStatus =>
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
187
|
+
const normalizeV2Status = (deviceInfo?: ProtocolV2DeviceInfo): DeviceInfoStatus => {
|
|
188
|
+
const status = deviceInfo?.status;
|
|
189
|
+
const bootloaderMode = isProtocolV2BootloaderDeviceInfo(deviceInfo);
|
|
190
|
+
return {
|
|
191
|
+
mode: getProtocolV2Mode(deviceInfo),
|
|
192
|
+
initialized: status?.init_states ?? null,
|
|
193
|
+
bootloaderMode,
|
|
194
|
+
unlocked: status?.unlocked ?? null,
|
|
195
|
+
passphraseProtection: status?.passphrase_enabled ?? null,
|
|
196
|
+
attachToPinEnabled: status?.attach_to_pin_enabled ?? null,
|
|
197
|
+
unlockedAttachPin: status?.unlocked_by_attach_to_pin ?? null,
|
|
198
|
+
backupRequired: status?.backup_required ?? null,
|
|
199
|
+
noBackup: null,
|
|
200
|
+
language: null,
|
|
201
|
+
bleEnabled: null,
|
|
202
|
+
};
|
|
203
|
+
};
|
|
185
204
|
|
|
186
205
|
const normalizeV1Verify = (
|
|
187
206
|
features?: Features,
|
|
188
|
-
|
|
207
|
+
protocolV1OneKeyFeatures?: OnekeyFeatures
|
|
189
208
|
): 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
|
-
|
|
209
|
+
firmwareBuildId:
|
|
210
|
+
protocolV1OneKeyFeatures?.onekey_firmware_build_id ?? features?.verify?.firmwareBuildId,
|
|
211
|
+
firmwareHash: protocolV1OneKeyFeatures?.onekey_firmware_hash ?? features?.verify?.firmwareHash,
|
|
212
|
+
bootloaderBuildId:
|
|
213
|
+
protocolV1OneKeyFeatures?.onekey_boot_build_id ?? features?.verify?.bootloaderBuildId,
|
|
214
|
+
bootloaderHash: protocolV1OneKeyFeatures?.onekey_boot_hash ?? features?.verify?.bootloaderHash,
|
|
215
|
+
boardBuildId: protocolV1OneKeyFeatures?.onekey_board_build_id ?? features?.verify?.boardBuildId,
|
|
216
|
+
boardHash: protocolV1OneKeyFeatures?.onekey_board_hash ?? features?.verify?.boardHash,
|
|
217
|
+
bleBuildId: protocolV1OneKeyFeatures?.onekey_ble_build_id ?? features?.verify?.bleBuildId,
|
|
218
|
+
bleHash: protocolV1OneKeyFeatures?.onekey_ble_hash ?? features?.verify?.bleHash,
|
|
219
|
+
se01BuildId: protocolV1OneKeyFeatures?.onekey_se01_build_id ?? features?.verify?.se01BuildId,
|
|
220
|
+
se01Hash: protocolV1OneKeyFeatures?.onekey_se01_hash ?? features?.verify?.se01Hash,
|
|
221
|
+
se02BuildId: protocolV1OneKeyFeatures?.onekey_se02_build_id ?? features?.verify?.se02BuildId,
|
|
222
|
+
se02Hash: protocolV1OneKeyFeatures?.onekey_se02_hash ?? features?.verify?.se02Hash,
|
|
223
|
+
se03BuildId: protocolV1OneKeyFeatures?.onekey_se03_build_id ?? features?.verify?.se03BuildId,
|
|
224
|
+
se03Hash: protocolV1OneKeyFeatures?.onekey_se03_hash ?? features?.verify?.se03Hash,
|
|
225
|
+
se04BuildId: protocolV1OneKeyFeatures?.onekey_se04_build_id ?? features?.verify?.se04BuildId,
|
|
226
|
+
se04Hash: protocolV1OneKeyFeatures?.onekey_se04_hash ?? features?.verify?.se04Hash,
|
|
227
|
+
se01BootBuildId:
|
|
228
|
+
protocolV1OneKeyFeatures?.onekey_se01_boot_build_id ?? features?.verify?.se01BootBuildId,
|
|
229
|
+
se01BootHash: protocolV1OneKeyFeatures?.onekey_se01_boot_hash ?? features?.verify?.se01BootHash,
|
|
230
|
+
se02BootBuildId:
|
|
231
|
+
protocolV1OneKeyFeatures?.onekey_se02_boot_build_id ?? features?.verify?.se02BootBuildId,
|
|
232
|
+
se02BootHash: protocolV1OneKeyFeatures?.onekey_se02_boot_hash ?? features?.verify?.se02BootHash,
|
|
233
|
+
se03BootBuildId:
|
|
234
|
+
protocolV1OneKeyFeatures?.onekey_se03_boot_build_id ?? features?.verify?.se03BootBuildId,
|
|
235
|
+
se03BootHash: protocolV1OneKeyFeatures?.onekey_se03_boot_hash ?? features?.verify?.se03BootHash,
|
|
236
|
+
se04BootBuildId:
|
|
237
|
+
protocolV1OneKeyFeatures?.onekey_se04_boot_build_id ?? features?.verify?.se04BootBuildId,
|
|
238
|
+
se04BootHash: protocolV1OneKeyFeatures?.onekey_se04_boot_hash ?? features?.verify?.se04BootHash,
|
|
214
239
|
});
|
|
215
240
|
|
|
216
|
-
const normalizeV2Verify = (deviceInfo?: ProtocolV2DeviceInfo): DeviceProfileVerify =>
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
241
|
+
const normalizeV2Verify = (deviceInfo?: ProtocolV2DeviceInfo): DeviceProfileVerify => {
|
|
242
|
+
const info = deviceInfo;
|
|
243
|
+
return {
|
|
244
|
+
firmwareBuildId: getImageBuildId(info?.fw?.application),
|
|
245
|
+
firmwareHash: getImageHash(info?.fw?.application),
|
|
246
|
+
bootloaderBuildId: getImageBuildId(info?.fw?.bootloader),
|
|
247
|
+
bootloaderHash: getImageHash(info?.fw?.bootloader),
|
|
248
|
+
boardBuildId: getImageBuildId(info?.fw?.application_data ?? info?.fw?.romloader),
|
|
249
|
+
boardHash: getImageHash(info?.fw?.application_data ?? info?.fw?.romloader),
|
|
250
|
+
bleBuildId: getImageBuildId(info?.coprocessor?.application),
|
|
251
|
+
bleHash: getImageHash(info?.coprocessor?.application),
|
|
252
|
+
se01BuildId: getImageBuildId(info?.se1?.application),
|
|
253
|
+
se01Hash: getImageHash(info?.se1?.application),
|
|
254
|
+
se02BuildId: getImageBuildId(info?.se2?.application),
|
|
255
|
+
se02Hash: getImageHash(info?.se2?.application),
|
|
256
|
+
se03BuildId: getImageBuildId(info?.se3?.application),
|
|
257
|
+
se03Hash: getImageHash(info?.se3?.application),
|
|
258
|
+
se04BuildId: getImageBuildId(info?.se4?.application),
|
|
259
|
+
se04Hash: getImageHash(info?.se4?.application),
|
|
260
|
+
se01BootBuildId: getImageBuildId(info?.se1?.bootloader),
|
|
261
|
+
se01BootHash: getImageHash(info?.se1?.bootloader),
|
|
262
|
+
se02BootBuildId: getImageBuildId(info?.se2?.bootloader),
|
|
263
|
+
se02BootHash: getImageHash(info?.se2?.bootloader),
|
|
264
|
+
se03BootBuildId: getImageBuildId(info?.se3?.bootloader),
|
|
265
|
+
se03BootHash: getImageHash(info?.se3?.bootloader),
|
|
266
|
+
se04BootBuildId: getImageBuildId(info?.se4?.bootloader),
|
|
267
|
+
se04BootHash: getImageHash(info?.se4?.bootloader),
|
|
268
|
+
};
|
|
269
|
+
};
|
|
242
270
|
|
|
243
271
|
const normalizeRaw = ({
|
|
244
272
|
features,
|
|
245
|
-
|
|
273
|
+
protocolV1OneKeyFeatures,
|
|
246
274
|
protocolV2DeviceInfo,
|
|
247
275
|
}: {
|
|
248
276
|
features?: Features;
|
|
249
|
-
|
|
277
|
+
protocolV1OneKeyFeatures?: OnekeyFeatures;
|
|
250
278
|
protocolV2DeviceInfo?: ProtocolV2DeviceInfo;
|
|
251
279
|
}): DeviceProfileRaw => ({
|
|
252
280
|
...(features ? { features } : {}),
|
|
253
|
-
...(
|
|
281
|
+
...(protocolV1OneKeyFeatures ? { protocolV1OneKeyFeatures } : {}),
|
|
254
282
|
...(protocolV2DeviceInfo ? { protocolV2DeviceInfo } : {}),
|
|
255
283
|
});
|
|
256
284
|
|
|
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
285
|
export function buildProfileFromProtocolV1({
|
|
317
286
|
protocol = 'V1',
|
|
318
287
|
features,
|
|
319
|
-
|
|
288
|
+
protocolV1OneKeyFeatures,
|
|
320
289
|
sources = ['features'],
|
|
321
290
|
scope = 'basic',
|
|
322
291
|
includeRaw = false,
|
|
323
292
|
}: BuildProtocolV1ProfileParams): DeviceProfile {
|
|
324
|
-
const sourceFeatures =
|
|
325
|
-
const verify = normalizeV1Verify(sourceFeatures,
|
|
293
|
+
const sourceFeatures = features;
|
|
294
|
+
const verify = normalizeV1Verify(sourceFeatures, protocolV1OneKeyFeatures);
|
|
326
295
|
|
|
327
296
|
return {
|
|
328
297
|
protocol,
|
|
329
298
|
sources,
|
|
330
299
|
deviceType: getDeviceType(sourceFeatures),
|
|
331
300
|
firmwareType: getFirmwareType(sourceFeatures),
|
|
332
|
-
deviceId: sourceFeatures?.
|
|
301
|
+
deviceId: sourceFeatures?.deviceId || (sourceFeatures ? getDeviceUUID(sourceFeatures) : ''),
|
|
333
302
|
serialNo: sourceFeatures ? getDeviceUUID(sourceFeatures) : '',
|
|
334
303
|
label: getDeviceLabel(sourceFeatures),
|
|
335
304
|
bleName: getDeviceBleName(sourceFeatures),
|
|
336
305
|
status: normalizeV1Status(sourceFeatures),
|
|
337
|
-
versions: normalizeV1Versions(sourceFeatures,
|
|
306
|
+
versions: normalizeV1Versions(sourceFeatures, protocolV1OneKeyFeatures),
|
|
338
307
|
...(shouldIncludeVerify(scope) ? { verify } : {}),
|
|
339
308
|
...(includeRaw
|
|
340
309
|
? {
|
|
341
310
|
raw: normalizeRaw({
|
|
342
311
|
features,
|
|
343
|
-
|
|
312
|
+
protocolV1OneKeyFeatures,
|
|
344
313
|
}),
|
|
345
314
|
}
|
|
346
315
|
: {}),
|
|
@@ -352,12 +321,12 @@ export function buildProfileFromProtocolV2({
|
|
|
352
321
|
sources = ['deviceInfo'],
|
|
353
322
|
scope = 'basic',
|
|
354
323
|
includeRaw = false,
|
|
355
|
-
fallbackSerialNo,
|
|
356
324
|
}: BuildProtocolV2ProfileParams): DeviceProfile {
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
const
|
|
360
|
-
const
|
|
325
|
+
const info = deviceInfo;
|
|
326
|
+
const deviceId = info?.status?.device_id || '';
|
|
327
|
+
const serialNo = deviceInfo?.hw?.serial_no || '';
|
|
328
|
+
const label = null;
|
|
329
|
+
const bleName = info?.coprocessor?.bt_adv_name ?? null;
|
|
361
330
|
const verify = normalizeV2Verify(deviceInfo);
|
|
362
331
|
|
|
363
332
|
return {
|
|
@@ -365,11 +334,7 @@ export function buildProfileFromProtocolV2({
|
|
|
365
334
|
sources,
|
|
366
335
|
deviceType: EDeviceType.Pro2,
|
|
367
336
|
firmwareType: EFirmwareType.Universal,
|
|
368
|
-
|
|
369
|
-
// 这里只能回退 serialNo。注意语义差异:V1 的 device_id 随擦除/换种子轮换,serialNo 永不变化。
|
|
370
|
-
// 固件在 DevStatus 暴露 device_id 后,此处必须改为读取它,否则 wipe 后基于 deviceId 的
|
|
371
|
-
// session 缓存(deviceSessionCache)不会自然失效。
|
|
372
|
-
deviceId: serialNo,
|
|
337
|
+
deviceId,
|
|
373
338
|
serialNo,
|
|
374
339
|
label,
|
|
375
340
|
bleName,
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export { buildProfileFromProtocolV1, buildProfileFromProtocolV2 } from './buildDeviceProfile';
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
buildProtocolV1FeaturesPayload,
|
|
4
|
+
buildProtocolV2FeaturesPayload,
|
|
5
|
+
} from './buildDeviceFeatures';
|
package/src/inject.ts
CHANGED
|
@@ -100,6 +100,7 @@ export const createCoreApi = (
|
|
|
100
100
|
| 'switchTransport'
|
|
101
101
|
> => ({
|
|
102
102
|
getLogs: () => call({ method: 'getLogs' }),
|
|
103
|
+
clearSessionCache: params => call({ ...params, method: 'clearSessionCache' }),
|
|
103
104
|
/**
|
|
104
105
|
* 搜索设备
|
|
105
106
|
*/
|
|
@@ -151,28 +152,24 @@ export const createCoreApi = (
|
|
|
151
152
|
deviceRebootToBootloader: connectId => call({ connectId, method: 'deviceRebootToBootloader' }),
|
|
152
153
|
|
|
153
154
|
// File system & device control API (Protocol V2 only)
|
|
154
|
-
|
|
155
|
+
protocolInfoRequest: (connectId, params) =>
|
|
156
|
+
call({ ...params, connectId, method: 'protocolInfoRequest' }),
|
|
155
157
|
ping: (connectId, params) => call({ ...params, connectId, method: 'ping' }),
|
|
156
158
|
deviceReboot: (connectId, params) => call({ ...params, connectId, method: 'deviceReboot' }),
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
call({ ...params, connectId, method: '
|
|
159
|
+
deviceInfoGet: (connectId, params) => call({ ...params, connectId, method: 'deviceInfoGet' }),
|
|
160
|
+
deviceStatusGet: (connectId, params) => call({ ...params, connectId, method: 'deviceStatusGet' }),
|
|
161
|
+
deviceSessionGet: (connectId, params) =>
|
|
162
|
+
call({ ...params, connectId, method: 'deviceSessionGet' }),
|
|
161
163
|
deviceFirmwareUpdate: (connectId, params) =>
|
|
162
164
|
call({ ...params, connectId, method: 'deviceFirmwareUpdate' }),
|
|
163
165
|
deviceGetFirmwareUpdateStatus: (connectId, params) =>
|
|
164
166
|
call({ ...params, connectId, method: 'deviceGetFirmwareUpdateStatus' }),
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
call({ ...params, connectId, method: 'devGetFirmwareUpdateStatus' }),
|
|
172
|
-
factoryDeviceInfoSettings: (connectId, params) =>
|
|
173
|
-
call({ ...params, connectId, method: 'factoryDeviceInfoSettings' }),
|
|
174
|
-
factoryGetDeviceInfo: connectId => call({ connectId, method: 'factoryGetDeviceInfo' }),
|
|
175
|
-
filesystemFixPermission: connectId => call({ connectId, method: 'filesystemFixPermission' }),
|
|
167
|
+
deviceFactoryInfoSet: (connectId, params) =>
|
|
168
|
+
call({ ...params, connectId, method: 'deviceFactoryInfoSet' }),
|
|
169
|
+
deviceFactoryInfoGet: (connectId, params) =>
|
|
170
|
+
call({ ...params, connectId, method: 'deviceFactoryInfoGet' }),
|
|
171
|
+
filesystemPermissionFix: (connectId, params) =>
|
|
172
|
+
call({ ...params, connectId, method: 'filesystemPermissionFix' }),
|
|
176
173
|
fileRead: (connectId, params) => call({ ...params, connectId, method: 'fileRead' }),
|
|
177
174
|
fileWrite: (connectId, params) => call({ ...params, connectId, method: 'fileWrite' }),
|
|
178
175
|
fileDelete: (connectId, params) => call({ ...params, connectId, method: 'fileDelete' }),
|