-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…2566) * [gh-2381] add msg prefix to the account sign command. * [gh-2381] modify the sign command output as msg and auth payload. * [gh-2381] modify sign command for signing. * [gh-2381] add verify command. * [gh-2381] revise the sign and verify process. * [gh-2381] revise account verify command and add tests. * [gh-2381] follow #2580 to add account sign command. * [gh-2381] fix some issues of the account sign command. * [gh-2381] revise account verify command. * [gh-2381] revise the integ test. * [gh-2381] fix issues arisen from comments. * [gh-2381] fix cmd.feature. * [gh-2381] fix output. * [gh-2381] fix lint issues. * [gh-2381] fix tests. * [gh-2381] add assert to test and parsed signature struct. * [gh-2381] format the code. * [gh-2381] revise the signature hex and verify command. * [gh-2381] fix the issue of verification. --------- Co-authored-by: Feliciss <10203-feliciss@users.noreply.0xacab.org>
- Loading branch information
Showing
11 changed files
with
167 additions
and
47 deletions.
There are no files selected for viewing
17 changes: 0 additions & 17 deletions
17
crates/rooch-rpc-api/src/jsonrpc_types/account_sign_view.rs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::crypto::Signature; | ||
use fastcrypto::traits::ToFromBytes; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
// Parsed Rooch Signature, either Ed25519RoochSignature or Secp256k1RoochSignature | ||
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] | ||
pub struct ParsedSignature(Signature); | ||
|
||
impl ParsedSignature { | ||
pub fn into_inner(self) -> Signature { | ||
self.0 | ||
} | ||
|
||
pub fn from_signature(signature: Signature) -> Self { | ||
Self(signature) | ||
} | ||
|
||
pub fn parse(s: &str) -> anyhow::Result<Self, anyhow::Error> { | ||
let signature_bytes = hex::decode(s)?; | ||
Ok(Self::from_signature(Signature::from_bytes( | ||
&signature_bytes, | ||
)?)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ pub mod nullify; | |
pub mod sign; | ||
pub mod switch; | ||
pub mod transfer; | ||
pub mod verify; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::cli_types::{CommandAction, WalletContextOptions}; | ||
use async_trait::async_trait; | ||
use clap::Parser; | ||
use moveos_types::state::MoveState; | ||
use rooch_types::{ | ||
crypto::RoochSignature, | ||
error::RoochResult, | ||
framework::auth_payload::{SignData, MESSAGE_INFO_PREFIX}, | ||
rooch_signature::ParsedSignature, | ||
}; | ||
|
||
/// Verify a signature | ||
#[derive(Debug, Parser)] | ||
pub struct VerifyCommand { | ||
/// A signature for verify | ||
#[clap(short = 's', long, value_parser=ParsedSignature::parse)] | ||
signature: ParsedSignature, | ||
|
||
/// An original message to be verified | ||
#[clap(short = 'm', long)] | ||
message: String, | ||
|
||
#[clap(flatten)] | ||
pub context_options: WalletContextOptions, | ||
|
||
/// Return command outputs in json format | ||
#[clap(long, default_value = "false")] | ||
json: bool, | ||
} | ||
|
||
#[async_trait] | ||
impl CommandAction<Option<bool>> for VerifyCommand { | ||
async fn execute(self) -> RoochResult<Option<bool>> { | ||
let sign_data = | ||
SignData::new_without_tx_hash(MESSAGE_INFO_PREFIX.to_vec(), self.message.to_bytes()); | ||
let encoded_sign_data = sign_data.encode(); | ||
let verify_result = self | ||
.signature | ||
.into_inner() | ||
.verify(&encoded_sign_data) | ||
.is_ok(); | ||
|
||
if self.json { | ||
Ok(Some(verify_result)) | ||
} else { | ||
println!("Verification result: {}", verify_result); | ||
Ok(None) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters