Skip to content

Commit

Permalink
Add vct Field to OpenID4VP flows
Browse files Browse the repository at this point in the history
Added vct field as const to the verifier, and updated wallet to send documents
which match the defined vct if defined as a const.

Tested manually with verifier changes + with verifiers without defined vct.

Signed-off-by: Suzanna Jiwani <[email protected]>
  • Loading branch information
suzannajiwani committed Nov 12, 2024
1 parent 4c31c5b commit 71d6739
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class DocumentType private constructor(
}
list
}
VcRequest(claims)
VcRequest(vcBuilder!!.type, claims)
}
sampleRequests.add(DocumentWellKnownRequest(id, displayName, mdocRequest, vcRequest))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ package com.android.identity.documenttype
* @param claimsToRequest the claims to request.
*/
data class VcRequest(
val vct: String,
val claimsToRequest: List<DocumentAttribute>
)
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,14 @@ private fun sdjwtCalcPresentationDefinition(
format.put("jwt_vc", algContainer)

val fields = JSONArray()
val vctArray = JSONArray()
vctArray.add("\$.vct")
val vctFilter = JSONObject()
vctFilter.put("const", request.vcRequest!!.vct)
val vctField = JSONObject()
vctField.put("path", vctArray)
vctField.put("filter", vctFilter)
fields.add(vctField)
for (claim in request.vcRequest!!.claimsToRequest) {
var array = JSONArray()
array.add("\$.${claim.identifier}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,12 @@ class OpenID4VPPresentationActivity : FragmentActivity() {
val documentConfiguration = document.documentConfiguration
return when (credentialFormat) {
CredentialFormat.MDOC_MSO -> documentConfiguration.mdocConfiguration?.docType == docType
CredentialFormat.SD_JWT_VC -> documentConfiguration.sdJwtVcDocumentConfiguration != null
CredentialFormat.SD_JWT_VC ->
if (docType == "") {
documentConfiguration.sdJwtVcDocumentConfiguration != null
} else {
documentConfiguration.sdJwtVcDocumentConfiguration?.vct == docType
}
}
}

Expand Down Expand Up @@ -479,7 +484,24 @@ class OpenID4VPPresentationActivity : FragmentActivity() {
// https://identity.foundation/presentation-exchange/spec/v2.0.0/#input-descriptor
//
val inputDescriptorObj = inputDescriptors[0].jsonObject
val docType = inputDescriptorObj["id"]!!.toString().run { substring(1, this.length - 1) }
val docType = if (credentialFormat == CredentialFormat.MDOC_MSO) {
inputDescriptorObj["id"]!!.toString().run { substring(1, this.length - 1) }
} else {
try {
var vct = ""
val constraints = inputDescriptorObj["constraints"]!!.jsonObject
for (field in constraints["fields"]!!.jsonArray) {
if (field.jsonObject["path"]!!.jsonArray[0].toString() == "\"\$.vct\"") {
val vctField = field.jsonObject
val filter = vctField["filter"]!!.jsonObject
vct = filter["const"]!!.toString().run { substring(1, this.length - 1) }
}
}
vct
} catch (e: Exception) {
""
}
}

val documentRequest = formatAsDocumentRequest(inputDescriptorObj)
val document = firstMatchingDocument(credentialFormat, docType)
Expand Down

0 comments on commit 71d6739

Please sign in to comment.