@@ -106,6 +106,7 @@ use miniscript::{SigType, ToPublicKey};
106106use super :: utils:: SecpCtx ;
107107use crate :: descriptor:: { DescriptorMeta , XKeyUtils } ;
108108use crate :: psbt:: PsbtUtils ;
109+ use crate :: types:: IndexOutOfBoundsError ;
109110use crate :: wallet:: error:: MiniscriptPsbtError ;
110111
111112/// Identifier of a signer in the `SignersContainers`. Used as a key to find the right signer among
@@ -142,7 +143,7 @@ pub enum SignerError {
142143 /// The user canceled the operation
143144 UserCanceled ,
144145 /// Input index is out of range
145- InputIndexOutOfRange ,
146+ InputIndexOutOfRange ( IndexOutOfBoundsError ) ,
146147 /// The `non_witness_utxo` field of the transaction is required to sign this input
147148 MissingNonWitnessUtxo ,
148149 /// The `non_witness_utxo` specified is invalid
@@ -179,7 +180,7 @@ impl fmt::Display for SignerError {
179180 Self :: MissingKey => write ! ( f, "Missing private key" ) ,
180181 Self :: InvalidKey => write ! ( f, "The private key in use has the right fingerprint but derives differently than expected" ) ,
181182 Self :: UserCanceled => write ! ( f, "The user canceled the operation" ) ,
182- Self :: InputIndexOutOfRange => write ! ( f, "Input index out of range " ) ,
183+ Self :: InputIndexOutOfRange ( err ) => write ! ( f, "{err} " ) ,
183184 Self :: MissingNonWitnessUtxo => write ! ( f, "Missing non-witness UTXO" ) ,
184185 Self :: InvalidNonWitnessUtxo => write ! ( f, "Invalid non-witness UTXO" ) ,
185186 Self :: MissingWitnessUtxo => write ! ( f, "Missing witness UTXO" ) ,
@@ -195,6 +196,12 @@ impl fmt::Display for SignerError {
195196 }
196197}
197198
199+ impl From < IndexOutOfBoundsError > for SignerError {
200+ fn from ( err : IndexOutOfBoundsError ) -> Self {
201+ Self :: InputIndexOutOfRange ( err)
202+ }
203+ }
204+
198205#[ cfg( feature = "std" ) ]
199206impl std:: error:: Error for SignerError { }
200207
@@ -318,7 +325,7 @@ impl InputSigner for SignerWrapper<DescriptorXKey<Xpriv>> {
318325 secp : & SecpCtx ,
319326 ) -> Result < ( ) , SignerError > {
320327 if input_index >= psbt. inputs . len ( ) {
321- return Err ( SignerError :: InputIndexOutOfRange ) ;
328+ return Err ( IndexOutOfBoundsError :: new ( input_index , psbt . inputs . len ( ) ) ) ? ;
322329 }
323330
324331 if psbt. inputs [ input_index] . final_script_sig . is_some ( )
@@ -442,8 +449,14 @@ impl InputSigner for SignerWrapper<PrivateKey> {
442449 sign_options : & SignOptions ,
443450 secp : & SecpCtx ,
444451 ) -> Result < ( ) , SignerError > {
445- if input_index >= psbt. inputs . len ( ) || input_index >= psbt. unsigned_tx . input . len ( ) {
446- return Err ( SignerError :: InputIndexOutOfRange ) ;
452+ if input_index >= psbt. inputs . len ( ) {
453+ return Err ( IndexOutOfBoundsError :: new ( input_index, psbt. inputs . len ( ) ) ) ?;
454+ }
455+ if input_index >= psbt. unsigned_tx . input . len ( ) {
456+ return Err ( IndexOutOfBoundsError :: new (
457+ input_index,
458+ psbt. unsigned_tx . input . len ( ) ,
459+ ) ) ?;
447460 }
448461
449462 if psbt. inputs [ input_index] . final_script_sig . is_some ( )
@@ -834,8 +847,14 @@ fn compute_tap_sighash(
834847 input_index : usize ,
835848 extra : Option < taproot:: TapLeafHash > ,
836849) -> Result < ( sighash:: TapSighash , TapSighashType ) , SignerError > {
837- if input_index >= psbt. inputs . len ( ) || input_index >= psbt. unsigned_tx . input . len ( ) {
838- return Err ( SignerError :: InputIndexOutOfRange ) ;
850+ if input_index >= psbt. inputs . len ( ) {
851+ Err ( IndexOutOfBoundsError :: new ( input_index, psbt. inputs . len ( ) ) ) ?;
852+ }
853+ if input_index >= psbt. unsigned_tx . input . len ( ) {
854+ Err ( IndexOutOfBoundsError :: new (
855+ input_index,
856+ psbt. unsigned_tx . input . len ( ) ,
857+ ) ) ?;
839858 }
840859
841860 let psbt_input = & psbt. inputs [ input_index] ;
0 commit comments