Skip to content

Commit d54d66e

Browse files
authored
Merge pull request #261 from credebl/refactor/w3c-revocation-v1
revert: revocation code
2 parents 08a04a4 + ee9b63d commit d54d66e

File tree

6 files changed

+1
-490
lines changed

6 files changed

+1
-490
lines changed

src/constants.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/controllers/credentials/CredentialController.ts

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ import {
1313
CredentialRole,
1414
createPeerDidDocumentFromServices,
1515
PeerDidNumAlgo,
16-
ClaimFormat,
1716
} from '@credo-ts/core'
18-
import axios from 'axios'
1917
import { injectable } from 'tsyringe'
20-
import { v4 as uuidv4 } from 'uuid'
2118

2219
import ErrorHandlingService from '../../errorHandlingService'
2320
import { CredentialExchangeRecordExample, RecordId } from '../examples'
@@ -33,15 +30,6 @@ import {
3330
ThreadId,
3431
} from '../types'
3532

36-
import { initialBitsEncoded } from 'src/constants'
37-
import {
38-
CredentialContext,
39-
CredentialStatusListType,
40-
CredentialType,
41-
RevocationListType,
42-
SignatureType,
43-
} from 'src/enums/enum'
44-
import { BadRequestError, InternalServerError } from 'src/errors'
4533
import { Body, Controller, Get, Path, Post, Route, Tags, Example, Query, Security } from 'tsoa'
4634

4735
@Tags('Credentials')
@@ -326,137 +314,4 @@ export class CredentialController extends Controller {
326314
throw ErrorHandlingService.handle(error)
327315
}
328316
}
329-
330-
/**
331-
* Create bitstring status list credential
332-
*
333-
* @param tenantId Id of the tenant
334-
* @param request BSLC required details
335-
*/
336-
@Security('apiKey')
337-
@Post('/create-bslc')
338-
public async createBitstringStatusListCredential(
339-
@Path('tenantId') tenantId: string,
340-
@Body() request: { issuerDID: string; statusPurpose: string; verificationMethod: string }
341-
) {
342-
try {
343-
const { issuerDID, statusPurpose, verificationMethod } = request
344-
const bslcId = uuidv4()
345-
const credentialpayload = {
346-
'@context': [`${CredentialContext.V1}`, `${CredentialContext.V2}`],
347-
id: `${process.env.BSLC_SERVER_URL}/bitstring/${bslcId}`,
348-
type: [`${CredentialType.VerifiableCredential}`, `${CredentialType.BitstringStatusListCredential}`],
349-
issuer: {
350-
id: issuerDID as string,
351-
},
352-
issuanceDate: new Date().toISOString(),
353-
credentialSubject: {
354-
id: `${process.env.BSLC_SERVER_URL}/bitstring/${bslcId}`,
355-
type: `${RevocationListType.Bitstring}`,
356-
statusPurpose: statusPurpose,
357-
encodedList: initialBitsEncoded,
358-
},
359-
credentialStatus: {
360-
id: `${process.env.BSLC_SERVER_URL}/bitstring/${bslcId}`,
361-
type: CredentialStatusListType.CredentialStatusList2017,
362-
},
363-
}
364-
365-
let signedCredential
366-
// Step 2: Sign the payload
367-
try {
368-
//TODO: Add correct type here
369-
signedCredential = await this.agent.w3cCredentials.signCredential({
370-
credential: credentialpayload,
371-
format: ClaimFormat.LdpVc,
372-
proofType: SignatureType.Ed25519Signature2018,
373-
verificationMethod,
374-
})
375-
} catch (signingError) {
376-
throw new InternalServerError(`Failed to sign the BitstringStatusListCredential: ${signingError}`)
377-
}
378-
// Step 3: Upload the signed payload to the server
379-
const serverUrl = process.env.BSLC_SERVER_URL
380-
if (!serverUrl) {
381-
throw new Error('BSLC_SERVER_URL is not defined in the environment variables')
382-
}
383-
384-
const token = process.env.BSLC_SERVER_TOKEN
385-
if (!token) {
386-
throw new Error('BSLC_SERVER_TOKEN is not defined in the environment variables')
387-
}
388-
const url = `${serverUrl}/bitstring`
389-
const bslcPayload = {
390-
id: bslcId,
391-
bslcObject: signedCredential,
392-
}
393-
try {
394-
const response = await axios.post(url, bslcPayload, {
395-
headers: {
396-
Accept: '*/*',
397-
Authorization: `Bearer ${token}`,
398-
'Content-Type': 'application/json',
399-
},
400-
})
401-
402-
if (response.status !== 200) {
403-
throw new Error('Failed to upload the signed BitstringStatusListCredential')
404-
}
405-
} catch (error) {
406-
throw new InternalServerError(`Error uploading the BitstringStatusListCredential: ${error}`)
407-
}
408-
return signedCredential
409-
} catch (error) {
410-
throw ErrorHandlingService.handle(error)
411-
}
412-
}
413-
414-
@Security('apiKey')
415-
@Post('/get-empty-index/:BSLCUrl')
416-
public async getEmptyIndexForBSLC(@Path('BSLCUrl') BSLCUrl: string) {
417-
try {
418-
if (!BSLCUrl) {
419-
throw new BadRequestError('BSLCUrl is required')
420-
}
421-
422-
const response = await axios.get(BSLCUrl)
423-
if (response.status !== 200) {
424-
throw new Error('Failed to fetch the BitstringStatusListCredential')
425-
}
426-
427-
const credential = response.data
428-
const encodedList = credential?.credentialSubject?.claims.encodedList
429-
if (!encodedList) {
430-
throw new Error('Encoded list not found in the credential')
431-
}
432-
433-
let bitstring
434-
try {
435-
const compressedData = Buffer.from(encodedList, 'base64').toString('binary')
436-
bitstring = Array.from(compressedData)
437-
.map((byte) => byte.padStart(8, '0'))
438-
.join('')
439-
} catch (error) {
440-
throw new Error('Failed to decompress and process the encoded list')
441-
}
442-
443-
const unusedIndexes = []
444-
for (let i = 0; i < bitstring.length; i++) {
445-
if (bitstring[i] === '0') {
446-
unusedIndexes.push(i)
447-
}
448-
}
449-
//TODO: add logic to filter from used indexs, for now returning random index with bit status as 0.
450-
if (unusedIndexes.length === 0) {
451-
throw new Error('No unused index found in the BitstringStatusList')
452-
}
453-
454-
const randomIndex = unusedIndexes[Math.floor(Math.random() * unusedIndexes.length)]
455-
return {
456-
index: randomIndex,
457-
}
458-
} catch (error) {
459-
throw ErrorHandlingService.handle(error)
460-
}
461-
}
462317
}

