Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Add private-key to deposit to batcher #1724

Open
wants to merge 4 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions batcher/aligned/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use aligned_sdk::sdk::get_chain_id;
use aligned_sdk::sdk::get_nonce_from_batcher;
use aligned_sdk::sdk::{deposit_to_aligned, get_balance_in_aligned};
use aligned_sdk::sdk::{get_vk_commitment, is_proof_verified, save_response, submit_multiple};
use clap::Args;
use clap::Parser;
use clap::Subcommand;
use clap::ValueEnum;
Expand Down Expand Up @@ -103,10 +104,8 @@ pub struct SubmitArgs {
default_value = "./aligned_verification_data/"
)]
batch_inclusion_data_directory_path: String,
#[arg(name = "Path to local keystore", long = "keystore_path")]
keystore_path: Option<PathBuf>,
#[arg(name = "Private key", long = "private_key")]
private_key: Option<String>,
#[command(flatten)]
private_key_type: PrivateKeyType,
#[arg(
name = "Max Fee (ether)",
long = "max_fee",
Expand All @@ -126,18 +125,14 @@ pub struct SubmitArgs {
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct DepositToBatcherArgs {
#[arg(
name = "Path to local keystore",
long = "keystore_path",
required = true
)]
keystore_path: Option<PathBuf>,
#[arg(
name = "Ethereum RPC provider address",
long = "rpc_url",
default_value = "http://localhost:8545"
)]
eth_rpc_url: String,
#[command(flatten)]
private_key_type: PrivateKeyType,
#[arg(
name = "The working network's name",
long = "network",
Expand Down Expand Up @@ -218,6 +213,15 @@ pub struct GetUserNonceArgs {
address: String,
}

#[derive(Args, Debug)]
#[group(required = true, multiple = false)]
pub struct PrivateKeyType {
#[arg(name = "path_to_keystore", long = "keystore_path")]
keystore_path: Option<PathBuf>,
#[arg(name = "private_key", long = "private_key")]
private_key: Option<String>,
}

#[derive(Debug, Clone, ValueEnum, Copy)]
enum NetworkArg {
Devnet,
Expand Down Expand Up @@ -293,13 +297,8 @@ async fn main() -> Result<(), AlignedError> {
let repetitions = submit_args.repetitions;
let connect_addr = submit_args.batcher_url.clone();

let keystore_path = &submit_args.keystore_path;
let private_key = &submit_args.private_key;

if keystore_path.is_some() && private_key.is_some() {
warn!("Can't have a keystore path and a private key as input. Please use only one");
return Ok(());
}
let keystore_path = &submit_args.private_key_type.keystore_path;
let private_key = &submit_args.private_key_type.private_key;

let mut wallet = if let Some(keystore_path) = keystore_path {
let password = rpassword::prompt_password("Please enter your keystore password:")
Expand All @@ -311,7 +310,7 @@ async fn main() -> Result<(), AlignedError> {
.parse::<LocalWallet>()
.map_err(|e| SubmitError::GenericError(e.to_string()))?
} else {
warn!("Missing keystore used for payment. This proof will not be included if sent to Eth Mainnet");
warn!("Missing keystore or private key used for payment. This proof will not be included if sent to Eth Mainnet");
match LocalWallet::from_str(ANVIL_PRIVATE_KEY) {
Ok(wallet) => wallet,
Err(e) => {
Expand Down Expand Up @@ -473,15 +472,20 @@ async fn main() -> Result<(), AlignedError> {
))
})?;

let keystore_path = &deposit_to_batcher_args.keystore_path;
let keystore_path = &deposit_to_batcher_args.private_key_type.keystore_path;
let private_key = &deposit_to_batcher_args.private_key_type.private_key;

let mut wallet = if let Some(keystore_path) = keystore_path {
let password = rpassword::prompt_password("Please enter your keystore password:")
.map_err(|e| SubmitError::GenericError(e.to_string()))?;
Wallet::decrypt_keystore(keystore_path, password)
.map_err(|e| SubmitError::GenericError(e.to_string()))?
} else if let Some(private_key) = private_key {
private_key
.parse::<LocalWallet>()
.map_err(|e| SubmitError::GenericError(e.to_string()))?
} else {
warn!("Missing keystore used for payment.");
warn!("Missing keystore or private key used for payment.");
return Ok(());
};

Expand Down
1 change: 1 addition & 0 deletions docs/3_guides/9_aligned_cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Deposits Ethereum into the Aligned Layer's `BatcherPaymentService.sol` contract.

#### Options:
- `--keystore_path <path_to_local_keystore>`: Path to the local keystore.
- `--private_key <private_key>`: User's wallet private key.
- `--rpc_url <RPC_provider_url>`: User's Ethereum RPC provider connection address.
- Default: `http://localhost:8545`
- Mainnet: `https://ethereum-rpc.publicnode.com`
Expand Down
Loading