Hi, I'm Boluwatife Ayodele, a software engineer who loves rust and blockchain development. You can reach out to me on [twitter](https://twitter.com/yyceethetechiee), [linkedIn](https:/www.linkedin.com/in/boluwatife-ayodele-g/) and [github](https://github.com/YceeTheTECHie)
Generating key pairs address in rust using the secp256k rust crate.
In this snippet, two crates were used namely : Secp256k1 and anyhow. Read more at https://docs.rs/secp256k1/latest/secp256k1/
https://crates.io/crates/anyhow
A brief explanation on the crates used:
The Secp256k1 is a rust implementation of the Pieter Wuille’s secp256k1 eliptic curve. The bitcoin network uses this eliptic curve for its public key generation algorithm too.
The anyhow crate is used for handling error graciously in rust.
Now to the code...
First we declared a public function named "generate key pair" which returns a public key and private key pair.
We then initiated the secp256k1 crate. On line 3 we use the random number generator (rng) on the secp256k1 crate to generate a secured private key. On line 4, we generated the key pairs by invoking the generate_keypair method which takes a rng from line 3.
The main function just makes a call to the create_keypair function, and then print the output.
Note: As you change the integer in the 'seed_from_u64', you get a different set of private and public key.
To run this code,
add the following lines to your cargo.toml
[dependencies]
secp256k1 = {version = "0.20.3", features = ["rand"]}
anyhow = "1.0.47"
open your terminal, then then execute cargo run.