From c0d36d51eee72b67d8a1c45bd46bfd9c5cf0d3a3 Mon Sep 17 00:00:00 2001 From: Nikos Triantafyllou Date: Mon, 10 Jun 2024 15:42:58 +0300 Subject: [PATCH] multiple personas issueance --- package.json | 2 +- routes/boardingPassRoutes.js | 6 ++- routes/routes.js | 91 +++++++++++++++++++++++++++++++----- 3 files changed, 85 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 681b3f5..0a40b6f 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "module", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "dev": "SERVER_URL=https://2f95-2a02-587-871c-8800-5569-20c0-5a74-e8bf.ngrok-free.app node server.js" + "dev": "SERVER_URL=https://fb13-2a02-587-870a-9d00-812c-35df-3c2a-93f4.ngrok-free.app node server.js" }, "author": "", "license": "ISC", diff --git a/routes/boardingPassRoutes.js b/routes/boardingPassRoutes.js index f11fbfe..b36200b 100644 --- a/routes/boardingPassRoutes.js +++ b/routes/boardingPassRoutes.js @@ -37,12 +37,16 @@ const privateKey = fs.readFileSync("./private-key.pem", "utf-8"); const publicKeyPem = fs.readFileSync("./public-key.pem", "utf-8"); boardingPassRouter.get(["/pre-offer-jwt-bpass"], async (req, res) => { - const uuid = req.query.sessionId ? req.query.sessionId : uuidv4(); + let uuid = req.query.sessionId ? req.query.sessionId : uuidv4(); + const persona = req.query.persona ? req.query.persona : null; + if(persona) uuid = uuid+"-persona="+persona + const preSessions = getPreCodeSessions(); if (preSessions.sessions.indexOf(uuid) < 0) { preSessions.sessions.push(uuid); preSessions.results.push({ sessionId: uuid, status: "pending" }); } + // console.log(preSessions) let credentialOffer = `openid-credential-offer://?credential_offer_uri=${serverURL}/credential-offer-pre-jwt-bpass/${uuid}`; //OfferUUID let code = qr.image(credentialOffer, { type: "png", diff --git a/routes/routes.js b/routes/routes.js index 42b4ad2..452a0cc 100644 --- a/routes/routes.js +++ b/routes/routes.js @@ -505,7 +505,7 @@ router.post("/credential", async (req, res) => { eduPersonAssurance: [ "https://wiki.refeds.org/display/ASS/REFEDS+Assurance+Framework+ver+1.0", ], - } + }; } else if (persona === "2") { payload.vc.credentialSubject = { id: decodedHeaderSubjectDID || "", @@ -528,7 +528,7 @@ router.post("/credential", async (req, res) => { eduPersonAssurance: [ "https://wiki.refeds.org/display/ASS/REFEDS+Assurance+Framework+ver+1.0", ], - } + }; } else if (persona === "3") { payload.vc.credentialSubject = { id: decodedHeaderSubjectDID || "", @@ -551,7 +551,7 @@ router.post("/credential", async (req, res) => { eduPersonAssurance: [ "https://wiki.refeds.org/display/ASS/REFEDS+Assurance+Framework+ver+1.0", ], - } + }; } } else { if ( @@ -592,6 +592,13 @@ router.post("/credential", async (req, res) => { requestedCredentials != null && requestedCredentials[0] === "ferryBoardingPassCredential" ) { + const preSessions = getPreCodeSessions(); + let persona = getPersonaFromAccessToken( + token, + preSessions.personas, + preSessions.accessTokens + ); + payload = { iss: serverURL, sub: decodedHeaderSubjectDID || "", @@ -602,6 +609,15 @@ router.post("/credential", async (req, res) => { type: ["VerifiableCredential", "ferryBoardingPassCredential"], "@context": ["https://www.w3.org/2018/credentials/v1"], issuer: serverURL, + issuanceDate: new Date( + Math.floor(Date.now() / 1000) * 1000 + ).toISOString(), + expirationDate: new Date( + (Math.floor(Date.now() / 1000) + 60 * 60) * 1000 + ).toISOString(), + validFrom: new Date( + Math.floor(Date.now() / 1000) * 1000 + ).toISOString(), credentialSubject: { id: decodedHeaderSubjectDID || "", // Replace with the actual subject DID identifier: "John Doe", @@ -620,17 +636,68 @@ router.post("/credential", async (req, res) => { arrivalPort: "NYC", vesselDescription: "Ferry XYZ", }, - issuanceDate: new Date( - Math.floor(Date.now() / 1000) * 1000 - ).toISOString(), - expirationDate: new Date( - (Math.floor(Date.now() / 1000) + 60 * 60) * 1000 - ).toISOString(), - validFrom: new Date( - Math.floor(Date.now() / 1000) * 1000 - ).toISOString(), + }, }; + + if (persona === "1") { + payload.vc.credentialSubject ={ + id: decodedHeaderSubjectDID || "", // Replace with the actual subject DID + identifier: "Mario Conti", + ticketQR: + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHkAAAB5AQAAAAA+SX7VAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAABlUlEQVRIDe2YMUtCQRCFZxQVhQo2hdwV2NhZ+ggLFzcBrcNLYktjb2AiBBkDEtFiFE3d7WVo+BR+BX+gtEop3Rjb7ndmxmh8HTIz5TdvzZk5MhGoUZ1Hnz1swr3/ehyHt6nuKPexG5XQPeDqcgrBXT3wGso+ULuLoDr/owxPI27WqZLPKpFvH2FqESkBu8WqwCrCL3r6Ne3Slo6I0A9H/UUXH5KoJwUbPFLU5CJqsZubAiZwVLja4YpAyyKcijulVDrwjeMaLs5CmlgHds1GZc9K8T/AXTDwLB0yzhFb2CHavBtL68YRuBN3le6HB54Rz6MPGoNx7N2e3ws+b9YL2scQY8jI9iA9gN0FbgeEQLzUXwl90kpAmNyDe4SjH5itwbPfNRi7w0Ogl8KiB1QWUDZc0h34sFjDwrIs+w6GCSnNhWbzP9FAvVd8BzCgbChAkd4VnLQZX9VaQd9gM0b9D/UZoTQAAAABJRU5ErkJggg==", + ticketNumber: "3022", + ticketLet: "Y", + lastName: "Conti", + firstName: "Mario", + seatType: "Economy", + seatNumber: "12A", + departureDate: "2024-08-17", + departureTime: "13:07:34", + arrivalDate: "2024-08-17", + arrivalTime: "15:30:00", + arrivalPort: "MYKONOS TEST", + vesselDescription: "MYKONOS TEST", + } + }else if(persona === "2"){ + payload.vc.credentialSubject ={ + id: decodedHeaderSubjectDID || "", // Replace with the actual subject DID + identifier: "Hannah Matkalainen", + ticketQR: + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHkAAAB5AQAAAAA+SX7VAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAABlUlEQVRIDe2YMUtCQRCFZxQVhQo2hdwV2NhZ+ggLFzcBrcNLYktjb2AiBBkDEtFiFE3d7WVo+BR+BX+gtEop3Rjb7ndmxmh8HTIz5TdvzZk5MhGoUZ1Hnz1swr3/ehyHt6nuKPexG5XQPeDqcgrBXT3wGso+ULuLoDr/owxPI27WqZLPKpFvH2FqESkBu8WqwCrCL3r6Ne3Slo6I0A9H/UUXH5KoJwUbPFLU5CJqsZubAiZwVLja4YpAyyKcijulVDrwjeMaLs5CmlgHds1GZc9K8T/AXTDwLB0yzhFb2CHavBtL68YRuBN3le6HB54Rz6MPGoNx7N2e3ws+b9YL2scQY8jI9iA9gN0FbgeEQLzUXwl90kpAmNyDe4SjH5itwbPfNRi7w0Ogl8KiB1QWUDZc0h34sFjDwrIs+w6GCSnNhWbzP9FAvVd8BzCgbChAkd4VnLQZX9VaQd9gM0b9D/UZoTQAAAABJRU5ErkJggg==", + ticketNumber: "3022", + ticketLet: "Y", + lastName: "Matkalainen", + firstName: "Hannah", + seatType: "Economy", + seatNumber: "12A", + departureDate: "2024-08-17", + departureTime: "13:07:34", + arrivalDate: "2024-08-17", + arrivalTime: "15:30:00", + arrivalPort: "MYKONOS TEST", + vesselDescription: "MYKONOS TEST", + } + }else if(persona ==="3"){ + payload.vc.credentialSubject ={ + id: decodedHeaderSubjectDID || "", // Replace with the actual subject DID + identifier: "Felix Fischer", + ticketQR: + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHkAAAB5AQAAAAA+SX7VAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAABlUlEQVRIDe2YMUtCQRCFZxQVhQo2hdwV2NhZ+ggLFzcBrcNLYktjb2AiBBkDEtFiFE3d7WVo+BR+BX+gtEop3Rjb7ndmxmh8HTIz5TdvzZk5MhGoUZ1Hnz1swr3/ehyHt6nuKPexG5XQPeDqcgrBXT3wGso+ULuLoDr/owxPI27WqZLPKpFvH2FqESkBu8WqwCrCL3r6Ne3Slo6I0A9H/UUXH5KoJwUbPFLU5CJqsZubAiZwVLja4YpAyyKcijulVDrwjeMaLs5CmlgHds1GZc9K8T/AXTDwLB0yzhFb2CHavBtL68YRuBN3le6HB54Rz6MPGoNx7N2e3ws+b9YL2scQY8jI9iA9gN0FbgeEQLzUXwl90kpAmNyDe4SjH5itwbPfNRi7w0Ogl8KiB1QWUDZc0h34sFjDwrIs+w6GCSnNhWbzP9FAvVd8BzCgbChAkd4VnLQZX9VaQd9gM0b9D/UZoTQAAAABJRU5ErkJggg==", + ticketNumber: "3022", + ticketLet: "Y", + lastName: "Fischer", + firstName: "Felix", + seatType: "Economy", + seatNumber: "12A", + departureDate: "2024-08-17", + departureTime: "13:07:34", + arrivalDate: "2024-08-17", + arrivalTime: "15:30:00", + arrivalPort: "MYKONOS TEST", + vesselDescription: "MYKONOS TEST", + } + } } else { //sign as jwt payload = {