diff --git a/dataset-reader/index.js b/dataset-reader/index.js index 18edda5..1d50edf 100644 --- a/dataset-reader/index.js +++ b/dataset-reader/index.js @@ -19,7 +19,7 @@ function parsePidData(filePath) { // Convert worksheet to JSON format const data = XLSX.utils.sheet_to_json(worksheet, { - defval: undefined, + defval: null, dateNF: 'd"/"m"/"yyyy' // skipHidden: true, // header: 0 @@ -32,7 +32,7 @@ function parsePidData(filePath) { row = Object.values(row) const obj = {}; row.map((cell, index) => { - obj[headers[index]] = cell; // Assign key-value pairs + obj[headers[index]] = String(cell).trim(); // Assign key-value pairs }); return obj; @@ -56,12 +56,19 @@ function parseEhicData(filePath) { const worksheet = workbook.Sheets[sheetName]; // Convert worksheet to JSON format - const data = XLSX.utils.sheet_to_json(worksheet, { - defval: undefined, + let data = XLSX.utils.sheet_to_json(worksheet, { + defval: null, dateNF: 'd"/"m"/"yyyy' // skipHidden: true, // header: 0 }); + + data = data.map((row) => { + Object.keys(row).map((k) => { + row[k] = String(row[k]).trim(); + }) + return row; + }) return data; } @@ -82,23 +89,24 @@ function parsePda1Data(filePath) { // Convert worksheet to JSON format const data = XLSX.utils.sheet_to_json(worksheet, { - defval: undefined, + defval: null, dateNF: 'd"/"m"/"yyyy' // skipHidden: true, // header: 0 }); - let headers = Object.values(data[0]).map((h) => h.trim()); + let headers = Object.values(data[0]).map((h) => h); - const ncols = Object.keys(headers); + console.log("headers = ", headers) + // const ncols = Object.keys(headers); const result = data.slice(1).map(row => { row = Object.values(row) - + console.log("all values", row) const obj = {}; row.forEach((cell, index) => { - obj[headers[index]] = cell; // Assign key-value pairs + obj[headers[index]] = String(cell).trim(); // Assign key-value pairs }); return obj; }); diff --git a/dataset-reader/test.js b/dataset-reader/test.js new file mode 100644 index 0000000..45b0b4c --- /dev/null +++ b/dataset-reader/test.js @@ -0,0 +1,6 @@ +const { parsePda1Data, parseEhicData, parsePidData } = require('.') + + +const res = parsePda1Data('./dataset.xlsx') + +console.log("Res = ", res[0]) diff --git a/wallet-enterprise-configurations/ehic-issuer/src/configuration/SupportedCredentialsConfiguration/EHICSupportedCredentialSdJwt.ts b/wallet-enterprise-configurations/ehic-issuer/src/configuration/SupportedCredentialsConfiguration/EHICSupportedCredentialSdJwt.ts deleted file mode 100644 index 001492e..0000000 --- a/wallet-enterprise-configurations/ehic-issuer/src/configuration/SupportedCredentialsConfiguration/EHICSupportedCredentialSdJwt.ts +++ /dev/null @@ -1,144 +0,0 @@ -import config from "../../../config"; -import { CategorizedRawCredentialView, CategorizedRawCredentialViewRow } from "../../openid4vci/Metadata"; -import { VerifiableCredentialFormat, Display, CredentialSupportedJwtVcJson } from "../../types/oid4vci"; -import { CredentialIssuer } from "../../lib/CredentialIssuerConfig/CredentialIssuer"; -import { SupportedCredentialProtocol } from "../../lib/CredentialIssuerConfig/SupportedCredentialProtocol"; -import { AuthorizationServerState } from "../../entities/AuthorizationServerState.entity"; -import { CredentialView } from "../../authorization/types"; -import { randomUUID } from "node:crypto"; -import fs from 'fs'; -import { CredentialStatusList } from "../../lib/CredentialStatus"; - -export class EHICSupportedCredentialSdJwt implements SupportedCredentialProtocol { - - dataset: any; - - constructor(private credentialIssuerConfig: CredentialIssuer) { - this.dataset = JSON.parse(fs.readFileSync('/datasets/dataset.json', 'utf-8').toString()) as any - } - - getCredentialIssuerConfig(): CredentialIssuer { - return this.credentialIssuerConfig; - } - getId(): string { - return "urn:credential:ehic" - } - getFormat(): VerifiableCredentialFormat { - return VerifiableCredentialFormat.VC_SD_JWT; - } - getTypes(): string[] { - return ["VerifiableCredential", "VerifiableAttestation", "EuropeanHealthInsuranceCard", "NoPickupCode", this.getId()]; - } - getDisplay(): Display { - return { - name: "EHIC Card", - logo: { url: config.url + "/images/ehicCard.png" }, - background_color: "#4CC3DD" - } - } - - - async getProfile(userSession: AuthorizationServerState): Promise { - if (!userSession?.personalIdentifier) { - return null; - } - this.dataset = JSON.parse(fs.readFileSync('/datasets/dataset.json', 'utf-8').toString()) as any - const ehics = this.dataset.users.filter((user: any) => user.authentication.personalIdentifier == userSession.personalIdentifier); - const credentialViews: CredentialView[] = ehics - .map((ehic: any) => { - const rows: CategorizedRawCredentialViewRow[] = [ - // { name: "Family Name", value: ehic.claims.familyName }, - // { name: "First Name", value: ehic.claims.firstName }, - { name: "SSN", value: ehic.claims.socialSecurityIdentification.ssn }, - // { name: "Date of Birth", value: ehic.claims.birthdate }, - { name: "Expiration Date", value: ehic.claims.validityPeriod.endingDate }, - { name: "Document Id", value: ehic.claims.documentId }, - ]; - const rowsObject: CategorizedRawCredentialView = { rows }; - - return { - credential_id: this.getId(), - credential_supported_object: this.exportCredentialSupportedObject(), - view: rowsObject, - deferredFlow: false, - } - }) - return credentialViews[0]; - } - - async generateCredentialResponse(userSession: AuthorizationServerState, holderDID: string): Promise<{ format: VerifiableCredentialFormat; credential: any; }> { - if (!userSession.personalIdentifier) { - throw new Error("Cannot generate credential: personalIdentifier is missing"); - } - this.dataset = JSON.parse(fs.readFileSync('/datasets/dataset.json', 'utf-8').toString()) as any - const { claims, authentication } = this.dataset.users.filter((user: any) => user.authentication.personalIdentifier == userSession.personalIdentifier)[0]; - - const payload = { - "@context": ["https://www.w3.org/2018/credentials/v1"], - "type": this.getTypes(), - "id": `urn:ehic:${randomUUID()}`, - "name": "EHIC ID Card", // https://www.w3.org/TR/vc-data-model-2.0/#names-and-descriptions - "description": "This credential is issued by the National EHIC ID credential issuer and it can be used for authentication purposes", - "credentialSubject": { - ...claims, - "id": holderDID, - }, - "credentialStatus": { - "id": `${config.crl.url}#${(await CredentialStatusList.insert(authentication.username, claims.personalIdentifier)).id}`, - "type": "CertificateRevocationList" - }, - "credentialBranding": { - "image": { - "url": config.url + "/images/ehicCard.png" - }, - "backgroundColor": "#8ebeeb", - "textColor": "#ffffff" - }, - }; - const disclosureFrame = { - vc: { - credentialSubject: { - // familyName: true, - // firstName: true, - // birthdate: true, - personalIdentifier: true, - socialSecurityIdentification: { - ssn: true - }, - validityPeriod: { - startingDate: true, - endingDate: true - }, - documentId: true, - competentInstitution: { - competentInstitutionId: true, - competentInstitutionName: true, - competentInstitutionCountryCode: true - }, - } - } - } - const { jws } = await this.getCredentialIssuerConfig().getCredentialSigner() - .sign({ - vc: payload - }, {}, disclosureFrame, {}); - const response = { - format: this.getFormat(), - credential: jws - }; - - return response; - } - - exportCredentialSupportedObject(): CredentialSupportedJwtVcJson { - return { - id: this.getId(), - format: this.getFormat(), - display: [this.getDisplay()], - types: this.getTypes(), - cryptographic_binding_methods_supported: ["ES256"] - } - } - -} - diff --git a/wallet-enterprise-configurations/ehic-issuer/src/configuration/SupportedCredentialsConfiguration/PickupCodeEHICSupportedCredentialSdJwt.ts b/wallet-enterprise-configurations/ehic-issuer/src/configuration/SupportedCredentialsConfiguration/PickupCodeEHICSupportedCredentialSdJwt.ts index 901c117..6cbc43d 100644 --- a/wallet-enterprise-configurations/ehic-issuer/src/configuration/SupportedCredentialsConfiguration/PickupCodeEHICSupportedCredentialSdJwt.ts +++ b/wallet-enterprise-configurations/ehic-issuer/src/configuration/SupportedCredentialsConfiguration/PickupCodeEHICSupportedCredentialSdJwt.ts @@ -176,10 +176,13 @@ export class PickupCodeEHICSupportedCredentialSdJwt implements SupportedCredenti ehic_institution_name: claims.ehic_institution_name, ehic_institution_country_code: claims.ehic_institution_country_code, pid_id: undefined, + family_name: undefined, + given_name: undefined, + birth_date: undefined, "id": holderDID, }, "credentialStatus": { - "id": `${config.crl.url}#${(await CredentialStatusList.insert(userSession.familyName ?? "", userSession.personalIdentifier)).id}`, + "id": `${config.crl.url}#${(await CredentialStatusList.insert(userSession.family_name ?? "", userSession.personalIdentifier)).id}`, "type": "CertificateRevocationList" }, "credentialBranding": { diff --git a/wallet-enterprise-configurations/ehic-issuer/src/configuration/authentication/VIDAuthenticationComponent.ts b/wallet-enterprise-configurations/ehic-issuer/src/configuration/authentication/VIDAuthenticationComponent.ts index e12b27b..6ec4530 100644 --- a/wallet-enterprise-configurations/ehic-issuer/src/configuration/authentication/VIDAuthenticationComponent.ts +++ b/wallet-enterprise-configurations/ehic-issuer/src/configuration/authentication/VIDAuthenticationComponent.ts @@ -121,7 +121,7 @@ export class VIDAuthenticationComponent extends AuthenticationComponent { return; } authorizationServerState.personalIdentifier = personalIdentifier; - authorizationServerState.familyName = familyName; + authorizationServerState.family_name = familyName; req.session.authenticationChain.vidAuthenticationComponent = { personalIdentifier: personalIdentifier, familyName: familyName, @@ -129,7 +129,7 @@ export class VIDAuthenticationComponent extends AuthenticationComponent { console.log("Personal identifier = ", personalIdentifier) req.authorizationServerState.personalIdentifier = personalIdentifier; - req.authorizationServerState.familyName = familyName; + req.authorizationServerState.family_name = familyName; await AppDataSource.getRepository(AuthorizationServerState).save(authorizationServerState); return res.redirect(this.protectedEndpoint); diff --git a/wallet-enterprise-configurations/pda1-issuer/src/configuration/SupportedCredentialsConfiguration/PDA1SupportedCredentialSdJwt.ts b/wallet-enterprise-configurations/pda1-issuer/src/configuration/SupportedCredentialsConfiguration/PDA1SupportedCredentialSdJwt.ts index ff6af24..b758f56 100644 --- a/wallet-enterprise-configurations/pda1-issuer/src/configuration/SupportedCredentialsConfiguration/PDA1SupportedCredentialSdJwt.ts +++ b/wallet-enterprise-configurations/pda1-issuer/src/configuration/SupportedCredentialsConfiguration/PDA1SupportedCredentialSdJwt.ts @@ -70,7 +70,7 @@ export class PDA1SupportedCredentialSdJwt implements SupportedCredentialProtocol throw new Error("issuer_state was not found user session"); } - console.log("Family name = ", userSession.familyName) + console.log("Family name = ", userSession.family_name) console.log('type of issuer state ', typeof userSession.issuer_state); if (!userSession.personalIdentifier) { @@ -175,10 +175,13 @@ export class PDA1SupportedCredentialSdJwt implements SupportedCredentialProtocol pda1_expiry_date: undefined, // hide this field pda1_starting_date: undefined, // hide this field pda1_ending_date: undefined, // hide this field + family_name: undefined, + given_name: undefined, + birth_date: undefined, "id": holderDID, }, "credentialStatus": { - "id": `${config.crl.url}#${(await CredentialStatusList.insert(userSession.familyName ?? "", claims.pid_id)).id}`, + "id": `${config.crl.url}#${(await CredentialStatusList.insert(userSession.family_name ?? "", claims.pid_id)).id}`, "type": "CertificateRevocationList" }, "credentialBranding": { diff --git a/wallet-enterprise-configurations/pda1-issuer/src/configuration/authentication/VIDAuthenticationComponent.ts b/wallet-enterprise-configurations/pda1-issuer/src/configuration/authentication/VIDAuthenticationComponent.ts index 2d68005..ec3a457 100644 --- a/wallet-enterprise-configurations/pda1-issuer/src/configuration/authentication/VIDAuthenticationComponent.ts +++ b/wallet-enterprise-configurations/pda1-issuer/src/configuration/authentication/VIDAuthenticationComponent.ts @@ -128,7 +128,7 @@ export class VIDAuthenticationComponent extends AuthenticationComponent { return; } authorizationServerState.personalIdentifier = personalIdentifier; - authorizationServerState.familyName = familyName; + authorizationServerState.family_name = familyName; req.session.authenticationChain.vidAuthenticationComponent = { personalIdentifier: personalIdentifier, @@ -137,7 +137,7 @@ export class VIDAuthenticationComponent extends AuthenticationComponent { console.log("Personal identifier = ", personalIdentifier) req.authorizationServerState.personalIdentifier = personalIdentifier; - req.authorizationServerState.familyName = familyName; + req.authorizationServerState.family_name = familyName; await AppDataSource.getRepository(AuthorizationServerState).save(authorizationServerState); return res.redirect(this.protectedEndpoint); diff --git a/wallet-enterprise-configurations/vid-issuer/src/configuration/SupportedCredentialsConfiguration/VIDSupportedCredentialSdJwt.ts b/wallet-enterprise-configurations/vid-issuer/src/configuration/SupportedCredentialsConfiguration/VIDSupportedCredentialSdJwt.ts index e1eb60d..c87b176 100644 --- a/wallet-enterprise-configurations/vid-issuer/src/configuration/SupportedCredentialsConfiguration/VIDSupportedCredentialSdJwt.ts +++ b/wallet-enterprise-configurations/vid-issuer/src/configuration/SupportedCredentialsConfiguration/VIDSupportedCredentialSdJwt.ts @@ -36,13 +36,18 @@ export class VIDSupportedCredentialSdJwt implements SupportedCredentialProtocol async getProfile(userSession: AuthorizationServerState): Promise { - if (!userSession?.personalIdentifier) { - return null; - } + if (!userSession.given_name || !userSession.family_name || !userSession.birth_date) { + throw new Error("Cannot generate credential: (given_name, family_name, birth_date) is missing"); + } + const dataset = parsePidData("/datasets/dataset.xlsx"); - const vids = dataset.filter((user: any) => user.pid_id == userSession.personalIdentifier); - const credentialViews: CredentialView[] = vids + const data = dataset.filter((user: any) => + user.given_name == userSession.given_name && + user.family_name == userSession.family_name && + user.birth_date.toISOString() == userSession.birth_date + ); + const credentialViews: CredentialView[] = data .map((vid: any) => { const rows: CategorizedRawCredentialViewRow[] = [ { name: "Family Name", value: vid.family_name }, @@ -64,13 +69,16 @@ export class VIDSupportedCredentialSdJwt implements SupportedCredentialProtocol } async generateCredentialResponse(userSession: AuthorizationServerState, holderDID: string): Promise<{ format: VerifiableCredentialFormat; credential: any; }> { - if (!userSession.personalIdentifier) { - throw new Error("Cannot generate credential: Taxis id is missing"); + if (!userSession.given_name || !userSession.family_name || !userSession.birth_date) { + throw new Error("Cannot generate credential: (given_name, family_name, birth_date) is missing"); } - const dataset = parsePidData("/datasets/dataset.xlsx"); - const data = dataset.filter((user: any) => user.pid_id == userSession.personalIdentifier)[0]; + const data = dataset.filter((user: any) => + user.given_name == userSession.given_name && + user.family_name == userSession.family_name && + user.birth_date.toISOString() == userSession.birth_date + )[0]; const payload = { "@context": ["https://www.w3.org/2018/credentials/v1"], "type": this.getTypes(), diff --git a/wallet-enterprise-configurations/vid-issuer/src/configuration/authentication/LocalAuthenticationComponent.ts b/wallet-enterprise-configurations/vid-issuer/src/configuration/authentication/LocalAuthenticationComponent.ts index 526b207..3f38643 100644 --- a/wallet-enterprise-configurations/vid-issuer/src/configuration/authentication/LocalAuthenticationComponent.ts +++ b/wallet-enterprise-configurations/vid-issuer/src/configuration/authentication/LocalAuthenticationComponent.ts @@ -58,12 +58,12 @@ export class LocalAuthenticationComponent extends AuthenticationComponent { if (!req.session.authenticationChain?.localAuthenticationComponent?.username) { return false; } - const username = req.session.authenticationChain.localAuthenticationComponent.username; - if (!username || this.users.filter((u: any) => u.User == username).length != 1) return false; + // const username = req.session.authenticationChain.localAuthenticationComponent.username; + // if (!username || this.users.filter((u: any) => u.User == username).length != 1) return false; - const usersFound = this.users.filter((u: any) => u.User == username) as any; - req.authorizationServerState.personalIdentifier = usersFound[0].pid_id; - await AppDataSource.getRepository(AuthorizationServerState).save(req.authorizationServerState); + // const usersFound = this.users.filter((u: any) => u.User == username) as any; + // req.authorizationServerState.personalIdentifier = usersFound[0].pid_id; + // await AppDataSource.getRepository(AuthorizationServerState).save(req.authorizationServerState); return true; } @@ -94,7 +94,9 @@ export class LocalAuthenticationComponent extends AuthenticationComponent { username: username }; - req.authorizationServerState.personalIdentifier = (usersFound[0] as any).pid_id; + req.authorizationServerState.family_name = (usersFound[0] as any).family_name; + req.authorizationServerState.given_name = (usersFound[0] as any).given_name; + req.authorizationServerState.birth_date = new Date((usersFound[0] as any).birth_date).toISOString(); await AppDataSource.getRepository(AuthorizationServerState).save(req.authorizationServerState); return res.redirect(this.protectedEndpoint); }