Skip to content

Commit

Permalink
Add selective_disclosable field
Browse files Browse the repository at this point in the history
  • Loading branch information
w4ll3 committed Dec 18, 2024
1 parent 19aa323 commit 7485ce0
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/core/input_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ impl InputDescriptor {
self.constraints
.fields
.iter()
.map(|field| field.requested_fields(self.id.clone(), value))
.map(|field| {
field.requested_fields(self.id.clone(), self.constraints.limit_disclosure(), value)
})
.collect()
}

Expand Down Expand Up @@ -235,6 +237,13 @@ impl Constraints {
self.limit_disclosure.as_ref()
}

/// Returns if the fields are selective disclosable
pub fn selective_disclosable(&self) -> bool {
self.fields
.iter()
.any(|field| field.is_selective_disclosable(self.limit_disclosure()))
}

/// Returns if the constraints fields contain non-optional
/// fields that must be satisfied.
pub fn is_required(&self) -> bool {
Expand Down Expand Up @@ -483,6 +492,17 @@ impl ConstraintsField {
!self.is_optional()
}

/// Given limit_disclosure returns wether the property is selective disclosable
fn is_selective_disclosable(
&self,
limit_disclosure: Option<&ConstraintsLimitDisclosure>,
) -> bool {
match limit_disclosure {
Some(_) => self.is_optional(),
None => false,
}
}

/// Field query.
///
/// See: <https://identity.foundation/presentation-exchange/spec/v2.0.0/#input-evaluation>
Expand Down Expand Up @@ -520,6 +540,7 @@ impl ConstraintsField {
pub fn requested_fields<'a>(
&self,
input_descriptor_id: String,
limit_disclosure: Option<&ConstraintsLimitDisclosure>,
value: &'a serde_json::Value,
) -> RequestedField<'a> {
let raw_fields = self
Expand All @@ -533,6 +554,7 @@ impl ConstraintsField {
name: self.name.clone(),
required: self.is_required(),
retained: self.intent_to_retain,
selective_disclosable: self.is_selective_disclosable(limit_disclosure),
purpose: self.purpose.clone(),
input_descriptor_id,
raw_fields,
Expand Down Expand Up @@ -659,6 +681,7 @@ pub struct RequestedField<'a> {
pub name: Option<String>,
pub required: bool,
pub retained: bool,
pub selective_disclosable: bool,
pub purpose: Option<String>,
// the `raw_field` represents the actual field(s)
// being selected by the input descriptor JSON path
Expand Down

0 comments on commit 7485ce0

Please sign in to comment.