@onekeyfe/hd-core 1.1.27-alpha.34 → 1.1.27-alpha.4
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/SolSignMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- 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/TronSignMessage.d.ts.map +1 -1
- 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 +998 -16134
- 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 +2 -18
- 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/SolSignMessage.ts +1 -0
- package/src/api/solana/SolSignOffchainMessage.ts +1 -0
- package/src/api/solana/SolSignTransaction.ts +1 -0
- 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/TronSignMessage.ts +2 -1
- package/src/api/tron/TronSignTransaction.ts +1 -0
- 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 +75 -82
- package/src/device/DeviceCommands.ts +26 -162
- 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 -15
- 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 -1501
- 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 -74
- 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 -153
- 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 -13116
- package/src/protocols/protocol-v2/features.ts +0 -278
- 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/device/Device.ts
CHANGED
|
@@ -41,7 +41,6 @@ import { DataManager } from '../data-manager';
|
|
|
41
41
|
import TransportManager from '../data-manager/TransportManager';
|
|
42
42
|
import { toHardened } from '../api/helpers/pathUtils';
|
|
43
43
|
import { existCapability } from '../utils/capabilitieUtils';
|
|
44
|
-
import { getProtocolV2Features } from '../protocols/protocol-v2';
|
|
45
44
|
|
|
46
45
|
import type { PROTO } from '../constants';
|
|
47
46
|
import type {
|
|
@@ -50,7 +49,7 @@ import type {
|
|
|
50
49
|
PassphraseRequestPayload,
|
|
51
50
|
} from '../events';
|
|
52
51
|
import type { PassphrasePromptResponse } from './DeviceCommands';
|
|
53
|
-
import type { Deferred
|
|
52
|
+
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
54
53
|
import type { OneKeyDeviceInfo as DeviceDescriptor } from '@onekeyfe/hd-transport';
|
|
55
54
|
import type DeviceConnector from './DeviceConnector';
|
|
56
55
|
|
|
@@ -59,11 +58,11 @@ export type InitOptions = {
|
|
|
59
58
|
deviceId?: string;
|
|
60
59
|
passphraseState?: string;
|
|
61
60
|
deriveCardano?: boolean;
|
|
62
|
-
connectProtocol?: HardwareConnectProtocol;
|
|
63
61
|
};
|
|
64
62
|
|
|
65
63
|
export type RunOptions = {
|
|
66
64
|
keepSession?: boolean;
|
|
65
|
+
skipInitialize?: boolean;
|
|
67
66
|
} & InitOptions;
|
|
68
67
|
|
|
69
68
|
const parseRunOptions = (options?: RunOptions): RunOptions => {
|
|
@@ -198,6 +197,17 @@ export class Device extends EventEmitter {
|
|
|
198
197
|
|
|
199
198
|
pendingCallbackPromise?: Deferred<void>;
|
|
200
199
|
|
|
200
|
+
/** Pre-initialize timestamp (ms) */
|
|
201
|
+
private preInitializedAt?: number;
|
|
202
|
+
|
|
203
|
+
/** Pre-initialize context, used to verify state consistency before skipping */
|
|
204
|
+
private preInitializeMeta?: {
|
|
205
|
+
passphraseState?: string;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/** Last Initialize duration (ms), reported as "saved" when a skip happens */
|
|
209
|
+
private lastInitializeDurationMs?: number;
|
|
210
|
+
|
|
201
211
|
constructor(descriptor: DeviceDescriptor, sdkInstanceId?: string) {
|
|
202
212
|
super();
|
|
203
213
|
this.originalDescriptor = descriptor;
|
|
@@ -254,13 +264,13 @@ export class Device extends EventEmitter {
|
|
|
254
264
|
* Device connect
|
|
255
265
|
* @returns {Promise<boolean>}
|
|
256
266
|
*/
|
|
257
|
-
connect(
|
|
267
|
+
connect() {
|
|
258
268
|
const env = DataManager.getSettings('env');
|
|
259
269
|
// eslint-disable-next-line no-async-promise-executor
|
|
260
270
|
return new Promise<boolean>(async (resolve, reject) => {
|
|
261
271
|
if (DataManager.isBleConnect(env)) {
|
|
262
272
|
try {
|
|
263
|
-
await this.acquire(
|
|
273
|
+
await this.acquire();
|
|
264
274
|
resolve(true);
|
|
265
275
|
} catch (error) {
|
|
266
276
|
reject(error);
|
|
@@ -270,7 +280,7 @@ export class Device extends EventEmitter {
|
|
|
270
280
|
// 不存在 Session ID 或存在 Session ID 但设备在别处使用,都需要 acquire 获取最新 sessionID
|
|
271
281
|
if (!this.mainId || (!this.isUsedHere() && this.originalDescriptor)) {
|
|
272
282
|
try {
|
|
273
|
-
await this.acquire(
|
|
283
|
+
await this.acquire();
|
|
274
284
|
resolve(true);
|
|
275
285
|
} catch (error) {
|
|
276
286
|
reject(error);
|
|
@@ -285,40 +295,23 @@ export class Device extends EventEmitter {
|
|
|
285
295
|
});
|
|
286
296
|
}
|
|
287
297
|
|
|
288
|
-
async acquire(
|
|
298
|
+
async acquire() {
|
|
289
299
|
const env = DataManager.getSettings('env');
|
|
290
300
|
const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
|
|
291
|
-
const expectedProtocol = connectProtocol ?? this.originalDescriptor.protocolType;
|
|
292
301
|
try {
|
|
293
302
|
if (DataManager.isBleConnect(env)) {
|
|
294
|
-
const res = await this.deviceConnector?.acquire(
|
|
295
|
-
this.originalDescriptor.id,
|
|
296
|
-
undefined,
|
|
297
|
-
true,
|
|
298
|
-
expectedProtocol
|
|
299
|
-
);
|
|
303
|
+
const res = await this.deviceConnector?.acquire(this.originalDescriptor.id);
|
|
300
304
|
this.mainId = (res as unknown as any).uuid ?? '';
|
|
301
305
|
Log.debug('Expected uuid:', this.mainId);
|
|
302
306
|
} else {
|
|
303
307
|
this.mainId = await this.deviceConnector?.acquire(
|
|
304
308
|
this.originalDescriptor.path,
|
|
305
|
-
this.originalDescriptor.session
|
|
306
|
-
undefined,
|
|
307
|
-
expectedProtocol
|
|
309
|
+
this.originalDescriptor.session
|
|
308
310
|
);
|
|
309
311
|
Log.debug('Expected session id:', this.mainId);
|
|
310
312
|
}
|
|
311
313
|
this.deviceAcquired = true;
|
|
312
314
|
this.updateDescriptor({ [mainIdKey]: this.mainId } as unknown as DeviceDescriptor);
|
|
313
|
-
|
|
314
|
-
// Propagate protocol version detected during acquire.
|
|
315
|
-
const detectedProtocol = TransportManager.transport?.getProtocolType?.(
|
|
316
|
-
DataManager.isBleConnect(env) ? this.originalDescriptor.id : this.originalDescriptor.path
|
|
317
|
-
);
|
|
318
|
-
if (detectedProtocol) {
|
|
319
|
-
this.originalDescriptor.protocolType = detectedProtocol;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
315
|
if (this.commands) {
|
|
323
316
|
await this.commands.dispose(false);
|
|
324
317
|
}
|
|
@@ -374,6 +367,54 @@ export class Device extends EventEmitter {
|
|
|
374
367
|
this.deviceAcquired = false;
|
|
375
368
|
}
|
|
376
369
|
|
|
370
|
+
/**
|
|
371
|
+
* Pre-initialize: connect + Initialize ahead of the sign. Only runs the
|
|
372
|
+
* fallback init when features are missing (gate on `!this.features`, not
|
|
373
|
+
* isUsedHere which is always false on BLE); otherwise just records the mark.
|
|
374
|
+
*/
|
|
375
|
+
async preInitialize(initOptions?: InitOptions) {
|
|
376
|
+
if (!this.features) {
|
|
377
|
+
await this.acquire();
|
|
378
|
+
await this.initialize(initOptions);
|
|
379
|
+
}
|
|
380
|
+
this.markPreInitialized({
|
|
381
|
+
passphraseState: initOptions?.passphraseState,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
markPreInitialized(meta?: { passphraseState?: string }) {
|
|
386
|
+
this.preInitializedAt = Date.now();
|
|
387
|
+
this.preInitializeMeta = meta
|
|
388
|
+
? {
|
|
389
|
+
passphraseState: meta.passphraseState === '' ? undefined : meta.passphraseState,
|
|
390
|
+
}
|
|
391
|
+
: undefined;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
clearPreInitialized() {
|
|
395
|
+
this.preInitializedAt = undefined;
|
|
396
|
+
this.preInitializeMeta = undefined;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
isPreInitializeMetaMatch(payload?: { passphraseState?: string }) {
|
|
400
|
+
if (!this.preInitializeMeta) return true;
|
|
401
|
+
const passphraseState = payload?.passphraseState === '' ? undefined : payload?.passphraseState;
|
|
402
|
+
return this.preInitializeMeta.passphraseState === passphraseState;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
isPreInitializedValid(ttlMs: number) {
|
|
406
|
+
if (!this.preInitializedAt) return false;
|
|
407
|
+
return Date.now() - this.preInitializedAt <= ttlMs;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
setLastInitializeDuration(durationMs: number) {
|
|
411
|
+
this.lastInitializeDurationMs = durationMs;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
getLastInitializeDuration() {
|
|
415
|
+
return this.lastInitializeDurationMs;
|
|
416
|
+
}
|
|
417
|
+
|
|
377
418
|
getCommands() {
|
|
378
419
|
return this.commands;
|
|
379
420
|
}
|
|
@@ -481,17 +522,6 @@ export class Device extends EventEmitter {
|
|
|
481
522
|
}
|
|
482
523
|
|
|
483
524
|
async initialize(options?: InitOptions) {
|
|
484
|
-
// Protocol V2 不支持传统 Initialize,直接使用协议专用初始化流程。
|
|
485
|
-
if (this.originalDescriptor.protocolType === 'V2') {
|
|
486
|
-
this.passphraseState = options?.passphraseState;
|
|
487
|
-
if (this.features && !this.featuresNeedsReload && !options?.initSession) {
|
|
488
|
-
Log.debug('Skip Protocol V2 feature adapter; cached features are available');
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
await this._initializeProtocolV2();
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
525
|
// Log.debug('initialize param:', options);
|
|
496
526
|
|
|
497
527
|
this.passphraseState = options?.passphraseState;
|
|
@@ -512,13 +542,7 @@ export class Device extends EventEmitter {
|
|
|
512
542
|
payload.passphrase_state = options?.passphraseState;
|
|
513
543
|
payload.is_contains_attach = true;
|
|
514
544
|
|
|
515
|
-
|
|
516
|
-
deviceId: options?.deviceId,
|
|
517
|
-
passphraseState: options?.passphraseState,
|
|
518
|
-
initSession: options?.initSession,
|
|
519
|
-
InitializePayload: payload,
|
|
520
|
-
});
|
|
521
|
-
|
|
545
|
+
const initStartAt = Date.now();
|
|
522
546
|
try {
|
|
523
547
|
// @ts-expect-error
|
|
524
548
|
const { message } = await Promise.race([
|
|
@@ -531,7 +555,8 @@ export class Device extends EventEmitter {
|
|
|
531
555
|
}),
|
|
532
556
|
]);
|
|
533
557
|
|
|
534
|
-
|
|
558
|
+
const initCostMs = Date.now() - initStartAt;
|
|
559
|
+
this.setLastInitializeDuration(initCostMs);
|
|
535
560
|
this._updateFeatures(message, options?.initSession);
|
|
536
561
|
await TransportManager.reconfigure(this.features);
|
|
537
562
|
} catch (error) {
|
|
@@ -540,36 +565,6 @@ export class Device extends EventEmitter {
|
|
|
540
565
|
}
|
|
541
566
|
}
|
|
542
567
|
|
|
543
|
-
/**
|
|
544
|
-
* Device initialization over Protocol V2.
|
|
545
|
-
*
|
|
546
|
-
* Protocol V2 不走传统 Initialize/GetFeatures,当前通过 Ping 验证链路,
|
|
547
|
-
* 再用 DeviceGetDeviceInfo 归一成 legacy-style Features 视图。
|
|
548
|
-
*/
|
|
549
|
-
private async _initializeProtocolV2() {
|
|
550
|
-
Log.debug('Initialize device via Protocol V2 feature adapter');
|
|
551
|
-
|
|
552
|
-
try {
|
|
553
|
-
const features = await Promise.race([
|
|
554
|
-
getProtocolV2Features({
|
|
555
|
-
commands: this.commands,
|
|
556
|
-
descriptor: this.originalDescriptor,
|
|
557
|
-
timeoutMs: 10 * 1000,
|
|
558
|
-
}),
|
|
559
|
-
new Promise<never>((_, reject) => {
|
|
560
|
-
setTimeout(() => {
|
|
561
|
-
reject(ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed));
|
|
562
|
-
}, 10 * 1000);
|
|
563
|
-
}),
|
|
564
|
-
]);
|
|
565
|
-
Log.debug('Protocol V2 normalized features:', features);
|
|
566
|
-
this._updateFeatures(features);
|
|
567
|
-
} catch (error) {
|
|
568
|
-
Log.error('Protocol V2 initialization failed:', error);
|
|
569
|
-
throw error;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
|
|
573
568
|
async getFeatures() {
|
|
574
569
|
const { message } = await this.commands.typedCall('GetFeatures', 'Features', {});
|
|
575
570
|
this._updateFeatures(message);
|
|
@@ -640,7 +635,7 @@ export class Device extends EventEmitter {
|
|
|
640
635
|
const env = DataManager.getSettings('env');
|
|
641
636
|
if (env !== 'react-native') {
|
|
642
637
|
try {
|
|
643
|
-
await this.acquire(
|
|
638
|
+
await this.acquire();
|
|
644
639
|
} catch (error) {
|
|
645
640
|
this.runPromise = null;
|
|
646
641
|
return Promise.reject(error);
|
|
@@ -648,7 +643,9 @@ export class Device extends EventEmitter {
|
|
|
648
643
|
|
|
649
644
|
try {
|
|
650
645
|
if (fn) {
|
|
651
|
-
|
|
646
|
+
if (!options?.skipInitialize) {
|
|
647
|
+
await this.initialize(options);
|
|
648
|
+
}
|
|
652
649
|
}
|
|
653
650
|
} catch (error) {
|
|
654
651
|
this.runPromise = null;
|
|
@@ -882,13 +879,9 @@ export class Device extends EventEmitter {
|
|
|
882
879
|
this.features,
|
|
883
880
|
Enum_Capability.Capability_AttachToPin
|
|
884
881
|
);
|
|
885
|
-
const isPro2 = getDeviceType(this.features) === EDeviceType.Pro2;
|
|
886
882
|
|
|
887
883
|
const supportUnlock =
|
|
888
|
-
supportAttachPinCapability ||
|
|
889
|
-
// Pro2 V2 暂未从 features 暴露 capabilities,先直连该方法用于固件联调。
|
|
890
|
-
isPro2 ||
|
|
891
|
-
(versionRange && semver.gte(firmwareVersion, versionRange.min));
|
|
884
|
+
supportAttachPinCapability || (versionRange && semver.gte(firmwareVersion, versionRange.min));
|
|
892
885
|
|
|
893
886
|
if (supportUnlock) {
|
|
894
887
|
const res = await this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
|
|
@@ -12,12 +12,7 @@ import {
|
|
|
12
12
|
} from '../utils/tracing';
|
|
13
13
|
|
|
14
14
|
import type { Device } from './Device';
|
|
15
|
-
import type {
|
|
16
|
-
FailureType,
|
|
17
|
-
Messages,
|
|
18
|
-
Transport,
|
|
19
|
-
TransportCallOptions,
|
|
20
|
-
} from '@onekeyfe/hd-transport';
|
|
15
|
+
import type { FailureType, Messages, Transport } from '@onekeyfe/hd-transport';
|
|
21
16
|
|
|
22
17
|
export type PassphrasePromptResponse = {
|
|
23
18
|
passphrase?: string;
|
|
@@ -27,119 +22,16 @@ export type PassphrasePromptResponse = {
|
|
|
27
22
|
};
|
|
28
23
|
|
|
29
24
|
type MessageType = Messages.MessageType;
|
|
30
|
-
type MessageKey =
|
|
25
|
+
type MessageKey = keyof MessageType;
|
|
31
26
|
export type TypedResponseMessage<T extends MessageKey> = {
|
|
32
27
|
type: T;
|
|
33
28
|
message: MessageType[T];
|
|
34
29
|
};
|
|
35
30
|
type TypedCallResponseMap = {
|
|
36
|
-
[K in
|
|
31
|
+
[K in keyof MessageType]: TypedResponseMessage<K>;
|
|
37
32
|
};
|
|
38
33
|
export type DefaultMessageResponse = TypedCallResponseMap[keyof MessageType];
|
|
39
34
|
|
|
40
|
-
const MAX_DEBUG_ARRAY_ITEMS = 20;
|
|
41
|
-
const MAX_DEBUG_OBJECT_KEYS = 40;
|
|
42
|
-
const MAX_DEBUG_STRING_LENGTH = 512;
|
|
43
|
-
const MAX_DEBUG_DEPTH = 4;
|
|
44
|
-
const HIGH_VOLUME_DEBUG_CALLS = new Set([
|
|
45
|
-
'FilesystemFileRead',
|
|
46
|
-
'FilesystemFileWrite',
|
|
47
|
-
'FileRead',
|
|
48
|
-
'FileWrite',
|
|
49
|
-
'EmmcFileRead',
|
|
50
|
-
'EmmcFileWrite',
|
|
51
|
-
'FirmwareUpload',
|
|
52
|
-
'ResourceAck',
|
|
53
|
-
]);
|
|
54
|
-
|
|
55
|
-
function shouldReduceDebugForCall(type: string) {
|
|
56
|
-
return HIGH_VOLUME_DEBUG_CALLS.has(type);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function getBinaryByteLength(value: unknown): number | undefined {
|
|
60
|
-
if (value instanceof ArrayBuffer) {
|
|
61
|
-
return value.byteLength;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (ArrayBuffer.isView(value)) {
|
|
65
|
-
return value.byteLength;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (typeof Blob !== 'undefined' && value instanceof Blob) {
|
|
69
|
-
return value.size;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function summarizeRedactedData(value: unknown): string {
|
|
76
|
-
const byteLength = getBinaryByteLength(value);
|
|
77
|
-
if (byteLength !== undefined) {
|
|
78
|
-
return `[redacted data: ${byteLength} bytes]`;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (typeof value === 'string') {
|
|
82
|
-
return `[redacted data: string length=${value.length}]`;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (Array.isArray(value)) {
|
|
86
|
-
return `[redacted data: array length=${value.length}]`;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (value && typeof value === 'object') {
|
|
90
|
-
return `[redacted data: object keys=${Object.keys(value).length}]`;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return `[redacted data: ${typeof value}]`;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function sanitizeDebugPayload(value: unknown, key = '', depth = 0): unknown {
|
|
97
|
-
if (key === 'data' && value !== null && value !== undefined) {
|
|
98
|
-
return summarizeRedactedData(value);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const byteLength = getBinaryByteLength(value);
|
|
102
|
-
if (byteLength !== undefined) {
|
|
103
|
-
return `[binary: ${byteLength} bytes]`;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (typeof value === 'string') {
|
|
107
|
-
return value.length > MAX_DEBUG_STRING_LENGTH
|
|
108
|
-
? `${value.slice(0, MAX_DEBUG_STRING_LENGTH)}... (len=${value.length})`
|
|
109
|
-
: value;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (!value || typeof value !== 'object') {
|
|
113
|
-
return value;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (depth >= MAX_DEBUG_DEPTH) {
|
|
117
|
-
return Array.isArray(value)
|
|
118
|
-
? `[array length=${value.length}]`
|
|
119
|
-
: `[object keys=${Object.keys(value).length}]`;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (Array.isArray(value)) {
|
|
123
|
-
const items = value
|
|
124
|
-
.slice(0, MAX_DEBUG_ARRAY_ITEMS)
|
|
125
|
-
.map(item => sanitizeDebugPayload(item, key, depth + 1));
|
|
126
|
-
if (value.length > MAX_DEBUG_ARRAY_ITEMS) {
|
|
127
|
-
items.push(`... (${value.length - MAX_DEBUG_ARRAY_ITEMS} more)`);
|
|
128
|
-
}
|
|
129
|
-
return items;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const entries = Object.entries(value).slice(0, MAX_DEBUG_OBJECT_KEYS);
|
|
133
|
-
const sanitized: Record<string, unknown> = {};
|
|
134
|
-
entries.forEach(([entryKey, entryValue]) => {
|
|
135
|
-
sanitized[entryKey] = sanitizeDebugPayload(entryValue, entryKey, depth + 1);
|
|
136
|
-
});
|
|
137
|
-
if (Object.keys(value).length > MAX_DEBUG_OBJECT_KEYS) {
|
|
138
|
-
sanitized.__truncated__ = `${Object.keys(value).length - MAX_DEBUG_OBJECT_KEYS} more keys`;
|
|
139
|
-
}
|
|
140
|
-
return sanitized;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
35
|
const assertType = (res: DefaultMessageResponse, resType: string | string[]) => {
|
|
144
36
|
const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
|
|
145
37
|
if (!splitResTypes.includes(res.type)) {
|
|
@@ -332,21 +224,17 @@ export class DeviceCommands {
|
|
|
332
224
|
// Sends an async message to the opened device.
|
|
333
225
|
async call(
|
|
334
226
|
type: MessageKey,
|
|
335
|
-
msg
|
|
336
|
-
options?: TransportCallOptions
|
|
227
|
+
msg: DefaultMessageResponse['message'] = {}
|
|
337
228
|
): Promise<DefaultMessageResponse> {
|
|
338
|
-
|
|
339
|
-
if (!shouldReduceDebug) {
|
|
340
|
-
Log.debug('[DeviceCommands] [call] Sending', type);
|
|
341
|
-
}
|
|
229
|
+
Log.debug('[DeviceCommands] [call] Sending', type);
|
|
342
230
|
|
|
343
231
|
try {
|
|
344
|
-
const promise = this.transport.call(this.mainId, type, msg
|
|
232
|
+
const promise = this.transport.call(this.mainId, type, msg) as any;
|
|
345
233
|
this.callPromise = promise;
|
|
346
234
|
const res = await promise;
|
|
347
235
|
if (res.type === 'Failure') {
|
|
348
236
|
LogCore.debug('[DeviceCommands] [call] Received', res.type, res.message);
|
|
349
|
-
} else
|
|
237
|
+
} else {
|
|
350
238
|
LogCore.debug('[DeviceCommands] [call] Received', res.type);
|
|
351
239
|
}
|
|
352
240
|
return res;
|
|
@@ -395,22 +283,19 @@ export class DeviceCommands {
|
|
|
395
283
|
typedCall<T extends MessageKey, R extends MessageKey[]>(
|
|
396
284
|
type: T,
|
|
397
285
|
resType: R,
|
|
398
|
-
msg?: MessageType[T]
|
|
399
|
-
options?: TransportCallOptions
|
|
286
|
+
msg?: MessageType[T]
|
|
400
287
|
): Promise<TypedCallResponseMap[R[number]]>;
|
|
401
288
|
|
|
402
289
|
typedCall<T extends MessageKey, R extends MessageKey>(
|
|
403
290
|
type: T,
|
|
404
291
|
resType: R,
|
|
405
|
-
msg?: MessageType[T]
|
|
406
|
-
options?: TransportCallOptions
|
|
292
|
+
msg?: MessageType[T]
|
|
407
293
|
): Promise<TypedResponseMessage<R>>;
|
|
408
294
|
|
|
409
295
|
async typedCall(
|
|
410
296
|
type: MessageKey,
|
|
411
297
|
resType: MessageKey | MessageKey[],
|
|
412
|
-
msg?: DefaultMessageResponse['message']
|
|
413
|
-
options?: TransportCallOptions
|
|
298
|
+
msg?: DefaultMessageResponse['message']
|
|
414
299
|
) {
|
|
415
300
|
if (this.disposed) {
|
|
416
301
|
throw ERRORS.TypedError(
|
|
@@ -427,24 +312,16 @@ export class DeviceCommands {
|
|
|
427
312
|
'PassphraseAck',
|
|
428
313
|
'Cancel',
|
|
429
314
|
'BixinPinInputOnDevice',
|
|
430
|
-
'FilesystemFileRead',
|
|
431
|
-
'FilesystemFileWrite',
|
|
432
|
-
'FileRead',
|
|
433
|
-
'FileWrite',
|
|
434
|
-
'EmmcFileRead',
|
|
435
|
-
'EmmcFileWrite',
|
|
436
|
-
'FirmwareUpload',
|
|
437
|
-
'ResourceAck',
|
|
438
315
|
] as any;
|
|
439
316
|
if (!skipTypes.includes(type) && msg) {
|
|
440
317
|
// Use debug channel to avoid noise escalation
|
|
441
|
-
Log.debug('[DeviceCommands] [typedCall] Sending payload', type,
|
|
318
|
+
Log.debug('[DeviceCommands] [typedCall] Sending payload', type, msg);
|
|
442
319
|
}
|
|
443
320
|
} catch (e) {
|
|
444
321
|
// ignore logging errors
|
|
445
322
|
}
|
|
446
323
|
|
|
447
|
-
const response = await this._commonCall(type, msg
|
|
324
|
+
const response = await this._commonCall(type, msg);
|
|
448
325
|
try {
|
|
449
326
|
assertType(response, resType);
|
|
450
327
|
} catch (error) {
|
|
@@ -457,12 +334,6 @@ export class DeviceCommands {
|
|
|
457
334
|
// throw bridge network error
|
|
458
335
|
if (error instanceof HardwareError) {
|
|
459
336
|
if (error.errorCode === HardwareErrorCode.ResponseUnexpectTypeError) {
|
|
460
|
-
Log.debug('[DeviceCommands] [typedCall] Unexpected response type', {
|
|
461
|
-
request: type,
|
|
462
|
-
expected: resType,
|
|
463
|
-
received: response.type,
|
|
464
|
-
response: sanitizeDebugPayload(response.message),
|
|
465
|
-
});
|
|
466
337
|
// Do not intercept CallMethodError
|
|
467
338
|
// Do not intercept “assertType: Response of unexpected type” error
|
|
468
339
|
// Blocking the above two messages will not know what the specific error message is, and the specific error should be handled by the subsequent business logic.
|
|
@@ -476,7 +347,7 @@ export class DeviceCommands {
|
|
|
476
347
|
if (error.message.indexOf('BridgeDeviceDisconnected') > -1) {
|
|
477
348
|
throw ERRORS.TypedError(HardwareErrorCode.BridgeDeviceDisconnected);
|
|
478
349
|
}
|
|
479
|
-
throw
|
|
350
|
+
throw ERRORS.TypedError(HardwareErrorCode.ResponseUnexpectTypeError);
|
|
480
351
|
}
|
|
481
352
|
} else {
|
|
482
353
|
// throw error anyway, next call should be resolved properly// throw error anyway, next call should be resolved properly
|
|
@@ -486,27 +357,20 @@ export class DeviceCommands {
|
|
|
486
357
|
return response;
|
|
487
358
|
}
|
|
488
359
|
|
|
489
|
-
async _commonCall(
|
|
490
|
-
type
|
|
491
|
-
|
|
492
|
-
options?: TransportCallOptions
|
|
493
|
-
) {
|
|
494
|
-
const resp = await this.call(type, msg, options);
|
|
495
|
-
return this._filterCommonTypes(resp, type, options);
|
|
360
|
+
async _commonCall(type: MessageKey, msg?: DefaultMessageResponse['message']) {
|
|
361
|
+
const resp = await this.call(type, msg);
|
|
362
|
+
return this._filterCommonTypes(resp, type);
|
|
496
363
|
}
|
|
497
364
|
|
|
498
365
|
_filterCommonTypes(
|
|
499
366
|
res: DefaultMessageResponse,
|
|
500
|
-
callType: MessageKey
|
|
501
|
-
options?: TransportCallOptions
|
|
367
|
+
callType: MessageKey
|
|
502
368
|
): Promise<DefaultMessageResponse> {
|
|
503
369
|
try {
|
|
504
|
-
if (
|
|
505
|
-
|
|
506
|
-
} else if (DataManager.getSettings('env') === 'react-native') {
|
|
507
|
-
Log.debug('_filterCommonTypes: ', JSON.stringify(sanitizeDebugPayload(res)));
|
|
370
|
+
if (DataManager.getSettings('env') === 'react-native') {
|
|
371
|
+
Log.debug('_filterCommonTypes: ', JSON.stringify(res));
|
|
508
372
|
} else {
|
|
509
|
-
Log.debug('_filterCommonTypes: ',
|
|
373
|
+
Log.debug('_filterCommonTypes: ', res);
|
|
510
374
|
}
|
|
511
375
|
} catch (error) {
|
|
512
376
|
// ignore
|
|
@@ -608,7 +472,7 @@ export class DeviceCommands {
|
|
|
608
472
|
} else {
|
|
609
473
|
this.device.emit(DEVICE.BUTTON, this.device, res.message);
|
|
610
474
|
}
|
|
611
|
-
return this._commonCall('ButtonAck', {}
|
|
475
|
+
return this._commonCall('ButtonAck', {});
|
|
612
476
|
}
|
|
613
477
|
|
|
614
478
|
if (res.type === 'EntropyRequest') {
|
|
@@ -621,11 +485,11 @@ export class DeviceCommands {
|
|
|
621
485
|
if (pin === '@@ONEKEY_INPUT_PIN_IN_DEVICE') {
|
|
622
486
|
// only classic\1s\mini\pure
|
|
623
487
|
this.device.setCancelableAction(() => this.cancelDeviceOnOneKeyDevice());
|
|
624
|
-
return this._commonCall('BixinPinInputOnDevice'
|
|
488
|
+
return this._commonCall('BixinPinInputOnDevice').finally(() => {
|
|
625
489
|
this.device.clearCancelableAction();
|
|
626
490
|
});
|
|
627
491
|
}
|
|
628
|
-
return this._commonCall('PinMatrixAck', { pin }
|
|
492
|
+
return this._commonCall('PinMatrixAck', { pin });
|
|
629
493
|
},
|
|
630
494
|
error => Promise.reject(error)
|
|
631
495
|
);
|
|
@@ -640,12 +504,12 @@ export class DeviceCommands {
|
|
|
640
504
|
|
|
641
505
|
// Attach PIN on device
|
|
642
506
|
if (attachPinOnDevice && existsAttachPinUser) {
|
|
643
|
-
return this._commonCall('PassphraseAck', { on_device_attach_pin: true }
|
|
507
|
+
return this._commonCall('PassphraseAck', { on_device_attach_pin: true });
|
|
644
508
|
}
|
|
645
509
|
|
|
646
510
|
return !passphraseOnDevice
|
|
647
|
-
? this._commonCall('PassphraseAck', { passphrase }
|
|
648
|
-
: this._commonCall('PassphraseAck', { on_device: true }
|
|
511
|
+
? this._commonCall('PassphraseAck', { passphrase })
|
|
512
|
+
: this._commonCall('PassphraseAck', { on_device: true });
|
|
649
513
|
});
|
|
650
514
|
}
|
|
651
515
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
-
|
|
3
1
|
import { safeThrowError } from '../constants';
|
|
4
2
|
import { DataManager } from '../data-manager';
|
|
5
3
|
import TransportManager from '../data-manager/TransportManager';
|
|
@@ -8,7 +6,6 @@ import { resolveAfter } from '../utils/promiseUtils';
|
|
|
8
6
|
import { LoggerNames, getLogger } from '../utils';
|
|
9
7
|
|
|
10
8
|
import type { DeviceDescriptorDiff } from './DevicePool';
|
|
11
|
-
import type { HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
12
9
|
import type { OneKeyDeviceInfo as DeviceDescriptor, Transport } from '@onekeyfe/hd-transport';
|
|
13
10
|
|
|
14
11
|
const Log = getLogger(LoggerNames.DeviceConnector);
|
|
@@ -78,37 +75,15 @@ export default class DeviceConnector {
|
|
|
78
75
|
this.listening = false;
|
|
79
76
|
}
|
|
80
77
|
|
|
81
|
-
async acquire(
|
|
82
|
-
path
|
|
83
|
-
session?: string | null,
|
|
84
|
-
forceCleanRunPromise?: boolean,
|
|
85
|
-
connectProtocol?: HardwareConnectProtocol
|
|
86
|
-
) {
|
|
87
|
-
Log.debug('acquire', path, session, connectProtocol);
|
|
78
|
+
async acquire(path: string, session?: string | null, forceCleanRunPromise?: boolean) {
|
|
79
|
+
Log.debug('acquire', path, session);
|
|
88
80
|
const env = DataManager.getSettings('env');
|
|
89
81
|
try {
|
|
90
82
|
let res;
|
|
91
83
|
if (DataManager.isBleConnect(env)) {
|
|
92
|
-
res = await this.transport.acquire({
|
|
93
|
-
uuid: path,
|
|
94
|
-
forceCleanRunPromise,
|
|
95
|
-
expectedProtocol: connectProtocol,
|
|
96
|
-
});
|
|
84
|
+
res = await this.transport.acquire({ uuid: path, forceCleanRunPromise });
|
|
97
85
|
} else {
|
|
98
|
-
res = await this.transport.acquire({
|
|
99
|
-
path,
|
|
100
|
-
previous: session ?? null,
|
|
101
|
-
expectedProtocol: connectProtocol,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
if (connectProtocol) {
|
|
105
|
-
const detectedProtocol = this.transport.getProtocolType(path);
|
|
106
|
-
if (detectedProtocol !== connectProtocol) {
|
|
107
|
-
throw ERRORS.TypedError(
|
|
108
|
-
HardwareErrorCode.RuntimeError,
|
|
109
|
-
`Device protocol mismatch: expected ${connectProtocol}, detected ${detectedProtocol}`
|
|
110
|
-
);
|
|
111
|
-
}
|
|
86
|
+
res = await this.transport.acquire({ path, previous: session ?? null });
|
|
112
87
|
}
|
|
113
88
|
return res;
|
|
114
89
|
} catch (error) {
|
package/src/device/DevicePool.ts
CHANGED
|
@@ -150,7 +150,7 @@ export class DevicePool extends EventEmitter {
|
|
|
150
150
|
if (!device) {
|
|
151
151
|
device = Device.fromDescriptor(descriptor);
|
|
152
152
|
device.deviceConnector = this.connector;
|
|
153
|
-
await device.connect(
|
|
153
|
+
await device.connect();
|
|
154
154
|
await device.initialize(initOptions);
|
|
155
155
|
await device.release();
|
|
156
156
|
}
|
package/src/events/ui-request.ts
CHANGED
|
@@ -129,10 +129,6 @@ export interface FirmwareProgress {
|
|
|
129
129
|
device: Device;
|
|
130
130
|
progress: number;
|
|
131
131
|
progressType: IFirmwareUpdateProgressType;
|
|
132
|
-
transferredBytes?: number;
|
|
133
|
-
totalBytes?: number;
|
|
134
|
-
rateBytesPerSecond?: number;
|
|
135
|
-
elapsedMs?: number;
|
|
136
132
|
};
|
|
137
133
|
}
|
|
138
134
|
|
|
@@ -148,10 +144,6 @@ export interface DeviceProgress {
|
|
|
148
144
|
type: typeof UI_REQUEST.DEVICE_PROGRESS;
|
|
149
145
|
payload: {
|
|
150
146
|
progress?: number;
|
|
151
|
-
transferredBytes?: number;
|
|
152
|
-
totalBytes?: number;
|
|
153
|
-
rateBytesPerSecond?: number;
|
|
154
|
-
elapsedMs?: number;
|
|
155
147
|
};
|
|
156
148
|
}
|
|
157
149
|
|