MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / MessageVerify

Function MessageVerify

src/common/signmessage.cpp:26–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24const std::string MESSAGE_MAGIC = "Bitcoin Signed Message:\n";
25
26MessageVerificationResult MessageVerify(
27 const std::string& address,
28 const std::string& signature,
29 const std::string& message)
30{
31 CTxDestination destination = DecodeDestination(address);
32 if (!IsValidDestination(destination)) {
33 return MessageVerificationResult::ERR_INVALID_ADDRESS;
34 }
35
36 if (std::get_if<PKHash>(&destination) == nullptr) {
37 return MessageVerificationResult::ERR_ADDRESS_NO_KEY;
38 }
39
40 auto signature_bytes = DecodeBase64(signature);
41 if (!signature_bytes) {
42 return MessageVerificationResult::ERR_MALFORMED_SIGNATURE;
43 }
44
45 CPubKey pubkey;
46 if (!pubkey.RecoverCompact(MessageHash(message), *signature_bytes)) {
47 return MessageVerificationResult::ERR_PUBKEY_NOT_RECOVERED;
48 }
49
50 if (!(PKHash(pubkey) == *std::get_if<PKHash>(&destination))) {
51 return MessageVerificationResult::ERR_NOT_SIGNED;
52 }
53
54 return MessageVerificationResult::OK;
55}
56
57bool MessageSign(
58 const CKey& privkey,

Callers 4

BOOST_AUTO_TEST_CASEFunction · 0.85
message.cppFile · 0.85
verifymessageFunction · 0.85

Calls 6

DecodeDestinationFunction · 0.85
IsValidDestinationFunction · 0.85
DecodeBase64Function · 0.85
MessageHashFunction · 0.85
PKHashClass · 0.85
RecoverCompactMethod · 0.80

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68