Skip to content

Commit

Permalink
add type TRUST_REGITRY for entites and remove previous migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
vsvishalsharma committed Sep 16, 2024
1 parent aee1200 commit fff1b88
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 120 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
-- CreateEnum
CREATE TYPE "OrganizationType" AS ENUM ('ISSUER', 'VERIFIER', 'OTHER_TYPE');
CREATE TYPE "EntityType" AS ENUM ('ISSUER', 'VERIFIER', 'TRUST_REGISTRY');

-- CreateEnum
CREATE TYPE "SchemaType" AS ENUM ('W3C', 'ANONCREDS');

-- CreateEnum
CREATE TYPE "AuthorizationStatus" AS ENUM ('NOT_FOUND', 'CURRENT', 'EXPIRED', 'TERMINATED', 'REVOKED');

-- CreateTable
CREATE TABLE "GovernanceAuthority" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"did" TEXT NOT NULL,
"type" TEXT,
"serviceEndpoint" TEXT,
"relatedAuthorities" TEXT[],

CONSTRAINT "GovernanceAuthority_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Organization" (
CREATE TABLE "Entity" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"did" TEXT NOT NULL,
"type" "OrganizationType" NOT NULL,
"type" "EntityType" NOT NULL,
"governanceAuthorityId" TEXT NOT NULL,
"namespaceId" TEXT NOT NULL,
"assuranceLevelId" TEXT NOT NULL,
"onboardedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"attributes" JSONB,
"authorization" "AuthorizationStatus" NOT NULL,

CONSTRAINT "Organization_pkey" PRIMARY KEY ("id")
CONSTRAINT "Entity_pkey" PRIMARY KEY ("id")
);

