From 671a104d2c7d9d1e1be316d6169d0f3f215be58c Mon Sep 17 00:00:00 2001 From: pasta Date: Wed, 12 Aug 2026 23:21:00 -0500 Subject: [PATCH 01/14] feat(wallet): derive masternode operator keys from seed --- src/Makefile.am | 2 + src/Makefile.test.include | 1 + src/interfaces/masternode_operator.h | 40 ++ src/interfaces/node.h | 4 + src/interfaces/wallet.h | 20 + src/node/interfaces.cpp | 9 + src/wallet/interfaces.cpp | 76 +++- src/wallet/masternode_operator.h | 25 ++ src/wallet/scriptpubkeyman.cpp | 75 +++- src/wallet/scriptpubkeyman.h | 19 + src/wallet/test/masternode_operator_tests.cpp | 396 ++++++++++++++++++ src/wallet/wallet.cpp | 329 +++++++++++++++ src/wallet/wallet.h | 47 ++- src/wallet/walletdb.cpp | 26 +- src/wallet/walletdb.h | 5 + 15 files changed, 1061 insertions(+), 13 deletions(-) create mode 100644 src/interfaces/masternode_operator.h create mode 100644 src/wallet/masternode_operator.h create mode 100644 src/wallet/test/masternode_operator_tests.cpp diff --git a/src/Makefile.am b/src/Makefile.am index fb1ffde2529a..c909c2db5aee 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -280,6 +280,7 @@ BITCOIN_CORE_H = \ interfaces/handler.h \ interfaces/init.h \ interfaces/ipc.h \ + interfaces/masternode_operator.h \ interfaces/node.h \ interfaces/wallet.h \ kernel/blockmanager_opts.h \ @@ -476,6 +477,7 @@ BITCOIN_CORE_H = \ wallet/hdchain.h \ wallet/ismine.h \ wallet/load.h \ + wallet/masternode_operator.h \ wallet/receive.h \ wallet/rpc/util.h \ wallet/rpc/wallet.h \ diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 427909b8e12f..f3ef0cee4e4d 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -224,6 +224,7 @@ if ENABLE_WALLET BITCOIN_TESTS += \ wallet/test/bip39_tests.cpp \ wallet/test/coinjoin_tests.cpp \ + wallet/test/masternode_operator_tests.cpp \ wallet/test/psbt_wallet_tests.cpp \ wallet/test/spend_tests.cpp \ wallet/test/wallet_tests.cpp \ diff --git a/src/interfaces/masternode_operator.h b/src/interfaces/masternode_operator.h new file mode 100644 index 000000000000..235a7e6a4377 --- /dev/null +++ b/src/interfaces/masternode_operator.h @@ -0,0 +1,40 @@ +// Copyright (c) 2026 The Dash Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_INTERFACES_MASTERNODE_OPERATOR_H +#define BITCOIN_INTERFACES_MASTERNODE_OPERATOR_H + +#include + +#include +#include +#include + +namespace interfaces { + +/** Result of a deterministic masternode operator-key operation. */ +enum class MasternodeOperatorKeyStatus : uint8_t { + SUCCESS, + NOT_SUPPORTED, + WALLET_LOCKED, + EXHAUSTED, + INVALID_KEY, + NOT_FOUND, + CONFLICT, + DATABASE_ERROR, + DERIVATION_ERROR, +}; + +/** A deterministic masternode operator key reserved by the wallet. */ +struct MasternodeOperatorKey { + SecureVector secret_key; + std::vector public_key; + std::string path; + uint32_t index{0}; + uint64_t reservation_id{0}; +}; + +} // namespace interfaces + +#endif // BITCOIN_INTERFACES_MASTERNODE_OPERATOR_H diff --git a/src/interfaces/node.h b/src/interfaces/node.h index ba85809416be..32b93f88d041 100644 --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -86,6 +86,10 @@ class MnEntry virtual const int32_t& getPoSePenalty() const = 0; virtual const int32_t& getRegisteredHeight() const = 0; virtual const uint16_t& getOperatorReward() const = 0; + //! Registered operator public key normalized to 48-byte basic-scheme serialization. + //! This is stable regardless of the transaction's original wire-scheme version; + //! an entry whose operator was revoked returns an empty vector. + virtual std::vector getOperatorPubKeyBytes() const = 0; virtual const uint256& getProTxHash() const = 0; }; diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index 7300f4286e99..3c3ff1273f1e 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -8,6 +8,7 @@ #include // For CAmount #include #include // For ChainClient +#include #include // For CKeyID and CScriptID (definitions needed in CTxDestination instantiation) #include