Update decrypt_pcd to return Map

This commit is contained in:
Sosthene 2024-12-11 23:27:18 +01:00 committed by Nicolas Cantu
parent d24abe967e
commit ce0e5f7b73

View File

@ -69,21 +69,26 @@ impl ProcessState {
}
// Update the commitment
self.pcd_commitment = Value::Object(clear_pcd.hash_all_fields(self.commited_in)?);
self.pcd_commitment = Value::Object(Value::Object(clear_pcd.clone()).hash_all_fields(self.commited_in)?);
// Todo for now we rehash everything, which is a bit wasteful but fine for a proto
// Update the encrypted value
clear_pcd.encrypt_fields(&[key.to_string()], &mut self.keys, self.encrypted_pcd.as_object_mut().unwrap())?;
Value::Object(clear_pcd).encrypt_fields(&[key.to_string()], &mut self.keys, self.encrypted_pcd.as_object_mut().unwrap())?;
Ok(())
}
pub fn decrypt_pcd(&self) -> anyhow::Result<Value> {
/// Return a decrypted version of the pcd in this state
/// 3 outputs possible for each field:
/// 1) We have the key and we return the decrypted value
/// 2) We don't have the key, we return the commitment
/// 3) the field is unencrypted, we leave it as sit is
pub fn decrypt_pcd(&self) -> anyhow::Result<Map<String, Value>> {
let mut fields2plain = Map::new();
let fields2commit = self.pcd_commitment.to_value_object()?;
self.encrypted_pcd.decrypt_all(self.commited_in, &fields2commit, &self.keys, &mut fields2plain)?;
Ok(Value::Object(fields2plain))
Ok(fields2plain)
}
pub fn get_message_hash(&self, approval: bool) -> anyhow::Result<AnkHash> {
@ -199,7 +204,7 @@ impl ProcessState {
pub fn get_fields_to_validate_for_member(&self, member: &Member) -> anyhow::Result<Vec<String>> {
let decrypted = self.decrypt_pcd()?;
let roles = decrypted.extract_roles()?;
let roles = Value::Object(decrypted).extract_roles()?;
let mut res: HashSet<String> = HashSet::new();