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: w3c revocation using bit string status list for dedicated and multi-tenancy #171

Draft
wants to merge 19 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f10b842
refactor: add patch to credo to handle change in credential format to…
GHkrishna Jul 2, 2024
94fcaba
chore: start w3c revocation controller
GHkrishna Jul 3, 2024
c2cd406
Merge branch 'develop' of https://github.com/credebl/credo-controller…
GHkrishna Jul 3, 2024
a48c58b
feat: able to create statusListCredential
GHkrishna Jul 4, 2024
197ef0d
Merge branch 'develop' of https://github.com/credebl/credo-controller…
GHkrishna Jul 4, 2024
1a8697c
fix: add signing and storing capability of w3c status list credential
GHkrishna Jul 23, 2024
8b1c1c6
feat: implement w3c revoke functionality
Aug 8, 2024
dfc729e
feat: implement index find and updation when sending offer
Aug 9, 2024
a67acf4
feat: implemented w3c revocation with verification
Aug 13, 2024
211e447
feat: implemented w3c revocation for multi-tenancy
Aug 14, 2024
dede0d9
Merge branch 'develop' of https://github.com/credebl/credo-controller…
Aug 14, 2024
32dc113
fix: optimize the bit string credential function
Aug 16, 2024
9572f1e
fix: bug for create bit status string credential
Aug 16, 2024
1f5a098
fix: added the pako package for the compress the bitstring status lis…
Aug 28, 2024
3983dfc
refactor: added revocation notification for dedicated and multi-tenancy
Sep 3, 2024
3f4f66d
fix: revocation notification payload
Sep 3, 2024
f7d0c8c
feat: w3c revocation notification
Sep 4, 2024
1e775c9
Merge branch 'develop' of https://github.com/credebl/credo-controller…
Sep 4, 2024
415b614
refactor: oob revocation credential function
Sep 5, 2024
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
Prev Previous commit
Next Next commit
feat: implement w3c revoke functionality
Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>
  • Loading branch information
KulkarniShashank committed Aug 8, 2024
commit 8b1c1c65dd027e763e1f39d570bf0eac768d4d2d
5 changes: 5 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"port": 4001,
"schemaFileServerURL": "https://schema.credebl.id/schemas/",
"bitStringStatusListURL": "http://192.168.1.125:5005/credentials/status/1"
}
2 changes: 2 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ interface Parsed {
rpcUrl?: string
fileServerUrl?: string
fileServerToken?: string
bitStringStatusListURL?: string
}

interface InboundTransport {
@@ -253,5 +254,6 @@ export async function runCliServer() {
rpcUrl: parsed.rpcUrl,
fileServerUrl: parsed.fileServerUrl,
fileServerToken: parsed.fileServerToken,
bitStringStatusListURL: parsed.bitStringStatusListURL,
} as AriesRestConfig)
}
3 changes: 3 additions & 0 deletions src/cliAgent.ts
Original file line number Diff line number Diff line change
@@ -108,6 +108,7 @@ export interface AriesRestConfig {
fileServerToken?: string
walletScheme?: AskarMultiWalletDatabaseScheme
schemaFileServerURL?: string
bitStringStatusListURL?: string
}

