Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding native request_vc and request_batch_vc trusted call handlers #3183

Open
wants to merge 46 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d5aaa3e
refactoring create_credential_str to make it more generic
silva-fj Nov 11, 2024
1e32fb1
adding AssertionRepository to NativeTaskContext
silva-fj Nov 11, 2024
9bacb2f
fixing imports
silva-fj Nov 11, 2024
527da05
injecting StateHandler to NativeTaskContext
silva-fj Nov 12, 2024
e726844
adding utilities from lc-stf-task-receiver
silva-fj Nov 12, 2024
d2f007f
adding new error variant
silva-fj Nov 12, 2024
11c57a7
adding request_vc_handler (WIP)
silva-fj Nov 12, 2024
f69cff7
handling request_vc trusted call (WIP)
silva-fj Nov 12, 2024
5c84e57
fixing build
silva-fj Nov 12, 2024
8bbbbb6
adding on_vc_issued call for usage with omni_account
silva-fj Nov 20, 2024
cc31789
adding new types
silva-fj Nov 20, 2024
8f49cc8
wrapping up request_vc_handler
silva-fj Nov 20, 2024
3ddee64
hanlding request_vc trusted call
silva-fj Nov 20, 2024
eabf4a3
updating type
silva-fj Nov 20, 2024
324262d
refactoring native task result type
silva-fj Nov 20, 2024
63ed61a
adding missing import
silva-fj Nov 21, 2024
1fbd9f4
updating ts types definitions
silva-fj Nov 21, 2024
872d8e0
fixing extrinsic call
silva-fj Nov 21, 2024
af38421
renaming helpers to make it more generic
silva-fj Nov 21, 2024
c4bac05
adding createAuthenticatedTrustedCallRequestVc helper
silva-fj Nov 21, 2024
3a514b8
addint native_request_vc tests (WIP)
silva-fj Nov 21, 2024
956f5cd
small improvement
silva-fj Nov 21, 2024
2a93c8d
wrapping up native request_vc trusted call tests
silva-fj Nov 21, 2024
9828b85
setting up ci tests
silva-fj Nov 21, 2024
f3fa6aa
updating generics
silva-fj Nov 22, 2024
7268b6e
refactoring generics of request_vc_handlers
silva-fj Nov 22, 2024
efe4d4d
adding missing trait bounds
silva-fj Nov 22, 2024
36edcfa
updating types and fixing generics
silva-fj Nov 22, 2024
729bc56
refactoring vc_request response and updating types
silva-fj Nov 22, 2024
c263152
updating ts type definitions
silva-fj Nov 22, 2024
dcf8326
fixing tests
silva-fj Nov 22, 2024
642f515
cleaning up types
silva-fj Nov 22, 2024
5e991dd
cleaning up definitions
silva-fj Nov 22, 2024
dbabf31
fixing clippy issues
silva-fj Nov 22, 2024
04a72cd
implementing native request_batch_vc handler
silva-fj Nov 22, 2024
8a13d7c
adding Context alias
silva-fj Nov 22, 2024
87cfae8
adding test for request_batch_vc
silva-fj Nov 22, 2024
02e4500
refactoring types
silva-fj Nov 22, 2024
4e5ea0d
updating ts type definitions
silva-fj Nov 22, 2024
2661e34
updating tests
silva-fj Nov 22, 2024
39adcb6
small refactoring
silva-fj Nov 22, 2024
177743e
fixing fmt issue
silva-fj Nov 22, 2024
f77ce7c
fixing clippy for development feature
silva-fj Nov 22, 2024
dd6b948
updating parachain-api CHANGELOG and version
silva-fj Nov 25, 2024
a516014
updating client-sdk to 1.0.0-next.6
silva-fj Nov 25, 2024
b22e28e
fixing client-sdk tests
silva-fj Nov 25, 2024
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
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::VCHasBeenIssued{ 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,
},
VCHasBeenIssued {
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::VCHasBeenIssued {
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::VCHasBeenIssued {
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
Loading