Skip to content

Commit cc55ce7

Browse files
Kailai-Wang0xverinzzz
authored
Return encrypted IDGraph when changed (#1080)
* add id_graph to ocall extrinsics * adjust callback extrinsic * add cross-env&&dotenv * set env * random shard for testing * Change the versions of @PolkaDot * change the version of @polkadot/types * rm yarn.lock * slight renaming * change maxVerificationDelay to 30min * change yarn.lock * generateChallengeCode * modify yarn run command * change defaultSinger * add getSinger * add Sign functions * add getSinger && generateChallengeCode * add ID_HUB_URL for sign message * modify defaultSigner * modify shard * add ethers provider&&wallet * add eth endpoint * add @ethersproject/providers&&ethers * substrate&&ethereum tests * web3 types * nonce * change methods name * change methods name * change events * change methods name * change event * modify method name * ts-test support `id_graph` * fix bug * remove log * resolve conflicts Co-authored-by: Verin1005 <daqingchong0809@gmail.com> Co-authored-by: zzz <zhiming.zhong@litentry.com>
1 parent b734572 commit cc55ce7

16 files changed

Lines changed: 173 additions & 70 deletions

File tree

pallets/identity-management-mock/src/identity_context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.
1616

1717
use codec::{Decode, Encode, MaxEncodedLen};
18+
use frame_support::RuntimeDebugNoBound;
1819
use scale_info::TypeInfo;
1920

2021
use crate::{BlockNumberOf, Config, Metadata};
2122

2223
// The context associated with the (litentry-account, did) pair
2324
// TODO: maybe we have better naming
24-
#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
25+
#[derive(Clone, Eq, PartialEq, RuntimeDebugNoBound, Encode, Decode, TypeInfo, MaxEncodedLen)]
2526
#[scale_info(skip_type_params(T))]
2627
#[codec(mel_bound())]
2728
pub struct IdentityContext<T: Config> {

pallets/identity-management-mock/src/lib.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,28 +129,34 @@ pub mod pallet {
129129
IdentityCreatedPlain {
130130
account: T::AccountId,
131131
identity: Identity,
132+
id_graph: Vec<(Identity, IdentityContext<T>)>,
132133
},
133134
IdentityCreated {
134135
account: AesOutput,
135136
identity: AesOutput,
137+
id_graph: AesOutput,
136138
},
137139
// remove identity
138140
IdentityRemovedPlain {
139141
account: T::AccountId,
140142
identity: Identity,
143+
id_graph: Vec<(Identity, IdentityContext<T>)>,
141144
},
142145
IdentityRemoved {
143146
account: AesOutput,
144147
identity: AesOutput,
148+
id_graph: AesOutput,
145149
},
146150
// verify identity
147151
IdentityVerifiedPlain {
148152
account: T::AccountId,
149153
identity: Identity,
154+
id_graph: Vec<(Identity, IdentityContext<T>)>,
150155
},
151156
IdentityVerified {
152157
account: AesOutput,
153158
identity: AesOutput,
159+
id_graph: AesOutput,
154160
},
155161
// some error happened during processing in TEE, we use string-like
156162
// parameters for more "generic" error event reporting
@@ -344,10 +350,12 @@ pub mod pallet {
344350
Self::deposit_event(Event::<T>::IdentityCreatedPlain {
345351
account: who.clone(),
346352
identity: identity.clone(),
353+
id_graph: Self::get_id_graph(&who),
347354
});
348355
Self::deposit_event(Event::<T>::IdentityCreated {
349356
account: aes_encrypt_default(&key, who.encode().as_slice()),
350357
identity: aes_encrypt_default(&key, identity.encode().as_slice()),
358+
id_graph: aes_encrypt_default(&key, Self::get_id_graph(&who).encode().as_slice()),
351359
});
352360
Ok(())
353361
}
@@ -375,10 +383,12 @@ pub mod pallet {
375383
Self::deposit_event(Event::<T>::IdentityRemovedPlain {
376384
account: who.clone(),
377385
identity: identity.clone(),
386+
id_graph: Self::get_id_graph(&who),
378387
});
379388
Self::deposit_event(Event::<T>::IdentityRemoved {
380389
account: aes_encrypt_default(&key, who.encode().as_slice()),
381390
identity: aes_encrypt_default(&key, identity.encode().as_slice()),
391+
id_graph: aes_encrypt_default(&key, Self::get_id_graph(&who).encode().as_slice()),
382392
});
383393

384394
Ok(())
@@ -450,10 +460,15 @@ pub mod pallet {
450460
Self::deposit_event(Event::<T>::IdentityVerifiedPlain {
451461
account: who.clone(),
452462
identity: identity.clone(),
463+
id_graph: Self::get_id_graph(&who),
453464
});
454465
Self::deposit_event(Event::<T>::IdentityVerified {
455466
account: aes_encrypt_default(&key, who.encode().as_slice()),
456467
identity: aes_encrypt_default(&key, identity.encode().as_slice()),
468+
id_graph: aes_encrypt_default(
469+
&key,
470+
Self::get_id_graph(&who).encode().as_slice(),
471+
),
457472
});
458473
Ok(())
459474
})
@@ -487,9 +502,10 @@ pub mod pallet {
487502
origin: OriginFor<T>,
488503
account: AesOutput,
489504
identity: AesOutput,
505+
id_graph: AesOutput,
490506
) -> DispatchResultWithPostInfo {
491507
let _ = T::TEECallOrigin::ensure_origin(origin)?;
492-
Self::deposit_event(Event::IdentityCreated { account, identity });
508+
Self::deposit_event(Event::IdentityCreated { account, identity, id_graph });
493509
Ok(Pays::No.into())
494510
}
495511

@@ -498,9 +514,10 @@ pub mod pallet {
498514
origin: OriginFor<T>,
499515
account: AesOutput,
500516
identity: AesOutput,
517+
id_graph: AesOutput,
501518
) -> DispatchResultWithPostInfo {
502519
let _ = T::TEECallOrigin::ensure_origin(origin)?;
503-
Self::deposit_event(Event::IdentityRemoved { account, identity });
520+
Self::deposit_event(Event::IdentityRemoved { account, identity, id_graph });
504521
Ok(Pays::No.into())
505522
}
506523

@@ -509,9 +526,10 @@ pub mod pallet {
509526
origin: OriginFor<T>,
510527
account: AesOutput,
511528
identity: AesOutput,
529+
id_graph: AesOutput,
512530
) -> DispatchResultWithPostInfo {
513531
let _ = T::TEECallOrigin::ensure_origin(origin)?;
514-
Self::deposit_event(Event::IdentityVerified { account, identity });
532+
Self::deposit_event(Event::IdentityVerified { account, identity, id_graph });
515533
Ok(Pays::No.into())
516534
}
517535

@@ -663,5 +681,9 @@ pub mod pallet {
663681
addr[..20].copy_from_slice(&hashed_pk[12..32]);
664682
Ok(addr)
665683
}
684+
685+
pub fn get_id_graph(who: &T::AccountId) -> Vec<(Identity, IdentityContext<T>)> {
686+
IDGraphs::iter_prefix(who).collect::<Vec<_>>()
687+
}
666688
}
667689
}

pallets/identity-management-mock/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ pub fn setup_create_identity(
252252
System::assert_has_event(Event::IdentityManagementMock(crate::Event::IdentityCreatedPlain {
253253
account: who,
254254
identity: identity.clone(),
255+
id_graph: IdentityManagementMock::get_id_graph(&who),
255256
}));
256257
// encrypt the result
257258
let aes_encrypted_account = aes_encrypt_default(&key, who.encode().as_slice());

pallets/identity-management/src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ pub mod pallet {
8282
// event that should be triggered by TEECallOrigin
8383
UserShieldingKeySet { account: AesOutput },
8484
ChallengeCodeGenerated { account: AesOutput, identity: AesOutput, code: AesOutput },
85-
IdentityCreated { account: AesOutput, identity: AesOutput },
86-
IdentityRemoved { account: AesOutput, identity: AesOutput },
87-
IdentityVerified { account: AesOutput, identity: AesOutput },
85+
IdentityCreated { account: AesOutput, identity: AesOutput, id_graph: AesOutput },
86+
IdentityRemoved { account: AesOutput, identity: AesOutput, id_graph: AesOutput },
87+
IdentityVerified { account: AesOutput, identity: AesOutput, id_graph: AesOutput },
8888
// some error happened during processing in TEE, we use string-like
8989
// parameters for more "generic" error event reporting
9090
// TODO: maybe use concrete errors instead of events when we are more sure
@@ -177,9 +177,10 @@ pub mod pallet {
177177
origin: OriginFor<T>,
178178
account: AesOutput,
179179
identity: AesOutput,
180+
id_graph: AesOutput,
180181
) -> DispatchResultWithPostInfo {
181182
let _ = T::TEECallOrigin::ensure_origin(origin)?;
182-
Self::deposit_event(Event::IdentityCreated { account, identity });
183+
Self::deposit_event(Event::IdentityCreated { account, identity, id_graph });
183184
Ok(Pays::No.into())
184185
}
185186

@@ -188,9 +189,10 @@ pub mod pallet {
188189
origin: OriginFor<T>,
189190
account: AesOutput,
190191
identity: AesOutput,
192+
id_graph: AesOutput,
191193
) -> DispatchResultWithPostInfo {
192194
let _ = T::TEECallOrigin::ensure_origin(origin)?;
193-
Self::deposit_event(Event::IdentityRemoved { account, identity });
195+
Self::deposit_event(Event::IdentityRemoved { account, identity, id_graph });
194196
Ok(Pays::No.into())
195197
}
196198

@@ -199,9 +201,10 @@ pub mod pallet {
199201
origin: OriginFor<T>,
200202
account: AesOutput,
201203
identity: AesOutput,
204+
id_graph: AesOutput,
202205
) -> DispatchResultWithPostInfo {
203206
let _ = T::TEECallOrigin::ensure_origin(origin)?;
204-
Self::deposit_event(Event::IdentityVerified { account, identity });
207+
Self::deposit_event(Event::IdentityVerified { account, identity, id_graph });
205208
Ok(Pays::No.into())
206209
}
207210

runtime/litmus/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ ord_parameter_types! {
797797
impl pallet_identity_management_mock::Config for Runtime {
798798
type Event = Event;
799799
type ManageWhitelistOrigin = EnsureRootOrAllCouncil;
800-
type MaxVerificationDelay = ConstU32<10>;
800+
type MaxVerificationDelay = ConstU32<{ 30 * MINUTES }>;
801801
// intentionally use ALICE for the IMP mock
802802
type TEECallOrigin = EnsureSignedBy<ALICE, AccountId>;
803803
}

runtime/rococo/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,8 @@ ord_parameter_types! {
871871

872872
impl pallet_identity_management_mock::Config for Runtime {
873873
type Event = Event;
874-
type ManageWhitelistOrigin = EnsureRoot<Self::AccountId>;
875-
type MaxVerificationDelay = ConstU32<10>;
874+
type ManageWhitelistOrigin = EnsureRootOrAllCouncil;
875+
type MaxVerificationDelay = ConstU32<{ 30 * MINUTES }>;
876876
// intentionally use ALICE for the IMP mock
877877
type TEECallOrigin = EnsureSignedBy<ALICE, AccountId>;
878878
}

tee-worker/app-libs/sgx-runtime/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub use sp_runtime::BuildStorage;
7777
pub use sp_runtime::{Perbill, Permill};
7878

7979
// litentry
80+
use litentry_primitives::MINUTES;
8081
pub use pallet_imt::{self, Call as IdentityManagementCall};
8182

8283
/// Block type as expected by this sgx-runtime.
@@ -264,7 +265,7 @@ impl pallet_imt::Config for Runtime {
264265
type Event = Event;
265266
type ManageOrigin = EnsureRoot<AccountId>;
266267
type MaxMetadataLength = ConstU32<128>;
267-
type MaxVerificationDelay = ConstU32<20>;
268+
type MaxVerificationDelay = ConstU32<{ 30 * MINUTES }>;
268269
}
269270

270271
// The plain sgx-runtime without the `evm-pallet`

tee-worker/app-libs/stf/src/trusted_call.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,14 @@ where
440440
Ok(code) => {
441441
debug!("create_identity {} OK", account_id_to_string(&who));
442442
if let Some(key) = IdentityManagement::user_shielding_keys(&who) {
443+
let id_graph =
444+
ita_sgx_runtime::pallet_imt::Pallet::<Runtime>::get_id_graph(&who);
443445
calls.push(OpaqueCall::from_tuple(&(
444446
node_metadata_repo
445447
.get_from_metadata(|m| m.identity_created_call_indexes())??,
446448
aes_encrypt_default(&key, &who.encode()),
447449
aes_encrypt_default(&key, &identity.encode()),
450+
aes_encrypt_default(&key, &id_graph.encode()),
448451
)));
449452
calls.push(OpaqueCall::from_tuple(&(
450453
node_metadata_repo.get_from_metadata(|m| {
@@ -486,11 +489,14 @@ where
486489
Ok(()) => {
487490
debug!("remove_identity {} OK", account_id_to_string(&who));
488491
if let Some(key) = IdentityManagement::user_shielding_keys(&who) {
492+
let id_graph =
493+
ita_sgx_runtime::pallet_imt::Pallet::<Runtime>::get_id_graph(&who);
489494
calls.push(OpaqueCall::from_tuple(&(
490495
node_metadata_repo
491496
.get_from_metadata(|m| m.identity_removed_call_indexes())??,
492497
aes_encrypt_default(&key, &who.encode()),
493498
aes_encrypt_default(&key, &identity.encode()),
499+
aes_encrypt_default(&key, &id_graph.encode()),
494500
)));
495501
} else {
496502
calls.push(OpaqueCall::from_tuple(&(
@@ -535,11 +541,14 @@ where
535541
Ok(()) => {
536542
debug!("verify_identity {} OK", account_id_to_string(&who));
537543
if let Some(key) = IdentityManagement::user_shielding_keys(&who) {
544+
let id_graph =
545+
ita_sgx_runtime::pallet_imt::Pallet::<Runtime>::get_id_graph(&who);
538546
calls.push(OpaqueCall::from_tuple(&(
539547
node_metadata_repo
540548
.get_from_metadata(|m| m.identity_verified_call_indexes())??,
541549
aes_encrypt_default(&key, &who.encode()),
542550
aes_encrypt_default(&key, &identity.encode()),
551+
aes_encrypt_default(&key, &id_graph.encode()),
543552
)));
544553
} else {
545554
calls.push(OpaqueCall::from_tuple(&(

tee-worker/app-libs/stf/src/trusted_call_litentry.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,13 @@ impl TrustedCallSigned {
186186
who: AccountId,
187187
assertion: Assertion,
188188
) -> StfResult<()> {
189-
let v_identity_context =
190-
ita_sgx_runtime::pallet_imt::Pallet::<Runtime>::get_identity_and_identity_context(&who);
189+
let id_graph = ita_sgx_runtime::pallet_imt::Pallet::<Runtime>::get_id_graph(&who);
191190

192191
let mut vec_identity: BoundedVec<Identity, MaxIdentityLength> = vec![].try_into().unwrap();
193192

194-
for identity_ctx in &v_identity_context {
195-
if identity_ctx.1.is_verified {
196-
vec_identity
197-
.try_push(identity_ctx.0.clone())
198-
.map_err(|_| StfError::AssertionBuildFail)?;
193+
for id in &id_graph {
194+
if id.1.is_verified {
195+
vec_identity.try_push(id.0.clone()).map_err(|_| StfError::AssertionBuildFail)?;
199196
}
200197
}
201198

tee-worker/litentry/pallets/identity-management/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,7 @@ pub mod pallet {
247247
}
248248

249249
impl<T: Config> Pallet<T> {
250-
pub fn get_identity_and_identity_context(
251-
who: &T::AccountId,
252-
) -> Vec<(Identity, IdentityContext<T>)> {
250+
pub fn get_id_graph(who: &T::AccountId) -> Vec<(Identity, IdentityContext<T>)> {
253251
IDGraphs::iter_prefix(who).collect::<Vec<_>>()
254252
}
255253
}

0 commit comments

Comments
 (0)