Skip to content

Commit

Permalink
feat(signer-local): add keystore-geth-compat feature
Browse files Browse the repository at this point in the history
  • Loading branch information
gnapoli23 committed Sep 26, 2024
1 parent 8f7cf55 commit aa09bf1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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
24 changes: 23 additions & 1 deletion crates/signer-local/src/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ mod tests {
}
}

#[cfg(feature = "keystore")]
#[cfg(feature = "keystore-geth-compat")]
fn test_encrypted_json_keystore(key: LocalSigner<SigningKey>, uuid: &str, dir: &Path) {
// sign a message using the given key
let message = "Some data";
Expand Down 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 aa09bf1

Please sign in to comment.