wallet: Add deriveHDKey interface - #36070
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36070. ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
concept ACK will review soon :) |
jeanpablojp
left a comment
There was a problem hiding this comment.
Concept ACK
Left some comments.
| return *xprv; | ||
| } | ||
|
|
||
| util::Expected<std::pair<CExtKey, KeyOriginInfo>, WalletError> CWallet::DeriveHDKey(const std::vector<uint32_t>& path, const std::optional<CExtPubKey>& hdkey) const |
There was a problem hiding this comment.
in a1250d2 wallet: Add deriveHDKey interface
All this is duplicated from RPC code. Why not just make both the interface and the RPC rely on the same code? Because of both using different code functions, they both return different error codes for same errors.
Also probably this commit could be split in different commits. First a preparatory commit that creates the DeriveHDKey function + testing, then a commit rebasing the RPC to use it, then a commit creating the interface. You can check #34861 for a commit structure idea :)
There was a problem hiding this comment.
Done. Split into "Add CWallet::DeriveHDKey" and "Add deriveHDKey interface".
On sharing code with the RPC: it already calls SelectHDKey(). What's left is the watch-only, hardened-path and unlock guards, which pin the error codes wallet_derivehdkey.py asserts (-4, -8, -13).
DeriveHDKey() returns GenericError for every failure, so routing the rest through it would turn "Unable to derive HD key at the requested path" from -8 into -5. Keeping -8 would need a new WalletErrorCode just so one caller can pick a different number, which src/wallet/types.h:48-50 warns against.
The GUI will need to select an HD key without going through the RPC, so move the selection out of derivehdkey into CWallet::SelectHDKey. It returns a WalletError so that a caller can tell a locked wallet apart from the other failures. The RPC checks for a locked wallet before calling it, so everything it gets back maps to RPC_INVALID_ADDRESS_OR_KEY.
a1250d2 to
6131eab
Compare
jeanpablojp
left a comment
There was a problem hiding this comment.
Reviewed again. Left one more comment on the new test.
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
Requiring a hardened step means the parent xpub cannot be used to work out the sibling keys.
Only the xpub is returned. interfaces::Wallet is not authenticated, so private keys should not be passed over it.
6131eab to
32d7ebf
Compare
|
From https://github.com/bitcoin/bitcoin/actions/runs/33532997440/job/100190403622?pr=36070: --- a/src/interfaces/wallet.h
+++ b/src/interfaces/wallet.h
@@ -34,19 +34,16 @@
#include <vector>
class ArgsManager;
-class CKeyID;
-class CPubKey;
class CScript;
class PartiallySignedTransaction;
class uint256;
enum class FeeReason;
enum class OutputType;
struct bilingual_str;
+
namespace wallet {
-struct CreatedTransactionResult;
class CCoinControl;
class CWallet;
-enum class AddressPurpose;
struct CRecipient;
struct WalletContext;
} // namespace wallet |
This PR adds a wallet interface for derivehdkey.
The motivation is the same as #35436 and #34861. The derivehdkey RPC exists (#32784), but the GUI does not go through RPC, so the logic is currently out of its reach. A dedicated wallet interface makes it available for multisig setup. Alongside the addhdkey interface, this lets the GUI add an HD key and derive a shareable xpub from it. Tracked as the deriveHDKey item in #35645.
Key changes: