diff --git a/Cargo.lock b/Cargo.lock index b891ee4bda110586c0a424d6235f5ae58eedc143..f4b506062fe56537842e6d3e79bcfb579f0393f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2077,6 +2077,7 @@ version = "0.2.7" dependencies = [ "age", "anyhow", + "bip39", "bs58", "clap", "confy", @@ -2086,9 +2087,11 @@ dependencies = [ "graphql_client", "hex", "inquire", + "itertools 0.12.1", "log", "nacl", "parity-scale-codec", + "rand_chacha", "reqwest", "rpassword", "scrypt", diff --git a/Cargo.toml b/Cargo.toml index 8f7dfd2ac2603565edf394af7a38d7e774f6ad08..d8407770ea355b37a04f6ea864f4f5cd0e15af3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,13 +41,16 @@ confy = "^0.5.1" bs58 = "^0.5.0" inquire = "^0.6.2" directories = "^5.0.1" +itertools = "^0.12.1" + # crypto scrypt = { version = "^0.11", default-features = false } # for old-style key generation nacl = { version = "^0.5.3" } # for old-style key generation age = { default-features = false, version = "^0.10.0", features = [ "armor", ] } # this is beta crate for password -encrypted files - +rand_chacha = "^0.3.1" # used to generate random seed +bip39 = "^2.0.0" # to convert seed to mnemonic # allows to build gcli for different runtimes and with different predefined networks [features] diff --git a/src/commands/vault.rs b/src/commands/vault.rs index 5c2a9cf6168b9f8d131c4923bf56f971bf320979..63551102e2c4292afddb2c87b8b5f541910e15c9 100644 --- a/src/commands/vault.rs +++ b/src/commands/vault.rs @@ -1,5 +1,7 @@ use crate::*; use age::secrecy::Secret; +use itertools::Itertools; +use rand_chacha::rand_core::SeedableRng; use std::io::{Read, Write}; /// define universal dividends subcommands @@ -58,7 +60,12 @@ pub fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliError> println!("{}", data.project_dir.data_dir().to_str().unwrap()); } Subcommand::Generate => { - unimplemented!() + // ChaCha20Rng is ok for cryptography + let rng = rand_chacha::ChaCha20Rng::from_entropy(); + let seed = rng.get_seed(); + let mnemonic = bip39::Mnemonic::from_entropy(&seed); + let phrase = mnemonic.unwrap().word_iter().join(" "); + println!("{phrase}"); } Subcommand::Import => { // --- currently only support mnemonic secret