pub trait SignerExt {
// Provided methods
fn public_key<C: Curve>(&self) -> C::PublicKey
where Self: Signer<C> { ... }
fn sign<C: Curve>(
&self,
msg: &[u8],
) -> impl Future<Output = Result<C::Signature, Self::Error>> + Send
where Self: Signer<C> { ... }
fn sign_recoverable<C: RecoverableCurve>(
&self,
msg: &[u8],
) -> impl Future<Output = Result<(C::Signature, C::RecoveryId), Self::Error>> + Send
where Self: RecoverableSigner<C> { ... }
fn cache_public_key<C: Curve>(self) -> CachePublicKey<C, Self>
where Self: Signer<C> + Sized { ... }
}Expand description
An extention trait for Signer.
Provided Methods§
Sourcefn public_key<C: Curve>(&self) -> C::PublicKeywhere
Self: Signer<C>,
fn public_key<C: Curve>(&self) -> C::PublicKeywhere
Self: Signer<C>,
Get the public key of the signer on a curve C.
This method forwards to Signer::public_key().
§Examples
use defuse_crypto::{SignerExt, ed25519::Ed25519};
let public_key = signer.public_key::<Ed25519>();Sourcefn sign<C: Curve>(
&self,
msg: &[u8],
) -> impl Future<Output = Result<C::Signature, Self::Error>> + Sendwhere
Self: Signer<C>,
fn sign<C: Curve>(
&self,
msg: &[u8],
) -> impl Future<Output = Result<C::Signature, Self::Error>> + Sendwhere
Self: Signer<C>,
Sign a given message and return a signature.
NOTE: implementations MAY require msg to be prehash (i.e. output
of cryptographic hash function) of a fixed length and return an error
otherwise. Check corresponding docs before using.
This method forwards to Signer::sign().
§Examples
use defuse_crypto::{Curve, SignerExt, ed25519::Ed25519};
let msg = b"message";
let signature = signer.sign::<Ed25519>(msg).await?;
assert!(Ed25519::verify(
&signer.public_key::<Ed25519>(),
msg,
&signature,
));Sourcefn sign_recoverable<C: RecoverableCurve>(
&self,
msg: &[u8],
) -> impl Future<Output = Result<(C::Signature, C::RecoveryId), Self::Error>> + Sendwhere
Self: RecoverableSigner<C>,
fn sign_recoverable<C: RecoverableCurve>(
&self,
msg: &[u8],
) -> impl Future<Output = Result<(C::Signature, C::RecoveryId), Self::Error>> + Sendwhere
Self: RecoverableSigner<C>,
Sign a given message and return a signature along with recovery id.
NOTE: implementations MAY require msg to be prehash (i.e. output
of cryptographic hash function) of a fixed length and return an error
otherwise. Check corresponding docs before using.
This method forwards to RecoverableSigner::sign_recoverable().
§Examples
use defuse_crypto::{RecoverableCurve, SignerExt, secp256k1::Secp256k1};
// secp256k1 signs over 32-byte prehash
let prehash = hex!("f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2");
let (sig, recovery_id) = signer.sign_recoverable::<Secp256k1>(&prehash).await?;
assert_eq!(
Secp256k1::recover(&prehash, &sig, recovery_id),
Some(signer.public_key::<Secp256k1>()),
);Sourcefn cache_public_key<C: Curve>(self) -> CachePublicKey<C, Self>
fn cache_public_key<C: Curve>(self) -> CachePublicKey<C, Self>
Calculate .public_key() and cache its value for
further invocations.
This might be useful if a signer performs some expensive key derivation underneath.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.