Skip to content

Commit

Permalink
Adding omni-account pallet (#3098)
Browse files Browse the repository at this point in the history
  • Loading branch information
silva-fj authored Oct 4, 2024
1 parent 5d3ab44 commit f1f3f62
Show file tree
Hide file tree
Showing 13 changed files with 1,183 additions and 9 deletions.
35 changes: 33 additions & 2 deletions common/primitives/core/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ use parity_scale_codec::{Decode, Encode, Error, Input, MaxEncodedLen};
use scale_info::{meta_type, Type, TypeDefSequence, TypeInfo};
use sp_core::{
crypto::{AccountId32, ByteArray},
ecdsa, ed25519, sr25519, H160,
ecdsa, ed25519, sr25519, H160, H256,
};
use sp_io::hashing::blake2_256;
use sp_runtime::{
traits::{BlakeTwo256, ConstU32},
BoundedVec,
BoundedVec, RuntimeDebug,
};
use strum_macros::EnumIter;

Expand Down Expand Up @@ -468,6 +468,11 @@ impl Identity {
}
))
}

pub fn hash(&self) -> Result<H256, &'static str> {
let did = self.to_did()?;
Ok(H256::from(blake2_256(&did.encode())))
}
}

impl From<ed25519::Public> for Identity {
Expand Down Expand Up @@ -524,6 +529,24 @@ impl From<[u8; 33]> for Identity {
}
}

#[derive(Encode, Decode, TypeInfo, Clone, PartialEq, Eq, RuntimeDebug)]
pub enum MemberIdentity {
Public(Identity),
Private(Vec<u8>),
}

impl MemberIdentity {
pub fn is_public(&self) -> bool {
matches!(self, Self::Public(..))
}
}

impl From<Identity> for MemberIdentity {
fn from(identity: Identity) -> Self {
Self::Public(identity)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -773,4 +796,12 @@ mod tests {
assert_eq!(identity.to_did().unwrap(), did.as_str());
assert_eq!(Identity::from_did(did.as_str()).unwrap(), identity);
}

#[test]
fn test_identity_hash() {
let identity = Identity::Substrate([0; 32].into());
let did_str = "did:litentry:substrate:0x0000000000000000000000000000000000000000000000000000000000000000";
let hash = identity.hash().unwrap();
assert_eq!(hash, H256::from(blake2_256(&did_str.encode())));
}
}
24 changes: 24 additions & 0 deletions parachain/Cargo.lock

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

2 changes: 2 additions & 0 deletions parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
'pallets/teebag',
'pallets/vc-management',
'pallets/xcm-asset-manager',
'pallets/omni-account',
'precompiles/*',
'runtime/litentry',
'runtime/rococo',
Expand Down Expand Up @@ -257,6 +258,7 @@ pallet-bridge-transfer = { path = "pallets/bridge/bridge-transfer", default-feat
pallet-extrinsic-filter = { path = "pallets/extrinsic-filter", default-features = false }
pallet-group = { path = "pallets/group", default-features = false }
pallet-identity-management = { path = "pallets/identity-management", default-features = false }
pallet-omni-account = { path = "pallets/omni-account", default-features = false }
pallet-parachain-staking = { path = "pallets/parachain-staking", default-features = false }
pallet-score-staking = { path = "pallets/score-staking", default-features = false }
pallet-teebag = { path = "pallets/teebag", default-features = false }
Expand Down
52 changes: 52 additions & 0 deletions parachain/pallets/omni-account/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
authors = ['Trust Computing GmbH <[email protected]>']
version = "0.1.0"
edition = "2021"
homepage = 'https://litentry.com'
name = 'pallet-omni-account'
repository = 'https://github.com/litentry/litentry-parachain'

[dependencies]
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }

frame-support = { workspace = true }
frame-system = { workspace = true }
sp-core = { workspace = true }
sp-core-hashing = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

core-primitives = { workspace = true }

[dev-dependencies]
pallet-balances = { workspace = true, default-features = true }
pallet-timestamp = { workspace = true, features = ["std"] }
pallet-teebag = { workspace = true, features = ["std", "test-util"] }
pallet-utility = { workspace = true, features = ["std"] }
sp-keyring = { workspace = true }

[features]
default = ["std"]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-teebag/runtime-benchmarks",
]
std = [
"parity-scale-codec/std",
"scale-info/std",
"sp-std/std",
"sp-io/std",
"sp-core/std",
"sp-runtime/std",
"sp-core/std",
"sp-io/std",
"frame-support/std",
"frame-system/std",
"pallet-teebag/std",
"core-primitives/std",
]
try-runtime = ["frame-support/try-runtime"]
Loading

0 comments on commit f1f3f62

Please sign in to comment.