@sphereon/ssi-sdk.credential-validation 0.33.1-feature.vcdm2.tsup.32 → 0.33.1-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ import { IAgentPlugin } from '@veramo/core';
2
+ import { ICredentialValidation } from '../index';
3
+ export declare const credentialValidationMethods: Array<string>;
4
+ /**
5
+ * {@inheritDoc ICredentialValidation}
6
+ */
7
+ export declare class CredentialValidation implements IAgentPlugin {
8
+ readonly schema: any;
9
+ readonly methods: ICredentialValidation;
10
+ private detectSchemas;
11
+ private cvVerifyCredential;
12
+ private cvVerifySchema;
13
+ private validateSchema;
14
+ private fetchSchema;
15
+ private verifyCredentialAgainstSchema;
16
+ private cvVerifyMdoc;
17
+ private cvVerifyW3CCredential;
18
+ private cvVerifySDJWTCredential;
19
+ }
20
+ //# sourceMappingURL=CredentialValidation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CredentialValidation.d.ts","sourceRoot":"","sources":["../../src/agent/CredentialValidation.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAmF,MAAM,cAAc,CAAA;AAI5H,OAAO,EAEL,qBAAqB,EAUtB,MAAM,UAAU,CAAA;AAOjB,eAAO,MAAM,2BAA2B,EAAE,KAAK,CAAC,MAAM,CAMrD,CAAA;AAED;;GAEG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACvD,QAAQ,CAAC,MAAM,MAA+B;IAC9C,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAMtC;IAED,OAAO,CAAC,aAAa;YAkBP,kBAAkB;YA0BlB,cAAc;YAad,cAAc;YA8Bd,WAAW;YAQX,6BAA6B;YA0B7B,YAAY;YAyBZ,qBAAqB;YA6CrB,uBAAuB;CAqBtC"}
@@ -0,0 +1,243 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CredentialValidation = exports.credentialValidationMethods = void 0;
16
+ const kmp_mdoc_core_1 = require("@sphereon/kmp-mdoc-core");
17
+ const ssi_types_1 = require("@sphereon/ssi-types");
18
+ const ajv_formats_1 = __importDefault(require("ajv-formats"));
19
+ const _2020_1 = __importDefault(require("ajv/dist/2020"));
20
+ const cross_fetch_1 = __importDefault(require("cross-fetch"));
21
+ const index_1 = require("../index");
22
+ var decodeFrom = kmp_mdoc_core_1.com.sphereon.kmp.decodeFrom;
23
+ var IssuerSignedCbor = kmp_mdoc_core_1.com.sphereon.mdoc.data.device.IssuerSignedCbor;
24
+ const ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
25
+ // Exposing the methods here for any REST implementation
26
+ exports.credentialValidationMethods = [
27
+ 'cvVerifyCredential',
28
+ 'cvVerifySchema',
29
+ 'cvVerifyMdoc',
30
+ 'cvVerifySDJWTCredential',
31
+ 'cvVerifyW3CCredential',
32
+ ];
33
+ /**
34
+ * {@inheritDoc ICredentialValidation}
35
+ */
36
+ class CredentialValidation {
37
+ constructor() {
38
+ this.schema = index_1.schema.ICredentialValidation;
39
+ this.methods = {
40
+ cvVerifyCredential: this.cvVerifyCredential.bind(this),
41
+ cvVerifySchema: this.cvVerifySchema.bind(this),
42
+ cvVerifyMdoc: this.cvVerifyMdoc.bind(this),
43
+ cvVerifySDJWTCredential: this.cvVerifySDJWTCredential.bind(this),
44
+ cvVerifyW3CCredential: this.cvVerifyW3CCredential.bind(this),
45
+ };
46
+ }
47
+ detectSchemas(wrappedVC) {
48
+ if ('credential' in wrappedVC) {
49
+ const { credential } = wrappedVC;
50
+ if ('credentialSchema' in credential) {
51
+ const { credentialSchema } = credential;
52
+ if (Array.isArray(credentialSchema)) {
53
+ return credentialSchema;
54
+ }
55
+ else if (credentialSchema) {
56
+ return [credentialSchema];
57
+ }
58
+ }
59
+ }
60
+ return undefined;
61
+ }
62
+ cvVerifyCredential(args, context) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ var _a;
65
+ const { credential, hasher = ssi_sdk_core_1.defaultHasher, policies } = args;
66
+ // defaulting the schema validation to when_present
67
+ const schemaResult = yield this.cvVerifySchema({
68
+ credential,
69
+ validationPolicy: (_a = policies === null || policies === void 0 ? void 0 : policies.schemaValidation) !== null && _a !== void 0 ? _a : index_1.SchemaValidation.WHEN_PRESENT,
70
+ hasher,
71
+ });
72
+ if (!schemaResult.result) {
73
+ return schemaResult;
74
+ }
75
+ if (ssi_types_1.CredentialMapper.isMsoMdocOid4VPEncoded(credential)) {
76
+ return yield this.cvVerifyMdoc({ credential }, context);
77
+ }
78
+ else if (ssi_types_1.CredentialMapper.isSdJwtEncoded(credential)) {
79
+ return yield this.cvVerifySDJWTCredential({ credential, hasher }, context);
80
+ }
81
+ else {
82
+ return yield this.cvVerifyW3CCredential(Object.assign(Object.assign({}, args), { credential: credential }), context);
83
+ }
84
+ });
85
+ }
86
+ cvVerifySchema(args) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ const { credential, hasher = ssi_sdk_core_1.defaultHasher, validationPolicy } = args;
89
+ const wrappedCredential = ssi_types_1.CredentialMapper.toWrappedVerifiableCredential(credential, { hasher });
90
+ if (validationPolicy === index_1.SchemaValidation.NEVER) {
91
+ return {
92
+ result: true,
93
+ source: wrappedCredential,
94
+ subResults: [],
95
+ };
96
+ }
97
+ return this.validateSchema(wrappedCredential, validationPolicy);
98
+ });
99
+ }
100
+ validateSchema(wrappedVC, validationPolicy) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ const schemas = this.detectSchemas(wrappedVC);
103
+ if (!schemas) {
104
+ if (validationPolicy === index_1.SchemaValidation.ALWAYS) {
105
+ console.error(`No schema found for credential, but validation policy is set to ALWAYS. Returning false. Credential: ${JSON.stringify(wrappedVC.credential, null, 2)}`);
106
+ return {
107
+ result: false,
108
+ source: wrappedVC,
109
+ subResults: [],
110
+ };
111
+ }
112
+ else {
113
+ return {
114
+ result: true,
115
+ source: wrappedVC,
116
+ subResults: [],
117
+ };
118
+ }
119
+ }
120
+ const subResults = yield Promise.all(schemas.map((schema) => this.verifyCredentialAgainstSchema(wrappedVC, schema)));
121
+ return {
122
+ result: subResults.every((subResult) => subResult.result),
123
+ source: wrappedVC,
124
+ subResults,
125
+ };
126
+ });
127
+ }
128
+ fetchSchema(uri) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ const response = yield (0, cross_fetch_1.default)(uri);
131
+ if (!response.ok) {
132
+ throw new Error(`Unable to fetch schema from ${uri}`);
133
+ }
134
+ return response.json();
135
+ });
136
+ }
137
+ verifyCredentialAgainstSchema(wrappedVC, schema) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ const schemaUrl = typeof schema === 'string' ? schema : schema.id;
140
+ let schemaValue;
141
+ try {
142
+ schemaValue = yield this.fetchSchema(schemaUrl);
143
+ }
144
+ catch (error) {
145
+ console.error(error);
146
+ return {
147
+ result: false,
148
+ error: error,
149
+ };
150
+ }
151
+ const ajv = new _2020_1.default({ loadSchema: this.fetchSchema });
152
+ (0, ajv_formats_1.default)(ajv);
153
+ const validate = yield ajv.compileAsync(schemaValue);
154
+ const valid = validate(wrappedVC.credential);
155
+ if (!valid) {
156
+ console.error(`Schema validation failed for `, wrappedVC.credential);
157
+ }
158
+ return {
159
+ result: valid,
160
+ };
161
+ });
162
+ }
163
+ cvVerifyMdoc(args, context) {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ var _a;
166
+ const { credential } = args;
167
+ const issuerSigned = IssuerSignedCbor.Static.cborDecode(decodeFrom(credential, kmp_mdoc_core_1.com.sphereon.kmp.Encoding.BASE64URL));
168
+ const verification = yield context.agent.mdocVerifyIssuerSigned({ input: issuerSigned.toJson().issuerAuth }).catch((error) => {
169
+ var _a;
170
+ console.error(error);
171
+ return {
172
+ name: 'mdoc',
173
+ critical: true,
174
+ error: true,
175
+ message: (_a = error.message) !== null && _a !== void 0 ? _a : 'Mdoc Issuer Signed VC could not be verified',
176
+ };
177
+ });
178
+ return Object.assign({ source: ssi_types_1.CredentialMapper.toWrappedVerifiableCredential(credential, { hasher: ssi_sdk_core_1.defaultHasher }), result: !verification.error, subResults: [] }, (verification.error && {
179
+ error: (_a = verification.message) !== null && _a !== void 0 ? _a : `Could not verify mdoc from issuer`,
180
+ }));
181
+ });
182
+ }
183
+ cvVerifyW3CCredential(args, context) {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
186
+ // We also allow/add boolean, because 4.x Veramo returns a boolean for JWTs. 5.X will return better results
187
+ const { credential, policies } = args;
188
+ const result = (yield context.agent.verifyCredential(args));
189
+ if (typeof result === 'boolean') {
190
+ return Object.assign(Object.assign({
191
+ // FIXME the source is never used, need to start using this as the source of truth
192
+ source: ssi_types_1.CredentialMapper.toWrappedVerifiableCredential(args.credential, { hasher: ssi_sdk_core_1.defaultHasher }), result }, (!result && {
193
+ error: 'Invalid JWT VC',
194
+ errorDetails: `JWT VC was not valid with policies: ${JSON.stringify(policies)}`,
195
+ })), { subResults: [] });
196
+ }
197
+ else {
198
+ // TODO look at what this is doing and make it simple and readable
199
+ let error;
200
+ let errorDetails;
201
+ const subResults = [];
202
+ if (result.error) {
203
+ error = (_b = (_a = result.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : '';
204
+ errorDetails = (_e = (_d = (_c = result.error) === null || _c === void 0 ? void 0 : _c.details) === null || _d === void 0 ? void 0 : _d.code) !== null && _e !== void 0 ? _e : '';
205
+ errorDetails = (errorDetails !== '' ? `${errorDetails}, ` : '') + ((_h = (_g = (_f = result.error) === null || _f === void 0 ? void 0 : _f.details) === null || _g === void 0 ? void 0 : _g.url) !== null && _h !== void 0 ? _h : '');
206
+ if ((_j = result.error) === null || _j === void 0 ? void 0 : _j.errors) {
207
+ error = (error !== '' ? `${error}, ` : '') + ((_l = (_k = result.error) === null || _k === void 0 ? void 0 : _k.errors) === null || _l === void 0 ? void 0 : _l.map((error) => { var _a; return (_a = error.message) !== null && _a !== void 0 ? _a : error.name; }).join(', '));
208
+ errorDetails =
209
+ (errorDetails !== '' ? `${errorDetails}, ` : '') +
210
+ ((_o = (_m = result.error) === null || _m === void 0 ? void 0 : _m.errors) === null || _o === void 0 ? void 0 : _o.map((error) => { var _a, _b, _c; return (((_a = error === null || error === void 0 ? void 0 : error.details) === null || _a === void 0 ? void 0 : _a.code) ? `${error.details.code}, ` : '') + ((_c = (_b = error === null || error === void 0 ? void 0 : error.details) === null || _b === void 0 ? void 0 : _b.url) !== null && _c !== void 0 ? _c : ''); }).join(', '));
211
+ }
212
+ console.error(error);
213
+ }
214
+ return {
215
+ source: ssi_types_1.CredentialMapper.toWrappedVerifiableCredential(credential, { hasher: ssi_sdk_core_1.defaultHasher }),
216
+ result: result.verified,
217
+ subResults,
218
+ error,
219
+ errorDetails,
220
+ };
221
+ }
222
+ });
223
+ }
224
+ cvVerifySDJWTCredential(args, context) {
225
+ return __awaiter(this, void 0, void 0, function* () {
226
+ const { credential, hasher = ssi_sdk_core_1.defaultHasher } = args;
227
+ const verification = yield context.agent
228
+ .verifySdJwtVc({ credential })
229
+ .catch((error) => {
230
+ var _a;
231
+ console.error(error);
232
+ return {
233
+ error: 'Invalid SD-JWT VC',
234
+ errorDetails: (_a = error.message) !== null && _a !== void 0 ? _a : 'SD-JWT VC could not be verified',
235
+ };
236
+ });
237
+ const result = 'header' in verification && 'payload' in verification;
238
+ return Object.assign({ source: ssi_types_1.CredentialMapper.toWrappedVerifiableCredential(credential, { hasher: hasher !== null && hasher !== void 0 ? hasher : ssi_sdk_core_1.defaultHasher }), result, subResults: [] }, (!result && Object.assign({}, verification)));
239
+ });
240
+ }
241
+ }
242
+ exports.CredentialValidation = CredentialValidation;
243
+ //# sourceMappingURL=CredentialValidation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CredentialValidation.js","sourceRoot":"","sources":["../../src/agent/CredentialValidation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2DAA6C;AAE7C,mDAO4B;AAE5B,8DAAoC;AACpC,0DAAmC;AACnC,8DAA+B;AAC/B,oCAYiB;AAEjB,IAAO,UAAU,GAAG,mBAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAA;AAC/C,IAAO,gBAAgB,GAAG,mBAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAA;AACxE,yDAAsD;AAEtD,wDAAwD;AAC3C,QAAA,2BAA2B,GAAkB;IACxD,oBAAoB;IACpB,gBAAgB;IAChB,cAAc;IACd,yBAAyB;IACzB,uBAAuB;CACxB,CAAA;AAED;;GAEG;AACH,MAAa,oBAAoB;IAAjC;QACW,WAAM,GAAG,cAAM,CAAC,qBAAqB,CAAA;QACrC,YAAO,GAA0B;YACxC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC;YACtD,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;YAC9C,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;YAC1C,uBAAuB,EAAE,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC;YAChE,qBAAqB,EAAE,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC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M,EAAE,UAAU,EAAE,MAAM,GAAG,4BAAa,EAAE,GAAG,IAAI,CAAA;YAEnD,MAAM,YAAY,GAAuD,MAAM,OAAO,CAAC,KAAK;iBACzF,aAAa,CAAC,EAAE,UAAU,EAAE,CAAC;iBAC7B,KAAK,CAAC,CAAC,KAAY,EAA+B,EAAE;;gBACnD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;gBACpB,OAAO;oBACL,KAAK,EAAE,mBAAmB;oBAC1B,YAAY,EAAE,MAAA,KAAK,CAAC,OAAO,mCAAI,iCAAiC;iBACjE,CAAA;YACH,CAAC,CAAC,CAAA;YAEJ,MAAM,MAAM,GAAG,QAAQ,IAAI,YAAY,IAAI,SAAS,IAAI,YAAY,CAAA;YACpE,uBACE,MAAM,EAAE,4BAAgB,CAAC,6BAA6B,CAAC,UAA0C,EAAE,EAAE,MAAM,EAAE,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,4BAAa,EAAE,CAAC,EACvI,MAAM,EACN,UAAU,EAAE,EAAE,IACX,CAAC,CAAC,MAAM,sBAAS,YAAY,CAAE,CAAC,EACpC;QACH,CAAC;KAAA;CACF;AA9ND,oDA8NC"}
package/dist/index.d.ts CHANGED
@@ -1,83 +1,8 @@
1
- import { IAgentPlugin, IPluginMethodMap, IAgentContext, ICredentialVerifier } from '@veramo/core';
2
- import { OriginalVerifiableCredential, HasherSync, WrappedVerifiableCredential, WrappedVerifiablePresentation } from '@sphereon/ssi-types';
3
- import { ImDLMdoc } from '@sphereon/ssi-sdk.mdl-mdoc';
4
-
5
- declare const credentialValidationMethods: Array<string>;
6
- /**
7
- * {@inheritDoc ICredentialValidation}
8
- */
9
- declare class CredentialValidation implements IAgentPlugin {
10
- readonly schema: any;
11
- readonly methods: ICredentialValidation;
12
- private detectSchemas;
13
- private cvVerifyCredential;
14
- private cvVerifySchema;
15
- private validateSchema;
16
- private fetchSchema;
17
- private verifyCredentialAgainstSchema;
18
- private cvVerifyMdoc;
19
- private cvVerifyW3CCredential;
20
- private cvVerifySDJWTCredential;
21
- }
22
-
23
- interface ICredentialValidation extends IPluginMethodMap {
24
- cvVerifyCredential(args: VerifyCredentialArgs, context: RequiredContext): Promise<VerificationResult>;
25
- cvVerifySchema(args: ValidateSchemaArgs): Promise<VerificationResult>;
26
- cvVerifyMdoc(args: VerifyMdocCredentialArgs, context: RequiredContext): Promise<VerificationResult>;
27
- cvVerifySDJWTCredential(args: VerifySDJWTCredentialArgs, context: RequiredContext): Promise<VerificationResult>;
28
- cvVerifyW3CCredential(args: VerifyW3CCredentialArgs, context: RequiredContext): Promise<VerificationResult>;
29
- }
30
- declare enum SchemaValidation {
31
- ALWAYS = "ALWAYS",
32
- NEVER = "NEVER",
33
- WHEN_PRESENT = "WHEN_PRESENT"
34
- }
35
- type VerifyCredentialArgs = {
36
- credential: OriginalVerifiableCredential;
37
- hasher?: HasherSync;
38
- fetchRemoteContexts: boolean;
39
- policies?: VerificationPolicies;
40
- };
41
- type VerificationPolicies = {
42
- schemaValidation?: SchemaValidation;
43
- credentialStatus?: boolean;
44
- expirationDate: boolean;
45
- issuanceDate: boolean;
46
- };
47
- type ValidateSchemaArgs = {
48
- credential: OriginalVerifiableCredential;
49
- validationPolicy?: SchemaValidation;
50
- hasher?: HasherSync;
51
- };
52
- type VerifyMdocCredentialArgs = {
53
- credential: string;
54
- };
55
- type VerifySDJWTCredentialArgs = {
56
- credential: string;
57
- hasher?: HasherSync;
58
- };
59
- type VerifyW3CCredentialArgs = {};
60
- type VerificationResult = {
61
- result: boolean;
62
- source: WrappedVerifiableCredential | WrappedVerifiablePresentation;
63
- subResults: Array<VerificationSubResult>;
64
- error?: string | undefined;
65
- errorDetails?: string;
66
- };
67
- type VerificationSubResult = {
68
- result: boolean;
69
- error?: string;
70
- errorDetails?: string;
71
- };
72
- type CredentialVerificationError = {
73
- error?: string;
74
- errorDetails?: string;
75
- };
76
- type RequiredContext = IAgentContext<ImDLMdoc & ICredentialVerifier>;
77
-
78
1
  /**
79
2
  * @public
80
3
  */
81
4
  declare const schema: any;
82
-
83
- export { CredentialValidation, type CredentialVerificationError, type ICredentialValidation, type RequiredContext, SchemaValidation, type ValidateSchemaArgs, type VerificationPolicies, type VerificationResult, type VerificationSubResult, type VerifyCredentialArgs, type VerifyMdocCredentialArgs, type VerifySDJWTCredentialArgs, type VerifyW3CCredentialArgs, credentialValidationMethods, schema };
5
+ export { schema };
6
+ export { CredentialValidation, credentialValidationMethods } from './agent/CredentialValidation';
7
+ export * from './types/ICredentialValidation';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,QAAA,MAAM,MAAM,KAAmC,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,CAAA;AACjB,OAAO,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAA;AAChG,cAAc,+BAA+B,CAAA"}