-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80ed883
commit 6a8dc00
Showing
10 changed files
with
381 additions
and
3 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
prisma/migrations/20230908124838_add_revocation_list/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 @@ | ||
-- CreateTable | ||
CREATE TABLE "RevocationLists" ( | ||
"issuer" TEXT NOT NULL, | ||
"latestRevocationListId" TEXT NOT NULL, | ||
"lastCredentialIdx" INTEGER NOT NULL, | ||
"allRevocationLists" TEXT[], | ||
|
||
CONSTRAINT "RevocationLists_pkey" PRIMARY KEY ("issuer") | ||
); |
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
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,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 }); | ||
} | ||
} |
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 { 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 }); | ||
} | ||
} |
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,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 {} |
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,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(); | ||
}); | ||
}); |
Oops, something went wrong.