Secp256k1 key generation
@@ -240,6 +240,18 @@ impl SecioKeyPair {
.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.
#[cfg(feature = "secp256k1")]
pub fn secp256k1_raw_key<K>(key: K) -> Result<SecioKeyPair, Box<Error + Send + Sync>>
