This PR changes DescriptorScriptPubKeyMan to no longer handle relevant keys directly. Instead all keys for all DescriptorSPKMs will be handled by a new KeyManager
class which exists within CWallet
(a reference to it is passed to each DescriptorSPKM). This allows us to have a concept of a wallet HD key for descriptor wallets. This makes it easier to add new single key descriptors that use the same HD master key as the rest of the autogenerated descriptors (e.g. for taproot). Multisigs will also be easier as an xpub belonging to the wallet can be exported without needing to do weird things like descriptor introspection and guessing about which descriptor’s key to use.
KeyManager
is a class which handles all of the keys for DescriptorSPKMs. It contains the maps that hold the keys, deals with writing those keys to disk, and handles their encryption. Encryption keys are still managed by CWallet
but provided to KeyManager
through the WalletStorage
interface. Signing is still done through DescriptorScriptPubKeyMan::SignTransaction
however this will fetch the keys from KeyManager
rather than storing keys in the DescriptorSPKM to be used.
This change is backwards compatible. Although KeyManager
writes and uses keys in new keyman_key
and keyman_ckey
records, it will still write keys for each descriptor in walletdescriptorkey
and walletdescriptorckey
records. This allows a descriptor wallet created using this change to be opened by 22.0 and 0.21. Additionally, wallets created with older software will automatically be upgraded to using the KeyManager
at first loading. This is done in the background and does not require any user interaction (i.e. no passphrase required).