2021-04-20 21:33:02 +02:00
|
|
|
// Copyright (c) 2014-2020 The Dash Core developers
|
2017-04-12 09:04:06 +02:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2018-04-02 00:30:17 +02:00
|
|
|
#ifndef BITCOIN_MESSAGESIGNER_H
|
|
|
|
#define BITCOIN_MESSAGESIGNER_H
|
2017-04-12 09:04:06 +02:00
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <key.h>
|
2017-04-12 09:04:06 +02:00
|
|
|
|
|
|
|
/** Helper class for signing messages and checking their signatures
|
|
|
|
*/
|
|
|
|
class CMessageSigner
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Set the private/public key values, returns true if successful
|
2018-02-12 13:49:00 +01:00
|
|
|
static bool GetKeysFromSecret(const std::string& strSecret, CKey& keyRet, CPubKey& pubkeyRet);
|
2017-04-12 09:04:06 +02:00
|
|
|
/// Sign the message, returns true if successful
|
2018-02-12 13:49:00 +01:00
|
|
|
static bool SignMessage(const std::string& strMessage, std::vector<unsigned char>& vchSigRet, const CKey& key);
|
2021-07-17 21:15:21 +02:00
|
|
|
/// Verify the message signature, returns true if successful
|
2018-02-12 13:49:00 +01:00
|
|
|
static bool VerifyMessage(const CPubKey& pubkey, const std::vector<unsigned char>& vchSig, const std::string& strMessage, std::string& strErrorRet);
|
2021-07-17 21:15:21 +02:00
|
|
|
/// Verify the message signature, returns true if successful
|
2018-03-02 14:15:04 +01:00
|
|
|
static bool VerifyMessage(const CKeyID& keyID, const std::vector<unsigned char>& vchSig, const std::string& strMessage, std::string& strErrorRet);
|
2017-04-12 09:04:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Helper class for signing hashes and checking their signatures
|
|
|
|
*/
|
|
|
|
class CHashSigner
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Sign the hash, returns true if successful
|
2018-02-12 13:49:00 +01:00
|
|
|
static bool SignHash(const uint256& hash, const CKey& key, std::vector<unsigned char>& vchSigRet);
|
2021-07-19 12:39:22 +02:00
|
|
|
/// Verify the hash signature, returns true if successful
|
2018-02-12 13:49:00 +01:00
|
|
|
static bool VerifyHash(const uint256& hash, const CPubKey& pubkey, const std::vector<unsigned char>& vchSig, std::string& strErrorRet);
|
2021-07-19 12:39:22 +02:00
|
|
|
/// Verify the hash signature, returns true if successful
|
2018-03-02 14:15:04 +01:00
|
|
|
static bool VerifyHash(const uint256& hash, const CKeyID& keyID, const std::vector<unsigned char>& vchSig, std::string& strErrorRet);
|
2017-04-12 09:04:06 +02:00
|
|
|
};
|
|
|
|
|
2018-04-02 00:30:17 +02:00
|
|
|
#endif // BITCOIN_MESSAGESIGNER_H
|