Struct schnorr_fun::Signature
source · pub struct Signature<S = Public> {
pub R: Point<EvenY>,
pub s: Scalar<S, Zero>,
}
Expand description
A Schnorr signature.
Fields§
§R: Point<EvenY>
The signature’s public nonce
s: Scalar<S, Zero>
The challenge response part of the signature.
Implementations§
source§impl<S> Signature<S>
impl<S> Signature<S>
sourcepub fn to_bytes(&self) -> [u8; 64]
pub fn to_bytes(&self) -> [u8; 64]
Serializes the signature as 64 bytes – First the 32-byte nonce x-coordinate and then the 32-byte challenge response scalar.
§Examples
let bytes = signature.to_bytes();
assert_eq!(signature.R.to_xonly_bytes(), bytes[..32]);
assert_eq!(signature.s.to_bytes(), bytes[32..]);
sourcepub fn as_tuple(&self) -> (Point<EvenY>, &Scalar<S, Zero>)
pub fn as_tuple(&self) -> (Point<EvenY>, &Scalar<S, Zero>)
Gets a reference to the signature components as a tuple.
§Examples
let (R, s) = signature.as_tuple();
sourcepub fn set_secrecy<M: Secrecy>(self) -> Signature<M>
pub fn set_secrecy<M: Secrecy>(self) -> Signature<M>
Marks the signature with a Secrecy
. If it is marked as Secret
the
operations (e.g. verification) on the signature should be done in constant
time.
§Examples
use schnorr_fun::{fun::marker::*, Signature};
let signature = Signature::random(&mut rand::thread_rng());
let secret_sig = signature.set_secrecy::<Secret>();
source§impl Signature<Public>
impl Signature<Public>
sourcepub fn random<R: RngCore>(rng: &mut R) -> Self
pub fn random<R: RngCore>(rng: &mut R) -> Self
Generates a uniformly distributed signature. It will be valid for an infinite number of messages on every key but computationally you will never be able to find one! Useful for testing.
§Examples
use schnorr_fun::Signature;
let random_signature = Signature::random(&mut rand::thread_rng());
sourcepub fn from_bytes(bytes: [u8; 64]) -> Option<Self>
pub fn from_bytes(bytes: [u8; 64]) -> Option<Self>
Deserializes a signature from the byte representation produced by to_bytes
.
This returns None
if the first 32 bytes were not a valid x-only key or the last 32 bytes were not a valid scalar.
§Examples
match Signature::from_bytes(bytes) {
Some(signature) => println!("the bytes were a valid encoding of a signature!"),
None => eprintln!("the bytes did *not* encode a valid signature"),
}
Trait Implementations§
source§impl<'de, S: Secrecy> BorrowDecode<'de> for Signature<S>
Available on crate feature bincode
only.
impl<'de, S: Secrecy> BorrowDecode<'de> for Signature<S>
bincode
only.source§fn borrow_decode<D: BorrowDecoder<'de>>(
decoder: &mut D
) -> Result<Self, DecodeError>
fn borrow_decode<D: BorrowDecoder<'de>>( decoder: &mut D ) -> Result<Self, DecodeError>
source§impl<'de, S: Secrecy> Deserialize<'de> for Signature<S>
Available on crate feature serde
only.
impl<'de, S: Secrecy> Deserialize<'de> for Signature<S>
serde
only.