bdk icon indicating copy to clipboard operation
bdk copied to clipboard

Extend `IntoWalletDescriptor` Trait to Include `DerivedDescriptor`

Open KnowWhoami opened this issue 1 year ago • 2 comments

Describe the enhancement

  • Types implementing the IntoWalletDescriptor trait can currently be converted into ExtendedDescriptor and provide their corresponding KeyMap:

  • Currently, the IntoWalletDescriptor trait is exclusively defined for ExtendedDescriptors, which handle descriptors containing wildcards.

  • DerivedDescriptor, representing descriptors without wildcards, is currently excluded from the IntoWalletDescriptor trait. This enhancement proposes extending the trait to include DerivedDescriptor as well:

  • This enhancement will enable downstream users to create DerivedDescriptor instances for a keychain, leveraging all checks and validations performed by IntoWalletDescriptor and into_wallet_descriptor_checked.

Use case

  • Allow downstream users to seamlessly create DerivedDescriptor for their keychains.
  • Provide users with the benefit of using the comprehensive validation and conversion capabilities of the IntoWalletDescriptor trait 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 IntoWalletDescriptor lacks support for DerivedDescriptor, limiting users in creating fully validated descriptors for their keychains.

  • The validation checks performed in into_wallet_descriptor and into_wallet_descriptor_checked are applicable to DerivedDescriptor as well, with exceptions for specific checks like hardened derivation steps or wildcards.

  • Testing has shown that extending IntoWalletDescriptor to include DerivedDescriptor does 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.

KnowWhoami avatar Jul 10 '24 08:07 KnowWhoami