@onekeyfe/hd-core 1.1.27-alpha.4 → 1.1.27-alpha.41
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__/evmSignTransaction.test.ts +1 -1
- package/__tests__/evmSignTypedData.test.ts +1 -1
- package/__tests__/protocol-v2.test.ts +1688 -0
- package/dist/api/BaseMethod.d.ts +1 -7
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/DirList.d.ts +10 -0
- package/dist/api/DirList.d.ts.map +1 -0
- package/dist/api/DirMake.d.ts +9 -0
- package/dist/api/DirMake.d.ts.map +1 -0
- package/dist/api/DirRemove.d.ts +9 -0
- package/dist/api/DirRemove.d.ts.map +1 -0
- package/dist/api/FileDelete.d.ts +9 -0
- package/dist/api/FileDelete.d.ts.map +1 -0
- package/dist/api/FileRead.d.ts +19 -0
- package/dist/api/FileRead.d.ts.map +1 -0
- package/dist/api/FileWrite.d.ts +23 -0
- package/dist/api/FileWrite.d.ts.map +1 -0
- package/dist/api/FirmwareUpdateV3.d.ts +1 -0
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +32 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -0
- package/dist/api/GetDeviceInfo.d.ts +9 -0
- package/dist/api/GetDeviceInfo.d.ts.map +1 -0
- package/dist/api/GetFeatures.d.ts +1 -1
- package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts +6 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/PathInfo.d.ts +9 -0
- package/dist/api/PathInfo.d.ts.map +1 -0
- package/dist/api/SearchDevices.d.ts +2 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumGetAddress.d.ts +2 -6
- package/dist/api/alephium/AlephiumGetAddress.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignMessage.d.ts +2 -5
- package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignTransaction.d.ts +2 -5
- 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 +2 -9
- package/dist/api/benfen/BenfenGetAddress.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetPublicKey.d.ts +2 -9
- package/dist/api/benfen/BenfenGetPublicKey.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignMessage.d.ts +2 -8
- package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignTransaction.d.ts +2 -8
- package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCGetAddress.d.ts +1 -11
- package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
- package/dist/api/btc/BTCGetPublicKey.d.ts +1 -11
- package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
- package/dist/api/btc/BTCSignMessage.d.ts +1 -15
- 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 +1 -11
- package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCVerifyMessage.d.ts +1 -11
- package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
- package/dist/api/btc/helpers/versionLimit.d.ts +2 -11
- 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/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 +2 -8
- 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 +10 -2
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/helpers/deviceInfo.d.ts +15 -0
- package/dist/api/helpers/deviceInfo.d.ts.map +1 -0
- package/dist/api/helpers/filesystemValidation.d.ts +7 -0
- package/dist/api/helpers/filesystemValidation.d.ts.map +1 -0
- package/dist/api/index.d.ts +28 -1
- 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 +2 -8
- package/dist/api/neo/NeoGetAddress.d.ts.map +1 -1
- package/dist/api/neo/NeoSignTransaction.d.ts +2 -8
- package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
- package/dist/api/nervos/NervosGetAddress.d.ts +2 -9
- package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -1
- package/dist/api/nervos/NervosSignTransaction.d.ts +2 -9
- package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
- package/dist/api/nexa/NexaGetAddress.d.ts +2 -8
- package/dist/api/nexa/NexaGetAddress.d.ts.map +1 -1
- package/dist/api/nexa/NexaSignTransaction.d.ts +2 -9
- 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/protocol-v2/DeviceFirmwareUpdate.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceReboot.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -0
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +7 -0
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +1 -0
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +6 -0
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +10 -0
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +6 -0
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts +6 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
- package/dist/api/protocol-v2/GetProtoVersion.d.ts +6 -0
- package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +1 -0
- package/dist/api/protocol-v2/Ping.d.ts +8 -0
- package/dist/api/protocol-v2/Ping.d.ts.map +1 -0
- package/dist/api/protocol-v2/helpers.d.ts +49 -0
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
- package/dist/api/scdo/ScdoGetAddress.d.ts +2 -6
- package/dist/api/scdo/ScdoGetAddress.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignMessage.d.ts +2 -5
- package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignTransaction.d.ts +2 -5
- package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
- package/dist/api/solana/SolGetAddress.d.ts +1 -0
- package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
- package/dist/api/solana/SolSignMessage.d.ts +4 -0
- package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +4 -0
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +8 -0
- 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 +2 -1
- package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +2 -1
- 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 +4 -0
- package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
- package/dist/api/tron/TronSignTransaction.d.ts +4 -0
- package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
- package/dist/api/xrp/XrpSignTransaction.d.ts.map +1 -1
- 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 +7 -4
- 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 +5 -4
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +5 -18
- 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 +2 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +8 -0
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +292 -43
- package/dist/index.js +16693 -1501
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +104 -0
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/firmware.d.ts +12 -0
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/index.d.ts +3 -0
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
- 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 +7 -0
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/getDeviceInfo.d.ts +84 -0
- package/dist/types/api/getDeviceInfo.d.ts.map +1 -0
- package/dist/types/api/getPassphraseState.d.ts +10 -1
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +33 -3
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +127 -0
- package/dist/types/api/protocolV2.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 +6 -2
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +2 -1
- 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 +5 -3
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts +1 -0
- 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 +7 -82
- package/src/api/DirList.ts +29 -0
- package/src/api/DirMake.ts +21 -0
- package/src/api/DirRemove.ts +21 -0
- package/src/api/FileDelete.ts +21 -0
- package/src/api/FileRead.ts +165 -0
- package/src/api/FileWrite.ts +203 -0
- package/src/api/FirmwareUpdateV3.ts +21 -4
- package/src/api/FirmwareUpdateV4.ts +810 -0
- package/src/api/GetDeviceInfo.ts +161 -0
- package/src/api/GetOnekeyFeatures.ts +75 -3
- package/src/api/GetPassphraseState.ts +16 -7
- package/src/api/PathInfo.ts +25 -0
- package/src/api/SearchDevices.ts +7 -2
- package/src/api/alephium/AlephiumGetAddress.ts +6 -2
- package/src/api/alephium/AlephiumSignMessage.ts +6 -2
- package/src/api/alephium/AlephiumSignTransaction.ts +6 -3
- package/src/api/algo/AlgoSignTransaction.ts +0 -1
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +18 -9
- package/src/api/aptos/AptosSignInMessage.ts +0 -1
- package/src/api/aptos/AptosSignMessage.ts +0 -1
- package/src/api/aptos/AptosSignTransaction.ts +0 -1
- package/src/api/benfen/BenfenGetAddress.ts +6 -2
- package/src/api/benfen/BenfenGetPublicKey.ts +6 -2
- package/src/api/benfen/BenfenSignMessage.ts +6 -2
- package/src/api/benfen/BenfenSignTransaction.ts +6 -2
- package/src/api/btc/BTCSignMessage.ts +0 -1
- package/src/api/btc/BTCSignPsbt.ts +0 -1
- package/src/api/btc/BTCSignTransaction.ts +0 -1
- package/src/api/btc/helpers/versionLimit.ts +7 -1
- package/src/api/cardano/CardanoSignMessage.ts +0 -1
- package/src/api/cardano/CardanoSignTransaction.ts +0 -1
- package/src/api/conflux/ConfluxSignMessage.ts +0 -1
- package/src/api/conflux/ConfluxSignMessageCIP23.ts +0 -1
- package/src/api/conflux/ConfluxSignTransaction.ts +5 -3
- package/src/api/cosmos/CosmosSignTransaction.ts +0 -1
- package/src/api/device/DeviceRebootToBoardloader.ts +10 -1
- package/src/api/device/DeviceRebootToBootloader.ts +10 -1
- package/src/api/dynex/DnxGetAddress.ts +7 -0
- package/src/api/dynex/DnxSignTransaction.ts +7 -1
- package/src/api/evm/EVMGetAddress.ts +1 -1
- package/src/api/evm/EVMGetPublicKey.ts +1 -1
- package/src/api/evm/EVMSignMessage.ts +1 -3
- package/src/api/evm/EVMSignMessageEIP712.ts +14 -2
- package/src/api/evm/EVMSignTransaction.ts +1 -3
- package/src/api/evm/EVMSignTypedData.ts +6 -8
- package/src/api/evm/EVMVerifyMessage.ts +1 -1
- package/src/api/filecoin/FilecoinSignTransaction.ts +0 -1
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -4
- package/src/api/helpers/deviceInfo.ts +205 -0
- package/src/api/helpers/filesystemValidation.ts +51 -0
- package/src/api/index.ts +30 -1
- package/src/api/kaspa/KaspaSignTransaction.ts +0 -1
- package/src/api/near/NearSignTransaction.ts +0 -1
- package/src/api/nem/NEMSignTransaction.ts +0 -1
- package/src/api/neo/NeoGetAddress.ts +6 -1
- package/src/api/neo/NeoSignTransaction.ts +6 -2
- package/src/api/nervos/NervosGetAddress.ts +6 -2
- package/src/api/nervos/NervosSignTransaction.ts +6 -3
- package/src/api/nexa/NexaGetAddress.ts +6 -2
- package/src/api/nexa/NexaSignTransaction.ts +6 -4
- package/src/api/nostr/NostrSignEvent.ts +0 -1
- package/src/api/nostr/NostrSignSchnorr.ts +0 -1
- package/src/api/polkadot/PolkadotSignTransaction.ts +0 -1
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +50 -0
- package/src/api/protocol-v2/DeviceGetDeviceInfo.ts +35 -0
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +18 -0
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +18 -0
- package/src/api/protocol-v2/DeviceReboot.ts +22 -0
- package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +27 -0
- package/src/api/protocol-v2/FactoryGetDeviceInfo.ts +18 -0
- package/src/api/protocol-v2/FilesystemDiskControl.ts +34 -0
- package/src/api/protocol-v2/FilesystemFixPermission.ts +14 -0
- package/src/api/protocol-v2/FilesystemFormat.ts +14 -0
- package/src/api/protocol-v2/GetProtoVersion.ts +14 -0
- package/src/api/protocol-v2/Ping.ts +16 -0
- package/src/api/protocol-v2/helpers.ts +161 -0
- package/src/api/scdo/ScdoGetAddress.ts +6 -2
- package/src/api/scdo/ScdoSignMessage.ts +6 -2
- package/src/api/scdo/ScdoSignTransaction.ts +6 -3
- package/src/api/solana/SolGetAddress.ts +4 -0
- package/src/api/solana/SolSignMessage.ts +4 -1
- package/src/api/solana/SolSignOffchainMessage.ts +4 -1
- package/src/api/solana/SolSignTransaction.ts +8 -1
- package/src/api/starcoin/StarcoinSignMessage.ts +0 -1
- package/src/api/starcoin/StarcoinSignTransaction.ts +0 -1
- package/src/api/stellar/StellarGetAddress.ts +10 -1
- package/src/api/stellar/StellarSignTransaction.ts +14 -2
- package/src/api/sui/SuiSignMessage.ts +0 -1
- package/src/api/sui/SuiSignTransaction.ts +12 -10
- package/src/api/ton/TonSignData.ts +0 -1
- package/src/api/ton/TonSignMessage.ts +0 -1
- package/src/api/ton/TonSignProof.ts +0 -1
- package/src/api/tron/TronSignMessage.ts +5 -2
- package/src/api/tron/TronSignTransaction.ts +4 -1
- package/src/api/xrp/XrpSignTransaction.ts +1 -2
- package/src/core/RequestQueue.ts +3 -10
- package/src/core/index.ts +62 -153
- package/src/data/messages/messages-protocol-v2.json +13128 -0
- package/src/data-manager/DataManager.ts +12 -7
- package/src/data-manager/MessagesConfig.ts +14 -14
- package/src/data-manager/TransportManager.ts +38 -12
- package/src/device/Device.ts +98 -82
- package/src/device/DeviceCommands.ts +166 -26
- package/src/device/DeviceConnector.ts +29 -4
- package/src/device/DevicePool.ts +1 -1
- package/src/events/ui-request.ts +8 -0
- package/src/inject.ts +46 -2
- package/src/protocols/protocol-v2/features.ts +287 -0
- package/src/protocols/protocol-v2/firmware.ts +26 -0
- package/src/protocols/protocol-v2/index.ts +2 -0
- package/src/types/api/export.ts +1 -0
- package/src/types/api/firmwareUpdate.ts +12 -0
- package/src/types/api/getDeviceInfo.ts +97 -0
- package/src/types/api/getPassphraseState.ts +13 -2
- package/src/types/api/index.ts +80 -3
- package/src/types/api/protocolV2.ts +226 -0
- package/src/types/api/searchDevices.ts +2 -2
- package/src/types/device.ts +33 -2
- package/src/types/params.ts +4 -2
- package/src/types/settings.ts +1 -1
- package/src/utils/deviceFeaturesUtils.ts +62 -21
- package/src/utils/deviceInfoUtils.ts +15 -8
- package/src/utils/index.ts +1 -0
- package/__tests__/DeviceCommands.test.ts +0 -99
- package/__tests__/evmLedgerLegacySafety.test.ts +0 -261
- package/__tests__/preInitialize.test.ts +0 -22
- package/dist/api/device/PreInitialize.d.ts +0 -6
- package/dist/api/device/PreInitialize.d.ts.map +0 -1
- package/dist/core/PollingStateManager.d.ts +0 -8
- package/dist/core/PollingStateManager.d.ts.map +0 -1
- package/dist/types/api/preInitialize.d.ts +0 -3
- package/dist/types/api/preInitialize.d.ts.map +0 -1
- package/src/api/device/PreInitialize.ts +0 -41
- package/src/core/PollingStateManager.ts +0 -47
- package/src/types/api/preInitialize.ts +0 -3
|
@@ -4,6 +4,7 @@ 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';
|
|
7
8
|
import {
|
|
8
9
|
LoggerNames,
|
|
9
10
|
getDeviceBLEFirmwareVersion,
|
|
@@ -40,7 +41,8 @@ export const FIRMWARE_FIELDS = [
|
|
|
40
41
|
|
|
41
42
|
export type IFirmwareField = (typeof FIRMWARE_FIELDS)[number];
|
|
42
43
|
|
|
43
|
-
export type
|
|
44
|
+
export type ProtocolV1MessageSchema = 'v1CurrentSchema' | 'v1LegacySchema';
|
|
45
|
+
export type ProtobufMessageSchema = ProtocolV1MessageSchema | 'v2Schema';
|
|
44
46
|
|
|
45
47
|
const FIRMWARE_FIELD_TYPE_MAP: Readonly<Record<IFirmwareField, EFirmwareType>> = {
|
|
46
48
|
firmware: EFirmwareType.Universal,
|
|
@@ -62,7 +64,9 @@ function getFirmwareTypeFromField(firmwareField: IFirmwareField): EFirmwareType
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
export default class DataManager {
|
|
65
|
-
static deviceMap: DeviceTypeMap
|
|
67
|
+
static deviceMap: DeviceTypeMap & {
|
|
68
|
+
[k: string]: DeviceTypeMap[keyof DeviceTypeMap] | undefined;
|
|
69
|
+
} = {
|
|
66
70
|
[EDeviceType.Classic]: {
|
|
67
71
|
firmware: [],
|
|
68
72
|
ble: [],
|
|
@@ -93,9 +97,10 @@ export default class DataManager {
|
|
|
93
97
|
|
|
94
98
|
static settings: ConnectSettings;
|
|
95
99
|
|
|
96
|
-
static messages: { [
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
static messages: { [schema in ProtobufMessageSchema]: JSON } = {
|
|
101
|
+
v1CurrentSchema: MessagesJSON as unknown as JSON,
|
|
102
|
+
v1LegacySchema: MessagesLegacyV1JSON as unknown as JSON,
|
|
103
|
+
v2Schema: MessagesProtocolV2JSON as unknown as JSON,
|
|
99
104
|
};
|
|
100
105
|
|
|
101
106
|
static lastCheckTimestamp = 0;
|
|
@@ -472,8 +477,8 @@ export default class DataManager {
|
|
|
472
477
|
}
|
|
473
478
|
}
|
|
474
479
|
|
|
475
|
-
static getProtobufMessages(
|
|
476
|
-
return this.messages[
|
|
480
|
+
static getProtobufMessages(schema: ProtobufMessageSchema = 'v1CurrentSchema'): JSON {
|
|
481
|
+
return this.messages[schema];
|
|
477
482
|
}
|
|
478
483
|
|
|
479
484
|
static getSettings(key?: undefined): ConnectSettings;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import type { IDeviceModel, IDeviceType } from '../types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ProtocolV1MessageSchema } from './DataManager';
|
|
3
3
|
|
|
4
4
|
type DeviceVersionConfig = {
|
|
5
5
|
[deviceType in IDeviceType | IDeviceModel]?: {
|
|
6
6
|
minVersion: string;
|
|
7
|
-
|
|
7
|
+
protocolV1MessageSchema: ProtocolV1MessageSchema;
|
|
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 the current Protocol V1 schema by default.
|
|
14
|
+
// Only use the legacy Protocol V1 schema for specific old versions (< 3.3.0).
|
|
15
|
+
{ minVersion: '3.3.0', protocolV1MessageSchema: 'v1CurrentSchema' },
|
|
16
|
+
{ minVersion: '0.0.1', protocolV1MessageSchema: 'v1LegacySchema' },
|
|
17
|
+
// Fallback to current Protocol V1 schema for unknown versions (0.0.0).
|
|
18
|
+
{ minVersion: '0.0.0', protocolV1MessageSchema: 'v1CurrentSchema' },
|
|
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 the current Protocol V1 schema by default for Touch/Pro.
|
|
22
|
+
// Only use the legacy Protocol V1 schema for specific old versions (< 4.5.0).
|
|
23
|
+
{ minVersion: '4.5.0', protocolV1MessageSchema: 'v1CurrentSchema' },
|
|
24
|
+
{ minVersion: '0.0.1', protocolV1MessageSchema: 'v1LegacySchema' },
|
|
25
|
+
// Fallback to current Protocol V1 schema for unknown versions (0.0.0).
|
|
26
|
+
{ minVersion: '0.0.0', protocolV1MessageSchema: 'v1CurrentSchema' },
|
|
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 { getSupportProtocolV1MessageSchema } from '../utils/deviceFeaturesUtils';
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { ProtocolV1MessageSchema } from './DataManager';
|
|
10
10
|
import type { LowlevelTransportSharedPlugin, Transport } from '@onekeyfe/hd-transport';
|
|
11
11
|
import type { Features } from '../types';
|
|
12
12
|
|
|
@@ -17,6 +17,7 @@ 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;
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* transport 在同一个环境中只会存在一个
|
|
@@ -32,7 +33,7 @@ export default class TransportManager {
|
|
|
32
33
|
|
|
33
34
|
static reactNativeInit = false;
|
|
34
35
|
|
|
35
|
-
static
|
|
36
|
+
static protocolV1MessageSchema: ProtocolV1MessageSchema = 'v1CurrentSchema';
|
|
36
37
|
|
|
37
38
|
static plugin: LowlevelTransportSharedPlugin | null = null;
|
|
38
39
|
|
|
@@ -40,7 +41,7 @@ export default class TransportManager {
|
|
|
40
41
|
Log.debug('transport manager load');
|
|
41
42
|
this.defaultMessages = DataManager.getProtobufMessages();
|
|
42
43
|
this.currentMessages = this.defaultMessages;
|
|
43
|
-
this.
|
|
44
|
+
this.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
static async configure() {
|
|
@@ -74,6 +75,9 @@ export default class TransportManager {
|
|
|
74
75
|
}
|
|
75
76
|
Log.debug('Configuring transports');
|
|
76
77
|
await this.transport.configure(JSON.stringify(this.defaultMessages));
|
|
78
|
+
this.currentMessages = this.defaultMessages;
|
|
79
|
+
this.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
80
|
+
await this.configureProtocolV2Messages();
|
|
77
81
|
Log.debug('Configuring transports done');
|
|
78
82
|
} catch (error) {
|
|
79
83
|
Log.debug('Initializing transports error: ', error);
|
|
@@ -83,20 +87,31 @@ export default class TransportManager {
|
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Re-load the transport's main protobuf schema based on a device's reported features.
|
|
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);
|
|
89
104
|
|
|
90
105
|
if (this.currentMessages === messages || !messages) {
|
|
91
106
|
return;
|
|
92
107
|
}
|
|
93
108
|
|
|
94
|
-
Log.debug(`Reconfiguring transports
|
|
109
|
+
Log.debug(`Reconfiguring transports Protocol V1 schema:${protocolV1MessageSchema}`);
|
|
95
110
|
|
|
96
111
|
try {
|
|
97
112
|
await this.transport.configure(JSON.stringify(messages));
|
|
98
113
|
this.currentMessages = messages;
|
|
99
|
-
this.
|
|
114
|
+
this.protocolV1MessageSchema = protocolV1MessageSchema;
|
|
100
115
|
} catch (error) {
|
|
101
116
|
throw ERRORS.TypedError(
|
|
102
117
|
HardwareErrorCode.TransportInvalidProtobuf,
|
|
@@ -109,7 +124,9 @@ export default class TransportManager {
|
|
|
109
124
|
const env = DataManager.getSettings('env');
|
|
110
125
|
if (env === 'react-native') {
|
|
111
126
|
/** Actually initializes the ReactNativeTransport */
|
|
112
|
-
this.transport = new TransportConstructor({
|
|
127
|
+
this.transport = new TransportConstructor({
|
|
128
|
+
scanTimeout: REACT_NATIVE_BLE_SCAN_TIMEOUT_MS,
|
|
129
|
+
}) as unknown as Transport;
|
|
113
130
|
} else {
|
|
114
131
|
/** Actually initializes the HttpTransport */
|
|
115
132
|
this.transport = new TransportConstructor() as unknown as Transport;
|
|
@@ -130,6 +147,15 @@ export default class TransportManager {
|
|
|
130
147
|
return this.transport;
|
|
131
148
|
}
|
|
132
149
|
|
|
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
|
+
|
|
133
159
|
static getDefaultMessages() {
|
|
134
160
|
return this.defaultMessages;
|
|
135
161
|
}
|
|
@@ -138,7 +164,7 @@ export default class TransportManager {
|
|
|
138
164
|
return this.currentMessages;
|
|
139
165
|
}
|
|
140
166
|
|
|
141
|
-
static
|
|
142
|
-
return this.
|
|
167
|
+
static getProtocolV1MessageSchema() {
|
|
168
|
+
return this.protocolV1MessageSchema;
|
|
143
169
|
}
|
|
144
170
|
}
|
package/src/device/Device.ts
CHANGED
|
@@ -41,6 +41,7 @@ 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';
|
|
44
45
|
|
|
45
46
|
import type { PROTO } from '../constants';
|
|
46
47
|
import type {
|
|
@@ -49,7 +50,7 @@ import type {
|
|
|
49
50
|
PassphraseRequestPayload,
|
|
50
51
|
} from '../events';
|
|
51
52
|
import type { PassphrasePromptResponse } from './DeviceCommands';
|
|
52
|
-
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
53
|
+
import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
53
54
|
import type { OneKeyDeviceInfo as DeviceDescriptor } from '@onekeyfe/hd-transport';
|
|
54
55
|
import type DeviceConnector from './DeviceConnector';
|
|
55
56
|
|
|
@@ -58,11 +59,11 @@ export type InitOptions = {
|
|
|
58
59
|
deviceId?: string;
|
|
59
60
|
passphraseState?: string;
|
|
60
61
|
deriveCardano?: boolean;
|
|
62
|
+
connectProtocol?: HardwareConnectProtocol;
|
|
61
63
|
};
|
|
62
64
|
|
|
63
65
|
export type RunOptions = {
|
|
64
66
|
keepSession?: boolean;
|
|
65
|
-
skipInitialize?: boolean;
|
|
66
67
|
} & InitOptions;
|
|
67
68
|
|
|
68
69
|
const parseRunOptions = (options?: RunOptions): RunOptions => {
|
|
@@ -197,17 +198,6 @@ export class Device extends EventEmitter {
|
|
|
197
198
|
|
|
198
199
|
pendingCallbackPromise?: Deferred<void>;
|
|
199
200
|
|
|
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
|
-
|
|
211
201
|
constructor(descriptor: DeviceDescriptor, sdkInstanceId?: string) {
|
|
212
202
|
super();
|
|
213
203
|
this.originalDescriptor = descriptor;
|
|
@@ -264,13 +254,13 @@ export class Device extends EventEmitter {
|
|
|
264
254
|
* Device connect
|
|
265
255
|
* @returns {Promise<boolean>}
|
|
266
256
|
*/
|
|
267
|
-
connect() {
|
|
257
|
+
connect(connectProtocol?: HardwareConnectProtocol) {
|
|
268
258
|
const env = DataManager.getSettings('env');
|
|
269
259
|
// eslint-disable-next-line no-async-promise-executor
|
|
270
260
|
return new Promise<boolean>(async (resolve, reject) => {
|
|
271
261
|
if (DataManager.isBleConnect(env)) {
|
|
272
262
|
try {
|
|
273
|
-
await this.acquire();
|
|
263
|
+
await this.acquire(connectProtocol);
|
|
274
264
|
resolve(true);
|
|
275
265
|
} catch (error) {
|
|
276
266
|
reject(error);
|
|
@@ -280,7 +270,7 @@ export class Device extends EventEmitter {
|
|
|
280
270
|
// 不存在 Session ID 或存在 Session ID 但设备在别处使用,都需要 acquire 获取最新 sessionID
|
|
281
271
|
if (!this.mainId || (!this.isUsedHere() && this.originalDescriptor)) {
|
|
282
272
|
try {
|
|
283
|
-
await this.acquire();
|
|
273
|
+
await this.acquire(connectProtocol);
|
|
284
274
|
resolve(true);
|
|
285
275
|
} catch (error) {
|
|
286
276
|
reject(error);
|
|
@@ -295,23 +285,44 @@ export class Device extends EventEmitter {
|
|
|
295
285
|
});
|
|
296
286
|
}
|
|
297
287
|
|
|
298
|
-
async acquire() {
|
|
288
|
+
async acquire(connectProtocol?: HardwareConnectProtocol) {
|
|
299
289
|
const env = DataManager.getSettings('env');
|
|
300
290
|
const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
|
|
291
|
+
const expectedProtocol = connectProtocol ?? this.originalDescriptor.protocolType;
|
|
301
292
|
try {
|
|
293
|
+
let acquireResult: unknown;
|
|
302
294
|
if (DataManager.isBleConnect(env)) {
|
|
303
|
-
|
|
304
|
-
|
|
295
|
+
acquireResult = await this.deviceConnector?.acquire(
|
|
296
|
+
this.originalDescriptor.id,
|
|
297
|
+
undefined,
|
|
298
|
+
true,
|
|
299
|
+
expectedProtocol
|
|
300
|
+
);
|
|
301
|
+
this.mainId = (acquireResult as any)?.uuid ?? '';
|
|
305
302
|
Log.debug('Expected uuid:', this.mainId);
|
|
306
303
|
} else {
|
|
307
|
-
|
|
304
|
+
acquireResult = await this.deviceConnector?.acquire(
|
|
308
305
|
this.originalDescriptor.path,
|
|
309
|
-
this.originalDescriptor.session
|
|
306
|
+
this.originalDescriptor.session,
|
|
307
|
+
undefined,
|
|
308
|
+
expectedProtocol
|
|
310
309
|
);
|
|
310
|
+
this.mainId = acquireResult as string | undefined;
|
|
311
311
|
Log.debug('Expected session id:', this.mainId);
|
|
312
312
|
}
|
|
313
313
|
this.deviceAcquired = true;
|
|
314
314
|
this.updateDescriptor({ [mainIdKey]: this.mainId } as unknown as DeviceDescriptor);
|
|
315
|
+
|
|
316
|
+
// Propagate protocol version detected during acquire.
|
|
317
|
+
const detectedProtocol =
|
|
318
|
+
(acquireResult as { protocolType?: HardwareConnectProtocol } | undefined)?.protocolType ??
|
|
319
|
+
TransportManager.transport?.getProtocolType?.(
|
|
320
|
+
DataManager.isBleConnect(env) ? this.originalDescriptor.id : this.originalDescriptor.path
|
|
321
|
+
);
|
|
322
|
+
if (detectedProtocol) {
|
|
323
|
+
this.originalDescriptor.protocolType = detectedProtocol;
|
|
324
|
+
}
|
|
325
|
+
|
|
315
326
|
if (this.commands) {
|
|
316
327
|
await this.commands.dispose(false);
|
|
317
328
|
}
|
|
@@ -367,54 +378,6 @@ export class Device extends EventEmitter {
|
|
|
367
378
|
this.deviceAcquired = false;
|
|
368
379
|
}
|
|
369
380
|
|
|
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
|
-
|
|
418
381
|
getCommands() {
|
|
419
382
|
return this.commands;
|
|
420
383
|
}
|
|
@@ -522,6 +485,17 @@ export class Device extends EventEmitter {
|
|
|
522
485
|
}
|
|
523
486
|
|
|
524
487
|
async initialize(options?: InitOptions) {
|
|
488
|
+
// Protocol V2 不支持传统 Initialize,直接使用协议专用初始化流程。
|
|
489
|
+
if (this.originalDescriptor.protocolType === 'V2') {
|
|
490
|
+
this.passphraseState = options?.passphraseState;
|
|
491
|
+
if (this.features && !this.featuresNeedsReload && !options?.initSession) {
|
|
492
|
+
Log.debug('Skip Protocol V2 feature adapter; cached features are available');
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
await this._initializeProtocolV2();
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
|
|
525
499
|
// Log.debug('initialize param:', options);
|
|
526
500
|
|
|
527
501
|
this.passphraseState = options?.passphraseState;
|
|
@@ -542,7 +516,13 @@ export class Device extends EventEmitter {
|
|
|
542
516
|
payload.passphrase_state = options?.passphraseState;
|
|
543
517
|
payload.is_contains_attach = true;
|
|
544
518
|
|
|
545
|
-
|
|
519
|
+
Log.debug('Initialize device begin:', {
|
|
520
|
+
deviceId: options?.deviceId,
|
|
521
|
+
passphraseState: options?.passphraseState,
|
|
522
|
+
initSession: options?.initSession,
|
|
523
|
+
InitializePayload: payload,
|
|
524
|
+
});
|
|
525
|
+
|
|
546
526
|
try {
|
|
547
527
|
// @ts-expect-error
|
|
548
528
|
const { message } = await Promise.race([
|
|
@@ -555,8 +535,7 @@ export class Device extends EventEmitter {
|
|
|
555
535
|
}),
|
|
556
536
|
]);
|
|
557
537
|
|
|
558
|
-
|
|
559
|
-
this.setLastInitializeDuration(initCostMs);
|
|
538
|
+
Log.debug('Initialize device end: ', message);
|
|
560
539
|
this._updateFeatures(message, options?.initSession);
|
|
561
540
|
await TransportManager.reconfigure(this.features);
|
|
562
541
|
} catch (error) {
|
|
@@ -565,6 +544,36 @@ export class Device extends EventEmitter {
|
|
|
565
544
|
}
|
|
566
545
|
}
|
|
567
546
|
|
|
547
|
+
/**
|
|
548
|
+
* Device initialization over Protocol V2.
|
|
549
|
+
*
|
|
550
|
+
* Protocol V2 不走传统 Initialize/GetFeatures,直接用轻量 DeviceGetDeviceInfo
|
|
551
|
+
* 归一成 legacy-style Features 视图。
|
|
552
|
+
*/
|
|
553
|
+
private async _initializeProtocolV2() {
|
|
554
|
+
Log.debug('Initialize device via Protocol V2 feature adapter');
|
|
555
|
+
|
|
556
|
+
try {
|
|
557
|
+
const features = await Promise.race([
|
|
558
|
+
getProtocolV2Features({
|
|
559
|
+
commands: this.commands,
|
|
560
|
+
descriptor: this.originalDescriptor,
|
|
561
|
+
timeoutMs: 10 * 1000,
|
|
562
|
+
}),
|
|
563
|
+
new Promise<never>((_, reject) => {
|
|
564
|
+
setTimeout(() => {
|
|
565
|
+
reject(ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed));
|
|
566
|
+
}, 10 * 1000);
|
|
567
|
+
}),
|
|
568
|
+
]);
|
|
569
|
+
Log.debug('Protocol V2 normalized features:', features);
|
|
570
|
+
this._updateFeatures(features);
|
|
571
|
+
} catch (error) {
|
|
572
|
+
Log.error('Protocol V2 initialization failed:', error);
|
|
573
|
+
throw error;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
568
577
|
async getFeatures() {
|
|
569
578
|
const { message } = await this.commands.typedCall('GetFeatures', 'Features', {});
|
|
570
579
|
this._updateFeatures(message);
|
|
@@ -635,7 +644,7 @@ export class Device extends EventEmitter {
|
|
|
635
644
|
const env = DataManager.getSettings('env');
|
|
636
645
|
if (env !== 'react-native') {
|
|
637
646
|
try {
|
|
638
|
-
await this.acquire();
|
|
647
|
+
await this.acquire(options.connectProtocol);
|
|
639
648
|
} catch (error) {
|
|
640
649
|
this.runPromise = null;
|
|
641
650
|
return Promise.reject(error);
|
|
@@ -643,9 +652,7 @@ export class Device extends EventEmitter {
|
|
|
643
652
|
|
|
644
653
|
try {
|
|
645
654
|
if (fn) {
|
|
646
|
-
|
|
647
|
-
await this.initialize(options);
|
|
648
|
-
}
|
|
655
|
+
await this.initialize(options);
|
|
649
656
|
}
|
|
650
657
|
} catch (error) {
|
|
651
658
|
this.runPromise = null;
|
|
@@ -879,9 +886,13 @@ export class Device extends EventEmitter {
|
|
|
879
886
|
this.features,
|
|
880
887
|
Enum_Capability.Capability_AttachToPin
|
|
881
888
|
);
|
|
889
|
+
const isPro2 = getDeviceType(this.features) === EDeviceType.Pro2;
|
|
882
890
|
|
|
883
891
|
const supportUnlock =
|
|
884
|
-
supportAttachPinCapability ||
|
|
892
|
+
supportAttachPinCapability ||
|
|
893
|
+
// Pro2 V2 暂未从 features 暴露 capabilities,先直连该方法用于固件联调。
|
|
894
|
+
isPro2 ||
|
|
895
|
+
(versionRange && semver.gte(firmwareVersion, versionRange.min));
|
|
885
896
|
|
|
886
897
|
if (supportUnlock) {
|
|
887
898
|
const res = await this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
|
|
@@ -929,14 +940,11 @@ export class Device extends EventEmitter {
|
|
|
929
940
|
onlyMainPin: useEmptyPassphrase,
|
|
930
941
|
});
|
|
931
942
|
|
|
932
|
-
if (skipPassphraseCheck) {
|
|
933
|
-
return true;
|
|
934
|
-
}
|
|
935
|
-
|
|
936
943
|
// Main wallet and unlock Attach Pin, throw safe error
|
|
937
944
|
const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
|
|
938
945
|
const useErrorAttachPin =
|
|
939
946
|
unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
|
|
947
|
+
const passphraseStateMismatch = !!passphraseState && passphraseState !== newPassphraseState;
|
|
940
948
|
|
|
941
949
|
Log.debug('Check passphrase state safety: ', {
|
|
942
950
|
passphraseState,
|
|
@@ -945,6 +953,14 @@ export class Device extends EventEmitter {
|
|
|
945
953
|
useEmptyPassphrase,
|
|
946
954
|
});
|
|
947
955
|
|
|
956
|
+
if (skipPassphraseCheck) {
|
|
957
|
+
if (passphraseStateMismatch) {
|
|
958
|
+
this.clearInternalState();
|
|
959
|
+
return false;
|
|
960
|
+
}
|
|
961
|
+
return true;
|
|
962
|
+
}
|
|
963
|
+
|
|
948
964
|
if (mainWalletUseAttachPin || useErrorAttachPin) {
|
|
949
965
|
try {
|
|
950
966
|
await this.lockDevice();
|
|
@@ -956,7 +972,7 @@ export class Device extends EventEmitter {
|
|
|
956
972
|
}
|
|
957
973
|
|
|
958
974
|
// When exists passphraseState, check passphraseState
|
|
959
|
-
if (
|
|
975
|
+
if (passphraseStateMismatch) {
|
|
960
976
|
this.clearInternalState();
|
|
961
977
|
return false;
|
|
962
978
|
}
|