@onekeyfe/hd-core 1.2.0-alpha.2 → 1.2.0-alpha.21
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 +285 -0
- package/__tests__/DeviceEventRegistration.test.ts +43 -0
- package/__tests__/connectSettings.test.ts +19 -0
- package/__tests__/core-dispose.test.ts +34 -0
- package/__tests__/core-error-output.test.ts +39 -0
- package/__tests__/device-features-state.test.ts +78 -0
- package/__tests__/device-identity.test.ts +30 -0
- package/__tests__/device-lifecycle-events.test.ts +117 -0
- package/__tests__/device-pool-state.test.ts +132 -0
- package/__tests__/device-settings.test.ts +391 -0
- package/__tests__/device-state-contract.test.ts +27 -0
- package/__tests__/device-state-events.test.ts +162 -0
- package/__tests__/device-state-mapper.test.ts +241 -0
- package/__tests__/device-state-projector.test.ts +94 -0
- package/__tests__/device-state-store.test.ts +82 -0
- package/__tests__/device-utils.test.ts +106 -0
- package/__tests__/device-wallet-session-store.test.ts +213 -0
- package/__tests__/deviceFeaturesUtils.test.ts +39 -0
- package/__tests__/deviceSettings.test.ts +103 -0
- package/__tests__/evmLedgerLegacySafety.test.ts +10 -6
- 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 +410 -0
- package/__tests__/homescreen.test.ts +24 -0
- package/__tests__/kaspaSignTransaction.test.ts +591 -0
- package/__tests__/logBlockEvent.test.ts +26 -0
- 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__/preInitialize.test.ts +33 -0
- package/__tests__/pro2Wallpaper.test.ts +50 -0
- package/__tests__/protocol-v2-bootloader-mode.test.ts +37 -0
- package/__tests__/protocol-v2-firmware-targets.test.ts +19 -0
- package/__tests__/protocol-v2.test.ts +3954 -1191
- package/__tests__/protocolV2FileWrite.test.ts +92 -0
- package/__tests__/protocolV2UiInteraction.test.ts +266 -0
- package/__tests__/public-device-state-api.test.ts +257 -0
- package/__tests__/public-pro2-api-boundary.test.ts +110 -0
- package/__tests__/refresh-device-state.test.ts +101 -0
- package/__tests__/request-context-logging.test.ts +16 -0
- package/__tests__/search-devices.test.ts +136 -0
- package/dist/api/BaseMethod.d.ts +8 -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 +9 -0
- package/dist/api/ClearSessionCache.d.ts.map +1 -0
- package/dist/api/DirList.d.ts.map +1 -1
- package/dist/api/FileRead.d.ts.map +1 -1
- package/dist/api/FileWrite.d.ts +1 -0
- package/dist/api/FileWrite.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 +25 -5
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetDeviceState.d.ts +7 -0
- package/dist/api/GetDeviceState.d.ts.map +1 -0
- package/dist/api/GetFeatures.d.ts +1 -1
- package/dist/api/GetFeatures.d.ts.map +1 -1
- package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts +1 -6
- 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 +17 -0
- package/dist/api/UploadPortfolio.d.ts.map +1 -0
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceCancel.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/DeviceLock.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +1 -1
- package/dist/api/device/DeviceUnlock.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/FirmwareUpdateBaseMethod.d.ts +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +11 -3
- 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/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 +33 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -0
- package/dist/api/index.d.ts +12 -19
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts +5 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/kaspa/helpers/TransferSerialize.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/DeviceGetOnboardingStatus.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts +28 -0
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -1
- 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/DeviceUploadWallpaper.d.ts +26 -0
- package/dist/api/protocol-v2/DeviceUploadWallpaper.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/utils.d.ts +2 -1
- package/dist/api/utils.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/RequestQueue.d.ts.map +1 -1
- package/dist/core/deviceEventRegistration.d.ts +11 -0
- package/dist/core/deviceEventRegistration.d.ts.map +1 -0
- package/dist/core/index.d.ts +3 -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 +35 -11
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +8 -6
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceFeaturesState.d.ts +3 -0
- package/dist/device/DeviceFeaturesState.d.ts.map +1 -0
- package/dist/device/DevicePool.d.ts +4 -2
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/device/DeviceStateMapper.d.ts +13 -0
- package/dist/device/DeviceStateMapper.d.ts.map +1 -0
- package/dist/device/DeviceStateProjector.d.ts +7 -0
- package/dist/device/DeviceStateProjector.d.ts.map +1 -0
- package/dist/device/DeviceStateStore.d.ts +21 -0
- package/dist/device/DeviceStateStore.d.ts.map +1 -0
- package/dist/device/DeviceWalletSessionStore.d.ts +20 -0
- package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -0
- package/dist/device/cloneDeviceState.d.ts +2 -0
- package/dist/device/cloneDeviceState.d.ts.map +1 -0
- package/dist/device/deviceIdentity.d.ts +5 -0
- package/dist/device/deviceIdentity.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts +9 -3
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/deviceProfile/index.d.ts +0 -1
- package/dist/deviceProfile/index.d.ts.map +1 -1
- package/dist/events/device.d.ts +11 -2
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +18 -2
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +1361 -609
- package/dist/index.js +5898 -2860
- 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 +23 -28
- 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 +3 -2
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +2 -0
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +1 -0
- 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 +39 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +11 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts +19 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -0
- 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 +11 -2
- package/dist/types/api/deviceSettings.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +2 -2
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +6 -6
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/getDeviceState.d.ts +12 -0
- package/dist/types/api/getDeviceState.d.ts.map +1 -0
- 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 +2 -10
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +22 -25
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/kaspaSignTransaction.d.ts +27 -2
- package/dist/types/api/kaspaSignTransaction.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 +23 -28
- 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 +121 -5
- 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/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 +13 -3
- 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 +38 -7
- 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/homescreen.d.ts.map +1 -1
- package/dist/utils/index.d.ts +5 -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 +12 -0
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -0
- package/dist/utils/tracing.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +36 -9
- package/src/api/CheckBootloaderRelease.ts +1 -2
- package/src/api/CheckFirmwareRelease.ts +1 -2
- package/src/api/ClearSessionCache.ts +28 -0
- 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 +23 -7
- package/src/api/FileWrite.ts +23 -168
- 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 +1138 -357
- package/src/api/GetDeviceState.ts +55 -0
- package/src/api/GetFeatures.ts +8 -3
- package/src/api/GetOnekeyFeatures.ts +3 -72
- package/src/api/GetPassphraseState.ts +11 -18
- 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 +29 -4
- package/src/api/UploadPortfolio.ts +40 -0
- 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/cardano/CardanoSignMessage.ts +1 -1
- package/src/api/cardano/CardanoSignTransaction.ts +1 -1
- package/src/api/device/DeviceCancel.ts +1 -0
- package/src/api/device/DeviceChangePin.ts +24 -0
- package/src/api/device/DeviceFullyUploadResource.ts +4 -5
- package/src/api/device/DeviceLock.ts +1 -0
- package/src/api/device/DeviceRebootToBoardloader.ts +5 -4
- package/src/api/device/DeviceRebootToBootloader.ts +5 -4
- package/src/api/device/DeviceSettings.ts +183 -1
- package/src/api/device/DeviceUnlock.ts +11 -1
- package/src/api/device/DeviceUpdateBootloader.ts +1 -2
- package/src/api/device/DeviceWipe.ts +19 -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 +21 -7
- package/src/api/firmware/getBinary.ts +8 -3
- package/src/api/firmware/progressThrottle.ts +44 -0
- 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 +193 -0
- package/src/api/index.ts +14 -20
- package/src/api/kaspa/KaspaSignTransaction.ts +341 -22
- package/src/api/kaspa/helpers/TransferSerialize.ts +14 -0
- package/src/api/nervos/NervosSignTransaction.ts +2 -2
- package/src/api/nexa/NexaSignTransaction.ts +1 -1
- package/src/api/protocol-v2/{FactoryGetDeviceInfo.ts → DeviceFactoryInfoGet.ts} +4 -4
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +32 -0
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +7 -9
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +41 -6
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +6 -4
- package/src/api/protocol-v2/DeviceInfoGet.ts +145 -0
- package/src/api/protocol-v2/DeviceReboot.ts +5 -3
- package/src/api/protocol-v2/DeviceStatusGet.ts +16 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +131 -0
- package/src/api/protocol-v2/FilesystemFormat.ts +5 -2
- package/src/api/protocol-v2/{FilesystemFixPermission.ts → FilesystemPermissionFix.ts} +3 -3
- package/src/api/protocol-v2/Ping.ts +1 -1
- package/src/api/protocol-v2/{GetProtoVersion.ts → ProtocolInfoRequest.ts} +3 -3
- package/src/api/protocol-v2/helpers.ts +58 -62
- package/src/api/ton/TonSignData.ts +1 -5
- package/src/api/utils.ts +7 -3
- package/src/constants/index.ts +7 -1
- package/src/core/RequestQueue.ts +1 -0
- package/src/core/deviceEventRegistration.ts +23 -0
- package/src/core/index.ts +140 -35
- package/src/data/messages/messages-protocol-v2.json +825 -709
- package/src/data/messages/messages.json +286 -1
- package/src/data-manager/DataManager.ts +13 -6
- package/src/data-manager/connectSettings.ts +4 -0
- package/src/device/Device.ts +480 -192
- package/src/device/DeviceCommands.ts +81 -25
- package/src/device/DeviceFeaturesState.ts +25 -0
- package/src/device/DevicePool.ts +67 -19
- package/src/device/DeviceStateMapper.ts +349 -0
- package/src/device/DeviceStateProjector.ts +95 -0
- package/src/device/DeviceStateStore.ts +201 -0
- package/src/device/DeviceWalletSessionStore.ts +105 -0
- package/src/device/cloneDeviceState.ts +39 -0
- package/src/device/deviceIdentity.ts +18 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +235 -210
- package/src/deviceProfile/index.ts +0 -1
- package/src/events/device.ts +17 -1
- package/src/events/logBlockEvent.ts +8 -1
- package/src/events/ui-request.ts +24 -2
- package/src/inject.ts +23 -34
- package/src/protocols/protocol-v2/deviceSession.ts +24 -0
- package/src/protocols/protocol-v2/features.ts +68 -82
- package/src/protocols/protocol-v2/firmware.ts +12 -36
- package/src/protocols/protocol-v2/index.ts +3 -1
- package/src/protocols/protocol-v2/lockedError.ts +10 -0
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +61 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +210 -0
- package/src/protocols/protocol-v2/unlockRetry.ts +76 -0
- package/src/protocols/protocol-v2/walletSession.ts +107 -0
- package/src/types/api/checkAllFirmwareRelease.ts +1 -2
- package/src/types/api/deviceSettings.ts +26 -2
- package/src/types/api/deviceUnlock.ts +5 -2
- package/src/types/api/firmwareUpdate.ts +28 -20
- package/src/types/api/getDeviceState.ts +19 -0
- package/src/types/api/getFeatures.ts +3 -0
- package/src/types/api/getOnekeyFeatures.ts +3 -0
- package/src/types/api/getPassphraseState.ts +8 -11
- package/src/types/api/index.ts +30 -53
- package/src/types/api/kaspaSignTransaction.ts +40 -2
- package/src/types/api/openWalletSession.ts +64 -0
- package/src/types/api/protocolV2.ts +58 -55
- package/src/types/api/sessionCache.ts +14 -0
- package/src/types/device.ts +170 -4
- package/src/types/params.ts +4 -0
- package/src/types/settings.ts +42 -30
- package/src/utils/assets.ts +4 -1
- package/src/utils/deviceFeaturesCompat.ts +173 -0
- package/src/utils/deviceFeaturesUtils.ts +68 -24
- package/src/utils/deviceInfoUtils.ts +26 -64
- package/src/utils/deviceSettings.ts +161 -39
- package/src/utils/deviceVersionUtils.ts +25 -44
- package/src/utils/findDefectiveBatchDevice.ts +3 -3
- package/src/utils/homescreen.ts +10 -0
- package/src/utils/index.ts +21 -1
- package/src/utils/networkUtils.ts +270 -14
- package/src/utils/pro2Wallpaper.ts +109 -0
- package/src/utils/tracing.ts +3 -1
- package/dist/api/GetDeviceInfo.d.ts +0 -9
- package/dist/api/GetDeviceInfo.d.ts.map +0 -1
- 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 +0 -29
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.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/FilesystemDiskControl.d.ts +0 -13
- package/dist/api/protocol-v2/FilesystemDiskControl.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/buildDeviceProfile.d.ts +0 -21
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +0 -1
- package/dist/types/api/getDeviceInfo.d.ts +0 -85
- package/dist/types/api/getDeviceInfo.d.ts.map +0 -1
- package/src/api/GetDeviceInfo.ts +0 -145
- package/src/api/protocol-v2/DevReboot.ts +0 -24
- package/src/api/protocol-v2/DeviceGetDeviceInfo.ts +0 -118
- package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +0 -29
- package/src/api/protocol-v2/FilesystemDiskControl.ts +0 -50
- package/src/deviceProfile/buildDeviceProfile.ts +0 -334
- package/src/types/api/getDeviceInfo.ts +0 -99
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import { buildProtocolV1FeaturesPayload } from '../deviceProfile/buildDeviceFeatures';
|
|
4
|
+
import {
|
|
5
|
+
mapLanguageFromProtocolV2,
|
|
6
|
+
mapLanguageToProtocolV2,
|
|
7
|
+
normalizeSafetyCheckLevel,
|
|
8
|
+
} from '../utils/deviceSettings';
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
ApplySettings,
|
|
12
|
+
DeviceFirmwareImageInfo,
|
|
13
|
+
DeviceSettings,
|
|
14
|
+
DeviceStatus,
|
|
15
|
+
ProtocolV2DeviceInfo,
|
|
16
|
+
} from '@onekeyfe/hd-transport';
|
|
17
|
+
import type { PROTO } from '../constants';
|
|
18
|
+
import type {
|
|
19
|
+
DeviceFeaturesVerify,
|
|
20
|
+
DeviceStateMode,
|
|
21
|
+
DeviceStatePatch,
|
|
22
|
+
Features,
|
|
23
|
+
OnekeyFeatures,
|
|
24
|
+
} from '../types';
|
|
25
|
+
import type { DeviceSettingsParams } from '../types/api/deviceSettings';
|
|
26
|
+
|
|
27
|
+
const definedEntries = <T extends Record<string, unknown>>(value: T): T =>
|
|
28
|
+
Object.fromEntries(
|
|
29
|
+
Object.entries(value).filter(([, fieldValue]) => fieldValue !== undefined)
|
|
30
|
+
) as T;
|
|
31
|
+
|
|
32
|
+
const imageVersion = (image?: DeviceFirmwareImageInfo | null) => image?.version ?? undefined;
|
|
33
|
+
|
|
34
|
+
const bytesToHex = (value: unknown): string | undefined => {
|
|
35
|
+
if (!value) return undefined;
|
|
36
|
+
if (typeof value === 'string') return value;
|
|
37
|
+
if (value instanceof Uint8Array || Array.isArray(value)) {
|
|
38
|
+
return Array.from(value)
|
|
39
|
+
.map(byte => Number(byte).toString(16).padStart(2, '0'))
|
|
40
|
+
.join('');
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const imageBuildId = (image?: DeviceFirmwareImageInfo | null) => image?.build_id ?? undefined;
|
|
46
|
+
const imageHash = (image?: DeviceFirmwareImageInfo | null) => bytesToHex(image?.hash);
|
|
47
|
+
|
|
48
|
+
const getFeaturesMode = (features: Features): DeviceStateMode | undefined => {
|
|
49
|
+
if (features.mode !== undefined && features.mode !== null) return features.mode;
|
|
50
|
+
if (features.bootloaderMode === true) return 'bootloader';
|
|
51
|
+
if (features.initialized === false) return 'notInitialized';
|
|
52
|
+
if (features.initialized === true) return 'normal';
|
|
53
|
+
return undefined;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const getProtocolV2StatusMode = (initialized?: boolean | null): DeviceStateMode | undefined => {
|
|
57
|
+
if (initialized === false) return 'notInitialized';
|
|
58
|
+
if (initialized === true) return 'normal';
|
|
59
|
+
return undefined;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const mapFeaturesToState = (features: Features): DeviceStatePatch => ({
|
|
63
|
+
protocol: features.protocol,
|
|
64
|
+
protocolVersion: features.protocolVersion,
|
|
65
|
+
identity: {
|
|
66
|
+
deviceType: features.deviceType,
|
|
67
|
+
firmwareType: features.firmwareType,
|
|
68
|
+
model: features.model,
|
|
69
|
+
vendor: features.vendor,
|
|
70
|
+
deviceId: features.deviceId,
|
|
71
|
+
serialNo: features.serialNo,
|
|
72
|
+
label: features.label,
|
|
73
|
+
bleName: features.bleName,
|
|
74
|
+
},
|
|
75
|
+
status: {
|
|
76
|
+
mode: getFeaturesMode(features),
|
|
77
|
+
initialized: features.initialized,
|
|
78
|
+
unlocked: features.unlocked,
|
|
79
|
+
firmwarePresent: features.firmwarePresent,
|
|
80
|
+
backupRequired: features.backupRequired,
|
|
81
|
+
noBackup: features.noBackup,
|
|
82
|
+
unfinishedBackup: features.unfinishedBackup,
|
|
83
|
+
recoveryMode: features.recoveryMode,
|
|
84
|
+
passphraseProtection: features.passphraseProtection,
|
|
85
|
+
pinProtection: features.pinProtection,
|
|
86
|
+
attachToPinEnabled: features.attachToPinEnabled ?? null,
|
|
87
|
+
unlockedAttachPin: features.unlockedAttachPin ?? null,
|
|
88
|
+
},
|
|
89
|
+
settings: {
|
|
90
|
+
language: features.language,
|
|
91
|
+
bleEnabled: features.bleEnabled,
|
|
92
|
+
sdCardPresent: features.sdCardPresent,
|
|
93
|
+
sdProtection: features.sdProtection,
|
|
94
|
+
wipeCodeProtection: features.wipeCodeProtection,
|
|
95
|
+
passphraseAlwaysOnDevice: features.passphraseAlwaysOnDevice,
|
|
96
|
+
safetyChecks: features.safetyChecks,
|
|
97
|
+
autoLockDelayMs: features.autoLockDelayMs,
|
|
98
|
+
autoShutdownDelayMs: features.autoShutdownDelayMs,
|
|
99
|
+
displayRotation: features.displayRotation,
|
|
100
|
+
experimentalFeatures: features.experimentalFeatures,
|
|
101
|
+
wallpaperPath: features.wallpaperPath,
|
|
102
|
+
brightness: features.brightness,
|
|
103
|
+
animationEnabled: features.animationEnabled,
|
|
104
|
+
tapToWake: features.tapToWake,
|
|
105
|
+
hapticFeedback: features.hapticFeedback,
|
|
106
|
+
deviceNameDisplayEnabled: features.deviceNameDisplayEnabled,
|
|
107
|
+
airgapMode: features.airgapMode,
|
|
108
|
+
fidoEnabled: features.fidoEnabled,
|
|
109
|
+
usbLockEnabled: features.usbLockEnabled,
|
|
110
|
+
randomKeypad: features.randomKeypad,
|
|
111
|
+
},
|
|
112
|
+
versions: {
|
|
113
|
+
firmware: features.firmwareVersion,
|
|
114
|
+
bootloader: features.bootloaderVersion,
|
|
115
|
+
board: features.boardVersion,
|
|
116
|
+
ble: features.bleVersion,
|
|
117
|
+
// Legacy devices expose one SE version; project it to se01 and keep se as an alias.
|
|
118
|
+
se: features.seVersion,
|
|
119
|
+
se01: features.se01Version ?? features.seVersion,
|
|
120
|
+
se02: features.se02Version,
|
|
121
|
+
se03: features.se03Version,
|
|
122
|
+
se04: features.se04Version,
|
|
123
|
+
se01Boot: features.se01BootVersion,
|
|
124
|
+
se02Boot: features.se02BootVersion,
|
|
125
|
+
se03Boot: features.se03BootVersion,
|
|
126
|
+
se04Boot: features.se04BootVersion,
|
|
127
|
+
},
|
|
128
|
+
capabilities: features.capabilities,
|
|
129
|
+
verification: definedEntries(features.verify ?? {}),
|
|
130
|
+
raw: features.raw,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
export const mapProtocolV1FeaturesToState = (
|
|
134
|
+
protocolV1Features: PROTO.Features
|
|
135
|
+
): DeviceStatePatch => mapFeaturesToState(buildProtocolV1FeaturesPayload(protocolV1Features));
|
|
136
|
+
|
|
137
|
+
const meaningfulVersion = (version?: string | null) => {
|
|
138
|
+
if (!version || version === '0.0.0') return undefined;
|
|
139
|
+
const parts = version.split('.');
|
|
140
|
+
while (parts.length < 3) parts.push('0');
|
|
141
|
+
return parts.map(part => (Number.isNaN(Number.parseInt(part, 10)) ? '0' : part)).join('.');
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const mapProtocolV1OnekeyFeaturesToState = (features: OnekeyFeatures): DeviceStatePatch => {
|
|
145
|
+
const verification = definedEntries<DeviceFeaturesVerify>({
|
|
146
|
+
firmwareBuildId: features.onekey_firmware_build_id,
|
|
147
|
+
firmwareHash: features.onekey_firmware_hash,
|
|
148
|
+
bootloaderBuildId: features.onekey_boot_build_id,
|
|
149
|
+
bootloaderHash: features.onekey_boot_hash,
|
|
150
|
+
boardBuildId: features.onekey_board_build_id,
|
|
151
|
+
boardHash: features.onekey_board_hash,
|
|
152
|
+
bleBuildId: features.onekey_ble_build_id,
|
|
153
|
+
bleHash: features.onekey_ble_hash,
|
|
154
|
+
se01BuildId: features.onekey_se01_build_id,
|
|
155
|
+
se01Hash: features.onekey_se01_hash,
|
|
156
|
+
se02BuildId: features.onekey_se02_build_id,
|
|
157
|
+
se02Hash: features.onekey_se02_hash,
|
|
158
|
+
se03BuildId: features.onekey_se03_build_id,
|
|
159
|
+
se03Hash: features.onekey_se03_hash,
|
|
160
|
+
se04BuildId: features.onekey_se04_build_id,
|
|
161
|
+
se04Hash: features.onekey_se04_hash,
|
|
162
|
+
se01BootBuildId: features.onekey_se01_boot_build_id,
|
|
163
|
+
se01BootHash: features.onekey_se01_boot_hash,
|
|
164
|
+
se02BootBuildId: features.onekey_se02_boot_build_id,
|
|
165
|
+
se02BootHash: features.onekey_se02_boot_hash,
|
|
166
|
+
se03BootBuildId: features.onekey_se03_boot_build_id,
|
|
167
|
+
se03BootHash: features.onekey_se03_boot_hash,
|
|
168
|
+
se04BootBuildId: features.onekey_se04_boot_build_id,
|
|
169
|
+
se04BootHash: features.onekey_se04_boot_hash,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
versions: definedEntries({
|
|
174
|
+
firmware: meaningfulVersion(features.onekey_firmware_version),
|
|
175
|
+
bootloader: meaningfulVersion(features.onekey_boot_version),
|
|
176
|
+
board: meaningfulVersion(features.onekey_board_version),
|
|
177
|
+
ble: meaningfulVersion(features.onekey_ble_version),
|
|
178
|
+
se01: meaningfulVersion(features.onekey_se01_version),
|
|
179
|
+
se02: meaningfulVersion(features.onekey_se02_version),
|
|
180
|
+
se03: meaningfulVersion(features.onekey_se03_version),
|
|
181
|
+
se04: meaningfulVersion(features.onekey_se04_version),
|
|
182
|
+
se01Boot: meaningfulVersion(features.onekey_se01_boot_version),
|
|
183
|
+
se02Boot: meaningfulVersion(features.onekey_se02_boot_version),
|
|
184
|
+
se03Boot: meaningfulVersion(features.onekey_se03_boot_version),
|
|
185
|
+
se04Boot: meaningfulVersion(features.onekey_se04_boot_version),
|
|
186
|
+
}),
|
|
187
|
+
...(Object.keys(verification).length > 0 ? { verification } : {}),
|
|
188
|
+
raw: { protocolV1OneKeyFeatures: features },
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const mapProtocolV2DeviceInfoToState = (
|
|
193
|
+
info: ProtocolV2DeviceInfo,
|
|
194
|
+
mode: DeviceStateMode = 'unknown'
|
|
195
|
+
): DeviceStatePatch => {
|
|
196
|
+
const loader = mode === 'bootloader' || mode === 'romloader';
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
protocol: 'V2',
|
|
200
|
+
protocolVersion: info.protocol_version,
|
|
201
|
+
identity: definedEntries({
|
|
202
|
+
deviceType: EDeviceType.Pro2,
|
|
203
|
+
firmwareType: EFirmwareType.Universal,
|
|
204
|
+
model: 'pro2',
|
|
205
|
+
vendor: 'onekey.so',
|
|
206
|
+
serialNo: info.hw?.serial_no,
|
|
207
|
+
bleName: info.coprocessor?.bt_adv_name,
|
|
208
|
+
deviceId: loader ? null : undefined,
|
|
209
|
+
}),
|
|
210
|
+
status: loader
|
|
211
|
+
? {
|
|
212
|
+
mode,
|
|
213
|
+
initialized: null,
|
|
214
|
+
unlocked: null,
|
|
215
|
+
firmwarePresent: null,
|
|
216
|
+
backupRequired: null,
|
|
217
|
+
noBackup: null,
|
|
218
|
+
unfinishedBackup: null,
|
|
219
|
+
recoveryMode: null,
|
|
220
|
+
passphraseProtection: null,
|
|
221
|
+
pinProtection: null,
|
|
222
|
+
attachToPinEnabled: null,
|
|
223
|
+
unlockedAttachPin: null,
|
|
224
|
+
}
|
|
225
|
+
: { mode },
|
|
226
|
+
versions: definedEntries({
|
|
227
|
+
firmware: imageVersion(info.fw?.application),
|
|
228
|
+
bootloader: imageVersion(info.fw?.bootloader),
|
|
229
|
+
board: imageVersion(info.fw?.romloader),
|
|
230
|
+
ble: imageVersion(info.coprocessor?.application),
|
|
231
|
+
se01: imageVersion(info.se1?.application),
|
|
232
|
+
se02: imageVersion(info.se2?.application),
|
|
233
|
+
se03: imageVersion(info.se3?.application),
|
|
234
|
+
se04: imageVersion(info.se4?.application),
|
|
235
|
+
se01Boot: imageVersion(info.se1?.bootloader),
|
|
236
|
+
se02Boot: imageVersion(info.se2?.bootloader),
|
|
237
|
+
se03Boot: imageVersion(info.se3?.bootloader),
|
|
238
|
+
se04Boot: imageVersion(info.se4?.bootloader),
|
|
239
|
+
}),
|
|
240
|
+
verification: definedEntries({
|
|
241
|
+
firmwareBuildId: imageBuildId(info.fw?.application),
|
|
242
|
+
firmwareHash: imageHash(info.fw?.application),
|
|
243
|
+
bootloaderBuildId: imageBuildId(info.fw?.bootloader),
|
|
244
|
+
bootloaderHash: imageHash(info.fw?.bootloader),
|
|
245
|
+
boardBuildId: imageBuildId(info.fw?.romloader),
|
|
246
|
+
boardHash: imageHash(info.fw?.romloader),
|
|
247
|
+
bleBuildId: imageBuildId(info.coprocessor?.application),
|
|
248
|
+
bleHash: imageHash(info.coprocessor?.application),
|
|
249
|
+
se01BuildId: imageBuildId(info.se1?.application),
|
|
250
|
+
se01Hash: imageHash(info.se1?.application),
|
|
251
|
+
se02BuildId: imageBuildId(info.se2?.application),
|
|
252
|
+
se02Hash: imageHash(info.se2?.application),
|
|
253
|
+
se03BuildId: imageBuildId(info.se3?.application),
|
|
254
|
+
se03Hash: imageHash(info.se3?.application),
|
|
255
|
+
se04BuildId: imageBuildId(info.se4?.application),
|
|
256
|
+
se04Hash: imageHash(info.se4?.application),
|
|
257
|
+
se01BootBuildId: imageBuildId(info.se1?.bootloader),
|
|
258
|
+
se01BootHash: imageHash(info.se1?.bootloader),
|
|
259
|
+
se02BootBuildId: imageBuildId(info.se2?.bootloader),
|
|
260
|
+
se02BootHash: imageHash(info.se2?.bootloader),
|
|
261
|
+
se03BootBuildId: imageBuildId(info.se3?.bootloader),
|
|
262
|
+
se03BootHash: imageHash(info.se3?.bootloader),
|
|
263
|
+
se04BootBuildId: imageBuildId(info.se4?.bootloader),
|
|
264
|
+
se04BootHash: imageHash(info.se4?.bootloader),
|
|
265
|
+
}),
|
|
266
|
+
raw: {
|
|
267
|
+
protocolV2DeviceInfo: info,
|
|
268
|
+
...(loader ? { protocolV2DeviceStatus: null } : {}),
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
export const mapProtocolV2DeviceStatusToState = (status: DeviceStatus): DeviceStatePatch => ({
|
|
274
|
+
identity: definedEntries({ deviceId: status.device_id }),
|
|
275
|
+
status: definedEntries({
|
|
276
|
+
mode: getProtocolV2StatusMode(status.init_states),
|
|
277
|
+
initialized: status.init_states,
|
|
278
|
+
unlocked: status.unlocked,
|
|
279
|
+
passphraseProtection: status.unlocked === true ? status.passphrase_enabled ?? null : undefined,
|
|
280
|
+
backupRequired: status.backup_required,
|
|
281
|
+
attachToPinEnabled: status.attach_to_pin_enabled,
|
|
282
|
+
unlockedAttachPin: status.unlocked_by_attach_to_pin,
|
|
283
|
+
}),
|
|
284
|
+
raw: { protocolV2DeviceStatus: status },
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
export const mapApplySettingsToState = (settings: ApplySettings): DeviceStatePatch => {
|
|
288
|
+
const identity = definedEntries({ label: settings.label });
|
|
289
|
+
const status = definedEntries({ passphraseProtection: settings.use_passphrase });
|
|
290
|
+
const stateSettings = definedEntries({
|
|
291
|
+
language: settings.language,
|
|
292
|
+
autoLockDelayMs: settings.auto_lock_delay_ms,
|
|
293
|
+
autoShutdownDelayMs: settings.auto_shutdown_delay_ms,
|
|
294
|
+
displayRotation: settings.display_rotation,
|
|
295
|
+
passphraseAlwaysOnDevice: settings.passphrase_always_on_device,
|
|
296
|
+
safetyChecks: normalizeSafetyCheckLevel(settings.safety_checks),
|
|
297
|
+
experimentalFeatures: settings.experimental_features,
|
|
298
|
+
hapticFeedback: settings.haptic_feedback,
|
|
299
|
+
bleEnabled: settings.use_ble,
|
|
300
|
+
});
|
|
301
|
+
return {
|
|
302
|
+
...(Object.keys(identity).length ? { identity } : {}),
|
|
303
|
+
...(Object.keys(status).length ? { status } : {}),
|
|
304
|
+
...(Object.keys(stateSettings).length ? { settings: stateSettings } : {}),
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
export const mapDeviceSettingsToState = (settings: DeviceSettings): DeviceStatePatch => {
|
|
309
|
+
const identity = definedEntries({ label: settings.label });
|
|
310
|
+
const status = definedEntries({ passphraseProtection: settings.passphrase_enable });
|
|
311
|
+
const stateSettings = definedEntries({
|
|
312
|
+
bleEnabled: settings.bt_enable,
|
|
313
|
+
language: mapLanguageFromProtocolV2(settings.language),
|
|
314
|
+
wallpaperPath: settings.wallpaper_path,
|
|
315
|
+
brightness: settings.brightness,
|
|
316
|
+
autoLockDelayMs: settings.autolock_delay_ms,
|
|
317
|
+
autoShutdownDelayMs: settings.autoshutdown_delay_ms,
|
|
318
|
+
animationEnabled: settings.animation_enable,
|
|
319
|
+
tapToWake: settings.tap_to_wake,
|
|
320
|
+
hapticFeedback: settings.haptic_feedback,
|
|
321
|
+
deviceNameDisplayEnabled: settings.device_name_display_enabled,
|
|
322
|
+
airgapMode: settings.airgap_mode,
|
|
323
|
+
fidoEnabled: settings.fido_enabled,
|
|
324
|
+
usbLockEnabled: settings.usb_lock_enable,
|
|
325
|
+
randomKeypad: settings.random_keypad,
|
|
326
|
+
});
|
|
327
|
+
return {
|
|
328
|
+
...(Object.keys(identity).length ? { identity } : {}),
|
|
329
|
+
...(Object.keys(status).length ? { status } : {}),
|
|
330
|
+
...(Object.keys(stateSettings).length ? { settings: stateSettings } : {}),
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
export const mapCommonSettingsToProtocolV2 = (settings: DeviceSettingsParams): DeviceSettings =>
|
|
335
|
+
definedEntries({
|
|
336
|
+
label: settings.label,
|
|
337
|
+
bt_enable: settings.bluetoothEnabled,
|
|
338
|
+
language: mapLanguageToProtocolV2(settings.language),
|
|
339
|
+
brightness: settings.brightness,
|
|
340
|
+
autolock_delay_ms: settings.autoLockDelayMs,
|
|
341
|
+
autoshutdown_delay_ms: settings.autoShutdownDelayMs,
|
|
342
|
+
animation_enable: settings.animationEnabled,
|
|
343
|
+
tap_to_wake: settings.tapToWake,
|
|
344
|
+
haptic_feedback: settings.hapticFeedback,
|
|
345
|
+
device_name_display_enabled: settings.deviceNameDisplayEnabled,
|
|
346
|
+
fido_enabled: settings.fidoEnabled,
|
|
347
|
+
usb_lock_enable: settings.usbLockEnabled,
|
|
348
|
+
random_keypad: settings.randomKeypad,
|
|
349
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { cloneDeviceState } from './cloneDeviceState';
|
|
2
|
+
|
|
3
|
+
import type { DeviceFeaturesRaw, DeviceState, Features } from '../types';
|
|
4
|
+
|
|
5
|
+
type StoredDeviceState = DeviceState & {
|
|
6
|
+
raw?: DeviceFeaturesRaw;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const getBootloaderMode = (state: StoredDeviceState) =>
|
|
10
|
+
state.status.mode === 'bootloader' || state.status.mode === 'romloader';
|
|
11
|
+
|
|
12
|
+
export const projectFeatures = (state: StoredDeviceState): Features => {
|
|
13
|
+
const snapshot = cloneDeviceState(state);
|
|
14
|
+
const rawFeatures = snapshot.raw?.protocolV1Features ?? {};
|
|
15
|
+
const publicRawFeatures = { ...rawFeatures } as Record<string, unknown>;
|
|
16
|
+
delete publicRawFeatures.session_id;
|
|
17
|
+
delete publicRawFeatures.sessionId;
|
|
18
|
+
delete publicRawFeatures.passphraseState;
|
|
19
|
+
const rawOneKeyFeatures = snapshot.raw?.protocolV1OneKeyFeatures ?? {};
|
|
20
|
+
const bootloaderMode =
|
|
21
|
+
snapshot.protocol === 'V1'
|
|
22
|
+
? (rawFeatures as { bootloader_mode?: boolean | null }).bootloader_mode ?? null
|
|
23
|
+
: getBootloaderMode(snapshot);
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
...publicRawFeatures,
|
|
27
|
+
...rawOneKeyFeatures,
|
|
28
|
+
protocol: snapshot.protocol,
|
|
29
|
+
protocolVersion: snapshot.protocolVersion ?? (snapshot.protocol === 'V1' ? 1 : null),
|
|
30
|
+
deviceType: snapshot.identity.deviceType,
|
|
31
|
+
firmwareType: snapshot.identity.firmwareType,
|
|
32
|
+
model: snapshot.identity.model,
|
|
33
|
+
vendor: snapshot.identity.vendor,
|
|
34
|
+
deviceId: snapshot.identity.deviceId,
|
|
35
|
+
serialNo: snapshot.identity.serialNo,
|
|
36
|
+
label: snapshot.identity.label,
|
|
37
|
+
bleName: snapshot.identity.bleName,
|
|
38
|
+
capabilities: snapshot.capabilities,
|
|
39
|
+
mode: snapshot.status.mode,
|
|
40
|
+
initialized: snapshot.status.initialized,
|
|
41
|
+
bootloaderMode,
|
|
42
|
+
unlocked: snapshot.status.unlocked,
|
|
43
|
+
firmwarePresent: snapshot.status.firmwarePresent,
|
|
44
|
+
passphraseProtection: snapshot.status.passphraseProtection,
|
|
45
|
+
pinProtection: snapshot.status.pinProtection,
|
|
46
|
+
backupRequired: snapshot.status.backupRequired,
|
|
47
|
+
noBackup: snapshot.status.noBackup,
|
|
48
|
+
unfinishedBackup: snapshot.status.unfinishedBackup,
|
|
49
|
+
recoveryMode: snapshot.status.recoveryMode,
|
|
50
|
+
attachToPinEnabled: snapshot.status.attachToPinEnabled,
|
|
51
|
+
unlockedAttachPin: snapshot.status.unlockedAttachPin ?? undefined,
|
|
52
|
+
language: snapshot.settings.language,
|
|
53
|
+
bleEnabled: snapshot.settings.bleEnabled,
|
|
54
|
+
sdCardPresent: snapshot.settings.sdCardPresent,
|
|
55
|
+
sdProtection: snapshot.settings.sdProtection,
|
|
56
|
+
wipeCodeProtection: snapshot.settings.wipeCodeProtection,
|
|
57
|
+
passphraseAlwaysOnDevice: snapshot.settings.passphraseAlwaysOnDevice,
|
|
58
|
+
safetyChecks: snapshot.settings.safetyChecks,
|
|
59
|
+
autoLockDelayMs: snapshot.settings.autoLockDelayMs,
|
|
60
|
+
autoShutdownDelayMs: snapshot.settings.autoShutdownDelayMs,
|
|
61
|
+
displayRotation: snapshot.settings.displayRotation,
|
|
62
|
+
experimentalFeatures: snapshot.settings.experimentalFeatures,
|
|
63
|
+
wallpaperPath: snapshot.settings.wallpaperPath,
|
|
64
|
+
brightness: snapshot.settings.brightness,
|
|
65
|
+
animationEnabled: snapshot.settings.animationEnabled,
|
|
66
|
+
tapToWake: snapshot.settings.tapToWake,
|
|
67
|
+
hapticFeedback: snapshot.settings.hapticFeedback,
|
|
68
|
+
deviceNameDisplayEnabled: snapshot.settings.deviceNameDisplayEnabled,
|
|
69
|
+
airgapMode: snapshot.settings.airgapMode,
|
|
70
|
+
fidoEnabled: snapshot.settings.fidoEnabled,
|
|
71
|
+
usbLockEnabled: snapshot.settings.usbLockEnabled,
|
|
72
|
+
randomKeypad: snapshot.settings.randomKeypad,
|
|
73
|
+
firmwareVersion: snapshot.versions.firmware,
|
|
74
|
+
bootloaderVersion: snapshot.versions.bootloader,
|
|
75
|
+
boardVersion: snapshot.versions.board,
|
|
76
|
+
bleVersion: snapshot.versions.ble,
|
|
77
|
+
se01Version: snapshot.versions.se01,
|
|
78
|
+
se02Version: snapshot.versions.se02,
|
|
79
|
+
se03Version: snapshot.versions.se03,
|
|
80
|
+
se04Version: snapshot.versions.se04,
|
|
81
|
+
se01BootVersion: snapshot.versions.se01Boot,
|
|
82
|
+
se02BootVersion: snapshot.versions.se02Boot,
|
|
83
|
+
se03BootVersion: snapshot.versions.se03Boot,
|
|
84
|
+
se04BootVersion: snapshot.versions.se04Boot,
|
|
85
|
+
seVersion: snapshot.versions.se ?? null,
|
|
86
|
+
verify: snapshot.verification,
|
|
87
|
+
raw: snapshot.raw,
|
|
88
|
+
device_id: snapshot.identity.deviceId ?? undefined,
|
|
89
|
+
ble_name: snapshot.identity.bleName ?? undefined,
|
|
90
|
+
passphrase_protection: snapshot.status.passphraseProtection ?? undefined,
|
|
91
|
+
bootloader_mode: bootloaderMode,
|
|
92
|
+
sessionId: null,
|
|
93
|
+
session_id: null,
|
|
94
|
+
} as unknown as Features;
|
|
95
|
+
};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import { cloneDeviceState } from './cloneDeviceState';
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
DeviceFeaturesRaw,
|
|
7
|
+
DeviceState,
|
|
8
|
+
DeviceStateIdentity,
|
|
9
|
+
DeviceStatePatch,
|
|
10
|
+
DeviceStateUpdateSource,
|
|
11
|
+
} from '../types';
|
|
12
|
+
|
|
13
|
+
type StoredDeviceState = DeviceState & {
|
|
14
|
+
raw?: DeviceFeaturesRaw;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type DeviceStateUpdateResult = {
|
|
18
|
+
state: StoredDeviceState;
|
|
19
|
+
revision: number;
|
|
20
|
+
source: DeviceStateUpdateSource;
|
|
21
|
+
changedKeys: string[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function createEmptyDeviceState(
|
|
25
|
+
identity: Partial<DeviceStateIdentity> = {}
|
|
26
|
+
): StoredDeviceState {
|
|
27
|
+
const normalizedIdentity: DeviceStateIdentity = {
|
|
28
|
+
deviceType: EDeviceType.Unknown,
|
|
29
|
+
firmwareType: EFirmwareType.Universal,
|
|
30
|
+
model: null,
|
|
31
|
+
vendor: null,
|
|
32
|
+
deviceId: null,
|
|
33
|
+
serialNo: '',
|
|
34
|
+
label: null,
|
|
35
|
+
bleName: null,
|
|
36
|
+
...identity,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
schemaVersion: 1,
|
|
41
|
+
revision: 0,
|
|
42
|
+
updatedAt: Date.now(),
|
|
43
|
+
protocol: 'unknown',
|
|
44
|
+
protocolVersion: null,
|
|
45
|
+
identity: normalizedIdentity,
|
|
46
|
+
status: {
|
|
47
|
+
mode: 'unknown',
|
|
48
|
+
initialized: null,
|
|
49
|
+
unlocked: null,
|
|
50
|
+
firmwarePresent: null,
|
|
51
|
+
backupRequired: null,
|
|
52
|
+
noBackup: null,
|
|
53
|
+
unfinishedBackup: null,
|
|
54
|
+
recoveryMode: null,
|
|
55
|
+
passphraseProtection: null,
|
|
56
|
+
pinProtection: null,
|
|
57
|
+
attachToPinEnabled: null,
|
|
58
|
+
unlockedAttachPin: null,
|
|
59
|
+
},
|
|
60
|
+
settings: {
|
|
61
|
+
language: null,
|
|
62
|
+
bleEnabled: null,
|
|
63
|
+
sdCardPresent: null,
|
|
64
|
+
sdProtection: null,
|
|
65
|
+
wipeCodeProtection: null,
|
|
66
|
+
passphraseAlwaysOnDevice: null,
|
|
67
|
+
safetyChecks: null,
|
|
68
|
+
autoLockDelayMs: null,
|
|
69
|
+
autoShutdownDelayMs: null,
|
|
70
|
+
displayRotation: null,
|
|
71
|
+
experimentalFeatures: null,
|
|
72
|
+
wallpaperPath: null,
|
|
73
|
+
brightness: null,
|
|
74
|
+
animationEnabled: null,
|
|
75
|
+
tapToWake: null,
|
|
76
|
+
hapticFeedback: null,
|
|
77
|
+
deviceNameDisplayEnabled: null,
|
|
78
|
+
airgapMode: null,
|
|
79
|
+
fidoEnabled: null,
|
|
80
|
+
usbLockEnabled: null,
|
|
81
|
+
randomKeypad: null,
|
|
82
|
+
},
|
|
83
|
+
versions: {
|
|
84
|
+
firmware: null,
|
|
85
|
+
bootloader: null,
|
|
86
|
+
board: null,
|
|
87
|
+
ble: null,
|
|
88
|
+
},
|
|
89
|
+
capabilities: [],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const isEqual = (left: unknown, right: unknown) => JSON.stringify(left) === JSON.stringify(right);
|
|
94
|
+
|
|
95
|
+
const applySectionPatch = <T extends object>(
|
|
96
|
+
target: T,
|
|
97
|
+
patch: Partial<T>,
|
|
98
|
+
prefix: string,
|
|
99
|
+
changedKeys: string[]
|
|
100
|
+
) => {
|
|
101
|
+
for (const [key, value] of Object.entries(patch) as [keyof T, T[keyof T] | undefined][]) {
|
|
102
|
+
if (value !== undefined && !isEqual(target[key], value)) {
|
|
103
|
+
target[key] = value;
|
|
104
|
+
changedKeys.push(`${prefix}.${String(key)}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export class DeviceStateStore {
|
|
110
|
+
private state: StoredDeviceState | undefined;
|
|
111
|
+
|
|
112
|
+
constructor(initial?: StoredDeviceState) {
|
|
113
|
+
this.state = initial ? cloneDeviceState(initial) : undefined;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
getState() {
|
|
117
|
+
return this.state;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
replace(state: StoredDeviceState, source: DeviceStateUpdateSource): DeviceStateUpdateResult {
|
|
121
|
+
const revision = (this.state?.revision ?? 0) + 1;
|
|
122
|
+
this.state = {
|
|
123
|
+
...cloneDeviceState(state),
|
|
124
|
+
revision,
|
|
125
|
+
updatedAt: Date.now(),
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
state: this.state,
|
|
129
|
+
revision,
|
|
130
|
+
source,
|
|
131
|
+
changedKeys: ['*'],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
update(patch: DeviceStatePatch, source: DeviceStateUpdateSource): DeviceStateUpdateResult {
|
|
136
|
+
const next = cloneDeviceState(this.state ?? createEmptyDeviceState());
|
|
137
|
+
const changedKeys: string[] = [];
|
|
138
|
+
|
|
139
|
+
if (patch.protocol !== undefined && patch.protocol !== next.protocol) {
|
|
140
|
+
next.protocol = patch.protocol;
|
|
141
|
+
changedKeys.push('protocol');
|
|
142
|
+
}
|
|
143
|
+
if (patch.protocolVersion !== undefined && patch.protocolVersion !== next.protocolVersion) {
|
|
144
|
+
next.protocolVersion = patch.protocolVersion;
|
|
145
|
+
changedKeys.push('protocolVersion');
|
|
146
|
+
}
|
|
147
|
+
if (patch.identity) applySectionPatch(next.identity, patch.identity, 'identity', changedKeys);
|
|
148
|
+
if (patch.status) applySectionPatch(next.status, patch.status, 'status', changedKeys);
|
|
149
|
+
if (patch.settings) applySectionPatch(next.settings, patch.settings, 'settings', changedKeys);
|
|
150
|
+
if (patch.versions) applySectionPatch(next.versions, patch.versions, 'versions', changedKeys);
|
|
151
|
+
|
|
152
|
+
if (patch.capabilities !== undefined && !isEqual(next.capabilities, patch.capabilities)) {
|
|
153
|
+
next.capabilities = cloneDeviceState(patch.capabilities);
|
|
154
|
+
changedKeys.push('capabilities');
|
|
155
|
+
}
|
|
156
|
+
if (patch.verification !== undefined) {
|
|
157
|
+
const mergedVerification = {
|
|
158
|
+
...cloneDeviceState(next.verification ?? {}),
|
|
159
|
+
...cloneDeviceState(patch.verification),
|
|
160
|
+
};
|
|
161
|
+
if (!isEqual(next.verification, mergedVerification)) {
|
|
162
|
+
next.verification = mergedVerification;
|
|
163
|
+
changedKeys.push('verification');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (patch.raw !== undefined) {
|
|
167
|
+
const mergedRaw = cloneDeviceState(next.raw ?? {});
|
|
168
|
+
for (const [key, value] of Object.entries(patch.raw)) {
|
|
169
|
+
if (value === null) {
|
|
170
|
+
delete mergedRaw[key as keyof typeof mergedRaw];
|
|
171
|
+
} else if (value !== undefined) {
|
|
172
|
+
mergedRaw[key as keyof typeof mergedRaw] = cloneDeviceState(value) as never;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (!isEqual(next.raw, mergedRaw)) {
|
|
176
|
+
next.raw = mergedRaw;
|
|
177
|
+
changedKeys.push('raw');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (changedKeys.length > 0) {
|
|
181
|
+
next.revision = (this.state?.revision ?? 0) + 1;
|
|
182
|
+
next.updatedAt = Date.now();
|
|
183
|
+
this.state = next;
|
|
184
|
+
} else if (!this.state) {
|
|
185
|
+
this.state = next;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
state: this.state,
|
|
190
|
+
revision: this.state.revision,
|
|
191
|
+
source,
|
|
192
|
+
changedKeys,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export const createPublicDeviceState = (state: StoredDeviceState): DeviceState => {
|
|
198
|
+
const snapshot = cloneDeviceState(state);
|
|
199
|
+
delete snapshot.raw;
|
|
200
|
+
return snapshot;
|
|
201
|
+
};
|