Skip to content

Commit

Permalink
Fix #27: Updated sample for EdDSA
Browse files Browse the repository at this point in the history
  • Loading branch information
josmilan committed May 29, 2024
1 parent fd7400c commit 99ac76d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
16 changes: 8 additions & 8 deletions app/src/main/java/com/ewc/eudiwalletoidcandroid/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ class MainActivity : AppCompatActivity() {
}

private fun initClicks() {
binding.btnCreateDID.setOnClickListener {
viewModel?.subJwk = DIDService().createJWK()
viewModel?.did = DIDService().createDID(viewModel?.subJwk!!)

viewModel?.displayText?.value = "Sub JWK : \n ${Gson().toJson(viewModel?.subJwk)}\n\n"
viewModel?.displayText?.value =
"${viewModel?.displayText?.value}Did : ${viewModel?.did}\n\n"
}
// binding.btnCreateDID.setOnClickListener {
// viewModel?.subJwk = DIDService().createJWK()
// viewModel?.did = DIDService().createDID(viewModel?.subJwk!!)
//
// viewModel?.displayText?.value = "Sub JWK : \n ${Gson().toJson(viewModel?.subJwk)}\n\n"
// viewModel?.displayText?.value =
// "${viewModel?.displayText?.value}Did : ${viewModel?.did}\n\n"
// }

binding.addCredential.setOnClickListener {
if (ContextCompat.checkSelfPermission(
Expand Down
42 changes: 33 additions & 9 deletions app/src/main/java/com/ewc/eudiwalletoidcandroid/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.ewc.eudiwalletoidcandroid
import android.net.Uri
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.ewc.eudi_wallet_oidc_android.CryptographicAlgorithms
import com.ewc.eudi_wallet_oidc_android.models.AuthorisationServerWellKnownConfiguration
import com.ewc.eudi_wallet_oidc_android.models.CredentialOffer
import com.ewc.eudi_wallet_oidc_android.models.IssuerWellKnownConfiguration
Expand All @@ -17,15 +18,19 @@ import com.ewc.eudi_wallet_oidc_android.services.sdjwt.SDJWTService
import com.ewc.eudi_wallet_oidc_android.services.verification.VerificationService
import com.google.gson.Gson
import com.nimbusds.jose.jwk.ECKey
import com.nimbusds.jose.jwk.JWK
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.ArrayList
import java.util.Timer
import java.util.TimerTask

class MainViewModel : ViewModel() {

private var format: String? = null
private var types: ArrayList<String> = arrayListOf()
var isLoading = MutableLiveData<Boolean>(false)

var isPreAuthorised = MutableLiveData<Boolean>(false)
Expand All @@ -40,7 +45,7 @@ class MainViewModel : ViewModel() {
private var issuerConfig: IssuerWellKnownConfiguration? = null
private var offerCredential: CredentialOffer? = null
lateinit var did: String
lateinit var subJwk: ECKey
lateinit var subJwk: JWK

init {
isLoading.value = false
Expand All @@ -58,15 +63,36 @@ class MainViewModel : ViewModel() {

authConfig =
DiscoveryService().getAuthConfig(
"${issuerConfig?.authorizationServer ?: issuerConfig?.issuer}/.well-known/openid-configuration"
"${issuerConfig?.authorizationServer
?: issuerConfig?.authorizationServers?.get(0
)?: issuerConfig?.issuer}/.well-known/openid-configuration"
)
types = IssueService().getTypesFromCredentialOffer(offerCredential)
format =
IssueService().getFormatFromIssuerConfig(issuerConfig, types.lastOrNull() ?: "")

val cryptoSupported = IssueService().getCryptoFromIssuerConfig(
issuerConfig,
types.lastOrNull() ?: "ES256"
)

subJwk = DIDService().createJWK(
null,
cryptoSupported?.lastOrNull() ?: CryptographicAlgorithms.ES256
)
did = DIDService().createDID(
subJwk,
cryptoSupported?.lastOrNull() ?: CryptographicAlgorithms.ES256
)
// Generating code verifier
codeVerifier = CodeVerifierService().generateCodeVerifier()

withContext(Dispatchers.Main) {
displayText.value = "Sub JWK : \n ${Gson().toJson(subJwk)}\n\n"
displayText.value =
"${displayText.value}Did : $did\n\n"
displayText.value =
"${displayText?.value}Issuer Config : \n${Gson().toJson(issuerConfig)}\n\n"
"${displayText.value}Issuer Config : \n${Gson().toJson(issuerConfig)}\n\n"
displayText.value =
"${displayText.value}Auth Config : \n${Gson().toJson(authConfig)}\n\n"
displayText.value =
Expand Down Expand Up @@ -95,7 +121,7 @@ class MainViewModel : ViewModel() {
// Process Authorisation request
val authResponse = IssueService().processAuthorisationRequest(
did,
subJwk,
subJwk as ECKey,
offerCredential,
codeVerifier,
authConfig?.authorizationEndpoint
Expand All @@ -119,17 +145,15 @@ class MainViewModel : ViewModel() {
}

private suspend fun getCredential() {
val types = IssueService().getTypesFromCredentialOffer(offerCredential)
val format = IssueService().getFormatFromIssuerConfig(issuerConfig, types.lastOrNull() ?:"")

val credential = IssueService().processCredentialRequest(
did,
subJwk,
issuerConfig?.credentialIssuer,
tokenResponse?.tokenResponse?.cNonce,
offerCredential,
issuerConfig?.credentialEndpoint,
issuerConfig,
tokenResponse?.tokenResponse?.accessToken,
format?:"jwt_vc"
format ?: "jwt_vc"
)

withContext(Dispatchers.Main) {
Expand Down

0 comments on commit 99ac76d

Please sign in to comment.