Skip to content

Commit

Permalink
Updated parsing of Presentation Definition, Presentation Submission
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaioannou committed Apr 4, 2024
1 parent 99b97d0 commit 19ea97f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ file.

```groovy
dependencies {
implementation "eu.europa.ec.eudi:eudi-lib-android-wallet-core:0.5.2-SNAPSHOT"
implementation "eu.europa.ec.eudi:eudi-lib-android-wallet-core:0.5.3-SNAPSHOT"
implementation "androidx.biometric:biometric-ktx:1.2.0-alpha05"
}
```
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ systemProp.sonar.gradle.skipCompile=true
systemProp.sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/testDebugUnitTestCoverage/testDebugUnitTestCoverage.xml,build/reports/jacoco/testReleaseUnitTestCoverage/testReleaseUnitTestCoverage.xml
systemProp.sonar.projectName=eudi-lib-android-wallet-core

VERSION_NAME=0.5.2-SNAPSHOT
VERSION_NAME=0.5.3-SNAPSHOT

SONATYPE_HOST=S01
SONATYPE_AUTOMATIC_RELEASE=false
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ espresso-core = "3.5.1"
eudi-document-manager = "0.2.3-SNAPSHOT"
eudi-iso18013-data-transfer = "0.2.0-SNAPSHOT"
eudi-lib-jvm-openid4vci-kt = "0.1.2-SNAPSHOT"
eudi-lib-jvm-siop-openid4vp-kt = "0.3.1-SNAPSHOT"
eudi-lib-jvm-siop-openid4vp-kt = "0.3.3"
gradle-plugin = "7.4.0"
identity-credential = "20231002"
identity-credential-android = "20231002"
Expand Down
2 changes: 1 addition & 1 deletion licenses.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# EUDI Wallet Core library for Android
## Dependency License Report
_2024-03-04 19:48:37 EET_
_2024-04-04 16:00:54 EEST_
## Apache License, Version 2.0

**1** **Group:** `androidx.appcompat` **Name:** `appcompat` **Version:** `1.6.1`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,32 +100,37 @@ class OpenId4VpCBORResponseGeneratorImpl(private val documentsResolver: Document
* @return [RequestedDocumentData]
*/
override fun parseRequest(request: OpenId4VpRequest): RequestedDocumentData {
val inputDescriptor = request.presentationDefinition.inputDescriptors.first()
val fieldConstraints = inputDescriptor.constraints.fields()
return createRequestedDocumentData(
request.presentationDefinition.inputDescriptors
.mapNotNull { inputDescriptor ->
inputDescriptor.format?.jsonObject()
?.takeIf { it.containsKey("mso_mdoc") } // ignore formats other than "mso_mdoc"
?.run {
inputDescriptor.id.value.trim() to inputDescriptor.constraints.fields()
.mapNotNull { fieldConstraint ->
// path shall contain a requested data element as: $['<namespace>']['<data element identifier>']
val path = fieldConstraint.paths.first().value
Regex("\\\$\\['(.*?)']\\['(.*?)']").find(path)
?.let { matchResult ->
val (namespace, elementIdentifier) = matchResult.destructured
if (namespace.isNotBlank() && elementIdentifier.isNotBlank()) {
namespace to elementIdentifier
} else {
null
}
}

// find doc type
val docType = fieldConstraints.find { fieldConstraint ->
fieldConstraint.paths.first().value == "$.mdoc.doctype"
}?.filter?.get("const").toString().replace("\"", "")

// find namespace
val namespace = fieldConstraints.find { fieldConstraint ->
fieldConstraint.paths.first().value == "$.mdoc.namespace"
}?.filter?.get("const").toString().replace("\"", "")

// find requested fields
val requestedFields =
fieldConstraints.filter { fieldConstraint ->
fieldConstraint.intentToRetain != null
}.map { fieldConstraint ->
fieldConstraint.paths.first().value.replace(
"$.mdoc.",
""
).replace("\"", "")
}

return parseRequest(
mapOf(docType to mapOf(namespace to requestedFields)),
}.groupBy({ it.first }, { it.second })
.mapValues { (_, values) -> values.toList() }
.toMap()
} ?: run {
Log.w(
TAG,
"Input descriptor with id ${inputDescriptor.id} and format ${inputDescriptor.format} is skipped. Format is not mso_mdoc."
)
null
}
}.toMap(),
openid4VpX509CertificateTrust.getReaderAuth()
)
}
Expand Down Expand Up @@ -201,7 +206,7 @@ class OpenId4VpCBORResponseGeneratorImpl(private val documentsResolver: Document
return AddDocumentToResponse.Success
}

private fun parseRequest(
private fun createRequestedDocumentData(
requestedFields: Map<String, Map<String, List<String>>>,
readerAuth: ReaderAuth?
): RequestedDocumentData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import eu.europa.ec.eudi.openid4vp.SiopOpenId4VPConfig
import eu.europa.ec.eudi.openid4vp.SiopOpenId4Vp
import eu.europa.ec.eudi.openid4vp.SupportedClientIdScheme
import eu.europa.ec.eudi.openid4vp.asException
import eu.europa.ec.eudi.prex.ClaimFormat
import eu.europa.ec.eudi.prex.DescriptorMap
import eu.europa.ec.eudi.prex.Id
import eu.europa.ec.eudi.prex.JsonPath
Expand All @@ -50,6 +49,7 @@ import java.net.URI
import java.net.URLDecoder
import java.nio.charset.StandardCharsets
import java.util.Base64
import java.util.UUID
import java.util.concurrent.Executor

/**
Expand Down Expand Up @@ -261,25 +261,26 @@ class OpenId4vpManager(
resolvedRequestObject?.let { resolvedRequestObject ->
when (resolvedRequestObject) {
is ResolvedRequestObject.OpenId4VPAuthorization -> {
val presentationDefinition =
(resolvedRequestObject).presentationDefinition
val inputDescriptor =
presentationDefinition.inputDescriptors.first()

val vpToken =
Base64.getUrlEncoder().withoutPadding().encodeToString(deviceResponse)
Log.d(TAG, "VpToken: $vpToken")

val presentationDefinition =
(resolvedRequestObject).presentationDefinition
val consensus = Consensus.PositiveConsensus.VPTokenConsensus(
vpToken,
presentationSubmission = PresentationSubmission(
id = Id("pid-res"), // TODO id value ?
id = Id(UUID.randomUUID().toString()),
definitionId = presentationDefinition.id,
listOf(
DescriptorMap(
id = inputDescriptor.id,
format = ClaimFormat.MsoMdoc,
path = JsonPath.jsonPath("$")!! // TODO path ?
)
)
presentationDefinition.inputDescriptors.map {
inputDescriptor ->
DescriptorMap(
inputDescriptor.id,
"mso_mdoc",
path = JsonPath.jsonPath("$")!!
)
}
)
)
runCatching { siopOpenId4Vp.dispatch(resolvedRequestObject, consensus) }.onSuccess { dispatchOutcome ->
Expand Down

0 comments on commit 19ea97f

Please sign in to comment.