diff --git a/src/controllers/api/accreditation.ts b/src/controllers/api/accreditation.ts index b5a60e67..bf5d2abd 100644 --- a/src/controllers/api/accreditation.ts +++ b/src/controllers/api/accreditation.ts @@ -6,6 +6,7 @@ import type { RevokeAccreditationRequestBody, RevokeAccreditationRequestQuery, RevokeAccreditationResponseBody, + SchemaUrlType, SuspendAccreditationRequestBody, SuspendAccreditationRequestQuery, SuspendAccreditationResponseBody, @@ -45,9 +46,9 @@ export class AccreditationController { body('subjectDid').exists().isDID().bail(), body('schemas').exists().isArray().withMessage('schemas must be a array').bail(), body('schemas.*.url').isString().withMessage('schema urls must be a string').bail(), - body('schemas.*.type') + body('schemas.*.types') .custom((value) => typeof value === 'string' || (Array.isArray(value) && typeof value[0] === 'string')) - .withMessage('schema type must be a string'), + .withMessage('schema.types must be a string or a string array'), body('parentAccreditation').optional().isString().withMessage('parentAccreditation must be a string').bail(), body('rootAuthorisation').optional().isString().withMessage('rootAuthorisation must be a string').bail(), body('trustFramework').optional().isString().withMessage('trustFramework must be a string').bail(), @@ -96,9 +97,9 @@ export class AccreditationController { body('resourceType').optional().isString().withMessage('resourceType should be a string').bail(), body('schemas').optional().isArray().withMessage('schemas must be a array').bail(), body('schemas.*.url').isString().withMessage('schema urls must be a string').bail(), - body('schemas.*.type') + body('schemas.*.types') .custom((value) => typeof value === 'string' || (Array.isArray(value) && typeof value[0] === 'string')) - .withMessage('schema type must be a string'), + .withMessage('schema.types must be a string or a string array'), body('did') .custom((value, { req }) => { const { didUrl, resourceId, resourceName, resourceType } = req.body; @@ -236,9 +237,9 @@ export class AccreditationController { } const resourceId = v4(); - const accreditedFor = schemas.map(({ url, type }: any) => ({ + const accreditedFor = schemas.map(({ url, types }: SchemaUrlType) => ({ schemaId: url, - type, + types: Array.isArray(types) ? types : [types], })); // construct credential request @@ -402,9 +403,9 @@ export class AccreditationController { } try { - const accreditedFor = schemas?.map(({ url, type }: any) => ({ + const accreditedFor = schemas?.map(({ url, types }: SchemaUrlType) => ({ schemaId: url, - type, + types: Array.isArray(types) ? types : [types], })); const result = await AccreditationService.instance.verify_accreditation( diff --git a/src/services/api/accreditation.ts b/src/services/api/accreditation.ts index 2a374407..b448168f 100644 --- a/src/services/api/accreditation.ts +++ b/src/services/api/accreditation.ts @@ -74,7 +74,9 @@ export class AccreditationService { if ( !accreditedFor.every((schema) => accreditation.credentialSubject.accreditedFor.some( - (accredited) => accredited.type === schema.type && accredited.schemaId === schema.schemaId + (accredited) => + accredited.types.every((value) => schema.types.includes(value)) && + accredited.schemaId === schema.schemaId ) ) ) { diff --git a/src/types/accreditation.ts b/src/types/accreditation.ts index 8f1973d2..be9f041a 100644 --- a/src/types/accreditation.ts +++ b/src/types/accreditation.ts @@ -23,12 +23,12 @@ export enum AccreditationRequestType { } export type AccreditationSchemaType = { - type: string; + types: string[]; schemaId: string; }; export type SchemaUrlType = { - type: string; + types: string[] | string; url: string; }; diff --git a/tests/e2e/payloads/accreditation/accredit-jwt.json b/tests/e2e/payloads/accreditation/accredit-jwt.json index 2fa5965e..4033166b 100644 --- a/tests/e2e/payloads/accreditation/accredit-jwt.json +++ b/tests/e2e/payloads/accreditation/accredit-jwt.json @@ -4,7 +4,7 @@ "schemas": [ { "url": "https://schema.org/Person", - "type": "Person" + "types": "Person" } ], "format": "jwt", diff --git a/tests/e2e/payloads/accreditation/attest-jwt.json b/tests/e2e/payloads/accreditation/attest-jwt.json index c8ee70ed..444b0104 100644 --- a/tests/e2e/payloads/accreditation/attest-jwt.json +++ b/tests/e2e/payloads/accreditation/attest-jwt.json @@ -4,7 +4,7 @@ "schemas": [ { "url": "https://schema.org/Person", - "type": "Person" + "types": "Person" } ], "format": "jwt", diff --git a/tests/e2e/payloads/accreditation/authorise-jwt-revocation.json b/tests/e2e/payloads/accreditation/authorise-jwt-revocation.json index 88615f28..92da1ce5 100644 --- a/tests/e2e/payloads/accreditation/authorise-jwt-revocation.json +++ b/tests/e2e/payloads/accreditation/authorise-jwt-revocation.json @@ -9,7 +9,7 @@ "schemas": [ { "url": "https://schema.org/Learn", - "type": "Learn" + "types": "Learn" } ], "accreditationName": "revocationAccreditation", diff --git a/tests/e2e/payloads/accreditation/authorise-jwt.json b/tests/e2e/payloads/accreditation/authorise-jwt.json index 621926ae..90fcd174 100644 --- a/tests/e2e/payloads/accreditation/authorise-jwt.json +++ b/tests/e2e/payloads/accreditation/authorise-jwt.json @@ -4,7 +4,7 @@ "schemas": [ { "url": "https://schema.org/Person", - "type": "Person" + "types": "Person" } ], "format": "jwt", diff --git a/tests/e2e/payloads/accreditation/child-accredit-jwt.json b/tests/e2e/payloads/accreditation/child-accredit-jwt.json index 050bc224..d12ff950 100644 --- a/tests/e2e/payloads/accreditation/child-accredit-jwt.json +++ b/tests/e2e/payloads/accreditation/child-accredit-jwt.json @@ -4,7 +4,7 @@ "schemas": [ { "url": "https://schema.org/Person", - "type": "Person" + "types": "Person" } ], "format": "jwt", diff --git a/tests/e2e/payloads/accreditation/invalid-schema-accredit.json b/tests/e2e/payloads/accreditation/invalid-schema-accredit.json index dd25cc92..e75b3a84 100644 --- a/tests/e2e/payloads/accreditation/invalid-schema-accredit.json +++ b/tests/e2e/payloads/accreditation/invalid-schema-accredit.json @@ -4,7 +4,7 @@ "schemas": [ { "url": "https://schema.org/Event", - "type": "Event" + "types": "Event" } ], "format": "jwt",