This PR adds a wallet interface for addhdkey.
The motivation is same as #34861 - while we have addhdkey RPC, Bitcoin Core GUI does not use the RPC interface. Having a dedicated wallet interface is helpful for GUI when performing multisig setup. When used in tandem with a similar interface for derivehdkey (#32784), the GUI can produce a shareable xpub during multisig setup.
Key changes:
Introduce
wallet::AddHDKey()helper in a newhd_keys.{h,cpp}. The core logic from RPC is moved to this helper.Introduce
wallet::AddHDKeyResultwhich is a struct that wraps the resulting master xpub and its fingerprint.Introduce a concrete error enum
wallet::AddHDKeyError. Caller can useAddHDKeyErrorString()to convert the error to translatable user-facing messages.Update
addhdkeyRPC to use the above wallet helper. The RPC also exposes the master fingerprint in hex asfingerprintfield.<details> <summary>Sample Output</summary>
$ build/bin/bitcoin-cli -rpcwallet=Alice addhdkey { "fingerprint": "d2f7b7da", "xpub": "tpubD6NzVbkrYhZ4YKrGrgkAbx4HuqDxKDMzJMsipFMd2VzFaaxLMBXZ9uzqCmbpRXWHVoS2Q6WgY4K1mUbvdhcDQEDs6VjNHQmnTcHQKAyDzUf" }</details>
Add
interfaces::Wallet::addHDKey(), a new interface that GUI can call. Only the fingerprint is returned, the master xpub is intentionally not returned.Update
test/functional/wallet_hd.pyto assert the new fingerprint field.