From 9c703e851f00ba0e0711cd490daf238a0a296215 Mon Sep 17 00:00:00 2001 From: Matteo Cristino <102997993+matteo-cristino@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:47:24 +0200 Subject: [PATCH] fix: get credential by sdjwt match without disclosures (#473) Fix case in which not all fields are disclosed at the same time --- src/lib/preferences/credentials.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/lib/preferences/credentials.ts b/src/lib/preferences/credentials.ts index ae330f3e..04f997be 100644 --- a/src/lib/preferences/credentials.ts +++ b/src/lib/preferences/credentials.ts @@ -10,7 +10,7 @@ export type Credential = { configuration_ids: string[]; sdJwt: string; issuer: string; - issuerUrl:string + issuerUrl: string; display_name: string; description: string; expirationDate: number; @@ -49,13 +49,15 @@ export async function getCredentialsPreference(): Promise{ +export async function getCredentialsbySdjwts(sdjwts: string[]): Promise { const credentials = await getCredentialsPreference(); if (!credentials) return []; - return credentials.filter((credential) => sdjwts.includes(credential.sdJwt)); + const sdjwtsWithoutDisclosures = sdjwts.map((sdjwt) => sdjwt.split('~')[0]); + return credentials.filter((credential) => + sdjwtsWithoutDisclosures.includes(credential.sdJwt.split('~')[0]) + ); } - export async function getCredentialsSdjwt(): Promise { const credentials = await getCredentialsPreference(); if (!credentials) return; @@ -82,8 +84,7 @@ export async function getCredentialPreference(id: string): Promise String(credential.id) === id); } - -export async function getExpiredCredentials(): Promise{ +export async function getExpiredCredentials(): Promise { const credentials = await getCredentialsPreference(); if (!credentials) return []; return credentials.filter((credential) => credential.expirationDate < dayjs().unix());