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

feat(iota): don't require key generation for client.yaml if there is already one #3978

Merged
merged 5 commits into from
Nov 28, 2024
Merged
Changes from 3 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
38 changes: 22 additions & 16 deletions crates/iota/src/iota_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,29 +1201,35 @@ async fn prompt_if_no_config(
.unwrap_or(&iota_config_dir()?)
.join(IOTA_KEYSTORE_FILENAME);
let mut keystore = Keystore::from(FileBasedKeystore::new(&keystore_path)?);
let key_scheme = if accept_defaults {
SignatureScheme::ED25519
// Get an existing address or generate a new one
let active_address = if let Some(existing_address) = keystore.addresses().first() {
*existing_address
} else {
let key_scheme = if accept_defaults {
SignatureScheme::ED25519
} else {
println!(
"Select key scheme to generate keypair (0 for ed25519, 1 for secp256k1, 2: for secp256r1):"
);
match SignatureScheme::from_flag(read_line()?.trim()) {
Ok(s) => s,
Err(e) => return Err(anyhow!("{e}")),
}
};
let (new_address, phrase, scheme) =
keystore.generate_and_add_new_key(key_scheme, None, None, None)?;
let alias = keystore.get_alias_by_address(&new_address)?;
println!(
"Select key scheme to generate keypair (0 for ed25519, 1 for secp256k1, 2: for secp256r1):"
"Generated new keypair and alias for address with scheme {:?} [{alias}: {new_address}]",
scheme.to_string()
);
match SignatureScheme::from_flag(read_line()?.trim()) {
Ok(s) => s,
Err(e) => return Err(anyhow!("{e}")),
}
println!("Secret Recovery Phrase : [{phrase}]");
new_address
};
let (new_address, phrase, scheme) =
keystore.generate_and_add_new_key(key_scheme, None, None, None)?;
let alias = keystore.get_alias_by_address(&new_address)?;
println!(
"Generated new keypair and alias for address with scheme {:?} [{alias}: {new_address}]",
scheme.to_string()
);
println!("Secret Recovery Phrase : [{phrase}]");
let alias = env.alias().clone();
IotaClientConfig::new(keystore)
.with_envs([env])
.with_active_address(new_address)
.with_active_address(active_address)
.with_active_env(alias)
.persisted(wallet_conf_path)
.save()?;
Expand Down
Loading