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 all 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: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 - 2024-01-23

### Added

- Ledger Nano support;

## 1.2.0 - 2023-10-26

### Added
Expand Down
3 changes: 2 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cli-wallet"
version = "1.2.0"
version = "1.3.0"
authors = ["IOTA Stiftung"]
edition = "2021"
homepage = "https://iota.org"
Expand All @@ -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
73 changes: 62 additions & 11 deletions cli/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

use clap::Parser;
use colored::Colorize;
use iota_sdk::wallet::{Account, Wallet};
use iota_sdk::{
client::secret::SecretManager,
wallet::{Account, Wallet},
};
use rustyline::{error::ReadlineError, history::MemHistory, Config, Editor};

use crate::{
Expand All @@ -22,7 +25,7 @@ use crate::{
account_completion::AccountPromptHelper,
},
error::Error,
helper::bytes_from_hex_or_file,
helper::{bytes_from_hex_or_file, get_password},
println_log_error,
};

Expand Down Expand Up @@ -62,6 +65,17 @@ pub enum AccountPromptResponse {
Switch(Account),
}

async fn ensure_password(wallet: &Wallet) -> Result<(), Error> {
if matches!(*wallet.get_secret_manager().read().await, SecretManager::Stronghold(_))
&& !wallet.is_stronghold_password_available().await?
{
let password = get_password("Stronghold password", false)?;
wallet.set_stronghold_password(password).await?;
}

Ok(())
}

// loop on the account prompt
pub async fn account_prompt_internal(
wallet: &Wallet,
Expand Down Expand Up @@ -110,19 +124,33 @@ pub async fn account_prompt_internal(
AccountCommand::Addresses => addresses_command(account).await,
AccountCommand::Balance { addresses } => balance_command(account, addresses).await,
AccountCommand::BurnNativeToken { token_id, amount } => {
ensure_password(wallet).await?;
burn_native_token_command(account, token_id, amount).await
}
AccountCommand::BurnNft { nft_id } => burn_nft_command(account, nft_id).await,
AccountCommand::Claim { output_id } => claim_command(account, output_id).await,
AccountCommand::BurnNft { nft_id } => {
ensure_password(wallet).await?;
burn_nft_command(account, nft_id).await
}
AccountCommand::Claim { output_id } => {
ensure_password(wallet).await?;
claim_command(account, output_id).await
}
AccountCommand::ClaimableOutputs => claimable_outputs_command(account).await,
AccountCommand::Consolidate => consolidate_command(account).await,
AccountCommand::CreateAliasOutput => create_alias_outputs_command(account).await,
AccountCommand::Consolidate => {
ensure_password(wallet).await?;
consolidate_command(account).await
}
AccountCommand::CreateAliasOutput => {
ensure_password(wallet).await?;
create_alias_outputs_command(account).await
}
AccountCommand::CreateNativeToken {
circulating_supply,
maximum_supply,
foundry_metadata_hex,
foundry_metadata_file,
} => {
ensure_password(wallet).await?;
create_native_token_command(
account,
circulating_supply,
Expand All @@ -131,18 +159,24 @@ pub async fn account_prompt_internal(
)
.await
}
AccountCommand::DestroyAlias { alias_id } => destroy_alias_command(account, alias_id).await,
AccountCommand::DestroyAlias { alias_id } => {
ensure_password(wallet).await?;
destroy_alias_command(account, alias_id).await
}
AccountCommand::DestroyFoundry { foundry_id } => {
ensure_password(wallet).await?;
destroy_foundry_command(account, foundry_id).await
}
AccountCommand::Exit => {
return Ok(AccountPromptResponse::Done);
}
AccountCommand::Faucet { address, url } => faucet_command(account, address, url).await,
AccountCommand::MeltNativeToken { token_id, amount } => {
ensure_password(wallet).await?;
melt_native_token_command(account, token_id, amount).await
}
AccountCommand::MintNativeToken { token_id, amount } => {
ensure_password(wallet).await?;
mint_native_token(account, token_id, amount).await
}
AccountCommand::MintNft {
Expand All @@ -155,6 +189,7 @@ pub async fn account_prompt_internal(
sender,
issuer,
} => {
ensure_password(wallet).await?;
mint_nft_command(
account,
address,
Expand All @@ -166,7 +201,10 @@ pub async fn account_prompt_internal(
)
.await
}
AccountCommand::NewAddress => new_address_command(account).await,
AccountCommand::NewAddress => {
ensure_password(wallet).await?;
new_address_command(account).await
}
AccountCommand::NodeInfo => node_info_command(account).await,
AccountCommand::Output { selector } => output_command(account, selector).await,
AccountCommand::Outputs => outputs_command(account).await,
Expand All @@ -177,6 +215,7 @@ pub async fn account_prompt_internal(
expiration,
allow_micro_amount,
} => {
ensure_password(wallet).await?;
let allow_micro_amount = if return_address.is_some() || expiration.is_some() {
true
} else {
Expand All @@ -197,8 +236,14 @@ pub async fn account_prompt_internal(
token_id,
amount,
gift_storage_deposit,
} => send_native_token_command(account, address, token_id, amount, gift_storage_deposit).await,
AccountCommand::SendNft { address, nft_id } => send_nft_command(account, address, nft_id).await,
} => {
ensure_password(wallet).await?;
send_native_token_command(account, address, token_id, amount, gift_storage_deposit).await
}
AccountCommand::SendNft { address, nft_id } => {
ensure_password(wallet).await?;
send_nft_command(account, address, nft_id).await
}
AccountCommand::Switch { account_id } => {
return Ok(AccountPromptResponse::Switch(wallet.get_account(account_id).await?));
}
Expand All @@ -208,8 +253,12 @@ pub async fn account_prompt_internal(
transactions_command(account, show_details).await
}
AccountCommand::UnspentOutputs => unspent_outputs_command(account).await,
AccountCommand::Vote { event_id, answers } => vote_command(account, event_id, answers).await,
AccountCommand::Vote { event_id, answers } => {
ensure_password(wallet).await?;
vote_command(account, event_id, answers).await
}
AccountCommand::StopParticipating { event_id } => {
ensure_password(wallet).await?;
stop_participating_command(account, event_id).await
}
AccountCommand::ParticipationOverview { event_ids } => {
Expand All @@ -218,9 +267,11 @@ pub async fn account_prompt_internal(
}
AccountCommand::VotingPower => voting_power_command(account).await,
AccountCommand::IncreaseVotingPower { amount } => {
ensure_password(wallet).await?;
increase_voting_power_command(account, amount).await
}
AccountCommand::DecreaseVotingPower { amount } => {
ensure_password(wallet).await?;
decrease_voting_power_command(account, amount).await
}
AccountCommand::VotingOutput => voting_output_command(account).await,
Expand Down
Loading
Loading