Skip to content

Commit

Permalink
multiple personas issueance
Browse files Browse the repository at this point in the history
  • Loading branch information
endimion committed Jun 10, 2024
1 parent fa379d4 commit c0d36d5
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 14 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://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",
Expand Down
6 changes: 5 additions & 1 deletion routes/boardingPassRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
91 changes: 79 additions & 12 deletions routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || "",
Expand All @@ -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 || "",
Expand All @@ -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 (
Expand Down Expand Up @@ -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 || "",
Expand All @@ -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",
Expand All @@ -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 = {
Expand Down

0 comments on commit c0d36d5

Please sign in to comment.