From 46e28114307db583a49106ff043a94d7406540bf Mon Sep 17 00:00:00 2001 From: waltkb <68587968+waltkb@users.noreply.github.com> Date: Wed, 22 Nov 2023 17:34:27 +0100 Subject: [PATCH] Correctly present basic SD-JWTs --- .../id/walt/service/SSIKit2WalletService.kt | 4 +- .../service/oidc4vc/TestCredentialWallet.kt | 2 + .../web/controllers/ExchangeController.kt | 6 +- web/src/composables/disclosures.ts | 2 +- .../wallet/[wallet]/exchange/presentation.vue | 76 ++++++------------- 5 files changed, 35 insertions(+), 55 deletions(-) diff --git a/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt b/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt index 78b0b24..e2f4887 100644 --- a/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt +++ b/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt @@ -391,10 +391,12 @@ class SSIKit2WalletService(accountId: UUID, walletId: UUID) : WalletService(acco val disclosuresString = disclosures.joinToString("~") + val credentialWithoutDisclosures = credential.substringBefore("~") + WalletCredential( wallet = walletId, id = credentialId, - document = credential, + document = credentialWithoutDisclosures, disclosures = disclosuresString, addedOn = Clock.System.now() ) diff --git a/src/main/kotlin/id/walt/service/oidc4vc/TestCredentialWallet.kt b/src/main/kotlin/id/walt/service/oidc4vc/TestCredentialWallet.kt index 1f4ed8a..1a4bb84 100644 --- a/src/main/kotlin/id/walt/service/oidc4vc/TestCredentialWallet.kt +++ b/src/main/kotlin/id/walt/service/oidc4vc/TestCredentialWallet.kt @@ -113,7 +113,9 @@ class TestCredentialWallet( val selectedDisclosures = HACK_outsideMappedSelectedDisclosuresPerSession[session.authorizationRequest!!.state + session.authorizationRequest.presentationDefinition]!! + println("Selected credentials: $selectedCredentials") val matchedCredentials = walletService.getCredentialsByIds(selectedCredentials) + println("Matched credentials: $matchedCredentials") val vp = Json.encodeToString( mapOf( diff --git a/src/main/kotlin/id/walt/web/controllers/ExchangeController.kt b/src/main/kotlin/id/walt/web/controllers/ExchangeController.kt index 715bd22..c0ec817 100644 --- a/src/main/kotlin/id/walt/web/controllers/ExchangeController.kt +++ b/src/main/kotlin/id/walt/web/controllers/ExchangeController.kt @@ -177,6 +177,8 @@ fun Application.exchange() = walletRoute { @Serializable data class UsePresentationRequest( val did: String? = null, - val selectedCredentials: List, - val presentationRequest: String + val presentationRequest: String, + + val selectedCredentials: List, // todo: automatically choose matching + val disclosures: Map>? = null, ) diff --git a/web/src/composables/disclosures.ts b/web/src/composables/disclosures.ts index c47fe93..4beba6f 100644 --- a/web/src/composables/disclosures.ts +++ b/web/src/composables/disclosures.ts @@ -10,5 +10,5 @@ export function parseDisclosures(disclosureString: string) { } export function encodeDisclosure(disclosure: any[]): string { - return encodeUtf8ToBase64(JSON.stringify(disclosure)) + return encodeUtf8ToBase64(JSON.stringify(disclosure)).replaceAll("=", "") } diff --git a/web/src/pages/wallet/[wallet]/exchange/presentation.vue b/web/src/pages/wallet/[wallet]/exchange/presentation.vue index aa14dac..b336eb1 100644 --- a/web/src/pages/wallet/[wallet]/exchange/presentation.vue +++ b/web/src/pages/wallet/[wallet]/exchange/presentation.vue @@ -69,17 +69,6 @@
-
+
Selectively disclosable attributes @@ -111,7 +100,7 @@
@@ -127,7 +116,6 @@
- View presentation definition JSON @@ -137,30 +125,6 @@ -
@@ -175,7 +139,7 @@ import { useTitle } from "@vueuse/core"; import VerifiableCredentialCard from "~/components/credentials/VerifiableCredentialCard.vue"; import { Disclosure, DisclosureButton, DisclosurePanel } from "@headlessui/vue"; -import { parseDisclosures } from "../../../../composables/disclosures"; +import { encodeDisclosure, parseDisclosures } from "../../../../composables/disclosures"; const currentWallet = useCurrentWallet(); @@ -231,18 +195,27 @@ const matchedCredentials = await $fetch(`/r/wallet/${currentWallet.value}/exchan }); const selection = ref({}); -const selectedCredentialIds = computed(() => { - const _selectedCredentialIds = []; +const selectedCredentialIds = computed(() => Object.entries(selection.value).filter((it) => it[1]).map((it) => it[0])) - for (let credentialId in selection.value) { - if (selection.value[credentialId] === true) - _selectedCredentialIds.push(credentialId); - } +const disclosures = ref({}); +//const encodedDisclosures = computed(() => Object.keys(disclosures.value).map((cred) => disclosures.values[cred].map((disclosure) => encodeDisclosure(disclosure)))) +const encodedDisclosures = computed(() => { + if (JSON.stringify(disclosures.value) === "{}") return null + + const m = {} + for (let credId in disclosures.value) { + if (m[credId] === undefined) { + m[credId] = [] + } - return _selectedCredentialIds; -}); + for (let disclosure of disclosures.value[credId]) { + console.log("DISC ", disclosure) + m[credId].push(encodeDisclosure(disclosure)) + } + } -const disclosures = ref({}); + return m +}) function addDisclosure(credentialId: string, disclosure: string) { if (disclosures.value[credentialId] === undefined) { @@ -258,9 +231,10 @@ function removeDisclosure(credentialId: string, disclosure: string) { async function acceptPresentation() { const req = { - //did: String, + //did: String, // todo: choose DID of shared credential + presentationRequest: request, selectedCredentials: selectedCredentialIds.value, - presentationRequest: request + disclosures: encodedDisclosures.value }; const response = await fetch(`/r/wallet/${currentWallet.value}/exchange/usePresentationRequest`, { @@ -292,7 +266,7 @@ async function acceptPresentation() { failMessage.value = error.message; console.log("Error response: " + JSON.stringify(error)); - // window.alert(error.message) + window.alert(error.errorMessage) if (error.redirectUri != null) { navigateTo(error.redirectUri as string, {