electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 6ccd4b78008ae81ed39a9591721679ba446e4883
parent 9d4dd20b239c975e99aef4254160732c5031997b
Author: ThomasV <thomasv@electrum.org>
Date:   Sat, 30 Dec 2017 14:39:02 +0100

Merge pull request #3621 from slush0/master

Make Electrum work with trezorlib 0.9.0
Diffstat:
Micons/trezor.png | 0
Micons/trezor_unpaired.png | 0
Mplugins/trezor/clientbase.py | 6+++---
Mplugins/trezor/plugin.py | 27+++++++++++----------------
Mplugins/trezor/qt_generic.py | 30++++++++++++++++++------------
Mplugins/trezor/trezor.py | 13+++++++------
6 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/icons/trezor.png b/icons/trezor.png Binary files differ. diff --git a/icons/trezor_unpaired.png b/icons/trezor_unpaired.png Binary files differ. diff --git a/plugins/trezor/clientbase.py b/plugins/trezor/clientbase.py @@ -28,9 +28,9 @@ class GuiMixin(object): # However, making the user acknowledge they cancelled # gets old very quickly, so we suppress those. The NotInitialized # one is misnamed and indicates a passphrase request was cancelled. - if msg.code in (self.types.Failure_PinCancelled, - self.types.Failure_ActionCancelled, - self.types.Failure_NotInitialized): + if msg.code in (self.types.FailureType.PinCancelled, + self.types.FailureType.ActionCancelled, + self.types.FailureType.NotInitialized): raise UserCancelled() raise RuntimeError(msg.message) diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py @@ -76,13 +76,8 @@ class TrezorCompatiblePlugin(HW_PluginBase): def _try_hid(self, device): self.print_error("Trying to connect over USB...") - if device.interface_number == 1: - pair = [None, device.path] - else: - pair = [device.path, None] - try: - return self.hid_transport(pair) + return self.hid_transport(device) except BaseException as e: # see fdb810ba622dc7dbe1259cbafb5b28e19d2ab114 # raise @@ -247,7 +242,7 @@ class TrezorCompatiblePlugin(HW_PluginBase): address_path = "%s/%d/%d"%(derivation, change, index) address_n = client.expand_path(address_path) 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) def tx_inputs(self, tx, for_sig=False, segwit=False): @@ -264,8 +259,8 @@ class TrezorCompatiblePlugin(HW_PluginBase): x_pubkey = x_pubkeys[0] xpub, s = parse_xpubkey(x_pubkey) xpub_n = self.client_class.expand_path(self.xpub_path[xpub]) - txinputtype.address_n.extend(xpub_n + s) - txinputtype.script_type = self.types.SPENDP2SHWITNESS if segwit else self.types.SPENDADDRESS + txinputtype._extend_address_n(xpub_n + s) + txinputtype.script_type = self.types.InputScriptType.SPENDP2SHWITNESS if segwit else self.types.InputScriptType.SPENDADDRESS else: def f(x_pubkey): if is_xpubkey(x_pubkey): @@ -281,7 +276,7 @@ class TrezorCompatiblePlugin(HW_PluginBase): signatures=map(lambda x: bfh(x)[:-1] if x else b'', txin.get('signatures')), 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( script_type=script_type, multisig=multisig @@ -292,7 +287,7 @@ class TrezorCompatiblePlugin(HW_PluginBase): xpub, s = parse_xpubkey(x_pubkey) if xpub in self.xpub_path: 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 prev_hash = unhexlify(txin['prevout_hash']) @@ -332,7 +327,7 @@ class TrezorCompatiblePlugin(HW_PluginBase): address_n = address_n, ) 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) nodes = map(self.ckd_public.deserialize, xpubs) pubkeys = [ self.types.HDNodePathType(node=node, address_n=address_n) for node in nodes] @@ -349,10 +344,10 @@ class TrezorCompatiblePlugin(HW_PluginBase): txoutputtype = self.types.TxOutputType() txoutputtype.amount = amount if _type == TYPE_SCRIPT: - txoutputtype.script_type = self.types.PAYTOOPRETURN + txoutputtype.script_type = self.types.OutputScriptType.PAYTOOPRETURN txoutputtype.op_return_data = address[2:] elif _type == TYPE_ADDRESS: - txoutputtype.script_type = self.types.PAYTOADDRESS + txoutputtype.script_type = self.types.OutputScriptType.PAYTOADDRESS txoutputtype.address = address outputs.append(txoutputtype) @@ -365,9 +360,9 @@ class TrezorCompatiblePlugin(HW_PluginBase): t.version = d['version'] t.lock_time = d['lockTime'] inputs = self.tx_inputs(tx) - t.inputs.extend(inputs) + t._extend_inputs(inputs) for vout in d['outputs']: - o = t.bin_outputs.add() + o = t._add_bin_outputs() o.amount = vout['value'] o.script_pubkey = bfh(vout['scriptPubKey']) return t diff --git a/plugins/trezor/qt_generic.py b/plugins/trezor/qt_generic.py @@ -375,25 +375,31 @@ class SettingsDialog(WindowModalDialog): invoke_client('toggle_passphrase', unpair_after=currently_enabled) def change_homescreen(): - from PIL import Image # FIXME dialog = QFileDialog(self, _("Choose Homescreen")) filename, __ = dialog.getOpenFileName() - if filename: - im = Image.open(str(filename)) - if im.size != (hs_cols, hs_rows): - raise Exception('Image must be 64 x 128 pixels') + + if filename.endswith('.toif'): + img = open(filename, 'rb').read() + 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') pix = im.load() - img = '' - for j in range(hs_rows): - for i in range(hs_cols): - img += '1' if pix[i, j] else '0' - img = ''.join(chr(int(img[i:i + 8], 2)) - for i in range(0, len(img), 8)) + img = bytearray(1024) + for j in range(64): + for i in range(128): + if pix[i, j]: + o = (i + j * 128) + img[o // 8] |= (1 << (7 - o % 8)) + img = bytes(img) invoke_client('change_homescreen', img) def clear_homescreen(): - invoke_client('change_homescreen', '\x00') + invoke_client('change_homescreen', b'\x00') def set_pin(): invoke_client('set_pin', remove=False) diff --git a/plugins/trezor/trezor.py b/plugins/trezor/trezor.py @@ -6,9 +6,9 @@ class TrezorKeyStore(TrezorCompatibleKeyStore): device = 'TREZOR' class TrezorPlugin(TrezorCompatiblePlugin): - firmware_URL = 'https://www.mytrezor.com' + firmware_URL = 'https://wallet.trezor.io' libraries_URL = 'https://github.com/trezor/python-trezor' - minimum_firmware = (1, 3, 3) + minimum_firmware = (1, 5, 2) keystore_class = TrezorKeyStore def __init__(self, *args): @@ -17,18 +17,19 @@ class TrezorPlugin(TrezorCompatiblePlugin): import trezorlib import trezorlib.ckd_public import trezorlib.transport_hid + import trezorlib.messages self.client_class = client.TrezorClient self.ckd_public = trezorlib.ckd_public - self.types = trezorlib.client.types - self.DEVICE_IDS = trezorlib.transport_hid.DEVICE_IDS + self.types = trezorlib.messages + self.DEVICE_IDS = (trezorlib.transport_hid.DEV_TREZOR1, trezorlib.transport_hid.DEV_TREZOR2) self.libraries_available = True except ImportError: self.libraries_available = False TrezorCompatiblePlugin.__init__(self, *args) - def hid_transport(self, pair): + def hid_transport(self, device): from trezorlib.transport_hid import HidTransport - return HidTransport(pair) + return HidTransport.find_by_path(device.path) def bridge_transport(self, d): from trezorlib.transport_bridge import BridgeTransport