@sphereon/ssi-sdk.credential-vcdm 0.33.1-feature.jose.vcdm.55 → 0.33.1-feature.jose.vcdm.57
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.
- package/dist/index.cjs +96 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -7
- package/dist/index.d.ts +20 -7
- package/dist/index.js +97 -51
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/__tests__/action-handler.test.ts +4 -6
- package/src/__tests__/issue-verify-flow-w3c.test.ts +49 -47
- package/src/functions.ts +78 -2
- package/src/index.ts +1 -1
- package/src/types.ts +15 -32
- package/src/{action-handler.ts → vcdmCredentialPlugin.ts} +22 -66
package/dist/index.cjs
CHANGED
|
@@ -38,6 +38,8 @@ __export(index_exports, {
|
|
|
38
38
|
extractIssuer: () => extractIssuer2,
|
|
39
39
|
isRevoked: () => isRevoked,
|
|
40
40
|
pickSigningKey: () => pickSigningKey,
|
|
41
|
+
preProcessCredentialPayload: () => preProcessCredentialPayload,
|
|
42
|
+
preProcessPresentation: () => preProcessPresentation,
|
|
41
43
|
removeDIDParameters: () => removeDIDParameters
|
|
42
44
|
});
|
|
43
45
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -152,14 +154,14 @@ var W3cMessageHandler = class extends import_message_handler.AbstractMessageHand
|
|
|
152
154
|
}
|
|
153
155
|
};
|
|
154
156
|
|
|
155
|
-
// src/
|
|
157
|
+
// src/vcdmCredentialPlugin.ts
|
|
156
158
|
var import_core = require("@veramo/core");
|
|
157
|
-
var import_utils3 = require("@veramo/utils");
|
|
158
159
|
var import_debug2 = __toESM(require("debug"), 1);
|
|
159
160
|
|
|
160
161
|
// src/functions.ts
|
|
161
162
|
var import_utils2 = require("@veramo/utils");
|
|
162
163
|
var import_did_jwt = require("did-jwt");
|
|
164
|
+
var import_ssi_types = require("@sphereon/ssi-types");
|
|
163
165
|
function extractIssuer2(input, options = {}) {
|
|
164
166
|
if (!(0, import_utils2.isDefined)(input)) {
|
|
165
167
|
return "";
|
|
@@ -212,8 +214,82 @@ async function isRevoked(credential, context) {
|
|
|
212
214
|
throw new Error(`invalid_setup: The credential status can't be verified because there is no ICredentialStatusVerifier plugin installed.`);
|
|
213
215
|
}
|
|
214
216
|
__name(isRevoked, "isRevoked");
|
|
217
|
+
function preProcessCredentialPayload({ credential, now = /* @__PURE__ */ new Date() }) {
|
|
218
|
+
const credentialContext = (0, import_ssi_types.addVcdmContextIfNeeded)(credential?.["@context"]);
|
|
219
|
+
const isVdcm1 = (0, import_ssi_types.isVcdm1Credential)(credential);
|
|
220
|
+
const isVdcm2 = (0, import_ssi_types.isVcdm2Credential)(credential);
|
|
221
|
+
const credentialType = (0, import_utils2.processEntryToArray)(credential?.type, "VerifiableCredential");
|
|
222
|
+
let issuanceDate = credential?.validFrom ?? credential?.issuanceDate ?? (typeof now === "number" ? new Date(now) : now).toISOString();
|
|
223
|
+
if (issuanceDate instanceof Date) {
|
|
224
|
+
issuanceDate = issuanceDate.toISOString();
|
|
225
|
+
}
|
|
226
|
+
const credentialPayload = {
|
|
227
|
+
...credential,
|
|
228
|
+
"@context": credentialContext,
|
|
229
|
+
type: credentialType,
|
|
230
|
+
...isVdcm1 && {
|
|
231
|
+
issuanceDate
|
|
232
|
+
},
|
|
233
|
+
...isVdcm2 && {
|
|
234
|
+
validFrom: issuanceDate
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
const issuer = extractIssuer2(credentialPayload, {
|
|
238
|
+
removeParameters: true
|
|
239
|
+
});
|
|
240
|
+
if (!issuer || typeof issuer === "undefined") {
|
|
241
|
+
throw new Error("invalid_argument: args.credential.issuer must not be empty");
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
credential: credentialPayload,
|
|
245
|
+
issuer,
|
|
246
|
+
now
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
__name(preProcessCredentialPayload, "preProcessCredentialPayload");
|
|
250
|
+
function preProcessPresentation(args) {
|
|
251
|
+
const { presentation, now = /* @__PURE__ */ new Date() } = args;
|
|
252
|
+
const credentials = presentation?.verifiableCredential ?? [];
|
|
253
|
+
const v1Credential = credentials.find((cred) => typeof cred === "object" && cred["@context"].includes(import_ssi_types.VCDM_CREDENTIAL_CONTEXT_V1)) ? import_ssi_types.VCDM_CREDENTIAL_CONTEXT_V1 : void 0;
|
|
254
|
+
const v2Credential = credentials.find((cred) => typeof cred === "object" && cred["@context"].includes(import_ssi_types.VCDM_CREDENTIAL_CONTEXT_V2)) ? import_ssi_types.VCDM_CREDENTIAL_CONTEXT_V2 : void 0;
|
|
255
|
+
const presentationContext = (0, import_ssi_types.addVcdmContextIfNeeded)(args?.presentation?.["@context"] ?? [], v2Credential ?? v1Credential ?? import_ssi_types.VCDM_CREDENTIAL_CONTEXT_V2);
|
|
256
|
+
const presentationType = (0, import_utils2.processEntryToArray)(args?.presentation?.type, "VerifiablePresentation");
|
|
257
|
+
let issuanceDate = presentation?.validFrom ?? presentation?.issuanceDate ?? (typeof now === "number" ? new Date(now) : now).toISOString();
|
|
258
|
+
if (issuanceDate instanceof Date) {
|
|
259
|
+
issuanceDate = issuanceDate.toISOString();
|
|
260
|
+
}
|
|
261
|
+
const presentationPayload = {
|
|
262
|
+
...presentation,
|
|
263
|
+
"@context": presentationContext,
|
|
264
|
+
type: presentationType,
|
|
265
|
+
...v1Credential && {
|
|
266
|
+
issuanceDate
|
|
267
|
+
},
|
|
268
|
+
...v2Credential && {
|
|
269
|
+
validFrom: issuanceDate
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
if (!(0, import_utils2.isDefined)(presentationPayload.holder) || !presentationPayload.holder) {
|
|
273
|
+
throw new Error("invalid_argument: args.presentation.holderDID must not be empty");
|
|
274
|
+
}
|
|
275
|
+
if (presentationPayload.verifiableCredential) {
|
|
276
|
+
presentationPayload.verifiableCredential = presentationPayload.verifiableCredential.map((cred) => {
|
|
277
|
+
if (typeof cred !== "string" && cred.proof.jwt) {
|
|
278
|
+
return cred.proof.jwt;
|
|
279
|
+
} else {
|
|
280
|
+
return cred;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
presentation: presentationPayload,
|
|
286
|
+
holder: removeDIDParameters(presentationPayload.holder)
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
__name(preProcessPresentation, "preProcessPresentation");
|
|
215
290
|
|
|
216
|
-
// src/
|
|
291
|
+
// src/vcdmCredentialPlugin.ts
|
|
292
|
+
var import_ssi_sdk = require("@sphereon/ssi-sdk.core");
|
|
217
293
|
var debug2 = (0, import_debug2.default)("sphereon:ssi-sdk:vcdm");
|
|
218
294
|
var VcdmCredentialPlugin = class {
|
|
219
295
|
static {
|
|
@@ -258,29 +334,10 @@ var VcdmCredentialPlugin = class {
|
|
|
258
334
|
/** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiableCredential} */
|
|
259
335
|
async createVerifiableCredential(args, context) {
|
|
260
336
|
let {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
/* keyRef, removeOriginalFields,*/
|
|
264
|
-
now
|
|
265
|
-
/*, ...otherOptions */
|
|
337
|
+
proofFormat
|
|
338
|
+
/* keyRef, removeOriginalFields, now , ...otherOptions */
|
|
266
339
|
} = args;
|
|
267
|
-
const
|
|
268
|
-
const credentialType = (0, import_utils3.processEntryToArray)(credential.type, "VerifiableCredential");
|
|
269
|
-
now = typeof now === "number" ? new Date(now * 1e3) : now;
|
|
270
|
-
if (!Object.getOwnPropertyNames(credential).includes("issuanceDate")) {
|
|
271
|
-
credential.issuanceDate = (now instanceof Date ? now : /* @__PURE__ */ new Date()).toISOString();
|
|
272
|
-
}
|
|
273
|
-
credential = {
|
|
274
|
-
...credential,
|
|
275
|
-
"@context": credentialContext,
|
|
276
|
-
type: credentialType
|
|
277
|
-
};
|
|
278
|
-
const issuer = extractIssuer2(credential, {
|
|
279
|
-
removeParameters: true
|
|
280
|
-
});
|
|
281
|
-
if (!issuer || typeof issuer === "undefined") {
|
|
282
|
-
throw new Error("invalid_argument: credential.issuer must not be empty");
|
|
283
|
-
}
|
|
340
|
+
const { credential, issuer, now } = preProcessCredentialPayload(args);
|
|
284
341
|
try {
|
|
285
342
|
await context.agent.didManagerGet({
|
|
286
343
|
did: issuer
|
|
@@ -294,10 +351,14 @@ var VcdmCredentialPlugin = class {
|
|
|
294
351
|
if (issuer2.canIssueCredentialType({
|
|
295
352
|
proofFormat
|
|
296
353
|
})) {
|
|
297
|
-
return await issuer2.createVerifiableCredential(
|
|
354
|
+
return await issuer2.createVerifiableCredential({
|
|
355
|
+
...args,
|
|
356
|
+
credential,
|
|
357
|
+
now
|
|
358
|
+
}, context);
|
|
298
359
|
}
|
|
299
360
|
}
|
|
300
|
-
throw new Error(
|
|
361
|
+
throw new Error(`invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(",")}`);
|
|
301
362
|
}
|
|
302
363
|
__name(findAndIssueCredential, "findAndIssueCredential");
|
|
303
364
|
const verifiableCredential = await findAndIssueCredential(this.issuers);
|
|
@@ -326,7 +387,7 @@ var VcdmCredentialPlugin = class {
|
|
|
326
387
|
return issuer.verifyCredential(args, context);
|
|
327
388
|
}
|
|
328
389
|
}
|
|
329
|
-
return Promise.reject(Error(
|
|
390
|
+
return Promise.reject(Error(`invalid_setup: No verifier found for the provided credential credential type: ${JSON.stringify(args.credential.type)} proof type ${(0, import_ssi_sdk.asArray)(args.credential.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(",")}`));
|
|
330
391
|
}
|
|
331
392
|
__name(findAndVerifyCredential, "findAndVerifyCredential");
|
|
332
393
|
verificationResult = await findAndVerifyCredential(this.issuers);
|
|
@@ -344,36 +405,21 @@ var VcdmCredentialPlugin = class {
|
|
|
344
405
|
}
|
|
345
406
|
/** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiablePresentation} */
|
|
346
407
|
async createVerifiablePresentation(args, context) {
|
|
347
|
-
|
|
348
|
-
const
|
|
349
|
-
const presentationType = (0, import_utils3.processEntryToArray)(args?.presentation?.type, "VerifiablePresentation");
|
|
350
|
-
presentation = {
|
|
351
|
-
...presentation,
|
|
352
|
-
"@context": presentationContext,
|
|
353
|
-
type: presentationType
|
|
354
|
-
};
|
|
355
|
-
if (!(0, import_utils3.isDefined)(presentation.holder)) {
|
|
356
|
-
throw new Error("invalid_argument: presentation.holder must not be empty");
|
|
357
|
-
}
|
|
358
|
-
if (presentation.verifiableCredential) {
|
|
359
|
-
presentation.verifiableCredential = presentation.verifiableCredential.map((cred) => {
|
|
360
|
-
if (typeof cred !== "string" && cred.proof.jwt) {
|
|
361
|
-
return cred.proof.jwt;
|
|
362
|
-
} else {
|
|
363
|
-
return cred;
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
}
|
|
408
|
+
const { proofFormat } = args;
|
|
409
|
+
const { presentation } = preProcessPresentation(args);
|
|
367
410
|
let verifiablePresentation;
|
|
368
411
|
async function findAndCreatePresentation(issuers) {
|
|
369
412
|
for (const issuer of issuers) {
|
|
370
413
|
if (issuer.canIssueCredentialType({
|
|
371
414
|
proofFormat
|
|
372
415
|
})) {
|
|
373
|
-
return await issuer.createVerifiablePresentation(
|
|
416
|
+
return await issuer.createVerifiablePresentation({
|
|
417
|
+
...args,
|
|
418
|
+
presentation
|
|
419
|
+
}, context);
|
|
374
420
|
}
|
|
375
421
|
}
|
|
376
|
-
throw new Error(
|
|
422
|
+
throw new Error(`invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(",")}`);
|
|
377
423
|
}
|
|
378
424
|
__name(findAndCreatePresentation, "findAndCreatePresentation");
|
|
379
425
|
verifiablePresentation = await findAndCreatePresentation(this.issuers);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/message-handler.ts","../src/action-handler.ts","../src/functions.ts"],"sourcesContent":["/**\n * Provides a {@link @veramo/credential-w3c#CredentialPlugin | plugin} for the {@link @veramo/core#Agent} that\n * implements\n * {@link @veramo/core#ICredentialIssuer} interface.\n *\n * Provides a {@link @veramo/credential-w3c#W3cMessageHandler | plugin} for the\n * {@link @veramo/message-handler#MessageHandler} that verifies Credentials and Presentations in a message.\n *\n * @packageDocumentation\n */\nexport type * from './types'\nexport { W3cMessageHandler, MessageTypes } from './message-handler'\nimport { VcdmCredentialPlugin } from './action-handler'\n\n/**\n * @deprecated please use {@link VcdmCredentialPlugin} instead\n * @public\n */\nconst CredentialIssuer = VcdmCredentialPlugin\nexport { CredentialIssuer, VcdmCredentialPlugin }\n\n// For backward compatibility, re-export the plugin types that were moved to core in v4\nexport type { ICredentialIssuer, ICredentialVerifier } from '@veramo/core'\n\nexport * from './functions'\n","import type {\n IAgentContext,\n ICredentialVerifier,\n IResolver,\n VerifiableCredential,\n VerifiablePresentation,\n} from '@veramo/core'\nimport { AbstractMessageHandler, Message } from '@veramo/message-handler'\nimport { asArray, computeEntryHash, decodeCredentialToObject, extractIssuer } from '@veramo/utils'\n\nimport {\n normalizeCredential,\n normalizePresentation,\n validateJwtCredentialPayload,\n validateJwtPresentationPayload,\n}// @ts-ignore\nfrom 'did-jwt-vc'\n\nimport { v4 as uuidv4 } from 'uuid'\nimport Debug from 'debug'\n\nconst debug = Debug('sphereon:vcdm:message-handler')\n\n/**\n * These types are used by `@veramo/data-store` when storing Verifiable Credentials and Presentations\n *\n * @internal\n */\nexport const MessageTypes = {\n /** Represents a Verifiable Credential */\n vc: 'w3c.vc',\n /** Represents a Verifiable Presentation */\n vp: 'w3c.vp',\n}\n\n/**\n * Represents the requirements that this plugin has.\n * The agent that is using this plugin is expected to provide these methods.\n *\n * This interface can be used for static type checks, to make sure your application is properly initialized.\n */\nexport type IContext = IAgentContext<IResolver & ICredentialVerifier>\n\n/**\n * An implementation of the {@link @veramo/message-handler#AbstractMessageHandler}.\n *\n * This plugin can handle incoming W3C Verifiable Credentials and Presentations and prepare them\n * for internal storage as {@link @veramo/message-handler#Message} types.\n *\n * The current version can only handle `JWT` encoded\n *\n * @remarks {@link @veramo/core#IDataStore | IDataStore }\n *\n * @public\n */\nexport class W3cMessageHandler extends AbstractMessageHandler {\n async handle(message: Message, context: IContext): Promise<Message> {\n const meta = message.getLastMetaData()\n\n // console.log(JSON.stringify(message, null, 2))\n\n //FIXME: messages should not be expected to be only JWT\n if (meta?.type === 'JWT' && message.raw) {\n const { data } = message\n\n try {\n validateJwtPresentationPayload(data)\n\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vp)\n const presentation = normalizePresentation(message.raw)\n const credentials = presentation.verifiableCredential\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vp\n message.from = presentation.holder\n message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = credentials\n\n return message\n } catch (e) {}\n\n try {\n validateJwtCredentialPayload(data)\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vc)\n const credential = normalizeCredential(message.raw)\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vc\n message.from = credential.issuer.id\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } catch (e) {}\n }\n\n // LDS Verification and Handling\n if (message.type === MessageTypes.vc && message.data) {\n // verify credential\n const credential = message.data as VerifiableCredential\n\n const result = await context.agent.verifyCredential({ credential })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vc\n message.from = extractIssuer(credential)\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n if (message.type === MessageTypes.vp && message.data) {\n // verify presentation\n const presentation = message.data as VerifiablePresentation\n\n // throws on error.\n const result = await context.agent.verifyPresentation({\n presentation,\n // FIXME: HARDCODED CHALLENGE VERIFICATION FOR NOW\n challenge: 'VERAMO',\n domain: 'VERAMO',\n })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vp\n message.from = presentation.holder\n // message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n // message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = asArray(presentation.verifiableCredential).map(decodeCredentialToObject)\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n return super.handle(message, context)\n }\n}\n","import type { IAgentPlugin, IIdentifier, IVerifyResult, VerifiableCredential, VerifiablePresentation } from '@veramo/core'\nimport { schema } from '@veramo/core'\n\nimport type {\n ICreateVerifiableCredentialLDArgs,\n ICreateVerifiablePresentationLDArgs,\n IVcdmCredentialPlugin,\n IVcdmCredentialProvider,\n IVcdmIssuerAgentContext,\n IVcdmVerifierAgentContext,\n IVerifyCredentialLDArgs,\n IVerifyPresentationLDArgs,\n} from './types'\n\nimport { isDefined, MANDATORY_CREDENTIAL_CONTEXT, processEntryToArray } from '@veramo/utils'\nimport Debug from 'debug'\nimport { extractIssuer, isRevoked } from './functions'\nimport type { W3CVerifiableCredential, W3CVerifiablePresentation } from '@sphereon/ssi-types'\nimport type { VerifiableCredentialSP, VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'\n\nconst debug = Debug('sphereon:ssi-sdk:vcdm')\n\n/**\n * A plugin that implements the {@link @sphereon/ssi-sdk.credential-vcdm#IVcdmCredentialPlugin} methods.\n *\n * @public\n */\nexport class VcdmCredentialPlugin implements IAgentPlugin {\n readonly methods: IVcdmCredentialPlugin\n readonly schema = {\n components: {\n schemas: {\n ...schema.ICredentialIssuer.components.schemas,\n ...schema.ICredentialVerifier.components.schemas,\n },\n methods: {\n ...schema.ICredentialIssuer.components.methods,\n ...schema.ICredentialVerifier.components.methods,\n },\n },\n }\n private issuers: IVcdmCredentialProvider[]\n\n constructor(options: { issuers: IVcdmCredentialProvider[] }) {\n this.issuers = options.issuers\n this.methods = {\n listUsableProofFormats: this.listUsableProofFormats.bind(this),\n createVerifiableCredential: this.createVerifiableCredential.bind(this),\n verifyCredential: this.verifyCredential.bind(this),\n createVerifiablePresentation: this.createVerifiablePresentation.bind(this),\n verifyPresentation: this.verifyPresentation.bind(this),\n }\n }\n\n async listUsableProofFormats(did: IIdentifier, context: IVcdmIssuerAgentContext): Promise<string[]> {\n const signingOptions: string[] = []\n const keys = did.keys\n for (const key of keys) {\n for (const issuer of this.issuers) {\n if (issuer.matchKeyForType(key)) {\n signingOptions.push(issuer.getTypeProofFormat())\n }\n }\n }\n return signingOptions\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiableCredential} */\n async createVerifiableCredential(args: ICreateVerifiableCredentialLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiableCredentialSP> {\n let { credential, proofFormat, /* keyRef, removeOriginalFields,*/ now /*, ...otherOptions */ } = args\n const credentialContext = processEntryToArray(credential['@context'], MANDATORY_CREDENTIAL_CONTEXT)\n const credentialType = processEntryToArray(credential.type, 'VerifiableCredential')\n\n // only add issuanceDate for JWT\n now = typeof now === 'number' ? new Date(now * 1000) : now\n if (!Object.getOwnPropertyNames(credential).includes('issuanceDate')) {\n credential.issuanceDate = (now instanceof Date ? now : new Date()).toISOString()\n }\n\n credential = {\n ...credential,\n '@context': credentialContext,\n type: credentialType,\n }\n\n //FIXME: if the identifier is not found, the error message should reflect that.\n const issuer = extractIssuer(credential, { removeParameters: true })\n if (!issuer || typeof issuer === 'undefined') {\n throw new Error('invalid_argument: credential.issuer must not be empty')\n }\n\n try {\n await context.agent.didManagerGet({ did: issuer })\n } catch (e) {\n throw new Error(`invalid_argument: credential.issuer must be a DID managed by this agent. ${e}`)\n }\n try {\n async function findAndIssueCredential(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiableCredential(args, context)\n }\n }\n throw new Error('invalid_setup: No issuer found for the requested proof format')\n }\n const verifiableCredential = await findAndIssueCredential(this.issuers)\n return verifiableCredential\n } catch (error) {\n debug(error)\n return Promise.reject(error)\n }\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyCredential} */\n async verifyCredential(args: IVerifyCredentialLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { credential, policies /*, ...otherOptions*/ } = args\n let verifiedCredential: VerifiableCredential\n let verificationResult: IVerifyResult | undefined = { verified: false }\n\n async function findAndVerifyCredential(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: credential as W3CVerifiableCredential })) {\n return issuer.verifyCredential(args, context)\n }\n }\n return Promise.reject(Error('invalid_setup: No issuer found for the provided credential'))\n }\n verificationResult = await findAndVerifyCredential(this.issuers)\n verifiedCredential = <VerifiableCredential>credential\n\n if (policies?.credentialStatus !== false && (await isRevoked(verifiedCredential, context as any))) {\n verificationResult = {\n verified: false,\n error: {\n message: 'revoked: The credential was revoked by the issuer',\n errorCode: 'revoked',\n },\n }\n }\n\n return verificationResult\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiablePresentation} */\n async createVerifiablePresentation(args: ICreateVerifiablePresentationLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiablePresentationSP> {\n let {\n presentation,\n proofFormat,\n /* domain,\n challenge,\n removeOriginalFields,\n keyRef,*/\n // save,\n /*now,*/\n /*...otherOptions*/\n } = args\n const presentationContext: string[] = processEntryToArray(args?.presentation?.['@context'], MANDATORY_CREDENTIAL_CONTEXT)\n const presentationType = processEntryToArray(args?.presentation?.type, 'VerifiablePresentation')\n presentation = {\n ...presentation,\n '@context': presentationContext,\n type: presentationType,\n }\n\n if (!isDefined(presentation.holder)) {\n throw new Error('invalid_argument: presentation.holder must not be empty')\n }\n\n if (presentation.verifiableCredential) {\n presentation.verifiableCredential = presentation.verifiableCredential.map((cred) => {\n // map JWT credentials to their canonical form\n if (typeof cred !== 'string' && cred.proof.jwt) {\n return cred.proof.jwt\n } else {\n return cred\n }\n })\n }\n\n let verifiablePresentation: VerifiablePresentation | undefined\n\n async function findAndCreatePresentation(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiablePresentation(args, context)\n }\n }\n throw new Error('invalid_setup: No issuer found for the requested proof format')\n }\n\n verifiablePresentation = await findAndCreatePresentation(this.issuers)\n return verifiablePresentation as VerifiablePresentationSP // fixme: this is a hack to get around the fact that the return type is not correct.\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyPresentation} */\n async verifyPresentation(args: IVerifyPresentationLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { presentation /*domain, challenge, fetchRemoteContexts, policies, ...otherOptions*/ } = args\n async function findAndVerifyPresentation(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: presentation as W3CVerifiablePresentation })) {\n return issuer.verifyPresentation(args, context)\n }\n }\n throw new Error('invalid_setup: No verifier found for the provided presentation')\n }\n const result = await findAndVerifyPresentation(this.issuers)\n return result\n }\n}\n","import {\n CredentialPayload,\n IAgentContext, ICredentialStatusVerifier,\n IIdentifier,\n IKey,\n IssuerType,\n PresentationPayload,\n VerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation\n} from '@veramo/core'\nimport { isDefined } from '@veramo/utils'\nimport { decodeJWT } from 'did-jwt'\n\n/**\n * Decodes a credential or presentation and returns the issuer ID\n * `iss` from a JWT or `issuer`/`issuer.id` from a VC or `holder` from a VP\n *\n * @param input - the credential or presentation whose issuer/holder needs to be extracted.\n * @param options - options for the extraction\n * removeParameters - Remove all DID parameters from the issuer ID\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function extractIssuer(\n input?:\n | W3CVerifiableCredential\n | W3CVerifiablePresentation\n | CredentialPayload\n | PresentationPayload\n | null,\n options: { removeParameters?: boolean } = {}\n): string {\n if (!isDefined(input)) {\n return ''\n } else if (typeof input === 'string') {\n // JWT\n try {\n const { payload } = decodeJWT(input.split(`~`)[0])\n const iss = payload.iss ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n } catch (e: any) {\n return ''\n }\n } else {\n // JSON\n let iss: IssuerType\n if (input.issuer) {\n iss = input.issuer\n } else if (input.holder) {\n iss = input.holder\n } else {\n iss = ''\n }\n if (typeof iss !== 'string') iss = iss.id ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n }\n}\n\n\n/**\n * Remove all DID parameters from a DID url after the query part (?)\n *\n * @param did - the DID URL\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function removeDIDParameters(did: string): string {\n return did.replace(/\\?.*$/, '')\n}\n\n\nexport function pickSigningKey(identifier: IIdentifier, keyRef?: string): IKey {\n let key: IKey | undefined\n\n if (!keyRef) {\n key = identifier.keys.find((k) => k.type === 'Secp256k1' || k.type === 'Ed25519' || k.type === 'Secp256r1')\n if (!key) throw Error('key_not_found: No signing key for ' + identifier.did)\n } else {\n key = identifier.keys.find((k) => k.kid === keyRef)\n if (!key) throw Error('key_not_found: No signing key for ' + identifier.did + ' with kid ' + keyRef)\n }\n\n return key as IKey\n}\n\nexport async function isRevoked(credential: VerifiableCredential, context: IAgentContext<ICredentialStatusVerifier>): Promise<boolean> {\n if (!credential.credentialStatus) return false\n\n if (typeof context.agent.checkCredentialStatus === 'function') {\n const status = await context.agent.checkCredentialStatus({ credential })\n return status?.revoked == true || status?.verified === false\n }\n\n throw new Error(`invalid_setup: The credential status can't be verified because there is no ICredentialStatusVerifier plugin installed.`)\n}\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AqBoB,IAAI,CAACC,SAAAA;AAEzE,YAAI,OAAOA,SAAS,YAAYA,KAAKC,MAAMC,KAAK;AAC9C,iBAAOF,KAAKC,MAAMC;QACpB,OAAO;AACL,iBAAOF;QACT;MACF,CAAA;IACF;AAEA,QAAIG;AAEJ,mBAAeC,0BAA0BlE,SAAkC;AACzE,iBAAWc,UAAUd,SAAS;AAC5B,YAAIc,OAAO0B,uBAAuB;UAAEpB;QAAY,CAAA,GAAI;AAClD,iBAAO,MAAMN,OAAOP,6BAA6BW,MAAMR,OAAAA;QACzD;MACF;AACA,YAAM,IAAIyB,MAAM,+DAAA;IAClB;AAPe+B;AASfD,6BAAyB,MAAMC,0BAA0B,KAAKlE,OAAO;AACrE,WAAOiE;EACT;;EAGA,MAAMzD,mBAAmBU,MAAiCR,SAA4D;AACpH,QAAI;MAAE8C;;IAAgF,IAAOtC;AAC7F,mBAAeiD,0BAA0BnE,SAAkC;AACzE,iBAAWc,UAAUd,SAAS;AAC5B,YAAIc,OAAOoC,sBAAsB;UAAEC,UAAUK;QAA0C,CAAA,GAAI;AACzF,iBAAO1C,OAAON,mBAAmBU,MAAMR,OAAAA;QACzC;MACF;AACA,YAAM,IAAIyB,MAAM,gEAAA;IAClB;AAPegC;AAQf,UAAMC,SAAS,MAAMD,0BAA0B,KAAKnE,OAAO;AAC3D,WAAOoE;EACT;AACF;;;AF9LA,IAAMC,mBAAmBC;","names":["extractIssuer","debug","Debug","MessageTypes","vc","vp","W3cMessageHandler","AbstractMessageHandler","handle","message","context","meta","getLastMetaData","type","raw","data","validateJwtPresentationPayload","presentation","normalizePresentation","credentials","verifiableCredential","id","computeEntryHash","from","holder","to","verifier","tag","threadId","createdAt","issuanceDate","presentations","e","validateJwtCredentialPayload","credential","normalizeCredential","issuer","credentialSubject","result","agent","verifyCredential","verified","uuidv4","extractIssuer","Error","error","verifyPresentation","challenge","domain","asArray","map","decodeCredentialToObject","import_utils","import_debug","import_utils","extractIssuer","input","options","isDefined","payload","decodeJWT","split","iss","removeParameters","removeDIDParameters","e","issuer","holder","id","did","replace","pickSigningKey","identifier","keyRef","key","keys","find","k","type","Error","kid","isRevoked","credential","context","credentialStatus","agent","checkCredentialStatus","status","revoked","verified","debug","Debug","VcdmCredentialPlugin","methods","schema","components","schemas","ICredentialIssuer","ICredentialVerifier","issuers","constructor","options","listUsableProofFormats","bind","createVerifiableCredential","verifyCredential","createVerifiablePresentation","verifyPresentation","did","context","signingOptions","keys","key","issuer","matchKeyForType","push","getTypeProofFormat","args","credential","proofFormat","now","credentialContext","processEntryToArray","MANDATORY_CREDENTIAL_CONTEXT","credentialType","type","Date","Object","getOwnPropertyNames","includes","issuanceDate","toISOString","extractIssuer","removeParameters","Error","agent","didManagerGet","e","findAndIssueCredential","canIssueCredentialType","verifiableCredential","error","Promise","reject","policies","verifiedCredential","verificationResult","verified","findAndVerifyCredential","canVerifyDocumentType","document","credentialStatus","isRevoked","message","errorCode","presentation","presentationContext","presentationType","isDefined","holder","map","cred","proof","jwt","verifiablePresentation","findAndCreatePresentation","findAndVerifyPresentation","result","CredentialIssuer","VcdmCredentialPlugin"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/message-handler.ts","../src/vcdmCredentialPlugin.ts","../src/functions.ts"],"sourcesContent":["/**\n * Provides a {@link @veramo/credential-w3c#CredentialPlugin | plugin} for the {@link @veramo/core#Agent} that\n * implements\n * {@link @veramo/core#ICredentialIssuer} interface.\n *\n * Provides a {@link @veramo/credential-w3c#W3cMessageHandler | plugin} for the\n * {@link @veramo/message-handler#MessageHandler} that verifies Credentials and Presentations in a message.\n *\n * @packageDocumentation\n */\nexport type * from './types'\nexport { W3cMessageHandler, MessageTypes } from './message-handler'\nimport { VcdmCredentialPlugin } from './vcdmCredentialPlugin'\n\n/**\n * @deprecated please use {@link VcdmCredentialPlugin} instead\n * @public\n */\nconst CredentialIssuer = VcdmCredentialPlugin\nexport { CredentialIssuer, VcdmCredentialPlugin }\n\n// For backward compatibility, re-export the plugin types that were moved to core in v4\nexport type { ICredentialIssuer, ICredentialVerifier } from '@veramo/core'\n\nexport * from './functions'\n","import type {\n IAgentContext,\n ICredentialVerifier,\n IResolver,\n VerifiableCredential,\n VerifiablePresentation,\n} from '@veramo/core'\nimport { AbstractMessageHandler, Message } from '@veramo/message-handler'\nimport { asArray, computeEntryHash, decodeCredentialToObject, extractIssuer } from '@veramo/utils'\n\nimport {\n normalizeCredential,\n normalizePresentation,\n validateJwtCredentialPayload,\n validateJwtPresentationPayload,\n}// @ts-ignore\nfrom 'did-jwt-vc'\n\nimport { v4 as uuidv4 } from 'uuid'\nimport Debug from 'debug'\n\nconst debug = Debug('sphereon:vcdm:message-handler')\n\n/**\n * These types are used by `@veramo/data-store` when storing Verifiable Credentials and Presentations\n *\n * @internal\n */\nexport const MessageTypes = {\n /** Represents a Verifiable Credential */\n vc: 'w3c.vc',\n /** Represents a Verifiable Presentation */\n vp: 'w3c.vp',\n}\n\n/**\n * Represents the requirements that this plugin has.\n * The agent that is using this plugin is expected to provide these methods.\n *\n * This interface can be used for static type checks, to make sure your application is properly initialized.\n */\nexport type IContext = IAgentContext<IResolver & ICredentialVerifier>\n\n/**\n * An implementation of the {@link @veramo/message-handler#AbstractMessageHandler}.\n *\n * This plugin can handle incoming W3C Verifiable Credentials and Presentations and prepare them\n * for internal storage as {@link @veramo/message-handler#Message} types.\n *\n * The current version can only handle `JWT` encoded\n *\n * @remarks {@link @veramo/core#IDataStore | IDataStore }\n *\n * @public\n */\nexport class W3cMessageHandler extends AbstractMessageHandler {\n async handle(message: Message, context: IContext): Promise<Message> {\n const meta = message.getLastMetaData()\n\n // console.log(JSON.stringify(message, null, 2))\n\n //FIXME: messages should not be expected to be only JWT\n if (meta?.type === 'JWT' && message.raw) {\n const { data } = message\n\n try {\n validateJwtPresentationPayload(data)\n\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vp)\n const presentation = normalizePresentation(message.raw)\n const credentials = presentation.verifiableCredential\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vp\n message.from = presentation.holder\n message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = credentials\n\n return message\n } catch (e) {}\n\n try {\n validateJwtCredentialPayload(data)\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vc)\n const credential = normalizeCredential(message.raw)\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vc\n message.from = credential.issuer.id\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } catch (e) {}\n }\n\n // LDS Verification and Handling\n if (message.type === MessageTypes.vc && message.data) {\n // verify credential\n const credential = message.data as VerifiableCredential\n\n const result = await context.agent.verifyCredential({ credential })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vc\n message.from = extractIssuer(credential)\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n if (message.type === MessageTypes.vp && message.data) {\n // verify presentation\n const presentation = message.data as VerifiablePresentation\n\n // throws on error.\n const result = await context.agent.verifyPresentation({\n presentation,\n // FIXME: HARDCODED CHALLENGE VERIFICATION FOR NOW\n challenge: 'VERAMO',\n domain: 'VERAMO',\n })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vp\n message.from = presentation.holder\n // message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n // message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = asArray(presentation.verifiableCredential).map(decodeCredentialToObject)\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n return super.handle(message, context)\n }\n}\n","import type { IAgentPlugin, IIdentifier, IVerifyResult, VerifiableCredential } from '@veramo/core'\nimport { schema } from '@veramo/core'\n\nimport type {\n ICreateVerifiableCredentialLDArgs,\n ICreateVerifiablePresentationLDArgs,\n IVcdmCredentialPlugin,\n IVcdmCredentialProvider,\n IVcdmIssuerAgentContext,\n IVcdmVerifierAgentContext,\n IVerifyCredentialLDArgs,\n IVerifyPresentationLDArgs,\n} from './types'\nimport Debug from 'debug'\nimport { isRevoked, preProcessCredentialPayload, preProcessPresentation } from './functions'\nimport type { W3CVerifiableCredential, W3CVerifiablePresentation } from '@sphereon/ssi-types'\nimport { asArray, VerifiableCredentialSP, VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'\n\nconst debug = Debug('sphereon:ssi-sdk:vcdm')\n\n/**\n * A plugin that implements the {@link @sphereon/ssi-sdk.credential-vcdm#IVcdmCredentialPlugin} methods.\n *\n * @public\n */\nexport class VcdmCredentialPlugin implements IAgentPlugin {\n readonly methods: IVcdmCredentialPlugin\n readonly schema = {\n components: {\n schemas: {\n ...schema.ICredentialIssuer.components.schemas,\n ...schema.ICredentialVerifier.components.schemas,\n },\n methods: {\n ...schema.ICredentialIssuer.components.methods,\n ...schema.ICredentialVerifier.components.methods,\n },\n },\n }\n private issuers: IVcdmCredentialProvider[]\n\n constructor(options: { issuers: IVcdmCredentialProvider[] }) {\n this.issuers = options.issuers\n this.methods = {\n listUsableProofFormats: this.listUsableProofFormats.bind(this),\n createVerifiableCredential: this.createVerifiableCredential.bind(this),\n verifyCredential: this.verifyCredential.bind(this),\n createVerifiablePresentation: this.createVerifiablePresentation.bind(this),\n verifyPresentation: this.verifyPresentation.bind(this),\n }\n }\n\n async listUsableProofFormats(did: IIdentifier, context: IVcdmIssuerAgentContext): Promise<string[]> {\n const signingOptions: string[] = []\n const keys = did.keys\n for (const key of keys) {\n for (const issuer of this.issuers) {\n if (issuer.matchKeyForType(key)) {\n signingOptions.push(issuer.getTypeProofFormat())\n }\n }\n }\n return signingOptions\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiableCredential} */\n async createVerifiableCredential(args: ICreateVerifiableCredentialLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiableCredentialSP> {\n let { proofFormat /* keyRef, removeOriginalFields, now , ...otherOptions */ } = args\n const { credential, issuer, now } = preProcessCredentialPayload(args)\n\n try {\n await context.agent.didManagerGet({ did: issuer })\n } catch (e) {\n throw new Error(`invalid_argument: credential.issuer must be a DID managed by this agent. ${e}`)\n }\n try {\n async function findAndIssueCredential(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiableCredential({ ...args, credential, now }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n )\n }\n const verifiableCredential = await findAndIssueCredential(this.issuers)\n return verifiableCredential\n } catch (error) {\n debug(error)\n return Promise.reject(error)\n }\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyCredential} */\n async verifyCredential(args: IVerifyCredentialLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { credential, policies /*, ...otherOptions*/ } = args\n let verifiedCredential: VerifiableCredential\n let verificationResult: IVerifyResult | undefined = { verified: false }\n\n async function findAndVerifyCredential(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: credential as W3CVerifiableCredential })) {\n return issuer.verifyCredential(args, context)\n }\n }\n return Promise.reject(\n Error(\n `invalid_setup: No verifier found for the provided credential credential type: ${JSON.stringify(args.credential.type)} proof type ${asArray(args.credential.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n ),\n )\n }\n verificationResult = await findAndVerifyCredential(this.issuers)\n verifiedCredential = <VerifiableCredential>credential\n\n if (policies?.credentialStatus !== false && (await isRevoked(verifiedCredential, context as any))) {\n verificationResult = {\n verified: false,\n error: {\n message: 'revoked: The credential was revoked by the issuer',\n errorCode: 'revoked',\n },\n }\n }\n\n return verificationResult\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiablePresentation} */\n async createVerifiablePresentation(args: ICreateVerifiablePresentationLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiablePresentationSP> {\n const { proofFormat } = args\n const { presentation } = preProcessPresentation(args)\n\n let verifiablePresentation: VerifiablePresentationSP\n\n async function findAndCreatePresentation(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiablePresentation({ ...args, presentation }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n )\n }\n\n verifiablePresentation = await findAndCreatePresentation(this.issuers)\n return verifiablePresentation\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyPresentation} */\n async verifyPresentation(args: IVerifyPresentationLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { presentation /*domain, challenge, fetchRemoteContexts, policies, ...otherOptions*/ } = args\n async function findAndVerifyPresentation(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: presentation as W3CVerifiablePresentation })) {\n return issuer.verifyPresentation(args, context)\n }\n }\n throw new Error('invalid_setup: No verifier found for the provided presentation')\n }\n const result = await findAndVerifyPresentation(this.issuers)\n return result\n }\n}\n","import type {\n CredentialPayload,\n IAgentContext, ICredentialStatusVerifier,\n IIdentifier,\n IKey,\n IssuerType,\n PresentationPayload,\n VerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation\n} from '@veramo/core'\nimport { isDefined, processEntryToArray } from '@veramo/utils'\nimport { decodeJWT } from 'did-jwt'\nimport { addVcdmContextIfNeeded, isVcdm1Credential, isVcdm2Credential, VCDM_CREDENTIAL_CONTEXT_V1, VCDM_CREDENTIAL_CONTEXT_V2 } from '@sphereon/ssi-types'\nimport { ICreateVerifiablePresentationLDArgs } from './types'\n\n/**\n * Decodes a credential or presentation and returns the issuer ID\n * `iss` from a JWT or `issuer`/`issuer.id` from a VC or `holder` from a VP\n *\n * @param input - the credential or presentation whose issuer/holder needs to be extracted.\n * @param options - options for the extraction\n * removeParameters - Remove all DID parameters from the issuer ID\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function extractIssuer(\n input?:\n | W3CVerifiableCredential\n | W3CVerifiablePresentation\n | CredentialPayload\n | PresentationPayload\n | null,\n options: { removeParameters?: boolean } = {}\n): string {\n if (!isDefined(input)) {\n return ''\n } else if (typeof input === 'string') {\n // JWT\n try {\n const { payload } = decodeJWT(input.split(`~`)[0])\n const iss = payload.iss ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n } catch (e: any) {\n return ''\n }\n } else {\n // JSON\n let iss: IssuerType\n if (input.issuer) {\n iss = input.issuer\n } else if (input.holder) {\n iss = input.holder\n } else {\n iss = ''\n }\n if (typeof iss !== 'string') iss = iss.id ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n }\n}\n\n\n/**\n * Remove all DID parameters from a DID url after the query part (?)\n *\n * @param did - the DID URL\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function removeDIDParameters(did: string): string {\n return did.replace(/\\?.*$/, '')\n}\n\n\nexport function pickSigningKey(identifier: IIdentifier, keyRef?: string): IKey {\n let key: IKey | undefined\n\n if (!keyRef) {\n key = identifier.keys.find((k) => k.type === 'Secp256k1' || k.type === 'Ed25519' || k.type === 'Secp256r1')\n if (!key) throw Error('key_not_found: No signing key for ' + identifier.did)\n } else {\n key = identifier.keys.find((k) => k.kid === keyRef)\n if (!key) throw Error('key_not_found: No signing key for ' + identifier.did + ' with kid ' + keyRef)\n }\n\n return key as IKey\n}\n\nexport async function isRevoked(credential: VerifiableCredential, context: IAgentContext<ICredentialStatusVerifier>): Promise<boolean> {\n if (!credential.credentialStatus) return false\n\n if (typeof context.agent.checkCredentialStatus === 'function') {\n const status = await context.agent.checkCredentialStatus({ credential })\n return status?.revoked == true || status?.verified === false\n }\n\n throw new Error(`invalid_setup: The credential status can't be verified because there is no ICredentialStatusVerifier plugin installed.`)\n}\n\n\n\nexport function preProcessCredentialPayload({credential, now = new Date()}: {credential: CredentialPayload, now?: number | Date}) {\n const credentialContext = addVcdmContextIfNeeded(credential?.['@context'])\n const isVdcm1 = isVcdm1Credential(credential)\n const isVdcm2 = isVcdm2Credential(credential)\n const credentialType = processEntryToArray(credential?.type, 'VerifiableCredential')\n let issuanceDate = credential?.validFrom ?? credential?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()\n if (issuanceDate instanceof Date) {\n issuanceDate = issuanceDate.toISOString()\n }\n const credentialPayload: CredentialPayload = {\n ...credential,\n '@context': credentialContext,\n type: credentialType,\n ...(isVdcm1 && { issuanceDate }),\n ...(isVdcm2 && { validFrom: issuanceDate }),\n }\n\n // debug(JSON.stringify(credentialPayload))\n\n const issuer = extractIssuer(credentialPayload, {removeParameters: true})\n if (!issuer || typeof issuer === 'undefined') {\n throw new Error('invalid_argument: args.credential.issuer must not be empty')\n }\n return { credential: credentialPayload, issuer, now }\n}\n\n\nexport function preProcessPresentation(args: ICreateVerifiablePresentationLDArgs) {\n const { presentation, now = new Date() } = args\n const credentials = presentation?.verifiableCredential ?? []\n const v1Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V1))\n ? VCDM_CREDENTIAL_CONTEXT_V1\n : undefined\n const v2Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V2))\n ? VCDM_CREDENTIAL_CONTEXT_V2\n : undefined\n const presentationContext = addVcdmContextIfNeeded(args?.presentation?.['@context'] ?? [], v2Credential ?? v1Credential ?? VCDM_CREDENTIAL_CONTEXT_V2)\n const presentationType = processEntryToArray(args?.presentation?.type, 'VerifiablePresentation')\n\n let issuanceDate = presentation?.validFrom ?? presentation?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()\n if (issuanceDate instanceof Date) {\n issuanceDate = issuanceDate.toISOString()\n }\n const presentationPayload: PresentationPayload = {\n ...presentation,\n '@context': presentationContext,\n type: presentationType,\n ...(v1Credential && { issuanceDate }), // V1 only for JWT, but we remove it in the jsonld processor anyway\n ...(v2Credential && { validFrom: issuanceDate }),\n }\n // Workaround for bug in TypeError: Cannot read property 'length' of undefined\n // at VeramoEd25519Signature2018.preSigningPresModification\n /*if (!presentation.verifier) {\n presentation.verifier = []\n }*/\n\n if (!isDefined(presentationPayload.holder) || !presentationPayload.holder) {\n throw new Error('invalid_argument: args.presentation.holderDID must not be empty')\n }\n if (presentationPayload.verifiableCredential) {\n presentationPayload.verifiableCredential = presentationPayload.verifiableCredential.map((cred) => {\n // map JWT credentials to their canonical form\n if (typeof cred !== 'string' && cred.proof.jwt) {\n return cred.proof.jwt\n } else {\n return cred\n }\n })\n }\n return {presentation: presentationPayload, holder: removeDIDParameters(presentationPayload.holder)}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;uBAAAA;EAAA;;;;;;;;;ACOA,6BAAgD;AAChD,mBAAmF;AAEnF,wBAMK;AAEL,kBAA6B;AAC7B,mBAAkB;AAElB,IAAMC,YAAQC,aAAAA,SAAM,+BAAA;AAOb,IAAMC,eAAe;;EAE1BC,IAAI;;EAEJC,IAAI;AACN;AAsBO,IAAMC,oBAAN,cAAgCC,8CAAAA;EAhDvC,OAgDuCA;;;EACrC,MAAMC,OAAOC,SAAkBC,SAAqC;AAClE,UAAMC,OAAOF,QAAQG,gBAAe;AAKpC,QAAID,MAAME,SAAS,SAASJ,QAAQK,KAAK;AACvC,YAAM,EAAEC,KAAI,IAAKN;AAEjB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kC;AACzE,iBAAWc,UAAUd,SAAS;AAC5B,YAAIc,OAAOc,uBAAuB;UAAET;QAAY,CAAA,GAAI;AAClD,iBAAO,MAAML,OAAOP,6BAA6B;YAAE,GAAGW;YAAMkC;UAAa,GAAG1C,OAAAA;QAC9E;MACF;AACA,YAAM,IAAIgB,MACR,kEAAkEP,WAAAA,gBAA2BnB,QAAQ6B,IAAI,CAACC,MAAMA,EAAEb,mBAAkB,CAAA,EAAIc,KAAK,GAAA,CAAA,EAAM;IAEvJ;AATewB;AAWfD,6BAAyB,MAAMC,0BAA0B,KAAKvD,OAAO;AACrE,WAAOsD;EACT;;EAGA,MAAM9C,mBAAmBU,MAAiCR,SAA4D;AACpH,QAAI;MAAE0C;;IAAgF,IAAOlC;AAC7F,mBAAesC,0BAA0BxD,SAAkC;AACzE,iBAAWc,UAAUd,SAAS;AAC5B,YAAIc,OAAO2B,sBAAsB;UAAEC,UAAUU;QAA0C,CAAA,GAAI;AACzF,iBAAOtC,OAAON,mBAAmBU,MAAMR,OAAAA;QACzC;MACF;AACA,YAAM,IAAIgB,MAAM,gEAAA;IAClB;AAPe8B;AAQf,UAAMC,SAAS,MAAMD,0BAA0B,KAAKxD,OAAO;AAC3D,WAAOyD;EACT;AACF;;;AFlJA,IAAMC,mBAAmBC;","names":["extractIssuer","debug","Debug","MessageTypes","vc","vp","W3cMessageHandler","AbstractMessageHandler","handle","message","context","meta","getLastMetaData","type","raw","data","validateJwtPresentationPayload","presentation","normalizePresentation","credentials","verifiableCredential","id","computeEntryHash","from","holder","to","verifier","tag","threadId","createdAt","issuanceDate","presentations","e","validateJwtCredentialPayload","credential","normalizeCredential","issuer","credentialSubject","result","agent","verifyCredential","verified","uuidv4","extractIssuer","Error","error","verifyPresentation","challenge","domain","asArray","map","decodeCredentialToObject","import_debug","import_utils","extractIssuer","input","options","isDefined","payload","decodeJWT","split","iss","removeParameters","removeDIDParameters","e","issuer","holder","id","did","replace","pickSigningKey","identifier","keyRef","key","keys","find","k","type","Error","kid","isRevoked","credential","context","credentialStatus","agent","checkCredentialStatus","status","revoked","verified","preProcessCredentialPayload","now","Date","credentialContext","addVcdmContextIfNeeded","isVdcm1","isVcdm1Credential","isVdcm2","isVcdm2Credential","credentialType","processEntryToArray","issuanceDate","validFrom","toISOString","credentialPayload","preProcessPresentation","args","presentation","credentials","verifiableCredential","v1Credential","cred","includes","VCDM_CREDENTIAL_CONTEXT_V1","undefined","v2Credential","VCDM_CREDENTIAL_CONTEXT_V2","presentationContext","presentationType","presentationPayload","map","proof","jwt","debug","Debug","VcdmCredentialPlugin","methods","schema","components","schemas","ICredentialIssuer","ICredentialVerifier","issuers","constructor","options","listUsableProofFormats","bind","createVerifiableCredential","verifyCredential","createVerifiablePresentation","verifyPresentation","did","context","signingOptions","keys","key","issuer","matchKeyForType","push","getTypeProofFormat","args","proofFormat","credential","now","preProcessCredentialPayload","agent","didManagerGet","e","Error","findAndIssueCredential","canIssueCredentialType","map","i","join","verifiableCredential","error","Promise","reject","policies","verifiedCredential","verificationResult","verified","findAndVerifyCredential","canVerifyDocumentType","document","JSON","stringify","type","asArray","proof","credentialStatus","isRevoked","message","errorCode","presentation","preProcessPresentation","verifiablePresentation","findAndCreatePresentation","findAndVerifyPresentation","result","CredentialIssuer","VcdmCredentialPlugin"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { IPluginMethodMap, PresentationPayload, IAgentContext, IResolver, IDIDManager,
|
|
1
|
+
import { IPluginMethodMap, PresentationPayload, IAgentContext, IResolver, IDIDManager, IKeyManager, CredentialPayload, VerificationPolicies, IVerifyResult, IKey, ICredentialVerifier, IAgentPlugin, IIdentifier, W3CVerifiableCredential as W3CVerifiableCredential$1, W3CVerifiablePresentation as W3CVerifiablePresentation$1, VerifiableCredential, ICredentialStatusVerifier } from '@veramo/core';
|
|
2
2
|
export { ICredentialIssuer, ICredentialVerifier } from '@veramo/core';
|
|
3
3
|
import { VerifiablePresentationSP, VerifiableCredentialSP } from '@sphereon/ssi-sdk.core';
|
|
4
|
-
import { ISphereonKeyManager } from '@sphereon/ssi-sdk-ext.key-manager';
|
|
5
4
|
import { IIssueCredentialStatusOpts } from '@sphereon/ssi-sdk.vc-status-list';
|
|
6
|
-
import {
|
|
5
|
+
import { W3CVerifiablePresentation, W3CVerifiableCredential } from '@sphereon/ssi-types';
|
|
7
6
|
import { AbstractMessageHandler, Message } from '@veramo/message-handler';
|
|
8
7
|
|
|
9
8
|
type IVcdmCredentialPlugin = IVcdmCredentialIssuer & IVcdmCredentialVerifier;
|
|
@@ -147,7 +146,7 @@ interface IVerifyCredentialLDArgs {
|
|
|
147
146
|
* of the `credential`
|
|
148
147
|
*
|
|
149
148
|
*/
|
|
150
|
-
credential:
|
|
149
|
+
credential: VerifiableCredentialSP;
|
|
151
150
|
/**
|
|
152
151
|
* Set this to true if you want the '@context' URLs to be fetched in case they are not pre-loaded.
|
|
153
152
|
*
|
|
@@ -170,6 +169,7 @@ interface IVerifyCredentialLDArgs {
|
|
|
170
169
|
* Allows you to use the default integrated statusList 2021 support. If a checkStatus function is provided, this will be ignored
|
|
171
170
|
*/
|
|
172
171
|
statusList?: StatusListCheck;
|
|
172
|
+
[key: string]: any;
|
|
173
173
|
}
|
|
174
174
|
interface StatusListCheck {
|
|
175
175
|
/**
|
|
@@ -196,7 +196,7 @@ interface IVerifyPresentationLDArgs {
|
|
|
196
196
|
* of the `credential`
|
|
197
197
|
*
|
|
198
198
|
*/
|
|
199
|
-
presentation:
|
|
199
|
+
presentation: VerifiablePresentationSP | W3CVerifiablePresentation;
|
|
200
200
|
/**
|
|
201
201
|
* Optional (only for JWT) string challenge parameter to verify the verifiable presentation against
|
|
202
202
|
*/
|
|
@@ -227,6 +227,7 @@ interface IVerifyPresentationLDArgs {
|
|
|
227
227
|
* Allows you to use the default integrated statusList 2021 support. If a checkStatus function is provided, this will be ignored
|
|
228
228
|
*/
|
|
229
229
|
statusList?: StatusListCheck;
|
|
230
|
+
[key: string]: any;
|
|
230
231
|
}
|
|
231
232
|
/**
|
|
232
233
|
* Represents the requirements that this plugin has.
|
|
@@ -244,7 +245,7 @@ interface IVerifyPresentationLDArgs {
|
|
|
244
245
|
*
|
|
245
246
|
* @beta
|
|
246
247
|
*/
|
|
247
|
-
type IVcdmIssuerAgentContext = IAgentContext<IResolver & IDIDManager & Pick<
|
|
248
|
+
type IVcdmIssuerAgentContext = IAgentContext<IResolver & IDIDManager & Pick<IKeyManager, 'keyManagerGet' | 'keyManagerSign' | 'keyManagerVerify'>>;
|
|
248
249
|
type ContextDoc = {
|
|
249
250
|
'@context': string | Record<string, any>;
|
|
250
251
|
};
|
|
@@ -526,6 +527,18 @@ declare function extractIssuer(input?: W3CVerifiableCredential$1 | W3CVerifiable
|
|
|
526
527
|
declare function removeDIDParameters(did: string): string;
|
|
527
528
|
declare function pickSigningKey(identifier: IIdentifier, keyRef?: string): IKey;
|
|
528
529
|
declare function isRevoked(credential: VerifiableCredential, context: IAgentContext<ICredentialStatusVerifier>): Promise<boolean>;
|
|
530
|
+
declare function preProcessCredentialPayload({ credential, now }: {
|
|
531
|
+
credential: CredentialPayload;
|
|
532
|
+
now?: number | Date;
|
|
533
|
+
}): {
|
|
534
|
+
credential: CredentialPayload;
|
|
535
|
+
issuer: string;
|
|
536
|
+
now: number | Date;
|
|
537
|
+
};
|
|
538
|
+
declare function preProcessPresentation(args: ICreateVerifiablePresentationLDArgs): {
|
|
539
|
+
presentation: PresentationPayload;
|
|
540
|
+
holder: string;
|
|
541
|
+
};
|
|
529
542
|
|
|
530
543
|
/**
|
|
531
544
|
* Provides a {@link @veramo/credential-w3c#CredentialPlugin | plugin} for the {@link @veramo/core#Agent} that
|
|
@@ -544,4 +557,4 @@ declare function isRevoked(credential: VerifiableCredential, context: IAgentCont
|
|
|
544
557
|
*/
|
|
545
558
|
declare const CredentialIssuer: typeof VcdmCredentialPlugin;
|
|
546
559
|
|
|
547
|
-
export { type ContextDoc, CredentialIssuer, type IAssertionProofPurpose, type IAuthenticationProofPurpose, type ICanIssueCredentialTypeArgs, type ICanVerifyDocumentTypeArgs, type IControllerProofPurpose, type ICreateVerifiableCredentialLDArgs, type ICreateVerifiablePresentationLDArgs, type IProofPurpose, type IVcdmCredentialIssuer, type IVcdmCredentialPlugin, type IVcdmCredentialProvider, type IVcdmCredentialVerifier, type IVcdmIssuerAgentContext, type IVcdmVerifierAgentContext, type IVerifyCredentialLDArgs, type IVerifyPresentationLDArgs, MessageTypes, type StatusListCheck, VcdmCredentialPlugin, W3cMessageHandler, extractIssuer, isRevoked, pickSigningKey, removeDIDParameters };
|
|
560
|
+
export { type ContextDoc, CredentialIssuer, type IAssertionProofPurpose, type IAuthenticationProofPurpose, type ICanIssueCredentialTypeArgs, type ICanVerifyDocumentTypeArgs, type IControllerProofPurpose, type ICreateVerifiableCredentialLDArgs, type ICreateVerifiablePresentationLDArgs, type IProofPurpose, type IVcdmCredentialIssuer, type IVcdmCredentialPlugin, type IVcdmCredentialProvider, type IVcdmCredentialVerifier, type IVcdmIssuerAgentContext, type IVcdmVerifierAgentContext, type IVerifyCredentialLDArgs, type IVerifyPresentationLDArgs, MessageTypes, type StatusListCheck, VcdmCredentialPlugin, W3cMessageHandler, extractIssuer, isRevoked, pickSigningKey, preProcessCredentialPayload, preProcessPresentation, removeDIDParameters };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { IPluginMethodMap, PresentationPayload, IAgentContext, IResolver, IDIDManager,
|
|
1
|
+
import { IPluginMethodMap, PresentationPayload, IAgentContext, IResolver, IDIDManager, IKeyManager, CredentialPayload, VerificationPolicies, IVerifyResult, IKey, ICredentialVerifier, IAgentPlugin, IIdentifier, W3CVerifiableCredential as W3CVerifiableCredential$1, W3CVerifiablePresentation as W3CVerifiablePresentation$1, VerifiableCredential, ICredentialStatusVerifier } from '@veramo/core';
|
|
2
2
|
export { ICredentialIssuer, ICredentialVerifier } from '@veramo/core';
|
|
3
3
|
import { VerifiablePresentationSP, VerifiableCredentialSP } from '@sphereon/ssi-sdk.core';
|
|
4
|
-
import { ISphereonKeyManager } from '@sphereon/ssi-sdk-ext.key-manager';
|
|
5
4
|
import { IIssueCredentialStatusOpts } from '@sphereon/ssi-sdk.vc-status-list';
|
|
6
|
-
import {
|
|
5
|
+
import { W3CVerifiablePresentation, W3CVerifiableCredential } from '@sphereon/ssi-types';
|
|
7
6
|
import { AbstractMessageHandler, Message } from '@veramo/message-handler';
|
|
8
7
|
|
|
9
8
|
type IVcdmCredentialPlugin = IVcdmCredentialIssuer & IVcdmCredentialVerifier;
|
|
@@ -147,7 +146,7 @@ interface IVerifyCredentialLDArgs {
|
|
|
147
146
|
* of the `credential`
|
|
148
147
|
*
|
|
149
148
|
*/
|
|
150
|
-
credential:
|
|
149
|
+
credential: VerifiableCredentialSP;
|
|
151
150
|
/**
|
|
152
151
|
* Set this to true if you want the '@context' URLs to be fetched in case they are not pre-loaded.
|
|
153
152
|
*
|
|
@@ -170,6 +169,7 @@ interface IVerifyCredentialLDArgs {
|
|
|
170
169
|
* Allows you to use the default integrated statusList 2021 support. If a checkStatus function is provided, this will be ignored
|
|
171
170
|
*/
|
|
172
171
|
statusList?: StatusListCheck;
|
|
172
|
+
[key: string]: any;
|
|
173
173
|
}
|
|
174
174
|
interface StatusListCheck {
|
|
175
175
|
/**
|
|
@@ -196,7 +196,7 @@ interface IVerifyPresentationLDArgs {
|
|
|
196
196
|
* of the `credential`
|
|
197
197
|
*
|
|
198
198
|
*/
|
|
199
|
-
presentation:
|
|
199
|
+
presentation: VerifiablePresentationSP | W3CVerifiablePresentation;
|
|
200
200
|
/**
|
|
201
201
|
* Optional (only for JWT) string challenge parameter to verify the verifiable presentation against
|
|
202
202
|
*/
|
|
@@ -227,6 +227,7 @@ interface IVerifyPresentationLDArgs {
|
|
|
227
227
|
* Allows you to use the default integrated statusList 2021 support. If a checkStatus function is provided, this will be ignored
|
|
228
228
|
*/
|
|
229
229
|
statusList?: StatusListCheck;
|
|
230
|
+
[key: string]: any;
|
|
230
231
|
}
|
|
231
232
|
/**
|
|
232
233
|
* Represents the requirements that this plugin has.
|
|
@@ -244,7 +245,7 @@ interface IVerifyPresentationLDArgs {
|
|
|
244
245
|
*
|
|
245
246
|
* @beta
|
|
246
247
|
*/
|
|
247
|
-
type IVcdmIssuerAgentContext = IAgentContext<IResolver & IDIDManager & Pick<
|
|
248
|
+
type IVcdmIssuerAgentContext = IAgentContext<IResolver & IDIDManager & Pick<IKeyManager, 'keyManagerGet' | 'keyManagerSign' | 'keyManagerVerify'>>;
|
|
248
249
|
type ContextDoc = {
|
|
249
250
|
'@context': string | Record<string, any>;
|
|
250
251
|
};
|
|
@@ -526,6 +527,18 @@ declare function extractIssuer(input?: W3CVerifiableCredential$1 | W3CVerifiable
|
|
|
526
527
|
declare function removeDIDParameters(did: string): string;
|
|
527
528
|
declare function pickSigningKey(identifier: IIdentifier, keyRef?: string): IKey;
|
|
528
529
|
declare function isRevoked(credential: VerifiableCredential, context: IAgentContext<ICredentialStatusVerifier>): Promise<boolean>;
|
|
530
|
+
declare function preProcessCredentialPayload({ credential, now }: {
|
|
531
|
+
credential: CredentialPayload;
|
|
532
|
+
now?: number | Date;
|
|
533
|
+
}): {
|
|
534
|
+
credential: CredentialPayload;
|
|
535
|
+
issuer: string;
|
|
536
|
+
now: number | Date;
|
|
537
|
+
};
|
|
538
|
+
declare function preProcessPresentation(args: ICreateVerifiablePresentationLDArgs): {
|
|
539
|
+
presentation: PresentationPayload;
|
|
540
|
+
holder: string;
|
|
541
|
+
};
|
|
529
542
|
|
|
530
543
|
/**
|
|
531
544
|
* Provides a {@link @veramo/credential-w3c#CredentialPlugin | plugin} for the {@link @veramo/core#Agent} that
|
|
@@ -544,4 +557,4 @@ declare function isRevoked(credential: VerifiableCredential, context: IAgentCont
|
|
|
544
557
|
*/
|
|
545
558
|
declare const CredentialIssuer: typeof VcdmCredentialPlugin;
|
|
546
559
|
|
|
547
|
-
export { type ContextDoc, CredentialIssuer, type IAssertionProofPurpose, type IAuthenticationProofPurpose, type ICanIssueCredentialTypeArgs, type ICanVerifyDocumentTypeArgs, type IControllerProofPurpose, type ICreateVerifiableCredentialLDArgs, type ICreateVerifiablePresentationLDArgs, type IProofPurpose, type IVcdmCredentialIssuer, type IVcdmCredentialPlugin, type IVcdmCredentialProvider, type IVcdmCredentialVerifier, type IVcdmIssuerAgentContext, type IVcdmVerifierAgentContext, type IVerifyCredentialLDArgs, type IVerifyPresentationLDArgs, MessageTypes, type StatusListCheck, VcdmCredentialPlugin, W3cMessageHandler, extractIssuer, isRevoked, pickSigningKey, removeDIDParameters };
|
|
560
|
+
export { type ContextDoc, CredentialIssuer, type IAssertionProofPurpose, type IAuthenticationProofPurpose, type ICanIssueCredentialTypeArgs, type ICanVerifyDocumentTypeArgs, type IControllerProofPurpose, type ICreateVerifiableCredentialLDArgs, type ICreateVerifiablePresentationLDArgs, type IProofPurpose, type IVcdmCredentialIssuer, type IVcdmCredentialPlugin, type IVcdmCredentialProvider, type IVcdmCredentialVerifier, type IVcdmIssuerAgentContext, type IVcdmVerifierAgentContext, type IVerifyCredentialLDArgs, type IVerifyPresentationLDArgs, MessageTypes, type StatusListCheck, VcdmCredentialPlugin, W3cMessageHandler, extractIssuer, isRevoked, pickSigningKey, preProcessCredentialPayload, preProcessPresentation, removeDIDParameters };
|