[][src]Struct emerald_rs::core::PrivateKey

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

Private key used as x in an ECDSA signature

Implementations

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 Clone for PrivateKey[src]

impl Copy for PrivateKey[src]

impl Debug for PrivateKey[src]

impl Default for PrivateKey[src]

impl Deref for PrivateKey[src]

type Target = [u8]

The resulting type after dereferencing.

impl Display for PrivateKey[src]

impl Eq for PrivateKey[src]

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

impl From<SecretKey> for PrivateKey[src]

impl FromStr for PrivateKey[src]

type Err = Error

The associated error which can be returned from parsing.

impl Hash for PrivateKey[src]

impl Into<SecretKey> for PrivateKey[src]

impl Ord for PrivateKey[src]

impl PartialEq<PrivateKey> for PrivateKey[src]

impl PartialOrd<PrivateKey> for PrivateKey[src]

impl StructuralEq for PrivateKey[src]

impl StructuralPartialEq for PrivateKey[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

impl<T> From<T> for T[src]

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

impl<T> Same<T> for T

type Output = T

Should always be Self

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

type Owned = T

The resulting type after obtaining ownership.

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

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

type Err = <T as FromStr>::Err

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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