diff --git a/Cargo.lock b/Cargo.lock index 27e99f93c..8ebba8f07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1678,7 +1678,7 @@ dependencies = [ [[package]] name = "dock-price-feed" version = "0.2.1" -source = "git+https://github.com/docknetwork/dock-substrate-common.git#fa0855d4d68aa8d2523b023efa1c03fff8dd2c5c" +source = "git+https://github.com/docknetwork/dock-substrate-common.git#e36c43c4f314826ad48d90c03d879152cfd2ae21" dependencies = [ "frame-support", "frame-system", @@ -1696,7 +1696,7 @@ dependencies = [ [[package]] name = "dock-price-feed-rpc" version = "0.2.1" -source = "git+https://github.com/docknetwork/dock-substrate-common.git#fa0855d4d68aa8d2523b023efa1c03fff8dd2c5c" +source = "git+https://github.com/docknetwork/dock-substrate-common.git#e36c43c4f314826ad48d90c03d879152cfd2ae21" dependencies = [ "dock-price-feed", "jsonrpsee", @@ -1821,6 +1821,7 @@ dependencies = [ "sp-version", "static_assertions", "substrate-wasm-builder", + "utils", ] [[package]] @@ -5077,7 +5078,7 @@ dependencies = [ [[package]] name = "pallet-collective" version = "4.0.0-dev" -source = "git+https://github.com/docknetwork/dock-substrate-common.git#fa0855d4d68aa8d2523b023efa1c03fff8dd2c5c" +source = "git+https://github.com/docknetwork/dock-substrate-common.git#e36c43c4f314826ad48d90c03d879152cfd2ae21" dependencies = [ "frame-benchmarking", "frame-support", @@ -5094,7 +5095,7 @@ dependencies = [ [[package]] name = "pallet-democracy" version = "4.0.0-dev" -source = "git+https://github.com/docknetwork/dock-substrate-common.git#fa0855d4d68aa8d2523b023efa1c03fff8dd2c5c" +source = "git+https://github.com/docknetwork/dock-substrate-common.git#e36c43c4f314826ad48d90c03d879152cfd2ae21" dependencies = [ "frame-benchmarking", "frame-support", @@ -5152,7 +5153,7 @@ dependencies = [ [[package]] name = "pallet-elections-phragmen" version = "5.0.0-dev" -source = "git+https://github.com/docknetwork/dock-substrate-common.git#fa0855d4d68aa8d2523b023efa1c03fff8dd2c5c" +source = "git+https://github.com/docknetwork/dock-substrate-common.git#e36c43c4f314826ad48d90c03d879152cfd2ae21" dependencies = [ "frame-support", "frame-system", @@ -5476,7 +5477,7 @@ dependencies = [ [[package]] name = "pallet-staking" version = "4.0.0-dev" -source = "git+https://github.com/docknetwork/dock-substrate-common.git#fa0855d4d68aa8d2523b023efa1c03fff8dd2c5c" +source = "git+https://github.com/docknetwork/dock-substrate-common.git#e36c43c4f314826ad48d90c03d879152cfd2ae21" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5970,7 +5971,7 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "price-provider" version = "0.3.0" -source = "git+https://github.com/docknetwork/dock-substrate-common.git#fa0855d4d68aa8d2523b023efa1c03fff8dd2c5c" +source = "git+https://github.com/docknetwork/dock-substrate-common.git#e36c43c4f314826ad48d90c03d879152cfd2ae21" dependencies = [ "frame-support", "frame-system", @@ -9598,14 +9599,15 @@ dependencies = [ [[package]] name = "utils" -version = "0.3.1" -source = "git+https://github.com/docknetwork/dock-substrate-common.git#fa0855d4d68aa8d2523b023efa1c03fff8dd2c5c" +version = "0.3.2" +source = "git+https://github.com/docknetwork/dock-substrate-common.git#e36c43c4f314826ad48d90c03d879152cfd2ae21" dependencies = [ "frame-support", "num-traits", "parity-scale-codec", "scale-info", "serde", + "sp-io", "sp-runtime", "sp-std", ] diff --git a/pallets/core/src/common/policy.rs b/pallets/core/src/common/policy.rs index 653cd4720..0b8a486ca 100644 --- a/pallets/core/src/common/policy.rs +++ b/pallets/core/src/common/policy.rs @@ -9,7 +9,7 @@ use crate::util::btree_set; use crate::{ did, did::{ - AuthorizeAction, Did, DidKey, DidMethodKey, DidOrDidMethodKey, DidOrDidMethodKeySignature, + AuthorizeTarget, Did, DidKey, DidMethodKey, DidOrDidMethodKey, DidOrDidMethodKeySignature, Signed, SignedActionWithNonce, }, util::{Action, ActionWithNonce, NonceError, UpdateWithNonceError, WithNonce}, @@ -144,8 +144,8 @@ impl Policy { V: HasPolicy, F: FnOnce(S, &mut Option) -> Result, WithNonce: ActionWithNonce + ToStateChange, - Did: AuthorizeAction< as Action>::Target, DidKey>, - DidMethodKey: AuthorizeAction< as Action>::Target, DidMethodKey>, + Did: AuthorizeTarget< as Action>::Target, DidKey>, + DidMethodKey: AuthorizeTarget< as Action>::Target, DidMethodKey>, E: From + From> + From @@ -178,8 +178,8 @@ fn rec_update( where E: From + From + From>, WithNonce: ActionWithNonce + ToStateChange, - Did: AuthorizeAction< as Action>::Target, DidKey>, - DidMethodKey: AuthorizeAction< as Action>::Target, DidMethodKey>, + Did: AuthorizeTarget< as Action>::Target, DidKey>, + DidMethodKey: AuthorizeTarget< as Action>::Target, DidMethodKey>, { if let Some(sig_with_nonce) = proof.next() { let action_with_nonce = WithNonce::new_with_nonce(action, sig_with_nonce.nonce); @@ -202,8 +202,8 @@ pub struct PolicyExecutor(pub DidOrDidMethodKey); crate::impl_wrapper!(PolicyExecutor(DidOrDidMethodKey)); -impl AuthorizeAction for PolicyExecutor {} -impl AuthorizeAction for PolicyExecutor {} +impl AuthorizeTarget for PolicyExecutor {} +impl AuthorizeTarget for PolicyExecutor {} /// `DID`s signature along with the nonce. pub type DidSignatureWithNonce = WithNonce>; diff --git a/pallets/core/src/modules/accumulator/types.rs b/pallets/core/src/modules/accumulator/types.rs index 80aa43341..93ce643b9 100644 --- a/pallets/core/src/modules/accumulator/types.rs +++ b/pallets/core/src/modules/accumulator/types.rs @@ -3,7 +3,7 @@ use frame_support::{CloneNoBound, DebugNoBound, EqNoBound, PartialEqNoBound}; use super::*; use crate::{ common::{Limits, TypesAndLimits}, - did::{AuthorizeAction, DidKey, DidMethodKey, DidOrDidMethodKey}, + did::{AuthorizeTarget, DidKey, DidMethodKey, DidOrDidMethodKey}, util::BoundedBytes, }; @@ -32,8 +32,8 @@ pub struct AccumulatorOwner(pub DidOrDidMethodKey); crate::impl_wrapper!(AccumulatorOwner(DidOrDidMethodKey)); -impl AuthorizeAction<(), DidKey> for AccumulatorOwner {} -impl AuthorizeAction<(), DidMethodKey> for AccumulatorOwner {} +impl AuthorizeTarget<(), DidKey> for AccumulatorOwner {} +impl AuthorizeTarget<(), DidMethodKey> for AccumulatorOwner {} #[derive( scale_info_derive::TypeInfo, diff --git a/pallets/core/src/modules/attest/mod.rs b/pallets/core/src/modules/attest/mod.rs index ed7af3773..385c8740e 100644 --- a/pallets/core/src/modules/attest/mod.rs +++ b/pallets/core/src/modules/attest/mod.rs @@ -5,7 +5,7 @@ use crate::{ common::{signatures::ForSigType, Limits, TypesAndLimits}, did::{ - self, AuthorizeAction, DidKey, DidMethodKey, DidOrDidMethodKey, DidOrDidMethodKeySignature, + self, AuthorizeTarget, DidKey, DidMethodKey, DidOrDidMethodKey, DidOrDidMethodKeySignature, SignedActionWithNonce, }, util::BoundedBytes, @@ -37,8 +37,8 @@ pub type Iri = BoundedBytes<::MaxIriSize>; #[scale_info(omit_prefix)] pub struct Attester(pub DidOrDidMethodKey); -impl AuthorizeAction<(), DidKey> for Attester {} -impl AuthorizeAction<(), DidMethodKey> for Attester {} +impl AuthorizeTarget<(), DidKey> for Attester {} +impl AuthorizeTarget<(), DidMethodKey> for Attester {} crate::impl_wrapper!(Attester(DidOrDidMethodKey)); diff --git a/pallets/core/src/modules/blob/mod.rs b/pallets/core/src/modules/blob/mod.rs index babc249cd..a423567be 100644 --- a/pallets/core/src/modules/blob/mod.rs +++ b/pallets/core/src/modules/blob/mod.rs @@ -4,7 +4,7 @@ use crate::{ common::{signatures::ForSigType, Limits, TypesAndLimits}, did, did::{ - AuthorizeAction, Did, DidKey, DidMethodKey, DidOrDidMethodKey, DidOrDidMethodKeySignature, + AuthorizeTarget, Did, DidKey, DidMethodKey, DidOrDidMethodKey, DidOrDidMethodKeySignature, SignedActionWithNonce, }, util::BoundedBytes, @@ -35,8 +35,8 @@ mod weights; #[scale_info(omit_prefix)] pub struct BlobOwner(pub DidOrDidMethodKey); -impl AuthorizeAction<(), DidKey> for BlobOwner {} -impl AuthorizeAction<(), DidMethodKey> for BlobOwner {} +impl AuthorizeTarget<(), DidKey> for BlobOwner {} +impl AuthorizeTarget<(), DidMethodKey> for BlobOwner {} crate::impl_wrapper!(BlobOwner(DidOrDidMethodKey)); diff --git a/pallets/core/src/modules/did/base/did_method_key.rs b/pallets/core/src/modules/did/base/did_method_key.rs index 8ff47b31a..efb033dc5 100644 --- a/pallets/core/src/modules/did/base/did_method_key.rs +++ b/pallets/core/src/modules/did/base/did_method_key.rs @@ -30,7 +30,7 @@ impl StorageMapRef> for DidMethodKey type Storage = DidMethodKeys; } -impl AuthorizeAction for DidMethodKey {} +impl AuthorizeTarget for DidMethodKey {} impl Index for DidMethodKey { type Output = [u8]; diff --git a/pallets/core/src/modules/did/base/mod.rs b/pallets/core/src/modules/did/base/mod.rs index 8ea9f88c7..1026f9cb1 100644 --- a/pallets/core/src/modules/did/base/mod.rs +++ b/pallets/core/src/modules/did/base/mod.rs @@ -68,8 +68,8 @@ impl TryFrom for DidMethodKey { #[scale_info(omit_prefix)] pub struct Did(#[cfg_attr(feature = "serde", serde(with = "hex"))] pub RawDid); -impl AuthorizeAction for Did { - fn ensure_can_perform_action(&self, key: &DidKey, _: &A) -> Result<(), Error> +impl AuthorizeTarget for Did { + fn ensure_authorizes_target(&self, key: &DidKey, _: &A) -> Result<(), Error> where T: crate::did::Config, A: Action, diff --git a/pallets/core/src/modules/did/base/signature.rs b/pallets/core/src/modules/did/base/signature.rs index 64261c36f..a0a678c9e 100644 --- a/pallets/core/src/modules/did/base/signature.rs +++ b/pallets/core/src/modules/did/base/signature.rs @@ -5,10 +5,9 @@ use crate::common::{DidMethodKeySigValue, ForSigType, SigValue, ToStateChange, T use frame_support::traits::Get; /// Authorizes action performed by `Self` over supplied target using given key. -pub trait AuthorizeAction { - fn ensure_can_perform_action(&self, _: &Key, _: &A) -> Result<(), Error> +pub trait AuthorizeTarget { + fn ensure_authorizes_target(&self, _: &Key, _: &A) -> Result<(), Error> where - T: crate::did::Config, A: Action, { Ok(()) @@ -34,12 +33,18 @@ pub trait Signed { fn signer(&self) -> Self::Signer; } +type AuthorizationResult = Result< + Option::Signer, >::Key>>, + Error, +>; + /// Authorizes signed action. -pub trait AuthorizeSigned: Signed { - fn ensure_authorizes + ToStateChange>( - &self, - action: &A, - ) -> Result>, Error>; +pub trait AuthorizeSignedAction: Signed { + type Key; + + fn authorizes_signed_action(&self, action: &A) -> AuthorizationResult + where + A: ToStateChange; } /// `DID`'s signature along with the used `DID`s key reference. @@ -167,21 +172,26 @@ impl + Clone> Signed for DidSignature { /// Verifies that `did`'s key with id `key_id` can either authenticate or control otherwise returns an error. /// Then provided signature will be verified against the supplied public key and `true` returned for a valid signature. -impl + Clone, E> AuthorizeSigned for DidSignature +impl + Clone, A: Action> AuthorizeSignedAction for DidSignature where - D: AuthorizeAction, + D: AuthorizeTarget, { - fn ensure_authorizes + ToStateChange>( + type Key = DidKey; + + fn authorizes_signed_action( &self, action: &A, - ) -> Result>, Error> { + ) -> Result>, Error> + where + A: ToStateChange, + { let raw_did = self.did.clone().into(); let signer_pubkey = Pallet::::did_key(raw_did, self.key_id).ok_or(Error::::NoKeyForDid)?; let encoded_state_change = action.to_state_change().encode(); - raw_did.ensure_can_perform_action(&signer_pubkey, action)?; - self.did.ensure_can_perform_action(&signer_pubkey, action)?; + raw_did.ensure_authorizes_target(&signer_pubkey, action)?; + self.did.ensure_authorizes_target(&signer_pubkey, action)?; self.sig .verify(&encoded_state_change, signer_pubkey.public_key()) @@ -203,20 +213,25 @@ impl + Clone> Signed for DidKeySignature { } } -impl + Clone, E> AuthorizeSigned for DidKeySignature +impl + Clone, A: Action> AuthorizeSignedAction for DidKeySignature where - DK: AuthorizeAction, + DK: AuthorizeTarget, { - fn ensure_authorizes + ToStateChange>( + type Key = DidMethodKey; + + fn authorizes_signed_action( &self, action: &A, - ) -> Result>, Error> { + ) -> Result>, Error> + where + A: ToStateChange, + { let signer_pubkey = self.did_key.clone().into(); let encoded_state_change = action.to_state_change().encode(); - signer_pubkey.ensure_can_perform_action(&signer_pubkey, action)?; + signer_pubkey.ensure_authorizes_target(&signer_pubkey, action)?; self.did_key - .ensure_can_perform_action(&signer_pubkey, action)?; + .ensure_authorizes_target(&signer_pubkey, action)?; self.sig .verify(&encoded_state_change, &signer_pubkey) @@ -245,44 +260,48 @@ where } } -impl + From + Clone, E> - AuthorizeSigned for DidOrDidMethodKeySignature +impl + From + Clone, A: Action> + AuthorizeSignedAction for DidOrDidMethodKeySignature where - DidSignature: AuthorizeSigned, - DidKeySignature: AuthorizeSigned, - Did: AuthorizeAction, - DidMethodKey: AuthorizeAction, - D: AuthorizeAction + AuthorizeAction, + DidSignature: AuthorizeSignedAction, + DidKeySignature: + AuthorizeSignedAction, + Did: AuthorizeTarget, + DidMethodKey: AuthorizeTarget, + D: AuthorizeTarget + AuthorizeTarget, { - fn ensure_authorizes + ToStateChange>( + type Key = DidKeyOrDidMethodKey; + + fn authorizes_signed_action( &self, action: &A, - ) -> Result>, Error> { + ) -> Result>, Error> + where + A: ToStateChange, + { let authorization = match self { - Self::DidSignature(sig) => { - sig.ensure_authorizes(action)? - .map(|Authorization { signer, key, .. }| Authorization { - signer: D::from(DidOrDidMethodKey::Did(signer)), - key: DidKeyOrDidMethodKey::DidKey(key), - }) - } - Self::DidKeySignature(sig) => { - sig.ensure_authorizes(action)? - .map(|Authorization { signer, key, .. }| Authorization { - signer: DidOrDidMethodKey::DidMethodKey(signer).into(), - key: DidKeyOrDidMethodKey::DidMethodKey(key), - }) - } + Self::DidSignature(sig) => sig.authorizes_signed_action(action)?.map( + |Authorization { signer, key, .. }| Authorization { + signer: D::from(DidOrDidMethodKey::Did(signer)), + key: DidKeyOrDidMethodKey::DidKey(key), + }, + ), + Self::DidKeySignature(sig) => sig.authorizes_signed_action(action)?.map( + |Authorization { signer, key, .. }| Authorization { + signer: DidOrDidMethodKey::DidMethodKey(signer).into(), + key: DidKeyOrDidMethodKey::DidMethodKey(key), + }, + ), _ => None, }; if let Some(Authorization { key, signer }) = authorization.as_ref() { match key { DidKeyOrDidMethodKey::DidKey(did_key) => { - signer.ensure_can_perform_action(did_key, action)? + signer.ensure_authorizes_target(did_key, action)? } DidKeyOrDidMethodKey::DidMethodKey(did_method_key) => { - signer.ensure_can_perform_action(did_method_key, action)? + signer.ensure_authorizes_target(did_method_key, action)? } } } @@ -331,12 +350,14 @@ where impl SignedActionWithNonce> where A: ActionWithNonce + ToStateChange, - D: Into + AuthorizeAction + Clone, + D: Into + + AuthorizeTarget as AuthorizeSignedAction>::Key> + + Clone, + DidSignature: AuthorizeSignedAction, { pub fn execute(self, f: F) -> Result where F: FnOnce(A, D) -> Result, - DidSignature: AuthorizeSigned, E: From + From + From>, { let SignedActionWithNonce { @@ -344,7 +365,7 @@ where } = self; ensure!( - signature.ensure_authorizes(&action)?.is_some(), + signature.authorizes_signed_action(&action)?.is_some(), Error::::InvalidSignature ); @@ -357,12 +378,14 @@ where impl SignedActionWithNonce> where A: ActionWithNonce + ToStateChange, - D: Into + AuthorizeAction + Clone, + D: Into + + AuthorizeTarget as AuthorizeSignedAction>::Key> + + Clone, + DidKeySignature: AuthorizeSignedAction, { pub fn execute(self, f: F) -> Result where F: FnOnce(A, D) -> Result, - DidKeySignature: AuthorizeSigned, E: From + From + From>, { let SignedActionWithNonce { @@ -370,7 +393,7 @@ where } = self; ensure!( - signature.ensure_authorizes(&action)?.is_some(), + signature.authorizes_signed_action(&action)?.is_some(), Error::::InvalidSignature ); @@ -388,12 +411,12 @@ impl SignedActionWithNonce + ToStateChange, D: Into + From + Clone, - D: AuthorizeAction + AuthorizeAction, + D: AuthorizeTarget + AuthorizeTarget, + DidOrDidMethodKeySignature: AuthorizeSignedAction, { pub fn execute(self, f: F) -> Result where F: FnOnce(A, D) -> Result, - DidOrDidMethodKeySignature: AuthorizeSigned, E: From + From + From>, { let SignedActionWithNonce { @@ -401,7 +424,7 @@ where } = self; let Authorization { signer, .. } = signature - .ensure_authorizes(&action)? + .authorizes_signed_action(&action)? .ok_or(Error::::InvalidSignature)?; match signer.clone().into() { @@ -421,12 +444,12 @@ where impl SignedActionWithNonce> where A: ActionWithNonce + ToStateChange, + DidOrDidMethodKeySignature: + AuthorizeSignedAction, { pub fn execute_from_controller(self, f: F) -> Result where F: FnOnce(A, &mut OnChainDidDetails) -> Result, - DidOrDidMethodKeySignature: - AuthorizeSigned, E: From + From + From>, { self.execute_removable_from_controller(|action, reference| { @@ -437,8 +460,6 @@ where pub fn execute_removable_from_controller(self, f: F) -> Result where F: FnOnce(A, &mut Option) -> Result, - DidOrDidMethodKeySignature: - AuthorizeSigned, E: From + From + From>, { let SignedActionWithNonce { @@ -446,7 +467,7 @@ where } = self; let Authorization { signer, .. } = signature - .ensure_authorizes(&action)? + .authorizes_signed_action(&action)? .ok_or(Error::::InvalidSignature)?; match signer.into() { diff --git a/pallets/core/src/modules/did/controllers.rs b/pallets/core/src/modules/did/controllers.rs index 6009834da..0ae74f72e 100644 --- a/pallets/core/src/modules/did/controllers.rs +++ b/pallets/core/src/modules/did/controllers.rs @@ -22,8 +22,8 @@ impl Controller { } } -impl AuthorizeAction for Controller { - fn ensure_can_perform_action(&self, key: &DidKey, action: &A) -> Result<(), Error> +impl AuthorizeTarget for Controller { + fn ensure_authorizes_target(&self, key: &DidKey, action: &A) -> Result<(), Error> where T: crate::did::Config, A: Action, @@ -38,8 +38,8 @@ impl AuthorizeAction for Controller { } } -impl AuthorizeAction for Controller { - fn ensure_can_perform_action(&self, _: &DidMethodKey, action: &A) -> Result<(), Error> +impl AuthorizeTarget for Controller { + fn ensure_authorizes_target(&self, _: &DidMethodKey, action: &A) -> Result<(), Error> where T: crate::did::Config, A: Action, diff --git a/pallets/core/src/modules/master/mod.rs b/pallets/core/src/modules/master/mod.rs index 801d264a0..a0a6a5f86 100644 --- a/pallets/core/src/modules/master/mod.rs +++ b/pallets/core/src/modules/master/mod.rs @@ -61,7 +61,7 @@ use crate::util::btree_set; use crate::{ common::{signatures::ForSigType, Limits, Types}, - did::{self, Authorization, AuthorizeSigned, Did, DidSignature}, + did::{self, Authorization, AuthorizeSignedAction, Did, DidSignature}, util::WithNonce, }; use alloc::{boxed::Box, collections::BTreeMap, vec::Vec}; @@ -343,7 +343,7 @@ pub mod pallet { let action = WithNonce::new_with_nonce(new_payload, nonce); let Authorization { signer, .. } = a .data() - .ensure_authorizes(&action)? + .authorizes_signed_action(&action)? .ok_or(Error::::BadSig)?; // Check if nonce is valid and increase it diff --git a/pallets/core/src/modules/offchain_signatures/params.rs b/pallets/core/src/modules/offchain_signatures/params.rs index 71c111b76..617fda976 100644 --- a/pallets/core/src/modules/offchain_signatures/params.rs +++ b/pallets/core/src/modules/offchain_signatures/params.rs @@ -1,6 +1,6 @@ use crate::{ common::Limits, - did::{AuthorizeAction, DidKey, DidMethodKey, DidOrDidMethodKey}, + did::{AuthorizeTarget, DidKey, DidMethodKey, DidOrDidMethodKey}, offchain_signatures::schemes::*, util::IncId, }; @@ -24,8 +24,8 @@ pub struct SignatureParamsOwner(pub DidOrDidMethodKey); crate::impl_wrapper!(SignatureParamsOwner(DidOrDidMethodKey)); -impl AuthorizeAction<(), DidKey> for SignatureParamsOwner {} -impl AuthorizeAction<(), DidMethodKey> for SignatureParamsOwner {} +impl AuthorizeTarget<(), DidKey> for SignatureParamsOwner {} +impl AuthorizeTarget<(), DidMethodKey> for SignatureParamsOwner {} pub type SignatureParamsStorageKey = (SignatureParamsOwner, IncId); pub type BBSPublicKeyWithParams = (BBSPublicKey, Option>); diff --git a/pallets/core/src/modules/trust_registry/types.rs b/pallets/core/src/modules/trust_registry/types.rs index a8b1f5d17..c00acf2d6 100644 --- a/pallets/core/src/modules/trust_registry/types.rs +++ b/pallets/core/src/modules/trust_registry/types.rs @@ -1,11 +1,11 @@ use super::{Config, Error}; #[cfg(feature = "serde")] -use crate::util::{batch_update::*, btree_map, btree_set, hex}; +use crate::util::{btree_map, btree_set, hex}; use crate::{ common::Limits, - did::{AuthorizeAction, DidKey, DidMethodKey, DidOrDidMethodKey}, + did::{AuthorizeTarget, DidKey, DidMethodKey, DidOrDidMethodKey}, impl_wrapper, - util::BoundedKeyValue, + util::{batch_update::*, BoundedKeyValue}, }; use alloc::collections::BTreeMap; use codec::{Decode, Encode, MaxEncodedLen}; @@ -26,10 +26,10 @@ pub struct Convener(pub DidOrDidMethodKey); impl_wrapper!(Convener(DidOrDidMethodKey)); -impl AuthorizeAction<(), DidKey> for Convener {} -impl AuthorizeAction for Convener {} -impl AuthorizeAction<(), DidMethodKey> for Convener {} -impl AuthorizeAction for Convener {} +impl AuthorizeTarget<(), DidKey> for Convener {} +impl AuthorizeTarget for Convener {} +impl AuthorizeTarget<(), DidMethodKey> for Convener {} +impl AuthorizeTarget for Convener {} /// Maybe an `Issuer` or `Verifier` but definitely not a `Convener`. #[derive(Encode, Decode, Clone, Debug, Copy, PartialEq, Eq, Ord, PartialOrd, MaxEncodedLen)] @@ -69,8 +69,8 @@ pub struct Issuer(pub DidOrDidMethodKey); impl_wrapper!(Issuer(DidOrDidMethodKey)); -impl AuthorizeAction for Issuer {} -impl AuthorizeAction for Issuer {} +impl AuthorizeTarget for Issuer {} +impl AuthorizeTarget for Issuer {} /// Trust registry `Verifier`'s `DID`. #[derive(Encode, Decode, Clone, Debug, Copy, PartialEq, Eq, Ord, PartialOrd, MaxEncodedLen)] @@ -92,8 +92,8 @@ pub struct ConvenerOrIssuerOrVerifier(pub DidOrDidMethodKey); impl_wrapper!(ConvenerOrIssuerOrVerifier(DidOrDidMethodKey)); -impl AuthorizeAction for ConvenerOrIssuerOrVerifier {} -impl AuthorizeAction for ConvenerOrIssuerOrVerifier {} +impl AuthorizeTarget for ConvenerOrIssuerOrVerifier {} +impl AuthorizeTarget for ConvenerOrIssuerOrVerifier {} /// Trust registry `Convener`/`Issuer`/`Verifier`'s `DID`. #[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, Copy, Ord, PartialOrd, MaxEncodedLen)] @@ -238,6 +238,10 @@ impl DelegatedUpdate { SetOrModify::Modify(update) => update.len() as u32, } } + + pub fn is_empty(&self) -> bool { + self.len() == 0 + } } #[derive( diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 362d03b6e..550612e14 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -34,6 +34,10 @@ scale-info = { version = "2.1.2", default-features = false, features = ["derive" getrandom = { version = "0.2", features = ["js"] } hex = { version = "0.4", default-features = false } +[dependencies.utils] +git = "https://github.com/docknetwork/dock-substrate-common.git" +default-features = false + [dependencies.pallet-babe] default-features = false git = "https://github.com/paritytech/substrate.git" @@ -494,6 +498,7 @@ default = ["std"] std = [ "pallet-babe/std", "balances/std", + "utils/std", "sp-consensus-vrf/std", "codec/std", "log/std",