Implement setup, wipe, restore, and backup for Keepkey

Setup, wipe, and restore are supported, so implement those.

Backing up is not supported, so just raise an error for that
This commit is contained in:
Andrew Chow 2018-12-29 00:10:50 -05:00
parent cc3a6cae2d
commit 88349f2717

View File

@ -1,6 +1,6 @@
# KeepKey interaction script
from ..hwwclient import HardwareWalletClient
from ..hwwclient import HardwareWalletClient, UnavailableActionError
from keepkeylib.transport_hid import HidTransport
from keepkeylib.client import KeepKeyClient as KeepKey
from keepkeylib import tools
@ -11,6 +11,7 @@ from ..serializations import ser_uint256, uint256_from_str
import binascii
import json
import os
KEEPKEY_VENDOR_ID = 0x2B24
KEEPKEY_DEVICE_ID = 0x0001
@ -60,6 +61,9 @@ class KeepkeyClient(HardwareWalletClient):
if not self.client:
raise IOError("no Device")
self.password = password
os.environ['PASSPHRASE'] = password
# Must return a dict with the xpub
# Retrieves the public key at the specified BIP 32 derivation path
def get_pubkey_at_path(self, path):
@ -181,19 +185,24 @@ class KeepkeyClient(HardwareWalletClient):
# Setup a new device
def setup_device(self, label='', passphrase=''):
raise NotImplementedError('The KeepKey does not currently implement setup')
if self.client.features.initialized:
raise DeviceAlreadyInitError('Device is already initialized. Use wipe first and try again')
self.client.reset_device(False, 256, bool(self.password), True, label, 'english')
return {'success': True}
# Wipe this device
def wipe_device(self):
raise NotImplementedError('The KeepKey does not currently implement wipe')
self.client.wipe_device()
return {'success': True}
# Restore device from mnemonic or xprv
def restore_device(self, label=''):
raise NotImplementedError('The Keepkey does not implement device restoring')
self.client.recovery_device(False, 24, bool(self.password), True, label, 'english')
return {'success': True}
# Begin backup process
def backup_device(self, label='', passphrase=''):
raise NotImplementedError('The Keepkey does not implement this method')
raise UnavailableActionError('The Keepkey does not support creating a backup via software')
# Close the device
def close(self):