Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
print vc request result
  • Loading branch information
kziemianek committed Nov 13, 2023
commit 8c06470c1fafa65c53098b1b4cb439aa52b4a1fc
8 changes: 4 additions & 4 deletions scripts/launch-local-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ if [[ -z "${NODE_ENV}" ]]; then
else
echo "NODE_ENV=${NODE_ENV}" > .env
fi
pnpm install
pnpm run register-parathread 2>&1 | tee "$LITENTRY_PARACHAIN_DIR/register-parathread.log"
corepack pnpm install
corepack pnpm run register-parathread 2>&1 | tee "$LITENTRY_PARACHAIN_DIR/register-parathread.log"
print_divider

echo "upgrade parathread to parachain now ..."
Expand All @@ -129,8 +129,8 @@ if [[ -z "${NODE_ENV}" ]]; then
else
echo "NODE_ENV=${NODE_ENV}" > .env
fi
pnpm install
pnpm run upgrade-parathread 2>&1 | tee "$LITENTRY_PARACHAIN_DIR/upgrade-parathread.log"
corepack pnpm install
corepack pnpm run upgrade-parathread 2>&1 | tee "$LITENTRY_PARACHAIN_DIR/upgrade-parathread.log"
print_divider

echo "done. please check $LITENTRY_PARACHAIN_DIR for generated files if need"
Expand Down
2 changes: 1 addition & 1 deletion tee-worker/app-libs/stf/src/trusted_call_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use itp_types::H256;
use litentry_primitives::AesOutput;
use std::vec::Vec;

