From e700b0d7311183cceaf3481751319eead6abfbbe Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 29 Nov 2017 05:39:44 +0100 Subject: [PATCH 1/2] fix: keepkey sending to p2sh output --- plugins/trezor/plugin.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py index e5cc492c..ad8f1e44 100644 --- a/plugins/trezor/plugin.py +++ b/plugins/trezor/plugin.py @@ -4,7 +4,8 @@ from binascii import hexlify, unhexlify from electrum.util import bfh, bh2u from electrum.bitcoin import (b58_address_to_hash160, xpub_from_pubkey, - TYPE_ADDRESS, TYPE_SCRIPT, NetworkConstants) + TYPE_ADDRESS, TYPE_SCRIPT, NetworkConstants, + is_segwit_address) from electrum.i18n import _ from electrum.plugins import BasePlugin from electrum.transaction import deserialize @@ -351,7 +352,19 @@ class TrezorCompatiblePlugin(HW_PluginBase): txoutputtype.script_type = self.types.PAYTOOPRETURN txoutputtype.op_return_data = address[2:] elif _type == TYPE_ADDRESS: - txoutputtype.script_type = self.types.PAYTOADDRESS + # trezor would be fine with self.types.PAYTOADDRESS + # for any non-change output + # but we need to maintain keepkey compatibility in this cls + if is_segwit_address(address): + txoutputtype.script_type = self.types.PAYTOWITNESS + else: + addrtype, hash_160 = b58_address_to_hash160(address) + if addrtype == NetworkConstants.ADDRTYPE_P2PKH: + txoutputtype.script_type = self.types.PAYTOADDRESS + elif addrtype == NetworkConstants.ADDRTYPE_P2SH: + txoutputtype.script_type = self.types.PAYTOSCRIPTHASH + else: + raise BaseException('addrtype: ' + str(addrtype)) txoutputtype.address = address outputs.append(txoutputtype) From bf452ecfe7c788dff378bc2b70a74e4a0ec52407 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sat, 2 Dec 2017 16:08:49 +0900 Subject: [PATCH 2/2] Make trezor code specific to trezor Fixes #3308 --- plugins/trezor/plugin.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py index e5cc492c..57986f0d 100644 --- a/plugins/trezor/plugin.py +++ b/plugins/trezor/plugin.py @@ -183,11 +183,11 @@ class TrezorCompatiblePlugin(HW_PluginBase): if method == TIM_NEW: strength = 64 * (item + 2) # 128, 192 or 256 - u2f_counter = 0 - skip_backup = False - client.reset_device(True, strength, passphrase_protection, - pin_protection, label, language, - u2f_counter, skip_backup) + args = [True, strength, passphrase_protection, + pin_protection, label, language] + if self.device == 'TREZOR': + args.extend([0, False]) # u2f_counter, skip_backup + client.reset_device(*args) elif method == TIM_RECOVER: word_count = 6 * (item + 2) # 12, 18 or 24 client.step = 0