I am a noob with cryptography, I just try to learn using python and coincurve library (https://github.com/ofek/coincurve) which is a mature Python link for libsecp256k1.
The following code creates a private key and produces a signature of the string "Hello world!".
pk = coincurve.PrivateKey () message = b "this is a test!" s = pk.sign_recoverable (message)
Signature s is a sequence of 65 bytes.
The signature is recoverable: I can extract the public key from pk of s.
pub = pk.public_key pub2 = coincurve.PublicKey.from_signature_and_message (s, message) assert (pub == pub2)
Until here everything is fine! However, I do not understand how to use the verification method. The following code
valid = coincurve.verify_signature (s, message, pub)
gives the following error:
ValueError: the signature encoded in DER could not be parsed.
So the problem is that the method verify_signature is waiting for a signature in DER format. This is normally produced using the sign method as opposed to the signer_recouvrable method:
t = pk.sign (message) valid = coincurve.verify_signature (t, message, pub.format ())
that works well.
So my question is:
QUESTION: How to change from "DER" format to "recoverable" format in the Python library?