def test_signature_recoverable(self): private_key = PrivateKey(PRIVATE_KEY_BYTES) assert (private_key.public_key.format() == PublicKey( recover( MESSAGE, deserialize_recoverable( private_key.sign_recoverable(MESSAGE)))).format())
def from_signature_and_message(cls, serialized_sig, message, hasher=sha256, context=GLOBAL_CONTEXT): return PublicKey( recover(message, deserialize_recoverable(serialized_sig, context=context), hasher=hasher, context=context))
def from_signature_and_message(cls, signature: bytes, message: bytes, hasher: Hasher = sha256, context: Context = GLOBAL_CONTEXT): """ Recover an ECDSA public key from a recoverable signature. :param signature: The recoverable ECDSA signature. :param message: The message that was supposedly signed. :param hasher: The hash function to use, which must return 32 bytes. By default, the `sha256` algorithm is used. If `None`, no hashing occurs. :param context: :return: The public key that signed the message. :rtype: PublicKey :raises ValueError: If the message hash was not 32 bytes long or recovery of the ECDSA public key failed. """ return PublicKey( recover(message, deserialize_recoverable(signature, context=context), hasher=hasher, context=context))