src/controllers/multi-tenancy/MultiTenancyController.ts

Lines changed: 0 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,19 @@ import {
4545
injectable,
4646
createPeerDidDocumentFromServices,
4747
PeerDidNumAlgo,
48-
ClaimFormat,
4948
} from '@credo-ts/core'
5049
import { QuestionAnswerRole, QuestionAnswerState } from '@credo-ts/question-answer'
5150
import axios from 'axios'
5251
import * as fs from 'fs'
53-
import { v4 as uuidv4 } from 'uuid'
54-
// import * as zlib from 'zlib'
55-
// import { inflate } from 'pako'
5652

57-
import { initialBitsEncoded } from '../../constants'
5853
import {
59-
CredentialContext,
6054
CredentialEnum,
61-
CredentialStatusListType,
62-
CredentialType,
6355
DidMethod,
6456
EndorserMode,
6557
Network,
6658
NetworkTypes,
67-
RevocationListType,
6859
Role,
6960
SchemaError,
70-
SignatureType,
7161
} from '../../enums/enum'
7262
import ErrorHandlingService from '../../errorHandlingService'
7363
import { ENDORSER_DID_NOT_PRESENT } from '../../errorMessages'
@@ -1923,140 +1913,4 @@ export class MultiTenancyController extends Controller {
19231913
throw ErrorHandlingService.handle(error)
19241914
}
19251915
}
1926-
1927-
/**
1928-
* Create bitstring status list credential
1929-
*
1930-
* @param tenantId Id of the tenant
1931-
* @param request BSLC required details
1932-
*/
1933-
@Security('apiKey')
1934-
@Post('/create-bslc/:tenantId')
1935-
public async createBitstringStatusListCredential(
1936-
@Path('tenantId') tenantId: string,
1937-
@Body() request: { issuerDID: string; statusPurpose: string, verificationMethod:string }
1938-
) {
1939-
try {
1940-
const { issuerDID, statusPurpose, verificationMethod } = request
1941-
const bslcId = uuidv4()
1942-
const credentialpayload = {
1943-
'@context': [`${CredentialContext.V1}`, `${CredentialContext.V2}`],
1944-
id: `${process.env.BSLC_SERVER_URL}/bitstring/${bslcId}`,
1945-
type: [`${CredentialType.VerifiableCredential}`, `${CredentialType.BitstringStatusListCredential}`],
1946-
issuer: {
1947-
id: issuerDID as string,
1948-
},
1949-
issuanceDate: new Date().toISOString(),
1950-
credentialSubject: {
1951-
id: `${process.env.BSLC_SERVER_URL}/bitstring/${bslcId}`,
1952-
type: `${RevocationListType.Bitstring}`,
1953-
statusPurpose: statusPurpose,
1954-
encodedList: initialBitsEncoded,
1955-
},
1956-
credentialStatus: {
1957-
id: `${process.env.BSLC_SERVER_URL}/bitstring/${bslcId}`,
1958-
type: CredentialStatusListType.CredentialStatusList2017,
1959-
},
1960-
}
1961-
1962-
let signedCredential
1963-
1964-
await this.agent.modules.tenants.withTenantAgent({ tenantId }, async (tenantAgent) => {
1965-
// Step 2: Sign the payload
1966-
try {
1967-
//TODO: Add correct type here
1968-
signedCredential = await tenantAgent.w3cCredentials.signCredential({
1969-
credential: credentialpayload,
1970-
format: ClaimFormat.LdpVc,
1971-
proofType: SignatureType.Ed25519Signature2018,
1972-
verificationMethod,
1973-
})
1974-
} catch (signingError) {
1975-
throw new InternalServerError(`Failed to sign the BitstringStatusListCredential: ${signingError}`)
1976-
}
1977-
})
1978-
// Step 3: Upload the signed payload to the server
1979-
const serverUrl = process.env.BSLC_SERVER_URL
1980-
if (!serverUrl) {
1981-
throw new Error('BSLC_SERVER_URL is not defined in the environment variables')
1982-
}
1983-
1984-
const token = process.env.BSLC_SERVER_TOKEN
1985-
if (!token) {
1986-
throw new Error('BSLC_SERVER_TOKEN is not defined in the environment variables')
1987-
}
1988-
const url = `${serverUrl}/bitstring`
1989-
const bslcPayload = {
1990-
id: bslcId,
1991-
bslcObject: signedCredential,
1992-
}
1993-
try {
1994-
const response = await axios.post(url, bslcPayload, {
1995-
headers: {
1996-
Accept: '*/*',
1997-
Authorization: `Bearer ${token}`,
1998-
'Content-Type': 'application/json',
1999-
},
2000-
})
2001-
2002-
if (response.status !== 200) {
2003-
throw new Error('Failed to upload the signed BitstringStatusListCredential')
2004-
}
2005-
} catch (error) {
2006-
throw new InternalServerError(`Error uploading the BitstringStatusListCredential: ${error}`)
2007-
}
2008-
return signedCredential
2009-
} catch (error) {
2010-
throw ErrorHandlingService.handle(error)
2011-
}
2012-
}
2013-
2014-
@Security('apiKey')
2015-
@Post('/get-empty-index/:BSLCUrl')
2016-
public async getEmptyIndexForBSLC(@Path('BSLCUrl') BSLCUrl: string) {
2017-
try {
2018-
if (!BSLCUrl) {
2019-
throw new BadRequestError('BSLCUrl is required')
2020-
}
2021-
2022-
const response = await axios.get(BSLCUrl)
2023-
if (response.status !== 200) {
2024-
throw new Error('Failed to fetch the BitstringStatusListCredential')
2025-
}
2026-
2027-
const credential = response.data
2028-
const encodedList = credential?.credentialSubject?.claims.encodedList
2029-
if (!encodedList) {
2030-
throw new Error('Encoded list not found in the credential')
2031-
}
2032-
2033-
let bitstring
2034-
try {
2035-
const compressedData = Buffer.from(encodedList, 'base64').toString('binary')
2036-
bitstring = Array.from(compressedData)
2037-
.map((byte) => byte.padStart(8, '0'))
2038-
.join('')
2039-
} catch (error) {
2040-
throw new Error('Failed to decompress and process the encoded list')
2041-
}
2042-
2043-
const unusedIndexes = []
2044-
for (let i = 0; i < bitstring.length; i++) {
2045-
if (bitstring[i] === '0') {
2046-
unusedIndexes.push(i)
2047-
}
2048-
}
2049-
//TODO: add logic to filter from used indexs, for now returning random index with bit status as 0.
2050-
if (unusedIndexes.length === 0) {
2051-
throw new Error('No unused index found in the BitstringStatusList')
2052-
}
2053-
2054-
const randomIndex = unusedIndexes[Math.floor(Math.random() * unusedIndexes.length)]
2055-
return {
2056-
index: randomIndex,
2057-
}
2058-
} catch (error) {
2059-
throw ErrorHandlingService.handle(error)
2060-
}
2061-
}
20621916
}

src/enums/enum.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,4 @@ export enum HttpStatusCode {
7070
export declare enum CustomHandshakeProtocol {
7171
DidExchange = 'https://didcomm.org/didexchange/1.1',
7272
Connections = 'https://didcomm.org/connections/1.0',
73-
}
74-
75-
export enum CredentialContext {
76-
V1 = 'https://www.w3.org/2018/credentials/v1',
77-
V2 = 'https://www.w3.org/ns/credentials/v2',
78-
}
79-
80-
export enum CredentialType {
81-
VerifiableCredential = 'VerifiableCredential',
82-
BitstringStatusListCredential = 'BitstringStatusListCredential',
83-
}
84-
export enum RevocationListType {
85-
Bitstring = 'BitstringStatusList',
86-
}
87-
88-
export enum CredentialStatusListType {
89-
CredentialStatusList2017 = 'CredentialStatusList2017',
90-
}
91-
export enum SignatureType {
92-
Ed25519Signature2018 = 'Ed25519Signature2018',
93-
}
73+
}

0 commit comments

Comments
 (0)