@onekeyfe/hd-core 1.2.0-alpha.2 → 1.2.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +75 -0
- package/__tests__/DeviceCommands.test.ts +285 -0
- package/__tests__/DeviceEventRegistration.test.ts +43 -0
- package/__tests__/RequestQueue.test.ts +140 -0
- package/__tests__/UploadPortfolio.test.ts +46 -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 +286 -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 +229 -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 +63 -0
- package/__tests__/evmLedgerLegacySafety.test.ts +4 -1
- 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 +403 -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 +4054 -1178
- package/__tests__/protocolV2FileWrite.test.ts +92 -0
- package/__tests__/protocolV2UiInteraction.test.ts +266 -0
- package/__tests__/public-device-state-api.test.ts +253 -0
- package/__tests__/public-pro2-api-boundary.test.ts +91 -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 +11 -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 +18 -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.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 +15 -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/DeviceSettingsGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts +16 -0
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts +12 -0
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/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 +19 -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 +4 -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 +34 -10
- 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 +4 -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/call.d.ts +7 -0
- package/dist/events/call.d.ts.map +1 -1
- package/dist/events/core.d.ts +2 -2
- package/dist/events/core.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/iframe.d.ts +1 -0
- package/dist/events/iframe.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 +1351 -603
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5995 -2816
- package/dist/inject.d.ts +3 -2
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts +2 -1
- package/dist/lowLevelInject.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/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +1 -2
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceSettings.d.ts +9 -0
- package/dist/types/api/deviceSettings.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +1 -1
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/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 +26 -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 +31 -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 +120 -4
- 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 +2 -0
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/deviceVersionUtils.d.ts +6 -5
- package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
- package/dist/utils/homescreen.d.ts.map +1 -1
- package/dist/utils/index.d.ts +3 -1
- 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 +40 -7
- 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 +50 -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 +121 -0
- package/src/api/device/DeviceUnlock.ts +9 -0
- 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 +17 -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/DeviceSettingsGet.ts +18 -0
- package/src/api/protocol-v2/DeviceSettingsPageShow.ts +70 -0
- package/src/api/protocol-v2/DeviceSettingsSet.ts +44 -0
- 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 +124 -4
- package/src/core/deviceEventRegistration.ts +23 -0
- package/src/core/index.ts +171 -60
- 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 +34 -0
- package/src/device/DevicePool.ts +67 -19
- package/src/device/DeviceStateMapper.ts +348 -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 +233 -209
- package/src/deviceProfile/index.ts +0 -1
- package/src/events/call.ts +6 -0
- package/src/events/core.ts +2 -0
- package/src/events/device.ts +17 -1
- package/src/events/iframe.ts +1 -0
- package/src/events/logBlockEvent.ts +8 -1
- package/src/events/ui-request.ts +24 -2
- package/src/index.ts +4 -0
- package/src/inject.ts +33 -34
- package/src/lowLevelInject.ts +3 -0
- 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/topLevelInject.ts +2 -0
- package/src/types/api/checkAllFirmwareRelease.ts +1 -2
- package/src/types/api/deviceSettings.ts +9 -0
- package/src/types/api/deviceUnlock.ts +1 -1
- 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 +37 -53
- package/src/types/api/kaspaSignTransaction.ts +40 -2
- package/src/types/api/openWalletSession.ts +64 -0
- package/src/types/api/protocolV2.ts +88 -54
- package/src/types/api/sessionCache.ts +14 -0
- package/src/types/device.ts +167 -3
- 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 +48 -0
- 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 +3 -0
- 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,61 @@
|
|
|
1
|
+
import type { DeviceSettings, DeviceSettingsPage } from '@onekeyfe/hd-transport';
|
|
2
|
+
import type { UnlockPolicy } from '../../api/BaseMethod';
|
|
3
|
+
import type { ProtocolV2InteractionDescriptor } from './uiInteraction';
|
|
4
|
+
|
|
5
|
+
const LOCK_FREE_DEVICE_SETTINGS = new Set<keyof DeviceSettings>([
|
|
6
|
+
'label',
|
|
7
|
+
'language',
|
|
8
|
+
'brightness',
|
|
9
|
+
'haptic_feedback',
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
export const getProtocolV2SettingsUnlockPolicy = (settings: DeviceSettings): UnlockPolicy =>
|
|
13
|
+
Object.keys(settings).every(key => LOCK_FREE_DEVICE_SETTINGS.has(key as keyof DeviceSettings))
|
|
14
|
+
? 'none'
|
|
15
|
+
: 'retry-on-locked';
|
|
16
|
+
|
|
17
|
+
export type ProtocolV2SettingsOperation =
|
|
18
|
+
| {
|
|
19
|
+
kind: 'direct';
|
|
20
|
+
settings: DeviceSettings;
|
|
21
|
+
}
|
|
22
|
+
| {
|
|
23
|
+
kind: 'page';
|
|
24
|
+
page: DeviceSettingsPage;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const getProtocolV2SettingsBehavior = (
|
|
28
|
+
operation: ProtocolV2SettingsOperation
|
|
29
|
+
): {
|
|
30
|
+
unlockPolicy: UnlockPolicy;
|
|
31
|
+
uiInteraction?: ProtocolV2InteractionDescriptor;
|
|
32
|
+
} => {
|
|
33
|
+
if (operation.kind === 'page') {
|
|
34
|
+
return {
|
|
35
|
+
unlockPolicy: 'retry-on-locked',
|
|
36
|
+
uiInteraction: {
|
|
37
|
+
request: 'button',
|
|
38
|
+
source: 'method-lifecycle',
|
|
39
|
+
reason: 'settings-page',
|
|
40
|
+
completion: 'operation-completed',
|
|
41
|
+
deviceOnly: true,
|
|
42
|
+
page: operation.page,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
unlockPolicy: getProtocolV2SettingsUnlockPolicy(operation.settings),
|
|
49
|
+
uiInteraction:
|
|
50
|
+
typeof operation.settings.label === 'string'
|
|
51
|
+
? {
|
|
52
|
+
request: 'button',
|
|
53
|
+
source: 'method-lifecycle',
|
|
54
|
+
reason: 'device-management',
|
|
55
|
+
completion: 'operation-completed',
|
|
56
|
+
deviceOnly: true,
|
|
57
|
+
operation: 'change-label',
|
|
58
|
+
}
|
|
59
|
+
: undefined,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { UI_REQUEST, createUiMessage } from '../../events';
|
|
2
|
+
|
|
3
|
+
import type { CoreMessage, ProtocolV2UiCompletion } from '../../events';
|
|
4
|
+
import type { Device } from '../../device/Device';
|
|
5
|
+
import type { KnownDevice } from '../../types';
|
|
6
|
+
|
|
7
|
+
export type ProtocolV2InteractionDescriptor = {
|
|
8
|
+
request: 'button' | 'pin';
|
|
9
|
+
source: 'method-lifecycle';
|
|
10
|
+
reason:
|
|
11
|
+
| 'change-pin'
|
|
12
|
+
| 'device-unlock'
|
|
13
|
+
| 'settings-page'
|
|
14
|
+
| 'address-confirmation'
|
|
15
|
+
| 'public-key-confirmation'
|
|
16
|
+
| 'signing-confirmation'
|
|
17
|
+
| 'device-management';
|
|
18
|
+
completion: ProtocolV2UiCompletion;
|
|
19
|
+
deviceOnly: true;
|
|
20
|
+
page?: string | number;
|
|
21
|
+
operation?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type ProtocolV2InteractionMethod = {
|
|
25
|
+
name?: string;
|
|
26
|
+
params?: unknown;
|
|
27
|
+
payload?: unknown;
|
|
28
|
+
protocolV2UiInteraction?: ProtocolV2InteractionDescriptor;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type InteractionDevice = Pick<Device, 'isProtocolV2' | 'toMessageObject'>;
|
|
32
|
+
type PostMessage = (message: CoreMessage) => void;
|
|
33
|
+
|
|
34
|
+
export const isProtocolV2UiEnabled = (method: { protocolV2UiMode?: 'auto' | 'none' }) =>
|
|
35
|
+
method.protocolV2UiMode !== 'none';
|
|
36
|
+
|
|
37
|
+
const getDisplayState = (value: unknown) => {
|
|
38
|
+
const visited = new Set<object>();
|
|
39
|
+
let seen = false;
|
|
40
|
+
let enabled = false;
|
|
41
|
+
|
|
42
|
+
const visit = (current: unknown) => {
|
|
43
|
+
if (current == null || typeof current !== 'object') return;
|
|
44
|
+
if (visited.has(current)) return;
|
|
45
|
+
visited.add(current);
|
|
46
|
+
|
|
47
|
+
if (Array.isArray(current)) {
|
|
48
|
+
current.forEach(visit);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
Object.entries(current).forEach(([key, item]) => {
|
|
53
|
+
if ((key === 'show_display' || key === 'showOnOneKey') && typeof item === 'boolean') {
|
|
54
|
+
seen = true;
|
|
55
|
+
enabled ||= item;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
visit(item);
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
visit(value);
|
|
63
|
+
return { seen, enabled };
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const createMethodInteraction = (
|
|
67
|
+
reason: 'address-confirmation' | 'public-key-confirmation' | 'signing-confirmation',
|
|
68
|
+
operation: string
|
|
69
|
+
): ProtocolV2InteractionDescriptor => ({
|
|
70
|
+
request: 'button',
|
|
71
|
+
source: 'method-lifecycle',
|
|
72
|
+
reason,
|
|
73
|
+
completion: 'operation-completed',
|
|
74
|
+
deviceOnly: true,
|
|
75
|
+
operation,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const hasCipherConfirmation = (value: unknown): boolean => {
|
|
79
|
+
if (Array.isArray(value)) return value.some(hasCipherConfirmation);
|
|
80
|
+
if (value == null || typeof value !== 'object') return false;
|
|
81
|
+
|
|
82
|
+
const params = value as {
|
|
83
|
+
encrypt?: boolean;
|
|
84
|
+
ask_on_encrypt?: boolean;
|
|
85
|
+
ask_on_decrypt?: boolean;
|
|
86
|
+
};
|
|
87
|
+
return params.encrypt === true ? params.ask_on_encrypt === true : params.ask_on_decrypt === true;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Protocol V2 no longer relies on firmware ButtonRequest, so the SDK synthesizes
|
|
92
|
+
* compatible UI events. Explicit descriptors win; address/public-key prompts appear
|
|
93
|
+
* only when displayed, while signing emits one prompt.
|
|
94
|
+
*/
|
|
95
|
+
export const resolveProtocolV2UiInteraction = (
|
|
96
|
+
method: ProtocolV2InteractionMethod
|
|
97
|
+
): ProtocolV2InteractionDescriptor | undefined => {
|
|
98
|
+
if (method.protocolV2UiInteraction) return method.protocolV2UiInteraction;
|
|
99
|
+
|
|
100
|
+
const operation = method.name;
|
|
101
|
+
if (!operation) return undefined;
|
|
102
|
+
|
|
103
|
+
const isAddress = /getAddress(?:ByLoop)?$/i.test(operation);
|
|
104
|
+
const isPublicKey = /getPublicKey$/i.test(operation);
|
|
105
|
+
if (isAddress || isPublicKey) {
|
|
106
|
+
const paramsDisplay = getDisplayState(method.params);
|
|
107
|
+
const payloadDisplay = getDisplayState(method.payload);
|
|
108
|
+
const display = paramsDisplay.seen ? paramsDisplay : payloadDisplay;
|
|
109
|
+
|
|
110
|
+
// Address methods usually display by default; public-key methods may be silent.
|
|
111
|
+
const shouldDisplay = display.seen ? display.enabled : isAddress;
|
|
112
|
+
if (!shouldDisplay) return undefined;
|
|
113
|
+
|
|
114
|
+
return createMethodInteraction(
|
|
115
|
+
isAddress ? 'address-confirmation' : 'public-key-confirmation',
|
|
116
|
+
operation
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (/sign/i.test(operation) || /verifyMessage$/i.test(operation) || operation === 'lnurlAuth') {
|
|
121
|
+
return createMethodInteraction('signing-confirmation', operation);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (operation === 'nostrEncryptMessage' || operation === 'nostrDecryptMessage') {
|
|
125
|
+
const display = getDisplayState(method.params);
|
|
126
|
+
if (!display.enabled) return undefined;
|
|
127
|
+
return createMethodInteraction('signing-confirmation', operation);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (operation === 'cipherKeyValue' && hasCipherConfirmation(method.params)) {
|
|
131
|
+
return createMethodInteraction('signing-confirmation', operation);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return undefined;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export class ProtocolV2UiInteractionCoordinator {
|
|
138
|
+
private readonly device: InteractionDevice;
|
|
139
|
+
|
|
140
|
+
private readonly postMessage: PostMessage;
|
|
141
|
+
|
|
142
|
+
private methodInteraction?: ProtocolV2InteractionDescriptor;
|
|
143
|
+
|
|
144
|
+
private currentPhase?: string;
|
|
145
|
+
|
|
146
|
+
private opened = false;
|
|
147
|
+
|
|
148
|
+
private closed = false;
|
|
149
|
+
|
|
150
|
+
constructor(device: InteractionDevice, postMessage: PostMessage) {
|
|
151
|
+
this.device = device;
|
|
152
|
+
this.postMessage = postMessage;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
enterMethodInteraction(interaction?: ProtocolV2InteractionDescriptor) {
|
|
156
|
+
this.methodInteraction = interaction;
|
|
157
|
+
if (!interaction) return;
|
|
158
|
+
const { request, ...metadata } = interaction;
|
|
159
|
+
|
|
160
|
+
this.emit(
|
|
161
|
+
request === 'pin' ? UI_REQUEST.REQUEST_PIN : UI_REQUEST.REQUEST_BUTTON,
|
|
162
|
+
{
|
|
163
|
+
device: this.device.toMessageObject() as KnownDevice,
|
|
164
|
+
...metadata,
|
|
165
|
+
},
|
|
166
|
+
`method:${request}:${interaction.reason}:${interaction.page ?? ''}:${
|
|
167
|
+
interaction.operation ?? ''
|
|
168
|
+
}`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
enterUnlockInteraction(method?: string) {
|
|
173
|
+
this.emit(
|
|
174
|
+
UI_REQUEST.REQUEST_PIN,
|
|
175
|
+
{
|
|
176
|
+
device: this.device.toMessageObject() as KnownDevice,
|
|
177
|
+
source: 'unlock-coordinator',
|
|
178
|
+
reason: 'device-locked',
|
|
179
|
+
deviceOnly: true,
|
|
180
|
+
method,
|
|
181
|
+
},
|
|
182
|
+
`unlock:${method ?? ''}`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
resumeMethodInteraction() {
|
|
187
|
+
this.enterMethodInteraction(this.methodInteraction);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
close() {
|
|
191
|
+
if (!this.device.isProtocolV2() || !this.opened || this.closed) return;
|
|
192
|
+
this.closed = true;
|
|
193
|
+
this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private emit(
|
|
197
|
+
type: typeof UI_REQUEST.REQUEST_BUTTON | typeof UI_REQUEST.REQUEST_PIN,
|
|
198
|
+
payload: any,
|
|
199
|
+
phase: string
|
|
200
|
+
) {
|
|
201
|
+
if (!this.device.isProtocolV2() || this.closed || this.currentPhase === phase) return;
|
|
202
|
+
this.currentPhase = phase;
|
|
203
|
+
this.opened = true;
|
|
204
|
+
const message =
|
|
205
|
+
type === UI_REQUEST.REQUEST_BUTTON
|
|
206
|
+
? createUiMessage(UI_REQUEST.REQUEST_BUTTON, payload)
|
|
207
|
+
: createUiMessage(UI_REQUEST.REQUEST_PIN, payload);
|
|
208
|
+
this.postMessage(message);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { LoggerNames, getLogger } from '../../utils';
|
|
2
|
+
import { isDeviceLockedError } from './lockedError';
|
|
3
|
+
import { isProtocolV2UiEnabled, resolveProtocolV2UiInteraction } from './uiInteraction';
|
|
4
|
+
|
|
5
|
+
import type { BaseMethod } from '../../api/BaseMethod';
|
|
6
|
+
import type { Device } from '../../device/Device';
|
|
7
|
+
import type { ProtocolV2UiInteractionCoordinator } from './uiInteraction';
|
|
8
|
+
|
|
9
|
+
const Log = getLogger(LoggerNames.Core);
|
|
10
|
+
|
|
11
|
+
type RunnableMethod = Pick<
|
|
12
|
+
BaseMethod,
|
|
13
|
+
'run' | 'unlockPolicy' | 'protocolV2UiInteraction' | 'protocolV2UiMode' | 'params' | 'payload'
|
|
14
|
+
> & { name?: string };
|
|
15
|
+
type UnlockableDevice = Pick<Device, 'isProtocolV2' | 'unlockDevice' | 'features'>;
|
|
16
|
+
type UiInteractionCoordinator = Pick<
|
|
17
|
+
ProtocolV2UiInteractionCoordinator,
|
|
18
|
+
'enterMethodInteraction' | 'enterUnlockInteraction' | 'resumeMethodInteraction'
|
|
19
|
+
>;
|
|
20
|
+
|
|
21
|
+
export async function runMethodWithUnlockRetry(
|
|
22
|
+
method: RunnableMethod,
|
|
23
|
+
device: UnlockableDevice,
|
|
24
|
+
uiCoordinator?: UiInteractionCoordinator
|
|
25
|
+
) {
|
|
26
|
+
const shouldEmitUi = isProtocolV2UiEnabled(method);
|
|
27
|
+
const shouldUnlockBeforeRun =
|
|
28
|
+
device.isProtocolV2() &&
|
|
29
|
+
method.unlockPolicy === 'retry-on-locked' &&
|
|
30
|
+
device.features?.unlocked === false;
|
|
31
|
+
|
|
32
|
+
if (shouldUnlockBeforeRun) {
|
|
33
|
+
if (shouldEmitUi) {
|
|
34
|
+
uiCoordinator?.enterUnlockInteraction(method.name);
|
|
35
|
+
}
|
|
36
|
+
await device.unlockDevice();
|
|
37
|
+
Log.debug('Protocol V2 pre-unlock completed', { method: method.name });
|
|
38
|
+
if (shouldEmitUi) {
|
|
39
|
+
uiCoordinator?.enterMethodInteraction(resolveProtocolV2UiInteraction(method));
|
|
40
|
+
}
|
|
41
|
+
return method.run();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (shouldEmitUi) {
|
|
45
|
+
uiCoordinator?.enterMethodInteraction(resolveProtocolV2UiInteraction(method));
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
return await method.run();
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (
|
|
51
|
+
!device.isProtocolV2() ||
|
|
52
|
+
method.unlockPolicy !== 'retry-on-locked' ||
|
|
53
|
+
!isDeviceLockedError(error)
|
|
54
|
+
) {
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Log.debug('Protocol V2 unlock retry triggered', { method: method.name });
|
|
59
|
+
if (shouldEmitUi) {
|
|
60
|
+
uiCoordinator?.enterUnlockInteraction(method.name);
|
|
61
|
+
}
|
|
62
|
+
await device.unlockDevice();
|
|
63
|
+
Log.debug('Protocol V2 unlock completed', { method: method.name });
|
|
64
|
+
if (shouldEmitUi) {
|
|
65
|
+
uiCoordinator?.resumeMethodInteraction();
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const response = await method.run();
|
|
69
|
+
Log.debug('Protocol V2 method retry completed', { method: method.name, success: true });
|
|
70
|
+
return response;
|
|
71
|
+
} catch (retryError) {
|
|
72
|
+
Log.debug('Protocol V2 method retry completed', { method: method.name, success: false });
|
|
73
|
+
throw retryError;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import { assertCompleteDeviceSession } from './deviceSession';
|
|
4
|
+
import { isDeviceLockedError } from './lockedError';
|
|
5
|
+
|
|
6
|
+
import type { DeviceSessionGet } from '@onekeyfe/hd-transport';
|
|
7
|
+
import type { Device } from '../../device/Device';
|
|
8
|
+
|
|
9
|
+
export async function requestProtocolV2DeviceStatus(device: Device) {
|
|
10
|
+
const { message } = await device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
|
|
11
|
+
return message;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function refreshProtocolV2DeviceStatus(device: Device) {
|
|
15
|
+
const status = await requestProtocolV2DeviceStatus(device);
|
|
16
|
+
return device.updateProtocolV2Status(status);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const getDeviceSession = async (device: Device, request: DeviceSessionGet) => {
|
|
20
|
+
try {
|
|
21
|
+
return await device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (!isDeviceLockedError(error)) {
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
await device.unlockDevice();
|
|
27
|
+
return device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export async function getProtocolV2WalletSession(
|
|
32
|
+
device: Device,
|
|
33
|
+
options?: {
|
|
34
|
+
initSession?: boolean;
|
|
35
|
+
expectedPassphraseState?: string;
|
|
36
|
+
onlyMainPin?: boolean;
|
|
37
|
+
}
|
|
38
|
+
) {
|
|
39
|
+
if (options?.initSession) {
|
|
40
|
+
device.clearInternalState();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const expectedPassphraseState = options?.expectedPassphraseState ?? device.passphraseState;
|
|
44
|
+
|
|
45
|
+
// Unlock with PIN first. DeviceSessionGet operates on the wallet selected by
|
|
46
|
+
// the device unlock flow; Protocol V2 does not accept a host passphrase here.
|
|
47
|
+
if (device.features?.unlocked === false) {
|
|
48
|
+
await device.unlockDevice();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// A standard wallet needs no DeviceSession. After unlock confirms passphrase is
|
|
52
|
+
// disabled, do not create or forward a hidden-wallet passphraseState.
|
|
53
|
+
if (options?.onlyMainPin || device.getCurrentPassphraseProtection() === false) {
|
|
54
|
+
return {
|
|
55
|
+
passphraseState: undefined,
|
|
56
|
+
newSession: undefined,
|
|
57
|
+
unlockedAttachPin: device.features?.unlockedAttachPin ?? false,
|
|
58
|
+
resumed: false,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const cachedSessionId =
|
|
63
|
+
typeof device.getInternalState === 'function' ? device.getInternalState() : undefined;
|
|
64
|
+
let response;
|
|
65
|
+
let resumed = false;
|
|
66
|
+
|
|
67
|
+
if (cachedSessionId && expectedPassphraseState) {
|
|
68
|
+
try {
|
|
69
|
+
response = await getDeviceSession(device, { session_id: cachedSessionId });
|
|
70
|
+
resumed = true;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
device.clearInternalState();
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!response) {
|
|
78
|
+
response = await getDeviceSession(device, {});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const { message } = response;
|
|
82
|
+
try {
|
|
83
|
+
assertCompleteDeviceSession(message);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
device.clearInternalState();
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
if (expectedPassphraseState && expectedPassphraseState !== message.btc_test_address) {
|
|
89
|
+
device.clearInternalState();
|
|
90
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
device.updateInternalState(
|
|
94
|
+
true,
|
|
95
|
+
message.btc_test_address,
|
|
96
|
+
device.getCurrentDeviceId(),
|
|
97
|
+
message.session_id,
|
|
98
|
+
options?.initSession ? null : device.features?.sessionId ?? null
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
passphraseState: message.btc_test_address,
|
|
103
|
+
newSession: message.session_id,
|
|
104
|
+
unlockedAttachPin: device.features?.unlockedAttachPin ?? undefined,
|
|
105
|
+
resumed,
|
|
106
|
+
};
|
|
107
|
+
}
|
package/src/topLevelInject.ts
CHANGED
|
@@ -52,6 +52,8 @@ export const topLevelInject = () => {
|
|
|
52
52
|
|
|
53
53
|
cancel: (connectId?: string) => lowLevelApi?.cancel(connectId),
|
|
54
54
|
|
|
55
|
+
cancelOperation: (operationId: string) => lowLevelApi?.cancelOperation(operationId),
|
|
56
|
+
|
|
55
57
|
updateSettings: settings => lowLevelApi?.updateSettings(settings) ?? Promise.resolve(false),
|
|
56
58
|
|
|
57
59
|
switchTransport: (env: ConnectSettings['env']) =>
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { IBLEFirmwareReleaseInfo } from '../settings';
|
|
2
2
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
3
|
-
import type { Features } from '@onekeyfe/hd-transport';
|
|
4
3
|
import type { CommonParams, Response } from '../params';
|
|
5
|
-
import type { IDeviceBLEFirmwareStatus, IDeviceFirmwareStatus } from '../device';
|
|
4
|
+
import type { Features, IDeviceBLEFirmwareStatus, IDeviceFirmwareStatus } from '../device';
|
|
6
5
|
|
|
7
6
|
export type FirmwareRelease = {
|
|
8
7
|
shouldUpdate?: boolean;
|
|
@@ -14,7 +14,16 @@ export type DeviceSettingsParams = {
|
|
|
14
14
|
experimentalFeatures?: boolean;
|
|
15
15
|
autoShutdownDelayMs?: number;
|
|
16
16
|
changeBrightness?: boolean;
|
|
17
|
+
brightness?: number;
|
|
17
18
|
hapticFeedback?: boolean;
|
|
19
|
+
bluetoothEnabled?: boolean;
|
|
20
|
+
airgapMode?: boolean;
|
|
21
|
+
animationEnabled?: boolean;
|
|
22
|
+
tapToWake?: boolean;
|
|
23
|
+
deviceNameDisplayEnabled?: boolean;
|
|
24
|
+
fidoEnabled?: boolean;
|
|
25
|
+
usbLockEnabled?: boolean;
|
|
26
|
+
randomKeypad?: boolean;
|
|
18
27
|
};
|
|
19
28
|
|
|
20
29
|
export declare function deviceSettings(
|
|
@@ -58,42 +58,50 @@ export interface FirmwareUpdateV3Params {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
* firmwareUpdateV4
|
|
62
|
-
*
|
|
61
|
+
* firmwareUpdateV4 target binaries grouped by DeviceFirmwareTargetType.
|
|
62
|
+
* Except for romloader, each field maps to a target accepted by bootloader.
|
|
63
63
|
*/
|
|
64
|
+
export type FirmwareUpdateV4Target =
|
|
65
|
+
| 'boot'
|
|
66
|
+
| 'app_v1'
|
|
67
|
+
| 'app_v2'
|
|
68
|
+
| 'coprocessor'
|
|
69
|
+
| 'resource'
|
|
70
|
+
| 'se01'
|
|
71
|
+
| 'se02'
|
|
72
|
+
| 'se03'
|
|
73
|
+
| 'se04';
|
|
74
|
+
|
|
64
75
|
export interface FirmwareUpdateV4Params {
|
|
65
76
|
platform: IPlatform;
|
|
66
77
|
chunkSize?: number;
|
|
67
78
|
firmwareType?: EFirmwareType;
|
|
79
|
+
targetsToUpdate?: FirmwareUpdateV4Target[];
|
|
68
80
|
|
|
69
|
-
/**
|
|
81
|
+
/** FW_MGMT_TARGET_ROMLOADER = 2; Pro2 cannot install it through firmwareUpdateV4. */
|
|
70
82
|
romloaderBinary?: ArrayBuffer;
|
|
71
|
-
/**
|
|
83
|
+
/** FW_MGMT_TARGET_BOOTLOADER = 3 */
|
|
72
84
|
bootloaderBinary?: ArrayBuffer;
|
|
73
|
-
/**
|
|
85
|
+
/** FW_MGMT_TARGET_APPLICATION_P1 = 4 */
|
|
74
86
|
applicationP1Binary?: ArrayBuffer;
|
|
75
|
-
/**
|
|
87
|
+
/** FW_MGMT_TARGET_APPLICATION_P2 = 5 */
|
|
76
88
|
applicationP2Binary?: ArrayBuffer;
|
|
77
|
-
/**
|
|
89
|
+
/** FW_MGMT_TARGET_COPROCESSOR = 6 */
|
|
78
90
|
coprocessorBinary?: ArrayBuffer;
|
|
79
|
-
/**
|
|
91
|
+
/** FW_MGMT_TARGET_SE01-04 = 7-10 */
|
|
80
92
|
se01Binary?: ArrayBuffer;
|
|
81
93
|
se02Binary?: ArrayBuffer;
|
|
82
94
|
se03Binary?: ArrayBuffer;
|
|
83
95
|
se04Binary?: ArrayBuffer;
|
|
84
|
-
/** TARGET_RESOURCE = 10(zip 包,解压后逐文件上传) */
|
|
85
|
-
resourceBinary?: ArrayBuffer;
|
|
86
96
|
forcedUpdateRes?: boolean;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
/** legacy 别名:等价 coprocessorBinary */
|
|
96
|
-
bleBinary?: ArrayBuffer;
|
|
97
|
+
/**
|
|
98
|
+
* RESC bundle okpkg files written directly to devicePath through FilesystemFileWrite.
|
|
99
|
+
* Manual mode installs them without version comparison.
|
|
100
|
+
*/
|
|
101
|
+
resourceBundleFiles?: Array<{
|
|
102
|
+
binary: ArrayBuffer;
|
|
103
|
+
devicePath: string;
|
|
104
|
+
}>;
|
|
97
105
|
}
|
|
98
106
|
|
|
99
107
|
export declare function firmwareUpdateV3(
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DeviceState, DeviceStateSection } from '../device';
|
|
2
|
+
import type { CommonParams, Response } from '../params';
|
|
3
|
+
|
|
4
|
+
export type DeviceStateScope = 'runtime' | 'settings' | 'firmware';
|
|
5
|
+
|
|
6
|
+
export type GetDeviceStateParams = CommonParams & {
|
|
7
|
+
scope?: DeviceStateScope;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/** Internal state-read options, not part of the public CoreApi. */
|
|
11
|
+
export type DeviceStateReadOptions = {
|
|
12
|
+
refreshSections?: DeviceStateSection[];
|
|
13
|
+
includeRaw?: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export declare function getDeviceState(
|
|
17
|
+
connectId?: string,
|
|
18
|
+
params?: GetDeviceStateParams
|
|
19
|
+
): Response<DeviceState>;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { CommonParams, Response } from '../params';
|
|
2
2
|
import type { Features } from '../device';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use `getDeviceState` for both Protocol V1 and Protocol V2 devices.
|
|
6
|
+
*/
|
|
4
7
|
export declare function getFeatures(connectId?: string, params?: CommonParams): Response<Features>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { CommonParams, Response } from '../params';
|
|
2
2
|
import type { OnekeyFeatures } from '../device';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use `getDeviceState(connectId, { scope: 'firmware' })`.
|
|
6
|
+
*/
|
|
4
7
|
export declare function getOnekeyFeatures(
|
|
5
8
|
connectId?: string,
|
|
6
9
|
params?: CommonParams
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import type { CommonParams, Response } from '../params';
|
|
2
2
|
|
|
3
|
-
export type
|
|
4
|
-
passphrase_state?: string;
|
|
5
|
-
session_id?: string;
|
|
6
|
-
unlocked_attach_pin?: boolean;
|
|
7
|
-
passphrase_protection?: boolean | null;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type GetPassphraseStateParams = CommonParams & {
|
|
11
|
-
allowCreateAttachPin?: boolean;
|
|
12
|
-
};
|
|
3
|
+
export type GetPassphraseStateParams = CommonParams;
|
|
13
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Legacy Protocol V1 wallet API.
|
|
7
|
+
*
|
|
8
|
+
* This remains supported for Protocol V1 integrations. New cross-protocol integrations
|
|
9
|
+
* and all Protocol V2 callers should use `openWalletSession`.
|
|
10
|
+
*/
|
|
14
11
|
export declare function getPassphraseState(
|
|
15
12
|
connectId?: string,
|
|
16
13
|
params?: GetPassphraseStateParams
|
|
17
|
-
): Response<
|
|
14
|
+
): Response<string | undefined>;
|