Skip to content

Commit

Permalink
refactor: changed the name of CredentialIssuerMetadataSupportedCreden…
Browse files Browse the repository at this point in the history
…tials to CredentialSupported

Signed-off-by: sksadjad <[email protected]>
  • Loading branch information
sksadjad committed Apr 6, 2023
1 parent 60cd3d4 commit cd55d8e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 34 deletions.
8 changes: 4 additions & 4 deletions packages/common/lib/types/Generic.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,29 @@ export type Display = NameAndLocale & LogoAndColor;
export interface IssuerMetadata {
credential_endpoint: string;
batch_credential_endpoint?: string;
credentials_supported: CredentialIssuerMetadataSupportedCredentials[];
credentials_supported: CredentialSupported[];
credential_issuer: string; // REQUIRED. The URL of the Credential Issuer, the Wallet is requested to obtain one or more Credentials from.
authorization_server?: string;
token_endpoint?: string;
display?: Display[];
}

export interface CredentialIssuerMetadataSupportedCredentials {
export interface CredentialSupported {
format: CredentialFormatEnum | string;
id?: string;
cryptographic_binding_methods_supported?: string[];
cryptographic_suites_supported?: string[];
}

export interface SupportedCredentialIssuerMetadataJwtVcJsonLdAndLdpVc extends CredentialIssuerMetadataSupportedCredentials {
export interface SupportedCredentialIssuerMetadataJwtVcJsonLdAndLdpVc extends CredentialSupported {
format: CredentialFormatEnum.ldp_vc;
'@context': ICredentialContextType[];
types: string[];
credentialSubject?: IssuerCredentialSubject;
display?: Display[];
}

export interface SupportedCredentialIssuerMetadataJwtVcJson extends CredentialIssuerMetadataSupportedCredentials {
export interface SupportedCredentialIssuerMetadataJwtVcJson extends CredentialSupported {
types: string[];
credentialSubject?: IssuerCredentialSubject;
display?: Display[];
Expand Down
4 changes: 2 additions & 2 deletions packages/issuer-rest/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
CredentialFormatEnum,
CredentialIssuerMetadataSupportedCredentials,
CredentialRequest,
CredentialSupported,
Display,
IssuerCredentialSubjectDisplay,
IssuerMetadata,
Expand All @@ -14,7 +14,7 @@ import express, { Express, Response } from 'express'
import { v4 as uuidv4 } from 'uuid'

function buildVCIFromEnvironment() {
const credentialsSupported: CredentialIssuerMetadataSupportedCredentials = new CredentialSupportedV1_11Builder()
const credentialsSupported: CredentialSupported = new CredentialSupportedV1_11Builder()
.withCryptographicSuitesSupported(process.env.cryptographic_suites_supported as string)
.withCryptographicBindingMethod(process.env.cryptographic_binding_methods_supported as string)
.withFormat(process.env.credential_supported_format as unknown as CredentialFormatEnum)
Expand Down
12 changes: 3 additions & 9 deletions packages/issuer/lib/__test__/VcIssuerBuilder.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import {
CredentialFormatEnum,
CredentialIssuerMetadataSupportedCredentials,
Display,
IssuerCredentialSubjectDisplay,
TokenErrorResponse,
} from '@sphereon/openid4vci-common'
import { CredentialFormatEnum, CredentialSupported, Display, IssuerCredentialSubjectDisplay, TokenErrorResponse } from '@sphereon/openid4vci-common'

import { CredentialSupportedV1_11Builder, VcIssuerBuilder } from '../index'

describe('VcIssuer builder should', () => {
it('generate a VcIssuer', () => {
const credentialsSupported: CredentialIssuerMetadataSupportedCredentials = new CredentialSupportedV1_11Builder()
const credentialsSupported: CredentialSupported = new CredentialSupportedV1_11Builder()
.withCryptographicSuitesSupported('ES256K')
.withCryptographicBindingMethod('did')
.withFormat(CredentialFormatEnum.jwt_vc_json)
Expand Down Expand Up @@ -47,7 +41,7 @@ describe('VcIssuer builder should', () => {
})

it('fail to generate a VcIssuer', () => {
const credentialsSupported: CredentialIssuerMetadataSupportedCredentials = new CredentialSupportedV1_11Builder()
const credentialsSupported: CredentialSupported = new CredentialSupportedV1_11Builder()
.withCryptographicSuitesSupported('ES256K')
.withCryptographicBindingMethod('did')
.withFormat(CredentialFormatEnum.jwt_vc_json)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
CredentialFormatEnum,
CredentialIssuerMetadataSupportedCredentials,
CredentialSupported,
Display,
IssuerCredentialSubject,
IssuerCredentialSubjectDisplay,
Expand Down Expand Up @@ -101,11 +101,11 @@ export class CredentialSupportedV1_11Builder {
return this
}

public build(): CredentialIssuerMetadataSupportedCredentials {
public build(): CredentialSupported {
if (!this.format) {
throw new Error(TokenErrorResponse.invalid_request)
}
const credentialSupported: CredentialIssuerMetadataSupportedCredentials = {
const credentialSupported: CredentialSupported = {
format: this.format,
}
if (this.credentialSubject) {
Expand Down
12 changes: 4 additions & 8 deletions packages/issuer/lib/builder/VcIssuerBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CredentialIssuerMetadataSupportedCredentials, Display, IssuerMetadata, TokenErrorResponse } from '@sphereon/openid4vci-common'
import { CredentialSupported, Display, IssuerMetadata, TokenErrorResponse } from '@sphereon/openid4vci-common'

import { VcIssuer } from '../VcIssuer'

Expand All @@ -9,7 +9,7 @@ export class VcIssuerBuilder {
batchCredentialEndpoint?: string
tokenEndpoint?: string
issuerDisplay?: Display[]
credentialsSupported?: CredentialIssuerMetadataSupportedCredentials[]
credentialsSupported?: CredentialSupported[]
userPinRequired?: boolean

public withCredentialIssuer(issuer: string): VcIssuerBuilder {
Expand Down Expand Up @@ -49,16 +49,12 @@ export class VcIssuerBuilder {
return this
}

public withCredentialsSupported(
credentialSupported: CredentialIssuerMetadataSupportedCredentials | CredentialIssuerMetadataSupportedCredentials[]
): VcIssuerBuilder {
public withCredentialsSupported(credentialSupported: CredentialSupported | CredentialSupported[]): VcIssuerBuilder {
this.credentialsSupported = Array.isArray(credentialSupported) ? credentialSupported : [credentialSupported]
return this
}

public addCredentialsSupported(
credentialSupported: CredentialIssuerMetadataSupportedCredentials | CredentialIssuerMetadataSupportedCredentials[]
): VcIssuerBuilder {
public addCredentialsSupported(credentialSupported: CredentialSupported | CredentialSupported[]): VcIssuerBuilder {
if (!Array.isArray(credentialSupported))
this.credentialsSupported = this.credentialsSupported ? [...this.credentialsSupported, credentialSupported] : [credentialSupported]
else {
Expand Down
10 changes: 2 additions & 8 deletions packages/issuer/lib/functions/CredentialOffer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
CredentialFormatEnum,
CredentialIssuerMetadataSupportedCredentials,
encodeJsonAsURI,
IssuerMetadata,
TokenErrorResponse,
} from '@sphereon/openid4vci-common'
import { CredentialFormatEnum, CredentialSupported, encodeJsonAsURI, IssuerMetadata, TokenErrorResponse } from '@sphereon/openid4vci-common'
import { v4 as uuidv4 } from 'uuid'

export function createCredentialOfferDeeplink(preAuthorizedCode: string, issuerMetadata: IssuerMetadata): string {
Expand All @@ -18,7 +12,7 @@ export function createCredentialOfferDeeplink(preAuthorizedCode: string, issuerM

const types: string[] = []
issuerMetadata.credentials_supported.map((cs) => {
if (cs.format != CredentialFormatEnum.mso_mdoc) types.push(...(cs['types' as keyof CredentialIssuerMetadataSupportedCredentials] as string[]))
if (cs.format != CredentialFormatEnum.mso_mdoc) types.push(...(cs['types' as keyof CredentialSupported] as string[]))
})
return `openid-credential-offer://?credential_offer=${encodeJsonAsURI({
credential_issuer: issuerMetadata.credential_issuer,
Expand Down

0 comments on commit cd55d8e

Please sign in to comment.