From 19aa3230750449904e718c0208464552e0966d69 Mon Sep 17 00:00:00 2001 From: Ryan Tate Date: Tue, 17 Dec 2024 07:49:38 -0800 Subject: [PATCH] patch credential match validation for array of values (#45) * patch credential match validation for array of values Co-Authored-By: Jacob Ward Signed-off-by: Ryan Tate * Update src/core/presentation_definition.rs Co-authored-by: Jacob * test the constraint against each array element Signed-off-by: Ryan Tate --------- Signed-off-by: Ryan Tate Co-authored-by: Jacob Ward --- src/core/presentation_definition.rs | 30 +++++++++++++---------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/core/presentation_definition.rs b/src/core/presentation_definition.rs index 0365fac..2b9402b 100644 --- a/src/core/presentation_definition.rs +++ b/src/core/presentation_definition.rs @@ -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, }