commit 0f4b5abc158d46ac25fc2a976154004a2c705f2d
parent 6c215c895a9a9babe9ff27a2b3487cbc94a75e67
Author: ThomasV <thomasv@electrum.org>
Date: Wed, 4 Oct 2017 13:04:21 +0200
add use_compressed_pubkeys field to keystores. fix #2973
Diffstat:
3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/lib/bitcoin.py b/lib/bitcoin.py
@@ -617,10 +617,6 @@ def verify_message(address, sig, message):
print_error("Verification error: {0}".format(e))
return False
-def sign_message_with_wif_privkey(sec, message):
- txin_type, privkey, compressed = deserialize_privkey(sec)
- key = regenerate_key(privkey)
- return key.sign_message(message, compressed)
def encrypt_message(message, pubkey):
return EC_KEY.encrypt_message(message, bfh(pubkey))
diff --git a/lib/keystore.py b/lib/keystore.py
@@ -88,7 +88,9 @@ class Software_KeyStore(KeyStore):
def sign_message(self, sequence, message, password):
sec = self.get_private_key(sequence, password)
- return sign_message_with_wif_privkey(sec, message)
+ compressed = self.use_compressed_pubkeys
+ key = regenerate_key(privkey)
+ return key.sign_message(message, compressed)
def decrypt_message(self, sequence, message, password):
sec = self.get_private_key(sequence, password)
@@ -277,6 +279,7 @@ class BIP32_KeyStore(Deterministic_KeyStore, Xpub):
def __init__(self, d):
Xpub.__init__(self)
Deterministic_KeyStore.__init__(self, d)
+ self.use_compressed_pubkeys = True
self.xpub = d.get('xpub')
self.xprv = d.get('xprv')
@@ -337,6 +340,7 @@ class Old_KeyStore(Deterministic_KeyStore):
def __init__(self, d):
Deterministic_KeyStore.__init__(self, d)
self.mpk = d.get('mpk')
+ self.use_compressed_pubkeys = False
def get_hex_seed(self, password):
return pw_decode(self.seed, password).encode('utf8')
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -274,12 +274,13 @@ class Abstract_Wallet(PrintError):
return []
index = self.get_address_index(address)
pk = self.keystore.get_private_key(index, password)
+ compressed = self.keystore.use_compressed_pubkeys
if self.txin_type in ['p2sh', 'p2wsh', 'p2wsh-p2sh']:
pubkeys = self.get_public_keys(address)
redeem_script = self.pubkeys_to_redeem_script(pubkeys)
else:
redeem_script = None
- return bitcoin.serialize_privkey(pk, True, self.txin_type), redeem_script
+ return bitcoin.serialize_privkey(pk, compressed, self.txin_type), redeem_script
def get_public_key(self, address):
if self.keystore.can_import():