Skip to content

Commit

Permalink
Fix: #2 - Support for optional parameter inside fields
Browse files Browse the repository at this point in the history
  • Loading branch information
lijogeorgep authored Nov 5, 2024
1 parent c071133 commit 8cf6145
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ class PresentationExchange() : IPresentationExchange {

if (!fieldMatched) {
// If any one field didn't match then move to next credential
credentialMatched = false
if (field.optional != true) {
credentialMatched = false
}
break@fieldLoop
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,40 @@ class PresentationExchangeTest {

assertEquals(1, matches.size)
}

@Test
fun `find matched Credentials of field vct which is not present in credential and field optional value is true`(){
val pex = PresentationExchange()
val inputDescriptor =
"""{"id":"abd4acb1-1dcb-41ad-8596-ceb1401a69c7","format":{"vc+sd-jwt":{"alg":["ES256","ES384"]}},"constraints":{"fields":[{"path":["${'$'}.given_name"]},{"path":["${'$'}.last_name"]},{"path":["${'$'}.vct"],"filter":{"type":"string","const":"VerifiablePortableDocumentA1"},"optional":true}]},"limit_disclosure":"required"}"""
val credentialsList = listOf(
"""{"iss":"https://dss.aegean.gr/rfc-issuer","iat":1712657569263,"given_name":"John","last_name":"Doe"}""",
)
val matches: List<MatchedCredential> = pex.matchCredentials(inputDescriptor, credentialsList)
assertEquals(1, matches.size)
}

@Test
fun `find matched Credentials of field vct which is not present in credential and field optional value is false`(){
val pex = PresentationExchange()
val inputDescriptor =
"""{"id":"abd4acb1-1dcb-41ad-8596-ceb1401a69c7","format":{"vc+sd-jwt":{"alg":["ES256","ES384"]}},"constraints":{"fields":[{"path":["${'$'}.given_name"]},{"path":["${'$'}.last_name"]},{"path":["${'$'}.vct"],"filter":{"type":"string","const":"VerifiablePortableDocumentA1"},"optional":false}]},"limit_disclosure":"required"}"""
val credentialsList = listOf(
"""{"iss":"https://dss.aegean.gr/rfc-issuer","iat":1712657569263,"given_name":"John","last_name":"Doe"}""",
)
val matches: List<MatchedCredential> = pex.matchCredentials(inputDescriptor, credentialsList)
assertEquals(0, matches.size)
}

@Test
fun `find matched Credentials of field vct which is not present in credential and field optional is not present`(){
val pex = PresentationExchange()
val inputDescriptor =
"""{"id":"abd4acb1-1dcb-41ad-8596-ceb1401a69c7","format":{"vc+sd-jwt":{"alg":["ES256","ES384"]}},"constraints":{"fields":[{"path":["${'$'}.given_name"]},{"path":["${'$'}.last_name"]},{"path":["${'$'}.vct"],"filter":{"type":"string","const":"VerifiablePortableDocumentA1"}}]},"limit_disclosure":"required"}"""
val credentialsList = listOf(
"""{"iss":"https://dss.aegean.gr/rfc-issuer","iat":1712657569263,"given_name":"John","last_name":"Doe"}""",
)
val matches: List<MatchedCredential> = pex.matchCredentials(inputDescriptor, credentialsList)
assertEquals(0, matches.size)
}
}

0 comments on commit 8cf6145

Please sign in to comment.