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.
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.
Get bytes back from a PrivateKey
Create a public key for a given private key.
This is well explained in the Ethereum Yellow Paper Appendix F.
use clarity::PrivateKey;
let private_key : PrivateKey = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f1e".parse().unwrap();
let public_key = private_key.to_public_key().unwrap();
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 inpput 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.
let private_key : PrivateKey = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f1e".parse().unwrap();
let hash = Keccak256::digest("Hello, world!".as_bytes());
let signature = private_key.sign_hash(&hash);
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.
let private_key : PrivateKey = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f1e".parse().unwrap();
let signature = private_key.sign_msg("Hello, world!".as_bytes());
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
Returns the "default value" for a type. Read more
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Converts PrivateKey into a textual representation.
Performs copy-assignment from source
. Read more
This method returns an Ordering
between self
and other
. Read more
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
Formats the value using the given formatter. Read more
Formats the value using the given formatter.
Formats the value using the given formatter.
The associated error which can be returned from parsing.
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.
Serialize this value into the given Serde serializer. Read more
Deserialize this value from the given Serde deserializer. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String
. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static