@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,820 @@
|
|
|
1
|
+
import { ERRORS, HardwareError, HardwareErrorCode, wait } from '@onekeyfe/hd-shared';
|
|
2
|
+
import {
|
|
3
|
+
DevRebootType,
|
|
4
|
+
PROTOCOL_V2_BLE_FILE_CHUNK_SIZE,
|
|
5
|
+
PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE,
|
|
6
|
+
} from '@onekeyfe/hd-transport';
|
|
7
|
+
|
|
8
|
+
import { FirmwareUpdateTipMessage, UI_REQUEST } from '../events/ui-request';
|
|
9
|
+
import { validateParams } from './helpers/paramsValidator';
|
|
10
|
+
import {
|
|
11
|
+
LoggerNames,
|
|
12
|
+
getDeviceBLEFirmwareVersion,
|
|
13
|
+
getDeviceBootloaderVersion,
|
|
14
|
+
getDeviceFirmwareVersion,
|
|
15
|
+
getFirmwareType,
|
|
16
|
+
getLogger,
|
|
17
|
+
} from '../utils';
|
|
18
|
+
import { getBinary, getSysResourceBinary } from './firmware/getBinary';
|
|
19
|
+
import { DataManager } from '../data-manager';
|
|
20
|
+
import { FirmwareUpdateBaseMethod } from './firmware/FirmwareUpdateBaseMethod';
|
|
21
|
+
import { DevicePool } from '../device/DevicePool';
|
|
22
|
+
import {
|
|
23
|
+
PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
|
|
24
|
+
ProtocolV2FirmwareTargetType,
|
|
25
|
+
protocolV2FileNameToTargetId,
|
|
26
|
+
} from '../protocols/protocol-v2';
|
|
27
|
+
import { requestProtocolV2DeviceInfo } from '../protocols/protocol-v2/features';
|
|
28
|
+
import {
|
|
29
|
+
PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES,
|
|
30
|
+
getProtocolV2UnknownErrorText,
|
|
31
|
+
isProtocolV2DeviceDisconnectedError,
|
|
32
|
+
} from './protocol-v2/helpers';
|
|
33
|
+
|
|
34
|
+
import type { FirmwareUpdateV4Params } from '../types/api/firmwareUpdate';
|
|
35
|
+
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
36
|
+
import type { PROTO } from '../constants';
|
|
37
|
+
import type { TypedResponseMessage } from '../device/DeviceCommands';
|
|
38
|
+
import type { Features } from '../types';
|
|
39
|
+
|
|
40
|
+
const Log = getLogger(LoggerNames.Method);
|
|
41
|
+
|
|
42
|
+
const SESSION_ERROR = 'session not found';
|
|
43
|
+
const PROTOCOL_V2_BOOTLOADER_RECONNECT_TIMEOUT = 60 * 1000;
|
|
44
|
+
const PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT = 5 * 1000;
|
|
45
|
+
const PROTOCOL_V2_INSTALL_TIMEOUT = 5 * 60 * 1000;
|
|
46
|
+
const PROTOCOL_V2_TARGET_STATUS_FINISHED = 0;
|
|
47
|
+
const PROTOCOL_V2_TARGET_STATUS_IN_PROGRESS = 1;
|
|
48
|
+
const PROTOCOL_V2_TARGET_STATUS_FAILED = 2;
|
|
49
|
+
const PROTOCOL_V2_CONNECT_PROTOCOL = 'V2';
|
|
50
|
+
const PROTOCOL_V2_FIRMWARE_STAGING_VOLUME = 'vol1:';
|
|
51
|
+
const PROTOCOL_V2_MIN_FILE_CHUNK_SIZE = 64;
|
|
52
|
+
|
|
53
|
+
type ProtocolV2FirmwareUpdateStatusTarget = {
|
|
54
|
+
target_id: number;
|
|
55
|
+
status: number;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type ProtocolV2FirmwareUpdateStartResponse =
|
|
59
|
+
| TypedResponseMessage<'Success'>
|
|
60
|
+
| TypedResponseMessage<'DevFirmwareUpdateStatus'>
|
|
61
|
+
| undefined;
|
|
62
|
+
|
|
63
|
+
const isProtocolV2ReconnectProbeError = (error: unknown) => {
|
|
64
|
+
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
65
|
+
return (
|
|
66
|
+
(message.includes('device protocol mismatch') && message.includes('expected v2')) ||
|
|
67
|
+
message.includes('did not respond to expected protocol')
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const isProtocolV2PollingTransientError = (error: unknown) => {
|
|
72
|
+
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
73
|
+
return (
|
|
74
|
+
isProtocolV2DeviceDisconnectedError(error) ||
|
|
75
|
+
isProtocolV2ReconnectProbeError(error) ||
|
|
76
|
+
(message.includes('response timeout') && message.includes('devicegetfirmwareupdatestatus')) ||
|
|
77
|
+
message.includes('device not found') ||
|
|
78
|
+
message.includes('transportnotfound')
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* FirmwareUpdateV4 is the complete Protocol V2 firmware update flow.
|
|
84
|
+
*
|
|
85
|
+
* It intentionally does not fall back to FirmwareUpdateV3/V1 behavior:
|
|
86
|
+
* - upload uses FilesystemFileWrite
|
|
87
|
+
* - install uses DevFirmwareUpdate
|
|
88
|
+
* - completion reboots to normal, then polls Ping
|
|
89
|
+
*/
|
|
90
|
+
export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareUpdateV4Params> {
|
|
91
|
+
init() {
|
|
92
|
+
this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.NOT_INITIALIZE];
|
|
93
|
+
this.requireDeviceMode = [];
|
|
94
|
+
this.useDevicePassphraseState = false;
|
|
95
|
+
this.skipForceUpdateCheck = true;
|
|
96
|
+
|
|
97
|
+
const { payload } = this;
|
|
98
|
+
|
|
99
|
+
validateParams(payload, [
|
|
100
|
+
{ name: 'bleVersion', type: 'array' },
|
|
101
|
+
{ name: 'bleBinary', type: 'buffer' },
|
|
102
|
+
{ name: 'chunkSize', type: 'number' },
|
|
103
|
+
{ name: 'firmwareVersion', type: 'array' },
|
|
104
|
+
{ name: 'firmwareBinary', type: 'buffer' },
|
|
105
|
+
{ name: 'resourceBinary', type: 'buffer' },
|
|
106
|
+
{ name: 'forcedUpdateRes', type: 'boolean' },
|
|
107
|
+
{ name: 'bootloaderVersion', type: 'array' },
|
|
108
|
+
{ name: 'bootloaderBinary', type: 'buffer' },
|
|
109
|
+
{ name: 'romloaderBinary', type: 'buffer' },
|
|
110
|
+
{ name: 'applicationP1Binary', type: 'buffer' },
|
|
111
|
+
{ name: 'applicationP2Binary', type: 'buffer' },
|
|
112
|
+
{ name: 'coprocessorBinary', type: 'buffer' },
|
|
113
|
+
{ name: 'se01Binary', type: 'buffer' },
|
|
114
|
+
{ name: 'se02Binary', type: 'buffer' },
|
|
115
|
+
{ name: 'se03Binary', type: 'buffer' },
|
|
116
|
+
{ name: 'se04Binary', type: 'buffer' },
|
|
117
|
+
{ name: 'firmwareType', type: 'string' },
|
|
118
|
+
{ name: 'platform', type: 'string' },
|
|
119
|
+
]);
|
|
120
|
+
|
|
121
|
+
this.params = {
|
|
122
|
+
bleBinary: payload.bleBinary,
|
|
123
|
+
chunkSize: payload.chunkSize,
|
|
124
|
+
firmwareBinary: payload.firmwareBinary,
|
|
125
|
+
forcedUpdateRes: payload.forcedUpdateRes,
|
|
126
|
+
bleVersion: payload.bleVersion,
|
|
127
|
+
bootloaderVersion: payload.bootloaderVersion,
|
|
128
|
+
bootloaderBinary: payload.bootloaderBinary,
|
|
129
|
+
romloaderBinary: payload.romloaderBinary,
|
|
130
|
+
applicationP1Binary: payload.applicationP1Binary,
|
|
131
|
+
applicationP2Binary: payload.applicationP2Binary,
|
|
132
|
+
coprocessorBinary: payload.coprocessorBinary,
|
|
133
|
+
se01Binary: payload.se01Binary,
|
|
134
|
+
se02Binary: payload.se02Binary,
|
|
135
|
+
se03Binary: payload.se03Binary,
|
|
136
|
+
se04Binary: payload.se04Binary,
|
|
137
|
+
firmwareVersion: payload.firmwareVersion,
|
|
138
|
+
resourceBinary: payload.resourceBinary,
|
|
139
|
+
firmwareType: payload.firmwareType,
|
|
140
|
+
platform: payload.platform,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private getProtocolV2FirmwareChunkSize() {
|
|
145
|
+
const payloadChunkSize = Number(this.params?.chunkSize);
|
|
146
|
+
const env = DataManager.getSettings('env');
|
|
147
|
+
const maxChunkSize =
|
|
148
|
+
this.params?.platform === 'native' || (env && DataManager.isBleConnect(env))
|
|
149
|
+
? PROTOCOL_V2_BLE_FILE_CHUNK_SIZE
|
|
150
|
+
: PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
151
|
+
if (!Number.isFinite(payloadChunkSize) || payloadChunkSize <= 0) {
|
|
152
|
+
return maxChunkSize;
|
|
153
|
+
}
|
|
154
|
+
return Math.min(
|
|
155
|
+
Math.max(Math.floor(payloadChunkSize), PROTOCOL_V2_MIN_FILE_CHUNK_SIZE),
|
|
156
|
+
maxChunkSize
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async run() {
|
|
161
|
+
if (!this.device.isProtocolV2()) {
|
|
162
|
+
throw ERRORS.TypedError(
|
|
163
|
+
HardwareErrorCode.RuntimeError,
|
|
164
|
+
'firmwareUpdateV4 requires a Protocol V2 device'
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
Log.debug('FirmwareUpdateV4 strategy: Protocol V2');
|
|
169
|
+
return this.runProtocolV2();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private async runProtocolV2() {
|
|
173
|
+
const deviceFeatures = await this.getProtocolV2DeviceFeatures();
|
|
174
|
+
const deviceFirmwareType = getFirmwareType(deviceFeatures);
|
|
175
|
+
const firmwareType = this.params.firmwareType ?? deviceFirmwareType;
|
|
176
|
+
|
|
177
|
+
let resourceBinary: ArrayBuffer | null = null;
|
|
178
|
+
let fwBinaryMap: { fileName: string; binary: ArrayBuffer; targetId?: number }[] = [];
|
|
179
|
+
let bootloaderBinary: ArrayBuffer | null = null;
|
|
180
|
+
try {
|
|
181
|
+
this.postTipMessage(FirmwareUpdateTipMessage.StartDownloadFirmware);
|
|
182
|
+
resourceBinary = await this.prepareResourceBinary(firmwareType, deviceFeatures);
|
|
183
|
+
fwBinaryMap = await this.prepareFirmwareAndBleBinary(firmwareType, deviceFeatures);
|
|
184
|
+
bootloaderBinary = await this.prepareBootloaderBinary(firmwareType, deviceFeatures);
|
|
185
|
+
// 按 DevFirmwareTargetType 拆分的目标二进制(显式 target_id,不走文件名推断)
|
|
186
|
+
fwBinaryMap.push(...this.collectExplicitTargetBinaries());
|
|
187
|
+
this.postTipMessage(FirmwareUpdateTipMessage.FinishDownloadFirmware);
|
|
188
|
+
} catch (err) {
|
|
189
|
+
throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateDownloadFailed, err.message ?? err);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (!resourceBinary && !bootloaderBinary && fwBinaryMap.length === 0) {
|
|
193
|
+
throw ERRORS.TypedError(
|
|
194
|
+
HardwareErrorCode.FirmwareUpdateDownloadFailed,
|
|
195
|
+
'No firmware to update'
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// TODO: 当前 firmware-pro2 子模块的 reboot/bootloader 流程还未稳定,先暂停自动进 bootloader。
|
|
200
|
+
// await this.enterProtocolV2BootloaderMode();
|
|
201
|
+
|
|
202
|
+
await this.executeProtocolV2Update({
|
|
203
|
+
resourceBinary,
|
|
204
|
+
fwBinaryMap,
|
|
205
|
+
bootloaderBinary,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
await this.exitProtocolV2BootloaderToNormal();
|
|
209
|
+
|
|
210
|
+
const versions = await this.waitForProtocolV2FinalFeatures();
|
|
211
|
+
this.postTipMessage(FirmwareUpdateTipMessage.FirmwareUpdateCompleted);
|
|
212
|
+
DevicePool.resetState();
|
|
213
|
+
|
|
214
|
+
return versions;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private async getProtocolV2DeviceFeatures(): Promise<Features> {
|
|
218
|
+
if (typeof this.device.getFeatures === 'function') {
|
|
219
|
+
const features = await this.device.getFeatures();
|
|
220
|
+
if (features) return features;
|
|
221
|
+
}
|
|
222
|
+
if (this.device.features) {
|
|
223
|
+
return this.device.features;
|
|
224
|
+
}
|
|
225
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Device features not available');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
private async prepareResourceBinary(firmwareType: EFirmwareType, features: Features) {
|
|
229
|
+
if (this.params.resourceBinary) {
|
|
230
|
+
return this.params.resourceBinary;
|
|
231
|
+
}
|
|
232
|
+
const resourceUrl = DataManager.getSysResourcesLatestRelease({
|
|
233
|
+
features,
|
|
234
|
+
forcedUpdateRes: this.params.forcedUpdateRes,
|
|
235
|
+
firmwareType,
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
if (resourceUrl) {
|
|
239
|
+
const resource = (await getSysResourceBinary(resourceUrl)).binary;
|
|
240
|
+
return resource;
|
|
241
|
+
}
|
|
242
|
+
Log.warn('No resource url found');
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private async prepareBootloaderBinary(
|
|
247
|
+
firmwareType: EFirmwareType,
|
|
248
|
+
features: Features
|
|
249
|
+
): Promise<ArrayBuffer | null> {
|
|
250
|
+
if (this.params.bootloaderBinary) {
|
|
251
|
+
return this.params.bootloaderBinary;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (this.params.bootloaderVersion) {
|
|
255
|
+
const bootResourceUrl = DataManager.getBootloaderResource(features, firmwareType);
|
|
256
|
+
if (bootResourceUrl) {
|
|
257
|
+
const bootBinary = (await getSysResourceBinary(bootResourceUrl)).binary;
|
|
258
|
+
return bootBinary;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private isProtocolV2BootloaderMode() {
|
|
265
|
+
if (typeof this.device.isBootloader === 'function') {
|
|
266
|
+
return this.device.isBootloader();
|
|
267
|
+
}
|
|
268
|
+
return !!this.device.features?.bootloaderMode;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async enterProtocolV2BootloaderMode() {
|
|
272
|
+
if (this.isProtocolV2BootloaderMode()) {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
try {
|
|
277
|
+
this.postTipMessage(FirmwareUpdateTipMessage.AutoRebootToBootloader);
|
|
278
|
+
await this.protocolV2Reboot(DevRebootType.Bootloader);
|
|
279
|
+
this.postTipMessage(FirmwareUpdateTipMessage.GoToBootloaderSuccess);
|
|
280
|
+
this.checkDeviceToBootloader(this.payload.connectId);
|
|
281
|
+
await this.checkPromise?.promise;
|
|
282
|
+
this.checkPromise = null;
|
|
283
|
+
await wait(1500);
|
|
284
|
+
await this.device.acquire?.();
|
|
285
|
+
return true;
|
|
286
|
+
} catch (error) {
|
|
287
|
+
if (error instanceof HardwareError) {
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
290
|
+
Log.log('Protocol V2 auto go to bootloader mode failed: ', error);
|
|
291
|
+
throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* 收集按 DevFirmwareTargetType 拆分的显式目标二进制。
|
|
297
|
+
* 文件名仅用于 staging 路径展示,target_id 已显式给定。
|
|
298
|
+
*/
|
|
299
|
+
private collectExplicitTargetBinaries() {
|
|
300
|
+
const entries: { fileName: string; binary: ArrayBuffer; targetId: number }[] = [];
|
|
301
|
+
const push = (binary: ArrayBuffer | undefined, fileName: string, targetId: number) => {
|
|
302
|
+
if (binary) entries.push({ fileName, binary, targetId });
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
push(
|
|
306
|
+
this.params.romloaderBinary,
|
|
307
|
+
'romloader.bin',
|
|
308
|
+
ProtocolV2FirmwareTargetType.TARGET_MAIN_BOOT
|
|
309
|
+
);
|
|
310
|
+
push(
|
|
311
|
+
this.params.applicationP1Binary,
|
|
312
|
+
'application_p1.bin',
|
|
313
|
+
ProtocolV2FirmwareTargetType.TARGET_MAIN_APP
|
|
314
|
+
);
|
|
315
|
+
push(
|
|
316
|
+
this.params.applicationP2Binary,
|
|
317
|
+
'application_p2.bin',
|
|
318
|
+
ProtocolV2FirmwareTargetType.TARGET_MAIN_APP
|
|
319
|
+
);
|
|
320
|
+
push(this.params.coprocessorBinary, 'coprocessor.bin', ProtocolV2FirmwareTargetType.TARGET_BT);
|
|
321
|
+
push(this.params.se01Binary, 'se01.bin', ProtocolV2FirmwareTargetType.TARGET_SE1);
|
|
322
|
+
push(this.params.se02Binary, 'se02.bin', ProtocolV2FirmwareTargetType.TARGET_SE2);
|
|
323
|
+
push(this.params.se03Binary, 'se03.bin', ProtocolV2FirmwareTargetType.TARGET_SE3);
|
|
324
|
+
push(this.params.se04Binary, 'se04.bin', ProtocolV2FirmwareTargetType.TARGET_SE4);
|
|
325
|
+
return entries;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
private async prepareFirmwareAndBleBinary(firmwareType: EFirmwareType, features: Features) {
|
|
329
|
+
const fwBinaryMap: { fileName: string; binary: ArrayBuffer; targetId?: number }[] = [];
|
|
330
|
+
if (this.params.firmwareBinary) {
|
|
331
|
+
fwBinaryMap.push({
|
|
332
|
+
fileName: 'firmware.bin',
|
|
333
|
+
binary: this.params.firmwareBinary,
|
|
334
|
+
});
|
|
335
|
+
} else if (this.params.firmwareVersion) {
|
|
336
|
+
const firmwareBinary = (
|
|
337
|
+
await getBinary({
|
|
338
|
+
features,
|
|
339
|
+
version: this.params.firmwareVersion,
|
|
340
|
+
updateType: 'firmware',
|
|
341
|
+
isUpdateBootloader: false,
|
|
342
|
+
firmwareType,
|
|
343
|
+
})
|
|
344
|
+
).binary;
|
|
345
|
+
fwBinaryMap.push({
|
|
346
|
+
fileName: 'firmware.bin',
|
|
347
|
+
binary: firmwareBinary,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (this.params.bleBinary) {
|
|
352
|
+
fwBinaryMap.push({
|
|
353
|
+
fileName: 'ble-firmware.bin',
|
|
354
|
+
binary: this.params.bleBinary,
|
|
355
|
+
});
|
|
356
|
+
} else if (this.params.bleVersion) {
|
|
357
|
+
const bleBinary = await getBinary({
|
|
358
|
+
features,
|
|
359
|
+
version: this.params.bleVersion,
|
|
360
|
+
updateType: 'ble',
|
|
361
|
+
firmwareType,
|
|
362
|
+
});
|
|
363
|
+
fwBinaryMap.push({
|
|
364
|
+
fileName: 'ble-firmware.bin',
|
|
365
|
+
binary: bleBinary.binary,
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return fwBinaryMap;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
private async executeProtocolV2Update({
|
|
373
|
+
resourceBinary,
|
|
374
|
+
fwBinaryMap,
|
|
375
|
+
bootloaderBinary,
|
|
376
|
+
}: {
|
|
377
|
+
resourceBinary: ArrayBuffer | null;
|
|
378
|
+
fwBinaryMap: { fileName: string; binary: ArrayBuffer; targetId?: number }[];
|
|
379
|
+
bootloaderBinary: ArrayBuffer | null;
|
|
380
|
+
}) {
|
|
381
|
+
let totalSize = 0;
|
|
382
|
+
let processedSize = 0;
|
|
383
|
+
|
|
384
|
+
if (resourceBinary) totalSize += resourceBinary.byteLength;
|
|
385
|
+
for (const fwbinary of fwBinaryMap) totalSize += fwbinary.binary.byteLength;
|
|
386
|
+
if (bootloaderBinary) totalSize += bootloaderBinary.byteLength;
|
|
387
|
+
|
|
388
|
+
this.postTipMessage(FirmwareUpdateTipMessage.StartTransferData);
|
|
389
|
+
|
|
390
|
+
const targets: Array<{ target_id: number; path: string }> = [];
|
|
391
|
+
|
|
392
|
+
if (resourceBinary) {
|
|
393
|
+
// resource 仅支持单文件 .bin:整文件一次上传,target path 指向该文件
|
|
394
|
+
const resourceFilePath = `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}resource.bin`;
|
|
395
|
+
processedSize = await this.protocolV2CommonUpdateProcess({
|
|
396
|
+
payload: resourceBinary,
|
|
397
|
+
filePath: resourceFilePath,
|
|
398
|
+
processedSize,
|
|
399
|
+
totalSize,
|
|
400
|
+
});
|
|
401
|
+
targets.push({
|
|
402
|
+
target_id: ProtocolV2FirmwareTargetType.TARGET_RESOURCE,
|
|
403
|
+
path: resourceFilePath,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (bootloaderBinary) {
|
|
408
|
+
const bootloaderPath = `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}bootloader.bin`;
|
|
409
|
+
processedSize = await this.protocolV2CommonUpdateProcess({
|
|
410
|
+
payload: bootloaderBinary,
|
|
411
|
+
filePath: bootloaderPath,
|
|
412
|
+
processedSize,
|
|
413
|
+
totalSize,
|
|
414
|
+
});
|
|
415
|
+
targets.push({
|
|
416
|
+
target_id: ProtocolV2FirmwareTargetType.TARGET_MAIN_BOOT,
|
|
417
|
+
path: bootloaderPath,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
for (const fwbinary of fwBinaryMap) {
|
|
422
|
+
const firmwarePath = `${PROTOCOL_V2_FIRMWARE_STAGING_VOLUME}${fwbinary.fileName}`;
|
|
423
|
+
processedSize = await this.protocolV2CommonUpdateProcess({
|
|
424
|
+
payload: fwbinary.binary,
|
|
425
|
+
filePath: firmwarePath,
|
|
426
|
+
processedSize,
|
|
427
|
+
totalSize,
|
|
428
|
+
});
|
|
429
|
+
targets.push({
|
|
430
|
+
target_id: fwbinary.targetId ?? protocolV2FileNameToTargetId(fwbinary.fileName),
|
|
431
|
+
path: firmwarePath,
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (totalSize > 0) {
|
|
436
|
+
this.postProgressMessage(100, 'transferData');
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
this.postTipMessage(FirmwareUpdateTipMessage.ConfirmOnDevice);
|
|
440
|
+
const startResponse = await this.protocolV2StartFirmwareUpdate({ targets });
|
|
441
|
+
await this.waitForProtocolV2FirmwareUpdateComplete(targets, startResponse);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
private async queryProtocolV2FirmwareUpdateStatus() {
|
|
445
|
+
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
446
|
+
return typedCall(
|
|
447
|
+
'DevGetFirmwareUpdateStatus',
|
|
448
|
+
'DevFirmwareUpdateStatus',
|
|
449
|
+
{},
|
|
450
|
+
{
|
|
451
|
+
timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
|
|
452
|
+
}
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
private async pingProtocolV2Device() {
|
|
457
|
+
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
458
|
+
await typedCall(
|
|
459
|
+
'Ping',
|
|
460
|
+
'Success',
|
|
461
|
+
{ message: 'firmware-update' },
|
|
462
|
+
{
|
|
463
|
+
timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
|
|
464
|
+
}
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
private assertProtocolV2TargetStatus(
|
|
469
|
+
statusTargets: ProtocolV2FirmwareUpdateStatusTarget[],
|
|
470
|
+
expectedTargetIds: Set<number>
|
|
471
|
+
) {
|
|
472
|
+
const failedTarget = statusTargets.find(
|
|
473
|
+
target =>
|
|
474
|
+
expectedTargetIds.has(target.target_id) &&
|
|
475
|
+
target.status === PROTOCOL_V2_TARGET_STATUS_FAILED
|
|
476
|
+
);
|
|
477
|
+
if (failedTarget) {
|
|
478
|
+
throw ERRORS.TypedError(
|
|
479
|
+
HardwareErrorCode.FirmwareError,
|
|
480
|
+
`Protocol V2 firmware target ${failedTarget.target_id} failed`
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
const completedTargets = statusTargets.filter(
|
|
485
|
+
target =>
|
|
486
|
+
expectedTargetIds.has(target.target_id) &&
|
|
487
|
+
target.status === PROTOCOL_V2_TARGET_STATUS_FINISHED
|
|
488
|
+
);
|
|
489
|
+
if (completedTargets.length === expectedTargetIds.size && expectedTargetIds.size > 0) {
|
|
490
|
+
return true;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const inProgressTarget = statusTargets.find(
|
|
494
|
+
target =>
|
|
495
|
+
expectedTargetIds.has(target.target_id) &&
|
|
496
|
+
target.status === PROTOCOL_V2_TARGET_STATUS_IN_PROGRESS
|
|
497
|
+
);
|
|
498
|
+
if (inProgressTarget) {
|
|
499
|
+
this.postProgressMessage(99, 'installingFirmware');
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
private async waitForProtocolV2FirmwareUpdateComplete(
|
|
506
|
+
targets: Array<{ target_id: number; path: string }>,
|
|
507
|
+
startResponse?: ProtocolV2FirmwareUpdateStartResponse
|
|
508
|
+
) {
|
|
509
|
+
const expectedTargetIds = new Set(targets.map(target => target.target_id));
|
|
510
|
+
if (startResponse?.type === 'Success') {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
if (startResponse?.type === 'DevFirmwareUpdateStatus') {
|
|
514
|
+
const statusTargets = (startResponse.message.targets ??
|
|
515
|
+
[]) as ProtocolV2FirmwareUpdateStatusTarget[];
|
|
516
|
+
if (this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds)) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const startTime = Date.now();
|
|
522
|
+
let lastError: unknown;
|
|
523
|
+
|
|
524
|
+
while (Date.now() - startTime < PROTOCOL_V2_INSTALL_TIMEOUT) {
|
|
525
|
+
try {
|
|
526
|
+
const statusRes = await this.queryProtocolV2FirmwareUpdateStatus();
|
|
527
|
+
const statusTargets = (statusRes.message.targets ??
|
|
528
|
+
[]) as ProtocolV2FirmwareUpdateStatusTarget[];
|
|
529
|
+
if (this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds)) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
} catch (error) {
|
|
533
|
+
lastError = error;
|
|
534
|
+
if (error instanceof HardwareError && error.errorCode === HardwareErrorCode.FirmwareError) {
|
|
535
|
+
throw error;
|
|
536
|
+
}
|
|
537
|
+
Log.log('Protocol V2 firmware install status polling failed: ', error);
|
|
538
|
+
if (isProtocolV2PollingTransientError(error)) {
|
|
539
|
+
try {
|
|
540
|
+
await this.reconnectProtocolV2Device();
|
|
541
|
+
} catch (reconnectError) {
|
|
542
|
+
lastError = reconnectError;
|
|
543
|
+
Log.log(
|
|
544
|
+
'Protocol V2 firmware install reconnect/status polling failed: ',
|
|
545
|
+
reconnectError
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
try {
|
|
549
|
+
await this.pingProtocolV2Device();
|
|
550
|
+
Log.log('Protocol V2 firmware status unavailable, Ping is ready');
|
|
551
|
+
return;
|
|
552
|
+
} catch (pingError) {
|
|
553
|
+
lastError = pingError;
|
|
554
|
+
Log.log('Protocol V2 firmware install Ping polling failed: ', pingError);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
await wait(1000);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
throw ERRORS.TypedError(
|
|
562
|
+
HardwareErrorCode.RuntimeError,
|
|
563
|
+
`Protocol V2 firmware update status timeout: ${this.normalizeErrorMessage(lastError)}`
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
private async exitProtocolV2BootloaderToNormal() {
|
|
568
|
+
this.postTipMessage(FirmwareUpdateTipMessage.SwitchFirmwareReconnectDevice);
|
|
569
|
+
await this.protocolV2Reboot(DevRebootType.Normal);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
private async waitForProtocolV2FinalFeatures() {
|
|
573
|
+
const features = await this.waitForProtocolV2ReconnectAndFeatures(
|
|
574
|
+
PROTOCOL_V2_BOOTLOADER_RECONNECT_TIMEOUT
|
|
575
|
+
);
|
|
576
|
+
|
|
577
|
+
const bootloaderVersion = getDeviceBootloaderVersion(features).join('.');
|
|
578
|
+
const bleVersion = getDeviceBLEFirmwareVersion(features).join('.');
|
|
579
|
+
const firmwareVersion = getDeviceFirmwareVersion(features).join('.');
|
|
580
|
+
if (firmwareVersion === '0.0.0') {
|
|
581
|
+
Log.warn(
|
|
582
|
+
'Protocol V2 firmware update finished but app firmware version is still 0.0.0. This is allowed for Pro2 debug BLE-only update flows.'
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
return {
|
|
587
|
+
bootloaderVersion,
|
|
588
|
+
bleVersion,
|
|
589
|
+
firmwareVersion,
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
private async waitForProtocolV2ReconnectAndFeatures(timeout: number) {
|
|
594
|
+
const startTime = Date.now();
|
|
595
|
+
let lastError: unknown;
|
|
596
|
+
|
|
597
|
+
while (Date.now() - startTime < timeout) {
|
|
598
|
+
try {
|
|
599
|
+
await this.reconnectProtocolV2Device();
|
|
600
|
+
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
601
|
+
commands: this.device.getCommands(),
|
|
602
|
+
timeoutMs: PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT,
|
|
603
|
+
// 更新完成判定只需要各 target 版本号;scope 与请求内容保持一致
|
|
604
|
+
request: PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
|
|
605
|
+
});
|
|
606
|
+
return this.device.updateProtocolV2Features(deviceInfo);
|
|
607
|
+
} catch (error) {
|
|
608
|
+
lastError = error;
|
|
609
|
+
Log.log('Protocol V2 normal mode not ready, polling Ping: ', error);
|
|
610
|
+
await wait(1000);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
throw ERRORS.TypedError(
|
|
615
|
+
HardwareErrorCode.DeviceNotFound,
|
|
616
|
+
`Protocol V2 final features not ready within ${timeout / 1000}s: ${this.normalizeErrorMessage(
|
|
617
|
+
lastError
|
|
618
|
+
)}`
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
private async reconnectProtocolV2Device() {
|
|
623
|
+
if (this.isBleReconnect()) {
|
|
624
|
+
await this.acquireProtocolV2BleDevice();
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
const deviceDiff = await this.device.deviceConnector?.enumerate();
|
|
629
|
+
const devicesDescriptor = deviceDiff?.descriptors ?? [];
|
|
630
|
+
|
|
631
|
+
const { deviceList } = await DevicePool.getDevices(devicesDescriptor, this.connectId);
|
|
632
|
+
if (deviceList.length !== 1) {
|
|
633
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceNotFound);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
this.device.updateFromCache(deviceList[0]);
|
|
637
|
+
await this.device.acquire();
|
|
638
|
+
this.device.commands.disposed = false;
|
|
639
|
+
this.device.getCommands().mainId = this.device.mainId ?? '';
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
private async protocolV2CommonUpdateProcess({
|
|
643
|
+
payload,
|
|
644
|
+
filePath,
|
|
645
|
+
processedSize,
|
|
646
|
+
totalSize,
|
|
647
|
+
}: PROTO.FirmwareUpload & {
|
|
648
|
+
filePath: string;
|
|
649
|
+
processedSize?: number;
|
|
650
|
+
totalSize?: number;
|
|
651
|
+
}) {
|
|
652
|
+
const chunkSize = this.getProtocolV2FirmwareChunkSize();
|
|
653
|
+
let offset = 0;
|
|
654
|
+
const getUploadProgress = (fileOffset: number) => {
|
|
655
|
+
if (totalSize !== undefined && processedSize !== undefined) {
|
|
656
|
+
return Math.min(Math.ceil(((processedSize + fileOffset) / totalSize) * 100), 99);
|
|
657
|
+
}
|
|
658
|
+
return Math.min(Math.ceil((fileOffset / payload.byteLength) * 100), 99);
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
while (offset < payload.byteLength) {
|
|
662
|
+
const chunkEnd = Math.min(offset + chunkSize, payload.byteLength);
|
|
663
|
+
const chunkLength = chunkEnd - offset;
|
|
664
|
+
const chunk = payload.slice(offset, chunkEnd);
|
|
665
|
+
const overwrite = offset === 0;
|
|
666
|
+
const progress = getUploadProgress(chunkEnd);
|
|
667
|
+
|
|
668
|
+
const writeRes = await this.fileWriteWithRetry(
|
|
669
|
+
filePath,
|
|
670
|
+
payload.byteLength,
|
|
671
|
+
offset,
|
|
672
|
+
chunk,
|
|
673
|
+
overwrite,
|
|
674
|
+
progress
|
|
675
|
+
);
|
|
676
|
+
const processedByte = Number(writeRes.message.processed_byte);
|
|
677
|
+
const nextOffset =
|
|
678
|
+
Number.isFinite(processedByte) && processedByte > offset
|
|
679
|
+
? processedByte
|
|
680
|
+
: offset + chunkLength;
|
|
681
|
+
if (nextOffset <= offset || nextOffset > payload.byteLength) {
|
|
682
|
+
throw ERRORS.TypedError(
|
|
683
|
+
HardwareErrorCode.EmmcFileWriteFirmwareError,
|
|
684
|
+
`invalid processed_byte ${writeRes.message.processed_byte} for offset ${offset}`
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
offset = nextOffset;
|
|
688
|
+
this.postProgressMessage(getUploadProgress(offset), 'transferData');
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
return totalSize !== undefined ? (processedSize ?? 0) + payload.byteLength : 0;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
private async fileWriteWithRetry(
|
|
695
|
+
filePath: string,
|
|
696
|
+
totalFileSize: number,
|
|
697
|
+
offset: number,
|
|
698
|
+
chunk: ArrayBuffer | Buffer,
|
|
699
|
+
overwrite: boolean,
|
|
700
|
+
progress: number | null
|
|
701
|
+
): Promise<TypedResponseMessage<'FilesystemFile'>> {
|
|
702
|
+
const writeFunc = async () => {
|
|
703
|
+
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
704
|
+
const writeRes = await typedCall('FilesystemFileWrite', 'FilesystemFile', {
|
|
705
|
+
file: {
|
|
706
|
+
path: filePath,
|
|
707
|
+
offset,
|
|
708
|
+
total_size: totalFileSize,
|
|
709
|
+
data: chunk,
|
|
710
|
+
},
|
|
711
|
+
overwrite,
|
|
712
|
+
append: false,
|
|
713
|
+
ui_percentage: progress ?? undefined,
|
|
714
|
+
});
|
|
715
|
+
if (writeRes.type !== 'FilesystemFile') {
|
|
716
|
+
if ((writeRes as any).type === 'CallMethodError') {
|
|
717
|
+
if (((writeRes as any).message.error ?? '').indexOf(SESSION_ERROR) > -1) {
|
|
718
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, SESSION_ERROR);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
throw ERRORS.TypedError(
|
|
722
|
+
HardwareErrorCode.EmmcFileWriteFirmwareError,
|
|
723
|
+
'transfer data error'
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
return writeRes;
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
let retryCount = 10;
|
|
730
|
+
while (retryCount > 0) {
|
|
731
|
+
try {
|
|
732
|
+
const result = await writeFunc();
|
|
733
|
+
return result;
|
|
734
|
+
} catch (error) {
|
|
735
|
+
Log.error(`fileWrite error: `, error);
|
|
736
|
+
retryCount--;
|
|
737
|
+
if (retryCount === 0) {
|
|
738
|
+
throw ERRORS.TypedError(
|
|
739
|
+
HardwareErrorCode.EmmcFileWriteFirmwareError,
|
|
740
|
+
'transfer data error'
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
const env = DataManager.getSettings('env');
|
|
744
|
+
if (DataManager.isBleConnect(env)) {
|
|
745
|
+
await wait(3000);
|
|
746
|
+
await this.acquireProtocolV2BleDevice();
|
|
747
|
+
await this.device.initialize();
|
|
748
|
+
}
|
|
749
|
+
await wait(2000);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
throw ERRORS.TypedError(HardwareErrorCode.EmmcFileWriteFirmwareError, 'transfer data error');
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
private async acquireProtocolV2BleDevice() {
|
|
756
|
+
await this.device.deviceConnector?.acquire(
|
|
757
|
+
this.device.originalDescriptor.id,
|
|
758
|
+
null,
|
|
759
|
+
true,
|
|
760
|
+
PROTOCOL_V2_CONNECT_PROTOCOL
|
|
761
|
+
);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
private async protocolV2StartFirmwareUpdate({
|
|
765
|
+
targets,
|
|
766
|
+
}: {
|
|
767
|
+
targets: Array<{ target_id: number; path: string }>;
|
|
768
|
+
}) {
|
|
769
|
+
const commands = this.device.getCommands();
|
|
770
|
+
let response: ProtocolV2FirmwareUpdateStartResponse;
|
|
771
|
+
try {
|
|
772
|
+
response = await commands.typedCall(
|
|
773
|
+
'DevFirmwareUpdate',
|
|
774
|
+
PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES,
|
|
775
|
+
{
|
|
776
|
+
targets,
|
|
777
|
+
},
|
|
778
|
+
{
|
|
779
|
+
intermediateTypes: ['DevFirmwareInstallProgress'],
|
|
780
|
+
onIntermediateResponse: (response: { message?: { progress?: number } }) => {
|
|
781
|
+
const progress = Number(response.message?.progress);
|
|
782
|
+
if (Number.isFinite(progress)) {
|
|
783
|
+
this.postProgressMessage(Math.min(progress, 99), 'installingFirmware');
|
|
784
|
+
}
|
|
785
|
+
},
|
|
786
|
+
}
|
|
787
|
+
);
|
|
788
|
+
} catch (error) {
|
|
789
|
+
if (isProtocolV2DeviceDisconnectedError(error)) {
|
|
790
|
+
Log.log('Rebooting device');
|
|
791
|
+
} else {
|
|
792
|
+
throw error;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
this.postTipMessage(FirmwareUpdateTipMessage.FirmwareUpdating);
|
|
796
|
+
return response;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
private async protocolV2Reboot(rebootType: DevRebootType) {
|
|
800
|
+
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
801
|
+
try {
|
|
802
|
+
const res = await typedCall('DevReboot', 'Success', {
|
|
803
|
+
reboot_type: rebootType,
|
|
804
|
+
});
|
|
805
|
+
return res.message;
|
|
806
|
+
} catch (error) {
|
|
807
|
+
if (isProtocolV2DeviceDisconnectedError(error) || isProtocolV2ReconnectProbeError(error)) {
|
|
808
|
+
return { message: 'Device rebooted successfully' };
|
|
809
|
+
}
|
|
810
|
+
throw error;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
private normalizeErrorMessage(error: unknown): string {
|
|
815
|
+
if (!error) {
|
|
816
|
+
return '';
|
|
817
|
+
}
|
|
818
|
+
return getProtocolV2UnknownErrorText(error);
|
|
819
|
+
}
|
|
820
|
+
}
|