Skip to content

Commit

Permalink
feat: added schemaValidation to CredentialRequestClient
Browse files Browse the repository at this point in the history
  • Loading branch information
sksadjad committed Sep 24, 2024
1 parent 0a6c8e3 commit 14f4546
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/client/lib/CredentialRequestClientBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ExperimentalSubjectIssuance,
OID4VCICredentialFormat,
OpenId4VCIVersion,
SchemaValidation,
UniformCredentialOfferRequest,
} from '@sphereon/oid4vci-common';
import { CredentialFormat } from '@sphereon/ssi-types';
Expand Down Expand Up @@ -173,6 +174,11 @@ export class CredentialRequestClientBuilder {
return this;
}

public withSchemaValidation(schemaValidation: SchemaValidation): this {
this._builder.withSchemaValidation(schemaValidation);
return this;
}

public withFormat(format: CredentialFormat | OID4VCICredentialFormat): this {
this._builder.withFormat(format);
return this;
Expand Down
7 changes: 7 additions & 0 deletions packages/client/lib/CredentialRequestClientBuilderV1_0_11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getTypesFromOfferV1_0_11,
OID4VCICredentialFormat,
OpenId4VCIVersion,
SchemaValidation,
UniformCredentialOfferRequest,
} from '@sphereon/oid4vci-common';
import { CredentialFormat } from '@sphereon/ssi-types';
Expand All @@ -24,6 +25,7 @@ export class CredentialRequestClientBuilderV1_0_11 {
deferredCredentialAwait = false;
deferredCredentialIntervalInMS = 5000;
credentialTypes: string[] = [];
schemaValidation: SchemaValidation = SchemaValidation.WHEN_PRESENT;
format?: CredentialFormat | OID4VCICredentialFormat;
token?: string;
version?: OpenId4VCIVersion;
Expand Down Expand Up @@ -129,6 +131,11 @@ export class CredentialRequestClientBuilderV1_0_11 {
return this;
}

public withSchemaValidation(schemaValidation: SchemaValidation): this {
this.schemaValidation = schemaValidation;
return this;
}

public withFormat(format: CredentialFormat | OID4VCICredentialFormat): this {
this.format = format;
return this;
Expand Down
7 changes: 7 additions & 0 deletions packages/client/lib/CredentialRequestClientBuilderV1_0_13.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getIssuerFromCredentialOfferPayload,
OID4VCICredentialFormat,
OpenId4VCIVersion,
SchemaValidation,
UniformCredentialOfferRequest,
} from '@sphereon/oid4vci-common';
import { CredentialFormat } from '@sphereon/ssi-types';
Expand All @@ -23,6 +24,7 @@ export class CredentialRequestClientBuilderV1_0_13 {
deferredCredentialIntervalInMS = 5000;
credentialIdentifier?: string;
credentialTypes?: string[] = [];
schemaValidation: SchemaValidation = SchemaValidation.WHEN_PRESENT;
format?: CredentialFormat | OID4VCICredentialFormat;
token?: string;
version?: OpenId4VCIVersion;
Expand Down Expand Up @@ -139,6 +141,11 @@ export class CredentialRequestClientBuilderV1_0_13 {
return this;
}

public withSchemaValidation(schemaValidation: SchemaValidation): this {
this.schemaValidation = schemaValidation;
return this;
}

public withFormat(format: CredentialFormat | OID4VCICredentialFormat): this {
this.format = format;
return this;
Expand Down
5 changes: 5 additions & 0 deletions packages/client/lib/CredentialRequestClientV1_0_11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
OpenIDResponse,
post,
ProofOfPossession,
SchemaValidation,
UniformCredentialRequest,
URL_NOT_VALID,
} from '@sphereon/oid4vci-common';
Expand All @@ -35,6 +36,7 @@ export interface CredentialRequestOptsV1_0_11 {
format?: CredentialFormat | OID4VCICredentialFormat;
proof: ProofOfPossession;
token: string;
schemaValidation: SchemaValidation;
version: OpenId4VCIVersion;
}

Expand All @@ -54,6 +56,9 @@ export class CredentialRequestClientV1_0_11 {
return this.credentialRequestOpts.credentialEndpoint;
}

public getSchemaValidation(): SchemaValidation {
return this.credentialRequestOpts.schemaValidation;
}
public getDeferredCredentialEndpoint(): string | undefined {
return this.credentialRequestOpts.deferredCredentialEndpoint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Jwt,
OpenId4VCIVersion,
ProofOfPossession,
SchemaValidation,
URL_NOT_VALID,
WellKnownEndpoints,
} from '@sphereon/oid4vci-common';
Expand Down Expand Up @@ -90,6 +91,7 @@ describe('Credential Request Client ', () => {
const credReqClient = CredentialRequestClientBuilderV1_0_11.fromCredentialOffer({ credentialOffer: INITIATION_TEST_V1_0_08 })
.withCredentialEndpoint(basePath + '/credential')
.withFormat('ldp_vc')
.withSchemaValidation(SchemaValidation.NEVER)
.withCredentialType('https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential')
.build();
const proof: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({
Expand All @@ -103,6 +105,7 @@ describe('Credential Request Client ', () => {
.withClientId('sphereon:wallet')
.withKid(kid)
.build();
expect(credReqClient.getSchemaValidation()).toEqual(SchemaValidation.NEVER);
expect(credReqClient.getCredentialEndpoint()).toEqual(basePath + '/credential');
const credentialRequest = await credReqClient.createCredentialRequest({ proofInput: proof, version: OpenId4VCIVersion.VER_1_0_08 });
expect(credentialRequest.proof?.jwt?.includes(partialJWT)).toBeTruthy();
Expand All @@ -120,6 +123,7 @@ describe('Credential Request Client ', () => {
const credReqClient = CredentialRequestClientBuilderV1_0_11.fromCredentialOffer({ credentialOffer: INITIATION_TEST_V1_0_08 })
.withCredentialEndpoint(basePath + '/credential')
.withFormat('ldp_vc')
.withSchemaValidation(SchemaValidation.ALWAYS)
.withCredentialType('https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential')
.build();
const proof: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({
Expand All @@ -133,6 +137,7 @@ describe('Credential Request Client ', () => {
.withClientId('sphereon:wallet')
.withKid(kid_withoutDid)
.build();
expect(credReqClient.getSchemaValidation()).toEqual(SchemaValidation.ALWAYS);
expect(credReqClient.getCredentialEndpoint()).toEqual(basePath + '/credential');
const credentialRequest = await credReqClient.createCredentialRequest({ proofInput: proof, version: OpenId4VCIVersion.VER_1_0_08 });
expect(credentialRequest.proof?.jwt?.includes(partialJWT_withoutDid)).toBeTruthy();
Expand Down
6 changes: 6 additions & 0 deletions packages/oid4vci-common/lib/types/Generic.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,9 @@ export type NotificationResult = {
export interface NotificationErrorResponse {
error: NotificationError | string;
}

export enum SchemaValidation {
ALWAYS = 'ALWAYS',
NEVER = 'NEVER',
WHEN_PRESENT = 'WHEN_PRESENT',
}

0 comments on commit 14f4546

Please sign in to comment.