mithril_common/crypto_helper/cardano/
cold_key.rs1use ed25519_dalek::SigningKey as ColdSecretKey;
2use rand_chacha::ChaCha20Rng;
3use rand_core::SeedableRng;
4
5#[doc(hidden)]
7#[derive(Debug)]
8pub struct ColdKeyGenerator();
9
10impl ColdKeyGenerator {
11 #[doc(hidden)]
12 pub fn create_deterministic_keypair(seed: [u8; 32]) -> ColdSecretKey {
14 let mut rng = ChaCha20Rng::from_seed(seed);
15 ColdSecretKey::generate(&mut rng)
16 }
17}
18
19#[cfg(test)]
20mod tests {
21 use super::*;
22
23 #[test]
24 fn test_generate_deterministic_genesis_keypair() {
25 let cold_keypair1 = ColdKeyGenerator::create_deterministic_keypair([0u8; 32]);
26 let cold_keypair2 = ColdKeyGenerator::create_deterministic_keypair([0u8; 32]);
27 let cold_keypair3 = ColdKeyGenerator::create_deterministic_keypair([1u8; 32]);
28 assert_eq!(cold_keypair1.to_bytes(), cold_keypair2.to_bytes());
29 assert_ne!(cold_keypair1.to_bytes(), cold_keypair3.to_bytes());
30 }
31}