@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
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeviceRebootType } from '@onekeyfe/hd-transport';
|
|
2
2
|
|
|
3
3
|
import { invalidParameter, validateNonEmptyString } from '../helpers/filesystemValidation';
|
|
4
|
+
import { ProtocolV2FirmwareTargetType } from '../../protocols/protocol-v2/firmware';
|
|
4
5
|
|
|
5
6
|
import type {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
DeviceFirmwareTarget,
|
|
8
|
+
DeviceFirmwareTargetType,
|
|
9
|
+
DeviceFirmwareUpdateRecordFields,
|
|
8
10
|
TransportCallOptions,
|
|
9
11
|
} from '@onekeyfe/hd-transport';
|
|
10
12
|
|
|
11
|
-
export type RebootTypeInput =
|
|
12
|
-
| DevRebootType
|
|
13
|
-
| DeviceRebootType
|
|
14
|
-
| keyof typeof DevRebootType
|
|
15
|
-
| keyof typeof DeviceRebootType
|
|
16
|
-
| string
|
|
17
|
-
| number;
|
|
13
|
+
export type RebootTypeInput = DeviceRebootType | keyof typeof DeviceRebootType | string | number;
|
|
18
14
|
|
|
19
15
|
export type DeviceRebootParams = {
|
|
20
16
|
rebootType?: RebootTypeInput;
|
|
@@ -22,38 +18,37 @@ export type DeviceRebootParams = {
|
|
|
22
18
|
};
|
|
23
19
|
|
|
24
20
|
export type DeviceFirmwareTargetInput =
|
|
25
|
-
|
|
|
21
|
+
| DeviceFirmwareTarget
|
|
26
22
|
| {
|
|
27
|
-
targetId?:
|
|
28
|
-
target_id?:
|
|
23
|
+
targetId?: DeviceFirmwareTargetType | string | number;
|
|
24
|
+
target_id?: DeviceFirmwareTargetType | string | number;
|
|
29
25
|
path: string;
|
|
30
26
|
};
|
|
31
27
|
|
|
32
28
|
export type DeviceFirmwareUpdateParams = {
|
|
33
29
|
targets?: DeviceFirmwareTargetInput[];
|
|
34
|
-
targetId?:
|
|
35
|
-
target_id?:
|
|
30
|
+
targetId?: DeviceFirmwareTargetType | string | number;
|
|
31
|
+
target_id?: DeviceFirmwareTargetType | string | number;
|
|
36
32
|
path?: string;
|
|
37
33
|
};
|
|
38
34
|
|
|
39
|
-
export type
|
|
40
|
-
|
|
41
|
-
serialNo?: string;
|
|
42
|
-
cpu_info?: string;
|
|
43
|
-
cpuInfo?: string;
|
|
44
|
-
pre_firmware?: string;
|
|
45
|
-
preFirmware?: string;
|
|
35
|
+
export type DeviceFirmwareUpdateStatusGetParams = {
|
|
36
|
+
fields?: DeviceFirmwareUpdateRecordFields;
|
|
46
37
|
};
|
|
47
38
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
export type DeviceFactoryInfoSetParams = {
|
|
40
|
+
version?: number;
|
|
41
|
+
serial_number?: string;
|
|
42
|
+
burn_in_completed?: boolean;
|
|
43
|
+
factory_test_completed?: boolean;
|
|
44
|
+
manufacture_time?: {
|
|
45
|
+
year: number;
|
|
46
|
+
month: number;
|
|
47
|
+
day: number;
|
|
48
|
+
hour: number;
|
|
49
|
+
minute: number;
|
|
50
|
+
second: number;
|
|
51
|
+
};
|
|
57
52
|
};
|
|
58
53
|
|
|
59
54
|
const DEVICE_REBOOT_TYPES: Record<string, DeviceRebootType> = {
|
|
@@ -68,13 +63,13 @@ const DEVICE_REBOOT_TYPES: Record<string, DeviceRebootType> = {
|
|
|
68
63
|
};
|
|
69
64
|
|
|
70
65
|
export const PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS: TransportCallOptions = {
|
|
71
|
-
intermediateTypes: ['
|
|
66
|
+
intermediateTypes: ['DeviceFirmwareUpdateStatus'],
|
|
72
67
|
};
|
|
73
68
|
|
|
74
69
|
export const PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES: (
|
|
75
70
|
| 'Success'
|
|
76
|
-
| '
|
|
77
|
-
)[] = ['Success', '
|
|
71
|
+
| 'DeviceFirmwareUpdateStatus'
|
|
72
|
+
)[] = ['Success', 'DeviceFirmwareUpdateStatus'];
|
|
78
73
|
|
|
79
74
|
export const getProtocolV2UnknownErrorText = (error: unknown) => {
|
|
80
75
|
if (!error) {
|
|
@@ -123,9 +118,6 @@ export const isProtocolV2DeviceDisconnectedError = (error: unknown) => {
|
|
|
123
118
|
message.includes('connection has timed out unexpectedly') ||
|
|
124
119
|
message.includes('connection error has occured') ||
|
|
125
120
|
message.includes('connection error has occurred') ||
|
|
126
|
-
message.includes('transferIn') ||
|
|
127
|
-
message.includes('transferin') ||
|
|
128
|
-
message.includes('usbdevice') ||
|
|
129
121
|
message.includes('multiplatformbleadapter') ||
|
|
130
122
|
message.includes('multipalformebleadapter') ||
|
|
131
123
|
compactMessage.includes('rxerrorerror6') ||
|
|
@@ -133,19 +125,7 @@ export const isProtocolV2DeviceDisconnectedError = (error: unknown) => {
|
|
|
133
125
|
);
|
|
134
126
|
};
|
|
135
127
|
|
|
136
|
-
export function normalizeRebootType(value: RebootTypeInput | undefined):
|
|
137
|
-
if (typeof value === 'number') return value;
|
|
138
|
-
if (typeof value === 'string') {
|
|
139
|
-
const numeric = Number(value);
|
|
140
|
-
if (Number.isFinite(numeric)) return numeric;
|
|
141
|
-
if (value in DEV_REBOOT_TYPES) return DEV_REBOOT_TYPES[value];
|
|
142
|
-
}
|
|
143
|
-
return DevRebootType.Normal;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function normalizeDeviceRebootType(
|
|
147
|
-
value: RebootTypeInput | undefined
|
|
148
|
-
): DeviceRebootType {
|
|
128
|
+
export function normalizeRebootType(value: RebootTypeInput | undefined): DeviceRebootType {
|
|
149
129
|
if (typeof value === 'number') return value;
|
|
150
130
|
if (typeof value === 'string') {
|
|
151
131
|
const numeric = Number(value);
|
|
@@ -155,30 +135,46 @@ export function normalizeDeviceRebootType(
|
|
|
155
135
|
return DeviceRebootType.Normal;
|
|
156
136
|
}
|
|
157
137
|
|
|
158
|
-
//
|
|
159
|
-
const
|
|
138
|
+
// 与 firmware-pro2 的 proto_target_to_firmware_target 安装白名单保持一致。
|
|
139
|
+
const INSTALLABLE_FIRMWARE_TARGET_IDS = new Set<number>([
|
|
140
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_CRATE,
|
|
141
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER,
|
|
142
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P1,
|
|
143
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P2,
|
|
144
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_COPROCESSOR,
|
|
145
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE01,
|
|
146
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE02,
|
|
147
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE03,
|
|
148
|
+
ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_SE04,
|
|
149
|
+
]);
|
|
150
|
+
const FIRMWARE_TARGET_ID_BY_NAME = new Map<string, DeviceFirmwareTargetType>(
|
|
151
|
+
Object.entries(ProtocolV2FirmwareTargetType).flatMap(([key, value]) =>
|
|
152
|
+
INSTALLABLE_FIRMWARE_TARGET_IDS.has(value) ? [[key, value as DeviceFirmwareTargetType]] : []
|
|
153
|
+
)
|
|
154
|
+
);
|
|
160
155
|
|
|
161
156
|
function normalizeTargetId(
|
|
162
|
-
value:
|
|
157
|
+
value: DeviceFirmwareTargetType | string | number | undefined,
|
|
163
158
|
name: string
|
|
164
|
-
):
|
|
159
|
+
): DeviceFirmwareTargetType {
|
|
165
160
|
if (value === undefined || value === null) {
|
|
166
161
|
throw invalidParameter(`Missing required parameter: ${name}`);
|
|
167
162
|
}
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return numeric as DevFirmwareTargetType;
|
|
163
|
+
const named = typeof value === 'string' ? FIRMWARE_TARGET_ID_BY_NAME.get(value) : undefined;
|
|
164
|
+
const numeric = named ?? (typeof value === 'number' ? value : Number(value));
|
|
165
|
+
if (Number.isSafeInteger(numeric) && INSTALLABLE_FIRMWARE_TARGET_IDS.has(numeric)) {
|
|
166
|
+
return numeric as DeviceFirmwareTargetType;
|
|
173
167
|
}
|
|
174
168
|
throw invalidParameter(
|
|
175
|
-
`Parameter [${name}] must be
|
|
176
|
-
...
|
|
169
|
+
`Parameter [${name}] must be an installable firmware target id (one of ${[
|
|
170
|
+
...INSTALLABLE_FIRMWARE_TARGET_IDS,
|
|
177
171
|
].join(', ')}).`
|
|
178
172
|
);
|
|
179
173
|
}
|
|
180
174
|
|
|
181
|
-
export function normalizeFirmwareTargets(
|
|
175
|
+
export function normalizeFirmwareTargets(
|
|
176
|
+
params: DeviceFirmwareUpdateParams
|
|
177
|
+
): DeviceFirmwareTarget[] {
|
|
182
178
|
const targets =
|
|
183
179
|
params.targets ??
|
|
184
180
|
(params.path
|
package/src/api/utils.ts
CHANGED
|
@@ -2,16 +2,20 @@ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
|
2
2
|
|
|
3
3
|
import * as ApiMethods from './index';
|
|
4
4
|
|
|
5
|
+
import type { BaseMethod } from './BaseMethod';
|
|
5
6
|
import type { IFrameCallMessage } from '../events';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
type MethodConstructor = new (message: IFrameCallMessage & { id?: number }) => BaseMethod<any>;
|
|
9
|
+
|
|
10
|
+
const publicMethodRegistry = ApiMethods as unknown as Record<string, MethodConstructor>;
|
|
11
|
+
|
|
12
|
+
export function findMethod(message: IFrameCallMessage & { id?: number }): BaseMethod<any> {
|
|
8
13
|
const { method } = message.payload;
|
|
9
14
|
if (typeof method !== 'string') {
|
|
10
15
|
throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'Method is not set');
|
|
11
16
|
}
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
const MethodConstructor = ApiMethods[method];
|
|
18
|
+
const MethodConstructor = publicMethodRegistry[method];
|
|
15
19
|
if (MethodConstructor) {
|
|
16
20
|
return new MethodConstructor(message);
|
|
17
21
|
}
|
package/src/constants/index.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
export { safeThrowError } from './errors';
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
Messages as PROTO,
|
|
4
|
+
ResourceType,
|
|
5
|
+
TonSignDataType,
|
|
6
|
+
TonWalletVersion,
|
|
7
|
+
} from '@onekeyfe/hd-transport';
|
|
8
|
+
export type { HDNodeType, Success as DeviceSuccess } from '@onekeyfe/hd-transport';
|
package/src/core/RequestQueue.ts
CHANGED
|
@@ -1,21 +1,47 @@
|
|
|
1
|
+
import { type Deferred, createDeferred } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
1
3
|
import { LoggerNames, getLogger } from '../utils';
|
|
2
4
|
|
|
3
|
-
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
4
5
|
import type { BaseMethod } from '../api/BaseMethod';
|
|
5
6
|
|
|
6
7
|
const Log = getLogger(LoggerNames.Core);
|
|
8
|
+
const OPERATION_PRE_CANCEL_TTL_MS = 30_000;
|
|
9
|
+
const DEFAULT_BACKGROUND_PREEMPT_TIMEOUT_MS = 5_500;
|
|
10
|
+
|
|
7
11
|
export type RequestTask = {
|
|
8
12
|
id: number;
|
|
9
13
|
method: BaseMethod;
|
|
10
14
|
callPromise?: Deferred<any> | undefined;
|
|
11
15
|
abortController?: AbortController;
|
|
16
|
+
settled: Deferred<void>;
|
|
17
|
+
released: Deferred<void>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type RequestAdmission =
|
|
21
|
+
| { status: 'reserved'; task: RequestTask }
|
|
22
|
+
| { status: 'busy'; blockingTask?: RequestTask };
|
|
23
|
+
|
|
24
|
+
export type RequestAdmissionOptions = {
|
|
25
|
+
backgroundPreemptTimeoutMs?: number;
|
|
12
26
|
};
|
|
13
27
|
|
|
14
28
|
export default class RequestQueue {
|
|
15
29
|
private requestQueue = new Map<number, RequestTask>();
|
|
16
30
|
|
|
31
|
+
private operationRequestIds = new Map<string, number>();
|
|
32
|
+
|
|
33
|
+
private pendingOperationCancellations = new Map<string, number>();
|
|
34
|
+
|
|
17
35
|
private pendingCallbackTasks = new Map<string, Deferred<void>>();
|
|
18
36
|
|
|
37
|
+
private prunePendingOperationCancellations(now = Date.now()) {
|
|
38
|
+
this.pendingOperationCancellations.forEach((expiresAt, operationId) => {
|
|
39
|
+
if (expiresAt <= now) {
|
|
40
|
+
this.pendingOperationCancellations.delete(operationId);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
19
45
|
// 生成唯一请求ID
|
|
20
46
|
public generateRequestId = (method?: BaseMethod) => {
|
|
21
47
|
if (method && method.responseID != null) {
|
|
@@ -30,11 +56,94 @@ export default class RequestQueue {
|
|
|
30
56
|
method.responseID = requestId;
|
|
31
57
|
}
|
|
32
58
|
const abortController = new AbortController();
|
|
33
|
-
|
|
59
|
+
method.abortSignal = abortController.signal;
|
|
60
|
+
const task = {
|
|
61
|
+
id: requestId,
|
|
62
|
+
method,
|
|
63
|
+
abortController,
|
|
64
|
+
settled: createDeferred<void>(),
|
|
65
|
+
released: createDeferred<void>(),
|
|
66
|
+
};
|
|
34
67
|
this.requestQueue.set(requestId, task);
|
|
68
|
+
const operationId = method.payload?.operationId;
|
|
69
|
+
if (typeof operationId === 'string' && operationId) {
|
|
70
|
+
this.operationRequestIds.set(operationId, requestId);
|
|
71
|
+
this.prunePendingOperationCancellations();
|
|
72
|
+
if (this.pendingOperationCancellations.delete(operationId)) {
|
|
73
|
+
abortController.abort();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
35
76
|
return task;
|
|
36
77
|
}
|
|
37
78
|
|
|
79
|
+
public async admitTask(
|
|
80
|
+
method: BaseMethod,
|
|
81
|
+
options: RequestAdmissionOptions = {}
|
|
82
|
+
): Promise<RequestAdmission> {
|
|
83
|
+
const activeTasks = Array.from(this.requestQueue.values()).filter(
|
|
84
|
+
task => task.method.connectId === method.connectId
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
if (method.executionPriority === 'background') {
|
|
88
|
+
if (activeTasks.length) {
|
|
89
|
+
Log.debug(
|
|
90
|
+
`Reject background method ${method.name}: device is occupied by ${activeTasks[0].method.name}`
|
|
91
|
+
);
|
|
92
|
+
return { status: 'busy', blockingTask: activeTasks[0] };
|
|
93
|
+
}
|
|
94
|
+
return { status: 'reserved', task: this.createTask(method) };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const backgroundTasks = activeTasks.filter(
|
|
98
|
+
task => task.method.executionPriority === 'background'
|
|
99
|
+
);
|
|
100
|
+
if (!backgroundTasks.length) {
|
|
101
|
+
return { status: 'reserved', task: this.createTask(method) };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
Log.debug(
|
|
105
|
+
`Preempt ${backgroundTasks.length} background request(s) for user method ${method.name}`
|
|
106
|
+
);
|
|
107
|
+
backgroundTasks.forEach(task => task.abortController?.abort());
|
|
108
|
+
const timeoutMs =
|
|
109
|
+
options.backgroundPreemptTimeoutMs ??
|
|
110
|
+
Math.max(
|
|
111
|
+
DEFAULT_BACKGROUND_PREEMPT_TIMEOUT_MS,
|
|
112
|
+
...backgroundTasks.map(task => task.method.maxAbortLatencyMs ?? 0)
|
|
113
|
+
);
|
|
114
|
+
const released = await this.waitForTasksReleased(backgroundTasks, timeoutMs);
|
|
115
|
+
if (!released) {
|
|
116
|
+
Log.warn(`Background request cleanup timed out before user method ${method.name}`);
|
|
117
|
+
return { status: 'busy', blockingTask: backgroundTasks[0] };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return { status: 'reserved', task: this.createTask(method) };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private async waitForTasksReleased(tasks: RequestTask[], timeoutMs: number) {
|
|
124
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
125
|
+
const timeoutPromise = new Promise<false>(resolve => {
|
|
126
|
+
timer = setTimeout(() => resolve(false), timeoutMs);
|
|
127
|
+
});
|
|
128
|
+
const releasedPromise = Promise.all(tasks.map(task => task.released.promise)).then(() => true);
|
|
129
|
+
const released = await Promise.race([releasedPromise, timeoutPromise]);
|
|
130
|
+
if (timer) {
|
|
131
|
+
clearTimeout(timer);
|
|
132
|
+
}
|
|
133
|
+
return released;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public abortOperation(operationId: string) {
|
|
137
|
+
const requestId = this.operationRequestIds.get(operationId);
|
|
138
|
+
if (requestId !== undefined) {
|
|
139
|
+
return this.abortRequest(requestId);
|
|
140
|
+
}
|
|
141
|
+
const now = Date.now();
|
|
142
|
+
this.prunePendingOperationCancellations(now);
|
|
143
|
+
this.pendingOperationCancellations.set(operationId, now + OPERATION_PRE_CANCEL_TTL_MS);
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
38
147
|
public getTask(requestId: number): RequestTask | undefined {
|
|
39
148
|
return this.requestQueue.get(requestId);
|
|
40
149
|
}
|
|
@@ -77,6 +186,7 @@ export default class RequestQueue {
|
|
|
77
186
|
count++;
|
|
78
187
|
}
|
|
79
188
|
});
|
|
189
|
+
this.pendingOperationCancellations.clear();
|
|
80
190
|
return count;
|
|
81
191
|
}
|
|
82
192
|
|
|
@@ -90,8 +200,8 @@ export default class RequestQueue {
|
|
|
90
200
|
const request = this.requestQueue.get(requestId);
|
|
91
201
|
if (request) {
|
|
92
202
|
request.callPromise?.resolve(response);
|
|
203
|
+
request.settled.resolve();
|
|
93
204
|
}
|
|
94
|
-
this.releaseTask(requestId);
|
|
95
205
|
}
|
|
96
206
|
|
|
97
207
|
// 拒绝请求
|
|
@@ -99,12 +209,22 @@ export default class RequestQueue {
|
|
|
99
209
|
const request = this.requestQueue.get(requestId);
|
|
100
210
|
if (request) {
|
|
101
211
|
request.callPromise?.reject(error);
|
|
212
|
+
request.settled.resolve();
|
|
102
213
|
}
|
|
103
|
-
this.releaseTask(requestId);
|
|
104
214
|
}
|
|
105
215
|
|
|
106
216
|
// 删除请求
|
|
107
217
|
public releaseTask(requestId: number) {
|
|
218
|
+
const task = this.requestQueue.get(requestId);
|
|
219
|
+
const operationId = task?.method.payload?.operationId;
|
|
220
|
+
if (
|
|
221
|
+
typeof operationId === 'string' &&
|
|
222
|
+
this.operationRequestIds.get(operationId) === requestId
|
|
223
|
+
) {
|
|
224
|
+
this.operationRequestIds.delete(operationId);
|
|
225
|
+
}
|
|
226
|
+
task?.settled.resolve();
|
|
227
|
+
task?.released.resolve();
|
|
108
228
|
this.requestQueue.delete(requestId);
|
|
109
229
|
}
|
|
110
230
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DEVICE } from '../events';
|
|
2
|
+
|
|
3
|
+
import type { Device, DeviceEvents } from '../device/Device';
|
|
4
|
+
|
|
5
|
+
export type HardwareUiEventHandlers = {
|
|
6
|
+
pin: (...event: DeviceEvents[typeof DEVICE.PIN]) => void;
|
|
7
|
+
button: (...event: DeviceEvents[typeof DEVICE.BUTTON]) => void;
|
|
8
|
+
passphrase: (...event: DeviceEvents[typeof DEVICE.PASSPHRASE]) => void;
|
|
9
|
+
passphraseOnDevice: (...event: DeviceEvents[typeof DEVICE.PASSPHRASE_ON_DEVICE]) => void;
|
|
10
|
+
attachPinOnDevice: (...event: DeviceEvents[typeof DEVICE.ATTACH_PIN_ON_DEVICE]) => void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function registerHardwareUiEventListeners(
|
|
14
|
+
device: Pick<Device, 'on'>,
|
|
15
|
+
handlers: HardwareUiEventHandlers
|
|
16
|
+
) {
|
|
17
|
+
device.on(DEVICE.PIN, handlers.pin);
|
|
18
|
+
device.on(DEVICE.BUTTON, handlers.button);
|
|
19
|
+
device.on(DEVICE.PASSPHRASE, handlers.passphrase);
|
|
20
|
+
device.on(DEVICE.PASSPHRASE_ON_DEVICE, handlers.passphraseOnDevice);
|
|
21
|
+
device.on(DEVICE.ATTACH_PIN_ON_DEVICE, handlers.attachPinOnDevice);
|
|
22
|
+
return true;
|
|
23
|
+
}
|