Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added comments to docs #35

Merged
merged 12 commits into from
Jan 6, 2023
4 changes: 4 additions & 0 deletions src/Keys/testingKeys1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Private key 540eabea549412552b7b125a4317b5b006fc6429d2262156f53ce81e66b4424c
Public key 049a7aa1ceb27b9de1eda8d6a40d0f148db00da91ccad314a71178411024b754da12f533ec5742b8c7ef853bed1a3fe176b039f6eacb3be23c424c52da15b83483
ETH 60a386cb5aca9a3583c2b6b81a73fbfa81d0d702
REV Address 11112NVE314jMNWmvWuRzbkPYqf7HdcxVBoJeXTZJJDKYjmJaDoQKF
4 changes: 4 additions & 0 deletions src/Keys/testingKeys2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Private key 5ac6a1a363d352e3f8c4c31533ebf72aa664d8865305514ee5f6984b5b3ac0c8
Public key 04fbc8078fbba32a34adc92560ba0b3db5560ead6b260e199c704ca0c65f5ab3d57eb581145843326adc8324cdabf8753a553e4fbb83bb17193fe4f8d166dc37d4
ETH 76fe5c0efc7caa3f95d1a436d162ddf7f5fa888b
REV Address 11112pFDrc2uRQMvhd5BuuUSjQ2pE1mbTKsaBzaWbbevHPju3BFH2e
4 changes: 4 additions & 0 deletions src/Keys/testingKeys3
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Private key 8981468ca0ca8d3a7657bafb8ce26aa16b0d5cd0d45b5db03af7920804061718
Public key 04bce70f641718abfca5b84d7c9da9200ee6849be1a761d7d1a8cbf0740d501db3e363a1730e549fd573c3a523189f9d28e1489775c9aa7dd667593b71b4813957
ETH 2e5c77b208995d91ffa0cbdde8e0ad4e225c271d
REV Address 11115wi32GEe1YzEcetAc5SKUTuHvk1MrU5757tTbhohGx5CNsfEK
10 changes: 10 additions & 0 deletions src/utils/eth_address_from_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ use crate::error::Error;
use crate::utils::{decode_b16, keccak256};

//get eth address provided the uncompressed pub key
/// to convert from public key to eth addr
///
/// use crate::utils::eth_address_from_public_key::get_eth_addr_from_public_key;
///
/// ```no_run
/// let eth= get_eth_addr_from_public_key("").unwrap()
/// printl!("{eth}")
/// ```
///

pub fn get_eth_addr_from_public_key(pub_key: &str) -> Result<String, Error> {
if pub_key.len() != 130 {
Err(Error::EthAdressFromKey(
Expand Down
14 changes: 13 additions & 1 deletion src/utils/pub_from_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ use secp256k1::{
};

//use secret gotten from get_pri_pub_key_pair() to create new secret here
///get public key from a private key
/// ```no_run
/// use crate::utils::pub_from_private::{get_seckey_from_string,get_pub_key};
/// let seckey=get_seckey_from_string("secret key").unwrap();
/// let pub_key=get_pub_key(&seckey)
/// ```
///
pub fn get_pub_key(secret_key: &SecretKey) -> PublicKey {
let secp = Secp256k1::new();

PublicKey::from_secret_key(&secp, secret_key)
}

///get private key
/// ```no_run
/// use crate::utils::pub_from_private::get_pri_key;
/// let pri_key=get_pri_key()
/// ````
///
pub fn get_pri_key() -> SecretKey {
let secp = Secp256k1::new();
let mut rng = thread_rng();
Expand Down
14 changes: 14 additions & 0 deletions src/utils/rev_address_from_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,26 @@ pub fn get_addr_from_eth(eth_addr_raw: &str) -> Result<String, Error> {
}

//get rev addr from pub key
///
/// use::crate::utils::rev_address_from public_key::rev_address_from_public_key;
///
/// ```no_run
/// let rev=rev_address_from_public_key("public key").unwrap()
/// print!("{rev}")
/// ````
///
pub fn rev_address_from_public_key(pub_key: &str) -> Result<String, Error> {
let eth_addr = get_eth_addr_from_public_key(pub_key)?;
get_addr_from_eth(&eth_addr)
}

//get rev address from private key
///
///```no_run
/// use::crate::utils::rev_address_from_public_key::get_rev_addr_from_private_key;
/// let pub_key=get_rev_addr_from_private_key("private key").unwrap();
///```
///
pub fn get_rev_addr_from_private_key(key: &SecretKey) -> Result<String, Error> {
let pub_key = get_pub_key(key);
rev_address_from_public_key(&hex::encode(pub_key.serialize_uncompressed()))
Expand Down