fix command line interface for hardware wallets. fixes #3056
This commit is contained in:
@@ -37,7 +37,7 @@ from .bitcoin import *
|
|||||||
from .bitcoin import is_old_seed, is_new_seed, is_seed
|
from .bitcoin import is_old_seed, is_new_seed, is_seed
|
||||||
from .util import PrintError, InvalidPassword, hfu
|
from .util import PrintError, InvalidPassword, hfu
|
||||||
from .mnemonic import Mnemonic, load_wordlist
|
from .mnemonic import Mnemonic, load_wordlist
|
||||||
|
from .plugins import run_hook
|
||||||
|
|
||||||
class KeyStore(PrintError):
|
class KeyStore(PrintError):
|
||||||
|
|
||||||
@@ -488,6 +488,7 @@ class Hardware_KeyStore(KeyStore, Xpub):
|
|||||||
self.label = d.get('label')
|
self.label = d.get('label')
|
||||||
self.derivation = d.get('derivation')
|
self.derivation = d.get('derivation')
|
||||||
self.handler = None
|
self.handler = None
|
||||||
|
run_hook('init_keystore', self)
|
||||||
|
|
||||||
def set_label(self, label):
|
def set_label(self, label):
|
||||||
self.label = label
|
self.label = label
|
||||||
|
|||||||
@@ -1,17 +1,11 @@
|
|||||||
from electrum.util import print_msg
|
from electrum.util import print_msg
|
||||||
from .digitalbitbox import DigitalBitboxPlugin
|
from .digitalbitbox import DigitalBitboxPlugin
|
||||||
|
from ..hw_wallet import CmdLineHandler
|
||||||
class DigitalBitboxCmdLineHandler:
|
|
||||||
def stop(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def show_message(self, msg):
|
|
||||||
print_msg(msg)
|
|
||||||
|
|
||||||
def get_passphrase(self, msg, confirm):
|
|
||||||
import getpass
|
|
||||||
print_msg(msg)
|
|
||||||
return getpass.getpass('')
|
|
||||||
|
|
||||||
class Plugin(DigitalBitboxPlugin):
|
class Plugin(DigitalBitboxPlugin):
|
||||||
handler = DigitalBitboxCmdLineHandler()
|
handler = CmdLineHandler()
|
||||||
|
@hook
|
||||||
|
def init_keystore(self, keystore):
|
||||||
|
if not isinstance(keystore, self.keystore_class):
|
||||||
|
return
|
||||||
|
keystore.handler = self.handler
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
from .plugin import HW_PluginBase
|
from .plugin import HW_PluginBase
|
||||||
|
from .cmdline import CmdLineHandler
|
||||||
|
|||||||
39
plugins/hw_wallet/cmdline.py
Normal file
39
plugins/hw_wallet/cmdline.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
from electrum.util import print_msg, print_error, raw_input
|
||||||
|
|
||||||
|
class CmdLineHandler:
|
||||||
|
|
||||||
|
def get_passphrase(self, msg, confirm):
|
||||||
|
import getpass
|
||||||
|
print_msg(msg)
|
||||||
|
return getpass.getpass('')
|
||||||
|
|
||||||
|
def get_pin(self, msg):
|
||||||
|
t = { 'a':'7', 'b':'8', 'c':'9', 'd':'4', 'e':'5', 'f':'6', 'g':'1', 'h':'2', 'i':'3'}
|
||||||
|
print_msg(msg)
|
||||||
|
print_msg("a b c\nd e f\ng h i\n-----")
|
||||||
|
o = raw_input()
|
||||||
|
return ''.join(map(lambda x: t[x], o))
|
||||||
|
|
||||||
|
def prompt_auth(self, msg):
|
||||||
|
import getpass
|
||||||
|
print_msg(msg)
|
||||||
|
response = getpass.getpass('')
|
||||||
|
if len(response) == 0:
|
||||||
|
return None
|
||||||
|
return response
|
||||||
|
|
||||||
|
def yes_no_question(self, msg):
|
||||||
|
print_msg(msg)
|
||||||
|
return raw_input() in 'yY'
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def show_message(self, msg, on_cancel):
|
||||||
|
print_msg(msg)
|
||||||
|
|
||||||
|
def update_status(self, b):
|
||||||
|
print_error('trezor status', b)
|
||||||
|
|
||||||
|
def finished(self):
|
||||||
|
pass
|
||||||
@@ -1,25 +1,11 @@
|
|||||||
from electrum.util import print_msg, raw_input
|
from electrum.util import print_msg, raw_input
|
||||||
from .keepkey import KeepKeyPlugin
|
from .keepkey import KeepKeyPlugin
|
||||||
|
from ..hw_wallet import CmdLineHandler
|
||||||
class KeepKeyCmdLineHandler:
|
|
||||||
|
|
||||||
def get_passphrase(self, msg, confirm):
|
|
||||||
import getpass
|
|
||||||
print_msg(msg)
|
|
||||||
return getpass.getpass('')
|
|
||||||
|
|
||||||
def get_pin(self, msg):
|
|
||||||
t = { 'a':'7', 'b':'8', 'c':'9', 'd':'4', 'e':'5', 'f':'6', 'g':'1', 'h':'2', 'i':'3'}
|
|
||||||
print_msg(msg)
|
|
||||||
print_msg("a b c\nd e f\ng h i\n-----")
|
|
||||||
o = raw_input()
|
|
||||||
return ''.join(map(lambda x: t[x], o))
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def show_message(self, msg):
|
|
||||||
print_msg(msg)
|
|
||||||
|
|
||||||
class Plugin(KeepKeyPlugin):
|
class Plugin(KeepKeyPlugin):
|
||||||
handler = KeepKeyCmdLineHandler()
|
handler = CmdLineHandler()
|
||||||
|
@hook
|
||||||
|
def init_keystore(self, keystore):
|
||||||
|
if not isinstance(keystore, self.keystore_class):
|
||||||
|
return
|
||||||
|
keystore.handler = self.handler
|
||||||
|
|||||||
@@ -1,20 +1,11 @@
|
|||||||
from electrum.util import print_msg
|
from electrum.util import print_msg
|
||||||
from .ledger import LedgerPlugin
|
from .ledger import LedgerPlugin
|
||||||
|
from ..hw_wallet import CmdLineHandler
|
||||||
class BTChipCmdLineHandler:
|
|
||||||
def stop(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def show_message(self, msg):
|
|
||||||
print_msg(msg)
|
|
||||||
|
|
||||||
def prompt_auth(self, msg):
|
|
||||||
import getpass
|
|
||||||
print_msg(msg)
|
|
||||||
response = getpass.getpass('')
|
|
||||||
if len(response) == 0:
|
|
||||||
return None
|
|
||||||
return response
|
|
||||||
|
|
||||||
class Plugin(LedgerPlugin):
|
class Plugin(LedgerPlugin):
|
||||||
handler = BTChipCmdLineHandler()
|
handler = CmdLineHandler()
|
||||||
|
@hook
|
||||||
|
def init_keystore(self, keystore):
|
||||||
|
if not isinstance(keystore, self.keystore_class):
|
||||||
|
return
|
||||||
|
keystore.handler = self.handler
|
||||||
|
|||||||
@@ -1,26 +1,11 @@
|
|||||||
from electrum.util import print_msg, raw_input
|
from electrum.plugins import hook
|
||||||
from .trezor import TrezorPlugin
|
from .trezor import TrezorPlugin
|
||||||
|
from ..hw_wallet import CmdLineHandler
|
||||||
class TrezorCmdLineHandler:
|
|
||||||
|
|
||||||
def get_passphrase(self, msg, confirm):
|
|
||||||
import getpass
|
|
||||||
print_msg(msg)
|
|
||||||
return getpass.getpass('')
|
|
||||||
|
|
||||||
def get_pin(self, msg):
|
|
||||||
t = { 'a':'7', 'b':'8', 'c':'9', 'd':'4', 'e':'5', 'f':'6', 'g':'1', 'h':'2', 'i':'3'}
|
|
||||||
print_msg(msg)
|
|
||||||
print_msg("a b c\nd e f\ng h i\n-----")
|
|
||||||
o = raw_input()
|
|
||||||
return ''.join(map(lambda x: t[x], o))
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def show_message(self, msg):
|
|
||||||
print_msg(msg)
|
|
||||||
|
|
||||||
|
|
||||||
class Plugin(TrezorPlugin):
|
class Plugin(TrezorPlugin):
|
||||||
handler = TrezorCmdLineHandler()
|
handler = CmdLineHandler()
|
||||||
|
@hook
|
||||||
|
def init_keystore(self, keystore):
|
||||||
|
if not isinstance(keystore, self.keystore_class):
|
||||||
|
return
|
||||||
|
keystore.handler = self.handler
|
||||||
|
|||||||
@@ -132,8 +132,6 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
|||||||
return client
|
return client
|
||||||
|
|
||||||
def get_client(self, keystore, force_pair=True):
|
def get_client(self, keystore, force_pair=True):
|
||||||
# All client interaction should not be in the main GUI thread
|
|
||||||
assert self.main_thread != threading.current_thread()
|
|
||||||
devmgr = self.device_manager()
|
devmgr = self.device_manager()
|
||||||
handler = keystore.handler
|
handler = keystore.handler
|
||||||
with devmgr.hid_lock:
|
with devmgr.hid_lock:
|
||||||
|
|||||||
Reference in New Issue
Block a user