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

Commit 46e2811

Browse files
committed
Correctly present basic SD-JWTs
1 parent be237eb commit 46e2811

File tree

5 files changed

+35
-55
lines changed

5 files changed

+35
-55
lines changed

src/main/kotlin/id/walt/service/SSIKit2WalletService.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,12 @@ class SSIKit2WalletService(accountId: UUID, walletId: UUID) : WalletService(acco
391391

392392
val disclosuresString = disclosures.joinToString("~")
393393

394+
val credentialWithoutDisclosures = credential.substringBefore("~")
395+
394396
WalletCredential(
395397
wallet = walletId,
396398
id = credentialId,
397-
document = credential,
399+
document = credentialWithoutDisclosures,
398400
disclosures = disclosuresString,
399401
addedOn = Clock.System.now()
400402
)

src/main/kotlin/id/walt/service/oidc4vc/TestCredentialWallet.kt

+2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ class TestCredentialWallet(
113113
val selectedDisclosures =
114114
HACK_outsideMappedSelectedDisclosuresPerSession[session.authorizationRequest!!.state + session.authorizationRequest.presentationDefinition]!!
115115

116+
println("Selected credentials: $selectedCredentials")
116117
val matchedCredentials = walletService.getCredentialsByIds(selectedCredentials)
118+
println("Matched credentials: $matchedCredentials")
117119

118120
val vp = Json.encodeToString(
119121
mapOf(

src/main/kotlin/id/walt/web/controllers/ExchangeController.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ fun Application.exchange() = walletRoute {
177177
@Serializable
178178
data class UsePresentationRequest(
179179
val did: String? = null,
180-
val selectedCredentials: List<String>,
181-
val presentationRequest: String
180+
val presentationRequest: String,
181+
182+
val selectedCredentials: List<String>, // todo: automatically choose matching
183+
val disclosures: Map<String, List<String>>? = null,
182184
)

web/src/composables/disclosures.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export function parseDisclosures(disclosureString: string) {
1010
}
1111

1212
export function encodeDisclosure(disclosure: any[]): string {
13-
return encodeUtf8ToBase64(JSON.stringify(disclosure))
13+
return encodeUtf8ToBase64(JSON.stringify(disclosure)).replaceAll("=", "")
1414
}

web/src/pages/wallet/[wallet]/exchange/presentation.vue

+25-51
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,6 @@
6969
<div class="min-w-0 flex-1 text-sm leading-6">
7070
<div class="font-medium select-none text-gray-900">
7171
<label :for="`credential-${credential.id}`">
72-
73-
<!-- <div class="flex items-center gap-1">-->
74-
<!-- <CredentialIcon :credentialType="credential.parsedDocument.type.at(-1)" class="h-6 w-6 flex-none rounded-full bg-gray-50"></CredentialIcon>-->
75-
<!-- {{ credential.parsedDocument.type.at(-1) }}-->
76-
<!-- </div>-->
77-
78-
<!-- <div class="min-w-0 items-center">-->
79-
<!-- <p class="text-lg font-semibold leading-6 text-gray-900">{{ credential?.parsedDocument?.name }}</p>-->
80-
<!-- <p class="ml-1 truncate text-sm leading-5 text-gray-800">{{ credential.id }}</p>-->
81-
<!-- </div>-->
82-
8372
<VerifiableCredentialCard
8473
:class="[selection[credential.id] == true ? 'shadow-xl shadow-primary-400' : 'shadow-2xl']"
8574
:credential="credential.parsedDocument"
@@ -88,7 +77,7 @@
8877

8978
</label>
9079
</div>
91-
<div v-if="credential.disclosures" class="mt-3">
80+
<div v-if="credential.disclosures && selection[credential.id]" class="mt-6 border rounded-xl p-2">
9281
<fieldset>
9382
<legend class="text-base font-semibold leading-6 text-gray-900">Selectively disclosable attributes
9483
</legend>
@@ -111,7 +100,7 @@
111100
<div class="ml-3 flex h-6 items-center">
112101
<input :id="`disclosure-${credential.id}-${disclosure[0]}`"
113102
:name="`disclosure-${disclosure[0]}`"
114-
class="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600"
103+
class="h-4 w-4 rounded border-gray-300 text-primary-400 focus:ring-primary-500"
115104
type="checkbox"
116105
@click="$event.target.checked ? addDisclosure(credential.id, disclosure) : removeDisclosure(credential.id, disclosure) "
117106
/>
@@ -127,7 +116,6 @@
127116
</div>
128117
</fieldset>
129118

130-
131119
<Disclosure>
132120
<DisclosureButton class="py-2">
133121
<ButtonsWaltButton class="bg-gray-50 text-black">View presentation definition JSON</ButtonsWaltButton>
@@ -137,30 +125,6 @@
137125
</DisclosurePanel>
138126
</Disclosure>
139127

140-
<!--
141-
<ul>
142-
<li v-for="credential of matchedCredentials">
143-
- {{ credential }}
144-
</li>
145-
</ul>
146-
147-
<div aria-label="Credential list" class="h-full overflow-y-auto shadow-xl">
148-
<div v-for="group in groupedCredentialTypes.keys()" :key="group.id" class="relative">
149-
<div class="sticky top-0 z-10 border-y border-b-gray-200 border-t-gray-100 bg-gray-50 px-3 py-1.5 text-sm font-semibold leading-6 text-gray-900">
150-
<h3>{{ group }}s:</h3>
151-
</div>
152-
<ul class="divide-y divide-gray-100" role="list">
153-
<li v-for="credential in groupedCredentialTypes.get(group)" :key="credential" class="flex gap-x-4 px-3 py-5">
154-
<CredentialIcon :credentialType="credential.name" class="h-6 w-6 flex-none rounded-full bg-gray-50"></CredentialIcon>
155-
156-
<div class="min-w-0 flex flex-row items-center">
157-
<span class="text-lg font-semibold leading-6 text-gray-900">{{ credential.id }}.</span>
158-
<span class="ml-1 truncate text-sm leading-5 text-gray-800">{{ credential.name }}</span>
159-
</div>
160-
</li>
161-
</ul>
162-
</div>
163-
</div>-->
164128
</CenterMain>
165129
</div>
166130
</template>
@@ -175,7 +139,7 @@ import { useTitle } from "@vueuse/core";
175139
import VerifiableCredentialCard from "~/components/credentials/VerifiableCredentialCard.vue";
176140
177141
import { Disclosure, DisclosureButton, DisclosurePanel } from "@headlessui/vue";
178-
import { parseDisclosures } from "../../../../composables/disclosures";
142+
import { encodeDisclosure, parseDisclosures } from "../../../../composables/disclosures";
179143
180144
181145
const currentWallet = useCurrentWallet();
@@ -231,18 +195,27 @@ const matchedCredentials = await $fetch(`/r/wallet/${currentWallet.value}/exchan
231195
});
232196
233197
const selection = ref({});
234-
const selectedCredentialIds = computed(() => {
235-
const _selectedCredentialIds = [];
198+
const selectedCredentialIds = computed(() => Object.entries(selection.value).filter((it) => it[1]).map((it) => it[0]))
236199
237-
for (let credentialId in selection.value) {
238-
if (selection.value[credentialId] === true)
239-
_selectedCredentialIds.push(credentialId);
240-
}
200+
const disclosures = ref({});
201+
//const encodedDisclosures = computed(() => Object.keys(disclosures.value).map((cred) => disclosures.values[cred].map((disclosure) => encodeDisclosure(disclosure))))
202+
const encodedDisclosures = computed(() => {
203+
if (JSON.stringify(disclosures.value) === "{}") return null
204+
205+
const m = {}
206+
for (let credId in disclosures.value) {
207+
if (m[credId] === undefined) {
208+
m[credId] = []
209+
}
241210
242-
return _selectedCredentialIds;
243-
});
211+
for (let disclosure of disclosures.value[credId]) {
212+
console.log("DISC ", disclosure)
213+
m[credId].push(encodeDisclosure(disclosure))
214+
}
215+
}
244216
245-
const disclosures = ref({});
217+
return m
218+
})
246219
247220
function addDisclosure(credentialId: string, disclosure: string) {
248221
if (disclosures.value[credentialId] === undefined) {
@@ -258,9 +231,10 @@ function removeDisclosure(credentialId: string, disclosure: string) {
258231
259232
async function acceptPresentation() {
260233
const req = {
261-
//did: String,
234+
//did: String, // todo: choose DID of shared credential
235+
presentationRequest: request,
262236
selectedCredentials: selectedCredentialIds.value,
263-
presentationRequest: request
237+
disclosures: encodedDisclosures.value
264238
};
265239
266240
const response = await fetch(`/r/wallet/${currentWallet.value}/exchange/usePresentationRequest`, {
@@ -292,7 +266,7 @@ async function acceptPresentation() {
292266
failMessage.value = error.message;
293267
294268
console.log("Error response: " + JSON.stringify(error));
295-
// window.alert(error.message)
269+
window.alert(error.errorMessage)
296270
297271
if (error.redirectUri != null) {
298272
navigateTo(error.redirectUri as string, {

0 commit comments

Comments
 (0)