Trait miniscript::psbt::PsbtExt
source · pub trait PsbtExt {
// Required methods
fn finalize_mut<C: Verification>(
&mut self,
secp: &Secp256k1<C>
) -> Result<(), Vec<Error>>;
fn finalize<C: Verification>(
self,
secp: &Secp256k1<C>
) -> Result<Psbt, (Psbt, Vec<Error>)>;
fn finalize_mall_mut<C: Verification>(
&mut self,
secp: &Secp256k1<C>
) -> Result<(), Vec<Error>>;
fn finalize_mall<C: Verification>(
self,
secp: &Secp256k1<C>
) -> Result<Psbt, (Psbt, Vec<Error>)>;
fn finalize_inp_mut<C: Verification>(
&mut self,
secp: &Secp256k1<C>,
index: usize
) -> Result<(), Error>;
fn finalize_inp<C: Verification>(
self,
secp: &Secp256k1<C>,
index: usize
) -> Result<Psbt, (Psbt, Error)>;
fn finalize_inp_mall_mut<C: Verification>(
&mut self,
secp: &Secp256k1<C>,
index: usize
) -> Result<(), Error>;
fn finalize_inp_mall<C: Verification>(
self,
secp: &Secp256k1<C>,
index: usize
) -> Result<Psbt, (Psbt, Error)>;
fn extract<C: Verification>(
&self,
secp: &Secp256k1<C>
) -> Result<Transaction, Error>;
fn update_input_with_descriptor(
&mut self,
input_index: usize,
descriptor: &Descriptor<DefiniteDescriptorKey>
) -> Result<(), UtxoUpdateError>;
fn update_output_with_descriptor(
&mut self,
output_index: usize,
descriptor: &Descriptor<DefiniteDescriptorKey>
) -> Result<(), OutputUpdateError>;
fn sighash_msg<T: Borrow<Transaction>>(
&self,
idx: usize,
cache: &mut SighashCache<T>,
tapleaf_hash: Option<TapLeafHash>
) -> Result<PsbtSighashMsg, SighashError>;
}
Expand description
Additional operations for miniscript descriptors for various psbt roles. Note that these APIs would generally error when used on scripts that are not miniscripts.
Required Methods§
sourcefn finalize_mut<C: Verification>(
&mut self,
secp: &Secp256k1<C>
) -> Result<(), Vec<Error>>
fn finalize_mut<C: Verification>( &mut self, secp: &Secp256k1<C> ) -> Result<(), Vec<Error>>
Finalize the psbt. This function takes in a mutable reference to psbt and populates the final_witness and final_scriptsig for all miniscript inputs.
Finalizes all inputs that it can finalize, and returns an error for each input that it cannot finalize. Also performs a sanity interpreter check on the finalized psbt which involves checking the signatures/ preimages/timelocks.
Input finalization also fails if it is not possible to satisfy any of the inputs non-malleably See finalizer::finalize_mall if you want to allow malleable satisfactions
For finalizing individual inputs, see also PsbtExt::finalize_inp
Errors:
- A vector of errors, one of each of failed finalized input
sourcefn finalize<C: Verification>(
self,
secp: &Secp256k1<C>
) -> Result<Psbt, (Psbt, Vec<Error>)>
fn finalize<C: Verification>( self, secp: &Secp256k1<C> ) -> Result<Psbt, (Psbt, Vec<Error>)>
Same as PsbtExt::finalize_mut
, but does not mutate the input psbt and
returns a new psbt
Errors:
- Returns a mutated psbt with all inputs
finalize_mut
could finalize - A vector of input errors, one of each of failed finalized input
sourcefn finalize_mall_mut<C: Verification>(
&mut self,
secp: &Secp256k1<C>
) -> Result<(), Vec<Error>>
fn finalize_mall_mut<C: Verification>( &mut self, secp: &Secp256k1<C> ) -> Result<(), Vec<Error>>
Same as PsbtExt::finalize_mut, but allows for malleable satisfactions
sourcefn finalize_mall<C: Verification>(
self,
secp: &Secp256k1<C>
) -> Result<Psbt, (Psbt, Vec<Error>)>
fn finalize_mall<C: Verification>( self, secp: &Secp256k1<C> ) -> Result<Psbt, (Psbt, Vec<Error>)>
Same as PsbtExt::finalize, but allows for malleable satisfactions
sourcefn finalize_inp_mut<C: Verification>(
&mut self,
secp: &Secp256k1<C>,
index: usize
) -> Result<(), Error>
fn finalize_inp_mut<C: Verification>( &mut self, secp: &Secp256k1<C>, index: usize ) -> Result<(), Error>
Same as PsbtExt::finalize_mut
, but only tries to finalize a single input leaving other
inputs as is. Use this when not all of inputs that you are trying to
satisfy are miniscripts
Errors:
- Input error detailing why the finalization failed. The psbt is not mutated when the finalization fails
sourcefn finalize_inp<C: Verification>(
self,
secp: &Secp256k1<C>,
index: usize
) -> Result<Psbt, (Psbt, Error)>
fn finalize_inp<C: Verification>( self, secp: &Secp256k1<C>, index: usize ) -> Result<Psbt, (Psbt, Error)>
Same as PsbtExt::finalize_inp_mut
, but does not mutate the psbt and returns a new one
Errors:
Returns a tuple containing
- Original psbt
- Input Error detailing why the input finalization failed
sourcefn finalize_inp_mall_mut<C: Verification>(
&mut self,
secp: &Secp256k1<C>,
index: usize
) -> Result<(), Error>
fn finalize_inp_mall_mut<C: Verification>( &mut self, secp: &Secp256k1<C>, index: usize ) -> Result<(), Error>
Same as PsbtExt::finalize_inp_mut
, but allows for malleable satisfactions
sourcefn finalize_inp_mall<C: Verification>(
self,
secp: &Secp256k1<C>,
index: usize
) -> Result<Psbt, (Psbt, Error)>
fn finalize_inp_mall<C: Verification>( self, secp: &Secp256k1<C>, index: usize ) -> Result<Psbt, (Psbt, Error)>
Same as PsbtExt::finalize_inp
, but allows for malleable satisfactions
sourcefn extract<C: Verification>(
&self,
secp: &Secp256k1<C>
) -> Result<Transaction, Error>
fn extract<C: Verification>( &self, secp: &Secp256k1<C> ) -> Result<Transaction, Error>
Psbt extractor as defined in BIP174 that takes in a psbt reference and outputs a extracted bitcoin::Transaction Also does the interpreter sanity check Will error if the final ScriptSig or final Witness are missing or the interpreter check fails.
sourcefn update_input_with_descriptor(
&mut self,
input_index: usize,
descriptor: &Descriptor<DefiniteDescriptorKey>
) -> Result<(), UtxoUpdateError>
fn update_input_with_descriptor( &mut self, input_index: usize, descriptor: &Descriptor<DefiniteDescriptorKey> ) -> Result<(), UtxoUpdateError>
Update PSBT input with a descriptor and check consistency of *_utxo
fields.
This is the checked version of update_with_descriptor_unchecked
. It checks that the
witness_utxo
and non_witness_utxo
are sane and have a script_pubkey
that matches the
descriptor. In particular, it makes sure pre-segwit descriptors always have non_witness_utxo
present (and the txid matches). If both witness_utxo
and non_witness_utxo
are present
then it also checks they are consistent with each other.
Hint: because of the segwit bug some PSBT signers require that non_witness_utxo
is
present on segwitv0 inputs regardless but this function doesn’t enforce this so you will
have to do this check its presence manually (if it is present this will check its
validity).
The descriptor
must not have any wildcards in it
otherwise an error will be returned however it can (and should) have extended keys in it.
sourcefn update_output_with_descriptor(
&mut self,
output_index: usize,
descriptor: &Descriptor<DefiniteDescriptorKey>
) -> Result<(), OutputUpdateError>
fn update_output_with_descriptor( &mut self, output_index: usize, descriptor: &Descriptor<DefiniteDescriptorKey> ) -> Result<(), OutputUpdateError>
Update PSBT output with a descriptor and check consistency of the output’s script_pubkey
This is the checked version of update_with_descriptor_unchecked
. It checks that the
output’s script_pubkey
matches the descriptor.
The descriptor
must not have any wildcards in it
otherwise an error will be returned however it can (and should) have extended keys in it.
sourcefn sighash_msg<T: Borrow<Transaction>>(
&self,
idx: usize,
cache: &mut SighashCache<T>,
tapleaf_hash: Option<TapLeafHash>
) -> Result<PsbtSighashMsg, SighashError>
fn sighash_msg<T: Borrow<Transaction>>( &self, idx: usize, cache: &mut SighashCache<T>, tapleaf_hash: Option<TapLeafHash> ) -> Result<PsbtSighashMsg, SighashError>
Get the sighash message(data to sign) at input index idx
.
Based on the sighash
flag specified in the Psbt
sighash field. If the input sighash flag psbt field is None
the sighash::TapSighashType::Default
is chosen
for for taproot spends, otherwise EcdsaSighashType::All
is chosen.
If the utxo at idx
is a taproot output, returns a PsbtSighashMsg::TapSighash
variant.
If the utxo at idx
is a pre-taproot segwit output, returns a PsbtSighashMsg::SegwitV0Sighash
variant.
For legacy outputs, returns a PsbtSighashMsg::LegacySighash
variant.
The tapleaf_hash
parameter can be used to specify which tapleaf script hash has to be computed. If
tapleaf_hash
is None
, and the output is taproot output, the key spend hash is computed. This parameter must be
set to None
while computing sighash for pre-taproot outputs.
The function also updates the sighash cache with transaction computed during sighash computation of this input
Arguments:
idx
: The input index of psbt to signcache
: TheSighashCache
for used to cache/read previously cached computationstapleaf_hash
: If the output is taproot, compute the sighash for this particular leaf.