SecretKey

Struct SecretKey 

Source
pub struct SecretKey(/* private fields */);
Expand description

An EdDSA secret key.

Implementations§

Source§

impl SecretKey

Source

pub fn to_bytes(&self) -> [u8; 32]

Convert this secret key to a byte array.

Source

pub fn as_bytes(&self) -> &[u8; 32]

View this secret key as a byte array.

Source

pub fn from_bytes(bytes: Vec<u8>) -> Result<SecretKey, SignatureError>

Construct a SecretKey from a slice of bytes.

§Example
use xpx_chain_crypto::SecretKey;
use xpx_chain_crypto::SECRET_KEY_LENGTH;
use xpx_chain_crypto::SignatureError;

let secret_key_bytes: [u8; SECRET_KEY_LENGTH] = [
   157, 097, 177, 157, 239, 253, 090, 096,
   186, 132, 074, 244, 146, 236, 044, 196,
   068, 073, 197, 105, 123, 050, 105, 025,
   112, 059, 172, 003, 028, 174, 127, 096, ];

let secret_key: SecretKey = SecretKey::from_bytes(secret_key_bytes.to_vec())?;
§Returns

A Result whose okay value is an EdDSA SecretKey or whose error value is an SignatureError wrapping the internal error that occurred.

Source

pub fn generate<T>(csprng: &mut T) -> SecretKey
where T: CryptoRng + Rng,

Generate a SecretKey from a csprng.

§Example
extern crate rand;
extern crate sha3;
extern crate xpx_chain_crypto;

use rand::Rng;
use rand::rngs::OsRng;
use sha3::Sha3_512;
use xpx_chain_crypto::PublicKey;
use xpx_chain_crypto::SecretKey;
use xpx_chain_crypto::Signature;

let mut csprng = OsRng{};
let secret_key: SecretKey = SecretKey::generate(&mut csprng);

Afterwards, you can generate the corresponding public:


let public_key: PublicKey = (&secret_key).into();
§Input

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

Trait Implementations§

Source§

impl AsRef<[u8]> for SecretKey

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for SecretKey

Source§

fn clone(&self) -> SecretKey

Returns a duplicate 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 Debug for SecretKey

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for SecretKey

Source§

fn default() -> SecretKey

Returns the “default value” for a type. Read more
Source§

impl Drop for SecretKey

Overwrite secret key material with null bytes when it goes out of scope.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a> From<&'a SecretKey> for ExpandedSecretKey

Source§

fn from(secret_key: &'a SecretKey) -> ExpandedSecretKey

Construct an ExpandedSecretKey from a SecretKey.

§Examples
use rand::Rng;
use rand::thread_rng;
use sha3::Sha3_512;
use xpx_chain_crypto::{SecretKey, ExpandedSecretKey};

let mut csprng = thread_rng();
let secret_key: SecretKey = SecretKey::generate(&mut csprng);
let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from(&secret_key);
Source§

impl<'a> From<&'a SecretKey> for PublicKey

Source§

fn from(secret_key: &SecretKey) -> PublicKey

Derive this public key from its corresponding SecretKey.

Auto Trait Implementations§

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> Clear for T

Source§

fn clear(&mut self)

Completely overwrites this value.
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> InitializableFromZeroed for T
where T: Default,

Source§

unsafe fn initialize(place: *mut T)

Called to initialize a place to a valid value, after it is set to all-bits-zero. Read more
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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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

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

Source§

fn vzip(self) -> V