@onekeyfe/hd-core 1.1.28 → 1.2.0-alpha.1
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 +2908 -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 +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 +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/DeviceUnlock.d.ts +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/bootloaderHelper.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 +33 -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/constants/index.d.ts +2 -1
- package/dist/constants/index.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/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +33 -11
- 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/buildDeviceFeatures.d.ts +6 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceProfile.d.ts +21 -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/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 +717 -302
- package/dist/index.js +17654 -1271
- 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 +91 -5
- 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 +2 -1
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/capabilitieUtils.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/deviceVersionUtils.d.ts.map +1 -1
- package/dist/utils/findDefectiveBatchDevice.d.ts +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 +22 -19
- package/src/api/FirmwareUpdateV3.ts +19 -5
- package/src/api/FirmwareUpdateV4.ts +820 -0
- package/src/api/GetDeviceInfo.ts +145 -0
- package/src/api/GetFeatures.ts +5 -2
- package/src/api/GetOnekeyFeatures.ts +84 -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/bootloaderHelper.ts +3 -2
- package/src/api/firmware/getBinary.ts +1 -1
- package/src/api/firmware/releaseHelper.ts +3 -3
- package/src/api/firmware/uploadFirmware.ts +8 -12
- 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 +182 -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/constants/index.ts +10 -1
- package/src/core/index.ts +91 -61
- package/src/data/messages/messages-protocol-v2.json +13375 -0
- package/src/data-manager/DataManager.ts +16 -11
- package/src/data-manager/MessagesConfig.ts +14 -14
- package/src/data-manager/TransportManager.ts +38 -12
- package/src/data-manager/connectSettings.ts +6 -0
- package/src/device/Device.ts +398 -76
- package/src/device/DeviceCommands.ts +195 -29
- package/src/device/DeviceConnector.ts +29 -4
- package/src/device/DevicePool.ts +8 -8
- package/src/deviceProfile/buildDeviceFeatures.ts +368 -0
- package/src/deviceProfile/buildDeviceProfile.ts +333 -0
- package/src/deviceProfile/index.ts +5 -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 +178 -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 +200 -0
- package/src/types/api/searchDevices.ts +2 -2
- package/src/types/device.ts +102 -5
- package/src/types/params.ts +7 -0
- package/src/types/settings.ts +6 -1
- package/src/utils/capabilitieUtils.ts +1 -2
- package/src/utils/deviceFeaturesUtils.ts +75 -81
- package/src/utils/deviceInfoUtils.ts +23 -34
- package/src/utils/deviceVersionUtils.ts +7 -25
- package/src/utils/findDefectiveBatchDevice.ts +6 -6
- package/src/utils/index.ts +1 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import type { Features } from '../types';
|
|
4
|
+
import type { PROTO } from '../constants';
|
|
5
|
+
import type { DevFirmwareImageInfo, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
|
|
6
|
+
|
|
7
|
+
type ProtocolV2DeviceInfoCompat = ProtocolV2DeviceInfo & {
|
|
8
|
+
fw?: ProtocolV2DeviceInfo['fw'] & {
|
|
9
|
+
application?: DevFirmwareImageInfo | null;
|
|
10
|
+
application_data?: DevFirmwareImageInfo | null;
|
|
11
|
+
bootloader?: DevFirmwareImageInfo | null;
|
|
12
|
+
romloader?: DevFirmwareImageInfo | null;
|
|
13
|
+
};
|
|
14
|
+
coprocessor?: {
|
|
15
|
+
application?: DevFirmwareImageInfo | null;
|
|
16
|
+
bootloader?: DevFirmwareImageInfo | null;
|
|
17
|
+
bt_adv_name?: string | null;
|
|
18
|
+
bt_mac?: unknown;
|
|
19
|
+
} | null;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type ProtocolV1FeaturesCompat = PROTO.Features &
|
|
23
|
+
Partial<PROTO.OnekeyFeatures> & {
|
|
24
|
+
protocol_version?: number | null;
|
|
25
|
+
onekey_version?: string;
|
|
26
|
+
onekey_serial?: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const getImageVersion = (image?: DevFirmwareImageInfo | null) => image?.version ?? null;
|
|
30
|
+
|
|
31
|
+
const bytesToHex = (value: unknown): string | undefined => {
|
|
32
|
+
if (!value) return undefined;
|
|
33
|
+
if (typeof value === 'string') return value;
|
|
34
|
+
if (value instanceof Uint8Array) {
|
|
35
|
+
return Array.from(value)
|
|
36
|
+
.map(byte => byte.toString(16).padStart(2, '0'))
|
|
37
|
+
.join('');
|
|
38
|
+
}
|
|
39
|
+
if (Array.isArray(value)) {
|
|
40
|
+
return value.map(byte => Number(byte).toString(16).padStart(2, '0')).join('');
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const getImageBuildId = (image?: DevFirmwareImageInfo | null) => image?.build_id ?? undefined;
|
|
46
|
+
|
|
47
|
+
const getImageHash = (image?: DevFirmwareImageInfo | null) => bytesToHex(image?.hash);
|
|
48
|
+
|
|
49
|
+
const firstValue = <T>(...values: Array<T | null | undefined>) =>
|
|
50
|
+
values.find(value => value !== undefined && value !== null);
|
|
51
|
+
|
|
52
|
+
const firstMeaningfulVersion = (...versions: Array<string | null | undefined>) =>
|
|
53
|
+
versions.find(version => Boolean(version && version !== '0.0.0')) ?? null;
|
|
54
|
+
|
|
55
|
+
const versionFromParts = (major?: number | null, minor?: number | null, patch?: number | null) =>
|
|
56
|
+
[major, minor, patch].map(part => Number(part) || 0).join('.');
|
|
57
|
+
|
|
58
|
+
const getProtocolV1Mode = (features: ProtocolV1FeaturesCompat): Features['mode'] => {
|
|
59
|
+
if (features.bootloader_mode === true) return 'bootloader';
|
|
60
|
+
if (features.initialized === false) return 'notInitialized';
|
|
61
|
+
if (features.initialized === true) return 'normal';
|
|
62
|
+
return 'unknown';
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const getProtocolV1DeviceType = (features: ProtocolV1FeaturesCompat): Features['deviceType'] => {
|
|
66
|
+
const onekeyDeviceType = features.onekey_device_type as string | null | undefined;
|
|
67
|
+
switch (onekeyDeviceType) {
|
|
68
|
+
case 'CLASSIC':
|
|
69
|
+
return EDeviceType.Classic;
|
|
70
|
+
case 'CLASSIC1S':
|
|
71
|
+
return EDeviceType.Classic1s;
|
|
72
|
+
case 'MINI':
|
|
73
|
+
return EDeviceType.Mini;
|
|
74
|
+
case 'TOUCH':
|
|
75
|
+
return EDeviceType.Touch;
|
|
76
|
+
case 'PRO':
|
|
77
|
+
return EDeviceType.Pro;
|
|
78
|
+
case 'PRO2':
|
|
79
|
+
case 'pro2':
|
|
80
|
+
return EDeviceType.Pro2;
|
|
81
|
+
case 'PURE':
|
|
82
|
+
return EDeviceType.ClassicPure;
|
|
83
|
+
default:
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const serialNo = features.onekey_serial_no || features.onekey_serial || features.serial_no || '';
|
|
88
|
+
const prefix = serialNo.slice(0, 2).toLowerCase();
|
|
89
|
+
if (prefix === 'bi' || prefix === 'cl') return EDeviceType.Classic;
|
|
90
|
+
if (prefix === 'cp') return EDeviceType.ClassicPure;
|
|
91
|
+
if (prefix === 'mi') return EDeviceType.Mini;
|
|
92
|
+
if (prefix === 'tc') return EDeviceType.Touch;
|
|
93
|
+
if (prefix === 'pr') return EDeviceType.Pro;
|
|
94
|
+
if (prefix === 'p2') return EDeviceType.Pro2;
|
|
95
|
+
if (!serialNo && features.bootloader_mode === true && features.model === '1') {
|
|
96
|
+
return EDeviceType.Classic;
|
|
97
|
+
}
|
|
98
|
+
return EDeviceType.Unknown;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const getProtocolV1FirmwareType = (
|
|
102
|
+
features: ProtocolV1FeaturesCompat
|
|
103
|
+
): Features['firmwareType'] => {
|
|
104
|
+
if (features.fw_vendor === 'OneKey Bitcoin-only') return EFirmwareType.BitcoinOnly;
|
|
105
|
+
return EFirmwareType.Universal;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const getProtocolV1Label = (
|
|
109
|
+
features: ProtocolV1FeaturesCompat,
|
|
110
|
+
deviceType: Features['deviceType'],
|
|
111
|
+
bleName: string | null
|
|
112
|
+
) => {
|
|
113
|
+
if (features.label) return features.label;
|
|
114
|
+
if (bleName) return bleName;
|
|
115
|
+
if (deviceType === EDeviceType.Unknown) return null;
|
|
116
|
+
if (deviceType === EDeviceType.ClassicPure) return 'OneKey Classic 1S';
|
|
117
|
+
return `OneKey ${deviceType.charAt(0).toUpperCase()}${deviceType.slice(1)}`;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const buildProtocolV1FeaturesPayload = (
|
|
121
|
+
protocolV1Features: PROTO.Features,
|
|
122
|
+
previous?: Features
|
|
123
|
+
): Features => {
|
|
124
|
+
const features = protocolV1Features as ProtocolV1FeaturesCompat;
|
|
125
|
+
const firmwareVersion = firstMeaningfulVersion(
|
|
126
|
+
features.onekey_firmware_version,
|
|
127
|
+
features.onekey_version,
|
|
128
|
+
versionFromParts(features.major_version, features.minor_version, features.patch_version)
|
|
129
|
+
);
|
|
130
|
+
const bootloaderVersion = firstMeaningfulVersion(
|
|
131
|
+
features.onekey_boot_version,
|
|
132
|
+
features.bootloader_version,
|
|
133
|
+
features.bootloader_mode
|
|
134
|
+
? versionFromParts(features.major_version, features.minor_version, features.patch_version)
|
|
135
|
+
: null
|
|
136
|
+
);
|
|
137
|
+
const boardVersion = firstMeaningfulVersion(
|
|
138
|
+
features.onekey_board_version,
|
|
139
|
+
features.boardloader_version
|
|
140
|
+
);
|
|
141
|
+
const bleVersion = firstMeaningfulVersion(features.onekey_ble_version, features.ble_ver);
|
|
142
|
+
const serialNo = features.onekey_serial_no || features.onekey_serial || features.serial_no || '';
|
|
143
|
+
const bleName = features.onekey_ble_name || features.ble_name || null;
|
|
144
|
+
const deviceType = getProtocolV1DeviceType(features);
|
|
145
|
+
const sessionId = features.session_id ?? previous?.sessionId ?? null;
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
protocol: 'V1',
|
|
149
|
+
protocolVersion: features.protocol_version ?? previous?.protocolVersion ?? 1,
|
|
150
|
+
deviceType,
|
|
151
|
+
firmwareType: getProtocolV1FirmwareType(features),
|
|
152
|
+
model: features.model ?? null,
|
|
153
|
+
vendor: features.vendor ?? null,
|
|
154
|
+
deviceId: features.device_id ?? null,
|
|
155
|
+
serialNo,
|
|
156
|
+
label: getProtocolV1Label(features, deviceType, bleName),
|
|
157
|
+
bleName,
|
|
158
|
+
capabilities: features.capabilities ?? [],
|
|
159
|
+
mode: getProtocolV1Mode(features),
|
|
160
|
+
initialized: features.initialized ?? null,
|
|
161
|
+
bootloaderMode: features.bootloader_mode ?? null,
|
|
162
|
+
unlocked: features.unlocked ?? true,
|
|
163
|
+
firmwarePresent: features.firmware_present ?? null,
|
|
164
|
+
passphraseProtection: features.passphrase_protection ?? null,
|
|
165
|
+
pinProtection: features.pin_protection ?? null,
|
|
166
|
+
backupRequired: features.needs_backup ?? null,
|
|
167
|
+
noBackup: features.no_backup ?? null,
|
|
168
|
+
unfinishedBackup: features.unfinished_backup ?? null,
|
|
169
|
+
recoveryMode: features.recovery_mode ?? null,
|
|
170
|
+
language: features.language ?? null,
|
|
171
|
+
bleEnabled: features.ble_enable ?? null,
|
|
172
|
+
sdCardPresent: features.sd_card_present ?? null,
|
|
173
|
+
sdProtection: features.sd_protection ?? null,
|
|
174
|
+
wipeCodeProtection: features.wipe_code_protection ?? null,
|
|
175
|
+
passphraseAlwaysOnDevice: features.passphrase_always_on_device ?? null,
|
|
176
|
+
safetyChecks: features.safety_checks ?? null,
|
|
177
|
+
autoLockDelayMs: features.auto_lock_delay_ms ?? null,
|
|
178
|
+
displayRotation: features.display_rotation ?? null,
|
|
179
|
+
experimentalFeatures: features.experimental_features ?? null,
|
|
180
|
+
firmwareVersion,
|
|
181
|
+
bootloaderVersion,
|
|
182
|
+
boardVersion,
|
|
183
|
+
bleVersion,
|
|
184
|
+
se01Version: firstMeaningfulVersion(features.onekey_se01_version),
|
|
185
|
+
se02Version: firstMeaningfulVersion(features.onekey_se02_version),
|
|
186
|
+
se03Version: firstMeaningfulVersion(features.onekey_se03_version),
|
|
187
|
+
se04Version: firstMeaningfulVersion(features.onekey_se04_version),
|
|
188
|
+
se01BootVersion: firstMeaningfulVersion(features.onekey_se01_boot_version),
|
|
189
|
+
se02BootVersion: firstMeaningfulVersion(features.onekey_se02_boot_version),
|
|
190
|
+
se03BootVersion: firstMeaningfulVersion(features.onekey_se03_boot_version),
|
|
191
|
+
se04BootVersion: firstMeaningfulVersion(features.onekey_se04_boot_version),
|
|
192
|
+
seVersion: features.se_ver ?? null,
|
|
193
|
+
verify: {
|
|
194
|
+
firmwareBuildId: features.onekey_firmware_build_id,
|
|
195
|
+
firmwareHash: features.onekey_firmware_hash,
|
|
196
|
+
bootloaderBuildId: features.onekey_boot_build_id,
|
|
197
|
+
bootloaderHash: features.onekey_boot_hash,
|
|
198
|
+
boardBuildId: features.onekey_board_build_id,
|
|
199
|
+
boardHash: features.onekey_board_hash,
|
|
200
|
+
bleBuildId: features.onekey_ble_build_id,
|
|
201
|
+
bleHash: features.onekey_ble_hash,
|
|
202
|
+
se01BuildId: features.onekey_se01_build_id,
|
|
203
|
+
se01Hash: features.onekey_se01_hash,
|
|
204
|
+
se02BuildId: features.onekey_se02_build_id,
|
|
205
|
+
se02Hash: features.onekey_se02_hash,
|
|
206
|
+
se03BuildId: features.onekey_se03_build_id,
|
|
207
|
+
se03Hash: features.onekey_se03_hash,
|
|
208
|
+
se04BuildId: features.onekey_se04_build_id,
|
|
209
|
+
se04Hash: features.onekey_se04_hash,
|
|
210
|
+
se01BootBuildId: features.onekey_se01_boot_build_id,
|
|
211
|
+
se01BootHash: features.onekey_se01_boot_hash,
|
|
212
|
+
se02BootBuildId: features.onekey_se02_boot_build_id,
|
|
213
|
+
se02BootHash: features.onekey_se02_boot_hash,
|
|
214
|
+
se03BootBuildId: features.onekey_se03_boot_build_id,
|
|
215
|
+
se03BootHash: features.onekey_se03_boot_hash,
|
|
216
|
+
se04BootBuildId: features.onekey_se04_boot_build_id,
|
|
217
|
+
se04BootHash: features.onekey_se04_boot_hash,
|
|
218
|
+
},
|
|
219
|
+
sessionId,
|
|
220
|
+
raw: {
|
|
221
|
+
protocolV1Features: protocolV1Features,
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Protocol V2 的结构化 `Features` 构建器。
|
|
228
|
+
*
|
|
229
|
+
* 这是 Device 内部唯一缓存状态。字段只来自 DevGetDeviceInfo 或前一次 features
|
|
230
|
+
* 缓存的同名字段级合并;不存在协议等价语义的字段保持 null/空值,不再通过
|
|
231
|
+
* DeviceProfile 或 transport path 做身份兜底。
|
|
232
|
+
*/
|
|
233
|
+
export const buildProtocolV2FeaturesPayload = (
|
|
234
|
+
deviceInfo?: ProtocolV2DeviceInfo,
|
|
235
|
+
previous?: Features
|
|
236
|
+
): Features => {
|
|
237
|
+
const info = deviceInfo as ProtocolV2DeviceInfoCompat | undefined;
|
|
238
|
+
const fwApplication = firstValue(info?.fw?.application, info?.fw?.app);
|
|
239
|
+
const fwBootloader = firstValue(info?.fw?.bootloader, info?.fw?.boot);
|
|
240
|
+
const fwBoard = firstValue(info?.fw?.application_data, info?.fw?.board);
|
|
241
|
+
const bleApplication = firstValue(info?.coprocessor?.application, info?.bt?.app);
|
|
242
|
+
|
|
243
|
+
const firmwareVersion = firstMeaningfulVersion(
|
|
244
|
+
getImageVersion(fwApplication),
|
|
245
|
+
previous?.firmwareVersion
|
|
246
|
+
);
|
|
247
|
+
const bootloaderVersion = firstMeaningfulVersion(
|
|
248
|
+
getImageVersion(fwBootloader),
|
|
249
|
+
previous?.bootloaderVersion
|
|
250
|
+
);
|
|
251
|
+
const boardVersion = firstMeaningfulVersion(getImageVersion(fwBoard), previous?.boardVersion);
|
|
252
|
+
const bleVersion = firstMeaningfulVersion(getImageVersion(bleApplication), previous?.bleVersion);
|
|
253
|
+
const deviceId = firstValue(info?.hw?.device_id, previous?.deviceId) ?? null;
|
|
254
|
+
const serialNo = firstValue(info?.hw?.serial_no, previous?.serialNo) ?? '';
|
|
255
|
+
const label = firstValue(deviceInfo?.status?.label, previous?.label) ?? null;
|
|
256
|
+
const bleName = firstValue(info?.coprocessor?.bt_adv_name, info?.bt?.adv_name, previous?.bleName);
|
|
257
|
+
const initialized = firstValue(deviceInfo?.status?.init_states, previous?.initialized) ?? null;
|
|
258
|
+
const passphraseProtection =
|
|
259
|
+
firstValue(deviceInfo?.status?.passphrase_protection, previous?.passphraseProtection) ?? null;
|
|
260
|
+
const language = firstValue(deviceInfo?.status?.language, previous?.language) ?? null;
|
|
261
|
+
const backupRequired =
|
|
262
|
+
firstValue(deviceInfo?.status?.backup_required, previous?.backupRequired) ?? null;
|
|
263
|
+
const bleEnabled = firstValue(deviceInfo?.status?.bt_enable, previous?.bleEnabled);
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
protocol: 'V2',
|
|
267
|
+
protocolVersion: deviceInfo?.protocol_version ?? previous?.protocolVersion ?? null,
|
|
268
|
+
deviceType: EDeviceType.Pro2,
|
|
269
|
+
firmwareType: previous?.firmwareType ?? EFirmwareType.Universal,
|
|
270
|
+
model: 'pro2',
|
|
271
|
+
vendor: 'onekey.so',
|
|
272
|
+
deviceId,
|
|
273
|
+
serialNo,
|
|
274
|
+
label,
|
|
275
|
+
bleName: bleName ?? null,
|
|
276
|
+
capabilities: [],
|
|
277
|
+
mode: initialized === false ? 'notInitialized' : initialized === true ? 'normal' : 'unknown',
|
|
278
|
+
initialized,
|
|
279
|
+
bootloaderMode: false,
|
|
280
|
+
unlocked: previous?.unlocked ?? null,
|
|
281
|
+
firmwarePresent: previous?.firmwarePresent ?? null,
|
|
282
|
+
passphraseProtection,
|
|
283
|
+
pinProtection: null,
|
|
284
|
+
backupRequired,
|
|
285
|
+
noBackup: null,
|
|
286
|
+
unfinishedBackup: null,
|
|
287
|
+
recoveryMode: null,
|
|
288
|
+
language,
|
|
289
|
+
bleEnabled: bleEnabled ?? null,
|
|
290
|
+
sdCardPresent: null,
|
|
291
|
+
sdProtection: null,
|
|
292
|
+
wipeCodeProtection: null,
|
|
293
|
+
passphraseAlwaysOnDevice: null,
|
|
294
|
+
safetyChecks: null,
|
|
295
|
+
autoLockDelayMs: null,
|
|
296
|
+
displayRotation: null,
|
|
297
|
+
experimentalFeatures: null,
|
|
298
|
+
firmwareVersion,
|
|
299
|
+
bootloaderVersion,
|
|
300
|
+
boardVersion,
|
|
301
|
+
bleVersion,
|
|
302
|
+
se01Version: firstMeaningfulVersion(
|
|
303
|
+
getImageVersion(deviceInfo?.se1?.app),
|
|
304
|
+
previous?.se01Version
|
|
305
|
+
),
|
|
306
|
+
se02Version: firstMeaningfulVersion(
|
|
307
|
+
getImageVersion(deviceInfo?.se2?.app),
|
|
308
|
+
previous?.se02Version
|
|
309
|
+
),
|
|
310
|
+
se03Version: firstMeaningfulVersion(
|
|
311
|
+
getImageVersion(deviceInfo?.se3?.app),
|
|
312
|
+
previous?.se03Version
|
|
313
|
+
),
|
|
314
|
+
se04Version: firstMeaningfulVersion(
|
|
315
|
+
getImageVersion(deviceInfo?.se4?.app),
|
|
316
|
+
previous?.se04Version
|
|
317
|
+
),
|
|
318
|
+
se01BootVersion: firstMeaningfulVersion(
|
|
319
|
+
getImageVersion(deviceInfo?.se1?.boot),
|
|
320
|
+
previous?.se01BootVersion
|
|
321
|
+
),
|
|
322
|
+
se02BootVersion: firstMeaningfulVersion(
|
|
323
|
+
getImageVersion(deviceInfo?.se2?.boot),
|
|
324
|
+
previous?.se02BootVersion
|
|
325
|
+
),
|
|
326
|
+
se03BootVersion: firstMeaningfulVersion(
|
|
327
|
+
getImageVersion(deviceInfo?.se3?.boot),
|
|
328
|
+
previous?.se03BootVersion
|
|
329
|
+
),
|
|
330
|
+
se04BootVersion: firstMeaningfulVersion(
|
|
331
|
+
getImageVersion(deviceInfo?.se4?.boot),
|
|
332
|
+
previous?.se04BootVersion
|
|
333
|
+
),
|
|
334
|
+
seVersion: previous?.seVersion ?? null,
|
|
335
|
+
verify: {
|
|
336
|
+
firmwareBuildId: getImageBuildId(fwApplication) ?? previous?.verify?.firmwareBuildId,
|
|
337
|
+
firmwareHash: getImageHash(fwApplication) ?? previous?.verify?.firmwareHash,
|
|
338
|
+
bootloaderBuildId: getImageBuildId(fwBootloader) ?? previous?.verify?.bootloaderBuildId,
|
|
339
|
+
bootloaderHash: getImageHash(fwBootloader) ?? previous?.verify?.bootloaderHash,
|
|
340
|
+
boardBuildId: getImageBuildId(fwBoard) ?? previous?.verify?.boardBuildId,
|
|
341
|
+
boardHash: getImageHash(fwBoard) ?? previous?.verify?.boardHash,
|
|
342
|
+
bleBuildId: getImageBuildId(bleApplication) ?? previous?.verify?.bleBuildId,
|
|
343
|
+
bleHash: getImageHash(bleApplication) ?? previous?.verify?.bleHash,
|
|
344
|
+
se01BuildId: getImageBuildId(deviceInfo?.se1?.app) ?? previous?.verify?.se01BuildId,
|
|
345
|
+
se01Hash: getImageHash(deviceInfo?.se1?.app) ?? previous?.verify?.se01Hash,
|
|
346
|
+
se02BuildId: getImageBuildId(deviceInfo?.se2?.app) ?? previous?.verify?.se02BuildId,
|
|
347
|
+
se02Hash: getImageHash(deviceInfo?.se2?.app) ?? previous?.verify?.se02Hash,
|
|
348
|
+
se03BuildId: getImageBuildId(deviceInfo?.se3?.app) ?? previous?.verify?.se03BuildId,
|
|
349
|
+
se03Hash: getImageHash(deviceInfo?.se3?.app) ?? previous?.verify?.se03Hash,
|
|
350
|
+
se04BuildId: getImageBuildId(deviceInfo?.se4?.app) ?? previous?.verify?.se04BuildId,
|
|
351
|
+
se04Hash: getImageHash(deviceInfo?.se4?.app) ?? previous?.verify?.se04Hash,
|
|
352
|
+
se01BootBuildId: getImageBuildId(deviceInfo?.se1?.boot) ?? previous?.verify?.se01BootBuildId,
|
|
353
|
+
se01BootHash: getImageHash(deviceInfo?.se1?.boot) ?? previous?.verify?.se01BootHash,
|
|
354
|
+
se02BootBuildId: getImageBuildId(deviceInfo?.se2?.boot) ?? previous?.verify?.se02BootBuildId,
|
|
355
|
+
se02BootHash: getImageHash(deviceInfo?.se2?.boot) ?? previous?.verify?.se02BootHash,
|
|
356
|
+
se03BootBuildId: getImageBuildId(deviceInfo?.se3?.boot) ?? previous?.verify?.se03BootBuildId,
|
|
357
|
+
se03BootHash: getImageHash(deviceInfo?.se3?.boot) ?? previous?.verify?.se03BootHash,
|
|
358
|
+
se04BootBuildId: getImageBuildId(deviceInfo?.se4?.boot) ?? previous?.verify?.se04BootBuildId,
|
|
359
|
+
se04BootHash: getImageHash(deviceInfo?.se4?.boot) ?? previous?.verify?.se04BootHash,
|
|
360
|
+
},
|
|
361
|
+
sessionId: previous?.sessionId ?? null,
|
|
362
|
+
passphraseState: previous?.passphraseState,
|
|
363
|
+
unlockedAttachPin: previous?.unlockedAttachPin,
|
|
364
|
+
raw: {
|
|
365
|
+
protocolV2DeviceInfo: deviceInfo,
|
|
366
|
+
},
|
|
367
|
+
};
|
|
368
|
+
};
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getDeviceBLEFirmwareVersion,
|
|
5
|
+
getDeviceBoardloaderVersion,
|
|
6
|
+
getDeviceBootloaderVersion,
|
|
7
|
+
getDeviceFirmwareVersion,
|
|
8
|
+
} from '../utils/deviceVersionUtils';
|
|
9
|
+
import {
|
|
10
|
+
getDeviceBleName,
|
|
11
|
+
getDeviceLabel,
|
|
12
|
+
getDeviceType,
|
|
13
|
+
getDeviceUUID,
|
|
14
|
+
getFirmwareType,
|
|
15
|
+
} from '../utils/deviceInfoUtils';
|
|
16
|
+
|
|
17
|
+
import type {
|
|
18
|
+
DeviceInfoProtocol,
|
|
19
|
+
DeviceInfoSource,
|
|
20
|
+
DeviceInfoStatus,
|
|
21
|
+
DeviceProfile,
|
|
22
|
+
DeviceProfileRaw,
|
|
23
|
+
DeviceProfileVerify,
|
|
24
|
+
DeviceProfileVersions,
|
|
25
|
+
GetDeviceInfoParams,
|
|
26
|
+
} from '../types/api/getDeviceInfo';
|
|
27
|
+
import type { Features, OnekeyFeatures } from '../types';
|
|
28
|
+
import type { DevFirmwareImageInfo, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
|
|
29
|
+
|
|
30
|
+
type BuildProtocolV1ProfileParams = {
|
|
31
|
+
protocol?: DeviceInfoProtocol;
|
|
32
|
+
features?: Features;
|
|
33
|
+
protocolV1OneKeyFeatures?: OnekeyFeatures;
|
|
34
|
+
sources?: DeviceInfoSource[];
|
|
35
|
+
scope?: GetDeviceInfoParams['scope'];
|
|
36
|
+
includeRaw?: boolean;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type BuildProtocolV2ProfileParams = {
|
|
40
|
+
deviceInfo?: ProtocolV2DeviceInfo;
|
|
41
|
+
sources?: DeviceInfoSource[];
|
|
42
|
+
scope?: GetDeviceInfoParams['scope'];
|
|
43
|
+
includeRaw?: boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const isMeaningfulVersion = (version?: string | null) => Boolean(version && version !== '0.0.0');
|
|
47
|
+
|
|
48
|
+
const firstMeaningfulVersion = (...versions: Array<string | null | undefined>) =>
|
|
49
|
+
versions.find(isMeaningfulVersion) ?? null;
|
|
50
|
+
|
|
51
|
+
const versionArrayToString = (version?: Array<number | string | null> | null) => {
|
|
52
|
+
if (!version || version.length === 0) return null;
|
|
53
|
+
const value = version.join('.');
|
|
54
|
+
return isMeaningfulVersion(value) ? value : null;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const bytesToHex = (value: unknown): string | undefined => {
|
|
58
|
+
if (!value) return undefined;
|
|
59
|
+
if (typeof value === 'string') return value;
|
|
60
|
+
if (value instanceof Uint8Array) {
|
|
61
|
+
return Array.from(value)
|
|
62
|
+
.map(byte => byte.toString(16).padStart(2, '0'))
|
|
63
|
+
.join('');
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
return value.map(byte => Number(byte).toString(16).padStart(2, '0')).join('');
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const getImageVersion = (image?: DevFirmwareImageInfo | null) => image?.version ?? null;
|
|
72
|
+
|
|
73
|
+
const getImageBuildId = (image?: DevFirmwareImageInfo | null) => image?.build_id ?? undefined;
|
|
74
|
+
|
|
75
|
+
const getImageHash = (image?: DevFirmwareImageInfo | null) => bytesToHex(image?.hash);
|
|
76
|
+
|
|
77
|
+
const shouldIncludeVerify = (scope?: GetDeviceInfoParams['scope']) =>
|
|
78
|
+
scope === 'verify' || scope === 'full';
|
|
79
|
+
|
|
80
|
+
const getDeviceMode = (features?: Features): DeviceInfoStatus['mode'] => {
|
|
81
|
+
if (!features) return 'unknown';
|
|
82
|
+
if (features.bootloaderMode === true) return 'bootloader';
|
|
83
|
+
if (features.initialized === false) return 'notInitialized';
|
|
84
|
+
if (features.initialized === true) return 'normal';
|
|
85
|
+
return 'unknown';
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const getProtocolV2Mode = (deviceInfo?: ProtocolV2DeviceInfo): DeviceInfoStatus['mode'] => {
|
|
89
|
+
const initialized = deviceInfo?.status?.init_states;
|
|
90
|
+
if (initialized === false) return 'notInitialized';
|
|
91
|
+
if (initialized === true) return 'normal';
|
|
92
|
+
return 'unknown';
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const normalizeV1Versions = (
|
|
96
|
+
features?: Features,
|
|
97
|
+
protocolV1OneKeyFeatures?: OnekeyFeatures
|
|
98
|
+
): DeviceProfileVersions => ({
|
|
99
|
+
firmware: firstMeaningfulVersion(
|
|
100
|
+
protocolV1OneKeyFeatures?.onekey_firmware_version,
|
|
101
|
+
versionArrayToString(getDeviceFirmwareVersion(features))
|
|
102
|
+
),
|
|
103
|
+
bootloader: firstMeaningfulVersion(
|
|
104
|
+
protocolV1OneKeyFeatures?.onekey_boot_version,
|
|
105
|
+
versionArrayToString(getDeviceBootloaderVersion(features))
|
|
106
|
+
),
|
|
107
|
+
board: firstMeaningfulVersion(
|
|
108
|
+
protocolV1OneKeyFeatures?.onekey_board_version,
|
|
109
|
+
versionArrayToString(features ? getDeviceBoardloaderVersion(features) : undefined)
|
|
110
|
+
),
|
|
111
|
+
ble: firstMeaningfulVersion(
|
|
112
|
+
protocolV1OneKeyFeatures?.onekey_ble_version,
|
|
113
|
+
features?.bleVersion,
|
|
114
|
+
versionArrayToString(features ? getDeviceBLEFirmwareVersion(features) : undefined)
|
|
115
|
+
),
|
|
116
|
+
se01: firstMeaningfulVersion(
|
|
117
|
+
protocolV1OneKeyFeatures?.onekey_se01_version,
|
|
118
|
+
features?.se01Version
|
|
119
|
+
),
|
|
120
|
+
se02: firstMeaningfulVersion(
|
|
121
|
+
protocolV1OneKeyFeatures?.onekey_se02_version,
|
|
122
|
+
features?.se02Version
|
|
123
|
+
),
|
|
124
|
+
se03: firstMeaningfulVersion(
|
|
125
|
+
protocolV1OneKeyFeatures?.onekey_se03_version,
|
|
126
|
+
features?.se03Version
|
|
127
|
+
),
|
|
128
|
+
se04: firstMeaningfulVersion(
|
|
129
|
+
protocolV1OneKeyFeatures?.onekey_se04_version,
|
|
130
|
+
features?.se04Version
|
|
131
|
+
),
|
|
132
|
+
se01Boot: firstMeaningfulVersion(
|
|
133
|
+
protocolV1OneKeyFeatures?.onekey_se01_boot_version,
|
|
134
|
+
features?.se01BootVersion
|
|
135
|
+
),
|
|
136
|
+
se02Boot: firstMeaningfulVersion(
|
|
137
|
+
protocolV1OneKeyFeatures?.onekey_se02_boot_version,
|
|
138
|
+
features?.se02BootVersion
|
|
139
|
+
),
|
|
140
|
+
se03Boot: firstMeaningfulVersion(
|
|
141
|
+
protocolV1OneKeyFeatures?.onekey_se03_boot_version,
|
|
142
|
+
features?.se03BootVersion
|
|
143
|
+
),
|
|
144
|
+
se04Boot: firstMeaningfulVersion(
|
|
145
|
+
protocolV1OneKeyFeatures?.onekey_se04_boot_version,
|
|
146
|
+
features?.se04BootVersion
|
|
147
|
+
),
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const normalizeV2Versions = (deviceInfo?: ProtocolV2DeviceInfo): DeviceProfileVersions => ({
|
|
151
|
+
firmware: firstMeaningfulVersion(getImageVersion(deviceInfo?.fw?.app)),
|
|
152
|
+
bootloader: firstMeaningfulVersion(getImageVersion(deviceInfo?.fw?.boot)),
|
|
153
|
+
board: firstMeaningfulVersion(getImageVersion(deviceInfo?.fw?.board)),
|
|
154
|
+
ble: firstMeaningfulVersion(getImageVersion(deviceInfo?.bt?.app)),
|
|
155
|
+
se01: firstMeaningfulVersion(getImageVersion(deviceInfo?.se1?.app)),
|
|
156
|
+
se02: firstMeaningfulVersion(getImageVersion(deviceInfo?.se2?.app)),
|
|
157
|
+
se03: firstMeaningfulVersion(getImageVersion(deviceInfo?.se3?.app)),
|
|
158
|
+
se04: firstMeaningfulVersion(getImageVersion(deviceInfo?.se4?.app)),
|
|
159
|
+
se01Boot: firstMeaningfulVersion(getImageVersion(deviceInfo?.se1?.boot)),
|
|
160
|
+
se02Boot: firstMeaningfulVersion(getImageVersion(deviceInfo?.se2?.boot)),
|
|
161
|
+
se03Boot: firstMeaningfulVersion(getImageVersion(deviceInfo?.se3?.boot)),
|
|
162
|
+
se04Boot: firstMeaningfulVersion(getImageVersion(deviceInfo?.se4?.boot)),
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// V2 状态由 normalizeV2Status 处理,这里只服务 buildProfileFromProtocolV1 的 V1 路径。
|
|
166
|
+
const normalizeV1Status = (features?: Features): DeviceInfoStatus => ({
|
|
167
|
+
mode: getDeviceMode(features),
|
|
168
|
+
initialized: features?.initialized ?? null,
|
|
169
|
+
bootloaderMode: features?.bootloaderMode ?? null,
|
|
170
|
+
unlocked: features?.unlocked ?? null,
|
|
171
|
+
passphraseProtection: features?.passphraseProtection ?? null,
|
|
172
|
+
backupRequired: features?.backupRequired ?? null,
|
|
173
|
+
noBackup: features?.noBackup ?? null,
|
|
174
|
+
language: features?.language ?? null,
|
|
175
|
+
bleEnabled: features?.bleEnabled ?? null,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
const normalizeV2Status = (deviceInfo?: ProtocolV2DeviceInfo): DeviceInfoStatus => ({
|
|
179
|
+
mode: getProtocolV2Mode(deviceInfo),
|
|
180
|
+
initialized: deviceInfo?.status?.init_states ?? null,
|
|
181
|
+
bootloaderMode: false,
|
|
182
|
+
unlocked: null,
|
|
183
|
+
passphraseProtection: deviceInfo?.status?.passphrase_protection ?? null,
|
|
184
|
+
backupRequired: deviceInfo?.status?.backup_required ?? null,
|
|
185
|
+
noBackup: null,
|
|
186
|
+
language: deviceInfo?.status?.language ?? null,
|
|
187
|
+
bleEnabled: deviceInfo?.status?.bt_enable ?? null,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const normalizeV1Verify = (
|
|
191
|
+
features?: Features,
|
|
192
|
+
protocolV1OneKeyFeatures?: OnekeyFeatures
|
|
193
|
+
): DeviceProfileVerify => ({
|
|
194
|
+
firmwareBuildId:
|
|
195
|
+
protocolV1OneKeyFeatures?.onekey_firmware_build_id ?? features?.verify?.firmwareBuildId,
|
|
196
|
+
firmwareHash: protocolV1OneKeyFeatures?.onekey_firmware_hash ?? features?.verify?.firmwareHash,
|
|
197
|
+
bootloaderBuildId:
|
|
198
|
+
protocolV1OneKeyFeatures?.onekey_boot_build_id ?? features?.verify?.bootloaderBuildId,
|
|
199
|
+
bootloaderHash: protocolV1OneKeyFeatures?.onekey_boot_hash ?? features?.verify?.bootloaderHash,
|
|
200
|
+
boardBuildId: protocolV1OneKeyFeatures?.onekey_board_build_id ?? features?.verify?.boardBuildId,
|
|
201
|
+
boardHash: protocolV1OneKeyFeatures?.onekey_board_hash ?? features?.verify?.boardHash,
|
|
202
|
+
bleBuildId: protocolV1OneKeyFeatures?.onekey_ble_build_id ?? features?.verify?.bleBuildId,
|
|
203
|
+
bleHash: protocolV1OneKeyFeatures?.onekey_ble_hash ?? features?.verify?.bleHash,
|
|
204
|
+
se01BuildId: protocolV1OneKeyFeatures?.onekey_se01_build_id ?? features?.verify?.se01BuildId,
|
|
205
|
+
se01Hash: protocolV1OneKeyFeatures?.onekey_se01_hash ?? features?.verify?.se01Hash,
|
|
206
|
+
se02BuildId: protocolV1OneKeyFeatures?.onekey_se02_build_id ?? features?.verify?.se02BuildId,
|
|
207
|
+
se02Hash: protocolV1OneKeyFeatures?.onekey_se02_hash ?? features?.verify?.se02Hash,
|
|
208
|
+
se03BuildId: protocolV1OneKeyFeatures?.onekey_se03_build_id ?? features?.verify?.se03BuildId,
|
|
209
|
+
se03Hash: protocolV1OneKeyFeatures?.onekey_se03_hash ?? features?.verify?.se03Hash,
|
|
210
|
+
se04BuildId: protocolV1OneKeyFeatures?.onekey_se04_build_id ?? features?.verify?.se04BuildId,
|
|
211
|
+
se04Hash: protocolV1OneKeyFeatures?.onekey_se04_hash ?? features?.verify?.se04Hash,
|
|
212
|
+
se01BootBuildId:
|
|
213
|
+
protocolV1OneKeyFeatures?.onekey_se01_boot_build_id ?? features?.verify?.se01BootBuildId,
|
|
214
|
+
se01BootHash: protocolV1OneKeyFeatures?.onekey_se01_boot_hash ?? features?.verify?.se01BootHash,
|
|
215
|
+
se02BootBuildId:
|
|
216
|
+
protocolV1OneKeyFeatures?.onekey_se02_boot_build_id ?? features?.verify?.se02BootBuildId,
|
|
217
|
+
se02BootHash: protocolV1OneKeyFeatures?.onekey_se02_boot_hash ?? features?.verify?.se02BootHash,
|
|
218
|
+
se03BootBuildId:
|
|
219
|
+
protocolV1OneKeyFeatures?.onekey_se03_boot_build_id ?? features?.verify?.se03BootBuildId,
|
|
220
|
+
se03BootHash: protocolV1OneKeyFeatures?.onekey_se03_boot_hash ?? features?.verify?.se03BootHash,
|
|
221
|
+
se04BootBuildId:
|
|
222
|
+
protocolV1OneKeyFeatures?.onekey_se04_boot_build_id ?? features?.verify?.se04BootBuildId,
|
|
223
|
+
se04BootHash: protocolV1OneKeyFeatures?.onekey_se04_boot_hash ?? features?.verify?.se04BootHash,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const normalizeV2Verify = (deviceInfo?: ProtocolV2DeviceInfo): DeviceProfileVerify => ({
|
|
227
|
+
firmwareBuildId: getImageBuildId(deviceInfo?.fw?.app),
|
|
228
|
+
firmwareHash: getImageHash(deviceInfo?.fw?.app),
|
|
229
|
+
bootloaderBuildId: getImageBuildId(deviceInfo?.fw?.boot),
|
|
230
|
+
bootloaderHash: getImageHash(deviceInfo?.fw?.boot),
|
|
231
|
+
boardBuildId: getImageBuildId(deviceInfo?.fw?.board),
|
|
232
|
+
boardHash: getImageHash(deviceInfo?.fw?.board),
|
|
233
|
+
bleBuildId: getImageBuildId(deviceInfo?.bt?.app),
|
|
234
|
+
bleHash: getImageHash(deviceInfo?.bt?.app),
|
|
235
|
+
se01BuildId: getImageBuildId(deviceInfo?.se1?.app),
|
|
236
|
+
se01Hash: getImageHash(deviceInfo?.se1?.app),
|
|
237
|
+
se02BuildId: getImageBuildId(deviceInfo?.se2?.app),
|
|
238
|
+
se02Hash: getImageHash(deviceInfo?.se2?.app),
|
|
239
|
+
se03BuildId: getImageBuildId(deviceInfo?.se3?.app),
|
|
240
|
+
se03Hash: getImageHash(deviceInfo?.se3?.app),
|
|
241
|
+
se04BuildId: getImageBuildId(deviceInfo?.se4?.app),
|
|
242
|
+
se04Hash: getImageHash(deviceInfo?.se4?.app),
|
|
243
|
+
se01BootBuildId: getImageBuildId(deviceInfo?.se1?.boot),
|
|
244
|
+
se01BootHash: getImageHash(deviceInfo?.se1?.boot),
|
|
245
|
+
se02BootBuildId: getImageBuildId(deviceInfo?.se2?.boot),
|
|
246
|
+
se02BootHash: getImageHash(deviceInfo?.se2?.boot),
|
|
247
|
+
se03BootBuildId: getImageBuildId(deviceInfo?.se3?.boot),
|
|
248
|
+
se03BootHash: getImageHash(deviceInfo?.se3?.boot),
|
|
249
|
+
se04BootBuildId: getImageBuildId(deviceInfo?.se4?.boot),
|
|
250
|
+
se04BootHash: getImageHash(deviceInfo?.se4?.boot),
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
const normalizeRaw = ({
|
|
254
|
+
features,
|
|
255
|
+
protocolV1OneKeyFeatures,
|
|
256
|
+
protocolV2DeviceInfo,
|
|
257
|
+
}: {
|
|
258
|
+
features?: Features;
|
|
259
|
+
protocolV1OneKeyFeatures?: OnekeyFeatures;
|
|
260
|
+
protocolV2DeviceInfo?: ProtocolV2DeviceInfo;
|
|
261
|
+
}): DeviceProfileRaw => ({
|
|
262
|
+
...(features ? { features } : {}),
|
|
263
|
+
...(protocolV1OneKeyFeatures ? { protocolV1OneKeyFeatures } : {}),
|
|
264
|
+
...(protocolV2DeviceInfo ? { protocolV2DeviceInfo } : {}),
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
export function buildProfileFromProtocolV1({
|
|
268
|
+
protocol = 'V1',
|
|
269
|
+
features,
|
|
270
|
+
protocolV1OneKeyFeatures,
|
|
271
|
+
sources = ['features'],
|
|
272
|
+
scope = 'basic',
|
|
273
|
+
includeRaw = false,
|
|
274
|
+
}: BuildProtocolV1ProfileParams): DeviceProfile {
|
|
275
|
+
const sourceFeatures = features;
|
|
276
|
+
const verify = normalizeV1Verify(sourceFeatures, protocolV1OneKeyFeatures);
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
protocol,
|
|
280
|
+
sources,
|
|
281
|
+
deviceType: getDeviceType(sourceFeatures),
|
|
282
|
+
firmwareType: getFirmwareType(sourceFeatures),
|
|
283
|
+
deviceId: sourceFeatures?.deviceId || (sourceFeatures ? getDeviceUUID(sourceFeatures) : ''),
|
|
284
|
+
serialNo: sourceFeatures ? getDeviceUUID(sourceFeatures) : '',
|
|
285
|
+
label: getDeviceLabel(sourceFeatures),
|
|
286
|
+
bleName: getDeviceBleName(sourceFeatures),
|
|
287
|
+
status: normalizeV1Status(sourceFeatures),
|
|
288
|
+
versions: normalizeV1Versions(sourceFeatures, protocolV1OneKeyFeatures),
|
|
289
|
+
...(shouldIncludeVerify(scope) ? { verify } : {}),
|
|
290
|
+
...(includeRaw
|
|
291
|
+
? {
|
|
292
|
+
raw: normalizeRaw({
|
|
293
|
+
features,
|
|
294
|
+
protocolV1OneKeyFeatures,
|
|
295
|
+
}),
|
|
296
|
+
}
|
|
297
|
+
: {}),
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export function buildProfileFromProtocolV2({
|
|
302
|
+
deviceInfo,
|
|
303
|
+
sources = ['deviceInfo'],
|
|
304
|
+
scope = 'basic',
|
|
305
|
+
includeRaw = false,
|
|
306
|
+
}: BuildProtocolV2ProfileParams): DeviceProfile {
|
|
307
|
+
const deviceId = deviceInfo?.hw?.device_id || '';
|
|
308
|
+
const serialNo = deviceInfo?.hw?.serial_no || '';
|
|
309
|
+
const label = deviceInfo?.status?.label ?? null;
|
|
310
|
+
const bleName = deviceInfo?.bt?.adv_name ?? null;
|
|
311
|
+
const verify = normalizeV2Verify(deviceInfo);
|
|
312
|
+
|
|
313
|
+
return {
|
|
314
|
+
protocol: 'V2',
|
|
315
|
+
sources,
|
|
316
|
+
deviceType: EDeviceType.Pro2,
|
|
317
|
+
firmwareType: EFirmwareType.Universal,
|
|
318
|
+
deviceId,
|
|
319
|
+
serialNo,
|
|
320
|
+
label,
|
|
321
|
+
bleName,
|
|
322
|
+
status: normalizeV2Status(deviceInfo),
|
|
323
|
+
versions: normalizeV2Versions(deviceInfo),
|
|
324
|
+
...(shouldIncludeVerify(scope) ? { verify } : {}),
|
|
325
|
+
...(includeRaw
|
|
326
|
+
? {
|
|
327
|
+
raw: normalizeRaw({
|
|
328
|
+
protocolV2DeviceInfo: deviceInfo,
|
|
329
|
+
}),
|
|
330
|
+
}
|
|
331
|
+
: {}),
|
|
332
|
+
};
|
|
333
|
+
}
|