Extend `IntoWalletDescriptor` Trait to Include `DerivedDescriptor`
Describe the enhancement
-
Types implementing the
IntoWalletDescriptortrait can currently be converted intoExtendedDescriptorand provide their correspondingKeyMap: -
Currently, the
IntoWalletDescriptortrait is exclusively defined forExtendedDescriptors, which handle descriptors containing wildcards. -
DerivedDescriptor, representing descriptors without wildcards, is currently excluded from theIntoWalletDescriptortrait. This enhancement proposes extending the trait to includeDerivedDescriptoras well: -
This enhancement will enable downstream users to create
DerivedDescriptorinstances for a keychain, leveraging all checks and validations performed byIntoWalletDescriptorandinto_wallet_descriptor_checked.
Use case
- Allow downstream users to seamlessly create
DerivedDescriptorfor their keychains. - Provide users with the benefit of using the comprehensive validation and conversion capabilities of the
IntoWalletDescriptortrait and its associated functions. - Eliminate the need for users to manually perform validation and conversion tasks when dealing with
DerivedDescriptor.
Additional context
-
The current implementation of
IntoWalletDescriptorlacks support forDerivedDescriptor, limiting users in creating fully validated descriptors for their keychains. -
The validation checks performed in
into_wallet_descriptorandinto_wallet_descriptor_checkedare applicable toDerivedDescriptoras well, with exceptions for specific checks like hardened derivation steps or wildcards. -
Testing has shown that extending
IntoWalletDescriptorto includeDerivedDescriptordoes not break existing code, as shown:#[test] fn test() { let secp = Secp256k1::new(); let desc_string = "wpkh(tprv8ZgxMBicQKsPdpkqS7Eair4YxjcuuvDPNYmKX3sCniCf16tHEVrjjiSXEkFRnUH77yXc6ZcwHHcLNfjdi5qUvw3VDfgYiH5mNsj5izuiu2N/1/2)#spaum87w"; let (descriptor, keymap) = desc_string .into_wallet_descriptor(&secp, Network::Testnet) .expect("failed to parse & validate descriptor"); println!("descriptor: {:?}\n", descriptor); println!("keymap: {:?}", keymap); } -
Internal BDK structures, such as those in functions like
reveal_next_spk, are already designed to handle descriptors with and without wildcards accordingly. -
Several mentions in the BDK codebase already account for DerivedDescriptors, indicating that this enhancement aligns with the existing structure and design of the library.