Skip to content

Commit

Permalink
Fix: Update match credentials response and added func to normalise SD…
Browse files Browse the repository at this point in the history
…-JWT to plain JSON

Signed-off-by: George J Padayatti <george.padayatti@igrant.io>
  • Loading branch information
georgepadayatti committed Mar 11, 2024
1 parent e54d4fd commit 1bdf64e
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 14 deletions.
43 changes: 35 additions & 8 deletions app/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.decentraliseddataexchange.presentationexchangesdk


fun main() {
val pex = PresentationExchange()
val inputDescriptor = """
Expand All @@ -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"
}
}
]
}
Expand All @@ -26,14 +54,13 @@ fun main() {
{
"type": [
"Passport"
]
}
""".trimIndent(),
"""
{
"type": [
"Passport"
]
],
"name": "John",
"dob": "14-Mar-70",
"address": {
"city": "EKM",
"state": "Kerala"
}
}
""".trimIndent()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,7 +20,17 @@ interface IPresentationExchange {
* descriptor
* @return
*/
fun matchCredentials(inputDescriptorJson: String, credentials: List<String>): List<DescriptorMap>
fun matchCredentials(inputDescriptorJson: String, credentials: List<String>): MatchCredentialResponse


/**
* Normalise combine format for issuance to json string
*
* @param claimJson
* @param disclosureBase64s
* @return
*/
fun normaliseCombineFormatForIssuanceToJsonString(claimJson: String, disclosureBase64s: List<String>): String
}


Expand All @@ -46,9 +57,8 @@ class PresentationExchange() : IPresentationExchange {
* descriptor
* @return
*/
override fun matchCredentials(inputDescriptorJson: String, credentials: List<String>): List<DescriptorMap> {
// 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<String>): 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<DescriptorMap>()
Expand All @@ -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<List<String>>(credential, path)
val matched = JsonPath.read<Any>(credential, path)
val matchedJson = gson.toJson(matched)
// Validate JSON schema
this.validateJsonSchema(matchedJson, field.filter.toJsonSchemaString())
Expand All @@ -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>
): String {
TODO("Not yet implemented")
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SdJwtField>,
val vc: Any
)

// { "matchedCredentials": [ { "fields": [ { "index": 0, "jsonPathMatch": "[]" } ], "vc": "Passport" } ]

data class MatchCredentialResponse(
val descriptorMap: List<DescriptorMap>,
val matchedCredentials: List<MatchedCredentials>
)

0 comments on commit 1bdf64e

Please sign in to comment.