Skip to content

Commit

Permalink
OID4VP UI (#46)
Browse files Browse the repository at this point in the history
This implements the UI for the OID4VP flow and adds an error page
  • Loading branch information
Juliano1612 authored Oct 22, 2024
1 parent 798a352 commit 624a1bb
Show file tree
Hide file tree
Showing 15 changed files with 722 additions and 115 deletions.
5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion MobileSdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ android {
}

dependencies {
api("com.spruceid.mobile.sdk.rs:mobilesdkrs:0.0.37-SNAPSHOT")
api("com.spruceid.mobile.sdk.rs:mobilesdkrs:0.2.1")
//noinspection GradleCompatible
implementation("com.android.support:appcompat-v7:28.0.0")
/* Begin UI dependencies */
Expand Down
10 changes: 5 additions & 5 deletions MobileSdk/src/main/java/com/spruceid/mobile/sdk/Credential.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.spruceid.mobile.sdk
import com.spruceid.mobile.sdk.rs.JsonVc
import com.spruceid.mobile.sdk.rs.JwtVc
import com.spruceid.mobile.sdk.rs.Mdoc
import com.spruceid.mobile.sdk.rs.SdJwt
import com.spruceid.mobile.sdk.rs.Vcdm2SdJwt
import org.json.JSONException
import org.json.JSONObject
import org.json.JSONTokener
Expand Down Expand Up @@ -99,9 +99,9 @@ fun JsonVc.credentialClaimsFiltered(claimNames: List<String>): JSONObject {
}

/**
* Access the SD-JWT credential.
* Access the VCDM 2.0 SD-JWT credential.
*/
fun SdJwt.credentialClaims(): JSONObject {
fun Vcdm2SdJwt.credentialClaims(): JSONObject {
try {
return JSONObject(this.revealedClaimsAsJsonString())
} catch (e: Error) {
Expand All @@ -111,9 +111,9 @@ fun SdJwt.credentialClaims(): JSONObject {
}

/**
* Access the specified claims from the SD-JWT credential.
* Access the specified claims from the VCDM 2.0 SD-JWT credential.
*/
fun SdJwt.credentialClaimsFiltered(claimNames: List<String>): JSONObject {
fun Vcdm2SdJwt.credentialClaimsFiltered(claimNames: List<String>): JSONObject {
val old = this.credentialClaims()
val new = JSONObject()
for (name in claimNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.spruceid.mobile.sdk.rs.JsonVc
import com.spruceid.mobile.sdk.rs.JwtVc
import com.spruceid.mobile.sdk.rs.Mdoc
import com.spruceid.mobile.sdk.rs.ParsedCredential
import com.spruceid.mobile.sdk.rs.SdJwt
import com.spruceid.mobile.sdk.rs.Vcdm2SdJwt
import org.json.JSONObject

/**
Expand Down Expand Up @@ -48,7 +48,7 @@ class CredentialPack {
/**
* Add a SD-JWT to the CredentialPack.
*/
fun addSdJwt(sdJwt: SdJwt): List<ParsedCredential> {
fun addSdJwt(sdJwt: Vcdm2SdJwt): List<ParsedCredential> {
credentials.add(ParsedCredential.newSdJwt(sdJwt))
return credentials
}
Expand Down
202 changes: 202 additions & 0 deletions example/src/main/java/com/spruceid/mobilesdkexample/ErrorView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
package com.spruceid.mobilesdkexample

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.spruceid.mobilesdkexample.ui.theme.BorderSecondary
import com.spruceid.mobilesdkexample.ui.theme.ColorRose600
import com.spruceid.mobilesdkexample.ui.theme.ColorStone300
import com.spruceid.mobilesdkexample.ui.theme.ColorStone50
import com.spruceid.mobilesdkexample.ui.theme.ColorStone600
import com.spruceid.mobilesdkexample.ui.theme.Inter
import com.spruceid.mobilesdkexample.ui.theme.TextPrimary

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ErrorView(
errorTitle: String,
errorDetails: String,
closeButtonLabel: String = "Close",
onClose: () -> Unit
) {
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
var showSheet by remember {
mutableStateOf(false)
}

Box(
Modifier.fillMaxSize(),
) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = painterResource(id = R.drawable.error),
contentDescription = stringResource(id = R.string.error)
)
Text(
errorTitle,
fontFamily = Inter,
fontWeight = FontWeight.SemiBold,
fontSize = 26.sp,
color = ColorRose600,
textAlign = TextAlign.Center
)
Text(
"View technical details",
fontFamily = Inter,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
color = ColorStone600,
textAlign = TextAlign.Center,
textDecoration = TextDecoration.Underline,
modifier = Modifier.clickable {
showSheet = true
}
)
}

Column {
Spacer(Modifier.weight(1f))
Button(
onClick = {
onClose()
},
shape = RoundedCornerShape(6.dp),
colors = ButtonDefaults.buttonColors(
containerColor = Color.Transparent,
contentColor = TextPrimary,
),
modifier = Modifier
.fillMaxWidth()
.padding(30.dp)
.border(
width = 1.dp,
color = BorderSecondary,
shape = RoundedCornerShape(6.dp)
)
) {
Text(
text = closeButtonLabel,
fontFamily = Inter,
fontWeight = FontWeight.SemiBold,
color = TextPrimary,
)
}
}

if (showSheet) {
ModalBottomSheet(
onDismissRequest = {
showSheet = false
},
modifier =
Modifier
.fillMaxHeight(0.8f),
sheetState = sheetState,
dragHandle = null,
containerColor = Color.Transparent,
) {
Box(
Modifier
.fillMaxSize()
.background(Color.White),
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp)
.padding(top = 48.dp)
) {
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.weight(weight = 1f, fill = false)
.background(ColorStone50)
.border(1.dp, ColorStone300, RoundedCornerShape(6.dp))
.padding(16.dp)
) {
Text(
text = errorDetails,
fontSize = 16.sp,
fontFamily = FontFamily.Monospace,
color = Color.Black,
)
}

Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 12.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Button(
onClick = {
showSheet = false
},
shape = RoundedCornerShape(6.dp),
colors = ButtonDefaults.buttonColors(
containerColor = Color.Transparent,
contentColor = TextPrimary,
),
modifier = Modifier
.fillMaxWidth()
.border(
width = 1.dp,
color = BorderSecondary,
shape = RoundedCornerShape(6.dp)
)
.weight(1f)
) {
Text(
text = "Close",
fontFamily = Inter,
fontWeight = FontWeight.SemiBold,
color = TextPrimary,
)
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.spruceid.mobilesdkexample.ui.theme.CodeBorder
import com.spruceid.mobilesdkexample.ui.theme.ColorBase800
import com.spruceid.mobilesdkexample.ui.theme.Inter

@OptIn(ExperimentalAssetLoader::class)
@Composable
fun LoadingView(
loadingText: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,17 @@ val VerifierRequestBadgeFieldText = Color(0xFF0C0A09)
val VerifiedGreenValid = Color(0xFF047857)
val VerifiedRedInvalid = Color(0xFFBE123C)
val VerifierCloseButton = Color(0xFF44403C)
val ColorBase800 = Color(0xFF75675C)
// Design system colors
val ColorBase300 = Color(0xFFE6E1D6)
val ColorBase800 = Color(0xFF75675C)
val ColorBlue600 = Color(0xFF2F6AE1)
val ColorStone50 = Color(0xFFFAFAF9)
val ColorStone300 = Color(0xFFD6D3D1)
val ColorStone600 = Color(0xFF57534E)
val ColorStone950 = Color(0xFF0C0A09)
val ColorEmerald900 = Color(0xFF084C3A)
val ColorRose600 = Color(0xFFE11D48)
val TextBase = Color(0xFFFBF9F6)
val TextPrimary = Color(0xFF0C0A09)
val BgSurfacePureBlue = Color(0xFF2F6AE1)
val BorderSecondary = Color(0xFFD6D3D1)
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ val keyBase64 =
const val exampleSdJwt =
"eyJhbGciOiJFZERTQSJ9.eyJfc2RfYWxnIjoic2hhLTI1NiIsIkBjb250ZXh0IjpbImh0dHBzOi8vd3d3LnczLm9yZy9ucy9jcmVkZW50aWFscy92MiIsImh0dHBzOi8vcHVybC5pbXNnbG9iYWwub3JnL3NwZWMvb2IvdjNwMC9jb250ZXh0LTMuMC4zLmpzb24iXSwidHlwZSI6WyJWZXJpZmlhYmxlQ3JlZGVudGlhbCIsIk9wZW5CYWRnZUNyZWRlbnRpYWwiXSwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWRlbnRpdHkiOlt7Ii4uLiI6ImxoeTloT3p6eWZZVFc0WWlockc4VVZRcHhFcWN1Nk9icFdvOVBhNExFRzAifSx7Imhhc2hlZCI6ZmFsc2UsImlkZW50aXR5SGFzaCI6ImpvaG4uc21pdGhAZXhhbXBsZS5jb20iLCJpZGVudGl0eVR5cGUiOiJlbWFpbEFkZHJlc3MiLCJzYWx0Ijoibm90LXVzZWQiLCJ0eXBlIjoiSWRlbnRpdHlPYmplY3QifV0sImFjaGlldmVtZW50Ijp7Im5hbWUiOiJUZWFtIE1lbWJlcnNoaXAiLCJ0eXBlIjoiQWNoaWV2ZW1lbnQifX0sImlzc3VlciI6eyJpZCI6ImRpZDpqd2s6ZXlKaGJHY2lPaUpGVXpJMU5pSXNJbU55ZGlJNklsQXRNalUySWl3aWEzUjVJam9pUlVNaUxDSjRJam9pYldKVU0yZHFPV0Z2T0dOdVMyODBNMHByY1ZSUFVtTkpRVkk0TUZnd1RVRlhRV05HWXpadlIxSk1ZeUlzSW5raU9pSmlPRlZPWTBoRE1tRkhRM0oxU1RaMFFsUldTVlkwZFc1WldFVnlTME00WkRSblJURkdaMHMwUTA1SkluMCMwIiwibmFtZSI6Ildvcmtmb3JjZSBEZXZlbG9wbWVudCBDb3VuY2lsIiwidHlwZSI6IlByb2ZpbGUifSwiYXdhcmRlZERhdGUiOiIyMDI0LTA5LTIzVDE4OjEyOjEyKzAwMDAiLCJuYW1lIjoiVGVhbU1lbWJlcnNoaXAifQ.0zGx7-Fkio8bS4EZW_odUu3F6FG7nvRVEbGKIte2OZPXGM12XEhTJptty-1ZUgPAtP_jiyU_KTP3hPrGKKNnBg~WyJoS25GV0g0R3J5dEdVMkFLUFNJSDdRIix7Imhhc2hlZCI6ZmFsc2UsImlkZW50aXR5SGFzaCI6IkpvaG4gU21pdGgiLCJpZGVudGl0eVR5cGUiOiJuYW1lIiwic2FsdCI6Im5vdC11c2VkIiwidHlwZSI6IklkZW50aXR5T2JqZWN0In1d~"

val trustedDids = MutableList(1) { "did:web:ffe5-24-113-196-42.ngrok-free.app:oid4vp:client" }
val trustedDids = MutableList(1) { "did:web:0808-2001-1284-f50e-da31-25fe-76c-81c7-63ef.ngrok-free.app:oid4vp:client" }
Loading

0 comments on commit 624a1bb

Please sign in to comment.