Browse Source

fix issue #2064

283
ThomasV 8 years ago
parent
commit
cda0d14a13
  1. 29
      gui/qt/main_window.py
  2. 9
      lib/bitcoin.py

29
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:

9
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:

Loading…
Cancel
Save