mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-29 01:31:33 +00:00
Secp256k1 key generation (#474)
This commit is contained in:
@ -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>>
|
||||||
|
Reference in New Issue
Block a user