@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,275 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
import {
|
|
3
|
+
createDeviceNotSupportMethodError,
|
|
4
|
+
createNeedUpgradeFirmwareHardwareError,
|
|
5
|
+
} from '@onetokenfe/hd-shared';
|
|
6
|
+
|
|
7
|
+
import { supportInputPinOnSoftware, supportModifyHomescreen } from '../utils/deviceFeaturesUtils';
|
|
8
|
+
import { createDeviceMessage } from '../events/device';
|
|
9
|
+
import { UI_REQUEST } from '../constants/ui-request';
|
|
10
|
+
import { DEVICE, FIRMWARE, createFirmwareMessage, createUiMessage } from '../events';
|
|
11
|
+
import { getBleFirmwareReleaseInfo, getFirmwareReleaseInfo } from './firmware/releaseHelper';
|
|
12
|
+
import {
|
|
13
|
+
LoggerNames,
|
|
14
|
+
getDeviceFirmwareVersion,
|
|
15
|
+
getFirmwareType,
|
|
16
|
+
getLogger,
|
|
17
|
+
getMethodVersionRange,
|
|
18
|
+
} from '../utils';
|
|
19
|
+
import { generateInstanceId } from '../utils/tracing';
|
|
20
|
+
|
|
21
|
+
import type { Device } from '../device/Device';
|
|
22
|
+
import type DeviceConnector from '../device/DeviceConnector';
|
|
23
|
+
import type { DeviceFirmwareRange, KnownDevice } from '../types';
|
|
24
|
+
import type { CoreMessage } from '../events';
|
|
25
|
+
import type { RequestContext } from '../utils/tracing';
|
|
26
|
+
import type { CoreContext } from '../core';
|
|
27
|
+
|
|
28
|
+
const Log = getLogger(LoggerNames.Method);
|
|
29
|
+
|
|
30
|
+
export abstract class BaseMethod<Params = undefined> {
|
|
31
|
+
responseID: number;
|
|
32
|
+
|
|
33
|
+
// @ts-expect-error
|
|
34
|
+
device: Device;
|
|
35
|
+
|
|
36
|
+
// @ts-expect-error
|
|
37
|
+
params: Params;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* USB: onetoken_serial or serial_no
|
|
41
|
+
* iOS: uuid
|
|
42
|
+
* Android: MAC address
|
|
43
|
+
*/
|
|
44
|
+
connectId?: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* device id
|
|
48
|
+
*/
|
|
49
|
+
deviceId?: string;
|
|
50
|
+
|
|
51
|
+
deviceState?: string;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* method name
|
|
55
|
+
*/
|
|
56
|
+
name: string;
|
|
57
|
+
|
|
58
|
+
instanceId!: string;
|
|
59
|
+
|
|
60
|
+
sdkInstanceId?: string;
|
|
61
|
+
|
|
62
|
+
requestContext?: RequestContext;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 请求携带参数
|
|
66
|
+
*/
|
|
67
|
+
payload: Record<string, any>;
|
|
68
|
+
|
|
69
|
+
connector?: DeviceConnector;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 是否需要使用设备
|
|
73
|
+
*/
|
|
74
|
+
useDevice: boolean;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 允许的设备模式。当前设备模式在该数组中,则可以允许运行。
|
|
78
|
+
* eg. NOT_INITIALIZE, BOOTLOADER, SEEDLESS
|
|
79
|
+
*/
|
|
80
|
+
allowDeviceMode: string[];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 依赖的设备模式
|
|
84
|
+
*/
|
|
85
|
+
requireDeviceMode: string[];
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 是否需要轮询确认设备已连接
|
|
89
|
+
*/
|
|
90
|
+
shouldEnsureConnected = true;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 是否需要校验 features 的 deviceId 是否一致
|
|
94
|
+
*/
|
|
95
|
+
checkDeviceId = false;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 该方法是否需要校验 passphrase state
|
|
99
|
+
*/
|
|
100
|
+
useDevicePassphraseState = true;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* skip force update check
|
|
104
|
+
* @default false
|
|
105
|
+
*/
|
|
106
|
+
skipForceUpdateCheck = false;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 严格检查设备是否支持该方法,不支持则抛出错误
|
|
110
|
+
* @experiment 默认不严格检查,如果需要严格检查,则需要设置为 true
|
|
111
|
+
* @default false
|
|
112
|
+
*/
|
|
113
|
+
strictCheckDeviceSupport = false;
|
|
114
|
+
|
|
115
|
+
// @ts-expect-error: strictPropertyInitialization
|
|
116
|
+
postMessage: (message: CoreMessage) => void;
|
|
117
|
+
|
|
118
|
+
context?: CoreContext;
|
|
119
|
+
|
|
120
|
+
constructor(message: { id?: number; payload: any }) {
|
|
121
|
+
const { payload } = message;
|
|
122
|
+
this.name = payload.method;
|
|
123
|
+
this.payload = payload;
|
|
124
|
+
this.responseID = message.id || 0;
|
|
125
|
+
this.connectId = payload.connectId || '';
|
|
126
|
+
this.deviceId = payload.deviceId || '';
|
|
127
|
+
this.useDevice = true;
|
|
128
|
+
this.allowDeviceMode = [UI_REQUEST.NOT_INITIALIZE];
|
|
129
|
+
this.requireDeviceMode = [];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
abstract init(): void;
|
|
133
|
+
|
|
134
|
+
abstract run(): Promise<any>;
|
|
135
|
+
|
|
136
|
+
getVersionRange(): DeviceFirmwareRange {
|
|
137
|
+
return {};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
setContext(context: CoreContext) {
|
|
141
|
+
this.sdkInstanceId = context.sdkInstanceId;
|
|
142
|
+
this.instanceId = generateInstanceId('Method', this.sdkInstanceId);
|
|
143
|
+
Log.debug(
|
|
144
|
+
`[BaseMethod] Created: ${this.instanceId}, method: ${this.name}, SDK: ${this.sdkInstanceId}`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
setDevice(device: Device) {
|
|
149
|
+
this.device = device;
|
|
150
|
+
|
|
151
|
+
if (!device.sdkInstanceId && this.sdkInstanceId) {
|
|
152
|
+
device.sdkInstanceId = this.sdkInstanceId;
|
|
153
|
+
device.instanceId = generateInstanceId('Device', this.sdkInstanceId);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (this.requestContext) {
|
|
157
|
+
this.requestContext.deviceInstanceId = device.instanceId;
|
|
158
|
+
this.requestContext.commandsInstanceId = device.commands?.instanceId;
|
|
159
|
+
this.requestContext.sdkInstanceId = this.sdkInstanceId;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (device.commands && this.sdkInstanceId) {
|
|
163
|
+
device.commands.instanceId = generateInstanceId('DeviceCommands', this.sdkInstanceId);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (device.commands) {
|
|
167
|
+
device.commands.currentResponseID = this.responseID;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
Log.debug(
|
|
171
|
+
`[${this.instanceId}] setDevice: ${device.instanceId}, commands: ${device.commands?.instanceId}`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
checkFirmwareRelease() {
|
|
176
|
+
if (!this.device || !this.device.features) return;
|
|
177
|
+
const firmwareType = getFirmwareType(this.device.features);
|
|
178
|
+
const releaseInfo = getFirmwareReleaseInfo(this.device.features, firmwareType);
|
|
179
|
+
this.postMessage(
|
|
180
|
+
createFirmwareMessage(FIRMWARE.RELEASE_INFO, {
|
|
181
|
+
...releaseInfo,
|
|
182
|
+
device: this.device.toMessageObject(),
|
|
183
|
+
})
|
|
184
|
+
);
|
|
185
|
+
const bleReleaseInfo = getBleFirmwareReleaseInfo(this.device.features);
|
|
186
|
+
this.postMessage(
|
|
187
|
+
createFirmwareMessage(FIRMWARE.BLE_RELEASE_INFO, {
|
|
188
|
+
...bleReleaseInfo,
|
|
189
|
+
device: this.device.toMessageObject(),
|
|
190
|
+
})
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
checkDeviceSupportFeature() {
|
|
195
|
+
if (!this.device || !this.device.features) return;
|
|
196
|
+
const inputPinOnSoftware = supportInputPinOnSoftware(this.device.features);
|
|
197
|
+
const modifyHomescreen = supportModifyHomescreen(this.device.features);
|
|
198
|
+
|
|
199
|
+
this.postMessage(
|
|
200
|
+
createDeviceMessage(DEVICE.SUPPORT_FEATURES, {
|
|
201
|
+
inputPinOnSoftware,
|
|
202
|
+
modifyHomescreen,
|
|
203
|
+
device: this.device.toMessageObject(),
|
|
204
|
+
})
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
protected checkFeatureVersionLimit(
|
|
209
|
+
checkCondition: () => boolean,
|
|
210
|
+
getVersionRange: () => DeviceFirmwareRange,
|
|
211
|
+
options?: {
|
|
212
|
+
strictCheckDeviceSupport?: boolean;
|
|
213
|
+
}
|
|
214
|
+
) {
|
|
215
|
+
if (!checkCondition()) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const firmwareVersion = getDeviceFirmwareVersion(this.device.features)?.join('.');
|
|
220
|
+
const versionRange = getMethodVersionRange(
|
|
221
|
+
this.device.features,
|
|
222
|
+
type => getVersionRange()[type]
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
if (!versionRange) {
|
|
226
|
+
if (options?.strictCheckDeviceSupport) {
|
|
227
|
+
throw createDeviceNotSupportMethodError(this.name, getFirmwareType(this.device.features));
|
|
228
|
+
}
|
|
229
|
+
// Equipment that does not need to be repaired
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (semver.valid(firmwareVersion) && semver.lt(firmwareVersion, versionRange.min)) {
|
|
234
|
+
throw createNeedUpgradeFirmwareHardwareError({
|
|
235
|
+
currentVersion: firmwareVersion,
|
|
236
|
+
requireVersion: versionRange.min,
|
|
237
|
+
methodName: this.name,
|
|
238
|
+
firmwareType: getFirmwareType(this.device.features),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Automatic check safety_check level for Kovan, Ropsten, Rinkeby, Goerli test networks.
|
|
245
|
+
* @returns {void}
|
|
246
|
+
*/
|
|
247
|
+
async checkSafetyLevelOnTestNet() {
|
|
248
|
+
let checkFlag = false;
|
|
249
|
+
// 3 - Ropsten, 4 - Rinkeby, 5 - Goerli, 420 - Optimism Goerli, 11155111 - zkSync Sepolia
|
|
250
|
+
if (
|
|
251
|
+
this.name === 'evmSignTransaction' &&
|
|
252
|
+
[3, 4, 5, 420, 11155111].includes(Number(this.payload?.transaction?.chainId))
|
|
253
|
+
) {
|
|
254
|
+
checkFlag = true;
|
|
255
|
+
}
|
|
256
|
+
if (checkFlag && this.device.features?.safety_checks === 'Strict') {
|
|
257
|
+
Log.debug('will change safety_checks level');
|
|
258
|
+
await this.device.commands.typedCall('ApplySettings', 'Success', {
|
|
259
|
+
safety_checks: 'PromptTemporarily',
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
dispose() {}
|
|
265
|
+
|
|
266
|
+
// Reusable events
|
|
267
|
+
postPreviousAddressMessage = (data: { address?: string; path?: string }) => {
|
|
268
|
+
this.postMessage(
|
|
269
|
+
createUiMessage(UI_REQUEST.PREVIOUS_ADDRESS_RESULT, {
|
|
270
|
+
device: this.device.toMessageObject() as KnownDevice,
|
|
271
|
+
data,
|
|
272
|
+
})
|
|
273
|
+
);
|
|
274
|
+
};
|
|
275
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { BaseMethod } from './BaseMethod';
|
|
2
|
+
import { UI_REQUEST } from '../constants/ui-request';
|
|
3
|
+
import {
|
|
4
|
+
getBleFirmwareReleaseInfo,
|
|
5
|
+
getBootloaderReleaseInfo,
|
|
6
|
+
getFirmwareReleaseInfo,
|
|
7
|
+
} from './firmware/releaseHelper';
|
|
8
|
+
import { getBridgeReleaseInfo } from '../utils/bridgeUpdate';
|
|
9
|
+
import { getDeviceFirmwareVersion, getDeviceType, getFirmwareType } from '../utils';
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
AllFirmwareRelease,
|
|
13
|
+
CheckAllFirmwareReleaseParams,
|
|
14
|
+
} from '../types/api/checkAllFirmwareRelease';
|
|
15
|
+
|
|
16
|
+
export default class CheckAllFirmwareRelease extends BaseMethod {
|
|
17
|
+
init() {
|
|
18
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
|
|
19
|
+
this.useDevicePassphraseState = false;
|
|
20
|
+
this.skipForceUpdateCheck = true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async run() {
|
|
24
|
+
const { features } = this.device;
|
|
25
|
+
const { checkBridgeRelease, firmwareType: firmwareTypeParams } = this
|
|
26
|
+
.payload as CheckAllFirmwareReleaseParams;
|
|
27
|
+
|
|
28
|
+
if (!features) {
|
|
29
|
+
return Promise.resolve(null);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const deviceFirmwareType = getFirmwareType(features);
|
|
33
|
+
const firmwareType = firmwareTypeParams ?? deviceFirmwareType;
|
|
34
|
+
const firmwareRelease = getFirmwareReleaseInfo(features, firmwareType);
|
|
35
|
+
|
|
36
|
+
const currentFirmwareVersion = getDeviceFirmwareVersion(features).join('.');
|
|
37
|
+
const willUpdateFirmwareVersion = firmwareRelease.release?.version?.join('.');
|
|
38
|
+
const deviceType = getDeviceType(features);
|
|
39
|
+
|
|
40
|
+
let bridgeReleaseInfo = null;
|
|
41
|
+
if (
|
|
42
|
+
checkBridgeRelease &&
|
|
43
|
+
(firmwareRelease.status === 'required' || firmwareRelease.status === 'outdated')
|
|
44
|
+
) {
|
|
45
|
+
bridgeReleaseInfo = await getBridgeReleaseInfo({
|
|
46
|
+
deviceType,
|
|
47
|
+
currentFirmwareVersion,
|
|
48
|
+
willUpdateFirmwareVersion,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const bootloaderRelease = getBootloaderReleaseInfo({
|
|
52
|
+
features,
|
|
53
|
+
willUpdateFirmwareVersion,
|
|
54
|
+
firmwareType,
|
|
55
|
+
});
|
|
56
|
+
const bleFirmwareReleaseInfo = getBleFirmwareReleaseInfo(features);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
firmware: firmwareRelease,
|
|
60
|
+
bootloader: bootloaderRelease,
|
|
61
|
+
ble: bleFirmwareReleaseInfo,
|
|
62
|
+
bridge: bridgeReleaseInfo
|
|
63
|
+
? {
|
|
64
|
+
shouldUpdate: bridgeReleaseInfo.shouldUpdate,
|
|
65
|
+
status: bridgeReleaseInfo.shouldUpdate ? 'outdated' : 'valid',
|
|
66
|
+
changelog: bridgeReleaseInfo.changelog,
|
|
67
|
+
release: bridgeReleaseInfo.releaseVersion,
|
|
68
|
+
}
|
|
69
|
+
: undefined,
|
|
70
|
+
features,
|
|
71
|
+
} as AllFirmwareRelease;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseMethod } from './BaseMethod';
|
|
2
|
+
import { UI_REQUEST } from '../constants/ui-request';
|
|
3
|
+
import { getBleFirmwareReleaseInfo } from './firmware/releaseHelper';
|
|
4
|
+
|
|
5
|
+
export default class CheckBLEFirmwareRelease extends BaseMethod {
|
|
6
|
+
init() {
|
|
7
|
+
this.allowDeviceMode = [
|
|
8
|
+
...this.allowDeviceMode,
|
|
9
|
+
UI_REQUEST.NOT_INITIALIZE,
|
|
10
|
+
UI_REQUEST.BOOTLOADER,
|
|
11
|
+
];
|
|
12
|
+
this.useDevicePassphraseState = false;
|
|
13
|
+
this.skipForceUpdateCheck = true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
run() {
|
|
17
|
+
if (this.device.features) {
|
|
18
|
+
const releaseInfo = getBleFirmwareReleaseInfo(this.device.features);
|
|
19
|
+
return Promise.resolve(releaseInfo);
|
|
20
|
+
}
|
|
21
|
+
return Promise.resolve(null);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BaseMethod } from './BaseMethod';
|
|
2
|
+
import { UI_REQUEST } from '../constants/ui-request';
|
|
3
|
+
import { getBootloaderReleaseInfo } from './firmware/releaseHelper';
|
|
4
|
+
import { getFirmwareType } from '../utils';
|
|
5
|
+
|
|
6
|
+
import type { CheckBootloaderReleaseParams } from '../types/api/checkBootloaderRelease';
|
|
7
|
+
|
|
8
|
+
export default class CheckBootloaderRelease extends BaseMethod {
|
|
9
|
+
init() {
|
|
10
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
|
|
11
|
+
this.useDevicePassphraseState = false;
|
|
12
|
+
this.skipForceUpdateCheck = true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async run() {
|
|
16
|
+
if (!this.device.features) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const { features } = this.device;
|
|
20
|
+
const payload = this.payload as CheckBootloaderReleaseParams;
|
|
21
|
+
|
|
22
|
+
const deviceFirmwareType = getFirmwareType(features);
|
|
23
|
+
const firmwareType = payload.firmwareType ?? deviceFirmwareType;
|
|
24
|
+
|
|
25
|
+
const releaseInfo = getBootloaderReleaseInfo({
|
|
26
|
+
features,
|
|
27
|
+
willUpdateFirmwareVersion: payload.willUpdateFirmwareVersion,
|
|
28
|
+
firmwareType,
|
|
29
|
+
});
|
|
30
|
+
return Promise.resolve(releaseInfo);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BaseMethod } from './BaseMethod';
|
|
2
|
+
import { UI_REQUEST } from '../constants/ui-request';
|
|
3
|
+
import { getDeviceFirmwareVersion, getDeviceType } from '../utils';
|
|
4
|
+
import { getBridgeReleaseInfo } from '../utils/bridgeUpdate';
|
|
5
|
+
|
|
6
|
+
export default class CheckBridgeRelease extends BaseMethod {
|
|
7
|
+
init() {
|
|
8
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
|
|
9
|
+
this.useDevicePassphraseState = false;
|
|
10
|
+
this.skipForceUpdateCheck = true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async run() {
|
|
14
|
+
if (!this.device.features) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const { willUpdateFirmwareVersion } = this.payload;
|
|
19
|
+
const { features } = this.device;
|
|
20
|
+
const deviceType = getDeviceType(features);
|
|
21
|
+
const currentFirmwareVersion = getDeviceFirmwareVersion(features).join('.');
|
|
22
|
+
return getBridgeReleaseInfo({
|
|
23
|
+
deviceType,
|
|
24
|
+
currentFirmwareVersion,
|
|
25
|
+
willUpdateFirmwareVersion,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { ERRORS, HardwareErrorCode } from '@onetokenfe/hd-shared';
|
|
3
|
+
|
|
4
|
+
import { BaseMethod } from './BaseMethod';
|
|
5
|
+
|
|
6
|
+
export default class CheckBridgeStatus extends BaseMethod {
|
|
7
|
+
init() {
|
|
8
|
+
this.useDevice = false;
|
|
9
|
+
this.useDevicePassphraseState = false;
|
|
10
|
+
this.skipForceUpdateCheck = true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async run() {
|
|
14
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
15
|
+
axios
|
|
16
|
+
.request({
|
|
17
|
+
url: 'http://localhost:21320',
|
|
18
|
+
method: 'POST',
|
|
19
|
+
withCredentials: false,
|
|
20
|
+
timeout: 3000,
|
|
21
|
+
})
|
|
22
|
+
.then(() => resolve(true))
|
|
23
|
+
.catch(e => {
|
|
24
|
+
if (e.code === 'ECONNABORTED') {
|
|
25
|
+
reject(ERRORS.TypedError(HardwareErrorCode.BridgeTimeoutError));
|
|
26
|
+
} else {
|
|
27
|
+
resolve(false);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BaseMethod } from './BaseMethod';
|
|
2
|
+
import { UI_REQUEST } from '../constants/ui-request';
|
|
3
|
+
import { getFirmwareReleaseInfo } from './firmware/releaseHelper';
|
|
4
|
+
import { getFirmwareType } from '../utils';
|
|
5
|
+
|
|
6
|
+
import type { CheckFirmwareReleaseParams } from '../types/api/checkFirmwareRelease';
|
|
7
|
+
|
|
8
|
+
export default class CheckFirmwareRelease extends BaseMethod {
|
|
9
|
+
init() {
|
|
10
|
+
this.allowDeviceMode = [
|
|
11
|
+
...this.allowDeviceMode,
|
|
12
|
+
UI_REQUEST.NOT_INITIALIZE,
|
|
13
|
+
UI_REQUEST.BOOTLOADER,
|
|
14
|
+
];
|
|
15
|
+
this.useDevicePassphraseState = false;
|
|
16
|
+
this.skipForceUpdateCheck = true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
run() {
|
|
20
|
+
const payload = this.payload as CheckFirmwareReleaseParams;
|
|
21
|
+
|
|
22
|
+
if (this.device.features) {
|
|
23
|
+
const deviceFirmwareType = getFirmwareType(this.device.features);
|
|
24
|
+
const firmwareType = payload.firmwareType ?? deviceFirmwareType;
|
|
25
|
+
|
|
26
|
+
const releaseInfo = getFirmwareReleaseInfo(this.device.features, firmwareType);
|
|
27
|
+
return Promise.resolve(releaseInfo);
|
|
28
|
+
}
|
|
29
|
+
return Promise.resolve(null);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EDeviceType } from '@onetokenfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import { BaseMethod } from './BaseMethod';
|
|
4
|
+
import { getLatestFirmwareField } from '../utils/deviceFeaturesUtils';
|
|
5
|
+
import { DataManager } from '../data-manager';
|
|
6
|
+
import { findLatestRelease } from '../utils/release';
|
|
7
|
+
|
|
8
|
+
import type { CheckFirmwareTypeAvailableParams } from '../types/api/checkFirmwareTypeAvailable';
|
|
9
|
+
|
|
10
|
+
export default class CheckFirmwareTypeAvailable extends BaseMethod {
|
|
11
|
+
init() {
|
|
12
|
+
this.useDevice = false;
|
|
13
|
+
this.useDevicePassphraseState = false;
|
|
14
|
+
this.skipForceUpdateCheck = true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
run() {
|
|
18
|
+
const payload = this.payload as CheckFirmwareTypeAvailableParams;
|
|
19
|
+
const { deviceType, firmwareType } = payload;
|
|
20
|
+
if (deviceType === EDeviceType.Unknown) {
|
|
21
|
+
return Promise.resolve(undefined);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const latestFirmwareField = getLatestFirmwareField(firmwareType);
|
|
25
|
+
|
|
26
|
+
const releaseInfos = DataManager.deviceMap[deviceType]?.[latestFirmwareField] ?? [];
|
|
27
|
+
const releaseInfo = findLatestRelease(releaseInfos);
|
|
28
|
+
return Promise.resolve(releaseInfo);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { UI_REQUEST } from '../constants/ui-request';
|
|
2
|
+
import { serializedPath, validatePath } from './helpers/pathUtils';
|
|
3
|
+
import { BaseMethod } from './BaseMethod';
|
|
4
|
+
import { validateParams } from './helpers/paramsValidator';
|
|
5
|
+
import { formatAnyHex } from './helpers/hexUtils';
|
|
6
|
+
|
|
7
|
+
import type { CipheredKeyValue, CipheredKeyValueParams } from '../types';
|
|
8
|
+
import type { CipherKeyValue as HardwareCipherKeyValue } from '@onetokenfe/hd-transport';
|
|
9
|
+
|
|
10
|
+
export default class CipherKeyValue extends BaseMethod<HardwareCipherKeyValue[]> {
|
|
11
|
+
hasBundle = false;
|
|
12
|
+
|
|
13
|
+
init() {
|
|
14
|
+
this.checkDeviceId = true;
|
|
15
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
16
|
+
|
|
17
|
+
this.hasBundle = !!this.payload?.bundle;
|
|
18
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
19
|
+
|
|
20
|
+
// check payload
|
|
21
|
+
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
22
|
+
|
|
23
|
+
// init params
|
|
24
|
+
this.params = [];
|
|
25
|
+
payload.bundle.forEach((batch: CipheredKeyValueParams) => {
|
|
26
|
+
const addressN = validatePath(batch.path);
|
|
27
|
+
|
|
28
|
+
validateParams(batch, [
|
|
29
|
+
{ name: 'path', required: true },
|
|
30
|
+
{ name: 'key', type: 'string' },
|
|
31
|
+
{ name: 'value', type: 'hexString' },
|
|
32
|
+
{ name: 'encrypt', type: 'boolean' },
|
|
33
|
+
{ name: 'askOnEncrypt', type: 'boolean' },
|
|
34
|
+
{ name: 'askOnDecrypt', type: 'boolean' },
|
|
35
|
+
{ name: 'iv', type: 'hexString' },
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
this.params.push({
|
|
39
|
+
address_n: addressN,
|
|
40
|
+
key: batch.key,
|
|
41
|
+
value: formatAnyHex(batch.value),
|
|
42
|
+
encrypt: batch.encrypt,
|
|
43
|
+
ask_on_encrypt: batch.askOnEncrypt,
|
|
44
|
+
ask_on_decrypt: batch.askOnDecrypt,
|
|
45
|
+
iv: formatAnyHex(batch.iv),
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async run() {
|
|
51
|
+
const responses: CipheredKeyValue[] = [];
|
|
52
|
+
|
|
53
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
54
|
+
const param = this.params[i];
|
|
55
|
+
|
|
56
|
+
const res = await this.device.commands.typedCall('CipherKeyValue', 'CipheredKeyValue', {
|
|
57
|
+
...param,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
responses.push({
|
|
61
|
+
path: serializedPath(param.address_n),
|
|
62
|
+
...res.message,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
67
|
+
}
|
|
68
|
+
}
|