diff --git a/src/blsct/wallet/keyman.cpp b/src/blsct/wallet/keyman.cpp index 4c13c62a6e31c..3e790b3782552 100644 --- a/src/blsct/wallet/keyman.cpp +++ b/src/blsct/wallet/keyman.cpp @@ -458,6 +458,21 @@ blsct::PrivateKey KeyMan::GetMasterSeedKey() const return ret; } +blsct::PrivateKey KeyMan::GetPrivateViewKey() const +{ + if (!IsHDEnabled()) + throw std::runtime_error(strprintf("%s: the wallet has no HD enabled")); + + auto viewId = m_hd_chain.view_id; + + PrivateKey ret; + + if (!GetKey(viewId, ret)) + throw std::runtime_error(strprintf("%s: could not access the private view key", __func__)); + + return ret; +} + blsct::PrivateKey KeyMan::GetSpendingKey() const { if (!fSpendKeyDefined) diff --git a/src/blsct/wallet/keyman.h b/src/blsct/wallet/keyman.h index 833b1881d806f..c0633abb34763 100644 --- a/src/blsct/wallet/keyman.h +++ b/src/blsct/wallet/keyman.h @@ -135,6 +135,7 @@ class KeyMan : public Manager, public KeyRing CKeyID GetHashId(const blsct::PublicKey& blindingKey, const blsct::PublicKey& spendingKey) const; CTxDestination GetDestination(const CTxOut& txout) const; blsct::PrivateKey GetMasterSeedKey() const; + blsct::PrivateKey GetPrivateViewKey() const; blsct::PrivateKey GetSpendingKey() const; blsct::PrivateKey GetSpendingKeyForOutput(const CTxOut& out) const; blsct::PrivateKey GetSpendingKeyForOutput(const CTxOut& out, const CKeyID& id) const; diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index 634f754f977c4..13ad00d305440 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -712,6 +712,32 @@ RPCHelpMan getblsctseed() }; } + +RPCHelpMan getblsctviewkey() +{ + return RPCHelpMan{ + "getblsctviewkey", + "\nDumps the BLSCT wallet private view key, which can be used to observe the wallet history without being able to spend the transactions.\n" + "Note: This command is only compatible with BLSCT wallets.\n", + {}, + RPCResult{ + RPCResult::Type::STR, "viewkey", "The BLSCT wallet private view key"}, + RPCExamples{HelpExampleCli("getblsctviewkey", "") + HelpExampleRpc("getblsctseed", "")}, + [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { + const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); + if (!pwallet) return UniValue::VNULL; + + const CWallet& wallet = *pwallet; + const blsct::KeyMan& blsct_km = EnsureConstBlsctKeyMan(wallet); + + auto seed = blsct_km.GetMasterSeedKey(); + + return seed.GetScalar().GetString(); + }, + }; +} + + RPCHelpMan dumpwallet() { return RPCHelpMan{"dumpwallet", diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp index 80e46f385fb8a..0d44e6bb8372c 100644 --- a/src/wallet/rpc/wallet.cpp +++ b/src/wallet/rpc/wallet.cpp @@ -828,6 +828,7 @@ RPCHelpMan walletdisplayaddress(); // backup RPCHelpMan getblsctseed(); +RPCHelpMan getblsctviewkey(); RPCHelpMan dumpprivkey(); RPCHelpMan importprivkey(); RPCHelpMan importaddress(); @@ -907,6 +908,7 @@ Span GetWalletRPCCommands() {"wallet", &getaddressinfo}, {"wallet", &getbalance}, {"wallet", &getblsctseed}, + {"wallet", &getblsctviewkey}, {"wallet", &getnewaddress}, {"wallet", &getrawchangeaddress}, {"wallet", &getreceivedbyaddress},