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.
There was a problem hiding this comment.
Now both the interface and the RPC rely on the same CWallet::DeriveHDKey
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. |
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 |
32d7ebf to
3c88685
Compare
|
Why is |
It was done so that the the RPC error codes and messages are preserved. Also, looking at the discussions in #35436 (comment) it makes sense to collapse the error codes down based on how the errors are logged/displayed #35436 (comment) |
The derivehdkey RPC now calls it instead of repeating the watch-only, hardened path and unlock checks, so those errors change from -8 and -5 to -4.
Only the xpub is returned. interfaces::Wallet is not authenticated, so the private key is not passed over it.
3c88685 to
431f0d9
Compare
|
Rebased on master and rebuilt the history |
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:
requested path.
hardened path and unlock checks. Only the xpub argument parsing stays in the RPC.
key origin. Private key material does not cross the interface.
The RPC maps WalletErrorCode::UnlockNeeded to -13 so callers can prompt for a passphrase and retry, and everything else to -4, moving the unhardened path and failed derivation cases from -8 and the key selection cases from -5