Exemplo n.º 1
0
 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())
Exemplo n.º 2
0
 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))
Exemplo n.º 3
0
def ecrecover_to_pub(sig, rawhash):
    pk = coincurve.PublicKey.from_signature_and_message(serialized_sig=sig,
                                                        message=rawhash)
    # print(pk.format().hex())
    r_sig = ecdsa.deserialize_recoverable(sig)
    n_sig = ecdsa.recoverable_convert(r_sig)
    der = ecdsa.cdata_to_der(n_sig)
    assert pk.verify(der, rawhash)
    x, y = pk.point()
    print('======')
    print(hex(x))
    print(hex(y))
    print('======')
    # return pk.format(compressed=False)[1:]
    return unhexlify("%064x%064x" % (x, y))
Exemplo n.º 4
0
    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))