@onekeyfe/hd-core 1.2.0-alpha.19 → 1.2.0-alpha.20
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__/AllNetworkGetAddressBase.tracing.test.ts +75 -0
- package/__tests__/DeviceCommands.test.ts +143 -7
- package/__tests__/RequestQueue.test.ts +106 -0
- package/__tests__/UploadPortfolio.test.ts +46 -0
- package/__tests__/core-dispose.test.ts +34 -0
- package/__tests__/core-error-output.test.ts +39 -0
- package/__tests__/device-lifecycle-events.test.ts +117 -0
- package/__tests__/device-pool-state.test.ts +20 -1
- package/__tests__/device-settings.test.ts +184 -6
- package/__tests__/device-state-events.test.ts +1 -2
- package/__tests__/device-state-mapper.test.ts +33 -26
- package/__tests__/device-state-store.test.ts +1 -34
- package/__tests__/device-utils.test.ts +106 -0
- package/__tests__/device-wallet-session-store.test.ts +65 -29
- package/__tests__/deviceSettings.test.ts +21 -12
- package/__tests__/evmLedgerLegacySafety.test.ts +2 -2
- package/__tests__/evmSignTypedData.test.ts +80 -0
- package/__tests__/filesystemValidation.test.ts +53 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +402 -0
- package/__tests__/get-device-state.test.ts +77 -41
- package/__tests__/logBlockEvent.test.ts +24 -11
- package/__tests__/networkUtils.test.ts +386 -0
- package/__tests__/open-wallet-session-error-response.test.ts +43 -0
- package/__tests__/open-wallet-session.test.ts +559 -0
- package/__tests__/protocol-v2.test.ts +756 -452
- package/__tests__/public-device-state-api.test.ts +113 -13
- package/__tests__/public-pro2-api-boundary.test.ts +91 -0
- package/__tests__/search-devices.test.ts +43 -0
- package/dist/api/BaseMethod.d.ts +3 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
- package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
- package/dist/api/ClearSessionCache.d.ts.map +1 -1
- package/dist/api/DirList.d.ts.map +1 -1
- package/dist/api/FileRead.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +2 -2
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +3 -2
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts +14 -0
- package/dist/api/OpenWalletSession.d.ts.map +1 -0
- package/dist/api/PathInfo.d.ts.map +1 -1
- package/dist/api/PromptWebDeviceAccess.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts +3 -0
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
- package/dist/api/device/DeviceFullyUploadResource.d.ts +1 -2
- package/dist/api/device/DeviceFullyUploadResource.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +7 -3
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/helpers/filesystemValidation.d.ts +3 -0
- package/dist/api/helpers/filesystemValidation.d.ts.map +1 -1
- package/dist/api/helpers/paramsValidator.d.ts +1 -0
- package/dist/api/helpers/paramsValidator.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +7 -11
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +1 -1
- package/dist/api/utils.d.ts.map +1 -1
- package/dist/core/RequestQueue.d.ts +17 -1
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +6 -5
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +5 -5
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts +1 -0
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/device/DeviceStateMapper.d.ts +2 -2
- package/dist/device/DeviceStateMapper.d.ts.map +1 -1
- package/dist/device/DeviceStateProjector.d.ts +1 -2
- package/dist/device/DeviceStateProjector.d.ts.map +1 -1
- package/dist/device/DeviceStateStore.d.ts +1 -3
- package/dist/device/DeviceStateStore.d.ts.map +1 -1
- package/dist/device/DeviceWalletSessionStore.d.ts +6 -1
- package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -1
- package/dist/device/cloneDeviceState.d.ts +2 -0
- package/dist/device/cloneDeviceState.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts +3 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/index.d.ts +608 -75
- package/dist/index.js +2287 -1706
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/deviceSession.d.ts +7 -0
- package/dist/protocols/protocol-v2/deviceSession.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/features.d.ts +11 -4
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +2 -2
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts +16 -0
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +8 -3
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +1 -2
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceSettings.d.ts +1 -0
- package/dist/types/api/deviceSettings.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +1 -1
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/getFeatures.d.ts.map +1 -1
- package/dist/types/api/getOnekeyFeatures.d.ts.map +1 -1
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +13 -15
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +41 -0
- package/dist/types/api/openWalletSession.d.ts.map +1 -0
- package/dist/types/api/protocolV2.d.ts +6 -11
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +2 -9
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/assets.d.ts +2 -1
- package/dist/utils/assets.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts +13 -0
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -0
- package/dist/utils/deviceFeaturesUtils.d.ts +11 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts +9 -8
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts +2 -0
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/deviceVersionUtils.d.ts +6 -5
- package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/networkUtils.d.ts +9 -1
- package/dist/utils/networkUtils.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +17 -10
- package/src/api/CheckBootloaderRelease.ts +1 -2
- package/src/api/CheckFirmwareRelease.ts +1 -2
- package/src/api/ClearSessionCache.ts +0 -4
- package/src/api/DirList.ts +5 -3
- package/src/api/DirMake.ts +3 -3
- package/src/api/DirRemove.ts +3 -3
- package/src/api/FileDelete.ts +3 -3
- package/src/api/FileRead.ts +9 -6
- package/src/api/FileWrite.ts +3 -3
- package/src/api/FirmwareUpdate.ts +4 -4
- package/src/api/FirmwareUpdateV2.ts +133 -45
- package/src/api/FirmwareUpdateV3.ts +3 -5
- package/src/api/FirmwareUpdateV4.ts +192 -154
- package/src/api/GetPassphraseState.ts +10 -16
- package/src/api/OpenWalletSession.ts +221 -0
- package/src/api/PathInfo.ts +5 -3
- package/src/api/PromptWebDeviceAccess.ts +2 -3
- package/src/api/SearchDevices.ts +6 -2
- package/src/api/UploadPortfolio.ts +12 -3
- package/src/api/alephium/AlephiumSignTransaction.ts +2 -2
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +4 -8
- package/src/api/benfen/BenfenGetAddress.ts +1 -1
- package/src/api/btc/BTCGetPublicKey.ts +1 -1
- package/src/api/device/DeviceChangePin.ts +1 -0
- package/src/api/device/DeviceFullyUploadResource.ts +4 -5
- package/src/api/device/DeviceSettings.ts +93 -0
- package/src/api/device/DeviceUpdateBootloader.ts +1 -2
- package/src/api/device/DeviceWipe.ts +1 -0
- package/src/api/evm/EVMSignTypedData.ts +3 -5
- package/src/api/evm/legacyV1/getAddress.ts +2 -2
- package/src/api/evm/legacyV1/getPublicKey.ts +2 -2
- package/src/api/evm/legacyV1/signMessage.ts +2 -2
- package/src/api/evm/legacyV1/signTypedData.ts +2 -2
- package/src/api/evm/legacyV1/signTypedHash.ts +2 -2
- package/src/api/evm/legacyV1/verifyMessage.ts +2 -2
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +3 -3
- package/src/api/firmware/getBinary.ts +8 -3
- package/src/api/helpers/batchGetPublickeys.ts +2 -2
- package/src/api/helpers/filesystemValidation.ts +61 -0
- package/src/api/helpers/paramsValidator.ts +1 -1
- package/src/api/helpers/protocolV2FileWrite.ts +3 -2
- package/src/api/index.ts +9 -12
- package/src/api/nervos/NervosSignTransaction.ts +2 -2
- package/src/api/nexa/NexaSignTransaction.ts +1 -1
- package/src/api/protocol-v2/DeviceFactoryInfoGet.ts +1 -1
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +1 -1
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +4 -4
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +6 -5
- package/src/api/protocol-v2/DeviceInfoGet.ts +4 -4
- package/src/api/protocol-v2/DeviceReboot.ts +1 -1
- package/src/api/protocol-v2/DeviceSettingsPageShow.ts +11 -8
- package/src/api/protocol-v2/DeviceSettingsSet.ts +4 -11
- package/src/api/protocol-v2/FilesystemFormat.ts +1 -1
- package/src/api/protocol-v2/FilesystemPermissionFix.ts +1 -1
- package/src/api/protocol-v2/Ping.ts +1 -1
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +1 -1
- package/src/api/utils.ts +1 -3
- package/src/core/RequestQueue.ts +107 -6
- package/src/core/index.ts +91 -46
- package/src/data/messages/messages-protocol-v2.json +25 -79
- package/src/data-manager/DataManager.ts +6 -6
- package/src/device/Device.ts +186 -102
- package/src/device/DeviceCommands.ts +51 -21
- package/src/device/DeviceFeaturesState.ts +4 -4
- package/src/device/DevicePool.ts +17 -3
- package/src/device/DeviceStateMapper.ts +13 -29
- package/src/device/DeviceStateProjector.ts +11 -8
- package/src/device/DeviceStateStore.ts +11 -52
- package/src/device/DeviceWalletSessionStore.ts +31 -4
- package/src/device/cloneDeviceState.ts +39 -0
- package/src/device/deviceIdentity.ts +2 -2
- package/src/deviceProfile/buildDeviceFeatures.ts +29 -88
- package/src/events/logBlockEvent.ts +8 -1
- package/src/inject.ts +14 -24
- package/src/protocols/protocol-v2/deviceSession.ts +24 -0
- package/src/protocols/protocol-v2/features.ts +37 -49
- package/src/protocols/protocol-v2/firmware.ts +1 -1
- package/src/protocols/protocol-v2/index.ts +2 -3
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +61 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +4 -3
- package/src/protocols/protocol-v2/walletSession.ts +57 -146
- package/src/types/api/checkAllFirmwareRelease.ts +1 -2
- package/src/types/api/deviceSettings.ts +1 -0
- package/src/types/api/deviceUnlock.ts +1 -1
- package/src/types/api/firmwareUpdate.ts +5 -5
- package/src/types/api/getDeviceState.ts +1 -1
- package/src/types/api/getFeatures.ts +3 -0
- package/src/types/api/getOnekeyFeatures.ts +3 -0
- package/src/types/api/getPassphraseState.ts +6 -0
- package/src/types/api/index.ts +16 -23
- package/src/types/api/openWalletSession.ts +64 -0
- package/src/types/api/protocolV2.ts +36 -18
- package/src/types/device.ts +20 -14
- package/src/types/params.ts +1 -1
- package/src/types/settings.ts +8 -8
- package/src/utils/assets.ts +4 -1
- package/src/utils/deviceFeaturesCompat.ts +173 -0
- package/src/utils/deviceFeaturesUtils.ts +9 -8
- package/src/utils/deviceInfoUtils.ts +26 -64
- package/src/utils/deviceSettings.ts +18 -11
- package/src/utils/deviceVersionUtils.ts +25 -44
- package/src/utils/findDefectiveBatchDevice.ts +3 -3
- package/src/utils/index.ts +2 -5
- package/src/utils/networkUtils.ts +270 -14
- package/src/utils/pro2Wallpaper.ts +11 -13
- package/src/utils/tracing.ts +2 -2
- package/dist/api/internal.d.ts +0 -4
- package/dist/api/internal.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts +0 -28
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts.map +0 -1
- package/src/api/internal.ts +0 -9
- package/src/api/protocol-v2/DeviceSessionOpen.ts +0 -100
package/src/types/device.ts
CHANGED
|
@@ -27,6 +27,12 @@ export type UnavailableCapabilities = { [key: string]: UnavailableCapability };
|
|
|
27
27
|
|
|
28
28
|
export type KnownDevice = {
|
|
29
29
|
connectId: string | null;
|
|
30
|
+
/**
|
|
31
|
+
* Stable physical-device identity. Current SDK responses always include this
|
|
32
|
+
* value; it remains optional in the type during the uuid compatibility window.
|
|
33
|
+
*/
|
|
34
|
+
serialNo?: string;
|
|
35
|
+
/** @deprecated Use serialNo instead. */
|
|
30
36
|
uuid: string;
|
|
31
37
|
deviceId: string | null;
|
|
32
38
|
deviceType: IDeviceType | null;
|
|
@@ -35,14 +41,11 @@ export type KnownDevice = {
|
|
|
35
41
|
label: string;
|
|
36
42
|
bleName: string | null;
|
|
37
43
|
name: string;
|
|
38
|
-
/** 用户可见名称:优先设备标签;name 继续表示连接/发现名称。 */
|
|
39
|
-
displayName?: string;
|
|
40
44
|
error?: typeof undefined;
|
|
41
45
|
mode: EOneKeyDeviceMode;
|
|
42
46
|
features?: Features;
|
|
43
|
-
/** SDK
|
|
47
|
+
/** Unified SDK device-state snapshot; features remains a legacy projection. */
|
|
44
48
|
state?: DeviceState;
|
|
45
|
-
sessionId?: string | null;
|
|
46
49
|
unavailableCapabilities: UnavailableCapabilities;
|
|
47
50
|
bleFirmwareVersion: IVersionArray | null;
|
|
48
51
|
firmwareVersion: IVersionArray | null;
|
|
@@ -55,11 +58,21 @@ export type KnownDevice = {
|
|
|
55
58
|
|
|
56
59
|
export type SearchDevice = {
|
|
57
60
|
connectId: string | null;
|
|
61
|
+
/**
|
|
62
|
+
* Available after device initialization. BLE discovery does not connect to the
|
|
63
|
+
* device, so it returns null until a later initialized device response. Current
|
|
64
|
+
* SDK responses always include the field; it remains optional in the type during
|
|
65
|
+
* the uuid compatibility window.
|
|
66
|
+
*/
|
|
67
|
+
serialNo?: string | null;
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated Ambiguous legacy identifier. Use serialNo for hardware identity
|
|
70
|
+
* and connectId for transport routing.
|
|
71
|
+
*/
|
|
58
72
|
uuid: string;
|
|
59
73
|
deviceId: string | null;
|
|
60
74
|
deviceType: IDeviceType;
|
|
61
75
|
name: string;
|
|
62
|
-
displayName?: string;
|
|
63
76
|
commType: OneKeyDeviceCommType;
|
|
64
77
|
};
|
|
65
78
|
|
|
@@ -170,7 +183,6 @@ export type DeviceStateIdentity = {
|
|
|
170
183
|
serialNo: string;
|
|
171
184
|
label: string | null;
|
|
172
185
|
bleName: string | null;
|
|
173
|
-
displayName: string;
|
|
174
186
|
};
|
|
175
187
|
|
|
176
188
|
export type DeviceStateStatus = {
|
|
@@ -217,7 +229,7 @@ export type DeviceStateVersions = {
|
|
|
217
229
|
bootloader: string | null;
|
|
218
230
|
board: string | null;
|
|
219
231
|
ble: string | null;
|
|
220
|
-
/**
|
|
232
|
+
/** @deprecated Kept for legacy consumers; new code should read se01. */
|
|
221
233
|
se?: string | null;
|
|
222
234
|
se01?: string | null;
|
|
223
235
|
se02?: string | null;
|
|
@@ -229,17 +241,12 @@ export type DeviceStateVersions = {
|
|
|
229
241
|
se04Boot?: string | null;
|
|
230
242
|
};
|
|
231
243
|
|
|
232
|
-
export type DeviceStateSession = {
|
|
233
|
-
sessionId: string | null;
|
|
234
|
-
passphraseState?: string;
|
|
235
|
-
};
|
|
236
|
-
|
|
237
244
|
export type DeviceState = {
|
|
238
245
|
schemaVersion: 1;
|
|
239
246
|
revision: number;
|
|
240
247
|
updatedAt: number;
|
|
241
248
|
protocol: DeviceStateProtocol;
|
|
242
|
-
/**
|
|
249
|
+
/** Device-message protocol version, independent of the SDK V1/V2 protocol family. */
|
|
243
250
|
protocolVersion: number | null;
|
|
244
251
|
identity: DeviceStateIdentity;
|
|
245
252
|
status: DeviceStateStatus;
|
|
@@ -258,7 +265,6 @@ export type DeviceStatePatch = {
|
|
|
258
265
|
versions?: Partial<DeviceStateVersions>;
|
|
259
266
|
capabilities?: Array<number | string>;
|
|
260
267
|
verification?: DeviceFeaturesVerify;
|
|
261
|
-
session?: Partial<DeviceStateSession> | null;
|
|
262
268
|
raw?: DeviceFeaturesRawPatch;
|
|
263
269
|
};
|
|
264
270
|
|
package/src/types/params.ts
CHANGED
package/src/types/settings.ts
CHANGED
|
@@ -58,19 +58,19 @@ export type IProtocolV2FirmwareComponent = {
|
|
|
58
58
|
version?: IVersionArray;
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
/** Pro2 RESC bundle okpkg
|
|
61
|
+
/** Pro2 RESC bundle okpkg descriptor for incremental FileWrite synchronization. */
|
|
62
62
|
export type IProtocolV2ResourceBundle = {
|
|
63
|
-
/**
|
|
63
|
+
/** Bundle name, such as images, animation, translations, or fonts_roobert. */
|
|
64
64
|
name: string;
|
|
65
|
-
/**
|
|
65
|
+
/** Download URL. */
|
|
66
66
|
url: string;
|
|
67
|
-
/**
|
|
67
|
+
/** Device target path, such as vol0:/bundles/images/images.okpkg. */
|
|
68
68
|
devicePath: string;
|
|
69
|
-
/** okpkg
|
|
69
|
+
/** okpkg payload_version used to skip matching content after FileRead. */
|
|
70
70
|
version?: IVersionArray;
|
|
71
|
-
/** okpkg
|
|
71
|
+
/** okpkg payload_hash used for SHA3-512 comparison after FileRead. */
|
|
72
72
|
payloadHash?: string;
|
|
73
|
-
/** okpkg
|
|
73
|
+
/** okpkg header_hash used for SHA3-512 comparison after FileRead. */
|
|
74
74
|
headerHash?: string;
|
|
75
75
|
};
|
|
76
76
|
|
|
@@ -95,7 +95,7 @@ export type IFirmwareReleaseInfo = {
|
|
|
95
95
|
upgradeType?: 'payload-package-set' | string;
|
|
96
96
|
components?: Record<string, IProtocolV2FirmwareComponent>;
|
|
97
97
|
installOrder?: string[];
|
|
98
|
-
/** Pro2 RESC
|
|
98
|
+
/** Pro2 RESC bundles for incremental direct FileWrite synchronization. */
|
|
99
99
|
resourceBundles?: IProtocolV2ResourceBundle[];
|
|
100
100
|
bootloaderChangelog?: {
|
|
101
101
|
[k in ILocale]: string;
|
package/src/utils/assets.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { httpRequest as browserHttpRequest } from './networkUtils';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import type { HttpRequestOptions } from './networkUtils';
|
|
4
|
+
|
|
5
|
+
export const httpRequest = (url: string, type: string, options?: HttpRequestOptions): any =>
|
|
6
|
+
browserHttpRequest(url, type, options);
|
|
4
7
|
|
|
5
8
|
export const getTimeStamp = () => new Date().getTime();
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
|
+
import { Enum_Capability } from '@onekeyfe/hd-transport';
|
|
3
|
+
|
|
4
|
+
import type { PROTO } from '../constants';
|
|
5
|
+
import type { Features, IDeviceType } from '../types';
|
|
6
|
+
|
|
7
|
+
export type DeviceFeaturesInput = Features | PROTO.Features;
|
|
8
|
+
|
|
9
|
+
type CompatibleDeviceFeatures = Partial<Features> &
|
|
10
|
+
Partial<PROTO.Features> & {
|
|
11
|
+
onekey_serial?: string;
|
|
12
|
+
onekey_version?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const asCompatibleFeatures = (features: DeviceFeaturesInput): CompatibleDeviceFeatures =>
|
|
16
|
+
features as CompatibleDeviceFeatures;
|
|
17
|
+
|
|
18
|
+
const firstNonEmptyString = (...values: Array<string | null | undefined>) =>
|
|
19
|
+
values.find(value => typeof value === 'string' && value.length > 0);
|
|
20
|
+
|
|
21
|
+
const firstMeaningfulVersion = (...versions: Array<string | null | undefined>) =>
|
|
22
|
+
versions.find(version => Boolean(version && version !== '0.0.0')) ?? null;
|
|
23
|
+
|
|
24
|
+
const versionFromParts = (major?: number | null, minor?: number | null, patch?: number | null) =>
|
|
25
|
+
[major, minor, patch].map(part => Number(part) || 0).join('.');
|
|
26
|
+
|
|
27
|
+
export const resolveDeviceSerialNo = (features?: DeviceFeaturesInput): string => {
|
|
28
|
+
if (!features) return '';
|
|
29
|
+
const compatible = asCompatibleFeatures(features);
|
|
30
|
+
return (
|
|
31
|
+
firstNonEmptyString(
|
|
32
|
+
compatible.serialNo,
|
|
33
|
+
compatible.onekey_serial_no,
|
|
34
|
+
compatible.onekey_serial,
|
|
35
|
+
compatible.serial_no
|
|
36
|
+
) ?? ''
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const resolveDeviceType = (features?: DeviceFeaturesInput): IDeviceType => {
|
|
41
|
+
if (!features || typeof features !== 'object') {
|
|
42
|
+
return EDeviceType.Unknown;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const compatible = asCompatibleFeatures(features);
|
|
46
|
+
if (compatible.deviceType && compatible.deviceType !== EDeviceType.Unknown) {
|
|
47
|
+
return compatible.deviceType;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
switch (compatible.onekey_device_type?.toString().toUpperCase()) {
|
|
51
|
+
case 'CLASSIC':
|
|
52
|
+
return EDeviceType.Classic;
|
|
53
|
+
case 'CLASSIC1S':
|
|
54
|
+
return EDeviceType.Classic1s;
|
|
55
|
+
case 'MINI':
|
|
56
|
+
return EDeviceType.Mini;
|
|
57
|
+
case 'TOUCH':
|
|
58
|
+
return EDeviceType.Touch;
|
|
59
|
+
case 'PRO':
|
|
60
|
+
return EDeviceType.Pro;
|
|
61
|
+
case 'PRO2':
|
|
62
|
+
return EDeviceType.Pro2;
|
|
63
|
+
case 'PURE':
|
|
64
|
+
return EDeviceType.ClassicPure;
|
|
65
|
+
default:
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (compatible.model?.toString().toLowerCase() === EDeviceType.Pro2) {
|
|
70
|
+
return EDeviceType.Pro2;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const serialNo = resolveDeviceSerialNo(features);
|
|
74
|
+
const prefix = serialNo.slice(0, 2).toLowerCase();
|
|
75
|
+
if (prefix === 'bi' || prefix === 'cl') return EDeviceType.Classic;
|
|
76
|
+
if (prefix === 'cp') return EDeviceType.ClassicPure;
|
|
77
|
+
if (prefix === 'mi') return EDeviceType.Mini;
|
|
78
|
+
if (prefix === 'tc') return EDeviceType.Touch;
|
|
79
|
+
if (prefix === 'pr') return EDeviceType.Pro;
|
|
80
|
+
if (prefix === 'p2') return EDeviceType.Pro2;
|
|
81
|
+
|
|
82
|
+
const bootloaderMode = compatible.bootloaderMode ?? compatible.bootloader_mode;
|
|
83
|
+
if (!serialNo && bootloaderMode === true && compatible.model === '1') {
|
|
84
|
+
return EDeviceType.Classic;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return compatible.deviceType ?? EDeviceType.Unknown;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const resolveDeviceFirmwareType = (features?: DeviceFeaturesInput): EFirmwareType => {
|
|
91
|
+
if (!features) {
|
|
92
|
+
return EFirmwareType.Universal;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const compatible = asCompatibleFeatures(features);
|
|
96
|
+
if (compatible.firmwareType) {
|
|
97
|
+
return compatible.firmwareType;
|
|
98
|
+
}
|
|
99
|
+
if (compatible.fw_vendor === 'OneKey Bitcoin-only') {
|
|
100
|
+
return EFirmwareType.BitcoinOnly;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const capabilities = compatible.capabilities as Array<number | string> | null | undefined;
|
|
104
|
+
const supportsBitcoinLike = capabilities?.some(
|
|
105
|
+
capability =>
|
|
106
|
+
capability === Enum_Capability.Capability_Bitcoin_like ||
|
|
107
|
+
capability === 'Capability_Bitcoin_like'
|
|
108
|
+
);
|
|
109
|
+
return capabilities?.length && !supportsBitcoinLike
|
|
110
|
+
? EFirmwareType.BitcoinOnly
|
|
111
|
+
: EFirmwareType.Universal;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const resolveDeviceBleName = (features?: DeviceFeaturesInput): string | null => {
|
|
115
|
+
if (!features) return null;
|
|
116
|
+
const compatible = asCompatibleFeatures(features);
|
|
117
|
+
return (
|
|
118
|
+
firstNonEmptyString(compatible.bleName, compatible.onekey_ble_name, compatible.ble_name) ?? null
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export const resolveDeviceFirmwareVersion = (features?: DeviceFeaturesInput): string | null => {
|
|
123
|
+
if (!features) return null;
|
|
124
|
+
const compatible = asCompatibleFeatures(features);
|
|
125
|
+
return firstMeaningfulVersion(
|
|
126
|
+
compatible.firmwareVersion,
|
|
127
|
+
compatible.onekey_firmware_version,
|
|
128
|
+
compatible.onekey_version,
|
|
129
|
+
versionFromParts(compatible.major_version, compatible.minor_version, compatible.patch_version)
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const resolveDeviceBootloaderVersion = (features?: DeviceFeaturesInput): string | null => {
|
|
134
|
+
if (!features) return null;
|
|
135
|
+
const compatible = asCompatibleFeatures(features);
|
|
136
|
+
const bootloaderMode = compatible.bootloaderMode ?? compatible.bootloader_mode;
|
|
137
|
+
return firstMeaningfulVersion(
|
|
138
|
+
compatible.bootloaderVersion,
|
|
139
|
+
compatible.onekey_boot_version,
|
|
140
|
+
compatible.bootloader_version,
|
|
141
|
+
compatible.onekey_bootloader_version,
|
|
142
|
+
bootloaderMode
|
|
143
|
+
? versionFromParts(
|
|
144
|
+
compatible.major_version,
|
|
145
|
+
compatible.minor_version,
|
|
146
|
+
compatible.patch_version
|
|
147
|
+
)
|
|
148
|
+
: null
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export const resolveDeviceBoardVersion = (features?: DeviceFeaturesInput): string | null => {
|
|
153
|
+
if (!features) return null;
|
|
154
|
+
const compatible = asCompatibleFeatures(features);
|
|
155
|
+
return firstMeaningfulVersion(
|
|
156
|
+
compatible.boardVersion,
|
|
157
|
+
compatible.onekey_board_version,
|
|
158
|
+
compatible.boardloader_version,
|
|
159
|
+
compatible.onekey_romloader_version,
|
|
160
|
+
compatible.romloader_version
|
|
161
|
+
);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const resolveDeviceBleFirmwareVersion = (features?: DeviceFeaturesInput): string | null => {
|
|
165
|
+
if (!features) return null;
|
|
166
|
+
const compatible = asCompatibleFeatures(features);
|
|
167
|
+
return firstMeaningfulVersion(
|
|
168
|
+
compatible.bleVersion,
|
|
169
|
+
compatible.onekey_ble_version,
|
|
170
|
+
compatible.ble_ver,
|
|
171
|
+
compatible.onekey_coprocessor_version
|
|
172
|
+
);
|
|
173
|
+
};
|
|
@@ -30,11 +30,12 @@ export const getSupportProtocolV1MessageSchema = (
|
|
|
30
30
|
const currentDeviceVersion = getDeviceFirmwareVersion(features).join('.');
|
|
31
31
|
const deviceType = getDeviceType(features);
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
// In bootloader mode the major/minor/patch fields carry the bootloader version, not the
|
|
34
|
+
// firmware version; normalizing them would mis-route to the legacy schema (e.g. 2.x < 3.3.0).
|
|
35
|
+
// The legacy getDeviceFirmwareVersion returned 0.0.0 here and landed on v1CurrentSchema, so
|
|
36
|
+
// force v1CurrentSchema for every bootloader device, including in-place upgrades on
|
|
37
|
+
// Classic1s/Touch/Pro where firmware is still present.
|
|
38
|
+
if (features.bootloaderMode === true) {
|
|
38
39
|
return {
|
|
39
40
|
messages: DataManager.messages.v1CurrentSchema,
|
|
40
41
|
protocolV1MessageSchema: 'v1CurrentSchema',
|
|
@@ -66,7 +67,7 @@ export const getSupportProtocolV1MessageSchema = (
|
|
|
66
67
|
};
|
|
67
68
|
};
|
|
68
69
|
|
|
69
|
-
export const supportInputPinOnSoftware = (features
|
|
70
|
+
export const supportInputPinOnSoftware = (features?: Features): SupportFeatureType => {
|
|
70
71
|
if (!features) return { support: false };
|
|
71
72
|
|
|
72
73
|
const deviceType = getDeviceType(features);
|
|
@@ -170,7 +171,7 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
170
171
|
};
|
|
171
172
|
};
|
|
172
173
|
|
|
173
|
-
//
|
|
174
|
+
// Applies to Protocol V1 Pro only; Pro2 has an independent version line.
|
|
174
175
|
const supportProSeriesAttachPinPassphrase = (deviceType: IDeviceType, firmwareVersion: string) =>
|
|
175
176
|
deviceType === EDeviceType.Pro && semver.gte(firmwareVersion, '4.15.0');
|
|
176
177
|
|
|
@@ -188,7 +189,7 @@ export const getPassphraseState = async (
|
|
|
188
189
|
}> => {
|
|
189
190
|
const { features, commands } = device;
|
|
190
191
|
|
|
191
|
-
//
|
|
192
|
+
// Preserve legacy empty-result semantics until the device has established state.
|
|
192
193
|
if (!features)
|
|
193
194
|
return { passphraseState: undefined, newSession: undefined, unlockedAttachPin: undefined };
|
|
194
195
|
|
|
@@ -1,51 +1,22 @@
|
|
|
1
1
|
import { isEmpty } from 'lodash';
|
|
2
|
-
import { EDeviceType
|
|
3
|
-
import { Enum_Capability } from '@onekeyfe/hd-transport';
|
|
2
|
+
import { EDeviceType } from '@onekeyfe/hd-shared';
|
|
4
3
|
|
|
5
4
|
import { DeviceModelToTypes } from '../types';
|
|
6
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
resolveDeviceBleName,
|
|
7
|
+
resolveDeviceFirmwareType,
|
|
8
|
+
resolveDeviceSerialNo,
|
|
9
|
+
resolveDeviceType,
|
|
10
|
+
} from './deviceFeaturesCompat';
|
|
7
11
|
|
|
8
|
-
import type {
|
|
12
|
+
import type { IDeviceModel, IDeviceType, IVersionRange } from '../types';
|
|
13
|
+
import type { DeviceFeaturesInput } from './deviceFeaturesCompat';
|
|
9
14
|
|
|
10
15
|
/**
|
|
11
16
|
* get device type by features
|
|
12
17
|
*/
|
|
13
|
-
export const getDeviceType = (features?:
|
|
14
|
-
|
|
15
|
-
return EDeviceType.Unknown;
|
|
16
|
-
}
|
|
17
|
-
if (features.deviceType) {
|
|
18
|
-
return features.deviceType;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (features.model === EDeviceType.Pro2 || features.model === 'pro2') {
|
|
22
|
-
return EDeviceType.Pro2;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// low version hardware
|
|
26
|
-
// onekey_serial_no > onekey_serial > serial_no
|
|
27
|
-
const serialNo = getDeviceUUID(features);
|
|
28
|
-
|
|
29
|
-
// not exist serialNo, bootloader mode, model 1 is classic
|
|
30
|
-
if (isEmpty(serialNo) && features.bootloaderMode === true && features.model === '1') {
|
|
31
|
-
return EDeviceType.Classic;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (isEmpty(serialNo)) return EDeviceType.Unknown;
|
|
35
|
-
|
|
36
|
-
const miniFlag = serialNo.slice(0, 2);
|
|
37
|
-
// By May 2021, the miniFlag is 'bixin' for all classic devices
|
|
38
|
-
if (miniFlag.toLowerCase() === 'bi') return EDeviceType.Classic;
|
|
39
|
-
if (miniFlag.toLowerCase() === 'cl') return EDeviceType.Classic;
|
|
40
|
-
if (miniFlag.toLowerCase() === 'cp') return EDeviceType.ClassicPure;
|
|
41
|
-
if (miniFlag.toLowerCase() === 'mi') return EDeviceType.Mini;
|
|
42
|
-
if (miniFlag.toLowerCase() === 'tc') return EDeviceType.Touch;
|
|
43
|
-
if (miniFlag.toLowerCase() === 'pr') return EDeviceType.Pro;
|
|
44
|
-
if (miniFlag.toLowerCase() === 'p2') return EDeviceType.Pro2;
|
|
45
|
-
|
|
46
|
-
// unknown device
|
|
47
|
-
return EDeviceType.Unknown;
|
|
48
|
-
};
|
|
18
|
+
export const getDeviceType = (features?: DeviceFeaturesInput): IDeviceType =>
|
|
19
|
+
resolveDeviceType(features);
|
|
49
20
|
|
|
50
21
|
/**
|
|
51
22
|
* get device type by ble name
|
|
@@ -70,28 +41,30 @@ export const getDeviceTypeByBleName = (name?: string): IDeviceType => {
|
|
|
70
41
|
* Get Connected Device ble name by features
|
|
71
42
|
* @returns
|
|
72
43
|
*/
|
|
73
|
-
export const getDeviceBleName = (features?:
|
|
74
|
-
|
|
75
|
-
return features.bleName || null;
|
|
76
|
-
};
|
|
44
|
+
export const getDeviceBleName = (features?: DeviceFeaturesInput): string | null =>
|
|
45
|
+
resolveDeviceBleName(features);
|
|
77
46
|
|
|
78
47
|
/**
|
|
79
|
-
* Get Connected Device
|
|
48
|
+
* Get Connected Device serial number by features
|
|
80
49
|
*/
|
|
81
|
-
export const
|
|
82
|
-
|
|
83
|
-
|
|
50
|
+
export const getDeviceSerialNo = (features?: DeviceFeaturesInput): string =>
|
|
51
|
+
resolveDeviceSerialNo(features);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Use getDeviceSerialNo instead.
|
|
55
|
+
*/
|
|
56
|
+
export const getDeviceUUID = getDeviceSerialNo;
|
|
84
57
|
|
|
85
58
|
/**
|
|
86
59
|
* Get Connected Device label by features
|
|
87
60
|
*/
|
|
88
|
-
export const getDeviceLabel = (features?:
|
|
61
|
+
export const getDeviceLabel = (features?: DeviceFeaturesInput) => {
|
|
89
62
|
if (!features) return null;
|
|
90
63
|
|
|
91
64
|
const deviceType = getDeviceType(features);
|
|
92
65
|
if (deviceType == null) return null;
|
|
93
66
|
|
|
94
|
-
if (typeof features.label === 'string' && !isEmpty(features.label)) {
|
|
67
|
+
if ('label' in features && typeof features.label === 'string' && !isEmpty(features.label)) {
|
|
95
68
|
return features.label;
|
|
96
69
|
}
|
|
97
70
|
|
|
@@ -110,7 +83,7 @@ export const getDeviceLabel = (features?: Features) => {
|
|
|
110
83
|
* Type has a higher priority than Model
|
|
111
84
|
*/
|
|
112
85
|
export const getMethodVersionRange = (
|
|
113
|
-
features:
|
|
86
|
+
features: DeviceFeaturesInput | undefined,
|
|
114
87
|
getVersionRange: (deviceModel: IDeviceType | IDeviceModel) => IVersionRange | undefined
|
|
115
88
|
): IVersionRange | undefined => {
|
|
116
89
|
const deviceType = getDeviceType(features);
|
|
@@ -141,16 +114,5 @@ export const getMethodVersionRange = (
|
|
|
141
114
|
export const isMethodVersionRangeUnsupported = (versionRange?: IVersionRange): boolean =>
|
|
142
115
|
versionRange?.unsupported === true;
|
|
143
116
|
|
|
144
|
-
export const getFirmwareType = (features
|
|
145
|
-
|
|
146
|
-
return EFirmwareType.Universal;
|
|
147
|
-
}
|
|
148
|
-
if (features.firmwareType) {
|
|
149
|
-
return features.firmwareType;
|
|
150
|
-
}
|
|
151
|
-
// old firmware
|
|
152
|
-
return features?.capabilities?.length > 0 &&
|
|
153
|
-
!existCapability(features, Enum_Capability.Capability_Bitcoin_like)
|
|
154
|
-
? EFirmwareType.BitcoinOnly
|
|
155
|
-
: EFirmwareType.Universal;
|
|
156
|
-
};
|
|
117
|
+
export const getFirmwareType = (features?: DeviceFeaturesInput) =>
|
|
118
|
+
resolveDeviceFirmwareType(features);
|
|
@@ -19,19 +19,26 @@ export const LANGUAGE_LABELS = {
|
|
|
19
19
|
export type LanguageKey = keyof typeof LANGUAGE_LABELS;
|
|
20
20
|
export type LanguageOption = { code: LanguageKey; label: (typeof LANGUAGE_LABELS)[LanguageKey] };
|
|
21
21
|
|
|
22
|
+
export const PROTOCOL_V2_LANGUAGE_BY_KEY: Record<LanguageKey, string> = {
|
|
23
|
+
en: 'en-Latn-US',
|
|
24
|
+
zh_cn: 'zh-Hans-CN',
|
|
25
|
+
zh_hk: 'zh-Hant-HK',
|
|
26
|
+
ja: 'ja-Jpan-JP',
|
|
27
|
+
ko: 'ko-Kore-KR',
|
|
28
|
+
fr: 'fr-Latn-FR',
|
|
29
|
+
de: 'de-Latn-DE',
|
|
30
|
+
ru: 'ru-Cyrl-RU',
|
|
31
|
+
es: 'es-Latn-ES',
|
|
32
|
+
it: 'it-Latn-IT',
|
|
33
|
+
pt_br: 'pt-Latn-BR',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const mapLanguageToProtocolV2 = (language?: string) =>
|
|
37
|
+
language ? PROTOCOL_V2_LANGUAGE_BY_KEY[language as LanguageKey] ?? language : undefined;
|
|
38
|
+
|
|
22
39
|
const PRO2_LANGUAGE_OPTIONS = [
|
|
23
|
-
{ code
|
|
24
|
-
{ code: 'zh-Hans-CN', label: '简体中文' },
|
|
25
|
-
{ code: 'zh-Hant-HK', label: '繁體中文(香港)' },
|
|
40
|
+
...Object.entries(LANGUAGE_LABELS).map(([code, label]) => ({ code, label })),
|
|
26
41
|
{ code: 'zh-Hant-TW', label: '繁體中文(台灣)' },
|
|
27
|
-
{ code: 'ja-Jpan-JP', label: '日本語' },
|
|
28
|
-
{ code: 'ko-Kore-KR', label: '한국어' },
|
|
29
|
-
{ code: 'fr-Latn-FR', label: 'Français' },
|
|
30
|
-
{ code: 'de-Latn-DE', label: 'Deutsch' },
|
|
31
|
-
{ code: 'ru-Cyrl-RU', label: 'Русский' },
|
|
32
|
-
{ code: 'es-Latn-ES', label: 'Español' },
|
|
33
|
-
{ code: 'it-Latn-IT', label: 'Italiano' },
|
|
34
|
-
{ code: 'pt-Latn-BR', label: 'Portuguese (Brazil)' },
|
|
35
42
|
{ code: 'vi-Latn-VN', label: 'Tiếng Việt' },
|
|
36
43
|
{ code: 'tr-Latn-TR', label: 'Türkçe' },
|
|
37
44
|
{ code: 'id-Latn-ID', label: 'Bahasa Indonesia' },
|
|
@@ -1,61 +1,42 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import {
|
|
4
|
+
resolveDeviceBleFirmwareVersion,
|
|
5
|
+
resolveDeviceBoardVersion,
|
|
6
|
+
resolveDeviceBootloaderVersion,
|
|
7
|
+
resolveDeviceFirmwareVersion,
|
|
8
|
+
} from './deviceFeaturesCompat';
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
export const getDeviceFirmwareVersion = (features: Features | undefined): IVersionArray => {
|
|
9
|
-
if (!features) return [0, 0, 0];
|
|
10
|
+
import type { IVersionArray } from '../types';
|
|
11
|
+
import type { DeviceFeaturesInput } from './deviceFeaturesCompat';
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
return features.firmwareVersion.split('.').map(Number) as IVersionArray;
|
|
13
|
-
}
|
|
13
|
+
const EMPTY_VERSION: IVersionArray = [0, 0, 0];
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
const parseDeviceVersion = (version?: string | null): IVersionArray => {
|
|
16
|
+
const parsed = version ? semver.parse(version) : null;
|
|
17
|
+
return parsed ? [parsed.major, parsed.minor, parsed.patch] : [...EMPTY_VERSION];
|
|
16
18
|
};
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
|
-
* Get Connected Device
|
|
21
|
+
* Get Connected Device version by features
|
|
20
22
|
*/
|
|
21
|
-
export const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!bleVer) {
|
|
25
|
-
return [0, 0, 0];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (!semver.valid(bleVer)) {
|
|
29
|
-
return [0, 0, 0];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (bleVer) {
|
|
33
|
-
return bleVer.split('.').map(Number) as IVersionArray;
|
|
34
|
-
}
|
|
35
|
-
return [0, 0, 0];
|
|
36
|
-
};
|
|
23
|
+
export const getDeviceFirmwareVersion = (features?: DeviceFeaturesInput): IVersionArray =>
|
|
24
|
+
parseDeviceVersion(resolveDeviceFirmwareVersion(features));
|
|
37
25
|
|
|
38
26
|
/**
|
|
39
27
|
* Get Connected Device bootloader version by features
|
|
40
28
|
*/
|
|
41
|
-
export const getDeviceBootloaderVersion = (features
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// classic1s 3.5.0 pro 4.6.0
|
|
45
|
-
if (features.bootloaderVersion && semver.valid(features.bootloaderVersion)) {
|
|
46
|
-
return features.bootloaderVersion.split('.').map(Number) as IVersionArray;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return [0, 0, 0];
|
|
50
|
-
};
|
|
29
|
+
export const getDeviceBootloaderVersion = (features?: DeviceFeaturesInput): IVersionArray =>
|
|
30
|
+
parseDeviceVersion(resolveDeviceBootloaderVersion(features));
|
|
51
31
|
|
|
52
32
|
/**
|
|
53
|
-
* Get Connected Device boardloader version by features
|
|
33
|
+
* Get Connected Device boardloader/romloader version by features
|
|
54
34
|
*/
|
|
55
|
-
export const getDeviceBoardloaderVersion = (features
|
|
56
|
-
|
|
57
|
-
return features.boardVersion.split('.').map(Number) as IVersionArray;
|
|
58
|
-
}
|
|
35
|
+
export const getDeviceBoardloaderVersion = (features?: DeviceFeaturesInput): IVersionArray =>
|
|
36
|
+
parseDeviceVersion(resolveDeviceBoardVersion(features));
|
|
59
37
|
|
|
60
|
-
|
|
61
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Get Connected Device bluetooth firmware version by features
|
|
40
|
+
*/
|
|
41
|
+
export const getDeviceBLEFirmwareVersion = (features?: DeviceFeaturesInput): IVersionArray =>
|
|
42
|
+
parseDeviceVersion(resolveDeviceBleFirmwareVersion(features));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDeviceSerialNo, getDeviceType } from './deviceInfoUtils';
|
|
2
2
|
|
|
3
3
|
import type { Features } from '../types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 检测故障固件设备
|
|
7
7
|
* 检测规则:
|
|
8
|
-
* -
|
|
8
|
+
* - Serial number range: 21032200001 through 21032201500
|
|
9
9
|
* - SE版本为 1.1.0.2
|
|
10
10
|
*
|
|
11
11
|
* 对齐之前版本的检测逻辑
|
|
@@ -27,7 +27,7 @@ export const findDefectiveBatchDevice = (features: Features) => {
|
|
|
27
27
|
*/
|
|
28
28
|
export const getDefectiveDeviceInfo = (features: Features) => {
|
|
29
29
|
if (!findDefectiveBatchDevice(features)) return null;
|
|
30
|
-
const serialNo =
|
|
30
|
+
const serialNo = getDeviceSerialNo(features);
|
|
31
31
|
const deviceType = getDeviceType(features);
|
|
32
32
|
const { seVersion } = features;
|
|
33
33
|
|
package/src/utils/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export {
|
|
|
8
8
|
getDeviceTypeByBleName,
|
|
9
9
|
getDeviceType,
|
|
10
10
|
getDeviceBleName,
|
|
11
|
+
getDeviceSerialNo,
|
|
11
12
|
getDeviceUUID,
|
|
12
13
|
getDeviceLabel,
|
|
13
14
|
getMethodVersionRange,
|
|
@@ -38,11 +39,7 @@ export { getHDPath, getScriptType, getOutputScriptType } from '../api/helpers/pa
|
|
|
38
39
|
export const isBleConnect = (env: string) => env === 'react-native' || env === 'lowlevel';
|
|
39
40
|
|
|
40
41
|
export { getHomeScreenHex, getHomeScreenDefaultList, getHomeScreenSize } from './homescreen';
|
|
41
|
-
export {
|
|
42
|
-
encodePro2Wallpaper,
|
|
43
|
-
PRO2_WALLPAPER_HEIGHT,
|
|
44
|
-
PRO2_WALLPAPER_WIDTH,
|
|
45
|
-
} from './pro2Wallpaper';
|
|
42
|
+
export { encodePro2Wallpaper, PRO2_WALLPAPER_HEIGHT, PRO2_WALLPAPER_WIDTH } from './pro2Wallpaper';
|
|
46
43
|
export type { Pro2WallpaperColorFormat } from './pro2Wallpaper';
|
|
47
44
|
|
|
48
45
|
export const wait = (ms: number) =>
|