Skip to content

Commit

Permalink
fix: get credential by sdjwt match without disclosures (#473)
Browse files Browse the repository at this point in the history
Fix case in which not all fields are disclosed at the same time
  • Loading branch information
matteo-cristino authored Oct 3, 2024
1 parent 2569bfe commit 9c703e8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/lib/preferences/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,13 +49,15 @@ export async function getCredentialsPreference(): Promise<Credential[] | undefin
return await getStructuredPreferences(CREDENTIALS_PREFERENCES_KEY, true);
}

export async function getCredentialsbySdjwts(sdjwts:string[]):Promise<Credential[]>{
export async function getCredentialsbySdjwts(sdjwts: string[]): Promise<Credential[]> {
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<string[] | undefined> {
const credentials = await getCredentialsPreference();
if (!credentials) return;
Expand All @@ -82,8 +84,7 @@ export async function getCredentialPreference(id: string): Promise<Credential |
return credentials.find((credential) => String(credential.id) === id);
}


export async function getExpiredCredentials(): Promise<Credential[]>{
export async function getExpiredCredentials(): Promise<Credential[]> {
const credentials = await getCredentialsPreference();
if (!credentials) return [];
return credentials.filter((credential) => credential.expirationDate < dayjs().unix());
Expand Down

0 comments on commit 9c703e8

Please sign in to comment.