@onekeyfe/hd-core 1.1.27-patch.1 → 1.2.0-alpha.0
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__/evmLedgerLegacySafety.test.ts +15 -4
- package/__tests__/evmSignTransaction.test.ts +1 -1
- package/__tests__/evmSignTypedData.test.ts +1 -1
- package/__tests__/logBlockEvent.test.ts +37 -0
- package/__tests__/protocol-v2.test.ts +3025 -0
- package/dist/api/BaseMethod.d.ts +1 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/DirList.d.ts +10 -0
- package/dist/api/DirList.d.ts.map +1 -0
- package/dist/api/DirMake.d.ts +9 -0
- package/dist/api/DirMake.d.ts.map +1 -0
- package/dist/api/DirRemove.d.ts +9 -0
- package/dist/api/DirRemove.d.ts.map +1 -0
- package/dist/api/FileDelete.d.ts +9 -0
- package/dist/api/FileDelete.d.ts.map +1 -0
- package/dist/api/FileRead.d.ts +19 -0
- package/dist/api/FileRead.d.ts.map +1 -0
- package/dist/api/FileWrite.d.ts +24 -0
- package/dist/api/FileWrite.d.ts.map +1 -0
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +1 -0
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +35 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -0
- package/dist/api/GetDeviceInfo.d.ts +9 -0
- package/dist/api/GetDeviceInfo.d.ts.map +1 -0
- package/dist/api/GetFeatures.d.ts.map +1 -1
- package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts +6 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/PathInfo.d.ts +10 -0
- package/dist/api/PathInfo.d.ts.map +1 -0
- package/dist/api/PromptWebDeviceAccess.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts +2 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumGetAddress.d.ts +2 -6
- package/dist/api/alephium/AlephiumGetAddress.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignMessage.d.ts +2 -5
- package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignTransaction.d.ts +5 -8
- package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
- package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetAddress.d.ts +2 -9
- package/dist/api/benfen/BenfenGetAddress.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetPublicKey.d.ts +2 -9
- package/dist/api/benfen/BenfenGetPublicKey.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignMessage.d.ts +2 -8
- package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignTransaction.d.ts +2 -8
- package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCGetAddress.d.ts +1 -11
- package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
- package/dist/api/btc/BTCGetPublicKey.d.ts +1 -11
- package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
- package/dist/api/btc/BTCSignMessage.d.ts +1 -15
- 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 +1 -11
- package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCVerifyMessage.d.ts +1 -11
- package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
- package/dist/api/btc/helpers/versionLimit.d.ts +2 -11
- 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/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/DeviceSupportFeatures.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/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 +2 -8
- 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/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/batchGetPublickeys.d.ts +3 -0
- package/dist/api/helpers/batchGetPublickeys.d.ts.map +1 -1
- package/dist/api/helpers/filesystemValidation.d.ts +7 -0
- package/dist/api/helpers/filesystemValidation.d.ts.map +1 -0
- package/dist/api/index.d.ts +32 -0
- 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 +4 -0
- package/dist/api/lightning/LnurlAuth.d.ts.map +1 -1
- package/dist/api/neo/NeoGetAddress.d.ts +2 -8
- package/dist/api/neo/NeoGetAddress.d.ts.map +1 -1
- package/dist/api/neo/NeoSignTransaction.d.ts +2 -8
- package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
- package/dist/api/nervos/NervosGetAddress.d.ts +2 -9
- package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -1
- package/dist/api/nervos/NervosSignTransaction.d.ts +9 -12
- package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
- package/dist/api/nexa/NexaGetAddress.d.ts +2 -8
- package/dist/api/nexa/NexaGetAddress.d.ts.map +1 -1
- package/dist/api/nexa/NexaSignTransaction.d.ts +2 -9
- package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotGetAddress.d.ts +3 -0
- package/dist/api/polkadot/PolkadotGetAddress.d.ts.map +1 -1
- package/dist/api/polkadot/networks.d.ts +3 -0
- package/dist/api/polkadot/networks.d.ts.map +1 -1
- package/dist/api/protocol-v2/DevReboot.d.ts +7 -0
- package/dist/api/protocol-v2/DevReboot.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts +29 -0
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceReboot.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -0
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +7 -0
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +1 -0
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +6 -0
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +13 -0
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +6 -0
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts +6 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
- package/dist/api/protocol-v2/GetProtoVersion.d.ts +6 -0
- package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +1 -0
- package/dist/api/protocol-v2/Ping.d.ts +8 -0
- package/dist/api/protocol-v2/Ping.d.ts.map +1 -0
- package/dist/api/protocol-v2/helpers.d.ts +34 -0
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
- package/dist/api/scdo/ScdoGetAddress.d.ts +2 -6
- package/dist/api/scdo/ScdoGetAddress.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignMessage.d.ts +2 -5
- package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignTransaction.d.ts +2 -5
- 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 +3 -0
- package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +3 -0
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +6 -0
- package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
- package/dist/api/stellar/StellarGetAddress.d.ts +2 -1
- package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +3 -2
- package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
- package/dist/api/sui/SuiGetAddress.d.ts +3 -0
- package/dist/api/sui/SuiGetAddress.d.ts.map +1 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts +3 -0
- package/dist/api/sui/SuiGetPublicKey.d.ts.map +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts +3 -0
- package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +5 -2
- package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
- package/dist/api/ton/TonGetAddress.d.ts +3 -0
- package/dist/api/ton/TonGetAddress.d.ts.map +1 -1
- package/dist/api/ton/TonSignData.d.ts +5 -0
- package/dist/api/ton/TonSignData.d.ts.map +1 -1
- package/dist/api/ton/TonSignMessage.d.ts +3 -0
- package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
- package/dist/api/ton/TonSignProof.d.ts +3 -0
- package/dist/api/ton/TonSignProof.d.ts.map +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +4 -0
- package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
- package/dist/api/tron/TronSignTransaction.d.ts +4 -0
- package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +7 -4
- 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 +5 -4
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +36 -10
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +9 -9
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +2 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceProfile.d.ts +22 -0
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -0
- package/dist/deviceProfile/index.d.ts +3 -0
- package/dist/deviceProfile/index.d.ts.map +1 -0
- package/dist/deviceProfile/legacyFeaturesView.d.ts +5 -0
- package/dist/deviceProfile/legacyFeaturesView.d.ts.map +1 -0
- package/dist/events/logBlockEvent.d.ts +1 -0
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +8 -0
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +720 -382
- package/dist/index.js +17634 -1201
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +93 -0
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/firmware.d.ts +13 -0
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/index.d.ts +4 -0
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
- package/dist/types/api/export.d.ts +1 -1
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +27 -0
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/getDeviceInfo.d.ts +85 -0
- package/dist/types/api/getDeviceInfo.d.ts.map +1 -0
- package/dist/types/api/getPassphraseState.d.ts +10 -1
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +37 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +103 -0
- package/dist/types/api/protocolV2.d.ts.map +1 -0
- 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 +10 -3
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +2 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +1 -1
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +6 -8
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts +1 -0
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- 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/package.json +4 -4
- package/src/api/BaseMethod.ts +26 -22
- package/src/api/DirList.ts +31 -0
- package/src/api/DirMake.ts +23 -0
- package/src/api/DirRemove.ts +23 -0
- package/src/api/FileDelete.ts +23 -0
- package/src/api/FileRead.ts +167 -0
- package/src/api/FileWrite.ts +216 -0
- package/src/api/FirmwareUpdate.ts +13 -5
- package/src/api/FirmwareUpdateV2.ts +21 -25
- package/src/api/FirmwareUpdateV3.ts +17 -4
- package/src/api/FirmwareUpdateV4.ts +827 -0
- package/src/api/GetDeviceInfo.ts +152 -0
- package/src/api/GetFeatures.ts +5 -2
- package/src/api/GetOnekeyFeatures.ts +95 -3
- package/src/api/GetPassphraseState.ts +16 -10
- package/src/api/PathInfo.ts +39 -0
- package/src/api/PromptWebDeviceAccess.ts +11 -1
- package/src/api/SearchDevices.ts +7 -2
- package/src/api/alephium/AlephiumGetAddress.ts +6 -2
- package/src/api/alephium/AlephiumSignMessage.ts +6 -1
- package/src/api/alephium/AlephiumSignTransaction.ts +15 -4
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +21 -13
- package/src/api/aptos/AptosGetAddress.ts +2 -3
- package/src/api/benfen/BenfenGetAddress.ts +11 -7
- package/src/api/benfen/BenfenGetPublicKey.ts +6 -2
- package/src/api/benfen/BenfenSignMessage.ts +6 -1
- package/src/api/benfen/BenfenSignTransaction.ts +6 -1
- package/src/api/btc/BTCGetPublicKey.ts +3 -2
- package/src/api/btc/BTCSignPsbt.ts +1 -2
- package/src/api/btc/helpers/versionLimit.ts +7 -1
- package/src/api/cardano/CardanoSignTransaction.ts +2 -4
- package/src/api/conflux/ConfluxSignTransaction.ts +5 -2
- package/src/api/device/DeviceFullyUploadResource.ts +3 -3
- package/src/api/device/DeviceLock.ts +1 -3
- package/src/api/device/DeviceRebootToBoardloader.ts +10 -1
- package/src/api/device/DeviceRebootToBootloader.ts +10 -1
- package/src/api/device/DeviceSupportFeatures.ts +2 -13
- package/src/api/device/DeviceUpdateBootloader.ts +4 -4
- package/src/api/device/DeviceUploadResource.ts +4 -5
- package/src/api/device/DeviceVerify.ts +1 -2
- package/src/api/dynex/DnxGetAddress.ts +6 -0
- package/src/api/dynex/DnxSignTransaction.ts +6 -0
- package/src/api/evm/EVMGetAddress.ts +1 -1
- package/src/api/evm/EVMGetPublicKey.ts +3 -4
- package/src/api/evm/EVMSignMessage.ts +1 -1
- package/src/api/evm/EVMSignMessageEIP712.ts +14 -1
- package/src/api/evm/EVMSignTransaction.ts +1 -1
- package/src/api/evm/EVMSignTypedData.ts +32 -18
- package/src/api/evm/EVMVerifyMessage.ts +1 -1
- package/src/api/evm/latest/signTypedHash.ts +2 -4
- package/src/api/evm/legacyV1/getAddress.ts +5 -3
- package/src/api/evm/legacyV1/getPublicKey.ts +5 -3
- package/src/api/evm/legacyV1/signMessage.ts +5 -3
- package/src/api/evm/legacyV1/signTypedData.ts +9 -8
- package/src/api/evm/legacyV1/signTypedHash.ts +7 -7
- package/src/api/evm/legacyV1/verifyMessage.ts +5 -3
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +8 -8
- package/src/api/firmware/uploadFirmware.ts +3 -10
- package/src/api/helpers/batchGetPublickeys.ts +51 -6
- package/src/api/helpers/filesystemValidation.ts +51 -0
- package/src/api/index.ts +34 -0
- package/src/api/kaspa/KaspaSignTransaction.ts +4 -5
- package/src/api/lightning/LnurlAuth.ts +4 -0
- package/src/api/neo/NeoGetAddress.ts +6 -1
- package/src/api/neo/NeoSignTransaction.ts +6 -1
- package/src/api/nervos/NervosGetAddress.ts +6 -2
- package/src/api/nervos/NervosSignTransaction.ts +14 -4
- package/src/api/nexa/NexaGetAddress.ts +6 -2
- package/src/api/nexa/NexaSignTransaction.ts +11 -12
- package/src/api/polkadot/networks.ts +9 -0
- package/src/api/protocol-v2/DevReboot.ts +24 -0
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +63 -0
- package/src/api/protocol-v2/DeviceGetDeviceInfo.ts +118 -0
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +20 -0
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +16 -0
- package/src/api/protocol-v2/DeviceReboot.ts +24 -0
- package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +29 -0
- package/src/api/protocol-v2/FactoryGetDeviceInfo.ts +20 -0
- package/src/api/protocol-v2/FilesystemDiskControl.ts +50 -0
- package/src/api/protocol-v2/FilesystemFixPermission.ts +16 -0
- package/src/api/protocol-v2/FilesystemFormat.ts +16 -0
- package/src/api/protocol-v2/GetProtoVersion.ts +16 -0
- package/src/api/protocol-v2/Ping.ts +18 -0
- package/src/api/protocol-v2/helpers.ts +207 -0
- package/src/api/scdo/ScdoGetAddress.ts +6 -2
- package/src/api/scdo/ScdoSignMessage.ts +6 -1
- package/src/api/scdo/ScdoSignTransaction.ts +6 -2
- package/src/api/solana/SolGetAddress.ts +4 -0
- package/src/api/solana/SolSignMessage.ts +3 -0
- package/src/api/solana/SolSignOffchainMessage.ts +3 -0
- package/src/api/solana/SolSignTransaction.ts +6 -0
- package/src/api/stellar/StellarGetAddress.ts +10 -1
- package/src/api/stellar/StellarSignTransaction.ts +14 -1
- package/src/api/sui/SuiGetAddress.ts +5 -3
- package/src/api/sui/SuiGetPublicKey.ts +3 -0
- package/src/api/sui/SuiSignMessage.ts +3 -0
- package/src/api/sui/SuiSignTransaction.ts +14 -12
- package/src/api/ton/TonGetAddress.ts +3 -0
- package/src/api/ton/TonSignData.ts +10 -3
- package/src/api/ton/TonSignMessage.ts +6 -5
- package/src/api/ton/TonSignProof.ts +3 -0
- package/src/api/tron/TronSignMessage.ts +5 -1
- package/src/api/tron/TronSignTransaction.ts +4 -0
- package/src/api/xrp/XrpSignTransaction.ts +1 -1
- package/src/core/index.ts +87 -55
- package/src/data/messages/messages-protocol-v2.json +13369 -0
- package/src/data-manager/DataManager.ts +12 -7
- package/src/data-manager/MessagesConfig.ts +14 -14
- package/src/data-manager/TransportManager.ts +38 -12
- package/src/device/Device.ts +538 -61
- package/src/device/DeviceCommands.ts +195 -29
- package/src/device/DeviceConnector.ts +29 -4
- package/src/device/DevicePool.ts +7 -7
- package/src/deviceProfile/buildDeviceProfile.ts +387 -0
- package/src/deviceProfile/index.ts +2 -0
- package/src/deviceProfile/legacyFeaturesView.ts +123 -0
- package/src/events/logBlockEvent.ts +23 -0
- package/src/events/ui-request.ts +8 -0
- package/src/inject.ts +52 -1
- package/src/protocols/protocol-v2/features.ts +180 -0
- package/src/protocols/protocol-v2/firmware.ts +43 -0
- package/src/protocols/protocol-v2/index.ts +16 -0
- package/src/types/api/export.ts +1 -0
- package/src/types/api/firmwareUpdate.ts +49 -0
- package/src/types/api/getDeviceInfo.ts +99 -0
- package/src/types/api/getPassphraseState.ts +13 -2
- package/src/types/api/index.ts +88 -1
- package/src/types/api/protocolV2.ts +201 -0
- package/src/types/api/searchDevices.ts +2 -2
- package/src/types/device.ts +37 -3
- package/src/types/params.ts +7 -0
- package/src/types/settings.ts +1 -1
- package/src/utils/deviceFeaturesUtils.ts +70 -70
- package/src/utils/deviceInfoUtils.ts +15 -8
- package/src/utils/index.ts +1 -0
package/src/device/Device.ts
CHANGED
|
@@ -19,21 +19,30 @@ import {
|
|
|
19
19
|
getDeviceLabel,
|
|
20
20
|
getDeviceType,
|
|
21
21
|
getDeviceUUID,
|
|
22
|
+
getFirmwareType,
|
|
22
23
|
getLogger,
|
|
23
|
-
getMethodVersionRange,
|
|
24
24
|
} from '../utils';
|
|
25
25
|
import {
|
|
26
26
|
fixFeaturesFirmwareVersion,
|
|
27
27
|
getPassphraseStateWithRefreshDeviceInfo,
|
|
28
|
+
supportInputPinOnSoftware,
|
|
29
|
+
supportModifyHomescreen,
|
|
28
30
|
} from '../utils/deviceFeaturesUtils';
|
|
29
31
|
import { generateInstanceId } from '../utils/tracing';
|
|
30
32
|
// eslint-disable-next-line import/no-cycle
|
|
31
33
|
import { DeviceCommands } from './DeviceCommands';
|
|
32
34
|
import {
|
|
33
35
|
type DeviceFirmwareRange,
|
|
36
|
+
DeviceModelToTypes,
|
|
37
|
+
DeviceTypeToModels,
|
|
34
38
|
type Device as DeviceTyped,
|
|
35
39
|
EOneKeyDeviceMode,
|
|
36
40
|
type Features,
|
|
41
|
+
type IDeviceModel,
|
|
42
|
+
type IDeviceType,
|
|
43
|
+
type IVersionArray,
|
|
44
|
+
type IVersionRange,
|
|
45
|
+
type SupportFeatureType,
|
|
37
46
|
type UnavailableCapabilities,
|
|
38
47
|
} from '../types';
|
|
39
48
|
import { DEVICE, UI_REQUEST } from '../events';
|
|
@@ -41,6 +50,15 @@ import { DataManager } from '../data-manager';
|
|
|
41
50
|
import TransportManager from '../data-manager/TransportManager';
|
|
42
51
|
import { toHardened } from '../api/helpers/pathUtils';
|
|
43
52
|
import { existCapability } from '../utils/capabilitieUtils';
|
|
53
|
+
import {
|
|
54
|
+
PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST,
|
|
55
|
+
requestProtocolV2DeviceInfo,
|
|
56
|
+
} from '../protocols/protocol-v2/features';
|
|
57
|
+
import {
|
|
58
|
+
buildProfileFromProtocolV1,
|
|
59
|
+
buildProfileFromProtocolV2,
|
|
60
|
+
buildProtocolV2GetFeaturesPayload,
|
|
61
|
+
} from '../deviceProfile';
|
|
44
62
|
|
|
45
63
|
import type { PROTO } from '../constants';
|
|
46
64
|
import type {
|
|
@@ -49,15 +67,21 @@ import type {
|
|
|
49
67
|
PassphraseRequestPayload,
|
|
50
68
|
} from '../events';
|
|
51
69
|
import type { PassphrasePromptResponse } from './DeviceCommands';
|
|
52
|
-
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
53
|
-
import type {
|
|
70
|
+
import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
71
|
+
import type {
|
|
72
|
+
OneKeyDeviceInfo as DeviceDescriptor,
|
|
73
|
+
ProtocolV2DeviceInfo,
|
|
74
|
+
Success,
|
|
75
|
+
} from '@onekeyfe/hd-transport';
|
|
54
76
|
import type DeviceConnector from './DeviceConnector';
|
|
77
|
+
import type { DeviceProfile } from '../types/api/getDeviceInfo';
|
|
55
78
|
|
|
56
79
|
export type InitOptions = {
|
|
57
80
|
initSession?: boolean;
|
|
58
81
|
deviceId?: string;
|
|
59
82
|
passphraseState?: string;
|
|
60
83
|
deriveCardano?: boolean;
|
|
84
|
+
connectProtocol?: HardwareConnectProtocol;
|
|
61
85
|
};
|
|
62
86
|
|
|
63
87
|
export type RunOptions = {
|
|
@@ -72,6 +96,11 @@ const parseRunOptions = (options?: RunOptions): RunOptions => {
|
|
|
72
96
|
|
|
73
97
|
const Log = getLogger(LoggerNames.Device);
|
|
74
98
|
|
|
99
|
+
const profileVersionToArray = (version?: string | null): IVersionArray | null => {
|
|
100
|
+
if (!version) return null;
|
|
101
|
+
return version.split('.').map(part => Number(part) || 0) as IVersionArray;
|
|
102
|
+
};
|
|
103
|
+
|
|
75
104
|
export interface DeviceEvents {
|
|
76
105
|
[DEVICE.PIN]: [Device, PROTO.PinMatrixRequestType | undefined, (err: any, pin: string) => void];
|
|
77
106
|
[DEVICE.PASSPHRASE_ON_DEVICE]: [Device, ((response: any) => void)?];
|
|
@@ -167,12 +196,39 @@ export class Device extends EventEmitter {
|
|
|
167
196
|
private deviceAcquired = false;
|
|
168
197
|
|
|
169
198
|
/**
|
|
170
|
-
*
|
|
199
|
+
* 唯一设备状态缓存。
|
|
200
|
+
*
|
|
201
|
+
* V1 直接保存原生 Features;V2 保存由 DevGetDeviceInfo/profile 映射出的
|
|
202
|
+
* legacy Features 兼容视图。profile 作为结构化视图按需由 features 派生,
|
|
203
|
+
* 不再单独维护第二份缓存。
|
|
171
204
|
*/
|
|
172
205
|
features: Features | undefined = undefined;
|
|
173
206
|
|
|
207
|
+
private getFeaturesProfile(): DeviceProfile | undefined {
|
|
208
|
+
if (!this.features) return undefined;
|
|
209
|
+
const protocol = this.originalDescriptor.protocolType === 'V2' ? 'V2' : 'V1';
|
|
210
|
+
return buildProfileFromProtocolV1({
|
|
211
|
+
protocol,
|
|
212
|
+
features: this.features,
|
|
213
|
+
onekeyFeatures: this.features as Parameters<typeof buildProfileFromProtocolV1>[0]['onekeyFeatures'],
|
|
214
|
+
sources: ['features'],
|
|
215
|
+
scope: 'verify',
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
get profile(): DeviceProfile | undefined {
|
|
220
|
+
return this.getFeaturesProfile();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
set profile(profile: DeviceProfile | undefined) {
|
|
224
|
+
this.updateProfile(profile);
|
|
225
|
+
}
|
|
226
|
+
|
|
174
227
|
/**
|
|
175
|
-
*
|
|
228
|
+
* 是否需要更新设备信息。
|
|
229
|
+
*
|
|
230
|
+
* 历史名称保留用于兼容现有调用语义;对 V2 表示 features 需要由
|
|
231
|
+
* DevGetDeviceInfo 刷新。
|
|
176
232
|
*/
|
|
177
233
|
featuresNeedsReload = false;
|
|
178
234
|
|
|
@@ -228,32 +284,38 @@ export class Device extends EventEmitter {
|
|
|
228
284
|
|
|
229
285
|
// simplified object to pass via postMessage
|
|
230
286
|
toMessageObject(): DeviceTyped | null {
|
|
231
|
-
if (this.isUnacquired()
|
|
287
|
+
if (this.isUnacquired()) return null;
|
|
232
288
|
|
|
233
289
|
const env = DataManager.getSettings('env');
|
|
234
|
-
const deviceType =
|
|
290
|
+
const deviceType = this.getCurrentDeviceType();
|
|
235
291
|
|
|
236
|
-
const bleName =
|
|
237
|
-
const label =
|
|
292
|
+
const bleName = this.getCurrentBleName();
|
|
293
|
+
const label = this.getCurrentLabel();
|
|
294
|
+
const serialNo = this.getCurrentSerialNo();
|
|
295
|
+
const deviceId = this.getCurrentDeviceId() || null;
|
|
296
|
+
|
|
297
|
+
const features = this.features;
|
|
238
298
|
|
|
239
299
|
return {
|
|
240
300
|
/** Android uses Mac address, iOS uses uuid, USB uses uuid */
|
|
241
|
-
connectId: DataManager.isBleConnect(env) ? this.mainId || null :
|
|
301
|
+
connectId: DataManager.isBleConnect(env) ? this.mainId || null : serialNo,
|
|
242
302
|
/** Hardware ID, will not change at any time */
|
|
243
|
-
uuid:
|
|
303
|
+
uuid: serialNo,
|
|
244
304
|
commType: this.originalDescriptor.commType,
|
|
245
305
|
sdkInstanceId: this.sdkInstanceId,
|
|
246
306
|
instanceId: this.instanceId,
|
|
247
307
|
createdAt: this.createdAt,
|
|
248
308
|
deviceType,
|
|
249
309
|
/** ID for current seeds, will clear after replace a new seed at device */
|
|
250
|
-
deviceId
|
|
310
|
+
deviceId,
|
|
251
311
|
path: this.originalDescriptor?.path,
|
|
252
312
|
bleName,
|
|
253
313
|
name: bleName || label || `OneKey ${deviceType?.toUpperCase()}`,
|
|
254
314
|
label: label || 'OneKey',
|
|
255
315
|
mode: this.getMode(),
|
|
256
|
-
features
|
|
316
|
+
features,
|
|
317
|
+
profile: this.profile,
|
|
318
|
+
sessionId: this.features?.session_id ?? null,
|
|
257
319
|
firmwareVersion: this.getFirmwareVersion(),
|
|
258
320
|
bleFirmwareVersion: this.getBLEFirmwareVersion(),
|
|
259
321
|
unavailableCapabilities: this.unavailableCapabilities,
|
|
@@ -264,13 +326,13 @@ export class Device extends EventEmitter {
|
|
|
264
326
|
* Device connect
|
|
265
327
|
* @returns {Promise<boolean>}
|
|
266
328
|
*/
|
|
267
|
-
connect() {
|
|
329
|
+
connect(connectProtocol?: HardwareConnectProtocol) {
|
|
268
330
|
const env = DataManager.getSettings('env');
|
|
269
331
|
// eslint-disable-next-line no-async-promise-executor
|
|
270
332
|
return new Promise<boolean>(async (resolve, reject) => {
|
|
271
333
|
if (DataManager.isBleConnect(env)) {
|
|
272
334
|
try {
|
|
273
|
-
await this.acquire();
|
|
335
|
+
await this.acquire(connectProtocol);
|
|
274
336
|
resolve(true);
|
|
275
337
|
} catch (error) {
|
|
276
338
|
reject(error);
|
|
@@ -280,7 +342,7 @@ export class Device extends EventEmitter {
|
|
|
280
342
|
// 不存在 Session ID 或存在 Session ID 但设备在别处使用,都需要 acquire 获取最新 sessionID
|
|
281
343
|
if (!this.mainId || (!this.isUsedHere() && this.originalDescriptor)) {
|
|
282
344
|
try {
|
|
283
|
-
await this.acquire();
|
|
345
|
+
await this.acquire(connectProtocol);
|
|
284
346
|
resolve(true);
|
|
285
347
|
} catch (error) {
|
|
286
348
|
reject(error);
|
|
@@ -295,23 +357,49 @@ export class Device extends EventEmitter {
|
|
|
295
357
|
});
|
|
296
358
|
}
|
|
297
359
|
|
|
298
|
-
async acquire() {
|
|
360
|
+
async acquire(connectProtocol?: HardwareConnectProtocol) {
|
|
299
361
|
const env = DataManager.getSettings('env');
|
|
300
362
|
const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
|
|
363
|
+
const expectedProtocol = connectProtocol ?? this.originalDescriptor.protocolType;
|
|
301
364
|
try {
|
|
365
|
+
let acquireResult: unknown;
|
|
302
366
|
if (DataManager.isBleConnect(env)) {
|
|
303
|
-
|
|
304
|
-
|
|
367
|
+
// forceCleanRunPromise=true(自 e21b83c6 引入,修复 Pro2 BLE 重连):
|
|
368
|
+
// acquire 意味着开启一个全新会话,transport 里残留的上一次 runPromise
|
|
369
|
+
// 必然属于已死亡的会话(如固件升级重启、探测中断),不清理会让新会话的
|
|
370
|
+
// 调用被旧 promise 卡死。无法在 Device 层面区分“重连恢复”与普通 acquire,
|
|
371
|
+
// 因此对 BLE acquire 恒清理是有意为之。
|
|
372
|
+
acquireResult = await this.deviceConnector?.acquire(
|
|
373
|
+
this.originalDescriptor.id,
|
|
374
|
+
undefined,
|
|
375
|
+
true,
|
|
376
|
+
expectedProtocol
|
|
377
|
+
);
|
|
378
|
+
this.mainId = (acquireResult as any)?.uuid ?? '';
|
|
305
379
|
Log.debug('Expected uuid:', this.mainId);
|
|
306
380
|
} else {
|
|
307
|
-
|
|
381
|
+
acquireResult = await this.deviceConnector?.acquire(
|
|
308
382
|
this.originalDescriptor.path,
|
|
309
|
-
this.originalDescriptor.session
|
|
383
|
+
this.originalDescriptor.session,
|
|
384
|
+
undefined,
|
|
385
|
+
expectedProtocol
|
|
310
386
|
);
|
|
387
|
+
this.mainId = acquireResult as string | undefined;
|
|
311
388
|
Log.debug('Expected session id:', this.mainId);
|
|
312
389
|
}
|
|
313
390
|
this.deviceAcquired = true;
|
|
314
391
|
this.updateDescriptor({ [mainIdKey]: this.mainId } as unknown as DeviceDescriptor);
|
|
392
|
+
|
|
393
|
+
// Propagate protocol version detected during acquire.
|
|
394
|
+
const detectedProtocol =
|
|
395
|
+
(acquireResult as { protocolType?: HardwareConnectProtocol } | undefined)?.protocolType ??
|
|
396
|
+
TransportManager.transport?.getProtocolType?.(
|
|
397
|
+
DataManager.isBleConnect(env) ? this.originalDescriptor.id : this.originalDescriptor.path
|
|
398
|
+
);
|
|
399
|
+
if (detectedProtocol) {
|
|
400
|
+
this.originalDescriptor.protocolType = detectedProtocol;
|
|
401
|
+
}
|
|
402
|
+
|
|
315
403
|
if (this.commands) {
|
|
316
404
|
await this.commands.dispose(false);
|
|
317
405
|
}
|
|
@@ -368,12 +456,10 @@ export class Device extends EventEmitter {
|
|
|
368
456
|
}
|
|
369
457
|
|
|
370
458
|
/**
|
|
371
|
-
* Pre-initialize: connect + Initialize ahead of the sign.
|
|
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.
|
|
459
|
+
* Pre-initialize: connect + Initialize ahead of the sign.
|
|
374
460
|
*/
|
|
375
461
|
async preInitialize(initOptions?: InitOptions) {
|
|
376
|
-
if (
|
|
462
|
+
if (this.isUnacquired()) {
|
|
377
463
|
await this.acquire();
|
|
378
464
|
await this.initialize(initOptions);
|
|
379
465
|
}
|
|
@@ -419,6 +505,157 @@ export class Device extends EventEmitter {
|
|
|
419
505
|
return this.commands;
|
|
420
506
|
}
|
|
421
507
|
|
|
508
|
+
/**
|
|
509
|
+
* 唯一协议判别器。
|
|
510
|
+
*
|
|
511
|
+
* descriptor.protocolType 是协议探测后的结果;V2 features 由 DevGetDeviceInfo
|
|
512
|
+
* 映射产生,profile 只是 features 的结构化视图。
|
|
513
|
+
* 全 SDK 的协议分支都必须走这里,不要直接读 originalDescriptor.protocolType
|
|
514
|
+
* 或 profile.protocol。
|
|
515
|
+
*/
|
|
516
|
+
getProtocol(): 'V1' | 'V2' {
|
|
517
|
+
return this.originalDescriptor.protocolType === 'V2' ? 'V2' : 'V1';
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
isProtocolV2() {
|
|
521
|
+
return this.getProtocol() === 'V2';
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
getCurrentDeviceType() {
|
|
525
|
+
return this.profile?.deviceType ?? getDeviceType(this.features);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
getCurrentDeviceId() {
|
|
529
|
+
if (this.profile) {
|
|
530
|
+
return this.profile.deviceId || undefined;
|
|
531
|
+
}
|
|
532
|
+
return this.features?.device_id || undefined;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
getCurrentSerialNo() {
|
|
536
|
+
if (this.profile) {
|
|
537
|
+
return this.profile.serialNo || '';
|
|
538
|
+
}
|
|
539
|
+
return this.features ? getDeviceUUID(this.features) : '';
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
getCurrentBleName() {
|
|
543
|
+
// V2 不回退 legacy features,避免缓存残留的 V1 数据泄漏到 Pro2 视图
|
|
544
|
+
if (this.isProtocolV2()) return this.profile?.bleName ?? null;
|
|
545
|
+
return this.profile?.bleName ?? getDeviceBleName(this.features);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
getCurrentLabel() {
|
|
549
|
+
if (this.isProtocolV2()) return this.profile?.label ?? null;
|
|
550
|
+
return this.profile?.label ?? getDeviceLabel(this.features);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
getCurrentPassphraseProtection() {
|
|
554
|
+
if (this.profile) {
|
|
555
|
+
return this.profile.status.passphraseProtection;
|
|
556
|
+
}
|
|
557
|
+
return this.features?.passphrase_protection;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
getCurrentFirmwareType() {
|
|
561
|
+
return this.profile?.firmwareType ?? getFirmwareType(this.features);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
getCurrentFirmwareVersionString() {
|
|
565
|
+
return this.profile?.versions.firmware ?? getDeviceFirmwareVersion(this.features)?.join('.');
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
getCurrentBLEFirmwareVersionString() {
|
|
569
|
+
if (this.profile?.versions.ble) return this.profile.versions.ble;
|
|
570
|
+
if (!this.features) return undefined;
|
|
571
|
+
return getDeviceBLEFirmwareVersion(this.features).join('.');
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
getCurrentSafetyChecks() {
|
|
575
|
+
return this.features?.safety_checks;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
getCurrentMethodVersionRange(
|
|
579
|
+
getVersionRange: (deviceModel: IDeviceType | IDeviceModel) => IVersionRange | undefined
|
|
580
|
+
) {
|
|
581
|
+
const deviceType = this.getCurrentDeviceType();
|
|
582
|
+
const versionRange = getVersionRange(deviceType);
|
|
583
|
+
if (versionRange) return versionRange;
|
|
584
|
+
|
|
585
|
+
// Most-specific model first; must match getMethodVersionRange in deviceInfoUtils,
|
|
586
|
+
// otherwise e.g. Classic1s resolves the looser model_mini range before model_classic1s.
|
|
587
|
+
const modelFallbacks: IDeviceModel[] = [
|
|
588
|
+
'model_classic1s',
|
|
589
|
+
'model_classic',
|
|
590
|
+
'model_mini',
|
|
591
|
+
'model_touch',
|
|
592
|
+
];
|
|
593
|
+
for (const model of modelFallbacks) {
|
|
594
|
+
if (DeviceTypeToModels[deviceType]?.includes(model)) {
|
|
595
|
+
const fallbackRange = getVersionRange(model);
|
|
596
|
+
if (fallbackRange) return fallbackRange;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return undefined;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
supportNewPassphrase(): SupportFeatureType {
|
|
603
|
+
const deviceType = this.getCurrentDeviceType();
|
|
604
|
+
if (
|
|
605
|
+
deviceType === EDeviceType.Touch ||
|
|
606
|
+
deviceType === EDeviceType.Pro ||
|
|
607
|
+
deviceType === EDeviceType.Pro2
|
|
608
|
+
) {
|
|
609
|
+
return { support: true };
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
const firmwareVersion = this.getCurrentFirmwareVersionString();
|
|
613
|
+
return {
|
|
614
|
+
support: Boolean(firmwareVersion && semver.gte(firmwareVersion, '2.4.0')),
|
|
615
|
+
require: '2.4.0',
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
supportInputPinOnSoftware(): SupportFeatureType {
|
|
620
|
+
if (this.features) return supportInputPinOnSoftware(this.features);
|
|
621
|
+
|
|
622
|
+
const deviceType = this.getCurrentDeviceType();
|
|
623
|
+
if (
|
|
624
|
+
deviceType === EDeviceType.Touch ||
|
|
625
|
+
deviceType === EDeviceType.Pro ||
|
|
626
|
+
deviceType === EDeviceType.Pro2
|
|
627
|
+
) {
|
|
628
|
+
return { support: false };
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
const firmwareVersion = this.getCurrentFirmwareVersionString();
|
|
632
|
+
return {
|
|
633
|
+
support: Boolean(firmwareVersion && semver.gte(firmwareVersion, '2.3.0')),
|
|
634
|
+
require: '2.3.0',
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
supportModifyHomescreen(): SupportFeatureType {
|
|
639
|
+
// Pro2 走独立 1.x 版本线,不能套用 Touch/Pro 的 3.4.0 门槛(恒 false 且未来会误判)。
|
|
640
|
+
// 依据:firmware-pro2 协议 schema(messages-protocol-v2.json)的 ApplySettings
|
|
641
|
+
// 包含 homescreen 字段,V2 固件从首个版本即支持修改主屏。
|
|
642
|
+
if (this.isProtocolV2()) {
|
|
643
|
+
return { support: true };
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (this.features) return supportModifyHomescreen(this.features);
|
|
647
|
+
|
|
648
|
+
const deviceType = this.getCurrentDeviceType();
|
|
649
|
+
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
|
|
650
|
+
return { support: true };
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
const firmwareVersion = this.getCurrentFirmwareVersionString();
|
|
654
|
+
return {
|
|
655
|
+
support: Boolean(firmwareVersion && semver.gte(firmwareVersion, '3.4.0')),
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
|
|
422
659
|
private generateStateKey(deviceId: string, passphraseState?: string) {
|
|
423
660
|
if (passphraseState) {
|
|
424
661
|
return `${deviceId}@${passphraseState}`;
|
|
@@ -432,10 +669,11 @@ export class Device extends EventEmitter {
|
|
|
432
669
|
'getInternalState session param: ',
|
|
433
670
|
`device_id: ${_deviceId}`,
|
|
434
671
|
`features.device_id: ${this.features?.device_id}`,
|
|
672
|
+
`profile.deviceId: ${this.profile?.deviceId}`,
|
|
435
673
|
`passphraseState: ${this.passphraseState}`
|
|
436
674
|
);
|
|
437
675
|
|
|
438
|
-
const deviceId = _deviceId || this.
|
|
676
|
+
const deviceId = _deviceId || this.getCurrentDeviceId();
|
|
439
677
|
if (!deviceId) return undefined;
|
|
440
678
|
// Security invariant: no passphraseState → no session lookup.
|
|
441
679
|
// A previous fallback that scanned `${deviceId}@*` keys could silently
|
|
@@ -490,13 +728,13 @@ export class Device extends EventEmitter {
|
|
|
490
728
|
`state: ${state}`,
|
|
491
729
|
`initSession: ${initSession}`,
|
|
492
730
|
`device_id: ${this.features?.device_id}`,
|
|
731
|
+
`profile.deviceId: ${this.profile?.deviceId}`,
|
|
493
732
|
`passphraseState: ${this.passphraseState}`
|
|
494
733
|
);
|
|
495
734
|
|
|
496
|
-
if (!this.features) return;
|
|
497
735
|
if (!this.passphraseState && !initSession) return;
|
|
498
736
|
|
|
499
|
-
const deviceId = this.
|
|
737
|
+
const deviceId = this.getCurrentDeviceId();
|
|
500
738
|
if (!deviceId) return;
|
|
501
739
|
|
|
502
740
|
const key = this.generateStateKey(deviceId, this.passphraseState);
|
|
@@ -510,7 +748,7 @@ export class Device extends EventEmitter {
|
|
|
510
748
|
clearInternalState(_deviceId?: string) {
|
|
511
749
|
Log.debug('clearInternalState param: ', _deviceId);
|
|
512
750
|
|
|
513
|
-
const deviceId = _deviceId || this.
|
|
751
|
+
const deviceId = _deviceId || this.getCurrentDeviceId();
|
|
514
752
|
if (!deviceId) return;
|
|
515
753
|
const key = `${deviceId}`;
|
|
516
754
|
delete deviceSessionCache[key];
|
|
@@ -522,6 +760,21 @@ export class Device extends EventEmitter {
|
|
|
522
760
|
}
|
|
523
761
|
|
|
524
762
|
async initialize(options?: InitOptions) {
|
|
763
|
+
// Protocol V2 不支持传统 Initialize,直接使用协议专用初始化流程。
|
|
764
|
+
if (this.isProtocolV2()) {
|
|
765
|
+
this.passphraseState = options?.passphraseState;
|
|
766
|
+
if (this.profile && !this.featuresNeedsReload && !options?.initSession) {
|
|
767
|
+
// 不能直接信任缓存 profile:设备端 wipe / 完成初始化 / 改 label 后
|
|
768
|
+
// profile 会永久陈旧。每次 run 做一次轻量 status 刷新(不含 fw/SE,
|
|
769
|
+
// 单帧请求开销很小),用 applyProfileUpdate 字段级合并,
|
|
770
|
+
// 不会降级已有的 verify / SE versions 数据。
|
|
771
|
+
await this._refreshProtocolV2Status();
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
await this._initializeProtocolV2();
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
|
|
525
778
|
// Log.debug('initialize param:', options);
|
|
526
779
|
|
|
527
780
|
this.passphraseState = options?.passphraseState;
|
|
@@ -565,9 +818,91 @@ export class Device extends EventEmitter {
|
|
|
565
818
|
}
|
|
566
819
|
}
|
|
567
820
|
|
|
821
|
+
/**
|
|
822
|
+
* Device initialization over Protocol V2.
|
|
823
|
+
*
|
|
824
|
+
* Protocol V2 不走传统 Initialize/GetFeatures;DeviceProfile 作为标准模型,
|
|
825
|
+
* 同时维护一份由 profile/deviceInfo 适配出的 legacy Features,兼容旧方法内部判断。
|
|
826
|
+
*/
|
|
827
|
+
private async _initializeProtocolV2() {
|
|
828
|
+
Log.debug('Initialize device via Protocol V2 profile adapter');
|
|
829
|
+
|
|
830
|
+
try {
|
|
831
|
+
// 超时由 requestProtocolV2DeviceInfo 内部的 typedCall timeoutMs(默认 10s)负责,
|
|
832
|
+
// 不再额外包一层 Promise.race:外层 race 的 timer 不会清理,
|
|
833
|
+
// 且 reject 后底层调用仍会残留。
|
|
834
|
+
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
835
|
+
commands: this.commands,
|
|
836
|
+
});
|
|
837
|
+
// 默认请求不含 SE/hash 数据,scope 如实标注为 basic;
|
|
838
|
+
// 完整数据由 getDeviceInfo(scope:'verify'|'full') 获取。
|
|
839
|
+
const profile = this.applyProfileUpdate(
|
|
840
|
+
buildProfileFromProtocolV2({
|
|
841
|
+
deviceInfo,
|
|
842
|
+
sources: ['deviceInfo'],
|
|
843
|
+
scope: 'basic',
|
|
844
|
+
fallbackSerialNo: this.originalDescriptor?.path,
|
|
845
|
+
}),
|
|
846
|
+
deviceInfo
|
|
847
|
+
);
|
|
848
|
+
Log.debug('Protocol V2 profile:', profile);
|
|
849
|
+
this.featuresNeedsReload = false;
|
|
850
|
+
} catch (error) {
|
|
851
|
+
Log.error('Protocol V2 initialization failed:', error);
|
|
852
|
+
throw error;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* Protocol V2 的轻量状态刷新(每次 run 前调用)。
|
|
858
|
+
*
|
|
859
|
+
* 请求 hw + bt + status(不含 fw/SE target):status 提供 init_states / label /
|
|
860
|
+
* passphrase_protection 等会在设备端变化的字段;hw/bt 提供 serialNo / bleName,
|
|
861
|
+
* 避免 applyProfileUpdate 的顶层字段覆盖把已有身份字段清空。
|
|
862
|
+
* versions 为空时按字段级合并保留旧值,verify 数据不会被降级。
|
|
863
|
+
*/
|
|
864
|
+
private async _refreshProtocolV2Status() {
|
|
865
|
+
try {
|
|
866
|
+
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
867
|
+
commands: this.commands,
|
|
868
|
+
request: PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST,
|
|
869
|
+
});
|
|
870
|
+
const profile = this.applyProfileUpdate(
|
|
871
|
+
buildProfileFromProtocolV2({
|
|
872
|
+
deviceInfo,
|
|
873
|
+
sources: ['deviceInfo'],
|
|
874
|
+
scope: 'basic',
|
|
875
|
+
fallbackSerialNo: this.originalDescriptor?.path,
|
|
876
|
+
}),
|
|
877
|
+
deviceInfo
|
|
878
|
+
);
|
|
879
|
+
Log.debug('Protocol V2 profile (status refresh):', profile);
|
|
880
|
+
} catch (error) {
|
|
881
|
+
Log.error('Protocol V2 status refresh failed:', error);
|
|
882
|
+
throw error;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
568
886
|
async getFeatures() {
|
|
887
|
+
if (this.isProtocolV2()) {
|
|
888
|
+
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
889
|
+
commands: this.commands,
|
|
890
|
+
});
|
|
891
|
+
const profile = this.applyProfileUpdate(
|
|
892
|
+
buildProfileFromProtocolV2({
|
|
893
|
+
deviceInfo,
|
|
894
|
+
sources: ['deviceInfo'],
|
|
895
|
+
scope: 'basic',
|
|
896
|
+
fallbackSerialNo: this.originalDescriptor?.path,
|
|
897
|
+
}),
|
|
898
|
+
deviceInfo
|
|
899
|
+
);
|
|
900
|
+
return this.features ?? this.updateProtocolV2Features(profile, deviceInfo);
|
|
901
|
+
}
|
|
902
|
+
|
|
569
903
|
const { message } = await this.commands.typedCall('GetFeatures', 'Features', {});
|
|
570
904
|
this._updateFeatures(message);
|
|
905
|
+
return message;
|
|
571
906
|
}
|
|
572
907
|
|
|
573
908
|
_updateFeatures(feat: Features, initSession?: boolean) {
|
|
@@ -575,7 +910,7 @@ export class Device extends EventEmitter {
|
|
|
575
910
|
if (this.features && this.features.session_id && !feat.session_id) {
|
|
576
911
|
feat.session_id = this.features.session_id;
|
|
577
912
|
}
|
|
578
|
-
if (this.
|
|
913
|
+
if (this.getCurrentDeviceId() && feat.session_id) {
|
|
579
914
|
this.setInternalState(feat.session_id, initSession);
|
|
580
915
|
}
|
|
581
916
|
feat.unlocked = feat.unlocked ?? true;
|
|
@@ -583,10 +918,81 @@ export class Device extends EventEmitter {
|
|
|
583
918
|
feat = fixFeaturesFirmwareVersion(feat);
|
|
584
919
|
|
|
585
920
|
this.features = feat;
|
|
921
|
+
if (!this.isProtocolV2()) {
|
|
922
|
+
this.updateProfile(
|
|
923
|
+
buildProfileFromProtocolV1({
|
|
924
|
+
features: feat,
|
|
925
|
+
sources: ['features'],
|
|
926
|
+
})
|
|
927
|
+
);
|
|
928
|
+
}
|
|
586
929
|
this.featuresNeedsReload = false;
|
|
587
930
|
this.emit(DEVICE.FEATURES, this, feat);
|
|
588
931
|
}
|
|
589
932
|
|
|
933
|
+
updateProfile(profile: DeviceProfile | undefined) {
|
|
934
|
+
if (!profile) {
|
|
935
|
+
this.features = undefined;
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
if (profile.protocol === 'V2') {
|
|
939
|
+
this.updateProtocolV2Features(profile, profile.raw?.protocolV2DeviceInfo);
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
if (profile.raw?.features) {
|
|
943
|
+
this.features = fixFeaturesFirmwareVersion(profile.raw.features);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
/**
|
|
948
|
+
* 字段级合并刷新 profile,并返回合并后的结果。
|
|
949
|
+
*
|
|
950
|
+
* basic 范围的刷新(initialize / getFeatures)拿不到 SE 版本和 verify 数据,
|
|
951
|
+
* 不能整体替换掉 getDeviceInfo(scope:'verify'|'full') 建立的完整 profile。
|
|
952
|
+
*/
|
|
953
|
+
applyProfileUpdate(next: DeviceProfile, deviceInfo?: ProtocolV2DeviceInfo): DeviceProfile {
|
|
954
|
+
const prev = this.profile;
|
|
955
|
+
if (!prev || prev.protocol !== next.protocol) {
|
|
956
|
+
this.updateProfile({
|
|
957
|
+
...next,
|
|
958
|
+
raw: {
|
|
959
|
+
...next.raw,
|
|
960
|
+
...(deviceInfo ? { protocolV2DeviceInfo: deviceInfo } : {}),
|
|
961
|
+
},
|
|
962
|
+
});
|
|
963
|
+
return next;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
const versions = { ...prev.versions };
|
|
967
|
+
for (const [key, value] of Object.entries(next.versions)) {
|
|
968
|
+
if (value != null) {
|
|
969
|
+
(versions as Record<string, string | null | undefined>)[key] = value;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
const merged: DeviceProfile = {
|
|
974
|
+
...prev,
|
|
975
|
+
...next,
|
|
976
|
+
versions,
|
|
977
|
+
verify: next.verify ?? prev.verify,
|
|
978
|
+
raw: {
|
|
979
|
+
...prev.raw,
|
|
980
|
+
...next.raw,
|
|
981
|
+
...(deviceInfo ? { protocolV2DeviceInfo: deviceInfo } : {}),
|
|
982
|
+
},
|
|
983
|
+
};
|
|
984
|
+
this.updateProfile(merged);
|
|
985
|
+
return merged;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
private updateProtocolV2Features(profile: DeviceProfile, deviceInfo?: ProtocolV2DeviceInfo) {
|
|
989
|
+
const features = fixFeaturesFirmwareVersion(
|
|
990
|
+
buildProtocolV2GetFeaturesPayload(profile, deviceInfo)
|
|
991
|
+
);
|
|
992
|
+
this._updateFeatures(features);
|
|
993
|
+
return features;
|
|
994
|
+
}
|
|
995
|
+
|
|
590
996
|
/**
|
|
591
997
|
* 暂时只在 acquire 后更新 Session ID
|
|
592
998
|
* 后续看是否有需要依据 listen 返回结果更新
|
|
@@ -605,7 +1011,12 @@ export class Device extends EventEmitter {
|
|
|
605
1011
|
}
|
|
606
1012
|
|
|
607
1013
|
if (forceUpdate) {
|
|
608
|
-
|
|
1014
|
+
// 枚举得到的 descriptor 可能不带 protocolType(如 WebUSB enumerate),
|
|
1015
|
+
// 不能让覆盖丢掉已探测的协议结果。
|
|
1016
|
+
this.originalDescriptor = {
|
|
1017
|
+
...descriptor,
|
|
1018
|
+
protocolType: descriptor.protocolType ?? this.originalDescriptor.protocolType,
|
|
1019
|
+
};
|
|
609
1020
|
}
|
|
610
1021
|
}
|
|
611
1022
|
|
|
@@ -616,6 +1027,7 @@ export class Device extends EventEmitter {
|
|
|
616
1027
|
if (device.features) {
|
|
617
1028
|
this._updateFeatures(device.features);
|
|
618
1029
|
}
|
|
1030
|
+
this.updateProfile(device.profile);
|
|
619
1031
|
}
|
|
620
1032
|
|
|
621
1033
|
async run(fn?: () => Promise<void>, options?: RunOptions) {
|
|
@@ -635,7 +1047,7 @@ export class Device extends EventEmitter {
|
|
|
635
1047
|
const env = DataManager.getSettings('env');
|
|
636
1048
|
if (env !== 'react-native') {
|
|
637
1049
|
try {
|
|
638
|
-
await this.acquire();
|
|
1050
|
+
await this.acquire(options.connectProtocol);
|
|
639
1051
|
} catch (error) {
|
|
640
1052
|
this.runPromise = null;
|
|
641
1053
|
return Promise.reject(error);
|
|
@@ -748,6 +1160,16 @@ export class Device extends EventEmitter {
|
|
|
748
1160
|
}
|
|
749
1161
|
|
|
750
1162
|
getMode() {
|
|
1163
|
+
if (this.profile) {
|
|
1164
|
+
if (this.profile.status.mode === 'bootloader') return EOneKeyDeviceMode.bootloader;
|
|
1165
|
+
if (this.profile.status.mode === 'notInitialized') return EOneKeyDeviceMode.notInitialized;
|
|
1166
|
+
if (this.profile.status.noBackup === true) return EOneKeyDeviceMode.backupMode;
|
|
1167
|
+
if (this.profile.status.mode === 'normal') return EOneKeyDeviceMode.normal;
|
|
1168
|
+
// mode 'unknown'(V2 设备未上报 init_states)保守按未初始化处理,
|
|
1169
|
+
// 与 isInitialized() 的 fail-closed 行为保持一致。
|
|
1170
|
+
if (this.isProtocolV2()) return EOneKeyDeviceMode.notInitialized;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
751
1173
|
if (this.features?.bootloader_mode) {
|
|
752
1174
|
// bootloader mode
|
|
753
1175
|
return EOneKeyDeviceMode.bootloader;
|
|
@@ -768,11 +1190,17 @@ export class Device extends EventEmitter {
|
|
|
768
1190
|
}
|
|
769
1191
|
|
|
770
1192
|
getFirmwareVersion() {
|
|
1193
|
+
const profileVersion = profileVersionToArray(this.profile?.versions.firmware);
|
|
1194
|
+
if (profileVersion) return profileVersion;
|
|
1195
|
+
if (this.isProtocolV2()) return null;
|
|
771
1196
|
if (!this.features) return null;
|
|
772
1197
|
return getDeviceFirmwareVersion(this.features);
|
|
773
1198
|
}
|
|
774
1199
|
|
|
775
1200
|
getBLEFirmwareVersion() {
|
|
1201
|
+
const profileVersion = profileVersionToArray(this.profile?.versions.ble);
|
|
1202
|
+
if (profileVersion) return profileVersion;
|
|
1203
|
+
if (this.isProtocolV2()) return null;
|
|
776
1204
|
if (!this.features) return null;
|
|
777
1205
|
return getDeviceBLEFirmwareVersion(this.features);
|
|
778
1206
|
}
|
|
@@ -802,24 +1230,42 @@ export class Device extends EventEmitter {
|
|
|
802
1230
|
}
|
|
803
1231
|
|
|
804
1232
|
isBootloader() {
|
|
1233
|
+
if (this.profile) {
|
|
1234
|
+
return (
|
|
1235
|
+
this.profile.status.mode === 'bootloader' || this.profile.status.bootloaderMode === true
|
|
1236
|
+
);
|
|
1237
|
+
}
|
|
805
1238
|
return this.features && !!this.features.bootloader_mode;
|
|
806
1239
|
}
|
|
807
1240
|
|
|
808
1241
|
isInitialized() {
|
|
1242
|
+
if (this.profile) {
|
|
1243
|
+
if (this.profile.status.initialized != null) return this.profile.status.initialized;
|
|
1244
|
+
if (this.profile.status.mode === 'normal') return true;
|
|
1245
|
+
if (this.profile.status.mode === 'notInitialized') return false;
|
|
1246
|
+
// V2 设备未上报 init_states 时按未初始化处理(fail-closed):
|
|
1247
|
+
// 未知状态放行会让未初始化设备绕过 NOT_INITIALIZE 门禁。
|
|
1248
|
+
if (this.isProtocolV2()) return false;
|
|
1249
|
+
if (this.features) return !!this.features.initialized;
|
|
1250
|
+
return false;
|
|
1251
|
+
}
|
|
809
1252
|
return this.features && !!this.features.initialized;
|
|
810
1253
|
}
|
|
811
1254
|
|
|
812
1255
|
isSeedless() {
|
|
1256
|
+
if (this.profile) {
|
|
1257
|
+
return this.profile.status.noBackup === true;
|
|
1258
|
+
}
|
|
813
1259
|
return this.features && !!this.features.no_backup;
|
|
814
1260
|
}
|
|
815
1261
|
|
|
816
1262
|
isUnacquired(): boolean {
|
|
817
|
-
return this.features === undefined;
|
|
1263
|
+
return this.features === undefined && this.profile === undefined;
|
|
818
1264
|
}
|
|
819
1265
|
|
|
820
1266
|
hasUnexpectedMode(allow: string[], require: string[]) {
|
|
821
1267
|
// both allow and require cases might generate single unexpected mode
|
|
822
|
-
if (this.
|
|
1268
|
+
if (!this.isUnacquired()) {
|
|
823
1269
|
// allow cases
|
|
824
1270
|
if (this.isBootloader() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
|
|
825
1271
|
return UI_REQUEST.BOOTLOADER;
|
|
@@ -840,27 +1286,30 @@ export class Device extends EventEmitter {
|
|
|
840
1286
|
}
|
|
841
1287
|
|
|
842
1288
|
hasUsePassphrase() {
|
|
1289
|
+
const deviceType = this.getCurrentDeviceType();
|
|
843
1290
|
const isModeT =
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
1291
|
+
deviceType === EDeviceType.Touch ||
|
|
1292
|
+
deviceType === EDeviceType.Pro ||
|
|
1293
|
+
deviceType === EDeviceType.Pro2;
|
|
1294
|
+
const unlocked = this.profile ? this.profile.status.unlocked : this.features?.unlocked;
|
|
1295
|
+
const preCheckTouch = isModeT && unlocked === false;
|
|
1296
|
+
const passphraseProtection = this.getCurrentPassphraseProtection();
|
|
1297
|
+
|
|
1298
|
+
return Boolean(passphraseProtection === true || preCheckTouch);
|
|
849
1299
|
}
|
|
850
1300
|
|
|
851
1301
|
checkDeviceId(deviceId: string) {
|
|
852
|
-
|
|
853
|
-
return this.features.device_id === deviceId;
|
|
854
|
-
}
|
|
855
|
-
return false;
|
|
1302
|
+
return this.getCurrentDeviceId() === deviceId;
|
|
856
1303
|
}
|
|
857
1304
|
|
|
858
|
-
async lockDevice() {
|
|
1305
|
+
async lockDevice(): Promise<Success> {
|
|
859
1306
|
const res = await this.commands.typedCall('LockDevice', 'Success', {});
|
|
860
1307
|
return res.message;
|
|
861
1308
|
}
|
|
862
1309
|
|
|
863
1310
|
supportUnlockVersionRange(): DeviceFirmwareRange {
|
|
1311
|
+
// 仅适用于 Protocol V1 的 Pro 系列;Pro2 走独立版本线,
|
|
1312
|
+
// 且 Protocol V2 固件从首个版本即支持 UnLockDevice(见 unlockDevice 的 isProtocolV2 短路)。
|
|
864
1313
|
return {
|
|
865
1314
|
pro: {
|
|
866
1315
|
min: '4.15.0',
|
|
@@ -869,9 +1318,9 @@ export class Device extends EventEmitter {
|
|
|
869
1318
|
}
|
|
870
1319
|
|
|
871
1320
|
async unlockDevice() {
|
|
872
|
-
const firmwareVersion =
|
|
873
|
-
|
|
874
|
-
|
|
1321
|
+
const firmwareVersion = this.getCurrentFirmwareVersionString() ?? '0.0.0';
|
|
1322
|
+
// profile 优先的版本范围解析;features 仅作为 V1 capability 判断来源
|
|
1323
|
+
const versionRange = this.getCurrentMethodVersionRange(
|
|
875
1324
|
type => this.supportUnlockVersionRange()[type]
|
|
876
1325
|
);
|
|
877
1326
|
|
|
@@ -879,12 +1328,29 @@ export class Device extends EventEmitter {
|
|
|
879
1328
|
this.features,
|
|
880
1329
|
Enum_Capability.Capability_AttachToPin
|
|
881
1330
|
);
|
|
882
|
-
|
|
1331
|
+
// Pro2 (Protocol V2) 版本线独立于 Pro 系列,固件从首个版本即支持 UnLockDevice
|
|
883
1332
|
const supportUnlock =
|
|
884
|
-
|
|
1333
|
+
this.isProtocolV2() ||
|
|
1334
|
+
supportAttachPinCapability ||
|
|
1335
|
+
(versionRange &&
|
|
1336
|
+
semver.valid(firmwareVersion) &&
|
|
1337
|
+
semver.gte(firmwareVersion, versionRange.min));
|
|
885
1338
|
|
|
886
1339
|
if (supportUnlock) {
|
|
887
1340
|
const res = await this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
|
|
1341
|
+
// 解锁结果同步到 profile(标准模型),features 仅在 V1 缓存存在时回写
|
|
1342
|
+
if (this.profile) {
|
|
1343
|
+
this.updateProfile({
|
|
1344
|
+
...this.profile,
|
|
1345
|
+
status: {
|
|
1346
|
+
...this.profile.status,
|
|
1347
|
+
unlocked: res.message.unlocked == null ? null : res.message.unlocked,
|
|
1348
|
+
...(res.message.passphrase_protection != null
|
|
1349
|
+
? { passphraseProtection: res.message.passphrase_protection }
|
|
1350
|
+
: {}),
|
|
1351
|
+
},
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
888
1354
|
if (this.features) {
|
|
889
1355
|
this.features.unlocked = res.message.unlocked == null ? null : res.message.unlocked;
|
|
890
1356
|
this.features.unlocked_attach_pin =
|
|
@@ -895,9 +1361,16 @@ export class Device extends EventEmitter {
|
|
|
895
1361
|
return Promise.resolve(this.features);
|
|
896
1362
|
}
|
|
897
1363
|
|
|
898
|
-
const
|
|
899
|
-
|
|
900
|
-
|
|
1364
|
+
const features = await this.getFeatures();
|
|
1365
|
+
return Promise.resolve(features);
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
// legacy 解锁探测仅适用于 Protocol V1 老固件;V2 固件必然支持 UnLockDevice
|
|
1369
|
+
if (this.isProtocolV2()) {
|
|
1370
|
+
throw ERRORS.TypedError(
|
|
1371
|
+
HardwareErrorCode.RuntimeError,
|
|
1372
|
+
'unlock device error: device firmware does not support UnLockDevice'
|
|
1373
|
+
);
|
|
901
1374
|
}
|
|
902
1375
|
|
|
903
1376
|
const { type } = await this.commands.typedCall('GetAddress', 'Address', {
|
|
@@ -911,9 +1384,8 @@ export class Device extends EventEmitter {
|
|
|
911
1384
|
if (type === 'CallMethodError') {
|
|
912
1385
|
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'unlock device error');
|
|
913
1386
|
}
|
|
914
|
-
const
|
|
915
|
-
|
|
916
|
-
return Promise.resolve(res.message);
|
|
1387
|
+
const features = await this.getFeatures();
|
|
1388
|
+
return Promise.resolve(features);
|
|
917
1389
|
}
|
|
918
1390
|
|
|
919
1391
|
async checkPassphraseStateSafety(
|
|
@@ -921,7 +1393,7 @@ export class Device extends EventEmitter {
|
|
|
921
1393
|
useEmptyPassphrase?: boolean,
|
|
922
1394
|
skipPassphraseCheck?: boolean
|
|
923
1395
|
) {
|
|
924
|
-
if (
|
|
1396
|
+
if (this.isUnacquired()) return false;
|
|
925
1397
|
|
|
926
1398
|
const { passphraseState: newPassphraseState, unlockedAttachPin } =
|
|
927
1399
|
await getPassphraseStateWithRefreshDeviceInfo(this, {
|
|
@@ -929,14 +1401,11 @@ export class Device extends EventEmitter {
|
|
|
929
1401
|
onlyMainPin: useEmptyPassphrase,
|
|
930
1402
|
});
|
|
931
1403
|
|
|
932
|
-
if (skipPassphraseCheck) {
|
|
933
|
-
return true;
|
|
934
|
-
}
|
|
935
|
-
|
|
936
1404
|
// Main wallet and unlock Attach Pin, throw safe error
|
|
937
1405
|
const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
|
|
938
1406
|
const useErrorAttachPin =
|
|
939
1407
|
unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
|
|
1408
|
+
const passphraseStateMismatch = !!passphraseState && passphraseState !== newPassphraseState;
|
|
940
1409
|
|
|
941
1410
|
Log.debug('Check passphrase state safety: ', {
|
|
942
1411
|
passphraseState,
|
|
@@ -945,6 +1414,14 @@ export class Device extends EventEmitter {
|
|
|
945
1414
|
useEmptyPassphrase,
|
|
946
1415
|
});
|
|
947
1416
|
|
|
1417
|
+
if (skipPassphraseCheck) {
|
|
1418
|
+
if (passphraseStateMismatch) {
|
|
1419
|
+
this.clearInternalState();
|
|
1420
|
+
return false;
|
|
1421
|
+
}
|
|
1422
|
+
return true;
|
|
1423
|
+
}
|
|
1424
|
+
|
|
948
1425
|
if (mainWalletUseAttachPin || useErrorAttachPin) {
|
|
949
1426
|
try {
|
|
950
1427
|
await this.lockDevice();
|
|
@@ -956,7 +1433,7 @@ export class Device extends EventEmitter {
|
|
|
956
1433
|
}
|
|
957
1434
|
|
|
958
1435
|
// When exists passphraseState, check passphraseState
|
|
959
|
-
if (
|
|
1436
|
+
if (passphraseStateMismatch) {
|
|
960
1437
|
this.clearInternalState();
|
|
961
1438
|
return false;
|
|
962
1439
|
}
|