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
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
///rust
Bill-Kunj marked this conversation as resolved.
Show resolved Hide resolved
///
/// 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}")
/// ```
///
Bill-Kunj marked this conversation as resolved.
Show resolved Hide resolved

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

//use secret gotten from get_pri_pub_key_pair() to create new secret here
///
/// ```
/// 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)
/// ```
Bill-Kunj marked this conversation as resolved.
Show resolved Hide resolved
///
pub fn get_pub_key(secret_key: &SecretKey) -> PublicKey {
let secp = Secp256k1::new();

PublicKey::from_secret_key(&secp, secret_key)
}

///
/// ```
/// use crate::utils::pub_from_private::{get_seckey_from_string,get_pri_key};
/// let seckey=get_seckey_from_string("secret key").unwrap();
/// let pri_key=get_pri_key(&seckey)
/// ````
Bill-Kunj marked this conversation as resolved.
Show resolved Hide resolved
///
pub fn get_pri_key() -> SecretKey {
let secp = Secp256k1::new();
let mut rng = thread_rng();
Expand Down
13 changes: 13 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,25 @@ pub fn get_addr_from_eth(eth_addr_raw: &str) -> Result<String, Error> {
}

//get rev addr from pub key
///
/// use::crate::rev_address_from public_key::rev_address_from_public_key;
///
/// ```no_run
/// let rev=rev_address_from_public_key("").unwrap()
/// print!("{rev}")
/// ````
Bill-Kunj marked this conversation as resolved.
Show resolved Hide resolved
///
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
///
/// use::crate::rev_address_from_public_key::get_rev_addr_from_private_key;
/// let pub_key=get_rev_addr_from_private_key("pub key").unwrap();
/// let rev_addr=get_new_rev_address(&seckey);
///
Bill-Kunj marked this conversation as resolved.
Show resolved Hide resolved
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