add message signing/decryption for segwit addresses
This commit is contained in:
@@ -536,8 +536,7 @@ def public_key_from_private_key(pk, compressed):
|
||||
def address_from_private_key(sec):
|
||||
txin_type, privkey, compressed = deserialize_privkey(sec)
|
||||
public_key = public_key_from_private_key(privkey, compressed)
|
||||
address = pubkey_to_address(txin_type, public_key)
|
||||
return address
|
||||
return pubkey_to_address(txin_type, public_key)
|
||||
|
||||
def is_segwit_address(addr):
|
||||
witver, witprog = segwit_addr.decode(SEGWIT_HRP, addr)
|
||||
@@ -607,8 +606,11 @@ def verify_message(address, sig, message):
|
||||
public_key, compressed = pubkey_from_signature(sig, h)
|
||||
# check public key using the address
|
||||
pubkey = point_to_ser(public_key.pubkey.point, compressed)
|
||||
addr = public_key_to_p2pkh(pubkey)
|
||||
if address != addr:
|
||||
for txin_type in ['p2pkh','p2wpkh','p2wpkh-p2sh']:
|
||||
addr = pubkey_to_address(txin_type, bh2u(pubkey))
|
||||
if address == addr:
|
||||
break
|
||||
else:
|
||||
raise Exception("Bad signature")
|
||||
# check message
|
||||
public_key.verify_digest(sig[1:], h, sigdecode = ecdsa.util.sigdecode_string)
|
||||
|
||||
Reference in New Issue
Block a user