feat: add support for BIP-388 wallet policies#898
feat: add support for BIP-388 wallet policies#898trevarj wants to merge 4 commits intorust-bitcoin:masterfrom
Conversation
|
Closes #899 |
|
concept ACK. We do plan to implement musig and sortedmulti_a, but no timeline on that, and we can deal with it when we get to it. We are also working on overhauling our validation framework more broadly, which I think/hope should eliminate the need for your hack. (IIRC there are other instances of this hack, or at least something similar, because of our weird separation between So I'd be okay to undraft this. |
215e52e to
4a729f8
Compare
|
Did a force push to address the incompatibilities with the MSRV. |
Nice, I got side-tracked and explored adding musig, but got too far down in the muck and wanted to finish this first.
I will keep a lookout for this.
🫡 |
|
Trevor!! Can this be split up a bit mate? The wildcard display stuff, then maybe the |
|
API design suggestion but caveat this is not my repo so feel free to ignore me.
As far as semantics, it looks like the unit test prove the PR sufficiently to me. |
4a729f8 to
6387817
Compare
TOBIN! Thank you for the review
Split into four separate commits.
Seems better to me. Easier to track down the logic than having to find the TryFrom.
Done |
| WalletPolicyParseFromString(String), | ||
| /// Couldn't set key info on WalletPolicy | ||
| WalletPolicyInvalidKeyInfo, | ||
| } |
There was a problem hiding this comment.
I don't know the style here in this repo, leaving for @apoelstra to comment. This is a single big error for the whole module unlike how we do it in rust-bitcoin.
| impl FromStr for WalletPolicy { | ||
| type Err = WalletPolicyError; | ||
| fn from_str(s: &str) -> Result<Self, Self::Err> { s.try_into() } | ||
| } |
There was a problem hiding this comment.
Flagging that I'm not sure about the policy on this sort of thing in this repo. (by sort of thing I mean what could really be a blanket impl of FromStr using From<&str>.
|
Apart for the |
- Instead of accepting a closure to convert the Key type to a String, added type bounds to use Key: FromStr. - Added new error type XKeyParseError, which will be a wrapper for the error type on a Key's FromStr. XKeyParseError must implement From from that type. - Change visibility of parse_xkey_deriv to pub(crate) for later usage.
- two new derivation_path functions, `derivation_path` and `derivation_paths` that omit the path origin - a `wildcard` accessor function to get the Wildcard value
Implemented BIP-388 by introducing a new type, `WalletPolicy`, which can be used to create descriptor templates. The idea is pretty simple and only really required making a new type that implements `MiniscriptKey`, then the existing parser and `Translator` trait takes care of the rest. There are a few edge cases that require validation, which isn't so nice, but works for now. Test cases that require BIP-390 and BIP-387's sortedmulti_a are commented out and issues could arise with those test vectors when/if those BIPs are implemented. See `WalletPolicy`'s doc and the unit tests for usage.
6387817 to
945adb7
Compare
Implemented BIP-388 by introducing a new type,
WalletPolicy, which can be usedto create descriptor templates.
The idea is pretty simple and only really required making a new type that
implements
MiniscriptKey, then the existing parser andTranslatortraittakes care of the rest.
There are a few edge cases that require validation, which isn't so nice, but
works for now. Test cases that require BIP-390 and BIP-387's sortedmulti_a are
commented out and issues could arise with those test vectors when/if those BIPs
are implemented.
See
WalletPolicy's doc and the unit tests for usage.