@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,92 @@
|
|
|
1
|
+
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import { writeProtocolV2File } from '../src/api/helpers/protocolV2FileWrite';
|
|
4
|
+
|
|
5
|
+
jest.mock('../src/data/config', () => ({
|
|
6
|
+
getSDKVersion: jest.fn(() => '1.0.0'),
|
|
7
|
+
DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
describe('writeProtocolV2File', () => {
|
|
11
|
+
test('按分片写入并只在首片设置 overwrite', async () => {
|
|
12
|
+
const data = new Uint8Array(4097);
|
|
13
|
+
const typedCall = jest.fn().mockResolvedValue({ message: {} });
|
|
14
|
+
const onProgress = jest.fn();
|
|
15
|
+
|
|
16
|
+
const result = await writeProtocolV2File({
|
|
17
|
+
commands: { typedCall } as any,
|
|
18
|
+
path: 'vol1:/wallpapers/test.bin',
|
|
19
|
+
data,
|
|
20
|
+
totalSize: data.byteLength,
|
|
21
|
+
overwrite: true,
|
|
22
|
+
onProgress,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
expect(typedCall).toHaveBeenCalledTimes(2);
|
|
26
|
+
expect(typedCall.mock.calls[0][2]).toMatchObject({
|
|
27
|
+
file: { offset: 0, total_size: 4097, data: data.slice(0, 4000) },
|
|
28
|
+
overwrite: true,
|
|
29
|
+
append: false,
|
|
30
|
+
ui_percentage: 0,
|
|
31
|
+
});
|
|
32
|
+
expect(typedCall.mock.calls[1][2]).toMatchObject({
|
|
33
|
+
file: { offset: 4000, total_size: 4097, data: data.slice(4000) },
|
|
34
|
+
overwrite: false,
|
|
35
|
+
append: false,
|
|
36
|
+
ui_percentage: 100,
|
|
37
|
+
});
|
|
38
|
+
expect(result).toMatchObject({ processed_byte: 4097, chunks: 2 });
|
|
39
|
+
expect(onProgress).toHaveBeenLastCalledWith(
|
|
40
|
+
expect.objectContaining({ progress: 100, transferredBytes: 4097, totalBytes: 4097 })
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('拒绝越过文件末尾的 processed_byte', async () => {
|
|
45
|
+
const typedCall = jest.fn().mockResolvedValue({ message: { processed_byte: 10 } });
|
|
46
|
+
|
|
47
|
+
await expect(
|
|
48
|
+
writeProtocolV2File({
|
|
49
|
+
commands: { typedCall } as any,
|
|
50
|
+
path: 'vol1:/wallpapers/test.bin',
|
|
51
|
+
data: new Uint8Array([1]),
|
|
52
|
+
})
|
|
53
|
+
).rejects.toMatchObject({ errorCode: HardwareErrorCode.RuntimeError });
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('设备返回未前进的绝对 processed_byte 时立即失败', async () => {
|
|
57
|
+
const typedCall = jest.fn().mockResolvedValue({ message: { processed_byte: 0 } });
|
|
58
|
+
|
|
59
|
+
await expect(
|
|
60
|
+
writeProtocolV2File({
|
|
61
|
+
commands: { typedCall } as any,
|
|
62
|
+
path: 'vol1:/wallpapers/test.bin',
|
|
63
|
+
data: new Uint8Array([1, 2, 3]),
|
|
64
|
+
})
|
|
65
|
+
).rejects.toMatchObject({ errorCode: HardwareErrorCode.RuntimeError });
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('BLE 响应超时时原偏移重试且不重复上报进度', async () => {
|
|
69
|
+
const timeoutError = Object.assign(new Error('Lowlevel response timeout'), {
|
|
70
|
+
errorCode: HardwareErrorCode.BleTimeoutError,
|
|
71
|
+
});
|
|
72
|
+
const typedCall = jest
|
|
73
|
+
.fn()
|
|
74
|
+
.mockRejectedValueOnce(timeoutError)
|
|
75
|
+
.mockResolvedValueOnce({ message: { processed_byte: 3 } });
|
|
76
|
+
const onProgress = jest.fn();
|
|
77
|
+
|
|
78
|
+
await expect(
|
|
79
|
+
writeProtocolV2File({
|
|
80
|
+
commands: { typedCall } as any,
|
|
81
|
+
path: 'vol1:/wallpapers/test.bin',
|
|
82
|
+
data: new Uint8Array([1, 2, 3]),
|
|
83
|
+
maxChunkRetries: 2,
|
|
84
|
+
onProgress,
|
|
85
|
+
})
|
|
86
|
+
).resolves.toMatchObject({ processed_byte: 3, chunks: 1 });
|
|
87
|
+
|
|
88
|
+
expect(typedCall).toHaveBeenCalledTimes(2);
|
|
89
|
+
expect(typedCall.mock.calls[1][2]).toEqual(typedCall.mock.calls[0][2]);
|
|
90
|
+
expect(onProgress).toHaveBeenCalledTimes(1);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { UI_REQUEST } from '../src/events';
|
|
2
|
+
import {
|
|
3
|
+
ProtocolV2UiInteractionCoordinator,
|
|
4
|
+
isProtocolV2UiEnabled,
|
|
5
|
+
resolveProtocolV2UiInteraction,
|
|
6
|
+
} from '../src/protocols/protocol-v2/uiInteraction';
|
|
7
|
+
|
|
8
|
+
const createDevice = (protocolV2 = true) => ({
|
|
9
|
+
isProtocolV2: jest.fn(() => protocolV2),
|
|
10
|
+
toMessageObject: jest.fn(() => ({ connectId: 'pro2-test', deviceType: 'pro2' })),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const changePinInteraction = {
|
|
14
|
+
request: 'button',
|
|
15
|
+
source: 'method-lifecycle',
|
|
16
|
+
reason: 'change-pin',
|
|
17
|
+
completion: 'page-accepted',
|
|
18
|
+
deviceOnly: true,
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
describe('ProtocolV2UiInteractionCoordinator', () => {
|
|
22
|
+
test('does not synthesize UI events for Protocol V1 devices', () => {
|
|
23
|
+
const postMessage = jest.fn();
|
|
24
|
+
const coordinator = new ProtocolV2UiInteractionCoordinator(
|
|
25
|
+
createDevice(false) as any,
|
|
26
|
+
postMessage
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
coordinator.enterMethodInteraction(changePinInteraction);
|
|
30
|
+
coordinator.enterUnlockInteraction('deviceChangePin');
|
|
31
|
+
coordinator.close();
|
|
32
|
+
|
|
33
|
+
expect(postMessage).not.toHaveBeenCalled();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('synthesizes and deduplicates a Protocol V2 method interaction', () => {
|
|
37
|
+
const postMessage = jest.fn();
|
|
38
|
+
const device = createDevice();
|
|
39
|
+
const coordinator = new ProtocolV2UiInteractionCoordinator(device as any, postMessage);
|
|
40
|
+
|
|
41
|
+
coordinator.enterMethodInteraction(changePinInteraction);
|
|
42
|
+
coordinator.enterMethodInteraction(changePinInteraction);
|
|
43
|
+
|
|
44
|
+
expect(postMessage).toHaveBeenCalledTimes(1);
|
|
45
|
+
expect(postMessage).toHaveBeenCalledWith({
|
|
46
|
+
event: 'UI_EVENT',
|
|
47
|
+
type: UI_REQUEST.REQUEST_BUTTON,
|
|
48
|
+
payload: {
|
|
49
|
+
device: { connectId: 'pro2-test', deviceType: 'pro2' },
|
|
50
|
+
source: 'method-lifecycle',
|
|
51
|
+
reason: 'change-pin',
|
|
52
|
+
completion: 'page-accepted',
|
|
53
|
+
deviceOnly: true,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('synthesizes a PIN prompt for an explicit Protocol V2 unlock method', () => {
|
|
59
|
+
const postMessage = jest.fn();
|
|
60
|
+
const coordinator = new ProtocolV2UiInteractionCoordinator(createDevice() as any, postMessage);
|
|
61
|
+
|
|
62
|
+
coordinator.enterMethodInteraction({
|
|
63
|
+
request: 'pin',
|
|
64
|
+
source: 'method-lifecycle',
|
|
65
|
+
reason: 'device-unlock',
|
|
66
|
+
completion: 'operation-completed',
|
|
67
|
+
deviceOnly: true,
|
|
68
|
+
operation: 'unlock-device',
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(postMessage.mock.calls.map(([message]) => message.type)).toEqual([
|
|
72
|
+
UI_REQUEST.REQUEST_PIN,
|
|
73
|
+
]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('switches to unlock prompt and restores the method interaction', () => {
|
|
77
|
+
const postMessage = jest.fn();
|
|
78
|
+
const coordinator = new ProtocolV2UiInteractionCoordinator(createDevice() as any, postMessage);
|
|
79
|
+
|
|
80
|
+
coordinator.enterMethodInteraction(changePinInteraction);
|
|
81
|
+
coordinator.enterUnlockInteraction('deviceChangePin');
|
|
82
|
+
coordinator.resumeMethodInteraction();
|
|
83
|
+
|
|
84
|
+
expect(postMessage.mock.calls.map(([message]) => message.type)).toEqual([
|
|
85
|
+
UI_REQUEST.REQUEST_BUTTON,
|
|
86
|
+
UI_REQUEST.REQUEST_PIN,
|
|
87
|
+
UI_REQUEST.REQUEST_BUTTON,
|
|
88
|
+
]);
|
|
89
|
+
expect(postMessage.mock.calls[1][0]).toEqual({
|
|
90
|
+
event: 'UI_EVENT',
|
|
91
|
+
type: UI_REQUEST.REQUEST_PIN,
|
|
92
|
+
payload: {
|
|
93
|
+
device: { connectId: 'pro2-test', deviceType: 'pro2' },
|
|
94
|
+
source: 'unlock-coordinator',
|
|
95
|
+
reason: 'device-locked',
|
|
96
|
+
deviceOnly: true,
|
|
97
|
+
method: 'deviceChangePin',
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('only closes an opened interaction once', () => {
|
|
103
|
+
const postMessage = jest.fn();
|
|
104
|
+
const idleCoordinator = new ProtocolV2UiInteractionCoordinator(
|
|
105
|
+
createDevice() as any,
|
|
106
|
+
postMessage
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
idleCoordinator.close();
|
|
110
|
+
expect(postMessage).not.toHaveBeenCalled();
|
|
111
|
+
|
|
112
|
+
const coordinator = new ProtocolV2UiInteractionCoordinator(createDevice() as any, postMessage);
|
|
113
|
+
coordinator.enterMethodInteraction(changePinInteraction);
|
|
114
|
+
coordinator.close();
|
|
115
|
+
coordinator.close();
|
|
116
|
+
|
|
117
|
+
expect(postMessage.mock.calls.map(([message]) => message.type)).toEqual([
|
|
118
|
+
UI_REQUEST.REQUEST_BUTTON,
|
|
119
|
+
UI_REQUEST.CLOSE_UI_WINDOW,
|
|
120
|
+
]);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('does not emit interaction events for methods without metadata such as Portfolio', () => {
|
|
124
|
+
const postMessage = jest.fn();
|
|
125
|
+
const coordinator = new ProtocolV2UiInteractionCoordinator(createDevice() as any, postMessage);
|
|
126
|
+
|
|
127
|
+
coordinator.enterMethodInteraction(undefined);
|
|
128
|
+
coordinator.close();
|
|
129
|
+
|
|
130
|
+
expect(postMessage).not.toHaveBeenCalled();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('disables both synthesized prompts and compatibility close events for Portfolio', () => {
|
|
134
|
+
expect(isProtocolV2UiEnabled({ protocolV2UiMode: 'none' })).toBe(false);
|
|
135
|
+
expect(isProtocolV2UiEnabled({ protocolV2UiMode: 'auto' })).toBe(true);
|
|
136
|
+
expect(isProtocolV2UiEnabled({})).toBe(true);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe('resolveProtocolV2UiInteraction', () => {
|
|
141
|
+
test('keeps explicit method metadata as the highest-priority policy', () => {
|
|
142
|
+
expect(
|
|
143
|
+
resolveProtocolV2UiInteraction({
|
|
144
|
+
name: 'evmSignMessage',
|
|
145
|
+
params: {},
|
|
146
|
+
protocolV2UiInteraction: changePinInteraction,
|
|
147
|
+
})
|
|
148
|
+
).toBe(changePinInteraction);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test.each([
|
|
152
|
+
['evmGetAddress', 'address-confirmation'],
|
|
153
|
+
['btcGetPublicKey', 'public-key-confirmation'],
|
|
154
|
+
])('synthesizes display confirmation metadata for %s', (name, reason) => {
|
|
155
|
+
expect(
|
|
156
|
+
resolveProtocolV2UiInteraction({
|
|
157
|
+
name,
|
|
158
|
+
params: [{ show_display: false }, { show_display: true }],
|
|
159
|
+
})
|
|
160
|
+
).toEqual({
|
|
161
|
+
request: 'button',
|
|
162
|
+
source: 'method-lifecycle',
|
|
163
|
+
reason,
|
|
164
|
+
completion: 'operation-completed',
|
|
165
|
+
deviceOnly: true,
|
|
166
|
+
operation: name,
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test.each(['evmGetAddress', 'btcGetPublicKey'])('keeps non-display %s calls eventless', name => {
|
|
171
|
+
expect(
|
|
172
|
+
resolveProtocolV2UiInteraction({
|
|
173
|
+
name,
|
|
174
|
+
params: [{ show_display: false }],
|
|
175
|
+
})
|
|
176
|
+
).toBeUndefined();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('uses the public address payload for aggregate address methods', () => {
|
|
180
|
+
expect(
|
|
181
|
+
resolveProtocolV2UiInteraction({
|
|
182
|
+
name: 'allNetworkGetAddress',
|
|
183
|
+
params: undefined,
|
|
184
|
+
payload: {
|
|
185
|
+
bundle: [{ showOnOneKey: false }, { showOnOneKey: true }],
|
|
186
|
+
},
|
|
187
|
+
})
|
|
188
|
+
).toMatchObject({
|
|
189
|
+
reason: 'address-confirmation',
|
|
190
|
+
operation: 'allNetworkGetAddress',
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test('covers the loop-based aggregate address method', () => {
|
|
195
|
+
expect(
|
|
196
|
+
resolveProtocolV2UiInteraction({
|
|
197
|
+
name: 'allNetworkGetAddressByLoop',
|
|
198
|
+
payload: { bundle: [{ showOnOneKey: true }] },
|
|
199
|
+
})
|
|
200
|
+
).toMatchObject({
|
|
201
|
+
reason: 'address-confirmation',
|
|
202
|
+
operation: 'allNetworkGetAddressByLoop',
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test.each([
|
|
207
|
+
'evmSignMessage',
|
|
208
|
+
'evmSignTransaction',
|
|
209
|
+
'btcSignPsbt',
|
|
210
|
+
'nostrSignEvent',
|
|
211
|
+
'tonSignProof',
|
|
212
|
+
'lnurlAuth',
|
|
213
|
+
'btcVerifyMessage',
|
|
214
|
+
'evmVerifyMessage',
|
|
215
|
+
'starcoinVerifyMessage',
|
|
216
|
+
])('synthesizes one generic signing confirmation for %s', name => {
|
|
217
|
+
expect(resolveProtocolV2UiInteraction({ name, params: {} })).toEqual({
|
|
218
|
+
request: 'button',
|
|
219
|
+
source: 'method-lifecycle',
|
|
220
|
+
reason: 'signing-confirmation',
|
|
221
|
+
completion: 'operation-completed',
|
|
222
|
+
deviceOnly: true,
|
|
223
|
+
operation: name,
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test.each(['nostrEncryptMessage', 'nostrDecryptMessage'])(
|
|
228
|
+
'uses the display flag for interactive cryptographic method %s',
|
|
229
|
+
name => {
|
|
230
|
+
expect(
|
|
231
|
+
resolveProtocolV2UiInteraction({ name, params: { show_display: true } })
|
|
232
|
+
).toMatchObject({
|
|
233
|
+
reason: 'signing-confirmation',
|
|
234
|
+
operation: name,
|
|
235
|
+
});
|
|
236
|
+
expect(
|
|
237
|
+
resolveProtocolV2UiInteraction({ name, params: { show_display: false } })
|
|
238
|
+
).toBeUndefined();
|
|
239
|
+
}
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
test('only prompts for cipherKeyValue when the active direction asks for confirmation', () => {
|
|
243
|
+
expect(
|
|
244
|
+
resolveProtocolV2UiInteraction({
|
|
245
|
+
name: 'cipherKeyValue',
|
|
246
|
+
params: [{ encrypt: true, ask_on_encrypt: true, ask_on_decrypt: false }],
|
|
247
|
+
})
|
|
248
|
+
).toMatchObject({
|
|
249
|
+
reason: 'signing-confirmation',
|
|
250
|
+
operation: 'cipherKeyValue',
|
|
251
|
+
});
|
|
252
|
+
expect(
|
|
253
|
+
resolveProtocolV2UiInteraction({
|
|
254
|
+
name: 'cipherKeyValue',
|
|
255
|
+
params: [{ encrypt: false, ask_on_encrypt: true, ask_on_decrypt: false }],
|
|
256
|
+
})
|
|
257
|
+
).toBeUndefined();
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test.each(['deviceVerify', 'deviceStatusGet', 'uploadPortfolio'])(
|
|
261
|
+
'does not infer an interaction for %s',
|
|
262
|
+
name => {
|
|
263
|
+
expect(resolveProtocolV2UiInteraction({ name, params: {} })).toBeUndefined();
|
|
264
|
+
}
|
|
265
|
+
);
|
|
266
|
+
});
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import * as publicMethods from '../src/api';
|
|
2
|
+
import GetFeatures from '../src/api/GetFeatures';
|
|
3
|
+
import GetOnekeyFeatures from '../src/api/GetOnekeyFeatures';
|
|
4
|
+
import DeviceInfoGet from '../src/api/protocol-v2/DeviceInfoGet';
|
|
5
|
+
import DeviceStatusGet from '../src/api/protocol-v2/DeviceStatusGet';
|
|
6
|
+
import { createEmptyDeviceState } from '../src/device/DeviceStateStore';
|
|
7
|
+
import { findMethod } from '../src/api/utils';
|
|
8
|
+
import { createCoreApi } from '../src/inject';
|
|
9
|
+
|
|
10
|
+
import type { CoreApi } from '../src/types/api';
|
|
11
|
+
|
|
12
|
+
jest.mock('../src/data/config', () => ({
|
|
13
|
+
DEFAULT_DOMAIN: 'https://example.com/',
|
|
14
|
+
getSDKVersion: () => '0.0.0-test',
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
describe('public device state API boundary', () => {
|
|
18
|
+
test('exposes canonical device state operations without raw settings methods', () => {
|
|
19
|
+
const api = createCoreApi(jest.fn() as CoreApi['call']) as Record<string, unknown>;
|
|
20
|
+
|
|
21
|
+
expect(api.getDeviceState).toBeInstanceOf(Function);
|
|
22
|
+
expect(api.getPassphraseState).toBeInstanceOf(Function);
|
|
23
|
+
expect(api.openWalletSession).toBeInstanceOf(Function);
|
|
24
|
+
expect(api.clearSessionCache).toBeInstanceOf(Function);
|
|
25
|
+
expect(api.deviceGetOnboardingStatus).toBeInstanceOf(Function);
|
|
26
|
+
expect(api.uploadPortfolio).toBeInstanceOf(Function);
|
|
27
|
+
expect(api).not.toHaveProperty('refreshDeviceState');
|
|
28
|
+
expect(api.getFeatures).toBeInstanceOf(Function);
|
|
29
|
+
expect(api.getOnekeyFeatures).toBeInstanceOf(Function);
|
|
30
|
+
expect(api).not.toHaveProperty('getDeviceInfo');
|
|
31
|
+
expect(api.deviceInfoGet).toBeInstanceOf(Function);
|
|
32
|
+
expect(api.deviceStatusGet).toBeInstanceOf(Function);
|
|
33
|
+
expect(api).not.toHaveProperty('deviceSettingsGet');
|
|
34
|
+
expect(api).not.toHaveProperty('deviceSessionOpen');
|
|
35
|
+
expect(api).not.toHaveProperty('deviceSettingsSet');
|
|
36
|
+
expect(api).not.toHaveProperty('deviceSettingsPageShow');
|
|
37
|
+
expect(api.deviceFirmwareUpdate).toBeInstanceOf(Function);
|
|
38
|
+
expect(api.deviceGetFirmwareUpdateStatus).toBeInstanceOf(Function);
|
|
39
|
+
expect(api.deviceFactoryInfoSet).toBeInstanceOf(Function);
|
|
40
|
+
expect(api.deviceFactoryInfoGet).toBeInstanceOf(Function);
|
|
41
|
+
expect(api.filesystemPermissionFix).toBeInstanceOf(Function);
|
|
42
|
+
expect(api.filesystemFormat).toBeInstanceOf(Function);
|
|
43
|
+
expect(api.fileRead).toBeInstanceOf(Function);
|
|
44
|
+
expect(api.fileWrite).toBeInstanceOf(Function);
|
|
45
|
+
expect(api).not.toHaveProperty('filesystemFileRead');
|
|
46
|
+
expect(api).not.toHaveProperty('filesystemDirList');
|
|
47
|
+
|
|
48
|
+
expect(publicMethods).not.toHaveProperty('getDeviceInfo');
|
|
49
|
+
expect(publicMethods).toHaveProperty('deviceInfoGet');
|
|
50
|
+
expect(publicMethods).toHaveProperty('deviceStatusGet');
|
|
51
|
+
expect(publicMethods).not.toHaveProperty('deviceSettingsGet');
|
|
52
|
+
expect(publicMethods).not.toHaveProperty('deviceSessionOpen');
|
|
53
|
+
expect(publicMethods).not.toHaveProperty('deviceSettingsSet');
|
|
54
|
+
expect(publicMethods).not.toHaveProperty('deviceSettingsPageShow');
|
|
55
|
+
expect(publicMethods).toHaveProperty('filesystemPermissionFix');
|
|
56
|
+
expect(publicMethods).toHaveProperty('filesystemFormat');
|
|
57
|
+
expect(publicMethods).toHaveProperty('fileRead');
|
|
58
|
+
expect(publicMethods).toHaveProperty('fileWrite');
|
|
59
|
+
expect(publicMethods).not.toHaveProperty('filesystemFileRead');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('forwards the V1 compatibility API and the explicit V2 wallet session API', async () => {
|
|
63
|
+
const call = jest.fn().mockResolvedValue({ success: true, payload: {} });
|
|
64
|
+
const api = createCoreApi(call as CoreApi['call']) as CoreApi;
|
|
65
|
+
|
|
66
|
+
await api.getPassphraseState('device-1', {
|
|
67
|
+
initSession: true,
|
|
68
|
+
useEmptyPassphrase: false,
|
|
69
|
+
});
|
|
70
|
+
await api.openWalletSession('device-2', {
|
|
71
|
+
mode: 'resume-hidden',
|
|
72
|
+
deviceId: 'wallet-device-1',
|
|
73
|
+
passphraseState: 'wallet-state-1',
|
|
74
|
+
});
|
|
75
|
+
await api.clearSessionCache({
|
|
76
|
+
deviceId: 'wallet-device-1',
|
|
77
|
+
passphraseState: 'wallet-state-1',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(call).toHaveBeenNthCalledWith(1, {
|
|
81
|
+
connectId: 'device-1',
|
|
82
|
+
initSession: true,
|
|
83
|
+
useEmptyPassphrase: false,
|
|
84
|
+
method: 'getPassphraseState',
|
|
85
|
+
});
|
|
86
|
+
expect(call).toHaveBeenNthCalledWith(2, {
|
|
87
|
+
connectId: 'device-2',
|
|
88
|
+
mode: 'resume-hidden',
|
|
89
|
+
deviceId: 'wallet-device-1',
|
|
90
|
+
passphraseState: 'wallet-state-1',
|
|
91
|
+
method: 'openWalletSession',
|
|
92
|
+
});
|
|
93
|
+
expect(call).toHaveBeenNthCalledWith(3, {
|
|
94
|
+
deviceId: 'wallet-device-1',
|
|
95
|
+
passphraseState: 'wallet-state-1',
|
|
96
|
+
method: 'clearSessionCache',
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('forwards only the semantic scope through getDeviceState', async () => {
|
|
101
|
+
const call = jest.fn().mockResolvedValue({ success: true, payload: {} });
|
|
102
|
+
const api = createCoreApi(call as CoreApi['call']) as CoreApi;
|
|
103
|
+
|
|
104
|
+
await api.getDeviceState('device-1');
|
|
105
|
+
await (api.getDeviceState as any)('device-1', {
|
|
106
|
+
scope: 'settings',
|
|
107
|
+
refresh: ['status'],
|
|
108
|
+
includeRaw: true,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
expect(call).toHaveBeenNthCalledWith(1, {
|
|
112
|
+
connectId: 'device-1',
|
|
113
|
+
method: 'getDeviceState',
|
|
114
|
+
});
|
|
115
|
+
expect(call).toHaveBeenNthCalledWith(2, {
|
|
116
|
+
connectId: 'device-1',
|
|
117
|
+
method: 'getDeviceState',
|
|
118
|
+
scope: 'settings',
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('keeps Protocol V2 command implementations available inside the SDK', () => {
|
|
123
|
+
expect(DeviceInfoGet).toBeDefined();
|
|
124
|
+
expect(DeviceStatusGet).toBeDefined();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test.each([
|
|
128
|
+
['deviceInfoGet', DeviceInfoGet],
|
|
129
|
+
['deviceStatusGet', DeviceStatusGet],
|
|
130
|
+
])('allows the dispatcher to run the public development method %s', (name, Method) => {
|
|
131
|
+
const instance = findMethod({
|
|
132
|
+
id: 1,
|
|
133
|
+
payload: { method: name },
|
|
134
|
+
} as any);
|
|
135
|
+
|
|
136
|
+
expect(instance).toBeInstanceOf(Method);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test.each([
|
|
140
|
+
'protocolInfoRequest',
|
|
141
|
+
'ping',
|
|
142
|
+
'deviceFirmwareUpdate',
|
|
143
|
+
'deviceGetFirmwareUpdateStatus',
|
|
144
|
+
'deviceFactoryInfoSet',
|
|
145
|
+
'deviceFactoryInfoGet',
|
|
146
|
+
])('keeps the public development method %s available to the dispatcher', name => {
|
|
147
|
+
expect(
|
|
148
|
+
findMethod({
|
|
149
|
+
id: 1,
|
|
150
|
+
payload: { method: name },
|
|
151
|
+
} as any)
|
|
152
|
+
).toBeDefined();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test.each([
|
|
156
|
+
'deviceSessionOpen',
|
|
157
|
+
'deviceSettingsGet',
|
|
158
|
+
'deviceSettingsSet',
|
|
159
|
+
'deviceSettingsPageShow',
|
|
160
|
+
])('rejects removed raw method %s', name => {
|
|
161
|
+
expect(() =>
|
|
162
|
+
findMethod({
|
|
163
|
+
id: 1,
|
|
164
|
+
payload: { method: name },
|
|
165
|
+
} as any)
|
|
166
|
+
).toThrow(`Method ${name} is not set`);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test.each(['filesystemPermissionFix', 'filesystemFormat'])(
|
|
170
|
+
'keeps the development maintenance method %s available to the dispatcher',
|
|
171
|
+
name => {
|
|
172
|
+
expect(
|
|
173
|
+
findMethod({
|
|
174
|
+
id: 1,
|
|
175
|
+
payload: { method: name },
|
|
176
|
+
} as any)
|
|
177
|
+
).toBeDefined();
|
|
178
|
+
}
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
test('projects getFeatures from the canonical state for Protocol V1 compatibility', async () => {
|
|
182
|
+
const state = createEmptyDeviceState({
|
|
183
|
+
deviceId: 'device-1',
|
|
184
|
+
serialNo: 'SERIAL-1',
|
|
185
|
+
label: 'Unified',
|
|
186
|
+
});
|
|
187
|
+
const getDeviceState = jest.fn().mockResolvedValue(state);
|
|
188
|
+
const method = new GetFeatures({ id: 1, payload: { method: 'getFeatures' } });
|
|
189
|
+
method.init();
|
|
190
|
+
expect(method.unlockPolicy).toBe('none');
|
|
191
|
+
(method as any).device = {
|
|
192
|
+
getDeviceState,
|
|
193
|
+
getCurrentFirmwareType: () => 'universal',
|
|
194
|
+
isBootloader: () => false,
|
|
195
|
+
isProtocolV2: () => false,
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
await expect(method.run()).resolves.toMatchObject({
|
|
199
|
+
deviceId: 'device-1',
|
|
200
|
+
label: 'Unified',
|
|
201
|
+
});
|
|
202
|
+
expect(getDeviceState).toHaveBeenCalledWith({
|
|
203
|
+
includeRaw: true,
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test('rejects getFeatures for Protocol V2 devices', async () => {
|
|
208
|
+
const getDeviceState = jest.fn();
|
|
209
|
+
const method = new GetFeatures({ id: 1, payload: { method: 'getFeatures' } });
|
|
210
|
+
method.init();
|
|
211
|
+
expect(method.unlockPolicy).toBe('none');
|
|
212
|
+
(method as any).device = {
|
|
213
|
+
getDeviceState,
|
|
214
|
+
getCurrentFirmwareType: () => 'universal',
|
|
215
|
+
isBootloader: () => false,
|
|
216
|
+
isProtocolV2: () => true,
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
await expect(method.run()).rejects.toMatchObject({
|
|
220
|
+
errorCode: expect.any(Number),
|
|
221
|
+
});
|
|
222
|
+
expect(getDeviceState).not.toHaveBeenCalled();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('rejects getOnekeyFeatures for Protocol V2 devices', async () => {
|
|
226
|
+
const typedCall = jest.fn();
|
|
227
|
+
const method = new GetOnekeyFeatures({ id: 1, payload: { method: 'getOnekeyFeatures' } });
|
|
228
|
+
method.init();
|
|
229
|
+
expect(method.unlockPolicy).toBe('none');
|
|
230
|
+
(method as any).device = {
|
|
231
|
+
commands: { typedCall },
|
|
232
|
+
getCurrentFirmwareType: () => 'universal',
|
|
233
|
+
isProtocolV2: () => true,
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
await expect(method.run()).rejects.toMatchObject({
|
|
237
|
+
errorCode: expect.any(Number),
|
|
238
|
+
});
|
|
239
|
+
expect(typedCall).not.toHaveBeenCalled();
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// 这些临时 Pro2 查询不再属于 CoreApi;若重新暴露,下列断言会产生未使用的 ts-expect-error。
|
|
244
|
+
// @ts-expect-error getDeviceInfo 已从公共 API 删除
|
|
245
|
+
type RemovedGetDeviceInfo = CoreApi['getDeviceInfo'];
|
|
246
|
+
// @ts-expect-error deviceInfoGet 已从公共 API 删除
|
|
247
|
+
type RemovedDeviceInfoGet = CoreApi['deviceInfoGet'];
|
|
248
|
+
// @ts-expect-error deviceStatusGet 已从公共 API 删除
|
|
249
|
+
type RemovedDeviceStatusGet = CoreApi['deviceStatusGet'];
|
|
250
|
+
// @ts-expect-error deviceSettingsGet 已从公共 API 删除
|
|
251
|
+
type RemovedDeviceSettingsGet = CoreApi['deviceSettingsGet'];
|
|
252
|
+
// @ts-expect-error deviceSettingsSet 已从公共 API 删除
|
|
253
|
+
type RemovedDeviceSettingsSet = CoreApi['deviceSettingsSet'];
|
|
254
|
+
// @ts-expect-error deviceSettingsPageShow 已从公共 API 删除
|
|
255
|
+
type RemovedDeviceSettingsPageShow = CoreApi['deviceSettingsPageShow'];
|
|
256
|
+
// @ts-expect-error refreshDeviceState 已被 getDeviceState scope 取代
|
|
257
|
+
type RemovedRefreshDeviceState = CoreApi['refreshDeviceState'];
|