From ff3bb3d69ef573b9a01f2aecfe9319564eec25eb Mon Sep 17 00:00:00 2001 From: Hiro Satou Date: Tue, 22 Apr 2014 19:21:14 +0100 Subject: [PATCH] Add makekeypair to generate ECDSA keys Use this to generate keys for use in alert.cpp to replace old Litecoin keys. --- src/bitcoinrpc.cpp | 1 + src/bitcoinrpc.h | 1 + src/rpcnet.cpp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 466217897fd20..8f3845cb10b6a 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -252,6 +252,7 @@ static const CRPCCommand vRPCCommands[] = { "submitblock", &submitblock, false, false, false }, { "setmininput", &setmininput, false, false, false }, { "listsinceblock", &listsinceblock, false, false, true }, + { "makekeypair", &makekeypair, true, false, true }, { "dumpprivkey", &dumpprivkey, true, false, true }, { "importprivkey", &importprivkey, false, false, true }, { "listunspent", &listunspent, false, false, true }, diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index bea7712e889f7..5f4e59b3e9e47 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -175,6 +175,7 @@ extern json_spirit::Value listtransactions(const json_spirit::Array& params, boo extern json_spirit::Value listaddressgroupings(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value listaccounts(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value listsinceblock(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value makekeypair(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value gettransaction(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value backupwallet(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value keypoolrefill(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 1228cb44f1257..6f46d868ea70b 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -4,6 +4,8 @@ #include "net.h" #include "bitcoinrpc.h" +#include "alert.h" +#include "base58.h" using namespace json_spirit; using namespace std; @@ -206,3 +208,33 @@ Value getaddednodeinfo(const Array& params, bool fHelp) return ret; } +Value makekeypair(const Array& params, bool fHelp) +{ + if (fHelp || params.size() > 1) + throw runtime_error( + "makekeypair [prefix]\n" + "Make a public/private key pair.\n" + "[prefix] is optional preferred prefix for the public key.\n"); + + string strPrefix = ""; + if (params.size() > 0) + strPrefix = params[0].get_str(); + + CKey key; + CPubKey pubkey; + int nCount = 0; + do + { + key.MakeNewKey(false); + pubkey = key.GetPubKey(); + nCount++; + } while (nCount < 10000 && strPrefix != HexStr(pubkey.begin(), pubkey.end()).substr(0, strPrefix.size())); + + if (strPrefix != HexStr(pubkey.begin(), pubkey.end()).substr(0, strPrefix.size())) + return Value::null; + + Object result; + result.push_back(Pair("PublicKey", HexStr(pubkey.begin(), pubkey.end()))); + result.push_back(Pair("PrivateKey", CBitcoinSecret(key).ToString())); + return result; +}