From 2e4439b93628f22bc72f07e215be413ef22e5429 Mon Sep 17 00:00:00 2001 From: Giovanni Napoli Date: Thu, 26 Sep 2024 14:46:21 +0200 Subject: [PATCH] add `keystore-geth-compat` feature (#1376) --- crates/signer-local/Cargo.toml | 1 + crates/signer-local/src/private_key.rs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/crates/signer-local/Cargo.toml b/crates/signer-local/Cargo.toml index d4d3dc8cb82..f0ff36c73d8 100644 --- a/crates/signer-local/Cargo.toml +++ b/crates/signer-local/Cargo.toml @@ -58,6 +58,7 @@ yubihsm = { version = "0.42", features = ["mockhsm"] } [features] keystore = ["dep:eth-keystore", "dep:elliptic-curve"] +keystore-geth-compat = ["keystore", "eth-keystore?/geth-compat"] mnemonic = ["dep:coins-bip32", "dep:coins-bip39"] mnemonic-all-languages = ["mnemonic", "coins-bip39?/all-langs"] yubihsm = ["dep:yubihsm", "dep:elliptic-curve"] diff --git a/crates/signer-local/src/private_key.rs b/crates/signer-local/src/private_key.rs index 1102170cbd5..ee51e38e829 100644 --- a/crates/signer-local/src/private_key.rs +++ b/crates/signer-local/src/private_key.rs @@ -252,6 +252,28 @@ mod tests { test_encrypted_json_keystore(key, &uuid, dir.path()); } + #[test] + #[cfg(feature = "keystore-geth-compat")] + fn test_encrypted_json_keystore_with_address() { + // create and store an encrypted JSON keystore in this directory + + use std::fs::File; + + use eth_keystore::EthKeystore; + let dir = tempdir().unwrap(); + let mut rng = rand::thread_rng(); + let (key, uuid) = + LocalSigner::::new_keystore(&dir, &mut rng, "randpsswd", None).unwrap(); + + let path = Path::new(dir.path()).join(uuid.clone()); + let file = File::open(path).unwrap(); + let keystore = serde_json::from_reader::<_, EthKeystore>(file).unwrap(); + + assert!(!keystore.address.is_zero()); + + test_encrypted_json_keystore(key, &uuid, dir.path()); + } + #[test] fn signs_msg() { let message = "Some data";