Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit

Permalink
[Android][iOS] Add age over 18 verifier (#118)
Browse files Browse the repository at this point in the history
This adds `age_over_18` verification for mDLs
  • Loading branch information
Juliano1612 authored Feb 25, 2025
1 parent 751d5c1 commit 61c77d7
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const val VERIFY_DL_PATH = "verify_dl"
const val VERIFY_EA_PATH = "verify_ea"
const val VERIFY_VC_PATH = "verify_vc"
const val VERIFY_MDOC_PATH = "verify_mdoc"
const val VERIFY_MDL_OVER_18_PATH = "verify_mdl_over_18"
const val VERIFY_DELEGATED_OID4VP_PATH = "verify_delegated_oid4vp/{id}"
const val VERIFIER_SETTINGS_HOME_PATH = "verifier_settings_home"
const val VERIFIER_SETTINGS_ACTIVITY_LOG = "verifier_settings_activity_log"
Expand All @@ -24,6 +25,7 @@ sealed class Screen(val route: String) {
object VerifyEAScreen : Screen(VERIFY_EA_PATH)
object VerifyVCScreen : Screen(VERIFY_VC_PATH)
object VerifyMDocScreen : Screen(VERIFY_MDOC_PATH)
object VerifyMDlOver18Screen : Screen(VERIFY_MDL_OVER_18_PATH)
object VerifyDelegatedOid4vpScreen : Screen(VERIFY_DELEGATED_OID4VP_PATH)
object VerifierSettingsHomeScreen : Screen(VERIFIER_SETTINGS_HOME_PATH)
object VerifierSettingsActivityLogScreen : Screen(VERIFIER_SETTINGS_ACTIVITY_LOG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ fun SetupNavGraph(
verificationActivityLogsViewModel = verificationActivityLogsViewModel
)
}
composable(
route = Screen.VerifyMDlOver18Screen.route,
) {
VerifyMDocView(
navController,
verificationActivityLogsViewModel = verificationActivityLogsViewModel,
checkAgeOver18 = true
)
}
composable(
route = Screen.VerifyDelegatedOid4vpScreen.route,
) { backStackEntry ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
Expand All @@ -20,6 +21,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -64,7 +66,11 @@ fun VerifierBinarySuccessView(
Image(
painter = painterResource(id = R.drawable.valid_check),
contentDescription = stringResource(id = R.string.valid_check),
modifier = Modifier.padding(end = 12.dp)
modifier = Modifier
.padding(end = 12.dp)
.width(30.dp)
.height(30.dp),
colorFilter = ColorFilter.tint(Color.White)
)
Text(
text = "True",
Expand Down Expand Up @@ -95,7 +101,11 @@ fun VerifierBinarySuccessView(
Image(
painter = painterResource(id = R.drawable.invalid_check),
contentDescription = stringResource(id = R.string.invalid_check),
modifier = Modifier.padding(end = 12.dp)
modifier = Modifier
.padding(end = 12.dp)
.width(30.dp)
.height(30.dp),
colorFilter = ColorFilter.tint(Color.White)
)
Text(
text = "False",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ fun VerifierHomeBody(
navController.navigate(Screen.VerifyMDocScreen.route)
}
)
VerifierListItem(
title = "Mobile Driver's Licence - Over 18",
description = "Verifies an ISO formatted mobile driver's license by reading a QR code",
type = VerifierListItemTagType.SCAN_QR_CODE,
modifier = Modifier.clickable {
navController.navigate(Screen.VerifyMDlOver18Screen.route)
}
)
VerifierListItem(
title = "Verifiable Credential",
description = "Verifies a verifiable credential by reading the verifiable presentation QR code",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.util.Log
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
Expand Down Expand Up @@ -139,6 +137,13 @@ val defaultElements: Map<String, Map<String, Boolean>> =
)
)

val ageOver18Elements: Map<String, Map<String, Boolean>> =
mapOf(
"org.iso.18013.5.1" to mapOf(
"age_over_18" to false,
)
)

enum class State {
ENABLE_BLUETOOTH,
SCANNING,
Expand All @@ -147,13 +152,14 @@ enum class State {
}

@OptIn(
ExperimentalLayoutApi::class, ExperimentalMaterial3Api::class,
ExperimentalMaterial3Api::class,
ExperimentalPermissionsApi::class
)
@Composable
fun VerifyMDocView(
navController: NavController,
verificationActivityLogsViewModel: VerificationActivityLogsViewModel,
checkAgeOver18: Boolean = false
) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
Expand Down Expand Up @@ -232,11 +238,6 @@ fun VerifyMDocView(
}
}

fun elementMapToList(elements: Map<String, Map<String, Boolean>>): List<String> {
val elementList = listOf(elements.values.map { it.keys.toList() })
return elementList.flatten().flatten()
}

fun onRead(content: String) {
scanProcessState = State.TRANSMITTING
checkAndRequestBluetoothPermissions(
Expand All @@ -249,7 +250,11 @@ fun VerifyMDocView(
reader = IsoMdlReader(
bleCallback,
content,
defaultElements,
if (checkAgeOver18) {
ageOver18Elements
} else {
defaultElements
},
trustAnchorCerts,
bluetooth!!,
context
Expand Down
Binary file removed example/src/main/res/drawable-hdpi/invalid_check.png
Binary file not shown.
Binary file removed example/src/main/res/drawable-mdpi/invalid_check.png
Binary file not shown.
Binary file removed example/src/main/res/drawable-xhdpi/invalid_check.png
Binary file not shown.
Binary file removed example/src/main/res/drawable-xxhdpi/invalid_check.png
Binary file not shown.
Binary file removed example/src/main/res/drawable-xxxhdpi/invalid_check.png
Binary file not shown.
9 changes: 9 additions & 0 deletions example/src/main/res/drawable/invalid_check.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:pathData="M25.334,8.547L23.454,6.667L16,14.12L8.547,6.667L6.667,8.547L14.12,16L6.667,23.453L8.547,25.333L16,17.88L23.454,25.333L25.334,23.453L17.88,16L25.334,8.547Z"
android:fillColor="#FBF9F6"/>
</vector>

0 comments on commit 61c77d7

Please sign in to comment.