| 24 | const std::string MESSAGE_MAGIC = "Bitcoin Signed Message:\n"; |
| 25 | |
| 26 | MessageVerificationResult 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 | |
| 57 | bool MessageSign( |
| 58 | const CKey& privkey, |