Crates.io | ethereum-private-key-to-address |
lib.rs | ethereum-private-key-to-address |
version | 0.1.0 |
source | src |
created_at | 2023-01-08 20:22:48.940266 |
updated_at | 2023-01-08 20:22:48.940266 |
description | Library that converts private key to valid ethereum address. |
homepage | |
repository | https://github.com/Kuly14/ethereum-private-key-to-address |
max_upload_size | |
id | 753926 |
size | 17,616 |
This library will calculate ethereum address from a private key.
Step by step example to generate address:
ethereum-private-key-to-address
to your Cargo.toml
:[dependencies]
ethereum-private-key-to-address = "0.1"
PrivateKey
struct into your project:use ethereum_private_key_to_address::PrivateKey;
PrivateKey
struct with one of these methods:use ethereum_private_key_to_address::PrivateKey;
let private_key = PrivateKey::from_str("<your private key as string>").unwrap();
let private_key = PrivateKey::from_slice("<your private key as &[u8]>").unwrap();
address()
method on the PrivateKey
struct:use ethereum_private_key_to_address::PrivateKey;
let private_key = PrivateKey::from_str("<your private key as string>").unwrap();
// This will calculate your address from the given private key
let address = private_key.address();
println!("{}", address);
Step by step example to generate public key:
ethereum-private-key-to-address
to your Cargo.toml
:[dependencies]
ethereum-private-key-to-address = "0.1"
PrivateKey
struct into your project:use ethereum_private_key_to_address::PrivateKey;
PrivateKey
struct with one of these methods:use ethereum_private_key_to_address::PrivateKey;
let private_key = PrivateKey::from_str("<your private key as string>").unwrap();
let private_key = PrivateKey::from_slice("<your private key as &[u8]>").unwrap();
use ethereum_private_key_to_address::PrivateKey;
let private_key = PrivateKey::from_str("<your private key as string>").unwrap();
// Returns Full 65 byte Public Key including the prefix as a String. In this case prefix is 0x04.
// 0x04 is used to specify the type of the public key.
let full_public_key_with_prefix = private_key.public_key_full();
// Returns Full 64 byte Public Key from Private Key without 0x04 in the front as a String.
// 0x04 is used to specify the type of the public key. 0x04 in front means the public key is uncompressed.
let full_public_key = private_key.public_key();
// Returns the x-coordiante of the public key as a string.
let x_coordinate = private_key.public_key_x();
// Returns the y-coordinate of the public key.
let y_coordiante = private_key.public_key_y();
// Returns the entire public key in [u8; 65] format.
let public_key_slice = private_key.public_key_slice();