Skip to content

Descriptors API Reference

Resources:

wpkh()

Constructs a P2WPKH Descriptor with the given public key.

For example:

  • wpkh($alice)
  • wpkh(xpub661MyMwAqRbcGRXD6bfSCyz6kHu1rKqhLSz69rgSSagqfpLVwgibwu916Z2X6e5u3uj8P64HyjJrwhmpVWRAwWxneMTCanVevFyrMJAVqfy/0/9)
  • wpkh(03b2123025f45648c3f31fd4b7d3e1ec3344769ab3f53dec5af9b8a9a95385cbd5)

Rust source code: src/stdlib/miniscript.rs:N/A

When called with a Policy or SortedMulti, constructs a P2WSH Descriptor.

For example: wsh(pk($alice) && older(5))

wsh(Script) -> WshInfo

When called with a raw Script, constructs a WshInfo representation.

For example: wsh(`$alice OP_CHECKSIGVERIFY 5 OP_CSV`)

Descriptors can only represent scripts expressed as Miniscript. For raw Script, the WshInfo structure is used instead. See the raw Scripting guide for more details.

Rust source code: src/stdlib/miniscript.rs:N/A

tr()

tr(internal_key: PubKey) -> Descriptor<Tr>
tr(internal_key: PubKey, tree: Policy|Array<Policy>) -> Descriptor<Tr>
tr(tree: Policy|Array<Policy>) -> Descriptor<Tr>

tr(internal_key: PubKey, tree: Script|Array<Script>) -> TapInfo
tr(internal_key: PubKey, merkle_root: Hash) -> TapInfo
tr(tree: Script|Array<Script>) -> TapInfo

When called with a Miniscript Policy script tree or no tree (keypath-only), constructs a P2TR Descriptor.

When called with a raw Script tree or merkle_root hash, constructs a 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 full tr() documentation under the Taproot reference.

Rust source code: src/stdlib/taproot.rs:N/A

Constructs a legacy P2SH Descriptor with the given Policy|SortedMulti as the redeemScript.

For example: sh(pk($alice) && older(5))

sh(Descriptor<Wpkh|Wsh>) -> Descriptor<ShWpkh|ShWsh>

Wrap a Segwitv0 P2WPKH/P2WSH descriptor with a legacy P2SH descriptor, producing a P2SH-P2WPKH/P2SH-P2WSH descriptor.

For example: sh(wpkh($alice)), sh(wsh(pk($alice) && older(5)))

Rust source code: src/stdlib/miniscript.rs:N/A

pkh()

Constructs a legacy P2PKH Descriptor with the given public key.

Rust source code: src/stdlib/miniscript.rs:N/A

bare()

Constructs a bare descriptor, with the Policy used directly as the output's scriptPubKey.

Typically used for legacy P2PK: bare(pk($alice)), or just bare($alice)

Or for bare multi-sig: bare(multi(1, $alice, $bob)), bare(1 of [ $alice, $bob ])

Rust source code: src/stdlib/miniscript.rs:N/A

multi()

multi(threshold_k: Int, pks: Array<PubKey>|...PubKey) -> Policy

Require a signature by threshold_k of the public keys specified in pks.

The pks in the compiled Script will retain their original ordering.

Can be called with variadic arguments as multi(2, $alice, $bob, $charlie), or with an array as multi(2, [ $alice, $bob, $charlie ]).

Alias for: thresh()

While this is an alias to Miniscript's thresh() which technically returns a Policy and not a descriptor, it behaves and compiles identically as a descriptor multi() would. (see this comment)

Also see: BIP 383

Rust source code: src/stdlib/miniscript.rs:N/A

sortedmulti()

sortedmulti(threshold_k: Int, pks: Array<PubKey>|...PubKey) -> SortedMulti

Like multi(), expect that the pks in the compiled Script are sorted lexicographically.

Returns: The virtual SortedMulti type, represented as a tagged Array

Also see: BIP 383

Note that sortedmulti() must be used with wsh() or sh(). Using it under bare() or tr() descriptors is currently unsupported (by the underlying rust-miniscript library).

Rust source code: src/stdlib/miniscript.rs:N/A

Descriptor

Construction Examples:

  • wpkh(xpub661MyMwAqRbcFvXwqbgwi…cBX2nPX9KYVTz3cotpLmSkMxrp99L)
  • wsh(pk($alice) && older(2 days))
  • tr($alice, pk($bob) && older(3))
  • pkh(xpub661MyMwAqRbcFvXwqbgwi…cBX2nPX9KYVTz3cotpLmSkMxrp99L/<0;1>/*)
  • descriptor("wsh(and_v(v:pk(xpub661MyMwAqRbcFvXwqbgwi…cBX2nPX9KYVTz3cotpLmSkMxrp99L),older(1)))")

→ See the Descriptors guide for more.

Variations:

  • Descriptor<Tr> | Descriptor<Wpkh> | Descriptor<Wsh> | Descriptor<Pkh> | Descriptor<Sh> | Descriptor<ShWpkh> | Descriptor<ShWsh> | Descriptor<Bare>
  • Descriptor<SinglePath> | Descriptor<MultiPath>
  • Descriptor<Definite> | Descriptor<Indefinite>

Coerces from: (None)

Underlying type: miniscript::Descriptor

descriptor()

descriptor(String|Descriptor) -> Descriptor

Rust source code: src/stdlib/miniscript.rs:N/A

descriptor_type String

max_weight Int

singles Array<Descriptor<SinglePath>>

is_safe Bool

is_multipath Bool

is_wildcard Bool

is_definite Bool

Definite-only

The script_pubkey, explicit_script and witness_program fields are only available for definite descriptors - non-multi-path and with no underived /* wildcards.

script_pubkey Script opt

Also see:* scriptPubKey()

explicit_script Script opt

Only available for definite non-taproot descriptors

witness_program Int:Bytes opt

Only available for definite segwit descriptors

Taproot-only

The rest of the fields are only only available for Taproot tr() descriptors. Similar fields are mirrored on TapInfo.

internal_key PubKey opt

Also available for non-definite descriptors, returning the wildcard/multi-path PubKey used by the descriptor.

Taproot+Definite-only

The fields below are only only available for Taproot descriptors that are also definite.

output_key PubKey<SingleKey> opt

output_key_parity Int opt

The parity of the output key (0 for even, 1 for odd).

Only available for definite taproot descriptors.

merkle_root Hash opt

Only available for definite taproot descriptors with script paths.

script_tree TapNode opt

Only available for definite taproot descriptors with script paths.

scripts Array<Script> opt

Only available for definite taproot descriptors. Returns an empty array when there are no script paths.

WshInfo

Underlying type: minsc::WshInfo

script_pubkey Script

explicit_script Script

witness_program Int:Bytes

is_definite Bool

Always true

address_type String

Always "p2wsh"

SortedMulti