Skip to content

Commit

Permalink
chore!(sidecar): require keystore and keystore secrets path
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Oct 18, 2024
1 parent eeab58e commit 0f31b6d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 52 deletions.
3 changes: 0 additions & 3 deletions bolt-sidecar/keys/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions bolt-sidecar/keys/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions bolt-sidecar/secrets/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions bolt-sidecar/secrets/README.md

This file was deleted.

15 changes: 1 addition & 14 deletions bolt-sidecar/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{
fmt::{self, Display},
fs::read_to_string,
ops::Deref,
path::{Path, PathBuf},
path::Path,
};

use alloy::primitives::U256;
Expand Down Expand Up @@ -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);

Expand Down
15 changes: 4 additions & 11 deletions bolt-sidecar/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -116,17 +112,14 @@ impl SidecarDriver<StateClient, PrivateKeySigner> {

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,
)?
};
Expand Down
22 changes: 15 additions & 7 deletions bolt-sidecar/src/signer/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")]
Expand Down Expand Up @@ -194,11 +191,15 @@ fn read_path(entry: std::result::Result<DirEntry, io::Error>) -> SignerResult<Pa

#[cfg(test)]
mod tests {
use std::{fs::File, io::Write, path::PathBuf};
use std::{
fs::File,
io::Write,
path::{Path, PathBuf},
};

use blst::min_pk::SecretKey;

use crate::{common::parse_path, signer::local::LocalSigner, ChainConfig};
use crate::{signer::local::LocalSigner, ChainConfig};

use super::KeystoreSigner;
/// The str path of the root of the project
Expand All @@ -207,6 +208,13 @@ mod tests {
const KEYSTORES_DEFAULT_PATH_TEST: &str = "test_data/keys";
const KEYSTORES_SECRETS_DEFAULT_PATH_TEST: &str = "test_data/secrets";

/// 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.
fn make_path(relative_path: &str) -> PathBuf {
let project_root = env!("CARGO_MANIFEST_DIR");
Path::new(project_root).join(relative_path)
}

#[test]
fn test_keystore_signer() {
// 0. Test data setup
Expand Down Expand Up @@ -310,13 +318,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");
Expand Down

0 comments on commit 0f31b6d

Please sign in to comment.