Skip to content

Commit

Permalink
feat: add revocation functions
Browse files Browse the repository at this point in the history
  • Loading branch information
techsavvyash committed Sep 8, 2023
1 parent 80ed883 commit 6a8dc00
Show file tree
Hide file tree
Showing 10 changed files with 381 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- CreateTable
CREATE TABLE "RevocationLists" (
"issuer" TEXT NOT NULL,
"latestRevocationListId" TEXT NOT NULL,
"lastCredentialIdx" INTEGER NOT NULL,
"allRevocationLists" TEXT[],

CONSTRAINT "RevocationLists_pkey" PRIMARY KEY ("issuer")
);
7 changes: 7 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ model VerifiableCredentials {
updatedBy String?
tags String[]
}

model RevocationLists {
issuer String @id
latestRevocationListId String
lastCredentialIdx Int
allRevocationLists String[]
}
12 changes: 10 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ import { CredentialsModule } from './credentials/credentials.module';
import { TerminusModule } from '@nestjs/terminus';
import { HealthCheckUtilsService } from './credentials/utils/healthcheck.utils.service';
import { PrismaClient } from '@prisma/client';
import { RevocationListService } from './revocation-list/revocation-list.service';
import { RevocationListModule } from './revocation-list/revocation-list.module';
import { UtilsModule } from './utils/utils.module';
import { RevocationList } from './revocation-list/revocation-list.helper';
import { RevocationListImpl } from './revocation-list/revocation-list.impl';
import { IdentityUtilsService } from './credentials/utils/identity.utils.service';

@Module({
imports: [
HttpModule,
ConfigModule.forRoot({ isGlobal: true }),
CredentialsModule,
TerminusModule
TerminusModule,
RevocationListModule,
UtilsModule
],
controllers: [AppController],
providers: [AppService, ConfigService, PrismaClient, HealthCheckUtilsService],
providers: [AppService, ConfigService, PrismaClient, HealthCheckUtilsService, RevocationListService, RevocationList, RevocationListImpl, IdentityUtilsService],
})
export class AppModule {}
4 changes: 3 additions & 1 deletion src/credentials/credentials.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { IdentityUtilsService } from './utils/identity.utils.service';
import { RenderingUtilsService } from './utils/rendering.utils.service';
import { SchemaUtilsSerivce } from './utils/schema.utils.service';
import { PrismaClient } from '@prisma/client';
import { HealthCheckUtilsService } from './utils/healthcheck.utils.service';

@Module({
imports: [HttpModule],
providers: [CredentialsService, PrismaClient, IdentityUtilsService, RenderingUtilsService, SchemaUtilsSerivce],
providers: [CredentialsService, PrismaClient, IdentityUtilsService, RenderingUtilsService, SchemaUtilsSerivce, HealthCheckUtilsService],
controllers: [CredentialsController],
exports: [HealthCheckUtilsService]
})
export class CredentialsModule {}
42 changes: 42 additions & 0 deletions src/revocation-list/revocation-list.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Injectable } from '@nestjs/common';
// @ts-ignore
import { Bitstring } from '@SamagraX-RCW/bitstring';

type BitstringConstructorParam = {
length?: number,
buffer?: Uint8Array
};

export class RevocationList {

private bitstring: any;
// private length: number;

constructor({ length, buffer }: BitstringConstructorParam = { length: 100000 }) {
// if (length === undefined) length = 100000;
this.bitstring = new Bitstring({ length, buffer });
// this.length = this.bitstring.length;
}


setRevoked(index, revoked) {
if (typeof revoked !== 'boolean') {
throw new TypeError('revoked must be a boolean.');
}

return this.bitstring.set(index, revoked);
}

isRevoked(index) {
return this.bitstring.get(index);
}

async encode() {
return this.bitstring.encodeBits();
}

static async decode({ encodedList }) {
const buffer = await Bitstring.decodeBits({ encoded: encodedList });
return new RevocationList({ buffer });
}
}
15 changes: 15 additions & 0 deletions src/revocation-list/revocation-list.impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Injectable } from '@nestjs/common';
import { RevocationList } from './revocation-list.helper';

@Injectable()
export class RevocationListImpl {
constructor() {}

public createList({ length }) {
return new RevocationList({ length });
}

public async decodeList({ encodedList }) {
return await RevocationList.decode({ encodedList });
}
}
14 changes: 14 additions & 0 deletions src/revocation-list/revocation-list.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { RevocationListService } from './revocation-list.service';
import { RevocationList } from './revocation-list.helper';
import { PrismaClient } from '@prisma/client';
import { RevocationListImpl } from './revocation-list.impl';
import { CredentialsModule } from 'src/credentials/credentials.module';
import { IdentityUtilsService } from 'src/credentials/utils/identity.utils.service';
import { HttpModule, HttpService } from '@nestjs/axios';

@Module({
imports: [HttpModule],
providers: [RevocationList, RevocationListService, PrismaClient, RevocationListImpl, IdentityUtilsService]
})
export class RevocationListModule {}
18 changes: 18 additions & 0 deletions src/revocation-list/revocation-list.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { RevocationListService } from './revocation-list.service';

describe('RevocationListService', () => {
let service: RevocationListService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [RevocationListService],
}).compile();

service = module.get<RevocationListService>(RevocationListService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
Loading

0 comments on commit 6a8dc00

Please sign in to comment.