Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/p-884-integrate-with-passeo' int…
Browse files Browse the repository at this point in the history
…o p-884-integrate-with-passeo
  • Loading branch information
BillyWooo committed Sep 16, 2024
2 parents 22cfe31 + 1a66aae commit 2455724
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 59 deletions.
47 changes: 0 additions & 47 deletions docker/paseo-parachain-launch-config.yml

This file was deleted.

12 changes: 6 additions & 6 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 @@ -53,6 +53,7 @@ pub enum Command {
#[clap(subcommand)]
NftHolder(NftHolderCommand),
Dynamic(DynamicArg),
LinkedIdentities,
}

#[derive(Args, Debug)]
Expand Down Expand Up @@ -492,6 +493,7 @@ impl Command {
return_log: arg.return_log.unwrap_or_default(),
}))
},
Command::LinkedIdentities => Ok(LinkedIdentities),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default {
PlatformUser: "PlatformUserType",
NftHolder: "Web3NftType",
Dynamic: "DynamicParams",
LinkedIdentities: "Null",
},
},
AssertionSupportedNetwork: {
Expand Down
12 changes: 6 additions & 6 deletions tee-worker/enclave-runtime/Cargo.lock

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

1 change: 1 addition & 0 deletions tee-worker/litentry/core/assertion-build-v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use lc_assertion_build::{transpose_identity, Result};
use lc_service::DataProviderConfig;
use log::*;

pub mod linked_identities;
pub mod nft_holder;
pub mod platform_user;
pub mod token_holding_amount;
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright 2020-2024 Trust Computing GmbH.
// This file is part of Litentry.
//
// Litentry is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Litentry is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

#[cfg(all(feature = "std", feature = "sgx"))]
compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the same time");

#[cfg(all(not(feature = "std"), feature = "sgx"))]
extern crate sgx_tstd as std;

use lc_credentials_v2::{
linked_identities::LinkedIdentitiesAssertionUpdate, Credential, IssuerRuntimeVersion,
};
use lc_stf_task_sender::AssertionBuildRequest;

use crate::*;

pub fn build(req: &AssertionBuildRequest) -> Result<Credential> {
let identities = req
.identities
.iter()
.filter_map(|identity| identity.0.to_did().ok())
.collect::<Vec<_>>();

let runtime_version = IssuerRuntimeVersion {
parachain: req.parachain_runtime_version,
sidechain: req.sidechain_runtime_version,
};

match Credential::new(&req.who, &req.shard, &runtime_version) {
Ok(mut credential_unsigned) => {
credential_unsigned.update_linked_identities_assertion(identities);
Ok(credential_unsigned)
},
Err(e) => {
error!("Generate unsigned credential failed {:?}", e);
Err(Error::RequestVCFailed(Assertion::LinkedIdentities, e.into_error_detail()))
},
}
}

#[cfg(test)]
mod tests {
use super::*;
use itp_stf_primitives::types::ShardIdentifier;
use itp_types::AccountId;
use lc_credentials_v2::assertion_logic::{AssertionLogic, Op};
use litentry_primitives::{Identity, IdentityNetworkTuple, IdentityString};

#[test]
fn build_linked_identities_works() {
let mut identities: Vec<IdentityNetworkTuple> = vec![
(Identity::Substrate([0; 32].into()), vec![]),
(Identity::Evm([0; 20].into()), vec![]),
(Identity::Bitcoin([0; 33].into()), vec![]),
(Identity::Solana([0; 32].into()), vec![]),
(Identity::Discord(IdentityString::new("discord_handle".as_bytes().to_vec())), vec![]),
(Identity::Twitter(IdentityString::new("twitter_handle".as_bytes().to_vec())), vec![]),
(Identity::Github(IdentityString::new("github_handle".as_bytes().to_vec())), vec![]),
];

let req = AssertionBuildRequest {
shard: ShardIdentifier::default(),
signer: AccountId::from([0; 32]),
who: AccountId::from([0; 32]).into(),
assertion: Assertion::LinkedIdentities,
identities,
top_hash: Default::default(),
parachain_block_number: 0u32,
sidechain_block_number: 0u32,
parachain_runtime_version: 0u32,
sidechain_runtime_version: 0u32,
maybe_key: None,
should_create_id_graph: false,
req_ext_hash: Default::default(),
};

match build(&req) {
Ok(credential) => {
log::info!("build linked_identities done");
assert_eq!(
*(credential.credential_subject.assertions.first().unwrap()),
AssertionLogic::And {
items: vec![Box::new(AssertionLogic::Item {
src: "$identities".into(),
op: Op::Equal,
dst: "[\"did:litentry:substrate:0x0000000000000000000000000000000000000000000000000000000000000000\",\"did:litentry:evm:0x0000000000000000000000000000000000000000\",\"did:litentry:bitcoin:0x000000000000000000000000000000000000000000000000000000000000000000\",\"did:litentry:solana:11111111111111111111111111111111\",\"did:litentry:discord:discord_handle\",\"did:litentry:twitter:twitter_handle\",\"did:litentry:github:github_handle\"]".into()
})]
}
);
assert_eq!(*(credential.credential_subject.values.first().unwrap()), true);
},
Err(e) => {
panic!("build linked_identities failed with error {:?}", e);
},
}
}
}
1 change: 1 addition & 0 deletions tee-worker/litentry/core/credentials-v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the sam
// TODO migration to v2 in the future
pub use lc_credentials::{assertion_logic, Credential, IssuerRuntimeVersion};

pub mod linked_identities;
pub mod nft_holder;
pub mod platform_user;
pub mod token_holding_amount;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2020-2024 Trust Computing GmbH.
// This file is part of Litentry.
//
// Litentry is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Litentry is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

#[cfg(all(feature = "std", feature = "sgx"))]
compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the same time");

#[cfg(all(not(feature = "std"), feature = "sgx"))]
extern crate sgx_tstd as std;

use lc_credentials::{
assertion_logic::{AssertionLogic, Op},
Credential,
};
use std::{string::String, vec::Vec};

const TYPE: &str = "Linked web2/web3 identities";
const DESCRIPTION: &str = "All web2 and web3 identities you linked";

pub trait LinkedIdentitiesAssertionUpdate {
fn update_linked_identities_assertion(&mut self, identities: Vec<String>);
}

impl LinkedIdentitiesAssertionUpdate for Credential {
fn update_linked_identities_assertion(&mut self, identities: Vec<String>) {
self.add_subject_info(DESCRIPTION, TYPE);

let mut assertion = AssertionLogic::new_and();
let dst = format!("[\"{}\"]", identities.join("\",\""));
assertion =
assertion.add_item(AssertionLogic::new_item("$identities", Op::Equal, dst.as_str()));

self.credential_subject.assertions.push(assertion);
self.credential_subject.values.push(true);
}
}
2 changes: 2 additions & 0 deletions tee-worker/litentry/core/credentials/src/credential_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,7 @@ pub fn get_schema_url(assertion: &Assertion) -> Option<String> {
Some(format!("{BASE_URL}/25-token-holding-amount/1-1-4.json")),

Assertion::Dynamic(..) => None,

Assertion::LinkedIdentities => Some(format!("{BASE_URL}/27-linked-identities/1-0-0.json")),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ where
vc_logs = Some(result.1);
Ok(result.0)
},

Assertion::LinkedIdentities => lc_assertion_build_v2::linked_identities::build(req),
}?;

// post-process the credential
Expand Down
1 change: 1 addition & 0 deletions tee-worker/service/src/prometheus_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ fn assertion_to_string(assertion: Assertion) -> String {
Assertion::Dynamic(param) => {
format!("DynamicAssertion({:?})", param.smart_contract_id)
},
Assertion::LinkedIdentities => "LinkedIdentities".into(),
};
assertion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,12 @@ export const mockAssertions = [
WeirdoGhostGangHolder: [],
},
},

// LinkedIdentities
{
description: 'All web2 and web3 identities you linked',
assertion: {
LinkedIdentities: [],
},
},
];

0 comments on commit 2455724

Please sign in to comment.