Skip to content

Commit fd41626

Browse files
committed
Add getfeatures command and dummy hwwclient.get_features
1 parent 9d3b8bd commit fd41626

File tree

6 files changed

+42
-1
lines changed

6 files changed

+42
-1
lines changed

hwilib/cli.py

Lines changed: 17 additions & 1 deletion
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

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

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

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

hwilib/devices/coldcard.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ def prompt_pin(self):
242242
def send_pin(self, pin):
243243
raise UnavailableActionError('The Coldcard does not need a PIN sent from the host')
244244

245+
# Get HWI features for this device
246+
@classmethod
247+
def get_features(self):
248+
raise NotImplementedError('The Coldcard does not implement this method')
249+
245250
def enumerate(password=''):
246251
results = []
247252
devices = hid.enumerate(COINKITE_VID, CKCC_PID)

hwilib/devices/digitalbitbox.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,11 @@ def prompt_pin(self):
583583
def send_pin(self, pin):
584584
raise UnavailableActionError('The Digital Bitbox does not need a PIN sent from the host')
585585

586+
# Get HWI features for this device
587+
@classmethod
588+
def get_features(self):
589+
raise NotImplementedError('The Digital Bitbox does not implement this method')
590+
586591
class Digitalbitbox01Client(DigitalbitboxClient):
587592
def __init__(self, path, password='', expert=False):
588593
super(Digitalbitbox01Client, self).__init__(path, password, expert)

hwilib/devices/ledger.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ def prompt_pin(self):
355355
def send_pin(self, pin):
356356
raise UnavailableActionError('The {} does not need a PIN sent from the host'.format(self.type))
357357

358+
# Get HWI features for this device
359+
@classmethod
360+
def get_features(self):
361+
raise NotImplementedError('The Ledger Nano S and X does not implement this method')
362+
358363
class LedgerNanoSClient(LedgerClient):
359364
def __init__(self, path, password='', expert=False):
360365
super(LedgerNanoSClient, self).__init__(path, password, expert)

hwilib/devices/trezor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ def send_pin(self, pin):
434434
return {'success': False}
435435
return {'success': True}
436436

437+
# Get HWI features for this device
438+
@classmethod
439+
def get_features(self):
440+
raise NotImplementedError('The {} does not implement this method'.format(self.type))
441+
437442
class Trezor1Client(TrezorClient):
438443
def __init__(self, path, password='', expert=False):
439444
super(Trezor1Client, self).__init__(path, password, expert)

hwilib/hwwclient.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,8 @@ def prompt_pin(self):
6464
# Send pin
6565
def send_pin(self):
6666
raise NotImplementedError('The HardwareWalletClient base class does not implement this method')
67+
68+
# Get HWI features for this device
69+
@classmethod
70+
def get_features(self):
71+
raise NotImplementedError('The HardwareWalletClient base class does not implement this method')

0 commit comments

Comments
 (0)