Skip to content

Commit

Permalink
Merge pull request #3 from HiroSatou/master
Browse files Browse the repository at this point in the history
Add makekeypair to generate ECDSA keys
  • Loading branch information
evan82 committed Apr 24, 2014
2 parents 54fd5f3 + ff3bb3d commit 0779d04
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
1 change: 1 addition & 0 deletions src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions src/rpcnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "net.h"
#include "bitcoinrpc.h"
#include "alert.h"
#include "base58.h"

using namespace json_spirit;
using namespace std;
Expand Down Expand Up @@ -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;
}

0 comments on commit 0779d04

Please sign in to comment.