Skip to content

Miniscript

and()

and(Array<Policy>|...Policy) -> Policy

Create a Policy requiring that all of the given sub-policies are satisfied.

Can be called with variadic arguments as and($p1, $p2, ..), or with an array as and([ $p1, $p2, .. ]).

For example: and(pk($alice), older(3 days))

Also possible using the && operator: pk($alice) && older(3 days)

Unlike Miniscript's native and() policy which only accepts exactly 2 sub-policies, Minsc's and() and && also supports >2 by translating them into an N-of-N thresh() policy.

Aliased as: all()

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

or()

Create a Policy requiring that one of the given sub-policies is satisfied.

Can be called with variadic arguments as or($p1, $p2, ..), or with an array as or([ $p1, $p2, .. ]).

Execution probability weights may be provided using the @ operator. Miniscript uses this information to optimize for lower spending costs. When unspecified, the default weight is 1. This is only supported with 2 sub-policies, but they may be nested.

For example: or(pk($alice), pk($bob))
With weights: or(5@pk($alice), 1@or(2@pk($bob), 3@pk($charlie)))

Also possible using the || operator: pk($alice) || pk($bob)
With weights: 5@pk($alice) || (2@pk($bob) || 3@pk($charlie))

Unlike Miniscript's native or() policy which only accepts exactly 2 sub-policies, Minsc's or() and || also supports >2 by translating them into an 1-of-N thresh() policy.

Aliased as: any()

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

thresh()

thresh(k: Int, policies: Array<Policy>|...Policy) -> Policy

Create a Policy requiring that k of the given sub-policies are satisfied.

Can be called with variadic arguments as thresh(2, $p1, $p2, ..), or with an array as thresh(2, [ $p1, $p2, .. ]).

Also possible using the of operator: 2 of [ pk($alice), pk($bob), pk($charlie) ]

Execution probability weights are not supported in threshold policies.

Aliased as: multi()

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

pk()

pk(PubKey) -> Policy

Create a Policy requiring a signature by the PubKey.

PubKeys are automatically coerced into a Policy when used as such, making explicit pk() calls typically unnecessary. For example, wsh($alice && $bob) is equivalent to wsh(pk($alice) && pk($bob)).

(Not to be confused with pubkey())

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

after()

after(Int) -> Policy

Create a Policy requiring an absolute locktime (by-height or by-timestamp) to pass.

Supports human-readable dates formatted as yyyy-mm-ddT or yyyy-mm-ddThh:mm(Z).

For example: after(900000), after(2030-04-05T), after(2030-04-05T16:20)

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

older()

older(Int) -> Policy

Create a Policy requiring a relative locktime (by-block-count or by-seconds) to pass.

Supports human-readable durations formatted as N year(s)|month(s)|day(s)|week(s)|day(s)|hour(s)|second(s). Note that time durations are encoded in granularity of 512 seconds and rounded up (e.g. 513 seconds becomes 1024 seconds).

For example: older(5), older(10 days), older(1 month 3 weeks)

The heightwise keyword can be used as a prefix for block-count-estimated durations. For example, older(heightwise 1 day) is equivalent to older(144).

The blocks keyword may optionally be used as a suffix. This typically simply evaluates to the number, but also verifies that it does not cross the BIP68 limit of 65535 blocks – older(65536 blocks) will fail with an error, while older(65536) would work but possibly not as intended (interpreted as seconds).

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

sha256()

sha256(Hash) -> Policy

Create a Policy requiring the pre-image for the sha256 Hash to be revealed.

(Not to be confused with hash::sha256())

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

hash256()

hash256(Hash) -> Policy

Create a Policy requiring the pre-image for the hash256 Hash (double sha256) to be revealed.

(Not to be confused with hash::sha256d())

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

ripemd160()

ripemd160(Hash) -> Policy

Create a Policy requiring the pre-image for the ripemd160 Hash to be revealed.

(Not to be confused with hash::ripemd160())

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

hash160()

hash160(Hash) -> Policy

Create a Policy requiring the pre-image for the hash160 Hash (ripemd160 over sha256) to be revealed.

(Not to be confused with hash::hash160())

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

Policy

Construction Examples:

  • pk($alice)
  • and(pk($alice), older(3 days))
  • pk($alice) || pk($bob)
  • 2 of [ $alice, $bob, $charlie ]

→ See the Miniscript guide for more options.

Variations:

  • Policy<SinglePath> | Policy<MultiPath>
  • Policy<Definite> | Policy<Indefinite>

Coerces from:

  • PubKey – converted into a pk() policy
  • SecKey – converted into a PubKey, then to a pk() policy

Underlying type: miniscript::Policy

keys Array<PubKey>

is_definite Bool

is_wildcard Bool

is_multipath Bool

is_valid Bool

is_safe Bool

is_nonmalleable Bool

segwitv0()

segwitv0(Policy<Definite>) -> Script

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

tapscript()

tapscript(Policy<Definite>) -> Script

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

TRIVIAL Policy

UNSATISFIABLE Policy

likely Int

likely = 10