Skip to content

Commit

Permalink
Implement get_features for all clients.
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Jan 22, 2021
1 parent 4014273 commit 44140ee
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 8 deletions.
31 changes: 29 additions & 2 deletions hwilib/devices/coldcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from typing import Dict, Union

from ..hwwclient import HardwareWalletClient
from ..hwwclient import (
DeviceFeature,
HardwareWalletClient,
SupportedFeatures,
)
from ..errors import (
ActionCanceledError,
BadArgumentError,
Expand Down Expand Up @@ -94,6 +98,29 @@ def func(*args, **kwargs):
# This class extends the HardwareWalletClient for ColdCard specific things
class ColdcardClient(HardwareWalletClient):

# Setup features
features = SupportedFeatures()
features.getxpub = DeviceFeature.SUPPORTED
features.signmessage = DeviceFeature.SUPPORTED
features.setup = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.wipe = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.recover = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.backup = DeviceFeature.SUPPORTED
features.sign_p2pkh = DeviceFeature.SUPPORTED
features.sign_p2sh_p2wpkh = DeviceFeature.SUPPORTED
features.sign_p2wpkh = DeviceFeature.SUPPORTED
features.sign_multi_p2sh = DeviceFeature.SUPPORTED
features.sign_multi_p2sh_p2wsh = DeviceFeature.SUPPORTED
features.sign_multi_p2wsh = DeviceFeature.SUPPORTED
features.sign_multi_bare = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_bare = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_p2sh = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_p2sh_p2wsh = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_p2wsh = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_coinjoin = DeviceFeature.SUPPORTED
features.sign_mixed_segwit = DeviceFeature.SUPPORTED
features.display_address = DeviceFeature.SUPPORTED

def __init__(self, path, password='', expert=False):
super(ColdcardClient, self).__init__(path, password, expert)
# Simulator hard coded pipe socket
Expand Down Expand Up @@ -343,7 +370,7 @@ def toggle_passphrase(self):
# Get HWI features for this device
@classmethod
def get_features(self):
raise NotImplementedError('The Coldcard does not implement this method')
return self.features.get_printable_dict()

def enumerate(password=''):
results = []
Expand Down
31 changes: 29 additions & 2 deletions hwilib/devices/digitalbitbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
import time
from typing import Dict, Union

from ..hwwclient import HardwareWalletClient
from ..hwwclient import (
DeviceFeature,
HardwareWalletClient,
SupportedFeatures,
)
from ..errors import (
ActionCanceledError,
BadArgumentError,
Expand Down Expand Up @@ -326,6 +330,29 @@ def format_backup_filename(name):
# This class extends the HardwareWalletClient for Digital Bitbox specific things
class DigitalbitboxClient(HardwareWalletClient):

# Setup features
features = SupportedFeatures()
features.getxpub = DeviceFeature.SUPPORTED
features.signmessage = DeviceFeature.SUPPORTED
features.setup = DeviceFeature.SUPPORTED
features.wipe = DeviceFeature.SUPPORTED
features.recover = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.backup = DeviceFeature.SUPPORTED
features.sign_p2pkh = DeviceFeature.SUPPORTED
features.sign_p2sh_p2wpkh = DeviceFeature.SUPPORTED
features.sign_p2wpkh = DeviceFeature.SUPPORTED
features.sign_multi_p2sh = DeviceFeature.SUPPORTED
features.sign_multi_p2sh_p2wsh = DeviceFeature.SUPPORTED
features.sign_multi_p2wsh = DeviceFeature.SUPPORTED
features.sign_multi_bare = DeviceFeature.SUPPORTED
features.sign_arbitrary_bare = DeviceFeature.SUPPORTED
features.sign_arbitrary_p2sh = DeviceFeature.SUPPORTED
features.sign_arbitrary_p2sh_p2wsh = DeviceFeature.SUPPORTED
features.sign_arbitrary_p2wsh = DeviceFeature.SUPPORTED
features.sign_coinjoin = DeviceFeature.SUPPORTED
features.sign_mixed_segwit = DeviceFeature.SUPPORTED
features.display_address = DeviceFeature.FIRMWARE_NOT_SUPPORTED

def __init__(self, path, password, expert=False):
super(DigitalbitboxClient, self).__init__(path, password, expert)
if not password:
Expand Down Expand Up @@ -620,7 +647,7 @@ def toggle_passphrase(self):
# Get HWI features for this device
@classmethod
def get_features(self):
raise NotImplementedError('The Digital Bitbox does not implement this method')
return self.features.get_printable_dict()

class Digitalbitbox01Client(DigitalbitboxClient):
def __init__(self, path, password='', expert=False):
Expand Down
32 changes: 32 additions & 0 deletions hwilib/devices/keepkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
common_err_msgs,
handle_errors,
)
from ..hwwclient import (
DeviceFeature,
SupportedFeatures,
)
from .trezorlib.transport import (
enumerate_devices,
KEEPKEY_VENDOR_IDS,
Expand All @@ -15,10 +19,38 @@
py_enumerate = enumerate # Need to use the enumerate built-in but there's another function already named that

class KeepkeyClient(TrezorClient):

# Setup features
features = SupportedFeatures()
features.getxpub = DeviceFeature.SUPPORTED
features.signmessage = DeviceFeature.SUPPORTED
features.setup = DeviceFeature.SUPPORTED
features.wipe = DeviceFeature.SUPPORTED
features.recover = DeviceFeature.SUPPORTED
features.backup = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_p2pkh = DeviceFeature.SUPPORTED
features.sign_p2sh_p2wpkh = DeviceFeature.SUPPORTED
features.sign_p2wpkh = DeviceFeature.SUPPORTED
features.sign_multi_p2sh = DeviceFeature.SUPPORTED
features.sign_multi_p2sh_p2wsh = DeviceFeature.SUPPORTED
features.sign_multi_p2wsh = DeviceFeature.SUPPORTED
features.sign_multi_bare = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_bare = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_p2sh = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_p2sh_p2wsh = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_p2wsh = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_coinjoin = DeviceFeature.SUPPORTED
features.sign_mixed_segwit = DeviceFeature.SUPPORTED
features.display_address = DeviceFeature.SUPPORTED

def __init__(self, path, password='', expert=False):
super(KeepkeyClient, self).__init__(path, password, expert)
self.type = 'Keepkey'

@classmethod
def get_features(self):
return self.features.get_printable_dict()

def enumerate(password=''):
results = []
for dev in enumerate_devices():
Expand Down
31 changes: 29 additions & 2 deletions hwilib/devices/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from typing import Dict, Union

from ..hwwclient import HardwareWalletClient
from ..hwwclient import (
DeviceFeature,
HardwareWalletClient,
SupportedFeatures,
)
from ..errors import (
ActionCanceledError,
BadArgumentError,
Expand Down Expand Up @@ -100,6 +104,29 @@ def func(*args, **kwargs):
# This class extends the HardwareWalletClient for Ledger Nano S and Nano X specific things
class LedgerClient(HardwareWalletClient):

# Setup features
features = SupportedFeatures()
features.getxpub = DeviceFeature.SUPPORTED
features.signmessage = DeviceFeature.SUPPORTED
features.setup = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.wipe = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.recover = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.backup = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_p2pkh = DeviceFeature.SUPPORTED
features.sign_p2sh_p2wpkh = DeviceFeature.SUPPORTED
features.sign_p2wpkh = DeviceFeature.SUPPORTED
features.sign_multi_p2sh = DeviceFeature.SUPPORTED
features.sign_multi_p2sh_p2wsh = DeviceFeature.SUPPORTED
features.sign_multi_p2wsh = DeviceFeature.SUPPORTED
features.sign_multi_bare = DeviceFeature.SUPPORTED
features.sign_arbitrary_bare = DeviceFeature.SUPPORTED
features.sign_arbitrary_p2sh = DeviceFeature.SUPPORTED
features.sign_arbitrary_p2sh_p2wsh = DeviceFeature.SUPPORTED
features.sign_arbitrary_p2wsh = DeviceFeature.SUPPORTED
features.sign_coinjoin = DeviceFeature.SUPPORTED
features.sign_mixed_segwit = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.display_address = DeviceFeature.SUPPORTED

def __init__(self, path, password='', expert=False):
super(LedgerClient, self).__init__(path, password, expert)
self.type = 'Ledger Nano S and X'
Expand Down Expand Up @@ -390,7 +417,7 @@ def toggle_passphrase(self):
# Get HWI features for this device
@classmethod
def get_features(self):
raise NotImplementedError('The Ledger Nano S and X does not implement this method')
return self.features.get_printable_dict()

class LedgerNanoSClient(LedgerClient):
def __init__(self, path, password='', expert=False):
Expand Down
64 changes: 62 additions & 2 deletions hwilib/devices/trezor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from typing import Dict, Union

from ..hwwclient import HardwareWalletClient
from ..hwwclient import (
DeviceFeature,
HardwareWalletClient,
SupportedFeatures,
)
from ..errors import (
ActionCanceledError,
BadArgumentError,
Expand Down Expand Up @@ -554,18 +558,74 @@ def toggle_passphrase(self):
# Get HWI features for this device
@classmethod
def get_features(self):
raise NotImplementedError('The {} does not implement this method'.format(self.type))
raise UnavailableActionError('A specific Trezor model must be specified to get the features')

class Trezor1Client(TrezorClient):

# Setup features
features = SupportedFeatures()
features.getxpub = DeviceFeature.SUPPORTED
features.signmessage = DeviceFeature.SUPPORTED
features.setup = DeviceFeature.SUPPORTED
features.wipe = DeviceFeature.SUPPORTED
features.recover = DeviceFeature.SUPPORTED
features.backup = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_p2pkh = DeviceFeature.SUPPORTED
features.sign_p2sh_p2wpkh = DeviceFeature.SUPPORTED
features.sign_p2wpkh = DeviceFeature.SUPPORTED
features.sign_multi_p2sh = DeviceFeature.SUPPORTED
features.sign_multi_p2sh_p2wsh = DeviceFeature.SUPPORTED
features.sign_multi_p2wsh = DeviceFeature.SUPPORTED
features.sign_multi_bare = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_bare = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_p2sh = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_p2sh_p2wsh = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_p2wsh = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_coinjoin = DeviceFeature.SUPPORTED
features.sign_mixed_segwit = DeviceFeature.SUPPORTED
features.display_address = DeviceFeature.SUPPORTED

def __init__(self, path, password='', expert=False):
super(Trezor1Client, self).__init__(path, password, expert)
self.type = 'Trezor 1'

@classmethod
def get_features(self):
return self.features.get_printable_dict()

class TrezorTClient(TrezorClient):

# Setup features
features = SupportedFeatures()
features.getxpub = DeviceFeature.SUPPORTED
features.signmessage = DeviceFeature.SUPPORTED
features.setup = DeviceFeature.SUPPORTED
features.wipe = DeviceFeature.SUPPORTED
features.recover = DeviceFeature.SUPPORTED
features.backup = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_p2pkh = DeviceFeature.SUPPORTED
features.sign_p2sh_p2wpkh = DeviceFeature.SUPPORTED
features.sign_p2wpkh = DeviceFeature.SUPPORTED
features.sign_multi_p2sh = DeviceFeature.SUPPORTED
features.sign_multi_p2sh_p2wsh = DeviceFeature.SUPPORTED
features.sign_multi_p2wsh = DeviceFeature.SUPPORTED
features.sign_multi_bare = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_bare = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_p2sh = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_p2sh_p2wsh = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_arbitrary_p2wsh = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.sign_coinjoin = DeviceFeature.SUPPORTED
features.sign_mixed_segwit = DeviceFeature.FIRMWARE_NOT_SUPPORTED
features.display_address = DeviceFeature.SUPPORTED

def __init__(self, path, password='', expert=False):
super(TrezorTClient, self).__init__(path, password, expert)
self.type = 'Trezor T'

@classmethod
def get_features(self):
return self.features.get_printable_dict()

def enumerate(password=''):
results = []
for dev in enumerate_devices():
Expand Down

0 comments on commit 44140ee

Please sign in to comment.