Implement HashOf statement and op (#217)

This commit is contained in:
Ahmad Afuni 2025-05-06 19:14:53 +10:00 committed by GitHub
parent 53ade6ea26
commit 8cc090c5e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 139 additions and 6 deletions

View file

@ -7,9 +7,10 @@ use itertools::Itertools;
use serde::{Deserialize, Serialize};
use crate::middleware::{
self, check_st_tmpl, hash_str, AnchoredKey, Key, MainPodInputs, NativeOperation,
NativePredicate, OperationAux, OperationType, Params, PodId, PodProver, PodSigner, Predicate,
Statement, StatementArg, Value, WildcardValue, EMPTY_VALUE, KEY_TYPE, SELF,
self, check_st_tmpl, hash_str, hash_values, AnchoredKey, Hash, Key, MainPodInputs,
NativeOperation, NativePredicate, OperationAux, OperationType, Params, PodId, PodProver,
PodSigner, Predicate, Statement, StatementArg, Value, WildcardValue, EMPTY_VALUE, KEY_TYPE,
SELF,
};
mod custom;
@ -435,6 +436,26 @@ impl MainPodBuilder {
return Err(Error::op_invalid_args("max-of".to_string()));
}
},
HashOf => match (args[0].clone(), args[1].clone(), args[2].clone()) {
(
OperationArg::Statement(Statement::ValueOf(ak0, v0)),
OperationArg::Statement(Statement::ValueOf(ak1, v1)),
OperationArg::Statement(Statement::ValueOf(ak2, v2)),
) => {
if Hash::from(v0.raw()) == hash_values(&[v1, v2]) {
vec![
StatementArg::Key(ak0),
StatementArg::Key(ak1),
StatementArg::Key(ak2),
]
} else {
return Err(Error::op_invalid_args("hash-of".to_string()));
}
}
_ => {
return Err(Error::op_invalid_args("hash-of".to_string()));
}
},
ContainsFromEntries => self.op_args_entries(public, args)?,
NotContainsFromEntries => self.op_args_entries(public, args)?,
_ => Err(Error::custom(format!(