@sphereon/ssi-sdk.credential-vcdm 0.33.1-feature.jose.vcdm.57 → 0.33.1-feature.jose.vcdm.59

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 CHANGED
@@ -162,6 +162,7 @@ var import_debug2 = __toESM(require("debug"), 1);
162
162
  var import_utils2 = require("@veramo/utils");
163
163
  var import_did_jwt = require("did-jwt");
164
164
  var import_ssi_types = require("@sphereon/ssi-types");
165
+ var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.did-utils");
165
166
  function extractIssuer2(input, options = {}) {
166
167
  if (!(0, import_utils2.isDefined)(input)) {
167
168
  return "";
@@ -191,15 +192,12 @@ function removeDIDParameters(did) {
191
192
  return did.replace(/\?.*$/, "");
192
193
  }
193
194
  __name(removeDIDParameters, "removeDIDParameters");
194
- function pickSigningKey(identifier, keyRef) {
195
- let key;
196
- if (!keyRef) {
197
- key = identifier.keys.find((k) => k.type === "Secp256k1" || k.type === "Ed25519" || k.type === "Secp256r1");
198
- if (!key) throw Error("key_not_found: No signing key for " + identifier.did);
199
- } else {
200
- key = identifier.keys.find((k) => k.kid === keyRef);
201
- if (!key) throw Error("key_not_found: No signing key for " + identifier.did + " with kid " + keyRef);
202
- }
195
+ async function pickSigningKey({ identifier, kmsKeyRef }, context) {
196
+ const key = await (0, import_ssi_sdk_ext.getKey)({
197
+ identifier,
198
+ vmRelationship: "assertionMethod",
199
+ kmsKeyRef
200
+ }, context);
203
201
  return key;
204
202
  }
205
203
  __name(pickSigningKey, "pickSigningKey");
@@ -220,6 +218,7 @@ function preProcessCredentialPayload({ credential, now = /* @__PURE__ */ new Dat
220
218
  const isVdcm2 = (0, import_ssi_types.isVcdm2Credential)(credential);
221
219
  const credentialType = (0, import_utils2.processEntryToArray)(credential?.type, "VerifiableCredential");
222
220
  let issuanceDate = credential?.validFrom ?? credential?.issuanceDate ?? (typeof now === "number" ? new Date(now) : now).toISOString();
221
+ let expirationDate = credential?.validUntil ?? credential?.expirationDate;
223
222
  if (issuanceDate instanceof Date) {
224
223
  issuanceDate = issuanceDate.toISOString();
225
224
  }
@@ -230,10 +229,23 @@ function preProcessCredentialPayload({ credential, now = /* @__PURE__ */ new Dat
230
229
  ...isVdcm1 && {
231
230
  issuanceDate
232
231
  },
232
+ ...isVdcm1 && expirationDate && {
233
+ expirationDate
234
+ },
233
235
  ...isVdcm2 && {
234
236
  validFrom: issuanceDate
237
+ },
238
+ ...isVdcm2 && expirationDate && {
239
+ validUntil: expirationDate
235
240
  }
236
241
  };
242
+ if (isVdcm1) {
243
+ delete credentialPayload.validFrom;
244
+ delete credentialPayload.validUntil;
245
+ } else if (isVdcm2) {
246
+ delete credentialPayload.issuanceDate;
247
+ delete credentialPayload.expirationDate;
248
+ }
237
249
  const issuer = extractIssuer2(credentialPayload, {
238
250
  removeParameters: true
239
251
  });
@@ -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 {\n IAgentContext,\n ICredentialVerifier,\n IResolver,\n VerifiableCredential,\n VerifiablePresentation,\n} from '@veramo/core'\nimport { AbstractMessageHandler, Message } from '@veramo/message-handler'\nimport { asArray, computeEntryHash, decodeCredentialToObject, extractIssuer } from '@veramo/utils'\n\nimport {\n normalizeCredential,\n normalizePresentation,\n validateJwtCredentialPayload,\n validateJwtPresentationPayload,\n}// @ts-ignore\nfrom 'did-jwt-vc'\n\nimport { v4 as uuidv4 } from 'uuid'\nimport Debug from 'debug'\n\nconst debug = Debug('sphereon:vcdm:message-handler')\n\n/**\n * These types are used by `@veramo/data-store` when storing Verifiable Credentials and Presentations\n *\n * @internal\n */\nexport const MessageTypes = {\n /** Represents a Verifiable Credential */\n vc: 'w3c.vc',\n /** Represents a Verifiable Presentation */\n vp: 'w3c.vp',\n}\n\n/**\n * Represents the requirements that this plugin has.\n * The agent that is using this plugin is expected to provide these methods.\n *\n * This interface can be used for static type checks, to make sure your application is properly initialized.\n */\nexport type IContext = IAgentContext<IResolver & ICredentialVerifier>\n\n/**\n * An implementation of the {@link @veramo/message-handler#AbstractMessageHandler}.\n *\n * This plugin can handle incoming W3C Verifiable Credentials and Presentations and prepare them\n * for internal storage as {@link @veramo/message-handler#Message} types.\n *\n * The current version can only handle `JWT` encoded\n *\n * @remarks {@link @veramo/core#IDataStore | IDataStore }\n *\n * @public\n */\nexport class W3cMessageHandler extends AbstractMessageHandler {\n async handle(message: Message, context: IContext): Promise<Message> {\n const meta = message.getLastMetaData()\n\n // console.log(JSON.stringify(message, null, 2))\n\n //FIXME: messages should not be expected to be only JWT\n if (meta?.type === 'JWT' && message.raw) {\n const { data } = message\n\n try {\n validateJwtPresentationPayload(data)\n\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vp)\n const presentation = normalizePresentation(message.raw)\n const credentials = presentation.verifiableCredential\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vp\n message.from = presentation.holder\n message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = credentials\n\n return message\n } catch (e) {}\n\n try {\n validateJwtCredentialPayload(data)\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vc)\n const credential = normalizeCredential(message.raw)\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vc\n message.from = credential.issuer.id\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } catch (e) {}\n }\n\n // LDS Verification and Handling\n if (message.type === MessageTypes.vc && message.data) {\n // verify credential\n const credential = message.data as VerifiableCredential\n\n const result = await context.agent.verifyCredential({ credential })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vc\n message.from = extractIssuer(credential)\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n if (message.type === MessageTypes.vp && message.data) {\n // verify presentation\n const presentation = message.data as VerifiablePresentation\n\n // throws on error.\n const result = await context.agent.verifyPresentation({\n presentation,\n // FIXME: HARDCODED CHALLENGE VERIFICATION FOR NOW\n challenge: 'VERAMO',\n domain: 'VERAMO',\n })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vp\n message.from = presentation.holder\n // message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n // message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = asArray(presentation.verifiableCredential).map(decodeCredentialToObject)\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n return super.handle(message, context)\n }\n}\n","import type { IAgentPlugin, IIdentifier, IVerifyResult, VerifiableCredential } from '@veramo/core'\nimport { schema } from '@veramo/core'\n\nimport type {\n ICreateVerifiableCredentialLDArgs,\n ICreateVerifiablePresentationLDArgs,\n IVcdmCredentialPlugin,\n IVcdmCredentialProvider,\n IVcdmIssuerAgentContext,\n IVcdmVerifierAgentContext,\n IVerifyCredentialLDArgs,\n IVerifyPresentationLDArgs,\n} from './types'\nimport Debug from 'debug'\nimport { isRevoked, preProcessCredentialPayload, preProcessPresentation } from './functions'\nimport type { W3CVerifiableCredential, W3CVerifiablePresentation } from '@sphereon/ssi-types'\nimport { asArray, VerifiableCredentialSP, VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'\n\nconst debug = Debug('sphereon:ssi-sdk:vcdm')\n\n/**\n * A plugin that implements the {@link @sphereon/ssi-sdk.credential-vcdm#IVcdmCredentialPlugin} methods.\n *\n * @public\n */\nexport class VcdmCredentialPlugin implements IAgentPlugin {\n readonly methods: IVcdmCredentialPlugin\n readonly schema = {\n components: {\n schemas: {\n ...schema.ICredentialIssuer.components.schemas,\n ...schema.ICredentialVerifier.components.schemas,\n },\n methods: {\n ...schema.ICredentialIssuer.components.methods,\n ...schema.ICredentialVerifier.components.methods,\n },\n },\n }\n private issuers: IVcdmCredentialProvider[]\n\n constructor(options: { issuers: IVcdmCredentialProvider[] }) {\n this.issuers = options.issuers\n this.methods = {\n listUsableProofFormats: this.listUsableProofFormats.bind(this),\n createVerifiableCredential: this.createVerifiableCredential.bind(this),\n verifyCredential: this.verifyCredential.bind(this),\n createVerifiablePresentation: this.createVerifiablePresentation.bind(this),\n verifyPresentation: this.verifyPresentation.bind(this),\n }\n }\n\n async listUsableProofFormats(did: IIdentifier, context: IVcdmIssuerAgentContext): Promise<string[]> {\n const signingOptions: string[] = []\n const keys = did.keys\n for (const key of keys) {\n for (const issuer of this.issuers) {\n if (issuer.matchKeyForType(key)) {\n signingOptions.push(issuer.getTypeProofFormat())\n }\n }\n }\n return signingOptions\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiableCredential} */\n async createVerifiableCredential(args: ICreateVerifiableCredentialLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiableCredentialSP> {\n let { proofFormat /* keyRef, removeOriginalFields, now , ...otherOptions */ } = args\n const { credential, issuer, now } = preProcessCredentialPayload(args)\n\n try {\n await context.agent.didManagerGet({ did: issuer })\n } catch (e) {\n throw new Error(`invalid_argument: credential.issuer must be a DID managed by this agent. ${e}`)\n }\n try {\n async function findAndIssueCredential(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiableCredential({ ...args, credential, now }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n )\n }\n const verifiableCredential = await findAndIssueCredential(this.issuers)\n return verifiableCredential\n } catch (error) {\n debug(error)\n return Promise.reject(error)\n }\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyCredential} */\n async verifyCredential(args: IVerifyCredentialLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { credential, policies /*, ...otherOptions*/ } = args\n let verifiedCredential: VerifiableCredential\n let verificationResult: IVerifyResult | undefined = { verified: false }\n\n async function findAndVerifyCredential(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: credential as W3CVerifiableCredential })) {\n return issuer.verifyCredential(args, context)\n }\n }\n return Promise.reject(\n Error(\n `invalid_setup: No verifier found for the provided credential credential type: ${JSON.stringify(args.credential.type)} proof type ${asArray(args.credential.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n ),\n )\n }\n verificationResult = await findAndVerifyCredential(this.issuers)\n verifiedCredential = <VerifiableCredential>credential\n\n if (policies?.credentialStatus !== false && (await isRevoked(verifiedCredential, context as any))) {\n verificationResult = {\n verified: false,\n error: {\n message: 'revoked: The credential was revoked by the issuer',\n errorCode: 'revoked',\n },\n }\n }\n\n return verificationResult\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiablePresentation} */\n async createVerifiablePresentation(args: ICreateVerifiablePresentationLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiablePresentationSP> {\n const { proofFormat } = args\n const { presentation } = preProcessPresentation(args)\n\n let verifiablePresentation: VerifiablePresentationSP\n\n async function findAndCreatePresentation(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiablePresentation({ ...args, presentation }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n )\n }\n\n verifiablePresentation = await findAndCreatePresentation(this.issuers)\n return verifiablePresentation\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyPresentation} */\n async verifyPresentation(args: IVerifyPresentationLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { presentation /*domain, challenge, fetchRemoteContexts, policies, ...otherOptions*/ } = args\n async function findAndVerifyPresentation(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: presentation as W3CVerifiablePresentation })) {\n return issuer.verifyPresentation(args, context)\n }\n }\n throw new Error('invalid_setup: No verifier found for the provided presentation')\n }\n const result = await findAndVerifyPresentation(this.issuers)\n return result\n }\n}\n","import type {\n CredentialPayload,\n IAgentContext, ICredentialStatusVerifier,\n IIdentifier,\n IKey,\n IssuerType,\n PresentationPayload,\n VerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation\n} from '@veramo/core'\nimport { isDefined, processEntryToArray } from '@veramo/utils'\nimport { decodeJWT } from 'did-jwt'\nimport { addVcdmContextIfNeeded, isVcdm1Credential, isVcdm2Credential, VCDM_CREDENTIAL_CONTEXT_V1, VCDM_CREDENTIAL_CONTEXT_V2 } from '@sphereon/ssi-types'\nimport { ICreateVerifiablePresentationLDArgs } from './types'\n\n/**\n * Decodes a credential or presentation and returns the issuer ID\n * `iss` from a JWT or `issuer`/`issuer.id` from a VC or `holder` from a VP\n *\n * @param input - the credential or presentation whose issuer/holder needs to be extracted.\n * @param options - options for the extraction\n * removeParameters - Remove all DID parameters from the issuer ID\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function extractIssuer(\n input?:\n | W3CVerifiableCredential\n | W3CVerifiablePresentation\n | CredentialPayload\n | PresentationPayload\n | null,\n options: { removeParameters?: boolean } = {}\n): string {\n if (!isDefined(input)) {\n return ''\n } else if (typeof input === 'string') {\n // JWT\n try {\n const { payload } = decodeJWT(input.split(`~`)[0])\n const iss = payload.iss ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n } catch (e: any) {\n return ''\n }\n } else {\n // JSON\n let iss: IssuerType\n if (input.issuer) {\n iss = input.issuer\n } else if (input.holder) {\n iss = input.holder\n } else {\n iss = ''\n }\n if (typeof iss !== 'string') iss = iss.id ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n }\n}\n\n\n/**\n * Remove all DID parameters from a DID url after the query part (?)\n *\n * @param did - the DID URL\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function removeDIDParameters(did: string): string {\n return did.replace(/\\?.*$/, '')\n}\n\n\nexport function pickSigningKey(identifier: IIdentifier, keyRef?: string): IKey {\n let key: IKey | undefined\n\n if (!keyRef) {\n key = identifier.keys.find((k) => k.type === 'Secp256k1' || k.type === 'Ed25519' || k.type === 'Secp256r1')\n if (!key) throw Error('key_not_found: No signing key for ' + identifier.did)\n } else {\n key = identifier.keys.find((k) => k.kid === keyRef)\n if (!key) throw Error('key_not_found: No signing key for ' + identifier.did + ' with kid ' + keyRef)\n }\n\n return key as IKey\n}\n\nexport async function isRevoked(credential: VerifiableCredential, context: IAgentContext<ICredentialStatusVerifier>): Promise<boolean> {\n if (!credential.credentialStatus) return false\n\n if (typeof context.agent.checkCredentialStatus === 'function') {\n const status = await context.agent.checkCredentialStatus({ credential })\n return status?.revoked == true || status?.verified === false\n }\n\n throw new Error(`invalid_setup: The credential status can't be verified because there is no ICredentialStatusVerifier plugin installed.`)\n}\n\n\n\nexport function preProcessCredentialPayload({credential, now = new Date()}: {credential: CredentialPayload, now?: number | Date}) {\n const credentialContext = addVcdmContextIfNeeded(credential?.['@context'])\n const isVdcm1 = isVcdm1Credential(credential)\n const isVdcm2 = isVcdm2Credential(credential)\n const credentialType = processEntryToArray(credential?.type, 'VerifiableCredential')\n let issuanceDate = credential?.validFrom ?? credential?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()\n if (issuanceDate instanceof Date) {\n issuanceDate = issuanceDate.toISOString()\n }\n const credentialPayload: CredentialPayload = {\n ...credential,\n '@context': credentialContext,\n type: credentialType,\n ...(isVdcm1 && { issuanceDate }),\n ...(isVdcm2 && { validFrom: issuanceDate }),\n }\n\n // debug(JSON.stringify(credentialPayload))\n\n const issuer = extractIssuer(credentialPayload, {removeParameters: true})\n if (!issuer || typeof issuer === 'undefined') {\n throw new Error('invalid_argument: args.credential.issuer must not be empty')\n }\n return { credential: credentialPayload, issuer, now }\n}\n\n\nexport function preProcessPresentation(args: ICreateVerifiablePresentationLDArgs) {\n const { presentation, now = new Date() } = args\n const credentials = presentation?.verifiableCredential ?? []\n const v1Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V1))\n ? VCDM_CREDENTIAL_CONTEXT_V1\n : undefined\n const v2Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V2))\n ? VCDM_CREDENTIAL_CONTEXT_V2\n : undefined\n const presentationContext = addVcdmContextIfNeeded(args?.presentation?.['@context'] ?? [], v2Credential ?? v1Credential ?? VCDM_CREDENTIAL_CONTEXT_V2)\n const presentationType = processEntryToArray(args?.presentation?.type, 'VerifiablePresentation')\n\n let issuanceDate = presentation?.validFrom ?? presentation?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()\n if (issuanceDate instanceof Date) {\n issuanceDate = issuanceDate.toISOString()\n }\n const presentationPayload: PresentationPayload = {\n ...presentation,\n '@context': presentationContext,\n type: presentationType,\n ...(v1Credential && { issuanceDate }), // V1 only for JWT, but we remove it in the jsonld processor anyway\n ...(v2Credential && { validFrom: issuanceDate }),\n }\n // Workaround for bug in TypeError: Cannot read property 'length' of undefined\n // at VeramoEd25519Signature2018.preSigningPresModification\n /*if (!presentation.verifier) {\n presentation.verifier = []\n }*/\n\n if (!isDefined(presentationPayload.holder) || !presentationPayload.holder) {\n throw new Error('invalid_argument: args.presentation.holderDID must not be empty')\n }\n if (presentationPayload.verifiableCredential) {\n presentationPayload.verifiableCredential = presentationPayload.verifiableCredential.map((cred) => {\n // map JWT credentials to their canonical form\n if (typeof cred !== 'string' && cred.proof.jwt) {\n return cred.proof.jwt\n } else {\n return cred\n }\n })\n }\n return {presentation: presentationPayload, holder: removeDIDParameters(presentationPayload.holder)}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;uBAAAA;EAAA;;;;;;;;;ACOA,6BAAgD;AAChD,mBAAmF;AAEnF,wBAMK;AAEL,kBAA6B;AAC7B,mBAAkB;AAElB,IAAMC,YAAQC,aAAAA,SAAM,+BAAA;AAOb,IAAMC,eAAe;;EAE1BC,IAAI;;EAEJC,IAAI;AACN;AAsBO,IAAMC,oBAAN,cAAgCC,8CAAAA;EAhDvC,OAgDuCA;;;EACrC,MAAMC,OAAOC,SAAkBC,SAAqC;AAClE,UAAMC,OAAOF,QAAQG,gBAAe;AAKpC,QAAID,MAAME,SAAS,SAASJ,QAAQK,KAAK;AACvC,YAAM,EAAEC,KAAI,IAAKN;AAEjB,UAAI;AACFO,8DAA+BD,IAAAA;AAG/Bd,cAAM,UAAUE,aAAaE,EAAE;AAC/B,cAAMY,mBAAeC,yCAAsBT,QAAQK,GAAG;AACtD,cAAM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AE,GAAGW;YAAMkC;UAAa,GAAG1C,OAAAA;QAC9E;MACF;AACA,YAAM,IAAIgB,MACR,kEAAkEP,WAAAA,gBAA2BnB,QAAQ6B,IAAI,CAACC,MAAMA,EAAEb,mBAAkB,CAAA,EAAIc,KAAK,GAAA,CAAA,EAAM;IAEvJ;AATewB;AAWfD,6BAAyB,MAAMC,0BAA0B,KAAKvD,OAAO;AACrE,WAAOsD;EACT;;EAGA,MAAM9C,mBAAmBU,MAAiCR,SAA4D;AACpH,QAAI;MAAE0C;;IAAgF,IAAOlC;AAC7F,mBAAesC,0BAA0BxD,SAAkC;AACzE,iBAAWc,UAAUd,SAAS;AAC5B,YAAIc,OAAO2B,sBAAsB;UAAEC,UAAUU;QAA0C,CAAA,GAAI;AACzF,iBAAOtC,OAAON,mBAAmBU,MAAMR,OAAAA;QACzC;MACF;AACA,YAAM,IAAIgB,MAAM,gEAAA;IAClB;AAPe8B;AAQf,UAAMC,SAAS,MAAMD,0BAA0B,KAAKxD,OAAO;AAC3D,WAAOyD;EACT;AACF;;;AFlJA,IAAMC,mBAAmBC;","names":["extractIssuer","debug","Debug","MessageTypes","vc","vp","W3cMessageHandler","AbstractMessageHandler","handle","message","context","meta","getLastMetaData","type","raw","data","validateJwtPresentationPayload","presentation","normalizePresentation","credentials","verifiableCredential","id","computeEntryHash","from","holder","to","verifier","tag","threadId","createdAt","issuanceDate","presentations","e","validateJwtCredentialPayload","credential","normalizeCredential","issuer","credentialSubject","result","agent","verifyCredential","verified","uuidv4","extractIssuer","Error","error","verifyPresentation","challenge","domain","asArray","map","decodeCredentialToObject","import_debug","import_utils","extractIssuer","input","options","isDefined","payload","decodeJWT","split","iss","removeParameters","removeDIDParameters","e","issuer","holder","id","did","replace","pickSigningKey","identifier","keyRef","key","keys","find","k","type","Error","kid","isRevoked","credential","context","credentialStatus","agent","checkCredentialStatus","status","revoked","verified","preProcessCredentialPayload","now","Date","credentialContext","addVcdmContextIfNeeded","isVdcm1","isVcdm1Credential","isVdcm2","isVcdm2Credential","credentialType","processEntryToArray","issuanceDate","validFrom","toISOString","credentialPayload","preProcessPresentation","args","presentation","credentials","verifiableCredential","v1Credential","cred","includes","VCDM_CREDENTIAL_CONTEXT_V1","undefined","v2Credential","VCDM_CREDENTIAL_CONTEXT_V2","presentationContext","presentationType","presentationPayload","map","proof","jwt","debug","Debug","VcdmCredentialPlugin","methods","schema","components","schemas","ICredentialIssuer","ICredentialVerifier","issuers","constructor","options","listUsableProofFormats","bind","createVerifiableCredential","verifyCredential","createVerifiablePresentation","verifyPresentation","did","context","signingOptions","keys","key","issuer","matchKeyForType","push","getTypeProofFormat","args","proofFormat","credential","now","preProcessCredentialPayload","agent","didManagerGet","e","Error","findAndIssueCredential","canIssueCredentialType","map","i","join","verifiableCredential","error","Promise","reject","policies","verifiedCredential","verificationResult","verified","findAndVerifyCredential","canVerifyDocumentType","document","JSON","stringify","type","asArray","proof","credentialStatus","isRevoked","message","errorCode","presentation","preProcessPresentation","verifiablePresentation","findAndCreatePresentation","findAndVerifyPresentation","result","CredentialIssuer","VcdmCredentialPlugin"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/message-handler.ts","../src/vcdmCredentialPlugin.ts","../src/functions.ts"],"sourcesContent":["/**\n * Provides a {@link @veramo/credential-w3c#CredentialPlugin | plugin} for the {@link @veramo/core#Agent} that\n * implements\n * {@link @veramo/core#ICredentialIssuer} interface.\n *\n * Provides a {@link @veramo/credential-w3c#W3cMessageHandler | plugin} for the\n * {@link @veramo/message-handler#MessageHandler} that verifies Credentials and Presentations in a message.\n *\n * @packageDocumentation\n */\nexport type * from './types'\nexport { W3cMessageHandler, MessageTypes } from './message-handler'\nimport { VcdmCredentialPlugin } from './vcdmCredentialPlugin'\n\n/**\n * @deprecated please use {@link VcdmCredentialPlugin} instead\n * @public\n */\nconst CredentialIssuer = VcdmCredentialPlugin\nexport { CredentialIssuer, VcdmCredentialPlugin }\n\n// For backward compatibility, re-export the plugin types that were moved to core in v4\nexport type { ICredentialIssuer, ICredentialVerifier } from '@veramo/core'\n\nexport * from './functions'\n","import type {\n IAgentContext,\n ICredentialVerifier,\n IResolver,\n VerifiableCredential,\n VerifiablePresentation,\n} from '@veramo/core'\nimport { AbstractMessageHandler, Message } from '@veramo/message-handler'\nimport { asArray, computeEntryHash, decodeCredentialToObject, extractIssuer } from '@veramo/utils'\n\nimport {\n normalizeCredential,\n normalizePresentation,\n validateJwtCredentialPayload,\n validateJwtPresentationPayload,\n}// @ts-ignore\nfrom 'did-jwt-vc'\n\nimport { v4 as uuidv4 } from 'uuid'\nimport Debug from 'debug'\n\nconst debug = Debug('sphereon:vcdm:message-handler')\n\n/**\n * These types are used by `@veramo/data-store` when storing Verifiable Credentials and Presentations\n *\n * @internal\n */\nexport const MessageTypes = {\n /** Represents a Verifiable Credential */\n vc: 'w3c.vc',\n /** Represents a Verifiable Presentation */\n vp: 'w3c.vp',\n}\n\n/**\n * Represents the requirements that this plugin has.\n * The agent that is using this plugin is expected to provide these methods.\n *\n * This interface can be used for static type checks, to make sure your application is properly initialized.\n */\nexport type IContext = IAgentContext<IResolver & ICredentialVerifier>\n\n/**\n * An implementation of the {@link @veramo/message-handler#AbstractMessageHandler}.\n *\n * This plugin can handle incoming W3C Verifiable Credentials and Presentations and prepare them\n * for internal storage as {@link @veramo/message-handler#Message} types.\n *\n * The current version can only handle `JWT` encoded\n *\n * @remarks {@link @veramo/core#IDataStore | IDataStore }\n *\n * @public\n */\nexport class W3cMessageHandler extends AbstractMessageHandler {\n async handle(message: Message, context: IContext): Promise<Message> {\n const meta = message.getLastMetaData()\n\n // console.log(JSON.stringify(message, null, 2))\n\n //FIXME: messages should not be expected to be only JWT\n if (meta?.type === 'JWT' && message.raw) {\n const { data } = message\n\n try {\n validateJwtPresentationPayload(data)\n\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vp)\n const presentation = normalizePresentation(message.raw)\n const credentials = presentation.verifiableCredential\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vp\n message.from = presentation.holder\n message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = credentials\n\n return message\n } catch (e) {}\n\n try {\n validateJwtCredentialPayload(data)\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vc)\n const credential = normalizeCredential(message.raw)\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vc\n message.from = credential.issuer.id\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } catch (e) {}\n }\n\n // LDS Verification and Handling\n if (message.type === MessageTypes.vc && message.data) {\n // verify credential\n const credential = message.data as VerifiableCredential\n\n const result = await context.agent.verifyCredential({ credential })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vc\n message.from = extractIssuer(credential)\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n if (message.type === MessageTypes.vp && message.data) {\n // verify presentation\n const presentation = message.data as VerifiablePresentation\n\n // throws on error.\n const result = await context.agent.verifyPresentation({\n presentation,\n // FIXME: HARDCODED CHALLENGE VERIFICATION FOR NOW\n challenge: 'VERAMO',\n domain: 'VERAMO',\n })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vp\n message.from = presentation.holder\n // message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n // message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = asArray(presentation.verifiableCredential).map(decodeCredentialToObject)\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n return super.handle(message, context)\n }\n}\n","import type { IAgentPlugin, IIdentifier, IVerifyResult, VerifiableCredential } from '@veramo/core'\nimport { schema } from '@veramo/core'\n\nimport type {\n ICreateVerifiableCredentialLDArgs,\n ICreateVerifiablePresentationLDArgs,\n IVcdmCredentialPlugin,\n IVcdmCredentialProvider,\n IVcdmIssuerAgentContext,\n IVcdmVerifierAgentContext,\n IVerifyCredentialLDArgs,\n IVerifyPresentationLDArgs,\n} from './types'\nimport Debug from 'debug'\nimport { isRevoked, preProcessCredentialPayload, preProcessPresentation } from './functions'\nimport type { W3CVerifiableCredential, W3CVerifiablePresentation } from '@sphereon/ssi-types'\nimport { asArray, VerifiableCredentialSP, VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'\n\nconst debug = Debug('sphereon:ssi-sdk:vcdm')\n\n/**\n * A plugin that implements the {@link @sphereon/ssi-sdk.credential-vcdm#IVcdmCredentialPlugin} methods.\n *\n * @public\n */\nexport class VcdmCredentialPlugin implements IAgentPlugin {\n readonly methods: IVcdmCredentialPlugin\n readonly schema = {\n components: {\n schemas: {\n ...schema.ICredentialIssuer.components.schemas,\n ...schema.ICredentialVerifier.components.schemas,\n },\n methods: {\n ...schema.ICredentialIssuer.components.methods,\n ...schema.ICredentialVerifier.components.methods,\n },\n },\n }\n private issuers: IVcdmCredentialProvider[]\n\n constructor(options: { issuers: IVcdmCredentialProvider[] }) {\n this.issuers = options.issuers\n this.methods = {\n listUsableProofFormats: this.listUsableProofFormats.bind(this),\n createVerifiableCredential: this.createVerifiableCredential.bind(this),\n verifyCredential: this.verifyCredential.bind(this),\n createVerifiablePresentation: this.createVerifiablePresentation.bind(this),\n verifyPresentation: this.verifyPresentation.bind(this),\n }\n }\n\n async listUsableProofFormats(did: IIdentifier, context: IVcdmIssuerAgentContext): Promise<string[]> {\n const signingOptions: string[] = []\n const keys = did.keys\n for (const key of keys) {\n for (const issuer of this.issuers) {\n if (issuer.matchKeyForType(key)) {\n signingOptions.push(issuer.getTypeProofFormat())\n }\n }\n }\n return signingOptions\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiableCredential} */\n async createVerifiableCredential(args: ICreateVerifiableCredentialLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiableCredentialSP> {\n let { proofFormat /* keyRef, removeOriginalFields, now , ...otherOptions */ } = args\n const { credential, issuer, now } = preProcessCredentialPayload(args)\n\n try {\n await context.agent.didManagerGet({ did: issuer })\n } catch (e) {\n throw new Error(`invalid_argument: credential.issuer must be a DID managed by this agent. ${e}`)\n }\n try {\n async function findAndIssueCredential(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiableCredential({ ...args, credential, now }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n )\n }\n const verifiableCredential = await findAndIssueCredential(this.issuers)\n return verifiableCredential\n } catch (error) {\n debug(error)\n return Promise.reject(error)\n }\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyCredential} */\n async verifyCredential(args: IVerifyCredentialLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { credential, policies /*, ...otherOptions*/ } = args\n let verifiedCredential: VerifiableCredential\n let verificationResult: IVerifyResult | undefined = { verified: false }\n\n async function findAndVerifyCredential(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: credential as W3CVerifiableCredential })) {\n return issuer.verifyCredential(args, context)\n }\n }\n return Promise.reject(\n Error(\n `invalid_setup: No verifier found for the provided credential credential type: ${JSON.stringify(args.credential.type)} proof type ${asArray(args.credential.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n ),\n )\n }\n verificationResult = await findAndVerifyCredential(this.issuers)\n verifiedCredential = <VerifiableCredential>credential\n\n if (policies?.credentialStatus !== false && (await isRevoked(verifiedCredential, context as any))) {\n verificationResult = {\n verified: false,\n error: {\n message: 'revoked: The credential was revoked by the issuer',\n errorCode: 'revoked',\n },\n }\n }\n\n return verificationResult\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiablePresentation} */\n async createVerifiablePresentation(args: ICreateVerifiablePresentationLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiablePresentationSP> {\n const { proofFormat } = args\n const { presentation } = preProcessPresentation(args)\n\n let verifiablePresentation: VerifiablePresentationSP\n\n async function findAndCreatePresentation(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiablePresentation({ ...args, presentation }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n )\n }\n\n verifiablePresentation = await findAndCreatePresentation(this.issuers)\n return verifiablePresentation\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyPresentation} */\n async verifyPresentation(args: IVerifyPresentationLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { presentation /*domain, challenge, fetchRemoteContexts, policies, ...otherOptions*/ } = args\n async function findAndVerifyPresentation(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: presentation as W3CVerifiablePresentation })) {\n return issuer.verifyPresentation(args, context)\n }\n }\n throw new Error('invalid_setup: No verifier found for the provided presentation')\n }\n const result = await findAndVerifyPresentation(this.issuers)\n return result\n }\n}\n","import type {\n CredentialPayload,\n IAgentContext,\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;;;;;;;;;ACOA,6BAAgD;AAChD,mBAAmF;AAEnF,wBAMK;AAEL,kBAA6B;AAC7B,mBAAkB;AAElB,IAAMC,YAAQC,aAAAA,SAAM,+BAAA;AAOb,IAAMC,eAAe;;EAE1BC,IAAI;;EAEJC,IAAI;AACN;AAsBO,IAAMC,oBAAN,cAAgCC,8CAAAA;EAhDvC,OAgDuCA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AOb;EACT;;EAGA,MAAM/B,6BAA6BW,MAA2CR,SAAqE;AACjJ,UAAM,EAAES,YAAW,IAAKD;AACxB,UAAM,EAAEkC,aAAY,IAAKC,uBAAuBnC,IAAAA;AAEhD,QAAIoC;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;;;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"]}
package/dist/index.d.cts CHANGED
@@ -4,6 +4,7 @@ import { VerifiablePresentationSP, VerifiableCredentialSP } from '@sphereon/ssi-
4
4
  import { IIssueCredentialStatusOpts } from '@sphereon/ssi-sdk.vc-status-list';
5
5
  import { W3CVerifiablePresentation, W3CVerifiableCredential } from '@sphereon/ssi-types';
6
6
  import { AbstractMessageHandler, Message } from '@veramo/message-handler';
7
+ import { _ExtendedIKey } from '@veramo/utils';
7
8
 
8
9
  type IVcdmCredentialPlugin = IVcdmCredentialIssuer & IVcdmCredentialVerifier;
9
10
  /**
@@ -525,7 +526,10 @@ declare function extractIssuer(input?: W3CVerifiableCredential$1 | W3CVerifiable
525
526
  * @beta This API may change without a BREAKING CHANGE notice.
526
527
  */
527
528
  declare function removeDIDParameters(did: string): string;
528
- declare function pickSigningKey(identifier: IIdentifier, keyRef?: string): IKey;
529
+ declare function pickSigningKey({ identifier, kmsKeyRef }: {
530
+ identifier: IIdentifier;
531
+ kmsKeyRef?: string;
532
+ }, context: IAgentContext<IResolver & IDIDManager>): Promise<_ExtendedIKey>;
529
533
  declare function isRevoked(credential: VerifiableCredential, context: IAgentContext<ICredentialStatusVerifier>): Promise<boolean>;
530
534
  declare function preProcessCredentialPayload({ credential, now }: {
531
535
  credential: CredentialPayload;
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import { VerifiablePresentationSP, VerifiableCredentialSP } from '@sphereon/ssi-
4
4
  import { IIssueCredentialStatusOpts } from '@sphereon/ssi-sdk.vc-status-list';
5
5
  import { W3CVerifiablePresentation, W3CVerifiableCredential } from '@sphereon/ssi-types';
6
6
  import { AbstractMessageHandler, Message } from '@veramo/message-handler';
7
+ import { _ExtendedIKey } from '@veramo/utils';
7
8
 
8
9
  type IVcdmCredentialPlugin = IVcdmCredentialIssuer & IVcdmCredentialVerifier;
9
10
  /**
@@ -525,7 +526,10 @@ declare function extractIssuer(input?: W3CVerifiableCredential$1 | W3CVerifiable
525
526
  * @beta This API may change without a BREAKING CHANGE notice.
526
527
  */
527
528
  declare function removeDIDParameters(did: string): string;
528
- declare function pickSigningKey(identifier: IIdentifier, keyRef?: string): IKey;
529
+ declare function pickSigningKey({ identifier, kmsKeyRef }: {
530
+ identifier: IIdentifier;
531
+ kmsKeyRef?: string;
532
+ }, context: IAgentContext<IResolver & IDIDManager>): Promise<_ExtendedIKey>;
529
533
  declare function isRevoked(credential: VerifiableCredential, context: IAgentContext<ICredentialStatusVerifier>): Promise<boolean>;
530
534
  declare function preProcessCredentialPayload({ credential, now }: {
531
535
  credential: CredentialPayload;
package/dist/index.js CHANGED
@@ -119,6 +119,7 @@ import Debug2 from "debug";
119
119
  import { isDefined, processEntryToArray } from "@veramo/utils";
120
120
  import { decodeJWT } from "did-jwt";
121
121
  import { addVcdmContextIfNeeded, isVcdm1Credential, isVcdm2Credential, VCDM_CREDENTIAL_CONTEXT_V1, VCDM_CREDENTIAL_CONTEXT_V2 } from "@sphereon/ssi-types";
122
+ import { getKey } from "@sphereon/ssi-sdk-ext.did-utils";
122
123
  function extractIssuer2(input, options = {}) {
123
124
  if (!isDefined(input)) {
124
125
  return "";
@@ -148,15 +149,12 @@ function removeDIDParameters(did) {
148
149
  return did.replace(/\?.*$/, "");
149
150
  }
150
151
  __name(removeDIDParameters, "removeDIDParameters");
151
- function pickSigningKey(identifier, keyRef) {
152
- let key;
153
- if (!keyRef) {
154
- key = identifier.keys.find((k) => k.type === "Secp256k1" || k.type === "Ed25519" || k.type === "Secp256r1");
155
- if (!key) throw Error("key_not_found: No signing key for " + identifier.did);
156
- } else {
157
- key = identifier.keys.find((k) => k.kid === keyRef);
158
- if (!key) throw Error("key_not_found: No signing key for " + identifier.did + " with kid " + keyRef);
159
- }
152
+ async function pickSigningKey({ identifier, kmsKeyRef }, context) {
153
+ const key = await getKey({
154
+ identifier,
155
+ vmRelationship: "assertionMethod",
156
+ kmsKeyRef
157
+ }, context);
160
158
  return key;
161
159
  }
162
160
  __name(pickSigningKey, "pickSigningKey");
@@ -177,6 +175,7 @@ function preProcessCredentialPayload({ credential, now = /* @__PURE__ */ new Dat
177
175
  const isVdcm2 = isVcdm2Credential(credential);
178
176
  const credentialType = processEntryToArray(credential?.type, "VerifiableCredential");
179
177
  let issuanceDate = credential?.validFrom ?? credential?.issuanceDate ?? (typeof now === "number" ? new Date(now) : now).toISOString();
178
+ let expirationDate = credential?.validUntil ?? credential?.expirationDate;
180
179
  if (issuanceDate instanceof Date) {
181
180
  issuanceDate = issuanceDate.toISOString();
182
181
  }
@@ -187,10 +186,23 @@ function preProcessCredentialPayload({ credential, now = /* @__PURE__ */ new Dat
187
186
  ...isVdcm1 && {
188
187
  issuanceDate
189
188
  },
189
+ ...isVdcm1 && expirationDate && {
190
+ expirationDate
191
+ },
190
192
  ...isVdcm2 && {
191
193
  validFrom: issuanceDate
194
+ },
195
+ ...isVdcm2 && expirationDate && {
196
+ validUntil: expirationDate
192
197
  }
193
198
  };
199
+ if (isVdcm1) {
200
+ delete credentialPayload.validFrom;
201
+ delete credentialPayload.validUntil;
202
+ } else if (isVdcm2) {
203
+ delete credentialPayload.issuanceDate;
204
+ delete credentialPayload.expirationDate;
205
+ }
194
206
  const issuer = extractIssuer2(credentialPayload, {
195
207
  removeParameters: true
196
208
  });
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 {\n IAgentContext,\n ICredentialVerifier,\n IResolver,\n VerifiableCredential,\n VerifiablePresentation,\n} from '@veramo/core'\nimport { AbstractMessageHandler, Message } from '@veramo/message-handler'\nimport { asArray, computeEntryHash, decodeCredentialToObject, extractIssuer } from '@veramo/utils'\n\nimport {\n normalizeCredential,\n normalizePresentation,\n validateJwtCredentialPayload,\n validateJwtPresentationPayload,\n}// @ts-ignore\nfrom 'did-jwt-vc'\n\nimport { v4 as uuidv4 } from 'uuid'\nimport Debug from 'debug'\n\nconst debug = Debug('sphereon:vcdm:message-handler')\n\n/**\n * These types are used by `@veramo/data-store` when storing Verifiable Credentials and Presentations\n *\n * @internal\n */\nexport const MessageTypes = {\n /** Represents a Verifiable Credential */\n vc: 'w3c.vc',\n /** Represents a Verifiable Presentation */\n vp: 'w3c.vp',\n}\n\n/**\n * Represents the requirements that this plugin has.\n * The agent that is using this plugin is expected to provide these methods.\n *\n * This interface can be used for static type checks, to make sure your application is properly initialized.\n */\nexport type IContext = IAgentContext<IResolver & ICredentialVerifier>\n\n/**\n * An implementation of the {@link @veramo/message-handler#AbstractMessageHandler}.\n *\n * This plugin can handle incoming W3C Verifiable Credentials and Presentations and prepare them\n * for internal storage as {@link @veramo/message-handler#Message} types.\n *\n * The current version can only handle `JWT` encoded\n *\n * @remarks {@link @veramo/core#IDataStore | IDataStore }\n *\n * @public\n */\nexport class W3cMessageHandler extends AbstractMessageHandler {\n async handle(message: Message, context: IContext): Promise<Message> {\n const meta = message.getLastMetaData()\n\n // console.log(JSON.stringify(message, null, 2))\n\n //FIXME: messages should not be expected to be only JWT\n if (meta?.type === 'JWT' && message.raw) {\n const { data } = message\n\n try {\n validateJwtPresentationPayload(data)\n\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vp)\n const presentation = normalizePresentation(message.raw)\n const credentials = presentation.verifiableCredential\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vp\n message.from = presentation.holder\n message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = credentials\n\n return message\n } catch (e) {}\n\n try {\n validateJwtCredentialPayload(data)\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vc)\n const credential = normalizeCredential(message.raw)\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vc\n message.from = credential.issuer.id\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } catch (e) {}\n }\n\n // LDS Verification and Handling\n if (message.type === MessageTypes.vc && message.data) {\n // verify credential\n const credential = message.data as VerifiableCredential\n\n const result = await context.agent.verifyCredential({ credential })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vc\n message.from = extractIssuer(credential)\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n if (message.type === MessageTypes.vp && message.data) {\n // verify presentation\n const presentation = message.data as VerifiablePresentation\n\n // throws on error.\n const result = await context.agent.verifyPresentation({\n presentation,\n // FIXME: HARDCODED CHALLENGE VERIFICATION FOR NOW\n challenge: 'VERAMO',\n domain: 'VERAMO',\n })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vp\n message.from = presentation.holder\n // message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n // message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = asArray(presentation.verifiableCredential).map(decodeCredentialToObject)\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n return super.handle(message, context)\n }\n}\n","import type { IAgentPlugin, IIdentifier, IVerifyResult, VerifiableCredential } from '@veramo/core'\nimport { schema } from '@veramo/core'\n\nimport type {\n ICreateVerifiableCredentialLDArgs,\n ICreateVerifiablePresentationLDArgs,\n IVcdmCredentialPlugin,\n IVcdmCredentialProvider,\n IVcdmIssuerAgentContext,\n IVcdmVerifierAgentContext,\n IVerifyCredentialLDArgs,\n IVerifyPresentationLDArgs,\n} from './types'\nimport Debug from 'debug'\nimport { isRevoked, preProcessCredentialPayload, preProcessPresentation } from './functions'\nimport type { W3CVerifiableCredential, W3CVerifiablePresentation } from '@sphereon/ssi-types'\nimport { asArray, VerifiableCredentialSP, VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'\n\nconst debug = Debug('sphereon:ssi-sdk:vcdm')\n\n/**\n * A plugin that implements the {@link @sphereon/ssi-sdk.credential-vcdm#IVcdmCredentialPlugin} methods.\n *\n * @public\n */\nexport class VcdmCredentialPlugin implements IAgentPlugin {\n readonly methods: IVcdmCredentialPlugin\n readonly schema = {\n components: {\n schemas: {\n ...schema.ICredentialIssuer.components.schemas,\n ...schema.ICredentialVerifier.components.schemas,\n },\n methods: {\n ...schema.ICredentialIssuer.components.methods,\n ...schema.ICredentialVerifier.components.methods,\n },\n },\n }\n private issuers: IVcdmCredentialProvider[]\n\n constructor(options: { issuers: IVcdmCredentialProvider[] }) {\n this.issuers = options.issuers\n this.methods = {\n listUsableProofFormats: this.listUsableProofFormats.bind(this),\n createVerifiableCredential: this.createVerifiableCredential.bind(this),\n verifyCredential: this.verifyCredential.bind(this),\n createVerifiablePresentation: this.createVerifiablePresentation.bind(this),\n verifyPresentation: this.verifyPresentation.bind(this),\n }\n }\n\n async listUsableProofFormats(did: IIdentifier, context: IVcdmIssuerAgentContext): Promise<string[]> {\n const signingOptions: string[] = []\n const keys = did.keys\n for (const key of keys) {\n for (const issuer of this.issuers) {\n if (issuer.matchKeyForType(key)) {\n signingOptions.push(issuer.getTypeProofFormat())\n }\n }\n }\n return signingOptions\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiableCredential} */\n async createVerifiableCredential(args: ICreateVerifiableCredentialLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiableCredentialSP> {\n let { proofFormat /* keyRef, removeOriginalFields, now , ...otherOptions */ } = args\n const { credential, issuer, now } = preProcessCredentialPayload(args)\n\n try {\n await context.agent.didManagerGet({ did: issuer })\n } catch (e) {\n throw new Error(`invalid_argument: credential.issuer must be a DID managed by this agent. ${e}`)\n }\n try {\n async function findAndIssueCredential(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiableCredential({ ...args, credential, now }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n )\n }\n const verifiableCredential = await findAndIssueCredential(this.issuers)\n return verifiableCredential\n } catch (error) {\n debug(error)\n return Promise.reject(error)\n }\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyCredential} */\n async verifyCredential(args: IVerifyCredentialLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { credential, policies /*, ...otherOptions*/ } = args\n let verifiedCredential: VerifiableCredential\n let verificationResult: IVerifyResult | undefined = { verified: false }\n\n async function findAndVerifyCredential(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: credential as W3CVerifiableCredential })) {\n return issuer.verifyCredential(args, context)\n }\n }\n return Promise.reject(\n Error(\n `invalid_setup: No verifier found for the provided credential credential type: ${JSON.stringify(args.credential.type)} proof type ${asArray(args.credential.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n ),\n )\n }\n verificationResult = await findAndVerifyCredential(this.issuers)\n verifiedCredential = <VerifiableCredential>credential\n\n if (policies?.credentialStatus !== false && (await isRevoked(verifiedCredential, context as any))) {\n verificationResult = {\n verified: false,\n error: {\n message: 'revoked: The credential was revoked by the issuer',\n errorCode: 'revoked',\n },\n }\n }\n\n return verificationResult\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiablePresentation} */\n async createVerifiablePresentation(args: ICreateVerifiablePresentationLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiablePresentationSP> {\n const { proofFormat } = args\n const { presentation } = preProcessPresentation(args)\n\n let verifiablePresentation: VerifiablePresentationSP\n\n async function findAndCreatePresentation(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiablePresentation({ ...args, presentation }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n )\n }\n\n verifiablePresentation = await findAndCreatePresentation(this.issuers)\n return verifiablePresentation\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyPresentation} */\n async verifyPresentation(args: IVerifyPresentationLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { presentation /*domain, challenge, fetchRemoteContexts, policies, ...otherOptions*/ } = args\n async function findAndVerifyPresentation(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: presentation as W3CVerifiablePresentation })) {\n return issuer.verifyPresentation(args, context)\n }\n }\n throw new Error('invalid_setup: No verifier found for the provided presentation')\n }\n const result = await findAndVerifyPresentation(this.issuers)\n return result\n }\n}\n","import type {\n CredentialPayload,\n IAgentContext, ICredentialStatusVerifier,\n IIdentifier,\n IKey,\n IssuerType,\n PresentationPayload,\n VerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation\n} from '@veramo/core'\nimport { isDefined, processEntryToArray } from '@veramo/utils'\nimport { decodeJWT } from 'did-jwt'\nimport { addVcdmContextIfNeeded, isVcdm1Credential, isVcdm2Credential, VCDM_CREDENTIAL_CONTEXT_V1, VCDM_CREDENTIAL_CONTEXT_V2 } from '@sphereon/ssi-types'\nimport { ICreateVerifiablePresentationLDArgs } from './types'\n\n/**\n * Decodes a credential or presentation and returns the issuer ID\n * `iss` from a JWT or `issuer`/`issuer.id` from a VC or `holder` from a VP\n *\n * @param input - the credential or presentation whose issuer/holder needs to be extracted.\n * @param options - options for the extraction\n * removeParameters - Remove all DID parameters from the issuer ID\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function extractIssuer(\n input?:\n | W3CVerifiableCredential\n | W3CVerifiablePresentation\n | CredentialPayload\n | PresentationPayload\n | null,\n options: { removeParameters?: boolean } = {}\n): string {\n if (!isDefined(input)) {\n return ''\n } else if (typeof input === 'string') {\n // JWT\n try {\n const { payload } = decodeJWT(input.split(`~`)[0])\n const iss = payload.iss ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n } catch (e: any) {\n return ''\n }\n } else {\n // JSON\n let iss: IssuerType\n if (input.issuer) {\n iss = input.issuer\n } else if (input.holder) {\n iss = input.holder\n } else {\n iss = ''\n }\n if (typeof iss !== 'string') iss = iss.id ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n }\n}\n\n\n/**\n * Remove all DID parameters from a DID url after the query part (?)\n *\n * @param did - the DID URL\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function removeDIDParameters(did: string): string {\n return did.replace(/\\?.*$/, '')\n}\n\n\nexport function pickSigningKey(identifier: IIdentifier, keyRef?: string): IKey {\n let key: IKey | undefined\n\n if (!keyRef) {\n key = identifier.keys.find((k) => k.type === 'Secp256k1' || k.type === 'Ed25519' || k.type === 'Secp256r1')\n if (!key) throw Error('key_not_found: No signing key for ' + identifier.did)\n } else {\n key = identifier.keys.find((k) => k.kid === keyRef)\n if (!key) throw Error('key_not_found: No signing key for ' + identifier.did + ' with kid ' + keyRef)\n }\n\n return key as IKey\n}\n\nexport async function isRevoked(credential: VerifiableCredential, context: IAgentContext<ICredentialStatusVerifier>): Promise<boolean> {\n if (!credential.credentialStatus) return false\n\n if (typeof context.agent.checkCredentialStatus === 'function') {\n const status = await context.agent.checkCredentialStatus({ credential })\n return status?.revoked == true || status?.verified === false\n }\n\n throw new Error(`invalid_setup: The credential status can't be verified because there is no ICredentialStatusVerifier plugin installed.`)\n}\n\n\n\nexport function preProcessCredentialPayload({credential, now = new Date()}: {credential: CredentialPayload, now?: number | Date}) {\n const credentialContext = addVcdmContextIfNeeded(credential?.['@context'])\n const isVdcm1 = isVcdm1Credential(credential)\n const isVdcm2 = isVcdm2Credential(credential)\n const credentialType = processEntryToArray(credential?.type, 'VerifiableCredential')\n let issuanceDate = credential?.validFrom ?? credential?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()\n if (issuanceDate instanceof Date) {\n issuanceDate = issuanceDate.toISOString()\n }\n const credentialPayload: CredentialPayload = {\n ...credential,\n '@context': credentialContext,\n type: credentialType,\n ...(isVdcm1 && { issuanceDate }),\n ...(isVdcm2 && { validFrom: issuanceDate }),\n }\n\n // debug(JSON.stringify(credentialPayload))\n\n const issuer = extractIssuer(credentialPayload, {removeParameters: true})\n if (!issuer || typeof issuer === 'undefined') {\n throw new Error('invalid_argument: args.credential.issuer must not be empty')\n }\n return { credential: credentialPayload, issuer, now }\n}\n\n\nexport function preProcessPresentation(args: ICreateVerifiablePresentationLDArgs) {\n const { presentation, now = new Date() } = args\n const credentials = presentation?.verifiableCredential ?? []\n const v1Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V1))\n ? VCDM_CREDENTIAL_CONTEXT_V1\n : undefined\n const v2Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V2))\n ? VCDM_CREDENTIAL_CONTEXT_V2\n : undefined\n const presentationContext = addVcdmContextIfNeeded(args?.presentation?.['@context'] ?? [], v2Credential ?? v1Credential ?? VCDM_CREDENTIAL_CONTEXT_V2)\n const presentationType = processEntryToArray(args?.presentation?.type, 'VerifiablePresentation')\n\n let issuanceDate = presentation?.validFrom ?? presentation?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()\n if (issuanceDate instanceof Date) {\n issuanceDate = issuanceDate.toISOString()\n }\n const presentationPayload: PresentationPayload = {\n ...presentation,\n '@context': presentationContext,\n type: presentationType,\n ...(v1Credential && { issuanceDate }), // V1 only for JWT, but we remove it in the jsonld processor anyway\n ...(v2Credential && { validFrom: issuanceDate }),\n }\n // Workaround for bug in TypeError: Cannot read property 'length' of undefined\n // at VeramoEd25519Signature2018.preSigningPresModification\n /*if (!presentation.verifier) {\n presentation.verifier = []\n }*/\n\n if (!isDefined(presentationPayload.holder) || !presentationPayload.holder) {\n throw new Error('invalid_argument: args.presentation.holderDID must not be empty')\n }\n if (presentationPayload.verifiableCredential) {\n presentationPayload.verifiableCredential = presentationPayload.verifiableCredential.map((cred) => {\n // map JWT credentials to their canonical form\n if (typeof cred !== 'string' && cred.proof.jwt) {\n return cred.proof.jwt\n } else {\n return cred\n }\n })\n }\n return {presentation: presentationPayload, holder: removeDIDParameters(presentationPayload.holder)}\n}\n","/**\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":";;;;AAOA,SAASA,8BAAuC;AAChD,SAASC,SAASC,kBAAkBC,0BAA0BC,qBAAqB;AAEnF,SACEC,qBACAC,uBACAC,8BACAC,sCAEG;AAEL,SAASC,MAAMC,cAAc;AAC7B,OAAOC,WAAW;AAElB,IAAMC,QAAQC,MAAM,+BAAA;AAOb,IAAMC,eAAe;;EAE1BC,IAAI;;EAEJC,IAAI;AACN;AAsBO,IAAMC,oBAAN,cAAgCC,uBAAAA;EAhDvC,OAgDuCA;;;EACrC,MAAMC,OAAOC,SAAkBC,SAAqC;AAClE,UAAMC,OAAOF,QAAQG,gBAAe;AAKpC,QAAID,MAAME,SAAS,SAASJ,QAAQK,KAAK;AACvC,YAAM,EAAEC,KAAI,IAAKN;AAEjB,UAAI;AACFO,uCAA+BD,IAAAA;AAG/Bd,cAAM,UAAUE,aAAaE,EAAE;AAC/B,cAAMY,eAAeC,sBAAsBT,QAAQK,GAAG;AACtD,cAAMK,cAAcF,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,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","extractIssuer","input","options","isDefined","payload","decodeJWT","split","iss","removeParameters","removeDIDParameters","e","issuer","holder","id","did","replace","pickSigningKey","identifier","keyRef","key","keys","find","k","type","Error","kid","isRevoked","credential","context","credentialStatus","agent","checkCredentialStatus","status","revoked","verified","preProcessCredentialPayload","now","Date","credentialContext","addVcdmContextIfNeeded","isVdcm1","isVcdm1Credential","isVdcm2","isVcdm2Credential","credentialType","processEntryToArray","issuanceDate","validFrom","toISOString","credentialPayload","preProcessPresentation","args","presentation","credentials","verifiableCredential","v1Credential","cred","includes","VCDM_CREDENTIAL_CONTEXT_V1","undefined","v2Credential","VCDM_CREDENTIAL_CONTEXT_V2","presentationContext","presentationType","presentationPayload","map","proof","jwt","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 {\n IAgentContext,\n ICredentialVerifier,\n IResolver,\n VerifiableCredential,\n VerifiablePresentation,\n} from '@veramo/core'\nimport { AbstractMessageHandler, Message } from '@veramo/message-handler'\nimport { asArray, computeEntryHash, decodeCredentialToObject, extractIssuer } from '@veramo/utils'\n\nimport {\n normalizeCredential,\n normalizePresentation,\n validateJwtCredentialPayload,\n validateJwtPresentationPayload,\n}// @ts-ignore\nfrom 'did-jwt-vc'\n\nimport { v4 as uuidv4 } from 'uuid'\nimport Debug from 'debug'\n\nconst debug = Debug('sphereon:vcdm:message-handler')\n\n/**\n * These types are used by `@veramo/data-store` when storing Verifiable Credentials and Presentations\n *\n * @internal\n */\nexport const MessageTypes = {\n /** Represents a Verifiable Credential */\n vc: 'w3c.vc',\n /** Represents a Verifiable Presentation */\n vp: 'w3c.vp',\n}\n\n/**\n * Represents the requirements that this plugin has.\n * The agent that is using this plugin is expected to provide these methods.\n *\n * This interface can be used for static type checks, to make sure your application is properly initialized.\n */\nexport type IContext = IAgentContext<IResolver & ICredentialVerifier>\n\n/**\n * An implementation of the {@link @veramo/message-handler#AbstractMessageHandler}.\n *\n * This plugin can handle incoming W3C Verifiable Credentials and Presentations and prepare them\n * for internal storage as {@link @veramo/message-handler#Message} types.\n *\n * The current version can only handle `JWT` encoded\n *\n * @remarks {@link @veramo/core#IDataStore | IDataStore }\n *\n * @public\n */\nexport class W3cMessageHandler extends AbstractMessageHandler {\n async handle(message: Message, context: IContext): Promise<Message> {\n const meta = message.getLastMetaData()\n\n // console.log(JSON.stringify(message, null, 2))\n\n //FIXME: messages should not be expected to be only JWT\n if (meta?.type === 'JWT' && message.raw) {\n const { data } = message\n\n try {\n validateJwtPresentationPayload(data)\n\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vp)\n const presentation = normalizePresentation(message.raw)\n const credentials = presentation.verifiableCredential\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vp\n message.from = presentation.holder\n message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = credentials\n\n return message\n } catch (e) {}\n\n try {\n validateJwtCredentialPayload(data)\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vc)\n const credential = normalizeCredential(message.raw)\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vc\n message.from = credential.issuer.id\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } catch (e) {}\n }\n\n // LDS Verification and Handling\n if (message.type === MessageTypes.vc && message.data) {\n // verify credential\n const credential = message.data as VerifiableCredential\n\n const result = await context.agent.verifyCredential({ credential })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vc\n message.from = extractIssuer(credential)\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n if (message.type === MessageTypes.vp && message.data) {\n // verify presentation\n const presentation = message.data as VerifiablePresentation\n\n // throws on error.\n const result = await context.agent.verifyPresentation({\n presentation,\n // FIXME: HARDCODED CHALLENGE VERIFICATION FOR NOW\n challenge: 'VERAMO',\n domain: 'VERAMO',\n })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vp\n message.from = presentation.holder\n // message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n // message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = asArray(presentation.verifiableCredential).map(decodeCredentialToObject)\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n return super.handle(message, context)\n }\n}\n","import type { IAgentPlugin, IIdentifier, IVerifyResult, VerifiableCredential } from '@veramo/core'\nimport { schema } from '@veramo/core'\n\nimport type {\n ICreateVerifiableCredentialLDArgs,\n ICreateVerifiablePresentationLDArgs,\n IVcdmCredentialPlugin,\n IVcdmCredentialProvider,\n IVcdmIssuerAgentContext,\n IVcdmVerifierAgentContext,\n IVerifyCredentialLDArgs,\n IVerifyPresentationLDArgs,\n} from './types'\nimport Debug from 'debug'\nimport { isRevoked, preProcessCredentialPayload, preProcessPresentation } from './functions'\nimport type { W3CVerifiableCredential, W3CVerifiablePresentation } from '@sphereon/ssi-types'\nimport { asArray, VerifiableCredentialSP, VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'\n\nconst debug = Debug('sphereon:ssi-sdk:vcdm')\n\n/**\n * A plugin that implements the {@link @sphereon/ssi-sdk.credential-vcdm#IVcdmCredentialPlugin} methods.\n *\n * @public\n */\nexport class VcdmCredentialPlugin implements IAgentPlugin {\n readonly methods: IVcdmCredentialPlugin\n readonly schema = {\n components: {\n schemas: {\n ...schema.ICredentialIssuer.components.schemas,\n ...schema.ICredentialVerifier.components.schemas,\n },\n methods: {\n ...schema.ICredentialIssuer.components.methods,\n ...schema.ICredentialVerifier.components.methods,\n },\n },\n }\n private issuers: IVcdmCredentialProvider[]\n\n constructor(options: { issuers: IVcdmCredentialProvider[] }) {\n this.issuers = options.issuers\n this.methods = {\n listUsableProofFormats: this.listUsableProofFormats.bind(this),\n createVerifiableCredential: this.createVerifiableCredential.bind(this),\n verifyCredential: this.verifyCredential.bind(this),\n createVerifiablePresentation: this.createVerifiablePresentation.bind(this),\n verifyPresentation: this.verifyPresentation.bind(this),\n }\n }\n\n async listUsableProofFormats(did: IIdentifier, context: IVcdmIssuerAgentContext): Promise<string[]> {\n const signingOptions: string[] = []\n const keys = did.keys\n for (const key of keys) {\n for (const issuer of this.issuers) {\n if (issuer.matchKeyForType(key)) {\n signingOptions.push(issuer.getTypeProofFormat())\n }\n }\n }\n return signingOptions\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiableCredential} */\n async createVerifiableCredential(args: ICreateVerifiableCredentialLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiableCredentialSP> {\n let { proofFormat /* keyRef, removeOriginalFields, now , ...otherOptions */ } = args\n const { credential, issuer, now } = preProcessCredentialPayload(args)\n\n try {\n await context.agent.didManagerGet({ did: issuer })\n } catch (e) {\n throw new Error(`invalid_argument: credential.issuer must be a DID managed by this agent. ${e}`)\n }\n try {\n async function findAndIssueCredential(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiableCredential({ ...args, credential, now }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n )\n }\n const verifiableCredential = await findAndIssueCredential(this.issuers)\n return verifiableCredential\n } catch (error) {\n debug(error)\n return Promise.reject(error)\n }\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyCredential} */\n async verifyCredential(args: IVerifyCredentialLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { credential, policies /*, ...otherOptions*/ } = args\n let verifiedCredential: VerifiableCredential\n let verificationResult: IVerifyResult | undefined = { verified: false }\n\n async function findAndVerifyCredential(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: credential as W3CVerifiableCredential })) {\n return issuer.verifyCredential(args, context)\n }\n }\n return Promise.reject(\n Error(\n `invalid_setup: No verifier found for the provided credential credential type: ${JSON.stringify(args.credential.type)} proof type ${asArray(args.credential.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n ),\n )\n }\n verificationResult = await findAndVerifyCredential(this.issuers)\n verifiedCredential = <VerifiableCredential>credential\n\n if (policies?.credentialStatus !== false && (await isRevoked(verifiedCredential, context as any))) {\n verificationResult = {\n verified: false,\n error: {\n message: 'revoked: The credential was revoked by the issuer',\n errorCode: 'revoked',\n },\n }\n }\n\n return verificationResult\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiablePresentation} */\n async createVerifiablePresentation(args: ICreateVerifiablePresentationLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiablePresentationSP> {\n const { proofFormat } = args\n const { presentation } = preProcessPresentation(args)\n\n let verifiablePresentation: VerifiablePresentationSP\n\n async function findAndCreatePresentation(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiablePresentation({ ...args, presentation }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`,\n )\n }\n\n verifiablePresentation = await findAndCreatePresentation(this.issuers)\n return verifiablePresentation\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyPresentation} */\n async verifyPresentation(args: IVerifyPresentationLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { presentation /*domain, challenge, fetchRemoteContexts, policies, ...otherOptions*/ } = args\n async function findAndVerifyPresentation(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: presentation as W3CVerifiablePresentation })) {\n return issuer.verifyPresentation(args, context)\n }\n }\n throw new Error('invalid_setup: No verifier found for the provided presentation')\n }\n const result = await findAndVerifyPresentation(this.issuers)\n return result\n }\n}\n","import type {\n CredentialPayload,\n IAgentContext,\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":";;;;AAOA,SAASA,8BAAuC;AAChD,SAASC,SAASC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T;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"]}
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-feature.jose.vcdm.57+67da2083",
4
+ "version": "0.33.1-feature.jose.vcdm.59+5f24a990",
5
5
  "source": "src/index.ts",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
@@ -28,10 +28,12 @@
28
28
  "generate-plugin-schema": "tsx ../../packages/dev/bin/sphereon.js dev generate-plugin-schema"
29
29
  },
30
30
  "dependencies": {
31
- "@sphereon/ssi-sdk.agent-config": "0.33.1-feature.jose.vcdm.57+67da2083",
32
- "@sphereon/ssi-sdk.core": "0.33.1-feature.jose.vcdm.57+67da2083",
33
- "@sphereon/ssi-sdk.vc-status-list": "0.33.1-feature.jose.vcdm.57+67da2083",
34
- "@sphereon/ssi-types": "0.33.1-feature.jose.vcdm.57+67da2083",
31
+ "@sphereon/ssi-sdk-ext.did-utils": "workspace:*",
32
+ "@sphereon/ssi-sdk-ext.key-utils": "workspace:*",
33
+ "@sphereon/ssi-sdk.agent-config": "0.33.1-feature.jose.vcdm.59+5f24a990",
34
+ "@sphereon/ssi-sdk.core": "0.33.1-feature.jose.vcdm.59+5f24a990",
35
+ "@sphereon/ssi-sdk.vc-status-list": "0.33.1-feature.jose.vcdm.59+5f24a990",
36
+ "@sphereon/ssi-types": "0.33.1-feature.jose.vcdm.59+5f24a990",
35
37
  "@veramo/core": "4.2.0",
36
38
  "@veramo/message-handler": "4.2.0",
37
39
  "@veramo/utils": "4.2.0",
@@ -43,9 +45,9 @@
43
45
  "uuid": "^9.0.1"
44
46
  },
45
47
  "devDependencies": {
46
- "@sphereon/ssi-sdk-ext.did-provider-key": "0.28.1-feature.jose.vcdm.20",
47
- "@sphereon/ssi-sdk-ext.key-manager": "0.28.1-feature.jose.vcdm.20",
48
- "@sphereon/ssi-sdk-ext.kms-local": "0.28.1-feature.jose.vcdm.20",
48
+ "@sphereon/ssi-sdk-ext.did-provider-key": "0.28.1-feature.jose.vcdm.25",
49
+ "@sphereon/ssi-sdk-ext.key-manager": "0.28.1-feature.jose.vcdm.25",
50
+ "@sphereon/ssi-sdk-ext.kms-local": "0.28.1-feature.jose.vcdm.25",
49
51
  "@types/debug": "4.1.8",
50
52
  "@types/uuid": "9.0.2",
51
53
  "@veramo/did-manager": "4.2.0",
@@ -89,5 +91,5 @@
89
91
  "node_modules",
90
92
  "src"
91
93
  ],
92
- "gitHead": "67da2083bb6408f9896ad06e87688178ab3e2d31"
94
+ "gitHead": "5f24a9904d53b07534cdaf71f2874f8e64b4c845"
93
95
  }
@@ -2,7 +2,7 @@ import { beforeAll, describe, expect, test } from 'vitest'
2
2
 
3
3
  import { CredentialPayload, ICredentialPlugin, IDIDManager, IIdentifier, IKeyManager, IResolver, PresentationPayload, TAgent } from '@veramo/core'
4
4
  import { VcdmCredentialPlugin } from '../vcdmCredentialPlugin'
5
- import { CredentialProviderJWT } from '../../../credential-jwt/src'
5
+ import { CredentialProviderJWT } from '../../../credential-vcdm1-jwt-provider/src'
6
6
 
7
7
  import { getDidKeyResolver, SphereonKeyDidProvider } from '@sphereon/ssi-sdk-ext.did-provider-key'
8
8
  import { Resolver } from 'did-resolver'
@@ -13,11 +13,11 @@ import {
13
13
  LdDefaultContexts,
14
14
  SphereonEcdsaSecp256k1RecoverySignature2020, SphereonEd25519Signature2018,
15
15
  SphereonEd25519Signature2020
16
- } from '../../../credential-jsonld/src'
16
+ } from '../../../credential-vcdm-jsonld-provider/src'
17
17
  import { Resolver } from 'did-resolver'
18
18
  import { getResolver as ethrDidResolver } from 'ethr-did-resolver'
19
19
 
20
- import { CredentialProviderJWT } from '../../../credential-jwt/src'
20
+ import { CredentialProviderJWT } from '../../../credential-vcdm1-jwt-provider/src'
21
21
  import { VerifiableCredentialSP } from '@sphereon/ssi-sdk.core'
22
22
 
23
23
  const customContext: Record<string, ContextDoc> = {
package/src/functions.ts CHANGED
@@ -1,18 +1,27 @@
1
1
  import type {
2
2
  CredentialPayload,
3
- IAgentContext, ICredentialStatusVerifier,
3
+ IAgentContext,
4
+ ICredentialStatusVerifier,
5
+ IDIDManager,
4
6
  IIdentifier,
5
- IKey,
7
+ IResolver,
6
8
  IssuerType,
7
9
  PresentationPayload,
8
10
  VerifiableCredential,
9
11
  W3CVerifiableCredential,
10
- W3CVerifiablePresentation
12
+ W3CVerifiablePresentation,
11
13
  } from '@veramo/core'
12
- import { isDefined, processEntryToArray } from '@veramo/utils'
14
+ import { _ExtendedIKey, isDefined, processEntryToArray } from '@veramo/utils'
13
15
  import { decodeJWT } from 'did-jwt'
14
- import { addVcdmContextIfNeeded, isVcdm1Credential, isVcdm2Credential, VCDM_CREDENTIAL_CONTEXT_V1, VCDM_CREDENTIAL_CONTEXT_V2 } from '@sphereon/ssi-types'
16
+ import {
17
+ addVcdmContextIfNeeded,
18
+ isVcdm1Credential,
19
+ isVcdm2Credential,
20
+ VCDM_CREDENTIAL_CONTEXT_V1,
21
+ VCDM_CREDENTIAL_CONTEXT_V2,
22
+ } from '@sphereon/ssi-types'
15
23
  import { ICreateVerifiablePresentationLDArgs } from './types'
24
+ import { getKey } from '@sphereon/ssi-sdk-ext.did-utils'
16
25
 
17
26
  /**
18
27
  * Decodes a credential or presentation and returns the issuer ID
@@ -25,13 +34,8 @@ import { ICreateVerifiablePresentationLDArgs } from './types'
25
34
  * @beta This API may change without a BREAKING CHANGE notice.
26
35
  */
27
36
  export function extractIssuer(
28
- input?:
29
- | W3CVerifiableCredential
30
- | W3CVerifiablePresentation
31
- | CredentialPayload
32
- | PresentationPayload
33
- | null,
34
- options: { removeParameters?: boolean } = {}
37
+ input?: W3CVerifiableCredential | W3CVerifiablePresentation | CredentialPayload | PresentationPayload | null,
38
+ options: { removeParameters?: boolean } = {},
35
39
  ): string {
36
40
  if (!isDefined(input)) {
37
41
  return ''
@@ -59,7 +63,6 @@ export function extractIssuer(
59
63
  }
60
64
  }
61
65
 
62
-
63
66
  /**
64
67
  * Remove all DID parameters from a DID url after the query part (?)
65
68
  *
@@ -71,19 +74,12 @@ export function removeDIDParameters(did: string): string {
71
74
  return did.replace(/\?.*$/, '')
72
75
  }
73
76
 
74
-
75
- export function pickSigningKey(identifier: IIdentifier, keyRef?: string): IKey {
76
- let key: IKey | undefined
77
-
78
- if (!keyRef) {
79
- key = identifier.keys.find((k) => k.type === 'Secp256k1' || k.type === 'Ed25519' || k.type === 'Secp256r1')
80
- if (!key) throw Error('key_not_found: No signing key for ' + identifier.did)
81
- } else {
82
- key = identifier.keys.find((k) => k.kid === keyRef)
83
- if (!key) throw Error('key_not_found: No signing key for ' + identifier.did + ' with kid ' + keyRef)
84
- }
85
-
86
- return key as IKey
77
+ export async function pickSigningKey(
78
+ { identifier, kmsKeyRef }: { identifier: IIdentifier; kmsKeyRef?: string },
79
+ context: IAgentContext<IResolver & IDIDManager>,
80
+ ): Promise<_ExtendedIKey> {
81
+ const key = await getKey({ identifier, vmRelationship: 'assertionMethod', kmsKeyRef: kmsKeyRef }, context)
82
+ return key
87
83
  }
88
84
 
89
85
  export async function isRevoked(credential: VerifiableCredential, context: IAgentContext<ICredentialStatusVerifier>): Promise<boolean> {
@@ -97,14 +93,13 @@ export async function isRevoked(credential: VerifiableCredential, context: IAgen
97
93
  throw new Error(`invalid_setup: The credential status can't be verified because there is no ICredentialStatusVerifier plugin installed.`)
98
94
  }
99
95
 
100
-
101
-
102
- export function preProcessCredentialPayload({credential, now = new Date()}: {credential: CredentialPayload, now?: number | Date}) {
96
+ export function preProcessCredentialPayload({ credential, now = new Date() }: { credential: CredentialPayload; now?: number | Date }) {
103
97
  const credentialContext = addVcdmContextIfNeeded(credential?.['@context'])
104
98
  const isVdcm1 = isVcdm1Credential(credential)
105
99
  const isVdcm2 = isVcdm2Credential(credential)
106
100
  const credentialType = processEntryToArray(credential?.type, 'VerifiableCredential')
107
101
  let issuanceDate = credential?.validFrom ?? credential?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()
102
+ let expirationDate = credential?.validUntil ?? credential?.expirationDate
108
103
  if (issuanceDate instanceof Date) {
109
104
  issuanceDate = issuanceDate.toISOString()
110
105
  }
@@ -113,19 +108,27 @@ export function preProcessCredentialPayload({credential, now = new Date()}: {cre
113
108
  '@context': credentialContext,
114
109
  type: credentialType,
115
110
  ...(isVdcm1 && { issuanceDate }),
111
+ ...(isVdcm1 && expirationDate && { expirationDate }),
116
112
  ...(isVdcm2 && { validFrom: issuanceDate }),
113
+ ...(isVdcm2 && expirationDate && { validUntil: expirationDate }),
114
+ }
115
+ if (isVdcm1) {
116
+ delete credentialPayload.validFrom
117
+ delete credentialPayload.validUntil
118
+ } else if (isVdcm2) {
119
+ delete credentialPayload.issuanceDate
120
+ delete credentialPayload.expirationDate
117
121
  }
118
122
 
119
123
  // debug(JSON.stringify(credentialPayload))
120
124
 
121
- const issuer = extractIssuer(credentialPayload, {removeParameters: true})
125
+ const issuer = extractIssuer(credentialPayload, { removeParameters: true })
122
126
  if (!issuer || typeof issuer === 'undefined') {
123
127
  throw new Error('invalid_argument: args.credential.issuer must not be empty')
124
128
  }
125
129
  return { credential: credentialPayload, issuer, now }
126
130
  }
127
131
 
128
-
129
132
  export function preProcessPresentation(args: ICreateVerifiablePresentationLDArgs) {
130
133
  const { presentation, now = new Date() } = args
131
134
  const credentials = presentation?.verifiableCredential ?? []
@@ -135,7 +138,10 @@ export function preProcessPresentation(args: ICreateVerifiablePresentationLDArgs
135
138
  const v2Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V2))
136
139
  ? VCDM_CREDENTIAL_CONTEXT_V2
137
140
  : undefined
138
- const presentationContext = addVcdmContextIfNeeded(args?.presentation?.['@context'] ?? [], v2Credential ?? v1Credential ?? VCDM_CREDENTIAL_CONTEXT_V2)
141
+ const presentationContext = addVcdmContextIfNeeded(
142
+ args?.presentation?.['@context'] ?? [],
143
+ v2Credential ?? v1Credential ?? VCDM_CREDENTIAL_CONTEXT_V2,
144
+ )
139
145
  const presentationType = processEntryToArray(args?.presentation?.type, 'VerifiablePresentation')
140
146
 
141
147
  let issuanceDate = presentation?.validFrom ?? presentation?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()
@@ -168,5 +174,5 @@ export function preProcessPresentation(args: ICreateVerifiablePresentationLDArgs
168
174
  }
169
175
  })
170
176
  }
171
- return {presentation: presentationPayload, holder: removeDIDParameters(presentationPayload.holder)}
177
+ return { presentation: presentationPayload, holder: removeDIDParameters(presentationPayload.holder) }
172
178
  }
package/src/types.ts CHANGED
@@ -8,7 +8,7 @@ import type {
8
8
  IResolver,
9
9
  IVerifyResult,
10
10
  PresentationPayload,
11
- VerificationPolicies,
11
+ VerificationPolicies
12
12
  } from '@veramo/core'
13
13
 
14
14
  import type { VerifiableCredentialSP, VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'