mirror of
https://github.com/fluencelabs/trust-graph
synced 2025-04-24 23:32:13 +00:00
Make rand a feature-gated dep
This commit is contained in:
parent
35ea650928
commit
9a006f1f35
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -726,6 +726,7 @@ dependencies = [
|
||||
"curve25519-dalek",
|
||||
"ed25519",
|
||||
"rand 0.7.3",
|
||||
"rand_core 0.5.1",
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
"sha2 0.9.9",
|
||||
|
@ -10,8 +10,7 @@ repository = "https://github.com/fluencelabs/trust-graph"
|
||||
[dependencies]
|
||||
serde = { version = "1.0.118", features = ["derive"] }
|
||||
bs58 = "0.5.0"
|
||||
ed25519-dalek = { version = "1.0.1", features = ["serde", "std"] }
|
||||
rand = "0.8.5"
|
||||
ed25519-dalek = { version = "1.0.1", features = ["serde", "std"], default-features = false }
|
||||
thiserror = "1.0.23"
|
||||
lazy_static = "1.4"
|
||||
sha2 = "0.10.6"
|
||||
@ -20,9 +19,15 @@ serde_bytes = "0.11"
|
||||
eyre = "0.6.5"
|
||||
libp2p-identity = { workspace = true, default-features = false, features = ["peerid", "ed25519"] }
|
||||
multihash = { version = "0.18.0", features = ["identity"] }
|
||||
# rand fails to compile for restricted environments like NEAR contracts
|
||||
rand = { version = "0.8.5", optional = true }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
ring = { version = "0.16.9", features = ["alloc", "std"], default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["rand"]
|
||||
rand = ["dep:rand", "ed25519-dalek/rand_core"]
|
||||
|
||||
[dev-dependencies]
|
||||
quickcheck = "1.0.3"
|
||||
|
@ -22,6 +22,7 @@
|
||||
use crate::error::{DecodingError, SigningError, VerificationError};
|
||||
use core::fmt;
|
||||
use ed25519_dalek::{self as ed25519, Signer as _, Verifier as _};
|
||||
#[cfg(feature = "rand")]
|
||||
use rand::RngCore;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::convert::TryFrom;
|
||||
@ -32,6 +33,7 @@ pub struct Keypair(ed25519::Keypair);
|
||||
|
||||
impl Keypair {
|
||||
/// Generate a new Ed25519 keypair.
|
||||
#[cfg(feature = "rand")]
|
||||
pub fn generate() -> Self {
|
||||
Keypair::from(SecretKey::generate())
|
||||
}
|
||||
@ -174,6 +176,7 @@ impl fmt::Debug for SecretKey {
|
||||
|
||||
impl SecretKey {
|
||||
/// Generate a new Ed25519 secret key.
|
||||
#[cfg(feature = "rand")]
|
||||
pub fn generate() -> Self {
|
||||
let mut bytes = [0u8; 32];
|
||||
rand::thread_rng().fill_bytes(&mut bytes);
|
||||
@ -198,7 +201,7 @@ impl SecretKey {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
|
||||
pub struct Signature(pub Vec<u8>);
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, feature = "rand"))]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::KeyPair;
|
||||
|
@ -95,6 +95,7 @@ pub enum KeyPair {
|
||||
}
|
||||
|
||||
impl KeyPair {
|
||||
#[cfg(feature = "rand")]
|
||||
pub fn generate(format: KeyFormat) -> KeyPair {
|
||||
match format {
|
||||
KeyFormat::Ed25519 => KeyPair::generate_ed25519(),
|
||||
@ -102,6 +103,7 @@ impl KeyPair {
|
||||
}
|
||||
|
||||
/// Generate a new Ed25519 keypair.
|
||||
#[cfg(feature = "rand")]
|
||||
pub fn generate_ed25519() -> KeyPair {
|
||||
KeyPair::Ed25519(ed25519::Keypair::generate())
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ fn as_public_key(peer_id: &PeerId) -> Option<libp2p_identity::PublicKey> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, feature = "rand"))]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::KeyPair;
|
||||
|
Loading…
x
Reference in New Issue
Block a user