sweeping minikeys: search for both compressed and uncompressed pubkeys
This commit is contained in:
parent
568afd7a17
commit
9e2cd17790
|
@ -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)
|
||||
|
|
|
@ -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)'))
|
||||
|
|
Loading…
Reference in New Issue