Taproot¶
tr()
¶
tr(internal_key: PubKey) -> Descriptor<Tr>
Constructs a P2TR Descriptor with an explicit internal_key and no script paths (keypath-only).
For example:
Constructs a P2TR Descriptor with an explicit internal_key and a Taproot script tree expressed as Miniscript Policy.
If the policy has top-level OR branches or a 1-of-N threshold, the sub-policies will be split into separate Taproot script leaves
(structured based on the @ assigned execution probabilities, if provided).
Also accepts an array of policies, which is equivalent to a 1-of-N threshold policy between the array elements.
For example:
tr(tree: Policy|Array<Policy>) -> Descriptor<Tr>
Constructs a P2TR Descriptor with a Miniscript Policy tree and no explicit internal key.
If the policy includes an unencumbered key (may spend with no additional restrictions),
it will implicitly be promoted to the internal key and removed from the script tree.
If multiple exist, the most likely one will be chosen (based on the @ assigned execution probability).
If no unencumbered keys exists, NUMS will be used as the internal key.
The default NUMS used by tr() may be changed by setting TR_UNSPENDABLE.
For example:
tr(internal_key: PubKey, tree: Script|Array<Script>) -> TapInfo
tr(tree: Script|Array<Script>) -> TapInfo
Constructs a TapInfo with the given raw Script tree and optionally with an internal_key.
When called without an internal_key, NUMS will be used by default.
For example:
tr($alice, `$bob OP_CHECKSIG`)tr(NUMS, [ `$alice OP_CHECKSIG`, `$bob OP_CHEKCSIG` ])tr[ `$alice OP_CHECKSIG`, `$bob OP_CHECKSIG`, 2@`$charlie OP_CHECKSIG` ]
Constructs a TapInfo with the given merkle_root hash and internal_key.
Because the full script tree isn't provided, the resulting TapInfo supports key-path spends only and cannot be used to construct control blocks for script-path spends.
For example:
tr($alice, 0x4352c5df4ab2266ab1db28b4295b9508f798802bb6005a91a654c1e41ef71d10)
Rust source code: src/stdlib/taproot.rs:N/A
Descriptor<Tr> vs TapInfo
Descriptors can only represent Taproot trees expressed as Miniscript.
To represent trees with raw Script or trees known only by their merkle root hash, the TapInfo structure is used instead.
See the Taproot guide for more information.
tr::ctrl()
¶
tr::ctrl(
tap: Descriptor<Tr>|TapInfo|PsbtInput,
script_leaf: Script|Policy,
leaf_ver: LeafVersion = TapScript
) -> Bytes
Construct the Taproot Control Block for a script path spend through the given script_leaf.
If there are multiple possible control blocks, the shortest one is chosen.
When a PsbtInput is given, the control block is extracted from its tap_scripts field.
Throws: If the script_leaf is not contained in the tap tree.
Rust source code: src/stdlib/taproot.rs:N/A
tr::script_witness()
¶
tr::script_witness(
tap: Descriptor<Tr>|TapInfo|PsbtInput,
script_leaf: Script|Policy,
witness_stack: Array<Bytes> = [],
annex: Bytes = None,
) -> Array<Bytes>
Construct an input witness spending through the script_leaf path with the given witness_stack, and optionally with an annex.
The leaf version is assumed to be TapScript.
Throws: If the script_leaf is not contained in the tap tree.
Minsc source code: src/stdlib/btc.minsc:N/A
tr::tapinfo()
¶
tr::tapinfo(Descriptor<Tr>) -> TapInfo
Convert a Descriptor<Tr> into a TapInfo structure.
Should not typically be necessary.
Rust source code: src/stdlib/taproot.rs:N/A
TapInfo
¶
Miniscript-compatible Taproot trees are represented as a Descriptor<Tr> and not as a TapInfo, which is only used with raw Script or trees known only by their merkle root hash.
Construction Examples:
tr($alice, `$bob OP_CHECKSIG`)tr[ `$bob OP_CHECKSIG`, likely@`$charlie OP_CHECKSIGVERIFY 3 OP_CSV` ]tr(NUMS, 0x4352c5df4ab2266ab1db28b4295b9508f798802bb6005a91a654c1e41ef71d10)
Variations: (None)
Unlike the
Descriptor<Tr>type,TapInfos are alwaysDefiniteand contain public keys that are alwaysDefiniteandSingleKey. (The underlyingTaprootSpendInfocannot represent Xpubs, multi-path or wildcard keys.)
Coerces from:
Underlying type: bitcoin::TaprootSpendInfo
Similar fields are mirrored on Taproot P2TR Descriptors.
Also see:* scriptPubKey()
Always definite.
Always definite.
Get the parity of the output key (0 for even, 1 for odd)
Only available when there are script paths
Only available when there are script paths
Returns an empty array when there are no script paths
Always true
Always "p2tr"
The default unspendable NUMS key used by tr() when there are no internal key candidates. Can be overridden (shadowed over) in user-land code.
If set to false, Taproot compilation with no internal key candidates will fail with No viable internal key found instead of using a default NUMS.