diff --git a/lib/src/main/kotlin/com/github/decentraliseddataexchange/presentationexchangesdk/PresentationExchange.kt b/lib/src/main/kotlin/com/github/decentraliseddataexchange/presentationexchangesdk/PresentationExchange.kt index 5e9134f..9b0424f 100644 --- a/lib/src/main/kotlin/com/github/decentraliseddataexchange/presentationexchangesdk/PresentationExchange.kt +++ b/lib/src/main/kotlin/com/github/decentraliseddataexchange/presentationexchangesdk/PresentationExchange.kt @@ -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 } } diff --git a/lib/src/test/kotlin/com/github/decentraliseddataexchange/presentationexchangesdk/PresentationExchangeTest.kt b/lib/src/test/kotlin/com/github/decentraliseddataexchange/presentationexchangesdk/PresentationExchangeTest.kt index 5b92c0e..6b6bb92 100644 --- a/lib/src/test/kotlin/com/github/decentraliseddataexchange/presentationexchangesdk/PresentationExchangeTest.kt +++ b/lib/src/test/kotlin/com/github/decentraliseddataexchange/presentationexchangesdk/PresentationExchangeTest.kt @@ -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 = 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 = 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 = pex.matchCredentials(inputDescriptor, credentialsList) + assertEquals(0, matches.size) + } } \ No newline at end of file