Struct TaprootSpendInfo
pub struct TaprootSpendInfo { /* private fields */ }
Expand description
Represents taproot spending information.
Taproot output corresponds to a combination of a single public key condition (known as the internal key), and zero or more general conditions encoded in scripts organized in the form of a binary tree.
Taproot can be spent by either:
- Spending using the key path i.e., with secret key corresponding to the tweaked
output_key
. - By satisfying any of the scripts in the script spend path. Each script can be satisfied by providing a witness stack consisting of the script’s inputs, plus the script itself and the control block.
If one or more of the spending conditions consist of just a single key (after aggregation), the most likely key should be made the internal key. See BIP341 for more details on choosing internal keys for a taproot application.
Note: This library currently does not support annex.
Implementations§
§impl TaprootSpendInfo
impl TaprootSpendInfo
pub fn with_huffman_tree<C, I>(
secp: &Secp256k1<C>,
internal_key: XOnlyPublicKey,
script_weights: I,
) -> Result<TaprootSpendInfo, TaprootBuilderError>
pub fn with_huffman_tree<C, I>( secp: &Secp256k1<C>, internal_key: XOnlyPublicKey, script_weights: I, ) -> Result<TaprootSpendInfo, TaprootBuilderError>
Creates a new TaprootSpendInfo
from a list of scripts (with default script version) and
weights of satisfaction for that script.
See TaprootBuilder::with_huffman_tree
for more detailed documentation.
pub fn new_key_spend<C>(
secp: &Secp256k1<C>,
internal_key: XOnlyPublicKey,
merkle_root: Option<TapNodeHash>,
) -> TaprootSpendInfowhere
C: Verification,
pub fn new_key_spend<C>(
secp: &Secp256k1<C>,
internal_key: XOnlyPublicKey,
merkle_root: Option<TapNodeHash>,
) -> TaprootSpendInfowhere
C: Verification,
Creates a new key spend with internal_key
and merkle_root
. Provide None
for
the merkle_root
if there is no script path.
Note: As per BIP341
When the merkle root is None
, the output key commits to an unspendable script path
instead of having no script path. This is achieved by computing the output key point as
Q = P + int(hashTapTweak(bytes(P)))G
. See also TaprootSpendInfo::tap_tweak
.
Refer to BIP 341 footnote (‘Why should the output key always have a taproot commitment, even if there is no script path?’) for more details.
pub fn tap_tweak(&self) -> TapTweakHash
pub fn tap_tweak(&self) -> TapTweakHash
Returns the TapTweakHash
for this TaprootSpendInfo
i.e., the tweak using internal_key
and merkle_root
.
pub fn internal_key(&self) -> XOnlyPublicKey
pub fn internal_key(&self) -> XOnlyPublicKey
Returns the internal key for this TaprootSpendInfo
.
pub fn merkle_root(&self) -> Option<TapNodeHash>
pub fn merkle_root(&self) -> Option<TapNodeHash>
Returns the merkle root for this TaprootSpendInfo
.
pub fn output_key(&self) -> TweakedPublicKey
pub fn output_key(&self) -> TweakedPublicKey
Returns the output key (the key used in script pubkey) for this TaprootSpendInfo
.
pub fn output_key_parity(&self) -> Parity
pub fn output_key_parity(&self) -> Parity
Returns the parity of the output key. See also TaprootSpendInfo::output_key
.
pub fn script_map(
&self,
) -> &BTreeMap<(ScriptBuf, LeafVersion), BTreeSet<TaprootMerkleBranch>>
pub fn script_map( &self, ) -> &BTreeMap<(ScriptBuf, LeafVersion), BTreeSet<TaprootMerkleBranch>>
Returns a reference to the internal script map.
pub fn from_node_info<C>(
secp: &Secp256k1<C>,
internal_key: XOnlyPublicKey,
node: NodeInfo,
) -> TaprootSpendInfowhere
C: Verification,
pub fn from_node_info<C>(
secp: &Secp256k1<C>,
internal_key: XOnlyPublicKey,
node: NodeInfo,
) -> TaprootSpendInfowhere
C: Verification,
Computes the TaprootSpendInfo
from internal_key
and node
.
This is useful when you want to manually build a taproot tree without using
TaprootBuilder
.
pub fn control_block(
&self,
script_ver: &(ScriptBuf, LeafVersion),
) -> Option<ControlBlock>
pub fn control_block( &self, script_ver: &(ScriptBuf, LeafVersion), ) -> Option<ControlBlock>
Constructs a ControlBlock
for particular script with the given version.
§Returns
- If there are multiple control blocks possible, returns the shortest one.
- If the script is not contained in the
TaprootSpendInfo
, returnsNone
.
Trait Implementations§
§impl Clone for TaprootSpendInfo
impl Clone for TaprootSpendInfo
§fn clone(&self) -> TaprootSpendInfo
fn clone(&self) -> TaprootSpendInfo
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more