Skip to content

Commit

Permalink
crypto: Simplify some code in BIP44 derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
cronokirby committed Sep 15, 2023
1 parent d71fd37 commit 9c80e80
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions crates/bin/pcli/src/command/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,14 @@ impl KeysCmd {
// shared by users accidentally in log output.
println!("YOUR PRIVATE SEED PHRASE: {seed_phrase}\nDO NOT SHARE WITH ANYONE!");

if *bip44_derivation {
let wallet = if *bip44_derivation {
let path = Bip44Path::new(0);
let wallet = KeyStore::from_seed_phrase_bip44(seed_phrase, &path);
wallet.save(data_dir.join(crate::CUSTODY_FILE_NAME))?;
self.archive_wallet(&wallet)?;
KeyStore::from_seed_phrase_bip44(seed_phrase, &path)
} else {
let wallet = KeyStore::from_seed_phrase_bip39(seed_phrase);
wallet.save(data_dir.join(crate::CUSTODY_FILE_NAME))?;
self.archive_wallet(&wallet)?;
}
KeyStore::from_seed_phrase_bip39(seed_phrase)
};
wallet.save(data_dir.join(crate::CUSTODY_FILE_NAME))?;
self.archive_wallet(&wallet)?;
}
KeysCmd::Import(ImportCmd::Phrase { bip44_derivation }) => {
let mut seed_phrase = String::new();
Expand All @@ -110,20 +108,15 @@ impl KeysCmd {
}
}

if *bip44_derivation {
let seed_phrase = SeedPhrase::from_str(&seed_phrase)?;
let wallet = if *bip44_derivation {
let path = Bip44Path::new(0);
let wallet = KeyStore::from_seed_phrase_bip44(
SeedPhrase::from_str(&seed_phrase)?,
&path,
);
wallet.save(data_dir.join(crate::CUSTODY_FILE_NAME))?;
self.archive_wallet(&wallet)?;
KeyStore::from_seed_phrase_bip44(seed_phrase, &path)
} else {
let wallet =
KeyStore::from_seed_phrase_bip39(SeedPhrase::from_str(&seed_phrase)?);
wallet.save(data_dir.join(crate::CUSTODY_FILE_NAME))?;
self.archive_wallet(&wallet)?;
}
KeyStore::from_seed_phrase_bip39(seed_phrase)
};
wallet.save(data_dir.join(crate::CUSTODY_FILE_NAME))?;
self.archive_wallet(&wallet)?;
}
KeysCmd::Export(ExportCmd::FullViewingKey) => {
let wallet = KeyStore::load(data_dir.join(crate::CUSTODY_FILE_NAME))?;
Expand Down

0 comments on commit 9c80e80

Please sign in to comment.