diff --git a/Cargo.lock b/Cargo.lock index 897eab2..e505e39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -732,6 +732,7 @@ dependencies = [ "cw4-group", "fs-err", "futures", + "hex", "once_cell", "quickcheck", "regex", diff --git a/packages/cosmos-bin/Cargo.toml b/packages/cosmos-bin/Cargo.toml index f8445a6..d88e6b6 100644 --- a/packages/cosmos-bin/Cargo.toml +++ b/packages/cosmos-bin/Cargo.toml @@ -28,6 +28,7 @@ cw4-group = "2.0.0" cw-utils = "2.0.0" cosmwasm-std = "2.1.4" csv = "1.3.0" +hex = "0.4" [dev-dependencies] quickcheck = "1" diff --git a/packages/cosmos-bin/src/main.rs b/packages/cosmos-bin/src/main.rs index be3888a..6bd6254 100644 --- a/packages/cosmos-bin/src/main.rs +++ b/packages/cosmos-bin/src/main.rs @@ -80,10 +80,7 @@ fn gen_wallet(hrp: AddressHrp) -> Result<()> { let phrase = cosmos::SeedPhrase::random(); let wallet = phrase.with_hrp(hrp)?; let private_key = wallet.get_privkey().private_key.display_secret(); - let mut public_key = String::new(); - for byte in wallet.public_key_bytes() { - public_key.push_str(&format!("{:02x}", byte)); - } + let public_key = hex::encode(wallet.public_key_bytes()); println!("Mnemonic: {}", phrase.phrase()); println!("Address: {wallet}"); println!("Private Key: {}", private_key); diff --git a/packages/cosmos/src/wallet.rs b/packages/cosmos/src/wallet.rs index 8c0985f..d6f574b 100644 --- a/packages/cosmos/src/wallet.rs +++ b/packages/cosmos/src/wallet.rs @@ -559,10 +559,7 @@ mod tests { let address_hrp = AddressHrp::from_static("cosmos"); let wallet = Wallet::generate(address_hrp).unwrap(); let private_key = wallet.get_privkey().private_key.display_secret(); - let mut public_key = String::new(); - for byte in wallet.public_key_bytes() { - public_key.push_str(&format!("{:02x}", byte)); - } + let public_key = hex::encode(wallet.public_key_bytes()); assert_eq!(private_key.to_string().len(), 64); assert_eq!(public_key.to_string().len(), 66); }