Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sign: add message signing and verification #104

Merged
merged 26 commits into from
Mar 20, 2023

Conversation

xanimo
Copy link
Member

@xanimo xanimo commented Mar 15, 2023

This PR introduces message signing and verification into libdogecoin. It adheres to BIP-137 although is only applicable for P2PKH addressing and is slightly different considering we append the recid to the end of the signature if the recid != 0. This is needed in order to recover the public key in the verification step later on.

There are two implementations, one (signmsgwithprivkey and verifymessage) returns the signature as a char* and verifies the signature by passing a corresponding address into the verification function and the other (signmsgwitheckey and verifymessagewithsig) uses the eckey structure and signature structure to either auto generate a random privkey/pubkey pair or derives it from a private key in WIF format. This allows us to set the correct chain parameters for the rest of the usage throughout the process.

For instance, in such there is a hybrid implementation that uses the eckey and signature structures for the signing as we don't know the address and only provide the message we want to sign and the private key. On the verification step we can then pass the message, the signature and the corresponding address affiliated.

There is documentation for the API's (eckey.md, signing.md and tools.md) and corresponding examples within contrib/example.c.

xanimo added 21 commits March 7, 2023 23:43
-signing functions are now residing in sign.h and sign.c
-key functions to do with eckey structure are now in key.c
-added sign.h/.c to Makefile.am and CMakeLists.txt
-refactored message signing & verification functions to append the
recid on the end of the signature.
-added updated functions to corresponding documentation.
-added new new_eckey_from_privkey function to derive an eckey pair
from a WIF encoded private key.
-verifymessage now requires passing an address to it as this allows us to determine which network
prefixes are needed for creating the correct address from the recovered public key.
-added is_testnet bool to new_eckey and start_key functions as new_eckey was the only function
wherein we can't determine what chainparams are needed, thus let the user decide.
-updated documentation and example to reflect said changes.
-per spec's from core, each signed message is prepended with 'Dogecoin Signed Message:\n' which is now implemented in all signed messages.
@xanimo
Copy link
Member Author

xanimo commented Mar 16, 2023

Force pushed to amend the commit message to include a forgotten detail.

@xanimo
Copy link
Member Author

xanimo commented Mar 20, 2023

Greatly simplified the implementation with the help of @edtubbs over the weekend. There is only sign_message and verify_message now but this way is modeled after core's sign compact function. I've double checked a few samples by verifying the output and seem to be legit. Test's are passing and the program's I've tried are all memleak free.

Copy link
Collaborator

@edtubbs edtubbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and tested, ACK

@xanimo xanimo merged commit 4f793a8 into dogecoinfoundation:0.1.2-dev Mar 20, 2023
xanimo added a commit to xanimo/libdogecoin that referenced this pull request Mar 22, 2023
…igning

sign: add message signing and verification
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants