Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2009-2010 Satoshi Nakamoto2// Copyright (c) 2009-present The Bitcoin Core developers3// Distributed under the MIT software license, see the accompanying4// file COPYING or http://www.opensource.org/licenses/mit-license.php.6#ifndef BITCOIN_COMMON_SIGNMESSAGE_H7#define BITCOIN_COMMON_SIGNMESSAGE_H9#include <uint256.h>11#include <string>13class CKey;15extern const std::string MESSAGE_MAGIC;17/** The result of a signed message verification.18* Message verification takes as an input:19* - address (with whose private key the message is supposed to have been signed)20* - signature21* - message22*/23enum class MessageVerificationResult {24//! The provided address is invalid.25ERR_INVALID_ADDRESS,27//! The provided address is valid but does not refer to a public key.28ERR_ADDRESS_NO_KEY,30//! The provided signature couldn't be parsed (maybe invalid base64).31ERR_MALFORMED_SIGNATURE,33//! A public key could not be recovered from the provided signature and message.34ERR_PUBKEY_NOT_RECOVERED,36//! The message was not signed with the private key of the provided address.37ERR_NOT_SIGNED,39//! The message verification was successful.40OK41};43enum class SigningResult {44OK, //!< No error45PRIVATE_KEY_NOT_AVAILABLE,46SIGNING_FAILED,47};49/** Verify a signed message.50* @param[in] address Signer's bitcoin address, it must refer to a public key.51* @param[in] signature The signature in base64 format.52* @param[in] message The message that was signed.53* @return result code */54MessageVerificationResult MessageVerify(55const std::string& address,56const std::string& signature,57const std::string& message);59/** Sign a message.60* @param[in] privkey Private key to sign with.61* @param[in] message The message to sign.62* @param[out] signature Signature, base64 encoded, only set if true is returned.63* @return true if signing was successful. */64bool MessageSign(65const CKey& privkey,66const std::string& message,67std::string& signature);69/**70* Hashes a message for signing and verification in a manner that prevents71* inadvertently signing a transaction.72*/73uint256 MessageHash(const std::string& message);75std::string SigningResultString(SigningResult res);77#endif // BITCOIN_COMMON_SIGNMESSAGE_H