Add ECDSA pubkey recovery usage example#1714
Add ECDSA pubkey recovery usage example#1714theStack wants to merge 2 commits intobitcoin-core:masterfrom
Conversation
a58848d to
314da41
Compare
|
I suppose the CI failures for the Valgrind jobs on MacOS Ventura (https://github.com/bitcoin-core/secp256k1/actions/runs/16623024583/job/47031936047 and https://github.com/bitcoin-core/secp256k1/actions/runs/16623024583/job/47031935996) are caused by the same memcmp-issue as observed in the Silent Payments PR (see #1519 (comment) ff.). Stole the |
|
The CI failure seems unrelated and probably just needs a restart; its caused by a 503 when installing packages inside the docker container (if I'm reading the logs correctly): https://github.com/bitcoin-core/secp256k1/actions/runs/16635429498/job/47075060509?pr=1714 |
|
Kicked the failure. |
Yeah indeed. Before the latest force-push (i.e. still using
Thanks! |
Sorry, my comment was unclear. What I meant to say is your solution works and the current failure is definitely not related. |
| /* Successful recovery guarantees a correct signature, but we also do an explicit verification | ||
| do demonstrate how to convert a recoverable to a normal ECDSA signature */ | ||
| return_val = secp256k1_ecdsa_recoverable_signature_convert(ctx, &normal_sig, &recoverable_sig); | ||
| assert(return_val); | ||
| if (!secp256k1_ecdsa_verify(ctx, &normal_sig, msg, &recovered_pubkey)) { | ||
| printf("Signature verification with converted recoverable signature failed\n"); | ||
| return EXIT_FAILURE; | ||
| } |
There was a problem hiding this comment.
This is true for signatures created with secp256k1_ecdsa_sign_recoverable, but not necessarily for arbitrarily generated ECDSA signatures (see #1718).
There was a problem hiding this comment.
That's interesting, wasn't aware. Added an secp256k1_ecdsa_signature_normalize call before the verification (it's a no-op in this example, but for demonstration purposes) and tried to explain that with a comment.
314da41 to
de5b223
Compare
Co-authored-by: josibake <josibake@protonmail.com>
de5b223 to
d0b51eb
Compare
The
recoverymodule is probably not super-relevant these days for newer projects (the primary use-case I'm aware of is message signing in Bitcoin Core and Electrum, likely other wallets; something that is hopefully replaced by BIP-322 one day), but it still seems better to have an example than to have none. It contains all of the five API calls, i.e. for signing, recovering, converting, serializing, parsing. As usual with examples, a lot of code and comments are duplicated (e.g. context creation, keypair generation, cleanup with secret key clearing etc.).