Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for overwritting presentation definition and rename dateOfBirth fields #44

Merged
merged 4 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { CONSENT_ENTRYPOINT } from "../../authorization/constants";
import { GrantType } from "../../types/oid4vci";
import locale from "../locale";
import * as qrcode from 'qrcode';
import { openidForPresentationReceivingService } from "../../services/instances";
import { openidForPresentationReceivingService, verifierConfigurationService } from "../../services/instances";
import { UserAuthenticationMethod } from "../../types/UserAuthenticationMethod.enum";
import { PresentationDefinitionTypeWithFormat } from "../verifier/VerifierConfigurationService";

export class VIDAuthenticationComponent extends AuthenticationComponent {

Expand Down Expand Up @@ -115,8 +116,9 @@ export class VIDAuthenticationComponent extends AuthenticationComponent {
}


const presentationDefinition = JSON.parse(JSON.stringify(verifierConfigurationService.getPresentationDefinitions().filter(pd => pd.id == "vid")[0])) as PresentationDefinitionTypeWithFormat;

const { url, stateId } = await openidForPresentationReceivingService.generateAuthorizationRequestURL({req, res}, "vid", config.url + CONSENT_ENTRYPOINT);
const { url, stateId } = await openidForPresentationReceivingService.generateAuthorizationRequestURL({req, res}, presentationDefinition, config.url + CONSENT_ENTRYPOINT);

// attach the vid_auth_state with an authorization server state
req.authorizationServerState.vid_auth_state = stateId;
Expand Down
2 changes: 2 additions & 0 deletions src/configuration/verifier/VerifierConfigurationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { authorizationServerMetadataConfiguration } from "../../authorizationSer
import config from "../../../config";
import { VerifierConfigurationInterface } from "../../services/interfaces";
import { InputDescriptorType } from "@wwwallet/ssi-sdk";
import "reflect-metadata";

export type PresentationDefinitionTypeWithFormat = {
id: string;
Expand All @@ -14,6 +15,7 @@ export type PresentationDefinitionTypeWithFormat = {
@injectable()
export class VerifierConfigurationService implements VerifierConfigurationInterface {

constructor() { }
getPresentationDefinitions(): PresentationDefinitionTypeWithFormat[] {
return [{
"id": "vid", // scope name
Expand Down
21 changes: 8 additions & 13 deletions src/services/OpenidForPresentationReceivingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,12 @@ export class OpenidForPresentationsReceivingService implements OpenidForPresenta
return payload;
}

private async addVPtokenRequestSpecificAttributes(verifierStateId: string, payload: any, presentation_definition_id: string) {
const found = this.configurationService.getPresentationDefinitions().filter(pd => pd.id == presentation_definition_id);
console.log("Found = ", found[0])
if (found.length > 0) {
const presentationDefinition = found[0];
const verifierState = verifierStates.get(verifierStateId);
if (verifierState) {
verifierStates.set(verifierStateId, { ...verifierState, presentation_definition: presentationDefinition })
payload = { ...payload, presentation_definition_uri: config.url + '/verification/definition?state=' + payload.state };
return payload;
}
private async addVPtokenRequestSpecificAttributes(verifierStateId: string, payload: any, presentationDefinition: object) {
const verifierState = verifierStates.get(verifierStateId);
if (verifierState) {
verifierStates.set(verifierStateId, { ...verifierState, presentation_definition: presentationDefinition as any })
payload = { ...payload, presentation_definition_uri: config.url + '/verification/definition?state=' + payload.state };
return payload;
}
}

Expand All @@ -87,7 +82,7 @@ export class OpenidForPresentationsReceivingService implements OpenidForPresenta
}


async generateAuthorizationRequestURL(ctx: { req: Request, res: Response }, presentation_definition_id: string, callbackEndpoint?: string): Promise<{ url: URL; stateId: string }> {
async generateAuthorizationRequestURL(ctx: { req: Request, res: Response }, presentationDefinition: object, callbackEndpoint?: string): Promise<{ url: URL; stateId: string }> {
const nonce = randomUUID();
const stateId = randomUUID();
nonces.set(nonce, stateId);
Expand All @@ -106,7 +101,7 @@ export class OpenidForPresentationsReceivingService implements OpenidForPresenta
const redirectUri = ctx.req?.authorizationServerState?.redirect_uri ?? "openid://cb";

verifierStates.set(stateId, { callbackEndpoint });
payload = await this.addVPtokenRequestSpecificAttributes(stateId, payload, presentation_definition_id);
payload = await this.addVPtokenRequestSpecificAttributes(stateId, payload, presentationDefinition);
console.log("Payload = ", payload)
// const requestJwt = new SignJWT(payload)
// .setExpirationTime('30s');
Expand Down
2 changes: 2 additions & 0 deletions src/services/instances/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { VerifierConfigurationService } from "../../configuration/verifier/VerifierConfigurationService";
import { OpenidForCredentialIssuingAuthorizationServerService } from "../OpenidForCredentialIssuingAuthorizationServerService";
import { OpenidForPresentationsReceivingService } from "../OpenidForPresentationReceivingService";
import { appContainer } from "../inversify.config";


export const openidForCredentialIssuingAuthorizationServerService = appContainer.resolve(OpenidForCredentialIssuingAuthorizationServerService);
export const openidForPresentationReceivingService = appContainer.resolve(OpenidForPresentationsReceivingService);
export const verifierConfigurationService = appContainer.resolve(VerifierConfigurationService);
2 changes: 1 addition & 1 deletion src/services/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface OpenidForPresentationsReceivingInterface {



generateAuthorizationRequestURL(ctx: { req: Request, res: Response }, presentation_definition_id: string, directPostEndpoint?: string): Promise<{ url: URL; stateId: string }>;
generateAuthorizationRequestURL(ctx: { req: Request, res: Response }, presentationDefinition: object, directPostEndpoint?: string): Promise<{ url: URL; stateId: string }>;
getPresentationDefinitionHandler(ctx: { req: Request, res: Response }): Promise<void>;
getPresentationByState(state: string): Promise<{ status: boolean, presentationClaims?: PresentationClaims, rawPresentation?: string }>;
getPresentationById(id: string): Promise<{ status: boolean, presentationClaims?: PresentationClaims, rawPresentation?: string }>;
Expand Down
15 changes: 10 additions & 5 deletions src/verifier/verifierRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import locale from "../configuration/locale";
import * as qrcode from 'qrcode';
import config from "../../config";
import base64url from "base64url";
import { PresentationDefinitionTypeWithFormat } from "../configuration/verifier/VerifierConfigurationService";

const verifierRouter = Router();
// const verifiablePresentationRepository: Repository<VerifiablePresentationEntity> = AppDataSource.getRepository(VerifiablePresentationEntity);
Expand Down Expand Up @@ -117,7 +118,7 @@ verifierRouter.use('/public/definitions/presentation-request/:presentation_defin
});
}

const presentationDefinition = verifierConfiguration.getPresentationDefinitions().filter(pd => pd.id == presentation_definition_id)[0];
const presentationDefinition = JSON.parse(JSON.stringify(verifierConfiguration.getPresentationDefinitions().filter(pd => pd.id == presentation_definition_id)[0])) as PresentationDefinitionTypeWithFormat;
if (!presentationDefinition) {
return res.render('error', {
msg: "No presentation definition was found",
Expand All @@ -141,13 +142,17 @@ verifierRouter.use('/public/definitions/presentation-request/:presentation_defin
}
}));
// Filter existing paths to keep only those selected by the user and update presentationDefinition
const filteredConstraints = presentationDefinition.input_descriptors[0].constraints.fields.filter(field =>
selectedPaths.has(field.path.join(','))
const availableFields = presentationDefinition.input_descriptors[0].constraints.fields;
console.log("Available fields = ", availableFields)
const filteredFields = presentationDefinition.input_descriptors[0].constraints.fields.filter(field =>
selectedPaths.has(field.path[0])
);
presentationDefinition.input_descriptors[0].constraints.fields = filteredConstraints;

console.log("filtered fields = ", filteredFields)
presentationDefinition.input_descriptors[0].constraints.fields = filteredFields;
}

const { url } = await openidForPresentationReceivingService.generateAuthorizationRequestURL({req, res}, presentationDefinition.id, config.url + "/verifier/success");
const { url } = await openidForPresentationReceivingService.generateAuthorizationRequestURL({req, res}, presentationDefinition, config.url + "/verifier/success");
let authorizationRequestQR = await new Promise((resolve) => {
qrcode.toDataURL(url.toString(), {
margin: 1,
Expand Down
4 changes: 2 additions & 2 deletions views/verifier/selectable_presentation.pug
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ block layout-content
input(type='checkbox' id="personalIdentifier" name='fields' value='personalIdentifier')
label(for='personalIdentifier') Personal Identifier
.checkbox
input(type='checkbox' id="dateOfBirth" name='fields' value='dateOfBirth')
label(for='dateOfBirth') Date of Birth
input(type='checkbox' id="birthdate" name='fields' value='birthdate')
label(for='birthdate') Date of Birth
button.btn.btn-primary(type='submit') Present
link(rel="stylesheet" href="/styles/scan-qr-verifier.css")
Loading