Implement HashOf statement and op (#217)
This commit is contained in:
parent
53ade6ea26
commit
8cc090c5e0
6 changed files with 139 additions and 6 deletions
|
|
@ -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!(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue