I am a noob with cryptography, just trying to learn using python and the library Coincurve ( https://github.com/ofek/coincurve ) which is a mature Python binding 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)
The signature s is a sequence 65 bytes.
The signature is recoverable: i can extract the public key of pk from s.
pub = pk.public_key
pub2 = coincurve.PublicKey.from_signature_and_message(s,message)
assert(pub == pub2)
So far all good! However I can't understand how to use the verify method. The following code
valid = coincurve.verify_signature(s,message,pub)
gives the following error:
ValueError: The DER-encoded signature could not be parsed.
So the problem is that the method verify_signature expects a signature in DER format. This is normally produced using the sign method, as opposed to the sign_recoverable method:
t = pk.sign(message)
valid = coincurve.verify_signature(t,message,pub.format())
which works fine.
So my question is:
QUESTION: How do I move back and forth from the "DER" format to the "recoverable" format in the Python library coincurve?
THANKS!