Skip to content

Commit 92a9e36

Browse files
RinkalBhojanitipusinghaw
authored andcommitted
fix: refactored code
Signed-off-by: Rinkal Bhojani <[email protected]>
1 parent 24f835c commit 92a9e36

File tree

15 files changed

+45
-42
lines changed

15 files changed

+45
-42
lines changed

apps/api-gateway/src/oid4vc-issuance/dtos/oid4vc-credential-wh.dto.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,3 @@ export function extractCredentialConfigurationIds(payload: Partial<OidcIssueCred
7171
const cfg = payload?.credentialOfferPayload?.credential_configuration_ids;
7272
return Array.isArray(cfg) ? cfg : [];
7373
}
74-
75-
export function sanitizeOidcIssueCredentialDto(
76-
payload: Partial<OidcIssueCredentialDto>
77-
): Partial<OidcIssueCredentialDto> {
78-
const ids = extractCredentialConfigurationIds(payload);
79-
return {
80-
...payload,
81-
credentialOfferPayload: {
82-
// eslint-disable-next-line camelcase
83-
credential_configuration_ids: ids
84-
}
85-
};
86-
}

apps/api-gateway/src/oid4vc-issuance/oid4vc-issuance.controller.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { CustomExceptionFilter } from 'apps/api-gateway/common/exception-handler
4646
import { user } from '@prisma/client';
4747
import { IssuerCreationDto, IssuerUpdationDto } from './dtos/oid4vc-issuer.dto';
4848
import { CreateCredentialTemplateDto, UpdateCredentialTemplateDto } from './dtos/oid4vc-issuer-template.dto';
49-
import { OidcIssueCredentialDto, sanitizeOidcIssueCredentialDto } from './dtos/oid4vc-credential-wh.dto';
49+
import { OidcIssueCredentialDto } from './dtos/oid4vc-credential-wh.dto';
5050
import { Oid4vcIssuanceService } from './oid4vc-issuance.service';
5151
import {
5252
CreateCredentialOfferD2ADto,
@@ -428,7 +428,7 @@ export class Oid4vcIssuanceController {
428428
@User() user: user,
429429
@Res() res: Response
430430
): Promise<Response> {
431-
await this.oid4vcIssuanceService.deleteTemplate(user, orgId, templateId);
431+
await this.oid4vcIssuanceService.deleteTemplate(user, orgId, templateId, issuerId);
432432
const finalResponse: IResponse = {
433433
statusCode: HttpStatus.OK,
434434
message: ResponseMessages.oidcTemplate.success.delete
@@ -636,7 +636,7 @@ export class Oid4vcIssuanceController {
636636
if (id && 'default' === oidcIssueCredentialDto.contextCorrelationId) {
637637
oidcIssueCredentialDto.orgId = id;
638638
}
639-
// const sanitized = sanitizeOidcIssueCredentialDto(oidcIssueCredentialDto);
639+
640640
const getCredentialDetails = await this.oid4vcIssuanceService.oidcIssueCredentialWebhook(
641641
oidcIssueCredentialDto,
642642
id
@@ -653,9 +653,8 @@ export class Oid4vcIssuanceController {
653653
.catch((error) => {
654654
this.logger.debug(`error in getting webhook url ::: ${JSON.stringify(error)}`);
655655
});
656-
console.log(`webhookUrl `, webhookUrl);
657656
if (webhookUrl) {
658-
console.log(`Org webhook found `, JSON.stringify(webhookUrl), JSON.stringify(oidcIssueCredentialDto));
657+
this.logger.log(`Posting response to the webhook url`);
659658
const plainIssuanceDto = JSON.parse(JSON.stringify(oidcIssueCredentialDto));
660659

661660
await this.oid4vcIssuanceService._postWebhookResponse(webhookUrl, { data: plainIssuanceDto }).catch((error) => {

apps/api-gateway/src/oid4vc-issuance/oid4vc-issuance.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export class Oid4vcIssuanceService extends BaseService {
5353
return this.natsClient.sendNatsMessage(this.issuanceProxy, 'oid4vc-delete-issuer', payload);
5454
}
5555

56-
async deleteTemplate(userDetails: user, orgId: string, templateId: string): Promise<object> {
57-
const payload = { templateId, orgId, userDetails };
56+
async deleteTemplate(userDetails: user, orgId: string, templateId: string, issuerId: string): Promise<object> {
57+
const payload = { templateId, orgId, userDetails, issuerId };
5858
return this.natsClient.sendNatsMessage(this.issuanceProxy, 'oid4vc-template-delete', payload);
5959
}
6060

apps/api-gateway/src/oid4vc-verification/oid4vc-verification.controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class Oid4vcVerificationController {
7171
summary: 'Create OID4VP verifier',
7272
description: 'Creates a new OID4VP verifier for the specified organization.'
7373
})
74-
@ApiResponse({ status: HttpStatus.OK, description: 'Verifier created successfully.', type: ApiResponseDto })
74+
@ApiResponse({ status: HttpStatus.CREATED, description: 'Verifier created successfully.', type: ApiResponseDto })
7575
@ApiBearerAuth()
7676
@Roles(OrgRoles.OWNER)
7777
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@@ -151,7 +151,7 @@ export class Oid4vcVerificationController {
151151
message: ResponseMessages.oid4vp.success.update,
152152
data: updateVerifierRes
153153
};
154-
return res.status(HttpStatus.CREATED).json(finalResponse);
154+
return res.status(HttpStatus.OK).json(finalResponse);
155155
}
156156

157157
@Get('/orgs/:orgId/oid4vp/verifier')
@@ -242,7 +242,7 @@ export class Oid4vcVerificationController {
242242
this.logger.debug(`[deleteVerifierDetails] Deleted verifier: ${verifierId}`);
243243
const finalResponse: IResponse = {
244244
statusCode: HttpStatus.OK,
245-
message: ResponseMessages.oid4vp.success.fetch,
245+
message: ResponseMessages.oid4vp.success.delete,
246246
data: verifierDetails
247247
};
248248
return res.status(HttpStatus.OK).json(finalResponse);

apps/api-gateway/src/x509/dtos/x509.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export class BasicX509CreateCertificateConfig {
306306

307307
@ApiPropertyOptional({ type: () => AuthorityAndSubjectKeyDto })
308308
@IsOptional()
309-
@ValidateNested({ each: true })
309+
@ValidateNested()
310310
@Type(() => AuthorityAndSubjectKeyDto)
311311
subjectKey?: AuthorityAndSubjectKeyDto;
312312
}

apps/api-gateway/src/x509/x509.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export class X509Service extends BaseService {
3333
reqUser: user
3434
): Promise<X509CertificateRecord> {
3535
this.logger.log(`Start creating x509 certficate`);
36-
this.logger.debug(`payload : `, createDto, reqUser);
3736
const payload = { options: createDto, user: reqUser, orgId };
3837
return this.natsClient.sendNatsMessage(this.serviceProxy, 'create-x509-certificate', payload);
3938
}

apps/oid4vc-issuance/libs/helpers/credential-sessions.builder.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,22 @@ function buildSdJwtCredential(
282282
const templateSignerOption: SignerOption = signerOptions.find(
283283
(x) => templateRecord.signerOption.toLowerCase() === x.method
284284
);
285+
if (!templateSignerOption) {
286+
throw new UnprocessableEntityException(
287+
`Signer option "${templateRecord.signerOption}" is not configured for template ${templateRecord.id}`
288+
);
289+
}
285290

286291
if (templateRecord.signerOption === SignerMethodOption.X5C && credentialRequest.validityInfo) {
287-
const certificateDetail = activeCertificateDetails.find((x) => x.certificateBase64 === templateSignerOption.x5c[0]);
292+
if (!activeCertificateDetails?.length) {
293+
throw new UnprocessableEntityException('Active x.509 certificate details are required for x5c signer templates.');
294+
}
295+
const certificateDetail = activeCertificateDetails.find(
296+
(x) => x.certificateBase64 === templateSignerOption.x5c?.[0]
297+
);
298+
if (!certificateDetail) {
299+
throw new UnprocessableEntityException('No active x.509 certificate matches the configured signer option.');
300+
}
288301

289302
const validationResult = validateCredentialDatesInCertificateWindow(
290303
credentialRequest.validityInfo,
@@ -349,7 +362,17 @@ function buildMdocCredential(
349362
) {
350363
throw new UnprocessableEntityException(`${ResponseMessages.oidcIssuerSession.error.missingValidityInfo}`);
351364
}
365+
366+
if (!signerOptions?.length || !signerOptions[0].x5c?.length) {
367+
throw new UnprocessableEntityException('An x5c signer configuration is required for mdoc credentials.');
368+
}
369+
if (!activeCertificateDetails?.length) {
370+
throw new UnprocessableEntityException('Active x.509 certificate details are required for mdoc credentials.');
371+
}
352372
const certificateDetail = activeCertificateDetails.find((x) => x.certificateBase64 === signerOptions[0].x5c[0]);
373+
if (!certificateDetail) {
374+
throw new UnprocessableEntityException('No active x.509 certificate matches the configured signer option.');
375+
}
353376
const validationResult = validateCredentialDatesInCertificateWindow(
354377
credentialRequest.validityInfo,
355378
certificateDetail

apps/oid4vc-issuance/libs/helpers/issuer.metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export function buildIssuerPayload(
174174
return {
175175
display,
176176
dpopSigningAlgValuesSupported: opts?.dpopAlgs ?? [...ISSUER_DPOP_ALGS_DEFAULT],
177-
credentialConfigurationsSupported: credentialConfigurations.credentialConfigurationsSupported ?? [],
177+
credentialConfigurationsSupported: credentialConfigurations.credentialConfigurationsSupported ?? {},
178178
batchCredentialIssuance: {
179179
batchSize: oidcIssuer?.batchCredentialIssuanceSize ?? batchCredentialIssuanceDefault
180180
}

apps/oid4vc-issuance/src/oid4vc-issuance.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export class Oid4vcIssuanceService {
200200
async oidcIssuerGetById(id: string, orgId: string): Promise<IssuerResponse> {
201201
try {
202202
const getIssuerDetails = await this.oid4vcIssuanceRepository.getOidcIssuerDetailsById(id);
203-
if (!getIssuerDetails && getIssuerDetails.publicIssuerId) {
203+
if (!getIssuerDetails && !getIssuerDetails.publicIssuerId) {
204204
throw new NotFoundException(ResponseMessages.oidcIssuer.error.notFound);
205205
}
206206
const agentDetails = await this.oid4vcIssuanceRepository.getAgentEndPoint(orgId);
@@ -533,6 +533,9 @@ export class Oid4vcIssuanceService {
533533
}
534534

535535
const agentDetails = await this.oid4vcIssuanceRepository.getAgentEndPoint(orgId);
536+
if (!agentDetails) {
537+
throw new NotFoundException(ResponseMessages.issuance.error.agentEndPointNotFound);
538+
}
536539
//TDOD: signerOption should be under credentials change this with x509 support
537540

538541
//TDOD: signerOption should be under credentials change this with x509 support

apps/oid4vc-verification/src/oid4vc-verification.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ export class Oid4vpVerificationService extends BaseService {
283283
}
284284
}
285285

286-
async getVerifierSession(orgId: string, query?: VerificationSessionQuery): Promise<object> {
286+
async getVerifierSession(orgId: string, query: VerificationSessionQuery): Promise<object> {
287287
this.logger.debug(`[getVerifierSession] called for orgId=${orgId}, potentially with a query`);
288288
try {
289289
const agentDetails = await this.oid4vpRepository.getAgentEndPoint(orgId);

0 commit comments

Comments
 (0)