From 15f592f0220fa339b8bb709961a7c38ad0f56fff Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sun, 5 Jul 2015 23:29:36 +0200 Subject: [PATCH] trezor multisig: build xpub from pubkey --- lib/bitcoin.py | 8 ++++++++ plugins/trezor.py | 14 +++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/bitcoin.py b/lib/bitcoin.py index 2305b3e27..9a86dddae 100644 --- a/lib/bitcoin.py +++ b/lib/bitcoin.py @@ -714,6 +714,14 @@ def bip32_root(seed, testnet=False): return EncodeBase58Check(xprv), EncodeBase58Check(xpub) +def xpub_from_pubkey(cK, testnet=False): + header_pub, header_priv = _get_headers(testnet) + assert cK[0] in ['\x02','\x03'] + master_c = chr(0)*32 + xpub = (header_pub + "00" + "00000000" + "00000000").decode("hex") + master_c + cK + return EncodeBase58Check(xpub) + + def bip32_private_derivation(xprv, branch, sequence, testnet=False): assert sequence.startswith(branch) if branch == sequence: diff --git a/plugins/trezor.py b/plugins/trezor.py index 37dd763d5..6107e0a73 100644 --- a/plugins/trezor.py +++ b/plugins/trezor.py @@ -11,8 +11,10 @@ from PyQt4.Qt import QMessageBox, QDialog, QVBoxLayout, QLabel, QThread, SIGNAL, import PyQt4.QtCore as QtCore import electrum +from electrum import bitcoin + from electrum.account import BIP32_Account -from electrum.bitcoin import EncodeBase58Check, public_key_to_bc_address, bc_address_to_hash_160 +from electrum.bitcoin import EncodeBase58Check, public_key_to_bc_address, bc_address_to_hash_160, xpub_from_pubkey from electrum.i18n import _ from electrum.plugins import BasePlugin, hook, always_hook, run_hook from electrum.transaction import Transaction, deserialize, is_extended_pubkey, x_to_xpub @@ -245,8 +247,6 @@ class Plugin(BasePlugin): def tx_inputs(self, tx, for_sig=False): inputs = [] for txin in tx.inputs: - print txin - txinputtype = types.TxInputType() if txin.get('is_coinbase'): prev_hash = "\0"*32 @@ -261,13 +261,17 @@ class Plugin(BasePlugin): txinputtype.address_n.extend(xpub_n + s) else: def f(x_pubkey): - xpub, s = BIP32_Account.parse_xpubkey(x_pubkey) + if is_extended_pubkey(x_pubkey): + xpub, s = BIP32_Account.parse_xpubkey(x_pubkey) + else: + xpub = xpub_from_pubkey(x_pubkey.decode('hex')) + s = [] node = ckd_public.deserialize(xpub) return types.HDNodePathType(node=node, address_n=s) pubkeys = map(f, x_pubkeys) multisig = types.MultisigRedeemScriptType( pubkeys=pubkeys, - signatures=map(lambda x: x if x else '', txin.get('signatures')), + signatures=map(lambda x: x.decode('hex') if x else '', txin.get('signatures')), m=txin.get('num_sig'), ) txinputtype = types.TxInputType(