Skip to content

Commit

Permalink
fixed issue#12
Browse files Browse the repository at this point in the history
  • Loading branch information
endimion committed Jul 1, 2024
1 parent cb28357 commit 48edfc1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 50 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "SERVER_URL=https://95cf-2a02-587-8713-1c00-7651-758f-5657-ed40.ngrok-free.app node server.js"
"dev": "SERVER_URL=https://dd0d-2a02-587-8713-1c00-f2ea-680b-e09-62ed.ngrok-free.app node server.js"
},
"author": "",
"license": "ISC",
Expand Down
95 changes: 46 additions & 49 deletions routes/verifierRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ const jwks = pemToJWK(publicKeyPem, "public");

let verificationSessions = []; //TODO these should be redis or something a proper cache...
let sessions = [];
let sessionHistory = new TimedArray(30000) //cache data for 30sec
let verificationResultsHistory = new TimedArray(30000) //cache data for 30sec
let sessionHistory = new TimedArray(30000); //cache data for 30sec
let verificationResultsHistory = new TimedArray(30000); //cache data for 30sec

verifierRouter.get("/generateVPRequest", async (req, res) => {
const stateParam = req.query.id ? req.query.id : uuidv4();
Expand Down Expand Up @@ -214,48 +214,36 @@ verifierRouter.get("/vpRequestJwt/:id", async (req, res) => {
claims: null,
});

// let jwtToken = buildVpRequestJwt(
// stateParam,
// nonce,
// clientId,
// response_uri,
// presentation_definition_jwt,
// jwks,
// serverURL,
// privateKey
// );


clientMetadata.presentation_definition_uri= serverURL+"/presentation-definition/1"
clientMetadata.redirect_uris= [response_uri]
clientMetadata.client_id=clientId
clientMetadata.presentation_definition_uri =
serverURL + "/presentation-definition/1";
clientMetadata.redirect_uris = [response_uri];
clientMetadata.client_id = clientId;

let vpRequest= {
response_type: "vp_token",
let vpRequest = {
client_id: clientId,
client_id_scheme: "redirect_uri",
response_uri: response_uri,
response_type: "vp_token",
response_mode: "direct_post",
presentation_definition: presentation_definition_jwt,
redirect_uri: response_uri,
// response_mode: "direct_post",
client_metadata : encodeURIComponent(JSON.stringify(clientMetadata)),
}
nonce: nonce,
state: uuid,
};

console.log("will send vpRequest")
console.log(vpRequest)
// console.log("will send vpRequest");
// console.log(vpRequest);

res.json(vpRequest);
res.json(vpRequest);
});


verifierRouter.get("/presentation-definition/:type", async (req, res) => {
const { type } = req.params;
if(type == 1) {
if (type == 1) {
res.type("application/json").send(presentation_definition_jwt);
}
console.log("ERROR getting presentatiton-definition type")
res.status(500)
})

console.log("ERROR getting presentatiton-definition type");
res.status(500);
});

// *******************PILOT USE CASES ******************************
verifierRouter.get("/vp-request/:type", async (req, res) => {
Expand Down Expand Up @@ -322,17 +310,27 @@ verifierRouter.get("/vpRequest/:type/:id", async (req, res) => {
return res.status(400).type("text/plain").send("Invalid type parameter");
}

let jwtToken = buildVpRequestJwt(
stateParam,
nonce,
clientId,
response_uri,
presentationDefinition,
jwks,
serverURL,
privateKey
);
res.type("text/plain").send(jwtToken);
// let jwtToken = buildVpRequestJwt(
// stateParam,
// nonce,
// clientId,
// response_uri,
// presentationDefinition,
// jwks,
// serverURL,
// privateKey
// );
let vpRequest = {
client_id: clientId,
client_id_scheme: "redirect_uri",
response_uri: response_uri,
response_type: "vp_token",
response_mode: "direct_post",
presentation_definition: presentation_definition_jwt,
nonce: nonce,
state: uuid,
};
res.json(vpRequest);
});

verifierRouter.post("/direct_post_jwt/:id", async (req, res) => {
Expand Down Expand Up @@ -360,9 +358,9 @@ verifierRouter.post("/direct_post_jwt/:id", async (req, res) => {
// Convert credentials to claims
let claims;
try {
console.log(credentialsJwtArray)
console.log(credentialsJwtArray);
claims = await flattenCredentialsToClaims(credentialsJwtArray);
console.log(claims)
console.log(claims);
if (!claims) {
throw new Error("Claims conversion returned null or undefined.");
}
Expand Down Expand Up @@ -397,8 +395,8 @@ verifierRouter.get(["/verificationStatus"], (req, res) => {
result = verificationSessions[index].claims;
sessions.splice(index, 1);
verificationSessions.splice(index, 1);
sessionHistory.addElement(sessionId)
verificationResultsHistory.addElement(result)
sessionHistory.addElement(sessionId);
verificationResultsHistory.addElement(result);
}
// console.log(`new sessions`);
// console.log(sessions);
Expand All @@ -421,7 +419,7 @@ verifierRouter.get(["/verificationStatus"], (req, res) => {

verifierRouter.get(["/verificationStatusHistory"], (req, res) => {
let sessionId = req.query.sessionId;
let index = sessionHistory.getCurrentArray().indexOf(sessionId);
let index = sessionHistory.getCurrentArray().indexOf(sessionId);
if (index >= 0) {
res.json({
status: "success",
Expand All @@ -438,7 +436,6 @@ verifierRouter.get(["/verificationStatusHistory"], (req, res) => {
}
});


function buildVP(
client_id,
redirect_uri,
Expand Down

0 comments on commit 48edfc1

Please sign in to comment.