diff --git a/CHANGELOG.md b/CHANGELOG.md index cd72220..118a299 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.0.8 + +* Adds 'Type-3' data for Public Directory + ## 0.0.1 ### Additions and Improvements diff --git a/docs/api/Committee-Guide.md b/docs/api/Committee-Guide.md index eed6af1..c79fd2b 100644 --- a/docs/api/Committee-Guide.md +++ b/docs/api/Committee-Guide.md @@ -82,6 +82,35 @@ data='{"validDays":'$validDays', "expires":'$expires',"identificationData":'$ide curl -X 'POST' ${add_member_to_public_directory_url} -H 'accept: application/json' -F caCert=@$path_to_public_cacrt -F data=$data ``` +#### Onboarding a Type-3 member into the Public Directory + +* You must have: + 1. The DID (Decentralized Identifier) + 2. New Member's Metadata according to type-3 data type + +```sh +api_url=http://localhost:3002 # Set LACChain Trust url +``` + +```sh +validDays=500 +expires=false +# metadata +did="did:lac1:1iT58jc7tEP4Y8zbf9Ma8dpdiGKZjzYmjtmFEZZ8Dias9rbBpAYS39dAekAZupNDdgGb" +legalName="Ministry Of Country CHL" +countryCode="CHL" #urn:iso:std:iso:3166 +url="https://lacnet.lacchain.net" +identificationData='{"id":'\"$did\"',"legalName":'\"$legalName\"',"countryCode": '\"$countryCode\"', "url": '\"$url\"'}' + +# process +add_type3_member_to_public_directory_url="$api_url"/api/v1/public-directory/add-type3-member +data='{"validDays":'$validDays', "expires":'$expires',"identificationData":'$identificationData'}' + +curl -X 'POST' ${add_type3_member_to_public_directory_url} -H 'accept: application/json' \ +-H 'Content-Type: application/json' \ +-d "$data" +``` + ##### requirements * You must have: 1. The Certificate Authority diff --git a/package.json b/package.json index 9087168..c04651d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lacchain-trust", - "version": "0.0.7", + "version": "0.0.8", "description": "Rest api for Lacchain Trust built on top of Lacchain", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", diff --git a/src/controllers/lac1/public.directory.controller.ts b/src/controllers/lac1/public.directory.controller.ts index 4eed0af..5ed4c61 100644 --- a/src/controllers/lac1/public.directory.controller.ts +++ b/src/controllers/lac1/public.directory.controller.ts @@ -12,7 +12,10 @@ import { Service } from 'typedi'; import { LacchainPublicDirectory } from '../../services/public-directory/lacchain.public.directory'; import { ErrorsMessages } from '../../constants/errorMessages'; import { IManager } from 'src/interfaces/manager/manager'; -import { PublicDirectoryType1MemberDTO } from '@dto/public.directory/public.directoryDTO'; +import { + PublicDirectoryType1MemberDTO, + PublicDirectoryType3MemberDTO +} from '../../dto/public.directory/public.directoryDTO'; @JsonController('/public-directory') @Service() @@ -71,6 +74,36 @@ export class PublicDirectoryController { ); } } + + /** + * Type3 member add all base identification data + * @param {PublicDirectoryType1MemberDTO} data + * @example - POST + { + "validDays": 1000, + "expires": true, + "identificationData": { + "id": "did:lac1:1iT5QGEpfYcG6....2yfGHwM48pNDHJoqF92NGzzpo", + "legalName": "Racsel - American Electronic Health Cooperation Network", + "domainName": "racsel.org" + } + } + */ + @Post('/add-type3-member') + async addType3Member( + @Body({ validate: true }) data: PublicDirectoryType3MemberDTO + ): Promise { + try { + return this.publicDirectory.addType3Member(data); + } catch (error: any) { + if (error.detail ?? error.message) { + throw new BadRequestError(error.detail ?? error.message); + } + throw new InternalServerError( + error.detail ?? error.message ?? ErrorsMessages.INTERNAL_SERVER_ERROR + ); + } + } @Get('/get-manager') async getManager(): Promise { try { diff --git a/src/dto/public.directory/public.directoryDTO.ts b/src/dto/public.directory/public.directoryDTO.ts index 9266857..780dac4 100644 --- a/src/dto/public.directory/public.directoryDTO.ts +++ b/src/dto/public.directory/public.directoryDTO.ts @@ -74,6 +74,13 @@ export class Type2MemberDataValidator extends BaseTypeMemberDataValidator { certificateAuthority!: string; } +export class Type3MemberDataValidator extends BaseTypeMemberDataValidator { + @ValidateNested() + @IsDefined() + @Type(() => Base2IdentificationDataValidator) + identificationData!: Base2IdentificationDataValidator; +} + export class Base1PublicDirectoryMemberValidator { @Min(1) @IsPositive({ @@ -118,6 +125,13 @@ export class PublicDirectoryType2MemberDTO extends Base1PublicDirectoryMemberVal identificationData!: Base2IdentificationDataValidator; } +export class PublicDirectoryType3MemberDTO extends Base1PublicDirectoryMemberValidator { + @ValidateNested() + @IsDefined() + @Type(() => Base2IdentificationDataValidator) + identificationData!: Base2IdentificationDataValidator; +} + // eslint-disable-next-line max-len export class PublicDirectoryType1MemberValidator extends Base1PublicDirectoryMemberValidator { @ValidateNested() @@ -133,3 +147,11 @@ export class PublicDirectoryType2MemberValidator extends Base1PublicDirectoryMem @Type(() => Type2MemberDataValidator) memberData!: Type2MemberDataValidator; } + +// eslint-disable-next-line max-len +export class PublicDirectoryType3MemberValidator extends Base1PublicDirectoryMemberValidator { + @ValidateNested() + @IsDefined() + @Type(() => Type3MemberDataValidator) + memberData!: Type3MemberDataValidator; +} diff --git a/src/services/public-directory/lacchain.identity.structure.ts b/src/services/public-directory/lacchain.identity.structure.ts index 9904a5a..64046ea 100644 --- a/src/services/public-directory/lacchain.identity.structure.ts +++ b/src/services/public-directory/lacchain.identity.structure.ts @@ -5,7 +5,9 @@ import { Base2IdentificationDataValidator, PublicDirectoryType1MemberValidator, Type1MemberDataValidator, - Base1IdentificationDataValidator + Base1IdentificationDataValidator, + PublicDirectoryType3MemberValidator, + Type3MemberDataValidator } from '../../dto/public.directory/public.directoryDTO'; import { validateOrReject } from 'class-validator'; import { BadRequestError } from 'routing-controllers'; @@ -48,6 +50,21 @@ export class IdentityValidator { } } + async validateType3PublicDirectoryMember( + publicDirectoryMemberV: PublicDirectoryType3MemberValidator + ) { + const v = new PublicDirectoryType3MemberValidator(); + v.validDays = publicDirectoryMemberV.validDays; + v.expires = publicDirectoryMemberV.expires; + v.chainOfTrustAddress = publicDirectoryMemberV.chainOfTrustAddress; + v.memberData = publicDirectoryMemberV.memberData; + try { + await validateOrReject(v); + } catch (err: any) { + throw new BadRequestError(err); + } + } + async validateType1MemberData(memberData: Type1MemberDataValidator) { const v = new Type1MemberDataValidator(); v.type = memberData.type; @@ -73,6 +90,18 @@ export class IdentityValidator { } } + async validateType3MemberData(memberData: Type3MemberDataValidator) { + const v = new Type3MemberDataValidator(); + v.type = memberData.type; + v.version = memberData.version; + v.identificationData = memberData.identificationData; + try { + await validateOrReject(v); + } catch (err: any) { + throw new BadRequestError(err); + } + } + async validateBase1IdentificationData( identificationData: Base1IdentificationDataValidator ) { diff --git a/src/services/public-directory/lacchain.public.directory.ts b/src/services/public-directory/lacchain.public.directory.ts index 728d20e..6f30810 100644 --- a/src/services/public-directory/lacchain.public.directory.ts +++ b/src/services/public-directory/lacchain.public.directory.ts @@ -23,7 +23,10 @@ import { PublicDirectoryType2MemberValidator, Type1MemberDataValidator, PublicDirectoryType1MemberDTO, - PublicDirectoryType1MemberValidator + PublicDirectoryType1MemberValidator, + PublicDirectoryType3MemberDTO, + Type3MemberDataValidator, + PublicDirectoryType3MemberValidator } from '../../dto/public.directory/public.directoryDTO'; import { IdentityValidator } from './lacchain.identity.structure'; @@ -39,6 +42,8 @@ export class LacchainPublicDirectory { private memberDataType1Name = 'Type-1'; private memberDataType2EncodingVersion = '1.0.0'; private memberDataType2Name = 'Type-2'; + private memberDataType3EncodingVersion = '1.0.0'; + private memberDataType3Name = 'Type-3'; constructor() { this.publicDirectory = new PublicDirectoryBase( resolvePublicDirectoryAddress(), @@ -63,8 +68,6 @@ export class LacchainPublicDirectory { } await this._type1ValidateAndFillAdditionalParams(publicDirectoryMember); return this.addMember(publicDirectoryMember); - - // return { Ok: true }; } async rawAddType2Member( @@ -99,6 +102,23 @@ export class LacchainPublicDirectory { await this._type2ValidateAndFillAdditionalParams(publicDirectoryMember); return this.addMember(publicDirectoryMember); } + + async addType3Member(type3Data: PublicDirectoryType3MemberDTO): Promise { + const memberData = new Type3MemberDataValidator(); + memberData.identificationData = type3Data.identificationData; + const publicDirectoryMember = new PublicDirectoryType3MemberValidator(); + publicDirectoryMember.validDays = type3Data.validDays; + publicDirectoryMember.expires = type3Data.expires; + publicDirectoryMember.chainOfTrustAddress = type3Data.chainOfTrustAddress; + publicDirectoryMember.memberData = memberData; + + if (!publicDirectoryMember.memberData) { + throw new BadRequestError(ErrorsMessages.BAD_REQUEST_ERROR); + } + await this._type3ValidateAndFillAdditionalParams(publicDirectoryMember); + return this.addMember(publicDirectoryMember); + } + private _validatex509Cert(x509CA: X509Certificate) { if (!x509CA.ca) { throw new BadRequestError(ErrorsMessages.NOT_CA_CERTIFICATE_ERROR); @@ -149,6 +169,25 @@ export class LacchainPublicDirectory { ); } + private async _type3ValidateAndFillAdditionalParams( + publicDirectoryMemberV: PublicDirectoryType3MemberValidator + ) { + if (publicDirectoryMemberV.memberData) { + publicDirectoryMemberV.memberData.version = + this.memberDataType3EncodingVersion; + publicDirectoryMemberV.memberData.type = this.memberDataType3Name; + } + await this.identityValidator.validateType3PublicDirectoryMember( + publicDirectoryMemberV + ); + await this.identityValidator.validateType3MemberData( + publicDirectoryMemberV.memberData + ); + await this.identityValidator.validateBase2IdentificationData( + publicDirectoryMemberV.memberData.identificationData + ); + } + async addMember( publicDirectoryMember: | Type1PublicDirectoryMember