Enum miniscript::descriptor::Descriptor
source · 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§
source§impl<Pk: MiniscriptKey> Descriptor<Pk>
impl<Pk: MiniscriptKey> Descriptor<Pk>
sourcepub fn new_wpkh(pk: Pk) -> Result<Self, Error>
pub fn new_wpkh(pk: Pk) -> Result<Self, Error>
Create a new Wpkh descriptor Will return Err if uncompressed key is used
sourcepub fn new_sh_wpkh(pk: Pk) -> Result<Self, Error>
pub fn new_sh_wpkh(pk: Pk) -> Result<Self, Error>
Create a new sh wrapped wpkh from Pk
.
Errors when uncompressed keys are supplied
sourcepub fn new_sh(ms: Miniscript<Pk, Legacy>) -> Result<Self, Error>
pub fn new_sh(ms: Miniscript<Pk, Legacy>) -> Result<Self, Error>
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
sourcepub fn new_wsh(ms: Miniscript<Pk, Segwitv0>) -> Result<Self, Error>
pub fn new_wsh(ms: Miniscript<Pk, Segwitv0>) -> Result<Self, Error>
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
sourcepub fn new_sh_wsh(ms: Miniscript<Pk, Segwitv0>) -> Result<Self, Error>
pub fn new_sh_wsh(ms: Miniscript<Pk, Segwitv0>) -> Result<Self, Error>
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
sourcepub fn new_bare(ms: Miniscript<Pk, BareCtx>) -> Result<Self, Error>
pub fn new_bare(ms: Miniscript<Pk, BareCtx>) -> Result<Self, Error>
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
sourcepub fn new_sh_with_wpkh(wpkh: Wpkh<Pk>) -> Self
pub fn new_sh_with_wpkh(wpkh: Wpkh<Pk>) -> Self
Create a new sh wrapper for the given wpkh descriptor
sourcepub fn new_sh_with_wsh(wsh: Wsh<Pk>) -> Self
pub fn new_sh_with_wsh(wsh: Wsh<Pk>) -> Self
Create a new sh wrapper for the given wsh descriptor
sourcepub fn new_sh_sortedmulti(k: usize, pks: Vec<Pk>) -> Result<Self, Error>
pub fn new_sh_sortedmulti(k: usize, pks: Vec<Pk>) -> Result<Self, Error>
Create a new sh sortedmulti descriptor with threshold k
and Vec of pks
.
Errors when miniscript exceeds resource limits under p2sh context
sourcepub fn new_sh_wsh_sortedmulti(k: usize, pks: Vec<Pk>) -> Result<Self, Error>
pub fn new_sh_wsh_sortedmulti(k: usize, pks: Vec<Pk>) -> Result<Self, Error>
Create a new sh wrapped wsh sortedmulti descriptor from threshold
k
and Vec of pks
Errors when miniscript exceeds resource limits under segwit context
sourcepub fn new_wsh_sortedmulti(k: usize, pks: Vec<Pk>) -> Result<Self, Error>
pub fn new_wsh_sortedmulti(k: usize, pks: Vec<Pk>) -> Result<Self, Error>
Create a new wsh sorted multi descriptor Errors when miniscript exceeds resource limits under p2sh context
sourcepub fn new_tr(key: Pk, script: Option<TapTree<Pk>>) -> Result<Self, Error>
pub fn new_tr(key: Pk, script: Option<TapTree<Pk>>) -> Result<Self, Error>
Create new tr descriptor Errors when miniscript exceeds resource limits under Tap context
sourcepub fn desc_type(&self) -> DescriptorType
pub fn desc_type(&self) -> DescriptorType
Get the DescriptorType of Descriptor
sourcepub fn sanity_check(&self) -> Result<(), Error>
pub fn sanity_check(&self) -> Result<(), Error>
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.
sourcepub fn max_weight_to_satisfy(&self) -> Result<usize, Error>
pub fn max_weight_to_satisfy(&self) -> Result<usize, Error>
Computes an upper bound on the difference between a non-satisfied
TxIn
’s segwit_weight
and a satisfied TxIn
’s segwit_weight
Since this method uses segwit_weight
instead of legacy_weight
,
if you want to include only legacy inputs in your transaction,
you should remove 1WU from each input’s max_weight_to_satisfy
for a more accurate estimate.
In other words, for segwit inputs or legacy inputs included in segwit transactions, the following will hold for each input if that input was satisfied with the largest possible witness:
for i in 0..transaction.input.len() {
assert_eq!(
descriptor_for_input[i].max_weight_to_satisfy(),
transaction.input[i].segwit_weight() - TxIn::default().segwit_weight()
);
}
Instead, for legacy transactions, the following will hold for each input if that input was satisfied with the largest possible witness:
for i in 0..transaction.input.len() {
assert_eq!(
descriptor_for_input[i].max_weight_to_satisfy(),
transaction.input[i].legacy_weight() - TxIn::default().legacy_weight()
);
}
Assumes all ECDSA signatures are 73 bytes, including push opcode and sighash suffix. Assumes all Schnorr signatures are 66 bytes, including push opcode and sighash suffix.
Errors
When the descriptor is impossible to safisfy (ex: sh(OP_FALSE)).
sourcepub fn max_satisfaction_weight(&self) -> Result<usize, Error>
👎Deprecated: use max_weight_to_satisfy instead
pub fn max_satisfaction_weight(&self) -> Result<usize, Error>
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)).
source§impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk>
impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk>
sourcepub fn address(&self, network: Network) -> Result<Address, Error>
pub fn address(&self, network: Network) -> Result<Address, Error>
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.
sourcepub fn script_pubkey(&self) -> ScriptBuf
pub fn script_pubkey(&self) -> ScriptBuf
Computes the scriptpubkey of the descriptor.
sourcepub fn unsigned_script_sig(&self) -> ScriptBuf
pub fn unsigned_script_sig(&self) -> ScriptBuf
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).
sourcepub fn explicit_script(&self) -> Result<ScriptBuf, Error>
pub fn explicit_script(&self) -> Result<ScriptBuf, Error>
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.
sourcepub fn script_code(&self) -> Result<ScriptBuf, Error>
pub fn script_code(&self) -> Result<ScriptBuf, Error>
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.
sourcepub fn get_satisfaction<S>(
&self,
satisfier: S
) -> Result<(Vec<Vec<u8>>, ScriptBuf), Error>where
S: Satisfier<Pk>,
pub fn get_satisfaction<S>( &self, satisfier: S ) -> Result<(Vec<Vec<u8>>, ScriptBuf), Error>where S: Satisfier<Pk>,
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.
sourcepub fn get_satisfaction_mall<S>(
&self,
satisfier: S
) -> Result<(Vec<Vec<u8>>, ScriptBuf), Error>where
S: Satisfier<Pk>,
pub fn get_satisfaction_mall<S>( &self, satisfier: S ) -> Result<(Vec<Vec<u8>>, ScriptBuf), Error>where S: Satisfier<Pk>,
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.
source§impl Descriptor<DefiniteDescriptorKey>
impl Descriptor<DefiniteDescriptorKey>
sourcepub fn plan<P>(self, provider: &P) -> Result<Plan, Self>where
P: AssetProvider<DefiniteDescriptorKey>,
pub fn plan<P>(self, provider: &P) -> Result<Plan, Self>where P: AssetProvider<DefiniteDescriptorKey>,
Returns a plan if the provided assets are sufficient to produce a non-malleable satisfaction
If the assets aren’t sufficient for generating a Plan, the descriptor is returned
sourcepub fn plan_mall<P>(self, provider: &P) -> Result<Plan, Self>where
P: AssetProvider<DefiniteDescriptorKey>,
pub fn plan_mall<P>(self, provider: &P) -> Result<Plan, Self>where P: AssetProvider<DefiniteDescriptorKey>,
Returns a plan if the provided assets are sufficient to produce a malleable satisfaction
If the assets aren’t sufficient for generating a Plan, the descriptor is returned
source§impl Descriptor<DescriptorPublicKey>
impl Descriptor<DescriptorPublicKey>
sourcepub fn is_deriveable(&self) -> bool
👎Deprecated: use has_wildcards instead
pub fn is_deriveable(&self) -> bool
Whether or not the descriptor has any wildcards
sourcepub fn has_wildcard(&self) -> bool
pub fn has_wildcard(&self) -> bool
Whether or not the descriptor has any wildcards i.e. /*
.
sourcepub fn at_derivation_index(
&self,
index: u32
) -> Result<Descriptor<DefiniteDescriptorKey>, ConversionError>
pub fn at_derivation_index( &self, index: u32 ) -> Result<Descriptor<DefiniteDescriptorKey>, ConversionError>
Replaces all wildcards (i.e. /*
) in the descriptor with a particular derivation index,
turning it into a definite descriptor.
Errors
- If index ≥ 2^31
sourcepub fn derive(
&self,
index: u32
) -> Result<Descriptor<DefiniteDescriptorKey>, ConversionError>
👎Deprecated: use at_derivation_index instead
pub fn derive( &self, index: u32 ) -> Result<Descriptor<DefiniteDescriptorKey>, ConversionError>
Deprecated name for Self::at_derivation_index
.
sourcepub fn derived_descriptor<C: Verification>(
&self,
secp: &Secp256k1<C>,
index: u32
) -> Result<Descriptor<PublicKey>, ConversionError>
pub fn derived_descriptor<C: Verification>( &self, secp: &Secp256k1<C>, index: u32 ) -> Result<Descriptor<PublicKey>, ConversionError>
Convert all the public keys in the descriptor to bitcoin::PublicKey
by deriving them or
otherwise converting them. All bitcoin::secp256k1::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).unwrap().derived_descriptor(&secp).unwrap();
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.
sourcepub fn parse_descriptor<C: Signing>(
secp: &Secp256k1<C>,
s: &str
) -> Result<(Descriptor<DescriptorPublicKey>, KeyMap), Error>
pub fn parse_descriptor<C: Signing>( secp: &Secp256k1<C>, s: &str ) -> Result<(Descriptor<DescriptorPublicKey>, KeyMap), Error>
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.
sourcepub fn to_string_with_secret(&self, key_map: &KeyMap) -> String
pub fn to_string_with_secret(&self, key_map: &KeyMap) -> String
Serialize a descriptor to string with its secret keys
sourcepub fn find_derivation_index_for_spk<C: Verification>(
&self,
secp: &Secp256k1<C>,
script_pubkey: &Script,
range: Range<u32>
) -> Result<Option<(u32, Descriptor<PublicKey>)>, ConversionError>
pub fn find_derivation_index_for_spk<C: Verification>( &self, secp: &Secp256k1<C>, script_pubkey: &Script, range: Range<u32> ) -> Result<Option<(u32, Descriptor<PublicKey>)>, ConversionError>
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).
sourcepub fn is_multipath(&self) -> bool
pub fn is_multipath(&self) -> bool
Whether this descriptor contains a key that has multiple derivation paths.
sourcepub fn into_single_descriptors(
self
) -> Result<Vec<Descriptor<DescriptorPublicKey>>, Error>
pub fn into_single_descriptors( self ) -> Result<Vec<Descriptor<DescriptorPublicKey>>, Error>
Get as many descriptors as different paths in this descriptor.
For multipath descriptors it will return as many descriptors as there is “parallel” paths. For regular descriptors it will just return itself.
source§impl Descriptor<DefiniteDescriptorKey>
impl Descriptor<DefiniteDescriptorKey>
sourcepub fn derived_descriptor<C: Verification>(
&self,
secp: &Secp256k1<C>
) -> Result<Descriptor<PublicKey>, ConversionError>
pub fn derived_descriptor<C: Verification>( &self, secp: &Secp256k1<C> ) -> Result<Descriptor<PublicKey>, ConversionError>
Convert all the public keys in the descriptor to bitcoin::PublicKey
by deriving them or
otherwise converting them. All bitcoin::secp256k1::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).unwrap().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§
source§impl<Pk: Clone + MiniscriptKey> Clone for Descriptor<Pk>
impl<Pk: Clone + MiniscriptKey> Clone for Descriptor<Pk>
source§fn clone(&self) -> Descriptor<Pk>
fn clone(&self) -> Descriptor<Pk>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<Pk: MiniscriptKey> Debug for Descriptor<Pk>
impl<Pk: MiniscriptKey> Debug for Descriptor<Pk>
source§impl<Pk: MiniscriptKey> Display for Descriptor<Pk>
impl<Pk: MiniscriptKey> Display for Descriptor<Pk>
source§impl<Pk: MiniscriptKey> ForEachKey<Pk> for Descriptor<Pk>
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Descriptor<Pk>
source§impl<Pk: MiniscriptKey> From<Bare<Pk>> for Descriptor<Pk>
impl<Pk: MiniscriptKey> From<Bare<Pk>> for Descriptor<Pk>
source§impl<Pk: MiniscriptKey> From<Pkh<Pk>> for Descriptor<Pk>
impl<Pk: MiniscriptKey> From<Pkh<Pk>> for Descriptor<Pk>
source§impl<Pk: MiniscriptKey> From<Sh<Pk>> for Descriptor<Pk>
impl<Pk: MiniscriptKey> From<Sh<Pk>> for Descriptor<Pk>
source§impl<Pk: MiniscriptKey> From<Tr<Pk>> for Descriptor<Pk>
impl<Pk: MiniscriptKey> From<Tr<Pk>> for Descriptor<Pk>
source§impl<Pk: MiniscriptKey> From<Wpkh<Pk>> for Descriptor<Pk>
impl<Pk: MiniscriptKey> From<Wpkh<Pk>> for Descriptor<Pk>
source§impl<Pk: MiniscriptKey> From<Wsh<Pk>> for Descriptor<Pk>
impl<Pk: MiniscriptKey> From<Wsh<Pk>> for Descriptor<Pk>
source§impl<Pk> FromStr for Descriptor<Pk>where
Pk: MiniscriptKey + FromStr,
Pk::Sha256: FromStr,
Pk::Hash256: FromStr,
Pk::Ripemd160: FromStr,
Pk::Hash160: FromStr,
<Pk as FromStr>::Err: ToString,
<<Pk as MiniscriptKey>::Sha256 as FromStr>::Err: ToString,
<<Pk as MiniscriptKey>::Hash256 as FromStr>::Err: ToString,
<<Pk as MiniscriptKey>::Ripemd160 as FromStr>::Err: ToString,
<<Pk as MiniscriptKey>::Hash160 as FromStr>::Err: ToString,
impl<Pk> FromStr for Descriptor<Pk>where Pk: MiniscriptKey + FromStr, Pk::Sha256: FromStr, Pk::Hash256: FromStr, Pk::Ripemd160: FromStr, Pk::Hash160: FromStr, <Pk as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Sha256 as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Hash256 as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Ripemd160 as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Hash160 as FromStr>::Err: ToString,
source§impl<Pk> FromTree for Descriptor<Pk>where
Pk: MiniscriptKey + FromStr,
Pk::Sha256: FromStr,
Pk::Hash256: FromStr,
Pk::Ripemd160: FromStr,
Pk::Hash160: FromStr,
<Pk as FromStr>::Err: ToString,
<<Pk as MiniscriptKey>::Sha256 as FromStr>::Err: ToString,
<<Pk as MiniscriptKey>::Hash256 as FromStr>::Err: ToString,
<<Pk as MiniscriptKey>::Ripemd160 as FromStr>::Err: ToString,
<<Pk as MiniscriptKey>::Hash160 as FromStr>::Err: ToString,
impl<Pk> FromTree for Descriptor<Pk>where Pk: MiniscriptKey + FromStr, Pk::Sha256: FromStr, Pk::Hash256: FromStr, Pk::Ripemd160: FromStr, Pk::Hash160: FromStr, <Pk as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Sha256 as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Hash256 as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Ripemd160 as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Hash160 as FromStr>::Err: ToString,
source§impl<Pk: Hash + MiniscriptKey> Hash for Descriptor<Pk>
impl<Pk: Hash + MiniscriptKey> Hash for Descriptor<Pk>
source§impl<Pk: MiniscriptKey> Liftable<Pk> for Descriptor<Pk>
impl<Pk: MiniscriptKey> Liftable<Pk> for Descriptor<Pk>
source§impl<Pk: Ord + MiniscriptKey> Ord for Descriptor<Pk>
impl<Pk: Ord + MiniscriptKey> Ord for Descriptor<Pk>
source§fn cmp(&self, other: &Descriptor<Pk>) -> Ordering
fn cmp(&self, other: &Descriptor<Pk>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl<Pk: PartialEq + MiniscriptKey> PartialEq<Descriptor<Pk>> for Descriptor<Pk>
impl<Pk: PartialEq + MiniscriptKey> PartialEq<Descriptor<Pk>> for Descriptor<Pk>
source§fn eq(&self, other: &Descriptor<Pk>) -> bool
fn eq(&self, other: &Descriptor<Pk>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<Pk: PartialOrd + MiniscriptKey> PartialOrd<Descriptor<Pk>> for Descriptor<Pk>
impl<Pk: PartialOrd + MiniscriptKey> PartialOrd<Descriptor<Pk>> for Descriptor<Pk>
source§fn partial_cmp(&self, other: &Descriptor<Pk>) -> Option<Ordering>
fn partial_cmp(&self, other: &Descriptor<Pk>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<P, Q> TranslatePk<P, Q> for Descriptor<P>where
P: MiniscriptKey,
Q: MiniscriptKey,
impl<P, Q> TranslatePk<P, Q> for Descriptor<P>where P: MiniscriptKey, Q: MiniscriptKey,
source§fn translate_pk<T, E>(&self, t: &mut T) -> Result<Self::Output, TranslateErr<E>>where
T: Translator<P, Q, E>,
fn translate_pk<T, E>(&self, t: &mut T) -> Result<Self::Output, TranslateErr<E>>where T: Translator<P, Q, E>,
Converts a descriptor using abstract keys to one using specific keys.
§type Output = Descriptor<Q>
type Output = Descriptor<Q>
Self<Q>
.