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