export async function readRestConfig(path: string) {
@@ -260,6 +261,7 @@ async function generateSecretKey(length: number = 32): Promise<string> {

export async function runRestAgent(restConfig: AriesRestConfig) {
const {
bitStringStatusListURL,
schemaFileServerURL,
logLevel,
inboundTransports = [],
@@ -439,6 +441,7 @@ export async function runRestAgent(restConfig: AriesRestConfig) {
webhookUrl,
port: adminPort,
schemaFileServerURL,
bitStringStatusListURL,
},
token
)
60 changes: 59 additions & 1 deletion src/controllers/credentials/CredentialController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import type { RestAgentModules } from '../../cliAgent'
import type { CredentialExchangeRecordProps, CredentialProtocolVersionType, Routing } from '@credo-ts/core'
import type { BitStringCredential } from '../types'
import type {
CredentialExchangeRecordProps,
CredentialProtocolVersionType,
CredentialStatus,
Routing,
} from '@credo-ts/core'

import { CredentialState, Agent, W3cCredentialService, Key, KeyType, CredentialRole } from '@credo-ts/core'
import * as fs from 'fs'
import { injectable } from 'tsyringe'
import { promisify } from 'util'
import * as zlib from 'zlib'

import ErrorHandlingService from '../../errorHandlingService'
import { CredentialExchangeRecordExample, RecordId } from '../examples'
@@ -155,13 +164,62 @@ export class CredentialController extends Controller {
@Post('/create-offer')
public async createOffer(@Body() createOfferOptions: CreateOfferOptions) {
try {
if (createOfferOptions.credentialFormats.jsonld) {
if (createOfferOptions.isRevocable) {
const credentialStatus = await this.getCredentialStatus(createOfferOptions)
createOfferOptions.credentialFormats.jsonld.credential.credentialStatus = credentialStatus
}
}
const offer = await this.agent.credentials.offerCredential(createOfferOptions)
return offer
} catch (error) {
throw ErrorHandlingService.handle(error)
}
}

private async getCredentialStatus(createOfferOptions: CreateOfferOptions) {
try {
const bitStringStatusListURL = fs.readFileSync('config.json', 'utf-8')
const configJson = JSON.parse(bitStringStatusListURL)

if (!configJson.bitStringStatusListURL) {
throw new Error('Please provide valid bitStringStatusList server URL')
}

const bitStringStatusListCredential = await fetch(configJson.bitStringStatusListURL, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})

if (!bitStringStatusListCredential.ok) {
throw new Error(`HTTP error! Status: ${bitStringStatusListCredential.status}`)
}

const bitStringCredential = (await bitStringStatusListCredential.json()) as BitStringCredential
const encodedBitString = bitStringCredential.credential.credentialSubject.encodedList
const gunzip = promisify(zlib.gunzip)

const compressedBuffer = Buffer.from(encodedBitString, 'base64')
const decompressedBuffer = await gunzip(compressedBuffer)
const decodedBitString = decompressedBuffer.toString('binary')
const index = decodedBitString.indexOf('0')

const credentialStatus = {
id: `${configJson.bitStringStatusListURL}#${index}`,
type: 'BitstringStatusListEntry',
statusPurpose: createOfferOptions.statusPurpose,
statusListIndex: index.toString(),
statusListCredential: configJson.bitStringStatusListURL,
} as unknown as CredentialStatus

return credentialStatus
} catch (error) {
throw ErrorHandlingService.handle(error)
}
}

@Post('/create-offer-oob')
public async createOfferOob(@Body() outOfBandOption: CreateOfferOobOptions) {
try {
20 changes: 20 additions & 0 deletions src/controllers/types.ts
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ import type {
Attachment,
KeyType,
JsonLdCredentialFormat,
CredentialStatusPurpose,
} from '@credo-ts/core'
import type { DIDDocument } from 'did-resolver'

@@ -88,12 +89,16 @@ export interface AcceptCredentialProposalOptions {
comment?: string
}

export type CredentialStatusType = 'BitstringStatusListEntry'

export interface CreateOfferOptions {
isRevocable: boolean
protocolVersion: ProtocolVersion
connectionId: RecordId
credentialFormats: CredentialFormatPayload<CredentialFormats, 'createOffer'>
autoAcceptCredential?: AutoAcceptCredential
comment?: string
statusPurpose: CredentialStatusPurpose
}

type CredentialFormatType = LegacyIndyCredentialFormat | JsonLdCredentialFormat | AnonCredsCredentialFormat
@@ -397,3 +402,18 @@ export interface StatusList {
getStatus(index: any): any
encode(): Promise<any>
}

export interface SignCredentialPayload {
id: string
issuerId: string
statusPurpose: string
bitStringLength: number
}

export interface BitStringCredential {
credential: {
credentialSubject: {
encodedList: string
}
}
}
Loading