Skip to content

Commit

Permalink
Merge branch 'trust-registry-did-method-key' of github.com:docknetwor…
Browse files Browse the repository at this point in the history
…k/dock-substrate into trust-registry-did-method-key
  • Loading branch information
olegnn committed Oct 27, 2023
2 parents df00a81 + 664ac4d commit 97f4249
Show file tree
Hide file tree
Showing 16 changed files with 1,504 additions and 1,203 deletions.
2,554 changes: 1,425 additions & 1,129 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions pallets/core/src/common/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ pub trait Limits: Clone + Eq {
type MaxPolicyControllers: Size;

type MaxIssuerPriceCurrencySymbolSize: Size;
type MaxIssuersPerSchemaSize: Size;
type MaxVerifiersPerSchemaSize: Size;
type MaxIssuerPricesSize: Size;
/// Max no of issuers that can issue for a particular schema
type MaxIssuersPerSchema: Size;
/// Max no of verifiers that can verify (credential) for a particular schema
type MaxVerifiersPerSchema: Size;
/// Max no of currencies an issuer can set the price in for a particular schema
type MaxPriceCurrencies: Size;
type MaxTrustRegistryNameSize: Size;
type MaxConvenerRegistries: Size;
type MaxDelegatedIssuersSize: Size;
/// Max no of delegated issuers a particular issuer can have
type MaxDelegatedIssuers: Size;
/// Max no of schemas that a particular issuer can issue for
type MaxSchemasPerIssuer: Size;
/// Max no of schemas that a particular verifier can verify (credential) for
type MaxSchemasPerVerifier: Size;
}

Expand Down Expand Up @@ -96,12 +102,12 @@ impl Limits for () {
type MaxPolicyControllers = NoLimit;

type MaxIssuerPriceCurrencySymbolSize = NoLimit;
type MaxIssuersPerSchemaSize = NoLimit;
type MaxVerifiersPerSchemaSize = NoLimit;
type MaxIssuerPricesSize = NoLimit;
type MaxIssuersPerSchema = NoLimit;
type MaxVerifiersPerSchema = NoLimit;
type MaxPriceCurrencies = NoLimit;
type MaxTrustRegistryNameSize = NoLimit;
type MaxConvenerRegistries = NoLimit;
type MaxDelegatedIssuersSize = NoLimit;
type MaxDelegatedIssuers = NoLimit;
type MaxSchemasPerIssuer = NoLimit;
type MaxSchemasPerVerifier = NoLimit;
}
8 changes: 4 additions & 4 deletions pallets/core/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ impl<T: Types, L: Limits> Limits for CombineTypesAndLimits<T, L> {
type MaxPolicyControllers = L::MaxPolicyControllers;

type MaxIssuerPriceCurrencySymbolSize = L::MaxMasterMembers;
type MaxIssuersPerSchemaSize = L::MaxIssuersPerSchemaSize;
type MaxVerifiersPerSchemaSize = L::MaxVerifiersPerSchemaSize;
type MaxIssuerPricesSize = L::MaxIssuerPricesSize;
type MaxIssuersPerSchema = L::MaxIssuersPerSchema;
type MaxVerifiersPerSchema = L::MaxVerifiersPerSchema;
type MaxPriceCurrencies = L::MaxPriceCurrencies;
type MaxTrustRegistryNameSize = L::MaxTrustRegistryNameSize;
type MaxConvenerRegistries = L::MaxConvenerRegistries;
type MaxDelegatedIssuersSize = L::MaxDelegatedIssuersSize;
type MaxDelegatedIssuers = L::MaxDelegatedIssuers;
type MaxSchemasPerIssuer = L::MaxSchemasPerIssuer;
type MaxSchemasPerVerifier = L::MaxSchemasPerVerifier;
}
2 changes: 1 addition & 1 deletion pallets/core/src/modules/did/base/did_method_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use codec::{Decode, Encode, MaxEncodedLen};
use core::ops::{Index, RangeFull};
use frame_support::ensure;

/// The type of the `did:key:`.
/// The `public_key` in `did:key:<public_key>`.
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, Copy, Ord, PartialOrd, MaxEncodedLen)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(scale_info_derive::TypeInfo)]
Expand Down
2 changes: 1 addition & 1 deletion pallets/core/src/modules/did/base/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ where
DidOrDidMethodKey::DidMethodKey(did_method_key) => {
did_method_key.ensure_authorizes_target(key, action)
}
_ => Err(Error::<T>::ExpectedDid),
_ => Err(Error::<T>::ExpectedDidMethodKey),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions pallets/core/src/modules/did/controllers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::{common::AuthorizeTarget, deposit_indexed_event, did, impl_wrapper};
use crate::{common::AuthorizeTarget, deposit_indexed_event, impl_wrapper};

