Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: backport upstream changes #2

Closed
wants to merge 12 commits into from
Closed

Conversation

OttoAllmendinger
Copy link

@OttoAllmendinger OttoAllmendinger commented Oct 25, 2024

see commits for details

shesek and others added 12 commits October 25, 2024 15:38
Possible when all hardened derivation steps are shared among all paths
(or if there are none). Errors otherwise.
When working with Taproot descriptors you typically need to do an
annoying (and hard to discover) `match` statement to get the `Tr`
out of the descriptor, and then call accessors on that to get the
actual data out.

Add two new methods to `Descriptor` that directly access the internal
key and the taptree. Document that the actual leaves can be obtained by
calling `.iter` on the taptree.

Next, when a user is trying to sign a Taproot branch, they need to
obtain a TapLeafHash. We have internal code which does this (which I
have pulled into a helper function since there is some room to optimize
it there..) but no exposed code, forcing the user to go digging through
the rust-bitcoin docs to figure it out (including knowing the standard
Taproot leaf version, which is an arcane detail of the sort that
Miniscript otherwise hides).

Add a new method `leaf_hash` on Taproot miniscripts, so that the user
can directly obtain the leaf hashes.

Now you can write e.g.

for script in trdesc.tap_tree_iter() {
    let leaf_hash = script.leaf_hash();
    // Do whatever you want...
}

vs the previous code which was roughly

let tr = match trdesc {
    Descriptor::Tr(ref tr) => tr,
    _ => unreachable!("I know this is a Taproot descriptor"),
};
// Or tr.tap_tree().unwrap().iter() in case you miss the weirdly-named
// Tr::iter_scripts
for script in tr.iter_scripts() {
    // Hope you know your rust-bitcoin docs by heart, and also that
    // .encode is the way to convert a Miniscript to a Script!
    let leaf_hash = TapLeafHash::from_script(
        LeafVersion::TapScript,
        script.encode(),
    );
}
@OttoAllmendinger OttoAllmendinger changed the title backport master chore: backport upstream changes Oct 25, 2024
@OttoAllmendinger OttoAllmendinger marked this pull request as ready for review October 25, 2024 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants