Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing satisfiesPresentationDefinition #143

Merged
merged 6 commits into from
Nov 29, 2023
Merged

Conversation

nitro-neal
Copy link
Contributor

Implementing satisfiesPresentationDefinition function for PEX

Validates a list of Verifiable Credentials (VCs) against a specified Presentation Definition.

This function ensures that the provided VCs meet the criteria defined in the Presentation Definition.

It first checks for the presence of Submission Requirements in the definition and throws an exception if they exist (not supported

It does this by mapping the input descriptors in the presentation definition to the corresponding VCs. If the number of mapped descriptors does not match the required count, an error is thrown.

More detailed error messages are planned for the future with a Results object that will give warnings, and better details for errors

Copy link

codecov bot commented Nov 20, 2023

Codecov Report

Merging #143 (4e33934) into main (fe761a7) will increase coverage by 1.51%.
Report is 5 commits behind head on main.
The diff coverage is 81.57%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #143      +/-   ##
==========================================
+ Coverage   75.25%   76.77%   +1.51%     
==========================================
  Files          25       27       +2     
  Lines        1568     1804     +236     
  Branches      196      239      +43     
==========================================
+ Hits         1180     1385     +205     
- Misses        283      290       +7     
- Partials      105      129      +24     
Components Coverage Δ
credentials 76.58% <81.57%> (+1.58%) ⬆️
crypto 38.07% <ø> (+0.30%) ⬆️
dids 89.49% <ø> (-1.17%) ⬇️
common 64.80% <ø> (ø)

Copy link
Contributor

@andresuribe87 andresuribe87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome stuff @nitro-neal !

Some small comments

"type": "string",
"const": "StreetCred"
}
"pattern": ".*StreetCred.*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why this change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

@nitro-neal nitro-neal Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not valid, contains is used for array
for type string its pattern

https://json-schema.org/understanding-json-schema/reference/array

This will be caught and prevented in the next PR with PD validation + test vectors

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I think this was originally expecting the value at the path to be a string array, which is why contains + type: string was used.

 "$.vc.type[*]",
 "$.type[*]"

If the value at these paths is a single string and not a string array, then yeah we need pattern.

Comment on lines +58 to +62
throw PresentationExchangeError(
"Missing input descriptors: The presentation definition requires " +
"${presentationDefinition.inputDescriptors.size} descriptors, but only " +
"${inputDescriptorToVcMap.size} were found. Check and provide the missing descriptors."
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be incredibly useful if the library would tell the user what input descriptors were missing. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're addressing later, then disregard this comment!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup addressing in the next PR

@mistermoe
Copy link
Member

@nitro-neal are there any nuances specifically with respect what is/isn't supported for filter that we should document?

@mistermoe
Copy link
Member

mistermoe commented Nov 20, 2023

one of my gripes with PEX v2 is the conflation of path and filter. e.g.

{
  "path": [
    "$.type[*]"
  ],
  "filter": {
    "type": "string",
    "pattern": "^StreetCredential$"
  }
}

vs.

{
  "path": [
    "$.type"
  ],
  "filter": {
    "type": "array",
    "contains": {
      "type": "string",
      "const": "StreetCredential"
    }
  }
}

the 1st field constraint makes it such that filter has to be applied to each element in the array whereas the 2nd field constraint leans on json schema entirely (preferred)

have we implemented support for both or just one of the two? if the latter, which one do we support?

@nitro-neal
Copy link
Contributor Author

nitro-neal commented Nov 20, 2023

@mistermoe

-with a small change- It now has support for both cases

I added a unit test to make sure its functioning as intended

Works for both

"type": "string",
"const": "StreetCred"
}
"pattern": ".*StreetCred.*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I think this was originally expecting the value at the path to be a string array, which is why contains + type: string was used.

 "$.vc.type[*]",
 "$.type[*]"

If the value at these paths is a single string and not a string array, then yeah we need pattern.

vcJwtList: Iterable<String>,
presentationDefinition: PresentationDefinitionV2
): Map<InputDescriptorV2, List<String>> {
return presentationDefinition.inputDescriptors.associateWith { inputDescriptor ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have not used associateWith before, cool!

@nitro-neal nitro-neal merged commit 6174a15 into main Nov 29, 2023
6 checks passed
@nitro-neal nitro-neal deleted the pex-satisfy-pd branch November 29, 2023 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants