Skip to content

Commit 66b6ca5

Browse files
committed
Added Nimbus loader support
1 parent 38500b2 commit 66b6ca5

File tree

4 files changed

+59
-4
lines changed
  • crates/common/src/signer
  • tests/data/keystores/nimbus-keys
    • 0x883827193f7627cd04e621e1e8d56498362a52b2a30c9a1c72036eb935c4278dee23d38a24d2f7dda62689886f0c39f4
    • 0xb3a22e4a673ac7a153ab5b3c17a4dbef55f7e47210b20c0cbb0e66df5b36bb49ef808577610b034172e955d2312a61b9

4 files changed

+59
-4
lines changed

config.example.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,21 @@ jwt_auth_fail_timeout_seconds = 300
212212
[signer.local.loader]
213213
# File: path to the keys file
214214
key_path = "./tests/data/keys.example.json"
215-
# ValidatorsDir: format of the keystore (lighthouse, prysm, teku or lodestar)
215+
# ValidatorsDir: format of the keystore (lighthouse, prysm, teku, lodestar, or nimbus)
216216
# format = "lighthouse"
217217
# ValidatorsDir: full path to the keys directory
218-
# For lighthouse, it's de path to the directory where the `<pubkey>/voting-keystore.json` directories are located.
218+
# For lighthouse, it's the path to the directory where the `<pubkey>` directories are located, under each of which is a `voting-keystore.json` file.
219219
# For prysm, it's the path to the `all-accounts.keystore.json` file.
220220
# For teku, it's the path to the directory where all `<pubkey>.json` files are located.
221221
# For lodestar, it's the path to the directory where all `<pubkey>.json` files are located.
222+
# For nimbus, it's the path to the directory where the `<pubkey>` directories are located, under each of which is a `keystore.json` file.
222223
# keys_path = ""
223224
# ValidatorsDir: full path to the secrets file/directory
224-
# For lighthouse, it's de path to the directory where the `<pubkey>.json` files are located.
225+
# For lighthouse, it's the path to the directory where the `<pubkey>` files are located.
225226
# For prysm, it's the path to the file containing the wallet decryption password.
226227
# For teku, it's the path to the directory where all `<pubkey>.txt` files are located.
227228
# For lodestar, it's the path to the file containing the decryption password.
229+
# For nimbus, it's the path to the directory where the `<pubkey>` files are located.
228230
# secrets_path = ""
229231
# Configuration for how the Signer module should store proxy delegations. Supported types of store are:
230232
# - File: store keys and delegations from a plain text file (unsafe, use only for testing purposes)

crates/common/src/signer/loader.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ pub enum ValidatorKeysFormat {
4747
Lodestar,
4848
#[serde(alias = "prysm")]
4949
Prysm,
50+
#[serde(alias = "nimbus")]
51+
Nimbus,
5052
}
5153

5254
impl SignerLoader {
@@ -85,6 +87,7 @@ impl SignerLoader {
8587
load_from_lodestar_format(keys_path, secrets_path)
8688
}
8789
ValidatorKeysFormat::Prysm => load_from_prysm_format(keys_path, secrets_path),
90+
ValidatorKeysFormat::Nimbus => load_from_nimbus_format(keys_path, secrets_path),
8891
};
8992
}
9093
})
@@ -272,6 +275,42 @@ fn load_from_prysm_format(
272275
Ok(signers)
273276
}
274277