-- CreateTable
Expand All @@ -35,7 +42,7 @@ CREATE TABLE "Schema" (
"type" "SchemaType" NOT NULL,
"w3cUri" TEXT,
"anonCredsSchemaId" TEXT,
"organizationId" TEXT,
"entityId" TEXT,
"governanceAuthorityId" TEXT NOT NULL,

CONSTRAINT "Schema_pkey" PRIMARY KEY ("id")
Expand All @@ -60,36 +67,29 @@ CREATE TABLE "AssuranceLevel" (
CONSTRAINT "AssuranceLevel_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "RegistryRelationship" (
"id" TEXT NOT NULL,
"registryId" TEXT NOT NULL,
"relatedRegistryId" TEXT NOT NULL,
"relationshipType" TEXT NOT NULL,

CONSTRAINT "RegistryRelationship_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "GovernanceAuthority_did_key" ON "GovernanceAuthority"("did");

-- CreateIndex
CREATE UNIQUE INDEX "Organization_did_key" ON "Organization"("did");
CREATE UNIQUE INDEX "GovernanceAuthority_serviceEndpoint_key" ON "GovernanceAuthority"("serviceEndpoint");

-- CreateIndex
CREATE UNIQUE INDEX "Entity_did_key" ON "Entity"("did");

-- CreateIndex
CREATE UNIQUE INDEX "Namespace_name_key" ON "Namespace"("name");

-- AddForeignKey
ALTER TABLE "Organization" ADD CONSTRAINT "Organization_governanceAuthorityId_fkey" FOREIGN KEY ("governanceAuthorityId") REFERENCES "GovernanceAuthority"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE "Entity" ADD CONSTRAINT "Entity_governanceAuthorityId_fkey" FOREIGN KEY ("governanceAuthorityId") REFERENCES "GovernanceAuthority"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Organization" ADD CONSTRAINT "Organization_namespaceId_fkey" FOREIGN KEY ("namespaceId") REFERENCES "Namespace"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE "Entity" ADD CONSTRAINT "Entity_namespaceId_fkey" FOREIGN KEY ("namespaceId") REFERENCES "Namespace"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Organization" ADD CONSTRAINT "Organization_assuranceLevelId_fkey" FOREIGN KEY ("assuranceLevelId") REFERENCES "AssuranceLevel"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE "Entity" ADD CONSTRAINT "Entity_assuranceLevelId_fkey" FOREIGN KEY ("assuranceLevelId") REFERENCES "AssuranceLevel"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Schema" ADD CONSTRAINT "Schema_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE SET NULL ON UPDATE CASCADE;
ALTER TABLE "Schema" ADD CONSTRAINT "Schema_entityId_fkey" FOREIGN KEY ("entityId") REFERENCES "Entity"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Schema" ADD CONSTRAINT "Schema_governanceAuthorityId_fkey" FOREIGN KEY ("governanceAuthorityId") REFERENCES "GovernanceAuthority"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Expand All @@ -99,9 +99,3 @@ ALTER TABLE "Namespace" ADD CONSTRAINT "Namespace_governanceAuthorityId_fkey" FO

-- AddForeignKey
ALTER TABLE "AssuranceLevel" ADD CONSTRAINT "AssuranceLevel_governanceAuthorityId_fkey" FOREIGN KEY ("governanceAuthorityId") REFERENCES "GovernanceAuthority"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "RegistryRelationship" ADD CONSTRAINT "RegistryRelationship_registryId_fkey" FOREIGN KEY ("registryId") REFERENCES "GovernanceAuthority"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "RegistryRelationship" ADD CONSTRAINT "RegistryRelationship_relatedRegistryId_fkey" FOREIGN KEY ("relatedRegistryId") REFERENCES "GovernanceAuthority"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ model AssuranceLevel {
enum EntityType {
ISSUER
VERIFIER
OTHER_TYPE
TRUST_REGISTRY
}

enum SchemaType {
Expand Down
20 changes: 20 additions & 0 deletions src/governance-authority/dto/onboard-regstry.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { IsString, IsOptional, IsEnum } from 'class-validator';

export class OnboardRegistryDto {
@IsString()
name: string;

@IsString()
did: string;

@IsOptional()
@IsString()
namespaceId: string;

@IsOptional()
@IsString()
assuranceLevelId: string;

@IsOptional()
attributes?: any; // Change this if you have a specific structure for attributes
}
11 changes: 10 additions & 1 deletion src/governance-authority/governance-authority.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CreateNamespaceDto } from './dto/create-namespace.dto';
import { CreateSchemaDto } from './dto/create-schema.dto';
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard';
import { EntityType } from '@prisma/client';

import { OnboardRegistryDto } from './dto/onboard-regstry.dto';
@Controller('/')
export class GovernanceAuthorityController {
constructor(
Expand Down Expand Up @@ -45,6 +45,15 @@ export class GovernanceAuthorityController {
return this.governanceAuthorityService.onboardVerifier(dto, user.id);
}

@UseGuards(JwtAuthGuard)
@Post('onboard-registry')
async onboardRegistry(
@Body() dto: OnboardRegistryDto,
@CurrentUser() user: { id: string; did: string },
) {
return this.governanceAuthorityService.onboardRegistry(dto, user.id);
}

@UseGuards(JwtAuthGuard)
@Post('namespace')
async createNamespace(
Expand Down
31 changes: 27 additions & 4 deletions src/governance-authority/governance-authority.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PrismaService } from '../prisma/prisma.service';
import { CreateGovernanceAuthorityDto } from './dto/create-governance-authority.dto';
import { OnboardIssuerDto } from './dto/onboard-issuer.dto';
import { OnboardVerifierDto } from './dto/onboard-verifier.dto';
import { OnboardRegistryDto } from './dto/onboard-regstry.dto';
import { AuthorizationStatus, EntityType, Prisma } from '@prisma/client';
import { CreateAssuranceLevelDto } from './dto/create-assurance-level.dto';
import { CreateNamespaceDto } from './dto/create-namespace.dto';
Expand Down Expand Up @@ -293,14 +294,14 @@ export class GovernanceAuthorityService {

throw new NotFoundException(`No governance authority or entity found with DID: ${did}`);
}
async getEntityAuthorization(entityId: string): Promise<AuthorizationStatus> {
async getEntityAuthorization(entitydId: string): Promise<AuthorizationStatus> {
const entity = await this.prisma.entity.findUnique({
where: { id: entityId },
where: { did: entitydId },
select: { authorization: true },
});

if (!entity) {
throw new NotFoundException(`Entity with ID ${entityId} not found`);
throw new NotFoundException(`Entity with ID ${entitydId} not found`);
}

return entity.authorization;
Expand Down Expand Up @@ -359,4 +360,26 @@ export class GovernanceAuthorityService {
},
});
}
}

async onboardRegistry(
dto: OnboardRegistryDto,
governanceAuthorityId: string
) {
const registryEntity = await this.prisma.entity.create({
data: {
name: dto.name,
did: dto.did,
type: EntityType.TRUST_REGISTRY,
governanceAuthorityId: governanceAuthorityId,
namespaceId: dto.namespaceId,
assuranceLevelId: dto.assuranceLevelId,
authorization: AuthorizationStatus.CURRENT,
},
select: this.entitySelectFields(),
});


return registryEntity;
}

}

0 comments on commit fff1b88

Please sign in to comment.