Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add revocation functions #250

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions services/credentials-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@nestjs/swagger": "^6.1.4",
"@nestjs/terminus": "^9.1.4",
"@prisma/client": "4.8.1",
"@techsavvyash/bitstring": "^3.2.0",
"@types/uuid": "^9.0.1",
"ajv": "^8.12.0",
"did-jwt-vc": "^3.1.0",
Expand Down
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 services/credentials-service/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[]
}
9 changes: 7 additions & 2 deletions services/credentials-service/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ 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 { RevocationList } from './revocation-list/revocation-list.helper';
import { RevocationListImpl } from './revocation-list/revocation-list.impl';
import { RevocationListService } from './revocation-list/revocation-list.service';
import { RevocationListModule } from './revocation-list/revocation-list.module';

@Module({
imports: [
HttpModule,
ConfigModule.forRoot({ isGlobal: true }),
CredentialsModule,
TerminusModule
TerminusModule,
RevocationListModule
],
controllers: [AppController],
providers: [AppService, ConfigService, PrismaClient, HealthCheckUtilsService],
providers: [AppService, ConfigService, PrismaClient, HealthCheckUtilsService, RevocationList, RevocationListImpl, RevocationListService],
})
export class AppModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ import { PrismaClient } from '@prisma/client';
imports: [HttpModule],
providers: [CredentialsService, PrismaClient, IdentityUtilsService, RenderingUtilsService, SchemaUtilsSerivce],
controllers: [CredentialsController],
exports: [IdentityUtilsService]
})
export class CredentialsModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// @ts-ignore
import { Bitstring } from '@techsavvyash/bitstring';

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

export class RevocationList {

private bitstring: any;
constructor({ length, buffer }: BitstringConstructorParam = { length: 100000 }) {
this.bitstring = new Bitstring({ length, buffer });
}

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 });
}
}
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 });
}
}
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 {}
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