Skip to content

Commit

Permalink
Use cargo patch and decouple more deps (#3124)
Browse files Browse the repository at this point in the history
* use patch

* fix compile

* fix lockfile

* tabs

* add dcap related primitives

* fix ci
  • Loading branch information
Kailai-Wang authored Oct 11, 2024
1 parent 1189d1a commit b656376
Show file tree
Hide file tree
Showing 93 changed files with 2,351 additions and 2,668 deletions.
20 changes: 20 additions & 0 deletions common/primitives/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,27 @@ version = '0.1.0'

[dependencies]
base58 = { version = "0.2", default-features = false }
base64 = { version = "0.13", default-features = false, features = ["alloc"] }
parity-scale-codec = { version = "3.6", default-features = false, features = ["derive", "max-encoded-len"] }
strum = { version = "0.26", default-features = false }
strum_macros = { version = "0.26", default-features = false }
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
serde_json = { version = "=1.0.120", default-features = false }
der = { version = "0.6.0", default-features = false }
hex = { version = "0.4", default-features = false }
hex-literal = { version = "0.4.1", default-features = false }
chrono = { version = "0.4", default-features = false, features = ["serde"] }
ring = { version = "0.16.20", default-features = false, features = ["alloc"] }
x509-cert = { version = "0.1.0", default-features = false, features = ["alloc"] }
webpki = { version = "=0.102.0-alpha.3", git = "https://github.com/rustls/webpki", rev = "da923ed", package = "rustls-webpki", default-features = false, features = ["alloc", "ring"] }

frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
pallet-evm = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.1.0", default-features = false }
scale-info = { version = "2.11", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }

litentry-hex-utils = { path = "../../utils/hex", default-features = false }
litentry-macros = { path = "macros" }
Expand All @@ -24,13 +35,22 @@ litentry-proc-macros = { path = "proc-macros" }
[features]
default = ["std"]
std = [
"chrono/std",
"der/std",
"hex/std",
"ring/std",
"webpki/std",
"x509-cert/std",
"serde/std",
"serde_json/std",
"strum/std",
"parity-scale-codec/std",
"scale-info/std",
"frame-support/std",
"sp-core/std",
"sp-runtime/std",
"sp-io/std",
"sp-std/std",
"pallet-evm/std",
"litentry-hex-utils/std",
]
Expand Down
9 changes: 7 additions & 2 deletions common/primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ pub use error::*;
mod vc;
pub use vc::*;

pub mod teebag;
pub use teebag::*;

pub mod assertion;
pub use assertion::Assertion;

pub mod identity;
pub use identity::*;

extern crate alloc;
extern crate core;
use alloc::{format, str, str::FromStr, string::String, vec, vec::Vec};
use core::hash::Hash as CoreHash;
use sp_core::H256;
use sp_runtime::{traits::ConstU32, BoundedVec};

pub use constants::*;
Expand All @@ -44,10 +47,12 @@ pub type ParameterString = BoundedVec<u8, ConstU32<64>>;

/// Common types of parachains.
mod types {
use super::H256;
use sp_runtime::{
traits::{IdentifyAccount, Verify},
MultiSignature,
};

/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
pub type Signature = MultiSignature;

Expand All @@ -68,7 +73,7 @@ mod types {
pub type Nonce = u32;

/// A hash of some data used by the chain.
pub type Hash = sp_core::H256;
pub type Hash = H256;

/// An index to a block.
pub type BlockNumber = u32;
Expand Down
27 changes: 27 additions & 0 deletions common/primitives/core/src/teebag/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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/>.

mod types;
pub use types::*;

mod tcb;
pub use tcb::*;

mod sgx_verify;
pub use sgx_verify::*;

mod quoting_enclave;
pub use quoting_enclave::*;
78 changes: 78 additions & 0 deletions common/primitives/core/src/teebag/quoting_enclave.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright 2021 Integritee AG and Supercomputing Systems AG
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// `QuotingEnclave` primitive part, copied from Integritee

use crate::{MrSigner, QeTcb, Vec};
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_core::RuntimeDebug;

/// This represents all the collateral data that we need to store on chain in order to verify
/// the quoting enclave validity of another enclave that wants to register itself on chain
#[derive(Encode, Decode, Default, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
pub struct QuotingEnclave {
// Todo: make timestamp: Moment
pub issue_date: u64, // unix epoch in milliseconds
// Todo: make timestamp: Moment
pub next_update: u64, // unix epoch in milliseconds
pub miscselect: [u8; 4],
pub miscselect_mask: [u8; 4],
pub attributes: [u8; 16],
pub attributes_mask: [u8; 16],
pub mrsigner: MrSigner,
pub isvprodid: u16,
/// Contains only the TCB versions that are considered UpToDate
pub tcb: Vec<QeTcb>,
}

impl QuotingEnclave {
#[allow(clippy::too_many_arguments)]
pub fn new(
issue_date: u64,
next_update: u64,
miscselect: [u8; 4],
miscselect_mask: [u8; 4],
attributes: [u8; 16],
attributes_mask: [u8; 16],
mrsigner: MrSigner,
isvprodid: u16,
tcb: Vec<QeTcb>,
) -> Self {
Self {
issue_date,
next_update,
miscselect,
miscselect_mask,
attributes,
attributes_mask,
mrsigner,
isvprodid,
tcb,
}
}

pub fn attributes_flags_mask_as_u64(&self) -> u64 {
let slice_as_array: [u8; 8] = self.attributes_mask[0..8].try_into().unwrap();
u64::from_le_bytes(slice_as_array)
}

pub fn attributes_flags_as_u64(&self) -> u64 {
let slice_as_array: [u8; 8] = self.attributes[0..8].try_into().unwrap();
u64::from_le_bytes(slice_as_array)
}
}
Loading

0 comments on commit b656376

Please sign in to comment.