Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/account_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use iota_wallet::{

use crate::{
command::account_manager::{
init_command, new_command, set_node_command, sync_command, AccountManagerCli, AccountManagerCommand,
change_password_command, init_command, new_command, set_node_command, sync_command, AccountManagerCli,
AccountManagerCommand,
},
error::Error,
helper::get_password,
Expand All @@ -23,7 +24,7 @@ pub async fn new_account_manager(cli: AccountManagerCli) -> Result<(AccountManag
);
let stronghold_path = std::path::Path::new("./stardust-cli-wallet.stronghold");

let password = get_password(stronghold_path)?;
let password = get_password("Stronghold password", !stronghold_path.exists())?;
let secret_manager = SecretManager::Stronghold(
StrongholdSecretManager::builder()
.password(&password)
Expand All @@ -42,6 +43,7 @@ pub async fn new_account_manager(cli: AccountManagerCli) -> Result<(AccountManag
let mut account = None;

match command {
AccountManagerCommand::ChangePassword => change_password_command(&account_manager, &password).await?,
// PANIC: this will never happen because of the if/else.
AccountManagerCommand::Init(_) => unreachable!(),
AccountManagerCommand::New { alias } => account = Some(new_command(&account_manager, alias).await?),
Expand Down
19 changes: 16 additions & 3 deletions src/command/account_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use iota_wallet::{
};
use log::LevelFilter;

use crate::error::Error;
use crate::{error::Error, helper::get_password};

#[derive(Debug, Clone, Parser)]
#[clap(version, long_about = None)]
Expand All @@ -26,12 +26,17 @@ pub struct AccountManagerCli {

#[derive(Debug, Clone, Subcommand)]
pub enum AccountManagerCommand {
ChangePassword,
/// Parameters for the init command.
Init(InitParameters),
/// Create a new account with an optional alias.
New { alias: Option<String> },
New {
alias: Option<String>,
},
/// Set the node to use.
SetNode { url: String },
SetNode {
url: String,
},
/// Sync all accounts.
Sync,
}
Expand All @@ -46,6 +51,14 @@ pub struct InitParameters {
pub coin_type: Option<u32>,
}

pub async fn change_password_command(manager: &AccountManager, current: &str) -> Result<(), Error> {
let new = get_password("Stronghold new password", true)?;

manager.change_stronghold_password(&current, &new).await?;

Ok(())
}

pub async fn init_command(
secret_manager: SecretManager,
storage_path: String,
Expand Down
15 changes: 6 additions & 9 deletions src/helper.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
// Copyright 2020-2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::path::Path;

use dialoguer::{console::Term, theme::ColorfulTheme, Password, Select};
use iota_wallet::account_manager::AccountManager;

use crate::error::Error;

pub fn get_password(path: &Path) -> Result<String, Error> {
let mut prompt = Password::new();
pub fn get_password(prompt: &str, confirmation: bool) -> Result<String, Error> {
let mut password = Password::new();

prompt.with_prompt("Stronghold password");
password.with_prompt(prompt);

// Check if the stronghold exists already
if !path.exists() {
prompt.with_confirmation("Confirm password", "Password mismatch");
if confirmation {
password.with_confirmation("Confirm password", "Password mismatch");
}

Ok(prompt.interact()?)
Ok(password.interact()?)
}

pub async fn pick_account(manager: &AccountManager) -> Result<Option<u32>, Error> {
Expand Down