diff --git a/src/controllers/api/accreditation.ts b/src/controllers/api/accreditation.ts index 2c125d28..836466ca 100644 --- a/src/controllers/api/accreditation.ts +++ b/src/controllers/api/accreditation.ts @@ -12,11 +12,19 @@ import { IdentityServiceStrategySetup } from '../../services/identity/index.js'; import { AccreditationService } from '../../services/api/accreditation.js'; import { Credentials } from '../../services/api/credentials.js'; import { eventTracker } from '../../services/track/tracker.js'; -import { body, param } from '../validator/index.js'; +import { body, query } from '../validator/index.js'; export class AccreditationController { public static issueValidator = [ - param('accreditationType').exists().isString().isIn(['authorize', 'accredit', 'attest']).bail(), + query('accreditationType') + .exists() + .isString() + .isIn([ + AccreditationRequestType.authorize, + AccreditationRequestType.accredit, + AccreditationRequestType.attest, + ]) + .bail(), body('issuerDid').exists().isString().isDID().bail(), body('subjectDid').exists().isString().isDID().bail(), body('schemas').exists().isArray().bail(), @@ -25,7 +33,7 @@ export class AccreditationController { body('schemas.*.type.*').isString().bail(), body('parentAccreditation').optional().isURL().bail(), body('rootAuthorisation').optional().isURL().bail(), - param('accreditationType') + query('accreditationType') .custom((value, { req }) => { if (value === 'accredit' || value === 'attest') { return req.body.parentAccreditation && req.body.rootAuthorisation; @@ -37,7 +45,23 @@ export class AccreditationController { body('accreditationName').isString(), ]; - public static verifyValidator = [body('accreditation').exists().bail(), body('subjectDid').exists().bail()]; + public static verifyValidator = [ + body('accreditation').exists().bail(), + body('subjectDid').exists().bail(), + query('verifyStatus') + .optional() + .isBoolean() + .withMessage('verifyStatus should be a boolean value') + .toBoolean() + .bail(), + query('allowDeactivatedDid') + .optional() + .isBoolean() + .withMessage('allowDeactivatedDid should be a boolean value') + .toBoolean() + .bail(), + query('policies').optional().isObject().withMessage('Verification policies should be an object').bail(), + ]; /** * @openapi @@ -50,7 +74,7 @@ export class AccreditationController { * operationId: accredit-issue * parameters: * - in: query - * name: type + * name: accreditationType * description: Select the type of accreditation to be issued. * schema: * type: string @@ -104,6 +128,7 @@ export class AccreditationController { rootAuthorisation, attributes, accreditationName, + format, } = request.body as DIDAccreditationRequestBody; try { @@ -149,38 +174,41 @@ export class AccreditationController { id: subjectDid, }, issuerDid, - format: 'jwt', + format: format || 'jwt', connector: CredentialConnectors.Resource, // resource connector credentialId: resourceId, credentialName: accreditationName, }; + + let resourceType: string; switch (accreditationType) { - case AccreditationRequestType.authroize: - credentialRequest.type = [ - ...(type || []), - DIDAccreditationTypes.VerifiableAuthorisationForTrustChain, - ]; + case AccreditationRequestType.authorize: + resourceType = DIDAccreditationTypes.VerifiableAuthorisationForTrustChain; + credentialRequest.type = [...(type || []), resourceType]; credentialRequest.termsOfUse = { - type: DIDAccreditationTypes.VerifiableAuthorisationForTrustChain, + type: resourceType, trustFramework: 'cheqd Governance Framework', trustFrameworkId: 'https://learn.cheqd.io/governance/start', }; break; case AccreditationRequestType.accredit: - credentialRequest.type = [...(type || []), DIDAccreditationTypes.VerifiableAccreditationToAccredit]; + resourceType = DIDAccreditationTypes.VerifiableAccreditationToAccredit; + credentialRequest.type = [...(type || []), resourceType]; credentialRequest.termsOfUse = { - type: DIDAccreditationTypes.VerifiableAccreditationToAccredit, + type: resourceType, parentAccreditation, rootAuthorisation, }; break; case AccreditationRequestType.attest: - credentialRequest.type = [...(type || []), DIDAccreditationTypes.VerifiableAccreditationToAttest]; + resourceType = DIDAccreditationTypes.VerifiableAccreditationToAttest; + credentialRequest.type = [...(type || []), resourceType]; credentialRequest.termsOfUse = { - type: DIDAccreditationTypes.VerifiableAccreditationToAttest, + type: resourceType, parentAccreditation, rootAuthorisation, }; + break; } // validate parent and root accreditations @@ -192,14 +220,14 @@ export class AccreditationController { AccreditationService.instance.verify_accreditation( issuerDid, parentAccreditation, - true, + false, false, response.locals.customer ), AccreditationService.instance.verify_accreditation( issuerDid, rootAuthorisation, - true, + false, false, response.locals.customer ), @@ -291,7 +319,7 @@ export class AccreditationController { */ public async verify(request: Request, response: Response) { // Extract did from params - const { verifyStatus = false, allowDeactivatedDid = false } = request.query as VerifyCredentialRequestQuery; + let { verifyStatus = false, allowDeactivatedDid = false } = request.query as VerifyCredentialRequestQuery; const { accreditation, policies, subjectDid } = request.body; try { const result = await AccreditationService.instance.verify_accreditation( diff --git a/src/static/swagger-api.json b/src/static/swagger-api.json index 2a9fdb60..3edb454c 100644 --- a/src/static/swagger-api.json +++ b/src/static/swagger-api.json @@ -704,7 +704,12 @@ "AccreditationVerifyRequest": { "type": "object", "properties": { - "accrditation": { + "subjectDid": { + "description": "DID of the Verifiable Credential holder/subject. This needs to be a `did:key` DID.", + "type": "string", + "example": "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK" + }, + "accreditation": { "description": "Verifiable Credential to be verified as a VC-JWT string or a JSON object.", "type": "object" }, @@ -729,7 +734,11 @@ } } } - } + }, + "required": [ + "accreditation", + "subjectDid" + ] }, "PresentationCreateRequest": { "type": "object", @@ -2433,7 +2442,7 @@ "parameters": [ { "in": "query", - "name": "type", + "name": "accreditationType", "description": "Select the type of accreditation to be issued.", "schema": { "type": "string", diff --git a/src/types/accreditation.ts b/src/types/accreditation.ts index affeab9d..48c8b1fb 100644 --- a/src/types/accreditation.ts +++ b/src/types/accreditation.ts @@ -8,7 +8,7 @@ export enum DIDAccreditationTypes { } export enum AccreditationRequestType { - authroize = 'authorize', + authorize = 'authorize', accredit = 'accredit', attest = 'attest', }