From 129e91d9f0698a35e36211579e10a44db3541c4e Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 21 May 2019 17:19:56 -0400 Subject: [PATCH] Provide error codes in enumerate output --- hwilib/devices/coldcard.py | 6 +++++- hwilib/devices/digitalbitbox.py | 6 +++++- hwilib/devices/keepkey.py | 5 +++++ hwilib/devices/ledger.py | 6 +++++- hwilib/devices/trezor.py | 6 +++++- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/hwilib/devices/coldcard.py b/hwilib/devices/coldcard.py index 6fe8912..91689a4 100644 --- a/hwilib/devices/coldcard.py +++ b/hwilib/devices/coldcard.py @@ -1,7 +1,7 @@ # Coldcard interaction script from ..hwwclient import HardwareWalletClient -from ..errors import ActionCanceledError, BadArgumentError, DeviceBusyError, UnavailableActionError, DeviceFailureError +from ..errors import ActionCanceledError, BadArgumentError, DeviceBusyError, DeviceFailureError, HWWError, UnavailableActionError, UNKNOWN_ERROR from .ckcc.client import ColdcardDevice, COINKITE_VID, CKCC_PID from .ckcc.protocol import CCProtocolPacker, CCBusyError, CCProtoError, CCUserRefused from .ckcc.constants import MAX_BLK_LEN, AF_P2WPKH, AF_CLASSIC, AF_P2WPKH_P2SH @@ -230,8 +230,12 @@ def enumerate(password=''): try: client = ColdcardClient(path) d_data['fingerprint'] = client._get_fingerprint_hex() + except HWWError as e: + d_data['error'] = "Could not open client or get fingerprint information: " + e.get_msg() + d_data['code'] = e.get_code() except Exception as e: d_data['error'] = "Could not open client or get fingerprint information: " + str(e) + d_data['code'] = UNKNOWN_ERROR if client: client.close() diff --git a/hwilib/devices/digitalbitbox.py b/hwilib/devices/digitalbitbox.py index 16c6305..1ef0dbb 100644 --- a/hwilib/devices/digitalbitbox.py +++ b/hwilib/devices/digitalbitbox.py @@ -15,7 +15,7 @@ import sys import time from ..hwwclient import HardwareWalletClient -from ..errors import ActionCanceledError, BadArgumentError, DeviceFailureError, DeviceAlreadyInitError, DeviceNotReadyError, NoPasswordError, UnavailableActionError, DeviceFailureError +from ..errors import ActionCanceledError, BadArgumentError, DeviceFailureError, DeviceAlreadyInitError, DeviceNotReadyError, HWWError, NoPasswordError, UnavailableActionError, UNKNOWN_ERROR from ..serializations import CTransaction, PSBT, hash256, hash160, ser_sig_der, ser_sig_compact, ser_compact_size from ..base58 import get_xpub_fingerprint, decode, to_address, xpub_main_2_test, get_xpub_fingerprint_hex @@ -603,8 +603,12 @@ def enumerate(password=''): else: master_xpub = client.get_pubkey_at_path('m/0h')['xpub'] d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub) + except HWWError as e: + d_data['error'] = "Could not open client or get fingerprint information: " + e.get_msg() + d_data['code'] = e.get_code() except Exception as e: d_data['error'] = "Could not open client or get fingerprint information: " + str(e) + d_data['code'] = UNKNOWN_ERROR if client: client.close() diff --git a/hwilib/devices/keepkey.py b/hwilib/devices/keepkey.py index 6adf7fb..463fe95 100644 --- a/hwilib/devices/keepkey.py +++ b/hwilib/devices/keepkey.py @@ -1,5 +1,6 @@ # KeepKey interaction script +from ..errors import HWWError, UNKNOWN_ERROR from .trezorlib.transport import enumerate_devices from .trezor import TrezorClient from ..base58 import get_xpub_fingerprint_hex @@ -30,8 +31,12 @@ def enumerate(password=''): d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub) else: d_data['error'] = 'Not initialized' + except HWWError as e: + d_data['error'] = "Could not open client or get fingerprint information: " + e.get_msg() + d_data['code'] = e.get_code() except Exception as e: d_data['error'] = "Could not open client or get fingerprint information: " + str(e) + d_data['code'] = UNKNOWN_ERROR if client: client.close() diff --git a/hwilib/devices/ledger.py b/hwilib/devices/ledger.py index 5b4f689..8c2151f 100644 --- a/hwilib/devices/ledger.py +++ b/hwilib/devices/ledger.py @@ -1,7 +1,7 @@ # Ledger interaction script from ..hwwclient import HardwareWalletClient -from ..errors import ActionCanceledError, BadArgumentError, DeviceConnectionError, DeviceFailureError, UnavailableActionError +from ..errors import ActionCanceledError, BadArgumentError, DeviceConnectionError, DeviceFailureError, HWWError, UnavailableActionError, UNKNOWN_ERROR from .btchip.btchip import * from .btchip.btchipUtils import * import base64 @@ -350,8 +350,12 @@ def enumerate(password=''): client = LedgerClient(path, password) master_xpub = client.get_pubkey_at_path('m/0h')['xpub'] d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub) + except HWWError as e: + d_data['error'] = "Could not open client or get fingerprint information: " + e.get_msg() + d_data['code'] = e.get_code() except Exception as e: d_data['error'] = "Could not open client or get fingerprint information: " + str(e) + d_data['code'] = UNKNOWN_ERROR if client: client.close() diff --git a/hwilib/devices/trezor.py b/hwilib/devices/trezor.py index 780e4e0..025249f 100644 --- a/hwilib/devices/trezor.py +++ b/hwilib/devices/trezor.py @@ -1,7 +1,7 @@ # Trezor interaction script from ..hwwclient import HardwareWalletClient -from ..errors import ActionCanceledError, BadArgumentError, DeviceAlreadyInitError, DeviceAlreadyUnlockedError, DeviceConnectionError, UnavailableActionError, DeviceNotReadyError +from ..errors import ActionCanceledError, BadArgumentError, DeviceAlreadyInitError, DeviceAlreadyUnlockedError, DeviceConnectionError, DeviceNotReadyError, HWWError, UnavailableActionError, UNKNOWN_ERROR from .trezorlib.client import TrezorClient as Trezor from .trezorlib.debuglink import TrezorClientDebugLink, DebugUI from .trezorlib.exceptions import Cancelled @@ -426,8 +426,12 @@ def enumerate(password=''): d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub) else: d_data['error'] = 'Not initialized' + except HWWError as e: + d_data['error'] = "Could not open client or get fingerprint information: " + e.get_msg() + d_data['code'] = e.get_code() except Exception as e: d_data['error'] = "Could not open client or get fingerprint information: " + str(e) + d_data['code'] = UNKNOWN_ERROR if client: client.close()