mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 08:52:54 +00:00
Update local testnet scripts, fix eth1 sim (#1184)
* Update local testnet scripts * Add logs when decrypting validators * Update comment * Update account manager * Make random key generation explicit * Remove unnecessary clap constraint * Only decrypt voting keypair for eth1 deposit * Use insecure kdf for insecure keypairs * Simplify local testnet keygen * Update local testnet * Fix eth1 sim * Add eth1 sim to CI again * Remove old local testnet docs * Tidy * Remove checks for existing validators * Tidy * Fix typos
This commit is contained in:
@@ -97,6 +97,12 @@ impl<'a> KeystoreBuilder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Build the keystore using the supplied `kdf` instead of `crate::default_kdf`.
|
||||
pub fn kdf(mut self, kdf: Kdf) -> Self {
|
||||
self.kdf = kdf;
|
||||
self
|
||||
}
|
||||
|
||||
/// Consumes `self`, returning a `Keystore`.
|
||||
pub fn build(self) -> Result<Keystore, Error> {
|
||||
Keystore::encrypt(
|
||||
@@ -208,6 +214,11 @@ impl Keystore {
|
||||
&self.json.pubkey
|
||||
}
|
||||
|
||||
/// Returns the key derivation function for the keystore.
|
||||
pub fn kdf(&self) -> &Kdf {
|
||||
&self.json.crypto.kdf.params
|
||||
}
|
||||
|
||||
/// Encodes `self` as a JSON object.
|
||||
pub fn to_json_string(&self) -> Result<String, Error> {
|
||||
serde_json::to_string(self).map_err(|e| Error::UnableToSerialize(format!("{}", e)))
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
#![cfg(not(debug_assertions))]
|
||||
|
||||
use bls::Keypair;
|
||||
use eth2_keystore::{Error, Keystore, KeystoreBuilder};
|
||||
use eth2_keystore::{
|
||||
default_kdf,
|
||||
json_keystore::{Kdf, Pbkdf2, Prf, Scrypt},
|
||||
Error, Keystore, KeystoreBuilder, DKLEN,
|
||||
};
|
||||
use std::fs::OpenOptions;
|
||||
use tempfile::tempdir;
|
||||
|
||||
@@ -107,3 +111,52 @@ fn scrypt_params() {
|
||||
"should decrypt with good password"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_scrypt_kdf() {
|
||||
let keypair = Keypair::random();
|
||||
|
||||
let salt = vec![42];
|
||||
|
||||
let my_kdf = Kdf::Scrypt(Scrypt {
|
||||
dklen: DKLEN,
|
||||
n: 2,
|
||||
p: 1,
|
||||
r: 8,
|
||||
salt: salt.clone().into(),
|
||||
});
|
||||
|
||||
assert!(my_kdf != default_kdf(salt));
|
||||
|
||||
let keystore = KeystoreBuilder::new(&keypair, GOOD_PASSWORD, "".into())
|
||||
.unwrap()
|
||||
.kdf(my_kdf.clone())
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(keystore.kdf(), &my_kdf);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_pbkdf2_kdf() {
|
||||
let keypair = Keypair::random();
|
||||
|
||||
let salt = vec![42];
|
||||
|
||||
let my_kdf = Kdf::Pbkdf2(Pbkdf2 {
|
||||
dklen: DKLEN,
|
||||
c: 2,
|
||||
prf: Prf::HmacSha256,
|
||||
salt: salt.clone().into(),
|
||||
});
|
||||
|
||||
assert!(my_kdf != default_kdf(salt));
|
||||
|
||||
let keystore = KeystoreBuilder::new(&keypair, GOOD_PASSWORD, "".into())
|
||||
.unwrap()
|
||||
.kdf(my_kdf.clone())
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(keystore.kdf(), &my_kdf);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user