Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
1 change: 1 addition & 0 deletions tee-worker/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 {
#[codec(index = 0)]
Empty,
Expand Down
1 change: 1 addition & 0 deletions tee-worker/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ itp-stf-primitives = { path = "../core-primitives/stf-primitives" }
itp-time-utils = { path = "../core-primitives/time-utils" }
itp-types = { path = "../core-primitives/types" }
itp-utils = { path = "../core-primitives/utils" }
lc-credentials = { path = "../litentry/core/credentials" }

# litentry
frame-metadata = "15.0.0"
Expand Down
2 changes: 1 addition & 1 deletion tee-worker/cli/demo_shielding_unshielding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ echo "✔ ok"
echo ""

echo "* Send a 2 UNIT balance Transfer Bob -> Charlie (that will fail)"
$CLIENT trusted --direct --mrenclave ${MRENCLAVE} transfer ${ICGACCOUNTBOB} ${ICGACCOUNTCHARLIE} ${AMOUNT_TRANSFER}
$CLIENT trusted --direct --mrenclave ${MRENCLAVE} transfer ${ICGACCOUNTBOB} ${ICGACCOUNTCHARLIE} ${AMOUNT_TRANSFER} || true
echo ""

echo "* Assert Bob's incognito nonce..."
Expand Down
15 changes: 12 additions & 3 deletions tee-worker/cli/src/benchmark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ use crate::{
command_utils::get_worker_api_direct,
get_layer_two_nonce,
trusted_cli::TrustedCli,
trusted_command_utils::{
decode_balance, get_identifiers, get_keystore_path, get_pair_from_str,
},
trusted_command_utils::{get_identifiers, get_keystore_path, get_pair_from_str},
trusted_operation::{get_json_request, wait_until},
Cli, CliResult, CliResultOk, SR25519_KEY_TYPE,
};
Expand Down Expand Up @@ -368,3 +366,14 @@ fn is_submitted(s: TrustedOperationStatus) -> bool {
fn is_sidechain_block(s: TrustedOperationStatus) -> bool {
matches!(s, InSidechainBlock(_))
}

fn decode_balance(maybe_encoded_balance: Option<Vec<u8>>) -> Option<Balance> {
maybe_encoded_balance.and_then(|encoded_balance| {
if let Ok(vd) = Balance::decode(&mut encoded_balance.as_slice()) {
Some(vd)
} else {
warn!("Could not decode balance. maybe hasn't been set? {:x?}", encoded_balance);
None
}
})
}
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
3 changes: 1 addition & 2 deletions tee-worker/cli/src/evm/commands/evm_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::{
trusted_operation::perform_trusted_operation,
Cli, CliResult, CliResultOk,
};
use codec::Decode;
use ita_stf::{Index, TrustedCall, TrustedGetter, TrustedOperation};
use itp_stf_primitives::types::KeyPair;
use itp_types::AccountId;
Expand Down Expand Up @@ -80,7 +79,7 @@ impl EvmCallCommands {
)
.sign(&KeyPair::Sr25519(Box::new(sender)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_args.direct);
Ok(perform_trusted_operation(cli, trusted_args, &function_call)
Ok(perform_trusted_operation::<()>(cli, trusted_args, &function_call)
.map(|_| CliResultOk::None)?)
}
}
7 changes: 2 additions & 5 deletions tee-worker/cli/src/evm/commands/evm_command_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ macro_rules! get_layer_two_evm_nonce {
let top: TrustedOperation = TrustedGetter::evm_nonce($signer_pair.public().into())
.sign(&KeyPair::Sr25519(Box::new($signer_pair.clone())))
.into();
let res = perform_trusted_operation($cli, $trusted_args, &top).unwrap_or_default();
let nonce = match res {
Some(n) => Index::decode(&mut n.as_slice()).unwrap_or(0),
None => 0,
};
let nonce =
perform_trusted_operation::<Index>($cli, $trusted_args, &top).unwrap_or_default();
debug!("got evm nonce: {:?}", nonce);
nonce
}};
Expand Down
3 changes: 1 addition & 2 deletions tee-worker/cli/src/evm/commands/evm_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::{
trusted_operation::perform_trusted_operation,
Cli, CliResult, CliResultOk,
};
use codec::Decode;
use ita_stf::{
evm_helpers::evm_create_address, Index, TrustedCall, TrustedGetter, TrustedOperation,
};
Expand Down Expand Up @@ -80,7 +79,7 @@ impl EvmCreateCommands {
.sign(&from.into(), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_args.direct);

let _ = perform_trusted_operation(cli, trusted_args, &top)?;
perform_trusted_operation(cli, trusted_args, &top)?;

let execution_address = evm_create_address(sender_evm_acc, evm_account_nonce);
info!("trusted call evm_create executed");
Expand Down
20 changes: 3 additions & 17 deletions tee-worker/cli/src/evm/commands/evm_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

use crate::{
trusted_cli::TrustedCli, trusted_command_utils::get_pair_from_str,
trusted_operation::perform_trusted_operation, Cli, CliError, CliResult, CliResultOk,
trusted_operation::perform_trusted_operation, Cli, CliResult, CliResultOk,
};
use codec::Decode;
use ita_stf::{TrustedGetter, TrustedOperation};
use itp_stf_primitives::types::KeyPair;
use itp_types::AccountId;
Expand Down Expand Up @@ -56,20 +55,7 @@ impl EvmReadCommands {
TrustedGetter::evm_account_storages(sender_acc.into(), execution_address, H256::zero())
.sign(&KeyPair::Sr25519(Box::new(sender)))
.into();
let res = perform_trusted_operation(cli, trusted_args, &top)?;

debug!("received result for balance");
if let Some(v) = res {
if let Ok(vd) = H256::decode(&mut v.as_slice()) {
println!("{:?}", vd);
Ok(CliResultOk::H256 { hash: vd })
} else {
error!("could not decode value. {:x?}", v);
Err(CliError::EvmRead { msg: format!("could not decode value. {:x?}", v) })
}
} else {
error!("Nothing in state!");
Err(CliError::EvmRead { msg: "Nothing in state!".to_string() })
}
let hash = perform_trusted_operation::<H256>(cli, trusted_args, &top)?;
Ok(CliResultOk::H256 { hash })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::{
trusted_cli::TrustedCli, trusted_command_utils::get_pair_from_str,
trusted_operation::perform_trusted_operation, Cli, CliResult, CliResultOk,
};
use codec::Decode;
use ita_stf::{IDGraph, Runtime, TrustedGetter, TrustedOperation};
use itp_stf_primitives::types::KeyPair;
use litentry_primitives::Identity;
Expand All @@ -45,9 +44,8 @@ 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());
println!("{:?}", idgraph.unwrap().unwrap());
let idgraph = perform_trusted_operation::<IDGraph<Runtime>>(cli, trusted_cli, &top);
println!("{:?}", idgraph.unwrap());

Ok(CliResultOk::None)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::{
trusted_cli::TrustedCli, trusted_command_utils::get_pair_from_str,
trusted_operation::perform_trusted_operation, Cli, CliError, CliResult, CliResultOk,
};
use codec::Decode;
use ita_stf::{TrustedGetter, TrustedOperation};
use itp_stf_primitives::types::KeyPair;
use litentry_primitives::ParentchainAccountId;
Expand All @@ -38,25 +37,17 @@ 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::<IDGraphStatsVec>(cli, trusted_cli, &top);
println!("IDGraph stats:");
match id_graph_stats {
Ok(id_graph_stats) => {
let total_number = id_graph_stats
.map(|stats| {
let mut total_number = 0_u32;

stats.iter().for_each(|item| {
total_number += item.1;
let mut total_number = 0_u32;

println!("{:?} -> {}", item.0, item.1);
});
id_graph_stats.iter().for_each(|item| {
total_number += item.1;

total_number
})
.unwrap();
println!("{:?} -> {}", item.0, item.1);
});

println!("Total number: {}", total_number);
Ok(CliResultOk::None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ use crate::{
Cli, CliResult, CliResultOk,
};
use clap::Parser;
use codec::Decode;
use ita_stf::{Index, TrustedCall, TrustedOperation};
use itp_stf_primitives::types::KeyPair;
use litentry_primitives::{Identity, Web3Network};
use log::*;
use sp_core::Pair;

// usage exmaple:
Expand Down Expand Up @@ -79,6 +77,6 @@ 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)?)
Ok(perform_trusted_operation::<()>(cli, trusted_cli, &top).map(|_| CliResultOk::None)?)
}
}
48 changes: 34 additions & 14 deletions tee-worker/cli/src/trusted_base_cli/commands/litentry/request_vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ use crate::{
trusted_operation::perform_trusted_operation,
Cli, CliResult, CliResultOk,
};
use codec::Decode;
use ita_stf::{Index, TrustedCall, TrustedOperation};
use ita_stf::{trusted_call_result::RequestVCResult, Index, TrustedCall, TrustedOperation};
use itp_stf_primitives::types::KeyPair;
use itp_utils::hex::decode_hex;
use lc_credentials::Credential;
use litentry_primitives::{
AchainableAmount, AchainableAmountHolding, AchainableAmountToken, AchainableAmounts,
AchainableBasic, AchainableBetweenPercents, AchainableClassOfYear, AchainableDate,
AchainableDateInterval, AchainableDatePercent, AchainableParams, AchainableToken, Assertion,
GenericDiscordRoleType, Identity, OneBlockCourseType, ParameterString, SoraQuizType,
Web3Network,
aes_decrypt, AchainableAmount, AchainableAmountHolding, AchainableAmountToken,
AchainableAmounts, AchainableBasic, AchainableBetweenPercents, AchainableClassOfYear,
AchainableDate, AchainableDateInterval, AchainableDatePercent, AchainableParams,
AchainableToken, Assertion, GenericDiscordRoleType, Identity, OneBlockCourseType,
ParameterString, RequestAesKey, SoraQuizType, Web3Network, REQUEST_AES_KEY_LEN,
};
use log::*;
use sp_core::Pair;

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

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

// TODO: P-177, print actual VC content to stdout
let _vc = perform_trusted_operation(cli, trusted_cli, &top).unwrap();
let top: TrustedOperation = TrustedCall::request_vc(
alice.public().into(),
id,
assertion,
Some(key),
Default::default(),
)
.sign(&KeyPair::Sr25519(Box::new(alice)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_cli.direct);

match perform_trusted_operation::<RequestVCResult>(cli, trusted_cli, &top) {
Ok(mut vc) => {
let decrypted = aes_decrypt(&key, &mut vc.vc_payload).unwrap();
let credential: Credential = serde_json::from_slice(&decrypted).unwrap();
println!("----Generated VC-----");
println!("{:?}", credential);
},
Err(e) => {
println!("{:?}", e);
},
}
Ok(CliResultOk::None)
}

fn random_aes_key() -> RequestAesKey {
let random: Vec<u8> = (0..REQUEST_AES_KEY_LEN).map(|_| rand::random::<u8>()).collect();
random[0..REQUEST_AES_KEY_LEN].try_into().unwrap()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ use crate::{
trusted_operation::perform_direct_operation,
Cli, CliResult, CliResultOk,
};
use codec::Decode;
use ita_stf::{Index, TrustedCall, TrustedOperation};
use ita_stf::{trusted_call_result::RequestVCResult, Index, TrustedCall, TrustedOperation};
use itp_stf_primitives::types::KeyPair;
use itp_utils::hex::decode_hex;
use lc_credentials::Credential;
use litentry_primitives::{
AchainableAmount, AchainableAmountHolding, AchainableAmountToken, AchainableAmounts,
AchainableBasic, AchainableBetweenPercents, AchainableClassOfYear, AchainableDate,
AchainableDateInterval, AchainableDatePercent, AchainableParams, AchainableToken, Assertion,
GenericDiscordRoleType, Identity, OneBlockCourseType, RequestAesKey, SoraQuizType, Web3Network,
aes_decrypt, AchainableAmount, AchainableAmountHolding, AchainableAmountToken,
AchainableAmounts, AchainableBasic, AchainableBetweenPercents, AchainableClassOfYear,
AchainableDate, AchainableDateInterval, AchainableDatePercent, AchainableParams,
AchainableToken, Assertion, GenericDiscordRoleType, Identity, OneBlockCourseType,
RequestAesKey, SoraQuizType, Web3Network,
};
use log::*;
use sp_core::Pair;

// usage example (you can always use --help on subcommands to see more details)
Expand Down Expand Up @@ -253,7 +253,17 @@ impl RequestVcDirectCommand {
.into_trusted_operation(trusted_cli.direct);

// This should contain the AES Key for AESRequest
let _vc = perform_direct_operation(cli, trusted_cli, &top, key).unwrap();
match perform_direct_operation::<RequestVCResult>(cli, trusted_cli, &top, key) {
Ok(mut vc) => {
let decrypted = aes_decrypt(&key, &mut vc.vc_payload).unwrap();
let credential: Credential = serde_json::from_slice(&decrypted).unwrap();
println!("----Generated VC-----");
println!("{:?}", credential);
},
Err(e) => {
println!("{:?}", e);
},
}
Ok(CliResultOk::None)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ use crate::{
trusted_operation::perform_trusted_operation,
Cli, CliResult, CliResultOk,
};
use codec::Decode;
use ita_stf::{Index, TrustedCall, TrustedOperation};
use itp_stf_primitives::types::KeyPair;
use log::*;
use sp_core::Pair;

#[derive(Parser)]
Expand All @@ -41,6 +39,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::<()>(cli, trusted_cli, &top).map(|_| CliResultOk::None)?)
}
}
3 changes: 1 addition & 2 deletions tee-worker/cli/src/trusted_base_cli/commands/set_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::{
trusted_operation::perform_trusted_operation,
Cli, CliResult, CliResultOk,
};
use codec::Decode;
use ita_stf::{Index, TrustedCall, TrustedOperation};
use itp_stf_primitives::types::KeyPair;
use litentry_primitives::ParentchainBalance as Balance;
Expand Down Expand Up @@ -57,6 +56,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::<()>(cli, trusted_args, &top).map(|_| CliResultOk::None)?)
}
}
Loading