@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,31 @@
|
|
|
1
|
+
import { fromHardened } from '../api/helpers/pathUtils';
|
|
2
|
+
import bitcoin from '../data/coins/bitcoin.json';
|
|
3
|
+
|
|
4
|
+
const btcCoins = bitcoin.map(coin => coin.name);
|
|
5
|
+
|
|
6
|
+
export type BitcoinInfo = {
|
|
7
|
+
name: string;
|
|
8
|
+
slip44: number;
|
|
9
|
+
label: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default class CoinManager {
|
|
13
|
+
static getCoins(): string[] {
|
|
14
|
+
return btcCoins;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static getBitcoinCoinInfo(info: { name?: string; path?: number[] }): BitcoinInfo | undefined {
|
|
18
|
+
let coinInfo: BitcoinInfo | undefined;
|
|
19
|
+
if (info.name) {
|
|
20
|
+
const coinName = info.name.toLowerCase();
|
|
21
|
+
coinInfo = bitcoin.find(
|
|
22
|
+
c => c.name.toLowerCase() === coinName || c.label.toLowerCase() === coinName
|
|
23
|
+
);
|
|
24
|
+
} else if (info.path) {
|
|
25
|
+
const slip44 = fromHardened(info.path[1]);
|
|
26
|
+
coinInfo = bitcoin.find(c => c.slip44 === slip44);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return coinInfo;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import semver from 'semver';
|
|
3
|
+
import { EDeviceType, EFirmwareType } from '@onetokenfe/hd-shared';
|
|
4
|
+
|
|
5
|
+
import MessagesJSON from '../data/messages/messages.json';
|
|
6
|
+
import MessagesLegacyV1JSON from '../data/messages/messages_legacy_v1.json';
|
|
7
|
+
import {
|
|
8
|
+
LoggerNames,
|
|
9
|
+
getDeviceBLEFirmwareVersion,
|
|
10
|
+
getDeviceFirmwareVersion,
|
|
11
|
+
getDeviceType,
|
|
12
|
+
getFirmwareType,
|
|
13
|
+
getFirmwareUpdateField,
|
|
14
|
+
getLogger,
|
|
15
|
+
getTimeStamp,
|
|
16
|
+
} from '../utils';
|
|
17
|
+
import { DeviceModelToTypes } from '../types';
|
|
18
|
+
import { findLatestRelease, getReleaseChangelog, getReleaseStatus } from '../utils/release';
|
|
19
|
+
|
|
20
|
+
import type {
|
|
21
|
+
AssetsMap,
|
|
22
|
+
ConnectSettings,
|
|
23
|
+
DeviceTypeMap,
|
|
24
|
+
Features,
|
|
25
|
+
IDeviceBLEFirmwareStatus,
|
|
26
|
+
IDeviceFirmwareStatus,
|
|
27
|
+
ITransportStatus,
|
|
28
|
+
IVersionArray,
|
|
29
|
+
RemoteConfigResponse,
|
|
30
|
+
} from '../types';
|
|
31
|
+
|
|
32
|
+
const Log = getLogger(LoggerNames.Core);
|
|
33
|
+
|
|
34
|
+
export const FIRMWARE_FIELDS = [
|
|
35
|
+
'firmware',
|
|
36
|
+
'firmware-v2',
|
|
37
|
+
'firmware-v8',
|
|
38
|
+
'firmware-btc-v8',
|
|
39
|
+
] as const;
|
|
40
|
+
|
|
41
|
+
export type IFirmwareField = (typeof FIRMWARE_FIELDS)[number];
|
|
42
|
+
|
|
43
|
+
export type MessageVersion = 'latest' | 'v1';
|
|
44
|
+
|
|
45
|
+
const FIRMWARE_FIELD_TYPE_MAP: Readonly<Record<IFirmwareField, EFirmwareType>> = {
|
|
46
|
+
firmware: EFirmwareType.Universal,
|
|
47
|
+
'firmware-v2': EFirmwareType.Universal,
|
|
48
|
+
'firmware-v8': EFirmwareType.Universal,
|
|
49
|
+
'firmware-btc-v8': EFirmwareType.BitcoinOnly,
|
|
50
|
+
} as const;
|
|
51
|
+
|
|
52
|
+
function getFirmwareTypeFromField(firmwareField: IFirmwareField): EFirmwareType {
|
|
53
|
+
const firmwareType = FIRMWARE_FIELD_TYPE_MAP[firmwareField];
|
|
54
|
+
|
|
55
|
+
// Explicit check for type safety
|
|
56
|
+
if (firmwareType === undefined) {
|
|
57
|
+
// Fallback to Universal for safety
|
|
58
|
+
return EFirmwareType.Universal;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return firmwareType;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default class DataManager {
|
|
65
|
+
static deviceMap: DeviceTypeMap = {
|
|
66
|
+
[EDeviceType.Classic]: {
|
|
67
|
+
firmware: [],
|
|
68
|
+
ble: [],
|
|
69
|
+
},
|
|
70
|
+
[EDeviceType.Classic1s]: {
|
|
71
|
+
firmware: [],
|
|
72
|
+
ble: [],
|
|
73
|
+
},
|
|
74
|
+
[EDeviceType.Mini]: {
|
|
75
|
+
firmware: [],
|
|
76
|
+
ble: [],
|
|
77
|
+
},
|
|
78
|
+
[EDeviceType.Touch]: {
|
|
79
|
+
firmware: [],
|
|
80
|
+
ble: [],
|
|
81
|
+
},
|
|
82
|
+
[EDeviceType.Pro]: {
|
|
83
|
+
firmware: [],
|
|
84
|
+
ble: [],
|
|
85
|
+
},
|
|
86
|
+
[EDeviceType.ClassicPure]: {
|
|
87
|
+
firmware: [],
|
|
88
|
+
ble: [],
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
static assets: AssetsMap | null = null;
|
|
93
|
+
|
|
94
|
+
static settings: ConnectSettings;
|
|
95
|
+
|
|
96
|
+
static messages: { [version in MessageVersion]: JSON } = {
|
|
97
|
+
latest: MessagesJSON as unknown as JSON,
|
|
98
|
+
v1: MessagesLegacyV1JSON as unknown as JSON,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
static lastCheckTimestamp = 0;
|
|
102
|
+
|
|
103
|
+
static getFirmwareStatus = (
|
|
104
|
+
features: Features,
|
|
105
|
+
firmwareType: EFirmwareType
|
|
106
|
+
): IDeviceFirmwareStatus => {
|
|
107
|
+
const deviceType = getDeviceType(features);
|
|
108
|
+
if (deviceType === EDeviceType.Unknown) return 'unknown';
|
|
109
|
+
|
|
110
|
+
const deviceFirmwareType = getFirmwareType(features);
|
|
111
|
+
const deviceFirmwareVersion = getDeviceFirmwareVersion(features);
|
|
112
|
+
if (features.firmware_present === false) {
|
|
113
|
+
return 'none';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (DeviceModelToTypes.model_mini.includes(deviceType) && features.bootloader_mode) {
|
|
117
|
+
return 'unknown';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const firmwareUpdateField = getFirmwareUpdateField({
|
|
121
|
+
features,
|
|
122
|
+
updateType: 'firmware',
|
|
123
|
+
firmwareType,
|
|
124
|
+
});
|
|
125
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
|
|
126
|
+
let currentVersion = deviceFirmwareVersion.join('.');
|
|
127
|
+
if (targetDeviceConfigList.length > 0 && deviceFirmwareType !== firmwareType) {
|
|
128
|
+
currentVersion = '0.0.0';
|
|
129
|
+
}
|
|
130
|
+
return getReleaseStatus(targetDeviceConfigList, currentVersion);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Touch、Pro System UI Resource Update
|
|
135
|
+
* ** Interval upgrade is not considered **
|
|
136
|
+
*/
|
|
137
|
+
static getSysResourcesLatestRelease = ({
|
|
138
|
+
features,
|
|
139
|
+
forcedUpdateRes,
|
|
140
|
+
firmwareType,
|
|
141
|
+
}: {
|
|
142
|
+
features: Features;
|
|
143
|
+
forcedUpdateRes?: boolean;
|
|
144
|
+
firmwareType: EFirmwareType;
|
|
145
|
+
}) => {
|
|
146
|
+
const deviceType = getDeviceType(features);
|
|
147
|
+
const deviceFirmwareVersion = getDeviceFirmwareVersion(features);
|
|
148
|
+
|
|
149
|
+
if (deviceType !== EDeviceType.Pro && deviceType !== EDeviceType.Touch) return undefined;
|
|
150
|
+
|
|
151
|
+
const firmwareUpdateField = getFirmwareUpdateField({
|
|
152
|
+
features,
|
|
153
|
+
updateType: 'firmware',
|
|
154
|
+
firmwareType,
|
|
155
|
+
}) as IFirmwareField;
|
|
156
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
|
|
157
|
+
const currentVersion = deviceFirmwareVersion.join('.');
|
|
158
|
+
const targetDeviceConfig = targetDeviceConfigList.filter(item =>
|
|
159
|
+
forcedUpdateRes
|
|
160
|
+
? !!item.resource
|
|
161
|
+
: semver.gt(item.version.join('.'), currentVersion) && !!item.resource
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
return findLatestRelease(targetDeviceConfig)?.resource;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Touch、Pro System full UI Resource Update
|
|
169
|
+
* ** Interval upgrade is not considered **
|
|
170
|
+
*/
|
|
171
|
+
static getSysFullResource = (features: Features, firmwareType: EFirmwareType) => {
|
|
172
|
+
const deviceType = getDeviceType(features);
|
|
173
|
+
if (deviceType === EDeviceType.Unknown) return undefined;
|
|
174
|
+
|
|
175
|
+
if (deviceType !== EDeviceType.Pro && deviceType !== EDeviceType.Touch) return undefined;
|
|
176
|
+
|
|
177
|
+
const firmwareUpdateField = getFirmwareUpdateField({
|
|
178
|
+
features,
|
|
179
|
+
updateType: 'firmware',
|
|
180
|
+
firmwareType,
|
|
181
|
+
}) as IFirmwareField;
|
|
182
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
|
|
183
|
+
const targetDeviceConfig = targetDeviceConfigList.filter(item => !!item.fullResource);
|
|
184
|
+
|
|
185
|
+
return findLatestRelease(targetDeviceConfig)?.fullResource;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
static getBootloaderResource = (features: Features, firmwareType: EFirmwareType) => {
|
|
189
|
+
const deviceType = getDeviceType(features);
|
|
190
|
+
if (deviceType === EDeviceType.Unknown) throw new Error('Device type is unknown');
|
|
191
|
+
|
|
192
|
+
if (deviceType !== EDeviceType.Pro && deviceType !== EDeviceType.Touch) return undefined;
|
|
193
|
+
const firmwareUpdateField = getFirmwareUpdateField({
|
|
194
|
+
features,
|
|
195
|
+
updateType: 'firmware',
|
|
196
|
+
firmwareType,
|
|
197
|
+
}) as IFirmwareField;
|
|
198
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
|
|
199
|
+
if (targetDeviceConfigList.length === 0) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
`Could not found bootloader resource with deviceType:${deviceType} firmwareUpdateField:${firmwareUpdateField}`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
const targetDeviceConfig = targetDeviceConfigList.filter(item => !!item.bootloaderResource);
|
|
205
|
+
|
|
206
|
+
return findLatestRelease(targetDeviceConfig)?.bootloaderResource;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
static getBootloaderTargetVersion = (
|
|
210
|
+
features: Features,
|
|
211
|
+
firmwareType: EFirmwareType
|
|
212
|
+
): IVersionArray | undefined => {
|
|
213
|
+
const deviceType = getDeviceType(features);
|
|
214
|
+
if (deviceType === EDeviceType.Unknown) return undefined;
|
|
215
|
+
|
|
216
|
+
const firmwareUpdateField = getFirmwareUpdateField({
|
|
217
|
+
features,
|
|
218
|
+
updateType: 'firmware',
|
|
219
|
+
firmwareType,
|
|
220
|
+
}) as IFirmwareField;
|
|
221
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
|
|
222
|
+
const targetDeviceConfig = targetDeviceConfigList.filter(item => !!item.bootloaderResource);
|
|
223
|
+
|
|
224
|
+
return targetDeviceConfig?.[0]?.bootloaderVersion ?? undefined;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
static getBootloaderRelatedFirmwareVersion = (
|
|
228
|
+
features: Features,
|
|
229
|
+
firmwareType: EFirmwareType
|
|
230
|
+
): IVersionArray | undefined => {
|
|
231
|
+
const deviceType = getDeviceType(features);
|
|
232
|
+
if (deviceType === EDeviceType.Unknown) return undefined;
|
|
233
|
+
|
|
234
|
+
if (!DeviceModelToTypes.model_mini.includes(deviceType)) return undefined;
|
|
235
|
+
const firmwareUpdateField = getFirmwareUpdateField({
|
|
236
|
+
features,
|
|
237
|
+
updateType: 'firmware',
|
|
238
|
+
firmwareType,
|
|
239
|
+
}) as IFirmwareField;
|
|
240
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
|
|
241
|
+
const targetDeviceConfig = targetDeviceConfigList.filter(
|
|
242
|
+
item => !!item.bootloaderRelatedFirmwareVersion
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
return targetDeviceConfig?.[0]?.bootloaderRelatedFirmwareVersion ?? undefined;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
static getFirmwareChangelog = (features: Features, firmwareType: EFirmwareType) => {
|
|
249
|
+
const deviceType = getDeviceType(features);
|
|
250
|
+
if (deviceType === EDeviceType.Unknown) return [];
|
|
251
|
+
|
|
252
|
+
const deviceFirmwareVersion = getDeviceFirmwareVersion(features);
|
|
253
|
+
|
|
254
|
+
const firmwareUpdateField = getFirmwareUpdateField({
|
|
255
|
+
features,
|
|
256
|
+
updateType: 'firmware',
|
|
257
|
+
firmwareType,
|
|
258
|
+
}) as IFirmwareField;
|
|
259
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
|
|
260
|
+
|
|
261
|
+
if (
|
|
262
|
+
features.firmware_present === false ||
|
|
263
|
+
(DeviceModelToTypes.model_classic.includes(deviceType) && features.bootloader_mode)
|
|
264
|
+
) {
|
|
265
|
+
// Always return least changelog
|
|
266
|
+
return getReleaseChangelog(targetDeviceConfigList, '0.0.0');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const currentVersion = deviceFirmwareVersion.join('.');
|
|
270
|
+
return getReleaseChangelog(targetDeviceConfigList, currentVersion);
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
static getFirmwareLatestRelease = (features: Features, firmwareType: EFirmwareType) => {
|
|
274
|
+
const deviceType = getDeviceType(features);
|
|
275
|
+
if (deviceType === EDeviceType.Unknown) return undefined;
|
|
276
|
+
|
|
277
|
+
const firmwareUpdateField = getFirmwareUpdateField({
|
|
278
|
+
features,
|
|
279
|
+
updateType: 'firmware',
|
|
280
|
+
firmwareType,
|
|
281
|
+
}) as IFirmwareField;
|
|
282
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.[firmwareUpdateField] ?? [];
|
|
283
|
+
|
|
284
|
+
const target = findLatestRelease(targetDeviceConfigList);
|
|
285
|
+
if (!target) return target;
|
|
286
|
+
|
|
287
|
+
if (!target.resource) {
|
|
288
|
+
const resource = this.getSysResourcesLatestRelease({ features, firmwareType });
|
|
289
|
+
return {
|
|
290
|
+
...target,
|
|
291
|
+
resource,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
return target;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
static getBLEFirmwareStatus = (features: Features): IDeviceBLEFirmwareStatus => {
|
|
298
|
+
const deviceType = getDeviceType(features);
|
|
299
|
+
if (deviceType === EDeviceType.Unknown) return 'unknown';
|
|
300
|
+
|
|
301
|
+
const deviceBLEFirmwareVersion = getDeviceBLEFirmwareVersion(features);
|
|
302
|
+
|
|
303
|
+
/** mini has no device ble_ver */
|
|
304
|
+
if (!deviceBLEFirmwareVersion) {
|
|
305
|
+
return 'none';
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.ble ?? [];
|
|
309
|
+
const currentVersion = deviceBLEFirmwareVersion.join('.');
|
|
310
|
+
return getReleaseStatus(targetDeviceConfigList, currentVersion);
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
static getBleFirmwareChangelog = (features: Features) => {
|
|
314
|
+
const deviceType = getDeviceType(features);
|
|
315
|
+
if (deviceType === EDeviceType.Unknown) return [];
|
|
316
|
+
|
|
317
|
+
const deviceBLEFirmwareVersion = getDeviceBLEFirmwareVersion(features);
|
|
318
|
+
|
|
319
|
+
if (!deviceBLEFirmwareVersion) {
|
|
320
|
+
return [];
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.ble ?? [];
|
|
324
|
+
const currentVersion = deviceBLEFirmwareVersion.join('.');
|
|
325
|
+
return getReleaseChangelog(targetDeviceConfigList, currentVersion);
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
static getBleFirmwareLatestRelease = (features: Features) => {
|
|
329
|
+
const deviceType = getDeviceType(features);
|
|
330
|
+
if (deviceType === EDeviceType.Unknown) return undefined;
|
|
331
|
+
|
|
332
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.ble ?? [];
|
|
333
|
+
return findLatestRelease(targetDeviceConfigList);
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
static getTransportStatus = (localVersion: string): ITransportStatus => {
|
|
337
|
+
const latestTransportVersion = this.assets?.bridge?.version;
|
|
338
|
+
if (!latestTransportVersion) return 'valid';
|
|
339
|
+
const isLatest = semver.gte(localVersion, latestTransportVersion.join('.'));
|
|
340
|
+
return isLatest ? 'valid' : 'outdated';
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
static getBridgeChangelog = () => this.assets?.bridge.changelog;
|
|
344
|
+
|
|
345
|
+
private static enrichFirmwareReleaseInfo(
|
|
346
|
+
deviceData: DeviceTypeMap[keyof DeviceTypeMap] | undefined
|
|
347
|
+
): DeviceTypeMap[keyof DeviceTypeMap] {
|
|
348
|
+
// Safety check: return default structure if input is undefined/null
|
|
349
|
+
if (!deviceData || typeof deviceData !== 'object') {
|
|
350
|
+
return {
|
|
351
|
+
firmware: [],
|
|
352
|
+
ble: [],
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Create a shallow copy to avoid mutating original data
|
|
357
|
+
const enrichedData = { ...deviceData };
|
|
358
|
+
|
|
359
|
+
FIRMWARE_FIELDS.forEach(field => {
|
|
360
|
+
const releases = enrichedData[field];
|
|
361
|
+
|
|
362
|
+
if (!releases || !Array.isArray(releases) || releases.length === 0) {
|
|
363
|
+
return; // Skip this field
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Add firmwareType to each release in this field
|
|
367
|
+
try {
|
|
368
|
+
enrichedData[field] = releases.map(release => {
|
|
369
|
+
// Safety checks:
|
|
370
|
+
if (!release || typeof release !== 'object' || !!release.firmwareType) {
|
|
371
|
+
return release; // Return as-is if invalid or already has firmwareType
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const firmwareType = getFirmwareTypeFromField(field);
|
|
375
|
+
|
|
376
|
+
return {
|
|
377
|
+
...release,
|
|
378
|
+
firmwareType,
|
|
379
|
+
};
|
|
380
|
+
});
|
|
381
|
+
} catch (error) {
|
|
382
|
+
console.error(`Error enriching firmware field "${field}":`, error);
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
return enrichedData;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
static async load(settings: ConnectSettings) {
|
|
390
|
+
this.settings = settings;
|
|
391
|
+
if (!settings.fetchConfig) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const url = settings.preRelease
|
|
396
|
+
? 'https://data.onetoken.so/pre-config.json'
|
|
397
|
+
: 'https://data.onetoken.so/config.json';
|
|
398
|
+
|
|
399
|
+
const urlWithCache = `${url}?noCache=${getTimeStamp()}`;
|
|
400
|
+
let data: RemoteConfigResponse | null = null;
|
|
401
|
+
let fetchMethod: 'configFetcher' | 'axios' | 'none' = 'none';
|
|
402
|
+
|
|
403
|
+
// 1. Try custom configFetcher first (client-side IP direct connection support)
|
|
404
|
+
if (settings.configFetcher) {
|
|
405
|
+
Log.debug('[DataConfig] Trying configFetcher (client-side fetcher)...');
|
|
406
|
+
try {
|
|
407
|
+
data = await settings.configFetcher(urlWithCache);
|
|
408
|
+
if (data) {
|
|
409
|
+
fetchMethod = 'configFetcher';
|
|
410
|
+
Log.log('[DataConfig] ConfigFetcher success');
|
|
411
|
+
} else {
|
|
412
|
+
Log.debug('[DataConfig] ConfigFetcher returned null, will fallback to axios');
|
|
413
|
+
}
|
|
414
|
+
} catch (e) {
|
|
415
|
+
Log.warn('[DataConfig] ConfigFetcher error, will fallback to axios:', e);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// 2. Fallback to default axios request
|
|
420
|
+
if (!data) {
|
|
421
|
+
Log.debug('[DataConfig] Trying axios (SDK default fetcher)...');
|
|
422
|
+
try {
|
|
423
|
+
const response = await axios.get<RemoteConfigResponse>(urlWithCache, {
|
|
424
|
+
// because of iframe timeout is 10000
|
|
425
|
+
timeout: 7000,
|
|
426
|
+
});
|
|
427
|
+
data = response.data;
|
|
428
|
+
fetchMethod = 'axios';
|
|
429
|
+
Log.log('[DataConfig] Axios fetch success');
|
|
430
|
+
} catch (e) {
|
|
431
|
+
Log.warn('[DataConfig] Axios fetch error:', e);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// 3. Apply config if available
|
|
436
|
+
if (data) {
|
|
437
|
+
Log.log(`[DataConfig] Config loaded successfully via [${fetchMethod}]`);
|
|
438
|
+
this.deviceMap = {
|
|
439
|
+
[EDeviceType.Classic]: this.enrichFirmwareReleaseInfo(data.classic),
|
|
440
|
+
[EDeviceType.Classic1s]: this.enrichFirmwareReleaseInfo(data.classic1s),
|
|
441
|
+
[EDeviceType.ClassicPure]: this.enrichFirmwareReleaseInfo(data.classicpure),
|
|
442
|
+
[EDeviceType.Mini]: this.enrichFirmwareReleaseInfo(data.mini),
|
|
443
|
+
[EDeviceType.Touch]: this.enrichFirmwareReleaseInfo(data.touch),
|
|
444
|
+
[EDeviceType.Pro]: this.enrichFirmwareReleaseInfo(data.pro),
|
|
445
|
+
};
|
|
446
|
+
this.assets = {
|
|
447
|
+
bridge: data.bridge,
|
|
448
|
+
};
|
|
449
|
+
} else {
|
|
450
|
+
Log.warn('[DataConfig] All fetch methods failed, using built-in default config');
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
static updateEnv(newEnv: ConnectSettings['env']) {
|
|
455
|
+
if (this.settings) {
|
|
456
|
+
const prevEnv = this.settings.env;
|
|
457
|
+
this.settings = {
|
|
458
|
+
...this.settings,
|
|
459
|
+
env: newEnv,
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
// Log the environment change
|
|
463
|
+
console.debug(`DataManager env updated: ${prevEnv} -> ${newEnv}`);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
static async checkAndReloadData() {
|
|
468
|
+
if (getTimeStamp() - this.lastCheckTimestamp > 1000 * 60 * 60 * 3) {
|
|
469
|
+
await this.load(this.settings).then(() => {
|
|
470
|
+
this.lastCheckTimestamp = getTimeStamp();
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
static getProtobufMessages(messageVersion: MessageVersion = 'latest'): JSON {
|
|
476
|
+
return this.messages[messageVersion];
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
static getSettings(key?: undefined): ConnectSettings;
|
|
480
|
+
|
|
481
|
+
static getSettings<T extends keyof ConnectSettings>(key: T): ConnectSettings[T];
|
|
482
|
+
|
|
483
|
+
static getSettings(key?: keyof ConnectSettings) {
|
|
484
|
+
if (!this.settings) return null;
|
|
485
|
+
if (typeof key === 'string') {
|
|
486
|
+
return this.settings[key];
|
|
487
|
+
}
|
|
488
|
+
return this.settings;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
static isBleConnect = (env: ConnectSettings['env']) =>
|
|
492
|
+
env === 'react-native' || env === 'lowlevel' || env === 'desktop-web-ble';
|
|
493
|
+
|
|
494
|
+
/** Desktop WebUSB doesn't need browser permission prompt */
|
|
495
|
+
static isDesktopWebUsb = (env: ConnectSettings['env']) => env === 'desktop-webusb';
|
|
496
|
+
|
|
497
|
+
/** Browser WebUSB needs permission prompt */
|
|
498
|
+
static isBrowserWebUsb = (env: ConnectSettings['env']) => env === 'webusb';
|
|
499
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { IDeviceModel, IDeviceType } from '../types';
|
|
2
|
+
import type { MessageVersion } from './DataManager';
|
|
3
|
+
|
|
4
|
+
type DeviceVersionConfig = {
|
|
5
|
+
[deviceType in IDeviceType | IDeviceModel]?: {
|
|
6
|
+
minVersion: string;
|
|
7
|
+
messageVersion: MessageVersion;
|
|
8
|
+
}[];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const PROTOBUF_MESSAGE_CONFIG: DeviceVersionConfig = {
|
|
12
|
+
model_mini: [
|
|
13
|
+
// Classic1s starts from 3.5.0, so use latest by default
|
|
14
|
+
// Only use v1 for specific old versions (< 3.3.0)
|
|
15
|
+
{ minVersion: '3.3.0', messageVersion: 'latest' },
|
|
16
|
+
{ minVersion: '0.0.1', messageVersion: 'v1' },
|
|
17
|
+
// Fallback to latest for unknown versions (0.0.0) to prevent device type detection issues
|
|
18
|
+
{ minVersion: '0.0.0', messageVersion: 'latest' },
|
|
19
|
+
],
|
|
20
|
+
model_touch: [
|
|
21
|
+
// Use latest by default for Touch/Pro
|
|
22
|
+
// Only use v1 for specific old versions (< 4.5.0)
|
|
23
|
+
{ minVersion: '4.5.0', messageVersion: 'latest' },
|
|
24
|
+
{ minVersion: '0.0.1', messageVersion: 'v1' },
|
|
25
|
+
// Fallback to latest for unknown versions (0.0.0)
|
|
26
|
+
{ minVersion: '0.0.0', messageVersion: 'latest' },
|
|
27
|
+
],
|
|
28
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { ERRORS, HardwareErrorCode } from '@onetokenfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import DataManager from './DataManager';
|
|
4
|
+
import { LoggerNames, getLogger } from '../utils';
|
|
5
|
+
// eslint-disable-next-line import/no-cycle
|
|
6
|
+
import { DevicePool } from '../device/DevicePool';
|
|
7
|
+
import { getSupportMessageVersion } from '../utils/deviceFeaturesUtils';
|
|
8
|
+
|
|
9
|
+
import type { MessageVersion } from './DataManager';
|
|
10
|
+
import type { LowlevelTransportSharedPlugin, Transport } from '@onetokenfe/hd-transport';
|
|
11
|
+
import type { Features } from '../types';
|
|
12
|
+
|
|
13
|
+
const Log = getLogger(LoggerNames.Transport);
|
|
14
|
+
const BleLogger = getLogger(LoggerNames.HdBleTransport);
|
|
15
|
+
const HttpLogger = getLogger(LoggerNames.HdTransportHttp);
|
|
16
|
+
const LowLevelLogger = getLogger(LoggerNames.HdTransportLowLevel);
|
|
17
|
+
const WebBleLogger = getLogger(LoggerNames.HdWebBleTransport);
|
|
18
|
+
const WebUsbLogger = getLogger(LoggerNames.HdTransportWebUsb);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* transport 在同一个环境中只会存在一个
|
|
22
|
+
* 这里设计成单例获取
|
|
23
|
+
* 方便进行环境判断,读取不同的 transport
|
|
24
|
+
*/
|
|
25
|
+
export default class TransportManager {
|
|
26
|
+
static transport: Transport;
|
|
27
|
+
|
|
28
|
+
static defaultMessages: JSON | Record<string, any>;
|
|
29
|
+
|
|
30
|
+
static currentMessages: JSON | Record<string, any>;
|
|
31
|
+
|
|
32
|
+
static reactNativeInit = false;
|
|
33
|
+
|
|
34
|
+
static messageVersion: MessageVersion = 'latest';
|
|
35
|
+
|
|
36
|
+
static plugin: LowlevelTransportSharedPlugin | null = null;
|
|
37
|
+
|
|
38
|
+
static load() {
|
|
39
|
+
Log.debug('transport manager load');
|
|
40
|
+
this.defaultMessages = DataManager.getProtobufMessages();
|
|
41
|
+
this.currentMessages = this.defaultMessages;
|
|
42
|
+
this.messageVersion = 'latest';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static async configure() {
|
|
46
|
+
try {
|
|
47
|
+
const env = DataManager.getSettings('env');
|
|
48
|
+
Log.debug('Initializing transports', env);
|
|
49
|
+
if (env === 'react-native') {
|
|
50
|
+
if (!this.reactNativeInit) {
|
|
51
|
+
await this.transport.init(BleLogger, DevicePool.emitter);
|
|
52
|
+
this.reactNativeInit = true;
|
|
53
|
+
} else {
|
|
54
|
+
Log.debug('React Native Do Not Initializing transports');
|
|
55
|
+
}
|
|
56
|
+
} else if (env === 'lowlevel') {
|
|
57
|
+
if (!this.plugin) {
|
|
58
|
+
throw ERRORS.TypedError(
|
|
59
|
+
HardwareErrorCode.TransportNotConfigured,
|
|
60
|
+
'Lowlevel transport mast have plugin'
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
await this.transport.init(LowLevelLogger, DevicePool.emitter, this.plugin);
|
|
64
|
+
} else if (env === 'desktop-web-ble') {
|
|
65
|
+
await this.transport.init(WebBleLogger, DevicePool.emitter);
|
|
66
|
+
} else if (env === 'webusb' || env === 'desktop-webusb') {
|
|
67
|
+
await this.transport.init(WebUsbLogger);
|
|
68
|
+
} else {
|
|
69
|
+
await this.transport.init(HttpLogger);
|
|
70
|
+
}
|
|
71
|
+
Log.debug('Configuring transports');
|
|
72
|
+
await this.transport.configure(JSON.stringify(this.defaultMessages));
|
|
73
|
+
Log.debug('Configuring transports done');
|
|
74
|
+
} catch (error) {
|
|
75
|
+
Log.debug('Initializing transports error: ', error);
|
|
76
|
+
if (error.code === 'ECONNABORTED') {
|
|
77
|
+
throw ERRORS.TypedError(HardwareErrorCode.BridgeTimeoutError);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static async reconfigure(features?: Features | undefined) {
|
|
83
|
+
Log.debug(`Begin reconfiguring transports`);
|
|
84
|
+
const { messageVersion, messages } = getSupportMessageVersion(features);
|
|
85
|
+
|
|
86
|
+
if (this.currentMessages === messages || !messages) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Log.debug(`Reconfiguring transports version:${messageVersion}`);
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
await this.transport.configure(JSON.stringify(messages));
|
|
94
|
+
this.currentMessages = messages;
|
|
95
|
+
this.messageVersion = messageVersion;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
throw ERRORS.TypedError(
|
|
98
|
+
HardwareErrorCode.TransportInvalidProtobuf,
|
|
99
|
+
`Transport_InvalidProtobuf: ${error.message as unknown as string}`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static setTransport(TransportConstructor: any, plugin?: LowlevelTransportSharedPlugin) {
|
|
105
|
+
const env = DataManager.getSettings('env');
|
|
106
|
+
if (env === 'react-native') {
|
|
107
|
+
/** Actually initializes the ReactNativeTransport */
|
|
108
|
+
this.transport = new TransportConstructor({ scanTimeout: 3000 }) as unknown as Transport;
|
|
109
|
+
} else {
|
|
110
|
+
/** Actually initializes the HttpTransport */
|
|
111
|
+
this.transport = new TransportConstructor() as unknown as Transport;
|
|
112
|
+
}
|
|
113
|
+
if (plugin) {
|
|
114
|
+
this.plugin = plugin;
|
|
115
|
+
Log.debug('set transport plugin: ', this.plugin);
|
|
116
|
+
}
|
|
117
|
+
Log.debug(
|
|
118
|
+
'set transport: ',
|
|
119
|
+
this.transport.name,
|
|
120
|
+
this.transport.version,
|
|
121
|
+
this.transport.configured
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static getTransport() {
|
|
126
|
+
return this.transport;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static getDefaultMessages() {
|
|
130
|
+
return this.defaultMessages;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static getCurrentMessages() {
|
|
134
|
+
return this.currentMessages;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static getMessageVersion() {
|
|
138
|
+
return this.messageVersion;
|
|
139
|
+
}
|
|
140
|
+
}
|