Skip to content

Commit

Permalink
Merge pull request #53 from wwWallet/display-verification-timestamp
Browse files Browse the repository at this point in the history
exported verification timestamp
  • Loading branch information
kkmanos authored Jul 3, 2024
2 parents 315566e + 607baa1 commit ae63dbe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
7 changes: 1 addition & 6 deletions src/entities/VerifiablePresentation.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
import { VerifiableCredentialFormat } from "../types/oid4vci";

export enum VerificationStatus {
REVOKED,
Expand Down Expand Up @@ -84,16 +83,12 @@ export class VerifiablePresentationEntity {
return null;
}

@Column({ name: "date", type: "date", nullable: true })
@Column({ name: "date", type: "datetime", nullable: true })
date?: Date;

@Column({ name: "format", type: "enum", enum: VerifiableCredentialFormat, nullable: true })
format?: VerifiableCredentialFormat;

@Column({ name: "status", type: "boolean", nullable: true })
status?: boolean;


@Column({ name: "state", type: "varchar", nullable: true })
state?: string;
}
4 changes: 2 additions & 2 deletions src/services/OpenidForPresentationReceivingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ export class OpenidForPresentationsReceivingService implements OpenidForPresenta
}


public async getPresentationByState(state: string): Promise<{ status: boolean, presentationClaims?: PresentationClaims, rawPresentation?: string }> {
public async getPresentationByState(state: string): Promise<{ status: true, vp: VerifiablePresentationEntity } | { status: false }> {
const vp = await this.verifiablePresentationRepository.createQueryBuilder('vp')
.where("state = :state", { state: state })
.getOne();
Expand All @@ -479,7 +479,7 @@ export class OpenidForPresentationsReceivingService implements OpenidForPresenta
}

if (vp)
return { status: true, presentationClaims: vp.claims, rawPresentation: vp?.raw_presentation };
return { status: true, vp };
else
return { status: false };
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { OpenidForPresentationsConfiguration } from "./types/OpenidForPresentati
import 'reflect-metadata';
import { AuthorizationDetailsSchemaType, CredentialSupported, GrantType } from "../types/oid4vci";
import { CredentialIssuersRepository } from "../lib/CredentialIssuersRepository";
import { PresentationClaims } from "../entities/VerifiablePresentation.entity";
import { PresentationClaims, VerifiablePresentationEntity } from "../entities/VerifiablePresentation.entity";

export interface CredentialSigner {
sign(payload: any, headers: JWTHeaderParameters | {}, disclosureFrame: any | undefined): Promise<{ jws: string }>;
Expand Down Expand Up @@ -37,7 +37,7 @@ export interface OpenidForPresentationsReceivingInterface {

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 }>;
getPresentationByState(state: string): Promise<{ status: true, vp: VerifiablePresentationEntity } | { status: false }>;
getPresentationById(id: string): Promise<{ status: boolean, presentationClaims?: PresentationClaims, rawPresentation?: string }>;

/**
Expand Down
21 changes: 13 additions & 8 deletions src/verifier/verifierRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,20 @@ verifierRouter.get('/public/definitions', async (req, res) => {

verifierRouter.get('/success/status', async (req, res) => { // response with the status of the presentation (this endpoint should be protected)
const state = req.query.state;
const {status, presentationClaims, rawPresentation } = await openidForPresentationReceivingService.getPresentationByState(state as string);
if (!presentationClaims) {
const result = await openidForPresentationReceivingService.getPresentationByState(state as string);
if (!result.status) {
return res.send({ status: false, error: "Presentation not received" });
}
return res.send({ status, presentationClaims, presentation: rawPresentation });
return res.send({ status: result.status, presentationClaims: result.vp.claims, presentation: result.vp.raw_presentation });
})

verifierRouter.get('/success', async (req, res) => {
const state = req.query.state;
const {status, presentationClaims, rawPresentation } = await openidForPresentationReceivingService.getPresentationByState(state as string);
if (!presentationClaims || !rawPresentation) {
const result = await openidForPresentationReceivingService.getPresentationByState(state as string);
if (result.status == false ||
result.vp.raw_presentation == null ||
result.vp.claims == null ||
result.vp.date == null) {
return res.render('error.pug', {
msg: "Failed to get presentation",
code: 0,
Expand All @@ -73,8 +76,9 @@ verifierRouter.get('/success', async (req, res) => {
})
}


const presentationPayload = JSON.parse(base64url.decode(rawPresentation.split('.')[1])) as any;
const { status, raw_presentation, claims, date } = result.vp;

const presentationPayload = JSON.parse(base64url.decode(raw_presentation.split('.')[1])) as any;
const credentials = await Promise.all(presentationPayload.vp.verifiableCredential.map(async (vcString: any) => {
if (vcString.includes('~')) {
return SdJwt.fromCompact<Record<string, unknown>, any>(vcString)
Expand All @@ -93,7 +97,8 @@ verifierRouter.get('/success', async (req, res) => {
lang: req.lang,
locale: locale[req.lang],
status: status,
presentationClaims: presentationClaims,
verificationTimestamp: date.toISOString(),
presentationClaims: claims,
credentialPayloads: credentials,
})
})
Expand Down

0 comments on commit ae63dbe

Please sign in to comment.