Skip to content

Commit

Permalink
New display data matching openid/OpenID4VCI#421
Browse files Browse the repository at this point in the history
  • Loading branch information
QZHelen committed Dec 3, 2024
1 parent 367c68a commit b83f77e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/src/main/assets/databasenew.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions app/src/main/java/com/credman/cmwallet/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ fun String.decodeBase64UrlNoPadding(): ByteArray {
return Base64.UrlSafe.withPadding(kotlin.io.encoding.Base64.PaddingOption.ABSENT).decode(this)
}

@OptIn(ExperimentalEncodingApi::class)
fun String.decodeBase64(): ByteArray {
return Base64.decode(this)
}

fun createJWTES256(
header: JsonElement,
payload: JsonElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.credman.cmwallet.openid4vci.OpenId4VCI
import com.credman.cmwallet.openid4vci.data.AuthorizationDetailResponseOpenIdCredential
import com.credman.cmwallet.openid4vci.data.CredentialRequest
import com.credman.cmwallet.openid4vci.data.TokenRequest
import com.credman.cmwallet.openid4vci.data.imageUriToImageB64
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import org.json.JSONObject
Expand Down Expand Up @@ -121,13 +122,14 @@ class CreateCredentialViewModel : ViewModel() {
)
Log.i(TAG, "credentialResponse $credentialResponse")
val config = openId4VCI.credentialOffer.issuerMetadata.credentialConfigurationsSupported[authDetail.credentialConfigurationId]!!
val display = credentialResponse.display?.firstOrNull()
val newCredentialItem = CredentialItem(
id = Uuid.random().toHexString(),
config = config,
displayData = CredentialDisplayData(
title = "Test Cred",
subtitle = "test cred subtitle",
icon = null
title = display?.name ?:"Unknown",
subtitle = display?.description,
icon = display?.logo?.uri.imageUriToImageB64()
),
credentials = credentialResponse.credentials!!.map {
Credential(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.util.Log
import com.credman.cmwallet.data.model.CredentialItem
import com.credman.cmwallet.data.source.CredentialDatabaseDataSource
import com.credman.cmwallet.data.source.TestCredentialsDataSource
import com.credman.cmwallet.decodeBase64
import com.credman.cmwallet.decodeBase64UrlNoPadding
import com.credman.cmwallet.mdoc.MDoc
import com.credman.cmwallet.openid4vci.OpenId4VCI
Expand Down Expand Up @@ -99,7 +100,7 @@ class CredentialRepository {
val iconMap: Map<String, RegistryIcon> = items.associate {
Pair(
it.id,
RegistryIcon(it.displayData.icon?.decodeBase64UrlNoPadding() ?: ByteArray(0))
RegistryIcon(it.displayData.icon?.decodeBase64() ?: ByteArray(0))
)
}
// Write the offset to the json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.credman.cmwallet.openid4vci.data

import android.net.Uri
import android.util.Log
import com.credman.cmwallet.CmWalletApplication.Companion.TAG
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -26,5 +29,34 @@ data class Credential(
data class CredentialResponse(
@SerialName("credentials") val credentials: List<Credential>? = null,
@SerialName("transaction_id") val transactionId: String? = null,
@SerialName("notification_id") val notificationId: String? = null
)
@SerialName("notification_id") val notificationId: String? = null,
@SerialName("display") val display: List<Display>? = null,
)

@Serializable
data class Display(
@SerialName("locale") val locale: String? = null,
@SerialName("name") val name: String? = null,
@SerialName("description") val description: String? = null,
@SerialName("logo") val logo: CredentialResponseLogo? = null,
)

@Serializable
data class CredentialResponseLogo(
@SerialName("uri") val uri: String,
@SerialName("alt_text") val altText: String?,
)

fun String?.imageUriToImageB64(): String? {
val regex = "image/.*,".toRegex()
return this?.let {
val imageUri = Uri.parse(it)
if (imageUri.scheme == "data") {
val ssp = Uri.parse(it).schemeSpecificPart
return@let ssp.replace(regex, "")
} else {
Log.w(TAG, "Unrecognized uri scheme: ${imageUri.scheme}")
return@let null
}
}
}
5 changes: 2 additions & 3 deletions app/src/main/java/com/credman/cmwallet/ui/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -45,7 +44,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import com.credman.cmwallet.R
import com.credman.cmwallet.data.model.CredentialItem
import com.credman.cmwallet.decodeBase64UrlNoPadding
import com.credman.cmwallet.decodeBase64
import com.credman.cmwallet.openid4vci.data.CredentialConfigurationMDoc
import kotlin.io.encoding.ExperimentalEncodingApi

Expand Down Expand Up @@ -209,7 +208,7 @@ fun CredentialCard(
onCredentialClick: (CredentialItem) -> Unit
) {

val cardArt = credential.displayData.icon?.decodeBase64UrlNoPadding() ?: ByteArray(0)
val cardArt = credential.displayData.icon?.decodeBase64() ?: ByteArray(0)
Card(
modifier = Modifier.size(350.dp, 210.dp),
shape = CardDefaults.shape,
Expand Down

0 comments on commit b83f77e

Please sign in to comment.