Updated TREZOR plugin to work with trezorlib>=0.9.0.
This commit is contained in:
@@ -28,9 +28,9 @@ class GuiMixin(object):
|
|||||||
# However, making the user acknowledge they cancelled
|
# However, making the user acknowledge they cancelled
|
||||||
# gets old very quickly, so we suppress those. The NotInitialized
|
# gets old very quickly, so we suppress those. The NotInitialized
|
||||||
# one is misnamed and indicates a passphrase request was cancelled.
|
# one is misnamed and indicates a passphrase request was cancelled.
|
||||||
if msg.code in (self.types.Failure_PinCancelled,
|
if msg.code in (self.types.FailureType.PinCancelled,
|
||||||
self.types.Failure_ActionCancelled,
|
self.types.FailureType.ActionCancelled,
|
||||||
self.types.Failure_NotInitialized):
|
self.types.FailureType.NotInitialized):
|
||||||
raise UserCancelled()
|
raise UserCancelled()
|
||||||
raise RuntimeError(msg.message)
|
raise RuntimeError(msg.message)
|
||||||
|
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
|||||||
address_path = "%s/%d/%d"%(derivation, change, index)
|
address_path = "%s/%d/%d"%(derivation, change, index)
|
||||||
address_n = client.expand_path(address_path)
|
address_n = client.expand_path(address_path)
|
||||||
segwit = wallet.keystore.is_segwit()
|
segwit = wallet.keystore.is_segwit()
|
||||||
script_type = self.types.SPENDP2SHWITNESS if segwit else self.types.SPENDADDRESS
|
script_type = self.types.InputScriptType.SPENDP2SHWITNESS if segwit else self.types.InputScriptType.SPENDADDRESS
|
||||||
client.get_address(self.get_coin_name(), address_n, True, script_type=script_type)
|
client.get_address(self.get_coin_name(), address_n, True, script_type=script_type)
|
||||||
|
|
||||||
def tx_inputs(self, tx, for_sig=False, segwit=False):
|
def tx_inputs(self, tx, for_sig=False, segwit=False):
|
||||||
@@ -259,8 +259,8 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
|||||||
x_pubkey = x_pubkeys[0]
|
x_pubkey = x_pubkeys[0]
|
||||||
xpub, s = parse_xpubkey(x_pubkey)
|
xpub, s = parse_xpubkey(x_pubkey)
|
||||||
xpub_n = self.client_class.expand_path(self.xpub_path[xpub])
|
xpub_n = self.client_class.expand_path(self.xpub_path[xpub])
|
||||||
txinputtype.address_n.extend(xpub_n + s)
|
txinputtype._extend_address_n(xpub_n + s)
|
||||||
txinputtype.script_type = self.types.SPENDP2SHWITNESS if segwit else self.types.SPENDADDRESS
|
txinputtype.script_type = self.types.InputScriptType.SPENDP2SHWITNESS if segwit else self.types.InputScriptType.SPENDADDRESS
|
||||||
else:
|
else:
|
||||||
def f(x_pubkey):
|
def f(x_pubkey):
|
||||||
if is_xpubkey(x_pubkey):
|
if is_xpubkey(x_pubkey):
|
||||||
@@ -276,7 +276,7 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
|||||||
signatures=map(lambda x: bfh(x)[:-1] if x else b'', txin.get('signatures')),
|
signatures=map(lambda x: bfh(x)[:-1] if x else b'', txin.get('signatures')),
|
||||||
m=txin.get('num_sig'),
|
m=txin.get('num_sig'),
|
||||||
)
|
)
|
||||||
script_type = self.types.SPENDP2SHWITNESS if segwit else self.types.SPENDMULTISIG
|
script_type = self.types.InputScriptType.SPENDP2SHWITNESS if segwit else self.types.InputScriptType.SPENDMULTISIG
|
||||||
txinputtype = self.types.TxInputType(
|
txinputtype = self.types.TxInputType(
|
||||||
script_type=script_type,
|
script_type=script_type,
|
||||||
multisig=multisig
|
multisig=multisig
|
||||||
@@ -287,7 +287,7 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
|||||||
xpub, s = parse_xpubkey(x_pubkey)
|
xpub, s = parse_xpubkey(x_pubkey)
|
||||||
if xpub in self.xpub_path:
|
if xpub in self.xpub_path:
|
||||||
xpub_n = self.client_class.expand_path(self.xpub_path[xpub])
|
xpub_n = self.client_class.expand_path(self.xpub_path[xpub])
|
||||||
txinputtype.address_n.extend(xpub_n + s)
|
txinputtype._extend_address_n(xpub_n + s)
|
||||||
break
|
break
|
||||||
|
|
||||||
prev_hash = unhexlify(txin['prevout_hash'])
|
prev_hash = unhexlify(txin['prevout_hash'])
|
||||||
@@ -327,7 +327,7 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
|||||||
address_n = address_n,
|
address_n = address_n,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
script_type = self.types.PAYTOP2SHWITNESS if segwit else self.types.PAYTOMULTISIG
|
script_type = self.types.OutputScriptType.PAYTOP2SHWITNESS if segwit else self.types.OutputScriptType.PAYTOMULTISIG
|
||||||
address_n = self.client_class.expand_path("/%d/%d"%index)
|
address_n = self.client_class.expand_path("/%d/%d"%index)
|
||||||
nodes = map(self.ckd_public.deserialize, xpubs)
|
nodes = map(self.ckd_public.deserialize, xpubs)
|
||||||
pubkeys = [ self.types.HDNodePathType(node=node, address_n=address_n) for node in nodes]
|
pubkeys = [ self.types.HDNodePathType(node=node, address_n=address_n) for node in nodes]
|
||||||
@@ -344,10 +344,10 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
|||||||
txoutputtype = self.types.TxOutputType()
|
txoutputtype = self.types.TxOutputType()
|
||||||
txoutputtype.amount = amount
|
txoutputtype.amount = amount
|
||||||
if _type == TYPE_SCRIPT:
|
if _type == TYPE_SCRIPT:
|
||||||
txoutputtype.script_type = self.types.PAYTOOPRETURN
|
txoutputtype.script_type = self.types.OutputScriptType.PAYTOOPRETURN
|
||||||
txoutputtype.op_return_data = address[2:]
|
txoutputtype.op_return_data = address[2:]
|
||||||
elif _type == TYPE_ADDRESS:
|
elif _type == TYPE_ADDRESS:
|
||||||
txoutputtype.script_type = self.types.PAYTOADDRESS
|
txoutputtype.script_type = self.types.OutputScriptType.PAYTOADDRESS
|
||||||
txoutputtype.address = address
|
txoutputtype.address = address
|
||||||
|
|
||||||
outputs.append(txoutputtype)
|
outputs.append(txoutputtype)
|
||||||
@@ -360,9 +360,9 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
|||||||
t.version = d['version']
|
t.version = d['version']
|
||||||
t.lock_time = d['lockTime']
|
t.lock_time = d['lockTime']
|
||||||
inputs = self.tx_inputs(tx)
|
inputs = self.tx_inputs(tx)
|
||||||
t.inputs.extend(inputs)
|
t._extend_inputs(inputs)
|
||||||
for vout in d['outputs']:
|
for vout in d['outputs']:
|
||||||
o = t.bin_outputs.add()
|
o = t._add_bin_outputs()
|
||||||
o.amount = vout['value']
|
o.amount = vout['value']
|
||||||
o.script_pubkey = bfh(vout['scriptPubKey'])
|
o.script_pubkey = bfh(vout['scriptPubKey'])
|
||||||
return t
|
return t
|
||||||
|
|||||||
@@ -375,25 +375,31 @@ class SettingsDialog(WindowModalDialog):
|
|||||||
invoke_client('toggle_passphrase', unpair_after=currently_enabled)
|
invoke_client('toggle_passphrase', unpair_after=currently_enabled)
|
||||||
|
|
||||||
def change_homescreen():
|
def change_homescreen():
|
||||||
from PIL import Image # FIXME
|
|
||||||
dialog = QFileDialog(self, _("Choose Homescreen"))
|
dialog = QFileDialog(self, _("Choose Homescreen"))
|
||||||
filename, __ = dialog.getOpenFileName()
|
filename, __ = dialog.getOpenFileName()
|
||||||
if filename:
|
|
||||||
im = Image.open(str(filename))
|
if filename.endswith('.toif'):
|
||||||
if im.size != (hs_cols, hs_rows):
|
img = open(filename, 'rb').read()
|
||||||
raise Exception('Image must be 64 x 128 pixels')
|
if img[:8] != b'TOIf\x90\x00\x90\x00':
|
||||||
|
raise Exception('File is not a TOIF file with size of 144x144')
|
||||||
|
else:
|
||||||
|
from PIL import Image # FIXME
|
||||||
|
im = Image.open(filename)
|
||||||
|
if im.size != (128, 64):
|
||||||
|
raise Exception('Image must be 128 x 64 pixels')
|
||||||
im = im.convert('1')
|
im = im.convert('1')
|
||||||
pix = im.load()
|
pix = im.load()
|
||||||
img = ''
|
img = bytearray(1024)
|
||||||
for j in range(hs_rows):
|
for j in range(64):
|
||||||
for i in range(hs_cols):
|
for i in range(128):
|
||||||
img += '1' if pix[i, j] else '0'
|
if pix[i, j]:
|
||||||
img = ''.join(chr(int(img[i:i + 8], 2))
|
o = (i + j * 128)
|
||||||
for i in range(0, len(img), 8))
|
img[o // 8] |= (1 << (7 - o % 8))
|
||||||
|
img = bytes(img)
|
||||||
invoke_client('change_homescreen', img)
|
invoke_client('change_homescreen', img)
|
||||||
|
|
||||||
def clear_homescreen():
|
def clear_homescreen():
|
||||||
invoke_client('change_homescreen', '\x00')
|
invoke_client('change_homescreen', b'\x00')
|
||||||
|
|
||||||
def set_pin():
|
def set_pin():
|
||||||
invoke_client('set_pin', remove=False)
|
invoke_client('set_pin', remove=False)
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ class TrezorPlugin(TrezorCompatiblePlugin):
|
|||||||
import trezorlib
|
import trezorlib
|
||||||
import trezorlib.ckd_public
|
import trezorlib.ckd_public
|
||||||
import trezorlib.transport_hid
|
import trezorlib.transport_hid
|
||||||
|
import trezorlib.messages
|
||||||
self.client_class = client.TrezorClient
|
self.client_class = client.TrezorClient
|
||||||
self.ckd_public = trezorlib.ckd_public
|
self.ckd_public = trezorlib.ckd_public
|
||||||
self.types = trezorlib.client.types
|
self.types = trezorlib.messages
|
||||||
self.DEVICE_IDS = (trezorlib.transport_hid.DEV_TREZOR1, trezorlib.transport_hid.DEV_TREZOR2)
|
self.DEVICE_IDS = (trezorlib.transport_hid.DEV_TREZOR1, trezorlib.transport_hid.DEV_TREZOR2)
|
||||||
self.libraries_available = True
|
self.libraries_available = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|||||||
Reference in New Issue
Block a user