support trezorlib 0.12
This commit is contained in:
@@ -26,7 +26,7 @@ class Trezor(interface.Device):
|
||||
required_version = '>=1.4.0'
|
||||
|
||||
ui = None # can be overridden by device's users
|
||||
cached_state = None
|
||||
cached_session_id = None
|
||||
|
||||
def _verify_version(self, connection):
|
||||
f = connection.features
|
||||
@@ -54,11 +54,14 @@ class Trezor(interface.Device):
|
||||
for _ in range(5): # Retry a few times in case of PIN failures
|
||||
connection = self._defs.Client(transport=transport,
|
||||
ui=self.ui,
|
||||
state=self.__class__.cached_state)
|
||||
session_id=self.__class__.cached_session_id)
|
||||
self._verify_version(connection)
|
||||
|
||||
try:
|
||||
connection.ping(msg='', pin_protection=True) # unlock PIN
|
||||
# unlock PIN and passphrase
|
||||
self._defs.get_address(connection,
|
||||
"Testnet",
|
||||
self._defs.PASSPHRASE_TEST_PATH)
|
||||
return connection
|
||||
except (self._defs.PinException, ValueError) as e:
|
||||
log.error('Invalid PIN: %s, retrying...', e)
|
||||
@@ -70,7 +73,7 @@ class Trezor(interface.Device):
|
||||
|
||||
def close(self):
|
||||
"""Close connection."""
|
||||
self.__class__.cached_state = self.conn.state
|
||||
self.__class__.cached_session_id = self.conn.session_id
|
||||
super().close()
|
||||
|
||||
def pubkey(self, identity, ecdh=False):
|
||||
|
||||
@@ -8,12 +8,12 @@ import mnemonic
|
||||
import semver
|
||||
import trezorlib
|
||||
|
||||
from trezorlib.client import TrezorClient as Client
|
||||
from trezorlib.client import TrezorClient as Client, PASSPHRASE_TEST_PATH
|
||||
from trezorlib.exceptions import TrezorFailure, PinException
|
||||
from trezorlib.transport import get_transport
|
||||
from trezorlib.messages import IdentityType
|
||||
|
||||
from trezorlib.btc import get_public_node
|
||||
from trezorlib.btc import get_address, get_public_node
|
||||
from trezorlib.misc import sign_identity, get_ecdh_session_key
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -4,6 +4,11 @@ import logging
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
try:
|
||||
from trezorlib.client import PASSPHRASE_ON_DEVICE
|
||||
except Exception:
|
||||
PASSPHRASE_ON_DEVICE = object()
|
||||
|
||||
from .. import util
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -40,18 +45,24 @@ class UI:
|
||||
binary=self.pin_entry_binary,
|
||||
options=self.options_getter())
|
||||
|
||||
def get_passphrase(self, prompt='Passphrase:'):
|
||||
def get_passphrase(self, prompt='Passphrase:', available_on_device=False):
|
||||
"""Ask the user for passphrase."""
|
||||
passphrase = None
|
||||
if self.cached_passphrase_ack:
|
||||
passphrase = self.cached_passphrase_ack.get()
|
||||
if passphrase is None:
|
||||
passphrase = interact(
|
||||
title='{} passphrase'.format(self.device_name),
|
||||
prompt=prompt,
|
||||
description=None,
|
||||
binary=self.passphrase_entry_binary,
|
||||
options=self.options_getter())
|
||||
env_passphrase = os.environ.get("TREZOR_PASSPHRASE")
|
||||
if env_passphrase is not None:
|
||||
passphrase = env_passphrase
|
||||
elif available_on_device:
|
||||
passphrase = PASSPHRASE_ON_DEVICE
|
||||
else:
|
||||
passphrase = interact(
|
||||
title='{} passphrase'.format(self.device_name),
|
||||
prompt=prompt,
|
||||
description=None,
|
||||
binary=self.passphrase_entry_binary,
|
||||
options=self.options_getter())
|
||||
if self.cached_passphrase_ack:
|
||||
self.cached_passphrase_ack.set(passphrase)
|
||||
return passphrase
|
||||
|
||||
Reference in New Issue
Block a user