@onekeyfe/hd-core 1.1.34-alpha.3 → 1.1.34-alpha.4
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__/DeviceCommands.test.ts +0 -217
- package/__tests__/evmLedgerLegacySafety.test.ts +4 -15
- package/__tests__/evmSignTransaction.test.ts +1 -1
- package/__tests__/evmSignTypedData.test.ts +1 -1
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +31 -48
- package/__tests__/preInitialize.test.ts +0 -33
- package/dist/api/BaseMethod.d.ts +0 -12
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
- package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +3 -14
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +3 -10
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/api/PromptWebDeviceAccess.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts +1 -5
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumGetAddress.d.ts +6 -2
- package/dist/api/alephium/AlephiumGetAddress.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignMessage.d.ts +5 -2
- package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignTransaction.d.ts +8 -5
- package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetAddress.d.ts +9 -2
- package/dist/api/benfen/BenfenGetAddress.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetPublicKey.d.ts +9 -2
- package/dist/api/benfen/BenfenGetPublicKey.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignMessage.d.ts +8 -2
- package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignTransaction.d.ts +8 -2
- package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCGetAddress.d.ts +11 -1
- package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
- package/dist/api/btc/BTCGetPublicKey.d.ts +11 -1
- package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
- package/dist/api/btc/BTCSignMessage.d.ts +15 -1
- package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
- package/dist/api/btc/BTCSignPsbt.d.ts.map +1 -1
- package/dist/api/btc/BTCSignTransaction.d.ts +11 -1
- package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCVerifyMessage.d.ts +11 -1
- package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
- package/dist/api/btc/helpers/versionLimit.d.ts +11 -2
- package/dist/api/btc/helpers/versionLimit.d.ts.map +1 -1
- package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
- package/dist/api/device/DeviceCancel.d.ts.map +1 -1
- package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
- package/dist/api/device/DeviceFullyUploadResource.d.ts +2 -1
- package/dist/api/device/DeviceFullyUploadResource.d.ts.map +1 -1
- package/dist/api/device/DeviceLock.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceSupportFeatures.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +1 -1
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts +1 -7
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceUploadResource.d.ts.map +1 -1
- package/dist/api/device/DeviceVerify.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.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/EVMGetPublicKey.d.ts.map +1 -1
- package/dist/api/evm/EVMSignMessageEIP712.d.ts +8 -2
- package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/evm/latest/signTypedData.d.ts +1 -1
- package/dist/api/evm/latest/signTypedData.d.ts.map +1 -1
- package/dist/api/evm/latest/signTypedHash.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/getAddress.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/getPublicKey.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/signMessage.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/signTypedData.d.ts +1 -1
- package/dist/api/evm/legacyV1/signTypedData.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/signTypedHash.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/verifyMessage.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +1 -10
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/bootloaderHelper.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +0 -11
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/updateBootloader.d.ts +0 -2
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +1 -9
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/batchGetPublickeys.d.ts +0 -3
- package/dist/api/helpers/batchGetPublickeys.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -29
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.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/neo/NeoGetAddress.d.ts +8 -2
- package/dist/api/neo/NeoGetAddress.d.ts.map +1 -1
- package/dist/api/neo/NeoSignTransaction.d.ts +8 -2
- package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
- package/dist/api/nervos/NervosGetAddress.d.ts +9 -2
- package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -1
- package/dist/api/nervos/NervosSignTransaction.d.ts +12 -9
- package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
- package/dist/api/nexa/NexaGetAddress.d.ts +8 -2
- package/dist/api/nexa/NexaGetAddress.d.ts.map +1 -1
- package/dist/api/nexa/NexaSignTransaction.d.ts +9 -2
- package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotGetAddress.d.ts +0 -3
- package/dist/api/polkadot/PolkadotGetAddress.d.ts.map +1 -1
- package/dist/api/polkadot/networks.d.ts +0 -3
- package/dist/api/polkadot/networks.d.ts.map +1 -1
- package/dist/api/scdo/ScdoGetAddress.d.ts +6 -2
- package/dist/api/scdo/ScdoGetAddress.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignMessage.d.ts +5 -2
- package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignTransaction.d.ts +5 -2
- package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
- package/dist/api/solana/SolGetAddress.d.ts +0 -1
- package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
- package/dist/api/solana/SolSignMessage.d.ts +0 -3
- package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +0 -3
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +0 -6
- package/dist/api/solana/SolSignTransaction.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 +0 -3
- package/dist/api/sui/SuiGetAddress.d.ts.map +1 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts +0 -3
- package/dist/api/sui/SuiGetPublicKey.d.ts.map +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts +0 -3
- package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +2 -5
- package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
- package/dist/api/ton/TonGetAddress.d.ts +0 -3
- package/dist/api/ton/TonGetAddress.d.ts.map +1 -1
- package/dist/api/ton/TonSignData.d.ts +0 -1
- package/dist/api/ton/TonSignData.d.ts.map +1 -1
- package/dist/api/ton/TonSignMessage.d.ts +0 -3
- package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
- package/dist/api/ton/TonSignProof.d.ts +0 -3
- package/dist/api/ton/TonSignProof.d.ts.map +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +0 -3
- package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
- package/dist/api/tron/TronSignTransaction.d.ts +0 -3
- package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
- package/dist/api/utils.d.ts +1 -2
- package/dist/api/utils.d.ts.map +1 -1
- package/dist/constants/index.d.ts +1 -2
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/core/RequestQueue.d.ts +1 -19
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -4
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +5 -9
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/MessagesConfig.d.ts +2 -2
- package/dist/data-manager/MessagesConfig.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts +4 -5
- 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 +16 -60
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +14 -16
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +1 -2
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts +2 -4
- package/dist/device/DevicePool.d.ts.map +1 -1
- 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 +2 -11
- 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 +0 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +2 -26
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +451 -1797
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5556 -26855
- package/dist/inject.d.ts +2 -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/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +2 -4
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceSettings.d.ts +0 -9
- package/dist/types/api/deviceSettings.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +1 -1
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +1 -6
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +1 -4
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +1 -114
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- 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 +1 -2
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +2 -48
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/searchDevices.d.ts +2 -2
- package/dist/types/api/searchDevices.d.ts.map +1 -1
- package/dist/types/device.d.ts +5 -207
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +0 -3
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +0 -33
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/capabilitieUtils.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +9 -17
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts +8 -10
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts +0 -2
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/deviceVersionUtils.d.ts +5 -6
- package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
- package/dist/utils/findDefectiveBatchDevice.d.ts +1 -1
- package/dist/utils/homescreen.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -3
- package/dist/utils/index.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/tracing.d.ts.map +1 -1
- package/dist/utils/versionUtils.d.ts +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +23 -60
- package/src/api/CheckAllFirmwareRelease.ts +3 -16
- package/src/api/CheckBootloaderRelease.ts +2 -1
- package/src/api/CheckFirmwareRelease.ts +2 -1
- package/src/api/FirmwareUpdate.ts +7 -15
- package/src/api/FirmwareUpdateV2.ts +148 -354
- package/src/api/FirmwareUpdateV3.ts +62 -376
- package/src/api/GetFeatures.ts +4 -12
- package/src/api/GetOnekeyFeatures.ts +3 -15
- package/src/api/GetPassphraseState.ts +10 -9
- package/src/api/PromptWebDeviceAccess.ts +1 -10
- package/src/api/SearchDevices.ts +3 -33
- package/src/api/alephium/AlephiumGetAddress.ts +2 -6
- package/src/api/alephium/AlephiumSignMessage.ts +1 -6
- package/src/api/alephium/AlephiumSignTransaction.ts +4 -15
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +21 -25
- package/src/api/aptos/AptosGetAddress.ts +3 -2
- package/src/api/benfen/BenfenGetAddress.ts +7 -11
- package/src/api/benfen/BenfenGetPublicKey.ts +2 -6
- package/src/api/benfen/BenfenSignMessage.ts +1 -6
- package/src/api/benfen/BenfenSignTransaction.ts +1 -6
- package/src/api/btc/BTCGetPublicKey.ts +2 -3
- package/src/api/btc/BTCSignPsbt.ts +2 -1
- package/src/api/btc/helpers/versionLimit.ts +1 -7
- package/src/api/cardano/CardanoSignTransaction.ts +4 -2
- package/src/api/conflux/ConfluxSignTransaction.ts +2 -5
- package/src/api/device/DeviceCancel.ts +0 -1
- package/src/api/device/DeviceChangePin.ts +0 -24
- package/src/api/device/DeviceFullyUploadResource.ts +7 -6
- package/src/api/device/DeviceLock.ts +3 -2
- package/src/api/device/DeviceRebootToBoardloader.ts +1 -11
- package/src/api/device/DeviceRebootToBootloader.ts +1 -11
- package/src/api/device/DeviceSettings.ts +0 -121
- package/src/api/device/DeviceSupportFeatures.ts +13 -2
- package/src/api/device/DeviceUnlock.ts +0 -9
- package/src/api/device/DeviceUpdateBootloader.ts +11 -175
- package/src/api/device/DeviceUploadResource.ts +5 -4
- package/src/api/device/DeviceVerify.ts +2 -1
- package/src/api/device/DeviceWipe.ts +0 -19
- package/src/api/dynex/DnxGetAddress.ts +0 -6
- package/src/api/dynex/DnxSignTransaction.ts +0 -6
- package/src/api/evm/EVMGetAddress.ts +1 -1
- package/src/api/evm/EVMGetPublicKey.ts +4 -3
- package/src/api/evm/EVMSignMessage.ts +1 -1
- package/src/api/evm/EVMSignMessageEIP712.ts +1 -14
- package/src/api/evm/EVMSignTransaction.ts +1 -1
- package/src/api/evm/EVMSignTypedData.ts +18 -30
- package/src/api/evm/EVMVerifyMessage.ts +1 -1
- package/src/api/evm/latest/signTypedHash.ts +4 -2
- package/src/api/evm/legacyV1/getAddress.ts +3 -5
- package/src/api/evm/legacyV1/getPublicKey.ts +3 -5
- package/src/api/evm/legacyV1/signMessage.ts +3 -5
- package/src/api/evm/legacyV1/signTypedData.ts +8 -9
- package/src/api/evm/legacyV1/signTypedHash.ts +7 -7
- package/src/api/evm/legacyV1/verifyMessage.ts +3 -5
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +15 -83
- package/src/api/firmware/bootloaderHelper.ts +2 -3
- package/src/api/firmware/getBinary.ts +1 -1
- package/src/api/firmware/releaseHelper.ts +3 -3
- package/src/api/firmware/updateBootloader.ts +4 -19
- package/src/api/firmware/uploadFirmware.ts +34 -148
- package/src/api/helpers/batchGetPublickeys.ts +6 -51
- package/src/api/index.ts +0 -32
- package/src/api/kaspa/KaspaSignTransaction.ts +3 -2
- package/src/api/lightning/LnurlAuth.ts +0 -4
- package/src/api/neo/NeoGetAddress.ts +1 -6
- package/src/api/neo/NeoSignTransaction.ts +1 -6
- package/src/api/nervos/NervosGetAddress.ts +2 -6
- package/src/api/nervos/NervosSignTransaction.ts +4 -14
- package/src/api/nexa/NexaGetAddress.ts +2 -6
- package/src/api/nexa/NexaSignTransaction.ts +12 -11
- package/src/api/polkadot/networks.ts +0 -9
- package/src/api/scdo/ScdoGetAddress.ts +2 -6
- package/src/api/scdo/ScdoSignMessage.ts +1 -6
- package/src/api/scdo/ScdoSignTransaction.ts +2 -6
- package/src/api/solana/SolGetAddress.ts +0 -4
- package/src/api/solana/SolSignMessage.ts +0 -3
- package/src/api/solana/SolSignOffchainMessage.ts +0 -3
- package/src/api/solana/SolSignTransaction.ts +0 -6
- package/src/api/stellar/StellarGetAddress.ts +1 -10
- package/src/api/stellar/StellarSignTransaction.ts +1 -14
- package/src/api/sui/SuiGetAddress.ts +3 -5
- package/src/api/sui/SuiGetPublicKey.ts +0 -3
- package/src/api/sui/SuiSignMessage.ts +0 -3
- package/src/api/sui/SuiSignTransaction.ts +12 -14
- package/src/api/ton/TonGetAddress.ts +0 -3
- package/src/api/ton/TonSignData.ts +3 -6
- package/src/api/ton/TonSignMessage.ts +5 -6
- package/src/api/ton/TonSignProof.ts +0 -3
- package/src/api/tron/TronSignMessage.ts +1 -4
- package/src/api/tron/TronSignTransaction.ts +0 -3
- package/src/api/utils.ts +3 -7
- package/src/api/xrp/XrpSignTransaction.ts +1 -1
- package/src/constants/index.ts +1 -7
- package/src/core/RequestQueue.ts +4 -124
- package/src/core/index.ts +116 -255
- package/src/data-manager/DataManager.ts +49 -61
- package/src/data-manager/MessagesConfig.ts +14 -14
- package/src/data-manager/TransportManager.ts +12 -38
- package/src/data-manager/connectSettings.ts +0 -15
- package/src/device/Device.ts +164 -759
- package/src/device/DeviceCommands.ts +36 -245
- package/src/device/DeviceConnector.ts +4 -29
- package/src/device/DevicePool.ts +21 -69
- package/src/events/call.ts +0 -6
- package/src/events/core.ts +0 -2
- package/src/events/device.ts +1 -17
- package/src/events/iframe.ts +0 -1
- package/src/events/logBlockEvent.ts +0 -30
- package/src/events/ui-request.ts +2 -32
- package/src/index.ts +0 -9
- package/src/inject.ts +3 -75
- package/src/lowLevelInject.ts +1 -8
- package/src/topLevelInject.ts +1 -7
- package/src/types/api/checkAllFirmwareRelease.ts +2 -4
- package/src/types/api/deviceSettings.ts +0 -9
- package/src/types/api/deviceUnlock.ts +1 -1
- package/src/types/api/deviceUpdateBootloader.ts +1 -10
- package/src/types/api/export.ts +0 -25
- package/src/types/api/firmwareUpdate.ts +1 -163
- package/src/types/api/getFeatures.ts +0 -3
- package/src/types/api/getOnekeyFeatures.ts +0 -3
- package/src/types/api/getPassphraseState.ts +2 -10
- package/src/types/api/index.ts +2 -89
- package/src/types/api/searchDevices.ts +2 -2
- package/src/types/device.ts +5 -266
- package/src/types/params.ts +0 -11
- package/src/types/settings.ts +29 -54
- package/src/utils/capabilitieUtils.ts +2 -1
- package/src/utils/deviceFeaturesUtils.ts +84 -122
- package/src/utils/deviceInfoUtils.ts +87 -38
- package/src/utils/deviceSettings.ts +0 -48
- package/src/utils/deviceVersionUtils.ts +62 -25
- package/src/utils/findDefectiveBatchDevice.ts +8 -8
- package/src/utils/homescreen.ts +0 -10
- package/src/utils/index.ts +0 -4
- package/src/utils/tracing.ts +1 -3
- package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +0 -75
- package/__tests__/RequestQueue.test.ts +0 -140
- package/__tests__/UploadPortfolio.test.ts +0 -46
- package/__tests__/connectSettings.test.ts +0 -61
- package/__tests__/device-lifecycle-events.test.ts +0 -117
- package/__tests__/device-pool-state.test.ts +0 -132
- package/__tests__/device-settings.test.ts +0 -286
- package/__tests__/device-state-mapper.test.ts +0 -229
- package/__tests__/device-utils.test.ts +0 -106
- package/__tests__/device-wallet-session-store.test.ts +0 -191
- package/__tests__/filesystemValidation.test.ts +0 -53
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +0 -119
- package/__tests__/firmware-update/firmware-checkpoint.test.ts +0 -105
- package/__tests__/firmware-update/firmware-host-binding.test.ts +0 -73
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +0 -17
- package/__tests__/firmware-update/firmware-update-plan.test.ts +0 -358
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +0 -200
- package/__tests__/firmware-update/firmware-update-recovery.test.ts +0 -81
- package/__tests__/firmware-update/firmware-upload-source.test.ts +0 -70
- package/__tests__/get-device-state.test.ts +0 -403
- package/__tests__/logBlockEvent.test.ts +0 -61
- package/__tests__/logger.test.ts +0 -34
- package/__tests__/open-wallet-session.test.ts +0 -565
- package/__tests__/pro2Wallpaper.test.ts +0 -39
- package/__tests__/protocol-v2-bootloader-mode.test.ts +0 -37
- package/__tests__/protocol-v2-firmware-targets.test.ts +0 -19
- package/__tests__/protocol-v2.test.ts +0 -6008
- package/__tests__/protocolV2FileWrite.test.ts +0 -67
- package/__tests__/public-pro2-api-boundary.test.ts +0 -66
- package/__tests__/search-devices.test.ts +0 -136
- package/dist/api/ClearSessionCache.d.ts +0 -9
- package/dist/api/ClearSessionCache.d.ts.map +0 -1
- package/dist/api/DirList.d.ts +0 -10
- package/dist/api/DirList.d.ts.map +0 -1
- package/dist/api/DirMake.d.ts +0 -9
- package/dist/api/DirMake.d.ts.map +0 -1
- package/dist/api/DirRemove.d.ts +0 -9
- package/dist/api/DirRemove.d.ts.map +0 -1
- package/dist/api/FileDelete.d.ts +0 -9
- package/dist/api/FileDelete.d.ts.map +0 -1
- package/dist/api/FileRead.d.ts +0 -19
- package/dist/api/FileRead.d.ts.map +0 -1
- package/dist/api/FileWrite.d.ts +0 -25
- package/dist/api/FileWrite.d.ts.map +0 -1
- package/dist/api/FirmwareUpdateV4.d.ts +0 -75
- package/dist/api/FirmwareUpdateV4.d.ts.map +0 -1
- package/dist/api/GetDeviceState.d.ts +0 -7
- package/dist/api/GetDeviceState.d.ts.map +0 -1
- package/dist/api/OpenWalletSession.d.ts +0 -14
- package/dist/api/OpenWalletSession.d.ts.map +0 -1
- package/dist/api/PathInfo.d.ts +0 -10
- package/dist/api/PathInfo.d.ts.map +0 -1
- package/dist/api/UploadPortfolio.d.ts +0 -18
- package/dist/api/UploadPortfolio.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +0 -26
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareCheckpoint.d.ts +0 -15
- package/dist/api/firmware/FirmwareCheckpoint.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareHostBinding.d.ts +0 -6
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +0 -3
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -29
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +0 -25
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.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/helpers/filesystemValidation.d.ts +0 -10
- package/dist/api/helpers/filesystemValidation.d.ts.map +0 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +0 -33
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +0 -7
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +0 -7
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +0 -7
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts +0 -28
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceReboot.d.ts +0 -7
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts +0 -28
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts +0 -16
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts +0 -12
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +0 -26
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +0 -1
- package/dist/api/protocol-v2/FilesystemFormat.d.ts +0 -6
- package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +0 -1
- package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts +0 -6
- package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +0 -1
- package/dist/api/protocol-v2/Ping.d.ts +0 -8
- package/dist/api/protocol-v2/Ping.d.ts.map +0 -1
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +0 -6
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +0 -1
- package/dist/api/protocol-v2/helpers.d.ts +0 -42
- package/dist/api/protocol-v2/helpers.d.ts.map +0 -1
- package/dist/core/deviceEventRegistration.d.ts +0 -11
- package/dist/core/deviceEventRegistration.d.ts.map +0 -1
- package/dist/device/DeviceFeaturesState.d.ts +0 -4
- package/dist/device/DeviceFeaturesState.d.ts.map +0 -1
- package/dist/device/DeviceStateMapper.d.ts +0 -13
- package/dist/device/DeviceStateMapper.d.ts.map +0 -1
- package/dist/device/DeviceStateProjector.d.ts +0 -7
- package/dist/device/DeviceStateProjector.d.ts.map +0 -1
- package/dist/device/DeviceStateStore.d.ts +0 -21
- package/dist/device/DeviceStateStore.d.ts.map +0 -1
- package/dist/device/DeviceWalletSessionStore.d.ts +0 -15
- package/dist/device/DeviceWalletSessionStore.d.ts.map +0 -1
- package/dist/device/cloneDeviceState.d.ts +0 -2
- package/dist/device/cloneDeviceState.d.ts.map +0 -1
- package/dist/device/deviceIdentity.d.ts +0 -5
- package/dist/device/deviceIdentity.d.ts.map +0 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts +0 -12
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +0 -1
- package/dist/deviceProfile/index.d.ts +0 -2
- package/dist/deviceProfile/index.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/deviceSession.d.ts +0 -7
- package/dist/protocols/protocol-v2/deviceSession.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/features.d.ts +0 -88
- package/dist/protocols/protocol-v2/features.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/firmware.d.ts +0 -15
- package/dist/protocols/protocol-v2/firmware.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/index.d.ts +0 -5
- package/dist/protocols/protocol-v2/index.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +0 -2
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts +0 -16
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +0 -39
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +0 -11
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +0 -21
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +0 -13
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdatePlan.d.ts +0 -35
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +0 -43
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +0 -1
- package/dist/types/api/getDeviceState.d.ts +0 -12
- package/dist/types/api/getDeviceState.d.ts.map +0 -1
- package/dist/types/api/openWalletSession.d.ts +0 -35
- package/dist/types/api/openWalletSession.d.ts.map +0 -1
- package/dist/types/api/protocolV2.d.ts +0 -113
- package/dist/types/api/protocolV2.d.ts.map +0 -1
- package/dist/types/api/sessionCache.d.ts +0 -10
- package/dist/types/api/sessionCache.d.ts.map +0 -1
- package/dist/utils/deviceFeaturesCompat.d.ts +0 -13
- package/dist/utils/deviceFeaturesCompat.d.ts.map +0 -1
- package/dist/utils/pro2Wallpaper.d.ts +0 -12
- package/dist/utils/pro2Wallpaper.d.ts.map +0 -1
- package/src/api/ClearSessionCache.ts +0 -28
- package/src/api/DirList.ts +0 -33
- package/src/api/DirMake.ts +0 -23
- package/src/api/DirRemove.ts +0 -23
- package/src/api/FileDelete.ts +0 -23
- package/src/api/FileRead.ts +0 -183
- package/src/api/FileWrite.ts +0 -71
- package/src/api/FirmwareUpdateV4.ts +0 -2279
- package/src/api/GetDeviceState.ts +0 -55
- package/src/api/OpenWalletSession.ts +0 -211
- package/src/api/PathInfo.ts +0 -41
- package/src/api/UploadPortfolio.ts +0 -50
- package/src/api/firmware/FirmwareArtifactSource.ts +0 -278
- package/src/api/firmware/FirmwareCheckpoint.ts +0 -188
- package/src/api/firmware/FirmwareHostBinding.ts +0 -108
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +0 -13
- package/src/api/firmware/FirmwareUpdatePlan.ts +0 -729
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +0 -403
- package/src/api/firmware/progressThrottle.ts +0 -44
- package/src/api/helpers/filesystemValidation.ts +0 -112
- package/src/api/helpers/protocolV2FileWrite.ts +0 -193
- package/src/api/protocol-v2/DeviceFactoryInfoGet.ts +0 -20
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +0 -32
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +0 -61
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +0 -55
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +0 -18
- package/src/api/protocol-v2/DeviceInfoGet.ts +0 -145
- package/src/api/protocol-v2/DeviceReboot.ts +0 -26
- package/src/api/protocol-v2/DeviceSessionOpen.ts +0 -102
- package/src/api/protocol-v2/DeviceSettingsGet.ts +0 -18
- package/src/api/protocol-v2/DeviceSettingsPageShow.ts +0 -70
- package/src/api/protocol-v2/DeviceSettingsSet.ts +0 -44
- package/src/api/protocol-v2/DeviceStatusGet.ts +0 -16
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +0 -131
- package/src/api/protocol-v2/FilesystemFormat.ts +0 -19
- package/src/api/protocol-v2/FilesystemPermissionFix.ts +0 -16
- package/src/api/protocol-v2/Ping.ts +0 -18
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +0 -16
- package/src/api/protocol-v2/helpers.ts +0 -203
- package/src/core/deviceEventRegistration.ts +0 -23
- package/src/data/messages/messages-protocol-v2.json +0 -13544
- package/src/device/DeviceFeaturesState.ts +0 -34
- package/src/device/DeviceStateMapper.ts +0 -348
- package/src/device/DeviceStateProjector.ts +0 -95
- package/src/device/DeviceStateStore.ts +0 -201
- package/src/device/DeviceWalletSessionStore.ts +0 -78
- package/src/device/cloneDeviceState.ts +0 -39
- package/src/device/deviceIdentity.ts +0 -18
- package/src/deviceProfile/buildDeviceFeatures.ts +0 -391
- package/src/deviceProfile/index.ts +0 -4
- package/src/protocols/protocol-v2/deviceSession.ts +0 -24
- package/src/protocols/protocol-v2/features.ts +0 -163
- package/src/protocols/protocol-v2/firmware.ts +0 -21
- package/src/protocols/protocol-v2/index.ts +0 -18
- package/src/protocols/protocol-v2/lockedError.ts +0 -10
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +0 -61
- package/src/protocols/protocol-v2/uiInteraction.ts +0 -210
- package/src/protocols/protocol-v2/unlockRetry.ts +0 -76
- package/src/protocols/protocol-v2/walletSession.ts +0 -202
- package/src/types/api/firmwareUpdateCapabilities.ts +0 -13
- package/src/types/api/firmwareUpdatePlan.ts +0 -52
- package/src/types/api/firmwareUpdatePreparedPlan.ts +0 -55
- package/src/types/api/getDeviceState.ts +0 -19
- package/src/types/api/openWalletSession.ts +0 -54
- package/src/types/api/protocolV2.ts +0 -244
- package/src/types/api/sessionCache.ts +0 -14
- package/src/utils/deviceFeaturesCompat.ts +0 -173
- package/src/utils/pro2Wallpaper.ts +0 -109
package/src/device/Device.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
2
|
import semver from 'semver';
|
|
3
|
-
import {
|
|
3
|
+
import { Enum_Capability } from '@onekeyfe/hd-transport';
|
|
4
4
|
import {
|
|
5
5
|
EDeviceType,
|
|
6
6
|
ERRORS,
|
|
@@ -9,56 +9,31 @@ import {
|
|
|
9
9
|
HardwareError,
|
|
10
10
|
HardwareErrorCode,
|
|
11
11
|
createDeferred,
|
|
12
|
-
createDeviceNotSupportMethodError,
|
|
13
12
|
} from '@onekeyfe/hd-shared';
|
|
14
13
|
|
|
15
14
|
import {
|
|
16
15
|
LoggerNames,
|
|
17
16
|
getDeviceBLEFirmwareVersion,
|
|
18
17
|
getDeviceBleName,
|
|
19
|
-
getDeviceBootloaderVersion,
|
|
20
18
|
getDeviceFirmwareVersion,
|
|
21
19
|
getDeviceLabel,
|
|
22
|
-
getDeviceSerialNo,
|
|
23
20
|
getDeviceType,
|
|
24
|
-
|
|
21
|
+
getDeviceUUID,
|
|
25
22
|
getLogger,
|
|
23
|
+
getMethodVersionRange,
|
|
26
24
|
} from '../utils';
|
|
27
25
|
import {
|
|
28
26
|
fixFeaturesFirmwareVersion,
|
|
29
27
|
getPassphraseStateWithRefreshDeviceInfo,
|
|
30
|
-
supportInputPinOnSoftware,
|
|
31
|
-
supportModifyHomescreen,
|
|
32
28
|
} from '../utils/deviceFeaturesUtils';
|
|
33
29
|
import { generateInstanceId } from '../utils/tracing';
|
|
34
30
|
// eslint-disable-next-line import/no-cycle
|
|
35
31
|
import { DeviceCommands } from './DeviceCommands';
|
|
36
|
-
import { mergeDeviceFeaturesPatch } from './DeviceFeaturesState';
|
|
37
|
-
import {
|
|
38
|
-
mapDeviceSettingsToState,
|
|
39
|
-
mapFeaturesToState,
|
|
40
|
-
mapProtocolV1OnekeyFeaturesToState,
|
|
41
|
-
mapProtocolV2DeviceInfoToState,
|
|
42
|
-
mapProtocolV2DeviceStatusToState,
|
|
43
|
-
} from './DeviceStateMapper';
|
|
44
|
-
import { projectFeatures } from './DeviceStateProjector';
|
|
45
|
-
import { DeviceStateStore, createPublicDeviceState } from './DeviceStateStore';
|
|
46
|
-
import { cloneDeviceState } from './cloneDeviceState';
|
|
47
|
-
import { deviceWalletSessionStore } from './DeviceWalletSessionStore';
|
|
48
32
|
import {
|
|
49
33
|
type DeviceFirmwareRange,
|
|
50
|
-
DeviceModelToTypes,
|
|
51
|
-
type DeviceStateEvent,
|
|
52
|
-
type DeviceStatePatch,
|
|
53
|
-
type DeviceStateUpdateSource,
|
|
54
|
-
DeviceTypeToModels,
|
|
55
34
|
type Device as DeviceTyped,
|
|
56
35
|
EOneKeyDeviceMode,
|
|
57
36
|
type Features,
|
|
58
|
-
type IDeviceModel,
|
|
59
|
-
type IDeviceType,
|
|
60
|
-
type IVersionRange,
|
|
61
|
-
type SupportFeatureType,
|
|
62
37
|
type UnavailableCapabilities,
|
|
63
38
|
} from '../types';
|
|
64
39
|
import { DEVICE, UI_REQUEST } from '../events';
|
|
@@ -66,32 +41,16 @@ import { DataManager } from '../data-manager';
|
|
|
66
41
|
import TransportManager from '../data-manager/TransportManager';
|
|
67
42
|
import { toHardened } from '../api/helpers/pathUtils';
|
|
68
43
|
import { existCapability } from '../utils/capabilitieUtils';
|
|
69
|
-
import {
|
|
70
|
-
PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST,
|
|
71
|
-
PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST,
|
|
72
|
-
PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
|
|
73
|
-
type ProtocolV2RuntimeMode,
|
|
74
|
-
getProtocolV2RuntimeMode,
|
|
75
|
-
requestProtocolV2DeviceInfo,
|
|
76
|
-
requestProtocolV2DeviceStatus,
|
|
77
|
-
} from '../protocols/protocol-v2/features';
|
|
78
|
-
import { buildProtocolV1FeaturesPayload } from '../deviceProfile';
|
|
79
44
|
|
|
80
45
|
import type { PROTO } from '../constants';
|
|
81
|
-
import type { DeviceStateReadOptions } from '../types/api/getDeviceState';
|
|
82
46
|
import type {
|
|
83
47
|
DeviceButtonRequestPayload,
|
|
84
48
|
DeviceFeaturesPayload,
|
|
85
49
|
PassphraseRequestPayload,
|
|
86
50
|
} from '../events';
|
|
87
51
|
import type { PassphrasePromptResponse } from './DeviceCommands';
|
|
88
|
-
import type { Deferred
|
|
89
|
-
import type {
|
|
90
|
-
OneKeyDeviceInfo as DeviceDescriptor,
|
|
91
|
-
DeviceStatus,
|
|
92
|
-
ProtocolV2DeviceInfo,
|
|
93
|
-
Success,
|
|
94
|
-
} from '@onekeyfe/hd-transport';
|
|
52
|
+
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
53
|
+
import type { OneKeyDeviceInfo as DeviceDescriptor } from '@onekeyfe/hd-transport';
|
|
95
54
|
import type DeviceConnector from './DeviceConnector';
|
|
96
55
|
|
|
97
56
|
export type InitOptions = {
|
|
@@ -99,10 +58,6 @@ export type InitOptions = {
|
|
|
99
58
|
deviceId?: string;
|
|
100
59
|
passphraseState?: string;
|
|
101
60
|
deriveCardano?: boolean;
|
|
102
|
-
connectProtocol?: HardwareConnectProtocol;
|
|
103
|
-
protocolV2DeviceInfoTimeoutMs?: number;
|
|
104
|
-
/** Refresh Protocol V2 runtime state before returning discovery results. */
|
|
105
|
-
refreshRuntimeState?: boolean;
|
|
106
61
|
};
|
|
107
62
|
|
|
108
63
|
export type RunOptions = {
|
|
@@ -119,11 +74,9 @@ const Log = getLogger(LoggerNames.Device);
|
|
|
119
74
|
|
|
120
75
|
export interface DeviceEvents {
|
|
121
76
|
[DEVICE.PIN]: [Device, PROTO.PinMatrixRequestType | undefined, (err: any, pin: string) => void];
|
|
122
|
-
[DEVICE.PASSPHRASE_ON_DEVICE]: [Device,
|
|
123
|
-
[DEVICE.ATTACH_PIN_ON_DEVICE]: [Device, PassphraseRequestPayload?];
|
|
77
|
+
[DEVICE.PASSPHRASE_ON_DEVICE]: [Device, ((response: any) => void)?];
|
|
124
78
|
[DEVICE.BUTTON]: [Device, DeviceButtonRequestPayload];
|
|
125
79
|
[DEVICE.FEATURES]: [Device, DeviceFeaturesPayload];
|
|
126
|
-
[DEVICE.STATE]: [Device, DeviceStateEvent];
|
|
127
80
|
[DEVICE.PASSPHRASE]: [
|
|
128
81
|
Device,
|
|
129
82
|
PassphraseRequestPayload,
|
|
@@ -147,6 +100,8 @@ export interface Device {
|
|
|
147
100
|
emit<K extends keyof DeviceEvents>(type: K, ...args: DeviceEvents[K]): boolean;
|
|
148
101
|
}
|
|
149
102
|
|
|
103
|
+
const deviceSessionCache: Record<string, string> = {};
|
|
104
|
+
|
|
150
105
|
/**
|
|
151
106
|
* Pre-populate the device session cache with a known session ID.
|
|
152
107
|
*
|
|
@@ -164,7 +119,8 @@ export function preloadSessionCache(
|
|
|
164
119
|
passphraseState: string,
|
|
165
120
|
sessionId: string
|
|
166
121
|
): void {
|
|
167
|
-
|
|
122
|
+
const key = `${deviceId}@${passphraseState}`;
|
|
123
|
+
deviceSessionCache[key] = sessionId;
|
|
168
124
|
}
|
|
169
125
|
|
|
170
126
|
export class Device extends EventEmitter {
|
|
@@ -210,51 +166,15 @@ export class Device extends EventEmitter {
|
|
|
210
166
|
*/
|
|
211
167
|
private deviceAcquired = false;
|
|
212
168
|
|
|
213
|
-
/**
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
private protocolV2StateNeedsReload = false;
|
|
218
|
-
|
|
219
|
-
get state() {
|
|
220
|
-
return this.stateStore.getState();
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
get features(): Features | undefined {
|
|
224
|
-
if (!this.state) return undefined;
|
|
225
|
-
const features = projectFeatures(this.state);
|
|
226
|
-
const sessionCacheDeviceKey =
|
|
227
|
-
this.state.identity.deviceId ||
|
|
228
|
-
(this.isProtocolV2()
|
|
229
|
-
? this.originalDescriptor.path || this.originalDescriptor.id
|
|
230
|
-
: undefined);
|
|
231
|
-
const sessionId =
|
|
232
|
-
sessionCacheDeviceKey && this.passphraseState
|
|
233
|
-
? deviceWalletSessionStore.get(sessionCacheDeviceKey, this.passphraseState)
|
|
234
|
-
: undefined;
|
|
235
|
-
return sessionId
|
|
236
|
-
? {
|
|
237
|
-
...features,
|
|
238
|
-
sessionId,
|
|
239
|
-
session_id: sessionId,
|
|
240
|
-
passphraseState: this.passphraseState,
|
|
241
|
-
}
|
|
242
|
-
: features;
|
|
243
|
-
}
|
|
169
|
+
/**
|
|
170
|
+
* 设备信息
|
|
171
|
+
*/
|
|
172
|
+
features: Features | undefined = undefined;
|
|
244
173
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const { passphraseState } = features;
|
|
250
|
-
const sessionId = features.sessionId ?? features.session_id;
|
|
251
|
-
const deviceKey = this.getSessionCacheDeviceKey(features.deviceId ?? undefined);
|
|
252
|
-
if (passphraseState && sessionId && deviceKey) {
|
|
253
|
-
this.passphraseState = passphraseState;
|
|
254
|
-
deviceWalletSessionStore.set(deviceKey, passphraseState, sessionId);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
174
|
+
/**
|
|
175
|
+
* 是否需要更新设备信息
|
|
176
|
+
*/
|
|
177
|
+
featuresNeedsReload = false;
|
|
258
178
|
|
|
259
179
|
runPromise?: Deferred<void> | null;
|
|
260
180
|
|
|
@@ -308,41 +228,32 @@ export class Device extends EventEmitter {
|
|
|
308
228
|
|
|
309
229
|
// simplified object to pass via postMessage
|
|
310
230
|
toMessageObject(): DeviceTyped | null {
|
|
311
|
-
if (this.isUnacquired()) return null;
|
|
231
|
+
if (this.isUnacquired() || !this.features) return null;
|
|
312
232
|
|
|
313
233
|
const env = DataManager.getSettings('env');
|
|
314
|
-
const deviceType = this.
|
|
234
|
+
const deviceType = getDeviceType(this.features);
|
|
315
235
|
|
|
316
|
-
const bleName = this.
|
|
317
|
-
const label = this.
|
|
318
|
-
const serialNo = this.getCurrentSerialNo();
|
|
319
|
-
const connectId = this.getConnectId();
|
|
320
|
-
const deviceId = this.getCurrentDeviceId() || null;
|
|
321
|
-
|
|
322
|
-
const { features } = this;
|
|
323
|
-
const state = this.state ? createPublicDeviceState(this.state) : undefined;
|
|
236
|
+
const bleName = getDeviceBleName(this.features);
|
|
237
|
+
const label = getDeviceLabel(this.features);
|
|
324
238
|
|
|
325
239
|
return {
|
|
326
|
-
/** Android uses
|
|
327
|
-
connectId: DataManager.isBleConnect(env) ? this.mainId || null :
|
|
328
|
-
/**
|
|
329
|
-
|
|
330
|
-
/** @deprecated Use serialNo instead. */
|
|
331
|
-
uuid: serialNo,
|
|
240
|
+
/** Android uses Mac address, iOS uses uuid, USB uses uuid */
|
|
241
|
+
connectId: DataManager.isBleConnect(env) ? this.mainId || null : getDeviceUUID(this.features),
|
|
242
|
+
/** Hardware ID, will not change at any time */
|
|
243
|
+
uuid: getDeviceUUID(this.features),
|
|
332
244
|
commType: this.originalDescriptor.commType,
|
|
333
245
|
sdkInstanceId: this.sdkInstanceId,
|
|
334
246
|
instanceId: this.instanceId,
|
|
335
247
|
createdAt: this.createdAt,
|
|
336
248
|
deviceType,
|
|
337
249
|
/** ID for current seeds, will clear after replace a new seed at device */
|
|
338
|
-
deviceId,
|
|
250
|
+
deviceId: this.features.device_id || null,
|
|
339
251
|
path: this.originalDescriptor?.path,
|
|
340
252
|
bleName,
|
|
341
253
|
name: bleName || label || `OneKey ${deviceType?.toUpperCase()}`,
|
|
342
254
|
label: label || 'OneKey',
|
|
343
255
|
mode: this.getMode(),
|
|
344
|
-
features,
|
|
345
|
-
state,
|
|
256
|
+
features: this.features,
|
|
346
257
|
firmwareVersion: this.getFirmwareVersion(),
|
|
347
258
|
bleFirmwareVersion: this.getBLEFirmwareVersion(),
|
|
348
259
|
unavailableCapabilities: this.unavailableCapabilities,
|
|
@@ -353,13 +264,13 @@ export class Device extends EventEmitter {
|
|
|
353
264
|
* Device connect
|
|
354
265
|
* @returns {Promise<boolean>}
|
|
355
266
|
*/
|
|
356
|
-
connect(
|
|
267
|
+
connect() {
|
|
357
268
|
const env = DataManager.getSettings('env');
|
|
358
269
|
// eslint-disable-next-line no-async-promise-executor
|
|
359
270
|
return new Promise<boolean>(async (resolve, reject) => {
|
|
360
271
|
if (DataManager.isBleConnect(env)) {
|
|
361
272
|
try {
|
|
362
|
-
await this.acquire(
|
|
273
|
+
await this.acquire();
|
|
363
274
|
resolve(true);
|
|
364
275
|
} catch (error) {
|
|
365
276
|
reject(error);
|
|
@@ -369,7 +280,7 @@ export class Device extends EventEmitter {
|
|
|
369
280
|
// 不存在 Session ID 或存在 Session ID 但设备在别处使用,都需要 acquire 获取最新 sessionID
|
|
370
281
|
if (!this.mainId || (!this.isUsedHere() && this.originalDescriptor)) {
|
|
371
282
|
try {
|
|
372
|
-
await this.acquire(
|
|
283
|
+
await this.acquire();
|
|
373
284
|
resolve(true);
|
|
374
285
|
} catch (error) {
|
|
375
286
|
reject(error);
|
|
@@ -384,60 +295,29 @@ export class Device extends EventEmitter {
|
|
|
384
295
|
});
|
|
385
296
|
}
|
|
386
297
|
|
|
387
|
-
async acquire(
|
|
388
|
-
connectProtocol?: HardwareConnectProtocol,
|
|
389
|
-
options?: { throwOnRunPromiseError?: boolean }
|
|
390
|
-
) {
|
|
298
|
+
async acquire() {
|
|
391
299
|
const env = DataManager.getSettings('env');
|
|
392
300
|
const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
|
|
393
|
-
const expectedProtocol = connectProtocol ?? this.originalDescriptor.protocolType;
|
|
394
301
|
try {
|
|
395
|
-
let acquireResult: unknown;
|
|
396
302
|
if (DataManager.isBleConnect(env)) {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
// otherwise block the new session. Device cannot distinguish recovery from a
|
|
400
|
-
// regular acquire, so BLE always clears it intentionally.
|
|
401
|
-
acquireResult = await this.deviceConnector?.acquire(
|
|
402
|
-
this.originalDescriptor.id,
|
|
403
|
-
undefined,
|
|
404
|
-
true,
|
|
405
|
-
expectedProtocol
|
|
406
|
-
);
|
|
407
|
-
this.mainId = (acquireResult as any)?.uuid ?? '';
|
|
303
|
+
const res = await this.deviceConnector?.acquire(this.originalDescriptor.id);
|
|
304
|
+
this.mainId = (res as unknown as any).uuid ?? '';
|
|
408
305
|
Log.debug('Expected uuid:', this.mainId);
|
|
409
306
|
} else {
|
|
410
|
-
|
|
307
|
+
this.mainId = await this.deviceConnector?.acquire(
|
|
411
308
|
this.originalDescriptor.path,
|
|
412
|
-
this.originalDescriptor.session
|
|
413
|
-
undefined,
|
|
414
|
-
expectedProtocol
|
|
309
|
+
this.originalDescriptor.session
|
|
415
310
|
);
|
|
416
|
-
this.mainId = acquireResult as string | undefined;
|
|
417
311
|
Log.debug('Expected session id:', this.mainId);
|
|
418
312
|
}
|
|
419
313
|
this.deviceAcquired = true;
|
|
420
314
|
this.updateDescriptor({ [mainIdKey]: this.mainId } as unknown as DeviceDescriptor);
|
|
421
|
-
|
|
422
|
-
// Propagate protocol version detected during acquire.
|
|
423
|
-
const detectedProtocol =
|
|
424
|
-
(acquireResult as { protocolType?: HardwareConnectProtocol } | undefined)?.protocolType ??
|
|
425
|
-
TransportManager.transport?.getProtocolType?.(
|
|
426
|
-
DataManager.isBleConnect(env) ? this.originalDescriptor.id : this.originalDescriptor.path
|
|
427
|
-
);
|
|
428
|
-
if (detectedProtocol) {
|
|
429
|
-
this.originalDescriptor.protocolType = detectedProtocol;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
315
|
if (this.commands) {
|
|
433
316
|
await this.commands.dispose(false);
|
|
434
317
|
}
|
|
435
318
|
|
|
436
319
|
this.commands = new DeviceCommands(this, this.mainId ?? '');
|
|
437
320
|
} catch (error) {
|
|
438
|
-
if (options?.throwOnRunPromiseError) {
|
|
439
|
-
throw error;
|
|
440
|
-
}
|
|
441
321
|
if (this.runPromise) {
|
|
442
322
|
this.runPromise.reject(error);
|
|
443
323
|
} else {
|
|
@@ -488,10 +368,12 @@ export class Device extends EventEmitter {
|
|
|
488
368
|
}
|
|
489
369
|
|
|
490
370
|
/**
|
|
491
|
-
* Pre-initialize: connect + Initialize ahead of the sign.
|
|
371
|
+
* Pre-initialize: connect + Initialize ahead of the sign. Only runs the
|
|
372
|
+
* fallback init when features are missing (gate on `!this.features`, not
|
|
373
|
+
* isUsedHere which is always false on BLE); otherwise just records the mark.
|
|
492
374
|
*/
|
|
493
375
|
async preInitialize(initOptions?: InitOptions) {
|
|
494
|
-
if (this.
|
|
376
|
+
if (!this.features) {
|
|
495
377
|
await this.acquire();
|
|
496
378
|
await this.initialize(initOptions);
|
|
497
379
|
}
|
|
@@ -537,174 +419,23 @@ export class Device extends EventEmitter {
|
|
|
537
419
|
return this.commands;
|
|
538
420
|
}
|
|
539
421
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
* descriptor.protocolType is established by active probing; V2 features are mapped
|
|
544
|
-
* from DeviceInfoGet. All protocol branches must use this method instead of reading
|
|
545
|
-
* originalDescriptor.protocolType directly or inferring a protocol from features.
|
|
546
|
-
*/
|
|
547
|
-
getProtocol(): 'V1' | 'V2' {
|
|
548
|
-
return this.originalDescriptor.protocolType === 'V2' ? 'V2' : 'V1';
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
isProtocolV2() {
|
|
552
|
-
return this.getProtocol() === 'V2';
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
getCurrentDeviceType() {
|
|
556
|
-
return getDeviceType(this.features);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
getCurrentDeviceId() {
|
|
560
|
-
return this.features?.deviceId || undefined;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
getCurrentSerialNo() {
|
|
564
|
-
return getDeviceSerialNo(this.features);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
getConnectId() {
|
|
568
|
-
const serialNo = this.getCurrentSerialNo();
|
|
569
|
-
if (serialNo) return serialNo;
|
|
570
|
-
|
|
571
|
-
// connectId is an internal routing key. Falling back to the transport descriptor
|
|
572
|
-
// does not change the business meaning of features.serialNo or deviceId.
|
|
573
|
-
return this.originalDescriptor.path || this.originalDescriptor.id || '';
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
getCurrentBleName() {
|
|
577
|
-
return getDeviceBleName(this.features);
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
getCurrentLabel() {
|
|
581
|
-
return getDeviceLabel(this.features);
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
getCurrentPassphraseProtection() {
|
|
585
|
-
return this.features?.passphraseProtection;
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
getCurrentFirmwareType() {
|
|
589
|
-
return getFirmwareType(this.features);
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
getCurrentFirmwareVersionString() {
|
|
593
|
-
return getDeviceFirmwareVersion(this.features)?.join('.');
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
getCurrentBLEFirmwareVersionString() {
|
|
597
|
-
if (!this.features) return undefined;
|
|
598
|
-
return getDeviceBLEFirmwareVersion(this.features).join('.');
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
getCurrentBootloaderVersionString() {
|
|
602
|
-
if (!this.features) return undefined;
|
|
603
|
-
return getDeviceBootloaderVersion(this.features).join('.');
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
getCurrentSafetyChecks() {
|
|
607
|
-
return this.features?.safetyChecks;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
getCurrentMethodVersionRange(
|
|
611
|
-
getVersionRange: (deviceModel: IDeviceType | IDeviceModel) => IVersionRange | undefined
|
|
612
|
-
) {
|
|
613
|
-
const deviceType = this.getCurrentDeviceType();
|
|
614
|
-
const versionRange = getVersionRange(deviceType);
|
|
615
|
-
if (versionRange) return versionRange;
|
|
616
|
-
|
|
617
|
-
// Most-specific model first; must match getMethodVersionRange in deviceInfoUtils,
|
|
618
|
-
// otherwise e.g. Classic1s resolves the looser model_mini range before model_classic1s.
|
|
619
|
-
const modelFallbacks: IDeviceModel[] = [
|
|
620
|
-
'model_classic1s',
|
|
621
|
-
'model_classic',
|
|
622
|
-
'model_mini',
|
|
623
|
-
'model_touch',
|
|
624
|
-
];
|
|
625
|
-
for (const model of modelFallbacks) {
|
|
626
|
-
if (DeviceTypeToModels[deviceType]?.includes(model)) {
|
|
627
|
-
const fallbackRange = getVersionRange(model);
|
|
628
|
-
if (fallbackRange) return fallbackRange;
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
return undefined;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
supportNewPassphrase(): SupportFeatureType {
|
|
635
|
-
const deviceType = this.getCurrentDeviceType();
|
|
636
|
-
if (
|
|
637
|
-
deviceType === EDeviceType.Touch ||
|
|
638
|
-
deviceType === EDeviceType.Pro ||
|
|
639
|
-
deviceType === EDeviceType.Pro2
|
|
640
|
-
) {
|
|
641
|
-
return { support: true };
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
const firmwareVersion = this.getCurrentFirmwareVersionString();
|
|
645
|
-
return {
|
|
646
|
-
support: Boolean(firmwareVersion && semver.gte(firmwareVersion, '2.4.0')),
|
|
647
|
-
require: '2.4.0',
|
|
648
|
-
};
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
supportInputPinOnSoftware(): SupportFeatureType {
|
|
652
|
-
if (this.features) return supportInputPinOnSoftware(this.features);
|
|
653
|
-
|
|
654
|
-
const deviceType = this.getCurrentDeviceType();
|
|
655
|
-
if (
|
|
656
|
-
deviceType === EDeviceType.Touch ||
|
|
657
|
-
deviceType === EDeviceType.Pro ||
|
|
658
|
-
deviceType === EDeviceType.Pro2
|
|
659
|
-
) {
|
|
660
|
-
return { support: false };
|
|
422
|
+
private generateStateKey(deviceId: string, passphraseState?: string) {
|
|
423
|
+
if (passphraseState) {
|
|
424
|
+
return `${deviceId}@${passphraseState}`;
|
|
661
425
|
}
|
|
662
|
-
|
|
663
|
-
const firmwareVersion = this.getCurrentFirmwareVersionString();
|
|
664
|
-
return {
|
|
665
|
-
support: Boolean(firmwareVersion && semver.gte(firmwareVersion, '2.3.0')),
|
|
666
|
-
require: '2.3.0',
|
|
667
|
-
};
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
supportModifyHomescreen(): SupportFeatureType {
|
|
671
|
-
// Pro2 has an independent 1.x version line and must not use the Touch/Pro 3.4.0
|
|
672
|
-
// threshold. ApplySettings includes homescreen from the first V2 firmware version.
|
|
673
|
-
if (this.isProtocolV2()) {
|
|
674
|
-
return { support: true };
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
if (this.features) return supportModifyHomescreen(this.features);
|
|
678
|
-
|
|
679
|
-
const deviceType = this.getCurrentDeviceType();
|
|
680
|
-
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
|
|
681
|
-
return { support: true };
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
const firmwareVersion = this.getCurrentFirmwareVersionString();
|
|
685
|
-
return {
|
|
686
|
-
support: Boolean(firmwareVersion && semver.gte(firmwareVersion, '3.4.0')),
|
|
687
|
-
};
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
private getSessionCacheDeviceKey(_deviceId?: string) {
|
|
691
|
-
const deviceId = _deviceId || this.getCurrentDeviceId();
|
|
692
|
-
if (deviceId) return deviceId;
|
|
693
|
-
if (this.isProtocolV2()) {
|
|
694
|
-
return this.originalDescriptor.path || this.originalDescriptor.id;
|
|
695
|
-
}
|
|
696
|
-
return undefined;
|
|
426
|
+
return deviceId;
|
|
697
427
|
}
|
|
698
428
|
|
|
699
429
|
getInternalState(_deviceId?: string) {
|
|
430
|
+
Log.debug('getInternalState session cache: ', deviceSessionCache);
|
|
700
431
|
Log.debug(
|
|
701
432
|
'getInternalState session param: ',
|
|
702
433
|
`device_id: ${_deviceId}`,
|
|
703
|
-
`features.
|
|
704
|
-
`
|
|
434
|
+
`features.device_id: ${this.features?.device_id}`,
|
|
435
|
+
`passphraseState: ${this.passphraseState}`
|
|
705
436
|
);
|
|
706
437
|
|
|
707
|
-
const deviceId = this.
|
|
438
|
+
const deviceId = _deviceId || this.features?.device_id;
|
|
708
439
|
if (!deviceId) return undefined;
|
|
709
440
|
// Security invariant: no passphraseState → no session lookup.
|
|
710
441
|
// A previous fallback that scanned `${deviceId}@*` keys could silently
|
|
@@ -714,14 +445,15 @@ export class Device extends EventEmitter {
|
|
|
714
445
|
// downstream call carries it and hits the primary lookup below.
|
|
715
446
|
if (!this.passphraseState) return undefined;
|
|
716
447
|
|
|
717
|
-
|
|
448
|
+
const usePassKey = this.generateStateKey(deviceId, this.passphraseState);
|
|
449
|
+
return deviceSessionCache[usePassKey];
|
|
718
450
|
}
|
|
719
451
|
|
|
720
452
|
// attach to pin to fix internal state
|
|
721
453
|
updateInternalState(
|
|
722
454
|
enablePassphrase: boolean,
|
|
723
455
|
passphraseState: string | undefined,
|
|
724
|
-
deviceId: string
|
|
456
|
+
deviceId: string,
|
|
725
457
|
sessionId: string | null = null,
|
|
726
458
|
featuresSessionId: string | null = null
|
|
727
459
|
) {
|
|
@@ -729,73 +461,67 @@ export class Device extends EventEmitter {
|
|
|
729
461
|
'updateInternalState session param: ',
|
|
730
462
|
`device_id: ${deviceId}`,
|
|
731
463
|
`enablePassphrase: ${enablePassphrase}`,
|
|
732
|
-
`
|
|
733
|
-
`
|
|
734
|
-
`
|
|
464
|
+
`passphraseState: ${passphraseState}`,
|
|
465
|
+
`sessionId: ${sessionId}`,
|
|
466
|
+
`featuresSessionId: ${featuresSessionId}`
|
|
735
467
|
);
|
|
736
468
|
|
|
737
|
-
const cacheDeviceKey = this.getSessionCacheDeviceKey(deviceId);
|
|
738
|
-
if (!cacheDeviceKey) return;
|
|
739
|
-
|
|
740
469
|
if (enablePassphrase) {
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
470
|
+
// update the sessionId
|
|
471
|
+
if (sessionId) {
|
|
472
|
+
deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = sessionId;
|
|
473
|
+
} else if (featuresSessionId) {
|
|
474
|
+
deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = featuresSessionId;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// delete the old sessionId
|
|
479
|
+
const oldKey = `${deviceId}`;
|
|
480
|
+
if (deviceSessionCache[oldKey]) {
|
|
481
|
+
delete deviceSessionCache[oldKey];
|
|
744
482
|
}
|
|
745
483
|
|
|
746
|
-
|
|
484
|
+
Log.debug('updateInternalState session cache: ', deviceSessionCache);
|
|
747
485
|
}
|
|
748
486
|
|
|
749
487
|
private setInternalState(state: string, initSession?: boolean) {
|
|
750
488
|
Log.debug(
|
|
751
489
|
'setInternalState session param: ',
|
|
752
|
-
`
|
|
490
|
+
`state: ${state}`,
|
|
753
491
|
`initSession: ${initSession}`,
|
|
754
|
-
`
|
|
755
|
-
`
|
|
492
|
+
`device_id: ${this.features?.device_id}`,
|
|
493
|
+
`passphraseState: ${this.passphraseState}`
|
|
756
494
|
);
|
|
757
495
|
|
|
496
|
+
if (!this.features) return;
|
|
758
497
|
if (!this.passphraseState && !initSession) return;
|
|
759
498
|
|
|
760
|
-
const deviceId = this.
|
|
499
|
+
const deviceId = this.features?.device_id;
|
|
761
500
|
if (!deviceId) return;
|
|
762
501
|
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
502
|
+
const key = this.generateStateKey(deviceId, this.passphraseState);
|
|
503
|
+
|
|
504
|
+
if (state) {
|
|
505
|
+
deviceSessionCache[key] = state;
|
|
767
506
|
}
|
|
507
|
+
Log.debug('setInternalState done session cache: ', deviceSessionCache);
|
|
768
508
|
}
|
|
769
509
|
|
|
770
510
|
clearInternalState(_deviceId?: string) {
|
|
771
511
|
Log.debug('clearInternalState param: ', _deviceId);
|
|
772
512
|
|
|
773
|
-
const deviceId = this.
|
|
513
|
+
const deviceId = _deviceId || this.features?.device_id;
|
|
774
514
|
if (!deviceId) return;
|
|
775
|
-
|
|
515
|
+
const key = `${deviceId}`;
|
|
516
|
+
delete deviceSessionCache[key];
|
|
776
517
|
|
|
777
518
|
if (this.passphraseState) {
|
|
778
|
-
|
|
519
|
+
const usePassKey = this.generateStateKey(deviceId, this.passphraseState);
|
|
520
|
+
delete deviceSessionCache[usePassKey];
|
|
779
521
|
}
|
|
780
522
|
}
|
|
781
523
|
|
|
782
524
|
async initialize(options?: InitOptions) {
|
|
783
|
-
// Protocol V2 does not support legacy Initialize; use its dedicated flow.
|
|
784
|
-
if (this.isProtocolV2()) {
|
|
785
|
-
this.passphraseState = options?.passphraseState;
|
|
786
|
-
if (this.state && !options?.initSession && !this.protocolV2StateNeedsReload) {
|
|
787
|
-
if (this.features?.bootloaderMode) {
|
|
788
|
-
return;
|
|
789
|
-
}
|
|
790
|
-
// Normal calls reuse the cache. Explicit getDeviceState refreshes, unlock flow,
|
|
791
|
-
// and device events update dynamic state without polling on every SDK call.
|
|
792
|
-
return;
|
|
793
|
-
}
|
|
794
|
-
await this._initializeProtocolV2(options);
|
|
795
|
-
this.protocolV2StateNeedsReload = false;
|
|
796
|
-
return;
|
|
797
|
-
}
|
|
798
|
-
|
|
799
525
|
// Log.debug('initialize param:', options);
|
|
800
526
|
|
|
801
527
|
this.passphraseState = options?.passphraseState;
|
|
@@ -839,284 +565,26 @@ export class Device extends EventEmitter {
|
|
|
839
565
|
}
|
|
840
566
|
}
|
|
841
567
|
|
|
842
|
-
/**
|
|
843
|
-
* Device initialization over Protocol V2.
|
|
844
|
-
*
|
|
845
|
-
* Protocol V2 bypasses legacy Initialize/GetFeatures and builds its canonical
|
|
846
|
-
* features state directly from DeviceInfoGet.
|
|
847
|
-
*/
|
|
848
|
-
private async _initializeProtocolV2(options?: InitOptions) {
|
|
849
|
-
Log.debug('Initialize device via Protocol V2 features adapter');
|
|
850
|
-
|
|
851
|
-
try {
|
|
852
|
-
// typedCall applies the request timeout. An outer Promise.race would leak its
|
|
853
|
-
// timer and leave the underlying call active after rejection.
|
|
854
|
-
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
855
|
-
commands: this.commands,
|
|
856
|
-
timeoutMs: options?.protocolV2DeviceInfoTimeoutMs,
|
|
857
|
-
});
|
|
858
|
-
// The default request excludes SE/hash data and therefore uses basic scope.
|
|
859
|
-
// Full version and verification data require getDeviceState({ scope: 'firmware' }).
|
|
860
|
-
const features = await this.probeProtocolV2RuntimeState(
|
|
861
|
-
deviceInfo,
|
|
862
|
-
options?.protocolV2DeviceInfoTimeoutMs
|
|
863
|
-
);
|
|
864
|
-
Log.debug('Protocol V2 features:', features);
|
|
865
|
-
} catch (error) {
|
|
866
|
-
Log.error('Protocol V2 initialization failed:', error);
|
|
867
|
-
throw error;
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
|
|
871
568
|
async getFeatures() {
|
|
872
|
-
if (this.isProtocolV2()) {
|
|
873
|
-
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
874
|
-
commands: this.commands,
|
|
875
|
-
});
|
|
876
|
-
return this.probeProtocolV2RuntimeState(deviceInfo);
|
|
877
|
-
}
|
|
878
|
-
|
|
879
569
|
const { message } = await this.commands.typedCall('GetFeatures', 'Features', {});
|
|
880
570
|
this._updateFeatures(message);
|
|
881
|
-
return this.features;
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
async getDeviceState(params: DeviceStateReadOptions = {}) {
|
|
885
|
-
const refresh = new Set(params.refreshSections ?? []);
|
|
886
|
-
const getProtocolV2DeviceInfoRequest = () => {
|
|
887
|
-
if (refresh.has('verification')) return PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST;
|
|
888
|
-
if (refresh.has('versions')) return PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST;
|
|
889
|
-
return PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST;
|
|
890
|
-
};
|
|
891
|
-
let initializedWithDeviceInfo = false;
|
|
892
|
-
let refreshedDeviceInfo: ProtocolV2DeviceInfo | undefined;
|
|
893
|
-
|
|
894
|
-
if (!this.state) {
|
|
895
|
-
if (this.isProtocolV2()) {
|
|
896
|
-
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
897
|
-
commands: this.commands,
|
|
898
|
-
request: getProtocolV2DeviceInfoRequest(),
|
|
899
|
-
});
|
|
900
|
-
await this.probeProtocolV2RuntimeState(deviceInfo);
|
|
901
|
-
refreshedDeviceInfo = deviceInfo;
|
|
902
|
-
initializedWithDeviceInfo = true;
|
|
903
|
-
} else {
|
|
904
|
-
await this.getFeatures();
|
|
905
|
-
}
|
|
906
|
-
} else if (!this.isProtocolV2() && refresh.size > 0) {
|
|
907
|
-
await this.getFeatures();
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
if (!this.isProtocolV2() && refresh.has('verification')) {
|
|
911
|
-
const { message } = await this.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
|
|
912
|
-
this.updateState(mapProtocolV1OnekeyFeaturesToState(message), 'device-info');
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
if (this.isProtocolV2()) {
|
|
916
|
-
const refreshDeviceInfo =
|
|
917
|
-
refresh.has('identity') || refresh.has('versions') || refresh.has('verification');
|
|
918
|
-
if (refreshDeviceInfo && !initializedWithDeviceInfo) {
|
|
919
|
-
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
920
|
-
commands: this.commands,
|
|
921
|
-
request: getProtocolV2DeviceInfoRequest(),
|
|
922
|
-
});
|
|
923
|
-
refreshedDeviceInfo = deviceInfo;
|
|
924
|
-
if (!refresh.has('status')) {
|
|
925
|
-
this.updateState(
|
|
926
|
-
mapProtocolV2DeviceInfoToState(deviceInfo, this.state?.status.mode),
|
|
927
|
-
'device-info'
|
|
928
|
-
);
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
if (refresh.has('status') && !initializedWithDeviceInfo) {
|
|
933
|
-
const deviceInfo =
|
|
934
|
-
refreshedDeviceInfo ??
|
|
935
|
-
(await requestProtocolV2DeviceInfo({
|
|
936
|
-
commands: this.commands,
|
|
937
|
-
request: getProtocolV2DeviceInfoRequest(),
|
|
938
|
-
}));
|
|
939
|
-
await this.probeProtocolV2RuntimeState(deviceInfo);
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
if (refresh.has('settings') && this.state?.status.mode === 'normal') {
|
|
943
|
-
const { message } = await this.commands.typedCall(
|
|
944
|
-
'DeviceSettingsGet',
|
|
945
|
-
'DeviceSettings',
|
|
946
|
-
{}
|
|
947
|
-
);
|
|
948
|
-
this.updateState(mapDeviceSettingsToState(message), 'apply-settings');
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
if (!this.state) {
|
|
953
|
-
throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
|
|
954
|
-
}
|
|
955
|
-
return params.includeRaw ? cloneDeviceState(this.state) : createPublicDeviceState(this.state);
|
|
956
571
|
}
|
|
957
572
|
|
|
958
|
-
_updateFeatures(
|
|
959
|
-
const previousCacheDeviceKey = this.getSessionCacheDeviceKey();
|
|
960
|
-
let feat =
|
|
961
|
-
'protocol' in protoFeatures
|
|
962
|
-
? protoFeatures
|
|
963
|
-
: buildProtocolV1FeaturesPayload(protoFeatures, this.features);
|
|
964
|
-
|
|
573
|
+
_updateFeatures(feat: Features, initSession?: boolean) {
|
|
965
574
|
// GetFeatures doesn't return 'session_id'
|
|
966
|
-
if (this.features
|
|
967
|
-
feat.
|
|
575
|
+
if (this.features && this.features.session_id && !feat.session_id) {
|
|
576
|
+
feat.session_id = this.features.session_id;
|
|
577
|
+
}
|
|
578
|
+
if (this.features && this.features.device_id && feat.session_id) {
|
|
579
|
+
this.setInternalState(feat.session_id, initSession);
|
|
968
580
|
}
|
|
969
581
|
feat.unlocked = feat.unlocked ?? true;
|
|
970
582
|
|
|
971
583
|
feat = fixFeaturesFirmwareVersion(feat);
|
|
972
584
|
|
|
973
|
-
this.
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
deviceWalletSessionStore.migrateDeviceKey(previousCacheDeviceKey, nextCacheDeviceKey);
|
|
977
|
-
}
|
|
978
|
-
if (feat.deviceId && feat.sessionId) {
|
|
979
|
-
this.setInternalState(feat.sessionId, initSession);
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
updateState(patch: DeviceStatePatch, source: DeviceStateUpdateSource) {
|
|
984
|
-
const result = this.stateStore.update(patch, source);
|
|
985
|
-
if (result.changedKeys.length === 0) return result.state;
|
|
986
|
-
|
|
987
|
-
const event: DeviceStateEvent = {
|
|
988
|
-
connectId: this.getConnectId() ?? null,
|
|
989
|
-
state: createPublicDeviceState(result.state),
|
|
990
|
-
revision: result.revision,
|
|
991
|
-
source,
|
|
992
|
-
changedKeys: result.changedKeys,
|
|
993
|
-
};
|
|
994
|
-
Log.debug('Device state patch committed', {
|
|
995
|
-
source,
|
|
996
|
-
keys: result.changedKeys,
|
|
997
|
-
});
|
|
998
|
-
this.emit(DEVICE.STATE, this, event);
|
|
999
|
-
if (result.state.protocol === 'V1') {
|
|
1000
|
-
this.emit(DEVICE.FEATURES, this, projectFeatures(result.state));
|
|
1001
|
-
}
|
|
1002
|
-
return result.state;
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
updateFeaturesPatch(patch: Partial<Features>, source: DeviceStateUpdateSource) {
|
|
1006
|
-
const currentFeatures = this.features;
|
|
1007
|
-
if (!currentFeatures) return undefined;
|
|
1008
|
-
|
|
1009
|
-
const features = mergeDeviceFeaturesPatch(currentFeatures, patch);
|
|
1010
|
-
if (features === currentFeatures) return currentFeatures;
|
|
1011
|
-
|
|
1012
|
-
const normalized = fixFeaturesFirmwareVersion(features);
|
|
1013
|
-
this.updateState(mapFeaturesToState(normalized), source);
|
|
1014
|
-
return this.features;
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
async probeProtocolV2RuntimeState(deviceInfo: ProtocolV2DeviceInfo, timeoutMs?: number) {
|
|
1018
|
-
let deviceStatus: DeviceStatus;
|
|
1019
|
-
try {
|
|
1020
|
-
deviceStatus = await requestProtocolV2DeviceStatus({
|
|
1021
|
-
commands: this.commands,
|
|
1022
|
-
timeoutMs,
|
|
1023
|
-
});
|
|
1024
|
-
} catch (error) {
|
|
1025
|
-
const runtimeMode = getProtocolV2RuntimeMode({
|
|
1026
|
-
deviceInfo,
|
|
1027
|
-
deviceStatusAvailable: false,
|
|
1028
|
-
});
|
|
1029
|
-
Log.debug('Protocol V2 DeviceStatusGet unavailable; use temporary loader fallback', {
|
|
1030
|
-
runtimeMode,
|
|
1031
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1032
|
-
});
|
|
1033
|
-
return this.updateProtocolV2Features(deviceInfo, null, runtimeMode);
|
|
1034
|
-
}
|
|
1035
|
-
return this.updateProtocolV2Features(deviceInfo, deviceStatus, 'normal');
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
updateProtocolV2Features(
|
|
1039
|
-
deviceInfo?: ProtocolV2DeviceInfo,
|
|
1040
|
-
deviceStatus?: DeviceStatus | null,
|
|
1041
|
-
runtimeMode?: ProtocolV2RuntimeMode
|
|
1042
|
-
) {
|
|
1043
|
-
const previousCacheDeviceKey = this.getSessionCacheDeviceKey();
|
|
1044
|
-
const resolvedMode =
|
|
1045
|
-
runtimeMode ??
|
|
1046
|
-
(deviceStatus
|
|
1047
|
-
? getProtocolV2RuntimeMode({ deviceInfo, deviceStatusAvailable: true })
|
|
1048
|
-
: this.state?.status.mode);
|
|
1049
|
-
if (deviceInfo) {
|
|
1050
|
-
this.updateState(mapProtocolV2DeviceInfoToState(deviceInfo, resolvedMode), 'device-info');
|
|
1051
|
-
}
|
|
1052
|
-
if (deviceStatus) {
|
|
1053
|
-
this.updateState(mapProtocolV2DeviceStatusToState(deviceStatus), 'device-status');
|
|
1054
|
-
}
|
|
1055
|
-
const nextCacheDeviceKey = this.getSessionCacheDeviceKey();
|
|
1056
|
-
if (previousCacheDeviceKey && nextCacheDeviceKey) {
|
|
1057
|
-
deviceWalletSessionStore.migrateDeviceKey(previousCacheDeviceKey, nextCacheDeviceKey);
|
|
1058
|
-
}
|
|
1059
|
-
return this.features as Features;
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
updateProtocolV2Status(status: DeviceStatus) {
|
|
1063
|
-
const previousDeviceInfo = this.state?.raw?.protocolV2DeviceInfo;
|
|
1064
|
-
const previousStatus = this.state?.raw?.protocolV2DeviceStatus;
|
|
1065
|
-
return this.updateProtocolV2Features(previousDeviceInfo, {
|
|
1066
|
-
...previousStatus,
|
|
1067
|
-
...status,
|
|
1068
|
-
});
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
markTransportDisconnected() {
|
|
1072
|
-
if (!this.isProtocolV2()) return;
|
|
1073
|
-
this.protocolV2StateNeedsReload = true;
|
|
1074
|
-
this.clearPreInitialized();
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
markProtocolV2Reboot(rebootType: DeviceRebootType) {
|
|
1078
|
-
if (!this.isProtocolV2()) return;
|
|
1079
|
-
|
|
1080
|
-
this.protocolV2StateNeedsReload = true;
|
|
1081
|
-
this.clearPreInitialized();
|
|
1082
|
-
let loaderMode: 'bootloader' | 'romloader' | undefined;
|
|
1083
|
-
if (rebootType === DeviceRebootType.Bootloader) {
|
|
1084
|
-
loaderMode = 'bootloader';
|
|
1085
|
-
} else if (rebootType === DeviceRebootType.Romloader) {
|
|
1086
|
-
loaderMode = 'romloader';
|
|
1087
|
-
}
|
|
1088
|
-
if (loaderMode) {
|
|
1089
|
-
this.updateState(
|
|
1090
|
-
{
|
|
1091
|
-
identity: { deviceId: null },
|
|
1092
|
-
status: {
|
|
1093
|
-
mode: loaderMode,
|
|
1094
|
-
initialized: null,
|
|
1095
|
-
unlocked: null,
|
|
1096
|
-
firmwarePresent: null,
|
|
1097
|
-
backupRequired: null,
|
|
1098
|
-
noBackup: null,
|
|
1099
|
-
unfinishedBackup: null,
|
|
1100
|
-
recoveryMode: null,
|
|
1101
|
-
passphraseProtection: null,
|
|
1102
|
-
pinProtection: null,
|
|
1103
|
-
attachToPinEnabled: null,
|
|
1104
|
-
unlockedAttachPin: null,
|
|
1105
|
-
},
|
|
1106
|
-
raw: { protocolV2DeviceStatus: null },
|
|
1107
|
-
},
|
|
1108
|
-
'transport-reconnect'
|
|
1109
|
-
);
|
|
1110
|
-
return;
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
this.updateState(
|
|
1114
|
-
{
|
|
1115
|
-
status: { mode: 'normal', unlocked: null },
|
|
1116
|
-
raw: { protocolV2DeviceStatus: null },
|
|
1117
|
-
},
|
|
1118
|
-
'transport-reconnect'
|
|
1119
|
-
);
|
|
585
|
+
this.features = feat;
|
|
586
|
+
this.featuresNeedsReload = false;
|
|
587
|
+
this.emit(DEVICE.FEATURES, this, feat);
|
|
1120
588
|
}
|
|
1121
589
|
|
|
1122
590
|
/**
|
|
@@ -1137,11 +605,7 @@ export class Device extends EventEmitter {
|
|
|
1137
605
|
}
|
|
1138
606
|
|
|
1139
607
|
if (forceUpdate) {
|
|
1140
|
-
|
|
1141
|
-
this.originalDescriptor = {
|
|
1142
|
-
...descriptor,
|
|
1143
|
-
protocolType: descriptor.protocolType ?? this.originalDescriptor.protocolType,
|
|
1144
|
-
};
|
|
608
|
+
this.originalDescriptor = descriptor;
|
|
1145
609
|
}
|
|
1146
610
|
}
|
|
1147
611
|
|
|
@@ -1162,37 +626,19 @@ export class Device extends EventEmitter {
|
|
|
1162
626
|
|
|
1163
627
|
options = parseRunOptions(options);
|
|
1164
628
|
|
|
1165
|
-
|
|
1166
|
-
this.runPromise
|
|
1167
|
-
this._runInner(fn, options, runPromise).catch(error => {
|
|
1168
|
-
if (this.runPromise === runPromise) {
|
|
1169
|
-
this.runPromise = null;
|
|
1170
|
-
}
|
|
1171
|
-
runPromise.reject(error);
|
|
1172
|
-
});
|
|
1173
|
-
return runPromise.promise;
|
|
629
|
+
this.runPromise = createDeferred(this._runInner.bind(this, fn, options));
|
|
630
|
+
return this.runPromise.promise;
|
|
1174
631
|
}
|
|
1175
632
|
|
|
1176
|
-
async _runInner<T>(
|
|
1177
|
-
fn: (() => Promise<T>) | undefined,
|
|
1178
|
-
options: RunOptions,
|
|
1179
|
-
runPromise: Deferred<void>
|
|
1180
|
-
) {
|
|
1181
|
-
const clearRunPromise = () => {
|
|
1182
|
-
if (this.runPromise === runPromise) {
|
|
1183
|
-
this.runPromise = null;
|
|
1184
|
-
}
|
|
1185
|
-
};
|
|
1186
|
-
|
|
633
|
+
async _runInner<T>(fn: (() => Promise<T>) | undefined, options: RunOptions) {
|
|
1187
634
|
if (!this.isUsedHere() || this.commands.disposed) {
|
|
1188
635
|
const env = DataManager.getSettings('env');
|
|
1189
636
|
if (env !== 'react-native') {
|
|
1190
637
|
try {
|
|
1191
|
-
await this.acquire(
|
|
638
|
+
await this.acquire();
|
|
1192
639
|
} catch (error) {
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
return;
|
|
640
|
+
this.runPromise = null;
|
|
641
|
+
return Promise.reject(error);
|
|
1196
642
|
}
|
|
1197
643
|
|
|
1198
644
|
try {
|
|
@@ -1202,19 +648,16 @@ export class Device extends EventEmitter {
|
|
|
1202
648
|
}
|
|
1203
649
|
}
|
|
1204
650
|
} catch (error) {
|
|
1205
|
-
|
|
1206
|
-
clearRunPromise();
|
|
651
|
+
this.runPromise = null;
|
|
1207
652
|
if (error instanceof HardwareError) {
|
|
1208
|
-
|
|
1209
|
-
return;
|
|
653
|
+
return Promise.reject(error);
|
|
1210
654
|
}
|
|
1211
|
-
|
|
655
|
+
return Promise.reject(
|
|
1212
656
|
ERRORS.TypedError(
|
|
1213
657
|
HardwareErrorCode.DeviceInitializeFailed,
|
|
1214
658
|
`Initialize failed: ${error.message as string}, code: ${error.code as string}`
|
|
1215
659
|
)
|
|
1216
660
|
);
|
|
1217
|
-
return;
|
|
1218
661
|
}
|
|
1219
662
|
} else if (env === 'react-native') {
|
|
1220
663
|
// TODO: implement react-native acquire
|
|
@@ -1233,7 +676,9 @@ export class Device extends EventEmitter {
|
|
|
1233
676
|
try {
|
|
1234
677
|
await fn();
|
|
1235
678
|
} catch (e) {
|
|
1236
|
-
runPromise
|
|
679
|
+
if (this.runPromise) {
|
|
680
|
+
this.runPromise.reject(e);
|
|
681
|
+
}
|
|
1237
682
|
|
|
1238
683
|
if (
|
|
1239
684
|
e instanceof HardwareError &&
|
|
@@ -1246,7 +691,7 @@ export class Device extends EventEmitter {
|
|
|
1246
691
|
Log.debug(`error code ${e.errorCode} release device, mainId: ${this.mainId}`);
|
|
1247
692
|
}
|
|
1248
693
|
|
|
1249
|
-
|
|
694
|
+
this.runPromise = null;
|
|
1250
695
|
return;
|
|
1251
696
|
}
|
|
1252
697
|
}
|
|
@@ -1260,8 +705,11 @@ export class Device extends EventEmitter {
|
|
|
1260
705
|
Log.debug('release device, mainId: ', this.mainId);
|
|
1261
706
|
}
|
|
1262
707
|
|
|
1263
|
-
runPromise
|
|
1264
|
-
|
|
708
|
+
if (this.runPromise) {
|
|
709
|
+
this.runPromise.resolve();
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
this.runPromise = null;
|
|
1265
713
|
}
|
|
1266
714
|
|
|
1267
715
|
async interruptionFromOutside() {
|
|
@@ -1300,23 +748,22 @@ export class Device extends EventEmitter {
|
|
|
1300
748
|
}
|
|
1301
749
|
|
|
1302
750
|
getMode() {
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
return EOneKeyDeviceMode.bootloader;
|
|
1307
|
-
case 'notInitialized':
|
|
1308
|
-
return EOneKeyDeviceMode.notInitialized;
|
|
1309
|
-
case 'backupMode':
|
|
1310
|
-
return EOneKeyDeviceMode.backupMode;
|
|
1311
|
-
case 'normal':
|
|
1312
|
-
return EOneKeyDeviceMode.normal;
|
|
1313
|
-
default:
|
|
1314
|
-
break;
|
|
751
|
+
if (this.features?.bootloader_mode) {
|
|
752
|
+
// bootloader mode
|
|
753
|
+
return EOneKeyDeviceMode.bootloader;
|
|
1315
754
|
}
|
|
1316
755
|
|
|
1317
|
-
if (this.features?.
|
|
1318
|
-
|
|
1319
|
-
|
|
756
|
+
if (!this.features?.initialized) {
|
|
757
|
+
// not initialized
|
|
758
|
+
return EOneKeyDeviceMode.notInitialized;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
if (this.features?.no_backup) {
|
|
762
|
+
// backup mode
|
|
763
|
+
return EOneKeyDeviceMode.backupMode;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// normal mode
|
|
1320
767
|
return EOneKeyDeviceMode.normal;
|
|
1321
768
|
}
|
|
1322
769
|
|
|
@@ -1355,7 +802,7 @@ export class Device extends EventEmitter {
|
|
|
1355
802
|
}
|
|
1356
803
|
|
|
1357
804
|
isBootloader() {
|
|
1358
|
-
return this.features && !!this.features.
|
|
805
|
+
return this.features && !!this.features.bootloader_mode;
|
|
1359
806
|
}
|
|
1360
807
|
|
|
1361
808
|
isInitialized() {
|
|
@@ -1363,7 +810,7 @@ export class Device extends EventEmitter {
|
|
|
1363
810
|
}
|
|
1364
811
|
|
|
1365
812
|
isSeedless() {
|
|
1366
|
-
return this.features && !!this.features.
|
|
813
|
+
return this.features && !!this.features.no_backup;
|
|
1367
814
|
}
|
|
1368
815
|
|
|
1369
816
|
isUnacquired(): boolean {
|
|
@@ -1372,9 +819,9 @@ export class Device extends EventEmitter {
|
|
|
1372
819
|
|
|
1373
820
|
hasUnexpectedMode(allow: string[], require: string[]) {
|
|
1374
821
|
// both allow and require cases might generate single unexpected mode
|
|
1375
|
-
if (
|
|
822
|
+
if (this.features) {
|
|
1376
823
|
// allow cases
|
|
1377
|
-
if (this.isBootloader() && !
|
|
824
|
+
if (this.isBootloader() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
|
|
1378
825
|
return UI_REQUEST.BOOTLOADER;
|
|
1379
826
|
}
|
|
1380
827
|
if (!this.isInitialized() && !allow.includes(UI_REQUEST.NOT_INITIALIZE)) {
|
|
@@ -1393,30 +840,27 @@ export class Device extends EventEmitter {
|
|
|
1393
840
|
}
|
|
1394
841
|
|
|
1395
842
|
hasUsePassphrase() {
|
|
1396
|
-
const deviceType = this.getCurrentDeviceType();
|
|
1397
843
|
const isModeT =
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
const passphraseProtection = this.getCurrentPassphraseProtection();
|
|
1404
|
-
|
|
1405
|
-
return Boolean(passphraseProtection === true || preCheckTouch);
|
|
844
|
+
getDeviceType(this.features) === EDeviceType.Touch ||
|
|
845
|
+
getDeviceType(this.features) === EDeviceType.Pro;
|
|
846
|
+
const preCheckTouch = isModeT && this.features?.unlocked === false;
|
|
847
|
+
|
|
848
|
+
return this.features && (!!this.features.passphrase_protection || preCheckTouch);
|
|
1406
849
|
}
|
|
1407
850
|
|
|
1408
851
|
checkDeviceId(deviceId: string) {
|
|
1409
|
-
|
|
852
|
+
if (this.features) {
|
|
853
|
+
return this.features.device_id === deviceId;
|
|
854
|
+
}
|
|
855
|
+
return false;
|
|
1410
856
|
}
|
|
1411
857
|
|
|
1412
|
-
async lockDevice()
|
|
858
|
+
async lockDevice() {
|
|
1413
859
|
const res = await this.commands.typedCall('LockDevice', 'Success', {});
|
|
1414
|
-
this.updateState({ status: { unlocked: false } }, 'lock');
|
|
1415
860
|
return res.message;
|
|
1416
861
|
}
|
|
1417
862
|
|
|
1418
863
|
supportUnlockVersionRange(): DeviceFirmwareRange {
|
|
1419
|
-
// This range applies to Protocol V1 Pro devices; Pro2 has a dedicated unlock flow.
|
|
1420
864
|
return {
|
|
1421
865
|
pro: {
|
|
1422
866
|
min: '4.15.0',
|
|
@@ -1425,28 +869,9 @@ export class Device extends EventEmitter {
|
|
|
1425
869
|
}
|
|
1426
870
|
|
|
1427
871
|
async unlockDevice() {
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
timeoutMs: 120_000,
|
|
1432
|
-
});
|
|
1433
|
-
} catch (error) {
|
|
1434
|
-
const errorText =
|
|
1435
|
-
error instanceof Error
|
|
1436
|
-
? `${error.name} ${error.message}`
|
|
1437
|
-
: String((error as { message?: unknown } | null)?.message ?? error ?? '');
|
|
1438
|
-
if (errorText.includes('Failure_UnexpectedMessage')) {
|
|
1439
|
-
throw createDeviceNotSupportMethodError('deviceUnlock', this.getCurrentFirmwareType());
|
|
1440
|
-
}
|
|
1441
|
-
throw error;
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
|
-
const status = await requestProtocolV2DeviceStatus({ commands: this.commands });
|
|
1445
|
-
return this.updateProtocolV2Status(status);
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
const firmwareVersion = this.getCurrentFirmwareVersionString() ?? '0.0.0';
|
|
1449
|
-
const versionRange = this.getCurrentMethodVersionRange(
|
|
872
|
+
const firmwareVersion = getDeviceFirmwareVersion(this.features)?.join('.');
|
|
873
|
+
const versionRange = getMethodVersionRange(
|
|
874
|
+
this.features,
|
|
1450
875
|
type => this.supportUnlockVersionRange()[type]
|
|
1451
876
|
);
|
|
1452
877
|
|
|
@@ -1454,35 +879,25 @@ export class Device extends EventEmitter {
|
|
|
1454
879
|
this.features,
|
|
1455
880
|
Enum_Capability.Capability_AttachToPin
|
|
1456
881
|
);
|
|
882
|
+
|
|
1457
883
|
const supportUnlock =
|
|
1458
|
-
supportAttachPinCapability ||
|
|
1459
|
-
(versionRange &&
|
|
1460
|
-
semver.valid(firmwareVersion) &&
|
|
1461
|
-
semver.gte(firmwareVersion, versionRange.min));
|
|
884
|
+
supportAttachPinCapability || (versionRange && semver.gte(firmwareVersion, versionRange.min));
|
|
1462
885
|
|
|
1463
886
|
if (supportUnlock) {
|
|
1464
887
|
const res = await this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
|
|
1465
888
|
if (this.features) {
|
|
1466
|
-
this.
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
res.message.unlocked_attach_pin == null ? null : res.message.unlocked_attach_pin,
|
|
1472
|
-
passphraseProtection:
|
|
1473
|
-
res.message.passphrase_protection == null
|
|
1474
|
-
? null
|
|
1475
|
-
: res.message.passphrase_protection,
|
|
1476
|
-
},
|
|
1477
|
-
},
|
|
1478
|
-
'unlock'
|
|
1479
|
-
);
|
|
889
|
+
this.features.unlocked = res.message.unlocked == null ? null : res.message.unlocked;
|
|
890
|
+
this.features.unlocked_attach_pin =
|
|
891
|
+
res.message.unlocked_attach_pin == null ? undefined : res.message.unlocked_attach_pin;
|
|
892
|
+
this.features.passphrase_protection =
|
|
893
|
+
res.message.passphrase_protection == null ? null : res.message.passphrase_protection;
|
|
1480
894
|
|
|
1481
895
|
return Promise.resolve(this.features);
|
|
1482
896
|
}
|
|
1483
897
|
|
|
1484
|
-
const
|
|
1485
|
-
|
|
898
|
+
const featuresRes = await this.commands.typedCall('GetFeatures', 'Features');
|
|
899
|
+
this._updateFeatures(featuresRes.message);
|
|
900
|
+
return Promise.resolve(featuresRes.message);
|
|
1486
901
|
}
|
|
1487
902
|
|
|
1488
903
|
const { type } = await this.commands.typedCall('GetAddress', 'Address', {
|
|
@@ -1496,8 +911,9 @@ export class Device extends EventEmitter {
|
|
|
1496
911
|
if (type === 'CallMethodError') {
|
|
1497
912
|
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'unlock device error');
|
|
1498
913
|
}
|
|
1499
|
-
const
|
|
1500
|
-
|
|
914
|
+
const res = await this.commands.typedCall('GetFeatures', 'Features');
|
|
915
|
+
this._updateFeatures(res.message);
|
|
916
|
+
return Promise.resolve(res.message);
|
|
1501
917
|
}
|
|
1502
918
|
|
|
1503
919
|
async checkPassphraseStateSafety(
|
|
@@ -1505,41 +921,30 @@ export class Device extends EventEmitter {
|
|
|
1505
921
|
useEmptyPassphrase?: boolean,
|
|
1506
922
|
skipPassphraseCheck?: boolean
|
|
1507
923
|
) {
|
|
1508
|
-
if (this.
|
|
924
|
+
if (!this.features) return false;
|
|
1509
925
|
|
|
1510
|
-
const expectedPassphraseState = useEmptyPassphrase ? undefined : passphraseState;
|
|
1511
926
|
const { passphraseState: newPassphraseState, unlockedAttachPin } =
|
|
1512
927
|
await getPassphraseStateWithRefreshDeviceInfo(this, {
|
|
1513
|
-
expectPassphraseState:
|
|
928
|
+
expectPassphraseState: passphraseState,
|
|
1514
929
|
onlyMainPin: useEmptyPassphrase,
|
|
1515
930
|
});
|
|
1516
931
|
|
|
932
|
+
if (skipPassphraseCheck) {
|
|
933
|
+
return true;
|
|
934
|
+
}
|
|
935
|
+
|
|
1517
936
|
// Main wallet and unlock Attach Pin, throw safe error
|
|
1518
937
|
const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
|
|
1519
938
|
const useErrorAttachPin =
|
|
1520
|
-
unlockedAttachPin &&
|
|
1521
|
-
expectedPassphraseState &&
|
|
1522
|
-
expectedPassphraseState !== newPassphraseState;
|
|
1523
|
-
const passphraseStateMismatch =
|
|
1524
|
-
!!expectedPassphraseState && expectedPassphraseState !== newPassphraseState;
|
|
939
|
+
unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
|
|
1525
940
|
|
|
1526
941
|
Log.debug('Check passphrase state safety: ', {
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
passphraseStateMatches:
|
|
1530
|
-
Boolean(expectedPassphraseState) && expectedPassphraseState === newPassphraseState,
|
|
942
|
+
passphraseState,
|
|
943
|
+
newPassphraseState,
|
|
1531
944
|
unlockedAttachPin,
|
|
1532
945
|
useEmptyPassphrase,
|
|
1533
946
|
});
|
|
1534
947
|
|
|
1535
|
-
if (skipPassphraseCheck) {
|
|
1536
|
-
if (passphraseStateMismatch) {
|
|
1537
|
-
this.clearInternalState();
|
|
1538
|
-
return false;
|
|
1539
|
-
}
|
|
1540
|
-
return true;
|
|
1541
|
-
}
|
|
1542
|
-
|
|
1543
948
|
if (mainWalletUseAttachPin || useErrorAttachPin) {
|
|
1544
949
|
try {
|
|
1545
950
|
await this.lockDevice();
|
|
@@ -1551,7 +956,7 @@ export class Device extends EventEmitter {
|
|
|
1551
956
|
}
|
|
1552
957
|
|
|
1553
958
|
// When exists passphraseState, check passphraseState
|
|
1554
|
-
if (
|
|
959
|
+
if (passphraseState && passphraseState !== newPassphraseState) {
|
|
1555
960
|
this.clearInternalState();
|
|
1556
961
|
return false;
|
|
1557
962
|
}
|