electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit cda0d14a133ea13bab745ef2fed0d22ee8fca485
parent a660590a70cacd86e785a7f307ad141bc78b6406
Author: ThomasV <thomasv@electrum.org>
Date:   Wed, 21 Dec 2016 13:30:35 +0100

fix issue #2064

Diffstat:
Mgui/qt/main_window.py | 29++++++++++++++++++++++-------
Mlib/bitcoin.py | 9+++++++++
2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -52,7 +52,7 @@ from electrum.util import (block_explorer, block_explorer_info, format_time, from electrum import Transaction, mnemonic from electrum import util, bitcoin, commands, coinchooser from electrum import SimpleConfig, paymentrequest -from electrum.wallet import Wallet, Multisig_Wallet +from electrum.wallet import Wallet, Multisig_Wallet, P2PK_Wallet from amountedit import BTCAmountEdit, MyLineEdit, BTCkBEdit from network_dialog import NetworkDialog @@ -1758,20 +1758,35 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): @protected def do_sign(self, address, message, signature, password): - message = unicode(message.toPlainText()).encode('utf-8') - task = partial(self.wallet.sign_message, str(address.text()), - message, password) + address = str(address.text()).strip() + message = unicode(message.toPlainText()).encode('utf-8').strip() + if not bitcoin.is_address(address): + self.show_message('Invalid Bitcoin address.') + return + if not bitcoin.is_p2pkh(address): + self.show_message('Cannot sign messages with this type of address.') + return + if not wallet.is_mine(address): + self.show_message('Address not in wallet.') + return + task = partial(self.wallet.sign_message, address, message, password) def show_signed_message(sig): signature.setText(base64.b64encode(sig)) self.wallet.thread.add(task, on_success=show_signed_message) def do_verify(self, address, message, signature): - message = unicode(message.toPlainText()) - message = message.encode('utf-8') + address = str(address.text()).strip() + message = unicode(message.toPlainText()).encode('utf-8').strip() + if not bitcoin.is_address(address): + self.show_message('Invalid Bitcoin address.') + return + if not bitcoin.is_p2pkh(address): + self.show_message('Cannot verify messages with this type of address.') + return try: # This can throw on invalid base64 sig = base64.b64decode(str(signature.toPlainText())) - verified = bitcoin.verify_message(address.text(), sig, message) + verified = bitcoin.verify_message(address, sig, message) except: verified = False if verified: diff --git a/lib/bitcoin.py b/lib/bitcoin.py @@ -384,6 +384,15 @@ def is_address(addr): return False return addr == hash_160_to_bc_address(h, addrtype) +def is_p2pkh(addr): + if is_address(addr): + addrtype, h = bc_address_to_hash_160(addr) + return addrtype in [0] + +def is_p2sh(addr): + if is_address(addr): + addrtype, h = bc_address_to_hash_160(addr) + return addrtype in [5] def is_private_key(key): try: