fix issue #2064
This commit is contained in:
@@ -52,7 +52,7 @@ from electrum.util import (block_explorer, block_explorer_info, format_time,
|
|||||||
from electrum import Transaction, mnemonic
|
from electrum import Transaction, mnemonic
|
||||||
from electrum import util, bitcoin, commands, coinchooser
|
from electrum import util, bitcoin, commands, coinchooser
|
||||||
from electrum import SimpleConfig, paymentrequest
|
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 amountedit import BTCAmountEdit, MyLineEdit, BTCkBEdit
|
||||||
from network_dialog import NetworkDialog
|
from network_dialog import NetworkDialog
|
||||||
@@ -1758,20 +1758,35 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||||||
|
|
||||||
@protected
|
@protected
|
||||||
def do_sign(self, address, message, signature, password):
|
def do_sign(self, address, message, signature, password):
|
||||||
message = unicode(message.toPlainText()).encode('utf-8')
|
address = str(address.text()).strip()
|
||||||
task = partial(self.wallet.sign_message, str(address.text()),
|
message = unicode(message.toPlainText()).encode('utf-8').strip()
|
||||||
message, password)
|
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):
|
def show_signed_message(sig):
|
||||||
signature.setText(base64.b64encode(sig))
|
signature.setText(base64.b64encode(sig))
|
||||||
self.wallet.thread.add(task, on_success=show_signed_message)
|
self.wallet.thread.add(task, on_success=show_signed_message)
|
||||||
|
|
||||||
def do_verify(self, address, message, signature):
|
def do_verify(self, address, message, signature):
|
||||||
message = unicode(message.toPlainText())
|
address = str(address.text()).strip()
|
||||||
message = message.encode('utf-8')
|
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:
|
try:
|
||||||
# This can throw on invalid base64
|
# This can throw on invalid base64
|
||||||
sig = base64.b64decode(str(signature.toPlainText()))
|
sig = base64.b64decode(str(signature.toPlainText()))
|
||||||
verified = bitcoin.verify_message(address.text(), sig, message)
|
verified = bitcoin.verify_message(address, sig, message)
|
||||||
except:
|
except:
|
||||||
verified = False
|
verified = False
|
||||||
if verified:
|
if verified:
|
||||||
|
|||||||
@@ -384,6 +384,15 @@ def is_address(addr):
|
|||||||
return False
|
return False
|
||||||
return addr == hash_160_to_bc_address(h, addrtype)
|
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):
|
def is_private_key(key):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user