forked from bitcoin-core/HWI
/
keepkeyi.py
56 lines (46 loc) · 2 KB
/
keepkeyi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# KeepKey interaction script
from hwi import HardwareWalletClient
from keepkeylib.transport_hid import HidTransport
from keepkeylib.client import KeepKeyClient as KeepKey
import binascii
# This class extends the HardwareWalletClient for Digital Bitbox specific things
class KeepKeyClient(HardwareWalletClient):
# device is an HID device that has already been opened.
def __init__(self, device, path):
super(KeepKeyClient, self).__init__(device)
device.close()
devices = HidTransport.enumerate()
self.client = None
for d in devices:
if d[0] == path:
transport = HidTransport(d)
self.client = KeepKey(transport)
break
# if it wasn't able to find a client, throw an error
if not self.client:
raise IOError("no Device")
# 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):
expanded_path = self.client.expand_path(path)
output = self.client.get_public_node(expanded_path)
print({'xpub':output.xpub})
return
# Must return a hex string with the signed transaction
# The tx must be in the combined unsigned transaction format
def sign_tx(self, tx):
raise NotImplementedError('The HardwareWalletClient base class does not '
'implement this method')
# Must return a base64 encoded string with the signed message
# The message can be any string
def sign_message(self, message):
raise NotImplementedError('The HardwareWalletClient base class does not '
'implement this method')
# Setup a new device
def setup_device(self):
raise NotImplementedError('The HardwareWalletClient base class does not '
'implement this method')
# Wipe this device
def wipe_device(self):
raise NotImplementedError('The HardwareWalletClient base class does not '
'implement this method')