@sphereon/ssi-sdk.vc-status-list
Version:
Sphereon SSI-SDK plugin for Status List management, like StatusList2021.
403 lines (396 loc) • 17.3 kB
TypeScript
import { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution';
import { IIssuer, StatusListType, CredentialProofFormat, StatusListCredential, StatusListDriverType, StatusListIndexingDirection, StatusPurpose2021, StatusListCredentialIdMode, ICredentialStatus, OrPromise, ICredential, IVerifiableCredential } from '@sphereon/ssi-types';
import { IPluginMethodMap, IAgentContext, ICredentialIssuer, ICredentialVerifier, IKeyManager, CredentialPayload } from '@veramo/core';
import { DataSource } from 'typeorm';
import { StatusList, BitsPerStatus } from '@sd-jwt/jwt-status-list';
import { SdJwtVcPayload } from '@sd-jwt/sd-jwt-vc';
import { StatusListOpts } from '@sphereon/oid4vci-common';
import { BitstringStatusPurpose } from '@4sure-tech/vc-bitstring-status-lists';
import { IVcdmCredentialPlugin } from '@sphereon/ssi-sdk.credential-vcdm';
import { BitstringStatusListArgs, IStatusListEntity, StatusListEntity, IStatusListEntryEntity, IBitstringStatusListEntryEntity, BitstringStatusListEntryCredentialStatus } from '@sphereon/ssi-sdk.data-store';
import { StatusMethod } from 'credential-status';
interface DecodedStatusListPayload {
issuer: string;
id: string;
statusList: StatusList;
exp?: number;
ttl?: number;
iat: number;
}
interface IExtractedCredentialDetails {
id: string;
issuer: string | IIssuer;
encodedList: string;
decodedPayload?: DecodedStatusListPayload;
}
interface IStatusListImplementationResult {
id: string;
encodedList: string;
issuer: string | IIssuer;
type: StatusListType;
proofFormat: CredentialProofFormat;
length: number;
statusListCredential: StatusListCredential;
statuslistContentType: string;
correlationId?: string;
driverType?: StatusListDriverType;
}
interface IStatusList2021ImplementationResult extends IStatusListImplementationResult {
type: StatusListType.StatusList2021;
indexingDirection: StatusListIndexingDirection;
statusPurpose: StatusPurpose2021;
}
interface IOAuthStatusListImplementationResult extends IStatusListImplementationResult {
type: StatusListType.OAuthStatusList;
bitsPerStatus: number;
expiresAt?: Date;
}
interface IBitstringStatusListImplementationResult extends IStatusListImplementationResult {
type: StatusListType.BitstringStatusList;
statusPurpose: BitstringStatusPurpose | BitstringStatusPurpose[];
bitsPerStatus?: number;
validFrom?: Date;
validUntil?: Date;
ttl?: number;
}
declare enum StatusOAuth {
Valid = 0,
Invalid = 1,
Suspended = 2
}
declare enum Status2021 {
Valid = 0,
Invalid = 1
}
type StatusList2021Args = {
indexingDirection: StatusListIndexingDirection;
statusPurpose?: StatusPurpose2021;
};
type OAuthStatusListArgs = {
bitsPerStatus: BitsPerStatus;
expiresAt?: Date;
};
type BaseCreateNewStatusListArgs = {
type: StatusListType;
id: string;
issuer: string | IIssuer;
correlationId?: string;
length?: number;
proofFormat?: CredentialProofFormat;
keyRef?: string;
statusList2021?: StatusList2021Args;
oauthStatusList?: OAuthStatusListArgs;
bitstringStatusList?: BitstringStatusListArgs;
driverType?: StatusListDriverType;
};
type UpdateStatusList2021Args = {
statusPurpose: StatusPurpose2021;
};
type UpdateOAuthStatusListArgs = {
bitsPerStatus: BitsPerStatus;
expiresAt?: Date;
};
type UpdateBitstringStatusListArgs = {
statusPurpose: BitstringStatusPurpose;
bitsPerStatus: number;
validFrom?: Date;
validUntil?: Date;
ttl?: number;
};
interface UpdateStatusListFromEncodedListArgs {
type?: StatusListType;
statusListIndex: number | string;
value: number;
proofFormat?: CredentialProofFormat;
keyRef?: string;
correlationId?: string;
encodedList: string;
issuer: string | IIssuer;
id: string;
statusList2021?: UpdateStatusList2021Args;
oauthStatusList?: UpdateOAuthStatusListArgs;
bitstringStatusList?: UpdateBitstringStatusListArgs;
}
interface UpdateStatusListFromStatusListCredentialArgs {
statusListCredential: StatusListCredential;
keyRef?: string;
statusListIndex: number | string;
value: number | Status2021 | StatusOAuth;
}
interface StatusListResult {
id: string;
encodedList: string;
issuer: string | IIssuer;
type: StatusListType;
proofFormat: CredentialProofFormat;
length: number;
statusListCredential: StatusListCredential;
statuslistContentType: string;
correlationId?: string;
driverType?: StatusListDriverType;
statusList2021?: {
indexingDirection: StatusListIndexingDirection;
statusPurpose: StatusPurpose2021;
credentialIdMode: StatusListCredentialIdMode;
};
oauthStatusList?: {
bitsPerStatus: number;
expiresAt?: Date;
};
bitstringStatusList?: {
statusPurpose: BitstringStatusPurpose | BitstringStatusPurpose[];
bitsPerStatus?: number;
validFrom?: Date;
validUntil?: Date;
ttl?: number;
};
}
interface StatusList2021EntryCredentialStatus extends ICredentialStatus {
type: 'StatusList2021Entry';
statusPurpose: StatusPurpose2021;
statusListIndex: string;
statusListCredential: string;
}
interface StatusListOAuthEntryCredentialStatus extends ICredentialStatus {
type: 'OAuthStatusListEntry';
bitsPerStatus: number;
statusListIndex: string;
statusListCredential: string;
expiresAt?: Date;
}
interface StatusList2021ToVerifiableCredentialArgs {
issuer: string | IIssuer;
id: string;
type?: StatusListType;
proofFormat?: CredentialProofFormat;
keyRef?: string;
encodedList: string;
statusPurpose: StatusPurpose2021;
}
interface CreateStatusListArgs {
issuer: string | IIssuer;
id: string;
proofFormat?: CredentialProofFormat;
keyRef?: string;
correlationId?: string;
length?: number;
statusList2021?: StatusList2021Args;
oauthStatusList?: OAuthStatusListArgs;
bitstringStatusList?: BitstringStatusListArgs;
}
interface UpdateStatusListIndexArgs {
statusListCredential: StatusListCredential;
statusListIndex: number | string;
value: number | Status2021 | StatusOAuth;
bitsPerStatus?: number;
keyRef?: string;
expiresAt?: Date;
}
interface CheckStatusIndexArgs {
statusListCredential: StatusListCredential;
statusListIndex: string | number;
bitsPerStatus?: number;
}
interface IToDetailsFromCredentialArgs {
statusListCredential: StatusListCredential;
statusListType: StatusListType;
bitsPerStatus?: number;
correlationId?: string;
driverType?: StatusListDriverType;
}
interface IMergeDetailsWithEntityArgs {
extractedDetails: IExtractedCredentialDetails;
statusListEntity: IStatusListEntity;
}
/**
* The interface definition for a plugin that can add statuslist info to a credential
*
* @remarks Please see {@link https://www.w3.org/TR/vc-data-model | W3C Verifiable Credentials data model}
*
* @beta This API is likely to change without a BREAKING CHANGE notice
*/
interface IStatusListPlugin extends IPluginMethodMap {
/**
* Create a new status list
*
* @param args Status list information like type and size
* @param context - This reserved param is automatically added and handled by the framework, *do not override*
*
* @returns - The details of the newly created status list
*/
slCreateStatusList(args: CreateNewStatusListArgs, context: IRequiredContext): Promise<StatusListResult>;
/**
* Ensures status list info like index and list id is added to a credential
*
* @param args - Arguments necessary to add the statuslist info.
* @param context - This reserved param is automatically added and handled by the framework, *do not override*
*
* @returns - a promise that resolves to the credential now with status support
*
* @beta This API is likely to change without a BREAKING CHANGE notice
*/
slAddStatusToCredential(args: IAddStatusToCredentialArgs, context: IRequiredContext): Promise<CredentialWithStatusSupport>;
slAddStatusToSdJwtCredential(args: IAddStatusToSdJwtCredentialArgs, context: IRequiredContext): Promise<SdJwtVcPayload>;
/**
* Get the status list using the configured driver for the SL. Normally a correlationId or id should suffice. Optionally accepts a dbName/datasource
* @param args
* @param context
*/
slGetStatusList(args: GetStatusListArgs, context: IRequiredContext): Promise<StatusListResult>;
/**
* Import status lists when noy yet present
*
* @param imports Array of status list information like type and size
* @param context - This reserved param is automatically added and handled by the framework, *do not override*
*/
slImportStatusLists(imports: Array<CreateNewStatusListArgs>, context: IRequiredContext): Promise<boolean>;
}
type CreateNewStatusListFuncArgs = BaseCreateNewStatusListArgs;
type CreateNewStatusListArgs = BaseCreateNewStatusListArgs & {
dbName?: string;
dataSource?: OrPromise<DataSource>;
isDefault?: boolean;
};
type IAddStatusToCredentialArgs = Omit<IIssueCredentialStatusOpts, 'dataSource'> & {
credential: CredentialWithStatusSupport;
};
type IAddStatusToSdJwtCredentialArgs = Omit<IIssueCredentialStatusOpts, 'dataSource'> & {
credential: SdJwtVcPayload;
};
interface IIssueCredentialStatusOpts {
dataSource?: DataSource;
statusLists?: Array<StatusListOpts>;
credentialId?: string;
value?: string;
}
type GetStatusListArgs = {
id?: string;
correlationId?: string;
dataSource?: OrPromise<DataSource>;
dbName?: string;
};
type CredentialWithStatusSupport = ICredential | CredentialPayload | IVerifiableCredential;
type SignedStatusListData = {
statusListCredential: StatusListCredential;
encodedList: string;
};
type IRequiredPlugins = IVcdmCredentialPlugin & IIdentifierResolution;
type IRequiredContext = IAgentContext<ICredentialIssuer & ICredentialVerifier & IIdentifierResolution & IKeyManager & IVcdmCredentialPlugin>;
/**
* Fetches a status list credential from a URL
* @param args - Object containing the status list credential URL
* @returns Promise resolving to the fetched StatusListCredential
*/
declare function fetchStatusListCredential(args: {
statusListCredential: string;
}): Promise<StatusListCredential>;
/**
* Creates a status checking function for credential-status plugin
* @param args - Configuration options for status verification
* @returns StatusMethod function for checking credential status
*/
declare function statusPluginStatusFunction(args: {
documentLoader: any;
suite: any;
mandatoryCredentialStatus?: boolean;
verifyStatusListCredential?: boolean;
verifyMatchingIssuers?: boolean;
errorUnknownListType?: boolean;
}): StatusMethod;
/**
* Function that can be used together with @digitalbazar/vc and @digitialcredentials/vc
* @param args - Configuration options for status verification
* @returns Function for checking credential status
*/
declare function vcLibCheckStatusFunction(args: {
mandatoryCredentialStatus?: boolean;
verifyStatusListCredential?: boolean;
verifyMatchingIssuers?: boolean;
errorUnknownListType?: boolean;
}): (args: {
credential: StatusListCredential;
documentLoader: any;
suite: any;
}) => Promise<{
verified: boolean;
error?: any;
}>;
/**
* Checks the status of a credential using its credential status information
* @param args - Parameters for credential status verification
* @returns Promise resolving to verification result with error details if any
*/
declare function checkStatusForCredential(args: {
credential: StatusListCredential;
documentLoader: any;
suite: any;
mandatoryCredentialStatus?: boolean;
verifyStatusListCredential?: boolean;
verifyMatchingIssuers?: boolean;
errorUnknownListType?: boolean;
}): Promise<{
verified: boolean;
error?: any;
}>;
declare function simpleCheckStatusFromStatusListUrl(args: {
statusListCredential: string;
statusPurpose?: StatusPurpose2021;
type?: StatusListType | 'StatusList2021Entry';
id?: string;
statusListIndex: string;
}): Promise<number | Status2021 | StatusOAuth>;
/**
* Checks the status at a specific index in a status list credential
* @param args - Parameters including credential and index to check
* @returns Promise resolving to status value at the specified index
*/
declare function checkStatusIndexFromStatusListCredential(args: {
statusListCredential: StatusListCredential;
statusPurpose?: StatusPurpose2021 | string | string[];
type?: StatusListType | 'StatusList2021Entry' | 'BitstringStatusListEntry';
id?: string;
statusListIndex: string | number;
bitsPerStatus?: number;
}): Promise<number | Status2021 | StatusOAuth>;
declare function createNewStatusList(args: CreateNewStatusListFuncArgs, context: IAgentContext<(IVcdmCredentialPlugin | any) & IIdentifierResolution>): Promise<StatusListResult>;
/**
* Updates a status index in a status list credential
* @param args - Parameters for status update including credential and new value
* @param context - Agent context with required plugins
* @returns Promise resolving to updated status list details
*/
declare function updateStatusIndexFromStatusListCredential(args: UpdateStatusListIndexArgs, context: IAgentContext<IVcdmCredentialPlugin & IIdentifierResolution>): Promise<StatusListResult>;
/**
* Extracts credential details from a status list credential
* @param statusListCredential - The status list credential to extract from
* @returns Promise resolving to extracted credential details
*/
declare function extractCredentialDetails(statusListCredential: StatusListCredential): Promise<IExtractedCredentialDetails>;
declare function toStatusListDetails(args: IToDetailsFromCredentialArgs): Promise<StatusListResult & (IStatusList2021ImplementationResult | IOAuthStatusListImplementationResult | IBitstringStatusListImplementationResult)>;
declare function toStatusListDetails(args: IMergeDetailsWithEntityArgs): Promise<StatusListResult & (IStatusList2021ImplementationResult | IOAuthStatusListImplementationResult | IBitstringStatusListImplementationResult)>;
/**
* Creates a credential status object from status list and entry information
* @param args - Parameters including status list, entry, and index
* @returns Promise resolving to appropriate credential status type
*/
declare function createCredentialStatusFromStatusList(args: {
statusList: StatusListEntity;
statusListEntry: IStatusListEntryEntity | IBitstringStatusListEntryEntity;
statusListIndex: number;
}): Promise<StatusList2021EntryCredentialStatus | StatusListOAuthEntryCredentialStatus | BitstringStatusListEntryCredentialStatus>;
/**
* Updates a status list using a base64 encoded list of statuses
* @param args - Parameters including encoded list and update details
* @param context - Agent context with required plugins
* @returns Promise resolving to updated status list details
*/
declare function updateStatusListIndexFromEncodedList(args: UpdateStatusListFromEncodedListArgs, context: IAgentContext<IVcdmCredentialPlugin & IIdentifierResolution>): Promise<StatusListResult>;
/**
* Converts a StatusList2021 to a verifiable credential
* @param args - Parameters for credential creation including issuer and encoded list
* @param context - Agent context with required plugins
* @returns Promise resolving to signed status list credential
*/
declare function statusList2021ToVerifiableCredential(args: StatusList2021ToVerifiableCredentialArgs, context: IAgentContext<IVcdmCredentialPlugin & IIdentifierResolution>): Promise<StatusListCredential>;
declare function determineStatusListType(credential: StatusListCredential): StatusListType;
export { type BaseCreateNewStatusListArgs, type CheckStatusIndexArgs, type CreateNewStatusListArgs, type CreateNewStatusListFuncArgs, type CreateStatusListArgs, type CredentialWithStatusSupport, type GetStatusListArgs, type IAddStatusToCredentialArgs, type IAddStatusToSdJwtCredentialArgs, type IIssueCredentialStatusOpts, type IMergeDetailsWithEntityArgs, type IRequiredContext, type IRequiredPlugins, type IStatusListPlugin, type IToDetailsFromCredentialArgs, type OAuthStatusListArgs, type SignedStatusListData, Status2021, type StatusList2021Args, type StatusList2021EntryCredentialStatus, type StatusList2021ToVerifiableCredentialArgs, type StatusListOAuthEntryCredentialStatus, type StatusListResult, StatusOAuth, type UpdateBitstringStatusListArgs, type UpdateOAuthStatusListArgs, type UpdateStatusList2021Args, type UpdateStatusListFromEncodedListArgs, type UpdateStatusListFromStatusListCredentialArgs, type UpdateStatusListIndexArgs, checkStatusForCredential, checkStatusIndexFromStatusListCredential, createCredentialStatusFromStatusList, createNewStatusList, determineStatusListType, extractCredentialDetails, fetchStatusListCredential, simpleCheckStatusFromStatusListUrl, statusList2021ToVerifiableCredential, statusPluginStatusFunction, toStatusListDetails, updateStatusIndexFromStatusListCredential, updateStatusListIndexFromEncodedList, vcLibCheckStatusFunction };