|
|
@ -272,18 +272,9 @@ def is_valid(addr): |
|
|
|
|
|
|
|
########### end pywallet functions ####################### |
|
|
|
|
|
|
|
# secp256k1, http://www.oid-info.com/get/1.3.132.0.10 |
|
|
|
_p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2FL |
|
|
|
_r = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141L |
|
|
|
_b = 0x0000000000000000000000000000000000000000000000000000000000000007L |
|
|
|
_a = 0x0000000000000000000000000000000000000000000000000000000000000000L |
|
|
|
_Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798L |
|
|
|
_Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8L |
|
|
|
curve_secp256k1 = ecdsa.ellipticcurve.CurveFp( _p, _a, _b ) |
|
|
|
generator_secp256k1 = ecdsa.ellipticcurve.Point( curve_secp256k1, _Gx, _Gy, _r ) |
|
|
|
oid_secp256k1 = (1,3,132,0,10) |
|
|
|
SECP256k1 = ecdsa.curves.Curve("SECP256k1", curve_secp256k1, generator_secp256k1, oid_secp256k1 ) |
|
|
|
|
|
|
|
from ecdsa.ecdsa import curve_secp256k1, generator_secp256k1 |
|
|
|
from ecdsa.curves import SECP256k1 |
|
|
|
from ecdsa.util import string_to_number, number_to_string |
|
|
|
|
|
|
|
def msg_magic(message): |
|
|
@ -293,6 +284,16 @@ def msg_magic(message): |
|
|
|
return "\x18Bitcoin Signed Message:\n" + encoded_varint + message |
|
|
|
|
|
|
|
|
|
|
|
def verify_message(address, signature, message): |
|
|
|
try: |
|
|
|
EC_KEY.verify_message(address, signature, message) |
|
|
|
return True |
|
|
|
except BaseException as e: |
|
|
|
print_error("Verification error: {0}".format(e)) |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EC_KEY(object): |
|
|
|
def __init__( self, secret ): |
|
|
|
self.pubkey = ecdsa.ecdsa.Public_key( generator_secp256k1, generator_secp256k1 * secret ) |
|
|
@ -302,7 +303,7 @@ class EC_KEY(object): |
|
|
|
def sign_message(self, message, compressed, address): |
|
|
|
private_key = ecdsa.SigningKey.from_secret_exponent( self.secret, curve = SECP256k1 ) |
|
|
|
public_key = private_key.get_verifying_key() |
|
|
|
signature = private_key.sign_digest( Hash( msg_magic(message) ), sigencode = ecdsa.util.sigencode_string ) |
|
|
|
signature = private_key.sign_digest_deterministic( Hash( msg_magic(message) ), hashfunc=hashlib.sha256, sigencode = ecdsa.util.sigencode_string ) |
|
|
|
assert public_key.verify_digest( signature, Hash( msg_magic(message) ), sigdecode = ecdsa.util.sigdecode_string) |
|
|
|
for i in range(4): |
|
|
|
sig = base64.b64encode( chr(27 + i + (4 if compressed else 0)) + signature ) |
|
|
|