Skip to content

Commit 8affeb3

Browse files
committed
Add getfeatures command and dummy hwwclient.get_features
1 parent bacd32d commit 8affeb3

File tree

6 files changed

+62
-3
lines changed

6 files changed

+62
-3
lines changed

hwilib/cli.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
#! /usr/bin/env python3
22

3-
from .commands import backup_device, displayaddress, enumerate, find_device, \
4-
get_client, getmasterxpub, getxpub, getkeypool, getdescriptors, prompt_pin, toggle_passphrase, restore_device, send_pin, setup_device, \
5-
signmessage, signtx, wipe_device, install_udev_rules
3+
from .commands import (
4+
backup_device,
5+
displayaddress,
6+
enumerate,
7+
find_device,
8+
get_client_class,
9+
get_client,
10+
getmasterxpub,
11+
getxpub,
12+
getkeypool,
13+
getdescriptors,
14+
prompt_pin,
15+
toggle_passphrase,
16+
restore_device,
17+
send_pin,
18+
setup_device,
19+
signmessage,
20+
signtx,
21+
wipe_device,
22+
install_udev_rules,
23+
)
624
from .errors import (
725
handle_errors,
26+
BAD_ARGUMENT,
827
DEVICE_CONN_ERROR,
928
HELP_TEXT,
1029
MISSING_ARGUMENTS,
@@ -71,6 +90,10 @@ def send_pin_handler(args, client):
7190
def install_udev_rules_handler(args):
7291
return install_udev_rules('udev', args.location)
7392

93+
def getfeatures_handler(args):
94+
client_class = get_client_class(args.device_type)
95+
return client_class.get_features()
96+
7497
class HWIHelpFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter):
7598
pass
7699

@@ -188,6 +211,9 @@ def process_commands(cli_args):
188211
sendpin_parser.add_argument('pin', help='The numeric positions of the PIN')
189212
sendpin_parser.set_defaults(func=send_pin_handler)
190213

214+
getfeatures_parser = subparsers.add_parser('getfeatures', help='Returns the supported features for the given device type')
215+
getfeatures_parser.set_defaults(func=getfeatures_handler)
216+
191217
if sys.platform.startswith("linux"):
192218
udevrules_parser = subparsers.add_parser('installudevrules', help='Install and load the udev rule files for the hardware wallet devices')
193219
udevrules_parser.add_argument('--location', help='The path where the udev rules files will be copied', default='/etc/udev/rules.d/')
@@ -234,6 +260,14 @@ def process_commands(cli_args):
234260
result = args.func(args)
235261
return result
236262

263+
# Do get features
264+
if command == 'getfeatures':
265+
if not args.device_type:
266+
return {'error': 'Device type needs to be specified to get features', 'code': BAD_ARGUMENT}
267+
with handle_errors(result=result, debug=args.debug):
268+
result = args.func(args)
269+
return result
270+
237271
# Auto detect if we are using fingerprint or type to identify device
238272
if args.fingerprint or (args.device_type and not args.device_path):
239273
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
@@ -246,6 +246,11 @@ def send_pin(self, pin):
246246
def toggle_passphrase(self):
247247
raise UnavailableActionError('The Coldcard does not support toggling passphrase from the host')
248248

249+
# Get HWI features for this device
250+
@classmethod
251+
def get_features(self):
252+
raise NotImplementedError('The Coldcard does not implement this method')
253+
249254
def enumerate(password=''):
250255
results = []
251256
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
@@ -587,6 +587,11 @@ def send_pin(self, pin):
587587
def toggle_passphrase(self):
588588
raise UnavailableActionError('The Digital Bitbox does not support toggling passphrase from the host')
589589

590+
# Get HWI features for this device
591+
@classmethod
592+
def get_features(self):
593+
raise NotImplementedError('The Digital Bitbox does not implement this method')
594+
590595
class Digitalbitbox01Client(DigitalbitboxClient):
591596
def __init__(self, path, password='', expert=False):
592597
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
@@ -358,6 +358,11 @@ def send_pin(self, pin):
358358
def toggle_passphrase(self):
359359
raise UnavailableActionError('The Ledger Nano S and X do not support toggling passphrase from the host')
360360

361+
# Get HWI features for this device
362+
@classmethod
363+
def get_features(self):
364+
raise NotImplementedError('The Ledger Nano S and X does not implement this method')
365+
361366
class LedgerNanoSClient(LedgerClient):
362367
def __init__(self, path, password='', expert=False):
363368
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
@@ -440,6 +440,11 @@ def toggle_passphrase(self):
440440
self._check_unlocked()
441441
return device.apply_settings(self.client, use_passphrase=not self.client.features.passphrase_protection)
442442

443+
# Get HWI features for this device
444+
@classmethod
445+
def get_features(self):
446+
raise NotImplementedError('The {} does not implement this method'.format(self.type))
447+
443448
class Trezor1Client(TrezorClient):
444449
def __init__(self, path, password='', expert=False):
445450
super(Trezor1Client, self).__init__(path, password, expert)

hwilib/hwwclient.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,8 @@ def send_pin(self):
7575
# Toggle passphrase
7676
def toggle_passphrase(self):
7777
raise NotImplementedError('The HardwareWalletClient base class does not implement this method')
78+
79+
# Get HWI features for this device
80+
@classmethod
81+
def get_features(self):
82+
raise NotImplementedError('The HardwareWalletClient base class does not implement this method')

0 commit comments

Comments
 (0)