Skip to content

Commit

Permalink
Handle insufficient metadata and nested presentation fields
Browse files Browse the repository at this point in the history
  • Loading branch information
pstamatop committed Nov 18, 2024
1 parent a5c15eb commit f5689f7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions public/styles/error.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


#Error .Back {
background-color: #fff;
background-color: inherit;
color: rgb(0, 162, 255);
transition: 0.4s;
border: none;
Expand All @@ -24,7 +24,7 @@
}

#Error .Back:hover {
opacity: 0.5;
opacity: 0.7;
/* text-decoration: underline; */
}

Expand Down
1 change: 1 addition & 0 deletions public/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
.container-positions {
padding-left: 5%;
padding-right: 5%;
padding-bottom: 5%;
}

.openwithwalletbuttonnative {
Expand Down
25 changes: 13 additions & 12 deletions src/verifier/verifierRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,27 @@ verifierRouter.post('/callback', async (req, res) => {
credentialPayloads.push(parsedCredential);
console.log("Parsed credential = ", parsedCredential)
const credentialIssuerMetadata = await axios.get(parsedCredential.iss + "/.well-known/openid-credential-issuer").catch(() => null);
let fistImageUri;
if (!credentialIssuerMetadata) {
console.error("Couldnt get image for the credential " + vp_token);
return res.status(400).send({ error: "Insufficient metadata" })
} else {
console.log("Credential issuer metadata = ", credentialIssuerMetadata?.data)
fistImageUri = Object.values(credentialIssuerMetadata?.data?.credential_configurations_supported).map((conf: any) => {
if (conf?.vct == parsedCredential?.vct) {
return conf?.display && conf?.display[0] && conf?.display[0]?.background_image?.uri ? conf?.display[0]?.background_image?.uri : undefined;
}
return undefined;
}).filter((val) => val)[0];
}
console.log("Credential issuer metadata = ", credentialIssuerMetadata.data)
const fistImageUri = Object.values(credentialIssuerMetadata.data.credential_configurations_supported).map((conf: any) => {
if (conf?.vct == parsedCredential?.vct) {
return conf?.display && conf?.display[0] && conf?.display[0]?.background_image?.uri ? conf?.display[0]?.background_image?.uri : undefined;
}
return undefined;
}).filter((val) => val)[0];

if (sdJwtHeader?.vctm && sdJwtHeader?.vctm?.display.length > 0 && sdJwtHeader?.vctm?.display[0][defaultLocale]?.rendering?.svg_templates.length > 0 && sdJwtHeader?.vctm?.display[0][defaultLocale]?.rendering?.svg_templates[0]?.uri) {

if (sdJwtHeader?.vctm && sdJwtHeader?.vctm?.display?.length > 0 && sdJwtHeader?.vctm?.display[0][defaultLocale]?.rendering?.svg_templates.length > 0 && sdJwtHeader?.vctm?.display[0][defaultLocale]?.rendering?.svg_templates[0]?.uri) {
const response = await axios.get(sdJwtHeader?.vctm?.display[0][defaultLocale].rendering.svg_templates[0].uri);
const svgText = response.data;
const pathsWithValues: any[] = [];
const dataUri = generateDataUriFromSvg(svgText, pathsWithValues); // replaces all with empty string
credentialImages.push(dataUri);
}
else if(sdJwtHeader?.vctm && sdJwtHeader?.vctm?.display.length > 0 && sdJwtHeader?.vctm?.display[0][defaultLocale]?.rendering?.simple?.logo?.uri) {
else if(sdJwtHeader?.vctm && sdJwtHeader?.vctm?.display?.length > 0 && sdJwtHeader?.vctm?.display[0][defaultLocale]?.rendering?.simple?.logo?.uri) {
credentialImages.push(sdJwtHeader?.vctm?.display[0][defaultLocale]?.rendering?.simple?.logo?.uri);
}
else if (fistImageUri) {
Expand All @@ -137,7 +138,7 @@ verifierRouter.post('/callback', async (req, res) => {
}
else {
console.error("Not supported format. Parsing failed")
return res.status(400).send({ error: "Not supoorted format" })
return res.status(400).send({ error: "Not supported format" })
}

return res.render('verifier/success.pug', {
Expand Down
1 change: 0 additions & 1 deletion views/error.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ block layout-content
#Error
.container
h1 Error
h3 #{code}
p #{msg}
.navigation
i.fa.fa-angle-left.next-icon(aria-hidden="true")
Expand Down
11 changes: 1 addition & 10 deletions views/footer.pug
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,10 @@ div.footer
ul
li
span.fa.fa-code  
a(href='/organisations') #{locale.footer.documentation}
a(href='https://wwwallet.github.io/wallet-docs/') #{locale.footer.documentation}
//- li
//- span.fa.fa-check-circle  
//- a(href='/verifier-panel') #{locale.footer.adminLogin}
#info
h3.header #{locale.footer.information}
ul
li
span.fa.fa-university  
a(href='https://ediplomas.gr/institutions' target='_blank' rel='noopener noreferrer') #{locale.footer.participatingInst}
li
span.fa.fa-handshake-o  
a(href='https://ediplomas.gr/terms' target='_blank' rel='noopener noreferrer') #{locale.footer.termsOfUse}
#contact
h3.header #{locale.footer.contact}
ul
Expand Down
15 changes: 12 additions & 3 deletions views/verifier/success.pug
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ block layout-content
th Value
tbody
each claim in presentationClaims[claimType]
tr
td= claim.name
td= claim.value
if typeof claim.value === 'object' && claim.value !== null
each entry in Object.entries(claim.value)
tr
- const [key, val] = entry
td= `${claim.name} - ${key}`
td= val
else
tr
td= claim.name
td= claim.value



h3 Credentials

Expand Down

0 comments on commit f5689f7

Please sign in to comment.