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] fix command sui keytool import using --alias is useless when inputting mnemonic phrase #17935

Merged
merged 17 commits into from
May 28, 2024
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
3 changes: 2 additions & 1 deletion crates/sui-keys/src/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@ pub trait AccountKeystore: Send + Sync {
phrase: &str,
key_scheme: SignatureScheme,
derivation_path: Option<DerivationPath>,
alias: Option<String>,
) -> Result<SuiAddress, anyhow::Error> {
let mnemonic = Mnemonic::from_phrase(phrase, Language::English)
.map_err(|e| anyhow::anyhow!("Invalid mnemonic phrase: {:?}", e))?;
let seed = Seed::new(&mnemonic, "");
match derive_key_pair_from_path(seed.as_bytes(), derivation_path, &key_scheme) {
Ok((address, kp)) => {
self.add_key(None, kp)?;
self.add_key(alias, kp)?;
Ok(address)
}
Err(e) => Err(anyhow!("error getting keypair {:?}", e)),
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-keys/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn mnemonic_test() {
let keystore_path_2 = temp_dir.path().join("sui2.keystore");
let mut keystore2 = Keystore::from(FileBasedKeystore::new(&keystore_path_2).unwrap());
let imported_address = keystore2
.import_from_mnemonic(&phrase, SignatureScheme::ED25519, None)
.import_from_mnemonic(&phrase, SignatureScheme::ED25519, None, None)
.unwrap();
assert_eq!(scheme.flag(), Ed25519SuiSignature::SCHEME.flag());
assert_eq!(address, imported_address);
Expand All @@ -222,7 +222,7 @@ fn sui_wallet_address_mnemonic_test() -> Result<(), anyhow::Error> {
let mut keystore = Keystore::from(FileBasedKeystore::new(&keystore_path).unwrap());

keystore
.import_from_mnemonic(phrase, SignatureScheme::ED25519, None)
.import_from_mnemonic(phrase, SignatureScheme::ED25519, None, None)
.unwrap();

let pubkey = keystore.keys()[0].clone();
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-sdk/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn mnemonic_test() {
let keystore_path_2 = temp_dir.path().join("sui2.keystore");
let mut keystore2 = Keystore::from(FileBasedKeystore::new(&keystore_path_2).unwrap());
let imported_address = keystore2
.import_from_mnemonic(&phrase, SignatureScheme::ED25519, None)
.import_from_mnemonic(&phrase, SignatureScheme::ED25519, None, None)
.unwrap();
assert_eq!(scheme.flag(), Ed25519SuiSignature::SCHEME.flag());
assert_eq!(address, imported_address);
Expand Down
1 change: 1 addition & 0 deletions crates/sui/src/keytool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ impl KeyToolCommand {
&input_string,
key_scheme,
derivation_path,
alias,
)?;
let skp = keystore.get_key(&sui_address)?;
let key = Key::from(skp);
Expand Down
Loading