Skip to content

Commit 861d3d6

Browse files
authored
feat: notice URL support for issuance (#1593)
* feat: notice URL support for issuance Signed-off-by: Tipu_Singh <tipu.singh@ayanworks.com> * feat: added logic to update notice url in update template Signed-off-by: Tipu_Singh <tipu.singh@ayanworks.com> * refactor: resolved coderabbitai suggestions Signed-off-by: Tipu_Singh <tipu.singh@ayanworks.com> --------- Signed-off-by: Tipu_Singh <tipu.singh@ayanworks.com>
1 parent 6f7da22 commit 861d3d6

7 files changed

Lines changed: 47 additions & 6 deletions

File tree

apps/api-gateway/src/oid4vc-issuance/dtos/issuer-sessions.dto.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ export class CreateOidcCredentialOfferDto {
186186
@IsIn(['preAuthorizedCodeFlow', 'authorizationCodeFlow'])
187187
authorizationType!: 'preAuthorizedCodeFlow' | 'authorizationCodeFlow';
188188

189+
@ApiPropertyOptional({
190+
example: 'https://dev-consent.sovio.id/api/consent-notice/CN-OGL70CWB',
191+
description: 'Optional notice URL to attach in the response when multiple credentials are offered.'
192+
})
193+
@IsOptional()
194+
@IsUrl()
195+
noticeUrl?: string;
196+
189197
issuerId?: string;
190198
}
191199

apps/api-gateway/src/oid4vc-issuance/dtos/oid4vc-issuer-template.dto.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ export class CreateCredentialTemplateDto {
282282
@Type(() => AppearanceDto)
283283
appearance?: AppearanceDto;
284284

285+
@ApiPropertyOptional({
286+
example: 'https://dev-consent.sovio.id/api/consent-notice/CN-OGL70CWB',
287+
description: 'Optional consent notice URL associated with this credential template'
288+
})
289+
@IsOptional()
290+
@IsString()
291+
noticeUrl?: string;
292+
285293
issuerId: string;
286294
}
287295

apps/oid4vc-issuance/interfaces/oid4vc-issuer-sessions.interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface CreateOidcCredentialOffer {
4747
// e.g. "abc-gov"
4848
authenticationType: AuthenticationType; // only option selector
4949
credentials: CredentialRequest[]; // one or more credentials
50+
noticeUrl?: string;
5051
}
5152

5253
export interface GetAllCredentialOffer {

apps/oid4vc-issuance/interfaces/oid4vc-template.interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface CreateCredentialTemplate {
2222
appearance?: Prisma.JsonValue;
2323
issuerId: string;
2424
template: SdJwtTemplate | MdocTemplate;
25+
noticeUrl?: string;
2526
}
2627

2728
export interface UpdateCredentialTemplate extends Partial<CreateCredentialTemplate> {}

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ export class Oid4vcIssuanceService {
309309
): Promise<credential_templates> {
310310
try {
311311
//TODO: add revert mechanism if agent call fails
312-
const { name, description, format, canBeRevoked, appearance, signerOption } = credentialTemplate;
312+
const { name, description, format, canBeRevoked, appearance, signerOption, noticeUrl } = credentialTemplate;
313313

314314
const checkNameExist = await this.oid4vcIssuanceRepository.getTemplateByNameForIssuer(name, issuerId);
315315
if (0 < checkNameExist.length) {
@@ -323,7 +323,8 @@ export class Oid4vcIssuanceService {
323323
attributes: instanceToPlain(credentialTemplate.template),
324324
appearance: appearance ?? {},
325325
issuerId,
326-
signerOption
326+
signerOption,
327+
noticeUrl: noticeUrl ?? null
327328
};
328329
// Persist in DB
329330
const createdTemplate = await this.oid4vcIssuanceRepository.createTemplate(issuerId, metadata);
@@ -393,7 +394,7 @@ export class Oid4vcIssuanceService {
393394
...updateCredentialTemplate,
394395
...(issuerId ? { issuerId } : {})
395396
};
396-
const { name, description, format, canBeRevoked, appearance, signerOption } = normalized;
397+
const { name, description, format, canBeRevoked, appearance, signerOption, noticeUrl } = normalized;
397398
const attributes = instanceToPlain(normalized.template);
398399

399400
const payload = {
@@ -404,7 +405,8 @@ export class Oid4vcIssuanceService {
404405
...(attributes !== undefined ? { attributes } : {}),
405406
...(appearance !== undefined ? { appearance } : {}),
406407
...(issuerId ? { issuerId } : {}),
407-
...(signerOption !== undefined ? { signerOption } : {})
408+
...(signerOption !== undefined ? { signerOption } : {}),
409+
...(noticeUrl !== undefined ? { noticeUrl } : {})
408410
};
409411

410412
const updatedTemplate = await this.oid4vcIssuanceRepository.updateTemplate(templateId, payload);
@@ -440,7 +442,9 @@ export class Oid4vcIssuanceService {
440442
canBeRevoked: template.canBeRevoked,
441443
attributes: template.attributes,
442444
appearance: template.appearance,
443-
issuerId: template.issuerId
445+
issuerId: template.issuerId,
446+
signerOption: template.signerOption,
447+
noticeUrl: template.noticeUrl ?? null
444448
};
445449
await this.oid4vcIssuanceRepository.updateTemplate(templateId, rollbackPayload);
446450
this.logger.log(`Rolled back template ${templateId} to previous state after agent error`);
@@ -625,7 +629,22 @@ export class Oid4vcIssuanceService {
625629
throw new NotFoundException(ResponseMessages.oidcIssuerSession.error.errorCreateOffer);
626630
}
627631

628-
return createCredentialOfferOnAgent.response;
632+
const { response } = createCredentialOfferOnAgent;
633+
634+
if (null !== response) {
635+
if (1 === filterTemplateIds.length) {
636+
const template = await this.oid4vcIssuanceRepository.getTemplateById(filterTemplateIds[0]);
637+
if (template?.noticeUrl) {
638+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
639+
(response as any).noticeUrl = template.noticeUrl;
640+
}
641+
} else if (createOidcCredentialOffer.noticeUrl) {
642+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
643+
(response as any).noticeUrl = createOidcCredentialOffer.noticeUrl;
644+
}
645+
}
646+
647+
return response;
629648
} catch (error) {
630649
const errorResponse = ErrorHandler.categorize(error, 'Failed to create credential offer');
631650
this.logger.error(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "credential_templates" ADD COLUMN "noticeUrl" TEXT;

libs/prisma-service/prisma/schema.prisma

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ model credential_templates {
651651
issuerId String @db.Uuid
652652
issuer oidc_issuer @relation(fields: [issuerId], references: [id])
653653
654+
noticeUrl String?
655+
654656
createdAt DateTime @default(now())
655657
updatedAt DateTime @updatedAt
656658
signerOption SignerOption

0 commit comments

Comments
 (0)