Development
State Manager
Get Started
SSI SDK
OID4VC
- Introduction
- Issuance (OID4VCI)
- Introduction
- REST
- OpenAPI
- Credential Design
- Authorization code
- Presentation during issuance
- Development
- Relying Party (OID4VP & SIOPv2)
Status Lists
- Introduction
- REST
- OpenAPI
W3C VC API
DIF Universal Resolver+Registrar
Mobile Wallet
eIDAS Advanced Electronic Signature Client
Well Known DID client
Development
State Manager
The CredentialOfferState is used to track of the creation date of the credential offer:
export interface CredentialOfferState {
credentialOffer: CredentialOfferPayloadV1_0_15
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> // clears all expired states compared against timestamp if provided, otherwise current timestamp
clearAllStates(): Promise<void> // clears all states
}
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',
})
.withCredentialConfigurationsSupported(credentialConfigurationsSupported)
.withInMemoryCredentialOfferStates(new MemoryCredentialOfferStateManager())
.build()
Multi-Authorization Server Support
In v1.0-15, Credential Issuers can work with multiple Authorization Servers. When building your issuer configuration:
const vcIssuer = new VcIssuerBuilder()
.withAuthorizationServers(['https://as1.example.com', 'https://as2.example.com']) // Array of AS identifiers
.withCredentialEndpoint('https://credential-endpoint')
.withCredentialIssuer('https://credential-issuer')
// ... rest of configuration
.build()
On this page