@@ -57,9 +57,7 @@ impl SignerLoader {
57
57
pub fn load_from_env ( self ) -> eyre:: Result < Vec < ConsensusSigner > > {
58
58
Ok ( match self {
59
59
SignerLoader :: File { key_path } => {
60
- let path = load_env_var ( SIGNER_KEYS_ENV ) . unwrap_or (
61
- key_path. to_str ( ) . ok_or_eyre ( "Missing signer key path" ) ?. to_string ( ) ,
62
- ) ;
60
+ let path = load_env_var ( SIGNER_KEYS_ENV ) . map ( PathBuf :: from) . unwrap_or ( key_path) ;
63
61
let file = std:: fs:: read_to_string ( path)
64
62
. unwrap_or_else ( |_| panic ! ( "Unable to find keys file" ) ) ;
65
63
@@ -73,12 +71,10 @@ impl SignerLoader {
73
71
SignerLoader :: ValidatorsDir { keys_path, secrets_path, format } => {
74
72
// TODO: hacky way to load for now, we should support reading the
75
73
// definitions.yml file
76
- let keys_path = load_env_var ( SIGNER_DIR_KEYS_ENV ) . unwrap_or (
77
- keys_path. to_str ( ) . ok_or_eyre ( "Missing signer keys path" ) ?. to_string ( ) ,
78
- ) ;
79
- let secrets_path = load_env_var ( SIGNER_DIR_SECRETS_ENV ) . unwrap_or (
80
- secrets_path. to_str ( ) . ok_or_eyre ( "Missing signer secrets path" ) ?. to_string ( ) ,
81
- ) ;
74
+ let keys_path =
75
+ load_env_var ( SIGNER_DIR_KEYS_ENV ) . map ( PathBuf :: from) . unwrap_or ( keys_path) ;
76
+ let secrets_path =
77
+ load_env_var ( SIGNER_DIR_SECRETS_ENV ) . map ( PathBuf :: from) . unwrap_or ( secrets_path) ;
82
78
83
79
return match format {
84
80
ValidatorKeysFormat :: Lighthouse => {
@@ -114,8 +110,8 @@ impl<'de> Deserialize<'de> for FileKey {
114
110
}
115
111
116
112
fn load_from_lighthouse_format (
117
- keys_path : String ,
118
- secrets_path : String ,
113
+ keys_path : PathBuf ,
114
+ secrets_path : PathBuf ,
119
115
) -> eyre:: Result < Vec < ConsensusSigner > > {
120
116
let entries = fs:: read_dir ( keys_path. clone ( ) ) ?;
121
117
@@ -129,8 +125,8 @@ fn load_from_lighthouse_format(
129
125
if path. is_dir ( ) {
130
126
if let Some ( maybe_pubkey) = path. file_name ( ) . and_then ( |d| d. to_str ( ) ) {
131
127
if let Ok ( pubkey) = BlsPublicKey :: from_hex ( maybe_pubkey) {
132
- let ks_path = format ! ( "{}/{}/ voting-keystore.json", keys_path , maybe_pubkey ) ;
133
- let pw_path = format ! ( "{}/{}" , secrets_path, pubkey) ;
128
+ let ks_path = keys_path . join ( maybe_pubkey ) . join ( " voting-keystore.json") ;
129
+ let pw_path = secrets_path. join ( pubkey. to_string ( ) ) ;
134
130
135
131
match load_one ( ks_path, pw_path) {
136
132
Ok ( signer) => signers. push ( signer) ,
@@ -147,8 +143,8 @@ fn load_from_lighthouse_format(
147
143
}
148
144
149
145
fn load_from_teku_format (
150
- keys_path : String ,
151
- secrets_path : String ,
146
+ keys_path : PathBuf ,
147
+ secrets_path : PathBuf ,
152
148
) -> eyre:: Result < Vec < ConsensusSigner > > {
153
149
let entries = fs:: read_dir ( keys_path. clone ( ) ) ?;
154
150
let mut signers = Vec :: new ( ) ;
@@ -171,8 +167,8 @@ fn load_from_teku_format(
171
167
. 0 ;
172
168
173
169
match load_one (
174
- format ! ( "{keys_path}/{ file_name}.json" ) ,
175
- format ! ( "{secrets_path}/{ file_name}.txt" ) ,
170
+ keys_path . join ( format ! ( "{file_name}.json" ) ) ,
171
+ secrets_path . join ( format ! ( "{file_name}.txt" ) ) ,
176
172
) {
177
173
Ok ( signer) => signers. push ( signer) ,
178
174
Err ( e) => warn ! ( "Sign load error: {e}" ) ,
@@ -183,8 +179,8 @@ fn load_from_teku_format(
183
179
}
184
180
185
181
fn load_from_lodestar_format (
186
- keys_path : String ,
187
- password_path : String ,
182
+ keys_path : PathBuf ,
183
+ password_path : PathBuf ,
188
184
) -> eyre:: Result < Vec < ConsensusSigner > > {
189
185
let entries = fs:: read_dir ( keys_path) ?;
190
186
let mut signers = Vec :: new ( ) ;
@@ -198,15 +194,7 @@ fn load_from_lodestar_format(
198
194
continue ;
199
195
}
200
196
201
- let key_path = match path. as_os_str ( ) . to_str ( ) {
202
- Some ( key_path) => key_path,
203
- None => {
204
- warn ! ( "Path {path:?} cannot be converted to string" ) ;
205
- continue ;
206
- }
207
- } ;
208
-
209
- match load_one ( key_path. to_string ( ) , password_path. clone ( ) ) {
197
+ match load_one ( path, password_path. clone ( ) ) {
210
198
Ok ( signer) => signers. push ( signer) ,
211
199
Err ( e) => warn ! ( "Sign load error: {e}" ) ,
212
200
}
@@ -233,8 +221,8 @@ fn load_from_lodestar_format(
233
221
/// }
234
222
/// ```
235
223
fn load_from_prysm_format (
236
- accounts_path : String ,
237
- password_path : String ,
224
+ accounts_path : PathBuf ,
225
+ password_path : PathBuf ,
238
226
) -> eyre:: Result < Vec < ConsensusSigner > > {
239
227
let accounts_file = File :: open ( accounts_path) ?;
240
228
let accounts_reader = BufReader :: new ( accounts_file) ;
@@ -281,25 +269,26 @@ fn load_from_prysm_format(
281
269
Ok ( signers)
282
270
}
283
271
284
- fn load_one ( ks_path : String , pw_path : String ) -> eyre:: Result < ConsensusSigner > {
272
+ fn load_one ( ks_path : PathBuf , pw_path : PathBuf ) -> eyre:: Result < ConsensusSigner > {
285
273
let keystore = Keystore :: from_json_file ( ks_path) . map_err ( |_| eyre ! ( "failed reading json" ) ) ?;
286
- let password =
287
- fs :: read ( pw_path . clone ( ) ) . map_err ( |e| eyre ! ( "Failed to read password ({pw_path }): {e}" ) ) ?;
274
+ let password = fs :: read ( pw_path . clone ( ) )
275
+ . map_err ( |e| eyre ! ( "Failed to read password ({}): {e}" , pw_path . display ( ) ) ) ?;
288
276
let key =
289
277
keystore. decrypt_keypair ( & password) . map_err ( |_| eyre ! ( "failed decrypting keypair" ) ) ?;
290
278
ConsensusSigner :: new_from_bytes ( key. sk . serialize ( ) . as_bytes ( ) )
291
279
}
292
280
293
281
pub fn load_bls_signer ( keys_path : PathBuf , secrets_path : PathBuf ) -> eyre:: Result < BlsSigner > {
294
- load_one ( keys_path. to_string_lossy ( ) . to_string ( ) , secrets_path. to_string_lossy ( ) . to_string ( ) )
282
+ load_one ( keys_path, secrets_path)
295
283
}
296
284
297
285
pub fn load_ecdsa_signer ( keys_path : PathBuf , secrets_path : PathBuf ) -> eyre:: Result < EcdsaSigner > {
298
- let key_file = std:: fs:: File :: open ( keys_path. to_string_lossy ( ) . to_string ( ) ) ?;
286
+ let key_file = std:: fs:: File :: open ( keys_path) ?;
299
287
let key_reader = std:: io:: BufReader :: new ( key_file) ;
300
288
let keystore: JsonKeystore = serde_json:: from_reader ( key_reader) ?;
301
289
let password = std:: fs:: read ( secrets_path) ?;
302
- let decrypted_password = eth2_keystore:: decrypt ( & password, & keystore. crypto ) . unwrap ( ) ;
290
+ let decrypted_password = eth2_keystore:: decrypt ( & password, & keystore. crypto )
291
+ . map_err ( |_| eyre:: eyre!( "Error decrypting ECDSA keystore" ) ) ?;
303
292
304
293
EcdsaSigner :: new_from_bytes ( decrypted_password. as_bytes ( ) )
305
294
}
0 commit comments