Skip to content

Commit

Permalink
Add nonce to store and refactor types
Browse files Browse the repository at this point in the history
  • Loading branch information
Jdu278 committed Aug 7, 2024
1 parent 8df47a0 commit 62b7271
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 104 deletions.
24 changes: 16 additions & 8 deletions components/PresentationForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,27 @@
Hier ausweisen
</button>
</div>
<div v-if="errorMessage" class="mx-6 my-4 p-4 border-red-400 border rounded text-red-500">
<p>{{ errorMessage }}</p>
</div>
</div>
</template>

<script setup lang="ts">
import axios from 'axios';
import type {PresentationRequest} from "~/models/PresentationRequest.ts";
import type {TransactionRequest} from "~/models/TransactionRequest.ts";
import {presentationInfo} from '~/models/PresentationInfo';
import type {PresentationResponse} from "~/models/PresentationResponse";
import type {TransactionResponse} from "~/models/TransactionResponse";
import {ref} from "vue";
const errorMessage = ref<string | null>(null);
const emit = defineEmits(['data-posted']);
const sessionStore = useSessionStore();
const runtimeConfig = useRuntimeConfig()
const baseUrl = runtimeConfig.public.apiUrl
const nonce = crypto.randomUUID()
const dataList = ref<{ kind: string, selected: boolean }[]>(Object.keys(presentationInfo).map(kind => ({
kind,
Expand All @@ -45,8 +52,8 @@ const dataList = ref<{ kind: string, selected: boolean }[]>(Object.keys(presenta
const postData = async () => {
const selectedItems = dataList.value.filter(item => item.selected);
const presentationRequest: PresentationRequest = {
nonce: crypto.randomUUID(),
const presentationRequest: TransactionRequest = {
nonce: nonce,
response_mode: 'direct_post',
type: 'vp_token',
presentation_definition: {
Expand Down Expand Up @@ -78,14 +85,15 @@ const postData = async () => {
try {
const response = await axios.post(`${baseUrl}/ui/presentations`, presentationRequest);
const presentationResponse: PresentationResponse = response.data;
const {client_id, presentation_id, request_uri}: TransactionResponse = response.data;
sessionStore.setPresentationResponse(presentationResponse);
emit('data-posted', presentationResponse);
sessionStore.setPresentationStore({client_id, presentation_id, request_uri, nonce});
emit('data-posted', {client_id, request_uri});
console.log('client_id: ', client_id);
emit('data-posted', presentationResponse);
} catch (error) {
console.error('Error posting data:', error);
errorMessage.value = 'Fehler beim Senden der Daten';
}
}
</script>
7 changes: 3 additions & 4 deletions components/QrCode.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-if="data" class="flex flex-col justify-center items-center gap-6">
<div v-if="props.data" class="flex flex-col justify-center items-center gap-6">
<qrcode-vue :value="link" :level="level" :render-as="renderAs" :size="200" class="my-10"/>
<NuxtLink :to="link">
<button class="btn btn-primary">
Expand All @@ -12,16 +12,15 @@
<script setup lang="ts">
import QrcodeVue from 'qrcode.vue'
import type {Level, RenderAs} from 'qrcode.vue'
import type {PresentationResponse} from "~/models/PresentationResponse";
const runtimeConfig = useRuntimeConfig()
const baseUrl = runtimeConfig.public.apiUrl
const props = defineProps<{
data: PresentationResponse;
data: { client_id: string, request_uri: string }
}>();
const {client_id, request_uri} = props.data;
const {request_uri, client_id} = props.data
const authenticationUrl = `eudi-openid4vp://${baseUrl}?client_id=${client_id}&request_uri=${request_uri}`
const link = ref(authenticationUrl)
Expand Down
81 changes: 0 additions & 81 deletions models/PresentationRequest.ts

This file was deleted.

34 changes: 34 additions & 0 deletions models/TransactionRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export type TransactionRequest = {
nonce: string;
presentation_definition: PresentationDefinition;
type: string;
response_mode: string;
}

type PresentationDefinition = {
id: string;
input_descriptors: InputDescriptor[];
}

type InputDescriptor = {
id: string;
name: string;
purpose: string;
format: Format;
constraints: Constraint;
}

type Format = {
mso_mdoc: {
alg: string[];
};
}

type Constraint = {
fields: Field[];
}

type Field = {
path: string[];
intent_to_retain: boolean;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type PresentationResponse = {
export type TransactionResponse = {
client_id: string;
presentation_id:string;
request_uri: string;
Expand Down
5 changes: 5 additions & 0 deletions models/TransactionStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { TransactionResponse } from "~/models/TransactionResponse";

export interface TransactionStore extends TransactionResponse {
nonce: string;
}
7 changes: 3 additions & 4 deletions pages/provider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
<script setup lang="ts">
import QrCode from "~/components/QrCode.vue";
import PresentationForm from "~/components/PresentationForm.vue";
import type {PresentationResponse} from "~/models/PresentationResponse";
const qrCodeData = ref<PresentationResponse | null>(null);
const qrCodeData = ref<{client_id: string, request_uri: string} | null>(null);
const handleDataPosted = (data: PresentationResponse) => {
qrCodeData.value = data;
const handleDataPosted = (client_id: string, request_uri: string) => {
qrCodeData.value = {client_id, request_uri};
};
</script>
21 changes: 15 additions & 6 deletions stores/SessionStore.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import { defineStore } from 'pinia'
import type {PresentationResponse} from "~/models/PresentationResponse";
import type {TransactionStore} from "~/models/TransactionStore";


export const useSessionStore = defineStore('session', {
state: () => ({
clientId: null as string | null,
presentationId: null as string | null,
requestUri: null as string | null,
nonce: null as string | null,
}),
actions: {
setPresentationResponse(response: PresentationResponse) {
this.clientId = response.client_id
this.presentationId = response.presentation_id
this.requestUri = response.request_uri
setPresentationStore(data: TransactionStore) {
this.clientId = data.client_id
this.presentationId = data.presentation_id
this.requestUri = data.request_uri
this.nonce = data.nonce
},
$reset() {
this.clientId = null
this.presentationId = null
this.requestUri = null
this.nonce = null
}
}
},
persist: true,
})

0 comments on commit 62b7271

Please sign in to comment.