From b390910be64e2d5fc29b5b94c7ce0315c8c67573 Mon Sep 17 00:00:00 2001 From: thedevbirb Date: Fri, 18 Oct 2024 13:29:43 +0200 Subject: [PATCH] chore!(sidecar): require keystore and keystore secrets path --- bolt-sidecar/keys/.gitignore | 3 --- bolt-sidecar/keys/README.md | 7 ------- bolt-sidecar/secrets/.gitignore | 3 --- bolt-sidecar/secrets/README.md | 7 ------- bolt-sidecar/src/common.rs | 15 +-------------- bolt-sidecar/src/driver.rs | 15 ++++----------- bolt-sidecar/src/signer/keystore.rs | 26 +++++++++++++++----------- 7 files changed, 20 insertions(+), 56 deletions(-) delete mode 100644 bolt-sidecar/keys/.gitignore delete mode 100644 bolt-sidecar/keys/README.md delete mode 100644 bolt-sidecar/secrets/.gitignore delete mode 100644 bolt-sidecar/secrets/README.md diff --git a/bolt-sidecar/keys/.gitignore b/bolt-sidecar/keys/.gitignore deleted file mode 100644 index 7c9d611b5..000000000 --- a/bolt-sidecar/keys/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -* -!.gitignore -!README.md diff --git a/bolt-sidecar/keys/README.md b/bolt-sidecar/keys/README.md deleted file mode 100644 index 1a539d703..000000000 --- a/bolt-sidecar/keys/README.md +++ /dev/null @@ -1,7 +0,0 @@ -### About - -This directory is intended to be used as the folder to place ERC-2335 keystores -files. - -It is assumed that each keystore file has a `.json` extension and is is placed -in a directory named after the public key it corresponds to. diff --git a/bolt-sidecar/secrets/.gitignore b/bolt-sidecar/secrets/.gitignore deleted file mode 100644 index 7c9d611b5..000000000 --- a/bolt-sidecar/secrets/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -* -!.gitignore -!README.md diff --git a/bolt-sidecar/secrets/README.md b/bolt-sidecar/secrets/README.md deleted file mode 100644 index a0af64906..000000000 --- a/bolt-sidecar/secrets/README.md +++ /dev/null @@ -1,7 +0,0 @@ -### About - -This directory is intended to be used as the folder to place ERC-2335 keystores -secrets. - -It is assumed that each secrets file is named after the public key it -corresponds to. and contains the password in plain text. diff --git a/bolt-sidecar/src/common.rs b/bolt-sidecar/src/common.rs index c4c676ba4..b8d6e80c4 100644 --- a/bolt-sidecar/src/common.rs +++ b/bolt-sidecar/src/common.rs @@ -2,7 +2,7 @@ use std::{ fmt::{self, Display}, fs::read_to_string, ops::Deref, - path::{Path, PathBuf}, + path::Path, }; use alloy::primitives::U256; @@ -96,19 +96,6 @@ pub fn validate_transaction( Ok(()) } -/// If `path` is `Some`, returns a clone of it. Otherwise, returns the path to the `fallback_relative_path` -/// starting from the root of the cargo project. -pub fn parse_path(path: Option<&PathBuf>, fallback_relative_path: &str) -> PathBuf { - let path = if let Some(path) = path { - path.clone() - } else { - let project_root = env!("CARGO_MANIFEST_DIR"); - Path::new(project_root).join(fallback_relative_path) - }; - dbg!(&path); - path -} - #[derive(Clone, Debug)] pub struct BlsSecretKeyWrapper(pub SecretKey); diff --git a/bolt-sidecar/src/driver.rs b/bolt-sidecar/src/driver.rs index b92dca037..8a1714c9c 100644 --- a/bolt-sidecar/src/driver.rs +++ b/bolt-sidecar/src/driver.rs @@ -21,16 +21,12 @@ use crate::{ server::{CommitmentsApiServer, Event as CommitmentEvent}, spec::Error as CommitmentError, }, - common::parse_path, crypto::{bls::cl_public_key_to_arr, SignableBLS, SignerECDSA}, primitives::{ read_signed_delegations_from_file, CommitmentRequest, ConstraintsMessage, FetchPayloadRequest, SignedConstraints, TransactionExt, }, - signer::{ - keystore::{KeystoreSigner, KEYSTORES_DEFAULT_PATH, KEYSTORES_SECRETS_DEFAULT_PATH}, - local::LocalSigner, - }, + signer::{keystore::KeystoreSigner, local::LocalSigner}, start_builder_proxy_server, state::{fetcher::StateFetcher, ConsensusState, ExecutionState, HeadTracker, StateClient}, telemetry::ApiMetrics, @@ -116,17 +112,14 @@ impl SidecarDriver { let keystore = if let Some(psw) = signing_opts.keystore_password.as_ref() { KeystoreSigner::from_password( - &parse_path(signing_opts.keystore_path.as_ref(), KEYSTORES_DEFAULT_PATH), + signing_opts.keystore_path.as_ref().expect("keystore path"), psw.as_ref(), opts.chain, )? } else { KeystoreSigner::from_secrets_directory( - &parse_path(signing_opts.keystore_path.as_ref(), KEYSTORES_DEFAULT_PATH), - &parse_path( - signing_opts.keystore_secrets_path.as_ref(), - KEYSTORES_SECRETS_DEFAULT_PATH, - ), + signing_opts.keystore_path.as_ref().expect("keystore path"), + signing_opts.keystore_secrets_path.as_ref().expect("keystore secrets path"), opts.chain, )? }; diff --git a/bolt-sidecar/src/signer/keystore.rs b/bolt-sidecar/src/signer/keystore.rs index b4e8cb117..fa8cfe7a5 100644 --- a/bolt-sidecar/src/signer/keystore.rs +++ b/bolt-sidecar/src/signer/keystore.rs @@ -20,9 +20,6 @@ use crate::{builder::signature::compute_signing_root, crypto::bls::BLSSig, Chain use super::SignerResult; -pub const KEYSTORES_DEFAULT_PATH: &str = "keys"; -pub const KEYSTORES_SECRETS_DEFAULT_PATH: &str = "keys"; - #[derive(Debug, thiserror::Error)] pub enum KeystoreError { #[error("failed to read keystore directory: {0}")] @@ -76,8 +73,6 @@ impl KeystoreSigner { ) -> SignerResult { let keystores_paths = find_json_keystores(keys_path)?; - println!("keystores_paths: {:?}", keystores_paths); - let mut keypairs = Vec::with_capacity(keystores_paths.len()); for path in keystores_paths { @@ -89,8 +84,6 @@ impl KeystoreSigner { let mut secret_path = secrets_path.clone(); secret_path.push(pubkey); - dbg!(secret_path.clone()); - let password = fs::read_to_string(secret_path) .map_err(|e| KeystoreError::ReadFromSecretFile(format!("{e:?}")))?; @@ -194,11 +187,15 @@ fn read_path(entry: std::result::Result) -> SignerResult PathBuf { + let project_root = env!("CARGO_MANIFEST_DIR"); + Path::new(project_root).join(relative_path) + } + #[test] fn test_keystore_signer() { // 0. Test data setup @@ -310,13 +314,13 @@ mod tests { .expect("to write to temp file"); // Create a file for the secret, we are going to test it as well - let keystores_secrets_path = parse_path(None, KEYSTORES_SECRETS_DEFAULT_PATH_TEST); + let keystores_secrets_path = make_path(KEYSTORES_SECRETS_DEFAULT_PATH_TEST); let mut tmp_secret_file = File::create(keystores_secrets_path.join(public_key)) .expect("to create secret file"); tmp_secret_file.write_all(password.as_bytes()).expect("to write to temp file"); - let keys_path = parse_path(None, KEYSTORES_DEFAULT_PATH_TEST); + let keys_path = make_path(KEYSTORES_DEFAULT_PATH_TEST); let keystore_signer_from_password = KeystoreSigner::from_password(&keys_path, password.as_bytes(), chain_config) .expect("to create keystore signer from password");