Skip to content

Commit ed8b7d0

Browse files
authored
Fix/remove-schema-validation (#330)
Signed-off-by: Mirko Mollik <[email protected]>
1 parent 9f37cdf commit ed8b7d0

File tree

5 files changed

+3
-150
lines changed

5 files changed

+3
-150
lines changed

packages/sd-jwt-vc/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@
4040
"dependencies": {
4141
"@sd-jwt/core": "workspace:*",
4242
"@sd-jwt/jwt-status-list": "workspace:*",
43-
"@sd-jwt/utils": "workspace:*",
44-
"ajv": "^8.17.1",
45-
"ajv-formats": "^3.0.1"
43+
"@sd-jwt/utils": "workspace:*"
4644
},
4745
"devDependencies": {
4846
"@sd-jwt/crypto-nodejs": "workspace:*",

packages/sd-jwt-vc/src/sd-jwt-vc-instance.ts

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import {
66
} from '@sd-jwt/jwt-status-list';
77
import type { DisclosureFrame, Hasher, Verifier } from '@sd-jwt/types';
88
import { base64urlDecode, SDJWTException } from '@sd-jwt/utils';
9-
import Ajv, { type SchemaObject } from 'ajv';
10-
import addFormats from 'ajv-formats';
119
import type {
1210
SDJWTVCConfig,
1311
StatusListFetcher,
@@ -210,25 +208,7 @@ export class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
210208
}
211209

212210
/**
213-
* Loads the schema either from the object or as fallback from the uri.
214-
* @param typeMetadataFormat
215-
* @returns
216-
*/
217-
private async loadSchema(typeMetadataFormat: TypeMetadataFormat) {
218-
//if schema is present, return it
219-
if (typeMetadataFormat.schema) return typeMetadataFormat.schema;
220-
if (typeMetadataFormat.schema_uri) {
221-
const schema = await this.fetch<SchemaObject>(
222-
typeMetadataFormat.schema_uri,
223-
typeMetadataFormat['schema_uri#Integrity'],
224-
);
225-
return schema;
226-
}
227-
throw new Error('No schema or schema_uri found');
228-
}
229-
230-
/**
231-
* Verifies the VCT of the SD-JWT-VC. Returns the type metadata format. If the schema does not match, an error is thrown. If it matches, it will return the type metadata format.
211+
* Verifies the VCT of the SD-JWT-VC. Returns the type metadata format.
232212
* @param result
233213
* @returns
234214
*/
@@ -241,38 +221,6 @@ export class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
241221
// implement based on https://www.ietf.org/archive/id/draft-ietf-oauth-sd-jwt-vc-08.html#name-extending-type-metadata
242222
//TODO: needs to be implemented. Unclear at this point which values will overwrite the values from the extended type metadata format
243223
}
244-
245-
//init the json schema validator, load referenced schemas on demand
246-
const schema = await this.loadSchema(typeMetadataFormat);
247-
const loadedSchemas = new Set<string>();
248-
// init the json schema validator
249-
const ajv = new Ajv({
250-
loadSchema: async (uri: string) => {
251-
if (loadedSchemas.has(uri)) {
252-
return {};
253-
}
254-
const response = await fetch(uri);
255-
if (!response.ok) {
256-
throw new Error(
257-
`Error fetching schema: ${
258-
response.status
259-
} ${await response.text()}`,
260-
);
261-
}
262-
loadedSchemas.add(uri);
263-
return response.json();
264-
},
265-
});
266-
addFormats(ajv);
267-
const validate = await ajv.compileAsync(schema);
268-
const valid = validate(result.payload);
269-
270-
if (!valid) {
271-
throw new SDJWTException(
272-
`Payload does not match the schema: ${JSON.stringify(validate.errors)}`,
273-
);
274-
}
275-
276224
return typeMetadataFormat;
277225
}
278226

packages/sd-jwt-vc/src/sd-jwt-vc-type-metadata-format.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,4 @@ export type TypeMetadataFormat = {
141141
display?: Display[];
142142
/** OPTIONAL. Array of claim metadata. */
143143
claims?: Claim[];
144-
/**
145-
* OPTIONAL. Embedded JSON Schema describing the VC structure.
146-
* Must not be present if schema_uri is provided.
147-
*/
148-
schema?: object;
149-
/**
150-
* OPTIONAL. URI pointing to a JSON Schema for the VC structure.
151-
* Must not be present if schema is provided.
152-
*/
153-
schema_uri?: string;
154-
/** OPTIONAL. Integrity metadata for the schema_uri field. */
155-
'schema_uri#Integrity'?: string;
156144
};

packages/sd-jwt-vc/src/test/vct.spec.ts

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,9 @@ const exampleVctm = {
1313
vct: 'http://example.com/example',
1414
name: 'ExampleCredentialType',
1515
description: 'An example credential type',
16-
schema_uri: 'http://example.com/schema/example',
17-
//this value could be generated on demand to make it easier when changing the values
18-
'schema_uri#Integrity':
19-
'sha256-48a61b283ded3b55e8d9a9b063327641dc4c53f76bd5daa96c23f232822167ae',
2016
};
2117

2218
const restHandlers = [
23-
http.get('http://example.com/schema/example', () => {
24-
const res = {
25-
$schema: 'https://json-schema.org/draft/2020-12/schema',
26-
type: 'object',
27-
properties: {
28-
vct: {
29-
type: 'string',
30-
},
31-
iss: {
32-
type: 'string',
33-
},
34-
nbf: {
35-
type: 'number',
36-
},
37-
exp: {
38-
type: 'number',
39-
},
40-
cnf: {
41-
type: 'object',
42-
},
43-
status: {
44-
type: 'object',
45-
},
46-
firstName: {
47-
type: 'string',
48-
},
49-
},
50-
required: ['iss', 'vct'],
51-
};
52-
return HttpResponse.json(res);
53-
}),
5419
http.get('http://example.com/example', () => {
5520
const res: TypeMetadataFormat = exampleVctm;
5621
return HttpResponse.json(res);
@@ -66,7 +31,7 @@ const restHandlers = [
6631

6732
//this value could be generated on demand to make it easier when changing the values
6833
const vctIntegrity =
69-
'sha256-96bed58130a44af05ae8970aa9caa0bf0135cd15afe721ea29f553394692acef';
34+
'sha256-e8bf419e6b860595f385611fc6172f1e95c18de3c80eef57c865f49e03747637';
7035

7136
const server = setupServer(...restHandlers);
7237

@@ -190,9 +155,6 @@ describe('App', () => {
190155
expect(typeMetadataFormat).to.deep.eq({
191156
description: 'An example credential type',
192157
name: 'ExampleCredentialType',
193-
schema_uri: 'http://example.com/schema/example',
194-
'schema_uri#Integrity':
195-
'sha256-48a61b283ded3b55e8d9a9b063327641dc4c53f76bd5daa96c23f232822167ae',
196158
vct: 'http://example.com/example',
197159
});
198160
});

pnpm-lock.yaml

Lines changed: 0 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)