|
|
|
|
@ -468,6 +468,7 @@ class MyVerifyingKey(ecdsa.VerifyingKey):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EC_KEY(object): |
|
|
|
|
|
|
|
|
|
def __init__( self, k ): |
|
|
|
|
secret = string_to_number(k) |
|
|
|
|
self.pubkey = ecdsa.ecdsa.Public_key( generator_secp256k1, generator_secp256k1 * secret ) |
|
|
|
|
@ -492,12 +493,11 @@ class EC_KEY(object):
|
|
|
|
|
else: |
|
|
|
|
raise Exception("error: cannot sign message") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
|
def verify_message(self, address, signature, message): |
|
|
|
|
sig = base64.b64decode(signature) |
|
|
|
|
if len(sig) != 65: raise Exception("Wrong encoding") |
|
|
|
|
|
|
|
|
|
if len(sig) != 65: |
|
|
|
|
raise Exception("Wrong encoding") |
|
|
|
|
nV = ord(sig[0]) |
|
|
|
|
if nV < 27 or nV >= 35: |
|
|
|
|
raise Exception("Bad encoding") |
|
|
|
|
@ -506,16 +506,15 @@ class EC_KEY(object):
|
|
|
|
|
nV -= 4 |
|
|
|
|
else: |
|
|
|
|
compressed = False |
|
|
|
|
|
|
|
|
|
recid = nV - 27 |
|
|
|
|
|
|
|
|
|
h = Hash(msg_magic(message)) |
|
|
|
|
public_key = MyVerifyingKey.from_signature(sig[1:], recid, h, curve = SECP256k1) |
|
|
|
|
|
|
|
|
|
# check public key |
|
|
|
|
public_key.verify_digest(sig[1:], h, sigdecode = ecdsa.util.sigdecode_string) |
|
|
|
|
|
|
|
|
|
pubkey = point_to_ser(public_key.pubkey.point, compressed) |
|
|
|
|
# check that we get the original signing address |
|
|
|
|
addr = public_key_to_bc_address( point_to_ser(public_key.pubkey.point, compressed) ) |
|
|
|
|
addr = public_key_to_bc_address(pubkey) |
|
|
|
|
if address != addr: |
|
|
|
|
raise Exception("Bad signature") |
|
|
|
|
|
|
|
|
|
|