PcdCommitments new refactor
This commit is contained in:
parent
2e64835142
commit
84ba054632
14
src/pcd.rs
14
src/pcd.rs
@ -192,28 +192,24 @@ 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<Self> {
|
||||
pub fn new(commited_in: &OutPoint, attributes: &Pcd, roles: &Roles) -> Result<Self> {
|
||||
let serialized_outpoint = serialize(commited_in);
|
||||
let mut field2hash: BTreeMap<String, [u8; 32]> = BTreeMap::new();
|
||||
for (field, value) in clear_state.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() {
|
||||
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());
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
Ok(Self(field2hash))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user