MCPcopy Create free account
hub / github.com/ElementsProject/elements / MessageVerify

Function MessageVerify

src/util/message.cpp:24–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 4

BOOST_AUTO_TEST_CASEFunction · 0.85
FUZZ_TARGET_INITFunction · 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 2

BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68