Skip to content

Commit

Permalink
feat: verify VCs in store backend using API call to gov issuer
Browse files Browse the repository at this point in the history
  • Loading branch information
Dexagod committed Apr 25, 2024
1 parent 4f4d130 commit 83137ce
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
2 changes: 0 additions & 2 deletions demo/backend/gov-vc-issuer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ app.post('/verify', async (req,res)=>{
documentLoader
})

console.log(verificationResult)

res.send({validationResult, verificationResult})
})

Expand Down
25 changes: 21 additions & 4 deletions demo/backend/store/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express, { Request, Response, response } from 'express';
import { processAgeResult, retrieveData, terms, verifyJwtToken } from './util'
import BackendStore, { Contract, Embedded, Retrieval } from './storage';
import { processAgeResult, retrieveData, terms, verifyVCsignature, verifyJwtToken } from './util'
import BackendStore, { Contract, Embedded } from './storage';
import cors from "cors"

const app = express()
Expand Down Expand Up @@ -56,9 +56,26 @@ app.get('/verify', async (req: Request, res: Response) => {
}
storage.storeEmbedded(embedded)

// todo:: check purpose checking etc double check

// 4 verify age credential signature
// todo: signature verification!!!!!!!!!!!!!!!!!!!!!!

// todo: signature verification currently done on VC service through API.
// this should be moved to the backend itself in due time?
let result = await verifyVCsignature('http://localhost:4444/verify', data)
if (!result.validationResult.valid) {
res.statusCode = 200;
res.send({
"verified": false, // todo: more info & credential verification result
"message": "Age Credential data validation failed"
})
}
if (!result.verificationResult.verified) {
res.statusCode = 200;
res.send({
"verified": false, // todo: more info & credential verification result
"message": "Age Credential signature verification failed"
})
}

// 5 check age
const decision = await processAgeResult(data, webId)
Expand Down
25 changes: 22 additions & 3 deletions demo/backend/store/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,28 @@ export async function extractContractFromToken(token: string, webId: string) {
}


export async function verifiyVCsignature(data: string) {
type VCVerificationResult = {
validationResult: {
valid: boolean
}
verificationResult: {
verified: boolean
}
}

export async function verifyVCsignature(verificationUrl: string, data: string): Promise<VCVerificationResult> {

const res = await fetch(verificationUrl, {
method: "POST",
body: data,
headers: { "Content-Type": "application/json" }
})

const {validationResult, verificationResult} = (await res.json()) as VCVerificationResult

console.log('[store-backend] validationResult', validationResult)
console.log('[store-backend] verificationResult', verificationResult)

// 1 -> get data as JSON-LD
// 2 -> validate using Gertjan's stuff (did I make something like this already?)
return {validationResult, verificationResult}

}
2 changes: 1 addition & 1 deletion demo/sites/updatedstore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"scripts": {
"dev": "yarn run -T react-scripts start",
"start": "yarn run -T serve -s build -l 5003",
"start": "yarn run -T serve -s build -l 5002",
"build": "yarn run -T react-scripts build"
},
"browserslist": {
Expand Down
1 change: 0 additions & 1 deletion demo/sites/updatedstore/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useEffect, useState } from 'react';
import './App.css';
import SearchComponent from './components/SearchComponent';
import ShowCourseComponent from './components/ShowCourseComponent';
import { performAgeVerification } from './util';
import PaymentComponent from './components/PaymentComponent';

export const storeBackendUrl = 'http://localhost:5123/'
Expand Down
11 changes: 11 additions & 0 deletions demo/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5610,6 +5610,17 @@ __metadata:
languageName: node
linkType: hard

"@solidlab/uma-demo-auditing@workspace:sites/auditingsite":
version: 0.0.0-use.local
resolution: "@solidlab/uma-demo-auditing@workspace:sites/auditingsite"
dependencies:
"@comunica/query-sparql": "npm:^2.6.9"
"@inrupt/solid-client-authn-browser": "npm:^1.14.0"
n3: "npm:^1.17.3"
uuid: "npm:^9.0.1"
languageName: unknown
linkType: soft

"@solidlab/uma-demo-authz@workspace:sites/authorizationsite":
version: 0.0.0-use.local
resolution: "@solidlab/uma-demo-authz@workspace:sites/authorizationsite"
Expand Down

0 comments on commit 83137ce

Please sign in to comment.