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

btc: convert pkscript_from_multisig() to Rust #1142

Merged
merged 2 commits into from
Nov 2, 2023

Conversation

benma
Copy link
Collaborator

@benma benma commented Oct 25, 2023

No description provided.

benma added 2 commits October 25, 2023 20:33
In preparation of converting the whole function to Rust.
Alternative implementation of this function based on rust-miniscript:

```
pub fn pkscript(
    multisig: &Multisig,
    keypath_change: u32,
    keypath_address: u32,
) -> Result<Vec<u8>, Error> {
    let pubkeys: Vec<bitcoin::PublicKey> = multisig
        .xpubs
        .iter()
        .map(|xpub| -> Result<bitcoin::PublicKey, ()> {
            bitcoin::PublicKey::from_slice(
                bip32::Xpub::from(xpub)
                    .derive(&[keypath_change, keypath_address])?
                    .public_key(),
            )
            .map_err(|_| ())
        })
        .collect::<Result<_, _>>()?;
    let sorted_multi = miniscript::descriptor::SortedMultiVec::<
        bitcoin::PublicKey,
        miniscript::Legacy,
    >::new(multisig.threshold as _, pubkeys)
    .map_err(|_| Error::InvalidInput)?;
    Ok(sorted_multi.encode().into_bytes())
}
```

This cost about 10kB of binary space. The manual implementation of
this commit costs nearly nothing.
@benma benma force-pushed the multisig-pkscript branch from 9c7949b to 4f7a1e3 Compare October 25, 2023 18:49
Copy link
Collaborator

@asi345 asi345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 👍

@benma benma merged commit 0b92aca into BitBoxSwiss:master Nov 2, 2023
1 check passed
@benma benma deleted the multisig-pkscript branch November 2, 2023 09:22
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.

2 participants