diff --git a/ecdsa/src/hazmat.rs b/ecdsa/src/hazmat.rs index 82560fc6..34e78e5f 100644 --- a/ecdsa/src/hazmat.rs +++ b/ecdsa/src/hazmat.rs @@ -60,40 +60,44 @@ where /// [`SignPrimitive`] for signature implementations that can provide public key /// recovery implementation. +#[cfg(feature = "arithmetic")] +#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))] pub trait RecoverableSignPrimitive where - C: Curve + Arithmetic, + C: Curve + ProjectiveArithmetic, + FieldBytes: From> + for<'r> From<&'r Scalar>, + Scalar: PrimeField>, SignatureSize: ArrayLength, { - /// Type for recoverable signatures - type RecoverableSignature: signature::Signature + Into>; - /// Try to sign the prehashed message. /// /// Accepts the same arguments as [`SignPrimitive::try_sign_prehashed`] /// but returns a boolean flag which indicates whether or not the /// y-coordinate of the computed 𝐑 = 𝑘×𝑮 point is odd, which can be /// incorporated into recoverable signatures. - fn try_sign_recoverable_prehashed + Invert>( + fn try_sign_recoverable_prehashed> + Invert>>( &self, ephemeral_scalar: &K, - hashed_msg: &C::Scalar, - ) -> Result; + hashed_msg: &Scalar, + ) -> Result<(Signature, bool), Error>; } +#[cfg(feature = "arithmetic")] impl SignPrimitive for T where - C: Curve + Arithmetic, + C: Curve + ProjectiveArithmetic, T: RecoverableSignPrimitive, + FieldBytes: From> + for<'r> From<&'r Scalar>, + Scalar: PrimeField>, SignatureSize: ArrayLength, { - fn try_sign_prehashed + Invert>( + fn try_sign_prehashed> + Invert>>( &self, ephemeral_scalar: &K, - hashed_msg: &C::Scalar, + hashed_msg: &Scalar, ) -> Result, Error> { self.try_sign_recoverable_prehashed(ephemeral_scalar, hashed_msg) - .map(Into::into) + .map(|res| res.0) } }