Skip to content

Commit

Permalink
add rpc getblsctviewkey
Browse files Browse the repository at this point in the history
  • Loading branch information
alex v committed Aug 9, 2024
1 parent 8e14dba commit a9347aa
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/blsct/wallet/keyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/blsct/wallet/keyman.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions src/wallet/rpc/backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const CWallet> 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",
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/rpc/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ RPCHelpMan walletdisplayaddress();

// backup
RPCHelpMan getblsctseed();
RPCHelpMan getblsctviewkey();
RPCHelpMan dumpprivkey();
RPCHelpMan importprivkey();
RPCHelpMan importaddress();
Expand Down Expand Up @@ -907,6 +908,7 @@ Span<const CRPCCommand> GetWalletRPCCommands()
{"wallet", &getaddressinfo},
{"wallet", &getbalance},
{"wallet", &getblsctseed},
{"wallet", &getblsctviewkey},
{"wallet", &getnewaddress},
{"wallet", &getrawchangeaddress},
{"wallet", &getreceivedbyaddress},
Expand Down

0 comments on commit a9347aa

Please sign in to comment.