Bitcoin Core  27.99.0
P2P Digital Currency
Enumerations | Functions | Variables
message.h File Reference
#include <uint256.h>
#include <string>
Include dependency graph for message.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum class  MessageVerificationResult {
  ERR_INVALID_ADDRESS , ERR_ADDRESS_NO_KEY , ERR_MALFORMED_SIGNATURE , ERR_PUBKEY_NOT_RECOVERED ,
  ERR_NOT_SIGNED , OK
}
 The result of a signed message verification. More...
 
enum class  SigningResult { OK , PRIVATE_KEY_NOT_AVAILABLE , SIGNING_FAILED }
 

Functions

MessageVerificationResult MessageVerify (const std::string &address, const std::string &signature, const std::string &message)
 Verify a signed message. More...
 
bool MessageSign (const CKey &privkey, const std::string &message, std::string &signature)
 Sign a message. More...
 
uint256 MessageHash (const std::string &message)
 Hashes a message for signing and verification in a manner that prevents inadvertently signing a transaction. More...
 
std::string SigningResultString (const SigningResult res)
 

Variables

const std::string MESSAGE_MAGIC
 Text used to signify that a signed message follows and to prevent inadvertently signing a transaction. More...
 

Enumeration Type Documentation

◆ MessageVerificationResult

The result of a signed message verification.

Message verification takes as an input:

  • address (with whose private key the message is supposed to have been signed)
  • signature
  • message
Enumerator
ERR_INVALID_ADDRESS 

The provided address is invalid.

ERR_ADDRESS_NO_KEY 

The provided address is valid but does not refer to a public key.

ERR_MALFORMED_SIGNATURE 

The provided signature couldn't be parsed (maybe invalid base64).

ERR_PUBKEY_NOT_RECOVERED 

A public key could not be recovered from the provided signature and message.

ERR_NOT_SIGNED 

The message was not signed with the private key of the provided address.

OK 

The message verification was successful.

Definition at line 23 of file message.h.

◆ SigningResult

enum SigningResult
strong
Enumerator
OK 

No error.

PRIVATE_KEY_NOT_AVAILABLE 
SIGNING_FAILED 

Definition at line 43 of file message.h.

Function Documentation

◆ MessageHash()

uint256 MessageHash ( const std::string &  message)

Hashes a message for signing and verification in a manner that prevents inadvertently signing a transaction.

Definition at line 73 of file message.cpp.

Here is the caller graph for this function:

◆ MessageSign()

bool MessageSign ( const CKey privkey,
const std::string &  message,
std::string &  signature 
)

Sign a message.

Parameters
[in]privkeyPrivate key to sign with.
[in]messageThe message to sign.
[out]signatureSignature, base64 encoded, only set if true is returned.
Returns
true if signing was successful.

Definition at line 57 of file message.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MessageVerify()

MessageVerificationResult MessageVerify ( const std::string &  address,
const std::string &  signature,
const std::string &  message 
)

Verify a signed message.

Parameters
[in]addressSigner's bitcoin address, it must refer to a public key.
[in]signatureThe signature in base64 format.
[in]messageThe message that was signed.
Returns
result code

Definition at line 26 of file message.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SigningResultString()

std::string SigningResultString ( const SigningResult  res)

Definition at line 81 of file message.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ MESSAGE_MAGIC

const std::string MESSAGE_MAGIC
extern

Text used to signify that a signed message follows and to prevent inadvertently signing a transaction.

Definition at line 24 of file message.cpp.