1- use clap:: { self , ValueEnum } ;
1+ use alloy:: signers:: local:: { LocalSigner , PrivateKeySigner } ;
2+ use clap:: { self , Args , ValueEnum } ;
3+ use std:: path:: PathBuf ;
24use std:: str:: FromStr ;
35
46use agg_mode_sdk:: types:: Network ;
@@ -14,3 +16,30 @@ pub enum ProvingSystemArg {
1416 #[ clap( name = "Risc0" ) ]
1517 Risc0 ,
1618}
19+
20+ #[ derive( Args , Debug , Clone ) ]
21+ #[ group( required = true , multiple = false ) ]
22+ pub struct PrivateKeyType {
23+ #[ arg( name = "keystore_path" , long = "keystore-path" ) ]
24+ pub keystore_path : Option < PathBuf > ,
25+ #[ arg( name = "private_key" , long = "private-key" ) ]
26+ pub private_key : Option < String > ,
27+ }
28+
29+ impl PrivateKeyType {
30+ /// Creates a LocalSigner from either a keystore file or a raw private key.
31+ /// If a keystore path is provided, prompts for the password interactively.
32+ pub fn into_signer ( self ) -> Result < PrivateKeySigner , String > {
33+ if let Some ( keystore_path) = self . keystore_path {
34+ let password = rpassword:: prompt_password ( "Please enter your keystore password: " )
35+ . map_err ( |e| format ! ( "Failed to read password: {e}" ) ) ?;
36+ LocalSigner :: decrypt_keystore ( & keystore_path, password)
37+ . map_err ( |e| format ! ( "Failed to decrypt keystore: {e}" ) )
38+ } else if let Some ( private_key) = self . private_key {
39+ LocalSigner :: from_str ( private_key. trim ( ) )
40+ . map_err ( |e| format ! ( "Failed to parse private key: {e}" ) )
41+ } else {
42+ Err ( "Either --keystore-path or --private-key must be provided" . to_string ( ) )
43+ }
44+ }
45+ }
0 commit comments