Adds a derivehdkey RPC that returns an xpub, or optionally the xprv, at an arbitrary BIP32 path (with at least one hardened step), derived from a wallet HD key.
The main use case is coordinating a multisig setup, where each participant shares an xpub derived at a hardened path (e.g. m/87h/0h/0h) distinct from their default single-signature descriptors. See the (updated) doc/multisig-tutorial.md and (updated) functional test to see how that workflow improves.
The first commits are some helpful helpers:
- key: add DeriveExtKey() helper - performs the actual derivation
- test: move parse_hd_keypath test to bip32_tests - from
psbt_wallet_tests - Have ParseHDKeypath handle h derivation marker
- util: reject out-of-range BIP32 keypath indices -
ParseHDKeypathwould previously map overflowing values withouthto hardened. - fuzz: check ParseHDKeypath/WriteHDKeypath round-trip
- rpc: ParsePathBIP32 helper
- refactor: add hardened derivation helper -
HasHardenedDerivation(), to enforce the "at least one hardened step" rule - wallet: generalize GetActiveHDPubKeys helper - extracts code from
gethdkeyswhichderivehdkeyneeds - wallet: add GetExtKey helper - reconstruct an xprv from a wallet xpub (analog of
GetKey()); behavior-preserving prep, also simplifiesgethdkeys.
Meat and potatoes:
- rpc: add derivehdkey - the RPC itself, plus the
UnusedKeyfilter onGetHDPubKeysthat drives key selection. - test: use derivehdkey in M-of-N multisig demo - rewrites the functional multisig test to use the RPC and
<0;1>syntax. - doc: use derivehdkey in multisig tutorial - same for the prose tutorial.