Add a restore command and device class restore method to devices

This commit is contained in:
Andrew Chow 2018-12-29 00:10:46 -05:00
parent 67236e926f
commit 22fff28b1e
7 changed files with 38 additions and 0 deletions

View File

@ -214,6 +214,16 @@ def wipe_device(args, client):
except UnavailableActionError as e:
return {'error': str(e), 'code': UNAVAILABLE_ACTION}
def restore_device(args, client):
try:
return client.restore_device(args.label)
except UnavailableActionError as e:
return {'error': str(e), 'code': UNAVAILABLE_ACTION}
except DeviceAlreadyInitError as e:
return {'error': str(e), 'code': DEVICE_ALREADY_INIT}
except ValueError as e:
return {'error': str(e), 'code': BAD_ARGUMENT}
def process_commands(args):
parser = argparse.ArgumentParser(description='Access and send commands to a hardware wallet device. Responses are in JSON format')
parser.add_argument('--device-path', '-d', help='Specify the device path of the device to connect to')
@ -272,6 +282,10 @@ def process_commands(args):
wipedev_parser = subparsers.add_parser('wipe', help='Wipe a device')
wipedev_parser.set_defaults(func=wipe_device)
restore_parser = subparsers.add_parser('restore', help='Initiate the device restoring process')
restore_parser.add_argument('--label', '-l', help='The name to give to the device', default='')
restore_parser.set_defaults(func=restore_device)
args = parser.parse_args(args)
device_path = args.device_path

View File

@ -108,6 +108,10 @@ class ColdcardClient(HardwareWalletClient):
def wipe_device(self):
raise NotImplementedError('The Coldcard does not currently implement wipe')
# Restore device from mnemonic or xprv
def restore_device(self, label=''):
raise NotImplementedError('The Coldcard does not implement device restoring')
# Close the device
def close(self):
self.device.close()

View File

@ -362,6 +362,10 @@ class DigitalbitboxClient(HardwareWalletClient):
def wipe_device(self):
raise NotImplementedError('The DigitalBitbox does not currently implement wipe')
# Restore device from mnemonic or xprv
def restore_device(self, label=''):
raise NotImplementedError('The Digital Bitbox does not implement device restoring')
# Close the device
def close(self):
self.device.close()

View File

@ -187,6 +187,10 @@ class KeepkeyClient(HardwareWalletClient):
def wipe_device(self):
raise NotImplementedError('The KeepKey does not currently implement wipe')
# Restore device from mnemonic or xprv
def restore_device(self, label=''):
raise NotImplementedError('The Keepkey does not implement device restoring')
# Close the device
def close(self):
self.client.close()

View File

@ -255,6 +255,10 @@ class LedgerClient(HardwareWalletClient):
def wipe_device(self):
raise NotImplementedError('The Ledger Nano S does not support wiping via software')
# Restore device from mnemonic or xprv
def restore_device(self, label=''):
raise NotImplementedError('The Ledger Nano S does not implement device restoring')
# Close the device
def close(self):
self.dongle.close()

View File

@ -198,6 +198,10 @@ class TrezorClient(HardwareWalletClient):
def wipe_device(self):
raise NotImplementedError('The Trezor does not currently implement wipe')
# Restore device from mnemonic or xprv
def restore_device(self, label=''):
raise NotImplementedError('The Trezor does not implement device restoring')
# Close the device
def close(self):
self.client.close()

View File

@ -41,6 +41,10 @@ class HardwareWalletClient(object):
raise NotImplementedError('The HardwareWalletClient base class does not '
'implement this method')
# Restore device from mnemonic or xprv
def restore_device(self, label=''):
raise NotImplementedError('The HardwareWalletClient base class does not implement this method')
# Close the device
def close(self):
raise NotImplementedError('The HardwareWalletClient base class does not '