Skip to content

Commit

Permalink
patch credential match validation for array of values (#45)
Browse files Browse the repository at this point in the history
* patch credential match validation for array of values

Co-Authored-By: Jacob Ward <[email protected]>
Signed-off-by: Ryan Tate <[email protected]>

* Update src/core/presentation_definition.rs

Co-authored-by: Jacob <[email protected]>

* test the constraint against each array element

Signed-off-by: Ryan Tate <[email protected]>

---------

Signed-off-by: Ryan Tate <[email protected]>
Co-authored-by: Jacob Ward <[email protected]>
  • Loading branch information
Ryanmtate and cobward authored Dec 17, 2024
1 parent 347814f commit 19aa323
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/core/presentation_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,23 +223,19 @@ impl PresentationDefinition {
.filter(|field| field.is_required())
.all(|field| {
match field.filter.as_ref().map(|f| f.validator()) {
Some(validator) => {
let is_valid = field
.path
.iter()
// NOTE: Errors are ignored to allow other paths to
// be checked. Interested in whether there is at least
// one valid path.
//
// An empty iterator will return false on an any() call.
.flat_map(|path| path.query(credential))
// NOTE: This is currently assuming that if any of the paths are a match
// to the credential, then the validation is, at least partially, successful,
// and the credential may satisfy the presentation definition.
.any(|value| validator.validate(value).is_ok());

is_valid
}
Some(validator) => field
.path
.iter()
.flat_map(|path| path.query(credential))
.any(|value| {
if let serde_json::Value::Array(vals) = value {
if vals.iter().any(|val| validator.validate(val).is_ok()) {
return true;
}
}

validator.validate(value).is_ok()
}),
// Allow for fields without validators to pass through.
_ => true,
}
Expand Down

0 comments on commit 19aa323

Please sign in to comment.