Commit e36fea10 authored by Pavel Vasin's avatar Pavel Vasin

rpc: add blacknetkeypair

parent 3de1e704
This diff is collapsed.
......@@ -247,6 +247,7 @@ static const CRPCCommand vRPCCommands[] =
{ "validateaddress", &validateaddress, true, false, false },
{ "validatepubkey", &validatepubkey, true, false, false },
{ "verifymessage", &verifymessage, false, false, false },
{ "blacknetkeypair", &blacknetkeypair, true, true, false },
#ifdef ENABLE_WALLET
{ "getmininginfo", &getmininginfo, true, false, false },
......
......@@ -126,6 +126,7 @@ extern json_spirit::Value setaccount(const json_spirit::Array& params, bool fHel
extern json_spirit::Value getaccount(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getaddressesbyaccount(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value sendtoaddress(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value blacknetkeypair(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value burn(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value burnwallet(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value signmessage(const json_spirit::Array& params, bool fHelp);
......
......@@ -12,6 +12,8 @@
#include "util.h"
#include "wallet.h"
#include "walletdb.h"
#include "bip39_english.h"
#include "monocypher.h"
using namespace std;
using namespace json_spirit;
......@@ -290,6 +292,73 @@ Value sendtoaddress(const Array& params, bool fHelp)
return wtx.GetHash().GetHex();
}
bool crypto_blacknet_sk_check_version(const uint8_t sk[32])
{
return (sk[0] & 0xF0) == 0x10;
}
bool crypto_blacknet_mnemonic_sk(const SecureString& mnemonic, uint8_t sk[32])
{
crypto_blake2b_general(sk, 32, NULL, 0, (const uint8_t*)mnemonic.data(), mnemonic.length());
return crypto_blacknet_sk_check_version(sk);
}
bool crypto_blacknet_mnemonic_keypair(const SecureString& mnemonic, uint8_t pk[32], uint8_t sk[32])
{
if (!crypto_blacknet_mnemonic_sk(mnemonic, sk))
return false;
crypto_sign_public_key(pk, sk);
return true;
}
bool crypto_blacknet_mnemonic_check_version(const SecureString& mnemonic)
{
uint8_t sk[32];
bool ret = crypto_blacknet_mnemonic_sk(mnemonic, sk);
crypto_wipe(sk, sizeof(sk));
return ret;
}
SecureString crypto_blacknet_mnemonic()
{
const int words = 12; // 132 bits = 4 bits version + 128 bits seed
uint16_t seed[words];
SecureString mnemonic;
mnemonic.reserve(108);
while (true) {
RAND_bytes((unsigned char*)seed, sizeof(seed));
for (int i = 0; i < words; i++) {
mnemonic += bip39_english[seed[i] % 2048];
if (i < words - 1) mnemonic += ' ';
}
if (crypto_blacknet_mnemonic_check_version(mnemonic))
break;
mnemonic.clear();
}
crypto_wipe(seed, sizeof(seed));
return mnemonic;
}
Value blacknetkeypair(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 0)
throw runtime_error(
"blacknetkeypair\n"
"Make a public/private key pair.\n");
SecureString mnemonic = crypto_blacknet_mnemonic();
uint8_t pk[32], sk[32];
assert(crypto_blacknet_mnemonic_keypair(mnemonic, pk, sk));
crypto_wipe(sk, sizeof(sk));
Object result;
result.push_back(Pair("Mnemonic (private key)", mnemonic.c_str()));
result.push_back(Pair("PublicKey", HexStr(BEGIN(pk), END(pk))));
return result;
}
Value burn(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
......@@ -353,7 +422,7 @@ Value burnwallet(const Array& params, bool fHelp)
EnsureWalletIsUnlocked();
if (!fForce) {
if (scriptPubKey.size() <= 32)
if (scriptPubKey.size() < 34)
throw JSONRPCError(RPC_WALLET_ERROR, "Warning: small data");
if (pwalletMain->GetUnconfirmedBalance() != 0)
throw JSONRPCError(RPC_WALLET_ERROR, "Warning: Unconfirmed Balance != 0");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment