mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
Deduplicate the message signing code
The logic of signing a message was duplicated in 3 places: src/qt/signverifymessagedialog.cpp SignVerifyMessageDialog::on_signMessageButton_SM_clicked() src/rpc/misc.cpp signmessagewithprivkey() src/wallet/rpcwallet.cpp signmessage() Move the logic into src/util/message.cpp MessageSign() and call it from all the 3 places.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <hash.h> // For CHashWriter
|
||||
#include <key.h> // For CKey
|
||||
#include <key_io.h> // For DecodeDestination()
|
||||
#include <pubkey.h> // For CPubKey
|
||||
#include <script/standard.h> // For CTxDestination, IsValidDestination(), PKHash
|
||||
@@ -51,3 +52,23 @@ MessageVerificationResult MessageVerify(
|
||||
|
||||
return MessageVerificationResult::OK;
|
||||
}
|
||||
|
||||
bool MessageSign(
|
||||
const CKey& privkey,
|
||||
const std::string& message,
|
||||
std::string& signature)
|
||||
{
|
||||
CHashWriter ss(SER_GETHASH, 0);
|
||||
ss << strMessageMagic;
|
||||
ss << message;
|
||||
|
||||
std::vector<unsigned char> signature_bytes;
|
||||
|
||||
if (!privkey.SignCompact(ss.GetHash(), signature_bytes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
signature = EncodeBase64(signature_bytes.data(), signature_bytes.size());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user