Struct clarity::private_key::PrivateKey [−][src]
pub struct PrivateKey(_);
Representation of an Ethereum private key.
Private key can be created using a textual representation, a raw binary form using array of bytes.
With PrivateKey you are able to sign messages, derive public keys. Cryptography-related methods use SECP256K1 elliptic curves.
Implementations
impl PrivateKey
[src]
impl PrivateKey
[src]pub fn from_slice(slice: &[u8]) -> Result<PrivateKey, Error>
[src]
Convert a given slice of bytes into a valid private key.
Input bytes are validated for a length only.
slice
- A slice of raw bytes with a length of 32.
pub fn to_bytes(&self) -> [u8; 32]
[src]
Get bytes back from a PrivateKey
pub fn to_public_key(&self) -> Result<Address, Error>
[src]
Create a public key for a given private key.
This is well explained in the Ethereum Yellow Paper Appendix F.
Examples
use clarity::PrivateKey; let private_key : PrivateKey = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f1e".parse().unwrap(); let public_key = private_key.to_public_key().unwrap();
pub fn sign_hash(&self, data: &[u8]) -> Signature
[src]
Signs a message that is represented by a hash contained in a binary form.
Requires the data buffer to be exactly 32 bytes in length. You can prepare
an input using a hashing function such as Keccak256
which will return
a buffer of exact size.
You are advised, though, to use sign_msg which is more user friendly version that uses Keccak256 internally.
Example
let private_key : PrivateKey = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f1e".parse().unwrap(); let hash = Keccak256::digest("Hello, world!".as_bytes()); let signature = private_key.sign_hash(&hash);
pub fn sign_msg(&self, data: &[u8]) -> Signature
[src]
Please use sign_ethereum_msg or sign_insecure_msg instead
Signs any message represented by a slice of data.
Internally it makes Keccak256
hash out of your data, and then creates a
signature.
This is more user friendly version of sign_hash which means
it will use Keccak256
function to hash your input data.
This method is deprecated as insecure, since it does not prevent signed messages from being possibly valid transactions by appending the standard \x19Ethereum Signed Message:\n32
Example
let private_key : PrivateKey = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f1e".parse().unwrap(); let signature = private_key.sign_msg("Hello, world!".as_bytes());
pub fn sign_insecure_msg(&self, data: &[u8]) -> Signature
[src]
Signs any message represented by a slice of data.
Internally it makes Keccak256
hash out of your data, and then creates a
signature.
This is more user friendly version of sign_hash which means
it will use Keccak256
function to hash your input data.
This method is provided on the assumption you know what you are doing, it does not prevent signed messages from being possibly valid transactions. No Ethereum signed message salt is appended. Use with Caution!
Example
let private_key : PrivateKey = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f1e".parse().unwrap(); let signature = private_key.sign_msg("Hello, world!".as_bytes());
pub fn sign_ethereum_msg(&self, data: &[u8]) -> Signature
[src]
Signs any message represented by a slice of data.
Internally it makes Keccak256
hash out of your data, and then creates a
signature.
This is more user friendly version of sign_hash which means
it will use Keccak256
function to hash your input data.
Remember this function appends \x19Ethereum Signed Message:\n32 to your hash! so you may need to take that into account when you go to verify
Example
let private_key : PrivateKey = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f1e".parse().unwrap(); let signature = private_key.sign_ethereum_msg("Hello, world!".as_bytes());
Trait Implementations
impl Clone for PrivateKey
[src]
impl Clone for PrivateKey
[src]fn clone(&self) -> PrivateKey
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for PrivateKey
[src]
impl Copy for PrivateKey
[src]impl Default for PrivateKey
[src]
impl Default for PrivateKey
[src]fn default() -> PrivateKey
[src]
impl<'de> Deserialize<'de> for PrivateKey
[src]
impl<'de> Deserialize<'de> for PrivateKey
[src]fn deserialize<D>(deserializer: D) -> Result<PrivateKey, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl Eq for PrivateKey
[src]
impl Eq for PrivateKey
[src]impl FromStr for PrivateKey
[src]
impl FromStr for PrivateKey
[src]type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
Parse a textual representation of a private key back into PrivateKey type.
It has to be a string that represents 64 characters that are hexadecimal
representation of 32 bytes. Optionally this string can be prefixed with 0x
at the beggining.
impl Ord for PrivateKey
[src]
impl Ord for PrivateKey
[src]impl PartialEq<PrivateKey> for PrivateKey
[src]
impl PartialEq<PrivateKey> for PrivateKey
[src]fn eq(&self, other: &PrivateKey) -> bool
[src]
fn ne(&self, other: &PrivateKey) -> bool
[src]
impl PartialOrd<PrivateKey> for PrivateKey
[src]
impl PartialOrd<PrivateKey> for PrivateKey
[src]impl Serialize for PrivateKey
[src]
impl Serialize for PrivateKey
[src]impl StructuralEq for PrivateKey
[src]
impl StructuralEq for PrivateKey
[src]impl StructuralPartialEq for PrivateKey
[src]
impl StructuralPartialEq for PrivateKey
[src]Auto Trait Implementations
impl RefUnwindSafe for PrivateKey
impl RefUnwindSafe for PrivateKey
impl Send for PrivateKey
impl Send for PrivateKey
impl Sync for PrivateKey
impl Sync for PrivateKey
impl Unpin for PrivateKey
impl Unpin for PrivateKey
impl UnwindSafe for PrivateKey
impl UnwindSafe for PrivateKey