diff --git a/app/src/main/kotlin/Main.kt b/app/src/main/kotlin/Main.kt index f0d159c..c0f8e33 100644 --- a/app/src/main/kotlin/Main.kt +++ b/app/src/main/kotlin/Main.kt @@ -1,5 +1,6 @@ package com.github.decentraliseddataexchange.presentationexchangesdk + fun main() { val pex = PresentationExchange() val inputDescriptor = """ @@ -17,6 +18,33 @@ fun main() { "const": "Passport" } } + }, + { + "path": [ + "${'$'}.name" + ], + "filter": { + "type": "string", + "const": "John" + } + }, + { + "path": [ + "${'$'}.dob" + ], + "filter": { + "type": "string", + "const": "14-Mar-70" + } + }, + { + "path": [ + "${'$'}.address.city" + ], + "filter": { + "type": "string", + "const": "EKM" + } } ] } @@ -26,14 +54,13 @@ fun main() { { "type": [ "Passport" - ] - } - """.trimIndent(), - """ - { - "type": [ - "Passport" - ] + ], + "name": "John", + "dob": "14-Mar-70", + "address": { + "city": "EKM", + "state": "Kerala" + } } """.trimIndent() ) 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 cef19c6..a522ab2 100644 --- a/lib/src/main/kotlin/com/github/decentraliseddataexchange/presentationexchangesdk/PresentationExchange.kt +++ b/lib/src/main/kotlin/com/github/decentraliseddataexchange/presentationexchangesdk/PresentationExchange.kt @@ -2,6 +2,7 @@ package com.github.decentraliseddataexchange.presentationexchangesdk import com.github.decentraliseddataexchange.presentationexchangesdk.models.DescriptorMap import com.github.decentraliseddataexchange.presentationexchangesdk.models.InputDescriptor +import com.github.decentraliseddataexchange.presentationexchangesdk.models.MatchCredentialResponse import com.github.decentraliseddataexchange.presentationexchangesdk.models.PathNested import com.google.gson.Gson import com.jayway.jsonpath.JsonPath @@ -19,7 +20,17 @@ interface IPresentationExchange { * descriptor * @return */ - fun matchCredentials(inputDescriptorJson: String, credentials: List): List + fun matchCredentials(inputDescriptorJson: String, credentials: List): MatchCredentialResponse + + + /** + * Normalise combine format for issuance to json string + * + * @param claimJson + * @param disclosureBase64s + * @return + */ + fun normaliseCombineFormatForIssuanceToJsonString(claimJson: String, disclosureBase64s: List): String } @@ -46,9 +57,8 @@ class PresentationExchange() : IPresentationExchange { * descriptor * @return */ - override fun matchCredentials(inputDescriptorJson: String, credentials: List): List { - // TODO: The response should be blueprint to create descriptor map and SD-JWTs/JWTs in VP token - // TODO: If limited_disclosure = true (SD-JWT), then only the fields specified should be present in the presentation + override fun matchCredentials(inputDescriptorJson: String, credentials: List): MatchCredentialResponse { + // TODO: If limited_disclosure = true (SD-JWT), then only the fields specified in the constraints should be present in SD-JWT-R val inputDescriptor = this.deserialiseInputDescriptor(inputDescriptorJson) val gson = Gson() val matches = mutableListOf() @@ -62,7 +72,7 @@ class PresentationExchange() : IPresentationExchange { // TODO: If either of the paths are available proceed as multiple paths are specified as an alternative for (path in field.path) { // Validate JSON path and fetch the match - val matched = JsonPath.read>(credential, path) + val matched = JsonPath.read(credential, path) val matchedJson = gson.toJson(matched) // Validate JSON schema this.validateJsonSchema(matchedJson, field.filter.toJsonSchemaString()) @@ -84,7 +94,17 @@ class PresentationExchange() : IPresentationExchange { } // Return the list of matched results - return matches + return MatchCredentialResponse( + matchedCredentials = listOf(), + descriptorMap = matches + ) + } + + override fun normaliseCombineFormatForIssuanceToJsonString( + claimJson: String, + disclosureBase64s: List + ): String { + TODO("Not yet implemented") } /** diff --git a/lib/src/main/kotlin/com/github/decentraliseddataexchange/presentationexchangesdk/models/MatchCredentialResponse.kt b/lib/src/main/kotlin/com/github/decentraliseddataexchange/presentationexchangesdk/models/MatchCredentialResponse.kt new file mode 100644 index 0000000..bad9400 --- /dev/null +++ b/lib/src/main/kotlin/com/github/decentraliseddataexchange/presentationexchangesdk/models/MatchCredentialResponse.kt @@ -0,0 +1,19 @@ +package com.github.decentraliseddataexchange.presentationexchangesdk.models + +data class SdJwtField( + val index: Int, + val jsonPathMatched: String +) + +data class MatchedCredentials( + val sdJwtField: List, + val vc: Any +) + +// { "matchedCredentials": [ { "fields": [ { "index": 0, "jsonPathMatch": "[]" } ], "vc": "Passport" } ] + +data class MatchCredentialResponse( + val descriptorMap: List, + val matchedCredentials: List +) +