Change TrezorClient to do what TrezorNoInit did
This commit is contained in:
parent
aa3665c971
commit
2693ae34f6
@ -3,7 +3,7 @@
|
||||
from ..hwwclient import HardwareWalletClient
|
||||
from ..errors import ActionCanceledError, BadArgumentError, DeviceAlreadyInitError, DeviceAlreadyUnlockedError, DeviceConnectionError, UnavailableActionError, DeviceNotReadyError
|
||||
from .trezorlib.client import TrezorClient as Trezor
|
||||
from .trezorlib.debuglink import DebugLink, DebugUI, TrezorClientDebugLink
|
||||
from .trezorlib.debuglink import TrezorClientDebugLink
|
||||
from .trezorlib.exceptions import Cancelled
|
||||
from .trezorlib.transport import enumerate_devices, get_transport
|
||||
from .trezorlib.ui import PassphraseUI, mnemonic_words, PIN_MATRIX_DESCRIPTION
|
||||
@ -57,26 +57,6 @@ def parse_multisig(script):
|
||||
multisig = proto.MultisigRedeemScriptType(m=m, signatures=[b''] * n, pubkeys=pubkeys)
|
||||
return (True, multisig)
|
||||
|
||||
class TrezorNoInit(Trezor):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def init_device(self):
|
||||
pass
|
||||
|
||||
def actual_init_device(self):
|
||||
return super().init_device()
|
||||
|
||||
class TrezorDebugNoInit(TrezorClientDebugLink):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def init_device(self):
|
||||
pass
|
||||
|
||||
def actual_init_device(self):
|
||||
return super().init_device()
|
||||
|
||||
def trezor_exception(f):
|
||||
def func(*args, **kwargs):
|
||||
try:
|
||||
@ -97,9 +77,9 @@ class TrezorClient(HardwareWalletClient):
|
||||
if path.startswith('udp'):
|
||||
logging.debug('Simulator found, using DebugLink')
|
||||
transport = get_transport(path)
|
||||
self.client = TrezorDebugNoInit(transport=transport)
|
||||
self.client = TrezorClientDebugLink(transport=transport)
|
||||
else:
|
||||
self.client = TrezorNoInit(transport=get_transport(path), ui=PassphraseUI(password))
|
||||
self.client = Trezor(transport=get_transport(path), ui=PassphraseUI(password))
|
||||
|
||||
# if it wasn't able to find a client, throw an error
|
||||
if not self.client:
|
||||
@ -109,7 +89,7 @@ class TrezorClient(HardwareWalletClient):
|
||||
self.client.open()
|
||||
|
||||
def _check_unlocked(self):
|
||||
self.client.actual_init_device()
|
||||
self.client.init_device()
|
||||
if self.client.features.pin_protection and not self.client.features.pin_cached:
|
||||
raise DeviceNotReadyError('Trezor is locked. Unlock by using \'promptpin\' and then \'sendpin\'.')
|
||||
|
||||
@ -333,7 +313,7 @@ class TrezorClient(HardwareWalletClient):
|
||||
# Setup a new device
|
||||
@trezor_exception
|
||||
def setup_device(self, label='', passphrase=''):
|
||||
self.client.actual_init_device()
|
||||
self.client.init_device()
|
||||
if self.client.features.initialized:
|
||||
raise DeviceAlreadyInitError('Device is already initialized. Use wipe first and try again')
|
||||
passphrase_enabled = False
|
||||
@ -368,7 +348,7 @@ class TrezorClient(HardwareWalletClient):
|
||||
# Prompt for a pin on device
|
||||
@trezor_exception
|
||||
def prompt_pin(self):
|
||||
self.client.actual_init_device()
|
||||
self.client.init_device()
|
||||
if not self.client.features.pin_protection:
|
||||
raise DeviceAlreadyUnlockedError('This device does not need a PIN')
|
||||
if self.client.features.pin_cached:
|
||||
@ -405,7 +385,7 @@ def enumerate(password=''):
|
||||
client = None
|
||||
try:
|
||||
client = TrezorClient(d_data['path'], password)
|
||||
client.client.actual_init_device()
|
||||
client.client.init_device()
|
||||
if client.client.features.initialized:
|
||||
master_xpub = client.get_pubkey_at_path('m/0h')['xpub']
|
||||
d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub)
|
||||
|
||||
@ -9,3 +9,4 @@ This stripped down version was made at commit [d5c2636f0d1b7da3cb94a4eff6169d77f
|
||||
- Removed altcoin support
|
||||
- Include the compiled protobuf definitions instead of making them on install
|
||||
- Removed functions that HWI does not use or plan to use
|
||||
- Changed `TrezorClient` from calling `init_device()` (HWI needs this behavior and doing it in the library makes this simpler)
|
||||
|
||||
@ -81,7 +81,6 @@ class TrezorClient:
|
||||
warnings.warn("UI class not supplied. This will probably crash soon.")
|
||||
|
||||
self.session_counter = 0
|
||||
self.init_device()
|
||||
|
||||
def open(self):
|
||||
if self.session_counter == 0:
|
||||
|
||||
@ -13,7 +13,7 @@ import unittest
|
||||
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
|
||||
from hwilib.devices.trezorlib.transport import enumerate_devices
|
||||
from hwilib.devices.trezorlib.transport.udp import UdpTransport
|
||||
from hwilib.devices.trezorlib.debuglink import DebugUI, TrezorClientDebugLink, load_device_by_mnemonic, load_device_by_xprv
|
||||
from hwilib.devices.trezorlib.debuglink import TrezorClientDebugLink, load_device_by_mnemonic, load_device_by_xprv
|
||||
from hwilib.devices.trezorlib import device, messages
|
||||
from test_device import DeviceEmulator, DeviceTestCase, start_bitcoind, TestDeviceConnect, TestDisplayAddress, TestGetKeypool, TestSignMessage, TestSignTx
|
||||
|
||||
@ -57,6 +57,7 @@ class TrezorEmulator(DeviceEmulator):
|
||||
wirelink = dev
|
||||
break
|
||||
client = TrezorClientDebugLink(wirelink)
|
||||
client.init_device()
|
||||
device.wipe(client)
|
||||
load_device_by_mnemonic(client=client, mnemonic='alcohol woman abuse must during monitor noble actual mixed trade anger aisle', pin='', passphrase_protection=False, label='test') # From Trezor device tests
|
||||
return client
|
||||
|
||||
Loading…
Reference in New Issue
Block a user