def throw_wrong_type(): private_key = ExtendedPrivateKey.from_seed(b"foo").get_private_key() message_hash = bytes([10] * 32) sig_prepend = private_key.sign_prepend_prehashed(message_hash).serialize() sig_secure = private_key.sign_prehashed(message_hash).serialize() try: Signature.from_bytes(sig_prepend) except ValueError: try: PrependSignature.from_bytes(sig_secure) except ValueError: return assert False assert False
def no_throw_bad_sig(): private_key = ExtendedPrivateKey.from_seed(b"foo").get_private_key() message_hash = bytes([9] * 32) sig = private_key.sign_prepend_prehashed(message_hash).serialize() sig = sig[:-1] + bytes([0]) public_key = private_key.get_public_key() try: bad_signature = PrependSignature.from_bytes(sig) except ValueError: return assert (False)
def signature_from_string(signature): try: sig = PrependSignature.from_bytes(bytes.fromhex(signature)) except Exception: raise Exception return sig