Struct schnorr::Keypair

source ·
#[repr(C)]
pub struct Keypair { pub secret: SecretKey, pub public: PublicKey, }
Expand description

An Schnorr keypair.

Fields

secret: SecretKey

The secret half of this keypair.

public: PublicKey

The public half of this keypair.

Implementations

Convert this keypair to bytes.

Returns

An array of bytes, [u8; KEYPAIR_LENGTH]. The first SECRET_KEY_LENGTH of bytes is the SecretKey, and the next PUBLIC_KEY_LENGTH bytes is the PublicKey

Construct a Keypair from the bytes of a PublicKey and SecretKey.

Inputs
  • bytes: an &[u8] representing the scalar for the secret key, and a compressed Edwards-Y coordinate of a point on curve25519, both as bytes. (As obtained from Keypair::to_bytes().)
Warning

Absolutely no validation is done on the key. If you give this function bytes which do not represent a valid point, or which do not represent corresponding parts of the key, then your Keypair will be broken and it will be your fault.

Returns

A Result whose okay value is an Schnorr Keypair or whose error value is an SignatureError describing the error that occurred.

Generate an schnorr keypair.

Example
extern crate rand;
extern crate schnorr;


use rand::Rng;
use rand::OsRng;
use schnorr::Keypair;
use schnorr::Signature;

let mut csprng: OsRng = OsRng::new().unwrap();
let keypair: Keypair = Keypair::generate(&mut csprng);
Input

A CSPRNG with a fill_bytes() method, e.g. rand::ChaChaRng.

The caller must also supply a hash function which implements the Digest and Default traits, and which returns 512 bits of output. The standard hash function used is Blake2b-512,

Sign a message with this keypair’s secret key.

Verify a signature on a message with this keypair’s public key.

Trait Implementations

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Completely overwrites this value.

Returns the argument unchanged.

Called to initialize a place to a valid value, after it is set to all-bits-zero. Read more

Calls U::from(self).

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

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.