Skip to content

Commit e00b5a2

Browse files
committed
[Stealth] Add dump stealth private keys and prefix
1 parent 85b140e commit e00b5a2

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

src/bdap/stealth.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
class CScript;
2020

2121
typedef std::vector<uint8_t> ec_point;
22-
typedef uint32_t stealth_bitfield;
2322

2423
const uint32_t MAX_STEALTH_NARRATION_SIZE = 48;
2524
const uint32_t MIN_STEALTH_RAW_SIZE = 1 + 33 + 1 + 33 + 1 + 1; // without checksum (4bytes) or version (1byte)
@@ -30,7 +29,7 @@ const size_t EC_UNCOMPRESSED_SIZE = 65;
3029
struct stealth_prefix
3130
{
3231
uint8_t number_bits;
33-
stealth_bitfield bitfield;
32+
uint32_t bitfield;
3433
};
3534

3635
class CStealthAddress

src/wallet/rpcdump.cpp

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -886,16 +886,41 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
886886
EnsureWalletIsUnlocked();
887887

888888
std::string strAddress = request.params[0].get_str();
889-
CDynamicAddress address;
890-
if (!address.SetString(strAddress))
891-
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dynamic address");
892-
CKeyID keyID;
893-
if (!address.GetKeyID(keyID))
894-
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
895-
CKey vchSecret;
896-
if (!pwalletMain->GetKey(keyID, vchSecret))
897-
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
898-
return CDynamicSecret(vchSecret).ToString();
889+
CTxDestination dest = DecodeDestination(strAddress);
890+
if (!IsValidDestination(dest))
891+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address " + strAddress);
892+
893+
if (dest.type() == typeid(CStealthAddress)) {
894+
CStealthAddress sxAddr = boost::get<CStealthAddress>(dest);
895+
if (!pwalletMain->GetStealthAddress(sxAddr.GetSpendKeyID(), sxAddr))
896+
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
897+
898+
UniValue result(UniValue::VOBJ);
899+
900+
result.push_back(Pair("scan_private_key", CDynamicSecret(sxAddr.scan_secret).ToString()));
901+
902+
CKey vchSpendSecret;
903+
if (!pwalletMain->GetKey(sxAddr.spend_secret_id, vchSpendSecret))
904+
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for spend address " + CDynamicAddress(sxAddr.spend_secret_id).ToString() + " is not known");
905+
906+
result.push_back(Pair("spend_private_key", CDynamicSecret(vchSpendSecret).ToString()));
907+
result.push_back(Pair("prefix_number_bits", (int)sxAddr.prefix.number_bits));
908+
result.push_back(Pair("prefix_bitfield", (int)sxAddr.prefix.bitfield));
909+
910+
return result;
911+
} else {
912+
CDynamicAddress address;
913+
if (!address.SetString(strAddress))
914+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dynamic address");
915+
CKeyID keyID;
916+
if (!address.GetKeyID(keyID))
917+
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
918+
CKey vchSecret;
919+
if (!pwalletMain->GetKey(keyID, vchSecret))
920+
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
921+
return CDynamicSecret(vchSecret).ToString();
922+
}
923+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unknown address type: " + strAddress + " Must be a standard or stealth address.");
899924
}
900925

901926
UniValue dumpbdapkeys(const JSONRPCRequest& request)

0 commit comments

Comments
 (0)