Skip to content

Commit

Permalink
[rooch-networkgh-2381] fix output.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feliciss committed Sep 6, 2024
1 parent fabffcb commit e6d8acb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
10 changes: 6 additions & 4 deletions crates/rooch/src/commands/account/commands/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use moveos_types::state::MoveState;
use rooch_key::keystore::account_keystore::AccountKeystore;
use rooch_types::{
address::ParsedAddress,
crypto::Signature,
error::RoochResult,
framework::auth_payload::{SignData, MESSAGE_INFO, MESSAGE_INFO_PREFIX},
};
Expand Down Expand Up @@ -37,7 +36,7 @@ pub struct SignCommand {

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct SignAccountOutput {
pub signature: Signature,
pub signature_hash: String,
pub message_hash: String,
}

Expand All @@ -62,14 +61,17 @@ impl CommandAction<Option<SignAccountOutput>> for SignCommand {
.sign_hashed(&rooch_address, &encoded_sign_data, password)?;

let output = SignAccountOutput {
signature,
signature_hash: signature.encode_hex(),
message_hash: encoded_sign_data.encode_hex(),
};

if self.json {
Ok(Some(output))
} else {
println!("Sign message succeeded with the sign output: {:?}", output);
println!(
"Sign message succeeded with the signatue hash {} and the message hash: {}",
output.signature_hash, output.message_hash
);
Ok(None)
}
}
Expand Down
9 changes: 5 additions & 4 deletions crates/rooch/src/commands/account/commands/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use fastcrypto::{
secp256k1::{Secp256k1PublicKey, Secp256k1Signature},
traits::ToFromBytes,
};
use moveos_types::state::MoveState;
use rooch_types::{
crypto::{RoochSignature, Signature},
error::{RoochError, RoochResult},
Expand All @@ -20,7 +19,7 @@ use rooch_types::{
pub struct VerifyCommand {
/// A signature for verify
#[clap(short = 's', long)]
signature: String,
signature_hash: String,

/// A hashed message to be verified
#[clap(short = 'm', long)]
Expand All @@ -37,7 +36,9 @@ pub struct VerifyCommand {
#[async_trait]
impl CommandAction<Option<bool>> for VerifyCommand {
async fn execute(self) -> RoochResult<Option<bool>> {
let signature_bytes = self.signature.to_bytes();
let signature_bytes = hex::decode(self.signature_hash).map_err(|e| {
RoochError::CommandArgumentError(format!("Decode hex failed: {}", e.to_string()))
})?;
let signatrue = Signature::from_bytes(&signature_bytes).map_err(|e| {
RoochError::CommandArgumentError(format!(
"Invalid signature argument: {}",
Expand Down Expand Up @@ -65,7 +66,7 @@ impl CommandAction<Option<bool>> for VerifyCommand {
Ok(Some(true))
} else {
println!("Verification succeeded");
Ok(Some(true))
Ok(None)
}
}
}
2 changes: 1 addition & 1 deletion crates/testsuite/features/cmd.feature
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Feature: Rooch CLI integration tests

# account sign and verify
Then cmd: "account sign -a {{$.account[-1].account0.address}} -m 'empty' --json"
Then cmd: "account verify -s {{$.account[-1].signature}} -m {{$.account[-1].message_hash}}"
Then cmd: "account verify -s {{$.account[-1].signature_hash}} -m {{$.account[-1].message_hash}}"

# account balance
Then cmd: "account balance"
Expand Down

0 comments on commit e6d8acb

Please sign in to comment.