Skip to content

Commit

Permalink
Merge pull request #154 from niscy-eudiw/main
Browse files Browse the repository at this point in the history
Dynamic attestation issuance implementation
  • Loading branch information
stzouvaras authored Jul 23, 2024
2 parents 6f37903 + f870e5e commit 7daf51d
Show file tree
Hide file tree
Showing 22 changed files with 313 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import eu.europa.ec.uilogic.serializer.UiSerializableParser
import eu.europa.ec.uilogic.serializer.adapter.SerializableTypeAdapter

sealed interface PresentationMode {
data class OpenId4Vp(val uri: String) : PresentationMode
data object Ble : PresentationMode
data class OpenId4Vp(val uri: String, val initiatorRoute: String) : PresentationMode
data class Ble(val initiatorRoute: String) : PresentationMode
}

data class RequestUriConfig(
Expand All @@ -46,7 +46,10 @@ data class RequestUriConfig(

fun RequestUriConfig.toDomainConfig(): PresentationControllerConfig {
return when (mode) {
is PresentationMode.Ble -> PresentationControllerConfig.Ble
is PresentationMode.OpenId4Vp -> PresentationControllerConfig.OpenId4VP(mode.uri)
is PresentationMode.Ble -> PresentationControllerConfig.Ble(mode.initiatorRoute)
is PresentationMode.OpenId4Vp -> PresentationControllerConfig.OpenId4VP(
mode.uri,
mode.initiatorRoute
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import eu.europa.ec.uilogic.extension.resetBackStack
import eu.europa.ec.uilogic.extension.setBackStackFlowCancelled
import eu.europa.ec.uilogic.extension.setBackStackFlowSuccess
import eu.europa.ec.uilogic.navigation.CommonScreens
import eu.europa.ec.uilogic.navigation.DashboardScreens
import eu.europa.ec.uilogic.navigation.helper.handleDeepLinkAction
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
Expand Down Expand Up @@ -122,19 +122,22 @@ fun BiometricScreen(
}

is Effect.Navigation.Deeplink -> {

context.cacheDeepLink(navigationEffect.link)

if (navigationEffect.isPreAuthorization) {
navController.navigate(DashboardScreens.Dashboard.screenRoute) {
popUpTo(CommonScreens.Biometric.screenRoute) { inclusive = true }
navigationEffect.routeToPop?.let { route ->
context.cacheDeepLink(navigationEffect.link)
if (navigationEffect.isPreAuthorization) {
navController.navigate(route) {
popUpTo(CommonScreens.Biometric.screenRoute) {
inclusive = true
}
}
} else {
navController.popBackStack(
route = route,
inclusive = false
)
}
} else {
navController.popBackStack(
route = DashboardScreens.Dashboard.screenRoute,
inclusive = false
)
}
} ?: handleDeepLinkAction(navController, navigationEffect.link)

}

is Effect.Navigation.Pop -> navController.popBackStack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ sealed class Effect : ViewSideEffect {
) : Navigation()

data object LaunchBiometricsSystemScreen : Navigation()
data class Deeplink(val link: Uri, val isPreAuthorization: Boolean) : Navigation()
data class Deeplink(
val link: Uri,
val isPreAuthorization: Boolean,
val routeToPop: String? = null
) : Navigation()

data object Pop : Navigation()
data object Finish : Navigation()
}
Expand Down Expand Up @@ -272,7 +277,8 @@ class BiometricViewModel(

is NavigationType.Deeplink -> Effect.Navigation.Deeplink(
nav.link.toUri(),
viewState.value.config.isPreAuthorization
viewState.value.config.isPreAuthorization,
nav.routeToPop
)

is NavigationType.Pop -> Effect.Navigation.Pop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ class QrScanViewModel(
arguments = generateComposableArguments(
mapOf(
RequestUriConfig.serializedKeyName to uiSerializer.toBase64(
RequestUriConfig(PresentationMode.OpenId4Vp(uri = scanResult)),
RequestUriConfig(
PresentationMode.OpenId4Vp(
uri = scanResult,
initiatorRoute = DashboardScreens.Dashboard.screenRoute
)
),
RequestUriConfig.Parser
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import eu.europa.ec.uilogic.config.ConfigNavigation
import eu.europa.ec.uilogic.config.NavigationType
import eu.europa.ec.uilogic.extension.cacheDeepLink
import eu.europa.ec.uilogic.navigation.CommonScreens
import eu.europa.ec.uilogic.navigation.DashboardScreens
import eu.europa.ec.uilogic.navigation.StartupScreens
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -96,10 +95,12 @@ fun SuccessScreen(

is Effect.Navigation.DeepLink -> {
context.cacheDeepLink(navigationEffect.link)
navController.popBackStack(
route = DashboardScreens.Dashboard.screenRoute,
inclusive = false
)
navigationEffect.routeToPop?.let {
navController.popBackStack(
route = it,
inclusive = false
)
} ?: navController.popBackStack()
}

is Effect.Navigation.Pop -> navController.popBackStack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ sealed class Effect : ViewSideEffect {
data object Pop : Navigation()

data class DeepLink(
val link: Uri
val link: Uri,
val routeToPop: String?
) : Navigation()
}
}
Expand Down Expand Up @@ -108,7 +109,8 @@ class SuccessViewModel(
}

is NavigationType.Deeplink -> Effect.Navigation.DeepLink(
nav.link.toUri()
nav.link.toUri(),
nav.routeToPop
)

is NavigationType.Pop, NavigationType.Finish -> Effect.Navigation.Pop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ import org.koin.core.annotation.Scope
import org.koin.core.annotation.Scoped
import java.net.URI

sealed class PresentationControllerConfig {
data class OpenId4VP(val uri: String) : PresentationControllerConfig()
data object Ble : PresentationControllerConfig()
sealed class PresentationControllerConfig(val initiatorRoute: String) {
data class OpenId4VP(val uri: String, val initiator: String) :
PresentationControllerConfig(initiator)

data class Ble(val initiator: String) : PresentationControllerConfig(initiator)
}

sealed class TransferEventPartialState {
Expand Down Expand Up @@ -120,6 +122,14 @@ interface WalletCorePresentationController {
* */
val verifierName: String?

/**
* Who started the presentation
* */
val initiatorRoute: String

/**
* Set [PresentationControllerConfig]
* */
fun setConfig(config: PresentationControllerConfig)

/**
Expand Down Expand Up @@ -187,9 +197,16 @@ class WalletCorePresentationControllerImpl(

override var disclosedDocuments: DisclosedDocuments? = null
private set

override var verifierName: String? = null
private set

override val initiatorRoute: String
get() {
val config = requireInit { _config }
return config.initiatorRoute
}

override fun setConfig(config: PresentationControllerConfig) {
_config = config
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ package eu.europa.ec.corelogic.util

object CoreActions {
const val VCI_RESUME_ACTION = "vci.resume.eudi.action"
const val VCI_DYNAMIC_PRESENTATION = "vci.dynamic.presentation.eudi.action"
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,12 @@ class DashboardViewModel(
generateComposableArguments(
mapOf(
RequestUriConfig.serializedKeyName to uiSerializer.toBase64(
RequestUriConfig(PresentationMode.OpenId4Vp(uri.toString())),
RequestUriConfig(
PresentationMode.OpenId4Vp(
uri.toString(),
DashboardScreens.Dashboard.screenRoute
)
),
RequestUriConfig.Parser
)
)
Expand Down Expand Up @@ -366,7 +371,7 @@ class DashboardViewModel(
arguments = generateComposableArguments(
mapOf(
RequestUriConfig.serializedKeyName to uiSerializer.toBase64(
RequestUriConfig(PresentationMode.Ble),
RequestUriConfig(PresentationMode.Ble(DashboardScreens.Dashboard.screenRoute)),
RequestUriConfig.Parser
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,18 @@ fun AddDocumentScreen(
viewModel.setEvent(Event.Init(context.getPendingDeepLink()))
}

SystemBroadcastReceiver(action = CoreActions.VCI_RESUME_ACTION) {
viewModel.setEvent(Event.OnResumeIssuance)
SystemBroadcastReceiver(
actions = listOf(
CoreActions.VCI_RESUME_ACTION,
CoreActions.VCI_DYNAMIC_PRESENTATION
)
) {
when (it?.action) {
CoreActions.VCI_RESUME_ACTION -> viewModel.setEvent(Event.OnResumeIssuance)
CoreActions.VCI_DYNAMIC_PRESENTATION -> it.extras?.getString("uri")?.let { link ->
viewModel.setEvent(Event.OnDynamicPresentation(link))
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ import androidx.lifecycle.viewModelScope
import eu.europa.ec.authenticationlogic.controller.authentication.DeviceAuthenticationResult
import eu.europa.ec.commonfeature.config.IssuanceFlowUiConfig
import eu.europa.ec.commonfeature.config.OfferUiConfig
import eu.europa.ec.commonfeature.config.PresentationMode
import eu.europa.ec.commonfeature.config.QrScanFlow
import eu.europa.ec.commonfeature.config.QrScanUiConfig
import eu.europa.ec.commonfeature.config.RequestUriConfig
import eu.europa.ec.commonfeature.model.DocumentOptionItemUi
import eu.europa.ec.corelogic.controller.AddSampleDataPartialState
import eu.europa.ec.corelogic.controller.IssuanceMethod
import eu.europa.ec.corelogic.controller.IssueDocumentPartialState
import eu.europa.ec.corelogic.di.getOrCreatePresentationScope
import eu.europa.ec.corelogic.model.DocType
import eu.europa.ec.corelogic.model.DocumentIdentifier
import eu.europa.ec.issuancefeature.interactor.document.AddDocumentInteractor
Expand All @@ -45,6 +48,7 @@ import eu.europa.ec.uilogic.mvi.ViewState
import eu.europa.ec.uilogic.navigation.CommonScreens
import eu.europa.ec.uilogic.navigation.DashboardScreens
import eu.europa.ec.uilogic.navigation.IssuanceScreens
import eu.europa.ec.uilogic.navigation.PresentationScreens
import eu.europa.ec.uilogic.navigation.helper.DeepLinkType
import eu.europa.ec.uilogic.navigation.helper.generateComposableArguments
import eu.europa.ec.uilogic.navigation.helper.generateComposableNavigationLink
Expand Down Expand Up @@ -72,6 +76,7 @@ sealed class Event : ViewEvent {
data object Pop : Event()
data object OnPause : Event()
data object OnResumeIssuance : Event()
data class OnDynamicPresentation(val uri: String) : Event()
data object Finish : Event()
data object DismissError : Event()
data class IssueDocument(
Expand Down Expand Up @@ -147,6 +152,31 @@ class AddDocumentViewModel(
is Event.OnResumeIssuance -> setState {
copy(isLoading = true)
}

is Event.OnDynamicPresentation -> {
getOrCreatePresentationScope()
setEffect {
Effect.Navigation.SwitchScreen(
generateComposableNavigationLink(
PresentationScreens.PresentationRequest,
generateComposableArguments(
mapOf(
RequestUriConfig.serializedKeyName to uiSerializer.toBase64(
RequestUriConfig(
PresentationMode.OpenId4Vp(
event.uri,
IssuanceScreens.AddDocument.screenRoute
)
),
RequestUriConfig.Parser
)
)
)
),
inclusive = false
)
}
}
}
}

Expand Down Expand Up @@ -394,6 +424,15 @@ class AddDocumentViewModel(
}
}

DeepLinkType.EXTERNAL -> {
setEffect {
Effect.Navigation.OpenDeepLinkAction(
deepLinkUri = uri,
arguments = null
)
}
}

else -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import eu.europa.ec.uilogic.component.content.ContentTitle
import eu.europa.ec.uilogic.component.content.GradientEdge
import eu.europa.ec.uilogic.component.content.ScreenNavigateAction
import eu.europa.ec.uilogic.component.utils.LifecycleEffect
import eu.europa.ec.uilogic.component.utils.OneTimeLaunchedEffect
import eu.europa.ec.uilogic.component.utils.SPACING_EXTRA_LARGE
import eu.europa.ec.uilogic.component.utils.SPACING_MEDIUM
import eu.europa.ec.uilogic.component.utils.SPACING_SMALL
Expand All @@ -61,8 +60,9 @@ import eu.europa.ec.uilogic.component.wrap.WrapModalBottomSheet
import eu.europa.ec.uilogic.component.wrap.WrapPrimaryButton
import eu.europa.ec.uilogic.component.wrap.WrapSecondaryButton
import eu.europa.ec.uilogic.extension.cacheDeepLink
import eu.europa.ec.uilogic.navigation.DashboardScreens
import eu.europa.ec.uilogic.extension.getPendingDeepLink
import eu.europa.ec.uilogic.navigation.IssuanceScreens
import eu.europa.ec.uilogic.navigation.helper.handleDeepLinkAction
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
Expand Down Expand Up @@ -130,12 +130,25 @@ fun DocumentOfferScreen(
viewModel.setEvent(Event.OnPause)
}

OneTimeLaunchedEffect {
viewModel.setEvent(Event.Init)
LifecycleEffect(
lifecycleOwner = LocalLifecycleOwner.current,
lifecycleEvent = Lifecycle.Event.ON_RESUME
) {
viewModel.setEvent(Event.Init(context.getPendingDeepLink()))
}

SystemBroadcastReceiver(action = CoreActions.VCI_RESUME_ACTION) {
viewModel.setEvent(Event.OnResumeIssuance)
SystemBroadcastReceiver(
actions = listOf(
CoreActions.VCI_RESUME_ACTION,
CoreActions.VCI_DYNAMIC_PRESENTATION
)
) {
when (it?.action) {
CoreActions.VCI_RESUME_ACTION -> viewModel.setEvent(Event.OnResumeIssuance)
CoreActions.VCI_DYNAMIC_PRESENTATION -> it.extras?.getString("uri")?.let { link ->
viewModel.setEvent(Event.OnDynamicPresentation(link))
}
}
}
}

Expand Down Expand Up @@ -301,11 +314,13 @@ private fun handleNavigationEffect(
}

is Effect.Navigation.DeepLink -> {
context.cacheDeepLink(navigationEffect.link)
navController.popBackStack(
route = DashboardScreens.Dashboard.screenRoute,
inclusive = false
)
navigationEffect.routeToPop?.let {
context.cacheDeepLink(navigationEffect.link)
navController.popBackStack(
route = it,
inclusive = false
)
} ?: handleDeepLinkAction(navController, navigationEffect.link)
}

is Effect.Navigation.Pop -> navController.popBackStack()
Expand Down
Loading

0 comments on commit 7daf51d

Please sign in to comment.