From ec635b19f20c1e51d5e7af5b0f333cb0afa937eb Mon Sep 17 00:00:00 2001 From: Revertron Date: Wed, 5 May 2021 10:41:32 +0200 Subject: [PATCH] Config update to support new chain. --- alfis.toml | 4 ++-- src/keystore.rs | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/alfis.toml b/alfis.toml index 05b6135..d102971 100644 --- a/alfis.toml +++ b/alfis.toml @@ -1,7 +1,7 @@ # The hash of first block in a chain to know with which nodes to work -origin = "0AE588D62D710422A7972EA1E8A659CC8E93DB59489ACE32C499CD279B000000" +origin = "00002883BB006454F795BE6902770B1A18D897B33A0AB1631F53C37C2F41F800" # A path to your key file to load automatically -key_file = "default.key" +key_file = "key1.toml" # How many last blocks to check on start check_blocks = 8 diff --git a/src/keystore.rs b/src/keystore.rs index a508e64..d97005d 100644 --- a/src/keystore.rs +++ b/src/keystore.rs @@ -34,7 +34,8 @@ pub struct Keystore { keypair: Keypair, hash: RefCell, path: String, - crypto_box: CryptoBox + crypto_box: CryptoBox, + old: bool } impl Keystore { @@ -42,20 +43,20 @@ impl Keystore { let mut csprng = rand_old::thread_rng(); let keypair = ed25519_dalek::Keypair::generate(&mut csprng); let crypto_box = CryptoBox::generate(&mut csprng); - Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box } + Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box, old: false } } pub fn from_random(csprng: &mut R) -> Self where R: CryptoRng + RngCore { let keypair = ed25519_dalek::Keypair::generate(csprng); let crypto_box = CryptoBox::generate(csprng); - Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box } + Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box, old: false } } pub fn from_bytes(seed: &[u8]) -> Self { let keypair = Keypair::from_bytes(seed).expect("Error creating keypair from bytes!"); let mut csprng = rand_old::thread_rng(); let crypto_box = CryptoBox::generate(&mut csprng); - Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box } + Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box, old: false } } pub fn from_random_bytes(key: &[u8]) -> Self { @@ -64,7 +65,7 @@ impl Keystore { let keypair = Keypair { secret, public }; let mut csprng = rand_old::thread_rng(); let crypto_box = CryptoBox::generate(&mut csprng); - Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box } + Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box, old: false } } pub fn from_file(filename: &str, _password: &str) -> Option { @@ -75,6 +76,7 @@ impl Keystore { 32 => { let mut keystore = Keystore::from_random_bytes(key.as_slice()); keystore.path = path.to_str().unwrap().to_owned(); + keystore.old = true; let bytes = Bytes::from_bytes(&keystore.keypair.public.to_bytes()); if check_public_key_strength(&bytes, KEYSTORE_DIFFICULTY) { warn!("Loaded key from OLD format! Please, resave it!"); @@ -86,6 +88,7 @@ impl Keystore { 64 => { let mut keystore = Self::from_bytes(key.as_slice()); keystore.path = path.to_str().unwrap().to_owned(); + keystore.old = true; let bytes = Bytes::from_bytes(&keystore.keypair.public.to_bytes()); if check_public_key_strength(&bytes, KEYSTORE_DIFFICULTY) { warn!("Loaded key from OLD format! Please, resave it!"); @@ -101,7 +104,7 @@ impl Keystore { let public = PublicKey::from_bytes(&from_hex(&keys.signing.public).unwrap()).unwrap(); let keypair = Keypair { secret, public }; let crypto_box = CryptoBox::from_strings(&keys.encryption.secret, &keys.encryption.public); - let keystore = Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::from(filename), crypto_box }; + let keystore = Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::from(filename), crypto_box, old: false }; let bytes = Bytes::from_bytes(&keystore.keypair.public.to_bytes()); if check_public_key_strength(&bytes, KEYSTORE_DIFFICULTY) { Some(keystore) @@ -192,7 +195,7 @@ impl Keystore { impl Clone for Keystore { fn clone(&self) -> Self { let keypair = Keypair::from_bytes(&self.keypair.to_bytes()).unwrap(); - Self { keypair, hash: RefCell::new(Bytes::default()), path: self.path.clone(), crypto_box: self.crypto_box.clone() } + Self { keypair, hash: RefCell::new(Bytes::default()), path: self.path.clone(), crypto_box: self.crypto_box.clone(), old: self.old } } }