-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POST and GET endpoints for issuer,verifier,schema,namespace,assurance…
…-levels Signed-off-by: Vishal Sharma <[email protected]>
- Loading branch information
1 parent
63c96e9
commit 4eff568
Showing
28 changed files
with
941 additions
and
51 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
prisma/migrations/20240701121336_add_issuer_id_and_verified_schemas/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `organizationId` on the `Schema` table. All the data in the column will be lost. | ||
- Added the required column `issuerId` to the `Schema` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE "Schema" DROP CONSTRAINT "Schema_organizationId_fkey"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Schema" DROP COLUMN "organizationId", | ||
ADD COLUMN "issuerId" TEXT NOT NULL; | ||
|
||
-- CreateTable | ||
CREATE TABLE "_VerifierSchemas" ( | ||
"A" TEXT NOT NULL, | ||
"B" TEXT NOT NULL | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "_VerifierSchemas_AB_unique" ON "_VerifierSchemas"("A", "B"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "_VerifierSchemas_B_index" ON "_VerifierSchemas"("B"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Schema" ADD CONSTRAINT "Schema_issuerId_fkey" FOREIGN KEY ("issuerId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "_VerifierSchemas" ADD CONSTRAINT "_VerifierSchemas_A_fkey" FOREIGN KEY ("A") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "_VerifierSchemas" ADD CONSTRAINT "_VerifierSchemas_B_fkey" FOREIGN KEY ("B") REFERENCES "Schema"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `definition` on the `Schema` table. All the data in the column will be lost. | ||
- You are about to drop the column `issuerId` on the `Schema` table. All the data in the column will be lost. | ||
- You are about to drop the `Credential` table. If the table is not empty, all the data it contains will be lost. | ||
- You are about to drop the `CredentialDefinition` table. If the table is not empty, all the data it contains will be lost. | ||
- You are about to drop the `RevocationRegistry` table. If the table is not empty, all the data it contains will be lost. | ||
- You are about to drop the `_VerifierSchemas` table. If the table is not empty, all the data it contains will be lost. | ||
- Added the required column `assuranceLevelId` to the `Organization` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `namespaceId` to the `Organization` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `organizationId` to the `Schema` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `type` to the `Schema` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- CreateEnum | ||
CREATE TYPE "SchemaType" AS ENUM ('W3C', 'ANONCREDS'); | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Credential" DROP CONSTRAINT "Credential_definitionId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Credential" DROP CONSTRAINT "Credential_revocationRegistryId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Credential" DROP CONSTRAINT "Credential_schemaId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Schema" DROP CONSTRAINT "Schema_issuerId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "_VerifierSchemas" DROP CONSTRAINT "_VerifierSchemas_A_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "_VerifierSchemas" DROP CONSTRAINT "_VerifierSchemas_B_fkey"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Organization" ADD COLUMN "assuranceLevelId" TEXT NOT NULL, | ||
ADD COLUMN "namespaceId" TEXT NOT NULL; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Schema" DROP COLUMN "definition", | ||
DROP COLUMN "issuerId", | ||
ADD COLUMN "anonCredsDefinitionId" TEXT, | ||
ADD COLUMN "organizationId" TEXT NOT NULL, | ||
ADD COLUMN "type" "SchemaType" NOT NULL, | ||
ADD COLUMN "w3cUri" TEXT; | ||
|
||
-- DropTable | ||
DROP TABLE "Credential"; | ||
|
||
-- DropTable | ||
DROP TABLE "CredentialDefinition"; | ||
|
||
-- DropTable | ||
DROP TABLE "RevocationRegistry"; | ||
|
||
-- DropTable | ||
DROP TABLE "_VerifierSchemas"; | ||
|
||
-- DropEnum | ||
DROP TYPE "CredentialType"; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Organization" ADD CONSTRAINT "Organization_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; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Schema" ADD CONSTRAINT "Schema_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240718151011_add_attributes/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Organization" ADD COLUMN "attributes" TEXT[]; |
8 changes: 8 additions & 0 deletions
8
prisma/migrations/20240718151510_without_attribute/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `attributes` on the `Organization` table. All the data in the column will be lost. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Organization" DROP COLUMN "attributes"; |
9 changes: 9 additions & 0 deletions
9
prisma/migrations/20240718151719_name_to_anon_creds_schema_id/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `anonCredsDefinitionId` on the `Schema` table. All the data in the column will be lost. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Schema" DROP COLUMN "anonCredsDefinitionId", | ||
ADD COLUMN "anonCredsSchemaId" TEXT; |
8 changes: 8 additions & 0 deletions
8
prisma/migrations/20240718152250_add_post_route_for_schema/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- DropForeignKey | ||
ALTER TABLE "Schema" DROP CONSTRAINT "Schema_organizationId_fkey"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Schema" ALTER COLUMN "organizationId" DROP NOT NULL; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Schema" ADD CONSTRAINT "Schema_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
11 changes: 11 additions & 0 deletions
11
prisma/migrations/20240718155719_add_govid_to_schema/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `governanceAuthorityId` to the `Schema` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Schema" ADD COLUMN "governanceAuthorityId" TEXT NOT NULL; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Schema" ADD CONSTRAINT "Schema_governanceAuthorityId_fkey" FOREIGN KEY ("governanceAuthorityId") REFERENCES "GovernanceAuthority"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240719073117_add_attributes/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Organization" ADD COLUMN "attributes" JSONB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Controller, Post, Body } from '@nestjs/common'; | ||
import { AuthService } from './auth.service'; | ||
import { LoginDto } from './dto/login.dto'; | ||
import { Public } from './public.decorator'; | ||
|
||
@Controller('auth') | ||
export class AuthController { | ||
constructor(private authService: AuthService) {} | ||
|
||
@Public() | ||
@Post('login') | ||
async login(@Body() loginDto: LoginDto) { | ||
return this.authService.login(loginDto); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// src/auth/auth.module.ts | ||
import { Module } from '@nestjs/common'; | ||
import { JwtModule } from '@nestjs/jwt'; | ||
import { PassportModule } from '@nestjs/passport'; | ||
import { AuthService } from './auth.service'; | ||
import { AuthController } from './auth.controller'; | ||
import { JwtStrategy } from './jwt.strategy'; | ||
import { PrismaModule } from '../prisma/prisma.module'; | ||
|
||
@Module({ | ||
imports: [ | ||
PrismaModule, | ||
PassportModule, | ||
JwtModule.register({ | ||
secret: process.env.JWT_SECRET, // Make sure to set this in your .env file | ||
signOptions: { expiresIn: '1h' }, | ||
}), | ||
], | ||
providers: [AuthService, JwtStrategy], | ||
controllers: [AuthController], | ||
exports: [AuthService], | ||
}) | ||
export class AuthModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
import { Injectable, UnauthorizedException } from '@nestjs/common'; | ||
import { JwtService } from '@nestjs/jwt'; | ||
import { PrismaService } from '../prisma/prisma.service'; | ||
import { LoginDto } from './dto/login.dto'; | ||
|
||
@Injectable() | ||
export class AuthService { | ||
constructor( | ||
private prisma: PrismaService, | ||
private jwtService: JwtService | ||
) {} | ||
|
||
async login(loginDto: LoginDto) { | ||
const governanceAuthority = await this.prisma.governanceAuthority.findUnique({ | ||
where: { did: loginDto.did }, | ||
}); | ||
|
||
if (!governanceAuthority) { | ||
throw new UnauthorizedException('Invalid credentials'); | ||
} | ||
|
||
const payload = { did: governanceAuthority.did, sub: governanceAuthority.id }; | ||
return { | ||
access_token: this.jwtService.sign(payload), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
import { createParamDecorator, ExecutionContext } from '@nestjs/common'; | ||
|
||
export const CurrentUser = createParamDecorator( | ||
(data: unknown, ctx: ExecutionContext) => { | ||
const request = ctx.switchToHttp().getRequest(); | ||
return request.user; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { IsString } from 'class-validator'; | ||
|
||
export class LoginDto { | ||
@IsString() | ||
did: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// src/auth/jwt-auth.guard.ts | ||
import { ExecutionContext, Injectable } from '@nestjs/common'; | ||
import { Reflector } from '@nestjs/core'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { IS_PUBLIC_KEY } from './public.decorator'; | ||
|
||
@Injectable() | ||
export class JwtAuthGuard extends AuthGuard('jwt') { | ||
constructor(private reflector: Reflector) { | ||
super(); | ||
} | ||
|
||
canActivate(context: ExecutionContext) { | ||
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [ | ||
context.getHandler(), | ||
context.getClass(), | ||
]); | ||
if (isPublic) { | ||
return true; | ||
} | ||
return super.canActivate(context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// src/auth/jwt.strategy.ts | ||
import { Injectable } from '@nestjs/common'; | ||
import { PassportStrategy } from '@nestjs/passport'; | ||
import { ExtractJwt, Strategy } from 'passport-jwt'; | ||
import { PrismaService } from '../prisma/prisma.service'; | ||
|
||
@Injectable() | ||
export class JwtStrategy extends PassportStrategy(Strategy) { | ||
constructor(private prisma: PrismaService) { | ||
super({ | ||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), | ||
ignoreExpiration: false, | ||
secretOrKey: process.env.JWT_SECRET, | ||
}); | ||
} | ||
|
||
async validate(payload: any) { | ||
const governanceAuthority = await this.prisma.governanceAuthority.findUnique({ | ||
where: { did: payload.did }, | ||
}); | ||
return { id: governanceAuthority.id, did: payload.did }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// src/auth/public.decorator.ts | ||
import { SetMetadata } from '@nestjs/common'; | ||
|
||
export const IS_PUBLIC_KEY = 'isPublic'; | ||
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { registerDecorator, ValidationOptions, ValidationArguments } from 'class-validator'; | ||
|
||
export function IsValidSchema(validationOptions?: ValidationOptions) { | ||
return function (object: Object, propertyName: string) { | ||
registerDecorator({ | ||
name: 'isValidSchema', | ||
target: object.constructor, | ||
propertyName: propertyName, | ||
options: validationOptions, | ||
validator: { | ||
validate(value: any, args: ValidationArguments) { | ||
return value.w3cUri || value.anonCredsDefinitionId; | ||
}, | ||
defaultMessage(args: ValidationArguments) { | ||
return 'Schema must have either w3cUri or anonCredsDefinitionId'; | ||
}, | ||
}, | ||
}); | ||
}; | ||
} |
Oops, something went wrong.