@onekeyfe/hd-core 1.2.0-alpha.3 → 1.2.0-alpha.31
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 +77 -0
- package/__tests__/DeviceCommands.test.ts +433 -0
- package/__tests__/DeviceEventRegistration.test.ts +43 -0
- package/__tests__/chain-params-onekey-compatibility.test.ts +229 -0
- package/__tests__/connectSettings.test.ts +61 -0
- package/__tests__/core-dispose.test.ts +34 -0
- package/__tests__/core-error-output.test.ts +39 -0
- package/__tests__/device-features-state.test.ts +78 -0
- package/__tests__/device-identity.test.ts +52 -0
- package/__tests__/device-lifecycle-events.test.ts +197 -0
- package/__tests__/device-pool-state.test.ts +132 -0
- package/__tests__/device-settings.test.ts +391 -0
- package/__tests__/device-state-contract.test.ts +27 -0
- package/__tests__/device-state-events.test.ts +286 -0
- package/__tests__/device-state-mapper.test.ts +241 -0
- package/__tests__/device-state-projector.test.ts +94 -0
- package/__tests__/device-state-store.test.ts +82 -0
- package/__tests__/device-utils.test.ts +106 -0
- package/__tests__/device-wallet-session-store.test.ts +358 -0
- package/__tests__/deviceFeaturesUtils.test.ts +39 -0
- package/__tests__/deviceSettings.test.ts +103 -0
- package/__tests__/evmLedgerLegacySafety.test.ts +12 -6
- package/__tests__/evmSignTypedData.test.ts +80 -0
- package/__tests__/filesystemValidation.test.ts +53 -0
- package/__tests__/firmware-update/check-all-firmware-release.test.ts +174 -0
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
- package/__tests__/firmware-update/firmware-host-binding.test.ts +70 -0
- package/__tests__/firmware-update/firmware-preparation-error.test.ts +27 -0
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +593 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +213 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +430 -0
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +58 -0
- package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
- package/__tests__/get-device-state.test.ts +410 -0
- package/__tests__/homescreen.test.ts +24 -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 +592 -0
- package/__tests__/logBlockEvent.test.ts +43 -0
- package/__tests__/method-protocol-support.test.ts +113 -0
- package/__tests__/networkUtils.test.ts +386 -0
- package/__tests__/open-wallet-session-error-response.test.ts +43 -0
- package/__tests__/open-wallet-session.test.ts +915 -0
- package/__tests__/preInitialize.test.ts +33 -0
- package/__tests__/pro2Wallpaper.test.ts +39 -0
- package/__tests__/protocol-v2-bootloader-mode.test.ts +37 -0
- package/__tests__/protocol-v2-firmware-targets.test.ts +19 -0
- package/__tests__/protocol-v2-ping.test.ts +28 -0
- package/__tests__/protocol-v2-unlock-policy.test.ts +45 -0
- package/__tests__/protocol-v2.test.ts +5310 -1856
- package/__tests__/protocolV2FileWrite.test.ts +92 -0
- package/__tests__/protocolV2UiInteraction.test.ts +266 -0
- package/__tests__/public-device-state-api.test.ts +266 -0
- package/__tests__/public-pro2-api-boundary.test.ts +106 -0
- package/__tests__/refresh-device-state.test.ts +101 -0
- package/__tests__/request-context-logging.test.ts +16 -0
- package/__tests__/search-devices.test.ts +136 -0
- package/__tests__/tron-sign-message-init.test.ts +74 -0
- package/dist/api/BaseMethod.d.ts +14 -1
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
- package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
- package/dist/api/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/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 +47 -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 +1 -0
- 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/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 +25 -0
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts +6 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -0
- package/dist/api/firmware/FirmwarePreparationError.d.ts +3 -0
- package/dist/api/firmware/FirmwarePreparationError.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +8 -0
- 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 +25 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +30 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/api/firmware/getBinary.d.ts +18 -3
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/progressThrottle.d.ts +3 -0
- package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
- package/dist/api/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 +33 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -0
- package/dist/api/index.d.ts +6 -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 +1 -0
- 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/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 +2 -1
- 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/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 +1 -0
- package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +1 -0
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +1 -0
- 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 +1 -0
- package/dist/api/sui/SuiGetAddress.d.ts.map +1 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts +1 -0
- package/dist/api/sui/SuiGetPublicKey.d.ts.map +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts +1 -0
- package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +1 -0
- package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
- package/dist/api/ton/TonGetAddress.d.ts +1 -0
- 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 +1 -0
- package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
- package/dist/api/ton/TonSignProof.d.ts +1 -0
- 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 +5 -0
- package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
- package/dist/api/tron/TronSignTransaction.d.ts +1 -0
- package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
- package/dist/api/utils.d.ts +2 -1
- package/dist/api/utils.d.ts.map +1 -1
- package/dist/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 +11 -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/data-manager/DataManager.d.ts +2 -1
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +40 -13
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +8 -6
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceFeaturesState.d.ts +3 -0
- package/dist/device/DeviceFeaturesState.d.ts.map +1 -0
- package/dist/device/DevicePool.d.ts +4 -2
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/device/DeviceStateMapper.d.ts +13 -0
- package/dist/device/DeviceStateMapper.d.ts.map +1 -0
- package/dist/device/DeviceStateProjector.d.ts +7 -0
- package/dist/device/DeviceStateProjector.d.ts.map +1 -0
- package/dist/device/DeviceStateStore.d.ts +21 -0
- package/dist/device/DeviceStateStore.d.ts.map +1 -0
- package/dist/device/DeviceWalletSessionStore.d.ts +20 -0
- package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -0
- package/dist/device/cloneDeviceState.d.ts +2 -0
- package/dist/device/cloneDeviceState.d.ts.map +1 -0
- package/dist/device/deviceIdentity.d.ts +5 -0
- package/dist/device/deviceIdentity.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts +9 -3
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/deviceProfile/index.d.ts +0 -1
- package/dist/deviceProfile/index.d.ts.map +1 -1
- package/dist/events/device.d.ts +12 -2
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +19 -2
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +1487 -691
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8831 -4014
- 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 +23 -28
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts +11 -9
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +3 -2
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +2 -0
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts +16 -0
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +39 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts +4 -0
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +10 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts +31 -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 +5 -2
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- 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 +1 -1
- 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 +5 -2
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +75 -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 +25 -35
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/kaspaSignTransaction.d.ts +42 -4
- package/dist/types/api/kaspaSignTransaction.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +29 -0
- package/dist/types/api/openWalletSession.d.ts.map +1 -0
- package/dist/types/api/protocolV2.d.ts +15 -89
- 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 +122 -6
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +1 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +34 -2
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/assets.d.ts +2 -1
- package/dist/utils/assets.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts +13 -0
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -0
- package/dist/utils/deviceFeaturesUtils.d.ts +11 -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.map +1 -1
- package/dist/utils/index.d.ts +5 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/networkUtils.d.ts +9 -1
- package/dist/utils/networkUtils.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/pro2Wallpaper.d.ts +12 -0
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -0
- package/dist/utils/tracing.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +52 -17
- package/src/api/CheckAllFirmwareRelease.ts +51 -4
- package/src/api/CheckBootloaderRelease.ts +1 -2
- package/src/api/CheckFirmwareRelease.ts +1 -2
- package/src/api/CipherKeyValue.ts +4 -0
- package/src/api/ClearSessionCache.ts +32 -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 +11 -12
- package/src/api/FirmwareUpdateV2.ts +370 -112
- package/src/api/FirmwareUpdateV3.ts +266 -68
- package/src/api/FirmwareUpdateV4.ts +1687 -397
- 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 +21 -21
- package/src/api/OpenWalletSession.ts +202 -0
- package/src/api/PathInfo.ts +9 -4
- package/src/api/PromptWebDeviceAccess.ts +2 -3
- package/src/api/SearchDevices.ts +29 -4
- package/src/api/UploadPortfolio.ts +40 -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/AllNetworkGetAddressBase.ts +9 -21
- 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 +187 -1
- package/src/api/device/DeviceSupportFeatures.ts +4 -0
- package/src/api/device/DeviceUnlock.ts +13 -0
- package/src/api/device/DeviceUpdateBootloader.ts +123 -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 +4 -0
- package/src/api/evm/EVMGetPublicKey.ts +4 -0
- package/src/api/evm/EVMSignMessage.ts +4 -0
- package/src/api/evm/EVMSignMessageEIP712.ts +1 -11
- package/src/api/evm/EVMSignTransaction.ts +4 -0
- package/src/api/evm/EVMSignTypedData.ts +7 -5
- package/src/api/evm/EVMVerifyMessage.ts +4 -0
- 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/filecoin/FilecoinGetAddress.ts +4 -0
- package/src/api/filecoin/FilecoinSignTransaction.ts +4 -0
- package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
- package/src/api/firmware/FirmwareHostBinding.ts +100 -0
- package/src/api/firmware/FirmwarePreparationError.ts +12 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +71 -7
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +745 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +392 -0
- package/src/api/firmware/getBinary.ts +8 -3
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/firmware/updateBootloader.ts +19 -4
- package/src/api/firmware/uploadFirmware.ts +140 -22
- 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 +199 -0
- package/src/api/index.ts +7 -30
- package/src/api/kaspa/KaspaGetAddress.ts +7 -0
- package/src/api/kaspa/KaspaSignTransaction.ts +373 -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/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/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 +19 -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 +4 -0
- package/src/api/solana/SolSignOffchainMessage.ts +4 -0
- package/src/api/solana/SolSignTransaction.ts +4 -0
- 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 +4 -0
- package/src/api/sui/SuiGetPublicKey.ts +4 -0
- package/src/api/sui/SuiSignMessage.ts +4 -0
- package/src/api/sui/SuiSignTransaction.ts +4 -0
- package/src/api/ton/TonGetAddress.ts +4 -0
- package/src/api/ton/TonSignData.ts +6 -6
- package/src/api/ton/TonSignMessage.ts +4 -0
- package/src/api/ton/TonSignProof.ts +4 -0
- package/src/api/tron/TronGetAddress.ts +4 -0
- package/src/api/tron/TronSignMessage.ts +18 -7
- package/src/api/tron/TronSignTransaction.ts +4 -0
- package/src/api/utils.ts +7 -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 +23 -0
- package/src/core/index.ts +181 -58
- package/src/data/messages/messages-protocol-v2.json +796 -620
- package/src/data/messages/messages.json +286 -1
- package/src/data-manager/DataManager.ts +45 -38
- package/src/data-manager/TransportManager.ts +1 -1
- package/src/data-manager/connectSettings.ts +13 -4
- package/src/device/Device.ts +573 -278
- package/src/device/DeviceCommands.ts +154 -156
- package/src/device/DeviceFeaturesState.ts +25 -0
- package/src/device/DevicePool.ts +61 -13
- package/src/device/DeviceStateMapper.ts +366 -0
- package/src/device/DeviceStateProjector.ts +101 -0
- package/src/device/DeviceStateStore.ts +201 -0
- package/src/device/DeviceWalletSessionStore.ts +105 -0
- package/src/device/cloneDeviceState.ts +39 -0
- package/src/device/deviceIdentity.ts +18 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +234 -210
- package/src/deviceProfile/index.ts +0 -1
- package/src/events/device.ts +18 -1
- package/src/events/logBlockEvent.ts +1 -7
- package/src/events/ui-request.ts +25 -2
- package/src/index.ts +5 -0
- package/src/inject.ts +35 -47
- package/src/lowLevelInject.ts +5 -1
- package/src/protocols/protocol-v2/deviceSession.ts +24 -0
- package/src/protocols/protocol-v2/features.ts +68 -83
- package/src/protocols/protocol-v2/firmware.ts +12 -36
- package/src/protocols/protocol-v2/index.ts +3 -1
- package/src/protocols/protocol-v2/lockedError.ts +10 -0
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +60 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +210 -0
- package/src/protocols/protocol-v2/unlockPolicy.ts +105 -0
- package/src/protocols/protocol-v2/unlockRetry.ts +98 -0
- package/src/protocols/protocol-v2/walletSession.ts +202 -0
- package/src/topLevelInject.ts +5 -1
- package/src/types/api/checkAllFirmwareRelease.ts +5 -2
- package/src/types/api/deviceSettings.ts +26 -2
- package/src/types/api/deviceUnlock.ts +1 -1
- package/src/types/api/deviceUpdateBootloader.ts +6 -0
- package/src/types/api/export.ts +21 -0
- package/src/types/api/firmwareUpdate.ts +103 -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 +33 -73
- package/src/types/api/kaspaSignTransaction.ts +60 -4
- package/src/types/api/openWalletSession.ts +45 -0
- package/src/types/api/protocolV2.ts +23 -162
- package/src/types/api/sessionCache.ts +19 -0
- package/src/types/device.ts +172 -5
- package/src/types/params.ts +4 -0
- package/src/types/settings.ts +55 -35
- package/src/utils/assets.ts +4 -1
- package/src/utils/deviceFeaturesCompat.ts +173 -0
- package/src/utils/deviceFeaturesUtils.ts +66 -24
- package/src/utils/deviceInfoUtils.ts +27 -69
- package/src/utils/deviceSettings.ts +171 -39
- package/src/utils/deviceVersionUtils.ts +25 -44
- package/src/utils/findDefectiveBatchDevice.ts +3 -3
- package/src/utils/homescreen.ts +10 -0
- package/src/utils/index.ts +21 -2
- package/src/utils/networkUtils.ts +270 -14
- package/src/utils/pro2Wallpaper.ts +109 -0
- package/src/utils/tracing.ts +3 -1
- package/tsconfig.type-tests.json +8 -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,14 +54,19 @@ 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_FEATURES_DEVICE_INFO_REQUEST,
|
|
59
|
+
PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST,
|
|
60
|
+
PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
|
|
61
|
+
type ProtocolV2RuntimeMode,
|
|
62
|
+
getProtocolV2RuntimeMode,
|
|
54
63
|
requestProtocolV2DeviceInfo,
|
|
64
|
+
requestProtocolV2DeviceStatus,
|
|
55
65
|
} from '../protocols/protocol-v2/features';
|
|
56
|
-
import { buildProtocolV1FeaturesPayload
|
|
66
|
+
import { buildProtocolV1FeaturesPayload } from '../deviceProfile';
|
|
57
67
|
|
|
58
68
|
import type { PROTO } from '../constants';
|
|
69
|
+
import type { DeviceStateReadOptions } from '../types/api/getDeviceState';
|
|
59
70
|
import type {
|
|
60
71
|
DeviceButtonRequestPayload,
|
|
61
72
|
DeviceFeaturesPayload,
|
|
@@ -65,6 +76,7 @@ import type { PassphrasePromptResponse } from './DeviceCommands';
|
|
|
65
76
|
import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
66
77
|
import type {
|
|
67
78
|
OneKeyDeviceInfo as DeviceDescriptor,
|
|
79
|
+
DeviceStatus,
|
|
68
80
|
ProtocolV2DeviceInfo,
|
|
69
81
|
Success,
|
|
70
82
|
} from '@onekeyfe/hd-transport';
|
|
@@ -76,6 +88,9 @@ export type InitOptions = {
|
|
|
76
88
|
passphraseState?: string;
|
|
77
89
|
deriveCardano?: boolean;
|
|
78
90
|
connectProtocol?: HardwareConnectProtocol;
|
|
91
|
+
protocolV2DeviceInfoTimeoutMs?: number;
|
|
92
|
+
/** Refresh Protocol V2 runtime state before returning discovery results. */
|
|
93
|
+
refreshRuntimeState?: boolean;
|
|
79
94
|
};
|
|
80
95
|
|
|
81
96
|
export type RunOptions = {
|
|
@@ -92,9 +107,11 @@ const Log = getLogger(LoggerNames.Device);
|
|
|
92
107
|
|
|
93
108
|
export interface DeviceEvents {
|
|
94
109
|
[DEVICE.PIN]: [Device, PROTO.PinMatrixRequestType | undefined, (err: any, pin: string) => void];
|
|
95
|
-
[DEVICE.PASSPHRASE_ON_DEVICE]: [Device,
|
|
110
|
+
[DEVICE.PASSPHRASE_ON_DEVICE]: [Device, PassphraseRequestPayload?];
|
|
111
|
+
[DEVICE.ATTACH_PIN_ON_DEVICE]: [Device, PassphraseRequestPayload?];
|
|
96
112
|
[DEVICE.BUTTON]: [Device, DeviceButtonRequestPayload];
|
|
97
113
|
[DEVICE.FEATURES]: [Device, DeviceFeaturesPayload];
|
|
114
|
+
[DEVICE.STATE]: [Device, DeviceStateEvent];
|
|
98
115
|
[DEVICE.PASSPHRASE]: [
|
|
99
116
|
Device,
|
|
100
117
|
PassphraseRequestPayload,
|
|
@@ -118,15 +135,14 @@ export interface Device {
|
|
|
118
135
|
emit<K extends keyof DeviceEvents>(type: K, ...args: DeviceEvents[K]): boolean;
|
|
119
136
|
}
|
|
120
137
|
|
|
121
|
-
const deviceSessionCache: Record<string, string> = {};
|
|
122
|
-
|
|
123
138
|
/**
|
|
124
139
|
* Pre-populate the device session cache with a known session ID.
|
|
125
140
|
*
|
|
126
141
|
* This allows short-lived processes (e.g. CLI) to restore a previously
|
|
127
142
|
* obtained session, avoiding the need to re-enter passphrase on every
|
|
128
143
|
* invocation. The session must have been obtained from a prior
|
|
129
|
-
*
|
|
144
|
+
* wallet-session call on the same device. This compatibility hook is intended
|
|
145
|
+
* for a trusted CLI process restoring its own OS-keychain entry.
|
|
130
146
|
*
|
|
131
147
|
* @param deviceId - The device's device_id (from features)
|
|
132
148
|
* @param passphraseState - The passphrase state token
|
|
@@ -137,8 +153,7 @@ export function preloadSessionCache(
|
|
|
137
153
|
passphraseState: string,
|
|
138
154
|
sessionId: string
|
|
139
155
|
): void {
|
|
140
|
-
|
|
141
|
-
deviceSessionCache[key] = sessionId;
|
|
156
|
+
deviceWalletSessionStore.set(deviceId, passphraseState, sessionId);
|
|
142
157
|
}
|
|
143
158
|
|
|
144
159
|
export class Device extends EventEmitter {
|
|
@@ -184,22 +199,34 @@ export class Device extends EventEmitter {
|
|
|
184
199
|
*/
|
|
185
200
|
private deviceAcquired = false;
|
|
186
201
|
|
|
187
|
-
/**
|
|
188
|
-
|
|
189
|
-
*
|
|
190
|
-
* V1 直接保存原生 Features;V2 保存由 DevGetDeviceInfo 映射出的
|
|
191
|
-
* Features 视图。Device 不再保存 profile,结构化 DeviceProfile 只作为
|
|
192
|
-
* getDeviceInfo() 的 API 返回值存在。
|
|
193
|
-
*/
|
|
194
|
-
features: Features | undefined = undefined;
|
|
202
|
+
/** Canonical device-state cache; legacy Features is a compatibility projection. */
|
|
203
|
+
private stateStore = new DeviceStateStore();
|
|
195
204
|
|
|
196
|
-
/**
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
205
|
+
/** Force the next initialization to reload DeviceInfo after reconnect or reboot. */
|
|
206
|
+
private protocolV2StateNeedsReload = false;
|
|
207
|
+
|
|
208
|
+
get state() {
|
|
209
|
+
return this.stateStore.getState();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
get features(): Features | undefined {
|
|
213
|
+
if (!this.state) return undefined;
|
|
214
|
+
return projectFeatures(this.state);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
set features(features: Features | undefined) {
|
|
218
|
+
this.stateStore = new DeviceStateStore();
|
|
219
|
+
if (features) {
|
|
220
|
+
this.stateStore.update(mapFeaturesToState(features), 'compatibility');
|
|
221
|
+
const { passphraseState } = features;
|
|
222
|
+
const sessionId = features.sessionId ?? features.session_id;
|
|
223
|
+
const deviceKey = this.getSessionCacheDeviceKey(features.deviceId ?? undefined);
|
|
224
|
+
if (passphraseState && sessionId && deviceKey) {
|
|
225
|
+
this.passphraseState = passphraseState;
|
|
226
|
+
deviceWalletSessionStore.set(deviceKey, passphraseState, sessionId);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
203
230
|
|
|
204
231
|
runPromise?: Deferred<void> | null;
|
|
205
232
|
|
|
@@ -259,32 +286,38 @@ export class Device extends EventEmitter {
|
|
|
259
286
|
const deviceType = this.getCurrentDeviceType();
|
|
260
287
|
|
|
261
288
|
const bleName = this.getCurrentBleName();
|
|
262
|
-
const
|
|
289
|
+
const displayName = this.getCurrentDisplayName();
|
|
263
290
|
const serialNo = this.getCurrentSerialNo();
|
|
264
291
|
const connectId = this.getConnectId();
|
|
265
292
|
const deviceId = this.getCurrentDeviceId() || null;
|
|
266
293
|
|
|
267
|
-
const features = this
|
|
294
|
+
const { features } = this;
|
|
295
|
+
const state = this.state ? createPublicDeviceState(this.state) : undefined;
|
|
268
296
|
|
|
269
297
|
return {
|
|
270
|
-
/** Android uses
|
|
298
|
+
/** Android uses a MAC address, while iOS and USB use transport-specific identifiers. */
|
|
271
299
|
connectId: DataManager.isBleConnect(env) ? this.mainId || null : connectId,
|
|
272
|
-
/**
|
|
300
|
+
/** Stable physical-device identity. */
|
|
301
|
+
serialNo,
|
|
302
|
+
/** @deprecated Use serialNo instead. */
|
|
273
303
|
uuid: serialNo,
|
|
274
304
|
commType: this.originalDescriptor.commType,
|
|
275
305
|
sdkInstanceId: this.sdkInstanceId,
|
|
276
306
|
instanceId: this.instanceId,
|
|
277
307
|
createdAt: this.createdAt,
|
|
278
308
|
deviceType,
|
|
279
|
-
/** ID
|
|
309
|
+
/** Wallet-lifecycle ID; changes after the device is wiped or reinitialized. */
|
|
280
310
|
deviceId,
|
|
281
311
|
path: this.originalDescriptor?.path,
|
|
282
312
|
bleName,
|
|
283
|
-
name:
|
|
284
|
-
|
|
313
|
+
name: displayName || bleName || `OneKey ${deviceType?.toUpperCase()}`,
|
|
314
|
+
// Keep the legacy top-level field string-compatible while preserving
|
|
315
|
+
// the canonical nullable value at state.identity.label.
|
|
316
|
+
label: displayName ?? '',
|
|
317
|
+
status: this.getStatus(),
|
|
285
318
|
mode: this.getMode(),
|
|
286
319
|
features,
|
|
287
|
-
|
|
320
|
+
state,
|
|
288
321
|
firmwareVersion: this.getFirmwareVersion(),
|
|
289
322
|
bleFirmwareVersion: this.getBLEFirmwareVersion(),
|
|
290
323
|
unavailableCapabilities: this.unavailableCapabilities,
|
|
@@ -300,6 +333,10 @@ export class Device extends EventEmitter {
|
|
|
300
333
|
// eslint-disable-next-line no-async-promise-executor
|
|
301
334
|
return new Promise<boolean>(async (resolve, reject) => {
|
|
302
335
|
if (DataManager.isBleConnect(env)) {
|
|
336
|
+
if (this.hasDeviceAcquire() && this.commands && !this.commands.disposed) {
|
|
337
|
+
resolve(true);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
303
340
|
try {
|
|
304
341
|
await this.acquire(connectProtocol);
|
|
305
342
|
resolve(true);
|
|
@@ -326,18 +363,20 @@ export class Device extends EventEmitter {
|
|
|
326
363
|
});
|
|
327
364
|
}
|
|
328
365
|
|
|
329
|
-
async acquire(
|
|
366
|
+
async acquire(
|
|
367
|
+
connectProtocol?: HardwareConnectProtocol,
|
|
368
|
+
options?: { throwOnRunPromiseError?: boolean }
|
|
369
|
+
) {
|
|
330
370
|
const env = DataManager.getSettings('env');
|
|
331
371
|
const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
|
|
332
372
|
const expectedProtocol = connectProtocol ?? this.originalDescriptor.protocolType;
|
|
333
373
|
try {
|
|
334
374
|
let acquireResult: unknown;
|
|
335
375
|
if (DataManager.isBleConnect(env)) {
|
|
336
|
-
//
|
|
337
|
-
//
|
|
338
|
-
//
|
|
339
|
-
//
|
|
340
|
-
// 因此对 BLE acquire 恒清理是有意为之。
|
|
376
|
+
// acquire starts a new BLE session. Any previous runPromise belongs to a dead
|
|
377
|
+
// session, such as an interrupted probe or firmware-update reboot, and would
|
|
378
|
+
// otherwise block the new session. Device cannot distinguish recovery from a
|
|
379
|
+
// regular acquire, so BLE always clears it intentionally.
|
|
341
380
|
acquireResult = await this.deviceConnector?.acquire(
|
|
342
381
|
this.originalDescriptor.id,
|
|
343
382
|
undefined,
|
|
@@ -375,6 +414,9 @@ export class Device extends EventEmitter {
|
|
|
375
414
|
|
|
376
415
|
this.commands = new DeviceCommands(this, this.mainId ?? '');
|
|
377
416
|
} catch (error) {
|
|
417
|
+
if (options?.throwOnRunPromiseError) {
|
|
418
|
+
throw error;
|
|
419
|
+
}
|
|
378
420
|
if (this.runPromise) {
|
|
379
421
|
this.runPromise.reject(error);
|
|
380
422
|
} else {
|
|
@@ -475,12 +517,11 @@ export class Device extends EventEmitter {
|
|
|
475
517
|
}
|
|
476
518
|
|
|
477
519
|
/**
|
|
478
|
-
*
|
|
520
|
+
* Canonical protocol discriminator.
|
|
479
521
|
*
|
|
480
|
-
* descriptor.protocolType
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
* 或从 features 反推。
|
|
522
|
+
* descriptor.protocolType is established by active probing; V2 features are mapped
|
|
523
|
+
* from DeviceInfoGet. All protocol branches must use this method instead of reading
|
|
524
|
+
* originalDescriptor.protocolType directly or inferring a protocol from features.
|
|
484
525
|
*/
|
|
485
526
|
getProtocol(): 'V1' | 'V2' {
|
|
486
527
|
return this.originalDescriptor.protocolType === 'V2' ? 'V2' : 'V1';
|
|
@@ -491,54 +532,75 @@ export class Device extends EventEmitter {
|
|
|
491
532
|
}
|
|
492
533
|
|
|
493
534
|
getCurrentDeviceType() {
|
|
494
|
-
return
|
|
535
|
+
return this.state?.identity.deviceType ?? EDeviceType.Unknown;
|
|
495
536
|
}
|
|
496
537
|
|
|
497
538
|
getCurrentDeviceId() {
|
|
498
|
-
return this.
|
|
539
|
+
return this.state?.identity.deviceId || undefined;
|
|
499
540
|
}
|
|
500
541
|
|
|
501
542
|
getCurrentSerialNo() {
|
|
502
|
-
return this.
|
|
543
|
+
return this.state?.identity.serialNo ?? '';
|
|
503
544
|
}
|
|
504
545
|
|
|
505
546
|
getConnectId() {
|
|
506
547
|
const serialNo = this.getCurrentSerialNo();
|
|
507
548
|
if (serialNo) return serialNo;
|
|
508
549
|
|
|
509
|
-
// connectId
|
|
510
|
-
//
|
|
511
|
-
// features.serialNo / deviceId 的业务语义。
|
|
550
|
+
// connectId is an internal routing key. Falling back to the transport descriptor
|
|
551
|
+
// does not change the business meaning of features.serialNo or deviceId.
|
|
512
552
|
return this.originalDescriptor.path || this.originalDescriptor.id || '';
|
|
513
553
|
}
|
|
514
554
|
|
|
515
555
|
getCurrentBleName() {
|
|
516
|
-
return
|
|
556
|
+
return this.state?.identity.bleName ?? null;
|
|
517
557
|
}
|
|
518
558
|
|
|
519
559
|
getCurrentLabel() {
|
|
520
|
-
return
|
|
560
|
+
return this.state?.identity.label ?? null;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
getCurrentDisplayName() {
|
|
564
|
+
if (!this.state) return null;
|
|
565
|
+
|
|
566
|
+
const label = this.getCurrentLabel();
|
|
567
|
+
if (label) return label;
|
|
568
|
+
|
|
569
|
+
const bleName = this.getCurrentBleName();
|
|
570
|
+
if (bleName) return bleName;
|
|
571
|
+
|
|
572
|
+
const deviceType = this.getCurrentDeviceType();
|
|
573
|
+
if (deviceType === EDeviceType.ClassicPure) {
|
|
574
|
+
return 'OneKey Classic 1S';
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
return `OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
|
|
521
578
|
}
|
|
522
579
|
|
|
523
580
|
getCurrentPassphraseProtection() {
|
|
524
|
-
return this.
|
|
581
|
+
return this.state?.status.passphraseProtection;
|
|
525
582
|
}
|
|
526
583
|
|
|
527
584
|
getCurrentFirmwareType() {
|
|
528
|
-
return
|
|
585
|
+
return this.state?.identity.firmwareType ?? EFirmwareType.Universal;
|
|
529
586
|
}
|
|
530
587
|
|
|
531
588
|
getCurrentFirmwareVersionString() {
|
|
532
|
-
return
|
|
589
|
+
return parseDeviceVersion(this.state?.versions.firmware).join('.');
|
|
533
590
|
}
|
|
534
591
|
|
|
535
592
|
getCurrentBLEFirmwareVersionString() {
|
|
536
|
-
if (!this.
|
|
537
|
-
return
|
|
593
|
+
if (!this.state) return undefined;
|
|
594
|
+
return parseDeviceVersion(this.state.versions.ble).join('.');
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
getCurrentBootloaderVersionString() {
|
|
598
|
+
if (!this.state) return undefined;
|
|
599
|
+
return parseDeviceVersion(this.state.versions.bootloader).join('.');
|
|
538
600
|
}
|
|
539
601
|
|
|
540
602
|
getCurrentSafetyChecks() {
|
|
541
|
-
return this.
|
|
603
|
+
return this.state?.settings.safetyChecks;
|
|
542
604
|
}
|
|
543
605
|
|
|
544
606
|
getCurrentMethodVersionRange(
|
|
@@ -583,8 +645,6 @@ export class Device extends EventEmitter {
|
|
|
583
645
|
}
|
|
584
646
|
|
|
585
647
|
supportInputPinOnSoftware(): SupportFeatureType {
|
|
586
|
-
if (this.features) return supportInputPinOnSoftware(this.features);
|
|
587
|
-
|
|
588
648
|
const deviceType = this.getCurrentDeviceType();
|
|
589
649
|
if (
|
|
590
650
|
deviceType === EDeviceType.Touch ||
|
|
@@ -602,15 +662,12 @@ export class Device extends EventEmitter {
|
|
|
602
662
|
}
|
|
603
663
|
|
|
604
664
|
supportModifyHomescreen(): SupportFeatureType {
|
|
605
|
-
// Pro2
|
|
606
|
-
//
|
|
607
|
-
// 包含 homescreen 字段,V2 固件从首个版本即支持修改主屏。
|
|
665
|
+
// Pro2 has an independent 1.x version line and must not use the Touch/Pro 3.4.0
|
|
666
|
+
// threshold. ApplySettings includes homescreen from the first V2 firmware version.
|
|
608
667
|
if (this.isProtocolV2()) {
|
|
609
668
|
return { support: true };
|
|
610
669
|
}
|
|
611
670
|
|
|
612
|
-
if (this.features) return supportModifyHomescreen(this.features);
|
|
613
|
-
|
|
614
671
|
const deviceType = this.getCurrentDeviceType();
|
|
615
672
|
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
|
|
616
673
|
return { support: true };
|
|
@@ -622,29 +679,29 @@ export class Device extends EventEmitter {
|
|
|
622
679
|
};
|
|
623
680
|
}
|
|
624
681
|
|
|
625
|
-
private generateStateKey(deviceId: string, passphraseState?: string) {
|
|
626
|
-
if (passphraseState) {
|
|
627
|
-
return `${deviceId}@${passphraseState}`;
|
|
628
|
-
}
|
|
629
|
-
return deviceId;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
682
|
private getSessionCacheDeviceKey(_deviceId?: string) {
|
|
633
683
|
const deviceId = _deviceId || this.getCurrentDeviceId();
|
|
634
684
|
if (deviceId) return deviceId;
|
|
635
685
|
if (this.isProtocolV2()) {
|
|
636
|
-
return this.originalDescriptor.path
|
|
686
|
+
return this.originalDescriptor.path;
|
|
637
687
|
}
|
|
638
688
|
return undefined;
|
|
639
689
|
}
|
|
640
690
|
|
|
691
|
+
private reconcileSessionCacheDeviceIdentity(previousDeviceId?: string) {
|
|
692
|
+
deviceWalletSessionStore.reconcileDeviceIdentity({
|
|
693
|
+
temporaryKey: this.isProtocolV2() ? this.originalDescriptor.path : undefined,
|
|
694
|
+
previousDeviceId,
|
|
695
|
+
nextDeviceId: this.getCurrentDeviceId(),
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
|
|
641
699
|
getInternalState(_deviceId?: string) {
|
|
642
|
-
Log.debug('getInternalState session cache: ', deviceSessionCache);
|
|
643
700
|
Log.debug(
|
|
644
701
|
'getInternalState session param: ',
|
|
645
702
|
`device_id: ${_deviceId}`,
|
|
646
|
-
`
|
|
647
|
-
`
|
|
703
|
+
`currentDeviceId: ${this.getCurrentDeviceId()}`,
|
|
704
|
+
`hasPassphraseState: ${Boolean(this.passphraseState)}`
|
|
648
705
|
);
|
|
649
706
|
|
|
650
707
|
const deviceId = this.getSessionCacheDeviceKey(_deviceId);
|
|
@@ -657,8 +714,7 @@ export class Device extends EventEmitter {
|
|
|
657
714
|
// downstream call carries it and hits the primary lookup below.
|
|
658
715
|
if (!this.passphraseState) return undefined;
|
|
659
716
|
|
|
660
|
-
|
|
661
|
-
return deviceSessionCache[usePassKey];
|
|
717
|
+
return deviceWalletSessionStore.get(deviceId, this.passphraseState);
|
|
662
718
|
}
|
|
663
719
|
|
|
664
720
|
// attach to pin to fix internal state
|
|
@@ -673,40 +729,30 @@ export class Device extends EventEmitter {
|
|
|
673
729
|
'updateInternalState session param: ',
|
|
674
730
|
`device_id: ${deviceId}`,
|
|
675
731
|
`enablePassphrase: ${enablePassphrase}`,
|
|
676
|
-
`
|
|
677
|
-
`
|
|
678
|
-
`
|
|
732
|
+
`hasPassphraseState: ${Boolean(passphraseState)}`,
|
|
733
|
+
`hasSessionId: ${Boolean(sessionId)}`,
|
|
734
|
+
`hasFeaturesSessionId: ${Boolean(featuresSessionId)}`
|
|
679
735
|
);
|
|
680
736
|
|
|
681
737
|
const cacheDeviceKey = this.getSessionCacheDeviceKey(deviceId);
|
|
682
738
|
if (!cacheDeviceKey) return;
|
|
683
739
|
|
|
684
740
|
if (enablePassphrase) {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
} else if (featuresSessionId) {
|
|
689
|
-
deviceSessionCache[this.generateStateKey(cacheDeviceKey, passphraseState)] =
|
|
690
|
-
featuresSessionId;
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
// delete the old sessionId
|
|
695
|
-
const oldKey = `${cacheDeviceKey}`;
|
|
696
|
-
if (deviceSessionCache[oldKey]) {
|
|
697
|
-
delete deviceSessionCache[oldKey];
|
|
741
|
+
const walletSessionId =
|
|
742
|
+
sessionId || featuresSessionId || deviceWalletSessionStore.getPending(cacheDeviceKey);
|
|
743
|
+
deviceWalletSessionStore.set(cacheDeviceKey, passphraseState, walletSessionId ?? undefined);
|
|
698
744
|
}
|
|
699
745
|
|
|
700
|
-
|
|
746
|
+
deviceWalletSessionStore.deletePending(cacheDeviceKey);
|
|
701
747
|
}
|
|
702
748
|
|
|
703
749
|
private setInternalState(state: string, initSession?: boolean) {
|
|
704
750
|
Log.debug(
|
|
705
751
|
'setInternalState session param: ',
|
|
706
|
-
`
|
|
752
|
+
`hasState: ${Boolean(state)}`,
|
|
707
753
|
`initSession: ${initSession}`,
|
|
708
|
-
`deviceId: ${this.
|
|
709
|
-
`
|
|
754
|
+
`deviceId: ${this.getCurrentDeviceId()}`,
|
|
755
|
+
`hasPassphraseState: ${Boolean(this.passphraseState)}`
|
|
710
756
|
);
|
|
711
757
|
|
|
712
758
|
if (!this.passphraseState && !initSession) return;
|
|
@@ -714,12 +760,11 @@ export class Device extends EventEmitter {
|
|
|
714
760
|
const deviceId = this.getSessionCacheDeviceKey();
|
|
715
761
|
if (!deviceId) return;
|
|
716
762
|
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
if (
|
|
720
|
-
|
|
763
|
+
if (this.passphraseState) {
|
|
764
|
+
deviceWalletSessionStore.set(deviceId, this.passphraseState, state);
|
|
765
|
+
} else if (initSession) {
|
|
766
|
+
deviceWalletSessionStore.setPending(deviceId, state);
|
|
721
767
|
}
|
|
722
|
-
Log.debug('setInternalState done session cache: ', deviceSessionCache);
|
|
723
768
|
}
|
|
724
769
|
|
|
725
770
|
clearInternalState(_deviceId?: string) {
|
|
@@ -727,67 +772,79 @@ export class Device extends EventEmitter {
|
|
|
727
772
|
|
|
728
773
|
const deviceId = this.getSessionCacheDeviceKey(_deviceId);
|
|
729
774
|
if (!deviceId) return;
|
|
730
|
-
|
|
731
|
-
delete deviceSessionCache[key];
|
|
775
|
+
deviceWalletSessionStore.deletePending(deviceId);
|
|
732
776
|
|
|
733
777
|
if (this.passphraseState) {
|
|
734
|
-
|
|
735
|
-
delete deviceSessionCache[usePassKey];
|
|
778
|
+
deviceWalletSessionStore.delete(deviceId, this.passphraseState);
|
|
736
779
|
}
|
|
737
780
|
}
|
|
738
781
|
|
|
739
782
|
async initialize(options?: InitOptions) {
|
|
740
|
-
// Protocol V2
|
|
783
|
+
// Protocol V2 does not support legacy Initialize; use its dedicated flow.
|
|
741
784
|
if (this.isProtocolV2()) {
|
|
742
785
|
this.passphraseState = options?.passphraseState;
|
|
743
|
-
if (this.
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
786
|
+
if (this.state && !options?.initSession && !this.protocolV2StateNeedsReload) {
|
|
787
|
+
if (this.state.status.mode === 'bootloader' || this.state.status.mode === 'romloader') {
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
// Normal calls reuse the cache. Explicit getDeviceState refreshes, unlock flow,
|
|
791
|
+
// and device events update dynamic state without polling on every SDK call.
|
|
748
792
|
return;
|
|
749
793
|
}
|
|
750
|
-
await this._initializeProtocolV2();
|
|
794
|
+
await this._initializeProtocolV2(options);
|
|
795
|
+
this.protocolV2StateNeedsReload = false;
|
|
751
796
|
return;
|
|
752
797
|
}
|
|
753
798
|
|
|
754
|
-
|
|
799
|
+
try {
|
|
800
|
+
const callInitialize = async (payload: Record<string, unknown>, initSession?: boolean) => {
|
|
801
|
+
const initStartAt = Date.now();
|
|
802
|
+
const { message } = await this.commands.typedCall('Initialize', 'Features', payload, {
|
|
803
|
+
// iOS BLE bound devices can need close to 20 seconds.
|
|
804
|
+
timeoutMs: 25 * 1000,
|
|
805
|
+
});
|
|
806
|
+
this.setLastInitializeDuration(Date.now() - initStartAt);
|
|
807
|
+
this._updateFeatures(message, initSession);
|
|
808
|
+
await TransportManager.reconfigure(this.features);
|
|
809
|
+
};
|
|
755
810
|
|
|
756
|
-
|
|
811
|
+
const expectedDeviceId = options?.deviceId;
|
|
812
|
+
if (expectedDeviceId) {
|
|
813
|
+
// Establish the live physical identity before sending wallet-bound state.
|
|
814
|
+
this.passphraseState = undefined;
|
|
815
|
+
await callInitialize({ is_contains_attach: true });
|
|
816
|
+
if (!this.checkDeviceId(expectedDeviceId)) {
|
|
817
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
757
820
|
|
|
758
|
-
|
|
759
|
-
this.clearInternalState(options?.deviceId);
|
|
760
|
-
}
|
|
821
|
+
this.passphraseState = options?.passphraseState;
|
|
761
822
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
payload.session_id = internalState;
|
|
766
|
-
}
|
|
823
|
+
if (options?.initSession) {
|
|
824
|
+
this.clearInternalState(options?.deviceId);
|
|
825
|
+
}
|
|
767
826
|
|
|
768
|
-
|
|
769
|
-
payload
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
827
|
+
const internalState = this.getInternalState(options?.deviceId);
|
|
828
|
+
const payload: Record<string, unknown> = {
|
|
829
|
+
passphrase_state: options?.passphraseState,
|
|
830
|
+
is_contains_attach: true,
|
|
831
|
+
};
|
|
832
|
+
if (internalState) {
|
|
833
|
+
payload.session_id = internalState;
|
|
834
|
+
}
|
|
835
|
+
if (options?.deriveCardano) {
|
|
836
|
+
payload.derive_cardano = true;
|
|
837
|
+
}
|
|
773
838
|
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
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);
|
|
839
|
+
const requiresWalletInitialize =
|
|
840
|
+
!expectedDeviceId ||
|
|
841
|
+
Boolean(internalState) ||
|
|
842
|
+
Boolean(options?.passphraseState) ||
|
|
843
|
+
options?.deriveCardano === true ||
|
|
844
|
+
options?.initSession === true;
|
|
845
|
+
if (requiresWalletInitialize) {
|
|
846
|
+
await callInitialize(payload, options?.initSession);
|
|
847
|
+
}
|
|
791
848
|
} catch (error) {
|
|
792
849
|
Log.error('Initialization failed:', error);
|
|
793
850
|
throw error;
|
|
@@ -797,57 +854,38 @@ export class Device extends EventEmitter {
|
|
|
797
854
|
/**
|
|
798
855
|
* Device initialization over Protocol V2.
|
|
799
856
|
*
|
|
800
|
-
* Protocol V2
|
|
801
|
-
*
|
|
857
|
+
* Protocol V2 bypasses legacy Initialize/GetFeatures and builds its canonical
|
|
858
|
+
* features state directly from DeviceInfoGet.
|
|
802
859
|
*/
|
|
803
|
-
private async _initializeProtocolV2() {
|
|
860
|
+
private async _initializeProtocolV2(options?: InitOptions) {
|
|
804
861
|
Log.debug('Initialize device via Protocol V2 features adapter');
|
|
805
862
|
|
|
806
863
|
try {
|
|
807
|
-
//
|
|
808
|
-
//
|
|
809
|
-
// 且 reject 后底层调用仍会残留。
|
|
864
|
+
// typedCall applies the request timeout. An outer Promise.race would leak its
|
|
865
|
+
// timer and leave the underlying call active after rejection.
|
|
810
866
|
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
811
867
|
commands: this.commands,
|
|
868
|
+
timeoutMs: options?.protocolV2DeviceInfoTimeoutMs,
|
|
812
869
|
});
|
|
813
|
-
//
|
|
814
|
-
//
|
|
815
|
-
const features = this.
|
|
870
|
+
// The default request excludes SE/hash data and therefore uses basic scope.
|
|
871
|
+
// Full version and verification data require getDeviceState({ scope: 'firmware' }).
|
|
872
|
+
const features = await this.probeProtocolV2RuntimeState(
|
|
873
|
+
deviceInfo,
|
|
874
|
+
options?.protocolV2DeviceInfoTimeoutMs
|
|
875
|
+
);
|
|
816
876
|
Log.debug('Protocol V2 features:', features);
|
|
817
|
-
this.featuresNeedsReload = false;
|
|
818
877
|
} catch (error) {
|
|
819
878
|
Log.error('Protocol V2 initialization failed:', error);
|
|
820
879
|
throw error;
|
|
821
880
|
}
|
|
822
881
|
}
|
|
823
882
|
|
|
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
883
|
async getFeatures() {
|
|
846
884
|
if (this.isProtocolV2()) {
|
|
847
885
|
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
848
886
|
commands: this.commands,
|
|
849
887
|
});
|
|
850
|
-
return this.
|
|
888
|
+
return this.probeProtocolV2RuntimeState(deviceInfo);
|
|
851
889
|
}
|
|
852
890
|
|
|
853
891
|
const { message } = await this.commands.typedCall('GetFeatures', 'Features', {});
|
|
@@ -855,36 +893,249 @@ export class Device extends EventEmitter {
|
|
|
855
893
|
return this.features;
|
|
856
894
|
}
|
|
857
895
|
|
|
896
|
+
async getDeviceState(params: DeviceStateReadOptions = {}) {
|
|
897
|
+
const refresh = new Set(params.refreshSections ?? []);
|
|
898
|
+
const getProtocolV2DeviceInfoRequest = () => {
|
|
899
|
+
if (refresh.has('verification')) return PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST;
|
|
900
|
+
if (refresh.has('versions')) return PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST;
|
|
901
|
+
return PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST;
|
|
902
|
+
};
|
|
903
|
+
let initializedWithDeviceInfo = false;
|
|
904
|
+
let refreshedDeviceInfo: ProtocolV2DeviceInfo | undefined;
|
|
905
|
+
|
|
906
|
+
if (!this.state) {
|
|
907
|
+
if (this.isProtocolV2()) {
|
|
908
|
+
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
909
|
+
commands: this.commands,
|
|
910
|
+
request: getProtocolV2DeviceInfoRequest(),
|
|
911
|
+
});
|
|
912
|
+
await this.probeProtocolV2RuntimeState(deviceInfo);
|
|
913
|
+
refreshedDeviceInfo = deviceInfo;
|
|
914
|
+
initializedWithDeviceInfo = true;
|
|
915
|
+
} else {
|
|
916
|
+
await this.getFeatures();
|
|
917
|
+
}
|
|
918
|
+
} else if (!this.isProtocolV2() && refresh.size > 0) {
|
|
919
|
+
await this.getFeatures();
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
if (!this.isProtocolV2() && refresh.has('verification')) {
|
|
923
|
+
const { message } = await this.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
|
|
924
|
+
this.updateState(mapProtocolV1OnekeyFeaturesToState(message), 'device-info');
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
if (this.isProtocolV2()) {
|
|
928
|
+
const refreshDeviceInfo =
|
|
929
|
+
refresh.has('identity') || refresh.has('versions') || refresh.has('verification');
|
|
930
|
+
if (refreshDeviceInfo && !initializedWithDeviceInfo) {
|
|
931
|
+
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
932
|
+
commands: this.commands,
|
|
933
|
+
request: getProtocolV2DeviceInfoRequest(),
|
|
934
|
+
});
|
|
935
|
+
refreshedDeviceInfo = deviceInfo;
|
|
936
|
+
if (!refresh.has('status')) {
|
|
937
|
+
this.updateState(
|
|
938
|
+
mapProtocolV2DeviceInfoToState(deviceInfo, this.state?.status.mode),
|
|
939
|
+
'device-info'
|
|
940
|
+
);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
if (refresh.has('status') && !initializedWithDeviceInfo) {
|
|
945
|
+
const deviceInfo =
|
|
946
|
+
refreshedDeviceInfo ??
|
|
947
|
+
(await requestProtocolV2DeviceInfo({
|
|
948
|
+
commands: this.commands,
|
|
949
|
+
request: getProtocolV2DeviceInfoRequest(),
|
|
950
|
+
}));
|
|
951
|
+
await this.probeProtocolV2RuntimeState(deviceInfo);
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
if (refresh.has('settings') && this.state?.status.mode === 'normal') {
|
|
955
|
+
const { message } = await this.commands.typedCall(
|
|
956
|
+
'DeviceSettingsGet',
|
|
957
|
+
'DeviceSettings',
|
|
958
|
+
{}
|
|
959
|
+
);
|
|
960
|
+
this.updateState(mapDeviceSettingsToState(message), 'settings-read');
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
if (!this.state) {
|
|
965
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
|
|
966
|
+
}
|
|
967
|
+
return params.includeRaw ? cloneDeviceState(this.state) : createPublicDeviceState(this.state);
|
|
968
|
+
}
|
|
969
|
+
|
|
858
970
|
_updateFeatures(protoFeatures: PROTO.Features | Features, initSession?: boolean) {
|
|
971
|
+
const previousDeviceId = this.getCurrentDeviceId();
|
|
859
972
|
let feat =
|
|
860
973
|
'protocol' in protoFeatures
|
|
861
974
|
? protoFeatures
|
|
862
975
|
: buildProtocolV1FeaturesPayload(protoFeatures, this.features);
|
|
863
976
|
|
|
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
977
|
feat.unlocked = feat.unlocked ?? true;
|
|
872
978
|
|
|
873
979
|
feat = fixFeaturesFirmwareVersion(feat);
|
|
874
980
|
|
|
875
|
-
this.
|
|
876
|
-
this.
|
|
877
|
-
|
|
981
|
+
this.updateState(mapFeaturesToState(feat), 'initialize');
|
|
982
|
+
this.reconcileSessionCacheDeviceIdentity(previousDeviceId);
|
|
983
|
+
if (feat.deviceId && feat.sessionId) {
|
|
984
|
+
this.setInternalState(feat.sessionId, initSession);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
updateState(patch: DeviceStatePatch, source: DeviceStateUpdateSource) {
|
|
989
|
+
const result = this.stateStore.update(patch, source);
|
|
990
|
+
if (result.changedKeys.length === 0) return result.state;
|
|
991
|
+
|
|
992
|
+
const event: DeviceStateEvent = {
|
|
993
|
+
connectId: this.getConnectId() ?? null,
|
|
994
|
+
state: createPublicDeviceState(result.state),
|
|
995
|
+
revision: result.revision,
|
|
996
|
+
source,
|
|
997
|
+
changedKeys: result.changedKeys,
|
|
998
|
+
};
|
|
999
|
+
Log.debug('Device state patch committed', {
|
|
1000
|
+
source,
|
|
1001
|
+
keys: result.changedKeys,
|
|
1002
|
+
});
|
|
1003
|
+
this.emit(DEVICE.STATE, this, event);
|
|
1004
|
+
if (result.state.protocol === 'V1') {
|
|
1005
|
+
this.emit(DEVICE.FEATURES, this, projectFeatures(result.state));
|
|
1006
|
+
}
|
|
1007
|
+
return result.state;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
updateFeaturesPatch(patch: Partial<Features>, source: DeviceStateUpdateSource) {
|
|
1011
|
+
const currentFeatures = this.features;
|
|
1012
|
+
if (!currentFeatures) return undefined;
|
|
1013
|
+
|
|
1014
|
+
const features = mergeDeviceFeaturesPatch(currentFeatures, patch);
|
|
1015
|
+
if (features === currentFeatures) return currentFeatures;
|
|
1016
|
+
|
|
1017
|
+
const normalized = fixFeaturesFirmwareVersion(features);
|
|
1018
|
+
this.updateState(mapFeaturesToState(normalized), source);
|
|
1019
|
+
return this.features;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
async probeProtocolV2RuntimeState(deviceInfo: ProtocolV2DeviceInfo, timeoutMs?: number) {
|
|
1023
|
+
let deviceStatus: DeviceStatus;
|
|
1024
|
+
try {
|
|
1025
|
+
deviceStatus = await requestProtocolV2DeviceStatus({
|
|
1026
|
+
commands: this.commands,
|
|
1027
|
+
timeoutMs,
|
|
1028
|
+
});
|
|
1029
|
+
} catch (error) {
|
|
1030
|
+
const runtimeMode = getProtocolV2RuntimeMode({
|
|
1031
|
+
deviceInfo,
|
|
1032
|
+
deviceStatusAvailable: false,
|
|
1033
|
+
});
|
|
1034
|
+
Log.debug('Protocol V2 DeviceStatusGet unavailable; use temporary loader fallback', {
|
|
1035
|
+
runtimeMode,
|
|
1036
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1037
|
+
});
|
|
1038
|
+
return this.updateProtocolV2Features(deviceInfo, null, runtimeMode);
|
|
1039
|
+
}
|
|
1040
|
+
return this.updateProtocolV2Features(deviceInfo, deviceStatus, 'normal');
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
updateProtocolV2Features(
|
|
1044
|
+
deviceInfo?: ProtocolV2DeviceInfo,
|
|
1045
|
+
deviceStatus?: DeviceStatus | null,
|
|
1046
|
+
runtimeMode?: ProtocolV2RuntimeMode
|
|
1047
|
+
) {
|
|
1048
|
+
const previousDeviceId = this.getCurrentDeviceId();
|
|
1049
|
+
const resolvedMode =
|
|
1050
|
+
runtimeMode ??
|
|
1051
|
+
(deviceStatus
|
|
1052
|
+
? getProtocolV2RuntimeMode({ deviceInfo, deviceStatusAvailable: true })
|
|
1053
|
+
: this.state?.status.mode);
|
|
1054
|
+
if (deviceInfo) {
|
|
1055
|
+
this.updateState(mapProtocolV2DeviceInfoToState(deviceInfo, resolvedMode), 'device-info');
|
|
1056
|
+
}
|
|
1057
|
+
if (deviceStatus) {
|
|
1058
|
+
this.updateState(mapProtocolV2DeviceStatusToState(deviceStatus), 'device-status');
|
|
1059
|
+
}
|
|
1060
|
+
this.reconcileSessionCacheDeviceIdentity(previousDeviceId);
|
|
1061
|
+
return this.features as Features;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
updateProtocolV2Status(status: DeviceStatus) {
|
|
1065
|
+
const previousDeviceInfo = this.state?.raw?.protocolV2DeviceInfo;
|
|
1066
|
+
const previousStatus = this.state?.raw?.protocolV2DeviceStatus;
|
|
1067
|
+
return this.updateProtocolV2Features(previousDeviceInfo, {
|
|
1068
|
+
...previousStatus,
|
|
1069
|
+
...status,
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
markTransportDisconnected() {
|
|
1074
|
+
this.deviceAcquired = false;
|
|
1075
|
+
if (!this.isProtocolV2()) return;
|
|
1076
|
+
this.protocolV2StateNeedsReload = true;
|
|
1077
|
+
this.clearPreInitialized();
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
invalidateAfterWipe() {
|
|
1081
|
+
const deviceId = this.getCurrentDeviceId();
|
|
1082
|
+
if (deviceId) {
|
|
1083
|
+
deviceWalletSessionStore.deleteDevice(deviceId);
|
|
1084
|
+
}
|
|
1085
|
+
if (this.isProtocolV2() && this.originalDescriptor.path !== deviceId) {
|
|
1086
|
+
deviceWalletSessionStore.deleteDevice(this.originalDescriptor.path);
|
|
1087
|
+
this.protocolV2StateNeedsReload = true;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
this.passphraseState = undefined;
|
|
1091
|
+
this.stateStore = new DeviceStateStore();
|
|
1092
|
+
this.clearPreInitialized();
|
|
1093
|
+
this.needReloadDevice = true;
|
|
878
1094
|
}
|
|
879
1095
|
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
1096
|
+
markProtocolV2Reboot(rebootType: DeviceRebootType) {
|
|
1097
|
+
if (!this.isProtocolV2()) return;
|
|
1098
|
+
|
|
1099
|
+
this.protocolV2StateNeedsReload = true;
|
|
1100
|
+
this.clearPreInitialized();
|
|
1101
|
+
let loaderMode: 'bootloader' | 'romloader' | undefined;
|
|
1102
|
+
if (rebootType === DeviceRebootType.Bootloader) {
|
|
1103
|
+
loaderMode = 'bootloader';
|
|
1104
|
+
} else if (rebootType === DeviceRebootType.Romloader) {
|
|
1105
|
+
loaderMode = 'romloader';
|
|
1106
|
+
}
|
|
1107
|
+
if (loaderMode) {
|
|
1108
|
+
this.updateState(
|
|
1109
|
+
{
|
|
1110
|
+
identity: { deviceId: null },
|
|
1111
|
+
status: {
|
|
1112
|
+
mode: loaderMode,
|
|
1113
|
+
initialized: null,
|
|
1114
|
+
unlocked: null,
|
|
1115
|
+
firmwarePresent: null,
|
|
1116
|
+
backupRequired: null,
|
|
1117
|
+
noBackup: null,
|
|
1118
|
+
unfinishedBackup: null,
|
|
1119
|
+
recoveryMode: null,
|
|
1120
|
+
passphraseProtection: null,
|
|
1121
|
+
pinProtection: null,
|
|
1122
|
+
attachToPinEnabled: null,
|
|
1123
|
+
unlockedAttachPin: null,
|
|
1124
|
+
},
|
|
1125
|
+
raw: { protocolV2DeviceStatus: null },
|
|
1126
|
+
},
|
|
1127
|
+
'transport-reconnect'
|
|
1128
|
+
);
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
this.updateState(
|
|
1133
|
+
{
|
|
1134
|
+
status: { mode: 'normal', unlocked: null },
|
|
1135
|
+
raw: { protocolV2DeviceStatus: null },
|
|
1136
|
+
},
|
|
1137
|
+
'transport-reconnect'
|
|
883
1138
|
);
|
|
884
|
-
this.features = features;
|
|
885
|
-
this.featuresNeedsReload = false;
|
|
886
|
-
this.emit(DEVICE.FEATURES, this, features);
|
|
887
|
-
return features;
|
|
888
1139
|
}
|
|
889
1140
|
|
|
890
1141
|
/**
|
|
@@ -905,8 +1156,7 @@ export class Device extends EventEmitter {
|
|
|
905
1156
|
}
|
|
906
1157
|
|
|
907
1158
|
if (forceUpdate) {
|
|
908
|
-
//
|
|
909
|
-
// 不能让覆盖丢掉已探测的协议结果。
|
|
1159
|
+
// Enumerated descriptors may omit protocolType, so preserve an actively probed value.
|
|
910
1160
|
this.originalDescriptor = {
|
|
911
1161
|
...descriptor,
|
|
912
1162
|
protocolType: descriptor.protocolType ?? this.originalDescriptor.protocolType,
|
|
@@ -931,19 +1181,37 @@ export class Device extends EventEmitter {
|
|
|
931
1181
|
|
|
932
1182
|
options = parseRunOptions(options);
|
|
933
1183
|
|
|
934
|
-
|
|
935
|
-
|
|
1184
|
+
const runPromise = createDeferred<void>();
|
|
1185
|
+
this.runPromise = runPromise;
|
|
1186
|
+
this._runInner(fn, options, runPromise).catch(error => {
|
|
1187
|
+
if (this.runPromise === runPromise) {
|
|
1188
|
+
this.runPromise = null;
|
|
1189
|
+
}
|
|
1190
|
+
runPromise.reject(error);
|
|
1191
|
+
});
|
|
1192
|
+
return runPromise.promise;
|
|
936
1193
|
}
|
|
937
1194
|
|
|
938
|
-
async _runInner<T>(
|
|
1195
|
+
async _runInner<T>(
|
|
1196
|
+
fn: (() => Promise<T>) | undefined,
|
|
1197
|
+
options: RunOptions,
|
|
1198
|
+
runPromise: Deferred<void>
|
|
1199
|
+
) {
|
|
1200
|
+
const clearRunPromise = () => {
|
|
1201
|
+
if (this.runPromise === runPromise) {
|
|
1202
|
+
this.runPromise = null;
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
|
|
939
1206
|
if (!this.isUsedHere() || this.commands.disposed) {
|
|
940
1207
|
const env = DataManager.getSettings('env');
|
|
941
1208
|
if (env !== 'react-native') {
|
|
942
1209
|
try {
|
|
943
1210
|
await this.acquire(options.connectProtocol);
|
|
944
1211
|
} catch (error) {
|
|
945
|
-
|
|
946
|
-
|
|
1212
|
+
clearRunPromise();
|
|
1213
|
+
runPromise.reject(error);
|
|
1214
|
+
return;
|
|
947
1215
|
}
|
|
948
1216
|
|
|
949
1217
|
try {
|
|
@@ -953,16 +1221,19 @@ export class Device extends EventEmitter {
|
|
|
953
1221
|
}
|
|
954
1222
|
}
|
|
955
1223
|
} catch (error) {
|
|
956
|
-
this.
|
|
1224
|
+
await this.release();
|
|
1225
|
+
clearRunPromise();
|
|
957
1226
|
if (error instanceof HardwareError) {
|
|
958
|
-
|
|
1227
|
+
runPromise.reject(error);
|
|
1228
|
+
return;
|
|
959
1229
|
}
|
|
960
|
-
|
|
1230
|
+
runPromise.reject(
|
|
961
1231
|
ERRORS.TypedError(
|
|
962
1232
|
HardwareErrorCode.DeviceInitializeFailed,
|
|
963
1233
|
`Initialize failed: ${error.message as string}, code: ${error.code as string}`
|
|
964
1234
|
)
|
|
965
1235
|
);
|
|
1236
|
+
return;
|
|
966
1237
|
}
|
|
967
1238
|
} else if (env === 'react-native') {
|
|
968
1239
|
// TODO: implement react-native acquire
|
|
@@ -981,9 +1252,7 @@ export class Device extends EventEmitter {
|
|
|
981
1252
|
try {
|
|
982
1253
|
await fn();
|
|
983
1254
|
} catch (e) {
|
|
984
|
-
|
|
985
|
-
this.runPromise.reject(e);
|
|
986
|
-
}
|
|
1255
|
+
runPromise.reject(e);
|
|
987
1256
|
|
|
988
1257
|
if (
|
|
989
1258
|
e instanceof HardwareError &&
|
|
@@ -996,7 +1265,7 @@ export class Device extends EventEmitter {
|
|
|
996
1265
|
Log.debug(`error code ${e.errorCode} release device, mainId: ${this.mainId}`);
|
|
997
1266
|
}
|
|
998
1267
|
|
|
999
|
-
|
|
1268
|
+
clearRunPromise();
|
|
1000
1269
|
return;
|
|
1001
1270
|
}
|
|
1002
1271
|
}
|
|
@@ -1010,11 +1279,8 @@ export class Device extends EventEmitter {
|
|
|
1010
1279
|
Log.debug('release device, mainId: ', this.mainId);
|
|
1011
1280
|
}
|
|
1012
1281
|
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
this.runPromise = null;
|
|
1282
|
+
runPromise.resolve();
|
|
1283
|
+
clearRunPromise();
|
|
1018
1284
|
}
|
|
1019
1285
|
|
|
1020
1286
|
async interruptionFromOutside() {
|
|
@@ -1053,33 +1319,37 @@ export class Device extends EventEmitter {
|
|
|
1053
1319
|
}
|
|
1054
1320
|
|
|
1055
1321
|
getMode() {
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1322
|
+
switch (this.state?.status.mode) {
|
|
1323
|
+
case 'bootloader':
|
|
1324
|
+
case 'romloader':
|
|
1325
|
+
return EOneKeyDeviceMode.bootloader;
|
|
1326
|
+
case 'notInitialized':
|
|
1327
|
+
return EOneKeyDeviceMode.notInitialized;
|
|
1328
|
+
case 'backupMode':
|
|
1329
|
+
return EOneKeyDeviceMode.backupMode;
|
|
1330
|
+
case 'normal':
|
|
1331
|
+
return EOneKeyDeviceMode.normal;
|
|
1332
|
+
default:
|
|
1333
|
+
break;
|
|
1064
1334
|
}
|
|
1065
1335
|
|
|
1066
|
-
if (this.features?.noBackup) {
|
|
1067
|
-
// backup mode
|
|
1068
|
-
return EOneKeyDeviceMode.backupMode;
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
// normal mode
|
|
1072
1336
|
return EOneKeyDeviceMode.normal;
|
|
1073
1337
|
}
|
|
1074
1338
|
|
|
1339
|
+
getStatus() {
|
|
1340
|
+
if (this.isUsedElsewhere()) return 'occupied' as const;
|
|
1341
|
+
if (this.isUsedHere()) return 'used' as const;
|
|
1342
|
+
return 'available' as const;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1075
1345
|
getFirmwareVersion() {
|
|
1076
|
-
if (!this.
|
|
1077
|
-
return
|
|
1346
|
+
if (!this.state) return null;
|
|
1347
|
+
return parseDeviceVersion(this.state.versions.firmware);
|
|
1078
1348
|
}
|
|
1079
1349
|
|
|
1080
1350
|
getBLEFirmwareVersion() {
|
|
1081
|
-
if (!this.
|
|
1082
|
-
return
|
|
1351
|
+
if (!this.state) return null;
|
|
1352
|
+
return parseDeviceVersion(this.state.versions.ble);
|
|
1083
1353
|
}
|
|
1084
1354
|
|
|
1085
1355
|
isUsed() {
|
|
@@ -1097,7 +1367,7 @@ export class Device extends EventEmitter {
|
|
|
1097
1367
|
isUsedHere() {
|
|
1098
1368
|
const env = DataManager.getSettings('env');
|
|
1099
1369
|
if (DataManager.isBleConnect(env)) {
|
|
1100
|
-
return
|
|
1370
|
+
return this.deviceAcquired;
|
|
1101
1371
|
}
|
|
1102
1372
|
return this.isUsed() && this.originalDescriptor.session === this.mainId;
|
|
1103
1373
|
}
|
|
@@ -1107,26 +1377,29 @@ export class Device extends EventEmitter {
|
|
|
1107
1377
|
}
|
|
1108
1378
|
|
|
1109
1379
|
isBootloader() {
|
|
1110
|
-
|
|
1380
|
+
if (!this.state) return undefined;
|
|
1381
|
+
return this.state.status.mode === 'bootloader' || this.state.status.mode === 'romloader';
|
|
1111
1382
|
}
|
|
1112
1383
|
|
|
1113
1384
|
isInitialized() {
|
|
1114
|
-
|
|
1385
|
+
if (!this.state) return undefined;
|
|
1386
|
+
return this.state.status.initialized === true;
|
|
1115
1387
|
}
|
|
1116
1388
|
|
|
1117
1389
|
isSeedless() {
|
|
1118
|
-
|
|
1390
|
+
if (!this.state) return undefined;
|
|
1391
|
+
return this.state.status.noBackup === true;
|
|
1119
1392
|
}
|
|
1120
1393
|
|
|
1121
1394
|
isUnacquired(): boolean {
|
|
1122
|
-
return this.
|
|
1395
|
+
return this.state === undefined;
|
|
1123
1396
|
}
|
|
1124
1397
|
|
|
1125
1398
|
hasUnexpectedMode(allow: string[], require: string[]) {
|
|
1126
1399
|
// both allow and require cases might generate single unexpected mode
|
|
1127
1400
|
if (!this.isUnacquired()) {
|
|
1128
1401
|
// allow cases
|
|
1129
|
-
if (this.isBootloader() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
|
|
1402
|
+
if (this.isBootloader() && !this.isProtocolV2() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
|
|
1130
1403
|
return UI_REQUEST.BOOTLOADER;
|
|
1131
1404
|
}
|
|
1132
1405
|
if (!this.isInitialized() && !allow.includes(UI_REQUEST.NOT_INITIALIZE)) {
|
|
@@ -1150,7 +1423,7 @@ export class Device extends EventEmitter {
|
|
|
1150
1423
|
deviceType === EDeviceType.Touch ||
|
|
1151
1424
|
deviceType === EDeviceType.Pro ||
|
|
1152
1425
|
deviceType === EDeviceType.Pro2;
|
|
1153
|
-
const unlocked = this.
|
|
1426
|
+
const unlocked = this.state?.status.unlocked;
|
|
1154
1427
|
const preCheckTouch = isModeT && unlocked === false;
|
|
1155
1428
|
const passphraseProtection = this.getCurrentPassphraseProtection();
|
|
1156
1429
|
|
|
@@ -1163,12 +1436,12 @@ export class Device extends EventEmitter {
|
|
|
1163
1436
|
|
|
1164
1437
|
async lockDevice(): Promise<Success> {
|
|
1165
1438
|
const res = await this.commands.typedCall('LockDevice', 'Success', {});
|
|
1439
|
+
this.updateState({ status: { unlocked: false } }, 'lock');
|
|
1166
1440
|
return res.message;
|
|
1167
1441
|
}
|
|
1168
1442
|
|
|
1169
1443
|
supportUnlockVersionRange(): DeviceFirmwareRange {
|
|
1170
|
-
//
|
|
1171
|
-
// 且 Protocol V2 固件从首个版本即支持 UnLockDevice(见 unlockDevice 的 isProtocolV2 短路)。
|
|
1444
|
+
// This range applies to Protocol V1 Pro devices; Pro2 has a dedicated unlock flow.
|
|
1172
1445
|
return {
|
|
1173
1446
|
pro: {
|
|
1174
1447
|
min: '4.15.0',
|
|
@@ -1176,19 +1449,34 @@ export class Device extends EventEmitter {
|
|
|
1176
1449
|
};
|
|
1177
1450
|
}
|
|
1178
1451
|
|
|
1179
|
-
async unlockDevice() {
|
|
1452
|
+
async unlockDevice(pinType: DeviceSessionPinType = DeviceSessionPinType.Main) {
|
|
1453
|
+
if (this.isProtocolV2()) {
|
|
1454
|
+
try {
|
|
1455
|
+
await this.commands.typedCall('DeviceSessionAskPin', 'Success', { type: pinType });
|
|
1456
|
+
} catch (error) {
|
|
1457
|
+
const errorText =
|
|
1458
|
+
error instanceof Error
|
|
1459
|
+
? `${error.name} ${error.message}`
|
|
1460
|
+
: String((error as { message?: unknown } | null)?.message ?? error ?? '');
|
|
1461
|
+
if (errorText.includes('Failure_UnexpectedMessage')) {
|
|
1462
|
+
throw createDeviceNotSupportMethodError('deviceUnlock', this.getCurrentFirmwareType());
|
|
1463
|
+
}
|
|
1464
|
+
throw error;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
const status = await requestProtocolV2DeviceStatus({ commands: this.commands });
|
|
1468
|
+
return this.updateProtocolV2Status(status);
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1180
1471
|
const firmwareVersion = this.getCurrentFirmwareVersionString() ?? '0.0.0';
|
|
1181
1472
|
const versionRange = this.getCurrentMethodVersionRange(
|
|
1182
1473
|
type => this.supportUnlockVersionRange()[type]
|
|
1183
1474
|
);
|
|
1184
1475
|
|
|
1185
|
-
const supportAttachPinCapability =
|
|
1186
|
-
this.features,
|
|
1476
|
+
const supportAttachPinCapability = this.state?.capabilities.includes(
|
|
1187
1477
|
Enum_Capability.Capability_AttachToPin
|
|
1188
1478
|
);
|
|
1189
|
-
// Pro2 (Protocol V2) 版本线独立于 Pro 系列,固件从首个版本即支持 UnLockDevice
|
|
1190
1479
|
const supportUnlock =
|
|
1191
|
-
this.isProtocolV2() ||
|
|
1192
1480
|
supportAttachPinCapability ||
|
|
1193
1481
|
(versionRange &&
|
|
1194
1482
|
semver.valid(firmwareVersion) &&
|
|
@@ -1196,12 +1484,21 @@ export class Device extends EventEmitter {
|
|
|
1196
1484
|
|
|
1197
1485
|
if (supportUnlock) {
|
|
1198
1486
|
const res = await this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
|
|
1199
|
-
if (this.
|
|
1200
|
-
this.
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1487
|
+
if (this.state) {
|
|
1488
|
+
this.updateState(
|
|
1489
|
+
{
|
|
1490
|
+
status: {
|
|
1491
|
+
unlocked: res.message.unlocked == null ? null : res.message.unlocked,
|
|
1492
|
+
unlockedAttachPin:
|
|
1493
|
+
res.message.unlocked_attach_pin == null ? null : res.message.unlocked_attach_pin,
|
|
1494
|
+
passphraseProtection:
|
|
1495
|
+
res.message.passphrase_protection == null
|
|
1496
|
+
? null
|
|
1497
|
+
: res.message.passphrase_protection,
|
|
1498
|
+
},
|
|
1499
|
+
},
|
|
1500
|
+
'unlock'
|
|
1501
|
+
);
|
|
1205
1502
|
|
|
1206
1503
|
return Promise.resolve(this.features);
|
|
1207
1504
|
}
|
|
@@ -1210,14 +1507,6 @@ export class Device extends EventEmitter {
|
|
|
1210
1507
|
return Promise.resolve(features);
|
|
1211
1508
|
}
|
|
1212
1509
|
|
|
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
1510
|
const { type } = await this.commands.typedCall('GetAddress', 'Address', {
|
|
1222
1511
|
address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
|
|
1223
1512
|
coin_name: 'Testnet',
|
|
@@ -1240,21 +1529,27 @@ export class Device extends EventEmitter {
|
|
|
1240
1529
|
) {
|
|
1241
1530
|
if (this.isUnacquired()) return false;
|
|
1242
1531
|
|
|
1532
|
+
const expectedPassphraseState = useEmptyPassphrase ? undefined : passphraseState;
|
|
1243
1533
|
const { passphraseState: newPassphraseState, unlockedAttachPin } =
|
|
1244
1534
|
await getPassphraseStateWithRefreshDeviceInfo(this, {
|
|
1245
|
-
expectPassphraseState:
|
|
1535
|
+
expectPassphraseState: expectedPassphraseState,
|
|
1246
1536
|
onlyMainPin: useEmptyPassphrase,
|
|
1247
1537
|
});
|
|
1248
1538
|
|
|
1249
1539
|
// Main wallet and unlock Attach Pin, throw safe error
|
|
1250
1540
|
const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
|
|
1251
1541
|
const useErrorAttachPin =
|
|
1252
|
-
unlockedAttachPin &&
|
|
1253
|
-
|
|
1542
|
+
unlockedAttachPin &&
|
|
1543
|
+
expectedPassphraseState &&
|
|
1544
|
+
expectedPassphraseState !== newPassphraseState;
|
|
1545
|
+
const passphraseStateMismatch =
|
|
1546
|
+
!!expectedPassphraseState && expectedPassphraseState !== newPassphraseState;
|
|
1254
1547
|
|
|
1255
1548
|
Log.debug('Check passphrase state safety: ', {
|
|
1256
|
-
|
|
1257
|
-
newPassphraseState,
|
|
1549
|
+
hasExpectedPassphraseState: Boolean(expectedPassphraseState),
|
|
1550
|
+
hasNewPassphraseState: Boolean(newPassphraseState),
|
|
1551
|
+
passphraseStateMatches:
|
|
1552
|
+
Boolean(expectedPassphraseState) && expectedPassphraseState === newPassphraseState,
|
|
1258
1553
|
unlockedAttachPin,
|
|
1259
1554
|
useEmptyPassphrase,
|
|
1260
1555
|
});
|