MCPcopy Create free account
hub / github.com/ceramicnetwork/rust-ceramic / random

Method random

core/src/node_id.rs:291–308  ·  view source on GitHub ↗

Create a NodeId using a random Ed25519 key pair

()

Source from the content-addressed store, hash-verified

289 /// Create a NodeId using a random Ed25519 key pair
290 ///
291 pub fn random() -> NodeKey {
292 // Generate random secret key and corresponding key_pair
293 let random_secret = rand::thread_rng().gen::<[u8; 32]>();
294 let key_pair = Ed25519KeyPair::from_seed_unchecked(random_secret.as_ref())
295 .expect("expect 32 bytes to be well-formed");
296 // Encode the public key and secret key
297 let public_ed25519_key_bytes: [u8; 32] = key_pair
298 .public_key()
299 .as_ref()
300 .try_into()
301 .expect("expect public key to be 32 bytes");
302 NodeKey::new(
303 NodeId {
304 public_ed25519_key_bytes,
305 },
306 random_secret,
307 )
308 }
309 /// Sign data with this key
310 pub fn sign(&self, data: &[u8]) -> Signature {
311 let key_pair = Ed25519KeyPair::from_seed_unchecked(&self.private_key_bytes)

Callers

nothing calls this directly

Calls 4

newFunction · 0.85
expectMethod · 0.80
try_intoMethod · 0.80
as_refMethod · 0.45

Tested by

no test coverage detected