@onekeyfe/hd-core 1.1.34-alpha.2 → 1.1.34-alpha.3
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 +217 -0
- package/__tests__/RequestQueue.test.ts +140 -0
- package/__tests__/UploadPortfolio.test.ts +46 -0
- package/__tests__/connectSettings.test.ts +61 -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-mapper.test.ts +229 -0
- package/__tests__/device-utils.test.ts +106 -0
- package/__tests__/device-wallet-session-store.test.ts +191 -0
- package/__tests__/evmLedgerLegacySafety.test.ts +15 -4
- package/__tests__/evmSignTransaction.test.ts +1 -1
- package/__tests__/evmSignTypedData.test.ts +1 -1
- package/__tests__/filesystemValidation.test.ts +53 -0
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
- package/__tests__/firmware-update/firmware-checkpoint.test.ts +105 -0
- package/__tests__/firmware-update/firmware-host-binding.test.ts +73 -0
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +17 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +358 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +200 -0
- package/__tests__/firmware-update/firmware-update-recovery.test.ts +81 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +48 -31
- package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
- package/__tests__/get-device-state.test.ts +403 -0
- package/__tests__/logBlockEvent.test.ts +61 -0
- package/__tests__/logger.test.ts +34 -0
- package/__tests__/open-wallet-session.test.ts +565 -0
- package/__tests__/preInitialize.test.ts +33 -0
- package/__tests__/pro2Wallpaper.test.ts +39 -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 +6008 -0
- package/__tests__/protocolV2FileWrite.test.ts +67 -0
- package/__tests__/public-pro2-api-boundary.test.ts +66 -0
- package/__tests__/search-devices.test.ts +136 -0
- package/dist/api/BaseMethod.d.ts +12 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.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 +10 -0
- package/dist/api/DirList.d.ts.map +1 -0
- package/dist/api/DirMake.d.ts +9 -0
- package/dist/api/DirMake.d.ts.map +1 -0
- package/dist/api/DirRemove.d.ts +9 -0
- package/dist/api/DirRemove.d.ts.map +1 -0
- package/dist/api/FileDelete.d.ts +9 -0
- package/dist/api/FileDelete.d.ts.map +1 -0
- package/dist/api/FileRead.d.ts +19 -0
- package/dist/api/FileRead.d.ts.map +1 -0
- package/dist/api/FileWrite.d.ts +25 -0
- package/dist/api/FileWrite.d.ts.map +1 -0
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +14 -3
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +10 -3
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +75 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -0
- 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.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 +10 -0
- package/dist/api/PathInfo.d.ts.map +1 -0
- package/dist/api/PromptWebDeviceAccess.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts +5 -1
- 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/alephium/AlephiumGetAddress.d.ts +2 -6
- package/dist/api/alephium/AlephiumGetAddress.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignMessage.d.ts +2 -5
- package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignTransaction.d.ts +5 -8
- package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetAddress.d.ts +2 -9
- package/dist/api/benfen/BenfenGetAddress.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetPublicKey.d.ts +2 -9
- package/dist/api/benfen/BenfenGetPublicKey.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignMessage.d.ts +2 -8
- package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignTransaction.d.ts +2 -8
- package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCGetAddress.d.ts +1 -11
- package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
- package/dist/api/btc/BTCGetPublicKey.d.ts +1 -11
- package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
- package/dist/api/btc/BTCSignMessage.d.ts +1 -15
- package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
- package/dist/api/btc/BTCSignPsbt.d.ts.map +1 -1
- package/dist/api/btc/BTCSignTransaction.d.ts +1 -11
- package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCVerifyMessage.d.ts +1 -11
- package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
- package/dist/api/btc/helpers/versionLimit.d.ts +2 -11
- package/dist/api/btc/helpers/versionLimit.d.ts.map +1 -1
- package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignTransaction.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 +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/DeviceSupportFeatures.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 +7 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceUploadResource.d.ts.map +1 -1
- package/dist/api/device/DeviceVerify.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/dynex/DnxGetAddress.d.ts.map +1 -1
- package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
- package/dist/api/evm/EVMGetPublicKey.d.ts.map +1 -1
- package/dist/api/evm/EVMSignMessageEIP712.d.ts +2 -8
- package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/evm/latest/signTypedData.d.ts +1 -1
- package/dist/api/evm/latest/signTypedData.d.ts.map +1 -1
- package/dist/api/evm/latest/signTypedHash.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/getAddress.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/getPublicKey.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/signMessage.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/signTypedData.d.ts +1 -1
- package/dist/api/evm/legacyV1/signTypedData.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/signTypedHash.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/verifyMessage.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +26 -0
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareCheckpoint.d.ts +15 -0
- package/dist/api/firmware/FirmwareCheckpoint.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts +6 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +10 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +3 -0
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +29 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +25 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/api/firmware/bootloaderHelper.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +11 -0
- 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/firmware/updateBootloader.d.ts +2 -0
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +9 -1
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/batchGetPublickeys.d.ts +3 -0
- package/dist/api/helpers/batchGetPublickeys.d.ts.map +1 -1
- package/dist/api/helpers/filesystemValidation.d.ts +10 -0
- package/dist/api/helpers/filesystemValidation.d.ts.map +1 -0
- 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 +29 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/lightning/LnurlAuth.d.ts +4 -0
- package/dist/api/lightning/LnurlAuth.d.ts.map +1 -1
- package/dist/api/neo/NeoGetAddress.d.ts +2 -8
- package/dist/api/neo/NeoGetAddress.d.ts.map +1 -1
- package/dist/api/neo/NeoSignTransaction.d.ts +2 -8
- package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
- package/dist/api/nervos/NervosGetAddress.d.ts +2 -9
- package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -1
- package/dist/api/nervos/NervosSignTransaction.d.ts +9 -12
- package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
- package/dist/api/nexa/NexaGetAddress.d.ts +2 -8
- package/dist/api/nexa/NexaGetAddress.d.ts.map +1 -1
- package/dist/api/nexa/NexaSignTransaction.d.ts +2 -9
- package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotGetAddress.d.ts +3 -0
- package/dist/api/polkadot/PolkadotGetAddress.d.ts.map +1 -1
- package/dist/api/polkadot/networks.d.ts +3 -0
- package/dist/api/polkadot/networks.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 +7 -0
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
- 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 +7 -0
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts +28 -0
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts.map +1 -0
- 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 +6 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts +6 -0
- package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -0
- package/dist/api/protocol-v2/Ping.d.ts +8 -0
- package/dist/api/protocol-v2/Ping.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 +42 -0
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
- package/dist/api/scdo/ScdoGetAddress.d.ts +2 -6
- package/dist/api/scdo/ScdoGetAddress.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignMessage.d.ts +2 -5
- package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignTransaction.d.ts +2 -5
- package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
- package/dist/api/solana/SolGetAddress.d.ts +1 -0
- package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
- package/dist/api/solana/SolSignMessage.d.ts +3 -0
- package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +3 -0
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +6 -0
- package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
- package/dist/api/stellar/StellarGetAddress.d.ts +2 -1
- package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +3 -2
- package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
- package/dist/api/sui/SuiGetAddress.d.ts +3 -0
- package/dist/api/sui/SuiGetAddress.d.ts.map +1 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts +3 -0
- package/dist/api/sui/SuiGetPublicKey.d.ts.map +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts +3 -0
- package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +5 -2
- package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
- package/dist/api/ton/TonGetAddress.d.ts +3 -0
- package/dist/api/ton/TonGetAddress.d.ts.map +1 -1
- package/dist/api/ton/TonSignData.d.ts +1 -0
- package/dist/api/ton/TonSignData.d.ts.map +1 -1
- package/dist/api/ton/TonSignMessage.d.ts +3 -0
- package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
- package/dist/api/ton/TonSignProof.d.ts +3 -0
- package/dist/api/ton/TonSignProof.d.ts.map +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +3 -0
- package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
- package/dist/api/tron/TronSignTransaction.d.ts +3 -0
- package/dist/api/tron/TronSignTransaction.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 +9 -5
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/MessagesConfig.d.ts +2 -2
- package/dist/data-manager/MessagesConfig.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts +5 -4
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +60 -16
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +16 -14
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +2 -1
- package/dist/device/DeviceConnector.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 +15 -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 +12 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -0
- package/dist/deviceProfile/index.d.ts +2 -0
- package/dist/deviceProfile/index.d.ts.map +1 -0
- 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 +1 -0
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +26 -2
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +1797 -451
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26905 -5611
- 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 +88 -0
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/firmware.d.ts +15 -0
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/index.d.ts +5 -0
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
- 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 +21 -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 +4 -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/deviceUpdateBootloader.d.ts +6 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +4 -1
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +114 -1
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +13 -0
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts +35 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +43 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +1 -0
- 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 -1
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +48 -2
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +35 -0
- package/dist/types/api/openWalletSession.d.ts.map +1 -0
- package/dist/types/api/protocolV2.d.ts +113 -0
- package/dist/types/api/protocolV2.d.ts.map +1 -0
- package/dist/types/api/searchDevices.d.ts +2 -2
- package/dist/types/api/searchDevices.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 +207 -5
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +3 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +33 -0
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/capabilitieUtils.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 +17 -9
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts +10 -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/findDefectiveBatchDevice.d.ts +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/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/dist/utils/versionUtils.d.ts +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +60 -23
- package/src/api/CheckAllFirmwareRelease.ts +16 -3
- 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 +33 -0
- package/src/api/DirMake.ts +23 -0
- package/src/api/DirRemove.ts +23 -0
- package/src/api/FileDelete.ts +23 -0
- package/src/api/FileRead.ts +183 -0
- package/src/api/FileWrite.ts +71 -0
- package/src/api/FirmwareUpdate.ts +15 -7
- package/src/api/FirmwareUpdateV2.ts +354 -148
- package/src/api/FirmwareUpdateV3.ts +376 -62
- package/src/api/FirmwareUpdateV4.ts +2279 -0
- package/src/api/GetDeviceState.ts +55 -0
- package/src/api/GetFeatures.ts +12 -4
- package/src/api/GetOnekeyFeatures.ts +15 -3
- package/src/api/GetPassphraseState.ts +9 -10
- package/src/api/OpenWalletSession.ts +211 -0
- package/src/api/PathInfo.ts +41 -0
- package/src/api/PromptWebDeviceAccess.ts +10 -1
- package/src/api/SearchDevices.ts +33 -3
- package/src/api/UploadPortfolio.ts +50 -0
- package/src/api/alephium/AlephiumGetAddress.ts +6 -2
- package/src/api/alephium/AlephiumSignMessage.ts +6 -1
- package/src/api/alephium/AlephiumSignTransaction.ts +15 -4
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +25 -21
- package/src/api/aptos/AptosGetAddress.ts +2 -3
- package/src/api/benfen/BenfenGetAddress.ts +11 -7
- package/src/api/benfen/BenfenGetPublicKey.ts +6 -2
- package/src/api/benfen/BenfenSignMessage.ts +6 -1
- package/src/api/benfen/BenfenSignTransaction.ts +6 -1
- package/src/api/btc/BTCGetPublicKey.ts +3 -2
- package/src/api/btc/BTCSignPsbt.ts +1 -2
- package/src/api/btc/helpers/versionLimit.ts +7 -1
- package/src/api/cardano/CardanoSignTransaction.ts +2 -4
- package/src/api/conflux/ConfluxSignTransaction.ts +5 -2
- package/src/api/device/DeviceCancel.ts +1 -0
- package/src/api/device/DeviceChangePin.ts +24 -0
- package/src/api/device/DeviceFullyUploadResource.ts +6 -7
- package/src/api/device/DeviceLock.ts +2 -3
- package/src/api/device/DeviceRebootToBoardloader.ts +11 -1
- package/src/api/device/DeviceRebootToBootloader.ts +11 -1
- package/src/api/device/DeviceSettings.ts +121 -0
- package/src/api/device/DeviceSupportFeatures.ts +2 -13
- package/src/api/device/DeviceUnlock.ts +9 -0
- package/src/api/device/DeviceUpdateBootloader.ts +175 -11
- package/src/api/device/DeviceUploadResource.ts +4 -5
- package/src/api/device/DeviceVerify.ts +1 -2
- package/src/api/device/DeviceWipe.ts +19 -0
- package/src/api/dynex/DnxGetAddress.ts +6 -0
- package/src/api/dynex/DnxSignTransaction.ts +6 -0
- package/src/api/evm/EVMGetAddress.ts +1 -1
- package/src/api/evm/EVMGetPublicKey.ts +3 -4
- package/src/api/evm/EVMSignMessage.ts +1 -1
- package/src/api/evm/EVMSignMessageEIP712.ts +14 -1
- package/src/api/evm/EVMSignTransaction.ts +1 -1
- package/src/api/evm/EVMSignTypedData.ts +30 -18
- package/src/api/evm/EVMVerifyMessage.ts +1 -1
- package/src/api/evm/latest/signTypedHash.ts +2 -4
- package/src/api/evm/legacyV1/getAddress.ts +5 -3
- package/src/api/evm/legacyV1/getPublicKey.ts +5 -3
- package/src/api/evm/legacyV1/signMessage.ts +5 -3
- package/src/api/evm/legacyV1/signTypedData.ts +9 -8
- package/src/api/evm/legacyV1/signTypedHash.ts +7 -7
- package/src/api/evm/legacyV1/verifyMessage.ts +5 -3
- package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
- package/src/api/firmware/FirmwareCheckpoint.ts +188 -0
- package/src/api/firmware/FirmwareHostBinding.ts +108 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +83 -15
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +13 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +729 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +403 -0
- package/src/api/firmware/bootloaderHelper.ts +3 -2
- package/src/api/firmware/getBinary.ts +1 -1
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/firmware/releaseHelper.ts +3 -3
- package/src/api/firmware/updateBootloader.ts +19 -4
- package/src/api/firmware/uploadFirmware.ts +148 -34
- package/src/api/helpers/batchGetPublickeys.ts +51 -6
- package/src/api/helpers/filesystemValidation.ts +112 -0
- package/src/api/helpers/protocolV2FileWrite.ts +193 -0
- package/src/api/index.ts +32 -0
- package/src/api/kaspa/KaspaSignTransaction.ts +2 -3
- package/src/api/lightning/LnurlAuth.ts +4 -0
- package/src/api/neo/NeoGetAddress.ts +6 -1
- package/src/api/neo/NeoSignTransaction.ts +6 -1
- package/src/api/nervos/NervosGetAddress.ts +6 -2
- package/src/api/nervos/NervosSignTransaction.ts +14 -4
- package/src/api/nexa/NexaGetAddress.ts +6 -2
- package/src/api/nexa/NexaSignTransaction.ts +11 -12
- package/src/api/polkadot/networks.ts +9 -0
- package/src/api/protocol-v2/DeviceFactoryInfoGet.ts +20 -0
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +32 -0
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +61 -0
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +55 -0
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +18 -0
- package/src/api/protocol-v2/DeviceInfoGet.ts +145 -0
- package/src/api/protocol-v2/DeviceReboot.ts +26 -0
- package/src/api/protocol-v2/DeviceSessionOpen.ts +102 -0
- 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 +19 -0
- package/src/api/protocol-v2/FilesystemPermissionFix.ts +16 -0
- package/src/api/protocol-v2/Ping.ts +18 -0
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +16 -0
- package/src/api/protocol-v2/helpers.ts +203 -0
- package/src/api/scdo/ScdoGetAddress.ts +6 -2
- package/src/api/scdo/ScdoSignMessage.ts +6 -1
- package/src/api/scdo/ScdoSignTransaction.ts +6 -2
- package/src/api/solana/SolGetAddress.ts +4 -0
- package/src/api/solana/SolSignMessage.ts +3 -0
- package/src/api/solana/SolSignOffchainMessage.ts +3 -0
- package/src/api/solana/SolSignTransaction.ts +6 -0
- package/src/api/stellar/StellarGetAddress.ts +10 -1
- package/src/api/stellar/StellarSignTransaction.ts +14 -1
- package/src/api/sui/SuiGetAddress.ts +5 -3
- package/src/api/sui/SuiGetPublicKey.ts +3 -0
- package/src/api/sui/SuiSignMessage.ts +3 -0
- package/src/api/sui/SuiSignTransaction.ts +14 -12
- package/src/api/ton/TonGetAddress.ts +3 -0
- package/src/api/ton/TonSignData.ts +6 -3
- package/src/api/ton/TonSignMessage.ts +6 -5
- package/src/api/ton/TonSignProof.ts +3 -0
- package/src/api/tron/TronSignMessage.ts +4 -1
- package/src/api/tron/TronSignTransaction.ts +3 -0
- package/src/api/utils.ts +7 -3
- package/src/api/xrp/XrpSignTransaction.ts +1 -1
- 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 +253 -125
- package/src/data/messages/messages-protocol-v2.json +13544 -0
- package/src/data-manager/DataManager.ts +61 -49
- package/src/data-manager/MessagesConfig.ts +14 -14
- package/src/data-manager/TransportManager.ts +38 -12
- package/src/data-manager/connectSettings.ts +15 -0
- package/src/device/Device.ts +759 -164
- package/src/device/DeviceCommands.ts +245 -36
- package/src/device/DeviceConnector.ts +29 -4
- package/src/device/DeviceFeaturesState.ts +34 -0
- package/src/device/DevicePool.ts +69 -21
- 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 +78 -0
- package/src/device/cloneDeviceState.ts +39 -0
- package/src/device/deviceIdentity.ts +18 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +391 -0
- package/src/deviceProfile/index.ts +4 -0
- 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 +30 -0
- package/src/events/ui-request.ts +32 -2
- package/src/index.ts +9 -0
- package/src/inject.ts +75 -3
- package/src/lowLevelInject.ts +8 -1
- package/src/protocols/protocol-v2/deviceSession.ts +24 -0
- package/src/protocols/protocol-v2/features.ts +163 -0
- package/src/protocols/protocol-v2/firmware.ts +21 -0
- package/src/protocols/protocol-v2/index.ts +18 -0
- 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 +202 -0
- package/src/topLevelInject.ts +7 -1
- package/src/types/api/checkAllFirmwareRelease.ts +4 -2
- package/src/types/api/deviceSettings.ts +9 -0
- package/src/types/api/deviceUnlock.ts +1 -1
- package/src/types/api/deviceUpdateBootloader.ts +10 -1
- package/src/types/api/export.ts +25 -0
- package/src/types/api/firmwareUpdate.ts +163 -1
- package/src/types/api/firmwareUpdateCapabilities.ts +13 -0
- package/src/types/api/firmwareUpdatePlan.ts +52 -0
- package/src/types/api/firmwareUpdatePreparedPlan.ts +55 -0
- 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 +10 -2
- package/src/types/api/index.ts +89 -2
- package/src/types/api/openWalletSession.ts +54 -0
- package/src/types/api/protocolV2.ts +244 -0
- package/src/types/api/searchDevices.ts +2 -2
- package/src/types/api/sessionCache.ts +14 -0
- package/src/types/device.ts +266 -5
- package/src/types/params.ts +11 -0
- package/src/types/settings.ts +54 -29
- package/src/utils/capabilitieUtils.ts +1 -2
- package/src/utils/deviceFeaturesCompat.ts +173 -0
- package/src/utils/deviceFeaturesUtils.ts +122 -84
- package/src/utils/deviceInfoUtils.ts +38 -87
- package/src/utils/deviceSettings.ts +48 -0
- package/src/utils/deviceVersionUtils.ts +25 -62
- package/src/utils/findDefectiveBatchDevice.ts +8 -8
- package/src/utils/homescreen.ts +10 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/pro2Wallpaper.ts +109 -0
- package/src/utils/tracing.ts +3 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ERRORS, HardwareError, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
import { DeviceSessionOpen_FailureSubCodes } from '@onekeyfe/hd-transport';
|
|
2
3
|
|
|
3
4
|
import TransportManager from '../data-manager/TransportManager';
|
|
4
5
|
import DataManager from '../data-manager/DataManager';
|
|
5
|
-
import { LoggerNames,
|
|
6
|
+
import { LoggerNames, getLogger, patchFeatures } from '../utils';
|
|
6
7
|
import { DEVICE, type PassphraseRequestPayload } from '../events';
|
|
7
8
|
import { DeviceModelToTypes } from '../types';
|
|
8
9
|
import {
|
|
@@ -12,7 +13,12 @@ import {
|
|
|
12
13
|
} from '../utils/tracing';
|
|
13
14
|
|
|
14
15
|
import type { Device } from './Device';
|
|
15
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
FailureType,
|
|
18
|
+
Messages,
|
|
19
|
+
Transport,
|
|
20
|
+
TransportCallOptions,
|
|
21
|
+
} from '@onekeyfe/hd-transport';
|
|
16
22
|
|
|
17
23
|
export type PassphrasePromptResponse = {
|
|
18
24
|
passphrase?: string;
|
|
@@ -22,15 +28,137 @@ export type PassphrasePromptResponse = {
|
|
|
22
28
|
};
|
|
23
29
|
|
|
24
30
|
type MessageType = Messages.MessageType;
|
|
25
|
-
type MessageKey = keyof MessageType
|
|
31
|
+
type MessageKey = Extract<keyof MessageType, string>;
|
|
26
32
|
export type TypedResponseMessage<T extends MessageKey> = {
|
|
27
33
|
type: T;
|
|
28
34
|
message: MessageType[T];
|
|
29
35
|
};
|
|
30
36
|
type TypedCallResponseMap = {
|
|
31
|
-
[K in
|
|
37
|
+
[K in MessageKey]: TypedResponseMessage<K>;
|
|
38
|
+
};
|
|
39
|
+
export type DefaultMessageResponse = TypedCallResponseMap[MessageKey];
|
|
40
|
+
|
|
41
|
+
const MAX_DEBUG_ARRAY_ITEMS = 20;
|
|
42
|
+
const MAX_DEBUG_OBJECT_KEYS = 40;
|
|
43
|
+
const MAX_DEBUG_STRING_LENGTH = 512;
|
|
44
|
+
const MAX_DEBUG_DEPTH = 4;
|
|
45
|
+
const HIGH_VOLUME_DEBUG_CALLS = new Set([
|
|
46
|
+
'FilesystemFileRead',
|
|
47
|
+
'FilesystemFileWrite',
|
|
48
|
+
'FileRead',
|
|
49
|
+
'FileWrite',
|
|
50
|
+
'EmmcFileRead',
|
|
51
|
+
'EmmcFileWrite',
|
|
52
|
+
'FirmwareUpload',
|
|
53
|
+
'ResourceAck',
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
function shouldReduceDebugForCall(type: string) {
|
|
57
|
+
return HIGH_VOLUME_DEBUG_CALLS.has(type);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getBinaryByteLength(value: unknown): number | undefined {
|
|
61
|
+
if (value instanceof ArrayBuffer) {
|
|
62
|
+
return value.byteLength;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (ArrayBuffer.isView(value)) {
|
|
66
|
+
return value.byteLength;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (typeof Blob !== 'undefined' && value instanceof Blob) {
|
|
70
|
+
return value.size;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function summarizeRedactedData(value: unknown): string {
|
|
77
|
+
const byteLength = getBinaryByteLength(value);
|
|
78
|
+
if (byteLength !== undefined) {
|
|
79
|
+
return `[redacted data: ${byteLength} bytes]`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (typeof value === 'string') {
|
|
83
|
+
return `[redacted data: string length=${value.length}]`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (Array.isArray(value)) {
|
|
87
|
+
return `[redacted data: array length=${value.length}]`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (value && typeof value === 'object') {
|
|
91
|
+
return `[redacted data: object keys=${Object.keys(value).length}]`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return `[redacted data: ${typeof value}]`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function sanitizeDebugPayload(value: unknown, key = '', depth = 0): unknown {
|
|
98
|
+
if (key === 'data' && value !== null && value !== undefined) {
|
|
99
|
+
return summarizeRedactedData(value);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Redact passphrase-bearing keys as defense in depth so commands such as
|
|
103
|
+
// Protocol V2 DeviceSessionOpen can never write hidden-wallet secrets to logs.
|
|
104
|
+
if (key && /passphrase/i.test(key)) {
|
|
105
|
+
return '[redacted passphrase]';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const byteLength = getBinaryByteLength(value);
|
|
109
|
+
if (byteLength !== undefined) {
|
|
110
|
+
return `[binary: ${byteLength} bytes]`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (typeof value === 'string') {
|
|
114
|
+
return value.length > MAX_DEBUG_STRING_LENGTH
|
|
115
|
+
? `${value.slice(0, MAX_DEBUG_STRING_LENGTH)}... (len=${value.length})`
|
|
116
|
+
: value;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!value || typeof value !== 'object') {
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (depth >= MAX_DEBUG_DEPTH) {
|
|
124
|
+
return Array.isArray(value)
|
|
125
|
+
? `[array length=${value.length}]`
|
|
126
|
+
: `[object keys=${Object.keys(value).length}]`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (Array.isArray(value)) {
|
|
130
|
+
const items = value
|
|
131
|
+
.slice(0, MAX_DEBUG_ARRAY_ITEMS)
|
|
132
|
+
.map(item => sanitizeDebugPayload(item, key, depth + 1));
|
|
133
|
+
if (value.length > MAX_DEBUG_ARRAY_ITEMS) {
|
|
134
|
+
items.push(`... (${value.length - MAX_DEBUG_ARRAY_ITEMS} more)`);
|
|
135
|
+
}
|
|
136
|
+
return items;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const entries = Object.entries(value).slice(0, MAX_DEBUG_OBJECT_KEYS);
|
|
140
|
+
const sanitized: Record<string, unknown> = {};
|
|
141
|
+
entries.forEach(([entryKey, entryValue]) => {
|
|
142
|
+
sanitized[entryKey] = sanitizeDebugPayload(entryValue, entryKey, depth + 1);
|
|
143
|
+
});
|
|
144
|
+
if (Object.keys(value).length > MAX_DEBUG_OBJECT_KEYS) {
|
|
145
|
+
sanitized.__truncated__ = `${Object.keys(value).length - MAX_DEBUG_OBJECT_KEYS} more keys`;
|
|
146
|
+
}
|
|
147
|
+
return sanitized;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Interactive acknowledgements must not inherit timeoutMs from the original call.
|
|
152
|
+
* User confirmation and PIN/passphrase entry have unbounded think time. Preserve only
|
|
153
|
+
* response-related options such as expectedTypes and intermediateTypes.
|
|
154
|
+
*/
|
|
155
|
+
const stripInteractiveAckTimeout = (
|
|
156
|
+
options?: TransportCallOptions
|
|
157
|
+
): TransportCallOptions | undefined => {
|
|
158
|
+
if (!options) return options;
|
|
159
|
+
const { timeoutMs: _timeoutMs, ...rest } = options;
|
|
160
|
+
return rest;
|
|
32
161
|
};
|
|
33
|
-
export type DefaultMessageResponse = TypedCallResponseMap[keyof MessageType];
|
|
34
162
|
|
|
35
163
|
const assertType = (res: DefaultMessageResponse, resType: string | string[]) => {
|
|
36
164
|
const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
|
|
@@ -224,17 +352,21 @@ export class DeviceCommands {
|
|
|
224
352
|
// Sends an async message to the opened device.
|
|
225
353
|
async call(
|
|
226
354
|
type: MessageKey,
|
|
227
|
-
msg
|
|
355
|
+
msg?: DefaultMessageResponse['message'],
|
|
356
|
+
options?: TransportCallOptions
|
|
228
357
|
): Promise<DefaultMessageResponse> {
|
|
229
|
-
|
|
358
|
+
const shouldReduceDebug = shouldReduceDebugForCall(type);
|
|
359
|
+
if (!shouldReduceDebug) {
|
|
360
|
+
Log.debug('[DeviceCommands] [call] Sending', type);
|
|
361
|
+
}
|
|
230
362
|
|
|
231
363
|
try {
|
|
232
|
-
const promise = this.transport.call(this.mainId, type, msg) as any;
|
|
364
|
+
const promise = this.transport.call(this.mainId, type, msg ?? {}, options) as any;
|
|
233
365
|
this.callPromise = promise;
|
|
234
366
|
const res = await promise;
|
|
235
367
|
if (res.type === 'Failure') {
|
|
236
368
|
LogCore.debug('[DeviceCommands] [call] Received', res.type, res.message);
|
|
237
|
-
} else {
|
|
369
|
+
} else if (!shouldReduceDebug) {
|
|
238
370
|
LogCore.debug('[DeviceCommands] [call] Received', res.type);
|
|
239
371
|
}
|
|
240
372
|
return res;
|
|
@@ -283,19 +415,22 @@ export class DeviceCommands {
|
|
|
283
415
|
typedCall<T extends MessageKey, R extends MessageKey[]>(
|
|
284
416
|
type: T,
|
|
285
417
|
resType: R,
|
|
286
|
-
msg?: MessageType[T]
|
|
418
|
+
msg?: MessageType[T],
|
|
419
|
+
options?: TransportCallOptions
|
|
287
420
|
): Promise<TypedCallResponseMap[R[number]]>;
|
|
288
421
|
|
|
289
422
|
typedCall<T extends MessageKey, R extends MessageKey>(
|
|
290
423
|
type: T,
|
|
291
424
|
resType: R,
|
|
292
|
-
msg?: MessageType[T]
|
|
425
|
+
msg?: MessageType[T],
|
|
426
|
+
options?: TransportCallOptions
|
|
293
427
|
): Promise<TypedResponseMessage<R>>;
|
|
294
428
|
|
|
295
429
|
async typedCall(
|
|
296
430
|
type: MessageKey,
|
|
297
431
|
resType: MessageKey | MessageKey[],
|
|
298
|
-
msg?: DefaultMessageResponse['message']
|
|
432
|
+
msg?: DefaultMessageResponse['message'],
|
|
433
|
+
options?: TransportCallOptions
|
|
299
434
|
) {
|
|
300
435
|
if (this.disposed) {
|
|
301
436
|
throw ERRORS.TypedError(
|
|
@@ -311,17 +446,30 @@ export class DeviceCommands {
|
|
|
311
446
|
'PinMatrixAck',
|
|
312
447
|
'PassphraseAck',
|
|
313
448
|
'Cancel',
|
|
449
|
+
'DeviceSessionOpen',
|
|
314
450
|
'BixinPinInputOnDevice',
|
|
451
|
+
'FilesystemFileRead',
|
|
452
|
+
'FilesystemFileWrite',
|
|
453
|
+
'FileRead',
|
|
454
|
+
'FileWrite',
|
|
455
|
+
'EmmcFileRead',
|
|
456
|
+
'EmmcFileWrite',
|
|
457
|
+
'FirmwareUpload',
|
|
458
|
+
'ResourceAck',
|
|
315
459
|
] as any;
|
|
316
460
|
if (!skipTypes.includes(type) && msg) {
|
|
317
461
|
// Use debug channel to avoid noise escalation
|
|
318
|
-
Log.debug('[DeviceCommands] [typedCall] Sending payload', type, msg);
|
|
462
|
+
Log.debug('[DeviceCommands] [typedCall] Sending payload', type, sanitizeDebugPayload(msg));
|
|
319
463
|
}
|
|
320
464
|
} catch (e) {
|
|
321
465
|
// ignore logging errors
|
|
322
466
|
}
|
|
323
467
|
|
|
324
|
-
const
|
|
468
|
+
const expectedTypes = Array.isArray(resType) ? resType : resType.split('|');
|
|
469
|
+
const response = await this._commonCall(type, msg, {
|
|
470
|
+
...options,
|
|
471
|
+
expectedTypes: options?.expectedTypes ?? expectedTypes,
|
|
472
|
+
});
|
|
325
473
|
try {
|
|
326
474
|
assertType(response, resType);
|
|
327
475
|
} catch (error) {
|
|
@@ -334,6 +482,12 @@ export class DeviceCommands {
|
|
|
334
482
|
// throw bridge network error
|
|
335
483
|
if (error instanceof HardwareError) {
|
|
336
484
|
if (error.errorCode === HardwareErrorCode.ResponseUnexpectTypeError) {
|
|
485
|
+
Log.debug('[DeviceCommands] [typedCall] Unexpected response type', {
|
|
486
|
+
request: type,
|
|
487
|
+
expected: resType,
|
|
488
|
+
received: response.type,
|
|
489
|
+
response: sanitizeDebugPayload(response.message),
|
|
490
|
+
});
|
|
337
491
|
// Do not intercept CallMethodError
|
|
338
492
|
// Do not intercept “assertType: Response of unexpected type” error
|
|
339
493
|
// Blocking the above two messages will not know what the specific error message is, and the specific error should be handled by the subsequent business logic.
|
|
@@ -347,7 +501,7 @@ export class DeviceCommands {
|
|
|
347
501
|
if (error.message.indexOf('BridgeDeviceDisconnected') > -1) {
|
|
348
502
|
throw ERRORS.TypedError(HardwareErrorCode.BridgeDeviceDisconnected);
|
|
349
503
|
}
|
|
350
|
-
throw
|
|
504
|
+
throw error;
|
|
351
505
|
}
|
|
352
506
|
} else {
|
|
353
507
|
// throw error anyway, next call should be resolved properly// throw error anyway, next call should be resolved properly
|
|
@@ -357,20 +511,27 @@ export class DeviceCommands {
|
|
|
357
511
|
return response;
|
|
358
512
|
}
|
|
359
513
|
|
|
360
|
-
async _commonCall(
|
|
361
|
-
|
|
362
|
-
|
|
514
|
+
async _commonCall(
|
|
515
|
+
type: MessageKey,
|
|
516
|
+
msg?: DefaultMessageResponse['message'],
|
|
517
|
+
options?: TransportCallOptions
|
|
518
|
+
) {
|
|
519
|
+
const resp = await this.call(type, msg, options);
|
|
520
|
+
return this._filterCommonTypes(resp, type, options);
|
|
363
521
|
}
|
|
364
522
|
|
|
365
523
|
_filterCommonTypes(
|
|
366
524
|
res: DefaultMessageResponse,
|
|
367
|
-
callType: MessageKey
|
|
525
|
+
callType: MessageKey,
|
|
526
|
+
options?: TransportCallOptions
|
|
368
527
|
): Promise<DefaultMessageResponse> {
|
|
369
528
|
try {
|
|
370
|
-
if (
|
|
371
|
-
|
|
529
|
+
if (shouldReduceDebugForCall(callType)) {
|
|
530
|
+
// Avoid debug logging on every high-frequency file-write chunk.
|
|
531
|
+
} else if (DataManager.getSettings('env') === 'react-native') {
|
|
532
|
+
Log.debug('_filterCommonTypes: ', JSON.stringify(sanitizeDebugPayload(res)));
|
|
372
533
|
} else {
|
|
373
|
-
Log.debug('_filterCommonTypes: ', res);
|
|
534
|
+
Log.debug('_filterCommonTypes: ', sanitizeDebugPayload(res));
|
|
374
535
|
}
|
|
375
536
|
} catch (error) {
|
|
376
537
|
// ignore
|
|
@@ -378,8 +539,9 @@ export class DeviceCommands {
|
|
|
378
539
|
|
|
379
540
|
this.device.clearCancelableAction();
|
|
380
541
|
if (res.type === 'Failure') {
|
|
381
|
-
const { code, message } = res.message as {
|
|
542
|
+
const { code, subcode, message } = res.message as {
|
|
382
543
|
code?: string | FailureType;
|
|
544
|
+
subcode?: number;
|
|
383
545
|
message?: string;
|
|
384
546
|
};
|
|
385
547
|
let error: HardwareError | null = null;
|
|
@@ -423,8 +585,25 @@ export class DeviceCommands {
|
|
|
423
585
|
}
|
|
424
586
|
|
|
425
587
|
if (code === 'Failure_ProcessError') {
|
|
426
|
-
|
|
427
|
-
|
|
588
|
+
const isInvalidWalletSession =
|
|
589
|
+
this.device.isProtocolV2() &&
|
|
590
|
+
callType === 'DeviceSessionOpen' &&
|
|
591
|
+
subcode === DeviceSessionOpen_FailureSubCodes.InvalidSession;
|
|
592
|
+
const isLegacyProtocolV2LockedFailure =
|
|
593
|
+
this.device.isProtocolV2() && /^device (?:is )?locked$/i.test(message?.trim() ?? '');
|
|
594
|
+
if (isInvalidWalletSession) {
|
|
595
|
+
error = ERRORS.TypedError(HardwareErrorCode.WalletSessionInvalid, message, {
|
|
596
|
+
failureCode: code,
|
|
597
|
+
subcode,
|
|
598
|
+
firmwareMessage: message,
|
|
599
|
+
});
|
|
600
|
+
} else if (subcode === 9 || isLegacyProtocolV2LockedFailure) {
|
|
601
|
+
error = ERRORS.TypedError(HardwareErrorCode.DeviceLocked, message, {
|
|
602
|
+
failureCode: code,
|
|
603
|
+
subcode,
|
|
604
|
+
firmwareMessage: message,
|
|
605
|
+
});
|
|
606
|
+
} else if (
|
|
428
607
|
message?.includes('Bootloader file verify failed') ||
|
|
429
608
|
message?.includes('verify failed')
|
|
430
609
|
) {
|
|
@@ -461,7 +640,7 @@ export class DeviceCommands {
|
|
|
461
640
|
}
|
|
462
641
|
|
|
463
642
|
if (res.type === 'ButtonRequest') {
|
|
464
|
-
const deviceType =
|
|
643
|
+
const deviceType = this.device.getCurrentDeviceType();
|
|
465
644
|
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
|
|
466
645
|
this.device.setCancelableAction(() => this.cancelDeviceOnOneKeyDevice());
|
|
467
646
|
} else {
|
|
@@ -472,7 +651,7 @@ export class DeviceCommands {
|
|
|
472
651
|
} else {
|
|
473
652
|
this.device.emit(DEVICE.BUTTON, this.device, res.message);
|
|
474
653
|
}
|
|
475
|
-
return this._commonCall('ButtonAck', {});
|
|
654
|
+
return this._commonCall('ButtonAck', {}, stripInteractiveAckTimeout(options));
|
|
476
655
|
}
|
|
477
656
|
|
|
478
657
|
if (res.type === 'EntropyRequest') {
|
|
@@ -485,11 +664,15 @@ export class DeviceCommands {
|
|
|
485
664
|
if (pin === '@@ONEKEY_INPUT_PIN_IN_DEVICE') {
|
|
486
665
|
// only classic\1s\mini\pure
|
|
487
666
|
this.device.setCancelableAction(() => this.cancelDeviceOnOneKeyDevice());
|
|
488
|
-
return this._commonCall(
|
|
667
|
+
return this._commonCall(
|
|
668
|
+
'BixinPinInputOnDevice',
|
|
669
|
+
{},
|
|
670
|
+
stripInteractiveAckTimeout(options)
|
|
671
|
+
).finally(() => {
|
|
489
672
|
this.device.clearCancelableAction();
|
|
490
673
|
});
|
|
491
674
|
}
|
|
492
|
-
return this._commonCall('PinMatrixAck', { pin });
|
|
675
|
+
return this._commonCall('PinMatrixAck', { pin }, stripInteractiveAckTimeout(options));
|
|
493
676
|
},
|
|
494
677
|
error => Promise.reject(error)
|
|
495
678
|
);
|
|
@@ -497,19 +680,27 @@ export class DeviceCommands {
|
|
|
497
680
|
|
|
498
681
|
if (res.type === 'PassphraseRequest') {
|
|
499
682
|
const existsAttachPinUser = res.message.exists_attach_pin_user;
|
|
500
|
-
return this.
|
|
683
|
+
return this.promptPassphrase({
|
|
501
684
|
existsAttachPinUser,
|
|
502
685
|
}).then(response => {
|
|
503
686
|
const { passphrase, passphraseOnDevice, attachPinOnDevice } = response;
|
|
504
687
|
|
|
505
688
|
// Attach PIN on device
|
|
506
689
|
if (attachPinOnDevice && existsAttachPinUser) {
|
|
507
|
-
return this._commonCall(
|
|
690
|
+
return this._commonCall(
|
|
691
|
+
'PassphraseAck',
|
|
692
|
+
{ on_device_attach_pin: true },
|
|
693
|
+
stripInteractiveAckTimeout(options)
|
|
694
|
+
);
|
|
508
695
|
}
|
|
509
696
|
|
|
510
697
|
return !passphraseOnDevice
|
|
511
|
-
? this._commonCall('PassphraseAck', { passphrase })
|
|
512
|
-
: this._commonCall(
|
|
698
|
+
? this._commonCall('PassphraseAck', { passphrase }, stripInteractiveAckTimeout(options))
|
|
699
|
+
: this._commonCall(
|
|
700
|
+
'PassphraseAck',
|
|
701
|
+
{ on_device: true },
|
|
702
|
+
stripInteractiveAckTimeout(options)
|
|
703
|
+
);
|
|
513
704
|
});
|
|
514
705
|
}
|
|
515
706
|
|
|
@@ -587,10 +778,27 @@ export class DeviceCommands {
|
|
|
587
778
|
});
|
|
588
779
|
}
|
|
589
780
|
|
|
590
|
-
|
|
781
|
+
promptPassphrase(
|
|
782
|
+
options: PassphraseRequestPayload,
|
|
783
|
+
promptOptions: { cancelDeviceOnReject?: boolean } = {}
|
|
784
|
+
) {
|
|
591
785
|
return new Promise<PassphrasePromptResponse>((resolve, reject) => {
|
|
592
|
-
const cancelAndReject = (_error?: Error) =>
|
|
593
|
-
|
|
786
|
+
const cancelAndReject = (_error?: Error) => {
|
|
787
|
+
const rejectWithCancelledError = () => {
|
|
788
|
+
reject(
|
|
789
|
+
ERRORS.TypedError(
|
|
790
|
+
HardwareErrorCode.CallQueueActionCancelled,
|
|
791
|
+
`${DEVICE.PASSPHRASE} canceled`
|
|
792
|
+
)
|
|
793
|
+
);
|
|
794
|
+
};
|
|
795
|
+
|
|
796
|
+
if (promptOptions.cancelDeviceOnReject === false) {
|
|
797
|
+
rejectWithCancelledError();
|
|
798
|
+
return Promise.resolve();
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
return cancelDeviceInPrompt(this.device, false)
|
|
594
802
|
.then(onCancel => {
|
|
595
803
|
const error = ERRORS.TypedError(
|
|
596
804
|
HardwareErrorCode.CallQueueActionCancelled,
|
|
@@ -607,6 +815,7 @@ export class DeviceCommands {
|
|
|
607
815
|
.catch(error => {
|
|
608
816
|
reject(error);
|
|
609
817
|
});
|
|
818
|
+
};
|
|
610
819
|
|
|
611
820
|
if (this.device.listenerCount(DEVICE.PASSPHRASE) > 0) {
|
|
612
821
|
this.device.setCancelableAction(cancelAndReject);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
1
3
|
import { safeThrowError } from '../constants';
|
|
2
4
|
import { DataManager } from '../data-manager';
|
|
3
5
|
import TransportManager from '../data-manager/TransportManager';
|
|
@@ -6,6 +8,7 @@ import { resolveAfter } from '../utils/promiseUtils';
|
|
|
6
8
|
import { LoggerNames, getLogger } from '../utils';
|
|
7
9
|
|
|
8
10
|
import type { DeviceDescriptorDiff } from './DevicePool';
|
|
11
|
+
import type { HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
9
12
|
import type { OneKeyDeviceInfo as DeviceDescriptor, Transport } from '@onekeyfe/hd-transport';
|
|
10
13
|
|
|
11
14
|
const Log = getLogger(LoggerNames.DeviceConnector);
|
|
@@ -75,15 +78,37 @@ export default class DeviceConnector {
|
|
|
75
78
|
this.listening = false;
|
|
76
79
|
}
|
|
77
80
|
|
|
78
|
-
async acquire(
|
|
79
|
-
|
|
81
|
+
async acquire(
|
|
82
|
+
path: string,
|
|
83
|
+
session?: string | null,
|
|
84
|
+
forceCleanRunPromise?: boolean,
|
|
85
|
+
connectProtocol?: HardwareConnectProtocol
|
|
86
|
+
) {
|
|
87
|
+
Log.debug('acquire', path, session, connectProtocol);
|
|
80
88
|
const env = DataManager.getSettings('env');
|
|
81
89
|
try {
|
|
82
90
|
let res;
|
|
83
91
|
if (DataManager.isBleConnect(env)) {
|
|
84
|
-
res = await this.transport.acquire({
|
|
92
|
+
res = await this.transport.acquire({
|
|
93
|
+
uuid: path,
|
|
94
|
+
forceCleanRunPromise,
|
|
95
|
+
expectedProtocol: connectProtocol,
|
|
96
|
+
});
|
|
85
97
|
} else {
|
|
86
|
-
res = await this.transport.acquire({
|
|
98
|
+
res = await this.transport.acquire({
|
|
99
|
+
path,
|
|
100
|
+
previous: session ?? null,
|
|
101
|
+
expectedProtocol: connectProtocol,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (connectProtocol) {
|
|
105
|
+
const detectedProtocol = this.transport.getProtocolType(path);
|
|
106
|
+
if (detectedProtocol !== connectProtocol) {
|
|
107
|
+
throw ERRORS.TypedError(
|
|
108
|
+
HardwareErrorCode.RuntimeError,
|
|
109
|
+
`Device protocol mismatch: expected ${connectProtocol}, detected ${detectedProtocol}`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
87
112
|
}
|
|
88
113
|
return res;
|
|
89
114
|
} catch (error) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Features } from '../types';
|
|
2
|
+
|
|
3
|
+
export type DeviceFeaturesUpdateSource =
|
|
4
|
+
| 'device-info'
|
|
5
|
+
| 'device-status'
|
|
6
|
+
| 'device-settings-get'
|
|
7
|
+
| 'device-settings-set'
|
|
8
|
+
| 'apply-settings'
|
|
9
|
+
| 'unlock'
|
|
10
|
+
| 'cache';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Merge a field-level device-state patch.
|
|
14
|
+
*
|
|
15
|
+
* `undefined` means the response omitted a field and preserves the cache; `null`
|
|
16
|
+
* means the device explicitly returned an empty value and must be cached. Callers
|
|
17
|
+
* provide complete object fields such as raw; this function does not deep-merge.
|
|
18
|
+
*/
|
|
19
|
+
export function mergeDeviceFeaturesPatch(previous: Features, patch: Partial<Features>): Features {
|
|
20
|
+
let next = previous;
|
|
21
|
+
|
|
22
|
+
for (const [key, value] of Object.entries(patch) as Array<
|
|
23
|
+
[keyof Features, Features[keyof Features] | undefined]
|
|
24
|
+
>) {
|
|
25
|
+
if (value !== undefined && !Object.is(previous[key], value)) {
|
|
26
|
+
if (next === previous) {
|
|
27
|
+
next = { ...previous };
|
|
28
|
+
}
|
|
29
|
+
(next as Record<keyof Features, Features[keyof Features]>)[key] = value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return next;
|
|
34
|
+
}
|
package/src/device/DevicePool.ts
CHANGED
|
@@ -3,7 +3,7 @@ import EventEmitter from 'events';
|
|
|
3
3
|
// eslint-disable-next-line import/no-cycle
|
|
4
4
|
import { Device } from './Device';
|
|
5
5
|
import { DEVICE } from '../events';
|
|
6
|
-
import { LoggerNames,
|
|
6
|
+
import { LoggerNames, getLogger } from '../utils';
|
|
7
7
|
|
|
8
8
|
import type { InitOptions } from './Device';
|
|
9
9
|
import type { OneKeyDeviceInfo as DeviceDescriptor } from '@onekeyfe/hd-transport';
|
|
@@ -106,26 +106,32 @@ export class DevicePool extends EventEmitter {
|
|
|
106
106
|
if (exist) {
|
|
107
107
|
// Log.debug('find existed Device: ', connectId);
|
|
108
108
|
device.updateDescriptor(exist, true);
|
|
109
|
+
await this._refreshRuntimeState(device, initOptions);
|
|
109
110
|
devices[connectId] = device;
|
|
110
111
|
deviceList.push(device);
|
|
111
|
-
await this._checkDevicePool(initOptions);
|
|
112
|
+
await this._checkDevicePool(initOptions, connectId);
|
|
112
113
|
return { devices, deviceList };
|
|
113
114
|
}
|
|
114
115
|
Log.debug('found device in cache, but path is different: ', connectId);
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
|
|
119
|
+
const matchedDescriptor = connectId
|
|
120
|
+
? descriptorList.find(descriptor => descriptor.path === connectId)
|
|
121
|
+
: undefined;
|
|
122
|
+
const descriptorsToInitialize = matchedDescriptor ? [matchedDescriptor] : descriptorList;
|
|
123
|
+
|
|
124
|
+
for await (const descriptor of descriptorsToInitialize) {
|
|
119
125
|
const device = await this._createDevice(descriptor, initOptions);
|
|
120
126
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (this.devicesCache[
|
|
124
|
-
const cache = this.devicesCache[
|
|
127
|
+
const connectId = device.getConnectId();
|
|
128
|
+
if (connectId) {
|
|
129
|
+
if (this.devicesCache[connectId]) {
|
|
130
|
+
const cache = this.devicesCache[connectId];
|
|
125
131
|
cache.updateDescriptor(descriptor, true);
|
|
126
132
|
}
|
|
127
|
-
this.devicesCache[
|
|
128
|
-
devices[
|
|
133
|
+
this.devicesCache[connectId] = device;
|
|
134
|
+
devices[connectId] = device;
|
|
129
135
|
}
|
|
130
136
|
|
|
131
137
|
deviceList.push(device);
|
|
@@ -133,7 +139,7 @@ export class DevicePool extends EventEmitter {
|
|
|
133
139
|
// Log.debug('get devices result : ', devices, deviceList);
|
|
134
140
|
// console.log('device poll -> connected: ', this.connectedPool);
|
|
135
141
|
// console.log('device poll -> disconnected: ', this.disconnectPool);
|
|
136
|
-
await this._checkDevicePool(initOptions);
|
|
142
|
+
await this._checkDevicePool(initOptions, matchedDescriptor ? connectId : undefined);
|
|
137
143
|
return { devices, deviceList };
|
|
138
144
|
}
|
|
139
145
|
|
|
@@ -150,33 +156,74 @@ export class DevicePool extends EventEmitter {
|
|
|
150
156
|
if (!device) {
|
|
151
157
|
device = Device.fromDescriptor(descriptor);
|
|
152
158
|
device.deviceConnector = this.connector;
|
|
153
|
-
await device.connect();
|
|
154
|
-
|
|
155
|
-
|
|
159
|
+
await device.connect(initOptions?.connectProtocol);
|
|
160
|
+
try {
|
|
161
|
+
await device.initialize(initOptions);
|
|
162
|
+
if (initOptions?.refreshRuntimeState && device.isProtocolV2()) {
|
|
163
|
+
await this._refreshProtocolV2DiscoveryState(device);
|
|
164
|
+
}
|
|
165
|
+
} finally {
|
|
166
|
+
await device.release();
|
|
167
|
+
}
|
|
156
168
|
}
|
|
157
169
|
return device;
|
|
158
170
|
}
|
|
159
171
|
|
|
160
|
-
static async
|
|
161
|
-
|
|
172
|
+
static async _refreshRuntimeState(device: Device, initOptions?: InitOptions) {
|
|
173
|
+
if (!initOptions?.refreshRuntimeState || !device.isProtocolV2()) return;
|
|
174
|
+
let refreshError: unknown;
|
|
175
|
+
await device.run(
|
|
176
|
+
async () => {
|
|
177
|
+
try {
|
|
178
|
+
await this._refreshProtocolV2DiscoveryState(device);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
// Device.run releases after the callback; then propagate the actual read error.
|
|
181
|
+
refreshError = error;
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
{ connectProtocol: initOptions.connectProtocol }
|
|
185
|
+
);
|
|
186
|
+
if (refreshError instanceof Error) throw refreshError;
|
|
187
|
+
if (refreshError) throw new Error(String(refreshError));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Device lists require live mode and name data. A status failure remains a connection
|
|
192
|
+
* error; settings only supplies a label, so its failure retains the existing name.
|
|
193
|
+
* Device.getDeviceState skips unsupported status/settings calls in loader mode.
|
|
194
|
+
*/
|
|
195
|
+
static async _refreshProtocolV2DiscoveryState(device: Device) {
|
|
196
|
+
await device.getDeviceState({ refreshSections: ['status'] });
|
|
197
|
+
try {
|
|
198
|
+
await device.getDeviceState({ refreshSections: ['settings'] });
|
|
199
|
+
} catch (error) {
|
|
200
|
+
Log.debug('Unable to refresh Protocol V2 device label during discovery', error);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
static async _checkDevicePool(initOptions?: InitOptions, connectId?: string) {
|
|
205
|
+
await this._sendConnectMessage(initOptions, connectId);
|
|
162
206
|
this._sendDisconnectMessage();
|
|
163
207
|
}
|
|
164
208
|
|
|
165
|
-
static async _sendConnectMessage(initOptions?: InitOptions) {
|
|
209
|
+
static async _sendConnectMessage(initOptions?: InitOptions, connectId?: string) {
|
|
166
210
|
for (let i = this.connectedPool.length - 1; i >= 0; i--) {
|
|
167
211
|
const descriptor = this.connectedPool[i];
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
212
|
+
if (!connectId || descriptor.path === connectId) {
|
|
213
|
+
const device = await this._createDevice(descriptor, initOptions);
|
|
214
|
+
Log.debug('emit DEVICE.CONNECT: ', device?.features);
|
|
215
|
+
this.emitter.emit(DEVICE.CONNECT, device);
|
|
216
|
+
this.connectedPool.splice(i, 1);
|
|
217
|
+
}
|
|
172
218
|
}
|
|
173
219
|
}
|
|
174
220
|
|
|
175
221
|
static _sendDisconnectMessage() {
|
|
176
222
|
for (let i = this.disconnectPool.length - 1; i >= 0; i--) {
|
|
177
|
-
const descriptor = this.
|
|
223
|
+
const descriptor = this.disconnectPool[i];
|
|
178
224
|
const device = descriptor?.path ? this.getDeviceByPath(descriptor.path) : null;
|
|
179
225
|
if (device) {
|
|
226
|
+
device.markTransportDisconnected();
|
|
180
227
|
this.emitter.emit(DEVICE.DISCONNECT, device);
|
|
181
228
|
}
|
|
182
229
|
this.disconnectPool.splice(i, 1);
|
|
@@ -216,6 +263,7 @@ export class DevicePool extends EventEmitter {
|
|
|
216
263
|
}
|
|
217
264
|
|
|
218
265
|
Log.debug('emit DEVICE.DISCONNECT: ', device.features);
|
|
266
|
+
device.markTransportDisconnected();
|
|
219
267
|
this.emitter.emit(DEVICE.DISCONNECT, device);
|
|
220
268
|
});
|
|
221
269
|
}
|