@vdcs/oid4vci
Version:
OpenID4VCI reference implementation in typescript
247 lines (239 loc) • 8.33 kB
TypeScript
type CredentialResponse = {
credentials: Array<{
credential: string | Record<string, unknown>;
}>;
notification_id?: string;
} | {
transaction_id: string;
notification_id?: string;
};
type CredentialOfferType = 'authorization_code' | 'pre-authorized_code';
type CredentialOfferOptionBase = {
type: CredentialOfferType;
credential_configuration_ids?: string[];
authorization_server?: string;
useRef?: boolean;
};
/**
* Transaction code
*
* @param input_mode - Input mode (numeric or text) default is numeric
* @param length - Length of transaction code (if used for creating credential offer then default is 4)
* @param description - Description of transaction code
*/
type TxCode = {
input_mode?: 'numeric' | 'text';
length?: number;
description?: string;
};
type CredentialOfferPreAuthOption = CredentialOfferOptionBase & {
type: 'pre-authorized_code';
tx_code?: TxCode;
};
type CredentialOfferAuthorizationCodeOption = CredentialOfferOptionBase & {
type: 'authorization_code';
issuer_state?: string;
};
type CredentialOfferOption = CredentialOfferPreAuthOption | CredentialOfferAuthorizationCodeOption;
type AuthorizationCodeGrant = {
authorization_code: {
issuer_state?: string;
authorization_server?: string;
};
};
type PreAuthorizedCodeGrant = {
'urn:ietf:params:oauth:grant-type:pre-authorized_code': {
'pre-authorized_code': string;
tx_code?: TxCode;
authorization_server?: string;
};
};
type Grant = AuthorizationCodeGrant | PreAuthorizedCodeGrant;
/**
* Credential offer
*
* @param credential_issuer - Credential issuer
* @param credential_configuration_ids - Credential configuration IDs
* @param grants - Grants (contains authorization_code or pre-authorized_code)
*/
type CredentialOffer = {
credential_issuer: string;
credential_configuration_ids: string[];
grants?: Grant;
};
/**
* Response of credential offer
*
* @param raw - Credential Offer Object
* @param credential_offer - URL encoded credential offer
* @param credential_offer_uri - URL encoded credential offer URI (when useRef is true)
* @param credential_offer_uri_key - Key of credential offer URI (when useRef is true)
* @param pre-authorized_code - Pre-authorized code (when type is pre-authorized_code)
* @param tx_code - Transaction code (when type is pre-authorized_code)
*/
type CredentialOfferResponse = {
raw: CredentialOffer;
credential_offer: string;
credential_offer_uri?: string;
credential_offer_uri_key?: string;
'pre-authorized_code'?: string;
tx_code?: string;
};
type AttackPotentialResistance = 'iso_18045_high' | 'iso_18045_moderate' | 'iso_18045_enhanced-basic' | 'iso_18045_basic';
type ProofType = 'jwt' | 'ldp_vp' | 'attestation';
type Format = 'jwt_vc_json' | 'jwt_vc_json-ld' | 'ldp_vc' | 'mso_mdoc' | 'dc+sd-jwt';
type Claim = {
path: string[];
mandatory?: boolean;
display?: {
name?: string;
locale?: string;
};
};
type CredentialConfigurationSupported = {
format: Format | string;
scope?: string;
cryptographic_binding_methods_supported?: Array<string>;
credential_signing_alg_values_supported?: Array<string>;
proof_types_supported?: {
[proofType: string]: {
proof_signing_alg_values_supported: string;
key_attestations_required?: {
key_storage?: Array<AttackPotentialResistance>;
user_authentication?: Array<AttackPotentialResistance>;
};
};
};
display?: Array<{
name: string;
locale?: string;
logo?: {
uri: string;
alt_text?: string;
};
description?: string;
background_color?: string;
background_image?: {
uri: string;
};
text_color?: string;
}>;
} & (JwtVcJsonMetadata | LdpVcMetadata | JwtVcJsonLdMetadata | MsoMdocMetadata | DcSdJwtMetadata);
type JwtVcJsonMetadata = {
claims?: Array<Claim>;
credential_definition: {
type: string[];
};
};
type LdpVcMetadata = {
claims?: Array<Claim>;
credential_definition: {
'@context': string[];
type: string[];
};
};
type JwtVcJsonLdMetadata = {
claims?: Array<Claim>;
credential_definition: {
'@context': string[];
type: string[];
};
};
type MsoMdocMetadata = {
claims?: Array<Claim>;
doctype: string;
};
type DcSdJwtMetadata = {
claims?: Array<Claim>;
vct: string;
};
type CredentialIssuerMetadata = {
credential_issuer: string;
authorization_servers?: string[];
credential_endpoint: string;
nonce_endpoint?: string;
deferred_credential_endpoint?: string;
notification_endpoint?: string;
credential_response_encryption?: {
batch_size: number;
};
signed_metadata?: string;
display: Array<{
name: string;
locale: string;
logo?: {
uri: string;
};
}>;
credential_configurations_supported: {
[credentialConfigurationId: string]: CredentialConfigurationSupported;
};
};
/**
* @Reference - https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html#RFC8414
* @Description - Authorization Server Metadata defined on RFC8414
*/
interface AuthorizationServerMetadata {
issuer: string;
authorization_endpoint: string;
token_endpoint: string;
jwks_uri?: string;
registration_endpoint?: string;
scopes_supported?: string[];
response_types_supported: string[];
response_modes_supported?: string[];
grant_types_supported?: string[];
token_endpoint_auth_methods_supported?: string[];
token_endpoint_auth_signing_alg_values_supported?: string[];
service_documentation?: string;
ui_locales_supported?: string[];
op_policy_uri?: string;
op_tos_uri?: string;
revocation_endpoint?: string;
revocation_endpoint_auth_methods_supported?: string[];
revocation_endpoint_auth_signing_alg_values_supported?: string[];
introspection_endpoint?: string;
introspection_endpoint_auth_methods_supported?: string[];
introspection_endpoint_auth_signing_alg_values_supported?: string[];
code_challenge_methods_supported?: string[];
'pre-authorized_grant_anonymous_access_supported'?: boolean;
}
type AuthorizationDetail = {
type: 'openid_credential';
credential_configuration_id: string;
} | ({
type: 'openid_credential';
format: 'jwt_vc_json';
} & JwtVcJsonLdMetadata) | ({
type: 'openid_credential';
format: 'ldp_vc';
} & LdpVcMetadata) | ({
type: 'openid_credential';
format: 'mso_mdoc';
} & MsoMdocMetadata) | ({
type: 'openid_credential';
format: 'dc+sd-jwt';
} & DcSdJwtMetadata);
type TokenAuthorizationDetail = Array<AuthorizationDetail & {
credential_identifiers: string[];
locations?: string[];
}>;
type ValidatePreAuthorizedCodeResponseDto = {
sub: string;
authorization_details: TokenAuthorizationDetail;
};
type TokenResponseDto = {
access_token: string;
token_type: 'Bearer';
expires_in: number;
authorization_details: TokenAuthorizationDetail;
};
declare enum NotificationEventEnum {
CREDENTIAL_ACCEPTED = "credential_accepted",
CREDENTIAL_FAILURE = "credential_failure",
CREDENTIAL_DELETED = "credential_deleted"
}
declare function isPreAuthorizedCodeGrant(offer: CredentialOffer): offer is CredentialOffer & {
grants: PreAuthorizedCodeGrant;
};
export { type AttackPotentialResistance, type AuthorizationCodeGrant, type AuthorizationDetail, type AuthorizationServerMetadata, type Claim, type CredentialConfigurationSupported, type CredentialIssuerMetadata, type CredentialOffer, type CredentialOfferAuthorizationCodeOption, type CredentialOfferOption, type CredentialOfferOptionBase, type CredentialOfferPreAuthOption, type CredentialOfferResponse, type CredentialOfferType, type CredentialResponse, type DcSdJwtMetadata, type Format, type Grant, type JwtVcJsonLdMetadata, type JwtVcJsonMetadata, type LdpVcMetadata, type MsoMdocMetadata, NotificationEventEnum, type PreAuthorizedCodeGrant, type ProofType, type TokenAuthorizationDetail, type TokenResponseDto, type TxCode, type ValidatePreAuthorizedCodeResponseDto, isPreAuthorizedCodeGrant };