Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/misc.cpp
Show First 20 Lines • Show All 289 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 2) { | ||||
"\nAs json rpc\n" + | "\nAs json rpc\n" + | ||||
HelpExampleRpc("signmessagewithprivkey", | HelpExampleRpc("signmessagewithprivkey", | ||||
"\"privkey\", \"my message\"")); | "\"privkey\", \"my message\"")); | ||||
} | } | ||||
std::string strPrivkey = request.params[0].get_str(); | std::string strPrivkey = request.params[0].get_str(); | ||||
std::string strMessage = request.params[1].get_str(); | std::string strMessage = request.params[1].get_str(); | ||||
CBitcoinSecret vchSecret; | CKey key = DecodeSecret(strPrivkey); | ||||
bool fGood = vchSecret.SetString(strPrivkey); | |||||
if (!fGood) { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key"); | |||||
} | |||||
CKey key = vchSecret.GetKey(); | |||||
if (!key.IsValid()) { | if (!key.IsValid()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key"); | ||||
"Private key outside allowed range"); | |||||
} | } | ||||
CHashWriter ss(SER_GETHASH, 0); | CHashWriter ss(SER_GETHASH, 0); | ||||
ss << strMessageMagic; | ss << strMessageMagic; | ||||
ss << strMessage; | ss << strMessage; | ||||
std::vector<uint8_t> vchSig; | std::vector<uint8_t> vchSig; | ||||
if (!key.SignCompact(ss.GetHash(), vchSig)) { | if (!key.SignCompact(ss.GetHash(), vchSig)) { | ||||
▲ Show 20 Lines • Show All 177 Lines • Show Last 20 Lines |