Skip to content

Commit

Permalink
Adding native request_vc and request_batch_vc trusted call handle…
Browse files Browse the repository at this point in the history
…rs (#3183)
  • Loading branch information
silva-fj authored Dec 6, 2024
1 parent 4558ce1 commit d9c5c63
Show file tree
Hide file tree
Showing 36 changed files with 2,731 additions and 1,585 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ jobs:
- test_name: lit-parentchain-nonce
- test_name: lit-test-failed-parentchain-extrinsic
- test_name: lit-omni-account-test
- test_name: lit-native-request-vc-test
name: ${{ matrix.test_name }}
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -880,6 +881,7 @@ jobs:
- test_name: lit-dr-vc-multiworker-test
- test_name: lit-resume-worker
- test_name: lit-omni-account-multiworker-test
- test_name: lit-native-request-vc-multiworker-test
name: ${{ matrix.test_name }}
steps:
- uses: actions/checkout@v4
Expand Down
12 changes: 12 additions & 0 deletions parachain/pallets/vc-management/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ benchmarks! {
assert_last_event::<T>(Event::SchemaRevoked { account, shard, index: 0 }.into())
}

// Benchmark `on_vc_issued`. There are no worst conditions. The benchmark showed that
// execution time is constant irrespective of encrypted_data size.
on_vc_issued {
let call_origin = T::TEECallOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let identity: Identity = frame_benchmarking::account::<AccountId>("TEST_A", 0u32, USER_SEED).into();
let assertion = Assertion::A1;
let omni_account: T::AccountId = frame_benchmarking::account("TEST_OMNI_ACCOUNT", 0u32, USER_SEED);
let req_ext_hash = H256::default();
}: _<T::RuntimeOrigin>(call_origin, identity.clone(), assertion.clone(), omni_account.clone(), req_ext_hash)
verify{
assert_last_event::<T>(Event::VCIssuedNew{ identity, assertion, omni_account, req_ext_hash }.into());
}
}

#[cfg(test)]
Expand Down
26 changes: 26 additions & 0 deletions parachain/pallets/vc-management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ pub mod pallet {
detail: ErrorDetail,
req_ext_hash: H256,
},
VCIssuedNew {
identity: Identity,
assertion: Assertion,
omni_account: T::AccountId,
req_ext_hash: H256,
},
}

#[pallet::error]
Expand Down Expand Up @@ -386,5 +392,25 @@ pub mod pallet {
}
Ok(Pays::No.into())
}

// TODO: update the weight info to use on_vc_issued
#[pallet::call_index(32)]
#[pallet::weight(<T as Config>::WeightInfo::vc_issued())]
pub fn on_vc_issued(
origin: OriginFor<T>,
identity: Identity,
assertion: Assertion,
omni_account: T::AccountId,
req_ext_hash: H256,
) -> DispatchResultWithPostInfo {
let _ = T::TEECallOrigin::ensure_origin(origin)?;
Self::deposit_event(Event::VCIssuedNew {
identity,
assertion,
omni_account,
req_ext_hash,
});
Ok(Pays::No.into())
}
}
}
22 changes: 22 additions & 0 deletions parachain/pallets/vc-management/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,25 @@ fn revoke_schema_with_unprivileged_origin_fails() {
);
});
}

#[test]
fn on_vc_issued_works() {
new_test_ext().execute_with(|| {
let signer: SystemAccountId = get_signer(TEST8_SIGNER_PUB);
let alice: Identity = get_signer(ALICE_PUBKEY);
let omni_account = alice.to_omni_account();
assert_ok!(VCManagement::on_vc_issued(
RuntimeOrigin::signed(signer),
alice.clone(),
Assertion::A1,
omni_account.clone(),
H256::default(),
));
System::assert_last_event(RuntimeEvent::VCManagement(crate::Event::VCIssuedNew {
identity: alice,
assertion: Assertion::A1,
omni_account,
req_ext_hash: H256::default(),
}));
});
}
3 changes: 3 additions & 0 deletions tee-worker/Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<Hash: Decode> From<substrate_api_client::ExtrinsicReport<Hash>> for Extrins
}

