Secp256k1 key generation (#474)

This commit is contained in:
Arkadiy Paronyan
2018-09-13 10:26:52 +02:00
committed by GitHub
parent 6a5681aed7
commit 5980a4538e

View File

@ -240,6 +240,18 @@ impl SecioKeyPair {
.expect("failed to parse generated Ed25519 key")) .expect("failed to parse generated Ed25519 key"))
} }
/// Generates a new random sec256k1 key pair.
#[cfg(feature = "secp256k1")]
pub fn secp256k1_generated() -> Result<SecioKeyPair, Box<Error + Send + Sync>> {
let secp = secp256k1::Secp256k1::with_caps(secp256k1::ContextFlag::Full);
let (private, _) = secp.generate_keypair(&mut ::rand::thread_rng())
.expect("failed to generate secp256k1 key");
Ok(SecioKeyPair {
inner: SecioKeyPairInner::Secp256k1 { private },
})
}
/// Builds a `SecioKeyPair` from a raw secp256k1 32 bytes private key. /// Builds a `SecioKeyPair` from a raw secp256k1 32 bytes private key.
#[cfg(feature = "secp256k1")] #[cfg(feature = "secp256k1")]
pub fn secp256k1_raw_key<K>(key: K) -> Result<SecioKeyPair, Box<Error + Send + Sync>> pub fn secp256k1_raw_key<K>(key: K) -> Result<SecioKeyPair, Box<Error + Send + Sync>>