[][src]Struct emerald_rs::PrivateKey

pub struct PrivateKey(pub [u8; 32]);

Private key used as x in an ECDSA signature

Methods

impl PrivateKey[src]

pub fn gen() -> Self[src]

Generate a new PrivateKey at random (rand::OsRng)

pub fn gen_custom<R: Rng>(rng: &mut R) -> Self[src]

Generate a new PrivateKey with given custom random generator

pub fn try_from(data: &[u8]) -> Result<Self, Error>[src]

Try to convert a byte slice into PrivateKey.

Arguments

  • data - A byte slice with PRIVATE_KEY_BYTES length

Example

const PKB: usize = emerald_rs::PRIVATE_KEY_BYTES;
let pk = emerald_rs::PrivateKey::try_from(&[0u8; PKB]).unwrap();
assert_eq!(pk.to_string(),
           "0x0000000000000000000000000000000000000000000000000000000000000000");

pub fn to_address(self) -> Result<Address, Error>[src]

Extract Address from current private key.

pub fn sign_message(&self, msg: &str) -> Result<Signature, Error>[src]

Sign message

pub fn sign_bytes(&self, data: &[u8]) -> Result<Signature, Error>[src]

Sign a slice of bytes

pub fn sign_hash(&self, hash: [u8; 32]) -> Result<Signature, Error>[src]

Sign hash from message (Keccak-256)

Trait Implementations

impl Into<SecretKey> for PrivateKey[src]

impl Eq for PrivateKey[src]

impl Copy for PrivateKey[src]

impl PartialOrd<PrivateKey> for PrivateKey[src]

impl Default for PrivateKey[src]

impl PartialEq<PrivateKey> for PrivateKey[src]

impl From<[u8; 32]> for PrivateKey[src]

impl From<SecretKey> for PrivateKey[src]

impl Clone for PrivateKey[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Ord for PrivateKey[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl Deref for PrivateKey[src]

type Target = [u8]

The resulting type after dereferencing.

impl Display for PrivateKey[src]

impl Debug for PrivateKey[src]

impl Hash for PrivateKey[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl FromStr for PrivateKey[src]

type Err = Error

The associated error which can be returned from parsing.

Auto Trait Implementations

impl Send for PrivateKey

impl Sync for PrivateKey

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From for T[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Same for T

type Output = T

Should always be Self

impl<T> Erased for T

impl<Q, K> Equivalent for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<'a, T> TryFrom for T where
    T: FromStr

type Err = <T as FromStr>::Err

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

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