ETCDEVTeam / libsecp256k1-rs

Pure Rust Implementation of secp256k1.
Apache License 2.0
12 stars 8 forks source link

How to generate keys #5

Closed elichai closed 6 years ago

elichai commented 6 years ago

Hi, I couldn't find an example on how to use this library. There's no context/generate_keypair function like in the rust-secp256k1: https://github.com/rust-bitcoin/rust-secp256k1/blob/master/src/lib.rs#L484

Thanks, Elichai.

sorpaas commented 6 years ago

@elichai Keys for secp256k1 are just random 32 bytes array. And in libsecp256k1 we have SecretKey::random(...) that allows you to pass an Rng to it. So for example, you can do:

SecretKey::random(&mut OsRng::new().unwrap())

devp2p-rs (https://source.that.world/source/devp2p-rs) is one of the example where libsecp256k1 is used. Let me know if there's anything confusing!

elichai commented 6 years ago

Nope, nothing confusing. If anyone is having problems understanding, you can also generate a key using your own randomness via: let priv = SecretKey::parse(&random_32_slice).unwrap();