From a14223238400209ace0fecdce615df865eecb685 Mon Sep 17 00:00:00 2001 From: sanket1729 Date: Tue, 2 Aug 2022 13:14:59 -0700 Subject: [PATCH] Allow dumpblinding key to accept non-CT address This facilitates the following workflow: 1) Obtain an updated psbt with in_witness_utxo and in_utxo_rangeproof 2) Get the blinding key from the input utxo address obtained from input script pubkey without revealing master blinding key 3) Rewind the proof to obtain blinding factors and implement stateless blinding --- src/wallet/rpcdump.cpp | 11 +++++------ test/functional/feature_confidential_transactions.py | 5 +++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 06250542a44..46ae01d02e5 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -2112,7 +2112,8 @@ RPCHelpMan importissuanceblindingkey() RPCHelpMan dumpblindingkey() { return RPCHelpMan{"dumpblindingkey", - "\nDumps the private blinding key for a CT address in hex.", + "\nDumps the private blinding key for a CT address in hex." + "\nNote: If the address is not a CT address, looks for blinding key corresponding to this non-CT address.", { {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The CT address"}, }, @@ -2134,17 +2135,15 @@ RPCHelpMan dumpblindingkey() if (!IsValidDestination(dest)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); } - if (!IsBlindDestination(dest)) { - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Not a CT address"); - } CScript script = GetScriptForDestination(dest); CKey key; key = pwallet->GetBlindingKey(&script); if (key.IsValid()) { CPubKey pubkey(key.GetPubKey()); - if (pubkey == GetDestinationBlindingKey(dest)) { - return HexStr(Span(key.begin(), key.size())); + if (IsBlindDestination(dest) && pubkey != GetDestinationBlindingKey(dest)) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "CT address blinding key does not match the blinding key in wallet"); } + return HexStr(Span(key.begin(), key.size())); } throw JSONRPCError(RPC_WALLET_ERROR, "Blinding key for address is unknown"); diff --git a/test/functional/feature_confidential_transactions.py b/test/functional/feature_confidential_transactions.py index 59156e741c3..cceed177281 100755 --- a/test/functional/feature_confidential_transactions.py +++ b/test/functional/feature_confidential_transactions.py @@ -272,6 +272,11 @@ def run_test(self): # Import the blinding key blindingkey = self.nodes[2].dumpblindingkey(address2) + + # Check that importing keys from non-CT address works as intended + blindingkey2 = self.nodes[2].dumpblindingkey(unconfidential_address2) + assert_equal(blindingkey, blindingkey2) + self.nodes[1].importblindingkey(address2, blindingkey) # Check the auditor's gettransaction and listreceivedbyaddress # Needs rescan to update wallet txns