Skip to content

Commit

Permalink
fix: merge request-vc commands (#2500)
Browse files Browse the repository at this point in the history
* fix: merge request-vc commands

* refactor: use opposite flag and reduce redundancy

* fix: remove request_vc_direct

---------

Co-authored-by: Zhouhui Tian <125243011+zhouhuitian@users.noreply.github.com>
  • Loading branch information
felixfaisal and zhouhuitian committed Feb 21, 2024
1 parent 6ad83aa commit bc47181
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ pub mod id_graph_stats;
pub mod link_identity;
pub mod remove_identity;
pub mod request_vc;
pub mod request_vc_direct;
pub mod send_erroneous_parentchain_call;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
get_layer_two_nonce,
trusted_cli::TrustedCli,
trusted_command_utils::{get_identifiers, get_pair_from_str},
trusted_operation::perform_trusted_operation,
trusted_operation::{perform_direct_operation, perform_trusted_operation},
Cli, CliResult, CliResultOk,
};
use ita_stf::{trusted_call_result::RequestVCResult, Index, TrustedCall, TrustedCallSigning};
Expand Down Expand Up @@ -75,6 +75,9 @@ pub struct RequestVcCommand {
/// subcommand to define the vc type requested
#[clap(subcommand)]
command: Command,
/// mode for the request-vc
#[clap(short = 's', long, default_value_t = false)]
stf: bool,
}

// see `assertion.rs`
Expand Down Expand Up @@ -518,7 +521,13 @@ impl RequestVcCommand {
.sign(&KeyPair::Sr25519(Box::new(alice)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_cli.direct);

match perform_trusted_operation::<RequestVCResult>(cli, trusted_cli, &top) {
let maybe_vc = if self.stf {
perform_trusted_operation::<RequestVCResult>(cli, trusted_cli, &top)
} else {
perform_direct_operation::<RequestVCResult>(cli, trusted_cli, &top, key)
};

match maybe_vc {
Ok(mut vc) => {
let decrypted = aes_decrypt(&key, &mut vc.vc_payload).unwrap();
let credential_str = String::from_utf8(decrypted).expect("Found invalid UTF-8");
Expand All @@ -529,6 +538,7 @@ impl RequestVcCommand {
println!("{:?}", e);
},
}

Ok(CliResultOk::None)
}

Expand Down

This file was deleted.

6 changes: 1 addition & 5 deletions tee-worker/cli/src/trusted_base_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
litentry::{
get_storage::GetStorageCommand, id_graph_stats::IDGraphStats,
link_identity::LinkIdentityCommand, remove_identity::RemoveIdentityCommand,
request_vc::RequestVcCommand, request_vc_direct::RequestVcDirectCommand,
request_vc::RequestVcCommand,
send_erroneous_parentchain_call::SendErroneousParentchainCallCommand,
},
nonce::NonceCommand,
Expand Down Expand Up @@ -93,9 +93,6 @@ pub enum TrustedBaseCommand {
/// Request VC
RequestVc(RequestVcCommand),

/// Request VC isolated from Block Production
RequestVcDirect(RequestVcDirectCommand),

/// Remove Identity from the prime identity
RemoveIdentity(RemoveIdentityCommand),
}
Expand All @@ -119,7 +116,6 @@ impl TrustedBaseCommand {
TrustedBaseCommand::LinkIdentity(cmd) => cmd.run(cli, trusted_cli),
TrustedBaseCommand::IDGraph(cmd) => cmd.run(cli, trusted_cli),
TrustedBaseCommand::RequestVc(cmd) => cmd.run(cli, trusted_cli),
TrustedBaseCommand::RequestVcDirect(cmd) => cmd.run(cli, trusted_cli),
TrustedBaseCommand::RemoveIdentity(cmd) => cmd.run(cli, trusted_cli),
}
}
Expand Down

0 comments on commit bc47181

Please sign in to comment.