Add promptpin and sendpin commands
This commit is contained in:
parent
bb88cc5e6f
commit
97b1d35637
@ -1,7 +1,7 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
from .commands import backup_device, displayaddress, enumerate, find_device, \
|
||||
get_client, getmasterxpub, getxpub, getkeypool, restore_device, setup_device, \
|
||||
get_client, getmasterxpub, getxpub, getkeypool, prompt_pin, restore_device, send_pin, setup_device, \
|
||||
signmessage, signtx, wipe_device, NO_DEVICE_PATH, DEVICE_CONN_ERROR, NO_PASSWORD, \
|
||||
UNKNWON_DEVICE_TYPE
|
||||
|
||||
@ -44,6 +44,12 @@ def signtx_handler(args, client):
|
||||
def wipe_device_handler(args, client):
|
||||
return wipe_device(client)
|
||||
|
||||
def prompt_pin_handler(args, client):
|
||||
return prompt_pin(client)
|
||||
|
||||
def send_pin_handler(args, client):
|
||||
return send_pin(client, pin=args.pin)
|
||||
|
||||
def process_commands(args):
|
||||
parser = argparse.ArgumentParser(description='Access and send commands to a hardware wallet device. Responses are in JSON format')
|
||||
parser.add_argument('--device-path', '-d', help='Specify the device path of the device to connect to')
|
||||
@ -111,6 +117,13 @@ def process_commands(args):
|
||||
backup_parser.add_argument('--backup_passphrase', '-b', help='The passphrase to use for the backup, if applicable', default='')
|
||||
backup_parser.set_defaults(func=backup_device_handler)
|
||||
|
||||
promptpin_parser = subparsers.add_parser('promptpin', help='Have the device prompt for your PIN')
|
||||
promptpin_parser.set_defaults(func=prompt_pin_handler)
|
||||
|
||||
sendpin_parser = subparsers.add_parser('sendpin', help='Send the numeric positions for your PIN to the device')
|
||||
sendpin_parser.add_argument('pin', help='The numeric positions of the PIN')
|
||||
sendpin_parser.set_defaults(func=send_pin_handler)
|
||||
|
||||
args = parser.parse_args(args)
|
||||
|
||||
device_path = args.device_path
|
||||
|
||||
@ -8,7 +8,7 @@ import importlib
|
||||
from .serializations import PSBT, Base64ToHex, HexToBase64, hash160
|
||||
from .base58 import xpub_to_address, xpub_to_pub_hex, get_xpub_fingerprint_as_id, get_xpub_fingerprint_hex
|
||||
from os.path import dirname, basename, isfile
|
||||
from .hwwclient import NoPasswordError, UnavailableActionError, DeviceAlreadyInitError
|
||||
from .hwwclient import NoPasswordError, UnavailableActionError, DeviceAlreadyInitError, DeviceAlreadyUnlockedError
|
||||
|
||||
# Error codes
|
||||
NO_DEVICE_PATH = -1
|
||||
@ -21,6 +21,7 @@ BAD_ARGUMENT = -7
|
||||
NOT_IMPLEMENTED = -8
|
||||
UNAVAILABLE_ACTION = -9
|
||||
DEVICE_ALREADY_INIT = -10
|
||||
DEVICE_ALREADY_UNLOCKED = -11
|
||||
|
||||
class UnknownDeviceError(Exception):
|
||||
def __init__(self,*args,**kwargs):
|
||||
@ -220,3 +221,17 @@ def backup_device(client, label='', backup_passphrase=''):
|
||||
return {'error': str(e), 'code': UNAVAILABLE_ACTION}
|
||||
except ValueError as e:
|
||||
return {'error': str(e), 'code': BAD_ARGUMENT}
|
||||
|
||||
def prompt_pin(client):
|
||||
try:
|
||||
return client.prompt_pin()
|
||||
except DeviceAlreadyUnlockedError as e:
|
||||
return {'error': str(e), 'code': DEVICE_ALREADY_UNLOCKED}
|
||||
|
||||
def send_pin(client, pin):
|
||||
try:
|
||||
return client.send_pin(pin)
|
||||
except DeviceAlreadyUnlockedError as e:
|
||||
return {'error': str(e), 'code': DEVICE_ALREADY_UNLOCKED}
|
||||
except ValueError as e:
|
||||
return {'error': str(e), 'code': BAD_ARGUMENT}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user