OpenID for Verifiable Credential Issuance - Issuer

IMPORTANT the packages are in an early development stage and currently only supports the pre-authorized code flow of
OpenID4VCI! Work is underway for the Authorized Flows as well, but not fully supported yet
Background
The OpenID4VCI issuer is used in issuer type applications, where an organization is issuing the credential(s)
Credential Offer State Manager
The CredentialOfferState is used to track of the creation date of the credential offer:
export interface CredentialOfferState {
credentialOffer: CredentialOfferPayloadV1_0_11
createdOn: number
}
The ICredentialOfferStateManager allows to have a custom implementation of the state manager:
export interface ICredentialOfferStateManager {
setState(state: string, payload: CredentialOfferState): Promise<Map<string, CredentialOfferState>>
getState(state: string): Promise<CredentialOfferState | undefined>
hasState(state: string): Promise<boolean>
deleteState(state: string): Promise<boolean>
clearExpiredStates(timestamp?: number): Promise<void>
clearAllStates(): Promise<void>
}
Here is an example, an in-memory implementation of the ICredentialOfferStateManager
export class MemoryCredentialOfferStateManager implements ICredentialOfferStateManager {
private readonly credentialOfferStateManager: Map<string, CredentialOfferState>
constructor() {
this.credentialOfferStateManager = new Map()
}
async clearAllStates(): Promise<void> {
this.credentialOfferStateManager.clear()
}
async clearExpiredStates(timestamp?: number): Promise<void> {
const states = Array.from(this.credentialOfferStateManager.entries())
timestamp = timestamp ?? +new Date()
for (const [issuerState, state] of states) {
if (state.createdOn < timestamp) {
this.credentialOfferStateManager.delete(issuerState)
}
}
}
async deleteState(state: string): Promise<boolean> {
return this.credentialOfferStateManager.delete(state)
}
async getState(state: string): Promise<CredentialOfferState | undefined> {
return this.credentialOfferStateManager.get(state)
}
async hasState(state: string): Promise<boolean> {
return this.credentialOfferStateManager.has(state)
}
async setState(state: string, payload: CredentialOfferState): Promise<Map<string, CredentialOfferState>> {
return this.credentialOfferStateManager.set(state, payload)
}
}
Usage
Pass an instance of the state manager to the VC Issuer Builder
const vcIssuer = new VcIssuerBuilder()
.withAuthorizationServer('https://authorization-server')
.withCredentialEndpoint('https://credential-endpoint')
.withCredentialIssuer('https://credential-issuer')
.withIssuerDisplay({
name: 'example issuer',
locale: 'en-US',
})
.withCredentialsSupported(credentialsSupported)
.withInMemoryCredentialOfferStates(new MemoryCredentialOfferStateManager())
.build()