Skip to content

Commit

Permalink
Fix multi word password
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocustodio committed Jan 22, 2024
1 parent 2462b9f commit 1711ed4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions bin/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ async fn update_user(

fn write_seed(seed: String) -> std::io::Result<()> {
let split_seed: Vec<String> = seed.split("///").map(|s| s.to_string()).collect();
let mnemonic = &split_seed[0];
let pass = split_seed.get(1);
let password: Option<&str> = match pass {
Some(p) => Some(p),
None => None,
};

let key = sr25519::Pair::from_phrase(&mnemonic, password)
let mnemonic = split_seed[0].clone();
let password = split_seed
.iter()
.skip(1)
.cloned()
.collect::<Vec<String>>()
.join(" ");

let key = sr25519::Pair::from_phrase(&mnemonic, Some(&*password))
.expect("Invalid mnemonic phrase or password");

let public_key = key.0.public();
Expand All @@ -98,7 +99,7 @@ fn write_seed(seed: String) -> std::io::Result<()> {
println!("Store file name: {}", file_name);

let mut file = File::create(format!("store/{}", file_name))?;
file.write_all(format!("\"{}\"", seed).as_bytes())?;
file.write_all(format!("\"{}\"", mnemonic).as_bytes())?;

Ok(())
}
Expand Down

0 comments on commit 1711ed4

Please sign in to comment.