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)!: show publicBase64Key without flag in keytool show #4637

Merged
merged 5 commits into from
Jan 6, 2025
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
2 changes: 1 addition & 1 deletion crates/iota/src/keytool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ impl From<PublicKey> for Key {
Key {
alias: None, // this is retrieved later
iota_address: IotaAddress::from(&pk),
public_base64_key: pk.encode_base64(),
public_base64_key: Base64::encode(pk.as_ref()),
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
key_scheme: pk.scheme().to_string(),
mnemonic: None,
flag: pk.flag(),
Expand Down
39 changes: 39 additions & 0 deletions crates/iota/src/unit_tests/keytool_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,3 +620,42 @@ async fn test_sign_command() -> Result<(), anyhow::Error> {
.await?;
Ok(())
}

#[test]
async fn test_show() -> Result<(), anyhow::Error> {
let temp_dir = TempDir::new().unwrap();
let path = temp_dir.path().join("iota.key");

// First create a .key file with a private key
std::fs::write(
&path,
"iotaprivkey1qp3asak8fsdwcrxc8fys02mhsg3fs35d7fe45s5zcyg6x3sp9zsw5wqnj5v",
)
.unwrap();

let mut keystore = Keystore::from(InMemKeystore::new_insecure_for_tests(0));
let output = KeyToolCommand::Show { file: path }
.execute(&mut keystore)
.await?;
match output {
CommandOutput::Show(key) => {
assert_eq!(
&key.iota_address.to_string(),
"0x5f60f23c01486c6af8540144cf9fa74c167257b93c08fc33b74b8f173a885038"
);
assert_eq!(
&key.public_base64_key,
"svUb1I94/15y2k6LKaEWqNLFf1rNMHq0hcWFAJynu0g="
);
assert_eq!(&key.key_scheme, "ed25519");
assert_eq!(key.flag, 0);
assert_eq!(
&key.peer_id.unwrap(),
"b2f51bd48f78ff5e72da4e8b29a116a8d2c57f5acd307ab485c585009ca7bb48"
);
}
_ => panic!("unexpected output: {output:?}"),
}

Ok(())
}
8 changes: 4 additions & 4 deletions docs/content/references/cli/keytool.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ $ iota keytool list
╭────────────────────────────────────────────────────────────────────────────────────────────╮
│ ╭─────────────────┬──────────────────────────────────────────────────────────────────────╮ │
│ │ iotaAddress │ 0x3047f142a84297a42a65fb0a8c7a716d9d1b0bd0413d6bfa5ddfec45df175235 │ │
│ │ publicBase64Key │ AHsXwcxaWNaNtCIIszwu7V2G6HO8aNM1598w/8y0zI5q │ │
│ │ publicBase64Key │ exfBzFpY1o20IgizPC7tXYboc7xo0zXn3zD/zLTMjmo= │ │
│ │ keyScheme │ ed25519 │ │
│ │ flag │ 0 │ │
│ │ peerId │ 7b17c1cc5a58d68db42208b33c2eed5d86e873bc68d335e7df30ffccb4cc8e6a │ │
│ ╰─────────────────┴──────────────────────────────────────────────────────────────────────╯ │
│ ╭─────────────────┬──────────────────────────────────────────────────────────────────────╮ │
│ │ iotaAddress │ 0x514692f08249c3e9957799ce29074695840422564bff85e424b56de462913e0d │ │
│ │ publicBase64Key │ AKJCGi8R8TslhYdO2OHIjI6rbr+to1eR+vlOjigLY6SX │ │
│ │ publicBase64Key │ okIaLxHxOyWFh07Y4ciMjqtuv62jV5H6+U6OKAtjpJc= │ │
│ │ keyScheme │ ed25519 │ │
│ │ flag │ 0 │ │
│ │ peerId │ a2421a2f11f13b2585874ed8e1c88c8eab6ebfada35791faf94e8e280b63a497 │ │
Expand All @@ -89,7 +89,7 @@ To generate a new key pair with the `ed25519` scheme, use the `iota keytool gene
$ iota keytool generate ed25519
╭─────────────────┬───────────────────────────────────────────────────────────────────────────────────╮
│ iotaAddress │ 0x5d8aa70f17d9343813d3ba6a59ecf5e8a23ffb487938e860999a722989eaef25 │
│ publicBase64Key │ AKTAGf9iv0JqeLXXlsr4PUzBXb9VY8lK7xiZMS50GSu6
│ publicBase64Key │ pMAZ/2K/Qmp4tdeWyvg9TMFdv1VjyUrvGJkxLnQZK7o=
│ keyScheme │ ed25519 │
│ flag │ 0 │
│ mnemonic │ cushion price ability recall payment embody kid media rude mosquito chalk broom │
Expand All @@ -105,7 +105,7 @@ Use `iota keytool show [filename]` to show the key pair data that is stored in a
$ iota keytool show 0x5d8aa70f17d9343813d3ba6a59ecf5e8a23ffb487938e860999a722989eaef25.key
╭─────────────────┬──────────────────────────────────────────────────────────────────────╮
│ iotaAddress │ 0x5d8aa70f17d9343813d3ba6a59ecf5e8a23ffb487938e860999a722989eaef25 │
│ publicBase64Key │ AC+AKTAGf9iv0JqeLXXlsr4PUzBXb9VY8lK7xiZMS50GSu6
│ publicBase64Key │ L4ApMAZ/2K/Qmp4tdeWyvg9TMFdv1VjyUrvGJkxLnQZK7g==
│ keyScheme │ ed25519 │
│ flag │ 0 │
│ peerId │ a4c019ff62bf426a78b5d796caf83d4cc15dbf5563c94aef1899312e74192bba │
Expand Down