Function eth_keystore::new
source · [−]pub fn new<P, R, S>(
dir: P,
rng: &mut R,
password: S,
name: Option<&str>
) -> Result<(Vec<u8>, String), KeystoreError> where
P: AsRef<Path>,
R: Rng + CryptoRng,
S: AsRef<[u8]>,
Expand description
Creates a new JSON keystore using the Scrypt
key derivation function. The keystore is encrypted by a key derived from the provided password
and stored in the provided directory with either the user-provided filename, or a generated
Uuid id
.
Example
use eth_keystore::new;
use std::path::Path;
let dir = Path::new("./keys");
let mut rng = rand::thread_rng();
// here `None` signifies we don't specify a filename for the keystore.
// the default filename is a generated Uuid for the keystore.
let (private_key, name) = new(&dir, &mut rng, "password_to_keystore", None)?;
// here `Some("my_key")` denotes a custom filename passed by the caller.
let (private_key, name) = new(&dir, &mut rng, "password_to_keystore", Some("my_key"))?;