278+
fn load_from_nimbus_format(
279+
keys_path: PathBuf,
280+
secrets_path: PathBuf,
281+
) -> eyre::Result<Vec<ConsensusSigner>> {
282+
let paths: Vec<_> =
283+
fs::read_dir(&keys_path)?.map(|res| res.map(|e| e.path())).collect::<Result<_, _>>()?;
284+
285+
let signers = paths
286+
.into_par_iter()
287+
.filter_map(|path| {
288+
if !path.is_dir() {
289+
return None
290+
}
291+
292+
let maybe_pubkey = path.file_name().and_then(|d| d.to_str())?;
293+
let Ok(pubkey) = BlsPublicKey::from_hex(maybe_pubkey) else {
294+
warn!("Invalid pubkey: {}", maybe_pubkey);
295+
return None
296+
};
297+
298+
let ks_path = keys_path.join(maybe_pubkey).join("keystore.json");
299+
let pw_path = secrets_path.join(pubkey.to_string());
300+
301+
match load_one(ks_path, pw_path) {
302+
Ok(signer) => Some(signer),
303+
Err(e) => {
304+
warn!("Failed to load signer for pubkey: {}, err: {}", pubkey, e);
305+
None
306+
}
307+
}
308+
})
309+
.collect();
310+
311+
Ok(signers)
312+
}
313+
275314
fn load_one(ks_path: PathBuf, pw_path: PathBuf) -> eyre::Result<ConsensusSigner> {
276315
let keystore = Keystore::from_json_file(ks_path).map_err(|_| eyre!("failed reading json"))?;
277316
let password = fs::read(pw_path.clone())
@@ -303,7 +342,7 @@ mod tests {
303342

304343
use super::{load_from_lighthouse_format, load_from_lodestar_format, FileKey};
305344
use crate::signer::{
306-
loader::{load_from_prysm_format, load_from_teku_format},
345+
loader::{load_from_nimbus_format, load_from_prysm_format, load_from_teku_format},
307346
BlsPublicKey, BlsSigner,
308347
};
309348

@@ -399,4 +438,16 @@ mod tests {
399438
hex!("b3a22e4a673ac7a153ab5b3c17a4dbef55f7e47210b20c0cbb0e66df5b36bb49ef808577610b034172e955d2312a61b9")
400439
)));
401440
}
441+
442+
#[test]
443+
fn test_load_nimbus() {
444+
let result = load_from_nimbus_format(
445+
"../../tests/data/keystores/nimbus-keys".into(),
446+
"../../tests/data/keystores/secrets".into(),
447+
);
448+
449+
assert!(result.is_ok());
450+
451+
test_correct_load(result.unwrap());
452+
}
402453
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"crypto":{"kdf":{"function":"pbkdf2","params":{"dklen":32,"c":262144,"prf":"hmac-sha256","salt":"0ded1a0ed9d0d5aa9c41ac1a6be6d9943835f9ccbe1081869af74925611a4687"},"message":""},"checksum":{"function":"sha256","params":{},"message":"b1de458543b0532666e8f24e679f93ed6f168fd09de1da7c3f4f79b7fa2f2412"},"cipher":{"function":"aes-128-ctr","params":{"iv":"3ca34eb318e53a4c7e545571d8d0c7af"},"message":"acc6c222eea80974107b5a9bf824c8156edaad944f0d444a1aab4cc2118cecc5"}},"description":"0x883827193f7627cd04e621e1e8d56498362a52b2a30c9a1c72036eb935c4278dee23d38a24d2f7dda62689886f0c39f4","pubkey":"883827193f7627cd04e621e1e8d56498362a52b2a30c9a1c72036eb935c4278dee23d38a24d2f7dda62689886f0c39f4","path":"","uuid":"61c06c9c-b0bc-4022-9bf8-a2f250d4e751","version":4}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"crypto":{"kdf":{"function":"pbkdf2","params":{"dklen":32,"c":262144,"prf":"hmac-sha256","salt":"2154bba4d5999c6069442db5b499b2b27b6c2f54f36490e51163934dd4fb412e"},"message":""},"checksum":{"function":"sha256","params":{},"message":"1db4975098c97905f1dd9a9207cab0a9af7e16bebdab700ee08efb51e068017f"},"cipher":{"function":"aes-128-ctr","params":{"iv":"2265a3b57110b46c08295e53379165b5"},"message":"3bd312cc34cebfdd890c9704752191ed93ecd562bb62d2d8ceb4ff945b58b790"}},"description":"0xb3a22e4a673ac7a153ab5b3c17a4dbef55f7e47210b20c0cbb0e66df5b36bb49ef808577610b034172e955d2312a61b9","pubkey":"b3a22e4a673ac7a153ab5b3c17a4dbef55f7e47210b20c0cbb0e66df5b36bb49ef808577610b034172e955d2312a61b9","path":"","uuid":"a8457299-739d-42fb-a0f6-961020f22b8e","version":4}

0 commit comments

Comments
 (0)