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>

source

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..]);
source

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();
source

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>

source

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());
source

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.
source§

fn borrow_decode<D: BorrowDecoder<'de>>( decoder: &mut D ) -> Result<Self, DecodeError>

Attempt to decode this type with the given BorrowDecode.
source§

impl<S: Clone> Clone for Signature<S>

source§

fn clone(&self) -> Signature<S>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<S> Debug for Signature<S>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the type as hex and any markers on the type.

source§

impl<S: Secrecy> Decode for Signature<S>

Available on crate feature bincode only.
source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>

Attempt to decode this type with the given Decode.
source§

impl<'de, S: Secrecy> Deserialize<'de> for Signature<S>

Available on crate feature serde only.
source§

fn deserialize<Deser: Deserializer<'de>>( deserializer: Deser ) -> Result<Signature<S>, Deser::Error>

Deserialize this value from the given Serde deserializer. Read more
source§

impl<S> Display for Signature<S>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Displays as hex.

source§

impl<S> Encode for Signature<S>

Available on crate feature bincode only.
source§

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>

Encode a given type.
source§

impl From<Signature> for Signature

source§

fn from(sig: Signature) -> Self

Converts to this type from the input type.
source§

impl From<Signature> for Signature

source§

fn from(sig: Signature) -> Self

Converts to this type from the input type.
source§

impl From<Signature> for Signature

source§

fn from(sig: Signature) -> Self

Converts to this type from the input type.
source§

impl From<Signature> for Signature

source§

fn from(sig: Signature) -> Self

Converts to this type from the input type.
source§

impl<S: Secrecy> FromStr for Signature<S>

source§

fn from_str(hex: &str) -> Result<Signature<S>, HexError>

Parses the string as hex and interprets tries to convert the resulting byte array into the desired value.

§

type Err = HexError

The associated error which can be returned from parsing.
source§

impl<S1, S2> PartialEq<Signature<S2>> for Signature<S1>

source§

fn eq(&self, rhs: &Signature<S2>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<S> Serialize for Signature<S>

Available on crate feature serde only.
source§

fn serialize<Ser: Serializer>( &self, serializer: Ser ) -> Result<Ser::Ok, Ser::Error>

Serialize this value into the given Serde serializer. Read more
source§

impl<S: Eq> Eq for Signature<S>

Auto Trait Implementations§

§

impl<S> RefUnwindSafe for Signature<S>
where S: RefUnwindSafe,

§

impl<S> Send for Signature<S>
where S: Send,

§

impl<S> Sync for Signature<S>
where S: Sync,

§

impl<S> Unpin for Signature<S>
where S: Unpin,

§

impl<S> UnwindSafe for Signature<S>
where S: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,