@onekeyfe/hd-core 1.2.0-alpha.15 → 1.2.0-alpha.151
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 +654 -0
- package/__tests__/DeviceEventRegistration.test.ts +17 -3
- 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 +335 -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 +162 -0
- package/__tests__/device-wallet-session-store.test.ts +474 -1
- package/__tests__/deviceFeaturesUtils.test.ts +39 -0
- 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 +12 -6
- package/__tests__/evmSignTransaction.test.ts +69 -0
- package/__tests__/evmSignTypedData.test.ts +80 -0
- package/__tests__/filesystemValidation.test.ts +53 -0
- package/__tests__/firmware-memory-host.test.ts +126 -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 +287 -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 +166 -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 +81 -0
- 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 +578 -0
- 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 +331 -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 +7405 -1680
- package/__tests__/protocolV2FileWrite.test.ts +221 -3
- package/__tests__/protocolV2UiInteraction.test.ts +329 -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 +191 -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 +14 -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 +60 -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/FirmwareMemoryHost.d.ts +22 -0
- package/dist/api/firmware/FirmwareMemoryHost.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 +72 -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 +11 -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 +9 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/kaspa/helpers/TransferSerialize.d.ts.map +1 -1
- package/dist/api/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 +4 -2
- 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 +84 -16
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +8 -6
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/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 +6 -2
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/device/DeviceStateMapper.d.ts +13 -0
- package/dist/device/DeviceStateMapper.d.ts.map +1 -0
- package/dist/device/DeviceStateProjector.d.ts +7 -0
- package/dist/device/DeviceStateProjector.d.ts.map +1 -0
- package/dist/device/DeviceStateStore.d.ts +21 -0
- package/dist/device/DeviceStateStore.d.ts.map +1 -0
- package/dist/device/DeviceWalletSessionStore.d.ts +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 +8 -2
- 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 +16 -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 +50 -4
- 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 +1763 -830
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11675 -4659
- 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 +33 -22
- 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 +16 -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 +42 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -0
- 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 +18 -4
- 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 +42 -4
- 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 -93
- 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 +139 -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 +45 -23
- 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 +2145 -749
- 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 +36 -12
- 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 +30 -4
- 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 +53 -45
- 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 +5 -0
- package/src/api/device/DeviceChangePin.ts +31 -0
- package/src/api/device/DeviceFullyUploadResource.ts +4 -5
- package/src/api/device/DeviceLock.ts +5 -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 +21 -3
- package/src/api/device/DeviceUpdateBootloader.ts +152 -8
- package/src/api/device/DeviceVerify.ts +25 -0
- package/src/api/device/DeviceWipe.ts +28 -0
- 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/FirmwareMemoryHost.ts +143 -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 +946 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +486 -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 +266 -42
- package/src/api/index.ts +6 -30
- package/src/api/kaspa/KaspaGetAddress.ts +7 -0
- package/src/api/kaspa/KaspaSignTransaction.ts +369 -29
- package/src/api/kaspa/helpers/TransferSerialize.ts +17 -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 -18
- package/src/api/protocol-v2/DeviceReboot.ts +12 -3
- package/src/api/protocol-v2/DeviceStatusGet.ts +6 -1
- package/src/api/protocol-v2/DeviceUploadNft.ts +249 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +59 -21
- 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 +7 -8
- package/src/core/index.ts +605 -198
- package/src/core/uiPromiseRegistry.ts +63 -0
- package/src/data/messages/messages-protocol-v2.json +523 -449
- package/src/data/messages/messages.json +286 -1
- package/src/data-manager/DataManager.ts +162 -44
- package/src/data-manager/TransportManager.ts +7 -1
- package/src/data-manager/connectSettings.ts +11 -0
- package/src/device/Device.ts +1019 -267
- package/src/device/DeviceCommands.ts +197 -161
- package/src/device/DeviceConnector.ts +54 -21
- package/src/device/DeviceFeaturesState.ts +25 -0
- package/src/device/DevicePool.ts +108 -23
- 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 +209 -191
- 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 +22 -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 +61 -4
- package/src/events/ui-response.ts +12 -2
- package/src/index.ts +13 -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 +118 -52
- package/src/protocols/protocol-v2/firmware.ts +3 -1
- package/src/protocols/protocol-v2/index.ts +9 -3
- package/src/protocols/protocol-v2/resources.ts +161 -0
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +65 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +250 -0
- 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 +417 -61
- 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 +60 -4
- package/src/types/api/openWalletSession.ts +54 -0
- package/src/types/api/protocolV2.ts +23 -188
- package/src/types/api/sessionCache.ts +9 -4
- package/src/types/device.ts +211 -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 +191 -0
- package/src/utils/deviceFeaturesUtils.ts +42 -9
- package/src/utils/deviceInfoUtils.ts +35 -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 +40 -0
- 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/DeviceSessionGet.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceSessionGet.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 -21
- 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 -9
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +0 -1
- package/dist/types/api/getDeviceInfo.d.ts +0 -87
- package/dist/types/api/getDeviceInfo.d.ts.map +0 -1
- package/src/api/GetDeviceInfo.ts +0 -145
- package/src/api/firmware/progressThrottle.ts +0 -44
- package/src/api/protocol-v2/DeviceSessionGet.ts +0 -15
- package/src/api/protocol-v2/DeviceSettingsGet.ts +0 -16
- package/src/api/protocol-v2/DeviceSettingsPageShow.ts +0 -59
- package/src/api/protocol-v2/DeviceSettingsSet.ts +0 -39
- package/src/deviceProfile/buildDeviceProfile.ts +0 -354
- package/src/protocols/protocol-v2/lockedError.ts +0 -10
- package/src/protocols/protocol-v2/unlockRetry.ts +0 -36
- package/src/types/api/getDeviceInfo.ts +0 -101
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,24 +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';
|
|
66
|
+
import {
|
|
67
|
+
ProtocolV2UiInteractionCoordinator,
|
|
68
|
+
isProtocolV2UiEnabled,
|
|
69
|
+
} from '../protocols/protocol-v2/uiInteraction';
|
|
70
|
+
import { createUiProgressMessageFilter } from '../utils/uiProgressThrottle';
|
|
61
71
|
|
|
62
72
|
import type { ConnectSettings, Features, KnownDevice } from '../types';
|
|
63
73
|
import type { CoreMessage, IFrameCallMessage, UiPromise, UiPromiseResponse } from '../events';
|
|
64
74
|
import type { DeviceEvents, InitOptions, RunOptions } from '../device/Device';
|
|
65
75
|
import type { SdkTracingContext } from '../utils/tracing';
|
|
66
76
|
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
67
|
-
import type {
|
|
77
|
+
import type {
|
|
78
|
+
LowlevelTransportSharedPlugin,
|
|
79
|
+
OneKeyDeviceInfo,
|
|
80
|
+
TransportDeviceDisconnectEvent,
|
|
81
|
+
} from '@onekeyfe/hd-transport';
|
|
68
82
|
import type { BaseMethod } from '../api/BaseMethod';
|
|
69
83
|
|
|
70
84
|
const Log = getLogger(LoggerNames.Core);
|
|
71
85
|
const PRE_INITIALIZE_TTL_MS = 60 * 1000;
|
|
86
|
+
const PRE_PENDING_CALL_TIMEOUT_MS = 15 * 1000;
|
|
72
87
|
|
|
73
88
|
// Dedup/coalesce state for "pre-warm signal" methods (isPreWarmSignal),
|
|
74
89
|
// keyed by getPreWarmKey(): coalesce in-flight, skip if warmed within TTL.
|
|
@@ -93,14 +108,15 @@ function hasDeriveCardano(method: BaseMethod): boolean {
|
|
|
93
108
|
|
|
94
109
|
const parseInitOptions = (method?: BaseMethod): InitOptions => ({
|
|
95
110
|
initSession: method?.payload.initSession,
|
|
96
|
-
passphraseState: method?.payload.passphraseState,
|
|
111
|
+
passphraseState: method?.payload.useEmptyPassphrase ? undefined : method?.payload.passphraseState,
|
|
97
112
|
deviceId: method?.payload.deviceId,
|
|
98
113
|
deriveCardano: method && hasDeriveCardano(method),
|
|
99
114
|
connectProtocol: method?.payload.connectProtocol,
|
|
115
|
+
forceProtocolDetection: method?.payload.forceProtocolDetection,
|
|
100
116
|
protocolV2DeviceInfoTimeoutMs: method?.payload.protocolV2DeviceInfoTimeoutMs,
|
|
101
117
|
});
|
|
102
118
|
|
|
103
|
-
let _core: Core;
|
|
119
|
+
let _core: Core | undefined;
|
|
104
120
|
let _deviceList: DeviceList | undefined;
|
|
105
121
|
let _connector: DeviceConnector | undefined;
|
|
106
122
|
let _uiPromises: UiPromise<UiPromiseResponse['type']>[] = []; // Waiting for ui response
|
|
@@ -125,6 +141,9 @@ const toError = (error: unknown): Error | undefined => {
|
|
|
125
141
|
}
|
|
126
142
|
};
|
|
127
143
|
|
|
144
|
+
const isExpectedCompatibilityError = (error: unknown) =>
|
|
145
|
+
error instanceof HardwareError && error.errorCode === HardwareErrorCode.DeviceNotSupportMethod;
|
|
146
|
+
|
|
128
147
|
const updateMethodRequestContext = (method: BaseMethod, updates: any) => {
|
|
129
148
|
if (method.requestContext) {
|
|
130
149
|
updateRequestContext(method.requestContext.responseID, updates);
|
|
@@ -144,11 +163,16 @@ export const callAPI = async (context: CoreContext, message: CoreMessage) => {
|
|
|
144
163
|
}
|
|
145
164
|
|
|
146
165
|
// find api method
|
|
147
|
-
let method
|
|
166
|
+
let method!: BaseMethod;
|
|
148
167
|
try {
|
|
149
168
|
method = findMethod(message as IFrameCallMessage);
|
|
150
169
|
method.connector = _connector;
|
|
151
|
-
|
|
170
|
+
const shouldPostMessage = createUiProgressMessageFilter();
|
|
171
|
+
method.postMessage = event => {
|
|
172
|
+
if (shouldPostMessage(event)) {
|
|
173
|
+
postMessage(event);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
152
176
|
method.setContext?.(context);
|
|
153
177
|
|
|
154
178
|
method.requestContext = createRequestContext(method.responseID, method.name, {
|
|
@@ -160,11 +184,13 @@ export const callAPI = async (context: CoreContext, message: CoreMessage) => {
|
|
|
160
184
|
|
|
161
185
|
method.init();
|
|
162
186
|
} catch (error) {
|
|
163
|
-
|
|
187
|
+
if (method) {
|
|
188
|
+
completeMethodRequestContext(method, error);
|
|
189
|
+
method.dispose();
|
|
190
|
+
}
|
|
191
|
+
return createResponseMessage(method?.responseID ?? message.id, false, { error });
|
|
164
192
|
}
|
|
165
193
|
|
|
166
|
-
DevicePool.emitter.on(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
167
|
-
|
|
168
194
|
if (!method.useDevice) {
|
|
169
195
|
updateMethodRequestContext(method, { status: 'running' });
|
|
170
196
|
try {
|
|
@@ -271,26 +297,35 @@ const handlePreWarmSignal = async (
|
|
|
271
297
|
}
|
|
272
298
|
};
|
|
273
299
|
|
|
274
|
-
const waitWithTimeout = async (promise: Promise<any>, timeout: number) => {
|
|
275
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
276
|
-
setTimeout(() => reject(new Error('Request timeout')), timeout);
|
|
277
|
-
});
|
|
278
|
-
return Promise.race([promise, timeoutPromise]);
|
|
279
|
-
};
|
|
280
|
-
|
|
281
300
|
const waitForPendingPromise = async (
|
|
282
|
-
|
|
283
|
-
|
|
301
|
+
connectId: string,
|
|
302
|
+
getPrePendingCallPromise: (connectId: string) => Promise<void> | undefined,
|
|
303
|
+
removePrePendingCallPromise?: (connectId: string, promise: Promise<void>) => void
|
|
284
304
|
) => {
|
|
285
|
-
const pendingPromise = getPrePendingCallPromise();
|
|
305
|
+
const pendingPromise = getPrePendingCallPromise(connectId);
|
|
286
306
|
if (pendingPromise) {
|
|
287
307
|
Log.debug('pre pending call promise before call method, wait for it');
|
|
308
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
309
|
+
let timedOut = false;
|
|
288
310
|
try {
|
|
289
|
-
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
|
+
]);
|
|
290
320
|
} catch (error) {
|
|
291
|
-
//
|
|
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 });
|
|
292
328
|
}
|
|
293
|
-
removePrePendingCallPromise?.(pendingPromise);
|
|
294
329
|
Log.debug('pre pending call promise before call method done');
|
|
295
330
|
}
|
|
296
331
|
};
|
|
@@ -302,7 +337,7 @@ const onCallDevice = async (
|
|
|
302
337
|
): Promise<any> => {
|
|
303
338
|
let messageResponse: any;
|
|
304
339
|
|
|
305
|
-
const { requestQueue, getPrePendingCallPromise,
|
|
340
|
+
const { requestQueue, getPrePendingCallPromise, removePrePendingCallPromise } = context;
|
|
306
341
|
|
|
307
342
|
updateMethodRequestContext(method, { status: 'running' });
|
|
308
343
|
|
|
@@ -330,7 +365,11 @@ const onCallDevice = async (
|
|
|
330
365
|
await context.waitForCallbackTasks(method.connectId);
|
|
331
366
|
}
|
|
332
367
|
|
|
333
|
-
await waitForPendingPromise(
|
|
368
|
+
await waitForPendingPromise(
|
|
369
|
+
method.connectId ?? '',
|
|
370
|
+
getPrePendingCallPromise,
|
|
371
|
+
removePrePendingCallPromise
|
|
372
|
+
);
|
|
334
373
|
|
|
335
374
|
const task = requestQueue.createTask(method);
|
|
336
375
|
|
|
@@ -359,7 +398,7 @@ const onCallDevice = async (
|
|
|
359
398
|
);
|
|
360
399
|
} catch (e) {
|
|
361
400
|
preWarmCallbackTask?.resolve();
|
|
362
|
-
|
|
401
|
+
Log.debug('ensureConnected error: ', e);
|
|
363
402
|
|
|
364
403
|
completeMethodRequestContext(method, e);
|
|
365
404
|
|
|
@@ -376,6 +415,10 @@ const onCallDevice = async (
|
|
|
376
415
|
if (method.payload?.onlyConnectBleDevice) {
|
|
377
416
|
preWarmCallbackTask?.resolve();
|
|
378
417
|
Log.debug('Call API - only connect ble device: ', device?.mainId);
|
|
418
|
+
// This early return bypasses the normal-path releaseTask 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
|
+
requestQueue.releaseTask(method.responseID);
|
|
379
422
|
return createResponseMessage(method.responseID, true, null);
|
|
380
423
|
}
|
|
381
424
|
|
|
@@ -398,17 +441,26 @@ const onCallDevice = async (
|
|
|
398
441
|
|
|
399
442
|
registerHardwareUiEventListeners(device, {
|
|
400
443
|
pin: onDevicePinHandler,
|
|
444
|
+
pinOnDevice: onEnterPinOnDeviceHandler,
|
|
445
|
+
pinOnDeviceComplete: onPinOnDeviceCompleteHandler,
|
|
401
446
|
button: onDeviceButtonHandler,
|
|
402
447
|
passphrase: message.payload.useEmptyPassphrase
|
|
403
448
|
? onEmptyPassphraseHandler
|
|
404
449
|
: onDevicePassphraseHandler,
|
|
405
450
|
passphraseOnDevice: onEnterPassphraseOnDeviceHandler,
|
|
451
|
+
attachPinOnDevice: onEnterAttachPinOnDeviceHandler,
|
|
406
452
|
});
|
|
407
453
|
device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
454
|
+
device.on(DEVICE.STATE, onDeviceStateHandler);
|
|
408
455
|
device.on(
|
|
409
456
|
DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE,
|
|
410
457
|
onSelectDeviceInBootloaderForWebDeviceHandler
|
|
411
458
|
);
|
|
459
|
+
|
|
460
|
+
const protocolV2UiCoordinator = new ProtocolV2UiInteractionCoordinator(device, postMessage);
|
|
461
|
+
let protocolV2Operation = false;
|
|
462
|
+
let protocolV2CloseEmitted = false;
|
|
463
|
+
device.beginProtocolV2UiInteraction();
|
|
412
464
|
device.on(
|
|
413
465
|
DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE,
|
|
414
466
|
onSelectDeviceForSwitchFirmwareWebDeviceHandler
|
|
@@ -420,14 +472,17 @@ const onCallDevice = async (
|
|
|
420
472
|
await context.waitForCallbackTasks(method.connectId, preWarmCallbackTask);
|
|
421
473
|
}
|
|
422
474
|
|
|
423
|
-
await waitForPendingPromise(
|
|
475
|
+
await waitForPendingPromise(
|
|
476
|
+
method.connectId ?? '',
|
|
477
|
+
getPrePendingCallPromise,
|
|
478
|
+
removePrePendingCallPromise
|
|
479
|
+
);
|
|
424
480
|
|
|
425
481
|
const inner = async (): Promise<void> => {
|
|
426
|
-
// Protocol
|
|
427
|
-
//
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
482
|
+
// Protocol is established from an active device response during acquire/initialize.
|
|
483
|
+
// Reject unsupported methods before any method-specific device command is sent.
|
|
484
|
+
method.assertProtocolSupported(device.getProtocol(), device.getCurrentFirmwareType());
|
|
485
|
+
protocolV2Operation = device.isProtocolV2();
|
|
431
486
|
|
|
432
487
|
// check firmware version
|
|
433
488
|
const versionRange = device.getCurrentMethodVersionRange(
|
|
@@ -438,8 +493,8 @@ const onCallDevice = async (
|
|
|
438
493
|
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
439
494
|
let newVersionStatus: ReturnType<typeof DataManager.getFirmwareStatus> | undefined;
|
|
440
495
|
|
|
441
|
-
//
|
|
442
|
-
// Pro2
|
|
496
|
+
// Defective-batch and forced-update gates depend on V1 features/remote config.
|
|
497
|
+
// Pro2 joins after DataManager supports its profile firmwareStatus.
|
|
443
498
|
if (device.features && !device.isProtocolV2()) {
|
|
444
499
|
await DataManager.checkAndReloadData();
|
|
445
500
|
|
|
@@ -487,10 +542,6 @@ const onCallDevice = async (
|
|
|
487
542
|
}
|
|
488
543
|
}
|
|
489
544
|
|
|
490
|
-
if (isMethodVersionRangeUnsupported(versionRange)) {
|
|
491
|
-
throw createDeviceNotSupportMethodError(method.name, deviceFirmwareType);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
545
|
if (versionRange) {
|
|
495
546
|
if (semver.valid(versionRange.min) && semver.lt(currentFirmwareVersion, versionRange.min)) {
|
|
496
547
|
if (newVersionStatus === 'none' || newVersionStatus === 'valid') {
|
|
@@ -541,89 +592,102 @@ const onCallDevice = async (
|
|
|
541
592
|
);
|
|
542
593
|
}
|
|
543
594
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
595
|
+
try {
|
|
596
|
+
let deviceIdCheckedDuringUnlockPreflight = false;
|
|
597
|
+
const response = await runMethodWithUnlockPolicy<object>(method, device, {
|
|
598
|
+
uiCoordinator: protocolV2UiCoordinator,
|
|
599
|
+
afterStatusBeforeUnlock: () => {
|
|
600
|
+
if (method.deviceId && method.checkDeviceId) {
|
|
601
|
+
if (!device.checkDeviceId(method.deviceId)) {
|
|
602
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
603
|
+
}
|
|
604
|
+
deviceIdCheckedDuringUnlockPreflight = true;
|
|
605
|
+
}
|
|
606
|
+
},
|
|
607
|
+
prepare: async () => {
|
|
608
|
+
if (method.deviceId && method.checkDeviceId && !deviceIdCheckedDuringUnlockPreflight) {
|
|
609
|
+
const isSameDeviceID = await checkLiveDeviceId(device, method.deviceId);
|
|
610
|
+
if (!isSameDeviceID) {
|
|
611
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
555
614
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
615
|
+
/**
|
|
616
|
+
* check firmware release info
|
|
617
|
+
*/
|
|
618
|
+
method.checkFirmwareRelease();
|
|
560
619
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
620
|
+
/**
|
|
621
|
+
* check additional supported feature
|
|
622
|
+
*/
|
|
623
|
+
method.checkDeviceSupportFeature();
|
|
565
624
|
|
|
566
|
-
|
|
567
|
-
|
|
625
|
+
// reconfigure messages
|
|
626
|
+
if (_deviceList && device.features && !device.isProtocolV2()) {
|
|
627
|
+
await TransportManager.reconfigure(device.features);
|
|
628
|
+
}
|
|
568
629
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
630
|
+
// Check to see if it is safe to use Passphrase
|
|
631
|
+
checkPassphraseEnableState(method, device.features);
|
|
632
|
+
|
|
633
|
+
if (shouldCheckPassphraseState(method, device)) {
|
|
634
|
+
// check version
|
|
635
|
+
const support = device.supportNewPassphrase();
|
|
636
|
+
if (!support.support) {
|
|
637
|
+
throw ERRORS.TypedError(
|
|
638
|
+
HardwareErrorCode.DeviceNotSupportPassphrase,
|
|
639
|
+
`Device not support passphrase, please update to ${support.require}`,
|
|
640
|
+
{
|
|
641
|
+
require: support.require,
|
|
642
|
+
}
|
|
643
|
+
);
|
|
579
644
|
}
|
|
580
|
-
)
|
|
581
|
-
);
|
|
582
|
-
}
|
|
583
645
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
646
|
+
// Check Device passphrase State after the Protocol V2 pre-unlock gate.
|
|
647
|
+
const passphraseStateSafety = await device.checkPassphraseStateSafety(
|
|
648
|
+
method.payload?.passphraseState,
|
|
649
|
+
method.payload?.useEmptyPassphrase,
|
|
650
|
+
method.payload?.skipPassphraseCheck,
|
|
651
|
+
hasDeriveCardano(method)
|
|
652
|
+
);
|
|
590
653
|
|
|
591
|
-
|
|
592
|
-
|
|
654
|
+
// Double check, handles the special case of Touch/Pro
|
|
655
|
+
checkPassphraseEnableState(method, device.features);
|
|
593
656
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
);
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
// close pin popup window
|
|
602
|
-
postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
|
|
603
|
-
}
|
|
657
|
+
if (!passphraseStateSafety) {
|
|
658
|
+
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
659
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
660
|
+
}
|
|
604
661
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
? e
|
|
612
|
-
: ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'open safety check failed.');
|
|
613
|
-
// messageResponse = createResponseMessage(method.responseID, false, { error });
|
|
614
|
-
// requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
615
|
-
// return;
|
|
616
|
-
throw error;
|
|
617
|
-
}
|
|
662
|
+
// Protocol V2 emits the PIN phase completion from DeviceSessionAskPin.
|
|
663
|
+
// Keep the legacy compatibility close for Protocol V1 only.
|
|
664
|
+
if (!device.isProtocolV2()) {
|
|
665
|
+
postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
|
|
666
|
+
}
|
|
667
|
+
}
|
|
618
668
|
|
|
619
|
-
|
|
669
|
+
// Automatic check safety_check level for Kovan, Ropsten, Rinkeby, Goerli test networks.
|
|
670
|
+
try {
|
|
671
|
+
await method.checkSafetyLevelOnTestNet();
|
|
672
|
+
} catch (e) {
|
|
673
|
+
throw e instanceof HardwareError
|
|
674
|
+
? e
|
|
675
|
+
: ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'open safety check failed.');
|
|
676
|
+
}
|
|
620
677
|
|
|
621
|
-
|
|
622
|
-
|
|
678
|
+
method.device?.commands?.checkDisposed();
|
|
679
|
+
},
|
|
680
|
+
});
|
|
623
681
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
624
682
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
625
683
|
completeMethodRequestContext(method);
|
|
626
684
|
} catch (error) {
|
|
685
|
+
// Device.run may release the request before transport callbacks finish after a timeout.
|
|
686
|
+
// Ignore the stale callback because the caller already received the connection error.
|
|
687
|
+
if (!requestQueue.getTask(method.responseID)) {
|
|
688
|
+
Log.debug(`Call API - Ignore late inner method result`, error);
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
627
691
|
Log.debug(`Call API - Inner Method Run Error`, error);
|
|
628
692
|
messageResponse = createResponseMessage(method.responseID, false, { error });
|
|
629
693
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
@@ -636,6 +700,13 @@ const onCallDevice = async (
|
|
|
636
700
|
) {
|
|
637
701
|
throw error;
|
|
638
702
|
}
|
|
703
|
+
} finally {
|
|
704
|
+
if (isProtocolV2UiEnabled(method)) {
|
|
705
|
+
protocolV2CloseEmitted = protocolV2UiCoordinator.close({
|
|
706
|
+
ensureOperationClose: protocolV2Operation,
|
|
707
|
+
protocolV2Operation,
|
|
708
|
+
});
|
|
709
|
+
}
|
|
639
710
|
}
|
|
640
711
|
};
|
|
641
712
|
Log.debug('Call API - Device Run: ', device.mainId);
|
|
@@ -651,7 +722,9 @@ const onCallDevice = async (
|
|
|
651
722
|
try {
|
|
652
723
|
return await task.callPromise.promise;
|
|
653
724
|
} catch (e) {
|
|
654
|
-
|
|
725
|
+
if (!isExpectedCompatibilityError(e)) {
|
|
726
|
+
Log.debug('Device Run Error: ', e);
|
|
727
|
+
}
|
|
655
728
|
completeMethodRequestContext(method, e);
|
|
656
729
|
return createResponseMessage(method.responseID, false, { error: e });
|
|
657
730
|
}
|
|
@@ -689,7 +762,17 @@ const onCallDevice = async (
|
|
|
689
762
|
|
|
690
763
|
requestQueue.releaseTask(method.responseID);
|
|
691
764
|
|
|
692
|
-
|
|
765
|
+
if (isProtocolV2UiEnabled(method)) {
|
|
766
|
+
if (!protocolV2CloseEmitted && protocolV2Operation) {
|
|
767
|
+
protocolV2CloseEmitted = protocolV2UiCoordinator.close({
|
|
768
|
+
ensureOperationClose: true,
|
|
769
|
+
protocolV2Operation: true,
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
if (!protocolV2CloseEmitted) {
|
|
773
|
+
closePopup();
|
|
774
|
+
}
|
|
775
|
+
}
|
|
693
776
|
|
|
694
777
|
cleanup();
|
|
695
778
|
|
|
@@ -835,24 +918,155 @@ function canSkipInitialize(method: BaseMethod, device: Device): boolean {
|
|
|
835
918
|
return true;
|
|
836
919
|
}
|
|
837
920
|
|
|
838
|
-
function isRetryableBleProtocolV2ProbeError(method: BaseMethod, error: unknown) {
|
|
839
|
-
const
|
|
921
|
+
export function isRetryableBleProtocolV2ProbeError(method: BaseMethod, error: unknown) {
|
|
922
|
+
const typedError = error as { errorCode?: unknown; message?: unknown };
|
|
923
|
+
const message =
|
|
924
|
+
typeof typedError?.message === 'string' ? typedError.message : String(error ?? '');
|
|
840
925
|
return (
|
|
841
926
|
method.payload.connectProtocol === 'V2' &&
|
|
927
|
+
typedError?.errorCode === HardwareErrorCode.RuntimeError &&
|
|
842
928
|
message.includes('Device protocol mismatch') &&
|
|
843
929
|
message.includes('expected V2') &&
|
|
844
930
|
message.includes('did not respond to expected protocol')
|
|
845
931
|
);
|
|
846
932
|
}
|
|
847
933
|
|
|
934
|
+
export function isRetryableBleConnectionError(method: BaseMethod, error: unknown) {
|
|
935
|
+
if (method.device?.wasInterruptedByUser()) {
|
|
936
|
+
return false;
|
|
937
|
+
}
|
|
938
|
+
const typedError = error as { errorCode?: unknown };
|
|
939
|
+
return (
|
|
940
|
+
typedError?.errorCode === HardwareErrorCode.BleTimeoutError ||
|
|
941
|
+
typedError?.errorCode === HardwareErrorCode.BleConnectedError ||
|
|
942
|
+
isRetryableBleProtocolV2ProbeError(method, error) ||
|
|
943
|
+
isMissingDetectedProtocolV2Error(method, error)
|
|
944
|
+
);
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
export function isMissingDetectedProtocolV2Error(method: BaseMethod, error: unknown) {
|
|
948
|
+
const typedError = error as { errorCode?: unknown; message?: unknown };
|
|
949
|
+
return (
|
|
950
|
+
method.payload.connectProtocol === 'V2' &&
|
|
951
|
+
typedError?.errorCode === HardwareErrorCode.RuntimeError &&
|
|
952
|
+
typeof typedError.message === 'string' &&
|
|
953
|
+
typedError.message.includes('Device protocol has not been detected')
|
|
954
|
+
);
|
|
955
|
+
}
|
|
956
|
+
|
|
848
957
|
/**
|
|
849
958
|
* If the Bluetooth connection times out, retry up to 6 times
|
|
850
959
|
* @param retryCount - Current retry count (default 0)
|
|
851
960
|
*/
|
|
852
|
-
|
|
961
|
+
// device.acquire awaits a transport reply with no deadline of its own; a
|
|
962
|
+
// transport that never settles (field case: Electron main lost an IPC reply,
|
|
963
|
+
// "reply was never sent" after 5 minutes) hangs the call forever and cancel()
|
|
964
|
+
// only takes effect at poll checkpoints. Race acquire against a deadline and
|
|
965
|
+
// the caller's abort signal so the hang is bounded and cancel is immediate.
|
|
966
|
+
const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
|
|
967
|
+
|
|
968
|
+
function raceBleAcquire<T>(acquirePromise: Promise<T>, abortSignal?: AbortSignal): Promise<T> {
|
|
969
|
+
return new Promise<T>((resolve, reject) => {
|
|
970
|
+
let settled = false;
|
|
971
|
+
const settle = (fn: () => void) => {
|
|
972
|
+
if (settled) return;
|
|
973
|
+
settled = true;
|
|
974
|
+
clearTimeout(deadline);
|
|
975
|
+
abortSignal?.removeEventListener('abort', onAbort);
|
|
976
|
+
fn();
|
|
977
|
+
};
|
|
978
|
+
const onAbort = () =>
|
|
979
|
+
settle(() => reject(ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled)));
|
|
980
|
+
const deadline = setTimeout(
|
|
981
|
+
() =>
|
|
982
|
+
settle(() =>
|
|
983
|
+
reject(
|
|
984
|
+
ERRORS.TypedError(
|
|
985
|
+
HardwareErrorCode.BleTimeoutError,
|
|
986
|
+
`BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`
|
|
987
|
+
)
|
|
988
|
+
)
|
|
989
|
+
),
|
|
990
|
+
BLE_ACQUIRE_DEADLINE_MS
|
|
991
|
+
);
|
|
992
|
+
// Attach before any early return so a late settlement of acquirePromise
|
|
993
|
+
// is always consumed — an abort or deadline must never leave the acquire
|
|
994
|
+
// rejection unhandled.
|
|
995
|
+
acquirePromise.then(
|
|
996
|
+
value => settle(() => resolve(value)),
|
|
997
|
+
error => settle(() => reject(error))
|
|
998
|
+
);
|
|
999
|
+
if (abortSignal) {
|
|
1000
|
+
if (abortSignal.aborted) {
|
|
1001
|
+
onAbort();
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
abortSignal.addEventListener('abort', onAbort);
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
async function connectDeviceForBle(
|
|
1010
|
+
method: BaseMethod,
|
|
1011
|
+
device: Device,
|
|
1012
|
+
abortSignal?: AbortSignal,
|
|
1013
|
+
retryCount = 0
|
|
1014
|
+
) {
|
|
853
1015
|
try {
|
|
854
|
-
|
|
1016
|
+
if (device.wasInterruptedByUser()) {
|
|
1017
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceInterruptedFromUser);
|
|
1018
|
+
}
|
|
1019
|
+
if (method.payload.forceProtocolDetection && device.hasDeviceAcquire()) {
|
|
1020
|
+
await device.release();
|
|
1021
|
+
}
|
|
1022
|
+
const shouldAcquire =
|
|
1023
|
+
method.payload.forceProtocolDetection ||
|
|
1024
|
+
!device.hasDeviceAcquire() ||
|
|
1025
|
+
!device.commands ||
|
|
1026
|
+
device.commands.disposed;
|
|
1027
|
+
if (shouldAcquire) {
|
|
1028
|
+
// The deadline/abort guards are scoped to the desktop electron
|
|
1029
|
+
// transport: its IPC acquire is the only path with a proven
|
|
1030
|
+
// never-settling failure mode, while react-native/lowlevel acquire may
|
|
1031
|
+
// legitimately block on a user-driven system bonding prompt for longer
|
|
1032
|
+
// than any sane deadline. Other envs keep the plain acquire unchanged.
|
|
1033
|
+
const useAcquireGuards = DataManager.getSettings('env') === 'desktop-web-ble';
|
|
1034
|
+
// A cancel landing during the retry backoff must not start a new acquire.
|
|
1035
|
+
if (useAcquireGuards && abortSignal?.aborted) {
|
|
1036
|
+
throw ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled);
|
|
1037
|
+
}
|
|
1038
|
+
if (!useAcquireGuards) {
|
|
1039
|
+
await device.acquire(method.payload.connectProtocol, {
|
|
1040
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
1041
|
+
});
|
|
1042
|
+
} else {
|
|
1043
|
+
try {
|
|
1044
|
+
await raceBleAcquire(
|
|
1045
|
+
device.acquire(method.payload.connectProtocol, {
|
|
1046
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
1047
|
+
}),
|
|
1048
|
+
abortSignal
|
|
1049
|
+
);
|
|
1050
|
+
} catch (err) {
|
|
1051
|
+
// A deadline hit means the transport is wedged mid-acquire; drop the
|
|
1052
|
+
// link before the retry so it cold-connects instead of stacking a
|
|
1053
|
+
// second connect onto the half-open one.
|
|
1054
|
+
if (
|
|
1055
|
+
err.errorCode === HardwareErrorCode.BleTimeoutError &&
|
|
1056
|
+
device.mainId &&
|
|
1057
|
+
device.deviceConnector
|
|
1058
|
+
) {
|
|
1059
|
+
await device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
|
|
1060
|
+
device.markTransportDisconnected();
|
|
1061
|
+
}
|
|
1062
|
+
throw err;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
855
1066
|
if (method.payload?.onlyConnectBleDevice) {
|
|
1067
|
+
if (shouldAcquire) {
|
|
1068
|
+
DevicePool.emitter.emit(DEVICE.CONNECT, device);
|
|
1069
|
+
}
|
|
856
1070
|
return;
|
|
857
1071
|
}
|
|
858
1072
|
// Skip initialize if conditions are met
|
|
@@ -863,17 +1077,31 @@ async function connectDeviceForBle(method: BaseMethod, device: Device, retryCoun
|
|
|
863
1077
|
passphraseState: initOptions.passphraseState,
|
|
864
1078
|
});
|
|
865
1079
|
}
|
|
1080
|
+
if (shouldAcquire) {
|
|
1081
|
+
DevicePool.emitter.emit(DEVICE.CONNECT, device);
|
|
1082
|
+
}
|
|
866
1083
|
} catch (err) {
|
|
1084
|
+
const requiresColdReconnect = isMissingDetectedProtocolV2Error(method, err);
|
|
1085
|
+
// Device.run()'s REQUIRE_DISCONNECT handling never sees acquire/initialize
|
|
1086
|
+
// failures, so with keep-alive a wedged link would be reused by every retry
|
|
1087
|
+
// (field case: Initialize timing out at 25s per attempt, forever). Drop it
|
|
1088
|
+
// here so the next retry cold-connects.
|
|
867
1089
|
if (
|
|
868
|
-
(err.errorCode
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
retryCount < 6
|
|
1090
|
+
(ERROR_CODES_REQUIRE_DISCONNECT.includes(err.errorCode) || requiresColdReconnect) &&
|
|
1091
|
+
device.mainId &&
|
|
1092
|
+
device.deviceConnector
|
|
872
1093
|
) {
|
|
1094
|
+
await device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
|
|
1095
|
+
// The connector only drops the link; `deviceAcquired` is reset by
|
|
1096
|
+
// release()/markTransportDisconnected() alone. Leaving it set makes the
|
|
1097
|
+
// next attempt skip acquire and initialize onto the link we just cut.
|
|
1098
|
+
device.markTransportDisconnected();
|
|
1099
|
+
}
|
|
1100
|
+
if (isRetryableBleConnectionError(method, err) && retryCount < 6) {
|
|
873
1101
|
const nextRetry = retryCount + 1;
|
|
874
|
-
Log.debug(`Bluetooth
|
|
1102
|
+
Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
|
|
875
1103
|
await wait(3000);
|
|
876
|
-
await connectDeviceForBle(method, device, nextRetry);
|
|
1104
|
+
await connectDeviceForBle(method, device, abortSignal, nextRetry);
|
|
877
1105
|
} else {
|
|
878
1106
|
throw err;
|
|
879
1107
|
}
|
|
@@ -978,13 +1206,31 @@ const ensureConnected = async (
|
|
|
978
1206
|
if (abort()) {
|
|
979
1207
|
return;
|
|
980
1208
|
}
|
|
981
|
-
|
|
1209
|
+
// One generation per public ensureConnected() call, not per poll
|
|
1210
|
+
// iteration. A later poll must not clear a user cancel.
|
|
1211
|
+
if (tryCount === 1) {
|
|
1212
|
+
device.beginConnectionAttempt();
|
|
1213
|
+
}
|
|
1214
|
+
await connectDeviceForBle(method, device, abortSignal);
|
|
982
1215
|
}
|
|
983
1216
|
resolve(device);
|
|
984
1217
|
return;
|
|
985
1218
|
}
|
|
986
1219
|
} catch (error) {
|
|
987
1220
|
Log.debug('device error: ', error);
|
|
1221
|
+
if (error.errorCode === HardwareErrorCode.BleUnavailableWhileUsbConnected) {
|
|
1222
|
+
reject(error);
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
if (isProtocolV2LinkDisabledError(error)) {
|
|
1226
|
+
reject(
|
|
1227
|
+
ERRORS.TypedError(HardwareErrorCode.BleUnavailableWhileUsbConnected, undefined, {
|
|
1228
|
+
failureCode: error.failureCode,
|
|
1229
|
+
firmwareMessage: error.firmwareMessage,
|
|
1230
|
+
})
|
|
1231
|
+
);
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
988
1234
|
if ([HardwareErrorCode.BleCharacteristicNotifyChangeFailure].includes(error.errorCode)) {
|
|
989
1235
|
postMessage(createUiMessage(UI_REQUEST.BLUETOOTH_CHARACTERISTIC_NOTIFY_CHANGE_FAILURE));
|
|
990
1236
|
}
|
|
@@ -1007,6 +1253,8 @@ const ensureConnected = async (
|
|
|
1007
1253
|
HardwareErrorCode.DeviceDetectInBootloaderMode,
|
|
1008
1254
|
HardwareErrorCode.BleCharacteristicNotifyChangeFailure,
|
|
1009
1255
|
HardwareErrorCode.BridgeNeedsPermission,
|
|
1256
|
+
HardwareErrorCode.DeviceInterruptedFromUser,
|
|
1257
|
+
HardwareErrorCode.CallQueueActionCancelled,
|
|
1010
1258
|
].includes(error.errorCode)
|
|
1011
1259
|
) {
|
|
1012
1260
|
reject(error);
|
|
@@ -1064,22 +1312,31 @@ export const cancel = (context: CoreContext, connectId?: string) => {
|
|
|
1064
1312
|
)}`
|
|
1065
1313
|
);
|
|
1066
1314
|
const canceledDevices: Device[] = [];
|
|
1315
|
+
const interruptDevice = (device: Device | undefined, deviceConnectId: string) => {
|
|
1316
|
+
if (!device || canceledDevices.includes(device)) {
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
setPrePendingCallPromise(deviceConnectId, device.interruptionFromUser());
|
|
1320
|
+
canceledDevices.push(device);
|
|
1321
|
+
};
|
|
1067
1322
|
for (const requestId of requestIds) {
|
|
1068
1323
|
const task = requestQueue.getTask(requestId);
|
|
1069
1324
|
Log.debug('Cancel Api connect task: ', task);
|
|
1070
|
-
if (task
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1325
|
+
if (task) {
|
|
1326
|
+
// During ensureConnected the method has a connectId but device is
|
|
1327
|
+
// assigned only after the poll succeeds. Interrupt the cached BLE
|
|
1328
|
+
// Device so an in-flight acquire/initialize cannot finish.
|
|
1329
|
+
interruptDevice(task.method?.device, task.method.connectId ?? connectId);
|
|
1330
|
+
interruptDevice(deviceCacheMap.get(connectId), connectId);
|
|
1076
1331
|
requestQueue.rejectRequest(
|
|
1077
1332
|
requestId,
|
|
1078
1333
|
ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled)
|
|
1079
1334
|
);
|
|
1080
1335
|
}
|
|
1081
1336
|
}
|
|
1337
|
+
interruptDevice(deviceCacheMap.get(connectId), connectId);
|
|
1082
1338
|
requestQueue.abortRequestsByConnectId(connectId);
|
|
1339
|
+
pollingManager.stop(connectId);
|
|
1083
1340
|
} catch (e) {
|
|
1084
1341
|
Log.error('Cancel API Error: ', e);
|
|
1085
1342
|
}
|
|
@@ -1088,22 +1345,31 @@ export const cancel = (context: CoreContext, connectId?: string) => {
|
|
|
1088
1345
|
if (DataManager.isBleConnect(env)) {
|
|
1089
1346
|
Log.debug('Cancel Api all _deviceList: ');
|
|
1090
1347
|
const canceledDevices: Device[] = [];
|
|
1348
|
+
const interruptDevice = (device?: Device) => {
|
|
1349
|
+
if (!device || canceledDevices.includes(device)) {
|
|
1350
|
+
return;
|
|
1351
|
+
}
|
|
1352
|
+
device.interruptionFromUser().catch(() => undefined);
|
|
1353
|
+
canceledDevices.push(device);
|
|
1354
|
+
};
|
|
1091
1355
|
for (const requestId of requestQueue.getRequestTasksId()) {
|
|
1092
1356
|
const task = requestQueue.getTask(requestId);
|
|
1093
1357
|
Log.debug('Cancel Api connect task: ', task);
|
|
1094
|
-
if (task
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1358
|
+
if (task) {
|
|
1359
|
+
interruptDevice(task.method?.device);
|
|
1360
|
+
if (task.method.connectId) {
|
|
1361
|
+
interruptDevice(deviceCacheMap.get(task.method.connectId));
|
|
1362
|
+
pollingManager.stop(task.method.connectId);
|
|
1099
1363
|
}
|
|
1100
|
-
|
|
1101
1364
|
requestQueue.rejectRequest(
|
|
1102
1365
|
requestId,
|
|
1103
1366
|
ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled)
|
|
1104
1367
|
);
|
|
1105
1368
|
}
|
|
1106
1369
|
}
|
|
1370
|
+
deviceCacheMap.forEach(interruptDevice);
|
|
1371
|
+
requestQueue.abortAllRequests();
|
|
1372
|
+
pollingManager.stopAll();
|
|
1107
1373
|
} else {
|
|
1108
1374
|
_deviceList?.allDevices().forEach(device => {
|
|
1109
1375
|
Log.debug('device: ', device, ' device.hasDeviceAcquire: ', device.hasDeviceAcquire());
|
|
@@ -1157,14 +1423,16 @@ const shouldCheckPassphraseState = (method: BaseMethod, device: Device) => {
|
|
|
1157
1423
|
};
|
|
1158
1424
|
|
|
1159
1425
|
const cleanup = () => {
|
|
1426
|
+
const pendingUiPromises = _uiPromises;
|
|
1160
1427
|
_uiPromises = [];
|
|
1161
|
-
|
|
1428
|
+
rejectUiPromises(
|
|
1429
|
+
pendingUiPromises,
|
|
1430
|
+
ERRORS.TypedError(HardwareErrorCode.ActionCancelled, 'UI request was cancelled')
|
|
1431
|
+
);
|
|
1162
1432
|
};
|
|
1163
1433
|
|
|
1164
1434
|
const removeDeviceListener = (device: Device) => {
|
|
1165
1435
|
device.removeAllListeners();
|
|
1166
|
-
DevicePool.emitter.removeAllListeners(DEVICE.CONNECT);
|
|
1167
|
-
// DevicePool.emitter.removeListener(DEVICE.DISCONNECT, onDeviceDisconnectHandler);
|
|
1168
1436
|
};
|
|
1169
1437
|
|
|
1170
1438
|
/**
|
|
@@ -1175,19 +1443,33 @@ const closePopup = () => {
|
|
|
1175
1443
|
};
|
|
1176
1444
|
|
|
1177
1445
|
const onDeviceConnectHandler = (device: Device) => {
|
|
1178
|
-
const
|
|
1179
|
-
|
|
1180
|
-
postMessage(createDeviceMessage(DEVICE.CONNECT, { device: deviceObject
|
|
1446
|
+
const deviceObject = device.toMessageObject();
|
|
1447
|
+
if (!deviceObject) return;
|
|
1448
|
+
postMessage(createDeviceMessage(DEVICE.CONNECT, { device: deviceObject }));
|
|
1181
1449
|
};
|
|
1182
1450
|
|
|
1183
1451
|
const onDeviceDisconnectHandler = (device: Device) => {
|
|
1184
1452
|
device.clearPreInitialized();
|
|
1185
|
-
const
|
|
1186
|
-
|
|
1187
|
-
postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject
|
|
1453
|
+
const deviceObject = device.toMessageObject();
|
|
1454
|
+
if (!deviceObject) return;
|
|
1455
|
+
postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject }));
|
|
1456
|
+
};
|
|
1457
|
+
|
|
1458
|
+
const onTransportDeviceDisconnectHandler = (event: TransportDeviceDisconnectEvent) => {
|
|
1459
|
+
const device =
|
|
1460
|
+
deviceCacheMap.get(event.connectId) ??
|
|
1461
|
+
DevicePool.devicesCache[event.connectId] ??
|
|
1462
|
+
DevicePool.getDeviceByPath(event.connectId);
|
|
1463
|
+
if (!device) {
|
|
1464
|
+
Log.debug('Ignoring transport disconnect for an unknown device:', event.connectId);
|
|
1465
|
+
return;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
device.markTransportDisconnected();
|
|
1469
|
+
DevicePool.emitter.emit(DEVICE.DISCONNECT, device);
|
|
1188
1470
|
};
|
|
1189
1471
|
|
|
1190
|
-
const onDevicePinHandler =
|
|
1472
|
+
const onDevicePinHandler = (...[device, type, callback]: DeviceEvents['pin']) => {
|
|
1191
1473
|
Log.log('request Input PIN');
|
|
1192
1474
|
// create ui promise
|
|
1193
1475
|
const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PIN, device);
|
|
@@ -1196,12 +1478,14 @@ const onDevicePinHandler = async (...[device, type, callback]: DeviceEvents['pin
|
|
|
1196
1478
|
createUiMessage(UI_REQUEST.REQUEST_PIN, {
|
|
1197
1479
|
device: device.toMessageObject() as unknown as KnownDevice,
|
|
1198
1480
|
type,
|
|
1481
|
+
responseCorrelation: uiPromise.responseCorrelation,
|
|
1199
1482
|
})
|
|
1200
1483
|
);
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1484
|
+
consumeUiPromise(
|
|
1485
|
+
uiPromise.promise,
|
|
1486
|
+
uiResp => callback(null, uiResp.payload),
|
|
1487
|
+
error => callback(error, '')
|
|
1488
|
+
);
|
|
1205
1489
|
};
|
|
1206
1490
|
|
|
1207
1491
|
export const onDeviceButtonHandler = (...[device, request]: [...DeviceEvents['button']]) => {
|
|
@@ -1225,7 +1509,11 @@ const onDeviceFeaturesHandler = (...[_, features]: [...DeviceEvents['features']]
|
|
|
1225
1509
|
postMessage(createDeviceMessage(DEVICE.FEATURES, { ...features }));
|
|
1226
1510
|
};
|
|
1227
1511
|
|
|
1228
|
-
const
|
|
1512
|
+
const onDeviceStateHandler = (...[_, stateEvent]: [...DeviceEvents['state']]) => {
|
|
1513
|
+
postMessage(createDeviceMessage(DEVICE.STATE, stateEvent));
|
|
1514
|
+
};
|
|
1515
|
+
|
|
1516
|
+
const onDevicePassphraseHandler = (
|
|
1229
1517
|
...[device, requestPayload, callback]: DeviceEvents['passphrase']
|
|
1230
1518
|
) => {
|
|
1231
1519
|
Log.debug('onDevicePassphraseHandler');
|
|
@@ -1235,18 +1523,27 @@ const onDevicePassphraseHandler = async (
|
|
|
1235
1523
|
device: device.toMessageObject() as KnownDevice,
|
|
1236
1524
|
passphraseState: device.passphraseState,
|
|
1237
1525
|
existsAttachPinUser: requestPayload.existsAttachPinUser,
|
|
1526
|
+
deviceOnly: requestPayload.deviceOnly,
|
|
1527
|
+
source: requestPayload.source,
|
|
1528
|
+
reason: requestPayload.reason,
|
|
1529
|
+
expectedPassphraseState: requestPayload.expectedPassphraseState,
|
|
1530
|
+
...(requestPayload.interaction ? { interaction: requestPayload.interaction } : {}),
|
|
1531
|
+
responseCorrelation: uiPromise.responseCorrelation,
|
|
1238
1532
|
})
|
|
1239
1533
|
);
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1534
|
+
consumeUiPromise(
|
|
1535
|
+
uiPromise.promise,
|
|
1536
|
+
uiResp => {
|
|
1537
|
+
const { value, passphraseOnDevice, save, attachPinOnDevice } = uiResp.payload;
|
|
1538
|
+
callback({
|
|
1539
|
+
passphrase: value.normalize('NFKD'),
|
|
1540
|
+
passphraseOnDevice,
|
|
1541
|
+
attachPinOnDevice,
|
|
1542
|
+
cache: save,
|
|
1543
|
+
});
|
|
1544
|
+
},
|
|
1545
|
+
error => callback({}, error)
|
|
1546
|
+
);
|
|
1250
1547
|
};
|
|
1251
1548
|
|
|
1252
1549
|
const onEmptyPassphraseHandler = (...[_, , callback]: DeviceEvents['passphrase']) => {
|
|
@@ -1256,17 +1553,62 @@ const onEmptyPassphraseHandler = (...[_, , callback]: DeviceEvents['passphrase']
|
|
|
1256
1553
|
};
|
|
1257
1554
|
|
|
1258
1555
|
const onEnterPassphraseOnDeviceHandler = (
|
|
1259
|
-
...[device]: [...DeviceEvents['passphrase_on_device']]
|
|
1556
|
+
...[device, requestPayload]: [...DeviceEvents['passphrase_on_device']]
|
|
1260
1557
|
) => {
|
|
1261
1558
|
postMessage(
|
|
1262
1559
|
createUiMessage(UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE, {
|
|
1263
1560
|
device: device.toMessageObject() as KnownDevice,
|
|
1264
1561
|
passphraseState: device.passphraseState,
|
|
1562
|
+
source: requestPayload?.source,
|
|
1563
|
+
reason: requestPayload?.reason,
|
|
1564
|
+
...(requestPayload?.interaction ? { interaction: requestPayload.interaction } : {}),
|
|
1265
1565
|
})
|
|
1266
1566
|
);
|
|
1267
1567
|
};
|
|
1268
1568
|
|
|
1269
|
-
const
|
|
1569
|
+
const onEnterAttachPinOnDeviceHandler = (
|
|
1570
|
+
...[device, requestPayload]: [...DeviceEvents['attach_pin_on_device']]
|
|
1571
|
+
) => {
|
|
1572
|
+
postMessage(
|
|
1573
|
+
createUiMessage(UI_REQUEST.REQUEST_PIN, {
|
|
1574
|
+
device: device.toMessageObject() as KnownDevice,
|
|
1575
|
+
type: 'ButtonRequest_AttachPin',
|
|
1576
|
+
source: requestPayload?.source,
|
|
1577
|
+
reason: requestPayload?.reason,
|
|
1578
|
+
...(requestPayload?.interaction ? { interaction: requestPayload.interaction } : {}),
|
|
1579
|
+
})
|
|
1580
|
+
);
|
|
1581
|
+
};
|
|
1582
|
+
|
|
1583
|
+
const onEnterPinOnDeviceHandler = (
|
|
1584
|
+
...[device, pinType, metadata]: [...DeviceEvents['pin_on_device']]
|
|
1585
|
+
) => {
|
|
1586
|
+
postMessage(
|
|
1587
|
+
createUiMessage(UI_REQUEST.REQUEST_PIN, {
|
|
1588
|
+
device: device.toMessageObject() as KnownDevice,
|
|
1589
|
+
type:
|
|
1590
|
+
pinType === DeviceSessionPinType.AttachToPin
|
|
1591
|
+
? 'ButtonRequest_AttachPin'
|
|
1592
|
+
: 'ButtonRequest_PinEntry',
|
|
1593
|
+
source: metadata?.source,
|
|
1594
|
+
reason: metadata?.reason,
|
|
1595
|
+
deviceOnly: metadata?.deviceOnly ?? true,
|
|
1596
|
+
completion: metadata?.completion,
|
|
1597
|
+
method: metadata?.method,
|
|
1598
|
+
page: metadata?.page,
|
|
1599
|
+
operation: metadata?.operation,
|
|
1600
|
+
...(metadata?.interaction ? { interaction: metadata.interaction } : {}),
|
|
1601
|
+
})
|
|
1602
|
+
);
|
|
1603
|
+
};
|
|
1604
|
+
|
|
1605
|
+
const onPinOnDeviceCompleteHandler = (
|
|
1606
|
+
...[_, metadata]: [...DeviceEvents['pin_on_device_complete']]
|
|
1607
|
+
) => {
|
|
1608
|
+
postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW, metadata));
|
|
1609
|
+
};
|
|
1610
|
+
|
|
1611
|
+
const onSelectDeviceInBootloaderForWebDeviceHandler = (
|
|
1270
1612
|
...[device, callback]: [...DeviceEvents['select_device_in_bootloader_for_web_device']]
|
|
1271
1613
|
) => {
|
|
1272
1614
|
Log.debug('onSelectDeviceInBootloaderForWebDeviceHandler');
|
|
@@ -1276,11 +1618,14 @@ const onSelectDeviceInBootloaderForWebDeviceHandler = async (
|
|
|
1276
1618
|
device: device.toMessageObject() as KnownDevice,
|
|
1277
1619
|
})
|
|
1278
1620
|
);
|
|
1279
|
-
|
|
1280
|
-
|
|
1621
|
+
consumeUiPromise(
|
|
1622
|
+
uiPromise.promise,
|
|
1623
|
+
uiResp => callback(null, uiResp.payload.deviceId),
|
|
1624
|
+
error => callback(error, '')
|
|
1625
|
+
);
|
|
1281
1626
|
};
|
|
1282
1627
|
|
|
1283
|
-
const onSelectDeviceForSwitchFirmwareWebDeviceHandler =
|
|
1628
|
+
const onSelectDeviceForSwitchFirmwareWebDeviceHandler = (
|
|
1284
1629
|
...[device, callback]: [...DeviceEvents['select_device_for_switch_firmware_web_device']]
|
|
1285
1630
|
) => {
|
|
1286
1631
|
Log.debug('onSelectDeviceForSwitchFirmwareWebDeviceHandler');
|
|
@@ -1293,8 +1638,11 @@ const onSelectDeviceForSwitchFirmwareWebDeviceHandler = async (
|
|
|
1293
1638
|
device: device.toMessageObject() as KnownDevice,
|
|
1294
1639
|
})
|
|
1295
1640
|
);
|
|
1296
|
-
|
|
1297
|
-
|
|
1641
|
+
consumeUiPromise(
|
|
1642
|
+
uiPromise.promise,
|
|
1643
|
+
uiResp => callback(null, uiResp.payload.deviceId),
|
|
1644
|
+
error => callback(error, '')
|
|
1645
|
+
);
|
|
1298
1646
|
};
|
|
1299
1647
|
|
|
1300
1648
|
/**
|
|
@@ -1313,14 +1661,21 @@ const postMessage = (message: CoreMessage) => {
|
|
|
1313
1661
|
|
|
1314
1662
|
const createUiPromise = <T extends UiPromiseResponse['type']>(promiseEvent: T, device?: Device) => {
|
|
1315
1663
|
const uiPromise: UiPromise<T> = createDeferred(promiseEvent, device);
|
|
1664
|
+
if (
|
|
1665
|
+
device &&
|
|
1666
|
+
(promiseEvent === UI_RESPONSE.RECEIVE_PIN || promiseEvent === UI_RESPONSE.RECEIVE_PASSPHRASE)
|
|
1667
|
+
) {
|
|
1668
|
+
const publicDeviceId = device.toMessageObject()?.deviceId;
|
|
1669
|
+
uiPromise.responseCorrelation = {
|
|
1670
|
+
interactionId: generateInstanceId('UiResponse', device.sdkInstanceId),
|
|
1671
|
+
deviceId: publicDeviceId || device.instanceId,
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1316
1674
|
_uiPromises.push(uiPromise as any);
|
|
1317
1675
|
|
|
1318
1676
|
return uiPromise;
|
|
1319
1677
|
};
|
|
1320
1678
|
|
|
1321
|
-
const findUiPromise = <T extends UiPromiseResponse['type']>(promiseEvent: T) =>
|
|
1322
|
-
_uiPromises.find(p => p.id === promiseEvent);
|
|
1323
|
-
|
|
1324
1679
|
const removeUiPromise = (promise: Deferred<any>) => {
|
|
1325
1680
|
_uiPromises = _uiPromises.filter(p => p !== promise);
|
|
1326
1681
|
};
|
|
@@ -1332,8 +1687,10 @@ export default class Core extends EventEmitter {
|
|
|
1332
1687
|
|
|
1333
1688
|
private requestQueue = new RequestQueue();
|
|
1334
1689
|
|
|
1690
|
+
private disposePromise?: Promise<void>;
|
|
1691
|
+
|
|
1335
1692
|
// background task
|
|
1336
|
-
private
|
|
1693
|
+
private prePendingCallPromises = new Map<string, Promise<void>>();
|
|
1337
1694
|
|
|
1338
1695
|
private methodSynchronize = getSynchronize();
|
|
1339
1696
|
|
|
@@ -1344,19 +1701,24 @@ export default class Core extends EventEmitter {
|
|
|
1344
1701
|
Log.debug(`[Core] Created SDK instance: ${this.sdkInstanceId}`);
|
|
1345
1702
|
}
|
|
1346
1703
|
|
|
1347
|
-
cancelOperation(operationId: string) {
|
|
1348
|
-
this.requestQueue.abortOperation(operationId);
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
1704
|
private getCoreContext() {
|
|
1352
1705
|
return {
|
|
1353
1706
|
sdkInstanceId: this.sdkInstanceId,
|
|
1354
1707
|
tracingContext: this.tracingContext,
|
|
1355
1708
|
requestQueue: this.requestQueue,
|
|
1356
1709
|
methodSynchronize: this.methodSynchronize,
|
|
1357
|
-
getPrePendingCallPromise: () => this.
|
|
1358
|
-
setPrePendingCallPromise: (
|
|
1359
|
-
|
|
1710
|
+
getPrePendingCallPromise: (connectId: string) => this.prePendingCallPromises.get(connectId),
|
|
1711
|
+
setPrePendingCallPromise: (connectId: string, promise?: Promise<void>) => {
|
|
1712
|
+
if (!promise) {
|
|
1713
|
+
this.prePendingCallPromises.delete(connectId);
|
|
1714
|
+
return;
|
|
1715
|
+
}
|
|
1716
|
+
this.prePendingCallPromises.set(connectId, promise);
|
|
1717
|
+
},
|
|
1718
|
+
removePrePendingCallPromise: (connectId: string, promise: Promise<void>) => {
|
|
1719
|
+
if (this.prePendingCallPromises.get(connectId) === promise) {
|
|
1720
|
+
this.prePendingCallPromises.delete(connectId);
|
|
1721
|
+
}
|
|
1360
1722
|
},
|
|
1361
1723
|
// callback 任务管理
|
|
1362
1724
|
registerCallbackTask: (connectId: string, callbackPromise: Deferred<any>) => {
|
|
@@ -1374,11 +1736,16 @@ export default class Core extends EventEmitter {
|
|
|
1374
1736
|
case UI_RESPONSE.RECEIVE_PASSPHRASE:
|
|
1375
1737
|
case UI_RESPONSE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE:
|
|
1376
1738
|
case UI_RESPONSE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE: {
|
|
1377
|
-
const uiPromise =
|
|
1739
|
+
const uiPromise = findUiPromiseForResponse(_uiPromises, message);
|
|
1378
1740
|
if (uiPromise) {
|
|
1379
1741
|
Log.log('receive UI Response: ', message.type);
|
|
1380
1742
|
uiPromise.resolve(message);
|
|
1381
1743
|
removeUiPromise(uiPromise);
|
|
1744
|
+
} else if (
|
|
1745
|
+
message.type === UI_RESPONSE.RECEIVE_PIN ||
|
|
1746
|
+
message.type === UI_RESPONSE.RECEIVE_PASSPHRASE
|
|
1747
|
+
) {
|
|
1748
|
+
Log.warn('Ignored unmatched or ambiguous sensitive UI response:', message.type);
|
|
1382
1749
|
}
|
|
1383
1750
|
break;
|
|
1384
1751
|
}
|
|
@@ -1394,10 +1761,17 @@ export default class Core extends EventEmitter {
|
|
|
1394
1761
|
}
|
|
1395
1762
|
|
|
1396
1763
|
case IFRAME.CALL: {
|
|
1397
|
-
|
|
1764
|
+
const logBlockLabel = getLogBlockLabel(message);
|
|
1765
|
+
Log.log(
|
|
1766
|
+
formatLogMethodLabel(`[${Date.now()}][CALL_API]`, logBlockLabel),
|
|
1767
|
+
getSafeLogPayload(message, logBlockLabel)
|
|
1768
|
+
);
|
|
1398
1769
|
const response = await callAPI(this.getCoreContext(), message);
|
|
1399
1770
|
const { success, payload } = response;
|
|
1400
|
-
Log.log(
|
|
1771
|
+
Log.log(
|
|
1772
|
+
formatLogMethodLabel(`[${Date.now()}][CALL_API_RESPONSE]`, logBlockLabel),
|
|
1773
|
+
getSafeLogPayload(response, logBlockLabel)
|
|
1774
|
+
);
|
|
1401
1775
|
if (success) {
|
|
1402
1776
|
return response;
|
|
1403
1777
|
}
|
|
@@ -1416,10 +1790,6 @@ export default class Core extends EventEmitter {
|
|
|
1416
1790
|
cancel(this.getCoreContext(), message.payload.connectId);
|
|
1417
1791
|
break;
|
|
1418
1792
|
}
|
|
1419
|
-
case IFRAME.CANCEL_OPERATION: {
|
|
1420
|
-
this.cancelOperation(message.payload.operationId);
|
|
1421
|
-
break;
|
|
1422
|
-
}
|
|
1423
1793
|
case IFRAME.CALLBACK: {
|
|
1424
1794
|
Log.log('callback message: ', message);
|
|
1425
1795
|
postMessage(message);
|
|
@@ -1431,25 +1801,65 @@ export default class Core extends EventEmitter {
|
|
|
1431
1801
|
return Promise.resolve(message);
|
|
1432
1802
|
}
|
|
1433
1803
|
|
|
1434
|
-
dispose() {
|
|
1804
|
+
dispose(): Promise<void> {
|
|
1805
|
+
if (!this.disposePromise) {
|
|
1806
|
+
this.disposePromise = this.disposeResources();
|
|
1807
|
+
}
|
|
1808
|
+
return this.disposePromise;
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
private async disposeResources(): Promise<void> {
|
|
1812
|
+
Log.debug(`[Core] Disposing SDK instance: ${this.sdkInstanceId}`);
|
|
1813
|
+
pollingManager.stopAll();
|
|
1814
|
+
this.requestQueue.abortAllRequests();
|
|
1815
|
+
cleanup();
|
|
1816
|
+
|
|
1817
|
+
_connector?.stop();
|
|
1818
|
+
let transportCleanup: Promise<void>;
|
|
1819
|
+
try {
|
|
1820
|
+
transportCleanup = Promise.resolve(TransportManager.getTransport()?.stop?.()).catch(error => {
|
|
1821
|
+
Log.warn('[Core] Transport cleanup failed:', error);
|
|
1822
|
+
});
|
|
1823
|
+
} catch (error) {
|
|
1824
|
+
Log.warn('[Core] Transport cleanup failed:', error);
|
|
1825
|
+
transportCleanup = Promise.resolve();
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
// Preserve synchronous dispose semantics for in-memory state and listeners.
|
|
1435
1829
|
_deviceList = undefined;
|
|
1436
1830
|
_connector = undefined;
|
|
1831
|
+
DevicePool.dispose();
|
|
1437
1832
|
deviceCacheMap.clear();
|
|
1438
1833
|
preWarmInflight.clear();
|
|
1439
1834
|
preWarmDoneAt.clear();
|
|
1440
|
-
|
|
1835
|
+
preConnectCache = { passphraseState: undefined };
|
|
1836
|
+
this.prePendingCallPromises.clear();
|
|
1837
|
+
this.removeAllListeners();
|
|
1441
1838
|
cleanupSdkInstance(this.sdkInstanceId);
|
|
1839
|
+
if (_core === this) _core = undefined;
|
|
1840
|
+
|
|
1841
|
+
// Transports, especially Node USB, may release native handles asynchronously.
|
|
1842
|
+
await transportCleanup;
|
|
1442
1843
|
}
|
|
1443
1844
|
}
|
|
1444
1845
|
|
|
1445
1846
|
export const initCore = () => {
|
|
1446
|
-
|
|
1447
|
-
|
|
1847
|
+
const core = new Core();
|
|
1848
|
+
_core = core;
|
|
1849
|
+
return core;
|
|
1448
1850
|
};
|
|
1449
1851
|
|
|
1450
1852
|
export const initConnector = () => {
|
|
1451
1853
|
_connector = new DeviceConnector();
|
|
1854
|
+
DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
1855
|
+
DevicePool.emitter.removeListener(DEVICE.DISCONNECT, onDeviceDisconnectHandler);
|
|
1856
|
+
DevicePool.emitter.removeListener(
|
|
1857
|
+
TRANSPORT_EVENT.DEVICE_DISCONNECT,
|
|
1858
|
+
onTransportDeviceDisconnectHandler
|
|
1859
|
+
);
|
|
1860
|
+
DevicePool.emitter.on(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
1452
1861
|
DevicePool.emitter.on(DEVICE.DISCONNECT, onDeviceDisconnectHandler);
|
|
1862
|
+
DevicePool.emitter.on(TRANSPORT_EVENT.DEVICE_DISCONNECT, onTransportDeviceDisconnectHandler);
|
|
1453
1863
|
return _connector;
|
|
1454
1864
|
};
|
|
1455
1865
|
|
|
@@ -1463,12 +1873,8 @@ export const init = async (
|
|
|
1463
1873
|
plugin?: LowlevelTransportSharedPlugin
|
|
1464
1874
|
) => {
|
|
1465
1875
|
try {
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
initTransport(Transport, plugin);
|
|
1469
|
-
} catch {
|
|
1470
|
-
Log.error('DataManager.load error');
|
|
1471
|
-
}
|
|
1876
|
+
await DataManager.load(settings);
|
|
1877
|
+
initTransport(Transport, plugin);
|
|
1472
1878
|
enableLog(DataManager.getSettings('debug'));
|
|
1473
1879
|
if (DataManager.getSettings('env') !== 'react-native') {
|
|
1474
1880
|
setLoggerPostMessage(postMessage);
|
|
@@ -1479,6 +1885,7 @@ export const init = async (
|
|
|
1479
1885
|
return _core;
|
|
1480
1886
|
} catch (error) {
|
|
1481
1887
|
Log.error('core init', error);
|
|
1888
|
+
throw error;
|
|
1482
1889
|
}
|
|
1483
1890
|
};
|
|
1484
1891
|
|