MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / signmessage

Function signmessage

src/rpc/rpcwallet.cpp:236–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236Value signmessage(const Array& params, bool fHelp) {
237 if (fHelp || params.size() != 2) {
238 throw runtime_error("signmessage \"signee\" \"message\"\n"
239 "\nSign a message by the private key of the given address"
240 + HelpRequiringPassphrase() + "\n"
241 "\nArguments:\n"
242 "1. \"signee\" (string, required) The coin address associated with the private key to sign.\n"
243 "2. \"message\" (string, required) The message to create a signature of.\n"
244 "\nResult:\n"
245 "\"signature\" (string) The signature of the message encoded in base 64\n"
246 "\nExamples:\n"
247 "\nUnlock the wallet for 30 seconds\n"
248 + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
249 "\nCreate the signature\n"
250 + HelpExampleCli("signmessage", R"("wLKf2NqwtHk3BfzK5wMDfbKYN1SC3weyR4" "my message")") +
251 "\nVerify the signature\n"
252 + HelpExampleCli("verifymessage", R"("wLKf2NqwtHk3BfzK5wMDfbKYN1SC3weyR4" "signature" "my message")") +
253 "\nAs json rpc\n"
254 + HelpExampleRpc("signmessage", R"("wLKf2NqwtHk3BfzK5wMDfbKYN1SC3weyR4", "my message")")
255 );
256 }
257
258 EnsureWalletIsUnlocked();
259
260 const CKeyID &keyId = RPC_PARAM::GetKeyId(params[0]);
261 string strMessage = params[1].get_str();
262
263 if (keyId.IsEmpty())
264 throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
265
266 CKey key;
267 if (!pWalletMain->GetKey(keyId, key))
268 throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available");
269
270 CHashWriter ss(SER_GETHASH, 0);
271 ss << strMessageMagic;
272 ss << strMessage;
273
274 vector<uint8_t> vchSig;
275 if (!key.SignCompact(ss.GetHash(), vchSig))
276 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
277
278 return EncodeBase64(&vchSig[0], vchSig.size());
279}
280
281Value submitsendtx(const Array& params, bool fHelp) {
282 if (fHelp || (params.size() < 3 && params.size() > 5))

Callers

nothing calls this directly

Calls 12

HelpRequiringPassphraseFunction · 0.85
HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
EnsureWalletIsUnlockedFunction · 0.85
GetKeyIdFunction · 0.85
JSONRPCErrorFunction · 0.85
EncodeBase64Function · 0.85
sizeMethod · 0.45
IsEmptyMethod · 0.45
GetKeyMethod · 0.45
SignCompactMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected