@onekeyfe/hd-core 1.2.0-alpha.18 → 1.2.0-alpha.181
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 +390 -0
- package/__tests__/DeviceCommands.test.ts +586 -9
- package/__tests__/DeviceEventRegistration.test.ts +6 -0
- package/__tests__/base64Data.test.ts +69 -0
- package/__tests__/chain-params-onekey-compatibility.test.ts +229 -0
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +878 -0
- package/__tests__/check-firmware-release-protocol-v2.test.ts +270 -0
- package/__tests__/connectSettings.test.ts +45 -5
- package/__tests__/core-dispose.test.ts +34 -0
- package/__tests__/core-error-output.test.ts +39 -0
- package/__tests__/core-initialization.test.ts +23 -0
- package/__tests__/device-connector-protocol.test.ts +102 -0
- package/__tests__/device-features-state.test.ts +78 -0
- package/__tests__/device-identity.test.ts +52 -0
- package/__tests__/device-initialize-timeout.test.ts +56 -0
- package/__tests__/device-lifecycle-events.test.ts +752 -0
- package/__tests__/device-pool-state.test.ts +191 -0
- package/__tests__/device-settings.test.ts +665 -0
- package/__tests__/device-state-contract.test.ts +28 -0
- package/__tests__/device-state-events.test.ts +286 -0
- package/__tests__/device-state-mapper.test.ts +344 -0
- package/__tests__/device-state-projector.test.ts +114 -0
- package/__tests__/device-state-store.test.ts +109 -0
- package/__tests__/device-utils.test.ts +168 -0
- package/__tests__/device-wallet-session-store.test.ts +474 -1
- package/__tests__/deviceFeaturesUtils.test.ts +13 -1
- package/__tests__/devicePoolBootloaderPath.test.ts +64 -0
- package/__tests__/deviceSettings.test.ts +117 -0
- package/__tests__/deviceUploadNft.test.ts +348 -0
- package/__tests__/evmLedgerLegacySafety.test.ts +10 -7
- package/__tests__/evmSignTransaction.test.ts +69 -0
- package/__tests__/evmSignTypedData.test.ts +80 -0
- package/__tests__/filesystemValidation.test.ts +53 -0
- package/__tests__/firmware-update/check-all-firmware-release.test.ts +175 -0
- package/__tests__/firmware-update/device-update-bootloader.test.ts +109 -0
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +171 -0
- package/__tests__/firmware-update/firmware-host-binding.test.ts +79 -0
- package/__tests__/firmware-update/firmware-preparation-error.test.ts +27 -0
- package/__tests__/firmware-update/firmware-prepared-host-digest.test.ts +583 -0
- package/__tests__/firmware-update/firmware-prepared-resource-archive.test.ts +171 -0
- package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +438 -0
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
- package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +474 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +819 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +297 -0
- package/__tests__/firmware-update/firmware-update-prepared-resource-executors.test.ts +326 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +457 -0
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +237 -0
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +525 -0
- package/__tests__/firmware-update/firmware-update-v4-parameters.test.ts +85 -0
- package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
- package/__tests__/get-device-state.test.ts +617 -0
- package/__tests__/homescreen.test.ts +58 -1
- package/__tests__/kaspa-public-types.type-test.ts +16 -0
- package/__tests__/kaspa-use-tweak-pro2.test.ts +20 -0
- package/__tests__/kaspaSignTransaction.test.ts +16 -29
- package/__tests__/known-device-public-types.type-test.ts +3 -0
- package/__tests__/logBlockEvent.test.ts +140 -1
- package/__tests__/method-protocol-support.test.ts +144 -0
- package/__tests__/networkUtils.test.ts +406 -0
- package/__tests__/open-wallet-session-error-response.test.ts +43 -0
- package/__tests__/open-wallet-session.test.ts +1899 -0
- package/__tests__/pro2Nft.test.ts +108 -0
- package/__tests__/pro2Wallpaper.test.ts +8 -19
- package/__tests__/protocol-binding.test.ts +89 -0
- package/__tests__/protocol-v2-firmware-targets.test.ts +105 -0
- package/__tests__/protocol-v2-ping.test.ts +28 -0
- package/__tests__/protocol-v2-resources.test.ts +371 -0
- package/__tests__/protocol-v2-ui-lifecycle.test.ts +91 -0
- package/__tests__/protocol-v2-unlock-policy.test.ts +507 -0
- package/__tests__/protocol-v2.test.ts +7577 -2183
- package/__tests__/protocolV2FileWrite.test.ts +193 -0
- package/__tests__/protocolV2UiInteraction.test.ts +63 -0
- package/__tests__/public-device-state-api.test.ts +275 -0
- package/__tests__/public-pro2-api-boundary.test.ts +107 -0
- package/__tests__/refresh-device-state.test.ts +103 -0
- package/__tests__/request-context-logging.test.ts +16 -0
- package/__tests__/resourceBase64Boundary.test.ts +48 -0
- package/__tests__/search-devices.test.ts +192 -0
- package/__tests__/ton-sign-message.test.ts +84 -0
- package/__tests__/tron-sign-message-init.test.ts +74 -0
- package/__tests__/uiProgressThrottle.test.ts +74 -0
- package/__tests__/uiPromiseRegistry.test.ts +115 -0
- package/dist/api/BaseMethod.d.ts +10 -2
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts +25 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/CheckBLEFirmwareRelease.d.ts +3 -2
- package/dist/api/CheckBLEFirmwareRelease.d.ts.map +1 -1
- package/dist/api/CheckBootloaderRelease.d.ts +2 -1
- package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
- package/dist/api/CheckFirmwareRelease.d.ts +3 -2
- package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
- package/dist/api/CipherKeyValue.d.ts +1 -0
- package/dist/api/CipherKeyValue.d.ts.map +1 -1
- package/dist/api/ClearSessionCache.d.ts.map +1 -1
- package/dist/api/DetectDeviceConnectProtocol.d.ts +7 -0
- package/dist/api/DetectDeviceConnectProtocol.d.ts.map +1 -0
- package/dist/api/DirList.d.ts +1 -0
- package/dist/api/DirList.d.ts.map +1 -1
- package/dist/api/DirMake.d.ts +1 -0
- package/dist/api/DirMake.d.ts.map +1 -1
- package/dist/api/DirRemove.d.ts +1 -0
- package/dist/api/DirRemove.d.ts.map +1 -1
- package/dist/api/FileDelete.d.ts +1 -0
- package/dist/api/FileDelete.d.ts.map +1 -1
- package/dist/api/FileRead.d.ts +1 -0
- 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/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +13 -2
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +7 -3
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +65 -14
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetDeviceState.d.ts +8 -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 -0
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts +8 -0
- package/dist/api/OpenWalletSession.d.ts.map +1 -0
- package/dist/api/PathInfo.d.ts +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 +1 -2
- package/dist/api/UploadPortfolio.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumGetAddress.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
- package/dist/api/algo/AlgoGetAddress.d.ts +1 -0
- package/dist/api/algo/AlgoGetAddress.d.ts.map +1 -1
- package/dist/api/algo/AlgoSignTransaction.d.ts +1 -0
- package/dist/api/algo/AlgoSignTransaction.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts +1 -0
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/aptos/AptosGetAddress.d.ts +1 -0
- package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -1
- package/dist/api/aptos/AptosGetPublicKey.d.ts +1 -0
- package/dist/api/aptos/AptosGetPublicKey.d.ts.map +1 -1
- package/dist/api/aptos/AptosSignInMessage.d.ts +1 -0
- package/dist/api/aptos/AptosSignInMessage.d.ts.map +1 -1
- package/dist/api/aptos/AptosSignMessage.d.ts +1 -0
- package/dist/api/aptos/AptosSignMessage.d.ts.map +1 -1
- package/dist/api/aptos/AptosSignTransaction.d.ts +1 -0
- package/dist/api/aptos/AptosSignTransaction.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetAddress.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetPublicKey.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCGetAddress.d.ts +1 -0
- package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
- package/dist/api/btc/BTCGetPublicKey.d.ts +1 -0
- package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
- package/dist/api/btc/BTCSignMessage.d.ts +1 -0
- package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
- package/dist/api/btc/BTCSignPsbt.d.ts +1 -0
- package/dist/api/btc/BTCSignPsbt.d.ts.map +1 -1
- package/dist/api/btc/BTCSignTransaction.d.ts +1 -0
- package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCVerifyMessage.d.ts +1 -0
- package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
- package/dist/api/btc/helpers/versionLimit.d.ts +2 -0
- package/dist/api/btc/helpers/versionLimit.d.ts.map +1 -1
- package/dist/api/cardano/CardanoGetAddress.d.ts +1 -0
- package/dist/api/cardano/CardanoGetAddress.d.ts.map +1 -1
- package/dist/api/cardano/CardanoGetPublicKey.d.ts +1 -0
- package/dist/api/cardano/CardanoGetPublicKey.d.ts.map +1 -1
- package/dist/api/cardano/CardanoSignMessage.d.ts +1 -0
- package/dist/api/cardano/CardanoSignMessage.d.ts.map +1 -1
- package/dist/api/cardano/CardanoSignTransaction.d.ts +1 -0
- package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxGetAddress.d.ts +2 -0
- package/dist/api/conflux/ConfluxGetAddress.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignMessage.d.ts +2 -0
- package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts +2 -0
- package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignTransaction.d.ts +2 -0
- package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
- package/dist/api/cosmos/CosmosGetAddress.d.ts +1 -0
- package/dist/api/cosmos/CosmosGetAddress.d.ts.map +1 -1
- package/dist/api/cosmos/CosmosGetPublicKey.d.ts +1 -0
- package/dist/api/cosmos/CosmosGetPublicKey.d.ts.map +1 -1
- package/dist/api/cosmos/CosmosSignTransaction.d.ts +1 -0
- package/dist/api/cosmos/CosmosSignTransaction.d.ts.map +1 -1
- package/dist/api/device/DeviceCancel.d.ts +1 -0
- package/dist/api/device/DeviceCancel.d.ts.map +1 -1
- package/dist/api/device/DeviceChangePin.d.ts +1 -0
- 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 +1 -0
- package/dist/api/device/DeviceLock.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -0
- package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBootloader.d.ts +1 -0
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts +1 -0
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceSupportFeatures.d.ts +1 -0
- package/dist/api/device/DeviceSupportFeatures.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +3 -2
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts +5 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceVerify.d.ts +1 -0
- package/dist/api/device/DeviceVerify.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts +1 -0
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/device/PreInitialize.d.ts +1 -0
- package/dist/api/device/PreInitialize.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/EVMGetAddress.d.ts +1 -0
- package/dist/api/evm/EVMGetAddress.d.ts.map +1 -1
- package/dist/api/evm/EVMGetPublicKey.d.ts +1 -0
- package/dist/api/evm/EVMGetPublicKey.d.ts.map +1 -1
- package/dist/api/evm/EVMSignMessage.d.ts +1 -0
- package/dist/api/evm/EVMSignMessage.d.ts.map +1 -1
- package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTransaction.d.ts +1 -0
- package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts +1 -0
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/evm/EVMVerifyMessage.d.ts +1 -0
- package/dist/api/evm/EVMVerifyMessage.d.ts.map +1 -1
- package/dist/api/evm/protocol.d.ts +3 -0
- package/dist/api/evm/protocol.d.ts.map +1 -0
- package/dist/api/filecoin/FilecoinGetAddress.d.ts +1 -0
- package/dist/api/filecoin/FilecoinGetAddress.d.ts.map +1 -1
- package/dist/api/filecoin/FilecoinSignTransaction.d.ts +1 -0
- package/dist/api/filecoin/FilecoinSignTransaction.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +29 -0
- package/dist/api/firmware/FirmwareArtifactSource.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/FirmwarePreparationError.d.ts +3 -0
- package/dist/api/firmware/FirmwarePreparationError.d.ts.map +1 -0
- package/dist/api/firmware/FirmwarePreparedResourceArchive.d.ts +11 -0
- package/dist/api/firmware/FirmwarePreparedResourceArchive.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +12 -3
- 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 +57 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +38 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/api/firmware/getBinary.d.ts +15 -4
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/protocolV2Release.d.ts +33 -0
- package/dist/api/firmware/protocolV2Release.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/base64Data.d.ts +16 -0
- package/dist/api/helpers/base64Data.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 +10 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +5 -29
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaGetAddress.d.ts +4 -0
- package/dist/api/kaspa/KaspaGetAddress.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts +4 -0
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/kaspa/helpers/TransferSerialize.d.ts.map +1 -1
- package/dist/api/lightning/LnurlAuth.d.ts +0 -4
- package/dist/api/lightning/LnurlAuth.d.ts.map +1 -1
- package/dist/api/near/NearGetAddress.d.ts +1 -0
- package/dist/api/near/NearGetAddress.d.ts.map +1 -1
- package/dist/api/near/NearSignTransaction.d.ts +1 -0
- package/dist/api/near/NearSignTransaction.d.ts.map +1 -1
- package/dist/api/nem/NEMGetAddress.d.ts +1 -0
- package/dist/api/nem/NEMGetAddress.d.ts.map +1 -1
- package/dist/api/nem/NEMSignTransaction.d.ts +1 -0
- package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -1
- package/dist/api/neo/NeoGetAddress.d.ts.map +1 -1
- package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
- package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -1
- package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
- package/dist/api/nexa/NexaGetAddress.d.ts.map +1 -1
- package/dist/api/nexa/NexaSignTransaction.d.ts +1 -0
- package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
- package/dist/api/nostr/NostrDecryptMessage.d.ts +1 -0
- package/dist/api/nostr/NostrDecryptMessage.d.ts.map +1 -1
- package/dist/api/nostr/NostrEncryptMessage.d.ts +1 -0
- package/dist/api/nostr/NostrEncryptMessage.d.ts.map +1 -1
- package/dist/api/nostr/NostrGetPublicKey.d.ts +1 -0
- package/dist/api/nostr/NostrGetPublicKey.d.ts.map +1 -1
- package/dist/api/nostr/NostrSignEvent.d.ts +1 -0
- package/dist/api/nostr/NostrSignEvent.d.ts.map +1 -1
- package/dist/api/nostr/NostrSignSchnorr.d.ts +1 -0
- package/dist/api/nostr/NostrSignSchnorr.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotGetAddress.d.ts +2 -1
- package/dist/api/polkadot/PolkadotGetAddress.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotSignTransaction.d.ts +1 -0
- package/dist/api/polkadot/PolkadotSignTransaction.d.ts.map +1 -1
- package/dist/api/polkadot/networks.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +1 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +1 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +4 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +1 -0
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +2 -1
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts +2 -2
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceReboot.d.ts +2 -1
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts +1 -0
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +30 -0
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +3 -3
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/api/protocol-v2/FilesystemFormat.d.ts +1 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -1
- package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts +1 -0
- package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -1
- package/dist/api/protocol-v2/Ping.d.ts +3 -0
- package/dist/api/protocol-v2/Ping.d.ts.map +1 -1
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +1 -0
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/scdo/ScdoGetAddress.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
- 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 +2 -1
- package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +2 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +3 -2
- package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
- package/dist/api/starcoin/StarcoinGetAddress.d.ts +1 -0
- package/dist/api/starcoin/StarcoinGetAddress.d.ts.map +1 -1
- package/dist/api/starcoin/StarcoinGetPublicKey.d.ts +1 -0
- package/dist/api/starcoin/StarcoinGetPublicKey.d.ts.map +1 -1
- package/dist/api/starcoin/StarcoinSignMessage.d.ts +1 -0
- package/dist/api/starcoin/StarcoinSignMessage.d.ts.map +1 -1
- package/dist/api/starcoin/StarcoinSignTransaction.d.ts +1 -0
- package/dist/api/starcoin/StarcoinSignTransaction.d.ts.map +1 -1
- package/dist/api/starcoin/StarcoinVerifyMessage.d.ts +1 -0
- package/dist/api/starcoin/StarcoinVerifyMessage.d.ts.map +1 -1
- package/dist/api/stellar/StellarGetAddress.d.ts +1 -2
- package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +2 -3
- package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
- package/dist/api/sui/SuiGetAddress.d.ts +2 -1
- package/dist/api/sui/SuiGetAddress.d.ts.map +1 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts +2 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts.map +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts +2 -1
- package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +2 -1
- package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
- package/dist/api/ton/TonGetAddress.d.ts +2 -1
- 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 +2 -1
- package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
- package/dist/api/ton/TonSignProof.d.ts +2 -1
- package/dist/api/ton/TonSignProof.d.ts.map +1 -1
- package/dist/api/tron/TronGetAddress.d.ts +1 -0
- package/dist/api/tron/TronGetAddress.d.ts.map +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +6 -1
- package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
- package/dist/api/tron/TronSignTransaction.d.ts +2 -1
- package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
- package/dist/api/utils.d.ts +4 -1
- package/dist/api/utils.d.ts.map +1 -1
- package/dist/api/xrp/XrpGetAddress.d.ts +1 -0
- package/dist/api/xrp/XrpGetAddress.d.ts.map +1 -1
- package/dist/api/xrp/XrpSignTransaction.d.ts +1 -0
- package/dist/api/xrp/XrpSignTransaction.d.ts.map +1 -1
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/core/RequestQueue.d.ts +0 -2
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/deviceEventRegistration.d.ts +2 -0
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/core/index.d.ts +8 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/uiPromiseRegistry.d.ts +6 -0
- package/dist/core/uiPromiseRegistry.d.ts.map +1 -0
- package/dist/data-manager/DataManager.d.ts +14 -5
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- 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 +82 -14
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +5 -5
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +4 -3
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/device/DeviceFeaturesState.d.ts +3 -0
- package/dist/device/DeviceFeaturesState.d.ts.map +1 -0
- package/dist/device/DevicePool.d.ts +4 -0
- 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 +13 -1
- package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -1
- 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 +3 -1
- 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/deviceProfile/protocolV2DeviceIdentity.d.ts +7 -0
- package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts.map +1 -0
- package/dist/events/call.d.ts +0 -7
- 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 +12 -2
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/iframe.d.ts +0 -1
- package/dist/events/iframe.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts +2 -0
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-promise.d.ts +4 -2
- package/dist/events/ui-promise.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +32 -2
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/events/ui-response.d.ts +10 -2
- package/dist/events/ui-response.d.ts.map +1 -1
- package/dist/index.d.ts +1690 -847
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10856 -4825
- package/dist/inject.d.ts +7 -3
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts +1 -2
- 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 +31 -8
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +2 -2
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/resources.d.ts +17 -0
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts +17 -0
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +7 -4
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts +2 -0
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +22 -0
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts +16 -3
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +48 -9
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/checkBLEFirmwareRelease.d.ts +2 -13
- package/dist/types/api/checkBLEFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/checkBootloaderRelease.d.ts +2 -6
- package/dist/types/api/checkBootloaderRelease.d.ts.map +1 -1
- package/dist/types/api/checkFirmwareRelease.d.ts +2 -13
- package/dist/types/api/checkFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/checkFirmwareTypeAvailable.d.ts +2 -2
- package/dist/types/api/checkFirmwareTypeAvailable.d.ts.map +1 -1
- package/dist/types/api/detectDeviceConnectProtocol.d.ts +4 -0
- package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +1 -0
- package/dist/types/api/deviceSettings.d.ts +11 -2
- package/dist/types/api/deviceSettings.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +6 -2
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +6 -0
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +8 -3
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +67 -5
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +9 -0
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts +28 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +42 -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.map +1 -1
- package/dist/types/api/index.d.ts +25 -35
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/kaspaSignTransaction.d.ts +15 -2
- package/dist/types/api/kaspaSignTransaction.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 +11 -95
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/api/sessionCache.d.ts +4 -1
- package/dist/types/api/sessionCache.d.ts.map +1 -1
- package/dist/types/device.d.ts +138 -8
- 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 +31 -16
- 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 +14 -0
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -0
- package/dist/utils/deviceFeaturesUtils.d.ts +10 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts +9 -9
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts +39 -7
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/deviceVersionUtils.d.ts +7 -5
- package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
- package/dist/utils/homescreen.d.ts +4 -0
- package/dist/utils/homescreen.d.ts.map +1 -1
- package/dist/utils/index.d.ts +5 -4
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/networkUtils.d.ts +10 -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/pro2Nft.d.ts +38 -0
- package/dist/utils/pro2Nft.d.ts.map +1 -0
- package/dist/utils/pro2Wallpaper.d.ts +10 -0
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
- package/dist/utils/tracing.d.ts.map +1 -1
- package/dist/utils/uiProgressThrottle.d.ts +3 -0
- package/dist/utils/uiProgressThrottle.d.ts.map +1 -0
- package/package.json +6 -4
- package/src/api/BaseMethod.ts +39 -25
- package/src/api/CheckAllFirmwareRelease.ts +440 -4
- package/src/api/CheckBLEFirmwareRelease.ts +37 -5
- package/src/api/CheckBootloaderRelease.ts +37 -5
- package/src/api/CheckFirmwareRelease.ts +36 -9
- package/src/api/CipherKeyValue.ts +4 -0
- package/src/api/ClearSessionCache.ts +4 -0
- package/src/api/DetectDeviceConnectProtocol.ts +18 -0
- package/src/api/DirList.ts +9 -4
- package/src/api/DirMake.ts +7 -4
- package/src/api/DirRemove.ts +7 -4
- package/src/api/FileDelete.ts +7 -4
- package/src/api/FileRead.ts +13 -7
- package/src/api/FileWrite.ts +7 -4
- package/src/api/FirmwareUpdate.ts +30 -15
- package/src/api/FirmwareUpdateV2.ts +535 -169
- package/src/api/FirmwareUpdateV3.ts +349 -91
- package/src/api/FirmwareUpdateV4.ts +2195 -696
- package/src/api/GetDeviceState.ts +59 -0
- package/src/api/GetFeatures.ts +6 -4
- package/src/api/GetOnekeyFeatures.ts +1 -75
- package/src/api/GetPassphraseState.ts +34 -13
- package/src/api/OpenWalletSession.ts +268 -0
- package/src/api/PathInfo.ts +9 -4
- package/src/api/PromptWebDeviceAccess.ts +3 -8
- package/src/api/SearchDevices.ts +35 -5
- package/src/api/UploadPortfolio.ts +29 -5
- package/src/api/alephium/AlephiumGetAddress.ts +0 -4
- package/src/api/alephium/AlephiumSignMessage.ts +0 -4
- package/src/api/alephium/AlephiumSignTransaction.ts +2 -6
- package/src/api/algo/AlgoGetAddress.ts +4 -0
- package/src/api/algo/AlgoSignTransaction.ts +4 -0
- package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +45 -32
- package/src/api/aptos/AptosGetAddress.ts +4 -0
- package/src/api/aptos/AptosGetPublicKey.ts +4 -0
- package/src/api/aptos/AptosSignInMessage.ts +4 -0
- package/src/api/aptos/AptosSignMessage.ts +4 -0
- package/src/api/aptos/AptosSignTransaction.ts +4 -0
- package/src/api/benfen/BenfenGetAddress.ts +11 -7
- package/src/api/benfen/BenfenGetPublicKey.ts +0 -4
- package/src/api/benfen/BenfenSignMessage.ts +0 -4
- package/src/api/benfen/BenfenSignTransaction.ts +0 -4
- package/src/api/btc/BTCGetAddress.ts +8 -1
- package/src/api/btc/BTCGetPublicKey.ts +9 -2
- package/src/api/btc/BTCSignMessage.ts +8 -1
- package/src/api/btc/BTCSignPsbt.ts +4 -0
- package/src/api/btc/BTCSignTransaction.ts +8 -1
- package/src/api/btc/BTCVerifyMessage.ts +8 -1
- package/src/api/btc/helpers/versionLimit.ts +7 -4
- package/src/api/cardano/CardanoGetAddress.ts +4 -0
- package/src/api/cardano/CardanoGetPublicKey.ts +4 -0
- package/src/api/cardano/CardanoSignMessage.ts +4 -0
- package/src/api/cardano/CardanoSignTransaction.ts +4 -0
- package/src/api/conflux/ConfluxGetAddress.ts +6 -0
- package/src/api/conflux/ConfluxSignMessage.ts +6 -0
- package/src/api/conflux/ConfluxSignMessageCIP23.ts +6 -0
- package/src/api/conflux/ConfluxSignTransaction.ts +8 -5
- package/src/api/cosmos/CosmosGetAddress.ts +4 -0
- package/src/api/cosmos/CosmosGetPublicKey.ts +4 -0
- package/src/api/cosmos/CosmosSignTransaction.ts +4 -0
- package/src/api/device/DeviceCancel.ts +4 -0
- package/src/api/device/DeviceChangePin.ts +9 -1
- package/src/api/device/DeviceFullyUploadResource.ts +4 -5
- package/src/api/device/DeviceLock.ts +4 -0
- package/src/api/device/DeviceRebootToBoardloader.ts +8 -1
- package/src/api/device/DeviceRebootToBootloader.ts +8 -1
- package/src/api/device/DeviceSettings.ts +211 -3
- package/src/api/device/DeviceSupportFeatures.ts +4 -0
- package/src/api/device/DeviceUnlock.ts +12 -3
- package/src/api/device/DeviceUpdateBootloader.ts +152 -8
- package/src/api/device/DeviceVerify.ts +25 -0
- package/src/api/device/DeviceWipe.ts +11 -1
- package/src/api/device/PreInitialize.ts +4 -0
- package/src/api/dynex/DnxGetAddress.ts +0 -6
- package/src/api/dynex/DnxSignTransaction.ts +0 -6
- package/src/api/evm/EVMGetAddress.ts +6 -2
- package/src/api/evm/EVMGetPublicKey.ts +6 -2
- package/src/api/evm/EVMSignMessage.ts +6 -2
- package/src/api/evm/EVMSignMessageEIP712.ts +1 -11
- package/src/api/evm/EVMSignTransaction.ts +6 -2
- package/src/api/evm/EVMSignTypedData.ts +42 -50
- package/src/api/evm/EVMVerifyMessage.ts +6 -2
- 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/evm/protocol.ts +6 -0
- package/src/api/filecoin/FilecoinGetAddress.ts +4 -0
- package/src/api/filecoin/FilecoinSignTransaction.ts +4 -0
- package/src/api/firmware/FirmwareArtifactSource.ts +305 -0
- package/src/api/firmware/FirmwareHostBinding.ts +123 -0
- package/src/api/firmware/FirmwarePreparationError.ts +12 -0
- package/src/api/firmware/FirmwarePreparedResourceArchive.ts +196 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +214 -77
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +905 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +490 -0
- package/src/api/firmware/getBinary.ts +8 -3
- package/src/api/firmware/protocolV2Release.ts +173 -0
- package/src/api/firmware/updateBootloader.ts +19 -4
- package/src/api/firmware/uploadFirmware.ts +157 -26
- package/src/api/helpers/base64Data.ts +85 -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 +260 -60
- package/src/api/index.ts +6 -30
- package/src/api/kaspa/KaspaGetAddress.ts +7 -0
- package/src/api/kaspa/KaspaSignTransaction.ts +48 -27
- package/src/api/kaspa/helpers/TransferSerialize.ts +3 -7
- package/src/api/lightning/LnurlAuth.ts +0 -4
- package/src/api/near/NearGetAddress.ts +4 -0
- package/src/api/near/NearSignTransaction.ts +4 -0
- package/src/api/nem/NEMGetAddress.ts +4 -0
- package/src/api/nem/NEMSignTransaction.ts +4 -0
- package/src/api/neo/NeoGetAddress.ts +0 -4
- package/src/api/neo/NeoSignTransaction.ts +0 -4
- package/src/api/nervos/NervosGetAddress.ts +0 -4
- package/src/api/nervos/NervosSignTransaction.ts +2 -6
- package/src/api/nexa/NexaGetAddress.ts +0 -4
- package/src/api/nexa/NexaSignTransaction.ts +3 -5
- package/src/api/nostr/NostrDecryptMessage.ts +4 -0
- package/src/api/nostr/NostrEncryptMessage.ts +4 -0
- package/src/api/nostr/NostrGetPublicKey.ts +4 -0
- package/src/api/nostr/NostrSignEvent.ts +4 -0
- package/src/api/nostr/NostrSignSchnorr.ts +4 -0
- package/src/api/polkadot/PolkadotGetAddress.ts +4 -0
- package/src/api/polkadot/PolkadotSignTransaction.ts +4 -0
- package/src/api/polkadot/networks.ts +3 -3
- package/src/api/protocol-v2/DeviceFactoryInfoGet.ts +5 -2
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +6 -3
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +13 -32
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +10 -6
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +6 -3
- package/src/api/protocol-v2/DeviceInfoGet.ts +11 -17
- package/src/api/protocol-v2/DeviceReboot.ts +12 -3
- package/src/api/protocol-v2/DeviceStatusGet.ts +5 -1
- package/src/api/protocol-v2/DeviceUploadNft.ts +249 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +57 -20
- package/src/api/protocol-v2/FilesystemFormat.ts +5 -2
- package/src/api/protocol-v2/FilesystemPermissionFix.ts +5 -2
- package/src/api/protocol-v2/Ping.ts +37 -3
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +8 -3
- package/src/api/protocol-v2/helpers.ts +1 -1
- package/src/api/scdo/ScdoGetAddress.ts +0 -4
- package/src/api/scdo/ScdoSignMessage.ts +0 -4
- package/src/api/scdo/ScdoSignTransaction.ts +0 -4
- package/src/api/solana/SolGetAddress.ts +4 -0
- package/src/api/solana/SolSignMessage.ts +5 -1
- package/src/api/solana/SolSignOffchainMessage.ts +5 -1
- package/src/api/solana/SolSignTransaction.ts +6 -2
- package/src/api/starcoin/StarcoinGetAddress.ts +4 -0
- package/src/api/starcoin/StarcoinGetPublicKey.ts +4 -0
- package/src/api/starcoin/StarcoinSignMessage.ts +4 -0
- package/src/api/starcoin/StarcoinSignTransaction.ts +4 -0
- package/src/api/starcoin/StarcoinVerifyMessage.ts +4 -0
- package/src/api/stellar/StellarGetAddress.ts +1 -10
- package/src/api/stellar/StellarSignTransaction.ts +1 -14
- package/src/api/sui/SuiGetAddress.ts +5 -1
- package/src/api/sui/SuiGetPublicKey.ts +5 -1
- package/src/api/sui/SuiSignMessage.ts +5 -1
- package/src/api/sui/SuiSignTransaction.ts +5 -1
- package/src/api/ton/TonGetAddress.ts +5 -1
- package/src/api/ton/TonSignData.ts +5 -1
- package/src/api/ton/TonSignMessage.ts +10 -4
- package/src/api/ton/TonSignProof.ts +5 -1
- package/src/api/tron/TronGetAddress.ts +4 -0
- package/src/api/tron/TronSignMessage.ts +19 -8
- package/src/api/tron/TronSignTransaction.ts +5 -1
- package/src/api/utils.ts +32 -3
- package/src/api/xrp/XrpGetAddress.ts +4 -0
- package/src/api/xrp/XrpSignTransaction.ts +5 -1
- package/src/constants/index.ts +1 -4
- package/src/core/RequestQueue.ts +0 -18
- package/src/core/deviceEventRegistration.ts +4 -0
- package/src/core/index.ts +583 -203
- package/src/core/uiPromiseRegistry.ts +63 -0
- package/src/data/messages/messages-protocol-v2.json +515 -540
- package/src/data-manager/DataManager.ts +162 -44
- package/src/data-manager/TransportManager.ts +10 -2
- package/src/data-manager/connectSettings.ts +11 -0
- package/src/device/Device.ts +1016 -254
- package/src/device/DeviceCommands.ts +175 -157
- package/src/device/DeviceConnector.ts +59 -22
- package/src/device/DeviceFeaturesState.ts +25 -0
- package/src/device/DevicePool.ts +96 -19
- package/src/device/DeviceStateMapper.ts +422 -0
- package/src/device/DeviceStateProjector.ts +152 -0
- package/src/device/DeviceStateStore.ts +232 -0
- package/src/device/DeviceWalletSessionStore.ts +72 -6
- package/src/device/cloneDeviceState.ts +39 -0
- package/src/device/deviceIdentity.ts +18 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +199 -188
- package/src/deviceProfile/index.ts +0 -1
- package/src/deviceProfile/protocolV2DeviceIdentity.ts +35 -0
- package/src/events/call.ts +0 -6
- package/src/events/core.ts +0 -2
- package/src/events/device.ts +18 -1
- package/src/events/iframe.ts +0 -1
- package/src/events/logBlockEvent.ts +93 -2
- package/src/events/ui-promise.ts +4 -2
- package/src/events/ui-request.ts +37 -2
- package/src/events/ui-response.ts +12 -2
- package/src/index.ts +7 -4
- package/src/inject.ts +89 -55
- package/src/lowLevelInject.ts +11 -7
- package/src/protocols/protocol-v2/deviceSession.ts +24 -0
- package/src/protocols/protocol-v2/features.ts +104 -45
- package/src/protocols/protocol-v2/firmware.ts +3 -1
- package/src/protocols/protocol-v2/index.ts +9 -2
- package/src/protocols/protocol-v2/resources.ts +173 -0
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +65 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +50 -9
- package/src/protocols/protocol-v2/unlockPolicy.ts +1 -0
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +136 -0
- package/src/protocols/protocol-v2/walletSession.ts +395 -130
- package/src/topLevelInject.ts +11 -6
- package/src/types/api/checkAllFirmwareRelease.ts +72 -9
- package/src/types/api/checkBLEFirmwareRelease.ts +4 -13
- package/src/types/api/checkBootloaderRelease.ts +2 -6
- package/src/types/api/checkFirmwareRelease.ts +2 -13
- package/src/types/api/checkFirmwareTypeAvailable.ts +2 -2
- package/src/types/api/detectDeviceConnectProtocol.ts +6 -0
- package/src/types/api/deviceSettings.ts +26 -2
- package/src/types/api/deviceUnlock.ts +13 -2
- package/src/types/api/deviceUpdateBootloader.ts +7 -0
- package/src/types/api/export.ts +33 -1
- package/src/types/api/firmwareUpdate.ts +85 -11
- package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
- package/src/types/api/firmwareUpdatePlan.ts +38 -0
- package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -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 +7 -0
- package/src/types/api/index.ts +43 -73
- package/src/types/api/kaspaSignTransaction.ts +20 -2
- package/src/types/api/openWalletSession.ts +54 -0
- package/src/types/api/protocolV2.ts +23 -190
- package/src/types/api/sessionCache.ts +9 -4
- package/src/types/device.ts +206 -9
- package/src/types/params.ts +9 -2
- package/src/types/settings.ts +37 -25
- package/src/utils/assets.ts +4 -1
- package/src/utils/deviceFeaturesCompat.ts +196 -0
- package/src/utils/deviceFeaturesUtils.ts +34 -14
- package/src/utils/deviceInfoUtils.ts +37 -70
- package/src/utils/deviceSettings.ts +181 -39
- package/src/utils/deviceVersionUtils.ts +25 -44
- package/src/utils/findDefectiveBatchDevice.ts +3 -3
- package/src/utils/homescreen.ts +37 -7
- package/src/utils/index.ts +26 -7
- package/src/utils/networkUtils.ts +274 -16
- package/src/utils/pro2Nft.ts +165 -0
- package/src/utils/pro2Wallpaper.ts +44 -25
- package/src/utils/tracing.ts +3 -1
- package/src/utils/uiProgressThrottle.ts +63 -0
- package/tsconfig.type-tests.json +12 -0
- package/__tests__/RequestQueue.test.ts +0 -34
- package/dist/api/GetDeviceInfo.d.ts +0 -9
- package/dist/api/GetDeviceInfo.d.ts.map +0 -1
- package/dist/api/firmware/progressThrottle.d.ts +0 -3
- package/dist/api/firmware/progressThrottle.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts +0 -28
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts +0 -16
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts +0 -12
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +0 -1
- package/dist/deviceProfile/buildDeviceProfile.d.ts +0 -22
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +0 -2
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +0 -11
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +0 -1
- package/dist/types/api/getDeviceInfo.d.ts +0 -88
- package/dist/types/api/getDeviceInfo.d.ts.map +0 -1
- package/src/api/GetDeviceInfo.ts +0 -152
- package/src/api/firmware/progressThrottle.ts +0 -44
- package/src/api/protocol-v2/DeviceSessionOpen.ts +0 -100
- package/src/api/protocol-v2/DeviceSettingsGet.ts +0 -16
- package/src/api/protocol-v2/DeviceSettingsPageShow.ts +0 -67
- package/src/api/protocol-v2/DeviceSettingsSet.ts +0 -49
- package/src/deviceProfile/buildDeviceProfile.ts +0 -370
- package/src/protocols/protocol-v2/lockedError.ts +0 -10
- package/src/protocols/protocol-v2/unlockRetry.ts +0 -76
- package/src/types/api/getDeviceInfo.ts +0 -106
package/src/core/index.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
2
|
import EventEmitter from 'events';
|
|
3
|
+
import {
|
|
4
|
+
DeviceSessionPinType,
|
|
5
|
+
TRANSPORT_EVENT,
|
|
6
|
+
isProtocolV2LinkDisabledError,
|
|
7
|
+
} from '@onekeyfe/hd-transport';
|
|
3
8
|
import {
|
|
4
9
|
ERRORS,
|
|
10
|
+
ERROR_CODES_REQUIRE_DISCONNECT,
|
|
5
11
|
ERROR_CODES_REQUIRE_RELEASE,
|
|
6
12
|
HardwareError,
|
|
7
13
|
HardwareErrorCode,
|
|
@@ -14,14 +20,7 @@ import {
|
|
|
14
20
|
createNewFirmwareUnReleaseHardwareError,
|
|
15
21
|
} from '@onekeyfe/hd-shared';
|
|
16
22
|
|
|
17
|
-
import {
|
|
18
|
-
LoggerNames,
|
|
19
|
-
enableLog,
|
|
20
|
-
getLogger,
|
|
21
|
-
isMethodVersionRangeUnsupported,
|
|
22
|
-
setLoggerPostMessage,
|
|
23
|
-
wait,
|
|
24
|
-
} from '../utils';
|
|
23
|
+
import { LoggerNames, enableLog, getLogger, setLoggerPostMessage, wait } from '../utils';
|
|
25
24
|
import {
|
|
26
25
|
findDefectiveBatchDevice,
|
|
27
26
|
getDefectiveDeviceInfo,
|
|
@@ -32,10 +31,12 @@ import {
|
|
|
32
31
|
createRequestContext,
|
|
33
32
|
createSdkTracingContext,
|
|
34
33
|
formatRequestContext,
|
|
34
|
+
generateInstanceId,
|
|
35
35
|
getActiveRequestsByDeviceInstance,
|
|
36
36
|
updateRequestContext,
|
|
37
37
|
} from '../utils/tracing';
|
|
38
38
|
import { Device } from '../device/Device';
|
|
39
|
+
import { checkLiveDeviceId } from '../device/deviceIdentity';
|
|
39
40
|
import { DeviceList } from '../device/DeviceList';
|
|
40
41
|
import { DevicePool } from '../device/DevicePool';
|
|
41
42
|
import { PollingStateManager } from './PollingStateManager';
|
|
@@ -51,28 +52,38 @@ import {
|
|
|
51
52
|
createDeviceMessage,
|
|
52
53
|
createResponseMessage,
|
|
53
54
|
createUiMessage,
|
|
55
|
+
formatLogMethodLabel,
|
|
56
|
+
getLogBlockLabel,
|
|
57
|
+
getSafeLogPayload,
|
|
54
58
|
} from '../events';
|
|
55
59
|
import TransportManager from '../data-manager/TransportManager';
|
|
56
60
|
import DeviceConnector from '../device/DeviceConnector';
|
|
57
61
|
import RequestQueue from './RequestQueue';
|
|
62
|
+
import { consumeUiPromise, findUiPromiseForResponse, rejectUiPromises } from './uiPromiseRegistry';
|
|
58
63
|
import { registerHardwareUiEventListeners } from './deviceEventRegistration';
|
|
59
64
|
import { getSynchronize } from '../utils/getSynchronize';
|
|
60
|
-
import {
|
|
65
|
+
import { runMethodWithUnlockPolicy } from '../protocols/protocol-v2/unlockPolicyRunner';
|
|
61
66
|
import {
|
|
62
67
|
ProtocolV2UiInteractionCoordinator,
|
|
63
68
|
isProtocolV2UiEnabled,
|
|
64
69
|
} from '../protocols/protocol-v2/uiInteraction';
|
|
70
|
+
import { createUiProgressMessageFilter } from '../utils/uiProgressThrottle';
|
|
65
71
|
|
|
66
72
|
import type { ConnectSettings, Features, KnownDevice } from '../types';
|
|
67
73
|
import type { CoreMessage, IFrameCallMessage, UiPromise, UiPromiseResponse } from '../events';
|
|
68
74
|
import type { DeviceEvents, InitOptions, RunOptions } from '../device/Device';
|
|
69
75
|
import type { SdkTracingContext } from '../utils/tracing';
|
|
70
76
|
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
71
|
-
import type {
|
|
77
|
+
import type {
|
|
78
|
+
LowlevelTransportSharedPlugin,
|
|
79
|
+
OneKeyDeviceInfo,
|
|
80
|
+
TransportDeviceDisconnectEvent,
|
|
81
|
+
} from '@onekeyfe/hd-transport';
|
|
72
82
|
import type { BaseMethod } from '../api/BaseMethod';
|
|
73
83
|
|
|
74
84
|
const Log = getLogger(LoggerNames.Core);
|
|
75
85
|
const PRE_INITIALIZE_TTL_MS = 60 * 1000;
|
|
86
|
+
const PRE_PENDING_CALL_TIMEOUT_MS = 15 * 1000;
|
|
76
87
|
|
|
77
88
|
// Dedup/coalesce state for "pre-warm signal" methods (isPreWarmSignal),
|
|
78
89
|
// keyed by getPreWarmKey(): coalesce in-flight, skip if warmed within TTL.
|
|
@@ -97,14 +108,15 @@ function hasDeriveCardano(method: BaseMethod): boolean {
|
|
|
97
108
|
|
|
98
109
|
const parseInitOptions = (method?: BaseMethod): InitOptions => ({
|
|
99
110
|
initSession: method?.payload.initSession,
|
|
100
|
-
passphraseState: method?.payload.passphraseState,
|
|
111
|
+
passphraseState: method?.payload.useEmptyPassphrase ? undefined : method?.payload.passphraseState,
|
|
101
112
|
deviceId: method?.payload.deviceId,
|
|
102
113
|
deriveCardano: method && hasDeriveCardano(method),
|
|
103
114
|
connectProtocol: method?.payload.connectProtocol,
|
|
115
|
+
forceProtocolDetection: method?.payload.forceProtocolDetection,
|
|
104
116
|
protocolV2DeviceInfoTimeoutMs: method?.payload.protocolV2DeviceInfoTimeoutMs,
|
|
105
117
|
});
|
|
106
118
|
|
|
107
|
-
let _core: Core;
|
|
119
|
+
let _core: Core | undefined;
|
|
108
120
|
let _deviceList: DeviceList | undefined;
|
|
109
121
|
let _connector: DeviceConnector | undefined;
|
|
110
122
|
let _uiPromises: UiPromise<UiPromiseResponse['type']>[] = []; // Waiting for ui response
|
|
@@ -129,6 +141,9 @@ const toError = (error: unknown): Error | undefined => {
|
|
|
129
141
|
}
|
|
130
142
|
};
|
|
131
143
|
|
|
144
|
+
const isExpectedCompatibilityError = (error: unknown) =>
|
|
145
|
+
error instanceof HardwareError && error.errorCode === HardwareErrorCode.DeviceNotSupportMethod;
|
|
146
|
+
|
|
132
147
|
const updateMethodRequestContext = (method: BaseMethod, updates: any) => {
|
|
133
148
|
if (method.requestContext) {
|
|
134
149
|
updateRequestContext(method.requestContext.responseID, updates);
|
|
@@ -148,11 +163,16 @@ export const callAPI = async (context: CoreContext, message: CoreMessage) => {
|
|
|
148
163
|
}
|
|
149
164
|
|
|
150
165
|
// find api method
|
|
151
|
-
let method
|
|
166
|
+
let method!: BaseMethod;
|
|
152
167
|
try {
|
|
153
168
|
method = findMethod(message as IFrameCallMessage);
|
|
154
169
|
method.connector = _connector;
|
|
155
|
-
|
|
170
|
+
const shouldPostMessage = createUiProgressMessageFilter();
|
|
171
|
+
method.postMessage = event => {
|
|
172
|
+
if (shouldPostMessage(event)) {
|
|
173
|
+
postMessage(event);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
156
176
|
method.setContext?.(context);
|
|
157
177
|
|
|
158
178
|
method.requestContext = createRequestContext(method.responseID, method.name, {
|
|
@@ -164,11 +184,13 @@ export const callAPI = async (context: CoreContext, message: CoreMessage) => {
|
|
|
164
184
|
|
|
165
185
|
method.init();
|
|
166
186
|
} catch (error) {
|
|
167
|
-
|
|
187
|
+
if (method) {
|
|
188
|
+
completeMethodRequestContext(method, error);
|
|
189
|
+
method.dispose();
|
|
190
|
+
}
|
|
191
|
+
return createResponseMessage(method?.responseID ?? message.id, false, { error });
|
|
168
192
|
}
|
|
169
193
|
|
|
170
|
-
DevicePool.emitter.on(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
171
|
-
|
|
172
194
|
if (!method.useDevice) {
|
|
173
195
|
updateMethodRequestContext(method, { status: 'running' });
|
|
174
196
|
try {
|
|
@@ -275,26 +297,35 @@ const handlePreWarmSignal = async (
|
|
|
275
297
|
}
|
|
276
298
|
};
|
|
277
299
|
|
|
278
|
-
const waitWithTimeout = async (promise: Promise<any>, timeout: number) => {
|
|
279
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
280
|
-
setTimeout(() => reject(new Error('Request timeout')), timeout);
|
|
281
|
-
});
|
|
282
|
-
return Promise.race([promise, timeoutPromise]);
|
|
283
|
-
};
|
|
284
|
-
|
|
285
300
|
const waitForPendingPromise = async (
|
|
286
|
-
|
|
287
|
-
|
|
301
|
+
connectId: string,
|
|
302
|
+
getPrePendingCallPromise: (connectId: string) => Promise<void> | undefined,
|
|
303
|
+
removePrePendingCallPromise?: (connectId: string, promise: Promise<void>) => void
|
|
288
304
|
) => {
|
|
289
|
-
const pendingPromise = getPrePendingCallPromise();
|
|
305
|
+
const pendingPromise = getPrePendingCallPromise(connectId);
|
|
290
306
|
if (pendingPromise) {
|
|
291
307
|
Log.debug('pre pending call promise before call method, wait for it');
|
|
308
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
309
|
+
let timedOut = false;
|
|
292
310
|
try {
|
|
293
|
-
await
|
|
311
|
+
await Promise.race([
|
|
312
|
+
pendingPromise,
|
|
313
|
+
new Promise<void>(resolve => {
|
|
314
|
+
timer = setTimeout(() => {
|
|
315
|
+
timedOut = true;
|
|
316
|
+
resolve();
|
|
317
|
+
}, PRE_PENDING_CALL_TIMEOUT_MS);
|
|
318
|
+
}),
|
|
319
|
+
]);
|
|
294
320
|
} catch (error) {
|
|
295
|
-
//
|
|
321
|
+
// Cancellation is best-effort; the transport teardown owns recovery.
|
|
322
|
+
} finally {
|
|
323
|
+
if (timer) clearTimeout(timer);
|
|
324
|
+
removePrePendingCallPromise?.(connectId, pendingPromise);
|
|
325
|
+
}
|
|
326
|
+
if (timedOut) {
|
|
327
|
+
Log.warn('pre pending call promise timed out before call method', { connectId });
|
|
296
328
|
}
|
|
297
|
-
removePrePendingCallPromise?.(pendingPromise);
|
|
298
329
|
Log.debug('pre pending call promise before call method done');
|
|
299
330
|
}
|
|
300
331
|
};
|
|
@@ -306,7 +337,7 @@ const onCallDevice = async (
|
|
|
306
337
|
): Promise<any> => {
|
|
307
338
|
let messageResponse: any;
|
|
308
339
|
|
|
309
|
-
const { requestQueue, getPrePendingCallPromise,
|
|
340
|
+
const { requestQueue, getPrePendingCallPromise, removePrePendingCallPromise } = context;
|
|
310
341
|
|
|
311
342
|
updateMethodRequestContext(method, { status: 'running' });
|
|
312
343
|
|
|
@@ -334,7 +365,11 @@ const onCallDevice = async (
|
|
|
334
365
|
await context.waitForCallbackTasks(method.connectId);
|
|
335
366
|
}
|
|
336
367
|
|
|
337
|
-
await waitForPendingPromise(
|
|
368
|
+
await waitForPendingPromise(
|
|
369
|
+
method.connectId ?? '',
|
|
370
|
+
getPrePendingCallPromise,
|
|
371
|
+
removePrePendingCallPromise
|
|
372
|
+
);
|
|
338
373
|
|
|
339
374
|
const task = requestQueue.createTask(method);
|
|
340
375
|
|
|
@@ -363,7 +398,7 @@ const onCallDevice = async (
|
|
|
363
398
|
);
|
|
364
399
|
} catch (e) {
|
|
365
400
|
preWarmCallbackTask?.resolve();
|
|
366
|
-
|
|
401
|
+
Log.debug('ensureConnected error: ', e);
|
|
367
402
|
|
|
368
403
|
completeMethodRequestContext(method, e);
|
|
369
404
|
|
|
@@ -380,6 +415,13 @@ const onCallDevice = async (
|
|
|
380
415
|
if (method.payload?.onlyConnectBleDevice) {
|
|
381
416
|
preWarmCallbackTask?.resolve();
|
|
382
417
|
Log.debug('Call API - only connect ble device: ', device?.mainId);
|
|
418
|
+
// This early return bypasses the normal-path bookkeeping at the end of the
|
|
419
|
+
// call. Without it the task leaks and haunts every later queue snapshot
|
|
420
|
+
// and cancel sweep (field log: a completed task lingered for 6 minutes),
|
|
421
|
+
// and the request stays in the active maps, so repeated preconnects pile
|
|
422
|
+
// up phantom work in diagnostics.
|
|
423
|
+
completeMethodRequestContext(method);
|
|
424
|
+
requestQueue.releaseTask(method.responseID);
|
|
383
425
|
return createResponseMessage(method.responseID, true, null);
|
|
384
426
|
}
|
|
385
427
|
|
|
@@ -402,6 +444,8 @@ const onCallDevice = async (
|
|
|
402
444
|
|
|
403
445
|
registerHardwareUiEventListeners(device, {
|
|
404
446
|
pin: onDevicePinHandler,
|
|
447
|
+
pinOnDevice: onEnterPinOnDeviceHandler,
|
|
448
|
+
pinOnDeviceComplete: onPinOnDeviceCompleteHandler,
|
|
405
449
|
button: onDeviceButtonHandler,
|
|
406
450
|
passphrase: message.payload.useEmptyPassphrase
|
|
407
451
|
? onEmptyPassphraseHandler
|
|
@@ -410,12 +454,16 @@ const onCallDevice = async (
|
|
|
410
454
|
attachPinOnDevice: onEnterAttachPinOnDeviceHandler,
|
|
411
455
|
});
|
|
412
456
|
device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
457
|
+
device.on(DEVICE.STATE, onDeviceStateHandler);
|
|
413
458
|
device.on(
|
|
414
459
|
DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE,
|
|
415
460
|
onSelectDeviceInBootloaderForWebDeviceHandler
|
|
416
461
|
);
|
|
417
462
|
|
|
418
463
|
const protocolV2UiCoordinator = new ProtocolV2UiInteractionCoordinator(device, postMessage);
|
|
464
|
+
let protocolV2Operation = false;
|
|
465
|
+
let protocolV2CloseEmitted = false;
|
|
466
|
+
device.beginProtocolV2UiInteraction();
|
|
419
467
|
device.on(
|
|
420
468
|
DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE,
|
|
421
469
|
onSelectDeviceForSwitchFirmwareWebDeviceHandler
|
|
@@ -427,14 +475,17 @@ const onCallDevice = async (
|
|
|
427
475
|
await context.waitForCallbackTasks(method.connectId, preWarmCallbackTask);
|
|
428
476
|
}
|
|
429
477
|
|
|
430
|
-
await waitForPendingPromise(
|
|
478
|
+
await waitForPendingPromise(
|
|
479
|
+
method.connectId ?? '',
|
|
480
|
+
getPrePendingCallPromise,
|
|
481
|
+
removePrePendingCallPromise
|
|
482
|
+
);
|
|
431
483
|
|
|
432
484
|
const inner = async (): Promise<void> => {
|
|
433
|
-
// Protocol
|
|
434
|
-
//
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
485
|
+
// Protocol is established from an active device response during acquire/initialize.
|
|
486
|
+
// Reject unsupported methods before any method-specific device command is sent.
|
|
487
|
+
method.assertProtocolSupported(device.getProtocol(), device.getCurrentFirmwareType());
|
|
488
|
+
protocolV2Operation = device.isProtocolV2();
|
|
438
489
|
|
|
439
490
|
// check firmware version
|
|
440
491
|
const versionRange = device.getCurrentMethodVersionRange(
|
|
@@ -445,8 +496,8 @@ const onCallDevice = async (
|
|
|
445
496
|
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
446
497
|
let newVersionStatus: ReturnType<typeof DataManager.getFirmwareStatus> | undefined;
|
|
447
498
|
|
|
448
|
-
//
|
|
449
|
-
// Pro2
|
|
499
|
+
// Defective-batch and forced-update gates depend on V1 features/remote config.
|
|
500
|
+
// Pro2 joins after DataManager supports its profile firmwareStatus.
|
|
450
501
|
if (device.features && !device.isProtocolV2()) {
|
|
451
502
|
await DataManager.checkAndReloadData();
|
|
452
503
|
|
|
@@ -494,10 +545,6 @@ const onCallDevice = async (
|
|
|
494
545
|
}
|
|
495
546
|
}
|
|
496
547
|
|
|
497
|
-
if (isMethodVersionRangeUnsupported(versionRange)) {
|
|
498
|
-
throw createDeviceNotSupportMethodError(method.name, deviceFirmwareType);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
548
|
if (versionRange) {
|
|
502
549
|
if (semver.valid(versionRange.min) && semver.lt(currentFirmwareVersion, versionRange.min)) {
|
|
503
550
|
if (newVersionStatus === 'none' || newVersionStatus === 'valid') {
|
|
@@ -548,93 +595,102 @@ const onCallDevice = async (
|
|
|
548
595
|
);
|
|
549
596
|
}
|
|
550
597
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
598
|
+
try {
|
|
599
|
+
let deviceIdCheckedDuringUnlockPreflight = false;
|
|
600
|
+
const response = await runMethodWithUnlockPolicy<object>(method, device, {
|
|
601
|
+
uiCoordinator: protocolV2UiCoordinator,
|
|
602
|
+
afterStatusBeforeUnlock: () => {
|
|
603
|
+
if (method.deviceId && method.checkDeviceId) {
|
|
604
|
+
if (!device.checkDeviceId(method.deviceId)) {
|
|
605
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
606
|
+
}
|
|
607
|
+
deviceIdCheckedDuringUnlockPreflight = true;
|
|
608
|
+
}
|
|
609
|
+
},
|
|
610
|
+
prepare: async () => {
|
|
611
|
+
if (method.deviceId && method.checkDeviceId && !deviceIdCheckedDuringUnlockPreflight) {
|
|
612
|
+
const isSameDeviceID = await checkLiveDeviceId(device, method.deviceId);
|
|
613
|
+
if (!isSameDeviceID) {
|
|
614
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
562
617
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
618
|
+
/**
|
|
619
|
+
* check firmware release info
|
|
620
|
+
*/
|
|
621
|
+
method.checkFirmwareRelease();
|
|
567
622
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
623
|
+
/**
|
|
624
|
+
* check additional supported feature
|
|
625
|
+
*/
|
|
626
|
+
method.checkDeviceSupportFeature();
|
|
572
627
|
|
|
573
|
-
|
|
574
|
-
|
|
628
|
+
// reconfigure messages
|
|
629
|
+
if (_deviceList && device.features && !device.isProtocolV2()) {
|
|
630
|
+
await TransportManager.reconfigure(device.features);
|
|
631
|
+
}
|
|
575
632
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
633
|
+
// Check to see if it is safe to use Passphrase
|
|
634
|
+
checkPassphraseEnableState(method, device.features);
|
|
635
|
+
|
|
636
|
+
if (shouldCheckPassphraseState(method, device)) {
|
|
637
|
+
// check version
|
|
638
|
+
const support = device.supportNewPassphrase();
|
|
639
|
+
if (!support.support) {
|
|
640
|
+
throw ERRORS.TypedError(
|
|
641
|
+
HardwareErrorCode.DeviceNotSupportPassphrase,
|
|
642
|
+
`Device not support passphrase, please update to ${support.require}`,
|
|
643
|
+
{
|
|
644
|
+
require: support.require,
|
|
645
|
+
}
|
|
646
|
+
);
|
|
586
647
|
}
|
|
587
|
-
)
|
|
588
|
-
);
|
|
589
|
-
}
|
|
590
648
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
649
|
+
// Check Device passphrase State after the Protocol V2 pre-unlock gate.
|
|
650
|
+
const passphraseStateSafety = await device.checkPassphraseStateSafety(
|
|
651
|
+
method.payload?.passphraseState,
|
|
652
|
+
method.payload?.useEmptyPassphrase,
|
|
653
|
+
method.payload?.skipPassphraseCheck,
|
|
654
|
+
hasDeriveCardano(method)
|
|
655
|
+
);
|
|
597
656
|
|
|
598
|
-
|
|
599
|
-
|
|
657
|
+
// Double check, handles the special case of Touch/Pro
|
|
658
|
+
checkPassphraseEnableState(method, device.features);
|
|
600
659
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
);
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
// close pin popup window
|
|
609
|
-
postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
|
|
610
|
-
}
|
|
660
|
+
if (!passphraseStateSafety) {
|
|
661
|
+
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
662
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
663
|
+
}
|
|
611
664
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
? e
|
|
619
|
-
: ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'open safety check failed.');
|
|
620
|
-
// messageResponse = createResponseMessage(method.responseID, false, { error });
|
|
621
|
-
// requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
622
|
-
// return;
|
|
623
|
-
throw error;
|
|
624
|
-
}
|
|
665
|
+
// Protocol V2 emits the PIN phase completion from DeviceSessionAskPin.
|
|
666
|
+
// Keep the legacy compatibility close for Protocol V1 only.
|
|
667
|
+
if (!device.isProtocolV2()) {
|
|
668
|
+
postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
|
|
669
|
+
}
|
|
670
|
+
}
|
|
625
671
|
|
|
626
|
-
|
|
672
|
+
// Automatic check safety_check level for Kovan, Ropsten, Rinkeby, Goerli test networks.
|
|
673
|
+
try {
|
|
674
|
+
await method.checkSafetyLevelOnTestNet();
|
|
675
|
+
} catch (e) {
|
|
676
|
+
throw e instanceof HardwareError
|
|
677
|
+
? e
|
|
678
|
+
: ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'open safety check failed.');
|
|
679
|
+
}
|
|
627
680
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
device,
|
|
632
|
-
protocolV2UiCoordinator
|
|
633
|
-
);
|
|
681
|
+
method.device?.commands?.checkDisposed();
|
|
682
|
+
},
|
|
683
|
+
});
|
|
634
684
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
635
685
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
636
686
|
completeMethodRequestContext(method);
|
|
637
687
|
} catch (error) {
|
|
688
|
+
// Device.run may release the request before transport callbacks finish after a timeout.
|
|
689
|
+
// Ignore the stale callback because the caller already received the connection error.
|
|
690
|
+
if (!requestQueue.getTask(method.responseID)) {
|
|
691
|
+
Log.debug(`Call API - Ignore late inner method result`, error);
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
638
694
|
Log.debug(`Call API - Inner Method Run Error`, error);
|
|
639
695
|
messageResponse = createResponseMessage(method.responseID, false, { error });
|
|
640
696
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
@@ -648,7 +704,12 @@ const onCallDevice = async (
|
|
|
648
704
|
throw error;
|
|
649
705
|
}
|
|
650
706
|
} finally {
|
|
651
|
-
|
|
707
|
+
if (isProtocolV2UiEnabled(method)) {
|
|
708
|
+
protocolV2CloseEmitted = protocolV2UiCoordinator.close({
|
|
709
|
+
ensureOperationClose: protocolV2Operation,
|
|
710
|
+
protocolV2Operation,
|
|
711
|
+
});
|
|
712
|
+
}
|
|
652
713
|
}
|
|
653
714
|
};
|
|
654
715
|
Log.debug('Call API - Device Run: ', device.mainId);
|
|
@@ -664,7 +725,9 @@ const onCallDevice = async (
|
|
|
664
725
|
try {
|
|
665
726
|
return await task.callPromise.promise;
|
|
666
727
|
} catch (e) {
|
|
667
|
-
|
|
728
|
+
if (!isExpectedCompatibilityError(e)) {
|
|
729
|
+
Log.debug('Device Run Error: ', e);
|
|
730
|
+
}
|
|
668
731
|
completeMethodRequestContext(method, e);
|
|
669
732
|
return createResponseMessage(method.responseID, false, { error: e });
|
|
670
733
|
}
|
|
@@ -703,7 +766,15 @@ const onCallDevice = async (
|
|
|
703
766
|
requestQueue.releaseTask(method.responseID);
|
|
704
767
|
|
|
705
768
|
if (isProtocolV2UiEnabled(method)) {
|
|
706
|
-
|
|
769
|
+
if (!protocolV2CloseEmitted && protocolV2Operation) {
|
|
770
|
+
protocolV2CloseEmitted = protocolV2UiCoordinator.close({
|
|
771
|
+
ensureOperationClose: true,
|
|
772
|
+
protocolV2Operation: true,
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
if (!protocolV2CloseEmitted) {
|
|
776
|
+
closePopup();
|
|
777
|
+
}
|
|
707
778
|
}
|
|
708
779
|
|
|
709
780
|
cleanup();
|
|
@@ -850,24 +921,155 @@ function canSkipInitialize(method: BaseMethod, device: Device): boolean {
|
|
|
850
921
|
return true;
|
|
851
922
|
}
|
|
852
923
|
|
|
853
|
-
function isRetryableBleProtocolV2ProbeError(method: BaseMethod, error: unknown) {
|
|
854
|
-
const
|
|
924
|
+
export function isRetryableBleProtocolV2ProbeError(method: BaseMethod, error: unknown) {
|
|
925
|
+
const typedError = error as { errorCode?: unknown; message?: unknown };
|
|
926
|
+
const message =
|
|
927
|
+
typeof typedError?.message === 'string' ? typedError.message : String(error ?? '');
|
|
855
928
|
return (
|
|
856
929
|
method.payload.connectProtocol === 'V2' &&
|
|
930
|
+
typedError?.errorCode === HardwareErrorCode.RuntimeError &&
|
|
857
931
|
message.includes('Device protocol mismatch') &&
|
|
858
932
|
message.includes('expected V2') &&
|
|
859
933
|
message.includes('did not respond to expected protocol')
|
|
860
934
|
);
|
|
861
935
|
}
|
|
862
936
|
|
|
937
|
+
export function isRetryableBleConnectionError(method: BaseMethod, error: unknown) {
|
|
938
|
+
if (method.device?.wasInterruptedByUser()) {
|
|
939
|
+
return false;
|
|
940
|
+
}
|
|
941
|
+
const typedError = error as { errorCode?: unknown };
|
|
942
|
+
return (
|
|
943
|
+
typedError?.errorCode === HardwareErrorCode.BleTimeoutError ||
|
|
944
|
+
typedError?.errorCode === HardwareErrorCode.BleConnectedError ||
|
|
945
|
+
isRetryableBleProtocolV2ProbeError(method, error) ||
|
|
946
|
+
isMissingDetectedProtocolV2Error(method, error)
|
|
947
|
+
);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
export function isMissingDetectedProtocolV2Error(method: BaseMethod, error: unknown) {
|
|
951
|
+
const typedError = error as { errorCode?: unknown; message?: unknown };
|
|
952
|
+
return (
|
|
953
|
+
method.payload.connectProtocol === 'V2' &&
|
|
954
|
+
typedError?.errorCode === HardwareErrorCode.RuntimeError &&
|
|
955
|
+
typeof typedError.message === 'string' &&
|
|
956
|
+
typedError.message.includes('Device protocol has not been detected')
|
|
957
|
+
);
|
|
958
|
+
}
|
|
959
|
+
|
|
863
960
|
/**
|
|
864
961
|
* If the Bluetooth connection times out, retry up to 6 times
|
|
865
962
|
* @param retryCount - Current retry count (default 0)
|
|
866
963
|
*/
|
|
867
|
-
|
|
964
|
+
// device.acquire awaits a transport reply with no deadline of its own; a
|
|
965
|
+
// transport that never settles (field case: Electron main lost an IPC reply,
|
|
966
|
+
// "reply was never sent" after 5 minutes) hangs the call forever and cancel()
|
|
967
|
+
// only takes effect at poll checkpoints. Race acquire against a deadline and
|
|
968
|
+
// the caller's abort signal so the hang is bounded and cancel is immediate.
|
|
969
|
+
const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
|
|
970
|
+
|
|
971
|
+
function raceBleAcquire<T>(acquirePromise: Promise<T>, abortSignal?: AbortSignal): Promise<T> {
|
|
972
|
+
return new Promise<T>((resolve, reject) => {
|
|
973
|
+
let settled = false;
|
|
974
|
+
const settle = (fn: () => void) => {
|
|
975
|
+
if (settled) return;
|
|
976
|
+
settled = true;
|
|
977
|
+
clearTimeout(deadline);
|
|
978
|
+
abortSignal?.removeEventListener('abort', onAbort);
|
|
979
|
+
fn();
|
|
980
|
+
};
|
|
981
|
+
const onAbort = () =>
|
|
982
|
+
settle(() => reject(ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled)));
|
|
983
|
+
const deadline = setTimeout(
|
|
984
|
+
() =>
|
|
985
|
+
settle(() =>
|
|
986
|
+
reject(
|
|
987
|
+
ERRORS.TypedError(
|
|
988
|
+
HardwareErrorCode.BleTimeoutError,
|
|
989
|
+
`BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`
|
|
990
|
+
)
|
|
991
|
+
)
|
|
992
|
+
),
|
|
993
|
+
BLE_ACQUIRE_DEADLINE_MS
|
|
994
|
+
);
|
|
995
|
+
// Attach before any early return so a late settlement of acquirePromise
|
|
996
|
+
// is always consumed — an abort or deadline must never leave the acquire
|
|
997
|
+
// rejection unhandled.
|
|
998
|
+
acquirePromise.then(
|
|
999
|
+
value => settle(() => resolve(value)),
|
|
1000
|
+
error => settle(() => reject(error))
|
|
1001
|
+
);
|
|
1002
|
+
if (abortSignal) {
|
|
1003
|
+
if (abortSignal.aborted) {
|
|
1004
|
+
onAbort();
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
abortSignal.addEventListener('abort', onAbort);
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
async function connectDeviceForBle(
|
|
1013
|
+
method: BaseMethod,
|
|
1014
|
+
device: Device,
|
|
1015
|
+
abortSignal?: AbortSignal,
|
|
1016
|
+
retryCount = 0
|
|
1017
|
+
) {
|
|
868
1018
|
try {
|
|
869
|
-
|
|
1019
|
+
if (device.wasInterruptedByUser()) {
|
|
1020
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceInterruptedFromUser);
|
|
1021
|
+
}
|
|
1022
|
+
if (method.payload.forceProtocolDetection && device.hasDeviceAcquire()) {
|
|
1023
|
+
await device.release();
|
|
1024
|
+
}
|
|
1025
|
+
const shouldAcquire =
|
|
1026
|
+
method.payload.forceProtocolDetection ||
|
|
1027
|
+
!device.hasDeviceAcquire() ||
|
|
1028
|
+
!device.commands ||
|
|
1029
|
+
device.commands.disposed;
|
|
1030
|
+
if (shouldAcquire) {
|
|
1031
|
+
// The deadline/abort guards are scoped to the desktop electron
|
|
1032
|
+
// transport: its IPC acquire is the only path with a proven
|
|
1033
|
+
// never-settling failure mode, while react-native/lowlevel acquire may
|
|
1034
|
+
// legitimately block on a user-driven system bonding prompt for longer
|
|
1035
|
+
// than any sane deadline. Other envs keep the plain acquire unchanged.
|
|
1036
|
+
const useAcquireGuards = DataManager.getSettings('env') === 'desktop-web-ble';
|
|
1037
|
+
// A cancel landing during the retry backoff must not start a new acquire.
|
|
1038
|
+
if (useAcquireGuards && abortSignal?.aborted) {
|
|
1039
|
+
throw ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled);
|
|
1040
|
+
}
|
|
1041
|
+
if (!useAcquireGuards) {
|
|
1042
|
+
await device.acquire(method.payload.connectProtocol, {
|
|
1043
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
1044
|
+
});
|
|
1045
|
+
} else {
|
|
1046
|
+
try {
|
|
1047
|
+
await raceBleAcquire(
|
|
1048
|
+
device.acquire(method.payload.connectProtocol, {
|
|
1049
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
1050
|
+
}),
|
|
1051
|
+
abortSignal
|
|
1052
|
+
);
|
|
1053
|
+
} catch (err) {
|
|
1054
|
+
// A deadline hit means the transport is wedged mid-acquire; drop the
|
|
1055
|
+
// link before the retry so it cold-connects instead of stacking a
|
|
1056
|
+
// second connect onto the half-open one.
|
|
1057
|
+
if (
|
|
1058
|
+
err.errorCode === HardwareErrorCode.BleTimeoutError &&
|
|
1059
|
+
device.mainId &&
|
|
1060
|
+
device.deviceConnector
|
|
1061
|
+
) {
|
|
1062
|
+
await device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
|
|
1063
|
+
device.markTransportDisconnected();
|
|
1064
|
+
}
|
|
1065
|
+
throw err;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
870
1069
|
if (method.payload?.onlyConnectBleDevice) {
|
|
1070
|
+
if (shouldAcquire) {
|
|
1071
|
+
DevicePool.emitter.emit(DEVICE.CONNECT, device);
|
|
1072
|
+
}
|
|
871
1073
|
return;
|
|
872
1074
|
}
|
|
873
1075
|
// Skip initialize if conditions are met
|
|
@@ -878,17 +1080,31 @@ async function connectDeviceForBle(method: BaseMethod, device: Device, retryCoun
|
|
|
878
1080
|
passphraseState: initOptions.passphraseState,
|
|
879
1081
|
});
|
|
880
1082
|
}
|
|
1083
|
+
if (shouldAcquire) {
|
|
1084
|
+
DevicePool.emitter.emit(DEVICE.CONNECT, device);
|
|
1085
|
+
}
|
|
881
1086
|
} catch (err) {
|
|
1087
|
+
const requiresColdReconnect = isMissingDetectedProtocolV2Error(method, err);
|
|
1088
|
+
// Device.run()'s REQUIRE_DISCONNECT handling never sees acquire/initialize
|
|
1089
|
+
// failures, so with keep-alive a wedged link would be reused by every retry
|
|
1090
|
+
// (field case: Initialize timing out at 25s per attempt, forever). Drop it
|
|
1091
|
+
// here so the next retry cold-connects.
|
|
882
1092
|
if (
|
|
883
|
-
(err.errorCode
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
retryCount < 6
|
|
1093
|
+
(ERROR_CODES_REQUIRE_DISCONNECT.includes(err.errorCode) || requiresColdReconnect) &&
|
|
1094
|
+
device.mainId &&
|
|
1095
|
+
device.deviceConnector
|
|
887
1096
|
) {
|
|
1097
|
+
await device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
|
|
1098
|
+
// The connector only drops the link; `deviceAcquired` is reset by
|
|
1099
|
+
// release()/markTransportDisconnected() alone. Leaving it set makes the
|
|
1100
|
+
// next attempt skip acquire and initialize onto the link we just cut.
|
|
1101
|
+
device.markTransportDisconnected();
|
|
1102
|
+
}
|
|
1103
|
+
if (isRetryableBleConnectionError(method, err) && retryCount < 6) {
|
|
888
1104
|
const nextRetry = retryCount + 1;
|
|
889
|
-
Log.debug(`Bluetooth
|
|
1105
|
+
Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
|
|
890
1106
|
await wait(3000);
|
|
891
|
-
await connectDeviceForBle(method, device, nextRetry);
|
|
1107
|
+
await connectDeviceForBle(method, device, abortSignal, nextRetry);
|
|
892
1108
|
} else {
|
|
893
1109
|
throw err;
|
|
894
1110
|
}
|
|
@@ -993,13 +1209,31 @@ const ensureConnected = async (
|
|
|
993
1209
|
if (abort()) {
|
|
994
1210
|
return;
|
|
995
1211
|
}
|
|
996
|
-
|
|
1212
|
+
// One generation per public ensureConnected() call, not per poll
|
|
1213
|
+
// iteration. A later poll must not clear a user cancel.
|
|
1214
|
+
if (tryCount === 1) {
|
|
1215
|
+
device.beginConnectionAttempt();
|
|
1216
|
+
}
|
|
1217
|
+
await connectDeviceForBle(method, device, abortSignal);
|
|
997
1218
|
}
|
|
998
1219
|
resolve(device);
|
|
999
1220
|
return;
|
|
1000
1221
|
}
|
|
1001
1222
|
} catch (error) {
|
|
1002
1223
|
Log.debug('device error: ', error);
|
|
1224
|
+
if (error.errorCode === HardwareErrorCode.BleUnavailableWhileUsbConnected) {
|
|
1225
|
+
reject(error);
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
if (isProtocolV2LinkDisabledError(error)) {
|
|
1229
|
+
reject(
|
|
1230
|
+
ERRORS.TypedError(HardwareErrorCode.BleUnavailableWhileUsbConnected, undefined, {
|
|
1231
|
+
failureCode: error.failureCode,
|
|
1232
|
+
firmwareMessage: error.firmwareMessage,
|
|
1233
|
+
})
|
|
1234
|
+
);
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1003
1237
|
if ([HardwareErrorCode.BleCharacteristicNotifyChangeFailure].includes(error.errorCode)) {
|
|
1004
1238
|
postMessage(createUiMessage(UI_REQUEST.BLUETOOTH_CHARACTERISTIC_NOTIFY_CHANGE_FAILURE));
|
|
1005
1239
|
}
|
|
@@ -1022,6 +1256,8 @@ const ensureConnected = async (
|
|
|
1022
1256
|
HardwareErrorCode.DeviceDetectInBootloaderMode,
|
|
1023
1257
|
HardwareErrorCode.BleCharacteristicNotifyChangeFailure,
|
|
1024
1258
|
HardwareErrorCode.BridgeNeedsPermission,
|
|
1259
|
+
HardwareErrorCode.DeviceInterruptedFromUser,
|
|
1260
|
+
HardwareErrorCode.CallQueueActionCancelled,
|
|
1025
1261
|
].includes(error.errorCode)
|
|
1026
1262
|
) {
|
|
1027
1263
|
reject(error);
|
|
@@ -1078,23 +1314,34 @@ export const cancel = (context: CoreContext, connectId?: string) => {
|
|
|
1078
1314
|
','
|
|
1079
1315
|
)}`
|
|
1080
1316
|
);
|
|
1317
|
+
// Abort before rejecting: rejectRequest releases the task and would make
|
|
1318
|
+
// its AbortController unreachable to an in-flight method loop.
|
|
1319
|
+
requestQueue.abortRequestsByConnectId(connectId);
|
|
1081
1320
|
const canceledDevices: Device[] = [];
|
|
1321
|
+
const interruptDevice = (device: Device | undefined, deviceConnectId: string) => {
|
|
1322
|
+
if (!device || canceledDevices.includes(device)) {
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
setPrePendingCallPromise(deviceConnectId, device.interruptionFromUser());
|
|
1326
|
+
canceledDevices.push(device);
|
|
1327
|
+
};
|
|
1082
1328
|
for (const requestId of requestIds) {
|
|
1083
1329
|
const task = requestQueue.getTask(requestId);
|
|
1084
1330
|
Log.debug('Cancel Api connect task: ', task);
|
|
1085
|
-
if (task
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1331
|
+
if (task) {
|
|
1332
|
+
// During ensureConnected the method has a connectId but device is
|
|
1333
|
+
// assigned only after the poll succeeds. Interrupt the cached BLE
|
|
1334
|
+
// Device so an in-flight acquire/initialize cannot finish.
|
|
1335
|
+
interruptDevice(task.method?.device, task.method.connectId ?? connectId);
|
|
1336
|
+
interruptDevice(deviceCacheMap.get(connectId), connectId);
|
|
1091
1337
|
requestQueue.rejectRequest(
|
|
1092
1338
|
requestId,
|
|
1093
1339
|
ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled)
|
|
1094
1340
|
);
|
|
1095
1341
|
}
|
|
1096
1342
|
}
|
|
1097
|
-
|
|
1343
|
+
interruptDevice(deviceCacheMap.get(connectId), connectId);
|
|
1344
|
+
pollingManager.stop(connectId);
|
|
1098
1345
|
} catch (e) {
|
|
1099
1346
|
Log.error('Cancel API Error: ', e);
|
|
1100
1347
|
}
|
|
@@ -1102,23 +1349,33 @@ export const cancel = (context: CoreContext, connectId?: string) => {
|
|
|
1102
1349
|
const env = DataManager.getSettings('env');
|
|
1103
1350
|
if (DataManager.isBleConnect(env)) {
|
|
1104
1351
|
Log.debug('Cancel Api all _deviceList: ');
|
|
1352
|
+
// Keep method abort signals observable until every active task is rejected.
|
|
1353
|
+
requestQueue.abortAllRequests();
|
|
1105
1354
|
const canceledDevices: Device[] = [];
|
|
1355
|
+
const interruptDevice = (device?: Device) => {
|
|
1356
|
+
if (!device || canceledDevices.includes(device)) {
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
1359
|
+
device.interruptionFromUser().catch(() => undefined);
|
|
1360
|
+
canceledDevices.push(device);
|
|
1361
|
+
};
|
|
1106
1362
|
for (const requestId of requestQueue.getRequestTasksId()) {
|
|
1107
1363
|
const task = requestQueue.getTask(requestId);
|
|
1108
1364
|
Log.debug('Cancel Api connect task: ', task);
|
|
1109
|
-
if (task
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1365
|
+
if (task) {
|
|
1366
|
+
interruptDevice(task.method?.device);
|
|
1367
|
+
if (task.method.connectId) {
|
|
1368
|
+
interruptDevice(deviceCacheMap.get(task.method.connectId));
|
|
1369
|
+
pollingManager.stop(task.method.connectId);
|
|
1114
1370
|
}
|
|
1115
|
-
|
|
1116
1371
|
requestQueue.rejectRequest(
|
|
1117
1372
|
requestId,
|
|
1118
1373
|
ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled)
|
|
1119
1374
|
);
|
|
1120
1375
|
}
|
|
1121
1376
|
}
|
|
1377
|
+
deviceCacheMap.forEach(interruptDevice);
|
|
1378
|
+
pollingManager.stopAll();
|
|
1122
1379
|
} else {
|
|
1123
1380
|
_deviceList?.allDevices().forEach(device => {
|
|
1124
1381
|
Log.debug('device: ', device, ' device.hasDeviceAcquire: ', device.hasDeviceAcquire());
|
|
@@ -1172,14 +1429,16 @@ const shouldCheckPassphraseState = (method: BaseMethod, device: Device) => {
|
|
|
1172
1429
|
};
|
|
1173
1430
|
|
|
1174
1431
|
const cleanup = () => {
|
|
1432
|
+
const pendingUiPromises = _uiPromises;
|
|
1175
1433
|
_uiPromises = [];
|
|
1176
|
-
|
|
1434
|
+
rejectUiPromises(
|
|
1435
|
+
pendingUiPromises,
|
|
1436
|
+
ERRORS.TypedError(HardwareErrorCode.ActionCancelled, 'UI request was cancelled')
|
|
1437
|
+
);
|
|
1177
1438
|
};
|
|
1178
1439
|
|
|
1179
1440
|
const removeDeviceListener = (device: Device) => {
|
|
1180
1441
|
device.removeAllListeners();
|
|
1181
|
-
DevicePool.emitter.removeAllListeners(DEVICE.CONNECT);
|
|
1182
|
-
// DevicePool.emitter.removeListener(DEVICE.DISCONNECT, onDeviceDisconnectHandler);
|
|
1183
1442
|
};
|
|
1184
1443
|
|
|
1185
1444
|
/**
|
|
@@ -1190,19 +1449,33 @@ const closePopup = () => {
|
|
|
1190
1449
|
};
|
|
1191
1450
|
|
|
1192
1451
|
const onDeviceConnectHandler = (device: Device) => {
|
|
1193
|
-
const
|
|
1194
|
-
|
|
1195
|
-
postMessage(createDeviceMessage(DEVICE.CONNECT, { device: deviceObject
|
|
1452
|
+
const deviceObject = device.toMessageObject();
|
|
1453
|
+
if (!deviceObject) return;
|
|
1454
|
+
postMessage(createDeviceMessage(DEVICE.CONNECT, { device: deviceObject }));
|
|
1196
1455
|
};
|
|
1197
1456
|
|
|
1198
1457
|
const onDeviceDisconnectHandler = (device: Device) => {
|
|
1199
1458
|
device.clearPreInitialized();
|
|
1200
|
-
const
|
|
1201
|
-
|
|
1202
|
-
postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject
|
|
1459
|
+
const deviceObject = device.toMessageObject();
|
|
1460
|
+
if (!deviceObject) return;
|
|
1461
|
+
postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject }));
|
|
1462
|
+
};
|
|
1463
|
+
|
|
1464
|
+
const onTransportDeviceDisconnectHandler = (event: TransportDeviceDisconnectEvent) => {
|
|
1465
|
+
const device =
|
|
1466
|
+
deviceCacheMap.get(event.connectId) ??
|
|
1467
|
+
DevicePool.devicesCache[event.connectId] ??
|
|
1468
|
+
DevicePool.getDeviceByPath(event.connectId);
|
|
1469
|
+
if (!device) {
|
|
1470
|
+
Log.debug('Ignoring transport disconnect for an unknown device:', event.connectId);
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
device.markTransportDisconnected();
|
|
1475
|
+
DevicePool.emitter.emit(DEVICE.DISCONNECT, device);
|
|
1203
1476
|
};
|
|
1204
1477
|
|
|
1205
|
-
const onDevicePinHandler =
|
|
1478
|
+
const onDevicePinHandler = (...[device, type, callback]: DeviceEvents['pin']) => {
|
|
1206
1479
|
Log.log('request Input PIN');
|
|
1207
1480
|
// create ui promise
|
|
1208
1481
|
const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PIN, device);
|
|
@@ -1211,12 +1484,14 @@ const onDevicePinHandler = async (...[device, type, callback]: DeviceEvents['pin
|
|
|
1211
1484
|
createUiMessage(UI_REQUEST.REQUEST_PIN, {
|
|
1212
1485
|
device: device.toMessageObject() as unknown as KnownDevice,
|
|
1213
1486
|
type,
|
|
1487
|
+
responseCorrelation: uiPromise.responseCorrelation,
|
|
1214
1488
|
})
|
|
1215
1489
|
);
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1490
|
+
consumeUiPromise(
|
|
1491
|
+
uiPromise.promise,
|
|
1492
|
+
uiResp => callback(null, uiResp.payload),
|
|
1493
|
+
error => callback(error, '')
|
|
1494
|
+
);
|
|
1220
1495
|
};
|
|
1221
1496
|
|
|
1222
1497
|
export const onDeviceButtonHandler = (...[device, request]: [...DeviceEvents['button']]) => {
|
|
@@ -1240,7 +1515,11 @@ const onDeviceFeaturesHandler = (...[_, features]: [...DeviceEvents['features']]
|
|
|
1240
1515
|
postMessage(createDeviceMessage(DEVICE.FEATURES, { ...features }));
|
|
1241
1516
|
};
|
|
1242
1517
|
|
|
1243
|
-
const
|
|
1518
|
+
const onDeviceStateHandler = (...[_, stateEvent]: [...DeviceEvents['state']]) => {
|
|
1519
|
+
postMessage(createDeviceMessage(DEVICE.STATE, stateEvent));
|
|
1520
|
+
};
|
|
1521
|
+
|
|
1522
|
+
const onDevicePassphraseHandler = (
|
|
1244
1523
|
...[device, requestPayload, callback]: DeviceEvents['passphrase']
|
|
1245
1524
|
) => {
|
|
1246
1525
|
Log.debug('onDevicePassphraseHandler');
|
|
@@ -1250,21 +1529,27 @@ const onDevicePassphraseHandler = async (
|
|
|
1250
1529
|
device: device.toMessageObject() as KnownDevice,
|
|
1251
1530
|
passphraseState: device.passphraseState,
|
|
1252
1531
|
existsAttachPinUser: requestPayload.existsAttachPinUser,
|
|
1532
|
+
deviceOnly: requestPayload.deviceOnly,
|
|
1253
1533
|
source: requestPayload.source,
|
|
1254
1534
|
reason: requestPayload.reason,
|
|
1255
1535
|
expectedPassphraseState: requestPayload.expectedPassphraseState,
|
|
1536
|
+
...(requestPayload.interaction ? { interaction: requestPayload.interaction } : {}),
|
|
1537
|
+
responseCorrelation: uiPromise.responseCorrelation,
|
|
1256
1538
|
})
|
|
1257
1539
|
);
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1540
|
+
consumeUiPromise(
|
|
1541
|
+
uiPromise.promise,
|
|
1542
|
+
uiResp => {
|
|
1543
|
+
const { value, passphraseOnDevice, save, attachPinOnDevice } = uiResp.payload;
|
|
1544
|
+
callback({
|
|
1545
|
+
passphrase: value.normalize('NFKD'),
|
|
1546
|
+
passphraseOnDevice,
|
|
1547
|
+
attachPinOnDevice,
|
|
1548
|
+
cache: save,
|
|
1549
|
+
});
|
|
1550
|
+
},
|
|
1551
|
+
error => callback({}, error)
|
|
1552
|
+
);
|
|
1268
1553
|
};
|
|
1269
1554
|
|
|
1270
1555
|
const onEmptyPassphraseHandler = (...[_, , callback]: DeviceEvents['passphrase']) => {
|
|
@@ -1282,6 +1567,7 @@ const onEnterPassphraseOnDeviceHandler = (
|
|
|
1282
1567
|
passphraseState: device.passphraseState,
|
|
1283
1568
|
source: requestPayload?.source,
|
|
1284
1569
|
reason: requestPayload?.reason,
|
|
1570
|
+
...(requestPayload?.interaction ? { interaction: requestPayload.interaction } : {}),
|
|
1285
1571
|
})
|
|
1286
1572
|
);
|
|
1287
1573
|
};
|
|
@@ -1295,11 +1581,40 @@ const onEnterAttachPinOnDeviceHandler = (
|
|
|
1295
1581
|
type: 'ButtonRequest_AttachPin',
|
|
1296
1582
|
source: requestPayload?.source,
|
|
1297
1583
|
reason: requestPayload?.reason,
|
|
1584
|
+
...(requestPayload?.interaction ? { interaction: requestPayload.interaction } : {}),
|
|
1585
|
+
})
|
|
1586
|
+
);
|
|
1587
|
+
};
|
|
1588
|
+
|
|
1589
|
+
const onEnterPinOnDeviceHandler = (
|
|
1590
|
+
...[device, pinType, metadata]: [...DeviceEvents['pin_on_device']]
|
|
1591
|
+
) => {
|
|
1592
|
+
postMessage(
|
|
1593
|
+
createUiMessage(UI_REQUEST.REQUEST_PIN, {
|
|
1594
|
+
device: device.toMessageObject() as KnownDevice,
|
|
1595
|
+
type:
|
|
1596
|
+
pinType === DeviceSessionPinType.AttachToPin
|
|
1597
|
+
? 'ButtonRequest_AttachPin'
|
|
1598
|
+
: 'ButtonRequest_PinEntry',
|
|
1599
|
+
source: metadata?.source,
|
|
1600
|
+
reason: metadata?.reason,
|
|
1601
|
+
deviceOnly: metadata?.deviceOnly ?? true,
|
|
1602
|
+
completion: metadata?.completion,
|
|
1603
|
+
method: metadata?.method,
|
|
1604
|
+
page: metadata?.page,
|
|
1605
|
+
operation: metadata?.operation,
|
|
1606
|
+
...(metadata?.interaction ? { interaction: metadata.interaction } : {}),
|
|
1298
1607
|
})
|
|
1299
1608
|
);
|
|
1300
1609
|
};
|
|
1301
1610
|
|
|
1302
|
-
const
|
|
1611
|
+
const onPinOnDeviceCompleteHandler = (
|
|
1612
|
+
...[_, metadata]: [...DeviceEvents['pin_on_device_complete']]
|
|
1613
|
+
) => {
|
|
1614
|
+
postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW, metadata));
|
|
1615
|
+
};
|
|
1616
|
+
|
|
1617
|
+
const onSelectDeviceInBootloaderForWebDeviceHandler = (
|
|
1303
1618
|
...[device, callback]: [...DeviceEvents['select_device_in_bootloader_for_web_device']]
|
|
1304
1619
|
) => {
|
|
1305
1620
|
Log.debug('onSelectDeviceInBootloaderForWebDeviceHandler');
|
|
@@ -1309,11 +1624,14 @@ const onSelectDeviceInBootloaderForWebDeviceHandler = async (
|
|
|
1309
1624
|
device: device.toMessageObject() as KnownDevice,
|
|
1310
1625
|
})
|
|
1311
1626
|
);
|
|
1312
|
-
|
|
1313
|
-
|
|
1627
|
+
consumeUiPromise(
|
|
1628
|
+
uiPromise.promise,
|
|
1629
|
+
uiResp => callback(null, uiResp.payload.deviceId),
|
|
1630
|
+
error => callback(error, '')
|
|
1631
|
+
);
|
|
1314
1632
|
};
|
|
1315
1633
|
|
|
1316
|
-
const onSelectDeviceForSwitchFirmwareWebDeviceHandler =
|
|
1634
|
+
const onSelectDeviceForSwitchFirmwareWebDeviceHandler = (
|
|
1317
1635
|
...[device, callback]: [...DeviceEvents['select_device_for_switch_firmware_web_device']]
|
|
1318
1636
|
) => {
|
|
1319
1637
|
Log.debug('onSelectDeviceForSwitchFirmwareWebDeviceHandler');
|
|
@@ -1326,8 +1644,11 @@ const onSelectDeviceForSwitchFirmwareWebDeviceHandler = async (
|
|
|
1326
1644
|
device: device.toMessageObject() as KnownDevice,
|
|
1327
1645
|
})
|
|
1328
1646
|
);
|
|
1329
|
-
|
|
1330
|
-
|
|
1647
|
+
consumeUiPromise(
|
|
1648
|
+
uiPromise.promise,
|
|
1649
|
+
uiResp => callback(null, uiResp.payload.deviceId),
|
|
1650
|
+
error => callback(error, '')
|
|
1651
|
+
);
|
|
1331
1652
|
};
|
|
1332
1653
|
|
|
1333
1654
|
/**
|
|
@@ -1346,14 +1667,21 @@ const postMessage = (message: CoreMessage) => {
|
|
|
1346
1667
|
|
|
1347
1668
|
const createUiPromise = <T extends UiPromiseResponse['type']>(promiseEvent: T, device?: Device) => {
|
|
1348
1669
|
const uiPromise: UiPromise<T> = createDeferred(promiseEvent, device);
|
|
1670
|
+
if (
|
|
1671
|
+
device &&
|
|
1672
|
+
(promiseEvent === UI_RESPONSE.RECEIVE_PIN || promiseEvent === UI_RESPONSE.RECEIVE_PASSPHRASE)
|
|
1673
|
+
) {
|
|
1674
|
+
const publicDeviceId = device.toMessageObject()?.deviceId;
|
|
1675
|
+
uiPromise.responseCorrelation = {
|
|
1676
|
+
interactionId: generateInstanceId('UiResponse', device.sdkInstanceId),
|
|
1677
|
+
deviceId: publicDeviceId || device.instanceId,
|
|
1678
|
+
};
|
|
1679
|
+
}
|
|
1349
1680
|
_uiPromises.push(uiPromise as any);
|
|
1350
1681
|
|
|
1351
1682
|
return uiPromise;
|
|
1352
1683
|
};
|
|
1353
1684
|
|
|
1354
|
-
const findUiPromise = <T extends UiPromiseResponse['type']>(promiseEvent: T) =>
|
|
1355
|
-
_uiPromises.find(p => p.id === promiseEvent);
|
|
1356
|
-
|
|
1357
1685
|
const removeUiPromise = (promise: Deferred<any>) => {
|
|
1358
1686
|
_uiPromises = _uiPromises.filter(p => p !== promise);
|
|
1359
1687
|
};
|
|
@@ -1365,8 +1693,10 @@ export default class Core extends EventEmitter {
|
|
|
1365
1693
|
|
|
1366
1694
|
private requestQueue = new RequestQueue();
|
|
1367
1695
|
|
|
1696
|
+
private disposePromise?: Promise<void>;
|
|
1697
|
+
|
|
1368
1698
|
// background task
|
|
1369
|
-
private
|
|
1699
|
+
private prePendingCallPromises = new Map<string, Promise<void>>();
|
|
1370
1700
|
|
|
1371
1701
|
private methodSynchronize = getSynchronize();
|
|
1372
1702
|
|
|
@@ -1377,19 +1707,24 @@ export default class Core extends EventEmitter {
|
|
|
1377
1707
|
Log.debug(`[Core] Created SDK instance: ${this.sdkInstanceId}`);
|
|
1378
1708
|
}
|
|
1379
1709
|
|
|
1380
|
-
cancelOperation(operationId: string) {
|
|
1381
|
-
this.requestQueue.abortOperation(operationId);
|
|
1382
|
-
}
|
|
1383
|
-
|
|
1384
1710
|
private getCoreContext() {
|
|
1385
1711
|
return {
|
|
1386
1712
|
sdkInstanceId: this.sdkInstanceId,
|
|
1387
1713
|
tracingContext: this.tracingContext,
|
|
1388
1714
|
requestQueue: this.requestQueue,
|
|
1389
1715
|
methodSynchronize: this.methodSynchronize,
|
|
1390
|
-
getPrePendingCallPromise: () => this.
|
|
1391
|
-
setPrePendingCallPromise: (
|
|
1392
|
-
|
|
1716
|
+
getPrePendingCallPromise: (connectId: string) => this.prePendingCallPromises.get(connectId),
|
|
1717
|
+
setPrePendingCallPromise: (connectId: string, promise?: Promise<void>) => {
|
|
1718
|
+
if (!promise) {
|
|
1719
|
+
this.prePendingCallPromises.delete(connectId);
|
|
1720
|
+
return;
|
|
1721
|
+
}
|
|
1722
|
+
this.prePendingCallPromises.set(connectId, promise);
|
|
1723
|
+
},
|
|
1724
|
+
removePrePendingCallPromise: (connectId: string, promise: Promise<void>) => {
|
|
1725
|
+
if (this.prePendingCallPromises.get(connectId) === promise) {
|
|
1726
|
+
this.prePendingCallPromises.delete(connectId);
|
|
1727
|
+
}
|
|
1393
1728
|
},
|
|
1394
1729
|
// callback 任务管理
|
|
1395
1730
|
registerCallbackTask: (connectId: string, callbackPromise: Deferred<any>) => {
|
|
@@ -1407,11 +1742,16 @@ export default class Core extends EventEmitter {
|
|
|
1407
1742
|
case UI_RESPONSE.RECEIVE_PASSPHRASE:
|
|
1408
1743
|
case UI_RESPONSE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE:
|
|
1409
1744
|
case UI_RESPONSE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE: {
|
|
1410
|
-
const uiPromise =
|
|
1745
|
+
const uiPromise = findUiPromiseForResponse(_uiPromises, message);
|
|
1411
1746
|
if (uiPromise) {
|
|
1412
1747
|
Log.log('receive UI Response: ', message.type);
|
|
1413
1748
|
uiPromise.resolve(message);
|
|
1414
1749
|
removeUiPromise(uiPromise);
|
|
1750
|
+
} else if (
|
|
1751
|
+
message.type === UI_RESPONSE.RECEIVE_PIN ||
|
|
1752
|
+
message.type === UI_RESPONSE.RECEIVE_PASSPHRASE
|
|
1753
|
+
) {
|
|
1754
|
+
Log.warn('Ignored unmatched or ambiguous sensitive UI response:', message.type);
|
|
1415
1755
|
}
|
|
1416
1756
|
break;
|
|
1417
1757
|
}
|
|
@@ -1427,10 +1767,17 @@ export default class Core extends EventEmitter {
|
|
|
1427
1767
|
}
|
|
1428
1768
|
|
|
1429
1769
|
case IFRAME.CALL: {
|
|
1430
|
-
|
|
1770
|
+
const logBlockLabel = getLogBlockLabel(message);
|
|
1771
|
+
Log.log(
|
|
1772
|
+
formatLogMethodLabel(`[${Date.now()}][CALL_API]`, logBlockLabel),
|
|
1773
|
+
getSafeLogPayload(message, logBlockLabel)
|
|
1774
|
+
);
|
|
1431
1775
|
const response = await callAPI(this.getCoreContext(), message);
|
|
1432
1776
|
const { success, payload } = response;
|
|
1433
|
-
Log.log(
|
|
1777
|
+
Log.log(
|
|
1778
|
+
formatLogMethodLabel(`[${Date.now()}][CALL_API_RESPONSE]`, logBlockLabel),
|
|
1779
|
+
getSafeLogPayload(response, logBlockLabel)
|
|
1780
|
+
);
|
|
1434
1781
|
if (success) {
|
|
1435
1782
|
return response;
|
|
1436
1783
|
}
|
|
@@ -1449,10 +1796,6 @@ export default class Core extends EventEmitter {
|
|
|
1449
1796
|
cancel(this.getCoreContext(), message.payload.connectId);
|
|
1450
1797
|
break;
|
|
1451
1798
|
}
|
|
1452
|
-
case IFRAME.CANCEL_OPERATION: {
|
|
1453
|
-
this.cancelOperation(message.payload.operationId);
|
|
1454
|
-
break;
|
|
1455
|
-
}
|
|
1456
1799
|
case IFRAME.CALLBACK: {
|
|
1457
1800
|
Log.log('callback message: ', message);
|
|
1458
1801
|
postMessage(message);
|
|
@@ -1464,25 +1807,65 @@ export default class Core extends EventEmitter {
|
|
|
1464
1807
|
return Promise.resolve(message);
|
|
1465
1808
|
}
|
|
1466
1809
|
|
|
1467
|
-
dispose() {
|
|
1810
|
+
dispose(): Promise<void> {
|
|
1811
|
+
if (!this.disposePromise) {
|
|
1812
|
+
this.disposePromise = this.disposeResources();
|
|
1813
|
+
}
|
|
1814
|
+
return this.disposePromise;
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
private async disposeResources(): Promise<void> {
|
|
1818
|
+
Log.debug(`[Core] Disposing SDK instance: ${this.sdkInstanceId}`);
|
|
1819
|
+
pollingManager.stopAll();
|
|
1820
|
+
this.requestQueue.abortAllRequests();
|
|
1821
|
+
cleanup();
|
|
1822
|
+
|
|
1823
|
+
_connector?.stop();
|
|
1824
|
+
let transportCleanup: Promise<void>;
|
|
1825
|
+
try {
|
|
1826
|
+
transportCleanup = Promise.resolve(TransportManager.getTransport()?.stop?.()).catch(error => {
|
|
1827
|
+
Log.warn('[Core] Transport cleanup failed:', error);
|
|
1828
|
+
});
|
|
1829
|
+
} catch (error) {
|
|
1830
|
+
Log.warn('[Core] Transport cleanup failed:', error);
|
|
1831
|
+
transportCleanup = Promise.resolve();
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
// Preserve synchronous dispose semantics for in-memory state and listeners.
|
|
1468
1835
|
_deviceList = undefined;
|
|
1469
1836
|
_connector = undefined;
|
|
1837
|
+
DevicePool.dispose();
|
|
1470
1838
|
deviceCacheMap.clear();
|
|
1471
1839
|
preWarmInflight.clear();
|
|
1472
1840
|
preWarmDoneAt.clear();
|
|
1473
|
-
|
|
1841
|
+
preConnectCache = { passphraseState: undefined };
|
|
1842
|
+
this.prePendingCallPromises.clear();
|
|
1843
|
+
this.removeAllListeners();
|
|
1474
1844
|
cleanupSdkInstance(this.sdkInstanceId);
|
|
1845
|
+
if (_core === this) _core = undefined;
|
|
1846
|
+
|
|
1847
|
+
// Transports, especially Node USB, may release native handles asynchronously.
|
|
1848
|
+
await transportCleanup;
|
|
1475
1849
|
}
|
|
1476
1850
|
}
|
|
1477
1851
|
|
|
1478
1852
|
export const initCore = () => {
|
|
1479
|
-
|
|
1480
|
-
|
|
1853
|
+
const core = new Core();
|
|
1854
|
+
_core = core;
|
|
1855
|
+
return core;
|
|
1481
1856
|
};
|
|
1482
1857
|
|
|
1483
1858
|
export const initConnector = () => {
|
|
1484
1859
|
_connector = new DeviceConnector();
|
|
1860
|
+
DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
1861
|
+
DevicePool.emitter.removeListener(DEVICE.DISCONNECT, onDeviceDisconnectHandler);
|
|
1862
|
+
DevicePool.emitter.removeListener(
|
|
1863
|
+
TRANSPORT_EVENT.DEVICE_DISCONNECT,
|
|
1864
|
+
onTransportDeviceDisconnectHandler
|
|
1865
|
+
);
|
|
1866
|
+
DevicePool.emitter.on(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
1485
1867
|
DevicePool.emitter.on(DEVICE.DISCONNECT, onDeviceDisconnectHandler);
|
|
1868
|
+
DevicePool.emitter.on(TRANSPORT_EVENT.DEVICE_DISCONNECT, onTransportDeviceDisconnectHandler);
|
|
1486
1869
|
return _connector;
|
|
1487
1870
|
};
|
|
1488
1871
|
|
|
@@ -1496,12 +1879,8 @@ export const init = async (
|
|
|
1496
1879
|
plugin?: LowlevelTransportSharedPlugin
|
|
1497
1880
|
) => {
|
|
1498
1881
|
try {
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
initTransport(Transport, plugin);
|
|
1502
|
-
} catch {
|
|
1503
|
-
Log.error('DataManager.load error');
|
|
1504
|
-
}
|
|
1882
|
+
await DataManager.load(settings);
|
|
1883
|
+
initTransport(Transport, plugin);
|
|
1505
1884
|
enableLog(DataManager.getSettings('debug'));
|
|
1506
1885
|
if (DataManager.getSettings('env') !== 'react-native') {
|
|
1507
1886
|
setLoggerPostMessage(postMessage);
|
|
@@ -1512,6 +1891,7 @@ export const init = async (
|
|
|
1512
1891
|
return _core;
|
|
1513
1892
|
} catch (error) {
|
|
1514
1893
|
Log.error('core init', error);
|
|
1894
|
+
throw error;
|
|
1515
1895
|
}
|
|
1516
1896
|
};
|
|
1517
1897
|
|