src/issuer/oid4vci/oid4vci.controller.ts
vci
Methods |
|
credential | ||||||
credential(req: Request)
|
||||||
Decorators :
@Post('credential')
|
||||||
Defined in src/issuer/oid4vci/oid4vci.controller.ts:56
|
||||||
Endpoint to issue credentials
Parameters :
Returns :
Promise<CredentialResponse>
|
Async getOffer | |||||||||
getOffer(res: Response, body: OfferRequest)
|
|||||||||
Decorators :
@ApiResponse({description: 'JSON response', status: 201, type: OfferResponse, content: undefined})
|
|||||||||
Defined in src/issuer/oid4vci/oid4vci.controller.ts:34
|
|||||||||
Create an offer for a credential. This endpoint may be protected
Parameters :
Returns :
any
|
notifications | ||||||
notifications(body: any)
|
||||||
Decorators :
@Post('notification')
|
||||||
Defined in src/issuer/oid4vci/oid4vci.controller.ts:77
|
||||||
Notification endpoint
Parameters :
Returns :
{}
|
import { Body, Controller, Post, Req, Res, UseGuards } from '@nestjs/common';
import type { CredentialResponse } from '@openid4vc/openid4vci';
import type { Request, Response } from 'express';
import * as QRCode from 'qrcode';
import { Oid4vciService } from '../../issuer/oid4vci/oid4vci.service';
import { OfferRequest, OfferResponse } from './dto/offer-request.dto';
import { ResponseType } from '../../verifier/oid4vp/dto/presentation-request.dto';
import { ApiProduces, ApiResponse, ApiSecurity } from '@nestjs/swagger';
import { ApiKeyGuard } from '../../auth/api-key-guard';
@Controller('vci')
export class Oid4vciController {
constructor(private readonly oid4vciService: Oid4vciService) {}
/**
* Create an offer for a credential. This endpoint may be protected
* @param res
* @param body
*/
@ApiResponse({
description: 'JSON response',
status: 201,
//TODO: do not use type, otherwhise the response can not deal with both JSON and PNG.
type: OfferResponse,
content: {
'application/json': { schema: { type: 'object' } },
'image/png': { schema: { type: 'string', format: 'binary' } },
},
})
@ApiProduces('application/json', 'image/png')
@UseGuards(ApiKeyGuard)
@ApiSecurity('apiKey')
@Post('offer')
async getOffer(@Res() res: Response, @Body() body: OfferRequest) {
const values = await this.oid4vciService.createOffer(body);
if (body.response_type === ResponseType.QRCode) {
// Generate QR code as a PNG buffer
const qrCodeBuffer = await QRCode.toBuffer(values.uri);
// Set the response content type to image/png
res.setHeader('Content-Type', 'image/png');
// Send the QR code image as the response
res.send(qrCodeBuffer);
} else {
res.send(values);
}
}
/**
* Endpoint to issue credentials
* @param req
* @returns
*/
@Post('credential')
credential(@Req() req: Request): Promise<CredentialResponse> {
return this.oid4vciService.getCredential(req);
}
//TODO: this endpoint may be relevant for the wallet attestation.
/* @Get('session')
session() {
console.log('Session requested');
//TODO store session and created at
const session = randomUUID();
return {
session_id: session,
};
} */
/**
* Notification endpoint
* @param body
* @returns
*/
@Post('notification')
notifications(@Body() body: any) {
//TODO: not implemented in the wallet yet.
console.log('Notification received:');
console.log(body);
return [];
}
}