-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Implement signmessagewithprivkey JSON-RPC command (rpc server) #1585
Conversation
Because of this Satoshi was finally able to sign his message the next day 😂 |
func handleSignMessageWithPrivKey(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { | ||
c := cmd.(*btcjson.SignMessageWithPrivKeyCmd) | ||
|
||
wif, err := btcutil.DecodeWIF(c.PrivKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bitcoind
rejects WIFs that do not belong to the current network. Or so it seems. Here's an example for you to reproduce using a mainnet WIF:
$ ./btcctl --regtest --rpcuser=aaaa --rpcpass=bbbb signmessagewithprivkey 5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ iamsatoshi
G+brEqKGQgPCSkPJrBau7x32eFhT3Y5YXdEXKG2bg2E2Tqi0lU54t+rYrEezLcSDLS4TM+/AO8a3A9ybAfvyMLY=
$ bitcoin-cli -regtest signmessagewithprivkey 5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ iamsatoshi
error code: -5
error message:
Invalid private key
The fix would be to simply check wif.IsForNet(s.cfg.ChainParams)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this was the case. Fixed by checking wif.IsForNet(s.cfg.ChainParams)
as you suggested.
Reuse the Bitcoin message signature header const also in verifymessage.
24f0882
to
65c6956
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested OK locally. ✔️
Looks good to me/tested locally against 0.20.0/0.19.0 (on bitcoind side). Since I'm not as familiar with btcec, would prefer to have someone else look over it as well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
Reuse the Bitcoin message signature header const
also in verifymessage.