diff --git a/bitcoin/src/psbt/map/input.rs b/bitcoin/src/psbt/map/input.rs index f59a6de76..79445d797 100644 --- a/bitcoin/src/psbt/map/input.rs +++ b/bitcoin/src/psbt/map/input.rs @@ -197,6 +197,22 @@ impl From for PsbtSighashType { } impl PsbtSighashType { + /// Ambiguous `ALL` sighash type, may refer to either [`EcdsaSighashType::All`] + /// or [`TapSighashType::All`]. + /// + /// This is equivalent to either `EcdsaSighashType::All.into()` or `TapSighashType::All.into()`. + /// For sighash types other than `ALL` use the ECDSA or Taproot sighash type directly. + /// + /// # Examples + /// + /// ``` + /// use bitcoin::{EcdsaSighashType, TapSighashType}; + /// use bitcoin::psbt::PsbtSighashType; + /// let ecdsa_sighash_anyone_can_pay: PsbtSighashType = EcdsaSighashType::AllPlusAnyoneCanPay.into(); + /// let tap_sighash_anyone_can_pay: PsbtSighashType = TapSighashType::AllPlusAnyoneCanPay.into(); + /// ``` + pub const ALL: PsbtSighashType = PsbtSighashType { inner: 0x01 }; + /// Returns the [`EcdsaSighashType`] if the [`PsbtSighashType`] can be /// converted to one. pub fn ecdsa_hash_ty(self) -> Result { @@ -545,4 +561,11 @@ mod test { assert_eq!(back.ecdsa_hash_ty(), Err(NonStandardSighashTypeError(nonstd))); assert_eq!(back.taproot_hash_ty(), Err(InvalidSighashTypeError(nonstd))); } + + #[test] + fn psbt_sighash_const_all() { + assert_eq!(PsbtSighashType::ALL.to_u32(), 0x01); + assert_eq!(PsbtSighashType::ALL.ecdsa_hash_ty().unwrap(), EcdsaSighashType::All); + assert_eq!(PsbtSighashType::ALL.taproot_hash_ty().unwrap(), TapSighashType::All); + } }