-
Notifications
You must be signed in to change notification settings - Fork 86
Feat/jwt vc jsonld #1646
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
Feat/jwt vc jsonld #1646
Changes from 4 commits
f268d48
4011757
03152e4
e931936
05b4fbb
70f9446
4afb9e1
40c0412
26d7b5c
0d1652e
6211dd0
2e05268
ae7e8ea
3a70c87
f73b179
f584dc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; | ||
| import { IsArray, IsNotEmpty, IsOptional, IsString } from 'class-validator'; | ||
|
|
||
| export class OidcResolveCredentialOfferDto { | ||
| @ApiProperty({ example: 'openid-credential-offer://?credential_offer_uri=...' }) | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| credentialOfferUri: string; | ||
| } | ||
|
|
||
| export class OidcRequestCredentialDto { | ||
| @ApiProperty({ example: 'openid-credential-offer://?credential_offer_uri=...' }) | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| credentialOfferUri: string; | ||
|
|
||
| @ApiProperty({ example: ['UniversityDegree'] }) | ||
| @IsArray() | ||
| @IsNotEmpty() | ||
| credentialsToRequest: string[]; | ||
|
|
||
| @ApiPropertyOptional({ example: '1234' }) | ||
| @IsString() | ||
| @IsOptional() | ||
| txCode?: string; | ||
| } | ||
|
|
||
| export class OidcResolveProofRequestDto { | ||
| @ApiProperty({ example: 'openid-vc-request://?request_uri=...' }) | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| proofRequestUri: string; | ||
| } | ||
|
|
||
| export class OidcAcceptProofRequestDto { | ||
| @ApiProperty({ example: 'openid-vc-request://?request_uri=...' }) | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| proofRequestUri: string; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import { Controller, Post, Body, UseGuards, HttpStatus, Res, Param, UseFilters, Logger } from '@nestjs/common'; | ||
| import { | ||
| ApiTags, | ||
| ApiOperation, | ||
| ApiResponse, | ||
| ApiBearerAuth, | ||
| ApiForbiddenResponse, | ||
| ApiUnauthorizedResponse | ||
| } from '@nestjs/swagger'; | ||
| import { AuthGuard } from '@nestjs/passport'; | ||
| import { ApiResponseDto } from '../dtos/apiResponse.dto'; | ||
| import { UnauthorizedErrorDto } from '../dtos/unauthorized-error.dto'; | ||
| import { ForbiddenErrorDto } from '../dtos/forbidden-error.dto'; | ||
| import { Response } from 'express'; | ||
| import { IResponse } from '@credebl/common/interfaces/response.interface'; | ||
| import { Roles } from '../authz/decorators/roles.decorator'; | ||
| import { OrgRoles } from 'libs/org-roles/enums'; | ||
| import { OrgRolesGuard } from '../authz/guards/org-roles.guard'; | ||
| import { CustomExceptionFilter } from 'apps/api-gateway/common/exception-handler'; | ||
| import { Oid4vcHolderService } from './oid4vc-holder.service'; | ||
| import { | ||
| OidcAcceptProofRequestDto, | ||
| OidcRequestCredentialDto, | ||
| OidcResolveCredentialOfferDto, | ||
| OidcResolveProofRequestDto | ||
| } from './dtos/oid4vc-holder.dto'; | ||
|
|
||
| @Controller('orgs/:orgId/oid4vc/holder') | ||
| @UseFilters(CustomExceptionFilter) | ||
| @ApiTags('OID4VC-Holder') | ||
| @ApiUnauthorizedResponse({ description: 'Unauthorized', type: UnauthorizedErrorDto }) | ||
| @ApiForbiddenResponse({ description: 'Forbidden', type: ForbiddenErrorDto }) | ||
| export class Oid4vcHolderController { | ||
| private readonly logger = new Logger('Oid4vcHolderController'); | ||
| constructor(private readonly oid4vcHolderService: Oid4vcHolderService) {} | ||
|
|
||
| @Post('resolve-credential-offer') | ||
| @ApiOperation({ | ||
| summary: 'Resolve OID4VC Credential Offer', | ||
| description: 'Resolves an OID4VC credential offer for the specified organization.' | ||
| }) | ||
| @ApiResponse({ status: HttpStatus.OK, description: 'Credential offer resolved successfully.', type: ApiResponseDto }) | ||
| @ApiBearerAuth() | ||
| @Roles(OrgRoles.OWNER) | ||
| @UseGuards(AuthGuard('jwt'), OrgRolesGuard) | ||
| async oidcHolderResolveCredentialOffer( | ||
| @Param('orgId') orgId: string, | ||
| @Body() resolveDto: OidcResolveCredentialOfferDto, | ||
| @Res() res: Response | ||
| ): Promise<Response> { | ||
| const data = await this.oid4vcHolderService.oidcHolderResolveCredentialOffer(orgId, resolveDto); | ||
| const finalResponse: IResponse = { | ||
| statusCode: HttpStatus.OK, | ||
| message: 'Credential offer resolved successfully.', | ||
| data | ||
| }; | ||
| return res.status(HttpStatus.OK).json(finalResponse); | ||
| } | ||
|
|
||
| @Post('request-credential') | ||
| @ApiOperation({ | ||
| summary: 'Request OID4VC Credential', | ||
| description: 'Requests and stores an OID4VC credential for the specified organization.' | ||
| }) | ||
| @ApiResponse({ status: HttpStatus.OK, description: 'Credential requested successfully.', type: ApiResponseDto }) | ||
| @ApiBearerAuth() | ||
| @Roles(OrgRoles.OWNER) | ||
| @UseGuards(AuthGuard('jwt'), OrgRolesGuard) | ||
| async oidcHolderRequestCredential( | ||
| @Param('orgId') orgId: string, | ||
| @Body() requestDto: OidcRequestCredentialDto, | ||
| @Res() res: Response | ||
| ): Promise<Response> { | ||
| const data = await this.oid4vcHolderService.oidcHolderRequestCredential(orgId, requestDto); | ||
| const finalResponse: IResponse = { | ||
| statusCode: HttpStatus.OK, | ||
| message: 'Credential requested successfully.', | ||
| data | ||
| }; | ||
| return res.status(HttpStatus.OK).json(finalResponse); | ||
| } | ||
|
|
||
| @Post('resolve-proof-request') | ||
| @ApiOperation({ | ||
| summary: 'Resolve OID4VC Proof Request', | ||
| description: 'Resolves an OID4VC proof request for the specified organization.' | ||
| }) | ||
| @ApiResponse({ status: HttpStatus.OK, description: 'Proof request resolved successfully.', type: ApiResponseDto }) | ||
| @ApiBearerAuth() | ||
| @Roles(OrgRoles.OWNER) | ||
| @UseGuards(AuthGuard('jwt'), OrgRolesGuard) | ||
| async oidcHolderResolveProofRequest( | ||
| @Param('orgId') orgId: string, | ||
| @Body() resolveDto: OidcResolveProofRequestDto, | ||
| @Res() res: Response | ||
| ): Promise<Response> { | ||
| const data = await this.oid4vcHolderService.oidcHolderResolveProofRequest(orgId, resolveDto); | ||
| const finalResponse: IResponse = { | ||
| statusCode: HttpStatus.OK, | ||
| message: 'Proof request resolved successfully.', | ||
| data | ||
| }; | ||
| return res.status(HttpStatus.OK).json(finalResponse); | ||
| } | ||
|
|
||
| @Post('accept-proof-request') | ||
| @ApiOperation({ | ||
| summary: 'Accept OID4VC Proof Request', | ||
| description: 'Accepts an OID4VC proof request for the specified organization.' | ||
| }) | ||
| @ApiResponse({ status: HttpStatus.OK, description: 'Proof request accepted successfully.', type: ApiResponseDto }) | ||
| @ApiBearerAuth() | ||
| @Roles(OrgRoles.OWNER) | ||
| @UseGuards(AuthGuard('jwt'), OrgRolesGuard) | ||
| async oidcHolderAcceptProofRequest( | ||
| @Param('orgId') orgId: string, | ||
| @Body() acceptDto: OidcAcceptProofRequestDto, | ||
| @Res() res: Response | ||
| ): Promise<Response> { | ||
| const data = await this.oid4vcHolderService.oidcHolderAcceptProofRequest(orgId, acceptDto); | ||
| const finalResponse: IResponse = { | ||
| statusCode: HttpStatus.OK, | ||
| message: 'Proof request accepted successfully.', | ||
| data | ||
| }; | ||
| return res.status(HttpStatus.OK).json(finalResponse); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { Module } from '@nestjs/common'; | ||
| import { NATSClient } from '@credebl/common/NATSClient'; | ||
| import { getNatsOptions } from '@credebl/common/nats.config'; | ||
| import { CommonConstants } from '@credebl/common/common.constant'; | ||
| import { ClientsModule, Transport } from '@nestjs/microservices'; | ||
| import { HttpModule } from '@nestjs/axios'; | ||
| import { Oid4vcHolderController } from './oid4vc-holder.controller'; | ||
| import { Oid4vcHolderService } from './oid4vc-holder.service'; | ||
|
|
||
| @Module({ | ||
| imports: [ | ||
| HttpModule, | ||
| ClientsModule.register([ | ||
| { | ||
| name: 'NATS_CLIENT', | ||
| transport: Transport.NATS, | ||
| options: getNatsOptions( | ||
| CommonConstants.OIDC4VC_HOLDER_SERVICE, | ||
| process.env.API_GATEWAY_NKEY_SEED, | ||
| process.env.NATS_CREDS_FILE | ||
| ) | ||
| } | ||
| ]) | ||
| ], | ||
| controllers: [Oid4vcHolderController], | ||
| providers: [Oid4vcHolderService, NATSClient] | ||
| }) | ||
| export class Oid4vcHolderModule {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { NATSClient } from '@credebl/common/NATSClient'; | ||
| import { Inject, Injectable } from '@nestjs/common'; | ||
| import { ClientProxy } from '@nestjs/microservices'; | ||
| import { BaseService } from 'libs/service/base.service'; | ||
| import { | ||
| OidcAcceptProofRequestDto, | ||
| OidcRequestCredentialDto, | ||
| OidcResolveCredentialOfferDto, | ||
| OidcResolveProofRequestDto | ||
| } from './dtos/oid4vc-holder.dto'; | ||
|
|
||
| @Injectable() | ||
| export class Oid4vcHolderService extends BaseService { | ||
| constructor( | ||
| @Inject('NATS_CLIENT') private readonly holderProxy: ClientProxy, | ||
| private readonly natsClient: NATSClient | ||
| ) { | ||
| super('Oid4vcHolderService'); | ||
| } | ||
|
|
||
| async oidcHolderResolveCredentialOffer(orgId: string, holderPayload: OidcResolveCredentialOfferDto): Promise<object> { | ||
| const payload = { orgId, holderPayload }; | ||
| return this.natsClient.sendNatsMessage(this.holderProxy, 'oid4vc-holder-resolve-credential-offer', payload); | ||
| } | ||
|
|
||
| async oidcHolderRequestCredential(orgId: string, holderPayload: OidcRequestCredentialDto): Promise<object> { | ||
| const payload = { orgId, holderPayload }; | ||
| return this.natsClient.sendNatsMessage(this.holderProxy, 'oid4vc-holder-request-credential', payload); | ||
| } | ||
|
|
||
| async oidcHolderResolveProofRequest(orgId: string, holderPayload: OidcResolveProofRequestDto): Promise<object> { | ||
| const payload = { orgId, holderPayload }; | ||
| return this.natsClient.sendNatsMessage(this.holderProxy, 'oid4vc-holder-resolve-proof-request', payload); | ||
| } | ||
|
|
||
| async oidcHolderAcceptProofRequest(orgId: string, holderPayload: OidcAcceptProofRequestDto): Promise<object> { | ||
| const payload = { orgId, holderPayload }; | ||
| return this.natsClient.sendNatsMessage(this.holderProxy, 'oid4vc-holder-accept-proof-request', payload); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -196,6 +196,14 @@ export class SdJwtTemplateDto { | |||||||||||||||||||||||||||||||
| @IsString() | ||||||||||||||||||||||||||||||||
| vct: string; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @ApiPropertyOptional({ | ||||||||||||||||||||||||||||||||
| example: ['https://www.w3.org/2018/credentials/v1', 'https://json-ld.org/contexts/person.jsonld'], | ||||||||||||||||||||||||||||||||
| description: 'JSON-LD context for the credential (optional, defaults to person schema for JSON-LD format)' | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| @IsArray() | ||||||||||||||||||||||||||||||||
| @IsOptional() | ||||||||||||||||||||||||||||||||
| context?: string[]; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
Comment on lines
+199
to
+206
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add element-level string validation for The Proposed fix `@ApiPropertyOptional`({
example: ['https://www.w3.org/2018/credentials/v1', 'https://json-ld.org/contexts/person.jsonld'],
description: 'JSON-LD context for the credential (optional, defaults to person schema for JSON-LD format)'
})
`@IsArray`()
+ `@IsString`({ each: true })
`@IsOptional`()
context?: string[];📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not expose or accept the context array directly from the user in the DTO. Instead, the backend automatically constructs it internally from the schemaUrl (which is strictly validated as a string via @IsString()) and a default constant. Therefore, this issue is already mitigated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||
| @ApiProperty({ | ||||||||||||||||||||||||||||||||
| type: 'array', | ||||||||||||||||||||||||||||||||
| items: { $ref: getSchemaPath(CredentialAttributeDto) }, | ||||||||||||||||||||||||||||||||
|
|
@@ -229,8 +237,11 @@ export class CreateCredentialTemplateDto { | |||||||||||||||||||||||||||||||
| @IsEnum(CredentialFormat) | ||||||||||||||||||||||||||||||||
| format: CredentialFormat; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @ValidateIf((o: CreateCredentialTemplateDto) => CredentialFormat.SdJwtVc === o.format) | ||||||||||||||||||||||||||||||||
| @IsEmpty({ message: 'doctype must not be provided when format is "dc+sd-jwt"' }) | ||||||||||||||||||||||||||||||||
| @ValidateIf( | ||||||||||||||||||||||||||||||||
| (o: CreateCredentialTemplateDto) => | ||||||||||||||||||||||||||||||||
| CredentialFormat.SdJwtVc === o.format || CredentialFormat.JwtVcJsonLd === o.format | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
Comment on lines
+240
to
+245
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the lint-blocking The current multiline arrow predicate triggers the ESLint Proposed fix- `@ValidateIf`(
- (o: CreateCredentialTemplateDto) =>
- CredentialFormat.SdJwtVc === o.format || CredentialFormat.JwtVcJsonLd === o.format
- )
+ `@ValidateIf`(
+ (o: CreateCredentialTemplateDto) =>
+ CredentialFormat.SdJwtVc === o.format || CredentialFormat.JwtVcJsonLd === o.format
+ )🧰 Tools🪛 ESLint[error] 234-234: Expected no linebreak before this expression. (implicit-arrow-linebreak) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| @IsEmpty({ message: 'doctype must not be provided when format is "dc+sd-jwt" or "jwt_vc_json-ld"' }) | ||||||||||||||||||||||||||||||||
| readonly _doctypeAbsentGuard?: unknown; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @ValidateIf((o: CreateCredentialTemplateDto) => CredentialFormat.Mdoc === o.format) | ||||||||||||||||||||||||||||||||
|
|
@@ -246,7 +257,7 @@ export class CreateCredentialTemplateDto { | |||||||||||||||||||||||||||||||
| @Type(({ object }) => { | ||||||||||||||||||||||||||||||||
| if (object.format === CredentialFormat.Mdoc) { | ||||||||||||||||||||||||||||||||
| return MdocTemplateDto; | ||||||||||||||||||||||||||||||||
| } else if (object.format === CredentialFormat.SdJwtVc) { | ||||||||||||||||||||||||||||||||
| } else if (object.format === CredentialFormat.SdJwtVc || object.format === CredentialFormat.JwtVcJsonLd) { | ||||||||||||||||||||||||||||||||
| return SdJwtTemplateDto; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| export interface IOidcHolderResolveCredentialOffer { | ||
| credentialOfferUri: string; | ||
| } | ||
|
|
||
| export interface IOidcHolderRequestCredential { | ||
| credentialOfferUri: string; | ||
| credentialsToRequest: string[]; | ||
| txCode?: string; | ||
| } | ||
|
|
||
| export interface IOidcHolderResolveProofRequest { | ||
| proofRequestUri: string; | ||
| } | ||
|
|
||
| export interface IOidcHolderAcceptProofRequest { | ||
| proofRequestUri: string; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { NestFactory } from '@nestjs/core'; | ||
| import { HttpExceptionFilter } from 'libs/http-exception.filter'; | ||
| import { Logger } from '@nestjs/common'; | ||
| import { MicroserviceOptions, Transport } from '@nestjs/microservices'; | ||
| import { getNatsOptions } from '@credebl/common/nats.config'; | ||
| import { CommonConstants } from '@credebl/common/common.constant'; | ||
| import NestjsLoggerServiceAdapter from '@credebl/logger/nestjsLoggerServiceAdapter'; | ||
| import { Oid4vcHolderModule } from './oid4vc-holder.module'; | ||
|
|
||
| const logger = new Logger(); | ||
|
|
||
| async function bootstrap(): Promise<void> { | ||
| const app = await NestFactory.createMicroservice<MicroserviceOptions>(Oid4vcHolderModule, { | ||
| transport: Transport.NATS, | ||
| options: getNatsOptions( | ||
| CommonConstants.OIDC4VC_HOLDER_SERVICE, | ||
| process.env.OIDC4VC_HOLDER_NKEY_SEED, | ||
| process.env.NATS_CREDS_FILE | ||
| ) | ||
| }); | ||
| app.useLogger(app.get(NestjsLoggerServiceAdapter)); | ||
| app.useGlobalFilters(new HttpExceptionFilter()); | ||
|
|
||
| await app.listen(); | ||
| logger.log('OID4VC-Holder-Service Microservice is listening to NATS '); | ||
| } | ||
| bootstrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: credebl/platform
Length of output: 103
🏁 Script executed:
Repository: credebl/platform
Length of output: 1409
🏁 Script executed:
Repository: credebl/platform
Length of output: 259
🏁 Script executed:
Repository: credebl/platform
Length of output: 1145
🏁 Script executed:
Repository: credebl/platform
Length of output: 8010
🏁 Script executed:
Repository: credebl/platform
Length of output: 351
🏁 Script executed:
Repository: credebl/platform
Length of output: 2143
🏁 Script executed:
Repository: credebl/platform
Length of output: 157
🏁 Script executed:
Repository: credebl/platform
Length of output: 12291
🏁 Script executed:
Repository: credebl/platform
Length of output: 5729
credentialsToRequestvalidation is too weak for the request contract.@IsNotEmpty()only guarantees the array itself isn’t empty; it doesn’t validate that each entry is a non-empty string, so invalid/empty members can reach the holder flow.Suggested fix
🤖 Prompt for AI Agents