Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #27: Updated sample for EdDSA #29

Merged
merged 1 commit into from
May 29, 2024
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
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