Skip to content

Commit

Permalink
Add check for format in descriptor maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Jdu278 committed Aug 23, 2024
1 parent 9286b98 commit 4bda413
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
2 changes: 0 additions & 2 deletions models/SdJwtClaims.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type {ClaimSignature} from "~/models/MDocClaims";

export const SdJwtClaims: ClaimSignature = {
'VCT': 'vct',
'Aussteller': 'iss',
'Name': 'given_name',
'Familienname': 'family_name',
'Geburtsname': 'birth_family_name',
Expand Down
18 changes: 18 additions & 0 deletions models/WalletResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export type WalletResponse = {
state: string;
vp_token: string; // TODO: add string[]
presentation_submission: PresentationSubmission;
nonce: string;
}

type PresentationSubmission = {
id: string;
definition_id: string;
descriptor_map: DescriptorMap[];
}

type DescriptorMap = {
id: string;
format: string;
path: string;
}
15 changes: 8 additions & 7 deletions pages/wallet-redirect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import axios from "axios";
import {onMounted, ref} from 'vue';
import {getMdocClaims, getSdJwtClaims} from "~/utils/utils";
import type {WalletResponse} from "~/models/WalletResponse";
const runtimeConfig = useRuntimeConfig()
const baseUrl = runtimeConfig.public.apiUrl
const dataList = ref<{ key: string; value: string }[]>([]);
const errorMessage = ref<string | null>(null);
let vpToken: string;
onMounted(async () => {
const sessionStore = useSessionStore();
const presentationId = sessionStore.presentationId
Expand All @@ -47,7 +47,6 @@ onMounted(async () => {
// errorMessage.value = 'Nonce ist falsch';
// return;
// }
console.log('presentationId', presentationId, 'hash', hash);
if (hash && presentationId) {
try {
const params = new URLSearchParams(hash.slice(1))
Expand All @@ -56,10 +55,11 @@ onMounted(async () => {
const response = await axios.get(
`${baseUrl}/ui/presentations/${presentationId}?response_code=${responseCode.value}`
);
vpToken = response.data.vp_token;
const walletResponse: WalletResponse = response.data
const vpToken = walletResponse.vp_token;
const format = walletResponse.presentation_submission.descriptor_map[0].format
// TODO: add proper check
if (vpToken.includes('ey')) {
if (['vc+sd-jwt', 'vc+sd-jwt+zkp'].includes(format)) {
const sdJwtClaims = await getSdJwtClaims(vpToken)
console.log('These are the claims', sdJwtClaims)
if (sdJwtClaims) {
Expand All @@ -74,7 +74,8 @@ onMounted(async () => {
} else {
errorMessage.value = 'Fehler beim Abrufen der Daten';
}
} else {
}
else if (['mso_mdoc', 'mso_mdoc+zkp'].includes(format)) {
const mdocClaims = await getMdocClaims(vpToken)
console.log('mdocClaims', mdocClaims)
if (mdocClaims) {
Expand All @@ -89,7 +90,7 @@ onMounted(async () => {
}
}
} catch (error) {
console.log('Error wallet redirect', error)
console.error('Error wallet redirect', error)
errorMessage.value = 'Fehler beim Abrufen der Daten';
}
} else {
Expand Down
13 changes: 7 additions & 6 deletions utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function getSdJwtClaims(vpToken: string): Promise<{ key: string; v
digest,
)
} catch (error) {
console.log('Error during getSdJwtClaims', error);
console.error('Error during getSdJwtClaims', error);
throw Error()
}
}
Expand All @@ -24,13 +24,14 @@ export async function getMdocClaims(vpToken: string): Promise<{
try {

const buf: Buffer = Buffer.from(vpToken, 'base64');
const valueOut: any = await cbor.decodeFirst(buf, {

const valueOut = await cbor.decodeFirst(buf, {
preferWeb: true

});
// TODO: edit for multiple Presentations
let namespaces = valueOut.nameSpaces;
let firstNamespace = Object.entries(namespaces)[0][0];
const namespaces = valueOut.nameSpaces;
const firstNamespace = Object.entries(namespaces)[0][0];
const dataArray: TagValue[] = namespaces[firstNamespace];

const requestDataPromises = dataArray.map((item: TagValue) => cborDecode(item.value));
Expand All @@ -44,12 +45,12 @@ export async function getMdocClaims(vpToken: string): Promise<{
Object.entries(claims)) as { [key: string]: { key: string; value: string } };

} catch (error) {
console.log('Error during getmdocclaims', error);
console.error('Error during getMdocClaims', error);
throw Error()
}
}

async function cborDecode(buf: Uint8Array): Promise<any> {
async function cborDecode(buf: Uint8Array) {
return cbor.decodeFirst(buf, {
preferWeb: true
});
Expand Down

0 comments on commit 4bda413

Please sign in to comment.