From 9e2cd177907406e7e5ddde4942ef88c3d5d64809 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sat, 11 Nov 2017 11:02:30 +0100 Subject: [PATCH] sweeping minikeys: search for both compressed and uncompressed pubkeys --- lib/bitcoin.py | 2 +- lib/wallet.py | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/bitcoin.py b/lib/bitcoin.py index eb65cd5b..a95e0cf4 100644 --- a/lib/bitcoin.py +++ b/lib/bitcoin.py @@ -600,7 +600,7 @@ def is_minikey(text): # permits any length of 20 or more provided the minikey is valid. # A valid minikey must begin with an 'S', be in base58, and when # suffixed with '?' have its SHA256 hash begin with a zero byte. - # They are widely used in Casascius physical bitoins. + # They are widely used in Casascius physical bitcoins. return (len(text) >= 20 and text[0] == 'S' and all(ord(c) in __b58chars for c in text) and sha256(text + '?')[0] == 0x00) diff --git a/lib/wallet.py b/lib/wallet.py index eb55d7aa..249dc983 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -893,15 +893,28 @@ class Abstract_Wallet(PrintError): inputs.append(item) def sweep(self, privkeys, network, config, recipient, fee=None, imax=100): + + def find_utxos_for_privkey(txin_type, privkey, compressed): + pubkey = bitcoin.public_key_from_private_key(privkey, compressed) + self._append_utxos_to_inputs(inputs, network, pubkey, txin_type, imax) + keypairs[pubkey] = privkey, compressed + inputs = [] keypairs = {} for sec in privkeys: txin_type, privkey, compressed = bitcoin.deserialize_privkey(sec) - pubkey = bitcoin.public_key_from_private_key(privkey, compressed) - self._append_utxos_to_inputs(inputs, network, pubkey, txin_type, imax) - if txin_type == 'p2pkh': # WIF serialization is ambiguous :( - self._append_utxos_to_inputs(inputs, network, pubkey, 'p2pk', imax) - keypairs[pubkey] = privkey, compressed + + find_utxos_for_privkey(txin_type, privkey, compressed) + + # do other lookups to increase support coverage + if is_minikey(sec): + # minikeys don't have a compressed byte + # we lookup both compressed and uncompressed pubkeys + find_utxos_for_privkey(txin_type, privkey, not compressed) + elif txin_type == 'p2pkh': + # WIF serialization does not distinguish p2pkh and p2pk + # we also search for pay-to-pubkey outputs + find_utxos_for_privkey('p2pk', privkey, compressed) if not inputs: raise BaseException(_('No inputs found. (Note that inputs need to be confirmed)'))