-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ryan Tate <[email protected]>
- Loading branch information
Showing
10 changed files
with
200 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 31 additions & 57 deletions
88
example/src/main/java/com/spruceid/mobilesdkexample/wallet/DispatchQRView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,55 @@ | ||
package com.spruceid.mobilesdkexample.wallet | ||
|
||
import android.os.Bundle | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
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.runtime.rememberCoroutineScope | ||
import androidx.navigation.NavController | ||
import androidx.navigation.navArgument | ||
import com.spruceid.mobilesdkexample.ScanningComponent | ||
import com.spruceid.mobilesdkexample.ScanningType | ||
import com.google.accompanist.permissions.ExperimentalPermissionsApi | ||
import com.spruceid.mobile.sdk.oid4vp.CredentialPresentation | ||
import com.spruceid.mobile.sdk.oid4vp.OID4VPHolder | ||
import com.spruceid.mobile.sdk.oid4vp.SelectCredentialsView | ||
import com.spruceid.mobile.sdk.rs.Credential | ||
import com.spruceid.mobile.sdk.rs.ParsedCredential | ||
import com.spruceid.mobile.sdk.rs.Uuid | ||
import kotlinx.coroutines.GlobalScope | ||
import com.spruceid.mobilesdkexample.navigation.Screen | ||
import com.spruceid.mobilesdkexample.viewmodels.IRawCredentialsViewModel | ||
import kotlinx.coroutines.launch | ||
import java.net.URLEncoder | ||
import java.nio.charset.StandardCharsets | ||
|
||
// The scheme for the OID4VP QR code. | ||
const val OPEN_ID4VP_SCHEME = "openid4vp://" | ||
|
||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalPermissionsApi::class) | ||
@Composable | ||
fun DispatchQRView( | ||
navController: NavController | ||
navController: NavController, | ||
) { | ||
// maintain of state of credentials that once loaded will be used | ||
// to lazy load the component view. | ||
var parsedCredentials by remember { mutableStateOf(emptyList<ParsedCredential>()) } | ||
val scope = rememberCoroutineScope() | ||
|
||
// Selected Credential ID to be used in the future. | ||
var selectedCredentialId by remember { mutableStateOf<Uuid?>(null) } | ||
fun onRead(url: String) { | ||
println("Reading URL: $url") | ||
|
||
// A function that sets the parsed credentials based on the Rust callback. | ||
fun onCredentials(credentialList: List<ParsedCredential>) { | ||
parsedCredentials = credentialList | ||
} | ||
scope.launch { | ||
|
||
// A function that returns the selectedCredentialId, called until a credential is selected. | ||
fun onSelectedCredential(): Uuid? { | ||
return selectedCredentialId | ||
} | ||
if (url.contains(OPEN_ID4VP_SCHEME)) { | ||
val encodedUrl = URLEncoder.encode( | ||
url, | ||
// url.replace(OPEN_ID4VP_SCHEME, ""), | ||
StandardCharsets.UTF_8.toString() | ||
) | ||
|
||
fun onRead(url: String) { | ||
// TODO: Should this be a different scope? | ||
GlobalScope.launch { | ||
// TODO: Need to find the key from the key manager. | ||
val keyId = "INSERT KEY ID HERE" | ||
|
||
// TODO: Change this to a VDC collection in the future. | ||
// TODO: Use the credential datastore to retrieve credentials. | ||
val credentials = emptyList<Credential>() | ||
navController.navigate("oid4vp/$encodedUrl") { | ||
launchSingleTop = true | ||
restoreState = true | ||
} | ||
} | ||
|
||
// TODO: Add an entry in utils file for trusted DIDs. | ||
val trustedDids = emptyList<String>() | ||
|
||
OID4VPHolder( | ||
keyId, | ||
credentials, | ||
trustedDids | ||
).handle_url(url, CredentialPresentation( | ||
::onCredentials, | ||
::onSelectedCredential | ||
)) | ||
} | ||
} | ||
|
||
// Return the scanning component while the credentials are being loaded (i.e. empty list). | ||
if (parsedCredentials.isEmpty()) { | ||
ScanningComponent( | ||
navController = navController, | ||
scanningType = ScanningType.QRCODE, | ||
onRead = ::onRead | ||
) | ||
} else { | ||
// Load the Credential View | ||
SelectCredentialsView(parsedCredentials, onSelectedCredential = { selectedCredential -> | ||
selectedCredentialId = selectedCredential.id() | ||
}) | ||
} | ||
ScanningComponent( | ||
navController = navController, | ||
scanningType = ScanningType.QRCODE, | ||
onRead = ::onRead | ||
) | ||
} |
Oops, something went wrong.