/// `DID`'s controller.
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, Copy, Ord, PartialOrd, MaxEncodedLen)]
Expand All @@ -25,7 +25,7 @@ impl Controller {
impl AuthorizeTarget<Did, DidKey> for Controller {
fn ensure_authorizes_target<T, A>(&self, key: &DidKey, action: &A) -> Result<(), Error<T>>
where
T: did::Config,
T: Config,
A: Action<Target = Did>,
{
ensure!(
Expand All @@ -41,7 +41,7 @@ impl AuthorizeTarget<Did, DidKey> for Controller {
impl AuthorizeTarget<Did, DidMethodKey> for Controller {
fn ensure_authorizes_target<T, A>(&self, _: &DidMethodKey, action: &A) -> Result<(), Error<T>>
where
T: did::Config,
T: Config,
A: Action<Target = Did>,
{
self.ensure_controller_for::<T>(&action.target())?;
Expand Down
2 changes: 1 addition & 1 deletion pallets/core/src/modules/did/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub mod pallet {
#[pallet::getter(fn did)]
pub type Dids<T> = StorageMap<_, Blake2_128Concat, Did, StoredDidDetails<T>>;

/// Stores details of the DID keys.
/// Stores nonce for `did:key` DIDs.
#[pallet::storage]
#[pallet::getter(fn did_method_key)]
pub type DidMethodKeys<T> = StorageMap<_, Blake2_128Concat, DidMethodKey, WithNonce<T, ()>>;
Expand Down
6 changes: 0 additions & 6 deletions pallets/core/src/modules/revoke/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ pub mod pallet {
///
/// # Errors
///
/// Returns an error if `revoke.last_modified` does not match the block number when the
/// registry referenced by `revoke.registry_id` was last modified.
///
/// Returns an error if `proof` does not satisfy the policy requirements of the registry
/// referenced by `revoke.registry_id`.
Expand All @@ -239,8 +237,6 @@ pub mod pallet {
///
/// Returns an error if the registry referenced by `revoke.registry_id` is `add_only`.
///
/// Returns an error if `unrevoke.last_modified` does not match the block number when the
/// registry referenced by `revoke.registry_id` was last modified.
///
/// Returns an error if `proof` does not satisfy the policy requirements of the registry
/// referenced by `unrevoke.registry_id`.
Expand All @@ -265,8 +261,6 @@ pub mod pallet {
///
/// Returns an error if the registry referenced by `revoke.registry_id` is `add_only`.
///
/// Returns an error if `removal.last_modified` does not match the block number when the
/// registry referenced by `removal.registry_id` was last modified.
///
/// Returns an error if `proof` does not satisfy the policy requirements of the registry
/// referenced by `removal.registry_id`.
Expand Down
8 changes: 6 additions & 2 deletions pallets/core/src/modules/trust_registry/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<T: Config> Pallet<T> {
TrustRegistriesInfo::<T>::try_mutate(registry_id, |info| {
if let Some(existing) = info.replace(TrustRegistryInfo { convener, name }) {
if existing.convener != convener {
Err(Error::<T>::NotAConvener)?
Err(Error::<T>::NotTheConvener)?
}
}

Expand Down Expand Up @@ -52,12 +52,14 @@ impl<T: Config> Pallet<T> {

Self::try_update_verifiers_and_issuers_with(registry_id, |verifiers, issuers| {
for (schema_id, schema_metadata) in &schemas {
// `issuers` would be a map as `issuer_id` -> `schema_id`s
for issuer in schema_metadata.issuers.keys() {
issuers
.entry(*issuer)
.or_default()
.insert(*schema_id, AddOrRemoveOrModify::Add(()));
}
// `verifiers` would be a map as `verifier_id` -> `schema_id`s
for verifier in schema_metadata.verifiers.iter() {
verifiers
.entry(*verifier)
Expand Down Expand Up @@ -100,7 +102,7 @@ impl<T: Config> Pallet<T> {
{
update.ensure_valid(&Convener(*actor), &schema_metadata)?;
} else {
update.ensure_valid(&MaybeIssuerOrVerifier(*actor), &schema_metadata)?;
update.ensure_valid(&IssuerOrVerifier(*actor), &schema_metadata)?;
}

if let Some(verifiers_update) = update
Expand Down Expand Up @@ -253,6 +255,8 @@ impl<T: Config> Pallet<T> {
})
}

/// Set `schema_id`s corresponding to each issuer and verifier of trust registry with given id.
/// Will check that updates are valid and then update storage in `TrustRegistryVerifierSchemas` and `TrustRegistryIssuerSchemas`
fn try_update_verifiers_and_issuers_with<R, F>(
registry_id: TrustRegistryId,
f: F,
Expand Down
16 changes: 8 additions & 8 deletions pallets/core/src/modules/trust_registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ pub mod pallet {
#[pallet::error]
pub enum Error<T> {
TooManyRegistries,
/// Not a `TrustRegistry`'s `Convener`.
NotAConvener,
/// Not the `TrustRegistry`'s `Convener`.
NotTheConvener,
NoSuchIssuer,
SchemaMetadataAlreadyExists,
SchemaMetadataDoesntExist,
Expand Down Expand Up @@ -80,7 +80,7 @@ pub mod pallet {
pub type TrustRegistriesInfo<T: Config> =
StorageMap<_, Blake2_128Concat, TrustRegistryId, TrustRegistryInfo<T>>;

/// Schema metadata stored in all trust registries.
/// Schema metadata stored in all trust registries. Mapping of the form (schema_id, registry_id) -> schema_metadata
#[pallet::storage]
#[pallet::getter(fn schema_metadata)]
pub type TrustRegistrySchemasMetadata<T: Config> = StorageDoubleMap<
Expand All @@ -92,7 +92,7 @@ pub mod pallet {
TrustRegistrySchemaMetadata<T>,
>;

/// Schema metadata stored in all trust registries.
/// Schema ids corresponding to trust registries. Mapping of registry_id -> schema_id
#[pallet::storage]
#[pallet::getter(fn registry_schema)]
pub type TrustRegistryStoredSchemas<T: Config> = StorageDoubleMap<
Expand All @@ -104,7 +104,7 @@ pub mod pallet {
(),
>;

/// Stores `TrustRegistry`s along with
/// Stores `TrustRegistry`s owned by conveners as a mapping of the form convener_id -> Set<registry_id>
#[pallet::storage]
#[pallet::getter(fn convener_trust_registries)]
pub type ConvenerTrustRegistries<T> =
Expand Down Expand Up @@ -152,7 +152,7 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Creates a new `Trust Registry` with the provided identifier.
/// The DID signature signer must be a registered `Convener` and will be set as a `Trust Registry` owner.
/// The DID signature signer will be set as a `Trust Registry` owner.
#[pallet::weight(SubstrateWeight::<T>::init_trust_registry(init_trust_registry, sig))]
pub fn init_trust_registry(
origin: OriginFor<T>,
Expand All @@ -175,7 +175,7 @@ pub mod pallet {
}

/// Adds a new schema metadata entry (entries).
/// The DID signature signer must be a registered `Convener` owning this Trust Registry.
/// The DID signature signer must be the `Convener` owning this Trust Registry.
#[pallet::weight(SubstrateWeight::<T>::add_schema_metadata(add_schema_metadata, sig))]
pub fn add_schema_metadata(
origin: OriginFor<T>,
Expand All @@ -190,7 +190,7 @@ pub mod pallet {
}

/// Updates the schema metadata entry (entries) with the supplied identifier(s).
/// - Registered `Convener` DID owning registry with the provided identifier can make any modifications.
/// - `Convener` DID owning registry with the provided identifier can make any modifications.
/// - `Issuer` DID can only modify his verification prices and remove himself from the `issuers` map.
/// - `Verifier` DID can only remove himself from the `verifiers` set.
#[pallet::weight(SubstrateWeight::<T>::update_schema_metadata(update_schema_metadata, sig))]
Expand Down
6 changes: 3 additions & 3 deletions pallets/core/src/modules/trust_registry/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ crate::did_or_did_method_key! {
init_trust_registry_already_exists,
other_did_sig
),
Error::<Test>::NotAConvener
Error::<Test>::NotTheConvener
);

let reinit_trust_registry = InitTrustRegistry::<Test> {
Expand Down Expand Up @@ -221,7 +221,7 @@ crate::did_or_did_method_key! {

assert_noop!(
Pallet::<Test>::suspend_issuers(Origin::signed(alice), suspend_issuers, sig),
Error::<Test>::NotAConvener
Error::<Test>::NotTheConvener
);

let suspend_issuers = SuspendIssuers {
Expand Down Expand Up @@ -431,7 +431,7 @@ crate::did_or_did_method_key! {
add_other_schema_metadata,
other_sig
),
Error::<Test>::NotAConvener
Error::<Test>::NotTheConvener
);

let add_other_schema_metadata = AddSchemaMetadata {
Expand Down
Loading

0 comments on commit 97f4249

Please sign in to comment.