pub enum Descriptor<Pk: MiniscriptKey> {
    Bare(Bare<Pk>),
    Pkh(Pkh<Pk>),
    Wpkh(Wpkh<Pk>),
    Sh(Sh<Pk>),
    Wsh(Wsh<Pk>),
    Tr(Tr<Pk>),
}
Expand description

Script descriptor

Variants

Bare(Bare<Pk>)

A raw scriptpubkey (including pay-to-pubkey) under Legacy context

Pkh(Pkh<Pk>)

Pay-to-PubKey-Hash

Wpkh(Wpkh<Pk>)

Pay-to-Witness-PubKey-Hash

Sh(Sh<Pk>)

Pay-to-ScriptHash(includes nested wsh/wpkh/sorted multi)

Wsh(Wsh<Pk>)

Pay-to-Witness-ScriptHash with Segwitv0 context

Tr(Tr<Pk>)

Pay-to-Taproot

Implementations

Create a new pk descriptor

Create a new PkH descriptor

Create a new Wpkh descriptor Will return Err if uncompressed key is used

Create a new sh wrapped wpkh from Pk. Errors when uncompressed keys are supplied

Create a new sh for a given redeem script Errors when miniscript exceeds resource limits under p2sh context or does not type check at the top level

Create a new wsh descriptor from witness script Errors when miniscript exceeds resource limits under p2sh context or does not type check at the top level

Create a new sh wrapped wsh descriptor with witness script Errors when miniscript exceeds resource limits under wsh context or does not type check at the top level

Create a new bare descriptor from witness script Errors when miniscript exceeds resource limits under bare context or does not type check at the top level

Create a new sh wrapper for the given wpkh descriptor

Create a new sh wrapper for the given wsh descriptor

Create a new sh sortedmulti descriptor with threshold k and Vec of pks. Errors when miniscript exceeds resource limits under p2sh context

Create a new sh wrapped wsh sortedmulti descriptor from threshold k and Vec of pks Errors when miniscript exceeds resource limits under segwit context

Create a new wsh sorted multi descriptor Errors when miniscript exceeds resource limits under p2sh context

Create new tr descriptor Errors when miniscript exceeds resource limits under Tap context

Checks whether the descriptor is safe.

Checks whether all the spend paths in the descriptor are possible on the bitcoin network under the current standardness and consensus rules. Also checks whether the descriptor requires signatures on all spend paths and whether the script is malleable.

In general, all the guarantees of miniscript hold only for safe scripts. The signer may not be able to find satisfactions even if one exists.

Computes an upper bound on the weight of a satisfying witness to the transaction.

Assumes all ec-signatures are 73 bytes, including push opcode and sighash suffix. Includes the weight of the VarInts encoding the scriptSig and witness stack length.

Errors

When the descriptor is impossible to safisfy (ex: sh(OP_FALSE)).

Computes the Bitcoin address of the descriptor, if one exists

Some descriptors like pk() don’t have an address.

Errors

For raw/bare descriptors that don’t have an address.

Computes the scriptpubkey of the descriptor.

Computes the scriptSig that will be in place for an unsigned input spending an output with this descriptor. For pre-segwit descriptors, which use the scriptSig for signatures, this returns the empty script.

This is used in Segwit transactions to produce an unsigned transaction whose txid will not change during signing (since only the witness data will change).

Computes the the underlying script before any hashing is done. For Bare, Pkh and Wpkh this is the scriptPubkey; for ShWpkh and Sh this is the redeemScript; for the others it is the witness script.

Errors

If the descriptor is a taproot descriptor.

Computes the scriptCode of a transaction output.

The scriptCode is the Script of the previous transaction output being serialized in the sighash when evaluating a CHECKSIG & co. OP code.

Errors

If the descriptor is a taproot descriptor.

Returns satisfying non-malleable witness and scriptSig to spend an output controlled by the given descriptor if it possible to construct one using the satisfier S.

Returns a possilbly mallable satisfying non-malleable witness and scriptSig to spend an output controlled by the given descriptor if it possible to construct one using the satisfier S.

Attempts to produce a non-malleable satisfying witness and scriptSig to spend an output controlled by the given descriptor; add the data to a given TxIn output.

👎Deprecated: use has_wildcards instead

Whether or not the descriptor has any wildcards

Whether or not the descriptor has any wildcards i.e. /*.

Replaces all wildcards (i.e. /*) in the descriptor with a particular derivation index, turning it into a definite descriptor.

Panics

If index ≥ 2^31

👎Deprecated: use at_derivation_index instead

Deprecated name for [at_derivation_index].

Convert all the public keys in the descriptor to bitcoin::PublicKey by deriving them or otherwise converting them. All [bitcoin::XOnlyPublicKey]s are converted to by adding a default(0x02) y-coordinate.

This is a shorthand for:

    .expect("Valid ranged descriptor");
let derived_descriptor = descriptor.at_derivation_index(index).derived_descriptor(&secp);

and is only here really here for backwards compatbility. See at_derivation_index and [derived_descriptor] for more documentation.

Errors

This function will return an error if hardened derivation is attempted.

Parse a descriptor that may contain secret keys

Internally turns every secret key found into the corresponding public key and then returns a a descriptor that only contains public keys and a map to lookup the secret key given a public key.

Serialize a descriptor to string with its secret keys

Utility method for deriving the descriptor at each index in a range to find one matching script_pubkey.

If it finds a match then it returns the index it was derived at and the concrete descriptor at that index. If the descriptor is non-derivable then it will simply check the script pubkey against the descriptor and return it if it matches (in this case the index returned will be meaningless).

Convert all the public keys in the descriptor to bitcoin::PublicKey by deriving them or otherwise converting them. All [bitcoin::XOnlyPublicKey]s are converted to by adding a default(0x02) y-coordinate.

Examples
use miniscript::descriptor::{Descriptor, DescriptorPublicKey};
use miniscript::bitcoin::secp256k1;
use std::str::FromStr;

// test from bip 86
let secp = secp256k1::Secp256k1::verification_only();
let descriptor = Descriptor::<DescriptorPublicKey>::from_str("tr(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/0/*)")
    .expect("Valid ranged descriptor");
let result = descriptor.at_derivation_index(0).derived_descriptor(&secp).expect("Non-hardened derivation");
assert_eq!(result.to_string(), "tr(03cc8a4bc64d897bddc5fbc2f670f7a8ba0b386779106cf1223c6fc5d7cd6fc115)#6qm9h8ym");
Errors

This function will return an error if hardened derivation is attempted.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Run a predicate on every key in the descriptor, returning whether the predicate returned true for every key Read more
Run a predicate on every key in the descriptor, returning whether the predicate returned true for any key Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more

Parse an expression tree into a descriptor.

Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
Convert the object into an abstract policy
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Converts a descriptor using abstract keys to one using specific keys.

The associated output type. This must be Self<Q>.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.