Skip to content

Commit

Permalink
Merged with latest develop
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderPostma committed Jan 10, 2024
1 parent a208343 commit 10f4651
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/client/lib/CredentialRequestClientBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class CredentialRequestClientBuilder {
}): CredentialRequestClientBuilder {
const issuer = credentialIssuer;
const builder = new CredentialRequestClientBuilder();
builder.withVersion(version ?? OpenId4VCIVersion.VER_1_0_11);
builder.withVersion(version ?? OpenId4VCIVersion.VER_1_0_12);
builder.withCredentialEndpoint(metadata?.credential_endpoint ?? (issuer.endsWith('/') ? `${issuer}credential` : `${issuer}/credential`));
builder.withCredentialType(credentialTypes);
return builder;
Expand Down
8 changes: 3 additions & 5 deletions packages/client/lib/OpenID4VCIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
CredentialSupported,
EndpointMetadataResult,
getIssuerFromCredentialOfferPayload,
getSupportedCredentials,
getTypesFromCredentialSupported,
JsonURIMode,
JWK,
KID_JWK_X5C_ERROR,
Expand Down Expand Up @@ -136,7 +134,7 @@ export class OpenID4VCIClient {
if (this.credentialOffer) {
this._endpointMetadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(this.credentialOffer);
} else if (this._credentialIssuer) {
this._endpointMetadata = await MetadataClient.retrieveAllMetadata(this._credentialIssuer);
this._endpointMetadata = await MetadataClient.retrieveAllMetadata([this._credentialIssuer]); // TODO multi-server support?
} else {
throw Error(`Cannot retrieve issuer metadata without either a credential offer, or issuer value`);
}
Expand Down Expand Up @@ -412,7 +410,7 @@ export class OpenID4VCIClient {
} else if (metadata.credentials_supported && !Array.isArray(metadata.credentials_supported)) {
const credentialsSupported = metadata.credentials_supported as CredentialSupported;
if (credentialsSupported.format === 'vc+sd-jwt') {
if (types.some((type) => !metadata.credentials_supported || credentialsSupported.credential_definition.vct === type)) { // TODO why are we doing iterating types and not using them?
if (types.some((type) => !metadata.credentials_supported || credentialsSupported.vct === type)) {
throw Error(`Not all credential types ${JSON.stringify(credentialTypes)} are supported by issuer ${this.getIssuer()}`);
}
} else {
Expand Down Expand Up @@ -509,7 +507,7 @@ export class OpenID4VCIClient {
}

public version(): OpenId4VCIVersion {
return this.credentialOffer?.version ?? OpenId4VCIVersion.VER_1_0_11;
return this.credentialOffer?.version ?? OpenId4VCIVersion.VER_1_0_12;
}

public get endpointMetadata(): EndpointMetadataResult {
Expand Down
9 changes: 4 additions & 5 deletions packages/common/lib/functions/IssuerMetadataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ export function getSupportedCredential(opts?: {

export function getTypesFromCredentialSupported(credentialSupported: CredentialSupported, opts?: { filterVerifiableCredential: boolean }) {
let types: string[] = [];
if (credentialSupported.format !== 'vc+sd-jwt') {
credentialSupported.format === 'jwt_vc_json' ||
if (credentialSupported.format === 'jwt_vc_json' ||
credentialSupported.format === 'jwt_vc' ||
credentialSupported.format === 'jwt_vc_json-ld' ||
credentialSupported.format === 'ldp_vc'
credentialSupported.format === 'ldp_vc') {
types = credentialSupported.credential_definition.type;
} else {
types = [credentialSupported.credential_definition.vct];
} else if (credentialSupported.format === 'vc+sd-jwt') {
types = [credentialSupported.vct];
}
if (!types || types.length === 0) {
throw Error('Could not deduce types from credential supported');
Expand Down
42 changes: 28 additions & 14 deletions packages/issuer/lib/builder/CredentialSupportedBuilderV1_12.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
CredentialsSupportedDisplay,
CredentialSupported,
isFormat,
IssuerCredentialSubject,
IssuerCredentialSubjectDisplay,
OID4VCICredentialFormat,
TokenErrorResponse,
} from '@sphereon/oid4vci-common'
import { ICredentialContextType } from '@sphereon/ssi-types';

export class CredentialSupportedBuilderV1_12 {
format?: OID4VCICredentialFormat
Expand Down Expand Up @@ -112,26 +112,40 @@ export class CredentialSupportedBuilderV1_12 {
if (!this.format) {
throw new Error(TokenErrorResponse.invalid_request)
}
const credentialSupported: Partial<CredentialSupported> = {
format: this.format,
}
let credentialSupported: CredentialSupported; // Partial<CredentialSupported> does not work in the v12 situation for some reason
if (!this.types) {
throw new Error('types are required')
}
if (!this.types || this.types.length === 0) {
throw new Error('No type specified')
}

// SdJwtVc has a different format
if (isFormat(credentialSupported, 'vc+sd-jwt')) {
if (this.format === 'vc+sd-jwt') {
if (this.types.length > 1) {
throw new Error('Only one type is allowed for vc+sd-jwt')
}
credentialSupported.vct = this.types[0]
}
// And else would work here, but this way we get the correct typing
else {
credentialSupported.credential_definition = {
type: this.types,
...this.credentialSubject ? { credentialSubject: this.credentialSubject } : {}
throw new Error('Only one type is allowed for vc+sd-jwt');
}
credentialSupported = {
format: this.format,
vct: this.types[0]
};
} else if (this.format === 'ldp_vc' || this.format === 'jwt_vc_json-ld') {
credentialSupported = {
format: this.format,
credential_definition: {
type: this.types as string[],
...this.credentialSubject ? { credentialSubject: this.credentialSubject } : {},
'@context': [] as ICredentialContextType[]
}
};
} else {
credentialSupported = {
format: this.format,
credential_definition: {
type: this.types as string[],
...this.credentialSubject ? { credentialSubject: this.credentialSubject } : {}
}
};
}

if (this.cryptographicSuitesSupported) {
Expand Down

0 comments on commit 10f4651

Please sign in to comment.