diff --git a/src/Makefile.am b/src/Makefile.am index 88e33df95..fe9a600d9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -358,6 +358,8 @@ crypto_libbitcoin_crypto_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_CONFIG_INCLUDES) crypto_libbitcoin_crypto_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) crypto_libbitcoin_crypto_a_SOURCES = \ crypto/common.h \ + crypto/bip39/bip39.h \ + crypto/bip39/bip39.c \ crypto/equihash.cpp \ crypto/equihash.h \ crypto/equihash.tcc \ diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 16b25ae81..095a11bdc 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -651,6 +651,7 @@ static const CRPCCommand vRPCCommands[] = { "wallet", "walletlock", &walletlock, true }, { "wallet", "walletpassphrasechange", &walletpassphrasechange, true }, { "wallet", "walletpassphrase", &walletpassphrase, true }, + { "wallet", "walletseedphrase", &walletseedphrase, true }, { "wallet", "z_listreceivedbyaddress",&z_listreceivedbyaddress,false }, { "wallet", "z_listreceivedaddress", &z_listreceivedaddress, false }, { "wallet", "z_getbalance", &z_getbalance, false }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 15c982d81..75f6bb54c 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -384,6 +384,7 @@ extern UniValue gettransaction(const UniValue& params, bool fHelp, const CPubKey extern UniValue backupwallet(const UniValue& params, bool fHelp, const CPubKey& mypk); extern UniValue keypoolrefill(const UniValue& params, bool fHelp, const CPubKey& mypk); extern UniValue walletpassphrase(const UniValue& params, bool fHelp, const CPubKey& mypk); +extern UniValue walletseedphrase(const UniValue& params, bool fHelp, const CPubKey& mypk); extern UniValue walletpassphrasechange(const UniValue& params, bool fHelp, const CPubKey& mypk); extern UniValue walletlock(const UniValue& params, bool fHelp, const CPubKey& mypk); extern UniValue encryptwallet(const UniValue& params, bool fHelp, const CPubKey& mypk); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 89d15f14f..98960f2ea 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -64,6 +64,7 @@ #include "komodo_defs.h" #include #include "rpchushwallet.h" +#include "crypto/bip39/bip39.h" using namespace std; @@ -2407,6 +2408,30 @@ static void LockWallet(CWallet* pWallet) pWallet->Lock(); } +UniValue walletseedphrase(const UniValue& params, bool fHelp, const CPubKey& mypk) +{ + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() > 1) + throw runtime_error( + "walletseedphrase\n" + "\nReturns HIP39 seedphrase of the current wallet." + + HelpRequiringPassphrase() + "\n" + "\nExamples:\n" + + HelpExampleCli("walletseedphrase", "") + + HelpExampleRpc("walletseedphrase", "") + ); + + LOCK2(cs_main, pwalletMain->cs_wallet); + UniValue seedphrase(UniValue::VSTR); + //TODO: Currently we just generate a random seedphrase + int strength = 256; + const char *mnemonic = mnemonic_generate(strength); + seedphrase = std::string(mnemonic); + return seedphrase; +} + UniValue walletpassphrase(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) @@ -8291,6 +8316,7 @@ static const CRPCCommand commands[] = { "wallet", "walletlock", &walletlock, true }, { "wallet", "walletpassphrasechange", &walletpassphrasechange, true }, { "wallet", "walletpassphrase", &walletpassphrase, true }, + { "wallet", "walletseedphrase", &walletseedphrase, true }, { "wallet", "z_listreceivedbyaddress", &z_listreceivedbyaddress, false }, { "wallet", "z_listunspent", &z_listunspent, false }, { "wallet", "z_getbalance", &z_getbalance, false },