Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Append disclosures for SD-JWT presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
waltkb committed Nov 22, 2023
1 parent 46e2811 commit cf7cfd6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/main/kotlin/id/walt/service/SSIKit2WalletService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class SSIKit2WalletService(accountId: UUID, walletId: UUID) : WalletService(acco
/**
* @return redirect uri
*/
override suspend fun usePresentationRequest(request: String, did: String, selectedCredentialIds: List<String>, disclosures: Map<String, List<String>>): Result<String?> {
override suspend fun usePresentationRequest(request: String, did: String, selectedCredentialIds: List<String>, disclosures: Map<String, List<String>>?): Result<String?> {
val credentialWallet = getCredentialWallet(did)

val authReq = AuthorizationRequest.fromHttpQueryString(Url(request).encodedQuery)
Expand All @@ -192,7 +192,9 @@ class SSIKit2WalletService(accountId: UUID, walletId: UUID) : WalletService(acco
println("USING PRESENTATION REQUEST, SELECTED CREDENTIALS: $selectedCredentialIds")

SessionAttributes.HACK_outsideMappedSelectedCredentialsPerSession[authReq.state + authReq.presentationDefinition] = selectedCredentialIds
SessionAttributes.HACK_outsideMappedSelectedDisclosuresPerSession[authReq.state + authReq.presentationDefinition] = disclosures
if (disclosures != null) {
SessionAttributes.HACK_outsideMappedSelectedDisclosuresPerSession[authReq.state + authReq.presentationDefinition] = disclosures
}

val presentationSession = credentialWallet.initializeAuthorization(authReq, 60.seconds, selectedCredentialIds.toSet())
println("Initialized authorization (VPPresentationSession): $presentationSession")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/service/WalletKitWalletService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class WalletKitWalletService(accountId: UUID, walletId: UUID) : WalletService(ac
val state: String?
)

override suspend fun usePresentationRequest(request: String, did: String, selectedCredentialIds: List<String>, disclosures: Map<String, List<String>>): Result<String?> {
override suspend fun usePresentationRequest(request: String, did: String, selectedCredentialIds: List<String>, disclosures: Map<String, List<String>>?): Result<String?> {
val decoded = URLDecoder.decode(request, Charset.defaultCharset())
val queryParams = getQueryParams(decoded)
val redirectUri = queryParams["redirect_uri"]?.first()
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/service/WalletService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class WalletService(val accountId: UUID, val walletId: UUID) {
abstract fun matchCredentialsByPresentationDefinition(presentationDefinition: PresentationDefinition): List<WalletCredential>

// SIOP
abstract suspend fun usePresentationRequest(request: String, did: String, selectedCredentialIds: List<String>, disclosures: Map<String, List<String>>): Result<String?>
abstract suspend fun usePresentationRequest(request: String, did: String, selectedCredentialIds: List<String>, disclosures: Map<String, List<String>>?): Result<String?>
abstract suspend fun resolvePresentationRequest(request: String): String
abstract suspend fun useOfferRequest(offer: String, did: String)

Expand Down
17 changes: 15 additions & 2 deletions src/main/kotlin/id/walt/service/oidc4vc/TestCredentialWallet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,25 @@ class TestCredentialWallet(
val selectedCredentials =
HACK_outsideMappedSelectedCredentialsPerSession[session.authorizationRequest!!.state + session.authorizationRequest.presentationDefinition]!!
val selectedDisclosures =
HACK_outsideMappedSelectedDisclosuresPerSession[session.authorizationRequest!!.state + session.authorizationRequest.presentationDefinition]!!
HACK_outsideMappedSelectedDisclosuresPerSession[session.authorizationRequest!!.state + session.authorizationRequest.presentationDefinition]

println("Selected credentials: $selectedCredentials")
val matchedCredentials = walletService.getCredentialsByIds(selectedCredentials)
println("Matched credentials: $matchedCredentials")

println("Using disclosures: $selectedDisclosures")

val credentialsPresented = matchedCredentials.map {
if (selectedDisclosures?.containsKey(it.id) == true) {
it.document + "~${selectedDisclosures[it.id]!!.joinToString("~") }"
} else {
it.document
}
}

println("Credentials presented: $credentialsPresented")


val vp = Json.encodeToString(
mapOf(
"sub" to this.did,
Expand All @@ -130,7 +143,7 @@ class TestCredentialWallet(
"type" to listOf("VerifiablePresentation"),
"id" to "urn:uuid:${UUID.generateUUID().toString().lowercase()}",
"holder" to this.did,
"verifiableCredential" to matchedCredentials.map { it.document }
"verifiableCredential" to credentialsPresented
)
).toJsonElement()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ fun Application.exchange() = walletRoute {
?: throw IllegalArgumentException("No DID to use supplied")
val selectedCredentialIds = req.selectedCredentials
// TODO -> ?: auto matching
val disclosures = req.disclosures


val result = wallet.usePresentationRequest(request, did, selectedCredentialIds, emptyMap()) // TODO add disclosures here
val result = wallet.usePresentationRequest(request, did, selectedCredentialIds, disclosures) // TODO add disclosures here

if (result.isSuccess) {
wallet.addOperationHistory(
Expand Down

0 comments on commit cf7cfd6

Please sign in to comment.