Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Chore/update eth keystore (#910)
Browse files Browse the repository at this point in the history
* chore(signers): bump up eth-keystore

* doc(signers): update doc for new_keystore

* chore: add changelog
  • Loading branch information
roynalnaruto authored Feb 14, 2022
1 parent a8cdfe6 commit 17d5b0e
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 43 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@

### Unreleased

- `eth-keystore-rs` crate updated. Allow an optional name for the to-be-generated
keystore file [#910](https://github.com/gakonst/ethers-rs/pull/910)

### 0.6.0

- `LocalWallet::new_keystore` now returns a tuple `(LocalWallet, String)`
Expand Down
122 changes: 83 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ethers-signers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tracing-futures = { version = "0.2.5", optional = true }
spki = { version = "0.5.4", optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
eth-keystore = { version = "0.3.0" }
eth-keystore = { version = "0.4.0" }
home = "0.5.3"

[dev-dependencies]
Expand Down
9 changes: 6 additions & 3 deletions ethers-signers/src/wallet/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,21 @@ impl Clone for Wallet<SigningKey> {
impl Wallet<SigningKey> {
/// Creates a new random encrypted JSON with the provided password and stores it in the
/// provided directory. Returns a tuple (Wallet, String) of the wallet instance for the
/// keystore with its random UUID.
/// keystore with its random UUID. Accepts an optional name for the keystore file. If `None`,
/// the keystore is stored as the stringified UUID.
#[cfg(not(target_arch = "wasm32"))]
pub fn new_keystore<P, R, S>(
dir: P,
rng: &mut R,
password: S,
name: Option<&str>,
) -> Result<(Self, String), WalletError>
where
P: AsRef<Path>,
R: Rng + CryptoRng + rand_core::CryptoRng,
S: AsRef<[u8]>,
{
let (secret, uuid) = eth_keystore::new(dir, rng, password)?;
let (secret, uuid) = eth_keystore::new(dir, rng, password, name)?;
let signer = SigningKey::from_bytes(secret.as_slice())?;
let address = secret_key_to_address(&signer);
Ok((Self { signer, address, chain_id: 1 }, uuid))
Expand Down Expand Up @@ -153,7 +155,8 @@ mod tests {
// create and store a random encrypted JSON keystore in this directory
let dir = tempdir().unwrap();
let mut rng = rand::thread_rng();
let (key, uuid) = Wallet::<SigningKey>::new_keystore(&dir, &mut rng, "randpsswd").unwrap();
let (key, uuid) =
Wallet::<SigningKey>::new_keystore(&dir, &mut rng, "randpsswd", None).unwrap();

// sign a message using the above key
let message = "Some data";
Expand Down

0 comments on commit 17d5b0e

Please sign in to comment.