Skip to content
Open
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 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 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[]
}
10 changes: 8 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ 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 { 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,
],
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 {}
16 changes: 10 additions & 6 deletions src/credentials/credentials.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class CredentialsService {
}
return credentials.map((cred: VerifiableCredentials) => {
const res = cred.signed;
res['credentialSchemaId'] = cred.credential_schema;
delete res['options'];
res['id'] = cred.id;
return res as W3CCredential;
Expand All @@ -73,6 +74,7 @@ export class CredentialsService {
const credential = await this.prisma.verifiableCredentials.findUnique({
where: { id: id },
select: {
credential_schema: true,
signed: true,
},
});
Expand All @@ -82,6 +84,7 @@ export class CredentialsService {
}
// formatting the response as per the spec
const res = credential.signed;
res['credentialSchemaId'] = credential.credential_schema;
delete res['options'];
res['id'] = id;
let template = null;
Expand Down Expand Up @@ -288,16 +291,17 @@ export class CredentialsService {
issuer: getCreds.issuer?.id,
AND: filteringSubject
? Object.keys(filteringSubject).map((key: string) => ({
subject: {
path: [key.toString()],
equals: filteringSubject[key],
},
}))
subject: {
path: [key.toString()],
equals: filteringSubject[key],
},
}))
: [],
},
select: {
id: true,
signed: true,
credential_schema: true
},
skip: (page - 1) * limit,
take: limit,
Expand All @@ -316,7 +320,7 @@ export class CredentialsService {
// formatting the output as per the spec
delete signed['id'];
delete signed['options'];
return { id: cred.id, ...signed };
return { id: cred.id, ...signed, credentialSchemaId: cred.credential_schema };
});
}
}
36 changes: 36 additions & 0 deletions src/revocation-list/revocation-list.helper.ts
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 });
}
}
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