@@ -89,6 +89,65 @@ std::string DecodeDumpString(const std::string &str) {
|
|||||||
return ret.str();
|
return ret.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UniValue convertpassphrase(const UniValue& params, bool fHelp)
|
||||||
|
{
|
||||||
|
if (fHelp || params.size() < 1 || params.size() > 1)
|
||||||
|
throw runtime_error(
|
||||||
|
"convertpassphrase \"agamapassphrase\"\n"
|
||||||
|
"\nConverts Agama passphrase to a private key and WIF (for import with importprivkey).\n"
|
||||||
|
"\nArguments:\n"
|
||||||
|
"1. \"agamapassphrase\" (string, required) Agama passphrase\n"
|
||||||
|
"\nResult:\n"
|
||||||
|
"\"agamapassphrase\": \"agamapassphrase\", (string) Agama passphrase you entered\n"
|
||||||
|
"\"address\": \"komodoaddress\", (string) Address corresponding to your passphrase\n"
|
||||||
|
"\"pubkey\": \"publickeyhex\", (string) The hex value of the raw public key\n"
|
||||||
|
"\"privkey\": \"privatekeyhex\", (string) The hex value of the raw private key\n"
|
||||||
|
"\"wif\": \"wif\" (string) The private key in WIF format to use with 'importprivkey'\n"
|
||||||
|
"\nExamples:\n"
|
||||||
|
+ HelpExampleCli("convertpassphrase", "\"agamapassphrase\"")
|
||||||
|
+ HelpExampleRpc("convertpassphrase", "\"agamapassphrase\"")
|
||||||
|
);
|
||||||
|
|
||||||
|
bool fCompressed = true;
|
||||||
|
string strAgamaPassphrase = params[0].get_str();
|
||||||
|
|
||||||
|
UniValue ret(UniValue::VOBJ);
|
||||||
|
ret.push_back(Pair("agamapassphrase", strAgamaPassphrase));
|
||||||
|
|
||||||
|
CKey tempkey = DecodeSecret(strAgamaPassphrase);
|
||||||
|
/* first we should check if user pass wif to method, instead of passphrase */
|
||||||
|
if (!tempkey.IsValid()) {
|
||||||
|
/* it's a passphrase, not wif */
|
||||||
|
uint256 sha256;
|
||||||
|
CSHA256().Write((const unsigned char *)strAgamaPassphrase.c_str(), strAgamaPassphrase.length()).Finalize(sha256.begin());
|
||||||
|
std::vector<unsigned char> privkey(sha256.begin(), sha256.begin() + sha256.size());
|
||||||
|
privkey.front() &= 0xf8;
|
||||||
|
privkey.back() &= 0x7f;
|
||||||
|
privkey.back() |= 0x40;
|
||||||
|
CKey key;
|
||||||
|
key.Set(privkey.begin(),privkey.end(), fCompressed);
|
||||||
|
CPubKey pubkey = key.GetPubKey();
|
||||||
|
assert(key.VerifyPubKey(pubkey));
|
||||||
|
CKeyID vchAddress = pubkey.GetID();
|
||||||
|
|
||||||
|
ret.push_back(Pair("address", EncodeDestination(vchAddress)));
|
||||||
|
ret.push_back(Pair("pubkey", HexStr(pubkey)));
|
||||||
|
ret.push_back(Pair("privkey", HexStr(privkey)));
|
||||||
|
ret.push_back(Pair("wif", EncodeSecret(key)));
|
||||||
|
} else {
|
||||||
|
/* seems it's a wif */
|
||||||
|
CPubKey pubkey = tempkey.GetPubKey();
|
||||||
|
assert(tempkey.VerifyPubKey(pubkey));
|
||||||
|
CKeyID vchAddress = pubkey.GetID();
|
||||||
|
ret.push_back(Pair("address", EncodeDestination(vchAddress)));
|
||||||
|
ret.push_back(Pair("pubkey", HexStr(pubkey)));
|
||||||
|
ret.push_back(Pair("privkey", HexStr(tempkey)));
|
||||||
|
ret.push_back(Pair("wif", strAgamaPassphrase));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
UniValue importprivkey(const UniValue& params, bool fHelp)
|
UniValue importprivkey(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (!EnsureWalletIsAvailable(fHelp))
|
if (!EnsureWalletIsAvailable(fHelp))
|
||||||
|
|||||||
@@ -7977,6 +7977,7 @@ UniValue heirlist(const UniValue& params, bool fHelp)
|
|||||||
|
|
||||||
|
|
||||||
extern UniValue dumpprivkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
|
extern UniValue dumpprivkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
|
||||||
|
extern UniValue convertpassphrase(const UniValue& params, bool fHelp);
|
||||||
extern UniValue importprivkey(const UniValue& params, bool fHelp);
|
extern UniValue importprivkey(const UniValue& params, bool fHelp);
|
||||||
extern UniValue importaddress(const UniValue& params, bool fHelp);
|
extern UniValue importaddress(const UniValue& params, bool fHelp);
|
||||||
extern UniValue dumpwallet(const UniValue& params, bool fHelp);
|
extern UniValue dumpwallet(const UniValue& params, bool fHelp);
|
||||||
@@ -8012,6 +8013,7 @@ static const CRPCCommand commands[] =
|
|||||||
{ "wallet", "gettransaction", &gettransaction, false },
|
{ "wallet", "gettransaction", &gettransaction, false },
|
||||||
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, false },
|
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, false },
|
||||||
{ "wallet", "getwalletinfo", &getwalletinfo, false },
|
{ "wallet", "getwalletinfo", &getwalletinfo, false },
|
||||||
|
{ "wallet", "convertpassphrase", &convertpassphrase, true },
|
||||||
{ "wallet", "importprivkey", &importprivkey, true },
|
{ "wallet", "importprivkey", &importprivkey, true },
|
||||||
{ "wallet", "importwallet", &importwallet, true },
|
{ "wallet", "importwallet", &importwallet, true },
|
||||||
{ "wallet", "importaddress", &importaddress, true },
|
{ "wallet", "importaddress", &importaddress, true },
|
||||||
|
|||||||
Reference in New Issue
Block a user