#[derive(Encode, Decode)]
#[derive(Encode, Decode, Debug)]
pub enum TrustedCallResult {
Empty,
Streamed,
Expand Down
3 changes: 0 additions & 3 deletions tee-worker/cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

use itp_node_api::api_client::ApiClientError;
use itp_types::parentchain::{BlockHash, BlockNumber};
use std::result::Result as StdResult;

pub type Result<T> = StdResult<T, Error>;

#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ impl IDGraphCommand {

let top: TrustedOperation =
TrustedGetter::id_graph(id).sign(&KeyPair::Sr25519(Box::new(alice))).into();
let idgraph = perform_trusted_operation(cli, trusted_cli, &top)
.map(|v| IDGraph::<Runtime>::decode(&mut v.unwrap().as_slice()).ok());
let idgraph = perform_trusted_operation::<Option<IDGraph::<Runtime>>>(cli, trusted_cli, &top);
println!("{:?}", idgraph.unwrap().unwrap());

Ok(CliResultOk::None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ impl IDGraphStats {
let top: TrustedOperation = TrustedGetter::id_graph_stats(who.public().into())
.sign(&KeyPair::Sr25519(Box::new(who)))
.into();
let id_graph_stats = perform_trusted_operation(cli, trusted_cli, &top)
.map(|v| IDGraphStatsVec::decode(&mut v.unwrap().as_slice()).ok());

let id_graph_stats = perform_trusted_operation::<Option<IDGraphStatsVec>>(cli, trusted_cli, &top);
println!("IDGraph stats:");
match id_graph_stats {
Ok(id_graph_stats) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl LinkIdentityCommand {
)
.sign(&KeyPair::Sr25519(Box::new(alice)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_cli.direct);
Ok(perform_trusted_operation(cli, trusted_cli, &top).map(|_| CliResultOk::None)?)
//todo proper generic type
Ok(perform_trusted_operation::<Vec<u8>>(cli, trusted_cli, &top).map(|_| CliResultOk::None)?)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ use crate::{
Cli, CliResult, CliResultOk,
};
use codec::Decode;
use ita_stf::{Index, TrustedCall, TrustedOperation};
use ita_stf::{Index, TrustedCall, TrustedOperation, TrustedGetter};
use itp_stf_primitives::types::KeyPair;
use itp_utils::hex::decode_hex;
use litentry_primitives::{
AchainableAmount, AchainableAmountHolding, AchainableAmountToken, AchainableAmounts,
AchainableBasic, AchainableBetweenPercents, AchainableClassOfYear, AchainableDate,
AchainableDateInterval, AchainableDatePercent, AchainableParams, AchainableToken, Assertion,
Identity, OneBlockCourseType, ParameterString, Web3Network,
Identity, OneBlockCourseType, ParameterString, Web3Network, UserShieldingKeyType, AesOutput, aes_decrypt
};
use log::*;
use sp_core::Pair;
use ita_stf::trusted_call_result::RequestVCResult;

// usage example (you can always use --help on subcommands to see more details)
//
Expand Down Expand Up @@ -382,13 +383,31 @@ impl RequestVcCommand {
},
};

let top_getter: TrustedOperation = TrustedGetter::user_shielding_key(id.clone())
.sign(&KeyPair::Sr25519(Box::new(alice.clone())))
.into();
let key = perform_trusted_operation::<Option<UserShieldingKeyType>>(cli, trusted_cli, &top_getter);

let real_key = key.unwrap().unwrap();
println!("Got real key: {:?}", real_key);


let top: TrustedOperation =
TrustedCall::request_vc(alice.public().into(), id, assertion, None, Default::default())
.sign(&KeyPair::Sr25519(Box::new(alice)), nonce, &mrenclave, &shard)
.sign(&KeyPair::Sr25519(Box::new(alice)), 2, &mrenclave, &shard)
.into_trusted_operation(trusted_cli.direct);

// TODO: P-177, print actual VC content to stdout
let _vc = perform_trusted_operation(cli, trusted_cli, &top).unwrap();

match perform_trusted_operation::<RequestVCResult>(cli, trusted_cli, &top) {
Ok(mut vc) => {

let vc_content = aes_decrypt(&real_key, &mut vc.vc_payload);
println!("Got vc result: {:?} with vc_content: {:?}", vc, vc_content);
},
Err(e) => {
println!("{:?}", e);
}
}
Ok(CliResultOk::None)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use ita_stf::{Index, TrustedCall, TrustedOperation};
use itp_stf_primitives::types::KeyPair;
use log::*;
use sp_core::Pair;
use ita_stf::trusted_call_result::TrustedCallResult;

#[derive(Parser)]
pub struct SendErroneousParentchainCallCommand {}
Expand All @@ -41,6 +42,6 @@ impl SendErroneousParentchainCallCommand {
TrustedCall::send_erroneous_parentchain_call(root.public().into())
.sign(&KeyPair::Sr25519(Box::new(root)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_cli.direct);
Ok(perform_trusted_operation(cli, trusted_cli, &top).map(|_| CliResultOk::None)?)
Ok(perform_trusted_operation::<TrustedCallResult>(cli, trusted_cli, &top).map(|_| CliResultOk::None)?)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use itp_stf_primitives::types::KeyPair;
use litentry_primitives::{Identity, UserShieldingKeyType};
use log::*;
use sp_core::Pair;
use ita_stf::trusted_call_result::SetUserShieldingKeyResult;

#[derive(Parser)]
pub struct SetUserShieldingKeyCommand {
Expand All @@ -50,8 +51,8 @@ impl SetUserShieldingKeyCommand {

let top: TrustedOperation =
TrustedCall::set_user_shielding_key(alice.public().into(), id, key, Default::default())
.sign(&KeyPair::Sr25519(Box::new(alice)), nonce, &mrenclave, &shard)
.sign(&KeyPair::Sr25519(Box::new(alice)), 0, &mrenclave, &shard)
.into_trusted_operation(trusted_cli.direct);
Ok(perform_trusted_operation(cli, trusted_cli, &top).map(|_| CliResultOk::None)?)
Ok(perform_trusted_operation::<SetUserShieldingKeyResult>(cli, trusted_cli, &top).map(|_| CliResultOk::None)?)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ impl UserShieldingKeyCommand {
let top: TrustedOperation = TrustedGetter::user_shielding_key(id)
.sign(&KeyPair::Sr25519(Box::new(alice)))
.into();
let key = perform_trusted_operation(cli, trusted_cli, &top)
.map(|v| UserShieldingKeyType::decode(&mut v.unwrap().as_slice()).ok());
let key = perform_trusted_operation::<Option<UserShieldingKeyType>>(cli, trusted_cli, &top);
println!("{}", hex::encode(key.unwrap().unwrap()));

Ok(CliResultOk::None)
Expand Down
3 changes: 2 additions & 1 deletion tee-worker/cli/src/trusted_base_cli/commands/set_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use litentry_primitives::ParentchainBalance as Balance;
use log::*;
use sp_core::{crypto::Ss58Codec, Pair};
use std::boxed::Box;
use ita_stf::trusted_call_result::TrustedCallResult;

#[derive(Parser)]
pub struct SetBalanceCommand {
Expand Down Expand Up @@ -57,6 +58,6 @@ impl SetBalanceCommand {
)
.sign(&KeyPair::Sr25519(Box::new(signer)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_args.direct);
Ok(perform_trusted_operation(cli, trusted_args, &top).map(|_| CliResultOk::None)?)
Ok(perform_trusted_operation::<TrustedCallResult>(cli, trusted_args, &top).map(|_| CliResultOk::None)?)
}
}
3 changes: 2 additions & 1 deletion tee-worker/cli/src/trusted_base_cli/commands/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use litentry_primitives::ParentchainBalance as Balance;
use log::*;
use sp_core::{crypto::Ss58Codec, Pair};
use std::boxed::Box;
use ita_stf::trusted_call_result::TrustedCallResult;

#[derive(Parser)]
pub struct TransferCommand {
Expand Down Expand Up @@ -62,7 +63,7 @@ impl TransferCommand {
TrustedCall::balance_transfer(from.public().into(), to, self.amount)
.sign(&KeyPair::Sr25519(Box::new(from)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_args.direct);
let res = perform_trusted_operation(cli, trusted_args, &top).map(|_| CliResultOk::None)?;
let res = perform_trusted_operation::<TrustedCallResult>(cli, trusted_args, &top).map(|_| CliResultOk::None)?;
info!("trusted call transfer executed");
Ok(res)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use litentry_primitives::ParentchainBalance as Balance;
use log::*;
use sp_core::{crypto::Ss58Codec, Pair};
use std::boxed::Box;
use ita_stf::trusted_call_result::TrustedCallResult;

#[derive(Parser)]
pub struct UnshieldFundsCommand {
Expand Down Expand Up @@ -62,6 +63,6 @@ impl UnshieldFundsCommand {
TrustedCall::balance_unshield(from.public().into(), to, self.amount, shard)
.sign(&KeyPair::Sr25519(Box::new(from)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_args.direct);
Ok(perform_trusted_operation(cli, trusted_args, &top).map(|_| CliResultOk::None)?)
Ok(perform_trusted_operation::<TrustedCallResult>(cli, trusted_args, &top).map(|_| CliResultOk::None)?)
}
}
4 changes: 2 additions & 2 deletions tee-worker/cli/src/trusted_command_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ macro_rules! get_layer_two_nonce {

let getter =
Getter::public(PublicGetter::nonce(Identity::Substrate($signer_pair.public().into())));
let getter_result = execute_getter_from_cli_args($cli, $trusted_args, &getter);
let getter_result = execute_getter_from_cli_args::<Option<Index>>($cli, $trusted_args, &getter);
let nonce = match getter_result {
Ok(Some(encoded_nonce)) => Index::decode(&mut encoded_nonce.as_slice()).unwrap(),
Ok(Some(nonce)) => nonce,
Ok(None) => Default::default(),
Err(_) => todo!(),
};
Expand Down
Loading