@onekeyfe/hd-core 1.2.0-alpha.1 → 1.2.0-alpha.100
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 +563 -0
- package/__tests__/DeviceEventRegistration.test.ts +49 -0
- package/__tests__/chain-params-onekey-compatibility.test.ts +229 -0
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +830 -0
- package/__tests__/check-firmware-release-protocol-v2.test.ts +270 -0
- package/__tests__/connectSettings.test.ts +59 -0
- 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 +81 -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 +351 -0
- package/__tests__/device-pool-state.test.ts +166 -0
- package/__tests__/device-settings.test.ts +437 -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 +288 -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 +154 -0
- package/__tests__/device-wallet-session-store.test.ts +478 -0
- package/__tests__/deviceFeaturesUtils.test.ts +39 -0
- package/__tests__/devicePoolBootloaderPath.test.ts +64 -0
- package/__tests__/deviceSettings.test.ts +113 -0
- package/__tests__/deviceUploadNft.test.ts +316 -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 +150 -0
- package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +375 -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 +815 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +283 -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 +121 -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 +578 -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 +128 -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__/preInitialize.test.ts +33 -0
- package/__tests__/pro2Nft.test.ts +108 -0
- package/__tests__/pro2Wallpaper.test.ts +39 -0
- package/__tests__/protocol-binding.test.ts +89 -0
- package/__tests__/protocol-v2-bootloader-mode.test.ts +37 -0
- package/__tests__/protocol-v2-firmware-targets.test.ts +124 -0
- package/__tests__/protocol-v2-ping.test.ts +28 -0
- package/__tests__/protocol-v2-resources.test.ts +270 -0
- package/__tests__/protocol-v2-ui-lifecycle.test.ts +91 -0
- package/__tests__/protocol-v2-unlock-policy.test.ts +308 -0
- package/__tests__/protocol-v2.test.ts +8346 -1866
- package/__tests__/protocolV2FileWrite.test.ts +285 -0
- 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 +101 -0
- package/__tests__/request-context-logging.test.ts +16 -0
- package/__tests__/search-devices.test.ts +145 -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 +16 -1
- 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 +9 -0
- package/dist/api/ClearSessionCache.d.ts.map +1 -0
- 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 +2 -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 +63 -6
- 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 +2 -6
- 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 +17 -0
- package/dist/api/UploadPortfolio.d.ts.map +1 -0
- 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/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 -2
- 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 +17 -3
- 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/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 +43 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -0
- package/dist/api/index.d.ts +8 -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 +7 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +8 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +2 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +4 -2
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +1 -0
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts +29 -0
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceReboot.d.ts +1 -0
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +31 -0
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +27 -0
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -0
- 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 +7 -0
- package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -0
- 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 +7 -0
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -0
- package/dist/api/protocol-v2/helpers.d.ts +27 -18
- 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 +2 -5
- 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 -2
- package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
- package/dist/api/tron/TronSignTransaction.d.ts +2 -2
- 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.map +1 -1
- package/dist/core/deviceEventRegistration.d.ts +13 -0
- package/dist/core/deviceEventRegistration.d.ts.map +1 -0
- package/dist/core/index.d.ts +3 -1
- 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 +12 -4
- 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 +75 -17
- 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 +27 -0
- package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -0
- package/dist/device/cloneDeviceState.d.ts +2 -0
- package/dist/device/cloneDeviceState.d.ts.map +1 -0
- package/dist/device/deviceIdentity.d.ts +5 -0
- package/dist/device/deviceIdentity.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts +9 -3
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/deviceProfile/index.d.ts +0 -1
- package/dist/deviceProfile/index.d.ts.map +1 -1
- package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts +7 -0
- package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts.map +1 -0
- package/dist/events/device.d.ts +16 -2
- package/dist/events/device.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 +1792 -750
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12615 -4679
- package/dist/inject.d.ts +6 -1
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/deviceSession.d.ts +7 -0
- package/dist/protocols/protocol-v2/deviceSession.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/features.d.ts +30 -28
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts +11 -9
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +3 -2
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/resources.d.ts +12 -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 +27 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -0
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +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 +68 -6
- 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 +2 -10
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +31 -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 +17 -88
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/api/sessionCache.d.ts +13 -0
- package/dist/types/api/sessionCache.d.ts.map +1 -0
- package/dist/types/device.d.ts +143 -10
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +2 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +71 -9
- 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 +12 -3
- 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 +38 -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 +6 -3
- 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 +31 -0
- package/dist/utils/pro2Nft.d.ts.map +1 -0
- package/dist/utils/pro2Wallpaper.d.ts +22 -0
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -0
- 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 +4 -4
- package/src/api/BaseMethod.ts +53 -20
- package/src/api/CheckAllFirmwareRelease.ts +442 -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 +32 -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 +27 -8
- package/src/api/FileWrite.ts +26 -168
- package/src/api/FirmwareUpdate.ts +30 -15
- package/src/api/FirmwareUpdateV2.ts +532 -169
- package/src/api/FirmwareUpdateV3.ts +320 -72
- package/src/api/FirmwareUpdateV4.ts +2691 -428
- 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 -18
- package/src/api/OpenWalletSession.ts +268 -0
- package/src/api/PathInfo.ts +9 -4
- package/src/api/PromptWebDeviceAccess.ts +2 -7
- package/src/api/SearchDevices.ts +31 -4
- package/src/api/UploadPortfolio.ts +58 -0
- package/src/api/alephium/AlephiumGetAddress.ts +0 -4
- package/src/api/alephium/AlephiumSignMessage.ts +0 -4
- package/src/api/alephium/AlephiumSignTransaction.ts +2 -6
- package/src/api/algo/AlgoGetAddress.ts +4 -0
- package/src/api/algo/AlgoSignTransaction.ts +4 -0
- package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +45 -32
- package/src/api/aptos/AptosGetAddress.ts +4 -0
- package/src/api/aptos/AptosGetPublicKey.ts +4 -0
- package/src/api/aptos/AptosSignInMessage.ts +4 -0
- package/src/api/aptos/AptosSignMessage.ts +4 -0
- package/src/api/aptos/AptosSignTransaction.ts +4 -0
- package/src/api/benfen/BenfenGetAddress.ts +11 -7
- package/src/api/benfen/BenfenGetPublicKey.ts +0 -4
- package/src/api/benfen/BenfenSignMessage.ts +0 -4
- package/src/api/benfen/BenfenSignTransaction.ts +0 -4
- package/src/api/btc/BTCGetAddress.ts +8 -1
- package/src/api/btc/BTCGetPublicKey.ts +9 -2
- package/src/api/btc/BTCSignMessage.ts +8 -1
- package/src/api/btc/BTCSignPsbt.ts +4 -0
- package/src/api/btc/BTCSignTransaction.ts +8 -1
- package/src/api/btc/BTCVerifyMessage.ts +8 -1
- package/src/api/btc/helpers/versionLimit.ts +7 -4
- package/src/api/cardano/CardanoGetAddress.ts +4 -0
- package/src/api/cardano/CardanoGetPublicKey.ts +4 -0
- package/src/api/cardano/CardanoSignMessage.ts +5 -1
- package/src/api/cardano/CardanoSignTransaction.ts +5 -1
- 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 +28 -0
- package/src/api/device/DeviceFullyUploadResource.ts +4 -5
- package/src/api/device/DeviceLock.ts +5 -0
- package/src/api/device/DeviceRebootToBoardloader.ts +9 -4
- package/src/api/device/DeviceRebootToBootloader.ts +9 -4
- package/src/api/device/DeviceSettings.ts +195 -1
- 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/DeviceWipe.ts +25 -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 +187 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +216 -65
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +945 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +486 -0
- package/src/api/firmware/getBinary.ts +8 -3
- package/src/api/firmware/protocolV2Release.ts +168 -0
- package/src/api/firmware/updateBootloader.ts +19 -4
- package/src/api/firmware/uploadFirmware.ts +157 -26
- 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 +392 -0
- package/src/api/index.ts +9 -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/{FactoryGetDeviceInfo.ts → DeviceFactoryInfoGet.ts} +8 -5
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +35 -0
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +11 -10
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +45 -7
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +10 -5
- package/src/api/protocol-v2/DeviceInfoGet.ts +141 -0
- package/src/api/protocol-v2/DeviceReboot.ts +8 -4
- package/src/api/protocol-v2/DeviceStatusGet.ts +19 -0
- package/src/api/protocol-v2/DeviceUploadNft.ts +197 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +134 -0
- package/src/api/protocol-v2/FilesystemFormat.ts +9 -3
- package/src/api/protocol-v2/{FilesystemFixPermission.ts → FilesystemPermissionFix.ts} +7 -4
- package/src/api/protocol-v2/Ping.ts +37 -3
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +21 -0
- package/src/api/protocol-v2/helpers.ts +71 -50
- 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 +6 -6
- package/src/api/ton/TonSignMessage.ts +5 -1
- package/src/api/ton/TonSignProof.ts +5 -1
- package/src/api/tron/TronGetAddress.ts +4 -0
- package/src/api/tron/TronSignMessage.ts +19 -9
- package/src/api/tron/TronSignTransaction.ts +5 -2
- 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 +1 -0
- package/src/core/deviceEventRegistration.ts +27 -0
- package/src/core/index.ts +400 -157
- package/src/core/uiPromiseRegistry.ts +63 -0
- package/src/data/messages/messages-protocol-v2.json +904 -791
- package/src/data/messages/messages.json +286 -1
- package/src/data-manager/DataManager.ts +158 -40
- package/src/data-manager/TransportManager.ts +7 -1
- package/src/data-manager/connectSettings.ts +13 -4
- package/src/device/Device.ts +909 -296
- package/src/device/DeviceCommands.ts +193 -158
- package/src/device/DeviceConnector.ts +44 -21
- package/src/device/DeviceFeaturesState.ts +25 -0
- package/src/device/DevicePool.ts +101 -23
- package/src/device/DeviceStateMapper.ts +416 -0
- package/src/device/DeviceStateProjector.ts +152 -0
- package/src/device/DeviceStateStore.ts +232 -0
- package/src/device/DeviceWalletSessionStore.ts +144 -0
- package/src/device/cloneDeviceState.ts +39 -0
- package/src/device/deviceIdentity.ts +18 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +243 -212
- package/src/deviceProfile/index.ts +0 -1
- package/src/deviceProfile/protocolV2DeviceIdentity.ts +35 -0
- package/src/events/device.ts +22 -1
- package/src/events/logBlockEvent.ts +80 -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 +17 -0
- package/src/inject.ts +93 -49
- package/src/lowLevelInject.ts +11 -4
- package/src/protocols/protocol-v2/deviceSession.ts +24 -0
- package/src/protocols/protocol-v2/features.ts +113 -83
- package/src/protocols/protocol-v2/firmware.ts +14 -36
- package/src/protocols/protocol-v2/index.ts +8 -1
- package/src/protocols/protocol-v2/resources.ts +210 -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 +131 -0
- package/src/protocols/protocol-v2/walletSession.ts +463 -0
- package/src/topLevelInject.ts +11 -4
- 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 +101 -19
- 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 +9 -11
- package/src/types/api/index.ts +50 -72
- package/src/types/api/kaspaSignTransaction.ts +60 -4
- package/src/types/api/openWalletSession.ts +54 -0
- package/src/types/api/protocolV2.ts +31 -157
- package/src/types/api/sessionCache.ts +19 -0
- package/src/types/device.ts +217 -10
- package/src/types/params.ts +12 -1
- package/src/types/settings.ts +91 -42
- package/src/utils/assets.ts +4 -1
- package/src/utils/deviceFeaturesCompat.ts +191 -0
- package/src/utils/deviceFeaturesUtils.ts +85 -26
- package/src/utils/deviceInfoUtils.ts +29 -69
- package/src/utils/deviceSettings.ts +174 -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 +27 -3
- package/src/utils/networkUtils.ts +274 -16
- package/src/utils/pro2Nft.ts +142 -0
- package/src/utils/pro2Wallpaper.ts +130 -0
- package/src/utils/tracing.ts +3 -1
- package/src/utils/uiProgressThrottle.ts +63 -0
- package/tsconfig.type-tests.json +12 -0
- package/dist/api/GetDeviceInfo.d.ts +0 -9
- package/dist/api/GetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/DevReboot.d.ts +0 -7
- package/dist/api/protocol-v2/DevReboot.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts +0 -29
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +0 -7
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +0 -1
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +0 -6
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +0 -13
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts.map +0 -1
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +0 -6
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +0 -1
- package/dist/api/protocol-v2/GetProtoVersion.d.ts +0 -6
- package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +0 -1
- package/dist/deviceProfile/buildDeviceProfile.d.ts +0 -21
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +0 -1
- package/dist/types/api/getDeviceInfo.d.ts +0 -85
- package/dist/types/api/getDeviceInfo.d.ts.map +0 -1
- package/src/api/GetDeviceInfo.ts +0 -145
- package/src/api/protocol-v2/DevReboot.ts +0 -24
- package/src/api/protocol-v2/DeviceGetDeviceInfo.ts +0 -118
- package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +0 -29
- package/src/api/protocol-v2/FilesystemDiskControl.ts +0 -50
- package/src/api/protocol-v2/GetProtoVersion.ts +0 -16
- package/src/deviceProfile/buildDeviceProfile.ts +0 -333
- package/src/types/api/getDeviceInfo.ts +0 -99
package/src/device/Device.ts
CHANGED
|
@@ -1,39 +1,45 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
2
|
import semver from 'semver';
|
|
3
|
-
import { Enum_Capability } from '@onekeyfe/hd-transport';
|
|
3
|
+
import { DeviceRebootType, DeviceSessionPinType, Enum_Capability } from '@onekeyfe/hd-transport';
|
|
4
4
|
import {
|
|
5
5
|
EDeviceType,
|
|
6
|
+
EFirmwareType,
|
|
6
7
|
ERRORS,
|
|
7
8
|
ERROR_CODES_REQUIRE_DISCONNECT,
|
|
8
9
|
ERROR_CODES_REQUIRE_RELEASE,
|
|
9
10
|
HardwareError,
|
|
10
11
|
HardwareErrorCode,
|
|
11
12
|
createDeferred,
|
|
13
|
+
createDeviceNotSupportMethodError,
|
|
12
14
|
} from '@onekeyfe/hd-shared';
|
|
13
15
|
|
|
14
|
-
import {
|
|
15
|
-
LoggerNames,
|
|
16
|
-
getDeviceBLEFirmwareVersion,
|
|
17
|
-
getDeviceBleName,
|
|
18
|
-
getDeviceFirmwareVersion,
|
|
19
|
-
getDeviceLabel,
|
|
20
|
-
getDeviceType,
|
|
21
|
-
getDeviceUUID,
|
|
22
|
-
getFirmwareType,
|
|
23
|
-
getLogger,
|
|
24
|
-
} from '../utils';
|
|
16
|
+
import { LoggerNames, getLogger } from '../utils';
|
|
25
17
|
import {
|
|
26
18
|
fixFeaturesFirmwareVersion,
|
|
27
19
|
getPassphraseStateWithRefreshDeviceInfo,
|
|
28
|
-
supportInputPinOnSoftware,
|
|
29
|
-
supportModifyHomescreen,
|
|
30
20
|
} from '../utils/deviceFeaturesUtils';
|
|
21
|
+
import { parseDeviceVersion } from '../utils/deviceVersionUtils';
|
|
31
22
|
import { generateInstanceId } from '../utils/tracing';
|
|
32
23
|
// eslint-disable-next-line import/no-cycle
|
|
33
24
|
import { DeviceCommands } from './DeviceCommands';
|
|
25
|
+
import { mergeDeviceFeaturesPatch } from './DeviceFeaturesState';
|
|
26
|
+
import {
|
|
27
|
+
mapDeviceSettingsToState,
|
|
28
|
+
mapFeaturesToState,
|
|
29
|
+
mapProtocolV1OnekeyFeaturesToState,
|
|
30
|
+
mapProtocolV2DeviceInfoToState,
|
|
31
|
+
mapProtocolV2DeviceStatusToState,
|
|
32
|
+
} from './DeviceStateMapper';
|
|
33
|
+
import { projectFeatures } from './DeviceStateProjector';
|
|
34
|
+
import { DeviceStateStore, createPublicDeviceState } from './DeviceStateStore';
|
|
35
|
+
import { cloneDeviceState } from './cloneDeviceState';
|
|
36
|
+
import { deviceWalletSessionStore } from './DeviceWalletSessionStore';
|
|
34
37
|
import {
|
|
35
38
|
type DeviceFirmwareRange,
|
|
36
39
|
DeviceModelToTypes,
|
|
40
|
+
type DeviceStateEvent,
|
|
41
|
+
type DeviceStatePatch,
|
|
42
|
+
type DeviceStateUpdateSource,
|
|
37
43
|
DeviceTypeToModels,
|
|
38
44
|
type Device as DeviceTyped,
|
|
39
45
|
EOneKeyDeviceMode,
|
|
@@ -48,23 +54,36 @@ import { DEVICE, UI_REQUEST } from '../events';
|
|
|
48
54
|
import { DataManager } from '../data-manager';
|
|
49
55
|
import TransportManager from '../data-manager/TransportManager';
|
|
50
56
|
import { toHardened } from '../api/helpers/pathUtils';
|
|
51
|
-
import { existCapability } from '../utils/capabilitieUtils';
|
|
52
57
|
import {
|
|
53
|
-
|
|
58
|
+
PROTOCOL_V2_DEVICE_STATUS_GET_MESSAGE_TYPE,
|
|
59
|
+
PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST,
|
|
60
|
+
PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST,
|
|
61
|
+
PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
|
|
62
|
+
type ProtocolV2RuntimeMode,
|
|
63
|
+
getProtocolV2RuntimeMode,
|
|
54
64
|
requestProtocolV2DeviceInfo,
|
|
65
|
+
requestProtocolV2DeviceStatus,
|
|
66
|
+
requestProtocolV2ProtocolInfo,
|
|
67
|
+
supportsProtocolV2Message,
|
|
55
68
|
} from '../protocols/protocol-v2/features';
|
|
56
|
-
import { buildProtocolV1FeaturesPayload
|
|
69
|
+
import { buildProtocolV1FeaturesPayload } from '../deviceProfile';
|
|
70
|
+
import { resolveProtocolV2DeviceIdentity } from '../deviceProfile/protocolV2DeviceIdentity';
|
|
57
71
|
|
|
58
72
|
import type { PROTO } from '../constants';
|
|
73
|
+
import type { DeviceStateReadOptions } from '../types/api/getDeviceState';
|
|
59
74
|
import type {
|
|
60
75
|
DeviceButtonRequestPayload,
|
|
61
76
|
DeviceFeaturesPayload,
|
|
77
|
+
HardwareUiInteractionMeta,
|
|
62
78
|
PassphraseRequestPayload,
|
|
79
|
+
ProtocolV2UiEventMetadata,
|
|
63
80
|
} from '../events';
|
|
64
81
|
import type { PassphrasePromptResponse } from './DeviceCommands';
|
|
65
82
|
import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
66
83
|
import type {
|
|
67
84
|
OneKeyDeviceInfo as DeviceDescriptor,
|
|
85
|
+
DeviceStatus,
|
|
86
|
+
ProtocolInfo,
|
|
68
87
|
ProtocolV2DeviceInfo,
|
|
69
88
|
Success,
|
|
70
89
|
} from '@onekeyfe/hd-transport';
|
|
@@ -76,6 +95,15 @@ export type InitOptions = {
|
|
|
76
95
|
passphraseState?: string;
|
|
77
96
|
deriveCardano?: boolean;
|
|
78
97
|
connectProtocol?: HardwareConnectProtocol;
|
|
98
|
+
forceProtocolDetection?: boolean;
|
|
99
|
+
protocolV2DeviceInfoTimeoutMs?: number;
|
|
100
|
+
/** Refresh Protocol V2 runtime state before returning discovery results. */
|
|
101
|
+
refreshRuntimeState?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Protocol V1 Initialize response timeout override. Reboot-wait polling passes a
|
|
104
|
+
* short value so an unanswered probe settles before the next poll tick.
|
|
105
|
+
*/
|
|
106
|
+
timeoutMs?: number;
|
|
79
107
|
};
|
|
80
108
|
|
|
81
109
|
export type RunOptions = {
|
|
@@ -90,11 +118,35 @@ const parseRunOptions = (options?: RunOptions): RunOptions => {
|
|
|
90
118
|
|
|
91
119
|
const Log = getLogger(LoggerNames.Device);
|
|
92
120
|
|
|
121
|
+
const isProtocolV2DeviceStatusUnsupportedError = (error: unknown) => {
|
|
122
|
+
if (error instanceof HardwareError) {
|
|
123
|
+
if (error.errorCode === HardwareErrorCode.DeviceNotSupportMethod) {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
if (error.params?.failureCode === 'Failure_UnexpectedMessage') {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const message =
|
|
132
|
+
error instanceof Error
|
|
133
|
+
? error.message
|
|
134
|
+
: String((error as { message?: unknown } | null)?.message ?? error ?? '');
|
|
135
|
+
return (
|
|
136
|
+
/^Failure_UnexpectedMessage(?:,|\b)/i.test(message) ||
|
|
137
|
+
/\b(?:unsupported message|handler not registered|message handler not found)\b/i.test(message)
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
|
|
93
141
|
export interface DeviceEvents {
|
|
94
142
|
[DEVICE.PIN]: [Device, PROTO.PinMatrixRequestType | undefined, (err: any, pin: string) => void];
|
|
95
|
-
[DEVICE.
|
|
143
|
+
[DEVICE.PIN_ON_DEVICE]: [Device, DeviceSessionPinType, ProtocolV2UiEventMetadata?];
|
|
144
|
+
[DEVICE.PIN_ON_DEVICE_COMPLETE]: [Device, HardwareUiInteractionMeta];
|
|
145
|
+
[DEVICE.PASSPHRASE_ON_DEVICE]: [Device, PassphraseRequestPayload?];
|
|
146
|
+
[DEVICE.ATTACH_PIN_ON_DEVICE]: [Device, PassphraseRequestPayload?];
|
|
96
147
|
[DEVICE.BUTTON]: [Device, DeviceButtonRequestPayload];
|
|
97
148
|
[DEVICE.FEATURES]: [Device, DeviceFeaturesPayload];
|
|
149
|
+
[DEVICE.STATE]: [Device, DeviceStateEvent];
|
|
98
150
|
[DEVICE.PASSPHRASE]: [
|
|
99
151
|
Device,
|
|
100
152
|
PassphraseRequestPayload,
|
|
@@ -118,15 +170,14 @@ export interface Device {
|
|
|
118
170
|
emit<K extends keyof DeviceEvents>(type: K, ...args: DeviceEvents[K]): boolean;
|
|
119
171
|
}
|
|
120
172
|
|
|
121
|
-
const deviceSessionCache: Record<string, string> = {};
|
|
122
|
-
|
|
123
173
|
/**
|
|
124
174
|
* Pre-populate the device session cache with a known session ID.
|
|
125
175
|
*
|
|
126
176
|
* This allows short-lived processes (e.g. CLI) to restore a previously
|
|
127
177
|
* obtained session, avoiding the need to re-enter passphrase on every
|
|
128
178
|
* invocation. The session must have been obtained from a prior
|
|
129
|
-
*
|
|
179
|
+
* wallet-session call on the same device. This compatibility hook is intended
|
|
180
|
+
* for a trusted CLI process restoring its own OS-keychain entry.
|
|
130
181
|
*
|
|
131
182
|
* @param deviceId - The device's device_id (from features)
|
|
132
183
|
* @param passphraseState - The passphrase state token
|
|
@@ -137,8 +188,7 @@ export function preloadSessionCache(
|
|
|
137
188
|
passphraseState: string,
|
|
138
189
|
sessionId: string
|
|
139
190
|
): void {
|
|
140
|
-
|
|
141
|
-
deviceSessionCache[key] = sessionId;
|
|
191
|
+
deviceWalletSessionStore.set(deviceId, passphraseState, sessionId);
|
|
142
192
|
}
|
|
143
193
|
|
|
144
194
|
export class Device extends EventEmitter {
|
|
@@ -184,22 +234,52 @@ export class Device extends EventEmitter {
|
|
|
184
234
|
*/
|
|
185
235
|
private deviceAcquired = false;
|
|
186
236
|
|
|
187
|
-
/**
|
|
188
|
-
|
|
189
|
-
*
|
|
190
|
-
* V1 直接保存原生 Features;V2 保存由 DevGetDeviceInfo 映射出的
|
|
191
|
-
* Features 视图。Device 不再保存 profile,结构化 DeviceProfile 只作为
|
|
192
|
-
* getDeviceInfo() 的 API 返回值存在。
|
|
193
|
-
*/
|
|
194
|
-
features: Features | undefined = undefined;
|
|
237
|
+
/** Canonical device-state cache; legacy Features is a compatibility projection. */
|
|
238
|
+
private stateStore = new DeviceStateStore();
|
|
195
239
|
|
|
196
|
-
/**
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
240
|
+
/** Force the next initialization to reload DeviceInfo after reconnect or reboot. */
|
|
241
|
+
private protocolV2StateNeedsReload = false;
|
|
242
|
+
|
|
243
|
+
/** Runtime context negotiated once per active Protocol V2 link. */
|
|
244
|
+
private protocolV2RuntimeContext?: ProtocolInfo;
|
|
245
|
+
|
|
246
|
+
/** Coalesces concurrent first-use runtime negotiation on the same active link. */
|
|
247
|
+
private protocolV2RuntimeContextPromise?: Promise<ProtocolInfo>;
|
|
248
|
+
|
|
249
|
+
/** Invalidates an in-flight runtime-context response without adding a transport epoch. */
|
|
250
|
+
private protocolV2RuntimeContextRequestToken?: object;
|
|
251
|
+
|
|
252
|
+
private protocolV2UiInteraction?: {
|
|
253
|
+
interactionId: string;
|
|
254
|
+
phaseCounter: number;
|
|
255
|
+
sequence: number;
|
|
256
|
+
opened: boolean;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
private protocolV2UiInteractionCounter = 0;
|
|
260
|
+
|
|
261
|
+
get state() {
|
|
262
|
+
return this.stateStore.getState();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
get features(): Features | undefined {
|
|
266
|
+
if (!this.state) return undefined;
|
|
267
|
+
return projectFeatures(this.state);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
set features(features: Features | undefined) {
|
|
271
|
+
this.stateStore = new DeviceStateStore();
|
|
272
|
+
if (features) {
|
|
273
|
+
this.stateStore.update(mapFeaturesToState(features), 'compatibility');
|
|
274
|
+
const { passphraseState } = features;
|
|
275
|
+
const sessionId = features.sessionId ?? features.session_id;
|
|
276
|
+
const deviceKey = this.getSessionCacheDeviceKey(features.deviceId ?? undefined);
|
|
277
|
+
if (passphraseState && sessionId && deviceKey) {
|
|
278
|
+
this.passphraseState = passphraseState;
|
|
279
|
+
deviceWalletSessionStore.set(deviceKey, passphraseState, sessionId);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
203
283
|
|
|
204
284
|
runPromise?: Deferred<void> | null;
|
|
205
285
|
|
|
@@ -253,38 +333,46 @@ export class Device extends EventEmitter {
|
|
|
253
333
|
|
|
254
334
|
// simplified object to pass via postMessage
|
|
255
335
|
toMessageObject(): DeviceTyped | null {
|
|
256
|
-
if (this.isUnacquired()) return null;
|
|
336
|
+
if (this.isUnacquired() || !this.features) return null;
|
|
257
337
|
|
|
258
338
|
const env = DataManager.getSettings('env');
|
|
259
339
|
const deviceType = this.getCurrentDeviceType();
|
|
260
340
|
|
|
261
341
|
const bleName = this.getCurrentBleName();
|
|
262
|
-
const
|
|
342
|
+
const displayName = this.getCurrentDisplayName();
|
|
263
343
|
const serialNo = this.getCurrentSerialNo();
|
|
264
344
|
const connectId = this.getConnectId();
|
|
265
345
|
const deviceId = this.getCurrentDeviceId() || null;
|
|
266
346
|
|
|
267
|
-
const features = this
|
|
347
|
+
const { features } = this;
|
|
348
|
+
const state = this.state ? createPublicDeviceState(this.state) : undefined;
|
|
268
349
|
|
|
269
350
|
return {
|
|
270
|
-
/** Android uses
|
|
351
|
+
/** Android uses a MAC address, while iOS and USB use transport-specific identifiers. */
|
|
271
352
|
connectId: DataManager.isBleConnect(env) ? this.mainId || null : connectId,
|
|
272
|
-
/**
|
|
353
|
+
/** Persist this after the first active probe so later calls do not need to guess. */
|
|
354
|
+
connectProtocol: this.originalDescriptor.protocolType,
|
|
355
|
+
/** Stable physical-device identity. */
|
|
356
|
+
serialNo,
|
|
357
|
+
/** @deprecated Use serialNo instead. */
|
|
273
358
|
uuid: serialNo,
|
|
274
359
|
commType: this.originalDescriptor.commType,
|
|
275
360
|
sdkInstanceId: this.sdkInstanceId,
|
|
276
361
|
instanceId: this.instanceId,
|
|
277
362
|
createdAt: this.createdAt,
|
|
278
363
|
deviceType,
|
|
279
|
-
/** ID
|
|
364
|
+
/** Wallet-lifecycle ID; changes after the device is wiped or reinitialized. */
|
|
280
365
|
deviceId,
|
|
281
366
|
path: this.originalDescriptor?.path,
|
|
282
367
|
bleName,
|
|
283
|
-
name: bleName ||
|
|
284
|
-
|
|
368
|
+
name: bleName || displayName || `OneKey ${deviceType?.toUpperCase()}`,
|
|
369
|
+
// Keep the legacy top-level field string-compatible while preserving
|
|
370
|
+
// the canonical nullable value at state.identity.label.
|
|
371
|
+
label: displayName ?? '',
|
|
372
|
+
status: this.getStatus(),
|
|
285
373
|
mode: this.getMode(),
|
|
286
374
|
features,
|
|
287
|
-
|
|
375
|
+
state,
|
|
288
376
|
firmwareVersion: this.getFirmwareVersion(),
|
|
289
377
|
bleFirmwareVersion: this.getBLEFirmwareVersion(),
|
|
290
378
|
unavailableCapabilities: this.unavailableCapabilities,
|
|
@@ -295,13 +383,20 @@ export class Device extends EventEmitter {
|
|
|
295
383
|
* Device connect
|
|
296
384
|
* @returns {Promise<boolean>}
|
|
297
385
|
*/
|
|
298
|
-
connect(
|
|
386
|
+
connect(
|
|
387
|
+
connectProtocol?: HardwareConnectProtocol,
|
|
388
|
+
options?: { forceProtocolDetection?: boolean }
|
|
389
|
+
) {
|
|
299
390
|
const env = DataManager.getSettings('env');
|
|
300
391
|
// eslint-disable-next-line no-async-promise-executor
|
|
301
392
|
return new Promise<boolean>(async (resolve, reject) => {
|
|
302
393
|
if (DataManager.isBleConnect(env)) {
|
|
394
|
+
if (this.hasDeviceAcquire() && this.commands && !this.commands.disposed) {
|
|
395
|
+
resolve(true);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
303
398
|
try {
|
|
304
|
-
await this.acquire(connectProtocol);
|
|
399
|
+
await this.acquire(connectProtocol, options);
|
|
305
400
|
resolve(true);
|
|
306
401
|
} catch (error) {
|
|
307
402
|
reject(error);
|
|
@@ -311,7 +406,7 @@ export class Device extends EventEmitter {
|
|
|
311
406
|
// 不存在 Session ID 或存在 Session ID 但设备在别处使用,都需要 acquire 获取最新 sessionID
|
|
312
407
|
if (!this.mainId || (!this.isUsedHere() && this.originalDescriptor)) {
|
|
313
408
|
try {
|
|
314
|
-
await this.acquire(connectProtocol);
|
|
409
|
+
await this.acquire(connectProtocol, options);
|
|
315
410
|
resolve(true);
|
|
316
411
|
} catch (error) {
|
|
317
412
|
reject(error);
|
|
@@ -326,23 +421,31 @@ export class Device extends EventEmitter {
|
|
|
326
421
|
});
|
|
327
422
|
}
|
|
328
423
|
|
|
329
|
-
async acquire(
|
|
424
|
+
async acquire(
|
|
425
|
+
expectedProtocol?: HardwareConnectProtocol,
|
|
426
|
+
options?: { throwOnRunPromiseError?: boolean; forceProtocolDetection?: boolean }
|
|
427
|
+
) {
|
|
330
428
|
const env = DataManager.getSettings('env');
|
|
331
429
|
const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
|
|
332
|
-
const
|
|
430
|
+
const previousProtocol = this.originalDescriptor.protocolType;
|
|
431
|
+
// A protocol stored after a successful probe is authoritative. Only the explicit
|
|
432
|
+
// first-connection/recovery path may bypass it and probe both protocols again.
|
|
433
|
+
const strictProtocol = options?.forceProtocolDetection
|
|
434
|
+
? undefined
|
|
435
|
+
: expectedProtocol ?? this.originalDescriptor.protocolType;
|
|
333
436
|
try {
|
|
334
437
|
let acquireResult: unknown;
|
|
335
438
|
if (DataManager.isBleConnect(env)) {
|
|
336
|
-
//
|
|
337
|
-
//
|
|
338
|
-
//
|
|
339
|
-
//
|
|
340
|
-
// 因此对 BLE acquire 恒清理是有意为之。
|
|
439
|
+
// acquire starts a new BLE session. Any previous runPromise belongs to a dead
|
|
440
|
+
// session, such as an interrupted probe or firmware-update reboot, and would
|
|
441
|
+
// otherwise block the new session. Device cannot distinguish recovery from a
|
|
442
|
+
// regular acquire, so BLE always clears it intentionally.
|
|
341
443
|
acquireResult = await this.deviceConnector?.acquire(
|
|
342
444
|
this.originalDescriptor.id,
|
|
343
445
|
undefined,
|
|
344
446
|
true,
|
|
345
|
-
|
|
447
|
+
strictProtocol,
|
|
448
|
+
undefined
|
|
346
449
|
);
|
|
347
450
|
this.mainId = (acquireResult as any)?.uuid ?? '';
|
|
348
451
|
Log.debug('Expected uuid:', this.mainId);
|
|
@@ -351,23 +454,31 @@ export class Device extends EventEmitter {
|
|
|
351
454
|
this.originalDescriptor.path,
|
|
352
455
|
this.originalDescriptor.session,
|
|
353
456
|
undefined,
|
|
354
|
-
|
|
457
|
+
strictProtocol,
|
|
458
|
+
undefined
|
|
355
459
|
);
|
|
356
460
|
this.mainId = acquireResult as string | undefined;
|
|
357
461
|
Log.debug('Expected session id:', this.mainId);
|
|
358
462
|
}
|
|
359
|
-
this.deviceAcquired = true;
|
|
360
|
-
this.updateDescriptor({ [mainIdKey]: this.mainId } as unknown as DeviceDescriptor);
|
|
361
|
-
|
|
362
463
|
// Propagate protocol version detected during acquire.
|
|
363
464
|
const detectedProtocol =
|
|
364
465
|
(acquireResult as { protocolType?: HardwareConnectProtocol } | undefined)?.protocolType ??
|
|
365
466
|
TransportManager.transport?.getProtocolType?.(
|
|
366
467
|
DataManager.isBleConnect(env) ? this.originalDescriptor.id : this.originalDescriptor.path
|
|
367
468
|
);
|
|
469
|
+
if (options?.forceProtocolDetection && !detectedProtocol) {
|
|
470
|
+
throw ERRORS.TypedError(
|
|
471
|
+
HardwareErrorCode.RuntimeError,
|
|
472
|
+
`Active protocol detection returned no protocol for ${
|
|
473
|
+
this.originalDescriptor.path || this.originalDescriptor.id
|
|
474
|
+
}`
|
|
475
|
+
);
|
|
476
|
+
}
|
|
368
477
|
if (detectedProtocol) {
|
|
369
478
|
this.originalDescriptor.protocolType = detectedProtocol;
|
|
370
479
|
}
|
|
480
|
+
this.deviceAcquired = true;
|
|
481
|
+
this.updateDescriptor({ [mainIdKey]: this.mainId } as unknown as DeviceDescriptor);
|
|
371
482
|
|
|
372
483
|
if (this.commands) {
|
|
373
484
|
await this.commands.dispose(false);
|
|
@@ -375,6 +486,25 @@ export class Device extends EventEmitter {
|
|
|
375
486
|
|
|
376
487
|
this.commands = new DeviceCommands(this, this.mainId ?? '');
|
|
377
488
|
} catch (error) {
|
|
489
|
+
if (options?.forceProtocolDetection) {
|
|
490
|
+
this.originalDescriptor.protocolType = previousProtocol;
|
|
491
|
+
const failedSession = this.mainId;
|
|
492
|
+
this.deviceAcquired = false;
|
|
493
|
+
if (failedSession) {
|
|
494
|
+
try {
|
|
495
|
+
await this.deviceConnector?.release?.(failedSession, false);
|
|
496
|
+
} catch (releaseError) {
|
|
497
|
+
Log.debug('Failed to release an unsuccessful protocol probe', releaseError);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (!DataManager.isBleConnect(env)) {
|
|
501
|
+
this.mainId = null;
|
|
502
|
+
this.updateDescriptor({ session: null } as DeviceDescriptor);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
if (options?.throwOnRunPromiseError) {
|
|
506
|
+
throw error;
|
|
507
|
+
}
|
|
378
508
|
if (this.runPromise) {
|
|
379
509
|
this.runPromise.reject(error);
|
|
380
510
|
} else {
|
|
@@ -413,7 +543,8 @@ export class Device extends EventEmitter {
|
|
|
413
543
|
}
|
|
414
544
|
}
|
|
415
545
|
try {
|
|
416
|
-
|
|
546
|
+
// BLE releases even when keepSession is set, so forward the intent.
|
|
547
|
+
await this.deviceConnector?.release(this.mainId, false, this.keepSession);
|
|
417
548
|
this.updateDescriptor({ session: null } as DeviceDescriptor);
|
|
418
549
|
} catch (err) {
|
|
419
550
|
Log.error('[Device] release error: ', err);
|
|
@@ -475,12 +606,11 @@ export class Device extends EventEmitter {
|
|
|
475
606
|
}
|
|
476
607
|
|
|
477
608
|
/**
|
|
478
|
-
*
|
|
609
|
+
* Canonical protocol discriminator.
|
|
479
610
|
*
|
|
480
|
-
* descriptor.protocolType
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
* 或从 features 反推。
|
|
611
|
+
* descriptor.protocolType is established by active probing; V2 features are mapped
|
|
612
|
+
* from DeviceInfoGet. All protocol branches must use this method instead of reading
|
|
613
|
+
* originalDescriptor.protocolType directly or inferring a protocol from features.
|
|
484
614
|
*/
|
|
485
615
|
getProtocol(): 'V1' | 'V2' {
|
|
486
616
|
return this.originalDescriptor.protocolType === 'V2' ? 'V2' : 'V1';
|
|
@@ -491,54 +621,75 @@ export class Device extends EventEmitter {
|
|
|
491
621
|
}
|
|
492
622
|
|
|
493
623
|
getCurrentDeviceType() {
|
|
494
|
-
return
|
|
624
|
+
return this.state?.identity.deviceType ?? EDeviceType.Unknown;
|
|
495
625
|
}
|
|
496
626
|
|
|
497
627
|
getCurrentDeviceId() {
|
|
498
|
-
return this.
|
|
628
|
+
return this.state?.identity.deviceId || undefined;
|
|
499
629
|
}
|
|
500
630
|
|
|
501
631
|
getCurrentSerialNo() {
|
|
502
|
-
return this.
|
|
632
|
+
return this.state?.identity.serialNo ?? '';
|
|
503
633
|
}
|
|
504
634
|
|
|
505
635
|
getConnectId() {
|
|
506
636
|
const serialNo = this.getCurrentSerialNo();
|
|
507
637
|
if (serialNo) return serialNo;
|
|
508
638
|
|
|
509
|
-
// connectId
|
|
510
|
-
//
|
|
511
|
-
// features.serialNo / deviceId 的业务语义。
|
|
639
|
+
// connectId is an internal routing key. Falling back to the transport descriptor
|
|
640
|
+
// does not change the business meaning of features.serialNo or deviceId.
|
|
512
641
|
return this.originalDescriptor.path || this.originalDescriptor.id || '';
|
|
513
642
|
}
|
|
514
643
|
|
|
515
644
|
getCurrentBleName() {
|
|
516
|
-
return
|
|
645
|
+
return this.state?.identity.bleName ?? null;
|
|
517
646
|
}
|
|
518
647
|
|
|
519
648
|
getCurrentLabel() {
|
|
520
|
-
return
|
|
649
|
+
return this.state?.identity.label ?? null;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
getCurrentDisplayName() {
|
|
653
|
+
if (!this.state) return null;
|
|
654
|
+
|
|
655
|
+
const label = this.getCurrentLabel();
|
|
656
|
+
if (label) return label;
|
|
657
|
+
|
|
658
|
+
const bleName = this.getCurrentBleName();
|
|
659
|
+
if (bleName) return bleName;
|
|
660
|
+
|
|
661
|
+
const deviceType = this.getCurrentDeviceType();
|
|
662
|
+
if (deviceType === EDeviceType.ClassicPure) {
|
|
663
|
+
return 'OneKey Classic 1S';
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
return `OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
|
|
521
667
|
}
|
|
522
668
|
|
|
523
669
|
getCurrentPassphraseProtection() {
|
|
524
|
-
return this.
|
|
670
|
+
return this.state?.status.passphraseProtection;
|
|
525
671
|
}
|
|
526
672
|
|
|
527
673
|
getCurrentFirmwareType() {
|
|
528
|
-
return
|
|
674
|
+
return this.state?.identity.firmwareType ?? EFirmwareType.Universal;
|
|
529
675
|
}
|
|
530
676
|
|
|
531
677
|
getCurrentFirmwareVersionString() {
|
|
532
|
-
return
|
|
678
|
+
return parseDeviceVersion(this.state?.versions.firmware).join('.');
|
|
533
679
|
}
|
|
534
680
|
|
|
535
681
|
getCurrentBLEFirmwareVersionString() {
|
|
536
|
-
if (!this.
|
|
537
|
-
return
|
|
682
|
+
if (!this.state) return undefined;
|
|
683
|
+
return parseDeviceVersion(this.state.versions.ble).join('.');
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
getCurrentBootloaderVersionString() {
|
|
687
|
+
if (!this.state) return undefined;
|
|
688
|
+
return parseDeviceVersion(this.state.versions.bootloader).join('.');
|
|
538
689
|
}
|
|
539
690
|
|
|
540
691
|
getCurrentSafetyChecks() {
|
|
541
|
-
return this.
|
|
692
|
+
return this.state?.settings.safetyChecks;
|
|
542
693
|
}
|
|
543
694
|
|
|
544
695
|
getCurrentMethodVersionRange(
|
|
@@ -551,6 +702,7 @@ export class Device extends EventEmitter {
|
|
|
551
702
|
// Most-specific model first; must match getMethodVersionRange in deviceInfoUtils,
|
|
552
703
|
// otherwise e.g. Classic1s resolves the looser model_mini range before model_classic1s.
|
|
553
704
|
const modelFallbacks: IDeviceModel[] = [
|
|
705
|
+
'model_pro2',
|
|
554
706
|
'model_classic1s',
|
|
555
707
|
'model_classic',
|
|
556
708
|
'model_mini',
|
|
@@ -570,7 +722,8 @@ export class Device extends EventEmitter {
|
|
|
570
722
|
if (
|
|
571
723
|
deviceType === EDeviceType.Touch ||
|
|
572
724
|
deviceType === EDeviceType.Pro ||
|
|
573
|
-
deviceType === EDeviceType.Pro2
|
|
725
|
+
deviceType === EDeviceType.Pro2 ||
|
|
726
|
+
deviceType === EDeviceType.Neo
|
|
574
727
|
) {
|
|
575
728
|
return { support: true };
|
|
576
729
|
}
|
|
@@ -583,13 +736,12 @@ export class Device extends EventEmitter {
|
|
|
583
736
|
}
|
|
584
737
|
|
|
585
738
|
supportInputPinOnSoftware(): SupportFeatureType {
|
|
586
|
-
if (this.features) return supportInputPinOnSoftware(this.features);
|
|
587
|
-
|
|
588
739
|
const deviceType = this.getCurrentDeviceType();
|
|
589
740
|
if (
|
|
590
741
|
deviceType === EDeviceType.Touch ||
|
|
591
742
|
deviceType === EDeviceType.Pro ||
|
|
592
|
-
deviceType === EDeviceType.Pro2
|
|
743
|
+
deviceType === EDeviceType.Pro2 ||
|
|
744
|
+
deviceType === EDeviceType.Neo
|
|
593
745
|
) {
|
|
594
746
|
return { support: false };
|
|
595
747
|
}
|
|
@@ -602,15 +754,12 @@ export class Device extends EventEmitter {
|
|
|
602
754
|
}
|
|
603
755
|
|
|
604
756
|
supportModifyHomescreen(): SupportFeatureType {
|
|
605
|
-
// Pro2
|
|
606
|
-
//
|
|
607
|
-
// 包含 homescreen 字段,V2 固件从首个版本即支持修改主屏。
|
|
757
|
+
// Pro2 has an independent 1.x version line and must not use the Touch/Pro 3.4.0
|
|
758
|
+
// threshold. ApplySettings includes homescreen from the first V2 firmware version.
|
|
608
759
|
if (this.isProtocolV2()) {
|
|
609
760
|
return { support: true };
|
|
610
761
|
}
|
|
611
762
|
|
|
612
|
-
if (this.features) return supportModifyHomescreen(this.features);
|
|
613
|
-
|
|
614
763
|
const deviceType = this.getCurrentDeviceType();
|
|
615
764
|
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
|
|
616
765
|
return { support: true };
|
|
@@ -622,29 +771,29 @@ export class Device extends EventEmitter {
|
|
|
622
771
|
};
|
|
623
772
|
}
|
|
624
773
|
|
|
625
|
-
private generateStateKey(deviceId: string, passphraseState?: string) {
|
|
626
|
-
if (passphraseState) {
|
|
627
|
-
return `${deviceId}@${passphraseState}`;
|
|
628
|
-
}
|
|
629
|
-
return deviceId;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
774
|
private getSessionCacheDeviceKey(_deviceId?: string) {
|
|
633
775
|
const deviceId = _deviceId || this.getCurrentDeviceId();
|
|
634
776
|
if (deviceId) return deviceId;
|
|
635
777
|
if (this.isProtocolV2()) {
|
|
636
|
-
return this.originalDescriptor.path
|
|
778
|
+
return this.originalDescriptor.path;
|
|
637
779
|
}
|
|
638
780
|
return undefined;
|
|
639
781
|
}
|
|
640
782
|
|
|
783
|
+
private reconcileSessionCacheDeviceIdentity(previousDeviceId?: string) {
|
|
784
|
+
deviceWalletSessionStore.reconcileDeviceIdentity({
|
|
785
|
+
temporaryKey: this.isProtocolV2() ? this.originalDescriptor.path : undefined,
|
|
786
|
+
previousDeviceId,
|
|
787
|
+
nextDeviceId: this.getCurrentDeviceId(),
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
|
|
641
791
|
getInternalState(_deviceId?: string) {
|
|
642
|
-
Log.debug('getInternalState session cache: ', deviceSessionCache);
|
|
643
792
|
Log.debug(
|
|
644
793
|
'getInternalState session param: ',
|
|
645
794
|
`device_id: ${_deviceId}`,
|
|
646
|
-
`
|
|
647
|
-
`
|
|
795
|
+
`currentDeviceId: ${this.getCurrentDeviceId()}`,
|
|
796
|
+
`hasPassphraseState: ${Boolean(this.passphraseState)}`
|
|
648
797
|
);
|
|
649
798
|
|
|
650
799
|
const deviceId = this.getSessionCacheDeviceKey(_deviceId);
|
|
@@ -657,8 +806,13 @@ export class Device extends EventEmitter {
|
|
|
657
806
|
// downstream call carries it and hits the primary lookup below.
|
|
658
807
|
if (!this.passphraseState) return undefined;
|
|
659
808
|
|
|
660
|
-
|
|
661
|
-
|
|
809
|
+
return deviceWalletSessionStore.get(deviceId, this.passphraseState);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
getStandardInternalState(_deviceId?: string) {
|
|
813
|
+
const deviceId = this.getSessionCacheDeviceKey(_deviceId);
|
|
814
|
+
if (!deviceId) return undefined;
|
|
815
|
+
return deviceWalletSessionStore.getStandard(deviceId);
|
|
662
816
|
}
|
|
663
817
|
|
|
664
818
|
// attach to pin to fix internal state
|
|
@@ -667,46 +821,45 @@ export class Device extends EventEmitter {
|
|
|
667
821
|
passphraseState: string | undefined,
|
|
668
822
|
deviceId: string | undefined,
|
|
669
823
|
sessionId: string | null = null,
|
|
670
|
-
featuresSessionId: string | null = null
|
|
824
|
+
featuresSessionId: string | null = null,
|
|
825
|
+
walletType: 'standard' | 'hidden' = 'hidden'
|
|
671
826
|
) {
|
|
672
827
|
Log.debug(
|
|
673
828
|
'updateInternalState session param: ',
|
|
674
829
|
`device_id: ${deviceId}`,
|
|
675
830
|
`enablePassphrase: ${enablePassphrase}`,
|
|
676
|
-
`
|
|
677
|
-
`
|
|
678
|
-
`
|
|
831
|
+
`hasPassphraseState: ${Boolean(passphraseState)}`,
|
|
832
|
+
`hasSessionId: ${Boolean(sessionId)}`,
|
|
833
|
+
`hasFeaturesSessionId: ${Boolean(featuresSessionId)}`
|
|
679
834
|
);
|
|
680
835
|
|
|
681
836
|
const cacheDeviceKey = this.getSessionCacheDeviceKey(deviceId);
|
|
682
837
|
if (!cacheDeviceKey) return;
|
|
683
838
|
|
|
684
839
|
if (enablePassphrase) {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
840
|
+
const walletSessionId =
|
|
841
|
+
sessionId || featuresSessionId || deviceWalletSessionStore.getPending(cacheDeviceKey);
|
|
842
|
+
if (walletType === 'standard') {
|
|
843
|
+
deviceWalletSessionStore.setStandard(
|
|
844
|
+
cacheDeviceKey,
|
|
845
|
+
passphraseState,
|
|
846
|
+
walletSessionId ?? undefined
|
|
847
|
+
);
|
|
848
|
+
} else {
|
|
849
|
+
deviceWalletSessionStore.set(cacheDeviceKey, passphraseState, walletSessionId ?? undefined);
|
|
691
850
|
}
|
|
692
851
|
}
|
|
693
852
|
|
|
694
|
-
|
|
695
|
-
const oldKey = `${cacheDeviceKey}`;
|
|
696
|
-
if (deviceSessionCache[oldKey]) {
|
|
697
|
-
delete deviceSessionCache[oldKey];
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
Log.debug('updateInternalState session cache: ', deviceSessionCache);
|
|
853
|
+
deviceWalletSessionStore.deletePending(cacheDeviceKey);
|
|
701
854
|
}
|
|
702
855
|
|
|
703
856
|
private setInternalState(state: string, initSession?: boolean) {
|
|
704
857
|
Log.debug(
|
|
705
858
|
'setInternalState session param: ',
|
|
706
|
-
`
|
|
859
|
+
`hasState: ${Boolean(state)}`,
|
|
707
860
|
`initSession: ${initSession}`,
|
|
708
|
-
`deviceId: ${this.
|
|
709
|
-
`
|
|
861
|
+
`deviceId: ${this.getCurrentDeviceId()}`,
|
|
862
|
+
`hasPassphraseState: ${Boolean(this.passphraseState)}`
|
|
710
863
|
);
|
|
711
864
|
|
|
712
865
|
if (!this.passphraseState && !initSession) return;
|
|
@@ -714,12 +867,11 @@ export class Device extends EventEmitter {
|
|
|
714
867
|
const deviceId = this.getSessionCacheDeviceKey();
|
|
715
868
|
if (!deviceId) return;
|
|
716
869
|
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
if (
|
|
720
|
-
|
|
870
|
+
if (this.passphraseState) {
|
|
871
|
+
deviceWalletSessionStore.set(deviceId, this.passphraseState, state);
|
|
872
|
+
} else if (initSession) {
|
|
873
|
+
deviceWalletSessionStore.setPending(deviceId, state);
|
|
721
874
|
}
|
|
722
|
-
Log.debug('setInternalState done session cache: ', deviceSessionCache);
|
|
723
875
|
}
|
|
724
876
|
|
|
725
877
|
clearInternalState(_deviceId?: string) {
|
|
@@ -727,67 +879,80 @@ export class Device extends EventEmitter {
|
|
|
727
879
|
|
|
728
880
|
const deviceId = this.getSessionCacheDeviceKey(_deviceId);
|
|
729
881
|
if (!deviceId) return;
|
|
730
|
-
|
|
731
|
-
delete deviceSessionCache[key];
|
|
882
|
+
deviceWalletSessionStore.deletePending(deviceId);
|
|
732
883
|
|
|
733
884
|
if (this.passphraseState) {
|
|
734
|
-
|
|
735
|
-
delete deviceSessionCache[usePassKey];
|
|
885
|
+
deviceWalletSessionStore.delete(deviceId, this.passphraseState);
|
|
736
886
|
}
|
|
737
887
|
}
|
|
738
888
|
|
|
889
|
+
clearStandardInternalState(_deviceId?: string) {
|
|
890
|
+
const deviceId = this.getSessionCacheDeviceKey(_deviceId);
|
|
891
|
+
if (!deviceId) return;
|
|
892
|
+
deviceWalletSessionStore.deleteStandard(deviceId);
|
|
893
|
+
}
|
|
894
|
+
|
|
739
895
|
async initialize(options?: InitOptions) {
|
|
740
|
-
// Protocol V2
|
|
896
|
+
// Protocol V2 does not support legacy Initialize; use its dedicated flow.
|
|
741
897
|
if (this.isProtocolV2()) {
|
|
742
898
|
this.passphraseState = options?.passphraseState;
|
|
743
|
-
if (this.
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
899
|
+
if (this.state && !options?.initSession && !this.protocolV2StateNeedsReload) {
|
|
900
|
+
if (this.state.status.mode === 'bootloader' || this.state.status.mode === 'romloader') {
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
// Normal calls reuse the cache. Explicit getDeviceState refreshes, unlock flow,
|
|
904
|
+
// and device events update dynamic state without polling on every SDK call.
|
|
748
905
|
return;
|
|
749
906
|
}
|
|
750
|
-
await this._initializeProtocolV2();
|
|
907
|
+
await this._initializeProtocolV2(options);
|
|
908
|
+
this.protocolV2StateNeedsReload = false;
|
|
751
909
|
return;
|
|
752
910
|
}
|
|
753
911
|
|
|
754
|
-
|
|
912
|
+
try {
|
|
913
|
+
const callInitialize = async (payload: Record<string, unknown>, initSession?: boolean) => {
|
|
914
|
+
const initStartAt = Date.now();
|
|
915
|
+
const { message } = await this.commands.typedCall('Initialize', 'Features', payload, {
|
|
916
|
+
// iOS BLE bound devices can need close to 20 seconds.
|
|
917
|
+
timeoutMs: options?.timeoutMs ?? 25 * 1000,
|
|
918
|
+
});
|
|
919
|
+
this.setLastInitializeDuration(Date.now() - initStartAt);
|
|
920
|
+
this._updateFeatures(message, initSession);
|
|
921
|
+
await TransportManager.reconfigure(this.features);
|
|
922
|
+
};
|
|
755
923
|
|
|
756
|
-
|
|
924
|
+
const expectedDeviceId = options?.deviceId;
|
|
925
|
+
if (expectedDeviceId) {
|
|
926
|
+
// 先只读校验物理设备身份;钱包上下文仍由下方携带完整参数的
|
|
927
|
+
// Initialize 选择,避免标准钱包请求复用此前的隐藏钱包上下文。
|
|
928
|
+
this.passphraseState = undefined;
|
|
929
|
+
const { message } = await this.commands.typedCall('GetFeatures', 'Features', {});
|
|
930
|
+
this._updateFeatures(message);
|
|
931
|
+
await TransportManager.reconfigure(this.features);
|
|
932
|
+
if (!this.checkDeviceId(expectedDeviceId)) {
|
|
933
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
757
936
|
|
|
758
|
-
|
|
759
|
-
this.clearInternalState(options?.deviceId);
|
|
760
|
-
}
|
|
937
|
+
this.passphraseState = options?.passphraseState;
|
|
761
938
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
payload.session_id = internalState;
|
|
766
|
-
}
|
|
939
|
+
if (options?.initSession) {
|
|
940
|
+
this.clearInternalState(options?.deviceId);
|
|
941
|
+
}
|
|
767
942
|
|
|
768
|
-
|
|
769
|
-
payload
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
943
|
+
const internalState = this.getInternalState(options?.deviceId);
|
|
944
|
+
const payload: Record<string, unknown> = {
|
|
945
|
+
passphrase_state: options?.passphraseState,
|
|
946
|
+
is_contains_attach: true,
|
|
947
|
+
};
|
|
948
|
+
if (internalState) {
|
|
949
|
+
payload.session_id = internalState;
|
|
950
|
+
}
|
|
951
|
+
if (options?.deriveCardano) {
|
|
952
|
+
payload.derive_cardano = true;
|
|
953
|
+
}
|
|
773
954
|
|
|
774
|
-
|
|
775
|
-
try {
|
|
776
|
-
// @ts-expect-error
|
|
777
|
-
const { message } = await Promise.race([
|
|
778
|
-
this.commands.typedCall('Initialize', 'Features', payload),
|
|
779
|
-
new Promise((_, reject) => {
|
|
780
|
-
setTimeout(() => {
|
|
781
|
-
reject(ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed));
|
|
782
|
-
// iOS ble bound device timeout 20s
|
|
783
|
-
}, 25 * 1000);
|
|
784
|
-
}),
|
|
785
|
-
]);
|
|
786
|
-
|
|
787
|
-
const initCostMs = Date.now() - initStartAt;
|
|
788
|
-
this.setLastInitializeDuration(initCostMs);
|
|
789
|
-
this._updateFeatures(message, options?.initSession);
|
|
790
|
-
await TransportManager.reconfigure(this.features);
|
|
955
|
+
await callInitialize(payload, options?.initSession);
|
|
791
956
|
} catch (error) {
|
|
792
957
|
Log.error('Initialization failed:', error);
|
|
793
958
|
throw error;
|
|
@@ -797,57 +962,38 @@ export class Device extends EventEmitter {
|
|
|
797
962
|
/**
|
|
798
963
|
* Device initialization over Protocol V2.
|
|
799
964
|
*
|
|
800
|
-
* Protocol V2
|
|
801
|
-
*
|
|
965
|
+
* Protocol V2 bypasses legacy Initialize/GetFeatures and builds its canonical
|
|
966
|
+
* features state directly from DeviceInfoGet.
|
|
802
967
|
*/
|
|
803
|
-
private async _initializeProtocolV2() {
|
|
968
|
+
private async _initializeProtocolV2(options?: InitOptions) {
|
|
804
969
|
Log.debug('Initialize device via Protocol V2 features adapter');
|
|
805
970
|
|
|
806
971
|
try {
|
|
807
|
-
//
|
|
808
|
-
//
|
|
809
|
-
// 且 reject 后底层调用仍会残留。
|
|
972
|
+
// typedCall applies the request timeout. An outer Promise.race would leak its
|
|
973
|
+
// timer and leave the underlying call active after rejection.
|
|
810
974
|
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
811
975
|
commands: this.commands,
|
|
976
|
+
timeoutMs: options?.protocolV2DeviceInfoTimeoutMs,
|
|
812
977
|
});
|
|
813
|
-
//
|
|
814
|
-
//
|
|
815
|
-
const features = this.
|
|
978
|
+
// The default request excludes SE/hash data and therefore uses basic scope.
|
|
979
|
+
// Full version and verification data require getDeviceState({ scope: 'firmware' }).
|
|
980
|
+
const features = await this.probeProtocolV2RuntimeState(
|
|
981
|
+
deviceInfo,
|
|
982
|
+
options?.protocolV2DeviceInfoTimeoutMs
|
|
983
|
+
);
|
|
816
984
|
Log.debug('Protocol V2 features:', features);
|
|
817
|
-
this.featuresNeedsReload = false;
|
|
818
985
|
} catch (error) {
|
|
819
986
|
Log.error('Protocol V2 initialization failed:', error);
|
|
820
987
|
throw error;
|
|
821
988
|
}
|
|
822
989
|
}
|
|
823
990
|
|
|
824
|
-
/**
|
|
825
|
-
* Protocol V2 的轻量状态刷新(每次 run 前调用)。
|
|
826
|
-
*
|
|
827
|
-
* 请求 hw + bt + status(不含 fw/SE target):status 提供 init_states / label /
|
|
828
|
-
* passphrase_protection 等会在设备端变化的字段;hw/bt 提供 serialNo / bleName。
|
|
829
|
-
* versions 为空时按字段级合并保留旧值,verify 数据不会被降级。
|
|
830
|
-
*/
|
|
831
|
-
private async _refreshProtocolV2Status() {
|
|
832
|
-
try {
|
|
833
|
-
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
834
|
-
commands: this.commands,
|
|
835
|
-
request: PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST,
|
|
836
|
-
});
|
|
837
|
-
const features = this.updateProtocolV2Features(deviceInfo);
|
|
838
|
-
Log.debug('Protocol V2 features (status refresh):', features);
|
|
839
|
-
} catch (error) {
|
|
840
|
-
Log.error('Protocol V2 status refresh failed:', error);
|
|
841
|
-
throw error;
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
|
|
845
991
|
async getFeatures() {
|
|
846
992
|
if (this.isProtocolV2()) {
|
|
847
993
|
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
848
994
|
commands: this.commands,
|
|
849
995
|
});
|
|
850
|
-
return this.
|
|
996
|
+
return this.probeProtocolV2RuntimeState(deviceInfo);
|
|
851
997
|
}
|
|
852
998
|
|
|
853
999
|
const { message } = await this.commands.typedCall('GetFeatures', 'Features', {});
|
|
@@ -855,36 +1001,332 @@ export class Device extends EventEmitter {
|
|
|
855
1001
|
return this.features;
|
|
856
1002
|
}
|
|
857
1003
|
|
|
1004
|
+
async getDeviceState(params: DeviceStateReadOptions = {}) {
|
|
1005
|
+
const refresh = new Set(params.refreshSections ?? []);
|
|
1006
|
+
const getProtocolV2DeviceInfoRequest = () => {
|
|
1007
|
+
if (refresh.has('verification')) return PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST;
|
|
1008
|
+
if (refresh.has('versions')) return PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST;
|
|
1009
|
+
return PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST;
|
|
1010
|
+
};
|
|
1011
|
+
let initializedWithDeviceInfo = false;
|
|
1012
|
+
let refreshedDeviceInfo: ProtocolV2DeviceInfo | undefined;
|
|
1013
|
+
|
|
1014
|
+
if (!this.state) {
|
|
1015
|
+
if (this.isProtocolV2()) {
|
|
1016
|
+
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
1017
|
+
commands: this.commands,
|
|
1018
|
+
request: getProtocolV2DeviceInfoRequest(),
|
|
1019
|
+
});
|
|
1020
|
+
await this.probeProtocolV2RuntimeState(deviceInfo);
|
|
1021
|
+
refreshedDeviceInfo = deviceInfo;
|
|
1022
|
+
initializedWithDeviceInfo = true;
|
|
1023
|
+
} else {
|
|
1024
|
+
await this.getFeatures();
|
|
1025
|
+
}
|
|
1026
|
+
} else if (!this.isProtocolV2() && refresh.size > 0) {
|
|
1027
|
+
await this.getFeatures();
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
const supportsProtocolV1OnekeyFeatures =
|
|
1031
|
+
this.getCurrentDeviceType() === EDeviceType.Touch ||
|
|
1032
|
+
this.getCurrentDeviceType() === EDeviceType.Pro;
|
|
1033
|
+
if (!this.isProtocolV2() && refresh.has('verification') && supportsProtocolV1OnekeyFeatures) {
|
|
1034
|
+
const { message } = await this.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
|
|
1035
|
+
this.updateState(mapProtocolV1OnekeyFeaturesToState(message), 'device-info');
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
if (this.isProtocolV2()) {
|
|
1039
|
+
const refreshDeviceInfo =
|
|
1040
|
+
refresh.has('identity') || refresh.has('versions') || refresh.has('verification');
|
|
1041
|
+
if (refreshDeviceInfo && !initializedWithDeviceInfo) {
|
|
1042
|
+
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
1043
|
+
commands: this.commands,
|
|
1044
|
+
request: getProtocolV2DeviceInfoRequest(),
|
|
1045
|
+
});
|
|
1046
|
+
refreshedDeviceInfo = deviceInfo;
|
|
1047
|
+
if (!refresh.has('status')) {
|
|
1048
|
+
this.updateState(
|
|
1049
|
+
mapProtocolV2DeviceInfoToState(deviceInfo, this.state?.status.mode),
|
|
1050
|
+
'device-info'
|
|
1051
|
+
);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
if (refresh.has('status') && !initializedWithDeviceInfo) {
|
|
1056
|
+
await this.probeProtocolV2RuntimeState(refreshedDeviceInfo);
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
if (refresh.has('settings') && this.state?.status.mode === 'normal') {
|
|
1060
|
+
const { message } = await this.commands.typedCall(
|
|
1061
|
+
'DeviceSettingsGet',
|
|
1062
|
+
'DeviceSettings',
|
|
1063
|
+
{}
|
|
1064
|
+
);
|
|
1065
|
+
this.updateState(mapDeviceSettingsToState(message), 'settings-read');
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
if (!this.state) {
|
|
1070
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
|
|
1071
|
+
}
|
|
1072
|
+
return params.includeRaw ? cloneDeviceState(this.state) : createPublicDeviceState(this.state);
|
|
1073
|
+
}
|
|
1074
|
+
|
|
858
1075
|
_updateFeatures(protoFeatures: PROTO.Features | Features, initSession?: boolean) {
|
|
1076
|
+
const previousDeviceId = this.getCurrentDeviceId();
|
|
859
1077
|
let feat =
|
|
860
1078
|
'protocol' in protoFeatures
|
|
861
1079
|
? protoFeatures
|
|
862
1080
|
: buildProtocolV1FeaturesPayload(protoFeatures, this.features);
|
|
863
1081
|
|
|
864
|
-
// GetFeatures doesn't return 'session_id'
|
|
865
|
-
if (this.features?.sessionId && !feat.sessionId) {
|
|
866
|
-
feat.sessionId = this.features.sessionId;
|
|
867
|
-
}
|
|
868
|
-
if (this.getCurrentDeviceId() && feat.sessionId) {
|
|
869
|
-
this.setInternalState(feat.sessionId, initSession);
|
|
870
|
-
}
|
|
871
1082
|
feat.unlocked = feat.unlocked ?? true;
|
|
872
1083
|
|
|
873
1084
|
feat = fixFeaturesFirmwareVersion(feat);
|
|
874
1085
|
|
|
875
|
-
this.
|
|
876
|
-
this.
|
|
877
|
-
|
|
1086
|
+
this.updateState(mapFeaturesToState(feat), 'initialize');
|
|
1087
|
+
this.reconcileSessionCacheDeviceIdentity(previousDeviceId);
|
|
1088
|
+
if (feat.deviceId && feat.sessionId) {
|
|
1089
|
+
this.setInternalState(feat.sessionId, initSession);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
updateState(patch: DeviceStatePatch, source: DeviceStateUpdateSource) {
|
|
1094
|
+
const result = this.stateStore.update(patch, source);
|
|
1095
|
+
if (result.changedKeys.length === 0) return result.state;
|
|
1096
|
+
|
|
1097
|
+
const event: DeviceStateEvent = {
|
|
1098
|
+
connectId: this.getConnectId() ?? null,
|
|
1099
|
+
state: createPublicDeviceState(result.state),
|
|
1100
|
+
revision: result.revision,
|
|
1101
|
+
source,
|
|
1102
|
+
changedKeys: result.changedKeys,
|
|
1103
|
+
};
|
|
1104
|
+
Log.debug('Device state patch committed', {
|
|
1105
|
+
source,
|
|
1106
|
+
keys: result.changedKeys,
|
|
1107
|
+
});
|
|
1108
|
+
this.emit(DEVICE.STATE, this, event);
|
|
1109
|
+
if (result.state.protocol === 'V1') {
|
|
1110
|
+
this.emit(DEVICE.FEATURES, this, projectFeatures(result.state));
|
|
1111
|
+
}
|
|
1112
|
+
return result.state;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
updateFeaturesPatch(patch: Partial<Features>, source: DeviceStateUpdateSource) {
|
|
1116
|
+
const currentFeatures = this.features;
|
|
1117
|
+
if (!currentFeatures) return undefined;
|
|
1118
|
+
|
|
1119
|
+
const features = mergeDeviceFeaturesPatch(currentFeatures, patch);
|
|
1120
|
+
if (features === currentFeatures) return currentFeatures;
|
|
1121
|
+
|
|
1122
|
+
const normalized = fixFeaturesFirmwareVersion(features);
|
|
1123
|
+
this.updateState(mapFeaturesToState(normalized), source);
|
|
1124
|
+
return this.features;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
async ensureProtocolV2RuntimeContext(timeoutMs?: number): Promise<ProtocolInfo> {
|
|
1128
|
+
const cachedProtocolInfo =
|
|
1129
|
+
this.protocolV2RuntimeContext ??
|
|
1130
|
+
(!this.protocolV2StateNeedsReload
|
|
1131
|
+
? this.state?.raw?.protocolV2ProtocolInfo ?? undefined
|
|
1132
|
+
: undefined);
|
|
1133
|
+
if (cachedProtocolInfo) {
|
|
1134
|
+
this.protocolV2RuntimeContext = cachedProtocolInfo;
|
|
1135
|
+
return cachedProtocolInfo;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
if (this.protocolV2RuntimeContextPromise) {
|
|
1139
|
+
return this.protocolV2RuntimeContextPromise;
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
const requestToken = {};
|
|
1143
|
+
const pendingRequest = (async () => {
|
|
1144
|
+
const protocolInfo = await requestProtocolV2ProtocolInfo({
|
|
1145
|
+
commands: this.commands,
|
|
1146
|
+
timeoutMs,
|
|
1147
|
+
});
|
|
1148
|
+
if (this.protocolV2RuntimeContextRequestToken !== requestToken) {
|
|
1149
|
+
throw ERRORS.TypedError(
|
|
1150
|
+
HardwareErrorCode.DeviceInitializeFailed,
|
|
1151
|
+
'Protocol V2 runtime context was invalidated while loading.'
|
|
1152
|
+
);
|
|
1153
|
+
}
|
|
1154
|
+
this.protocolV2RuntimeContext = protocolInfo;
|
|
1155
|
+
return protocolInfo;
|
|
1156
|
+
})();
|
|
1157
|
+
this.protocolV2RuntimeContextRequestToken = requestToken;
|
|
1158
|
+
this.protocolV2RuntimeContextPromise = pendingRequest;
|
|
1159
|
+
|
|
1160
|
+
try {
|
|
1161
|
+
return await pendingRequest;
|
|
1162
|
+
} finally {
|
|
1163
|
+
if (this.protocolV2RuntimeContextPromise === pendingRequest) {
|
|
1164
|
+
this.protocolV2RuntimeContextPromise = undefined;
|
|
1165
|
+
}
|
|
1166
|
+
if (this.protocolV2RuntimeContextRequestToken === requestToken) {
|
|
1167
|
+
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
878
1170
|
}
|
|
879
1171
|
|
|
880
|
-
|
|
881
|
-
const
|
|
882
|
-
|
|
1172
|
+
async probeProtocolV2RuntimeState(deviceInfo?: ProtocolV2DeviceInfo, timeoutMs?: number) {
|
|
1173
|
+
const protocolInfo = await this.ensureProtocolV2RuntimeContext(timeoutMs);
|
|
1174
|
+
const runtimeMode = getProtocolV2RuntimeMode(protocolInfo);
|
|
1175
|
+
const runtimeDeviceInfo = deviceInfo ?? this.state?.raw?.protocolV2DeviceInfo;
|
|
1176
|
+
const protocolV2DeviceType = runtimeDeviceInfo
|
|
1177
|
+
? resolveProtocolV2DeviceIdentity(runtimeDeviceInfo.hw?.Device_type).deviceType
|
|
1178
|
+
: this.getCurrentDeviceType();
|
|
1179
|
+
if (
|
|
1180
|
+
runtimeMode === 'romloader' &&
|
|
1181
|
+
protocolV2DeviceType !== EDeviceType.Pro2 &&
|
|
1182
|
+
protocolV2DeviceType !== EDeviceType.Neo
|
|
1183
|
+
) {
|
|
1184
|
+
throw ERRORS.TypedError(
|
|
1185
|
+
HardwareErrorCode.DeviceInitializeFailed,
|
|
1186
|
+
'Protocol V2 romloader mode is only supported for Pro2 and Neo.'
|
|
1187
|
+
);
|
|
1188
|
+
}
|
|
1189
|
+
const deviceStatusSupported = supportsProtocolV2Message(
|
|
1190
|
+
protocolInfo,
|
|
1191
|
+
PROTOCOL_V2_DEVICE_STATUS_GET_MESSAGE_TYPE
|
|
1192
|
+
);
|
|
1193
|
+
|
|
1194
|
+
if (runtimeMode === 'bootloader' || runtimeMode === 'romloader') {
|
|
1195
|
+
return this.updateProtocolV2Features(deviceInfo, null, runtimeMode, protocolInfo);
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
if (!deviceStatusSupported) {
|
|
1199
|
+
if (runtimeMode === 'normal') {
|
|
1200
|
+
return this.updateProtocolV2Features(deviceInfo, null, runtimeMode, protocolInfo);
|
|
1201
|
+
}
|
|
1202
|
+
throw ERRORS.TypedError(
|
|
1203
|
+
HardwareErrorCode.DeviceInitializeFailed,
|
|
1204
|
+
`Unknown Protocol V2 build fingerprint without DeviceStatusGet capability: ${protocolInfo.build_fingerprint}`
|
|
1205
|
+
);
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
let deviceStatus: DeviceStatus;
|
|
1209
|
+
try {
|
|
1210
|
+
deviceStatus = await requestProtocolV2DeviceStatus({
|
|
1211
|
+
commands: this.commands,
|
|
1212
|
+
timeoutMs,
|
|
1213
|
+
});
|
|
1214
|
+
} catch (error) {
|
|
1215
|
+
if (runtimeMode === undefined && isProtocolV2DeviceStatusUnsupportedError(error)) {
|
|
1216
|
+
return this.updateProtocolV2Features(deviceInfo, null, 'bootloader', protocolInfo);
|
|
1217
|
+
}
|
|
1218
|
+
throw error;
|
|
1219
|
+
}
|
|
1220
|
+
return this.updateProtocolV2Features(deviceInfo, deviceStatus, 'normal', protocolInfo);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
updateProtocolV2Features(
|
|
1224
|
+
deviceInfo?: ProtocolV2DeviceInfo,
|
|
1225
|
+
deviceStatus?: DeviceStatus | null,
|
|
1226
|
+
runtimeMode?: ProtocolV2RuntimeMode,
|
|
1227
|
+
protocolInfo?: ProtocolInfo
|
|
1228
|
+
) {
|
|
1229
|
+
const previousDeviceId = this.getCurrentDeviceId();
|
|
1230
|
+
const resolvedMode = runtimeMode ?? (deviceStatus ? 'normal' : this.state?.status.mode);
|
|
1231
|
+
if (deviceInfo) {
|
|
1232
|
+
this.updateState(mapProtocolV2DeviceInfoToState(deviceInfo, resolvedMode), 'device-info');
|
|
1233
|
+
}
|
|
1234
|
+
if (protocolInfo) {
|
|
1235
|
+
this.updateState({ raw: { protocolV2ProtocolInfo: protocolInfo } }, 'device-info');
|
|
1236
|
+
}
|
|
1237
|
+
if (deviceStatus) {
|
|
1238
|
+
this.updateState(mapProtocolV2DeviceStatusToState(deviceStatus), 'device-status');
|
|
1239
|
+
}
|
|
1240
|
+
this.reconcileSessionCacheDeviceIdentity(previousDeviceId);
|
|
1241
|
+
return this.features as Features;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
updateProtocolV2Status(status: DeviceStatus) {
|
|
1245
|
+
const previousDeviceInfo = this.state?.raw?.protocolV2DeviceInfo;
|
|
1246
|
+
const previousStatus = this.state?.raw?.protocolV2DeviceStatus;
|
|
1247
|
+
return this.updateProtocolV2Features(previousDeviceInfo, {
|
|
1248
|
+
...previousStatus,
|
|
1249
|
+
...status,
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
markTransportDisconnected() {
|
|
1254
|
+
this.deviceAcquired = false;
|
|
1255
|
+
if (!this.isProtocolV2()) return;
|
|
1256
|
+
this.protocolV2StateNeedsReload = true;
|
|
1257
|
+
this.protocolV2RuntimeContext = undefined;
|
|
1258
|
+
this.protocolV2RuntimeContextPromise = undefined;
|
|
1259
|
+
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
1260
|
+
this.clearPreInitialized();
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
invalidateAfterWipe() {
|
|
1264
|
+
const deviceId = this.getCurrentDeviceId();
|
|
1265
|
+
if (deviceId) {
|
|
1266
|
+
deviceWalletSessionStore.deleteDevice(deviceId);
|
|
1267
|
+
}
|
|
1268
|
+
if (this.isProtocolV2()) {
|
|
1269
|
+
if (this.originalDescriptor.path !== deviceId) {
|
|
1270
|
+
deviceWalletSessionStore.deleteDevice(this.originalDescriptor.path);
|
|
1271
|
+
}
|
|
1272
|
+
this.protocolV2StateNeedsReload = true;
|
|
1273
|
+
this.protocolV2RuntimeContext = undefined;
|
|
1274
|
+
this.protocolV2RuntimeContextPromise = undefined;
|
|
1275
|
+
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
this.passphraseState = undefined;
|
|
1279
|
+
this.stateStore = new DeviceStateStore();
|
|
1280
|
+
this.clearPreInitialized();
|
|
1281
|
+
this.needReloadDevice = true;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
markProtocolV2Reboot(rebootType: DeviceRebootType) {
|
|
1285
|
+
if (!this.isProtocolV2()) return;
|
|
1286
|
+
|
|
1287
|
+
this.protocolV2StateNeedsReload = true;
|
|
1288
|
+
this.protocolV2RuntimeContext = undefined;
|
|
1289
|
+
this.protocolV2RuntimeContextPromise = undefined;
|
|
1290
|
+
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
1291
|
+
this.clearPreInitialized();
|
|
1292
|
+
let loaderMode: 'bootloader' | 'romloader' | undefined;
|
|
1293
|
+
if (rebootType === DeviceRebootType.Bootloader) {
|
|
1294
|
+
loaderMode = 'bootloader';
|
|
1295
|
+
} else if (rebootType === DeviceRebootType.Romloader) {
|
|
1296
|
+
loaderMode = 'romloader';
|
|
1297
|
+
}
|
|
1298
|
+
if (loaderMode) {
|
|
1299
|
+
this.updateState(
|
|
1300
|
+
{
|
|
1301
|
+
identity: { deviceId: null },
|
|
1302
|
+
status: {
|
|
1303
|
+
mode: loaderMode,
|
|
1304
|
+
initialized: null,
|
|
1305
|
+
unlocked: null,
|
|
1306
|
+
firmwarePresent: null,
|
|
1307
|
+
backupRequired: null,
|
|
1308
|
+
noBackup: null,
|
|
1309
|
+
unfinishedBackup: null,
|
|
1310
|
+
recoveryMode: null,
|
|
1311
|
+
passphraseProtection: null,
|
|
1312
|
+
pinProtection: null,
|
|
1313
|
+
attachToPinEnabled: null,
|
|
1314
|
+
unlockedAttachPin: null,
|
|
1315
|
+
},
|
|
1316
|
+
raw: { protocolV2ProtocolInfo: null, protocolV2DeviceStatus: null },
|
|
1317
|
+
},
|
|
1318
|
+
'transport-reconnect'
|
|
1319
|
+
);
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
this.updateState(
|
|
1324
|
+
{
|
|
1325
|
+
status: { mode: 'normal', unlocked: null },
|
|
1326
|
+
raw: { protocolV2ProtocolInfo: null, protocolV2DeviceStatus: null },
|
|
1327
|
+
},
|
|
1328
|
+
'transport-reconnect'
|
|
883
1329
|
);
|
|
884
|
-
this.features = features;
|
|
885
|
-
this.featuresNeedsReload = false;
|
|
886
|
-
this.emit(DEVICE.FEATURES, this, features);
|
|
887
|
-
return features;
|
|
888
1330
|
}
|
|
889
1331
|
|
|
890
1332
|
/**
|
|
@@ -905,8 +1347,7 @@ export class Device extends EventEmitter {
|
|
|
905
1347
|
}
|
|
906
1348
|
|
|
907
1349
|
if (forceUpdate) {
|
|
908
|
-
//
|
|
909
|
-
// 不能让覆盖丢掉已探测的协议结果。
|
|
1350
|
+
// Enumerated descriptors may omit protocolType, so preserve an actively probed value.
|
|
910
1351
|
this.originalDescriptor = {
|
|
911
1352
|
...descriptor,
|
|
912
1353
|
protocolType: descriptor.protocolType ?? this.originalDescriptor.protocolType,
|
|
@@ -931,19 +1372,43 @@ export class Device extends EventEmitter {
|
|
|
931
1372
|
|
|
932
1373
|
options = parseRunOptions(options);
|
|
933
1374
|
|
|
934
|
-
|
|
935
|
-
|
|
1375
|
+
const runPromise = createDeferred<void>();
|
|
1376
|
+
this.runPromise = runPromise;
|
|
1377
|
+
this._runInner(fn, options, runPromise).catch(error => {
|
|
1378
|
+
if (this.runPromise === runPromise) {
|
|
1379
|
+
this.runPromise = null;
|
|
1380
|
+
}
|
|
1381
|
+
runPromise.reject(error);
|
|
1382
|
+
});
|
|
1383
|
+
return runPromise.promise;
|
|
936
1384
|
}
|
|
937
1385
|
|
|
938
|
-
async _runInner<T>(
|
|
939
|
-
|
|
940
|
-
|
|
1386
|
+
async _runInner<T>(
|
|
1387
|
+
fn: (() => Promise<T>) | undefined,
|
|
1388
|
+
options: RunOptions,
|
|
1389
|
+
runPromise: Deferred<void>
|
|
1390
|
+
) {
|
|
1391
|
+
const clearRunPromise = () => {
|
|
1392
|
+
if (this.runPromise === runPromise) {
|
|
1393
|
+
this.runPromise = null;
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
|
|
1397
|
+
const env = DataManager.getSettings('env');
|
|
1398
|
+
if (options.forceProtocolDetection && env !== 'react-native' && this.isUsedHere()) {
|
|
1399
|
+
await this.release();
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
if (options.forceProtocolDetection || !this.isUsedHere() || this.commands.disposed) {
|
|
941
1403
|
if (env !== 'react-native') {
|
|
942
1404
|
try {
|
|
943
|
-
await this.acquire(options.connectProtocol
|
|
1405
|
+
await this.acquire(options.connectProtocol, {
|
|
1406
|
+
forceProtocolDetection: options.forceProtocolDetection,
|
|
1407
|
+
});
|
|
944
1408
|
} catch (error) {
|
|
945
|
-
|
|
946
|
-
|
|
1409
|
+
clearRunPromise();
|
|
1410
|
+
runPromise.reject(error);
|
|
1411
|
+
return;
|
|
947
1412
|
}
|
|
948
1413
|
|
|
949
1414
|
try {
|
|
@@ -953,16 +1418,19 @@ export class Device extends EventEmitter {
|
|
|
953
1418
|
}
|
|
954
1419
|
}
|
|
955
1420
|
} catch (error) {
|
|
956
|
-
this.
|
|
1421
|
+
await this.release();
|
|
1422
|
+
clearRunPromise();
|
|
957
1423
|
if (error instanceof HardwareError) {
|
|
958
|
-
|
|
1424
|
+
runPromise.reject(error);
|
|
1425
|
+
return;
|
|
959
1426
|
}
|
|
960
|
-
|
|
1427
|
+
runPromise.reject(
|
|
961
1428
|
ERRORS.TypedError(
|
|
962
1429
|
HardwareErrorCode.DeviceInitializeFailed,
|
|
963
1430
|
`Initialize failed: ${error.message as string}, code: ${error.code as string}`
|
|
964
1431
|
)
|
|
965
1432
|
);
|
|
1433
|
+
return;
|
|
966
1434
|
}
|
|
967
1435
|
} else if (env === 'react-native') {
|
|
968
1436
|
// TODO: implement react-native acquire
|
|
@@ -981,9 +1449,7 @@ export class Device extends EventEmitter {
|
|
|
981
1449
|
try {
|
|
982
1450
|
await fn();
|
|
983
1451
|
} catch (e) {
|
|
984
|
-
|
|
985
|
-
this.runPromise.reject(e);
|
|
986
|
-
}
|
|
1452
|
+
runPromise.reject(e);
|
|
987
1453
|
|
|
988
1454
|
if (
|
|
989
1455
|
e instanceof HardwareError &&
|
|
@@ -996,7 +1462,7 @@ export class Device extends EventEmitter {
|
|
|
996
1462
|
Log.debug(`error code ${e.errorCode} release device, mainId: ${this.mainId}`);
|
|
997
1463
|
}
|
|
998
1464
|
|
|
999
|
-
|
|
1465
|
+
clearRunPromise();
|
|
1000
1466
|
return;
|
|
1001
1467
|
}
|
|
1002
1468
|
}
|
|
@@ -1010,11 +1476,8 @@ export class Device extends EventEmitter {
|
|
|
1010
1476
|
Log.debug('release device, mainId: ', this.mainId);
|
|
1011
1477
|
}
|
|
1012
1478
|
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
this.runPromise = null;
|
|
1479
|
+
runPromise.resolve();
|
|
1480
|
+
clearRunPromise();
|
|
1018
1481
|
}
|
|
1019
1482
|
|
|
1020
1483
|
async interruptionFromOutside() {
|
|
@@ -1053,33 +1516,37 @@ export class Device extends EventEmitter {
|
|
|
1053
1516
|
}
|
|
1054
1517
|
|
|
1055
1518
|
getMode() {
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
return EOneKeyDeviceMode.backupMode;
|
|
1519
|
+
switch (this.state?.status.mode) {
|
|
1520
|
+
case 'bootloader':
|
|
1521
|
+
case 'romloader':
|
|
1522
|
+
return EOneKeyDeviceMode.bootloader;
|
|
1523
|
+
case 'notInitialized':
|
|
1524
|
+
return EOneKeyDeviceMode.notInitialized;
|
|
1525
|
+
case 'backupMode':
|
|
1526
|
+
return EOneKeyDeviceMode.backupMode;
|
|
1527
|
+
case 'normal':
|
|
1528
|
+
return EOneKeyDeviceMode.normal;
|
|
1529
|
+
default:
|
|
1530
|
+
break;
|
|
1069
1531
|
}
|
|
1070
1532
|
|
|
1071
|
-
// normal mode
|
|
1072
1533
|
return EOneKeyDeviceMode.normal;
|
|
1073
1534
|
}
|
|
1074
1535
|
|
|
1536
|
+
getStatus() {
|
|
1537
|
+
if (this.isUsedElsewhere()) return 'occupied' as const;
|
|
1538
|
+
if (this.isUsedHere()) return 'used' as const;
|
|
1539
|
+
return 'available' as const;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1075
1542
|
getFirmwareVersion() {
|
|
1076
|
-
if (!this.
|
|
1077
|
-
return
|
|
1543
|
+
if (!this.state) return null;
|
|
1544
|
+
return parseDeviceVersion(this.state.versions.firmware);
|
|
1078
1545
|
}
|
|
1079
1546
|
|
|
1080
1547
|
getBLEFirmwareVersion() {
|
|
1081
|
-
if (!this.
|
|
1082
|
-
return
|
|
1548
|
+
if (!this.state) return null;
|
|
1549
|
+
return parseDeviceVersion(this.state.versions.ble);
|
|
1083
1550
|
}
|
|
1084
1551
|
|
|
1085
1552
|
isUsed() {
|
|
@@ -1097,7 +1564,7 @@ export class Device extends EventEmitter {
|
|
|
1097
1564
|
isUsedHere() {
|
|
1098
1565
|
const env = DataManager.getSettings('env');
|
|
1099
1566
|
if (DataManager.isBleConnect(env)) {
|
|
1100
|
-
return
|
|
1567
|
+
return this.deviceAcquired;
|
|
1101
1568
|
}
|
|
1102
1569
|
return this.isUsed() && this.originalDescriptor.session === this.mainId;
|
|
1103
1570
|
}
|
|
@@ -1107,26 +1574,39 @@ export class Device extends EventEmitter {
|
|
|
1107
1574
|
}
|
|
1108
1575
|
|
|
1109
1576
|
isBootloader() {
|
|
1110
|
-
|
|
1577
|
+
if (!this.state) return undefined;
|
|
1578
|
+
return this.state.status.mode === 'bootloader';
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
isRomloader() {
|
|
1582
|
+
if (!this.state) return undefined;
|
|
1583
|
+
return (
|
|
1584
|
+
this.isProtocolV2() &&
|
|
1585
|
+
(this.getCurrentDeviceType() === EDeviceType.Pro2 ||
|
|
1586
|
+
this.getCurrentDeviceType() === EDeviceType.Neo) &&
|
|
1587
|
+
this.state.status.mode === 'romloader'
|
|
1588
|
+
);
|
|
1111
1589
|
}
|
|
1112
1590
|
|
|
1113
1591
|
isInitialized() {
|
|
1114
|
-
|
|
1592
|
+
if (!this.state) return undefined;
|
|
1593
|
+
return this.state.status.initialized === true;
|
|
1115
1594
|
}
|
|
1116
1595
|
|
|
1117
1596
|
isSeedless() {
|
|
1118
|
-
|
|
1597
|
+
if (!this.state) return undefined;
|
|
1598
|
+
return this.state.status.noBackup === true;
|
|
1119
1599
|
}
|
|
1120
1600
|
|
|
1121
1601
|
isUnacquired(): boolean {
|
|
1122
|
-
return this.
|
|
1602
|
+
return this.state === undefined;
|
|
1123
1603
|
}
|
|
1124
1604
|
|
|
1125
1605
|
hasUnexpectedMode(allow: string[], require: string[]) {
|
|
1126
1606
|
// both allow and require cases might generate single unexpected mode
|
|
1127
1607
|
if (!this.isUnacquired()) {
|
|
1128
1608
|
// allow cases
|
|
1129
|
-
if (this.isBootloader() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
|
|
1609
|
+
if (this.isBootloader() && !this.isProtocolV2() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
|
|
1130
1610
|
return UI_REQUEST.BOOTLOADER;
|
|
1131
1611
|
}
|
|
1132
1612
|
if (!this.isInitialized() && !allow.includes(UI_REQUEST.NOT_INITIALIZE)) {
|
|
@@ -1149,8 +1629,9 @@ export class Device extends EventEmitter {
|
|
|
1149
1629
|
const isModeT =
|
|
1150
1630
|
deviceType === EDeviceType.Touch ||
|
|
1151
1631
|
deviceType === EDeviceType.Pro ||
|
|
1152
|
-
deviceType === EDeviceType.Pro2
|
|
1153
|
-
|
|
1632
|
+
deviceType === EDeviceType.Pro2 ||
|
|
1633
|
+
deviceType === EDeviceType.Neo;
|
|
1634
|
+
const unlocked = this.state?.status.unlocked;
|
|
1154
1635
|
const preCheckTouch = isModeT && unlocked === false;
|
|
1155
1636
|
const passphraseProtection = this.getCurrentPassphraseProtection();
|
|
1156
1637
|
|
|
@@ -1163,12 +1644,91 @@ export class Device extends EventEmitter {
|
|
|
1163
1644
|
|
|
1164
1645
|
async lockDevice(): Promise<Success> {
|
|
1165
1646
|
const res = await this.commands.typedCall('LockDevice', 'Success', {});
|
|
1647
|
+
this.updateState({ status: { unlocked: false } }, 'lock');
|
|
1166
1648
|
return res.message;
|
|
1167
1649
|
}
|
|
1168
1650
|
|
|
1651
|
+
beginProtocolV2UiInteraction() {
|
|
1652
|
+
if (!this.isProtocolV2()) return;
|
|
1653
|
+
this.protocolV2UiInteraction = {
|
|
1654
|
+
interactionId: `${this.instanceId}:${Date.now()}:${++this.protocolV2UiInteractionCounter}`,
|
|
1655
|
+
phaseCounter: 0,
|
|
1656
|
+
sequence: 0,
|
|
1657
|
+
opened: false,
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
createProtocolV2UiPhaseMetadata(
|
|
1662
|
+
phase: HardwareUiInteractionMeta['phase'],
|
|
1663
|
+
transition: HardwareUiInteractionMeta['transition'],
|
|
1664
|
+
options?: {
|
|
1665
|
+
phaseId?: string;
|
|
1666
|
+
outcome?: HardwareUiInteractionMeta['outcome'];
|
|
1667
|
+
}
|
|
1668
|
+
): HardwareUiInteractionMeta | undefined {
|
|
1669
|
+
if (!this.isProtocolV2()) return undefined;
|
|
1670
|
+
if (!this.protocolV2UiInteraction) this.beginProtocolV2UiInteraction();
|
|
1671
|
+
|
|
1672
|
+
const interaction = this.protocolV2UiInteraction;
|
|
1673
|
+
if (!interaction) return undefined;
|
|
1674
|
+
const phaseId =
|
|
1675
|
+
options?.phaseId ?? `${interaction.interactionId}:phase-${++interaction.phaseCounter}`;
|
|
1676
|
+
interaction.opened = true;
|
|
1677
|
+
interaction.sequence += 1;
|
|
1678
|
+
|
|
1679
|
+
return {
|
|
1680
|
+
interactionId: interaction.interactionId,
|
|
1681
|
+
phaseId,
|
|
1682
|
+
sequence: interaction.sequence,
|
|
1683
|
+
phase,
|
|
1684
|
+
transition,
|
|
1685
|
+
...(options?.outcome ? { outcome: options.outcome } : {}),
|
|
1686
|
+
protocol: 'V2',
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
completeProtocolV2UiPhase(
|
|
1691
|
+
phase: HardwareUiInteractionMeta,
|
|
1692
|
+
outcome: HardwareUiInteractionMeta['outcome'] = 'succeeded'
|
|
1693
|
+
) {
|
|
1694
|
+
return this.createProtocolV2UiPhaseMetadata(phase.phase, 'complete', {
|
|
1695
|
+
phaseId: phase.phaseId,
|
|
1696
|
+
outcome,
|
|
1697
|
+
});
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
finishProtocolV2UiInteraction(
|
|
1701
|
+
outcome?: HardwareUiInteractionMeta['outcome'],
|
|
1702
|
+
options?: { ensureMetadata?: boolean }
|
|
1703
|
+
) {
|
|
1704
|
+
const interaction = this.protocolV2UiInteraction;
|
|
1705
|
+
if (!interaction || (!interaction.opened && !options?.ensureMetadata)) {
|
|
1706
|
+
this.protocolV2UiInteraction = undefined;
|
|
1707
|
+
return undefined;
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
const phaseId = `${interaction.interactionId}:phase-${Math.max(interaction.phaseCounter, 1)}`;
|
|
1711
|
+
interaction.opened = true;
|
|
1712
|
+
interaction.sequence += 1;
|
|
1713
|
+
const metadata: HardwareUiInteractionMeta = {
|
|
1714
|
+
interactionId: interaction.interactionId,
|
|
1715
|
+
phaseId,
|
|
1716
|
+
sequence: interaction.sequence,
|
|
1717
|
+
phase: 'processing',
|
|
1718
|
+
transition: 'finish',
|
|
1719
|
+
outcome: outcome ?? 'succeeded',
|
|
1720
|
+
protocol: 'V2',
|
|
1721
|
+
};
|
|
1722
|
+
this.protocolV2UiInteraction = undefined;
|
|
1723
|
+
return metadata;
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
hasOpenProtocolV2UiInteraction() {
|
|
1727
|
+
return this.protocolV2UiInteraction?.opened === true;
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1169
1730
|
supportUnlockVersionRange(): DeviceFirmwareRange {
|
|
1170
|
-
//
|
|
1171
|
-
// 且 Protocol V2 固件从首个版本即支持 UnLockDevice(见 unlockDevice 的 isProtocolV2 短路)。
|
|
1731
|
+
// This range applies to Protocol V1 Pro devices; Pro2 has a dedicated unlock flow.
|
|
1172
1732
|
return {
|
|
1173
1733
|
pro: {
|
|
1174
1734
|
min: '4.15.0',
|
|
@@ -1176,19 +1736,62 @@ export class Device extends EventEmitter {
|
|
|
1176
1736
|
};
|
|
1177
1737
|
}
|
|
1178
1738
|
|
|
1179
|
-
async unlockDevice(
|
|
1739
|
+
async unlockDevice(
|
|
1740
|
+
pinType?: DeviceSessionPinType,
|
|
1741
|
+
options?: ProtocolV2UiEventMetadata & { emitUiEvent?: boolean }
|
|
1742
|
+
) {
|
|
1743
|
+
if (this.isProtocolV2()) {
|
|
1744
|
+
const requestedPinType = pinType ?? DeviceSessionPinType.Main;
|
|
1745
|
+
const interaction =
|
|
1746
|
+
options?.interaction ??
|
|
1747
|
+
(options?.emitUiEvent === false
|
|
1748
|
+
? undefined
|
|
1749
|
+
: this.createProtocolV2UiPhaseMetadata('pin', 'start'));
|
|
1750
|
+
if (options?.emitUiEvent !== false) {
|
|
1751
|
+
this.emit(DEVICE.PIN_ON_DEVICE, this, requestedPinType, {
|
|
1752
|
+
source: options?.source ?? 'unlock-coordinator',
|
|
1753
|
+
reason: options?.reason ?? 'device-unlock',
|
|
1754
|
+
deviceOnly: options?.deviceOnly ?? true,
|
|
1755
|
+
completion: options?.completion,
|
|
1756
|
+
method: options?.method,
|
|
1757
|
+
page: options?.page,
|
|
1758
|
+
operation: options?.operation,
|
|
1759
|
+
interaction: options?.interaction ?? interaction,
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
try {
|
|
1763
|
+
await this.commands.typedCall('DeviceSessionAskPin', 'Success', {
|
|
1764
|
+
type: requestedPinType,
|
|
1765
|
+
});
|
|
1766
|
+
} catch (error) {
|
|
1767
|
+
const errorText =
|
|
1768
|
+
error instanceof Error
|
|
1769
|
+
? `${error.name} ${error.message}`
|
|
1770
|
+
: String((error as { message?: unknown } | null)?.message ?? error ?? '');
|
|
1771
|
+
if (errorText.includes('Failure_UnexpectedMessage')) {
|
|
1772
|
+
throw createDeviceNotSupportMethodError('deviceUnlock', this.getCurrentFirmwareType());
|
|
1773
|
+
}
|
|
1774
|
+
throw error;
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
const completion = interaction ? this.completeProtocolV2UiPhase(interaction) : undefined;
|
|
1778
|
+
if (completion) {
|
|
1779
|
+
this.emit(DEVICE.PIN_ON_DEVICE_COMPLETE, this, completion);
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
const status = await requestProtocolV2DeviceStatus({ commands: this.commands });
|
|
1783
|
+
return this.updateProtocolV2Status(status);
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1180
1786
|
const firmwareVersion = this.getCurrentFirmwareVersionString() ?? '0.0.0';
|
|
1181
1787
|
const versionRange = this.getCurrentMethodVersionRange(
|
|
1182
1788
|
type => this.supportUnlockVersionRange()[type]
|
|
1183
1789
|
);
|
|
1184
1790
|
|
|
1185
|
-
const supportAttachPinCapability =
|
|
1186
|
-
this.features,
|
|
1791
|
+
const supportAttachPinCapability = this.state?.capabilities.includes(
|
|
1187
1792
|
Enum_Capability.Capability_AttachToPin
|
|
1188
1793
|
);
|
|
1189
|
-
// Pro2 (Protocol V2) 版本线独立于 Pro 系列,固件从首个版本即支持 UnLockDevice
|
|
1190
1794
|
const supportUnlock =
|
|
1191
|
-
this.isProtocolV2() ||
|
|
1192
1795
|
supportAttachPinCapability ||
|
|
1193
1796
|
(versionRange &&
|
|
1194
1797
|
semver.valid(firmwareVersion) &&
|
|
@@ -1196,12 +1799,21 @@ export class Device extends EventEmitter {
|
|
|
1196
1799
|
|
|
1197
1800
|
if (supportUnlock) {
|
|
1198
1801
|
const res = await this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
|
|
1199
|
-
if (this.
|
|
1200
|
-
this.
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1802
|
+
if (this.state) {
|
|
1803
|
+
this.updateState(
|
|
1804
|
+
{
|
|
1805
|
+
status: {
|
|
1806
|
+
unlocked: res.message.unlocked == null ? null : res.message.unlocked,
|
|
1807
|
+
unlockedAttachPin:
|
|
1808
|
+
res.message.unlocked_attach_pin == null ? null : res.message.unlocked_attach_pin,
|
|
1809
|
+
passphraseProtection:
|
|
1810
|
+
res.message.passphrase_protection == null
|
|
1811
|
+
? null
|
|
1812
|
+
: res.message.passphrase_protection,
|
|
1813
|
+
},
|
|
1814
|
+
},
|
|
1815
|
+
'unlock'
|
|
1816
|
+
);
|
|
1205
1817
|
|
|
1206
1818
|
return Promise.resolve(this.features);
|
|
1207
1819
|
}
|
|
@@ -1210,14 +1822,6 @@ export class Device extends EventEmitter {
|
|
|
1210
1822
|
return Promise.resolve(features);
|
|
1211
1823
|
}
|
|
1212
1824
|
|
|
1213
|
-
// legacy 解锁探测仅适用于 Protocol V1 老固件;V2 固件必然支持 UnLockDevice
|
|
1214
|
-
if (this.isProtocolV2()) {
|
|
1215
|
-
throw ERRORS.TypedError(
|
|
1216
|
-
HardwareErrorCode.RuntimeError,
|
|
1217
|
-
'unlock device error: device firmware does not support UnLockDevice'
|
|
1218
|
-
);
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
1825
|
const { type } = await this.commands.typedCall('GetAddress', 'Address', {
|
|
1222
1826
|
address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
|
|
1223
1827
|
coin_name: 'Testnet',
|
|
@@ -1236,25 +1840,34 @@ export class Device extends EventEmitter {
|
|
|
1236
1840
|
async checkPassphraseStateSafety(
|
|
1237
1841
|
passphraseState?: string,
|
|
1238
1842
|
useEmptyPassphrase?: boolean,
|
|
1239
|
-
skipPassphraseCheck?: boolean
|
|
1843
|
+
skipPassphraseCheck?: boolean,
|
|
1844
|
+
deriveCardano?: boolean
|
|
1240
1845
|
) {
|
|
1241
1846
|
if (this.isUnacquired()) return false;
|
|
1242
1847
|
|
|
1848
|
+
const expectedPassphraseState = useEmptyPassphrase ? undefined : passphraseState;
|
|
1243
1849
|
const { passphraseState: newPassphraseState, unlockedAttachPin } =
|
|
1244
1850
|
await getPassphraseStateWithRefreshDeviceInfo(this, {
|
|
1245
|
-
expectPassphraseState:
|
|
1851
|
+
expectPassphraseState: expectedPassphraseState,
|
|
1246
1852
|
onlyMainPin: useEmptyPassphrase,
|
|
1853
|
+
deriveCardano,
|
|
1854
|
+
rejectAttachPinForMainWallet: useEmptyPassphrase === true,
|
|
1247
1855
|
});
|
|
1248
1856
|
|
|
1249
1857
|
// Main wallet and unlock Attach Pin, throw safe error
|
|
1250
1858
|
const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
|
|
1251
1859
|
const useErrorAttachPin =
|
|
1252
|
-
unlockedAttachPin &&
|
|
1253
|
-
|
|
1860
|
+
unlockedAttachPin &&
|
|
1861
|
+
expectedPassphraseState &&
|
|
1862
|
+
expectedPassphraseState !== newPassphraseState;
|
|
1863
|
+
const passphraseStateMismatch =
|
|
1864
|
+
!!expectedPassphraseState && expectedPassphraseState !== newPassphraseState;
|
|
1254
1865
|
|
|
1255
1866
|
Log.debug('Check passphrase state safety: ', {
|
|
1256
|
-
|
|
1257
|
-
newPassphraseState,
|
|
1867
|
+
hasExpectedPassphraseState: Boolean(expectedPassphraseState),
|
|
1868
|
+
hasNewPassphraseState: Boolean(newPassphraseState),
|
|
1869
|
+
passphraseStateMatches:
|
|
1870
|
+
Boolean(expectedPassphraseState) && expectedPassphraseState === newPassphraseState,
|
|
1258
1871
|
unlockedAttachPin,
|
|
1259
1872
|
useEmptyPassphrase,
|
|
1260
1873
|
});
|