Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ dependencies {
implementation(libs.androidx.registry.provider)
implementation(libs.androidx.credentials)
implementation(libs.androidx.credentials.play)
implementation(libs.play.services.identity.credentials)
implementation(libs.androidx.registry.provider.play.services)
implementation(libs.lifecycle.runtime.ktx)
implementation(libs.androidx.core.ktx)
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/com/credman/cmwallet/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.credman.cmwallet

import android.R.attr.data
import android.app.PendingIntent
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.widget.Toast
Expand All @@ -15,7 +12,6 @@ import androidx.activity.result.contract.ActivityResultContracts
import com.credman.cmwallet.CmWalletApplication.Companion.TAG
import com.credman.cmwallet.ui.HomeScreen
import com.credman.cmwallet.ui.theme.CMWalletTheme
import com.google.android.gms.identitycredentials.IntentHelper.BUNDLE_KEY_PROVIDER_DATA


class MainActivity : ComponentActivity() {
Expand Down
54 changes: 22 additions & 32 deletions app/src/main/java/com/credman/cmwallet/ui/HomeViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
package com.credman.cmwallet.ui

import android.content.Context
import android.os.Bundle
import android.util.Base64
import android.util.Log
import androidx.credentials.DigitalCredential
import androidx.credentials.CreateDigitalCredentialRequest
import androidx.credentials.CreateDigitalCredentialResponse
import androidx.credentials.CredentialManager
import androidx.credentials.ExperimentalDigitalCredentialApi
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.credman.cmwallet.CmWalletApplication
import com.credman.cmwallet.CmWalletApplication.Companion.TAG
import com.credman.cmwallet.MainActivity
import com.credman.cmwallet.data.model.CredentialItem
import com.credman.cmwallet.loadECPrivateKey
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.google.android.gms.identitycredentials.CreateCredentialRequest
import com.google.android.gms.identitycredentials.IdentityCredentialManager
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.json.JSONObject
import java.security.KeyFactory
import java.security.interfaces.ECPrivateKey
import java.security.spec.X509EncodedKeySpec

data class HomeScreenUiState(
val credentials: List<CredentialItem>
Expand Down Expand Up @@ -57,25 +46,26 @@ class HomeViewModel : ViewModel() {
fun testIssuance(activity: MainActivity) {
Log.i("HomeViewModel", "testIssuance")
val credOfferJson = JSONObject(CmWalletApplication.credentialRepo.openId4VCITestRequestJson)
val requestJson = JSONObject().put("protocol", "openid4vci1.0").put("data", credOfferJson.toString()).toString()
val requestJson =
JSONObject().put("protocol", "openid4vci1.0").put("data", credOfferJson.toString())
.toString()

// Note: Long term this will be wrapped by a simple structured Jetpack API that
// automatically handles the request Bundle formation and pending intent launching
IdentityCredentialManager.getClient(activity).createCredential(
CreateCredentialRequest(
type = DigitalCredential.TYPE_DIGITAL_CREDENTIAL,
credentialData = Bundle().apply { putString("androidx.credentials.BUNDLE_KEY_REQUEST_JSON", requestJson) },
candidateQueryData = Bundle.EMPTY,
origin = null,
requestJson = requestJson,
resultReceiver = null
)
).addOnSuccessListener {
Log.d(TAG, "Issuance pending intent received ${it.pendingIntent}")
assert(it.pendingIntent != null) { "PendingIntent must be non-null in this case" }
activity.launchIssuanceIntent(it.pendingIntent!!)
}.addOnFailureListener {
Log.e(TAG, "Issuance failure", it)
viewModelScope.launch {
val response = try {
CredentialManager.create(activity).createCredential(
activity,
CreateDigitalCredentialRequest(
origin = null,
requestJson = requestJson,
)
)
} catch (e: Exception) {
Log.e(TAG, "Issuance failure", e)
null
}
(response as? CreateDigitalCredentialResponse)?.let {
Log.d(TAG, "Issuance response ${it.responseJson}")
}
}

// val openId4VCI = OpenId4VCI(requestJson)
Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx
lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx" }
androidx-lifecycle-runtime-compose-android = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose-android", version.ref = "lifecycleRuntimeComposeAndroid" }
androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "roomRuntime" }
play-services-identity-credentials = {module = "com.google.android.gms:play-services-identity-credentials", version = "16.0.0-alpha06"}

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down