From 84ba054632b42f2915e7fc2cd405fbc00b77b233 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Wed, 26 Mar 2025 12:29:05 +0100 Subject: [PATCH] PcdCommitments new refactor --- src/pcd.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/pcd.rs b/src/pcd.rs index 217a527..4d1c2c4 100644 --- a/src/pcd.rs +++ b/src/pcd.rs @@ -192,29 +192,25 @@ impl Tsify for PcdCommitments { impl PcdCommitments { /// Creates a new commitments map with both permissioned and public data, + roles - pub fn new(commited_in: &OutPoint, clear_state: &Pcd, public_data: &Pcd, roles: &Roles) -> Result { + pub fn new(commited_in: &OutPoint, attributes: &Pcd, roles: &Roles) -> Result { let serialized_outpoint = serialize(commited_in); let mut field2hash: BTreeMap = BTreeMap::new(); - for (field, value) in clear_state.iter() { + for (field, value) in attributes.iter() { let mut value_bin = serde_json::to_string(&value)?.into_bytes(); value_bin.extend_from_slice(field.as_bytes()); let tagged_hash = AnkPcdHash::from_value_with_outpoint(&value_bin, &serialized_outpoint); field2hash.insert(field.to_owned(), tagged_hash.to_byte_array()); } - for (field, value) in public_data.iter() { - let mut value_bin = serde_json::to_string(&value)?.into_bytes(); - value_bin.extend_from_slice(field.as_bytes()); - let tagged_hash = AnkPcdHash::from_value_with_outpoint(&value_bin, &serialized_outpoint); - field2hash.insert(field.to_owned(), tagged_hash.to_byte_array()); + if roles.len() > 0 { + // This should be very rare, but just in case + let serialized_roles = roles.to_bytes()?; + + let roles_hash = AnkPcdHash::from_value_with_outpoint(&serialized_roles, &serialized_outpoint); + + field2hash.insert("roles".to_owned(), roles_hash.to_byte_array()); } - let serialized_roles = roles.to_bytes()?; - - let roles_hash = AnkPcdHash::from_value_with_outpoint(&serialized_roles, &serialized_outpoint); - - field2hash.insert("roles".to_owned(), roles_hash.to_byte_array()); - Ok(Self(field2hash)) }