Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI wallet: Ledger Nano support #1606

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4f30cbd
finish impl
Alex6323 Nov 10, 2023
8c40009
changelog
Alex6323 Nov 10, 2023
790b5c9
Add Ledger Nano simulator choice
Alex6323 Nov 10, 2023
6316084
panic instead of unreachable
Alex6323 Nov 14, 2023
29f7d4f
Merge branch 'develop' into feat/cli/ledger-nano-support
Alex6323 Nov 14, 2023
b63bb3a
panic message
Alex6323 Nov 15, 2023
88ccfd2
full ledger nano support
Alex6323 Nov 15, 2023
22534e2
Merge branch 'develop' into feat/cli/ledger-nano-support
Alex6323 Nov 17, 2023
9ff617b
Merge branch 'develop' into feat/cli/ledger-nano-support
thibault-martinez Nov 24, 2023
374cf32
Merge branch 'develop' into feat/cli/ledger-nano-support
Thoralf-M Nov 29, 2023
1af13b9
Merge branch 'develop' into feat/cli/ledger-nano-support
Alex6323 Dec 11, 2023
2146605
Merge branch 'develop' into feat/cli/ledger-nano-support
Alex6323 Jan 8, 2024
6572ef5
fix usability issues
Alex6323 Jan 10, 2024
6be0c25
fix backup/restore
Alex6323 Jan 10, 2024
11b641a
clean up failed restore
Alex6323 Jan 10, 2024
fff53e4
Merge branch 'develop' into feat/cli/ledger-nano-support
Alex6323 Jan 10, 2024
46aa65e
PR suggestion
Alex6323 Jan 11, 2024
3ad1634
small cleanup
Alex6323 Jan 11, 2024
b32d194
Update year (how time flies :see_no_evil:)
Alex6323 Jan 11, 2024
7813b6d
revert breaking change
Alex6323 Jan 12, 2024
c77ee0d
fix fs cleanup after failed restore
Alex6323 Jan 12, 2024
3cbd368
getter
Alex6323 Jan 16, 2024
aaa57c8
derive ValueEnum
Alex6323 Jan 16, 2024
467d9a6
optional secret manager choice
Alex6323 Jan 16, 2024
edb77d1
remove unnecessary password input
Alex6323 Jan 16, 2024
03a4e9e
create initial account for init
Alex6323 Jan 16, 2024
b4e0867
ensure set stronghold password (lazily)
Alex6323 Jan 16, 2024
c1bbf5f
fix
Alex6323 Jan 16, 2024
b09cc16
changelog
Alex6323 Jan 17, 2024
f877a07
Merge branch 'develop' into feat/cli/ledger-nano-support
Alex6323 Jan 22, 2024
eeb85cb
Merge branch 'develop' into feat/cli/ledger-nano-support
thibault-martinez Jan 22, 2024
62b57ba
Edit changelog
thibault-martinez Jan 23, 2024
e0439de
Bump version and changelog
thibault-martinez Jan 23, 2024
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: 6 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security -->

## 1.3.0 - 2023-xx-xx
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved

### Added

- Ledger Nano support;

## 1.2.0 - 2023-10-26

### Added
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ iota-sdk = { path = "../sdk", default-features = false, features = [
"rocksdb",
"stronghold",
"participation",
"ledger_nano",
] }

chrono = { version = "0.4.31", default-features = false, features = ["std"] }
Expand Down
35 changes: 23 additions & 12 deletions cli/src/command/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use clap::{builder::BoolishValueParser, Args, CommandFactory, Parser, Subcommand
use iota_sdk::{
client::{
constants::SHIMMER_COIN_TYPE,
secret::{stronghold::StrongholdSecretManager, SecretManager},
secret::{ledger_nano::LedgerSecretManager, stronghold::StrongholdSecretManager, SecretManager},
stronghold::StrongholdAdapter,
utils::Password,
},
Expand All @@ -17,7 +17,10 @@ use log::LevelFilter;

use crate::{
error::Error,
helper::{check_file_exists, enter_or_generate_mnemonic, generate_mnemonic, get_password, import_mnemonic},
helper::{
check_file_exists, enter_or_generate_mnemonic, generate_mnemonic, get_password, import_mnemonic,
select_secret_manager, SecretManagerChoice,
},
println_log_error, println_log_info,
};

Expand Down Expand Up @@ -184,17 +187,25 @@ pub async fn init_command(
snapshot_path.display()
)));
}
let password = get_password("Stronghold password", true)?;
let mnemonic = match parameters.mnemonic_file_path {
Some(path) => import_mnemonic(&path).await?,
None => enter_or_generate_mnemonic().await?,
};

let secret_manager = StrongholdSecretManager::builder()
.password(password)
.build(snapshot_path)?;
secret_manager.store_mnemonic(mnemonic).await?;
let secret_manager = SecretManager::Stronghold(secret_manager);
let secret_manager = match select_secret_manager().await? {
SecretManagerChoice::Stronghold => {
let password = get_password("Stronghold password", true)?;
let mnemonic = match parameters.mnemonic_file_path {
Some(path) => import_mnemonic(&path).await?,
None => enter_or_generate_mnemonic().await?,
};

let secret_manager = StrongholdSecretManager::builder()
.password(password)
.build(snapshot_path)?;
secret_manager.store_mnemonic(mnemonic).await?;

SecretManager::Stronghold(secret_manager)
}
SecretManagerChoice::LedgerNano => SecretManager::LedgerNano(LedgerSecretManager::new(false)),
SecretManagerChoice::LedgerNanoSimulator => SecretManager::LedgerNano(LedgerSecretManager::new(true)),
};

Ok(Wallet::builder()
.with_secret_manager(secret_manager)
Expand Down
30 changes: 29 additions & 1 deletion cli/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub async fn enter_or_generate_mnemonic() -> Result<Mnemonic, Error> {
let mnemonic = match selected_choice {
0 => generate_mnemonic(None, None).await?,
1 => enter_mnemonic()?,
_ => unreachable!(),
_ => panic!("invalid choice index"),
};

Ok(mnemonic)
Expand Down Expand Up @@ -343,3 +343,31 @@ pub async fn check_file_exists(path: &Path) -> Result<(), Error> {
}
Ok(())
}

pub enum SecretManagerChoice {
Stronghold,
LedgerNano,
LedgerNanoSimulator,
}

impl From<usize> for SecretManagerChoice {
fn from(value: usize) -> Self {
match value {
0 => Self::Stronghold,
1 => Self::LedgerNano,
Thoralf-M marked this conversation as resolved.
Show resolved Hide resolved
2 => Self::LedgerNanoSimulator,
_ => panic!("invalid choice index"),
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

pub async fn select_secret_manager() -> Result<SecretManagerChoice, Error> {
let choices = ["Stronghold", "Ledger Nano", "Ledger Nano Simulator"];

Ok(Select::with_theme(&ColorfulTheme::default())
.with_prompt("Select secret manager")
.items(&choices)
.default(0)
.interact_on(&Term::stderr())?
.into())
}
Loading