@onetokenfe/hd-core 1.1.23
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/.eslintrc +6 -0
- package/README.md +32 -0
- package/__tests__/benfen.test.ts +68 -0
- package/__tests__/checkBootloaderReleast.test.ts +115 -0
- package/__tests__/evmSignTransaction.test.ts +419 -0
- package/jest.config.js +6 -0
- package/package.json +48 -0
- package/src/api/BaseMethod.ts +275 -0
- package/src/api/CheckAllFirmwareRelease.ts +73 -0
- package/src/api/CheckBLEFirmwareRelease.ts +23 -0
- package/src/api/CheckBootloaderRelease.ts +32 -0
- package/src/api/CheckBridgeRelease.ts +28 -0
- package/src/api/CheckBridgeStatus.ts +32 -0
- package/src/api/CheckFirmwareRelease.ts +31 -0
- package/src/api/CheckFirmwareTypeAvailable.tsx +30 -0
- package/src/api/CipherKeyValue.ts +68 -0
- package/src/api/FirmwareUpdate.ts +219 -0
- package/src/api/FirmwareUpdateV2.ts +408 -0
- package/src/api/FirmwareUpdateV3.ts +560 -0
- package/src/api/GetFeatures.ts +23 -0
- package/src/api/GetLogs.ts +40 -0
- package/src/api/GetOnetokenFeatures.ts +25 -0
- package/src/api/GetPassphraseState.ts +28 -0
- package/src/api/PromptWebDeviceAccess.ts +77 -0
- package/src/api/SearchDevices.ts +50 -0
- package/src/api/alephium/AlephiumGetAddress.ts +84 -0
- package/src/api/alephium/AlephiumSignMessage.ts +51 -0
- package/src/api/alephium/AlephiumSignTransaction.ts +135 -0
- package/src/api/algo/AlgoGetAddress.ts +73 -0
- package/src/api/algo/AlgoSignTransaction.ts +52 -0
- package/src/api/allnetwork/AllNetworkGetAddress.ts +88 -0
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +529 -0
- package/src/api/allnetwork/AllNetworkGetAddressByLoop.ts +162 -0
- package/src/api/aptos/AptosGetAddress.ts +129 -0
- package/src/api/aptos/AptosGetPublicKey.ts +64 -0
- package/src/api/aptos/AptosSignInMessage.ts +55 -0
- package/src/api/aptos/AptosSignMessage.ts +79 -0
- package/src/api/aptos/AptosSignTransaction.ts +72 -0
- package/src/api/benfen/BenfenGetAddress.ts +122 -0
- package/src/api/benfen/BenfenGetPublicKey.ts +68 -0
- package/src/api/benfen/BenfenSignMessage.ts +50 -0
- package/src/api/benfen/BenfenSignTransaction.ts +105 -0
- package/src/api/benfen/normalize.ts +51 -0
- package/src/api/btc/BTCGetAddress.ts +91 -0
- package/src/api/btc/BTCGetPublicKey.ts +174 -0
- package/src/api/btc/BTCSignMessage.ts +73 -0
- package/src/api/btc/BTCSignPsbt.ts +65 -0
- package/src/api/btc/BTCSignTransaction.ts +148 -0
- package/src/api/btc/BTCVerifyMessage.ts +46 -0
- package/src/api/btc/helpers/btcParamsUtils.ts +64 -0
- package/src/api/btc/helpers/signtx.ts +251 -0
- package/src/api/btc/helpers/signtxLegacy.ts +227 -0
- package/src/api/btc/helpers/versionLimit.ts +25 -0
- package/src/api/btc/helpers/xpubUtils.ts +132 -0
- package/src/api/cardano/CardanoGetAddress.ts +139 -0
- package/src/api/cardano/CardanoGetPublicKey.ts +72 -0
- package/src/api/cardano/CardanoSignMessage.ts +73 -0
- package/src/api/cardano/CardanoSignTransaction.ts +404 -0
- package/src/api/cardano/helper/addressParameters.ts +120 -0
- package/src/api/cardano/helper/auxiliaryData.ts +133 -0
- package/src/api/cardano/helper/cardanoInputs.ts +55 -0
- package/src/api/cardano/helper/cardanoOutputs.ts +89 -0
- package/src/api/cardano/helper/certificate.ts +246 -0
- package/src/api/cardano/helper/token.ts +44 -0
- package/src/api/cardano/helper/utils.ts +17 -0
- package/src/api/cardano/helper/witnesses.ts +62 -0
- package/src/api/conflux/ConfluxGetAddress.ts +78 -0
- package/src/api/conflux/ConfluxSignMessage.ts +49 -0
- package/src/api/conflux/ConfluxSignMessageCIP23.ts +49 -0
- package/src/api/conflux/ConfluxSignTransaction.ts +135 -0
- package/src/api/cosmos/CosmosGetAddress.ts +80 -0
- package/src/api/cosmos/CosmosGetPublicKey.ts +77 -0
- package/src/api/cosmos/CosmosSignTransaction.ts +68 -0
- package/src/api/device/DeviceBackup.ts +15 -0
- package/src/api/device/DeviceCancel.ts +15 -0
- package/src/api/device/DeviceChangePin.ts +25 -0
- package/src/api/device/DeviceFlags.ts +26 -0
- package/src/api/device/DeviceFullyUploadResource.ts +80 -0
- package/src/api/device/DeviceLock.ts +15 -0
- package/src/api/device/DeviceRebootToBoardloader.ts +30 -0
- package/src/api/device/DeviceRebootToBootloader.ts +28 -0
- package/src/api/device/DeviceRecovery.ts +44 -0
- package/src/api/device/DeviceReset.ts +46 -0
- package/src/api/device/DeviceSettings.ts +96 -0
- package/src/api/device/DeviceSupportFeatures.ts +29 -0
- package/src/api/device/DeviceUnlock.ts +13 -0
- package/src/api/device/DeviceUpdateBootloader.ts +111 -0
- package/src/api/device/DeviceUpdateReboot.ts +17 -0
- package/src/api/device/DeviceUploadResource.ts +204 -0
- package/src/api/device/DeviceVerify.ts +65 -0
- package/src/api/device/DeviceWipe.ts +15 -0
- package/src/api/dynex/DnxGetAddress.ts +75 -0
- package/src/api/dynex/DnxSignTransaction.ts +126 -0
- package/src/api/evm/EVMGetAddress.ts +88 -0
- package/src/api/evm/EVMGetPublicKey.ts +116 -0
- package/src/api/evm/EVMSignMessage.ts +49 -0
- package/src/api/evm/EVMSignMessageEIP712.ts +56 -0
- package/src/api/evm/EVMSignTransaction.ts +141 -0
- package/src/api/evm/EVMSignTypedData.ts +477 -0
- package/src/api/evm/EVMVerifyMessage.ts +46 -0
- package/src/api/evm/latest/getAddress.ts +13 -0
- package/src/api/evm/latest/getPublicKey.ts +17 -0
- package/src/api/evm/latest/signMessage.ts +19 -0
- package/src/api/evm/latest/signTransaction.ts +303 -0
- package/src/api/evm/latest/signTypedData.ts +34 -0
- package/src/api/evm/latest/signTypedHash.ts +46 -0
- package/src/api/evm/latest/verifyMessage.ts +15 -0
- package/src/api/evm/legacyV1/getAddress.ts +16 -0
- package/src/api/evm/legacyV1/getPublicKey.ts +20 -0
- package/src/api/evm/legacyV1/signMessage.ts +22 -0
- package/src/api/evm/legacyV1/signTransaction.ts +37 -0
- package/src/api/evm/legacyV1/signTypedData.ts +37 -0
- package/src/api/evm/legacyV1/signTypedHash.ts +50 -0
- package/src/api/evm/legacyV1/verifyMessage.ts +19 -0
- package/src/api/filecoin/FilecoinGetAddress.ts +80 -0
- package/src/api/filecoin/FilecoinSignTransaction.ts +57 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +476 -0
- package/src/api/firmware/bootloaderHelper.ts +46 -0
- package/src/api/firmware/getBinary.ts +99 -0
- package/src/api/firmware/releaseHelper.ts +78 -0
- package/src/api/firmware/updateBootloader.ts +82 -0
- package/src/api/firmware/uploadFirmware.ts +541 -0
- package/src/api/helpers/batchGetPublickeys.ts +84 -0
- package/src/api/helpers/bigNumberUtils.ts +58 -0
- package/src/api/helpers/hexUtils.ts +111 -0
- package/src/api/helpers/paramsValidator.ts +165 -0
- package/src/api/helpers/pathUtils.ts +145 -0
- package/src/api/helpers/stringUtils.ts +11 -0
- package/src/api/helpers/typeNameUtils.ts +137 -0
- package/src/api/index.ts +161 -0
- package/src/api/kaspa/KaspaGetAddress.ts +103 -0
- package/src/api/kaspa/KaspaSignTransaction.ts +182 -0
- package/src/api/kaspa/helpers/BufferWriter.ts +177 -0
- package/src/api/kaspa/helpers/HashWriter.ts +74 -0
- package/src/api/kaspa/helpers/SignatureType.ts +7 -0
- package/src/api/kaspa/helpers/TransferSerialize.ts +144 -0
- package/src/api/lightning/LnurlAuth.ts +52 -0
- package/src/api/near/NearGetAddress.ts +75 -0
- package/src/api/near/NearSignTransaction.ts +46 -0
- package/src/api/nem/NEMGetAddress.ts +72 -0
- package/src/api/nem/NEMSignTransaction.ts +251 -0
- package/src/api/neo/NeoGetAddress.ts +80 -0
- package/src/api/neo/NeoSignTransaction.ts +59 -0
- package/src/api/nervos/NervosGetAddress.ts +80 -0
- package/src/api/nervos/NervosSignTransaction.ts +116 -0
- package/src/api/nexa/NexaGetAddress.ts +88 -0
- package/src/api/nexa/NexaSignTransaction.ts +107 -0
- package/src/api/nostr/NostrDecryptMessage.ts +57 -0
- package/src/api/nostr/NostrEncryptMessage.ts +57 -0
- package/src/api/nostr/NostrGetPublicKey.ts +74 -0
- package/src/api/nostr/NostrSignEvent.ts +65 -0
- package/src/api/nostr/NostrSignSchnorr.ts +52 -0
- package/src/api/nostr/helper/index.ts +28 -0
- package/src/api/polkadot/PolkadotGetAddress.ts +83 -0
- package/src/api/polkadot/PolkadotSignTransaction.ts +53 -0
- package/src/api/polkadot/networks.ts +72 -0
- package/src/api/scdo/ScdoGetAddress.ts +76 -0
- package/src/api/scdo/ScdoSignMessage.ts +45 -0
- package/src/api/scdo/ScdoSignTransaction.ts +106 -0
- package/src/api/solana/SolGetAddress.ts +68 -0
- package/src/api/solana/SolSignMessage.ts +61 -0
- package/src/api/solana/SolSignOffchainMessage.ts +61 -0
- package/src/api/solana/SolSignTransaction.ts +108 -0
- package/src/api/starcoin/StarcoinGetAddress.ts +69 -0
- package/src/api/starcoin/StarcoinGetPublicKey.ts +70 -0
- package/src/api/starcoin/StarcoinSignMessage.ts +42 -0
- package/src/api/starcoin/StarcoinSignTransaction.ts +38 -0
- package/src/api/starcoin/StarcoinVerifyMessage.ts +35 -0
- package/src/api/stellar/StellarGetAddress.ts +68 -0
- package/src/api/stellar/StellarSignTransaction.ts +220 -0
- package/src/api/sui/SuiGetAddress.ts +117 -0
- package/src/api/sui/SuiGetPublicKey.ts +66 -0
- package/src/api/sui/SuiSignMessage.ts +48 -0
- package/src/api/sui/SuiSignTransaction.ts +126 -0
- package/src/api/sui/normalize.ts +28 -0
- package/src/api/test/TestInitializeDeviceDuration.ts +22 -0
- package/src/api/ton/TonGetAddress.ts +96 -0
- package/src/api/ton/TonSignMessage.ts +217 -0
- package/src/api/ton/TonSignProof.ts +62 -0
- package/src/api/tron/TronGetAddress.ts +75 -0
- package/src/api/tron/TronSignMessage.ts +89 -0
- package/src/api/tron/TronSignTransaction.ts +214 -0
- package/src/api/u2f/GetNextU2FCounter.ts +15 -0
- package/src/api/u2f/SetU2FCounter.ts +19 -0
- package/src/api/utils.ts +23 -0
- package/src/api/xrp/XrpGetAddress.ts +96 -0
- package/src/api/xrp/XrpSignTransaction.ts +71 -0
- package/src/constants/errors.ts +15 -0
- package/src/constants/index.ts +2 -0
- package/src/constants/ui-request.ts +3 -0
- package/src/core/RequestQueue.ts +134 -0
- package/src/core/index.ts +1320 -0
- package/src/data/coins/bitcoin.json +44 -0
- package/src/data/config.ts +25 -0
- package/src/data/messages/messages.json +13167 -0
- package/src/data/messages/messages_legacy_v1.json +10282 -0
- package/src/data-manager/CoinManager.ts +31 -0
- package/src/data-manager/DataManager.ts +499 -0
- package/src/data-manager/MessagesConfig.ts +28 -0
- package/src/data-manager/TransportManager.ts +140 -0
- package/src/data-manager/connectSettings.ts +121 -0
- package/src/data-manager/index.ts +3 -0
- package/src/device/Device.ts +884 -0
- package/src/device/DeviceCommands.ts +631 -0
- package/src/device/DeviceConnector.ts +124 -0
- package/src/device/DeviceList.ts +39 -0
- package/src/device/DevicePool.ts +266 -0
- package/src/events/call.ts +95 -0
- package/src/events/core.ts +65 -0
- package/src/events/device.ts +92 -0
- package/src/events/firmware.ts +43 -0
- package/src/events/iframe.ts +55 -0
- package/src/events/index.ts +10 -0
- package/src/events/log.ts +23 -0
- package/src/events/logBlockEvent.ts +6 -0
- package/src/events/ui-promise.ts +14 -0
- package/src/events/ui-request.ts +216 -0
- package/src/events/ui-response.ts +59 -0
- package/src/events/utils.ts +19 -0
- package/src/index.ts +70 -0
- package/src/inject.ts +408 -0
- package/src/lowLevelInject.ts +61 -0
- package/src/topLevelInject.ts +62 -0
- package/src/types/api/alephiumGetAddress.ts +31 -0
- package/src/types/api/alephiumSignMessage.ts +14 -0
- package/src/types/api/alephiumSignTransaction.ts +18 -0
- package/src/types/api/algoGetAddress.ts +23 -0
- package/src/types/api/algoSignTransaction.ts +17 -0
- package/src/types/api/allNetworkGetAddress.ts +130 -0
- package/src/types/api/aptosGetAddress.ts +28 -0
- package/src/types/api/aptosGetPublicKey.ts +27 -0
- package/src/types/api/aptosSignInMessage.ts +17 -0
- package/src/types/api/aptosSignMessage.ts +26 -0
- package/src/types/api/aptosSignTransaction.ts +18 -0
- package/src/types/api/benfenGetAddress.ts +24 -0
- package/src/types/api/benfenGetPublicKey.ts +23 -0
- package/src/types/api/benfenSignMessage.ts +13 -0
- package/src/types/api/benfenSignTransaction.ts +19 -0
- package/src/types/api/btcGetAddress.ts +26 -0
- package/src/types/api/btcGetPublicKey.ts +26 -0
- package/src/types/api/btcSignMessage.ts +16 -0
- package/src/types/api/btcSignPsbt.ts +13 -0
- package/src/types/api/btcSignTransaction.ts +98 -0
- package/src/types/api/btcVerifyMessage.ts +15 -0
- package/src/types/api/cardano.ts +212 -0
- package/src/types/api/cardanoGetAddress.ts +49 -0
- package/src/types/api/cardanoGetPublicKey.ts +33 -0
- package/src/types/api/cardanoSignMessage.ts +31 -0
- package/src/types/api/cardanoSignTransaction.ts +8 -0
- package/src/types/api/checkAllFirmwareRelease.ts +34 -0
- package/src/types/api/checkBLEFirmwareRelease.ts +15 -0
- package/src/types/api/checkBootloaderRelease.ts +19 -0
- package/src/types/api/checkBridgeRelease.ts +14 -0
- package/src/types/api/checkBridgeStatus.ts +3 -0
- package/src/types/api/checkFirmwareRelease.ts +23 -0
- package/src/types/api/checkFirmwareTypeAvailable.ts +12 -0
- package/src/types/api/cipherKeyValue.ts +28 -0
- package/src/types/api/confluxGetAddress.ts +24 -0
- package/src/types/api/confluxSignMessage.ts +13 -0
- package/src/types/api/confluxSignMessageCIP23.ts +14 -0
- package/src/types/api/confluxSignTransaction.ts +32 -0
- package/src/types/api/cosmosGetAddress.ts +24 -0
- package/src/types/api/cosmosGetPublicKey.ts +28 -0
- package/src/types/api/cosmosSignTransaction.ts +17 -0
- package/src/types/api/deviceBackup.ts +4 -0
- package/src/types/api/deviceCancel.ts +4 -0
- package/src/types/api/deviceChangePin.ts +11 -0
- package/src/types/api/deviceFlags.ts +11 -0
- package/src/types/api/deviceFullyUploadResource.ts +15 -0
- package/src/types/api/deviceLock.ts +4 -0
- package/src/types/api/deviceRebootToBoardloader.ts +6 -0
- package/src/types/api/deviceRebootToBootloader.ts +4 -0
- package/src/types/api/deviceRecovery.ts +19 -0
- package/src/types/api/deviceReset.ts +20 -0
- package/src/types/api/deviceSettings.ts +23 -0
- package/src/types/api/deviceSupportFeatures.ts +6 -0
- package/src/types/api/deviceUnlock.ts +4 -0
- package/src/types/api/deviceUpdateBootloader.ts +13 -0
- package/src/types/api/deviceUpdateReboot.ts +3 -0
- package/src/types/api/deviceUploadResource.ts +21 -0
- package/src/types/api/deviceVerify.ts +15 -0
- package/src/types/api/deviceWipe.ts +4 -0
- package/src/types/api/dnxGetAddress.ts +23 -0
- package/src/types/api/dnxSignTransaction.ts +36 -0
- package/src/types/api/event.ts +8 -0
- package/src/types/api/evmGetAddress.ts +24 -0
- package/src/types/api/evmGetPublicKey.ts +36 -0
- package/src/types/api/evmSignMessage.ts +14 -0
- package/src/types/api/evmSignMessageEIP712.ts +14 -0
- package/src/types/api/evmSignTransaction.ts +80 -0
- package/src/types/api/evmSignTypedData.ts +42 -0
- package/src/types/api/evmVerifyMessage.ts +15 -0
- package/src/types/api/export.ts +194 -0
- package/src/types/api/filecoinGetAddress.ts +24 -0
- package/src/types/api/filecoinSignTransaction.ts +24 -0
- package/src/types/api/firmwareUpdate.ts +66 -0
- package/src/types/api/getFeatures.ts +4 -0
- package/src/types/api/getLogs.ts +3 -0
- package/src/types/api/getNextU2FCounter.ts +7 -0
- package/src/types/api/getOnetokenFeatures.ts +7 -0
- package/src/types/api/getPassphraseState.ts +6 -0
- package/src/types/api/index.ts +404 -0
- package/src/types/api/init.ts +11 -0
- package/src/types/api/kaspaGetAddress.ts +26 -0
- package/src/types/api/kaspaSignTransaction.ts +44 -0
- package/src/types/api/lnurlAuth.ts +22 -0
- package/src/types/api/nearGetAddress.ts +23 -0
- package/src/types/api/nearSignTransaction.ts +13 -0
- package/src/types/api/nemGetAddress.ts +24 -0
- package/src/types/api/nemSignTransaction.ts +118 -0
- package/src/types/api/neoGetAddress.ts +24 -0
- package/src/types/api/neoSignTransaction.ts +18 -0
- package/src/types/api/nervosGetAddress.ts +24 -0
- package/src/types/api/nervosSignTransaction.ts +19 -0
- package/src/types/api/nexaGetAddress.ts +26 -0
- package/src/types/api/nexaSignTransaction.ts +28 -0
- package/src/types/api/nostrDecryptMessage.ts +25 -0
- package/src/types/api/nostrEncryptMessage.ts +25 -0
- package/src/types/api/nostrGetPublicKey.ts +28 -0
- package/src/types/api/nostrSignEvent.ts +52 -0
- package/src/types/api/nostrSignSchnorr.ts +22 -0
- package/src/types/api/polkadotGetAddress.ts +30 -0
- package/src/types/api/polkadotSignTransaction.ts +19 -0
- package/src/types/api/promptWebDeviceAccess.ts +6 -0
- package/src/types/api/scdoGetAddress.ts +23 -0
- package/src/types/api/scdoSignMessage.ts +13 -0
- package/src/types/api/scdoSignTransaction.ts +24 -0
- package/src/types/api/searchDevices.ts +4 -0
- package/src/types/api/setU2FCounter.ts +7 -0
- package/src/types/api/solGetAddress.ts +23 -0
- package/src/types/api/solSignMessage.ts +17 -0
- package/src/types/api/solSignOffchainMessage.ts +24 -0
- package/src/types/api/solSignTransaction.ts +27 -0
- package/src/types/api/starcoinGetAddress.ts +23 -0
- package/src/types/api/starcoinGetPublicKey.ts +23 -0
- package/src/types/api/starcoinSignMessage.ts +13 -0
- package/src/types/api/starcoinSignTransaction.ts +13 -0
- package/src/types/api/starcoinVerifyMessage.ts +14 -0
- package/src/types/api/stellarGetAddress.ts +23 -0
- package/src/types/api/stellarSignTransaction.ts +154 -0
- package/src/types/api/suiGetAddress.ts +28 -0
- package/src/types/api/suiGetPublicKey.ts +27 -0
- package/src/types/api/suiSignMessage.ts +13 -0
- package/src/types/api/suiSignTransaction.ts +17 -0
- package/src/types/api/testInitializeDeviceDuration.ts +6 -0
- package/src/types/api/tonGetAddress.ts +34 -0
- package/src/types/api/tonSignMessage.ts +42 -0
- package/src/types/api/tonSignProof.ts +25 -0
- package/src/types/api/tronGetAddress.ts +23 -0
- package/src/types/api/tronSignMessage.ts +14 -0
- package/src/types/api/tronSignTransaction.ts +89 -0
- package/src/types/api/uiResponse.ts +3 -0
- package/src/types/api/xrpGetAddress.ts +28 -0
- package/src/types/api/xrpSignTransaction.ts +29 -0
- package/src/types/device.ts +194 -0
- package/src/types/firmware.ts +41 -0
- package/src/types/global.d.ts +3 -0
- package/src/types/index.ts +5 -0
- package/src/types/params.ts +64 -0
- package/src/types/settings.ts +144 -0
- package/src/utils/arrayUtils.ts +7 -0
- package/src/utils/assets.ts +5 -0
- package/src/utils/bridgeUpdate.ts +80 -0
- package/src/utils/capabilitieUtils.ts +12 -0
- package/src/utils/deviceFeaturesUtils.ts +352 -0
- package/src/utils/deviceInfoUtils.ts +167 -0
- package/src/utils/deviceSettings.ts +109 -0
- package/src/utils/deviceVersionUtils.ts +79 -0
- package/src/utils/findDefectiveBatchDevice.ts +39 -0
- package/src/utils/getMutex.ts +41 -0
- package/src/utils/getSynchronize.ts +25 -0
- package/src/utils/homescreen.ts +345 -0
- package/src/utils/index.ts +44 -0
- package/src/utils/logger.ts +190 -0
- package/src/utils/networkUtils.ts +25 -0
- package/src/utils/patch.ts +14 -0
- package/src/utils/promiseUtils.ts +4 -0
- package/src/utils/release.ts +42 -0
- package/src/utils/semver.test.js +53 -0
- package/src/utils/tracing.ts +238 -0
- package/src/utils/versionUtils.ts +120 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { serializedPath, validatePath } from '../helpers/pathUtils';
|
|
2
|
+
import { BaseMethod } from '../BaseMethod';
|
|
3
|
+
import { validateParams } from '../helpers/paramsValidator';
|
|
4
|
+
import { formatAnyHex } from '../helpers/hexUtils';
|
|
5
|
+
|
|
6
|
+
import type { FilecoinSignTransactionParams } from '../../types';
|
|
7
|
+
import type { FilecoinSignTx as HardwareFilecoinSignTx } from '@onetokenfe/hd-transport';
|
|
8
|
+
|
|
9
|
+
export default class FilecoinSignTransaction extends BaseMethod<HardwareFilecoinSignTx> {
|
|
10
|
+
hasBundle = false;
|
|
11
|
+
|
|
12
|
+
init() {
|
|
13
|
+
this.checkDeviceId = true;
|
|
14
|
+
this.allowDeviceMode = [...this.allowDeviceMode];
|
|
15
|
+
|
|
16
|
+
// check payload
|
|
17
|
+
validateParams(this.payload, [
|
|
18
|
+
{ name: 'path', required: true },
|
|
19
|
+
{ name: 'rawTx', type: 'hexString', required: true },
|
|
20
|
+
{ name: 'isTestnet', type: 'boolean' },
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
// init params
|
|
24
|
+
const { path, rawTx, isTestnet } = this.payload as FilecoinSignTransactionParams;
|
|
25
|
+
const addressN = validatePath(path, 3);
|
|
26
|
+
|
|
27
|
+
this.params = {
|
|
28
|
+
address_n: addressN,
|
|
29
|
+
raw_tx: formatAnyHex(rawTx),
|
|
30
|
+
testnet: isTestnet,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getVersionRange() {
|
|
35
|
+
return {
|
|
36
|
+
model_mini: {
|
|
37
|
+
min: '2.10.0',
|
|
38
|
+
},
|
|
39
|
+
model_touch: {
|
|
40
|
+
min: '3.5.0',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async run() {
|
|
46
|
+
const res = await this.device.commands.typedCall('FilecoinSignTx', 'FilecoinSignedTx', {
|
|
47
|
+
...this.params,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const { signature } = res.message;
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
path: serializedPath(this.params.address_n),
|
|
54
|
+
signature,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EDeviceType,
|
|
3
|
+
ERRORS,
|
|
4
|
+
HardwareError,
|
|
5
|
+
HardwareErrorCode,
|
|
6
|
+
createDeferred,
|
|
7
|
+
} from '@onetokenfe/hd-shared';
|
|
8
|
+
|
|
9
|
+
import { FirmwareUpdateTipMessage, UI_REQUEST, createUiMessage } from '../../events/ui-request';
|
|
10
|
+
import { DevicePool } from '../../device/DevicePool';
|
|
11
|
+
import { LoggerNames, getDeviceType, getDeviceUUID, getLogger, wait } from '../../utils';
|
|
12
|
+
import { DeviceModelToTypes } from '../../types';
|
|
13
|
+
import { DataManager } from '../../data-manager';
|
|
14
|
+
import { BaseMethod } from '../BaseMethod';
|
|
15
|
+
import { DEVICE } from '../../events';
|
|
16
|
+
|
|
17
|
+
import type {
|
|
18
|
+
IFirmwareUpdateProgressType,
|
|
19
|
+
IFirmwareUpdateTipMessage,
|
|
20
|
+
} from '../../events/ui-request';
|
|
21
|
+
import type { PROTO } from '../../constants';
|
|
22
|
+
import type { RebootType } from '@onetokenfe/hd-transport';
|
|
23
|
+
import type { Deferred } from '@onetokenfe/hd-shared';
|
|
24
|
+
import type { KnownDevice } from '../../types';
|
|
25
|
+
import type { TypedResponseMessage } from '../../device/DeviceCommands';
|
|
26
|
+
|
|
27
|
+
const Log = getLogger(LoggerNames.Method);
|
|
28
|
+
const SESSION_ERROR = 'session not found';
|
|
29
|
+
const FIRMWARE_UPDATE_CONFIRM = 'Firmware install confirmed';
|
|
30
|
+
|
|
31
|
+
const isDeviceDisconnectedError = (error: unknown) => {
|
|
32
|
+
const message = error instanceof Error ? error.message : String(error ?? '');
|
|
33
|
+
return (
|
|
34
|
+
message.includes('device was disconnected') ||
|
|
35
|
+
message.includes('transferIn') ||
|
|
36
|
+
message.includes('USBDevice')
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
41
|
+
checkPromise: Deferred<any> | null = null;
|
|
42
|
+
|
|
43
|
+
init(): void {}
|
|
44
|
+
|
|
45
|
+
run(): Promise<any> {
|
|
46
|
+
return Promise.resolve();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
isBleReconnect(): boolean {
|
|
50
|
+
const env = DataManager.getSettings('env');
|
|
51
|
+
return this.payload.connectId && DataManager.isBleConnect(env);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @description Post the tip message
|
|
56
|
+
* @param message The message to be posted, defined in IFirmwareUpdateTipMessage
|
|
57
|
+
*/
|
|
58
|
+
postTipMessage = (message: IFirmwareUpdateTipMessage) => {
|
|
59
|
+
this.postMessage(
|
|
60
|
+
createUiMessage(UI_REQUEST.FIRMWARE_TIP, {
|
|
61
|
+
device: this.device.toMessageObject() as KnownDevice,
|
|
62
|
+
data: {
|
|
63
|
+
message,
|
|
64
|
+
},
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @description Post the processing message
|
|
71
|
+
* @param type
|
|
72
|
+
*/
|
|
73
|
+
postProcessingMessage = (type: 'firmware' | 'ble' | 'bootloader' | 'resource') => {
|
|
74
|
+
this.postMessage(
|
|
75
|
+
createUiMessage(UI_REQUEST.FIRMWARE_PROCESSING, {
|
|
76
|
+
type,
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @description Post the progress message
|
|
83
|
+
* @param progress Post the percentage of the progress
|
|
84
|
+
*/
|
|
85
|
+
postProgressMessage = (progress: number, progressType: IFirmwareUpdateProgressType) => {
|
|
86
|
+
this.postMessage(
|
|
87
|
+
createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
|
|
88
|
+
device: this.device.toMessageObject() as KnownDevice,
|
|
89
|
+
progress,
|
|
90
|
+
progressType,
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
protected async _promptDeviceInBootloaderForWebDevice() {
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
if (this.device.listenerCount(DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE) > 0) {
|
|
98
|
+
this.device.emit(
|
|
99
|
+
DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE,
|
|
100
|
+
this.device,
|
|
101
|
+
(err, deviceId) => {
|
|
102
|
+
if (err) {
|
|
103
|
+
reject(err);
|
|
104
|
+
} else {
|
|
105
|
+
resolve(deviceId);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
protected async _promptDeviceForSwitchFirmwareWebDevice() {
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
115
|
+
if (this.device.listenerCount(DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE) > 0) {
|
|
116
|
+
this.device.emit(
|
|
117
|
+
DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE,
|
|
118
|
+
this.device,
|
|
119
|
+
(err, deviceId) => {
|
|
120
|
+
if (err) {
|
|
121
|
+
reject(err);
|
|
122
|
+
} else {
|
|
123
|
+
resolve(deviceId);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
checkDeviceToBootloader(connectId: string | undefined) {
|
|
132
|
+
this.checkPromise = createDeferred();
|
|
133
|
+
const env = DataManager.getSettings('env');
|
|
134
|
+
const isBleReconnect = connectId && DataManager.isBleConnect(env);
|
|
135
|
+
|
|
136
|
+
Log.log('FirmwareUpdateBaseMethod [checkDeviceToBootloader] isBleReconnect: ', isBleReconnect);
|
|
137
|
+
|
|
138
|
+
// check device goto bootloader mode
|
|
139
|
+
let isFirstCheck = true;
|
|
140
|
+
let checkCount = 0;
|
|
141
|
+
// eslint-disable-next-line prefer-const
|
|
142
|
+
let timeoutTimer: ReturnType<typeof setTimeout> | undefined;
|
|
143
|
+
|
|
144
|
+
const isTouchOrProDevice =
|
|
145
|
+
getDeviceType(this?.device?.features) === EDeviceType.Touch ||
|
|
146
|
+
getDeviceType(this?.device?.features) === EDeviceType.Pro;
|
|
147
|
+
|
|
148
|
+
const intervalTimer: ReturnType<typeof setInterval> | undefined = setInterval(
|
|
149
|
+
async () => {
|
|
150
|
+
checkCount += 1;
|
|
151
|
+
Log.log('FirmwareUpdateBaseMethod [checkDeviceToBootloader] isFirstCheck: ', isFirstCheck);
|
|
152
|
+
if (isTouchOrProDevice && isFirstCheck) {
|
|
153
|
+
isFirstCheck = false;
|
|
154
|
+
Log.log('FirmwareUpdateBaseMethod [checkDeviceToBootloader] wait 3000ms');
|
|
155
|
+
await wait(3000);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (
|
|
159
|
+
checkCount > 4 &&
|
|
160
|
+
DataManager.isBrowserWebUsb(DataManager.getSettings('env')) &&
|
|
161
|
+
!this.payload.skipWebDevicePrompt
|
|
162
|
+
) {
|
|
163
|
+
clearInterval(intervalTimer);
|
|
164
|
+
clearTimeout(timeoutTimer);
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
this.postTipMessage(FirmwareUpdateTipMessage.SelectDeviceInBootloaderForWebDevice);
|
|
168
|
+
const confirmed = await this._promptDeviceInBootloaderForWebDevice();
|
|
169
|
+
if (confirmed) {
|
|
170
|
+
await this._checkDeviceInBootloaderMode(connectId, intervalTimer, timeoutTimer);
|
|
171
|
+
}
|
|
172
|
+
} catch (e) {
|
|
173
|
+
Log.log(
|
|
174
|
+
'FirmwareUpdateBaseMethod [checkDeviceToBootloader] _promptDeviceInBootloaderForWebDevice failed: ',
|
|
175
|
+
e
|
|
176
|
+
);
|
|
177
|
+
this.checkPromise?.reject(e);
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (isBleReconnect) {
|
|
183
|
+
try {
|
|
184
|
+
await this.device.deviceConnector?.acquire(
|
|
185
|
+
this.device.originalDescriptor.id,
|
|
186
|
+
null,
|
|
187
|
+
true
|
|
188
|
+
);
|
|
189
|
+
await this.device.initialize();
|
|
190
|
+
if (this.device.features?.bootloader_mode) {
|
|
191
|
+
clearInterval(intervalTimer);
|
|
192
|
+
this.checkPromise?.resolve(true);
|
|
193
|
+
}
|
|
194
|
+
} catch (e) {
|
|
195
|
+
// ignore error because of device is not connected
|
|
196
|
+
Log.log('catch Bluetooth error when device is restarting: ', e);
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
await this._checkDeviceInBootloaderMode(connectId, intervalTimer, timeoutTimer);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
isBleReconnect ? 3000 : 2000
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
// check goto bootloader mode timeout and throw error
|
|
206
|
+
timeoutTimer = setTimeout(() => {
|
|
207
|
+
if (this.checkPromise) {
|
|
208
|
+
clearInterval(intervalTimer);
|
|
209
|
+
this.checkPromise.reject(new Error());
|
|
210
|
+
}
|
|
211
|
+
}, 30000);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private async _checkDeviceInBootloaderMode(
|
|
215
|
+
connectId: string | undefined,
|
|
216
|
+
intervalTimer?: ReturnType<typeof setInterval>,
|
|
217
|
+
timeoutTimer?: ReturnType<typeof setTimeout>
|
|
218
|
+
) {
|
|
219
|
+
const deviceDiff = await this.device.deviceConnector?.enumerate();
|
|
220
|
+
const devicesDescriptor = deviceDiff?.descriptors ?? [];
|
|
221
|
+
const { deviceList } = await DevicePool.getDevices(devicesDescriptor, connectId);
|
|
222
|
+
|
|
223
|
+
if (deviceList.length === 1 && deviceList[0]?.features?.bootloader_mode) {
|
|
224
|
+
// should update current device from cache
|
|
225
|
+
// because device was reboot and had some new requests
|
|
226
|
+
this.device.updateFromCache(deviceList[0]);
|
|
227
|
+
this.device.commands.disposed = false;
|
|
228
|
+
|
|
229
|
+
if (intervalTimer) clearInterval(intervalTimer);
|
|
230
|
+
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
231
|
+
this.checkPromise?.resolve(true);
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async enterBootloaderMode() {
|
|
238
|
+
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
239
|
+
if (this.device.features && !this.device.features.bootloader_mode) {
|
|
240
|
+
const uuid = getDeviceUUID(this.device.features);
|
|
241
|
+
const deviceType = getDeviceType(this.device.features);
|
|
242
|
+
// auto go to bootloader mode
|
|
243
|
+
try {
|
|
244
|
+
this.postTipMessage(FirmwareUpdateTipMessage.AutoRebootToBootloader);
|
|
245
|
+
const bootRes = await typedCall('DeviceBackToBoot', 'Success');
|
|
246
|
+
// @ts-expect-error
|
|
247
|
+
if (bootRes.type === 'CallMethodError') {
|
|
248
|
+
throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure);
|
|
249
|
+
}
|
|
250
|
+
this.postTipMessage(FirmwareUpdateTipMessage.GoToBootloaderSuccess);
|
|
251
|
+
this.checkDeviceToBootloader(this.payload.connectId);
|
|
252
|
+
|
|
253
|
+
// force clean classic device cache so that the device can initialize again
|
|
254
|
+
if (DeviceModelToTypes.model_classic.includes(deviceType)) {
|
|
255
|
+
DevicePool.clearDeviceCache(uuid);
|
|
256
|
+
}
|
|
257
|
+
delete DevicePool.devicesCache[''];
|
|
258
|
+
await this.checkPromise?.promise;
|
|
259
|
+
this.checkPromise = null;
|
|
260
|
+
/**
|
|
261
|
+
* Touch 1 with bootloader v2.5.0 issue: BLE chip need more time for looking up name, here change the delay time to 3000ms after rebooting.
|
|
262
|
+
*/
|
|
263
|
+
const isTouch = DeviceModelToTypes.model_touch.includes(deviceType);
|
|
264
|
+
await wait(isTouch ? 3000 : 1500);
|
|
265
|
+
await this.device.acquire();
|
|
266
|
+
return true;
|
|
267
|
+
} catch (e) {
|
|
268
|
+
if (e instanceof HardwareError) {
|
|
269
|
+
return Promise.reject(e);
|
|
270
|
+
}
|
|
271
|
+
console.log('auto go to bootloader mode failed: ', e);
|
|
272
|
+
return Promise.reject(
|
|
273
|
+
ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateAutoEnterBootFailure)
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* @description The instruction that triggers the update process
|
|
281
|
+
* @param path The path of the file to be updated
|
|
282
|
+
*/
|
|
283
|
+
async startEmmcFirmwareUpdate({ path }: { path: string }) {
|
|
284
|
+
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
285
|
+
let updateResponse: TypedResponseMessage<'Success'>;
|
|
286
|
+
try {
|
|
287
|
+
updateResponse = await typedCall('FirmwareUpdateEmmc', 'Success', {
|
|
288
|
+
path,
|
|
289
|
+
reboot_on_success: true,
|
|
290
|
+
});
|
|
291
|
+
} catch (error) {
|
|
292
|
+
if (isDeviceDisconnectedError(error)) {
|
|
293
|
+
Log.log('Rebooting device');
|
|
294
|
+
updateResponse = {
|
|
295
|
+
type: 'Success',
|
|
296
|
+
message: { message: FIRMWARE_UPDATE_CONFIRM },
|
|
297
|
+
};
|
|
298
|
+
} else {
|
|
299
|
+
throw error;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (updateResponse.type !== 'Success') {
|
|
303
|
+
throw ERRORS.TypedError(HardwareErrorCode.FirmwareError, 'firmware update error');
|
|
304
|
+
}
|
|
305
|
+
this.postTipMessage(FirmwareUpdateTipMessage.FirmwareUpdating);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* @description Create the updates folder if it does not exist
|
|
310
|
+
* @param path The path of the folder to be created
|
|
311
|
+
*/
|
|
312
|
+
async createUpdatesFolderIfNotExists(path: string) {
|
|
313
|
+
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
314
|
+
await typedCall('EmmcDirMake', 'Success', {
|
|
315
|
+
path,
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* @param payload The payload of the file to be updated
|
|
321
|
+
* @param filePath The path of the file to be updated
|
|
322
|
+
*/
|
|
323
|
+
async emmcCommonUpdateProcess({
|
|
324
|
+
payload,
|
|
325
|
+
filePath,
|
|
326
|
+
processedSize,
|
|
327
|
+
totalSize,
|
|
328
|
+
}: PROTO.FirmwareUpload & {
|
|
329
|
+
filePath: string;
|
|
330
|
+
processedSize?: number;
|
|
331
|
+
totalSize?: number;
|
|
332
|
+
}) {
|
|
333
|
+
if (!filePath.startsWith('0:')) {
|
|
334
|
+
throw new Error('filePath must start with 0:');
|
|
335
|
+
}
|
|
336
|
+
const env = DataManager.getSettings('env');
|
|
337
|
+
const perPackageSize = DataManager.isBleConnect(env) ? 16 : 128;
|
|
338
|
+
const chunkSize = 1024 * perPackageSize;
|
|
339
|
+
const totalChunks = Math.ceil(payload.byteLength / chunkSize);
|
|
340
|
+
let offset = 0;
|
|
341
|
+
let currentFileProcessed = 0;
|
|
342
|
+
|
|
343
|
+
for (let i = 0; i < totalChunks; i++) {
|
|
344
|
+
const chunkStart = i * chunkSize;
|
|
345
|
+
const chunkEnd = Math.min(chunkStart + chunkSize, payload.byteLength);
|
|
346
|
+
const chunkLength = chunkEnd - chunkStart;
|
|
347
|
+
const chunk = payload.slice(chunkStart, chunkEnd);
|
|
348
|
+
const overwrite = i === 0;
|
|
349
|
+
|
|
350
|
+
// Calculate progress based on whether we're tracking overall progress or single file progress
|
|
351
|
+
let progress: number;
|
|
352
|
+
if (totalSize !== undefined && processedSize !== undefined) {
|
|
353
|
+
currentFileProcessed = processedSize + chunkEnd;
|
|
354
|
+
progress = Math.min(Math.ceil((currentFileProcessed / totalSize) * 100), 99);
|
|
355
|
+
} else {
|
|
356
|
+
progress = Math.min(Math.ceil(((i + 1) / totalChunks) * 100), 99);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const writeRes = await this.emmcFileWriteWithRetry(
|
|
360
|
+
filePath,
|
|
361
|
+
chunkLength,
|
|
362
|
+
offset,
|
|
363
|
+
chunk,
|
|
364
|
+
overwrite,
|
|
365
|
+
progress
|
|
366
|
+
);
|
|
367
|
+
// @ts-expect-error
|
|
368
|
+
offset += writeRes.message.processed_byte;
|
|
369
|
+
this.postProgressMessage(progress, 'transferData');
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Return processed size only if we're tracking overall progress
|
|
373
|
+
return totalSize !== undefined ? (processedSize ?? 0) + payload.byteLength : 0;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
async emmcFileWriteWithRetry(
|
|
377
|
+
filePath: string,
|
|
378
|
+
chunkLength: number,
|
|
379
|
+
offset: number,
|
|
380
|
+
chunk: ArrayBuffer | Buffer,
|
|
381
|
+
overwrite: boolean,
|
|
382
|
+
progress: number | null
|
|
383
|
+
) {
|
|
384
|
+
const writeFunc = async () => {
|
|
385
|
+
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
386
|
+
// @ts-expect-error
|
|
387
|
+
const writeRes = await typedCall('EmmcFileWrite', 'EmmcFile', {
|
|
388
|
+
file: {
|
|
389
|
+
path: filePath,
|
|
390
|
+
len: chunkLength,
|
|
391
|
+
offset,
|
|
392
|
+
data: chunk,
|
|
393
|
+
},
|
|
394
|
+
overwrite,
|
|
395
|
+
append: offset !== 0,
|
|
396
|
+
ui_percentage: progress,
|
|
397
|
+
});
|
|
398
|
+
if (writeRes.type !== 'EmmcFile') {
|
|
399
|
+
// @ts-expect-error
|
|
400
|
+
if (writeRes.type === 'CallMethodError') {
|
|
401
|
+
if (((writeRes as any).message.error ?? '').indexOf(SESSION_ERROR) > -1) {
|
|
402
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, SESSION_ERROR);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
throw ERRORS.TypedError(
|
|
406
|
+
HardwareErrorCode.EmmcFileWriteFirmwareError,
|
|
407
|
+
'transfer data error'
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
return writeRes;
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
let retryCount = 10;
|
|
414
|
+
while (retryCount > 0) {
|
|
415
|
+
try {
|
|
416
|
+
const result = await writeFunc();
|
|
417
|
+
return result;
|
|
418
|
+
} catch (error) {
|
|
419
|
+
Log.error(`emmcWrite error: `, error);
|
|
420
|
+
retryCount--;
|
|
421
|
+
if (retryCount === 0) {
|
|
422
|
+
throw ERRORS.TypedError(
|
|
423
|
+
HardwareErrorCode.EmmcFileWriteFirmwareError,
|
|
424
|
+
'transfer data error'
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
const env = DataManager.getSettings('env');
|
|
428
|
+
if (DataManager.isBleConnect(env)) {
|
|
429
|
+
await wait(3000);
|
|
430
|
+
await this.device.deviceConnector?.acquire(this.device.originalDescriptor.id, null, true);
|
|
431
|
+
await this.device.initialize();
|
|
432
|
+
} else if (
|
|
433
|
+
error?.message?.indexOf(SESSION_ERROR) > -1 ||
|
|
434
|
+
error?.response?.data?.indexOf(SESSION_ERROR) > -1
|
|
435
|
+
) {
|
|
436
|
+
const deviceDiff = await this.device.deviceConnector?.enumerate();
|
|
437
|
+
const devicesDescriptor = deviceDiff?.descriptors ?? [];
|
|
438
|
+
const { deviceList } = await DevicePool.getDevices(devicesDescriptor, undefined);
|
|
439
|
+
if (deviceList.length === 1 && deviceList[0]?.features?.bootloader_mode) {
|
|
440
|
+
this.device.updateFromCache(deviceList[0]);
|
|
441
|
+
await this.device.acquire();
|
|
442
|
+
this.device.getCommands().mainId = this.device.mainId ?? '';
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
await wait(2000);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* @description Device reboot (available in bootloader mode)
|
|
452
|
+
* @param rebootType Reboot type, see the RebootType enum
|
|
453
|
+
*/
|
|
454
|
+
async reboot(rebootType: RebootType) {
|
|
455
|
+
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
456
|
+
try {
|
|
457
|
+
const res = await typedCall('Reboot', 'Success', {
|
|
458
|
+
reboot_type: rebootType,
|
|
459
|
+
});
|
|
460
|
+
return res.message;
|
|
461
|
+
} catch (error) {
|
|
462
|
+
// Device disconnection during reboot is expected behavior
|
|
463
|
+
if (
|
|
464
|
+
error instanceof Error &&
|
|
465
|
+
(error.message.includes('device was disconnected') ||
|
|
466
|
+
error.message.includes('transferIn') ||
|
|
467
|
+
error.message.includes('USBDevice'))
|
|
468
|
+
) {
|
|
469
|
+
// This is expected - device successfully rebooted and disconnected
|
|
470
|
+
return { message: 'Device rebooted successfully' };
|
|
471
|
+
}
|
|
472
|
+
// Re-throw other errors
|
|
473
|
+
throw error;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
import { EDeviceType } from '@onetokenfe/hd-shared';
|
|
3
|
+
|
|
4
|
+
import { getDeviceType } from '../../utils';
|
|
5
|
+
|
|
6
|
+
import type { Features, IVersionArray } from '../../types';
|
|
7
|
+
|
|
8
|
+
export function shouldUpdateBootloaderForClassicAndMini({
|
|
9
|
+
currentVersion,
|
|
10
|
+
bootloaderVersion,
|
|
11
|
+
willUpdateFirmware,
|
|
12
|
+
targetBootloaderVersion,
|
|
13
|
+
bootloaderRelatedFirmwareVersion,
|
|
14
|
+
}: {
|
|
15
|
+
currentVersion: string;
|
|
16
|
+
bootloaderVersion: string;
|
|
17
|
+
willUpdateFirmware: string;
|
|
18
|
+
targetBootloaderVersion?: IVersionArray;
|
|
19
|
+
bootloaderRelatedFirmwareVersion: IVersionArray;
|
|
20
|
+
}) {
|
|
21
|
+
// If the current bootloader version is greater than or equal to the version that needs to be upgraded, then no upgrade is required
|
|
22
|
+
if (targetBootloaderVersion && semver.gte(bootloaderVersion, targetBootloaderVersion.join('.'))) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (semver.gte(willUpdateFirmware, bootloaderRelatedFirmwareVersion.join('.'))) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// The current version is greater than the relatedVersion and the bootloader version is lower than the target bootloader version
|
|
31
|
+
if (semver.gte(currentVersion, bootloaderRelatedFirmwareVersion.join('.'))) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function isEnteredManuallyBoot(features: Features, updateType: string) {
|
|
39
|
+
const deviceType = getDeviceType(features);
|
|
40
|
+
const isMini = deviceType === EDeviceType.Mini;
|
|
41
|
+
const isBoot183ClassicUpBle =
|
|
42
|
+
updateType === 'firmware' &&
|
|
43
|
+
deviceType === EDeviceType.Classic &&
|
|
44
|
+
features.bootloader_version === '1.8.3';
|
|
45
|
+
return isMini || isBoot183ClassicUpBle;
|
|
46
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
import { ERRORS, HardwareErrorCode } from '@onetokenfe/hd-shared';
|
|
3
|
+
|
|
4
|
+
import { getDeviceType, httpRequest } from '../../utils';
|
|
5
|
+
import { DataManager } from '../../data-manager';
|
|
6
|
+
import { findLatestRelease } from '../../utils/release';
|
|
7
|
+
import { getFirmwareUpdateField } from '../../utils/deviceFeaturesUtils';
|
|
8
|
+
|
|
9
|
+
import type { Features } from '../../types';
|
|
10
|
+
import type { EFirmwareType } from '@onetokenfe/hd-shared';
|
|
11
|
+
import type { IFirmwareField } from '../../data-manager/DataManager';
|
|
12
|
+
|
|
13
|
+
export interface GetInfoProps {
|
|
14
|
+
features: Features;
|
|
15
|
+
updateType: 'firmware' | 'ble';
|
|
16
|
+
isUpdateBootloader?: boolean;
|
|
17
|
+
targetVersion?: string;
|
|
18
|
+
firmwareType: EFirmwareType;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface GetBinaryProps extends GetInfoProps {
|
|
22
|
+
version?: number[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const getBinary = async ({
|
|
26
|
+
features,
|
|
27
|
+
updateType,
|
|
28
|
+
version,
|
|
29
|
+
isUpdateBootloader,
|
|
30
|
+
firmwareType,
|
|
31
|
+
}: GetBinaryProps) => {
|
|
32
|
+
const releaseInfo = getInfo({
|
|
33
|
+
features,
|
|
34
|
+
updateType,
|
|
35
|
+
targetVersion: version?.join('.'),
|
|
36
|
+
firmwareType,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (!releaseInfo) {
|
|
40
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'no firmware found for this device');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (version && !semver.eq(releaseInfo.version.join('.'), version.join('.'))) {
|
|
44
|
+
const touchWithoutVersion = getDeviceType(features) === 'touch' && !features.onetoken_version;
|
|
45
|
+
if (!touchWithoutVersion) {
|
|
46
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'firmware version mismatch');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const url =
|
|
51
|
+
// eslint-disable-next-line no-nested-ternary
|
|
52
|
+
updateType === 'ble'
|
|
53
|
+
? // @ts-expect-error
|
|
54
|
+
releaseInfo.webUpdate
|
|
55
|
+
: isUpdateBootloader
|
|
56
|
+
? releaseInfo.bootloaderResource
|
|
57
|
+
: releaseInfo.url;
|
|
58
|
+
let fw;
|
|
59
|
+
try {
|
|
60
|
+
fw = await httpRequest(url, 'binary');
|
|
61
|
+
} catch {
|
|
62
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Method_FirmwareUpdate_DownloadFailed');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
...releaseInfo,
|
|
67
|
+
binary: fw,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const getSysResourceBinary = async (url: string) => {
|
|
72
|
+
let fw;
|
|
73
|
+
try {
|
|
74
|
+
fw = await httpRequest(url, 'binary');
|
|
75
|
+
} catch {
|
|
76
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Method_FirmwareUpdate_DownloadFailed');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
binary: fw,
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const getInfo = ({ features, updateType, targetVersion, firmwareType }: GetInfoProps) => {
|
|
85
|
+
const deviceType = getDeviceType(features);
|
|
86
|
+
if (deviceType === 'unknown') {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const { deviceMap } = DataManager;
|
|
90
|
+
|
|
91
|
+
const firmwareUpdateField: 'ble' | IFirmwareField = getFirmwareUpdateField({
|
|
92
|
+
features,
|
|
93
|
+
updateType,
|
|
94
|
+
targetVersion,
|
|
95
|
+
firmwareType,
|
|
96
|
+
});
|
|
97
|
+
const releaseInfo = deviceMap?.[deviceType]?.[firmwareUpdateField] ?? [];
|
|
98
|
+
return findLatestRelease(releaseInfo);
|
|
99
|
+
};
|