Mitigate https://github.com/serai-dex/serai/issues/539 by making keystore deterministic

This commit is contained in:
Luke Parker 2024-03-06 21:37:40 -05:00
parent 5629c94b8b
commit 06c23368f2
No known key found for this signature in database

View file

@ -1,5 +1,4 @@
use zeroize::Zeroize; use zeroize::Zeroize;
use rand_core::RngCore;
use sp_core::{crypto::*, ed25519, sr25519}; use sp_core::{crypto::*, ed25519, sr25519};
use sp_keystore::*; use sp_keystore::*;
@ -13,8 +12,7 @@ impl Keystore {
key_hex.zeroize(); key_hex.zeroize();
assert_eq!(key.len(), 32, "KEY from environment wasn't 32 bytes"); assert_eq!(key.len(), 32, "KEY from environment wasn't 32 bytes");
key.extend([0; 32]); key.extend(sp_core::blake2_256(&key));
rand_core::OsRng.fill_bytes(&mut key[32 ..]);
let res = Self(sr25519::Pair::from(schnorrkel::SecretKey::from_bytes(&key).unwrap())); let res = Self(sr25519::Pair::from(schnorrkel::SecretKey::from_bytes(&key).unwrap()));
key.zeroize(); key.zeroize();