Skip to content

Commit 85f9ab6

Browse files
committed
Update the per credential response to be an array.
1 parent 3e368ae commit 85f9ab6

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

app/src/main/java/com/credman/cmwallet/getcred/GetCredentialActivity.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import com.credman.cmwallet.openid4vci.data.CredentialConfigurationMDoc
3636
import com.credman.cmwallet.openid4vci.data.CredentialConfigurationSdJwtVc
3737
import com.credman.cmwallet.openid4vci.data.CredentialConfigurationUnknownFormat
3838
import com.credman.cmwallet.openid4vp.OpenId4VP
39+
import com.credman.cmwallet.openid4vp.OpenId4VP.Companion.IDENTIFIERS_1_0
40+
import com.credman.cmwallet.openid4vp.OpenId4VP.Companion.IDENTIFIER_DRAFT_24
3941
import com.credman.cmwallet.openid4vp.OpenId4VPMatchedCredential
4042
import com.credman.cmwallet.openid4vp.OpenId4VPMatchedMDocClaims
4143
import com.credman.cmwallet.openid4vp.OpenId4VPMatchedSdJwtClaims
@@ -44,6 +46,7 @@ import com.credman.cmwallet.sdjwt.SdJwt
4446
import com.credman.cmwallet.toBase64UrlNoPadding
4547
import com.google.android.gms.identitycredentials.Credential
4648
import com.google.android.gms.identitycredentials.IntentHelper
49+
import org.json.JSONArray
4750
import org.json.JSONObject
4851

4952

@@ -57,6 +60,7 @@ fun createOpenID4VPResponse(
5760
var authenticationSubtitle: CharSequence? = null
5861
// Create the response
5962
val vpToken = JSONObject()
63+
var credentialResponse: String? = null
6064
when (selectedCredential.config) {
6165
is CredentialConfigurationSdJwtVc -> {
6266
val claims =
@@ -65,14 +69,12 @@ fun createOpenID4VPResponse(
6569
selectedCredential.credentials.first().credential,
6670
(selectedCredential.credentials.first().key as CredentialKeySoftware).privateKey
6771
)
68-
vpToken.put(
69-
matchedCredential.dcqlId,
72+
credentialResponse =
7073
sdJwtVc.present(
7174
claims,
7275
nonce = openId4VPRequest.nonce,
7376
aud = openId4VPRequest.getSdJwtKbAud(origin)
7477
)
75-
)
7678
}
7779
is CredentialConfigurationMDoc -> {
7880
val matchedClaims =
@@ -115,13 +117,20 @@ fun createOpenID4VPResponse(
115117
deviceNamespaces = deviceNamespaces
116118

117119
)
118-
val encodedDeviceResponse = deviceResponse.toBase64UrlNoPadding()
119-
vpToken.put(matchedCredential.dcqlId, encodedDeviceResponse)
120+
credentialResponse = deviceResponse.toBase64UrlNoPadding()
120121
}
121122

122123
is CredentialConfigurationUnknownFormat -> TODO()
123124
}
124125

126+
vpToken.put(
127+
matchedCredential.dcqlId,
128+
when (openId4VPRequest.protocolIdentifier) {
129+
IDENTIFIER_DRAFT_24 -> credentialResponse
130+
in IDENTIFIERS_1_0 -> JSONArray().put(credentialResponse)
131+
else -> throw UnsupportedOperationException("Invalid protocol identifier")
132+
}
133+
)
125134
// Create the openid4vp result
126135
val response = openId4VPRequest.generateResponse(vpToken)
127136
Log.d(TAG, "Returning $response")

0 commit comments

Comments
 (0)