From d41d232b644e50cf0dde2171c17d8f6813d0a574 Mon Sep 17 00:00:00 2001 From: Joel Moore <47923231+JMoore96@users.noreply.github.com> Date: Mon, 28 Mar 2022 03:25:05 -0400 Subject: [PATCH] MESH-1767 - Add secondary key and permissions length checks to `cdd_register_did` (#1221) * modified base_cdd_register_did function * minor change * minor change * minor change and formatting * minor changes and comments Co-authored-by: Adam Dossa Co-authored-by: Robert Gabriel Jakabosky --- pallets/identity/src/claims.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pallets/identity/src/claims.rs b/pallets/identity/src/claims.rs index c71f8eb2e8..408a343cef 100644 --- a/pallets/identity/src/claims.rs +++ b/pallets/identity/src/claims.rs @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{Claim1stKey, Claim2ndKey, Claims, DidRecords, Error, Module}; +use crate::{Claim1stKey, Claim2ndKey, Claims, DidRecord, DidRecords, Error, Module}; use core::convert::From; use frame_support::{ dispatch::{DispatchError, DispatchResult}, @@ -481,6 +481,23 @@ impl Module { // Sender has to be part of CDDProviders Self::ensure_authorized_cdd_provider(cdd_did)?; + let record = DidRecord { + ..Default::default() + }; + + // Calculates the cost complexity of the SK's permissions. + let cost = + secondary_keys + .iter() + .try_fold(0, |cost, auth| -> Result { + // Check limit for this SK's permissions. + Self::ensure_perms_length_limited(&auth.permissions)?; + Ok(cost.saturating_add(auth.permissions.complexity())) + })?; + + // Check secondary key limits. + Self::ensure_secondary_keys_limited(&record, secondary_keys.len(), cost)?; + // Register Identity let target_did = Self::_register_did( target_account,