@sphereon/ssi-sdk.credential-vcdm 0.33.1-next.68 → 0.33.1-next.73
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 +32 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +32 -7
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/types.ts +11 -6
- package/src/vcdmCredentialPlugin.ts +52 -20
package/dist/index.cjs
CHANGED
|
@@ -155,6 +155,8 @@ var W3cMessageHandler = class extends import_message_handler.AbstractMessageHand
|
|
|
155
155
|
};
|
|
156
156
|
|
|
157
157
|
// src/vcdmCredentialPlugin.ts
|
|
158
|
+
var import_ssi_sdk = require("@sphereon/ssi-sdk.core");
|
|
159
|
+
var import_ssi_types2 = require("@sphereon/ssi-types");
|
|
158
160
|
var import_core = require("@veramo/core");
|
|
159
161
|
var import_debug2 = __toESM(require("debug"), 1);
|
|
160
162
|
|
|
@@ -301,7 +303,6 @@ function preProcessPresentation(args) {
|
|
|
301
303
|
__name(preProcessPresentation, "preProcessPresentation");
|
|
302
304
|
|
|
303
305
|
// src/vcdmCredentialPlugin.ts
|
|
304
|
-
var import_ssi_sdk = require("@sphereon/ssi-sdk.core");
|
|
305
306
|
var debug2 = (0, import_debug2.default)("sphereon:ssi-sdk:vcdm");
|
|
306
307
|
var VcdmCredentialPlugin = class {
|
|
307
308
|
static {
|
|
@@ -388,9 +389,7 @@ var VcdmCredentialPlugin = class {
|
|
|
388
389
|
/*, ...otherOptions*/
|
|
389
390
|
} = args;
|
|
390
391
|
let verifiedCredential;
|
|
391
|
-
let verificationResult
|
|
392
|
-
verified: false
|
|
393
|
-
};
|
|
392
|
+
let verificationResult;
|
|
394
393
|
async function findAndVerifyCredential(issuers) {
|
|
395
394
|
for (const issuer of issuers) {
|
|
396
395
|
if (issuer.canVerifyDocumentType({
|
|
@@ -399,18 +398,44 @@ var VcdmCredentialPlugin = class {
|
|
|
399
398
|
return issuer.verifyCredential(args, context);
|
|
400
399
|
}
|
|
401
400
|
}
|
|
402
|
-
|
|
401
|
+
const uniform = import_ssi_types2.CredentialMapper.toUniformCredential(args.credential);
|
|
402
|
+
return Promise.reject(Error(`invalid_setup: No verifier found for the provided credential credential
|
|
403
|
+
type: ${JSON.stringify(uniform.type)} proof type
|
|
404
|
+
${(0, import_ssi_sdk.asArray)(uniform.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(",")}`));
|
|
403
405
|
}
|
|
404
406
|
__name(findAndVerifyCredential, "findAndVerifyCredential");
|
|
405
407
|
verificationResult = await findAndVerifyCredential(this.issuers);
|
|
406
408
|
verifiedCredential = credential;
|
|
407
409
|
if (policies?.credentialStatus !== false && await isRevoked(verifiedCredential, context)) {
|
|
408
|
-
|
|
410
|
+
const results = verificationResult.results;
|
|
411
|
+
const partialSingleResult = Array.isArray(results) ? results[0] : {
|
|
412
|
+
credential,
|
|
413
|
+
verified: false,
|
|
414
|
+
log: []
|
|
415
|
+
};
|
|
416
|
+
const result = {
|
|
417
|
+
...partialSingleResult,
|
|
418
|
+
credential,
|
|
409
419
|
verified: false,
|
|
410
420
|
error: {
|
|
411
421
|
message: "revoked: The credential was revoked by the issuer",
|
|
412
422
|
errorCode: "revoked"
|
|
413
|
-
}
|
|
423
|
+
},
|
|
424
|
+
log: [
|
|
425
|
+
...partialSingleResult.log ?? [],
|
|
426
|
+
{
|
|
427
|
+
id: "revocation_status",
|
|
428
|
+
valid: false
|
|
429
|
+
}
|
|
430
|
+
]
|
|
431
|
+
};
|
|
432
|
+
verificationResult = {
|
|
433
|
+
...verificationResult,
|
|
434
|
+
verified: false,
|
|
435
|
+
error: result.error,
|
|
436
|
+
results: [
|
|
437
|
+
result
|
|
438
|
+
]
|
|
414
439
|
};
|
|
415
440
|
}
|
|
416
441
|
return verificationResult;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 { IAgentContext, ICredentialVerifier, IResolver, VerifiableCredential, VerifiablePresentation } 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, // @ts-ignore\n} from '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,\n ICredentialStatusVerifier,\n IDIDManager,\n IIdentifier,\n IResolver,\n IssuerType,\n PresentationPayload,\n VerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation,\n} from '@veramo/core'\nimport { _ExtendedIKey, isDefined, processEntryToArray } from '@veramo/utils'\nimport { decodeJWT } from 'did-jwt'\nimport {\n addVcdmContextIfNeeded,\n isVcdm1Credential,\n isVcdm2Credential,\n VCDM_CREDENTIAL_CONTEXT_V1,\n VCDM_CREDENTIAL_CONTEXT_V2,\n} from '@sphereon/ssi-types'\nimport { ICreateVerifiablePresentationLDArgs } from './types'\nimport { getKey } from '@sphereon/ssi-sdk-ext.did-utils'\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?: W3CVerifiableCredential | W3CVerifiablePresentation | CredentialPayload | PresentationPayload | 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 * 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\nexport async function pickSigningKey(\n { identifier, kmsKeyRef }: { identifier: IIdentifier; kmsKeyRef?: string },\n context: IAgentContext<IResolver & IDIDManager>,\n): Promise<_ExtendedIKey> {\n const key = await getKey({ identifier, vmRelationship: 'assertionMethod', kmsKeyRef: kmsKeyRef }, context)\n return key\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\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 let expirationDate = credential?.validUntil ?? credential?.expirationDate\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 ...(isVdcm1 && expirationDate && { expirationDate }),\n ...(isVdcm2 && { validFrom: issuanceDate }),\n ...(isVdcm2 && expirationDate && { validUntil: expirationDate }),\n }\n if (isVdcm1) {\n delete credentialPayload.validFrom\n delete credentialPayload.validUntil\n } else if (isVdcm2) {\n delete credentialPayload.issuanceDate\n delete credentialPayload.expirationDate\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\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(\n args?.presentation?.['@context'] ?? [],\n v2Credential ?? v1Credential ?? VCDM_CREDENTIAL_CONTEXT_V2,\n )\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;;;;;;;;;ACCA,6BAAgD;AAChD,mBAAmF;AAEnF,wBAKO;AAEP,kBAA6B;AAC7B,mBAAkB;AAElB,IAAMC,YAAQC,aAAAA,SAAM,+BAAA;AAOb,IAAMC,eAAe;;EAE1BC,IAAI;;EAEJC,IAAI;AACN;AAsBO,IAAMC,oBAAN,cAAgCC,8CAAAA;EA/CvC,OA+CuCA;;;EACrC,MAAMC,OAAOC,SAAkBC,SAAqC;AAClE,UAAMC,OAAOF,QAAQG,gBAAe;AAKpC,QAAID,MAAME,SAAS,SAASJ,QAAQK,KAAK;AACvC,YAAM,EAAEC,KAAI,IAAKN;AAEjB,UAAI;AACFO,8DAA+BD,IAAAA;AAG/Bd,cAAM,UAAUE,aAAaE,EAAE;AAC/B,cAAMY,mBAAeC,yCAAsBT,QAAQK,GAAG;AACtD,cAAMK,cAAcF,aAAaG;AAEjCX,gBAAQY,SAAKC,+BAAiBb,QAAQK,GAAG;AACzCL,gBAAQI,OAAOV,aAAaE;AAC5BI,gBAAQc,OAAON,aAAaO;AAC5Bf,gBAAQgB,KAAKR,aAAaS,WAAW,CAAA;AAErC,YAAIT,aAAaU,KAAK;AACpBlB,kBAAQmB,WAAWX,aAAaU;QAClC;AAEAlB,gBAAQoB,YAAYZ,aAAaa;AACjCrB,gBAAQsB,gBAAgB;UAACd;;AACzBR,gBAAQU,cAAcA;AAEtB,eAAOV;MACT,SAASuB,GAAG;MAAC;AAEb,UAAI;AACFC,4DAA6BlB,IAAAA;AAE7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,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","kmsKeyRef","context","key","getKey","vmRelationship","isRevoked","credential","credentialStatus","agent","checkCredentialStatus","status","revoked","verified","Error","preProcessCredentialPayload","now","Date","credentialContext","addVcdmContextIfNeeded","isVdcm1","isVcdm1Credential","isVdcm2","isVcdm2Credential","credentialType","processEntryToArray","type","issuanceDate","validFrom","toISOString","expirationDate","validUntil","credentialPayload","preProcessPresentation","args","presentation","credentials","verifiableCredential","v1Credential","find","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"]}
|
|
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 { IAgentContext, ICredentialVerifier, IResolver, VerifiableCredential, VerifiablePresentation } 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, // @ts-ignore\n} from '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 { asArray, type VerifiableCredentialSP, type VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'\nimport {\n CredentialMapper,\n IVerifyResult,\n IVerifySingleResultItem,\n OriginalVerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation\n} from '@sphereon/ssi-types'\nimport type { IAgentPlugin, IIdentifier, VerifiableCredential } from '@veramo/core'\nimport { schema } from '@veramo/core'\nimport Debug from 'debug'\nimport { isRevoked, preProcessCredentialPayload, preProcessPresentation } from './functions'\n\nimport type {\n ICreateVerifiableCredentialLDArgs,\n ICreateVerifiablePresentationLDArgs,\n IVcdmCredentialPlugin,\n IVcdmCredentialProvider,\n IVcdmIssuerAgentContext,\n IVcdmVerifierAgentContext,\n IVerifyCredentialVcdmArgs,\n IVerifyPresentationLDArgs\n} from './types'\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\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: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { credential, policies /*, ...otherOptions*/ } = args\n let verifiedCredential: VerifiableCredential\n let verificationResult: IVerifyResult\n\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 const uniform = CredentialMapper.toUniformCredential(args.credential as OriginalVerifiableCredential)\n return Promise.reject(\n Error(\n `invalid_setup: No verifier found for the provided credential credential\n type: ${JSON.stringify(uniform.type)} proof type \n ${asArray(uniform.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`\n )\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 const results = verificationResult.results\n const partialSingleResult: Partial<IVerifySingleResultItem> = (Array.isArray(results) ? results[0] : {\n credential: credential as OriginalVerifiableCredential,\n verified: false,\n log: []\n })\n const result: IVerifySingleResultItem = {\n ...partialSingleResult,\n credential: credential as OriginalVerifiableCredential,\n verified: false,\n error: {\n message: 'revoked: The credential was revoked by the issuer',\n errorCode: 'revoked'\n },\n log: [...partialSingleResult.log ?? [], { id: 'revocation_status', valid: false }]\n }\n verificationResult = {\n ...verificationResult,\n verified: false,\n error: result.error,\n results: [\n result\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\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\n const result = await findAndVerifyPresentation(this.issuers)\n return result\n }\n}\n","import type {\n CredentialPayload,\n IAgentContext,\n ICredentialStatusVerifier,\n IDIDManager,\n IIdentifier,\n IResolver,\n IssuerType,\n PresentationPayload,\n VerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation,\n} from '@veramo/core'\nimport { _ExtendedIKey, isDefined, processEntryToArray } from '@veramo/utils'\nimport { decodeJWT } from 'did-jwt'\nimport {\n addVcdmContextIfNeeded,\n isVcdm1Credential,\n isVcdm2Credential,\n VCDM_CREDENTIAL_CONTEXT_V1,\n VCDM_CREDENTIAL_CONTEXT_V2,\n} from '@sphereon/ssi-types'\nimport { ICreateVerifiablePresentationLDArgs } from './types'\nimport { getKey } from '@sphereon/ssi-sdk-ext.did-utils'\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?: W3CVerifiableCredential | W3CVerifiablePresentation | CredentialPayload | PresentationPayload | 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 * 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\nexport async function pickSigningKey(\n { identifier, kmsKeyRef }: { identifier: IIdentifier; kmsKeyRef?: string },\n context: IAgentContext<IResolver & IDIDManager>,\n): Promise<_ExtendedIKey> {\n const key = await getKey({ identifier, vmRelationship: 'assertionMethod', kmsKeyRef: kmsKeyRef }, context)\n return key\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\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 let expirationDate = credential?.validUntil ?? credential?.expirationDate\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 ...(isVdcm1 && expirationDate && { expirationDate }),\n ...(isVdcm2 && { validFrom: issuanceDate }),\n ...(isVdcm2 && expirationDate && { validUntil: expirationDate }),\n }\n if (isVdcm1) {\n delete credentialPayload.validFrom\n delete credentialPayload.validUntil\n } else if (isVdcm2) {\n delete credentialPayload.issuanceDate\n delete credentialPayload.expirationDate\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\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(\n args?.presentation?.['@context'] ?? [],\n v2Credential ?? v1Credential ?? VCDM_CREDENTIAL_CONTEXT_V2,\n )\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;;;;;;;;;ACCA,6BAAgD;AAChD,mBAAmF;AAEnF,wBAKO;AAEP,kBAA6B;AAC7B,mBAAkB;AAElB,IAAMC,YAAQC,aAAAA,SAAM,+BAAA;AAOb,IAAMC,eAAe;;EAE1BC,IAAI;;EAEJC,IAAI;AACN;AAsBO,IAAMC,oBAAN,cAAgCC,8CAAAA;EA/CvC,OA+CuCA;;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AA;IAClB;AAPeyC;AASf,UAAMT,SAAS,MAAMS,0BAA0B,KAAKnE,OAAO;AAC3D,WAAO0D;EACT;AACF;;;AFlLA,IAAMU,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_ssi_types","import_debug","import_utils","extractIssuer","input","options","isDefined","payload","decodeJWT","split","iss","removeParameters","removeDIDParameters","e","issuer","holder","id","did","replace","pickSigningKey","identifier","kmsKeyRef","context","key","getKey","vmRelationship","isRevoked","credential","credentialStatus","agent","checkCredentialStatus","status","revoked","verified","Error","preProcessCredentialPayload","now","Date","credentialContext","addVcdmContextIfNeeded","isVdcm1","isVcdm1Credential","isVdcm2","isVcdm2Credential","credentialType","processEntryToArray","type","issuanceDate","validFrom","toISOString","expirationDate","validUntil","credentialPayload","preProcessPresentation","args","presentation","credentials","verifiableCredential","v1Credential","find","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","findAndVerifyCredential","canVerifyDocumentType","document","uniform","CredentialMapper","toUniformCredential","JSON","stringify","type","asArray","proof","credentialStatus","isRevoked","results","partialSingleResult","Array","isArray","verified","log","result","message","errorCode","id","valid","presentation","preProcessPresentation","verifiablePresentation","findAndCreatePresentation","findAndVerifyPresentation","CredentialIssuer","VcdmCredentialPlugin"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { IPluginMethodMap, PresentationPayload, IAgentContext, IResolver, IDIDManager, IKeyManager, CredentialPayload, VerificationPolicies,
|
|
1
|
+
import { IPluginMethodMap, PresentationPayload, IAgentContext, IResolver, IDIDManager, IKeyManager, CredentialPayload, VerificationPolicies, 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
4
|
import { IIssueCredentialStatusOpts } from '@sphereon/ssi-sdk.vc-status-list';
|
|
5
|
-
import { W3CVerifiablePresentation, W3CVerifiableCredential } from '@sphereon/ssi-types';
|
|
5
|
+
import { OriginalVerifiableCredential, ICredential, IVerifyResult, W3CVerifiablePresentation, W3CVerifiableCredential } from '@sphereon/ssi-types';
|
|
6
6
|
import { AbstractMessageHandler, Message } from '@veramo/message-handler';
|
|
7
7
|
import { _ExtendedIKey } from '@veramo/utils';
|
|
8
8
|
|
|
@@ -138,7 +138,7 @@ interface ICreateVerifiableCredentialLDArgs {
|
|
|
138
138
|
*
|
|
139
139
|
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
140
140
|
*/
|
|
141
|
-
interface
|
|
141
|
+
interface IVerifyCredentialVcdmArgs {
|
|
142
142
|
/**
|
|
143
143
|
* The json payload of the Credential according to the
|
|
144
144
|
* {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model}
|
|
@@ -147,7 +147,7 @@ interface IVerifyCredentialLDArgs {
|
|
|
147
147
|
* of the `credential`
|
|
148
148
|
*
|
|
149
149
|
*/
|
|
150
|
-
credential:
|
|
150
|
+
credential: OriginalVerifiableCredential | ICredential;
|
|
151
151
|
/**
|
|
152
152
|
* Set this to true if you want the '@context' URLs to be fetched in case they are not pre-loaded.
|
|
153
153
|
*
|
|
@@ -340,7 +340,7 @@ interface IVcdmCredentialProvider {
|
|
|
340
340
|
*
|
|
341
341
|
* @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model}
|
|
342
342
|
*/
|
|
343
|
-
verifyCredential(args:
|
|
343
|
+
verifyCredential(args: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult>;
|
|
344
344
|
/**
|
|
345
345
|
*
|
|
346
346
|
* @param args - Arguments necessary to verify a document
|
|
@@ -419,7 +419,7 @@ interface IVcdmCredentialVerifier extends IPluginMethodMap {
|
|
|
419
419
|
*
|
|
420
420
|
* @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model}
|
|
421
421
|
*/
|
|
422
|
-
verifyCredential(args:
|
|
422
|
+
verifyCredential(args: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult>;
|
|
423
423
|
/**
|
|
424
424
|
* Verifies a Verifiable Presentation JWT or LDS Format.
|
|
425
425
|
*
|
|
@@ -498,7 +498,7 @@ declare class VcdmCredentialPlugin implements IAgentPlugin {
|
|
|
498
498
|
/** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiableCredential} */
|
|
499
499
|
createVerifiableCredential(args: ICreateVerifiableCredentialLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiableCredentialSP>;
|
|
500
500
|
/** {@inheritdoc @veramo/core#ICredentialVerifier.verifyCredential} */
|
|
501
|
-
verifyCredential(args:
|
|
501
|
+
verifyCredential(args: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult>;
|
|
502
502
|
/** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiablePresentation} */
|
|
503
503
|
createVerifiablePresentation(args: ICreateVerifiablePresentationLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiablePresentationSP>;
|
|
504
504
|
/** {@inheritdoc @veramo/core#ICredentialVerifier.verifyPresentation} */
|
|
@@ -561,4 +561,4 @@ declare function preProcessPresentation(args: ICreateVerifiablePresentationLDArg
|
|
|
561
561
|
*/
|
|
562
562
|
declare const CredentialIssuer: typeof VcdmCredentialPlugin;
|
|
563
563
|
|
|
564
|
-
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
|
|
564
|
+
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 IVerifyCredentialVcdmArgs, type IVerifyPresentationLDArgs, MessageTypes, type StatusListCheck, VcdmCredentialPlugin, W3cMessageHandler, extractIssuer, isRevoked, pickSigningKey, preProcessCredentialPayload, preProcessPresentation, removeDIDParameters };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { IPluginMethodMap, PresentationPayload, IAgentContext, IResolver, IDIDManager, IKeyManager, CredentialPayload, VerificationPolicies,
|
|
1
|
+
import { IPluginMethodMap, PresentationPayload, IAgentContext, IResolver, IDIDManager, IKeyManager, CredentialPayload, VerificationPolicies, 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
4
|
import { IIssueCredentialStatusOpts } from '@sphereon/ssi-sdk.vc-status-list';
|
|
5
|
-
import { W3CVerifiablePresentation, W3CVerifiableCredential } from '@sphereon/ssi-types';
|
|
5
|
+
import { OriginalVerifiableCredential, ICredential, IVerifyResult, W3CVerifiablePresentation, W3CVerifiableCredential } from '@sphereon/ssi-types';
|
|
6
6
|
import { AbstractMessageHandler, Message } from '@veramo/message-handler';
|
|
7
7
|
import { _ExtendedIKey } from '@veramo/utils';
|
|
8
8
|
|
|
@@ -138,7 +138,7 @@ interface ICreateVerifiableCredentialLDArgs {
|
|
|
138
138
|
*
|
|
139
139
|
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
140
140
|
*/
|
|
141
|
-
interface
|
|
141
|
+
interface IVerifyCredentialVcdmArgs {
|
|
142
142
|
/**
|
|
143
143
|
* The json payload of the Credential according to the
|
|
144
144
|
* {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model}
|
|
@@ -147,7 +147,7 @@ interface IVerifyCredentialLDArgs {
|
|
|
147
147
|
* of the `credential`
|
|
148
148
|
*
|
|
149
149
|
*/
|
|
150
|
-
credential:
|
|
150
|
+
credential: OriginalVerifiableCredential | ICredential;
|
|
151
151
|
/**
|
|
152
152
|
* Set this to true if you want the '@context' URLs to be fetched in case they are not pre-loaded.
|
|
153
153
|
*
|
|
@@ -340,7 +340,7 @@ interface IVcdmCredentialProvider {
|
|
|
340
340
|
*
|
|
341
341
|
* @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model}
|
|
342
342
|
*/
|
|
343
|
-
verifyCredential(args:
|
|
343
|
+
verifyCredential(args: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult>;
|
|
344
344
|
/**
|
|
345
345
|
*
|
|
346
346
|
* @param args - Arguments necessary to verify a document
|
|
@@ -419,7 +419,7 @@ interface IVcdmCredentialVerifier extends IPluginMethodMap {
|
|
|
419
419
|
*
|
|
420
420
|
* @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model}
|
|
421
421
|
*/
|
|
422
|
-
verifyCredential(args:
|
|
422
|
+
verifyCredential(args: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult>;
|
|
423
423
|
/**
|
|
424
424
|
* Verifies a Verifiable Presentation JWT or LDS Format.
|
|
425
425
|
*
|
|
@@ -498,7 +498,7 @@ declare class VcdmCredentialPlugin implements IAgentPlugin {
|
|
|
498
498
|
/** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiableCredential} */
|
|
499
499
|
createVerifiableCredential(args: ICreateVerifiableCredentialLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiableCredentialSP>;
|
|
500
500
|
/** {@inheritdoc @veramo/core#ICredentialVerifier.verifyCredential} */
|
|
501
|
-
verifyCredential(args:
|
|
501
|
+
verifyCredential(args: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult>;
|
|
502
502
|
/** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiablePresentation} */
|
|
503
503
|
createVerifiablePresentation(args: ICreateVerifiablePresentationLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiablePresentationSP>;
|
|
504
504
|
/** {@inheritdoc @veramo/core#ICredentialVerifier.verifyPresentation} */
|
|
@@ -561,4 +561,4 @@ declare function preProcessPresentation(args: ICreateVerifiablePresentationLDArg
|
|
|
561
561
|
*/
|
|
562
562
|
declare const CredentialIssuer: typeof VcdmCredentialPlugin;
|
|
563
563
|
|
|
564
|
-
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
|
|
564
|
+
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 IVerifyCredentialVcdmArgs, type IVerifyPresentationLDArgs, MessageTypes, type StatusListCheck, VcdmCredentialPlugin, W3cMessageHandler, extractIssuer, isRevoked, pickSigningKey, preProcessCredentialPayload, preProcessPresentation, removeDIDParameters };
|
package/dist/index.js
CHANGED
|
@@ -112,6 +112,8 @@ var W3cMessageHandler = class extends AbstractMessageHandler {
|
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
// src/vcdmCredentialPlugin.ts
|
|
115
|
+
import { asArray as asArray2 } from "@sphereon/ssi-sdk.core";
|
|
116
|
+
import { CredentialMapper } from "@sphereon/ssi-types";
|
|
115
117
|
import { schema } from "@veramo/core";
|
|
116
118
|
import Debug2 from "debug";
|
|
117
119
|
|
|
@@ -258,7 +260,6 @@ function preProcessPresentation(args) {
|
|
|
258
260
|
__name(preProcessPresentation, "preProcessPresentation");
|
|
259
261
|
|
|
260
262
|
// src/vcdmCredentialPlugin.ts
|
|
261
|
-
import { asArray as asArray2 } from "@sphereon/ssi-sdk.core";
|
|
262
263
|
var debug2 = Debug2("sphereon:ssi-sdk:vcdm");
|
|
263
264
|
var VcdmCredentialPlugin = class {
|
|
264
265
|
static {
|
|
@@ -345,9 +346,7 @@ var VcdmCredentialPlugin = class {
|
|
|
345
346
|
/*, ...otherOptions*/
|
|
346
347
|
} = args;
|
|
347
348
|
let verifiedCredential;
|
|
348
|
-
let verificationResult
|
|
349
|
-
verified: false
|
|
350
|
-
};
|
|
349
|
+
let verificationResult;
|
|
351
350
|
async function findAndVerifyCredential(issuers) {
|
|
352
351
|
for (const issuer of issuers) {
|
|
353
352
|
if (issuer.canVerifyDocumentType({
|
|
@@ -356,18 +355,44 @@ var VcdmCredentialPlugin = class {
|
|
|
356
355
|
return issuer.verifyCredential(args, context);
|
|
357
356
|
}
|
|
358
357
|
}
|
|
359
|
-
|
|
358
|
+
const uniform = CredentialMapper.toUniformCredential(args.credential);
|
|
359
|
+
return Promise.reject(Error(`invalid_setup: No verifier found for the provided credential credential
|
|
360
|
+
type: ${JSON.stringify(uniform.type)} proof type
|
|
361
|
+
${asArray2(uniform.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(",")}`));
|
|
360
362
|
}
|
|
361
363
|
__name(findAndVerifyCredential, "findAndVerifyCredential");
|
|
362
364
|
verificationResult = await findAndVerifyCredential(this.issuers);
|
|
363
365
|
verifiedCredential = credential;
|
|
364
366
|
if (policies?.credentialStatus !== false && await isRevoked(verifiedCredential, context)) {
|
|
365
|
-
|
|
367
|
+
const results = verificationResult.results;
|
|
368
|
+
const partialSingleResult = Array.isArray(results) ? results[0] : {
|
|
369
|
+
credential,
|
|
370
|
+
verified: false,
|
|
371
|
+
log: []
|
|
372
|
+
};
|
|
373
|
+
const result = {
|
|
374
|
+
...partialSingleResult,
|
|
375
|
+
credential,
|
|
366
376
|
verified: false,
|
|
367
377
|
error: {
|
|
368
378
|
message: "revoked: The credential was revoked by the issuer",
|
|
369
379
|
errorCode: "revoked"
|
|
370
|
-
}
|
|
380
|
+
},
|
|
381
|
+
log: [
|
|
382
|
+
...partialSingleResult.log ?? [],
|
|
383
|
+
{
|
|
384
|
+
id: "revocation_status",
|
|
385
|
+
valid: false
|
|
386
|
+
}
|
|
387
|
+
]
|
|
388
|
+
};
|
|
389
|
+
verificationResult = {
|
|
390
|
+
...verificationResult,
|
|
391
|
+
verified: false,
|
|
392
|
+
error: result.error,
|
|
393
|
+
results: [
|
|
394
|
+
result
|
|
395
|
+
]
|
|
371
396
|
};
|
|
372
397
|
}
|
|
373
398
|
return verificationResult;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/message-handler.ts","../src/vcdmCredentialPlugin.ts","../src/functions.ts","../src/index.ts"],"sourcesContent":["import type { IAgentContext, ICredentialVerifier, IResolver, VerifiableCredential, VerifiablePresentation } 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, // @ts-ignore\n} from '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,\n ICredentialStatusVerifier,\n IDIDManager,\n IIdentifier,\n IResolver,\n IssuerType,\n PresentationPayload,\n VerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation,\n} from '@veramo/core'\nimport { _ExtendedIKey, isDefined, processEntryToArray } from '@veramo/utils'\nimport { decodeJWT } from 'did-jwt'\nimport {\n addVcdmContextIfNeeded,\n isVcdm1Credential,\n isVcdm2Credential,\n VCDM_CREDENTIAL_CONTEXT_V1,\n VCDM_CREDENTIAL_CONTEXT_V2,\n} from '@sphereon/ssi-types'\nimport { ICreateVerifiablePresentationLDArgs } from './types'\nimport { getKey } from '@sphereon/ssi-sdk-ext.did-utils'\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?: W3CVerifiableCredential | W3CVerifiablePresentation | CredentialPayload | PresentationPayload | 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 * 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\nexport async function pickSigningKey(\n { identifier, kmsKeyRef }: { identifier: IIdentifier; kmsKeyRef?: string },\n context: IAgentContext<IResolver & IDIDManager>,\n): Promise<_ExtendedIKey> {\n const key = await getKey({ identifier, vmRelationship: 'assertionMethod', kmsKeyRef: kmsKeyRef }, context)\n return key\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\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 let expirationDate = credential?.validUntil ?? credential?.expirationDate\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 ...(isVdcm1 && expirationDate && { expirationDate }),\n ...(isVdcm2 && { validFrom: issuanceDate }),\n ...(isVdcm2 && expirationDate && { validUntil: expirationDate }),\n }\n if (isVdcm1) {\n delete credentialPayload.validFrom\n delete credentialPayload.validUntil\n } else if (isVdcm2) {\n delete credentialPayload.issuanceDate\n delete credentialPayload.expirationDate\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\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(\n args?.presentation?.['@context'] ?? [],\n v2Credential ?? v1Credential ?? VCDM_CREDENTIAL_CONTEXT_V2,\n )\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","/**\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"],"mappings":";;;;AACA,SAASA,8BAAuC;AAChD,SAASC,SAASC,kBAAkBC,0BAA0BC,qBAAqB;AAEnF,SACEC,qBACAC,uBACAC,8BACAC,sCACK;AAEP,SAASC,MAAMC,cAAc;AAC7B,OAAOC,WAAW;AAElB,IAAMC,QAAQC,MAAM,+BAAA;AAOb,IAAMC,eAAe;;EAE1BC,IAAI;;EAEJC,IAAI;AACN;AAsBO,IAAMC,oBAAN,cAAgCC,uBAAAA;EA/CvC,OA+CuCA;;;EACrC,MAAMC,OAAOC,SAAkBC,SAAqC;AAClE,UAAMC,OAAOF,QAAQG,gBAAe;AAKpC,QAAID,MAAME,SAAS,SAASJ,QAAQK,KAAK;AACvC,YAAM,EAAEC,KAAI,IAAKN;AAEjB,UAAI;AACFO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AAIoC;AAEJ,mBAAeC,0BAA0BvD,SAAkC;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;;;AElJA,IAAMC,mBAAmBC;","names":["AbstractMessageHandler","asArray","computeEntryHash","decodeCredentialToObject","extractIssuer","normalizeCredential","normalizePresentation","validateJwtCredentialPayload","validateJwtPresentationPayload","v4","uuidv4","Debug","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","schema","Debug","isDefined","processEntryToArray","decodeJWT","addVcdmContextIfNeeded","isVcdm1Credential","isVcdm2Credential","VCDM_CREDENTIAL_CONTEXT_V1","VCDM_CREDENTIAL_CONTEXT_V2","getKey","extractIssuer","input","options","isDefined","payload","decodeJWT","split","iss","removeParameters","removeDIDParameters","e","issuer","holder","id","did","replace","pickSigningKey","identifier","kmsKeyRef","context","key","getKey","vmRelationship","isRevoked","credential","credentialStatus","agent","checkCredentialStatus","status","revoked","verified","Error","preProcessCredentialPayload","now","Date","credentialContext","addVcdmContextIfNeeded","isVdcm1","isVcdm1Credential","isVdcm2","isVcdm2Credential","credentialType","processEntryToArray","type","issuanceDate","validFrom","toISOString","expirationDate","validUntil","credentialPayload","preProcessPresentation","args","presentation","credentials","verifiableCredential","v1Credential","find","cred","includes","VCDM_CREDENTIAL_CONTEXT_V1","undefined","v2Credential","VCDM_CREDENTIAL_CONTEXT_V2","presentationContext","presentationType","presentationPayload","map","proof","jwt","asArray","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"]}
|
|
1
|
+
{"version":3,"sources":["../src/message-handler.ts","../src/vcdmCredentialPlugin.ts","../src/functions.ts","../src/index.ts"],"sourcesContent":["import type { IAgentContext, ICredentialVerifier, IResolver, VerifiableCredential, VerifiablePresentation } 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, // @ts-ignore\n} from '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 { asArray, type VerifiableCredentialSP, type VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'\nimport {\n CredentialMapper,\n IVerifyResult,\n IVerifySingleResultItem,\n OriginalVerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation\n} from '@sphereon/ssi-types'\nimport type { IAgentPlugin, IIdentifier, VerifiableCredential } from '@veramo/core'\nimport { schema } from '@veramo/core'\nimport Debug from 'debug'\nimport { isRevoked, preProcessCredentialPayload, preProcessPresentation } from './functions'\n\nimport type {\n ICreateVerifiableCredentialLDArgs,\n ICreateVerifiablePresentationLDArgs,\n IVcdmCredentialPlugin,\n IVcdmCredentialProvider,\n IVcdmIssuerAgentContext,\n IVcdmVerifierAgentContext,\n IVerifyCredentialVcdmArgs,\n IVerifyPresentationLDArgs\n} from './types'\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\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: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { credential, policies /*, ...otherOptions*/ } = args\n let verifiedCredential: VerifiableCredential\n let verificationResult: IVerifyResult\n\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 const uniform = CredentialMapper.toUniformCredential(args.credential as OriginalVerifiableCredential)\n return Promise.reject(\n Error(\n `invalid_setup: No verifier found for the provided credential credential\n type: ${JSON.stringify(uniform.type)} proof type \n ${asArray(uniform.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`\n )\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 const results = verificationResult.results\n const partialSingleResult: Partial<IVerifySingleResultItem> = (Array.isArray(results) ? results[0] : {\n credential: credential as OriginalVerifiableCredential,\n verified: false,\n log: []\n })\n const result: IVerifySingleResultItem = {\n ...partialSingleResult,\n credential: credential as OriginalVerifiableCredential,\n verified: false,\n error: {\n message: 'revoked: The credential was revoked by the issuer',\n errorCode: 'revoked'\n },\n log: [...partialSingleResult.log ?? [], { id: 'revocation_status', valid: false }]\n }\n verificationResult = {\n ...verificationResult,\n verified: false,\n error: result.error,\n results: [\n result\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\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\n const result = await findAndVerifyPresentation(this.issuers)\n return result\n }\n}\n","import type {\n CredentialPayload,\n IAgentContext,\n ICredentialStatusVerifier,\n IDIDManager,\n IIdentifier,\n IResolver,\n IssuerType,\n PresentationPayload,\n VerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation,\n} from '@veramo/core'\nimport { _ExtendedIKey, isDefined, processEntryToArray } from '@veramo/utils'\nimport { decodeJWT } from 'did-jwt'\nimport {\n addVcdmContextIfNeeded,\n isVcdm1Credential,\n isVcdm2Credential,\n VCDM_CREDENTIAL_CONTEXT_V1,\n VCDM_CREDENTIAL_CONTEXT_V2,\n} from '@sphereon/ssi-types'\nimport { ICreateVerifiablePresentationLDArgs } from './types'\nimport { getKey } from '@sphereon/ssi-sdk-ext.did-utils'\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?: W3CVerifiableCredential | W3CVerifiablePresentation | CredentialPayload | PresentationPayload | 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 * 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\nexport async function pickSigningKey(\n { identifier, kmsKeyRef }: { identifier: IIdentifier; kmsKeyRef?: string },\n context: IAgentContext<IResolver & IDIDManager>,\n): Promise<_ExtendedIKey> {\n const key = await getKey({ identifier, vmRelationship: 'assertionMethod', kmsKeyRef: kmsKeyRef }, context)\n return key\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\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 let expirationDate = credential?.validUntil ?? credential?.expirationDate\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 ...(isVdcm1 && expirationDate && { expirationDate }),\n ...(isVdcm2 && { validFrom: issuanceDate }),\n ...(isVdcm2 && expirationDate && { validUntil: expirationDate }),\n }\n if (isVdcm1) {\n delete credentialPayload.validFrom\n delete credentialPayload.validUntil\n } else if (isVdcm2) {\n delete credentialPayload.issuanceDate\n delete credentialPayload.expirationDate\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\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(\n args?.presentation?.['@context'] ?? [],\n v2Credential ?? v1Credential ?? VCDM_CREDENTIAL_CONTEXT_V2,\n )\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","/**\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"],"mappings":";;;;AACA,SAASA,8BAAuC;AAChD,SAASC,SAASC,kBAAkBC,0BAA0BC,qBAAqB;AAEnF,SACEC,qBACAC,uBACAC,8BACAC,sCACK;AAEP,SAASC,MAAMC,cAAc;AAC7B,OAAOC,WAAW;AAElB,IAAMC,QAAQC,MAAM,+BAAA;AAOb,IAAMC,eAAe;;EAE1BC,IAAI;;EAEJC,IAAI;AACN;AAsBO,IAAMC,oBAAN,cAAgCC,uBAAAA;EA/CvC,OA+CuCA;;;EACrC,MAAMC,OAAOC,SAAkBC,SAAqC;AAClE,UAAMC,OAAOF,QAAQG,gBAAe;AAKpC,QAAID,MAAME,SAAS,SAASJ,QAAQK,KAAK;AACvC,YAAM,EAAEC,KAAI,IAAKN;AAEjB,UAAI;AACFO,uCAA+BD,IAAAA;AAG/Bd,cAAM,UAAUE,aAAaE,EAAE;AAC/B,cAAMY,eAAeC,sBAAsBT,QAAQK,GAAG;AACtD,cAAMK,cAAcF,aAAaG;AAEjCX,gBAAQY,KAAKC,iBAAiBb,QAAQK,GAAG;AACzCL,gBAAQI,OAAOV,aAAaE;AAC5BI,gBAAQc,OAAON,aAAaO;AAC5Bf,gBAAQgB,KAAKR,aAAaS,WAAW,CAAA;AAErC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,UAAM,EAAES,YAAW,IAAKD;AACxB,UAAM,EAAE6C,aAAY,IAAKC,uBAAuB9C,IAAAA;AAEhD,QAAI+C;AAEJ,mBAAeC,0BAA0BlE,SAAkC;AACzE,iBAAWc,UAAUd,SAAS;AAC5B,YAAIc,OAAOc,uBAAuB;UAAET;QAAY,CAAA,GAAI;AAClD,iBAAO,MAAML,OAAOP,6BAA6B;YAAE,GAAGW;YAAM6C;UAAa,GAAGrD,OAAAA;QAC9E;MACF;AACA,YAAM,IAAIgB,MACR,kEAAkEP,WAAAA,gBAA2BnB,QAAQ6B,IAAI,CAACC,MAAMA,EAAEb,mBAAkB,CAAA,EAAIc,KAAK,GAAA,CAAA,EAAM;IAEvJ;AATemC;AAWfD,6BAAyB,MAAMC,0BAA0B,KAAKlE,OAAO;AACrE,WAAOiE;EACT;;EAGA,MAAMzD,mBAAmBU,MAAiCR,SAA4D;AACpH,QAAI;MAAEqD;;IAAgF,IAAO7C;AAE7F,mBAAeiD,0BAA0BnE,SAAkC;AACzE,iBAAWc,UAAUd,SAAS;AAC5B,YAAIc,OAAO0B,sBAAsB;UAAEC,UAAUsB;QAA0C,CAAA,GAAI;AACzF,iBAAOjD,OAAON,mBAAmBU,MAAMR,OAAAA;QACzC;MACF;AACA,YAAM,IAAIgB,MAAM,gEAAA;IAClB;AAPeyC;AASf,UAAMT,SAAS,MAAMS,0BAA0B,KAAKnE,OAAO;AAC3D,WAAO0D;EACT;AACF;;;AElLA,IAAMU,mBAAmBC;","names":["AbstractMessageHandler","asArray","computeEntryHash","decodeCredentialToObject","extractIssuer","normalizeCredential","normalizePresentation","validateJwtCredentialPayload","validateJwtPresentationPayload","v4","uuidv4","Debug","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","asArray","CredentialMapper","schema","Debug","isDefined","processEntryToArray","decodeJWT","addVcdmContextIfNeeded","isVcdm1Credential","isVcdm2Credential","VCDM_CREDENTIAL_CONTEXT_V1","VCDM_CREDENTIAL_CONTEXT_V2","getKey","extractIssuer","input","options","isDefined","payload","decodeJWT","split","iss","removeParameters","removeDIDParameters","e","issuer","holder","id","did","replace","pickSigningKey","identifier","kmsKeyRef","context","key","getKey","vmRelationship","isRevoked","credential","credentialStatus","agent","checkCredentialStatus","status","revoked","verified","Error","preProcessCredentialPayload","now","Date","credentialContext","addVcdmContextIfNeeded","isVdcm1","isVcdm1Credential","isVdcm2","isVcdm2Credential","credentialType","processEntryToArray","type","issuanceDate","validFrom","toISOString","expirationDate","validUntil","credentialPayload","preProcessPresentation","args","presentation","credentials","verifiableCredential","v1Credential","find","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","findAndVerifyCredential","canVerifyDocumentType","document","uniform","CredentialMapper","toUniformCredential","JSON","stringify","type","asArray","proof","credentialStatus","isRevoked","results","partialSingleResult","Array","isArray","verified","log","result","message","errorCode","id","valid","presentation","preProcessPresentation","verifiablePresentation","findAndCreatePresentation","findAndVerifyPresentation","CredentialIssuer","VcdmCredentialPlugin"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.credential-vcdm",
|
|
3
3
|
"description": "Plugin for working with W3C Verifiable Credentials DataModel 1 and 2 Credentials & Presentations.",
|
|
4
|
-
"version": "0.33.1-next.
|
|
4
|
+
"version": "0.33.1-next.73+be17b2cb",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@sphereon/ssi-sdk-ext.did-utils": "workspace:*",
|
|
32
32
|
"@sphereon/ssi-sdk-ext.key-utils": "workspace:*",
|
|
33
|
-
"@sphereon/ssi-sdk.agent-config": "0.33.1-next.
|
|
34
|
-
"@sphereon/ssi-sdk.core": "0.33.1-next.
|
|
35
|
-
"@sphereon/ssi-sdk.vc-status-list": "0.33.1-next.
|
|
36
|
-
"@sphereon/ssi-types": "0.33.1-next.
|
|
33
|
+
"@sphereon/ssi-sdk.agent-config": "0.33.1-next.73+be17b2cb",
|
|
34
|
+
"@sphereon/ssi-sdk.core": "0.33.1-next.73+be17b2cb",
|
|
35
|
+
"@sphereon/ssi-sdk.vc-status-list": "0.33.1-next.73+be17b2cb",
|
|
36
|
+
"@sphereon/ssi-types": "0.33.1-next.73+be17b2cb",
|
|
37
37
|
"@veramo/core": "4.2.0",
|
|
38
38
|
"@veramo/message-handler": "4.2.0",
|
|
39
39
|
"@veramo/utils": "4.2.0",
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"node_modules",
|
|
92
92
|
"src"
|
|
93
93
|
],
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "be17b2cb752a6e5368119259e89a1f2a99f56848"
|
|
95
95
|
}
|
package/src/types.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type {
|
|
|
6
6
|
IKeyManager,
|
|
7
7
|
IPluginMethodMap,
|
|
8
8
|
IResolver,
|
|
9
|
-
IVerifyResult,
|
|
10
9
|
PresentationPayload,
|
|
11
10
|
VerificationPolicies,
|
|
12
11
|
} from '@veramo/core'
|
|
@@ -14,7 +13,13 @@ import type {
|
|
|
14
13
|
import type { VerifiableCredentialSP, VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'
|
|
15
14
|
|
|
16
15
|
import type { IIssueCredentialStatusOpts } from '@sphereon/ssi-sdk.vc-status-list'
|
|
17
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
ICredential,
|
|
18
|
+
IVerifyResult,
|
|
19
|
+
OriginalVerifiableCredential,
|
|
20
|
+
W3CVerifiableCredential,
|
|
21
|
+
W3CVerifiablePresentation
|
|
22
|
+
} from '@sphereon/ssi-types'
|
|
18
23
|
|
|
19
24
|
export type IVcdmCredentialPlugin = IVcdmCredentialIssuer & IVcdmCredentialVerifier
|
|
20
25
|
|
|
@@ -168,7 +173,7 @@ export interface ICreateVerifiableCredentialLDArgs {
|
|
|
168
173
|
*
|
|
169
174
|
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
170
175
|
*/
|
|
171
|
-
export interface
|
|
176
|
+
export interface IVerifyCredentialVcdmArgs {
|
|
172
177
|
/**
|
|
173
178
|
* The json payload of the Credential according to the
|
|
174
179
|
* {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model}
|
|
@@ -177,7 +182,7 @@ export interface IVerifyCredentialLDArgs {
|
|
|
177
182
|
* of the `credential`
|
|
178
183
|
*
|
|
179
184
|
*/
|
|
180
|
-
credential:
|
|
185
|
+
credential: OriginalVerifiableCredential | ICredential
|
|
181
186
|
|
|
182
187
|
/**
|
|
183
188
|
* Set this to true if you want the '@context' URLs to be fetched in case they are not pre-loaded.
|
|
@@ -418,7 +423,7 @@ export interface IVcdmCredentialProvider {
|
|
|
418
423
|
*
|
|
419
424
|
* @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model}
|
|
420
425
|
*/
|
|
421
|
-
verifyCredential(args:
|
|
426
|
+
verifyCredential(args: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult>
|
|
422
427
|
|
|
423
428
|
/**
|
|
424
429
|
*
|
|
@@ -502,7 +507,7 @@ export interface IVcdmCredentialVerifier extends IPluginMethodMap {
|
|
|
502
507
|
*
|
|
503
508
|
* @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model}
|
|
504
509
|
*/
|
|
505
|
-
verifyCredential(args:
|
|
510
|
+
verifyCredential(args: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult>
|
|
506
511
|
|
|
507
512
|
/**
|
|
508
513
|
* Verifies a Verifiable Presentation JWT or LDS Format.
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { asArray, type VerifiableCredentialSP, type VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'
|
|
2
|
+
import {
|
|
3
|
+
CredentialMapper,
|
|
4
|
+
IVerifyResult,
|
|
5
|
+
IVerifySingleResultItem,
|
|
6
|
+
OriginalVerifiableCredential,
|
|
7
|
+
W3CVerifiableCredential,
|
|
8
|
+
W3CVerifiablePresentation
|
|
9
|
+
} from '@sphereon/ssi-types'
|
|
10
|
+
import type { IAgentPlugin, IIdentifier, VerifiableCredential } from '@veramo/core'
|
|
2
11
|
import { schema } from '@veramo/core'
|
|
12
|
+
import Debug from 'debug'
|
|
13
|
+
import { isRevoked, preProcessCredentialPayload, preProcessPresentation } from './functions'
|
|
3
14
|
|
|
4
15
|
import type {
|
|
5
16
|
ICreateVerifiableCredentialLDArgs,
|
|
@@ -8,13 +19,9 @@ import type {
|
|
|
8
19
|
IVcdmCredentialProvider,
|
|
9
20
|
IVcdmIssuerAgentContext,
|
|
10
21
|
IVcdmVerifierAgentContext,
|
|
11
|
-
|
|
12
|
-
IVerifyPresentationLDArgs
|
|
22
|
+
IVerifyCredentialVcdmArgs,
|
|
23
|
+
IVerifyPresentationLDArgs
|
|
13
24
|
} from './types'
|
|
14
|
-
import Debug from 'debug'
|
|
15
|
-
import { isRevoked, preProcessCredentialPayload, preProcessPresentation } from './functions'
|
|
16
|
-
import type { W3CVerifiableCredential, W3CVerifiablePresentation } from '@sphereon/ssi-types'
|
|
17
|
-
import { asArray, VerifiableCredentialSP, VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'
|
|
18
25
|
|
|
19
26
|
const debug = Debug('sphereon:ssi-sdk:vcdm')
|
|
20
27
|
|
|
@@ -29,13 +36,13 @@ export class VcdmCredentialPlugin implements IAgentPlugin {
|
|
|
29
36
|
components: {
|
|
30
37
|
schemas: {
|
|
31
38
|
...schema.ICredentialIssuer.components.schemas,
|
|
32
|
-
...schema.ICredentialVerifier.components.schemas
|
|
39
|
+
...schema.ICredentialVerifier.components.schemas
|
|
33
40
|
},
|
|
34
41
|
methods: {
|
|
35
42
|
...schema.ICredentialIssuer.components.methods,
|
|
36
|
-
...schema.ICredentialVerifier.components.methods
|
|
37
|
-
}
|
|
38
|
-
}
|
|
43
|
+
...schema.ICredentialVerifier.components.methods
|
|
44
|
+
}
|
|
45
|
+
}
|
|
39
46
|
}
|
|
40
47
|
private issuers: IVcdmCredentialProvider[]
|
|
41
48
|
|
|
@@ -46,7 +53,7 @@ export class VcdmCredentialPlugin implements IAgentPlugin {
|
|
|
46
53
|
createVerifiableCredential: this.createVerifiableCredential.bind(this),
|
|
47
54
|
verifyCredential: this.verifyCredential.bind(this),
|
|
48
55
|
createVerifiablePresentation: this.createVerifiablePresentation.bind(this),
|
|
49
|
-
verifyPresentation: this.verifyPresentation.bind(this)
|
|
56
|
+
verifyPresentation: this.verifyPresentation.bind(this)
|
|
50
57
|
}
|
|
51
58
|
}
|
|
52
59
|
|
|
@@ -81,9 +88,10 @@ export class VcdmCredentialPlugin implements IAgentPlugin {
|
|
|
81
88
|
}
|
|
82
89
|
}
|
|
83
90
|
throw new Error(
|
|
84
|
-
`invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}
|
|
91
|
+
`invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`
|
|
85
92
|
)
|
|
86
93
|
}
|
|
94
|
+
|
|
87
95
|
const verifiableCredential = await findAndIssueCredential(this.issuers)
|
|
88
96
|
return verifiableCredential
|
|
89
97
|
} catch (error) {
|
|
@@ -93,10 +101,11 @@ export class VcdmCredentialPlugin implements IAgentPlugin {
|
|
|
93
101
|
}
|
|
94
102
|
|
|
95
103
|
/** {@inheritdoc @veramo/core#ICredentialVerifier.verifyCredential} */
|
|
96
|
-
async verifyCredential(args:
|
|
104
|
+
async verifyCredential(args: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {
|
|
97
105
|
let { credential, policies /*, ...otherOptions*/ } = args
|
|
98
106
|
let verifiedCredential: VerifiableCredential
|
|
99
|
-
let verificationResult: IVerifyResult
|
|
107
|
+
let verificationResult: IVerifyResult
|
|
108
|
+
|
|
100
109
|
|
|
101
110
|
async function findAndVerifyCredential(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {
|
|
102
111
|
for (const issuer of issuers) {
|
|
@@ -104,22 +113,43 @@ export class VcdmCredentialPlugin implements IAgentPlugin {
|
|
|
104
113
|
return issuer.verifyCredential(args, context)
|
|
105
114
|
}
|
|
106
115
|
}
|
|
116
|
+
const uniform = CredentialMapper.toUniformCredential(args.credential as OriginalVerifiableCredential)
|
|
107
117
|
return Promise.reject(
|
|
108
118
|
Error(
|
|
109
|
-
`invalid_setup: No verifier found for the provided credential credential
|
|
110
|
-
|
|
119
|
+
`invalid_setup: No verifier found for the provided credential credential
|
|
120
|
+
type: ${JSON.stringify(uniform.type)} proof type
|
|
121
|
+
${asArray(uniform.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`
|
|
122
|
+
)
|
|
111
123
|
)
|
|
112
124
|
}
|
|
125
|
+
|
|
113
126
|
verificationResult = await findAndVerifyCredential(this.issuers)
|
|
114
127
|
verifiedCredential = <VerifiableCredential>credential
|
|
115
128
|
|
|
116
129
|
if (policies?.credentialStatus !== false && (await isRevoked(verifiedCredential, context as any))) {
|
|
117
|
-
|
|
130
|
+
const results = verificationResult.results
|
|
131
|
+
const partialSingleResult: Partial<IVerifySingleResultItem> = (Array.isArray(results) ? results[0] : {
|
|
132
|
+
credential: credential as OriginalVerifiableCredential,
|
|
133
|
+
verified: false,
|
|
134
|
+
log: []
|
|
135
|
+
})
|
|
136
|
+
const result: IVerifySingleResultItem = {
|
|
137
|
+
...partialSingleResult,
|
|
138
|
+
credential: credential as OriginalVerifiableCredential,
|
|
118
139
|
verified: false,
|
|
119
140
|
error: {
|
|
120
141
|
message: 'revoked: The credential was revoked by the issuer',
|
|
121
|
-
errorCode: 'revoked'
|
|
142
|
+
errorCode: 'revoked'
|
|
122
143
|
},
|
|
144
|
+
log: [...partialSingleResult.log ?? [], { id: 'revocation_status', valid: false }]
|
|
145
|
+
}
|
|
146
|
+
verificationResult = {
|
|
147
|
+
...verificationResult,
|
|
148
|
+
verified: false,
|
|
149
|
+
error: result.error,
|
|
150
|
+
results: [
|
|
151
|
+
result
|
|
152
|
+
]
|
|
123
153
|
}
|
|
124
154
|
}
|
|
125
155
|
|
|
@@ -140,7 +170,7 @@ export class VcdmCredentialPlugin implements IAgentPlugin {
|
|
|
140
170
|
}
|
|
141
171
|
}
|
|
142
172
|
throw new Error(
|
|
143
|
-
`invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}
|
|
173
|
+
`invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`
|
|
144
174
|
)
|
|
145
175
|
}
|
|
146
176
|
|
|
@@ -151,6 +181,7 @@ export class VcdmCredentialPlugin implements IAgentPlugin {
|
|
|
151
181
|
/** {@inheritdoc @veramo/core#ICredentialVerifier.verifyPresentation} */
|
|
152
182
|
async verifyPresentation(args: IVerifyPresentationLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {
|
|
153
183
|
let { presentation /*domain, challenge, fetchRemoteContexts, policies, ...otherOptions*/ } = args
|
|
184
|
+
|
|
154
185
|
async function findAndVerifyPresentation(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {
|
|
155
186
|
for (const issuer of issuers) {
|
|
156
187
|
if (issuer.canVerifyDocumentType({ document: presentation as W3CVerifiablePresentation })) {
|
|
@@ -159,6 +190,7 @@ export class VcdmCredentialPlugin implements IAgentPlugin {
|
|
|
159
190
|
}
|
|
160
191
|
throw new Error('invalid_setup: No verifier found for the provided presentation')
|
|
161
192
|
}
|
|
193
|
+
|
|
162
194
|
const result = await findAndVerifyPresentation(this.issuers)
|
|
163
195
|
return result
|
|
164
196
|
}
|