Skip to content

Commit 82cbdce

Browse files
committed
Add getfeatures command and dummy hwwclient.get_features
1 parent 207977e commit 82cbdce

File tree

6 files changed

+42
-1
lines changed

6 files changed

+42
-1
lines changed

hwilib/cli.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#! /usr/bin/env python3
22

33
from .commands import backup_device, displayaddress, enumerate, find_device, \
4-
get_client, getmasterxpub, getxpub, getkeypool, getdescriptors, prompt_pin, restore_device, send_pin, setup_device, \
4+
get_client_class, get_client, getmasterxpub, getxpub, getkeypool, getdescriptors, prompt_pin, restore_device, send_pin, setup_device, \
55
signmessage, signtx, wipe_device, install_udev_rules
66
from .errors import (
77
handle_errors,
8+
BAD_ARGUMENT,
89
DEVICE_CONN_ERROR,
910
HELP_TEXT,
1011
MISSING_ARGUMENTS,
@@ -68,6 +69,10 @@ def send_pin_handler(args, client):
6869
def install_udev_rules_handler(args):
6970
return install_udev_rules('udev', args.location)
7071

72+
def getfeatures_handler(args):
73+
client_class = get_client_class(args.device_type)
74+
return client_class.get_features()
75+
7176
class HWIHelpFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter):
7277
pass
7378

@@ -180,6 +185,9 @@ def process_commands(cli_args):
180185
sendpin_parser.add_argument('pin', help='The numeric positions of the PIN')
181186
sendpin_parser.set_defaults(func=send_pin_handler)
182187

188+
getfeatures_parser = subparsers.add_parser('getfeatures', help='Returns the supported features for the given device type')
189+
getfeatures_parser.set_defaults(func=getfeatures_handler)
190+
183191
if sys.platform.startswith("linux"):
184192
udevrules_parser = subparsers.add_parser('installudevrules', help='Install and load the udev rule files for the hardware wallet devices')
185193
udevrules_parser.add_argument('--location', help='The path where the udev rules files will be copied', default='/etc/udev/rules.d/')
@@ -226,6 +234,14 @@ def process_commands(cli_args):
226234
result = args.func(args)
227235
return result
228236

237+
# Do get features
238+
if command == 'getfeatures':
239+
if not args.device_type:
240+
return {'error': 'Device type needs to be specified to get features', 'code': BAD_ARGUMENT}
241+
with handle_errors(result=result, debug=args.debug):
242+
result = args.func(args)
243+
return result
244+
229245
# Auto detect if we are using fingerprint or type to identify device
230246
if args.fingerprint or (args.device_type and not args.device_path):
231247
client = find_device(args.device_path, args.password, args.device_type, args.fingerprint)

hwilib/devices/coldcard.py

+5
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ def prompt_pin(self):
217217
def send_pin(self, pin):
218218
raise UnavailableActionError('The Coldcard does not need a PIN sent from the host')
219219

220+
# Get HWI features for this device
221+
@classmethod
222+
def get_features(self):
223+
raise NotImplementedError('The Coldcard does not implement this method')
224+
220225
def enumerate(password=''):
221226
results = []
222227
for d in hid.enumerate(COINKITE_VID, CKCC_PID):

hwilib/devices/digitalbitbox.py

+5
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,11 @@ def prompt_pin(self):
578578
def send_pin(self, pin):
579579
raise UnavailableActionError('The Digital Bitbox does not need a PIN sent from the host')
580580

581+
# Get HWI features for this device
582+
@classmethod
583+
def get_features(self):
584+
raise NotImplementedError('The Digital Bitbox does not implement this method')
585+
581586
class Digitalbitbox01Client(DigitalbitboxClient):
582587
def __init__(self, path, password=''):
583588
super(Digitalbitbox01Client, self).__init__(path, password)

hwilib/devices/ledger.py

+5
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ def prompt_pin(self):
348348
def send_pin(self, pin):
349349
raise UnavailableActionError('The {} does not need a PIN sent from the host'.format(self.type))
350350

351+
# Get HWI features for this device
352+
@classmethod
353+
def get_features(self):
354+
raise NotImplementedError('The Ledger Nano S and X does not implement this method')
355+
351356
class LedgerNanoSClient(LedgerClient):
352357
def __init__(self, path, password=''):
353358
super(LedgerNanoSClient, self).__init__(path, password)

hwilib/devices/trezor.py

+5
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,11 @@ def send_pin(self, pin):
423423
return {'success': False}
424424
return {'success': True}
425425

426+
# Get HWI features for this device
427+
@classmethod
428+
def get_features(self):
429+
raise NotImplementedError('The {} does not implement this method'.format(self.type))
430+
426431
class Trezor1Client(TrezorClient):
427432
def __init__(self, path, password=''):
428433
super(Trezor1Client, self).__init__(path, password)

hwilib/hwwclient.py

+5
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,8 @@ def prompt_pin(self):
6363
# Send pin
6464
def send_pin(self):
6565
raise NotImplementedError('The HardwareWalletClient base class does not implement this method')
66+
67+
# Get HWI features for this device
68+
@classmethod
69+
def get_features(self):
70+
raise NotImplementedError('The HardwareWalletClient base class does not implement this method')

0 commit comments

Comments
 (0)