@onekeyfe/hd-core 1.1.27-alpha.40 → 1.1.27-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/DeviceCommands.test.ts +99 -0
- package/__tests__/evmLedgerLegacySafety.test.ts +261 -0
- package/__tests__/evmSignTransaction.test.ts +1 -1
- package/__tests__/evmSignTypedData.test.ts +1 -1
- package/__tests__/preInitialize.test.ts +22 -0
- package/dist/api/BaseMethod.d.ts +7 -1
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +0 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/GetFeatures.d.ts +1 -1
- package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts +1 -6
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts +1 -2
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumGetAddress.d.ts +6 -2
- package/dist/api/alephium/AlephiumGetAddress.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignMessage.d.ts +5 -2
- package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignTransaction.d.ts +5 -2
- package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
- package/dist/api/algo/AlgoSignTransaction.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/aptos/AptosSignInMessage.d.ts.map +1 -1
- package/dist/api/aptos/AptosSignMessage.d.ts.map +1 -1
- package/dist/api/aptos/AptosSignTransaction.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetAddress.d.ts +9 -2
- package/dist/api/benfen/BenfenGetAddress.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetPublicKey.d.ts +9 -2
- package/dist/api/benfen/BenfenGetPublicKey.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignMessage.d.ts +8 -2
- package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignTransaction.d.ts +8 -2
- package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCGetAddress.d.ts +11 -1
- package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
- package/dist/api/btc/BTCGetPublicKey.d.ts +11 -1
- package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
- package/dist/api/btc/BTCSignMessage.d.ts +15 -1
- package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
- package/dist/api/btc/BTCSignPsbt.d.ts.map +1 -1
- package/dist/api/btc/BTCSignTransaction.d.ts +11 -1
- package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCVerifyMessage.d.ts +11 -1
- package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
- package/dist/api/btc/helpers/versionLimit.d.ts +11 -2
- package/dist/api/btc/helpers/versionLimit.d.ts.map +1 -1
- package/dist/api/cardano/CardanoSignMessage.d.ts.map +1 -1
- package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
- package/dist/api/cosmos/CosmosSignTransaction.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/device/PreInitialize.d.ts +6 -0
- package/dist/api/device/PreInitialize.d.ts.map +1 -0
- package/dist/api/dynex/DnxGetAddress.d.ts.map +1 -1
- package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
- package/dist/api/evm/EVMSignMessage.d.ts.map +1 -1
- package/dist/api/evm/EVMSignMessageEIP712.d.ts +8 -2
- package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/evm/latest/signTypedData.d.ts +1 -1
- package/dist/api/evm/latest/signTypedData.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/signTypedData.d.ts +1 -1
- package/dist/api/evm/legacyV1/signTypedData.d.ts.map +1 -1
- package/dist/api/filecoin/FilecoinSignTransaction.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +2 -10
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -28
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/near/NearSignTransaction.d.ts.map +1 -1
- package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -1
- package/dist/api/neo/NeoGetAddress.d.ts +8 -2
- package/dist/api/neo/NeoGetAddress.d.ts.map +1 -1
- package/dist/api/neo/NeoSignTransaction.d.ts +8 -2
- package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
- package/dist/api/nervos/NervosGetAddress.d.ts +9 -2
- package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -1
- package/dist/api/nervos/NervosSignTransaction.d.ts +9 -2
- package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
- package/dist/api/nexa/NexaGetAddress.d.ts +8 -2
- package/dist/api/nexa/NexaGetAddress.d.ts.map +1 -1
- package/dist/api/nexa/NexaSignTransaction.d.ts +9 -2
- package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
- package/dist/api/nostr/NostrSignEvent.d.ts.map +1 -1
- package/dist/api/nostr/NostrSignSchnorr.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotSignTransaction.d.ts.map +1 -1
- package/dist/api/scdo/ScdoGetAddress.d.ts +6 -2
- package/dist/api/scdo/ScdoGetAddress.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignMessage.d.ts +5 -2
- package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignTransaction.d.ts +5 -2
- package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
- package/dist/api/solana/SolGetAddress.d.ts +0 -6
- package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
- package/dist/api/solana/SolSignMessage.d.ts +0 -4
- package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +0 -4
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +0 -8
- package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
- package/dist/api/starcoin/StarcoinSignMessage.d.ts.map +1 -1
- package/dist/api/starcoin/StarcoinSignTransaction.d.ts.map +1 -1
- package/dist/api/stellar/StellarGetAddress.d.ts +1 -2
- package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -2
- package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +2 -2
- package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
- package/dist/api/ton/TonSignData.d.ts.map +1 -1
- package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
- package/dist/api/ton/TonSignProof.d.ts.map +1 -1
- package/dist/api/tron/TronGetAddress.d.ts +0 -4
- package/dist/api/tron/TronGetAddress.d.ts.map +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +0 -4
- package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
- package/dist/api/tron/TronSignTransaction.d.ts +0 -4
- package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
- package/dist/api/xrp/XrpSignTransaction.d.ts.map +1 -1
- package/dist/core/PollingStateManager.d.ts +8 -0
- package/dist/core/PollingStateManager.d.ts.map +1 -0
- package/dist/core/RequestQueue.d.ts +1 -1
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +4 -7
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/MessagesConfig.d.ts +2 -2
- package/dist/data-manager/MessagesConfig.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts +4 -5
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +18 -5
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +8 -8
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +1 -2
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +0 -8
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +43 -292
- package/dist/index.js +1003 -16199
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +1 -1
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +0 -7
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/getPassphraseState.d.ts +1 -10
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +3 -33
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/preInitialize.d.ts +3 -0
- package/dist/types/api/preInitialize.d.ts.map +1 -0
- package/dist/types/api/searchDevices.d.ts +2 -2
- package/dist/types/api/searchDevices.d.ts.map +1 -1
- package/dist/types/device.d.ts +2 -6
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +1 -2
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +1 -1
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +3 -5
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts +0 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/versionUtils.d.ts +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +82 -7
- package/src/api/FirmwareUpdateV3.ts +4 -21
- package/src/api/GetOnekeyFeatures.ts +3 -75
- package/src/api/GetPassphraseState.ts +7 -16
- package/src/api/SearchDevices.ts +2 -7
- package/src/api/alephium/AlephiumGetAddress.ts +2 -6
- package/src/api/alephium/AlephiumSignMessage.ts +2 -6
- package/src/api/alephium/AlephiumSignTransaction.ts +3 -6
- package/src/api/algo/AlgoSignTransaction.ts +1 -0
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +9 -18
- package/src/api/aptos/AptosSignInMessage.ts +1 -0
- package/src/api/aptos/AptosSignMessage.ts +1 -0
- package/src/api/aptos/AptosSignTransaction.ts +1 -0
- package/src/api/benfen/BenfenGetAddress.ts +2 -6
- package/src/api/benfen/BenfenGetPublicKey.ts +2 -6
- package/src/api/benfen/BenfenSignMessage.ts +2 -6
- package/src/api/benfen/BenfenSignTransaction.ts +2 -6
- package/src/api/btc/BTCSignMessage.ts +1 -0
- package/src/api/btc/BTCSignPsbt.ts +1 -0
- package/src/api/btc/BTCSignTransaction.ts +1 -0
- package/src/api/btc/helpers/versionLimit.ts +1 -7
- package/src/api/cardano/CardanoSignMessage.ts +1 -0
- package/src/api/cardano/CardanoSignTransaction.ts +1 -0
- package/src/api/conflux/ConfluxSignMessage.ts +1 -0
- package/src/api/conflux/ConfluxSignMessageCIP23.ts +1 -0
- package/src/api/conflux/ConfluxSignTransaction.ts +3 -5
- package/src/api/cosmos/CosmosSignTransaction.ts +1 -0
- package/src/api/device/DeviceRebootToBoardloader.ts +1 -10
- package/src/api/device/DeviceRebootToBootloader.ts +1 -10
- package/src/api/device/PreInitialize.ts +41 -0
- package/src/api/dynex/DnxGetAddress.ts +0 -7
- package/src/api/dynex/DnxSignTransaction.ts +1 -7
- package/src/api/evm/EVMGetAddress.ts +1 -1
- package/src/api/evm/EVMGetPublicKey.ts +1 -1
- package/src/api/evm/EVMSignMessage.ts +3 -1
- package/src/api/evm/EVMSignMessageEIP712.ts +2 -14
- package/src/api/evm/EVMSignTransaction.ts +3 -1
- package/src/api/evm/EVMSignTypedData.ts +8 -6
- package/src/api/evm/EVMVerifyMessage.ts +1 -1
- package/src/api/filecoin/FilecoinSignTransaction.ts +1 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +4 -27
- package/src/api/index.ts +1 -30
- package/src/api/kaspa/KaspaSignTransaction.ts +1 -0
- package/src/api/near/NearSignTransaction.ts +1 -0
- package/src/api/nem/NEMSignTransaction.ts +1 -0
- package/src/api/neo/NeoGetAddress.ts +1 -6
- package/src/api/neo/NeoSignTransaction.ts +2 -6
- package/src/api/nervos/NervosGetAddress.ts +2 -6
- package/src/api/nervos/NervosSignTransaction.ts +3 -6
- package/src/api/nexa/NexaGetAddress.ts +2 -6
- package/src/api/nexa/NexaSignTransaction.ts +4 -6
- package/src/api/nostr/NostrSignEvent.ts +1 -0
- package/src/api/nostr/NostrSignSchnorr.ts +1 -0
- package/src/api/polkadot/PolkadotSignTransaction.ts +1 -0
- package/src/api/scdo/ScdoGetAddress.ts +2 -6
- package/src/api/scdo/ScdoSignMessage.ts +2 -6
- package/src/api/scdo/ScdoSignTransaction.ts +3 -6
- package/src/api/solana/SolGetAddress.ts +0 -9
- package/src/api/solana/SolSignMessage.ts +1 -4
- package/src/api/solana/SolSignOffchainMessage.ts +1 -4
- package/src/api/solana/SolSignTransaction.ts +1 -8
- package/src/api/starcoin/StarcoinSignMessage.ts +1 -0
- package/src/api/starcoin/StarcoinSignTransaction.ts +1 -0
- package/src/api/stellar/StellarGetAddress.ts +1 -10
- package/src/api/stellar/StellarSignTransaction.ts +2 -14
- package/src/api/sui/SuiSignMessage.ts +1 -0
- package/src/api/sui/SuiSignTransaction.ts +10 -12
- package/src/api/ton/TonSignData.ts +1 -0
- package/src/api/ton/TonSignMessage.ts +1 -0
- package/src/api/ton/TonSignProof.ts +1 -0
- package/src/api/tron/TronGetAddress.ts +0 -4
- package/src/api/tron/TronSignMessage.ts +2 -5
- package/src/api/tron/TronSignTransaction.ts +1 -4
- package/src/api/xrp/XrpSignTransaction.ts +2 -1
- package/src/core/PollingStateManager.ts +47 -0
- package/src/core/RequestQueue.ts +10 -3
- package/src/core/index.ts +153 -62
- package/src/data-manager/DataManager.ts +7 -12
- package/src/data-manager/MessagesConfig.ts +14 -14
- package/src/data-manager/TransportManager.ts +12 -38
- package/src/device/Device.ts +77 -88
- package/src/device/DeviceCommands.ts +26 -166
- package/src/device/DeviceConnector.ts +4 -29
- package/src/device/DevicePool.ts +1 -1
- package/src/events/ui-request.ts +0 -8
- package/src/inject.ts +2 -46
- package/src/types/api/export.ts +0 -1
- package/src/types/api/firmwareUpdate.ts +0 -12
- package/src/types/api/getPassphraseState.ts +2 -13
- package/src/types/api/index.ts +3 -80
- package/src/types/api/preInitialize.ts +3 -0
- package/src/types/api/searchDevices.ts +2 -2
- package/src/types/device.ts +2 -33
- package/src/types/params.ts +2 -4
- package/src/types/settings.ts +1 -1
- package/src/utils/deviceFeaturesUtils.ts +21 -62
- package/src/utils/deviceInfoUtils.ts +8 -15
- package/src/utils/index.ts +0 -1
- package/__tests__/protocol-v2.test.ts +0 -1661
- package/dist/api/DirList.d.ts +0 -10
- package/dist/api/DirList.d.ts.map +0 -1
- package/dist/api/DirMake.d.ts +0 -9
- package/dist/api/DirMake.d.ts.map +0 -1
- package/dist/api/DirRemove.d.ts +0 -9
- package/dist/api/DirRemove.d.ts.map +0 -1
- package/dist/api/FileDelete.d.ts +0 -9
- package/dist/api/FileDelete.d.ts.map +0 -1
- package/dist/api/FileRead.d.ts +0 -19
- package/dist/api/FileRead.d.ts.map +0 -1
- package/dist/api/FileWrite.d.ts +0 -23
- package/dist/api/FileWrite.d.ts.map +0 -1
- package/dist/api/FirmwareUpdateV4.d.ts +0 -32
- package/dist/api/FirmwareUpdateV4.d.ts.map +0 -1
- package/dist/api/GetDeviceInfo.d.ts +0 -9
- package/dist/api/GetDeviceInfo.d.ts.map +0 -1
- package/dist/api/PathInfo.d.ts +0 -9
- package/dist/api/PathInfo.d.ts.map +0 -1
- package/dist/api/helpers/deviceInfo.d.ts +0 -15
- package/dist/api/helpers/deviceInfo.d.ts.map +0 -1
- package/dist/api/helpers/filesystemValidation.d.ts +0 -7
- package/dist/api/helpers/filesystemValidation.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +0 -7
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts +0 -7
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceReboot.d.ts +0 -7
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +0 -1
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +0 -7
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +0 -1
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +0 -6
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +0 -10
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts.map +0 -1
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +0 -6
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +0 -1
- package/dist/api/protocol-v2/FilesystemFormat.d.ts +0 -6
- package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +0 -1
- package/dist/api/protocol-v2/GetProtoVersion.d.ts +0 -6
- package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +0 -1
- package/dist/api/protocol-v2/Ping.d.ts +0 -8
- package/dist/api/protocol-v2/Ping.d.ts.map +0 -1
- package/dist/api/protocol-v2/helpers.d.ts +0 -49
- package/dist/api/protocol-v2/helpers.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/features.d.ts +0 -104
- package/dist/protocols/protocol-v2/features.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/firmware.d.ts +0 -12
- package/dist/protocols/protocol-v2/firmware.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/index.d.ts +0 -3
- package/dist/protocols/protocol-v2/index.d.ts.map +0 -1
- package/dist/types/api/getDeviceInfo.d.ts +0 -84
- package/dist/types/api/getDeviceInfo.d.ts.map +0 -1
- package/dist/types/api/protocolV2.d.ts +0 -127
- package/dist/types/api/protocolV2.d.ts.map +0 -1
- package/src/api/DirList.ts +0 -29
- package/src/api/DirMake.ts +0 -21
- package/src/api/DirRemove.ts +0 -21
- package/src/api/FileDelete.ts +0 -21
- package/src/api/FileRead.ts +0 -165
- package/src/api/FileWrite.ts +0 -203
- package/src/api/FirmwareUpdateV4.ts +0 -810
- package/src/api/GetDeviceInfo.ts +0 -161
- package/src/api/PathInfo.ts +0 -25
- package/src/api/helpers/deviceInfo.ts +0 -205
- package/src/api/helpers/filesystemValidation.ts +0 -51
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +0 -50
- package/src/api/protocol-v2/DeviceGetDeviceInfo.ts +0 -35
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +0 -18
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +0 -18
- package/src/api/protocol-v2/DeviceReboot.ts +0 -22
- package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +0 -27
- package/src/api/protocol-v2/FactoryGetDeviceInfo.ts +0 -18
- package/src/api/protocol-v2/FilesystemDiskControl.ts +0 -34
- package/src/api/protocol-v2/FilesystemFixPermission.ts +0 -14
- package/src/api/protocol-v2/FilesystemFormat.ts +0 -14
- package/src/api/protocol-v2/GetProtoVersion.ts +0 -14
- package/src/api/protocol-v2/Ping.ts +0 -16
- package/src/api/protocol-v2/helpers.ts +0 -161
- package/src/data/messages/messages-protocol-v2.json +0 -13128
- package/src/protocols/protocol-v2/features.ts +0 -287
- package/src/protocols/protocol-v2/firmware.ts +0 -26
- package/src/protocols/protocol-v2/index.ts +0 -2
- package/src/types/api/getDeviceInfo.ts +0 -97
- package/src/types/api/protocolV2.ts +0 -226
package/src/core/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
2
|
import EventEmitter from 'events';
|
|
3
3
|
import {
|
|
4
|
-
EDeviceType,
|
|
5
4
|
ERRORS,
|
|
6
5
|
ERROR_CODES_REQUIRE_RELEASE,
|
|
7
6
|
HardwareError,
|
|
@@ -20,11 +19,9 @@ import {
|
|
|
20
19
|
enableLog,
|
|
21
20
|
getDeviceBLEFirmwareVersion,
|
|
22
21
|
getDeviceFirmwareVersion,
|
|
23
|
-
getDeviceType,
|
|
24
22
|
getFirmwareType,
|
|
25
23
|
getLogger,
|
|
26
24
|
getMethodVersionRange,
|
|
27
|
-
isMethodVersionRangeUnsupported,
|
|
28
25
|
setLoggerPostMessage,
|
|
29
26
|
wait,
|
|
30
27
|
} from '../utils';
|
|
@@ -45,6 +42,7 @@ import {
|
|
|
45
42
|
import { Device } from '../device/Device';
|
|
46
43
|
import { DeviceList } from '../device/DeviceList';
|
|
47
44
|
import { DevicePool } from '../device/DevicePool';
|
|
45
|
+
import { PollingStateManager } from './PollingStateManager';
|
|
48
46
|
import { findMethod } from '../api/utils';
|
|
49
47
|
import { DataManager } from '../data-manager';
|
|
50
48
|
import { UI_REQUEST as UI_REQUEST_CONST } from '../constants/ui-request';
|
|
@@ -76,6 +74,12 @@ import type {
|
|
|
76
74
|
import type { BaseMethod } from '../api/BaseMethod';
|
|
77
75
|
|
|
78
76
|
const Log = getLogger(LoggerNames.Core);
|
|
77
|
+
const PRE_INITIALIZE_TTL_MS = 60 * 1000;
|
|
78
|
+
|
|
79
|
+
// Dedup/coalesce state for "pre-warm signal" methods (isPreWarmSignal),
|
|
80
|
+
// keyed by getPreWarmKey(): coalesce in-flight, skip if warmed within TTL.
|
|
81
|
+
const preWarmInflight = new Map<string, Promise<any>>();
|
|
82
|
+
const preWarmDoneAt = new Map<string, number>();
|
|
79
83
|
|
|
80
84
|
export type CoreContext = ReturnType<Core['getCoreContext']>;
|
|
81
85
|
|
|
@@ -98,7 +102,6 @@ const parseInitOptions = (method?: BaseMethod): InitOptions => ({
|
|
|
98
102
|
passphraseState: method?.payload.passphraseState,
|
|
99
103
|
deviceId: method?.payload.deviceId,
|
|
100
104
|
deriveCardano: method && hasDeriveCardano(method),
|
|
101
|
-
connectProtocol: method?.payload.connectProtocol,
|
|
102
105
|
});
|
|
103
106
|
|
|
104
107
|
let _core: Core;
|
|
@@ -107,8 +110,7 @@ let _connector: DeviceConnector | undefined;
|
|
|
107
110
|
let _uiPromises: UiPromise<UiPromiseResponse['type']>[] = []; // Waiting for ui response
|
|
108
111
|
|
|
109
112
|
const deviceCacheMap = new Map<string, Device>();
|
|
110
|
-
|
|
111
|
-
const pollingState: Record<number, boolean> = {};
|
|
113
|
+
const pollingManager = new PollingStateManager();
|
|
112
114
|
|
|
113
115
|
let preConnectCache: {
|
|
114
116
|
passphraseState: string | undefined;
|
|
@@ -210,9 +212,63 @@ export const callAPI = async (context: CoreContext, message: CoreMessage) => {
|
|
|
210
212
|
return createResponseMessage(method.responseID, false, { error });
|
|
211
213
|
}
|
|
212
214
|
|
|
215
|
+
// only the pre-warm signal (PreInitialize) forks here; normal methods fall
|
|
216
|
+
// through to onCallDevice below, so the pre-warm dedup/guards never touch them
|
|
217
|
+
if (method.isPreWarmSignal) {
|
|
218
|
+
return handlePreWarmSignal(context, message, method);
|
|
219
|
+
}
|
|
220
|
+
|
|
213
221
|
return onCallDevice(context, message, method);
|
|
214
222
|
};
|
|
215
223
|
|
|
224
|
+
// Wrapper for "pre-warm signal" methods: coalesce in-flight same-key pre-warm,
|
|
225
|
+
// skip if warmed within TTL, else run + track. The "hang up so the next real
|
|
226
|
+
// call waits" part lives in onCallDevice (setPrePendingCallPromise).
|
|
227
|
+
const handlePreWarmSignal = async (
|
|
228
|
+
context: CoreContext,
|
|
229
|
+
message: CoreMessage,
|
|
230
|
+
method: BaseMethod
|
|
231
|
+
): Promise<any> => {
|
|
232
|
+
// no connectId: can't target a device safely, skip pre-warm (ack only)
|
|
233
|
+
if (!method.connectId) {
|
|
234
|
+
return createResponseMessage(method.responseID, true, true);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const key = method.getPreWarmKey();
|
|
238
|
+
|
|
239
|
+
const inflight = preWarmInflight.get(key);
|
|
240
|
+
if (inflight) {
|
|
241
|
+
// reply with THIS call's responseID (not the other call's response object)
|
|
242
|
+
try {
|
|
243
|
+
await inflight;
|
|
244
|
+
} catch {
|
|
245
|
+
// pre-warm is best-effort; ignore its failure for the coalesced caller
|
|
246
|
+
}
|
|
247
|
+
return createResponseMessage(method.responseID, true, true);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const doneAt = preWarmDoneAt.get(key);
|
|
251
|
+
if (typeof doneAt === 'number' && Date.now() - doneAt <= method.preWarmTtl) {
|
|
252
|
+
return createResponseMessage(method.responseID, true, true);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const run = onCallDevice(context, message, method);
|
|
256
|
+
preWarmInflight.set(key, run);
|
|
257
|
+
try {
|
|
258
|
+
const result = await run;
|
|
259
|
+
// Only remember the warm if it actually succeeded — a failed pre-warm must
|
|
260
|
+
// not suppress the next pre-warm within the TTL.
|
|
261
|
+
if (result?.success === true && result?.payload === true) {
|
|
262
|
+
preWarmDoneAt.set(key, Date.now());
|
|
263
|
+
}
|
|
264
|
+
return result;
|
|
265
|
+
} finally {
|
|
266
|
+
if (preWarmInflight.get(key) === run) {
|
|
267
|
+
preWarmInflight.delete(key);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
216
272
|
const waitWithTimeout = async (promise: Promise<any>, timeout: number) => {
|
|
217
273
|
const timeoutPromise = new Promise((_, reject) => {
|
|
218
274
|
setTimeout(() => reject(new Error('Request timeout')), timeout);
|
|
@@ -248,7 +304,15 @@ const onCallDevice = async (
|
|
|
248
304
|
|
|
249
305
|
updateMethodRequestContext(method, { status: 'running' });
|
|
250
306
|
|
|
251
|
-
|
|
307
|
+
// Normalize undefined / null / '' to '' — they all mean "main wallet, no
|
|
308
|
+
// passphrase". Without this, the first call (preConnectCache starts undefined)
|
|
309
|
+
// or any '' call after a non-'' one is wrongly treated as a passphrase switch
|
|
310
|
+
// and needlessly clears the device cache -> forces a re-enumeration Initialize.
|
|
311
|
+
// A real switch ('' <-> 'stateX', or 'stateX' <-> 'stateY') still differs.
|
|
312
|
+
const normalizePassphraseState = (s?: string | null) => s || '';
|
|
313
|
+
const connectStateChange =
|
|
314
|
+
normalizePassphraseState(preConnectCache.passphraseState) !==
|
|
315
|
+
normalizePassphraseState(method.payload.passphraseState);
|
|
252
316
|
|
|
253
317
|
preConnectCache = {
|
|
254
318
|
passphraseState: method.payload.passphraseState,
|
|
@@ -268,18 +332,31 @@ const onCallDevice = async (
|
|
|
268
332
|
|
|
269
333
|
const task = requestQueue.createTask(method);
|
|
270
334
|
|
|
335
|
+
// Pre-warm holds the device as a per-connectId callback task so a concurrent
|
|
336
|
+
// real call waits (before ensureConnected) instead of racing its Initialize.
|
|
337
|
+
// Only covers pre-warm -> real-call ordering; the reverse is fail-closed.
|
|
338
|
+
let preWarmCallbackTask: Deferred<void> | undefined;
|
|
339
|
+
if (method.isPreWarmSignal && method.connectId) {
|
|
340
|
+
preWarmCallbackTask = createDeferred<void>();
|
|
341
|
+
context.registerCallbackTask(method.connectId, preWarmCallbackTask);
|
|
342
|
+
}
|
|
343
|
+
|
|
271
344
|
let device: Device;
|
|
272
345
|
try {
|
|
273
346
|
/**
|
|
274
347
|
* Polling to ensure successful connection
|
|
275
348
|
*/
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
349
|
+
const connectId = method.connectId ?? '';
|
|
350
|
+
const pollingId = pollingManager.start(connectId);
|
|
351
|
+
device = await ensureConnected(
|
|
352
|
+
context,
|
|
353
|
+
method,
|
|
354
|
+
connectId,
|
|
355
|
+
pollingId,
|
|
356
|
+
task.abortController?.signal
|
|
357
|
+
);
|
|
282
358
|
} catch (e) {
|
|
359
|
+
preWarmCallbackTask?.resolve();
|
|
283
360
|
console.log('ensureConnected error: ', e);
|
|
284
361
|
|
|
285
362
|
completeMethodRequestContext(method, e);
|
|
@@ -295,6 +372,7 @@ const onCallDevice = async (
|
|
|
295
372
|
}
|
|
296
373
|
|
|
297
374
|
if (method.payload?.onlyConnectBleDevice) {
|
|
375
|
+
preWarmCallbackTask?.resolve();
|
|
298
376
|
Log.debug('Call API - only connect ble device: ', device?.mainId);
|
|
299
377
|
return createResponseMessage(method.responseID, true, null);
|
|
300
378
|
}
|
|
@@ -334,8 +412,9 @@ const onCallDevice = async (
|
|
|
334
412
|
);
|
|
335
413
|
|
|
336
414
|
try {
|
|
415
|
+
// Wait for any pending task except our own (self-wait would deadlock).
|
|
337
416
|
if (method.connectId) {
|
|
338
|
-
await context.waitForCallbackTasks(method.connectId);
|
|
417
|
+
await context.waitForCallbackTasks(method.connectId, preWarmCallbackTask);
|
|
339
418
|
}
|
|
340
419
|
|
|
341
420
|
await waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
@@ -396,10 +475,6 @@ const onCallDevice = async (
|
|
|
396
475
|
);
|
|
397
476
|
}
|
|
398
477
|
|
|
399
|
-
if (isMethodVersionRangeUnsupported(versionRange)) {
|
|
400
|
-
throw createDeviceNotSupportMethodError(method.name, getFirmwareType(device.features));
|
|
401
|
-
}
|
|
402
|
-
|
|
403
478
|
if (versionRange) {
|
|
404
479
|
if (
|
|
405
480
|
semver.valid(versionRange.min) &&
|
|
@@ -479,7 +554,7 @@ const onCallDevice = async (
|
|
|
479
554
|
// Check to see if it is safe to use Passphrase
|
|
480
555
|
checkPassphraseEnableState(method, device.features);
|
|
481
556
|
|
|
482
|
-
if (
|
|
557
|
+
if (device.hasUsePassphrase() && method.useDevicePassphraseState) {
|
|
483
558
|
// check version
|
|
484
559
|
const support = supportNewPassphrase(device.features);
|
|
485
560
|
if (!support.support) {
|
|
@@ -533,7 +608,6 @@ const onCallDevice = async (
|
|
|
533
608
|
|
|
534
609
|
try {
|
|
535
610
|
const response: object = await method.run();
|
|
536
|
-
Log.debug('Call API - Inner Method Run: ');
|
|
537
611
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
538
612
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
539
613
|
completeMethodRequestContext(method);
|
|
@@ -556,6 +630,7 @@ const onCallDevice = async (
|
|
|
556
630
|
|
|
557
631
|
const runOptions: RunOptions = {
|
|
558
632
|
keepSession: method.payload.keepSession,
|
|
633
|
+
skipInitialize: canSkipInitialize(method, device),
|
|
559
634
|
...parseInitOptions(method),
|
|
560
635
|
};
|
|
561
636
|
const deviceRun = () => device.run(inner, runOptions);
|
|
@@ -577,6 +652,9 @@ const onCallDevice = async (
|
|
|
577
652
|
Log.debug('Call API - Run Error: ', error);
|
|
578
653
|
completeMethodRequestContext(method, error);
|
|
579
654
|
} finally {
|
|
655
|
+
// Release the pre-warm callback task so the next real call can proceed.
|
|
656
|
+
preWarmCallbackTask?.resolve();
|
|
657
|
+
|
|
580
658
|
const response = messageResponse;
|
|
581
659
|
|
|
582
660
|
if (response) {
|
|
@@ -656,7 +734,6 @@ function initDevice(method: BaseMethod) {
|
|
|
656
734
|
} else if (allDevices.length > 1) {
|
|
657
735
|
throw ERRORS.TypedError(
|
|
658
736
|
[
|
|
659
|
-
'firmwareUpdateV4',
|
|
660
737
|
'firmwareUpdateV3',
|
|
661
738
|
'firmwareUpdateV2',
|
|
662
739
|
'checkFirmwareRelease',
|
|
@@ -707,38 +784,59 @@ function initDeviceForBle(method: BaseMethod) {
|
|
|
707
784
|
}
|
|
708
785
|
|
|
709
786
|
/**
|
|
710
|
-
*
|
|
787
|
+
* Check if we can skip initialize for this method
|
|
711
788
|
*/
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
);
|
|
789
|
+
function canSkipInitialize(method: BaseMethod, device: Device): boolean {
|
|
790
|
+
const reasons: string[] = [];
|
|
791
|
+
// only sign-style methods opt in; getAddress/getPublicKey never do
|
|
792
|
+
if (!method.allowUsePreInitialize) reasons.push('method.disallow');
|
|
793
|
+
// caller must opt in per call
|
|
794
|
+
if (!method.payload?.usePreInitialize) reasons.push('payload.usePreInitialize=false');
|
|
795
|
+
// no connectId: can't pin the target device, never skip
|
|
796
|
+
if (!method.connectId) reasons.push('connectId.missing');
|
|
797
|
+
// passphrase state must match the pre-initialize
|
|
798
|
+
if (!device.isPreInitializeMetaMatch(method.payload)) reasons.push('meta.mismatch');
|
|
799
|
+
// device must have been initialized before (has features)
|
|
800
|
+
if (!device.features) reasons.push('features.missing');
|
|
801
|
+
// within pre-initialize TTL
|
|
802
|
+
if (!device.isPreInitializedValid(PRE_INITIALIZE_TTL_MS)) reasons.push('ttl.expired');
|
|
803
|
+
|
|
804
|
+
if (reasons.length) {
|
|
805
|
+
Log.debug(`[PRE-INIT][MISS] method=${method.name} ${reasons.join(',')}`);
|
|
806
|
+
return false;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
const savedMs = device.getLastInitializeDuration();
|
|
810
|
+
const saved = typeof savedMs === 'number' ? `saved ${savedMs}ms` : 'within TTL + meta match';
|
|
811
|
+
Log.debug(`[PRE-INIT][HIT] method=${method.name} skip Initialize (${saved})`);
|
|
812
|
+
|
|
813
|
+
return true;
|
|
722
814
|
}
|
|
723
815
|
|
|
724
|
-
|
|
816
|
+
/**
|
|
817
|
+
* If the Bluetooth connection times out, retry up to 6 times
|
|
818
|
+
* @param retryCount - Current retry count (default 0)
|
|
819
|
+
*/
|
|
820
|
+
async function connectDeviceForBle(method: BaseMethod, device: Device, retryCount = 0) {
|
|
725
821
|
try {
|
|
726
|
-
await device.acquire(
|
|
822
|
+
await device.acquire();
|
|
727
823
|
if (method.payload?.onlyConnectBleDevice) {
|
|
728
824
|
return;
|
|
729
825
|
}
|
|
730
|
-
|
|
826
|
+
// Skip initialize if conditions are met
|
|
827
|
+
if (!canSkipInitialize(method, device)) {
|
|
828
|
+
const initOptions = parseInitOptions(method);
|
|
829
|
+
await device.initialize(initOptions);
|
|
830
|
+
device.markPreInitialized({
|
|
831
|
+
passphraseState: initOptions.passphraseState,
|
|
832
|
+
});
|
|
833
|
+
}
|
|
731
834
|
} catch (err) {
|
|
732
|
-
if (
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
isRetryableBleProtocolV2ProbeError(method, err)) &&
|
|
736
|
-
bleTimeoutRetry <= 5
|
|
737
|
-
) {
|
|
738
|
-
bleTimeoutRetry += 1;
|
|
739
|
-
Log.debug(`Bletooth connect timeout and will retry, retry count: ${bleTimeoutRetry}`);
|
|
835
|
+
if (err.errorCode === HardwareErrorCode.BleTimeoutError && retryCount < 6) {
|
|
836
|
+
const nextRetry = retryCount + 1;
|
|
837
|
+
Log.debug(`Bluetooth connect timeout and will retry, retry count: ${nextRetry}`);
|
|
740
838
|
await wait(3000);
|
|
741
|
-
await connectDeviceForBle(method, device);
|
|
839
|
+
await connectDeviceForBle(method, device, nextRetry);
|
|
742
840
|
} else {
|
|
743
841
|
throw err;
|
|
744
842
|
}
|
|
@@ -750,6 +848,7 @@ type IPollFn<T> = (time?: number) => T;
|
|
|
750
848
|
const ensureConnected = async (
|
|
751
849
|
_context: CoreContext,
|
|
752
850
|
method: BaseMethod,
|
|
851
|
+
connectId: string,
|
|
753
852
|
pollingId: number,
|
|
754
853
|
abortSignal?: AbortSignal
|
|
755
854
|
) => {
|
|
@@ -781,7 +880,7 @@ const ensureConnected = async (
|
|
|
781
880
|
return;
|
|
782
881
|
}
|
|
783
882
|
|
|
784
|
-
if (!
|
|
883
|
+
if (!pollingManager.isActive(connectId, pollingId)) {
|
|
785
884
|
Log.debug('EnsureConnected function stop, polling id: ', pollingId);
|
|
786
885
|
reject(ERRORS.TypedError(HardwareErrorCode.PollingStop));
|
|
787
886
|
return;
|
|
@@ -839,8 +938,6 @@ const ensureConnected = async (
|
|
|
839
938
|
* Bluetooth should call initialize here
|
|
840
939
|
*/
|
|
841
940
|
if (DataManager.isBleConnect(env)) {
|
|
842
|
-
bleTimeoutRetry = 0;
|
|
843
|
-
|
|
844
941
|
if (abort()) {
|
|
845
942
|
return;
|
|
846
943
|
}
|
|
@@ -903,7 +1000,7 @@ const ensureConnected = async (
|
|
|
903
1000
|
// eslint-disable-next-line no-promise-executor-return
|
|
904
1001
|
return setTimeout(() => resolve(poll(time * 1.5)), time);
|
|
905
1002
|
});
|
|
906
|
-
|
|
1003
|
+
// pollingManager.start(connectId) already registered this pollingId as active
|
|
907
1004
|
return poll();
|
|
908
1005
|
};
|
|
909
1006
|
|
|
@@ -1012,16 +1109,6 @@ const checkPassphraseEnableState = (method: BaseMethod, features?: Features) =>
|
|
|
1012
1109
|
}
|
|
1013
1110
|
};
|
|
1014
1111
|
|
|
1015
|
-
const shouldCheckPassphraseState = (method: BaseMethod, device: Device) => {
|
|
1016
|
-
if (!method.useDevicePassphraseState) return false;
|
|
1017
|
-
|
|
1018
|
-
const isPro2 = getDeviceType(device.features) === EDeviceType.Pro2;
|
|
1019
|
-
const pro2ExplicitWalletSelection =
|
|
1020
|
-
isPro2 && (!!method.payload?.passphraseState || !!method.payload?.useEmptyPassphrase);
|
|
1021
|
-
|
|
1022
|
-
return device.hasUsePassphrase() || pro2ExplicitWalletSelection;
|
|
1023
|
-
};
|
|
1024
|
-
|
|
1025
1112
|
const cleanup = () => {
|
|
1026
1113
|
_uiPromises = [];
|
|
1027
1114
|
Log.debug('Cleanup...');
|
|
@@ -1047,6 +1134,7 @@ const onDeviceConnectHandler = (device: Device) => {
|
|
|
1047
1134
|
};
|
|
1048
1135
|
|
|
1049
1136
|
const onDeviceDisconnectHandler = (device: Device) => {
|
|
1137
|
+
device.clearPreInitialized();
|
|
1050
1138
|
const env = DataManager.getSettings('env');
|
|
1051
1139
|
const deviceObject = DataManager.isBleConnect(env) ? device : device.toMessageObject();
|
|
1052
1140
|
postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject as KnownDevice }));
|
|
@@ -1223,8 +1311,8 @@ export default class Core extends EventEmitter {
|
|
|
1223
1311
|
registerCallbackTask: (connectId: string, callbackPromise: Deferred<any>) => {
|
|
1224
1312
|
this.requestQueue.registerPendingCallbackTask(connectId, callbackPromise);
|
|
1225
1313
|
},
|
|
1226
|
-
waitForCallbackTasks: (connectId: string) =>
|
|
1227
|
-
this.requestQueue.waitForPendingCallbackTasks(connectId),
|
|
1314
|
+
waitForCallbackTasks: (connectId: string, exceptTask?: Deferred<void>) =>
|
|
1315
|
+
this.requestQueue.waitForPendingCallbackTasks(connectId, exceptTask),
|
|
1228
1316
|
cancelCallbackTasks: (connectId: string) => this.requestQueue.cancelCallbackTasks(connectId),
|
|
1229
1317
|
};
|
|
1230
1318
|
}
|
|
@@ -1255,10 +1343,10 @@ export default class Core extends EventEmitter {
|
|
|
1255
1343
|
}
|
|
1256
1344
|
|
|
1257
1345
|
case IFRAME.CALL: {
|
|
1258
|
-
Log.log(
|
|
1346
|
+
Log.log(`[${Date.now()}][CALL_API]`, message);
|
|
1259
1347
|
const response = await callAPI(this.getCoreContext(), message);
|
|
1260
1348
|
const { success, payload } = response;
|
|
1261
|
-
Log.log(
|
|
1349
|
+
Log.log(`[${Date.now()}][CALL_API_RESPONSE]`, response);
|
|
1262
1350
|
if (success) {
|
|
1263
1351
|
return response;
|
|
1264
1352
|
}
|
|
@@ -1291,6 +1379,9 @@ export default class Core extends EventEmitter {
|
|
|
1291
1379
|
dispose() {
|
|
1292
1380
|
_deviceList = undefined;
|
|
1293
1381
|
_connector = undefined;
|
|
1382
|
+
deviceCacheMap.clear();
|
|
1383
|
+
preWarmInflight.clear();
|
|
1384
|
+
preWarmDoneAt.clear();
|
|
1294
1385
|
Log.debug(`[Core] Disposing SDK instance: ${this.sdkInstanceId}`);
|
|
1295
1386
|
cleanupSdkInstance(this.sdkInstanceId);
|
|
1296
1387
|
}
|
|
@@ -4,7 +4,6 @@ import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
|
4
4
|
|
|
5
5
|
import MessagesJSON from '../data/messages/messages.json';
|
|
6
6
|
import MessagesLegacyV1JSON from '../data/messages/messages_legacy_v1.json';
|
|
7
|
-
import MessagesProtocolV2JSON from '../data/messages/messages-protocol-v2.json';
|
|
8
7
|
import {
|
|
9
8
|
LoggerNames,
|
|
10
9
|
getDeviceBLEFirmwareVersion,
|
|
@@ -41,8 +40,7 @@ export const FIRMWARE_FIELDS = [
|
|
|
41
40
|
|
|
42
41
|
export type IFirmwareField = (typeof FIRMWARE_FIELDS)[number];
|
|
43
42
|
|
|
44
|
-
export type
|
|
45
|
-
export type ProtobufMessageSchema = ProtocolV1MessageSchema | 'v2Schema';
|
|
43
|
+
export type MessageVersion = 'latest' | 'v1';
|
|
46
44
|
|
|
47
45
|
const FIRMWARE_FIELD_TYPE_MAP: Readonly<Record<IFirmwareField, EFirmwareType>> = {
|
|
48
46
|
firmware: EFirmwareType.Universal,
|
|
@@ -64,9 +62,7 @@ function getFirmwareTypeFromField(firmwareField: IFirmwareField): EFirmwareType
|
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
export default class DataManager {
|
|
67
|
-
static deviceMap: DeviceTypeMap
|
|
68
|
-
[k: string]: DeviceTypeMap[keyof DeviceTypeMap] | undefined;
|
|
69
|
-
} = {
|
|
65
|
+
static deviceMap: DeviceTypeMap = {
|
|
70
66
|
[EDeviceType.Classic]: {
|
|
71
67
|
firmware: [],
|
|
72
68
|
ble: [],
|
|
@@ -97,10 +93,9 @@ export default class DataManager {
|
|
|
97
93
|
|
|
98
94
|
static settings: ConnectSettings;
|
|
99
95
|
|
|
100
|
-
static messages: { [
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
v2Schema: MessagesProtocolV2JSON as unknown as JSON,
|
|
96
|
+
static messages: { [version in MessageVersion]: JSON } = {
|
|
97
|
+
latest: MessagesJSON as unknown as JSON,
|
|
98
|
+
v1: MessagesLegacyV1JSON as unknown as JSON,
|
|
104
99
|
};
|
|
105
100
|
|
|
106
101
|
static lastCheckTimestamp = 0;
|
|
@@ -477,8 +472,8 @@ export default class DataManager {
|
|
|
477
472
|
}
|
|
478
473
|
}
|
|
479
474
|
|
|
480
|
-
static getProtobufMessages(
|
|
481
|
-
return this.messages[
|
|
475
|
+
static getProtobufMessages(messageVersion: MessageVersion = 'latest'): JSON {
|
|
476
|
+
return this.messages[messageVersion];
|
|
482
477
|
}
|
|
483
478
|
|
|
484
479
|
static getSettings(key?: undefined): ConnectSettings;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import type { IDeviceModel, IDeviceType } from '../types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { MessageVersion } from './DataManager';
|
|
3
3
|
|
|
4
4
|
type DeviceVersionConfig = {
|
|
5
5
|
[deviceType in IDeviceType | IDeviceModel]?: {
|
|
6
6
|
minVersion: string;
|
|
7
|
-
|
|
7
|
+
messageVersion: MessageVersion;
|
|
8
8
|
}[];
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export const PROTOBUF_MESSAGE_CONFIG: DeviceVersionConfig = {
|
|
12
12
|
model_mini: [
|
|
13
|
-
// Classic1s starts from 3.5.0, so use
|
|
14
|
-
// Only use
|
|
15
|
-
{ minVersion: '3.3.0',
|
|
16
|
-
{ minVersion: '0.0.1',
|
|
17
|
-
// Fallback to
|
|
18
|
-
{ minVersion: '0.0.0',
|
|
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
19
|
],
|
|
20
20
|
model_touch: [
|
|
21
|
-
// Use
|
|
22
|
-
// Only use
|
|
23
|
-
{ minVersion: '4.5.0',
|
|
24
|
-
{ minVersion: '0.0.1',
|
|
25
|
-
// Fallback to
|
|
26
|
-
{ minVersion: '0.0.0',
|
|
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
27
|
],
|
|
28
28
|
};
|
|
@@ -4,9 +4,9 @@ import DataManager from './DataManager';
|
|
|
4
4
|
import { LoggerNames, getLogger } from '../utils';
|
|
5
5
|
// eslint-disable-next-line import/no-cycle
|
|
6
6
|
import { DevicePool } from '../device/DevicePool';
|
|
7
|
-
import {
|
|
7
|
+
import { getSupportMessageVersion } from '../utils/deviceFeaturesUtils';
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { MessageVersion } from './DataManager';
|
|
10
10
|
import type { LowlevelTransportSharedPlugin, Transport } from '@onekeyfe/hd-transport';
|
|
11
11
|
import type { Features } from '../types';
|
|
12
12
|
|
|
@@ -17,7 +17,6 @@ const LowLevelLogger = getLogger(LoggerNames.HdTransportLowLevel);
|
|
|
17
17
|
const NodeUsbLogger = getLogger(LoggerNames.HdTransportNodeUsb);
|
|
18
18
|
const WebBleLogger = getLogger(LoggerNames.HdWebBleTransport);
|
|
19
19
|
const WebUsbLogger = getLogger(LoggerNames.HdTransportWebUsb);
|
|
20
|
-
const REACT_NATIVE_BLE_SCAN_TIMEOUT_MS = 8000;
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
22
|
* transport 在同一个环境中只会存在一个
|
|
@@ -33,7 +32,7 @@ export default class TransportManager {
|
|
|
33
32
|
|
|
34
33
|
static reactNativeInit = false;
|
|
35
34
|
|
|
36
|
-
static
|
|
35
|
+
static messageVersion: MessageVersion = 'latest';
|
|
37
36
|
|
|
38
37
|
static plugin: LowlevelTransportSharedPlugin | null = null;
|
|
39
38
|
|
|
@@ -41,7 +40,7 @@ export default class TransportManager {
|
|
|
41
40
|
Log.debug('transport manager load');
|
|
42
41
|
this.defaultMessages = DataManager.getProtobufMessages();
|
|
43
42
|
this.currentMessages = this.defaultMessages;
|
|
44
|
-
this.
|
|
43
|
+
this.messageVersion = 'latest';
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
static async configure() {
|
|
@@ -75,9 +74,6 @@ export default class TransportManager {
|
|
|
75
74
|
}
|
|
76
75
|
Log.debug('Configuring transports');
|
|
77
76
|
await this.transport.configure(JSON.stringify(this.defaultMessages));
|
|
78
|
-
this.currentMessages = this.defaultMessages;
|
|
79
|
-
this.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
80
|
-
await this.configureProtocolV2Messages();
|
|
81
77
|
Log.debug('Configuring transports done');
|
|
82
78
|
} catch (error) {
|
|
83
79
|
Log.debug('Initializing transports error: ', error);
|
|
@@ -87,31 +83,20 @@ export default class TransportManager {
|
|
|
87
83
|
}
|
|
88
84
|
}
|
|
89
85
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
* This handles protobuf schema compatibility within Protocol V1 (e.g. Touch's legacy
|
|
94
|
-
* vs current Protocol V1 schema). It is NOT used to switch between Protocol V1 and Protocol V2 —
|
|
95
|
-
* the transport already holds both schemas after initial configure(), and routes per
|
|
96
|
-
* device by `getProtocolType()`.
|
|
97
|
-
*/
|
|
98
|
-
static async reconfigure(features?: Features) {
|
|
99
|
-
if (!features) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const { protocolV1MessageSchema, messages } = getSupportProtocolV1MessageSchema(features);
|
|
86
|
+
static async reconfigure(features?: Features | undefined) {
|
|
87
|
+
Log.debug(`Begin reconfiguring transports`);
|
|
88
|
+
const { messageVersion, messages } = getSupportMessageVersion(features);
|
|
104
89
|
|
|
105
90
|
if (this.currentMessages === messages || !messages) {
|
|
106
91
|
return;
|
|
107
92
|
}
|
|
108
93
|
|
|
109
|
-
Log.debug(`Reconfiguring transports
|
|
94
|
+
Log.debug(`Reconfiguring transports version:${messageVersion}`);
|
|
110
95
|
|
|
111
96
|
try {
|
|
112
97
|
await this.transport.configure(JSON.stringify(messages));
|
|
113
98
|
this.currentMessages = messages;
|
|
114
|
-
this.
|
|
99
|
+
this.messageVersion = messageVersion;
|
|
115
100
|
} catch (error) {
|
|
116
101
|
throw ERRORS.TypedError(
|
|
117
102
|
HardwareErrorCode.TransportInvalidProtobuf,
|
|
@@ -124,9 +109,7 @@ export default class TransportManager {
|
|
|
124
109
|
const env = DataManager.getSettings('env');
|
|
125
110
|
if (env === 'react-native') {
|
|
126
111
|
/** Actually initializes the ReactNativeTransport */
|
|
127
|
-
this.transport = new TransportConstructor({
|
|
128
|
-
scanTimeout: REACT_NATIVE_BLE_SCAN_TIMEOUT_MS,
|
|
129
|
-
}) as unknown as Transport;
|
|
112
|
+
this.transport = new TransportConstructor({ scanTimeout: 3000 }) as unknown as Transport;
|
|
130
113
|
} else {
|
|
131
114
|
/** Actually initializes the HttpTransport */
|
|
132
115
|
this.transport = new TransportConstructor() as unknown as Transport;
|
|
@@ -147,15 +130,6 @@ export default class TransportManager {
|
|
|
147
130
|
return this.transport;
|
|
148
131
|
}
|
|
149
132
|
|
|
150
|
-
private static async configureProtocolV2Messages() {
|
|
151
|
-
const protocolV2Messages = DataManager.getProtobufMessages('v2Schema');
|
|
152
|
-
const { configureProtocolV2 } = this.transport;
|
|
153
|
-
if (protocolV2Messages && typeof configureProtocolV2 === 'function') {
|
|
154
|
-
await configureProtocolV2.call(this.transport, JSON.stringify(protocolV2Messages));
|
|
155
|
-
Log.debug('Protocol V2 messages configured');
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
133
|
static getDefaultMessages() {
|
|
160
134
|
return this.defaultMessages;
|
|
161
135
|
}
|
|
@@ -164,7 +138,7 @@ export default class TransportManager {
|
|
|
164
138
|
return this.currentMessages;
|
|
165
139
|
}
|
|
166
140
|
|
|
167
|
-
static
|
|
168
|
-
return this.
|
|
141
|
+
static getMessageVersion() {
|
|
142
|
+
return this.messageVersion;
|
|
169
143
|
}
|
|
170
144
|
}
|