@@ -669,7 +669,14 @@ UniValue dumpwallet(const JSONRPCRequest& request)
669669 CRavenExtKey b58extkey;
670670 b58extkey.SetKey (masterKey);
671671
672+ CExtPubKey pubkey;
673+ pubkey = masterKey.Neuter ();
674+
675+ CRavenExtPubKey b58extpubkey;
676+ b58extpubkey.SetKey (pubkey);
677+
672678 file << " # extended private masterkey: " << b58extkey.ToString () << " \n\n " ;
679+ file << " # extended public masterkey: " << b58extpubkey.ToString () << " \n\n " ;
673680 }
674681 }
675682
@@ -690,7 +697,14 @@ UniValue dumpwallet(const JSONRPCRequest& request)
690697 CRavenExtKey b58extkey;
691698 b58extkey.SetKey (masterKey);
692699
700+ CExtPubKey pubkey;
701+ pubkey = masterKey.Neuter ();
702+
703+ CRavenExtPubKey b58extpubkey;
704+ b58extpubkey.SetKey (pubkey);
705+
693706 file << " # extended private masterkey: " << b58extkey.ToString () << " \n\n " ;
707+ file << " # extended public masterkey: " << b58extpubkey.ToString () << " \n\n " ;
694708
695709 file << " # HD seed: " << HexStr (vchSeed) << " \n " ;
696710 file << " # mnemonic: " << std::string (vchWords.begin (), vchWords.end ()).c_str () << " \n " ;
@@ -729,6 +743,154 @@ UniValue dumpwallet(const JSONRPCRequest& request)
729743 return reply;
730744}
731745
746+ UniValue getmasterkeyinfo (const JSONRPCRequest& request)
747+ {
748+ CWallet * const pwallet = GetWalletForJSONRPCRequest (request);
749+ if (!EnsureWalletIsAvailable (pwallet, request.fHelp )) {
750+ return NullUniValue;
751+ }
752+
753+ if (request.fHelp || request.params .size () != 0 )
754+ throw std::runtime_error (
755+ " getmasterkeyinfo\n "
756+ " \n Fetches and displays the master private key and the master public key.\n "
757+ " \n Result:\n "
758+ " { (json object)\n "
759+ " \" bip32_root_private\" : (string) extended master private key,\n "
760+ " \" bip32_root_public\" : (string) extended master public key,\n "
761+ " \" account_derivation_path\" : (string) The derivation path to the account public/private keys\n "
762+ " \" account_extended_private_key\" : (string) extended account private key,\n "
763+ " \" account_extended_public_key\" : (string) extended account public key,\n "
764+ " }\n "
765+ " \n Examples:\n "
766+ + HelpExampleCli (" getmasterkeyinfo" , " " )
767+ + HelpExampleRpc (" getmasterkeyinfo" , " " )
768+ );
769+
770+ LOCK2 (cs_main, pwallet->cs_wallet );
771+
772+ EnsureWalletIsUnlocked (pwallet);
773+
774+ UniValue ret (UniValue::VOBJ);
775+
776+ // add the base58check encoded extended master if the wallet uses HD
777+ CKeyID seed_id = pwallet->GetHDChain ().seed_id ;
778+ if (!seed_id.IsNull ())
779+ {
780+
781+ if (!pwallet->GetHDChain ().IsBip44 ()) {
782+ CKey seed;
783+ if (pwallet->GetKey (seed_id, seed)) {
784+
785+ // Create the master key
786+ CExtKey masterKey;
787+ masterKey.SetSeed (seed.begin (), seed.size ());;
788+
789+ // Get the Raven Ext Key from the master key
790+ CRavenExtKey b58extkey;
791+ b58extkey.SetKey (masterKey);
792+
793+ // Get the public key from the master key
794+ CExtPubKey pubkey;
795+ pubkey = masterKey.Neuter ();
796+
797+ // Get the Raven Ext Key from the public key
798+ CRavenExtPubKey b58extpubkey;
799+ b58extpubkey.SetKey (pubkey);
800+
801+ // Add the private and public key to the output
802+ ret.push_back (std::make_pair (" bip32_root_private" , b58extkey.ToString ()));
803+ ret.push_back (std::make_pair (" bip32_root_public" , b58extpubkey.ToString ()));
804+ ret.push_back (std::make_pair (" account_derivation_path" , " m/0'" ));
805+
806+ CExtKey accountKey;
807+ // derive m/account'
808+ masterKey.Derive (accountKey, 0 | 0x80000000 );
809+
810+ // Create the account public key from the account private key
811+ CExtPubKey account_extended_public_key;
812+ account_extended_public_key = accountKey.Neuter ();
813+
814+ // Create the Raven Account Ext Private Key
815+ CRavenExtKey b58accountextprivatekey;
816+ b58accountextprivatekey.SetKey (accountKey);
817+
818+ // Create the Raven Account Ext Public Key
819+ CRavenExtPubKey b58actextpubkey;
820+ b58actextpubkey.SetKey (account_extended_public_key);
821+
822+ // Add the account extended public and private keys to the return
823+ ret.push_back (std::make_pair (" account_extended_private_key" , b58accountextprivatekey.ToString ()));
824+ ret.push_back (std::make_pair (" account_extended_public_key" , b58actextpubkey.ToString ()));
825+
826+ }
827+ }
828+
829+ if (pwallet->GetHDChain ().IsBip44 ())
830+ {
831+ CWalletDB walletdb (pwallet->GetDBHandle ());
832+
833+ std::vector<unsigned char > vchWords;
834+ std::vector<unsigned char > vchPassphrase;
835+ std::vector<unsigned char > vchSeed;
836+ uint256 hash;
837+
838+ pwallet->GetBip39Data (hash, vchWords, vchPassphrase, vchSeed);
839+
840+ // Create the master key
841+ CExtKey masterKey;
842+ masterKey.SetSeed (vchSeed.data (), vchSeed.size ());
843+
844+ // Get the Raven Ext Key from the master key
845+ CRavenExtKey b58extkey;
846+ b58extkey.SetKey (masterKey);
847+
848+ // Get the public key from the master key
849+ CExtPubKey pubkey;
850+ pubkey = masterKey.Neuter ();
851+
852+ // Get the Raven Ext Key from the public key
853+ CRavenExtPubKey b58extpubkey;
854+ b58extpubkey.SetKey (pubkey);
855+
856+ // Add the private and public key to the output
857+ ret.push_back (std::make_pair (" bip32_root_private" , b58extkey.ToString ()));
858+ ret.push_back (std::make_pair (" bip32_root_public" , b58extpubkey.ToString ()));
859+ std::string path = strprintf (" m/44'/%d'/%d'" , GetParams ().ExtCoinType (), 0 );
860+ ret.push_back (std::make_pair (" account_derivation_path" , path));
861+
862+ // Lets generate the account private and public keys
863+ CExtKey purposeKey;
864+ CExtKey coinTypeKey;
865+ CExtKey accountKey;
866+ // derive m/purpose'
867+ masterKey.Derive (purposeKey, 44 | 0x80000000 );
868+ // derive m/purpose'/coin_type'
869+ purposeKey.Derive (coinTypeKey, GetParams ().ExtCoinType () | 0x80000000 );
870+ // derive m/purpose'/coin_type'/account'
871+ coinTypeKey.Derive (accountKey, 0 | 0x80000000 );
872+
873+ // Create the account public key from the account private key
874+ CExtPubKey account_extended_public_key;
875+ account_extended_public_key = accountKey.Neuter ();
876+
877+ // Create the Raven Account Ext Private Key
878+ CRavenExtKey b58accountextprivatekey;
879+ b58accountextprivatekey.SetKey (accountKey);
880+
881+ // Create the Raven Account Ext Public Key
882+ CRavenExtPubKey b58actextpubkey;
883+ b58actextpubkey.SetKey (account_extended_public_key);
884+
885+ // Add the account extended public and private keys to the return
886+ ret.push_back (std::make_pair (" account_extended_private_key" , b58accountextprivatekey.ToString ()));
887+ ret.push_back (std::make_pair (" account_extended_public_key" , b58actextpubkey.ToString ()));
888+ }
889+ }
890+
891+ return ret;
892+ }
893+
732894
733895UniValue ProcessImport (CWallet * const pwallet, const UniValue& data, const int64_t timestamp)
734896{
0 commit comments