Require explicit wildcard derivation for descriptor key types
This is a small issue that's been on my mind for a very long time. Fixes #324.
Our DescriptorSecretKey and DescriptorPublicKey types, upon creation, build extended keys that have a wildcard added by default. For example, creating a DescriptorSecretKey currently gives you something like this:
tprv8ZgxMBicQKsPdWuqM1t1CDRvQtQuBPyfL6GbhQwtxDKgUAVPbxmj71pRA8raTqLrec5LyTs5TqCxdABcZr77bt2KyWA5bizJHnC4g4ysm4h/*
This is a bit weird because... well you wouldn't often add a wildcard right there as your first derivation step. None of the bips do this. Rather, you often add wildcards once you've fully derived your key at the index you want it at. Moreover, you could not use our API as is to create unwildcarded DescriptorSecretKeys or DescriptorPublicKeys. This is an odd limitation of the code as it stands, because in reality those are totally possible; we just didn't allow it with the current code. I suspect we didn't get a lot of feedback on this simply because it's not a part of the API that is used much.
This PR addresses that, and creates extended keys the way you'd expect them:
let mnemonic = Mnemonic::from_string("awesome awesome awesome awesome awesome awesome awesome awesome awesome awesome awesome awesome".to_string()).unwrap();
let key = DescriptorSecretKey::new(Network::Testnet, &mnemonic, None);
// key = "tprv8ZgxMBicQKsPdWAHbugK2tjtVtRjKGixYVZUdL7xLHMgXZS6BFbFi1UDb1CHT25Z5PU1F9j7wGxwUiRhqz9E3nZRztikGUV6HoRDYcqPhM4"
From there you can extend them however you want, including adding a wildcard to it if you'd like, using a new method on the type, add_wildcard().
Changelog notice
## Changed
- The `DescriptorSecretKey::new` constructor does not produce an extended key with an automatic wildcard anymore [#853]
## Added
- The `DescriptorPublicKey::new` constructor [#853]
- New `DescriptorPublicKey::add_wildcard` method, which adds a wildcard to the derivation path of the descriptor [#853]
- New `DescriptorSecretKey::add_wildcard` method, which adds a wildcard to the derivation path of the descriptor [#853]
[#853]: https://github.com/bitcoindevkit/bdk-ffi/pull/853
Checklists
All Submissions:
- [x] I've signed all my commits
- [x] I followed the contribution guidelines
- [x] I ran
cargo fmtandcargo clippybefore committing
New Features:
- [x] I've added tests for the new feature
- [x] I've added docs for the new feature
I'll reply to the comments tomorrow thanks for the reviews!
Just FYI this is a breaking change on the BDK libraries' API, and so would come in on the 3.0 release. Still I'd like to make sure it's good and everyone is happy with it sooner than later so it doesn't sit halfway done for 2 months before we all need to take another look/review because we forgot all about it.
this is a breaking change on the BDK libraries' API
This was the only remaining Q I had (breaking change) and was just going to ask about it tomorrow at the call, but you addressed generally what I was wondering (plan)