Skip to content

Commit

Permalink
add keystore-geth-compat feature (#1376)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnapoli23 committed Sep 26, 2024
1 parent 8f7cf55 commit 2e4439b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/signer-local/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
22 changes: 22 additions & 0 deletions crates/signer-local/src/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<SigningKey>::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";
Expand Down

0 comments on commit 2e4439b

Please sign in to comment.