/// Possible transaction status events.
#[derive(Encode, Decode, Debug, Clone, PartialEq, MaxEncodedLen)]
#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, MaxEncodedLen)]
pub enum TransactionStatus<Hash, BlockHash> {
/// Transaction is part of the future queue.
Future,
Expand Down
5 changes: 4 additions & 1 deletion tee-worker/identity/app-libs/stf/src/trusted_call_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct RequestVCResult {
pub pre_id_graph_hash: H256,
}

#[derive(Debug, Encode, Decode, Clone)]
#[derive(Debug, Encode, Decode, Clone, PartialEq, Eq)]
pub enum RequestVcErrorDetail {
UnexpectedCall(String),
DuplicateAssertionRequest,
Expand All @@ -128,6 +128,9 @@ pub enum RequestVcErrorDetail {
CallSendingFailed(String),
ExtrinsicConstructionFailed(String), // Stringified itp_extrinsics_factory::Error
ExtrinsicSendingFailed(String), // Stringified sgx_status_t
ExtractingMemberIdentityFailed,
OmniAccountStoreRetrievalFailed,
CreateAccountStoreFailed(String),
}

#[derive(Debug, Encode, Decode, Clone)]
Expand Down
2 changes: 2 additions & 0 deletions tee-worker/identity/client-api/parachain-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `TrustedCallAuthenticated` and `TCAuthentication` trusted call structs.
- Add `TrustedCallResult` to handle OmniAccount's call results.
- Add `TrustedOperationAuthenticated` type definition.
- Update `TrustedCallResult` type definition.
- Add error variants to `RequestVcErrorDetail`.

## [0.9.20-4.1] - 2024-09-30

Expand Down
2 changes: 1 addition & 1 deletion tee-worker/identity/client-api/parachain-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/src/index.js",
"module": "dist/src/index.js",
"sideEffects": false,
"version": "0.9.20-next.8",
"version": "0.9.20-next.9",
"scripts": {
"clean": "rm -rf dist build node_modules",
"update-metadata": "curl -s -H \"Content-Type: application/json\" -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9944 > prepare-build/litentry-parachain-metadata.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ export default {
* Native tasks (OmniAccount) results
* @see tee-worker/identity/litentry/core/native-task/receiver/src/lib.rs
*/
TrustedCallResult: "Result<ExtrinsicReport, NativeTaskError>",
TrustedCallResult: "Result<TrustedCallOk, TrustedCallError>",
TrustedCallOk: {
_enum: {
ExtrinsicReport: "ExtrinsicReport",
RequestVcResult: "RequestVcResultOrError",
},
},
ExtrinsicReport: {
// Hash of the extrinsic.
extrinsic_hash: "H256",
Expand Down Expand Up @@ -148,7 +154,7 @@ export default {
Invalid: "Null",
},
},
NativeTaskError: {
TrustedCallError: {
_enum: {
UnexpectedCall: "Text",
ShieldingKeyRetrievalFailed: "Text", // Stringified itp_sgx_crypto::Error
Expand All @@ -170,7 +176,6 @@ export default {
ExtrinsicConstructionFailed: "Text", // Stringified itp_extrinsics_factory::Error
ExtrinsicSendingFailed: "Text", // Stringified sgx_status_t
InvalidRequest: "Null",
NativeRequestSendFailed: "Null",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ export default {
pre_mutated_id_graph: "AesOutput",
pre_id_graph_hash: "H256",
},
RequestVcOk: {
vc_payload: "AesOutput",
vc_logs: "Option<AesOutput>",
pre_mutated_account_store: "AesOutput",
omni_account: "AccountId",
},
VCMPError: {
_enum: {
RequestVCFailed: "(Assertion, ErrorDetail)",
Expand Down Expand Up @@ -90,6 +96,9 @@ export default {
CallSendingFailed: "String",
ExtrinsicConstructionFailed: "String", // Stringified itp_extrinsics_factory::Error
ExtrinsicSendingFailed: "String", // Stringified sgx_status_t
ExtractingMemberIdentityFailed: "Null",
OmniAccountStoreRetrievalFailed: "Null",
CreateAccountStoreFailed: "String",
},
},
RequestVcResultOrError: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@litentry/client-sdk",
"description": "This package provides helpers for dApps to interact with the Litentry Protocol.",
"version": "1.0.0-next.5",
"version": "1.0.0-next.6",
"license": "GPL-3.0-or-later",
"dependencies": {},
"devDependencies": {
"@polkadot/rpc-provider": "^10.9.1"
},
"peerDependencies": {
"@litentry/parachain-api": "0.9.20-next.8",
"@litentry/parachain-api": "0.9.20-next.9",
"@litentry/sidechain-api": "0.9.20-next.8",
"@litentry/chaindata": "*",
"@polkadot/api": "^10.9.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ export async function callEthereum(
throw new Error(codecToString(result.asErr));
}

const { extrinsic_hash, block_hash } = result.asOk;
if (!result.asOk.isExtrinsicReport) {
throw new Error('Unexpected response type');
}

const { extrinsic_hash, block_hash } = result.asOk.asExtrinsicReport;

return {
response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ export async function createAccountStore(
throw new Error(codecToString(result.asErr));
}

const { extrinsic_hash, block_hash } = result.asOk;
if (!result.asOk.isExtrinsicReport) {
throw new Error('Unexpected response type');
}

const { extrinsic_hash, block_hash } = result.asOk.asExtrinsicReport;

return {
response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ export async function remark(
throw new Error(codecToString(result.asErr));
}

const { extrinsic_hash, block_hash } = result.asOk;
if (!result.asOk.isExtrinsicReport) {
throw new Error('Unexpected response type');
}

const { extrinsic_hash, block_hash } = result.asOk.asExtrinsicReport;

return {
response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ export async function transferEthereum(
throw new Error(codecToString(result.asErr));
}

const { extrinsic_hash, block_hash } = result.asOk;
if (!result.asOk.isExtrinsicReport) {
throw new Error('Unexpected response type');
}

const { extrinsic_hash, block_hash } = result.asOk.asExtrinsicReport;

return {
response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ export async function transferNative(
throw new Error(codecToString(result.asErr));
}

const { extrinsic_hash, block_hash } = result.asOk;
if (!result.asOk.isExtrinsicReport) {
throw new Error('Unexpected response type');
}

const { extrinsic_hash, block_hash } = result.asOk.asExtrinsicReport;

return {
response,
Expand Down
Loading

0 comments on commit d9c5c63

Please sign in to comment.