Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def is_sig_valid(signature: str, pub_key: str, msg: str) -> bool:
'''
Given a signature, public key, and a message,
check if the signature is valid
'''
r, s = signature.split('x')
p = pub_key_to_point(pub_key)
return ecdsa.verify((int(r, 16), int(s, 16)), msg, p)
assert len(pubk) == 130
data_hash = get_data_hash(raw_data)
sig_bin = base64.b64decode(sigb64)
assert len(sig_bin) == 64
sig_hex = sig_bin.encode('hex')
sig_r = int(sig_hex[:64], 16)
sig_s = int(sig_hex[64:], 16)
pubk_raw = pubk[2:]
pubk_i = (int(pubk_raw[:64], 16), int(pubk_raw[64:], 16))
res = fastecdsa.ecdsa.verify((sig_r, sig_s), raw_data, pubk_i, curve=fastecdsa.curve.secp256k1)
return res
# The signature decoder has a clause like
# assert len(signature) == 2*l, (len(signature), 2*l)
# If the AssertionError is consistent with that signature, translate it
# to a nicer error. Otherwise re-raise.
if (
len(e.args) == 1
and isinstance(e.args[0], tuple)
and len(e.args[0]) == 2
and isinstance(e.args[0][0], int)
and isinstance(e.args[0][1], int)
):
raise WrongSignatureSize()
else:
raise
verified = fastecdsa.ecdsa.verify(
signature, data, verifying_pubkey, curve=fastecdsa.curve.P384, hashfunc=hashlib.sha384
)
if not verified:
raise SignatureDoesNotMatch()
return True