Skip to content

Commit

Permalink
chore: refactor create presentation sd-jwt method
Browse files Browse the repository at this point in the history
  • Loading branch information
SinanovicEdis committed Jan 16, 2025
1 parent a4e1e95 commit c5dedad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"./files/circuits/credentialAtomicQuerySigV2/circuit_final.zkey",
"./files/circuits/credentialAtomicQuerySigV2/verification_key.json"
],
"shasum": "ciK/QVN8eKTGhyIUZpsFs5bLKWq7zrD7t/wIWvreYNs="
"shasum": "fTs/nRwh2XGR1RuhJnmiNl09h8ZS3+7RREx+lGLu51A="
},
"initialPermissions": {
"endowment:ethereum-provider": {},
Expand Down
30 changes: 16 additions & 14 deletions packages/snap/src/veramo/Veramo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ class VeramoService {
presentationFrame: presentationKeys as string[],
});

return presentation.res.presentation;
return presentation.presentation;
}
})
);
Expand Down Expand Up @@ -597,18 +597,17 @@ class VeramoService {
presentationFrame: string[];
}): Promise<any> {
const { encodedSdJwtVc, presentationFrame } = params;
const sdjwt = SDJwtService.get();

const presentationKeys =
await VeramoService.createPresentationFrame(presentationFrame);

const res = await VeramoService.instance.createSdJwtVcPresentation({
presentation: encodedSdJwtVc,
presentationKeys: {
credentialSubject: presentationKeys,
},
});
const sdJwtPresentation = await sdjwt.present(
encodedSdJwtVc,
presentationKeys
);

return { res, proof: { type: 'sd-jwt' } };
return { presentation: sdJwtPresentation, proof: { type: 'sd-jwt' } };
}

/**
Expand Down Expand Up @@ -709,24 +708,27 @@ class VeramoService {
static async createPresentationFrame(
claims: string[]
): Promise<PresentationFrame<Record<string, boolean>>> {
const frame: any = {};
let frame: any = {};

claims.forEach((claim) => {
// Split nested claims by '.'
const keys = claim.split('.');
// Start from the root
let current = frame;

// Build the nested structure
keys.forEach((key, index) => {
if (!current[key]) {
// If last key, set to true, otherwise set to an empty object
current[key] = index === keys.length - 1 ? true : {};
}
current = current[key]; // Traverse deeper
current = current[key];
});
});

// Change this if want to add more properties that are not in credentialSubject to the frame
frame = {
credentialSubject: {
...frame,
},
};

return frame as PresentationFrame<Record<string, boolean>>;
}

Expand Down

0 comments on commit c5dedad

Please sign in to comment.