@sphereon/ssi-sdk.credential-vcdm 0.34.1-feature.SSISDK.17.bitstring.sl.9 → 0.34.1-next.29

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/message-handler.ts","../src/vcdmCredentialPlugin.ts","../src/functions.ts"],"sourcesContent":["/**\n * Provides a {@link @veramo/credential-w3c#CredentialPlugin | plugin} for the {@link @veramo/core#Agent} that\n * implements\n * {@link @veramo/core#ICredentialIssuer} interface.\n *\n * Provides a {@link @veramo/credential-w3c#W3cMessageHandler | plugin} for the\n * {@link @veramo/message-handler#MessageHandler} that verifies Credentials and Presentations in a message.\n *\n * @packageDocumentation\n */\nexport type * from './types'\nexport { W3cMessageHandler, MessageTypes } from './message-handler'\nimport { VcdmCredentialPlugin } from './vcdmCredentialPlugin'\n\n/**\n * @deprecated please use {@link VcdmCredentialPlugin} instead\n * @public\n */\nconst CredentialIssuer = VcdmCredentialPlugin\nexport { CredentialIssuer, VcdmCredentialPlugin }\n\n// For backward compatibility, re-export the plugin types that were moved to core in v4\nexport type { ICredentialIssuer, ICredentialVerifier } from '@veramo/core'\n\nexport * from './functions'\n","import type { IAgentContext, ICredentialVerifier, IResolver, VerifiableCredential, VerifiablePresentation } from '@veramo/core'\nimport { AbstractMessageHandler, Message } from '@veramo/message-handler'\nimport { asArray, computeEntryHash, decodeCredentialToObject, extractIssuer } from '@veramo/utils'\n\nimport {\n normalizeCredential,\n normalizePresentation,\n validateJwtCredentialPayload,\n validateJwtPresentationPayload, // @ts-ignore\n} from 'did-jwt-vc'\n\nimport { v4 as uuidv4 } from 'uuid'\nimport Debug from 'debug'\n\nconst debug = Debug('sphereon:vcdm:message-handler')\n\n/**\n * These types are used by `@veramo/data-store` when storing Verifiable Credentials and Presentations\n *\n * @internal\n */\nexport const MessageTypes = {\n /** Represents a Verifiable Credential */\n vc: 'w3c.vc',\n /** Represents a Verifiable Presentation */\n vp: 'w3c.vp',\n}\n\n/**\n * Represents the requirements that this plugin has.\n * The agent that is using this plugin is expected to provide these methods.\n *\n * This interface can be used for static type checks, to make sure your application is properly initialized.\n */\nexport type IContext = IAgentContext<IResolver & ICredentialVerifier>\n\n/**\n * An implementation of the {@link @veramo/message-handler#AbstractMessageHandler}.\n *\n * This plugin can handle incoming W3C Verifiable Credentials and Presentations and prepare them\n * for internal storage as {@link @veramo/message-handler#Message} types.\n *\n * The current version can only handle `JWT` encoded\n *\n * @remarks {@link @veramo/core#IDataStore | IDataStore }\n *\n * @public\n */\nexport class W3cMessageHandler extends AbstractMessageHandler {\n async handle(message: Message, context: IContext): Promise<Message> {\n const meta = message.getLastMetaData()\n\n // console.log(JSON.stringify(message, null, 2))\n\n //FIXME: messages should not be expected to be only JWT\n if (meta?.type === 'JWT' && message.raw) {\n const { data } = message\n\n try {\n validateJwtPresentationPayload(data)\n\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vp)\n const presentation = normalizePresentation(message.raw)\n const credentials = presentation.verifiableCredential\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vp\n message.from = presentation.holder\n message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = credentials\n\n return message\n } catch (e) {}\n\n try {\n validateJwtCredentialPayload(data)\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vc)\n const credential = normalizeCredential(message.raw)\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vc\n message.from = credential.issuer.id\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } catch (e) {}\n }\n\n // LDS Verification and Handling\n if (message.type === MessageTypes.vc && message.data) {\n // verify credential\n const credential = message.data as VerifiableCredential\n\n const result = await context.agent.verifyCredential({ credential })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vc\n message.from = extractIssuer(credential)\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n if (message.type === MessageTypes.vp && message.data) {\n // verify presentation\n const presentation = message.data as VerifiablePresentation\n\n // throws on error.\n const result = await context.agent.verifyPresentation({\n presentation,\n // FIXME: HARDCODED CHALLENGE VERIFICATION FOR NOW\n challenge: 'VERAMO',\n domain: 'VERAMO',\n })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vp\n message.from = presentation.holder\n // message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n // message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = asArray(presentation.verifiableCredential).map(decodeCredentialToObject)\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n return super.handle(message, context)\n }\n}\n","import { asArray, type VerifiableCredentialSP, type VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'\nimport {\n CredentialMapper,\n IVerifyResult,\n IVerifySingleResultItem,\n OriginalVerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation\n} from '@sphereon/ssi-types'\nimport type { IAgentPlugin, IIdentifier, VerifiableCredential } from '@veramo/core'\nimport { schema } from '@veramo/core'\nimport Debug from 'debug'\nimport { isRevoked, preProcessCredentialPayload, preProcessPresentation } from './functions'\n\nimport type {\n ICreateVerifiableCredentialLDArgs,\n ICreateVerifiablePresentationLDArgs,\n IVcdmCredentialPlugin,\n IVcdmCredentialProvider,\n IVcdmIssuerAgentContext,\n IVcdmVerifierAgentContext,\n IVerifyCredentialVcdmArgs,\n IVerifyPresentationLDArgs\n} from './types'\n\nconst debug = Debug('sphereon:ssi-sdk:vcdm')\n\n/**\n * A plugin that implements the {@link @sphereon/ssi-sdk.credential-vcdm#IVcdmCredentialPlugin} methods.\n *\n * @public\n */\nexport class VcdmCredentialPlugin implements IAgentPlugin {\n readonly methods: IVcdmCredentialPlugin\n readonly schema = {\n components: {\n schemas: {\n ...schema.ICredentialIssuer.components.schemas,\n ...schema.ICredentialVerifier.components.schemas\n },\n methods: {\n ...schema.ICredentialIssuer.components.methods,\n ...schema.ICredentialVerifier.components.methods\n }\n }\n }\n private issuers: IVcdmCredentialProvider[]\n\n constructor(options: { issuers: IVcdmCredentialProvider[] }) {\n this.issuers = options.issuers\n this.methods = {\n listUsableProofFormats: this.listUsableProofFormats.bind(this),\n createVerifiableCredential: this.createVerifiableCredential.bind(this),\n verifyCredential: this.verifyCredential.bind(this),\n createVerifiablePresentation: this.createVerifiablePresentation.bind(this),\n verifyPresentation: this.verifyPresentation.bind(this)\n }\n }\n\n async listUsableProofFormats(did: IIdentifier, context: IVcdmIssuerAgentContext): Promise<string[]> {\n const signingOptions: string[] = []\n const keys = did.keys\n for (const key of keys) {\n for (const issuer of this.issuers) {\n if (issuer.matchKeyForType(key)) {\n signingOptions.push(issuer.getTypeProofFormat())\n }\n }\n }\n return signingOptions\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiableCredential} */\n async createVerifiableCredential(args: ICreateVerifiableCredentialLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiableCredentialSP> {\n let { proofFormat /* keyRef, removeOriginalFields, now , ...otherOptions */ } = args\n const { credential, issuer, now } = preProcessCredentialPayload(args)\n\n try {\n await context.agent.didManagerGet({ did: issuer })\n } catch (e) {\n throw new Error(`invalid_argument: credential.issuer must be a DID managed by this agent. ${e}`)\n }\n try {\n async function findAndIssueCredential(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiableCredential({ ...args, credential, now }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`\n )\n }\n\n const verifiableCredential = await findAndIssueCredential(this.issuers)\n return verifiableCredential\n } catch (error) {\n debug(error)\n return Promise.reject(error)\n }\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyCredential} */\n async verifyCredential(args: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { credential, policies /*, ...otherOptions*/ } = args\n let verifiedCredential: VerifiableCredential\n let verificationResult: IVerifyResult\n\n\n async function findAndVerifyCredential(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: credential as W3CVerifiableCredential })) {\n return issuer.verifyCredential(args, context)\n }\n }\n const uniform = CredentialMapper.toUniformCredential(args.credential as OriginalVerifiableCredential)\n return Promise.reject(\n Error(\n `invalid_setup: No verifier found for the provided credential credential\n type: ${JSON.stringify(uniform.type)} proof type \n ${asArray(uniform.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`\n )\n )\n }\n\n verificationResult = await findAndVerifyCredential(this.issuers)\n verifiedCredential = <VerifiableCredential>credential\n\n if (policies?.credentialStatus !== false && (await isRevoked(verifiedCredential, context as any))) {\n const results = verificationResult.results\n const partialSingleResult: Partial<IVerifySingleResultItem> = (Array.isArray(results) ? results[0] : {\n credential: credential as OriginalVerifiableCredential,\n verified: false,\n log: []\n })\n const result: IVerifySingleResultItem = {\n ...partialSingleResult,\n credential: credential as OriginalVerifiableCredential,\n verified: false,\n error: {\n message: 'revoked: The credential was revoked by the issuer',\n errorCode: 'revoked'\n },\n log: [...partialSingleResult.log ?? [], { id: 'revocation_status', valid: false }]\n }\n verificationResult = {\n ...verificationResult,\n verified: false,\n error: result.error,\n results: [\n result\n ]\n }\n }\n\n return verificationResult\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiablePresentation} */\n async createVerifiablePresentation(args: ICreateVerifiablePresentationLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiablePresentationSP> {\n const { proofFormat } = args\n const { presentation } = preProcessPresentation(args)\n\n let verifiablePresentation: VerifiablePresentationSP\n\n async function findAndCreatePresentation(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiablePresentation({ ...args, presentation }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`\n )\n }\n\n verifiablePresentation = await findAndCreatePresentation(this.issuers)\n return verifiablePresentation\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyPresentation} */\n async verifyPresentation(args: IVerifyPresentationLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { presentation /*domain, challenge, fetchRemoteContexts, policies, ...otherOptions*/ } = args\n\n async function findAndVerifyPresentation(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: presentation as W3CVerifiablePresentation })) {\n return issuer.verifyPresentation(args, context)\n }\n }\n throw new Error('invalid_setup: No verifier found for the provided presentation')\n }\n\n const result = await findAndVerifyPresentation(this.issuers)\n return result\n }\n}\n","import type {\n CredentialPayload,\n IAgentContext,\n ICredentialStatusVerifier,\n IDIDManager,\n IIdentifier,\n IResolver,\n IssuerType,\n PresentationPayload,\n VerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation,\n} from '@veramo/core'\nimport { _ExtendedIKey, isDefined, processEntryToArray } from '@veramo/utils'\nimport { decodeJWT } from 'did-jwt'\nimport {\n addVcdmContextIfNeeded,\n isVcdm1Credential,\n isVcdm2Credential,\n VCDM_CREDENTIAL_CONTEXT_V1,\n VCDM_CREDENTIAL_CONTEXT_V2,\n} from '@sphereon/ssi-types'\nimport { ICreateVerifiablePresentationLDArgs } from './types'\nimport { getKey } from '@sphereon/ssi-sdk-ext.did-utils'\n\n/**\n * Decodes a credential or presentation and returns the issuer ID\n * `iss` from a JWT or `issuer`/`issuer.id` from a VC or `holder` from a VP\n *\n * @param input - the credential or presentation whose issuer/holder needs to be extracted.\n * @param options - options for the extraction\n * removeParameters - Remove all DID parameters from the issuer ID\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function extractIssuer(\n input?: W3CVerifiableCredential | W3CVerifiablePresentation | CredentialPayload | PresentationPayload | null,\n options: { removeParameters?: boolean } = {},\n): string {\n if (!isDefined(input)) {\n return ''\n } else if (typeof input === 'string') {\n // JWT\n try {\n const { payload } = decodeJWT(input.split(`~`)[0])\n const iss = payload.iss ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n } catch (e: any) {\n return ''\n }\n } else {\n // JSON\n let iss: IssuerType\n if (input.issuer) {\n iss = input.issuer\n } else if (input.holder) {\n iss = input.holder\n } else {\n iss = ''\n }\n if (typeof iss !== 'string') iss = iss.id ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n }\n}\n\n/**\n * Remove all DID parameters from a DID url after the query part (?)\n *\n * @param did - the DID URL\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function removeDIDParameters(did: string): string {\n return did.replace(/\\?.*$/, '')\n}\n\nexport async function pickSigningKey(\n { identifier, kmsKeyRef }: { identifier: IIdentifier; kmsKeyRef?: string },\n context: IAgentContext<IResolver & IDIDManager>,\n): Promise<_ExtendedIKey> {\n const key = await getKey({ identifier, vmRelationship: 'assertionMethod', kmsKeyRef: kmsKeyRef }, context)\n return key\n}\n\nexport async function isRevoked(credential: VerifiableCredential, context: IAgentContext<ICredentialStatusVerifier>): Promise<boolean> {\n if (!credential.credentialStatus) return false\n\n if (typeof context.agent.checkCredentialStatus === 'function') {\n const status = await context.agent.checkCredentialStatus({ credential })\n return status?.revoked == true || status?.verified === false\n }\n\n throw new Error(`invalid_setup: The credential status can't be verified because there is no ICredentialStatusVerifier plugin installed.`)\n}\n\nexport function preProcessCredentialPayload({ credential, now = new Date() }: { credential: CredentialPayload; now?: number | Date }) {\n const credentialContext = addVcdmContextIfNeeded(credential?.['@context'])\n const isVdcm1 = isVcdm1Credential(credential)\n const isVdcm2 = isVcdm2Credential(credential)\n const credentialType = processEntryToArray(credential?.type, 'VerifiableCredential')\n let issuanceDate = credential?.validFrom ?? credential?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()\n let expirationDate = credential?.validUntil ?? credential?.expirationDate\n if (issuanceDate instanceof Date) {\n issuanceDate = issuanceDate.toISOString()\n }\n const credentialPayload: CredentialPayload = {\n ...credential,\n '@context': credentialContext,\n type: credentialType,\n ...(isVdcm1 && { issuanceDate }),\n ...(isVdcm1 && expirationDate && { expirationDate }),\n ...(isVdcm2 && { validFrom: issuanceDate }),\n ...(isVdcm2 && expirationDate && { validUntil: expirationDate }),\n }\n if (isVdcm1) {\n delete credentialPayload.validFrom\n delete credentialPayload.validUntil\n } else if (isVdcm2) {\n delete credentialPayload.issuanceDate\n delete credentialPayload.expirationDate\n }\n\n // debug(JSON.stringify(credentialPayload))\n\n const issuer = extractIssuer(credentialPayload, { removeParameters: true })\n if (!issuer || typeof issuer === 'undefined') {\n throw new Error('invalid_argument: args.credential.issuer must not be empty')\n }\n return { credential: credentialPayload, issuer, now }\n}\n\nexport function preProcessPresentation(args: ICreateVerifiablePresentationLDArgs) {\n const { presentation, now = new Date() } = args\n const credentials = presentation?.verifiableCredential ?? []\n const v1Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V1))\n ? VCDM_CREDENTIAL_CONTEXT_V1\n : undefined\n const v2Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V2))\n ? VCDM_CREDENTIAL_CONTEXT_V2\n : undefined\n const presentationContext = addVcdmContextIfNeeded(\n args?.presentation?.['@context'] ?? [],\n v2Credential ?? v1Credential ?? VCDM_CREDENTIAL_CONTEXT_V2,\n )\n const presentationType = processEntryToArray(args?.presentation?.type, 'VerifiablePresentation')\n\n let issuanceDate = presentation?.validFrom ?? presentation?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()\n if (issuanceDate instanceof Date) {\n issuanceDate = issuanceDate.toISOString()\n }\n const presentationPayload: PresentationPayload = {\n ...presentation,\n '@context': presentationContext,\n type: presentationType,\n ...(v1Credential && { issuanceDate }), // V1 only for JWT, but we remove it in the jsonld processor anyway\n ...(v2Credential && { validFrom: issuanceDate }),\n }\n // Workaround for bug in TypeError: Cannot read property 'length' of undefined\n // at VeramoEd25519Signature2018.preSigningPresModification\n /*if (!presentation.verifier) {\n presentation.verifier = []\n }*/\n\n if (!isDefined(presentationPayload.holder) || !presentationPayload.holder) {\n throw new Error('invalid_argument: args.presentation.holderDID must not be empty')\n }\n if (presentationPayload.verifiableCredential) {\n presentationPayload.verifiableCredential = presentationPayload.verifiableCredential.map((cred) => {\n // map JWT credentials to their canonical form\n if (typeof cred !== 'string' && cred.proof.jwt) {\n return cred.proof.jwt\n } else {\n return cred\n }\n })\n }\n return { presentation: presentationPayload, holder: removeDIDParameters(presentationPayload.holder) }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;uBAAAA;EAAA;;;;;;;;;ACCA,6BAAgD;AAChD,mBAAmF;AAEnF,wBAKO;AAEP,kBAA6B;AAC7B,mBAAkB;AAElB,IAAMC,YAAQC,aAAAA,SAAM,+BAAA;AAOb,IAAMC,eAAe;;EAE1BC,IAAI;;EAEJC,IAAI;AACN;AAsBO,IAAMC,oBAAN,cAAgCC,8CAAAA;EA/CvC,OA+CuCA;;;EACrC,MAAMC,OAAOC,SAAkBC,SAAqC;AAClE,UAAMC,OAAOF,QAAQG,gBAAe;AAKpC,QAAID,MAAME,SAAS,SAASJ,QAAQK,KAAK;AACvC,YAAM,EAAEC,KAAI,IAAKN;A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vp","W3cMessageHandler","AbstractMessageHandler","handle","message","context","meta","getLastMetaData","type","raw","data","validateJwtPresentationPayload","presentation","normalizePresentation","credentials","verifiableCredential","id","computeEntryHash","from","holder","to","verifier","tag","threadId","createdAt","issuanceDate","presentations","e","validateJwtCredentialPayload","credential","normalizeCredential","issuer","credentialSubject","result","agent","verifyCredential","verified","uuidv4","extractIssuer","Error","error","verifyPresentation","challenge","domain","asArray","map","decodeCredentialToObject","import_ssi_types","import_debug","import_utils","extractIssuer","input","options","isDefined","payload","decodeJWT","split","iss","removeParameters","removeDIDParameters","e","issuer","holder","id","did","replace","pickSigningKey","identifier","kmsKeyRef","context","key","getKey","vmRelationship","isRevoked","credential","credentialStatus","agent","checkCredentialStatus","status","revoked","verified","Error","preProcessCredentialPayload","now","Date","credentialContext","addVcdmContextIfNeeded","isVdcm1","isVcdm1Credential","isVdcm2","isVcdm2Credential","credentialType","processEntryToArray","type","issuanceDate","validFrom","toISOString","expirationDate","validUntil","credentialPayload","preProcessPresentation","args","presentation","credentials","verifiableCredential","v1Credential","find","cred","includes","VCDM_CREDENTIAL_CONTEXT_V1","undefined","v2Credential","VCDM_CREDENTIAL_CONTEXT_V2","presentationContext","presentationType","presentationPayload","map","proof","jwt","debug","Debug","VcdmCredentialPlugin","methods","schema","components","schemas","ICredentialIssuer","ICredentialVerifier","issuers","constructor","options","listUsableProofFormats","bind","createVerifiableCredential","verifyCredential","createVerifiablePresentation","verifyPresentation","did","context","signingOptions","keys","key","issuer","matchKeyForType","push","getTypeProofFormat","args","proofFormat","credential","now","preProcessCredentialPayload","agent","didManagerGet","e","Error","findAndIssueCredential","canIssueCredentialType","map","i","join","verifiableCredential","error","Promise","reject","policies","verifiedCredential","verificationResult","findAndVerifyCredential","canVerifyDocumentType","document","uniform","CredentialMapper","toUniformCredential","JSON","stringify","type","asArray","proof","credentialStatus","isRevoked","results","partialSingleResult","Array","isArray","verified","log","result","message","errorCode","id","valid","presentation","preProcessPresentation","verifiablePresentation","findAndCreatePresentation","findAndVerifyPresentation","CredentialIssuer","VcdmCredentialPlugin"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/message-handler.ts","../src/vcdmCredentialPlugin.ts","../src/functions.ts"],"sourcesContent":["/**\n * Provides a {@link @veramo/credential-w3c#CredentialPlugin | plugin} for the {@link @veramo/core#Agent} that\n * implements\n * {@link @veramo/core#ICredentialIssuer} interface.\n *\n * Provides a {@link @veramo/credential-w3c#W3cMessageHandler | plugin} for the\n * {@link @veramo/message-handler#MessageHandler} that verifies Credentials and Presentations in a message.\n *\n * @packageDocumentation\n */\nexport type * from './types'\nexport { W3cMessageHandler, MessageTypes } from './message-handler'\nimport { VcdmCredentialPlugin } from './vcdmCredentialPlugin'\n\n/**\n * @deprecated please use {@link VcdmCredentialPlugin} instead\n * @public\n */\nconst CredentialIssuer = VcdmCredentialPlugin\nexport { CredentialIssuer, VcdmCredentialPlugin }\n\n// For backward compatibility, re-export the plugin types that were moved to core in v4\nexport type { ICredentialIssuer, ICredentialVerifier } from '@veramo/core'\n\nexport * from './functions'\n","import type { IAgentContext, ICredentialVerifier, IResolver, VerifiableCredential, VerifiablePresentation } from '@veramo/core'\nimport { AbstractMessageHandler, Message } from '@veramo/message-handler'\nimport { asArray, computeEntryHash, decodeCredentialToObject, extractIssuer } from '@veramo/utils'\n\nimport {\n normalizeCredential,\n normalizePresentation,\n validateJwtCredentialPayload,\n validateJwtPresentationPayload, // @ts-ignore\n} from 'did-jwt-vc'\n\nimport { v4 as uuidv4 } from 'uuid'\nimport Debug from 'debug'\n\nconst debug = Debug('sphereon:vcdm:message-handler')\n\n/**\n * These types are used by `@veramo/data-store` when storing Verifiable Credentials and Presentations\n *\n * @internal\n */\nexport const MessageTypes = {\n /** Represents a Verifiable Credential */\n vc: 'w3c.vc',\n /** Represents a Verifiable Presentation */\n vp: 'w3c.vp',\n}\n\n/**\n * Represents the requirements that this plugin has.\n * The agent that is using this plugin is expected to provide these methods.\n *\n * This interface can be used for static type checks, to make sure your application is properly initialized.\n */\nexport type IContext = IAgentContext<IResolver & ICredentialVerifier>\n\n/**\n * An implementation of the {@link @veramo/message-handler#AbstractMessageHandler}.\n *\n * This plugin can handle incoming W3C Verifiable Credentials and Presentations and prepare them\n * for internal storage as {@link @veramo/message-handler#Message} types.\n *\n * The current version can only handle `JWT` encoded\n *\n * @remarks {@link @veramo/core#IDataStore | IDataStore }\n *\n * @public\n */\nexport class W3cMessageHandler extends AbstractMessageHandler {\n async handle(message: Message, context: IContext): Promise<Message> {\n const meta = message.getLastMetaData()\n\n // console.log(JSON.stringify(message, null, 2))\n\n //FIXME: messages should not be expected to be only JWT\n if (meta?.type === 'JWT' && message.raw) {\n const { data } = message\n\n try {\n validateJwtPresentationPayload(data)\n\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vp)\n const presentation = normalizePresentation(message.raw)\n const credentials = presentation.verifiableCredential\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vp\n message.from = presentation.holder\n message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = credentials\n\n return message\n } catch (e) {}\n\n try {\n validateJwtCredentialPayload(data)\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vc)\n const credential = normalizeCredential(message.raw)\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vc\n message.from = credential.issuer.id\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } catch (e) {}\n }\n\n // LDS Verification and Handling\n if (message.type === MessageTypes.vc && message.data) {\n // verify credential\n const credential = message.data as VerifiableCredential\n\n const result = await context.agent.verifyCredential({ credential })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vc\n message.from = extractIssuer(credential)\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n if (message.type === MessageTypes.vp && message.data) {\n // verify presentation\n const presentation = message.data as VerifiablePresentation\n\n // throws on error.\n const result = await context.agent.verifyPresentation({\n presentation,\n // FIXME: HARDCODED CHALLENGE VERIFICATION FOR NOW\n challenge: 'VERAMO',\n domain: 'VERAMO',\n })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vp\n message.from = presentation.holder\n // message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n // message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = asArray(presentation.verifiableCredential).map(decodeCredentialToObject)\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n return super.handle(message, context)\n }\n}\n","import { asArray, type VerifiableCredentialSP, type VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'\nimport {\n CredentialMapper,\n IVerifyResult,\n IVerifySingleResultItem,\n OriginalVerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation\n} from '@sphereon/ssi-types'\nimport type { IAgentPlugin, IIdentifier, VerifiableCredential } from '@veramo/core'\nimport { schema } from '@veramo/core'\nimport Debug from 'debug'\nimport { isRevoked, preProcessCredentialPayload, preProcessPresentation } from './functions'\n\nimport type {\n ICreateVerifiableCredentialLDArgs,\n ICreateVerifiablePresentationLDArgs,\n IVcdmCredentialPlugin,\n IVcdmCredentialProvider,\n IVcdmIssuerAgentContext,\n IVcdmVerifierAgentContext,\n IVerifyCredentialVcdmArgs,\n IVerifyPresentationLDArgs\n} from './types'\n\nconst debug = Debug('sphereon:ssi-sdk:vcdm')\n\n/**\n * A plugin that implements the {@link @sphereon/ssi-sdk.credential-vcdm#IVcdmCredentialPlugin} methods.\n *\n * @public\n */\nexport class VcdmCredentialPlugin implements IAgentPlugin {\n readonly methods: IVcdmCredentialPlugin\n readonly schema = {\n components: {\n schemas: {\n ...schema.ICredentialIssuer.components.schemas,\n ...schema.ICredentialVerifier.components.schemas\n },\n methods: {\n ...schema.ICredentialIssuer.components.methods,\n ...schema.ICredentialVerifier.components.methods\n }\n }\n }\n private issuers: IVcdmCredentialProvider[]\n\n constructor(options: { issuers: IVcdmCredentialProvider[] }) {\n this.issuers = options.issuers\n this.methods = {\n listUsableProofFormats: this.listUsableProofFormats.bind(this),\n createVerifiableCredential: this.createVerifiableCredential.bind(this),\n verifyCredential: this.verifyCredential.bind(this),\n createVerifiablePresentation: this.createVerifiablePresentation.bind(this),\n verifyPresentation: this.verifyPresentation.bind(this)\n }\n }\n\n async listUsableProofFormats(did: IIdentifier, context: IVcdmIssuerAgentContext): Promise<string[]> {\n const signingOptions: string[] = []\n const keys = did.keys\n for (const key of keys) {\n for (const issuer of this.issuers) {\n if (issuer.matchKeyForType(key)) {\n signingOptions.push(issuer.getTypeProofFormat())\n }\n }\n }\n return signingOptions\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiableCredential} */\n async createVerifiableCredential(args: ICreateVerifiableCredentialLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiableCredentialSP> {\n let { proofFormat /* keyRef, removeOriginalFields, now , ...otherOptions */ } = args\n const { credential, issuer, now } = preProcessCredentialPayload(args)\n\n try {\n await context.agent.didManagerGet({ did: issuer })\n } catch (e) {\n throw new Error(`invalid_argument: credential.issuer must be a DID managed by this agent. ${e}`)\n }\n try {\n async function findAndIssueCredential(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiableCredential({ ...args, credential, now }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`\n )\n }\n\n const verifiableCredential = await findAndIssueCredential(this.issuers)\n return verifiableCredential\n } catch (error) {\n debug(error)\n return Promise.reject(error)\n }\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyCredential} */\n async verifyCredential(args: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { credential, policies /*, ...otherOptions*/ } = args\n let verifiedCredential: VerifiableCredential\n let verificationResult: IVerifyResult\n\n\n async function findAndVerifyCredential(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: credential as W3CVerifiableCredential })) {\n return issuer.verifyCredential(args, context)\n }\n }\n const uniform = CredentialMapper.toUniformCredential(args.credential as OriginalVerifiableCredential)\n return Promise.reject(\n Error(\n `invalid_setup: No verifier found for the provided credential credential\n type: ${JSON.stringify(uniform.type)} proof type \n ${asArray(uniform.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`\n )\n )\n }\n\n verificationResult = await findAndVerifyCredential(this.issuers)\n verifiedCredential = <VerifiableCredential>credential\n\n if (policies?.credentialStatus !== false && (await isRevoked(verifiedCredential, context as any))) {\n const results = verificationResult.results\n const partialSingleResult: Partial<IVerifySingleResultItem> = (Array.isArray(results) ? results[0] : {\n credential: credential as OriginalVerifiableCredential,\n verified: false,\n log: []\n })\n const result: IVerifySingleResultItem = {\n ...partialSingleResult,\n credential: credential as OriginalVerifiableCredential,\n verified: false,\n error: {\n message: 'revoked: The credential was revoked by the issuer',\n errorCode: 'revoked'\n },\n log: [...partialSingleResult.log ?? [], { id: 'revocation_status', valid: false }]\n }\n verificationResult = {\n ...verificationResult,\n verified: false,\n error: result.error,\n results: [\n result\n ]\n }\n }\n\n return verificationResult\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiablePresentation} */\n async createVerifiablePresentation(args: ICreateVerifiablePresentationLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiablePresentationSP> {\n const { proofFormat } = args\n const { presentation } = preProcessPresentation(args)\n\n let verifiablePresentation: VerifiablePresentationSP\n\n async function findAndCreatePresentation(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiablePresentation({ ...args, presentation }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`\n )\n }\n\n verifiablePresentation = await findAndCreatePresentation(this.issuers)\n return verifiablePresentation\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyPresentation} */\n async verifyPresentation(args: IVerifyPresentationLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { presentation /*domain, challenge, fetchRemoteContexts, policies, ...otherOptions*/ } = args\n\n async function findAndVerifyPresentation(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: presentation as W3CVerifiablePresentation })) {\n return issuer.verifyPresentation(args, context)\n }\n }\n throw new Error('invalid_setup: No verifier found for the provided presentation')\n }\n\n const result = await findAndVerifyPresentation(this.issuers)\n return result\n }\n}\n","import type {\n CredentialPayload,\n IAgentContext,\n ICredentialStatusVerifier,\n IDIDManager,\n IIdentifier,\n IResolver,\n IssuerType,\n PresentationPayload,\n VerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation,\n} from '@veramo/core'\nimport { _ExtendedIKey, isDefined, processEntryToArray } from '@veramo/utils'\nimport { decodeJWT } from 'did-jwt'\nimport {\n addVcdmContextIfNeeded,\n isVcdm1Credential,\n isVcdm2Credential,\n VCDM_CREDENTIAL_CONTEXT_V1,\n VCDM_CREDENTIAL_CONTEXT_V2,\n} from '@sphereon/ssi-types'\nimport { ICreateVerifiablePresentationLDArgs } from './types'\nimport { getKey } from '@sphereon/ssi-sdk-ext.did-utils'\n\n/**\n * Decodes a credential or presentation and returns the issuer ID\n * `iss` from a JWT or `issuer`/`issuer.id` from a VC or `holder` from a VP\n *\n * @param input - the credential or presentation whose issuer/holder needs to be extracted.\n * @param options - options for the extraction\n * removeParameters - Remove all DID parameters from the issuer ID\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function extractIssuer(\n input?: W3CVerifiableCredential | W3CVerifiablePresentation | CredentialPayload | PresentationPayload | null,\n options: { removeParameters?: boolean } = {},\n): string {\n if (!isDefined(input)) {\n return ''\n } else if (typeof input === 'string') {\n // JWT\n try {\n const { payload } = decodeJWT(input.split(`~`)[0])\n const iss = payload.iss ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n } catch (e: any) {\n return ''\n }\n } else {\n // JSON\n let iss: IssuerType\n if (input.issuer) {\n iss = input.issuer\n } else if (input.holder) {\n iss = input.holder\n } else {\n iss = ''\n }\n if (typeof iss !== 'string') iss = iss.id ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n }\n}\n\n/**\n * Remove all DID parameters from a DID url after the query part (?)\n *\n * @param did - the DID URL\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function removeDIDParameters(did: string): string {\n return did.replace(/\\?.*$/, '')\n}\n\nexport async function pickSigningKey(\n { identifier, kmsKeyRef }: { identifier: IIdentifier; kmsKeyRef?: string },\n context: IAgentContext<IResolver & IDIDManager>,\n): Promise<_ExtendedIKey> {\n const key = await getKey({ identifier, vmRelationship: 'assertionMethod', kmsKeyRef: kmsKeyRef }, context)\n return key\n}\n\nexport async function isRevoked(credential: VerifiableCredential, context: IAgentContext<ICredentialStatusVerifier>): Promise<boolean> {\n if (!credential.credentialStatus) return false\n\n if (typeof context.agent.checkCredentialStatus === 'function') {\n const status = await context.agent.checkCredentialStatus({ credential })\n return status?.revoked == true || status?.verified === false\n }\n\n throw new Error(`invalid_setup: The credential status can't be verified because there is no ICredentialStatusVerifier plugin installed.`)\n}\n\nexport function preProcessCredentialPayload({ credential, now = new Date() }: { credential: CredentialPayload; now?: number | Date }) {\n const credentialContext = addVcdmContextIfNeeded(credential?.['@context'])\n const isVdcm1 = isVcdm1Credential(credential)\n const isVdcm2 = isVcdm2Credential(credential)\n const credentialType = processEntryToArray(credential?.type, 'VerifiableCredential')\n let issuanceDate = credential?.validFrom ?? credential?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()\n let expirationDate = credential?.validUntil ?? credential?.expirationDate\n if (issuanceDate instanceof Date) {\n issuanceDate = issuanceDate.toISOString()\n }\n const credentialPayload: CredentialPayload = {\n ...credential,\n '@context': credentialContext,\n type: credentialType,\n ...(isVdcm1 && { issuanceDate }),\n ...(isVdcm1 && expirationDate && { expirationDate }),\n ...(isVdcm2 && { validFrom: issuanceDate }),\n ...(isVdcm2 && expirationDate && { validUntil: expirationDate }),\n }\n if (isVdcm1) {\n delete credentialPayload.validFrom\n delete credentialPayload.validUntil\n } else if (isVdcm2) {\n delete credentialPayload.issuanceDate\n delete credentialPayload.expirationDate\n }\n\n // debug(JSON.stringify(credentialPayload))\n\n const issuer = extractIssuer(credentialPayload, { removeParameters: true })\n if (!issuer || typeof issuer === 'undefined') {\n throw new Error('invalid_argument: args.credential.issuer must not be empty')\n }\n return { credential: credentialPayload, issuer, now }\n}\n\nexport function preProcessPresentation(args: ICreateVerifiablePresentationLDArgs) {\n const { presentation, now = new Date() } = args\n const credentials = presentation?.verifiableCredential ?? []\n const v1Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V1))\n ? VCDM_CREDENTIAL_CONTEXT_V1\n : undefined\n const v2Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V2))\n ? VCDM_CREDENTIAL_CONTEXT_V2\n : undefined\n const presentationContext = addVcdmContextIfNeeded(\n args?.presentation?.['@context'] ?? [],\n v2Credential ?? v1Credential ?? VCDM_CREDENTIAL_CONTEXT_V2,\n )\n const presentationType = processEntryToArray(args?.presentation?.type, 'VerifiablePresentation')\n\n let issuanceDate = presentation?.validFrom ?? presentation?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()\n if (issuanceDate instanceof Date) {\n issuanceDate = issuanceDate.toISOString()\n }\n const presentationPayload: PresentationPayload = {\n ...presentation,\n '@context': presentationContext,\n type: presentationType,\n ...(v1Credential && { issuanceDate }), // V1 only for JWT, but we remove it in the jsonld processor anyway\n ...(v2Credential && { validFrom: issuanceDate }),\n }\n // Workaround for bug in TypeError: Cannot read property 'length' of undefined\n // at VeramoEd25519Signature2018.preSigningPresModification\n /*if (!presentation.verifier) {\n presentation.verifier = []\n }*/\n\n if (!isDefined(presentationPayload.holder) || !presentationPayload.holder) {\n throw new Error('invalid_argument: args.presentation.holderDID must not be empty')\n }\n if (presentationPayload.verifiableCredential) {\n presentationPayload.verifiableCredential = presentationPayload.verifiableCredential.map((cred) => {\n // map JWT credentials to their canonical form\n if (typeof cred !== 'string' && cred.proof.jwt) {\n return cred.proof.jwt\n } else {\n return cred\n }\n })\n }\n return { presentation: presentationPayload, holder: removeDIDParameters(presentationPayload.holder) }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;uBAAAA;EAAA;;;;;;;;;ACCA,6BAAgD;AAChD,mBAAmF;AAEnF,wBAKO;AAEP,kBAA6B;AAC7B,mBAAkB;AAElB,IAAMC,YAAQC,aAAAA,SAAM,+BAAA;AAOb,IAAMC,eAAe;;EAE1BC,IAAI;;EAEJC,IAAI;AACN;AAsBO,IAAMC,oBAAN,cAAgCC,8CAAAA;EA/CvC,OA+CuCA;;;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;AAC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BAAqB;QACnB,GAAGA;QACHkB,UAAU;QACVvB,OAAOyB,OAAOzB;QACdmB,SAAS;UACPM;;MAEJ;IACF;AAEA,WAAOpB;EACT;;EAGA,MAAM/B,6BAA6BW,MAA2CR,SAAqE;AACjJ,UAAM,EAAES,YAAW,IAAKD;AACxB,UAAM,EAAE6C,aAAY,IAAKC,uBAAuB9C,IAAAA;AAEhD,QAAI+C;AAEJ,mBAAeC,0BAA0BjE,SAAkC;AACzE,iBAAWa,UAAUb,SAAS;AAC5B,YAAIa,OAAOc,uBAAuB;UAAET;QAAY,CAAA,GAAI;AAClD,iBAAO,MAAML,OAAOP,6BAA6B;YAAE,GAAGW;YAAM6C;UAAa,GAAGrD,OAAAA;QAC9E;MACF;AACA,YAAM,IAAIgB,MACR,kEAAkEP,WAAAA,gBAA2BlB,QAAQ4B,IAAI,CAACC,MAAMA,EAAEb,mBAAkB,CAAA,EAAIc,KAAK,GAAA,CAAA,EAAM;IAEvJ;AATemC;AAWfD,6BAAyB,MAAMC,0BAA0B,KAAKjE,OAAO;AACrE,WAAOgE;EACT;;EAGA,MAAMzD,mBAAmBU,MAAiCR,SAA4D;AACpH,QAAI;MAAEqD;;IAAgF,IAAO7C;AAE7F,mBAAeiD,0BAA0BlE,SAAkC;AACzE,iBAAWa,UAAUb,SAAS;AAC5B,YAAIa,OAAO0B,sBAAsB;UAAEC,UAAUsB;QAA0C,CAAA,GAAI;AACzF,iBAAOjD,OAAON,mBAAmBU,MAAMR,OAAAA;QACzC;MACF;AACA,YAAM,IAAIgB,MAAM,gEAAA;IAClB;AAPeyC;AASf,UAAMT,SAAS,MAAMS,0BAA0B,KAAKlE,OAAO;AAC3D,WAAOyD;EACT;AACF;;;AFlLA,IAAMU,mBAAmBC;","names":["extractIssuer","debug","Debug","MessageTypes","vc","vp","W3cMessageHandler","AbstractMessageHandler","handle","message","context","meta","getLastMetaData","type","raw","data","validateJwtPresentationPayload","presentation","normalizePresentation","credentials","verifiableCredential","id","computeEntryHash","from","holder","to","verifier","tag","threadId","createdAt","issuanceDate","presentations","e","validateJwtCredentialPayload","credential","normalizeCredential","issuer","credentialSubject","result","agent","verifyCredential","verified","uuidv4","extractIssuer","Error","error","verifyPresentation","challenge","domain","asArray","map","decodeCredentialToObject","import_ssi_types","import_debug","import_utils","extractIssuer","input","options","isDefined","payload","decodeJWT","split","iss","removeParameters","removeDIDParameters","e","issuer","holder","id","did","replace","pickSigningKey","identifier","kmsKeyRef","context","key","getKey","vmRelationship","isRevoked","credential","credentialStatus","agent","checkCredentialStatus","status","revoked","verified","Error","preProcessCredentialPayload","now","Date","credentialContext","addVcdmContextIfNeeded","isVdcm1","isVcdm1Credential","isVdcm2","isVcdm2Credential","credentialType","processEntryToArray","type","issuanceDate","validFrom","toISOString","expirationDate","validUntil","credentialPayload","preProcessPresentation","args","presentation","credentials","verifiableCredential","v1Credential","find","cred","includes","VCDM_CREDENTIAL_CONTEXT_V1","undefined","v2Credential","VCDM_CREDENTIAL_CONTEXT_V2","presentationContext","presentationType","presentationPayload","map","proof","jwt","debug","Debug","VcdmCredentialPlugin","methods","schema","components","schemas","ICredentialIssuer","ICredentialVerifier","issuers","options","listUsableProofFormats","bind","createVerifiableCredential","verifyCredential","createVerifiablePresentation","verifyPresentation","did","context","signingOptions","keys","key","issuer","matchKeyForType","push","getTypeProofFormat","args","proofFormat","credential","now","preProcessCredentialPayload","agent","didManagerGet","e","Error","findAndIssueCredential","canIssueCredentialType","map","i","join","verifiableCredential","error","Promise","reject","policies","verifiedCredential","verificationResult","findAndVerifyCredential","canVerifyDocumentType","document","uniform","CredentialMapper","toUniformCredential","JSON","stringify","type","asArray","proof","credentialStatus","isRevoked","results","partialSingleResult","Array","isArray","verified","log","result","message","errorCode","id","valid","presentation","preProcessPresentation","verifiablePresentation","findAndCreatePresentation","findAndVerifyPresentation","CredentialIssuer","VcdmCredentialPlugin"]}
package/dist/index.d.cts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { IPluginMethodMap, PresentationPayload, IAgentContext, IResolver, IDIDManager, IKeyManager, CredentialPayload, VerificationPolicies, IKey, ICredentialVerifier, IAgentPlugin, IIdentifier, W3CVerifiableCredential as W3CVerifiableCredential$1, W3CVerifiablePresentation as W3CVerifiablePresentation$1, VerifiableCredential, ICredentialStatusVerifier } from '@veramo/core';
2
2
  export { ICredentialIssuer, ICredentialVerifier } from '@veramo/core';
3
3
  import { VerifiablePresentationSP, VerifiableCredentialSP } from '@sphereon/ssi-sdk.core';
4
- import { IIssueCredentialStatusOpts } from '@sphereon/ssi-sdk.vc-status-list';
4
+ import { StatusListOpts } from '@sphereon/oid4vci-common';
5
5
  import { OriginalVerifiableCredential, ICredential, IVerifyResult, W3CVerifiablePresentation, W3CVerifiableCredential } from '@sphereon/ssi-types';
6
+ import { DataSource } from 'typeorm';
6
7
  import { AbstractMessageHandler, Message } from '@veramo/message-handler';
7
8
  import { _ExtendedIKey } from '@veramo/utils';
8
9
 
@@ -81,6 +82,15 @@ interface ICreateVerifiablePresentationLDArgs {
81
82
  */
82
83
  now?: Date | number;
83
84
  }
85
+ /**
86
+ * Statuslist credential options, cloned from packages/vc-status-list/src/types/index.ts to break cyclic dependency loop
87
+ */
88
+ interface IIssueCredentialStatusOpts {
89
+ dataSource?: DataSource;
90
+ statusLists?: Array<StatusListOpts>;
91
+ credentialId?: string;
92
+ value?: string;
93
+ }
84
94
  /**
85
95
  * Encapsulates the parameters required to create a
86
96
  * {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential}
@@ -561,4 +571,4 @@ declare function preProcessPresentation(args: ICreateVerifiablePresentationLDArg
561
571
  */
562
572
  declare const CredentialIssuer: typeof VcdmCredentialPlugin;
563
573
 
564
- export { type ContextDoc, CredentialIssuer, type IAssertionProofPurpose, type IAuthenticationProofPurpose, type ICanIssueCredentialTypeArgs, type ICanVerifyDocumentTypeArgs, type IControllerProofPurpose, type ICreateVerifiableCredentialLDArgs, type ICreateVerifiablePresentationLDArgs, type IProofPurpose, type IVcdmCredentialIssuer, type IVcdmCredentialPlugin, type IVcdmCredentialProvider, type IVcdmCredentialVerifier, type IVcdmIssuerAgentContext, type IVcdmVerifierAgentContext, type IVerifyCredentialVcdmArgs, type IVerifyPresentationLDArgs, MessageTypes, type StatusListCheck, VcdmCredentialPlugin, W3cMessageHandler, extractIssuer, isRevoked, pickSigningKey, preProcessCredentialPayload, preProcessPresentation, removeDIDParameters };
574
+ export { type ContextDoc, CredentialIssuer, type IAssertionProofPurpose, type IAuthenticationProofPurpose, type ICanIssueCredentialTypeArgs, type ICanVerifyDocumentTypeArgs, type IControllerProofPurpose, type ICreateVerifiableCredentialLDArgs, type ICreateVerifiablePresentationLDArgs, type IIssueCredentialStatusOpts, type IProofPurpose, type IVcdmCredentialIssuer, type IVcdmCredentialPlugin, type IVcdmCredentialProvider, type IVcdmCredentialVerifier, type IVcdmIssuerAgentContext, type IVcdmVerifierAgentContext, type IVerifyCredentialVcdmArgs, type IVerifyPresentationLDArgs, MessageTypes, type StatusListCheck, VcdmCredentialPlugin, W3cMessageHandler, extractIssuer, isRevoked, pickSigningKey, preProcessCredentialPayload, preProcessPresentation, removeDIDParameters };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { IPluginMethodMap, PresentationPayload, IAgentContext, IResolver, IDIDManager, IKeyManager, CredentialPayload, VerificationPolicies, IKey, ICredentialVerifier, IAgentPlugin, IIdentifier, W3CVerifiableCredential as W3CVerifiableCredential$1, W3CVerifiablePresentation as W3CVerifiablePresentation$1, VerifiableCredential, ICredentialStatusVerifier } from '@veramo/core';
2
2
  export { ICredentialIssuer, ICredentialVerifier } from '@veramo/core';
3
3
  import { VerifiablePresentationSP, VerifiableCredentialSP } from '@sphereon/ssi-sdk.core';
4
- import { IIssueCredentialStatusOpts } from '@sphereon/ssi-sdk.vc-status-list';
4
+ import { StatusListOpts } from '@sphereon/oid4vci-common';
5
5
  import { OriginalVerifiableCredential, ICredential, IVerifyResult, W3CVerifiablePresentation, W3CVerifiableCredential } from '@sphereon/ssi-types';
6
+ import { DataSource } from 'typeorm';
6
7
  import { AbstractMessageHandler, Message } from '@veramo/message-handler';
7
8
  import { _ExtendedIKey } from '@veramo/utils';
8
9
 
@@ -81,6 +82,15 @@ interface ICreateVerifiablePresentationLDArgs {
81
82
  */
82
83
  now?: Date | number;
83
84
  }
85
+ /**
86
+ * Statuslist credential options, cloned from packages/vc-status-list/src/types/index.ts to break cyclic dependency loop
87
+ */
88
+ interface IIssueCredentialStatusOpts {
89
+ dataSource?: DataSource;
90
+ statusLists?: Array<StatusListOpts>;
91
+ credentialId?: string;
92
+ value?: string;
93
+ }
84
94
  /**
85
95
  * Encapsulates the parameters required to create a
86
96
  * {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential}
@@ -561,4 +571,4 @@ declare function preProcessPresentation(args: ICreateVerifiablePresentationLDArg
561
571
  */
562
572
  declare const CredentialIssuer: typeof VcdmCredentialPlugin;
563
573
 
564
- export { type ContextDoc, CredentialIssuer, type IAssertionProofPurpose, type IAuthenticationProofPurpose, type ICanIssueCredentialTypeArgs, type ICanVerifyDocumentTypeArgs, type IControllerProofPurpose, type ICreateVerifiableCredentialLDArgs, type ICreateVerifiablePresentationLDArgs, type IProofPurpose, type IVcdmCredentialIssuer, type IVcdmCredentialPlugin, type IVcdmCredentialProvider, type IVcdmCredentialVerifier, type IVcdmIssuerAgentContext, type IVcdmVerifierAgentContext, type IVerifyCredentialVcdmArgs, type IVerifyPresentationLDArgs, MessageTypes, type StatusListCheck, VcdmCredentialPlugin, W3cMessageHandler, extractIssuer, isRevoked, pickSigningKey, preProcessCredentialPayload, preProcessPresentation, removeDIDParameters };
574
+ export { type ContextDoc, CredentialIssuer, type IAssertionProofPurpose, type IAuthenticationProofPurpose, type ICanIssueCredentialTypeArgs, type ICanVerifyDocumentTypeArgs, type IControllerProofPurpose, type ICreateVerifiableCredentialLDArgs, type ICreateVerifiablePresentationLDArgs, type IIssueCredentialStatusOpts, type IProofPurpose, type IVcdmCredentialIssuer, type IVcdmCredentialPlugin, type IVcdmCredentialProvider, type IVcdmCredentialVerifier, type IVcdmIssuerAgentContext, type IVcdmVerifierAgentContext, type IVerifyCredentialVcdmArgs, type IVerifyPresentationLDArgs, MessageTypes, type StatusListCheck, VcdmCredentialPlugin, W3cMessageHandler, extractIssuer, isRevoked, pickSigningKey, preProcessCredentialPayload, preProcessPresentation, removeDIDParameters };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/message-handler.ts","../src/vcdmCredentialPlugin.ts","../src/functions.ts","../src/index.ts"],"sourcesContent":["import type { IAgentContext, ICredentialVerifier, IResolver, VerifiableCredential, VerifiablePresentation } from '@veramo/core'\nimport { AbstractMessageHandler, Message } from '@veramo/message-handler'\nimport { asArray, computeEntryHash, decodeCredentialToObject, extractIssuer } from '@veramo/utils'\n\nimport {\n normalizeCredential,\n normalizePresentation,\n validateJwtCredentialPayload,\n validateJwtPresentationPayload, // @ts-ignore\n} from 'did-jwt-vc'\n\nimport { v4 as uuidv4 } from 'uuid'\nimport Debug from 'debug'\n\nconst debug = Debug('sphereon:vcdm:message-handler')\n\n/**\n * These types are used by `@veramo/data-store` when storing Verifiable Credentials and Presentations\n *\n * @internal\n */\nexport const MessageTypes = {\n /** Represents a Verifiable Credential */\n vc: 'w3c.vc',\n /** Represents a Verifiable Presentation */\n vp: 'w3c.vp',\n}\n\n/**\n * Represents the requirements that this plugin has.\n * The agent that is using this plugin is expected to provide these methods.\n *\n * This interface can be used for static type checks, to make sure your application is properly initialized.\n */\nexport type IContext = IAgentContext<IResolver & ICredentialVerifier>\n\n/**\n * An implementation of the {@link @veramo/message-handler#AbstractMessageHandler}.\n *\n * This plugin can handle incoming W3C Verifiable Credentials and Presentations and prepare them\n * for internal storage as {@link @veramo/message-handler#Message} types.\n *\n * The current version can only handle `JWT` encoded\n *\n * @remarks {@link @veramo/core#IDataStore | IDataStore }\n *\n * @public\n */\nexport class W3cMessageHandler extends AbstractMessageHandler {\n async handle(message: Message, context: IContext): Promise<Message> {\n const meta = message.getLastMetaData()\n\n // console.log(JSON.stringify(message, null, 2))\n\n //FIXME: messages should not be expected to be only JWT\n if (meta?.type === 'JWT' && message.raw) {\n const { data } = message\n\n try {\n validateJwtPresentationPayload(data)\n\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vp)\n const presentation = normalizePresentation(message.raw)\n const credentials = presentation.verifiableCredential\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vp\n message.from = presentation.holder\n message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = credentials\n\n return message\n } catch (e) {}\n\n try {\n validateJwtCredentialPayload(data)\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vc)\n const credential = normalizeCredential(message.raw)\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vc\n message.from = credential.issuer.id\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } catch (e) {}\n }\n\n // LDS Verification and Handling\n if (message.type === MessageTypes.vc && message.data) {\n // verify credential\n const credential = message.data as VerifiableCredential\n\n const result = await context.agent.verifyCredential({ credential })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vc\n message.from = extractIssuer(credential)\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n if (message.type === MessageTypes.vp && message.data) {\n // verify presentation\n const presentation = message.data as VerifiablePresentation\n\n // throws on error.\n const result = await context.agent.verifyPresentation({\n presentation,\n // FIXME: HARDCODED CHALLENGE VERIFICATION FOR NOW\n challenge: 'VERAMO',\n domain: 'VERAMO',\n })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vp\n message.from = presentation.holder\n // message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n // message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = asArray(presentation.verifiableCredential).map(decodeCredentialToObject)\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n return super.handle(message, context)\n }\n}\n","import { asArray, type VerifiableCredentialSP, type VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'\nimport {\n CredentialMapper,\n IVerifyResult,\n IVerifySingleResultItem,\n OriginalVerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation\n} from '@sphereon/ssi-types'\nimport type { IAgentPlugin, IIdentifier, VerifiableCredential } from '@veramo/core'\nimport { schema } from '@veramo/core'\nimport Debug from 'debug'\nimport { isRevoked, preProcessCredentialPayload, preProcessPresentation } from './functions'\n\nimport type {\n ICreateVerifiableCredentialLDArgs,\n ICreateVerifiablePresentationLDArgs,\n IVcdmCredentialPlugin,\n IVcdmCredentialProvider,\n IVcdmIssuerAgentContext,\n IVcdmVerifierAgentContext,\n IVerifyCredentialVcdmArgs,\n IVerifyPresentationLDArgs\n} from './types'\n\nconst debug = Debug('sphereon:ssi-sdk:vcdm')\n\n/**\n * A plugin that implements the {@link @sphereon/ssi-sdk.credential-vcdm#IVcdmCredentialPlugin} methods.\n *\n * @public\n */\nexport class VcdmCredentialPlugin implements IAgentPlugin {\n readonly methods: IVcdmCredentialPlugin\n readonly schema = {\n components: {\n schemas: {\n ...schema.ICredentialIssuer.components.schemas,\n ...schema.ICredentialVerifier.components.schemas\n },\n methods: {\n ...schema.ICredentialIssuer.components.methods,\n ...schema.ICredentialVerifier.components.methods\n }\n }\n }\n private issuers: IVcdmCredentialProvider[]\n\n constructor(options: { issuers: IVcdmCredentialProvider[] }) {\n this.issuers = options.issuers\n this.methods = {\n listUsableProofFormats: this.listUsableProofFormats.bind(this),\n createVerifiableCredential: this.createVerifiableCredential.bind(this),\n verifyCredential: this.verifyCredential.bind(this),\n createVerifiablePresentation: this.createVerifiablePresentation.bind(this),\n verifyPresentation: this.verifyPresentation.bind(this)\n }\n }\n\n async listUsableProofFormats(did: IIdentifier, context: IVcdmIssuerAgentContext): Promise<string[]> {\n const signingOptions: string[] = []\n const keys = did.keys\n for (const key of keys) {\n for (const issuer of this.issuers) {\n if (issuer.matchKeyForType(key)) {\n signingOptions.push(issuer.getTypeProofFormat())\n }\n }\n }\n return signingOptions\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiableCredential} */\n async createVerifiableCredential(args: ICreateVerifiableCredentialLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiableCredentialSP> {\n let { proofFormat /* keyRef, removeOriginalFields, now , ...otherOptions */ } = args\n const { credential, issuer, now } = preProcessCredentialPayload(args)\n\n try {\n await context.agent.didManagerGet({ did: issuer })\n } catch (e) {\n throw new Error(`invalid_argument: credential.issuer must be a DID managed by this agent. ${e}`)\n }\n try {\n async function findAndIssueCredential(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiableCredential({ ...args, credential, now }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`\n )\n }\n\n const verifiableCredential = await findAndIssueCredential(this.issuers)\n return verifiableCredential\n } catch (error) {\n debug(error)\n return Promise.reject(error)\n }\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyCredential} */\n async verifyCredential(args: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { credential, policies /*, ...otherOptions*/ } = args\n let verifiedCredential: VerifiableCredential\n let verificationResult: IVerifyResult\n\n\n async function findAndVerifyCredential(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: credential as W3CVerifiableCredential })) {\n return issuer.verifyCredential(args, context)\n }\n }\n const uniform = CredentialMapper.toUniformCredential(args.credential as OriginalVerifiableCredential)\n return Promise.reject(\n Error(\n `invalid_setup: No verifier found for the provided credential credential\n type: ${JSON.stringify(uniform.type)} proof type \n ${asArray(uniform.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`\n )\n )\n }\n\n verificationResult = await findAndVerifyCredential(this.issuers)\n verifiedCredential = <VerifiableCredential>credential\n\n if (policies?.credentialStatus !== false && (await isRevoked(verifiedCredential, context as any))) {\n const results = verificationResult.results\n const partialSingleResult: Partial<IVerifySingleResultItem> = (Array.isArray(results) ? results[0] : {\n credential: credential as OriginalVerifiableCredential,\n verified: false,\n log: []\n })\n const result: IVerifySingleResultItem = {\n ...partialSingleResult,\n credential: credential as OriginalVerifiableCredential,\n verified: false,\n error: {\n message: 'revoked: The credential was revoked by the issuer',\n errorCode: 'revoked'\n },\n log: [...partialSingleResult.log ?? [], { id: 'revocation_status', valid: false }]\n }\n verificationResult = {\n ...verificationResult,\n verified: false,\n error: result.error,\n results: [\n result\n ]\n }\n }\n\n return verificationResult\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiablePresentation} */\n async createVerifiablePresentation(args: ICreateVerifiablePresentationLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiablePresentationSP> {\n const { proofFormat } = args\n const { presentation } = preProcessPresentation(args)\n\n let verifiablePresentation: VerifiablePresentationSP\n\n async function findAndCreatePresentation(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiablePresentation({ ...args, presentation }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`\n )\n }\n\n verifiablePresentation = await findAndCreatePresentation(this.issuers)\n return verifiablePresentation\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyPresentation} */\n async verifyPresentation(args: IVerifyPresentationLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { presentation /*domain, challenge, fetchRemoteContexts, policies, ...otherOptions*/ } = args\n\n async function findAndVerifyPresentation(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: presentation as W3CVerifiablePresentation })) {\n return issuer.verifyPresentation(args, context)\n }\n }\n throw new Error('invalid_setup: No verifier found for the provided presentation')\n }\n\n const result = await findAndVerifyPresentation(this.issuers)\n return result\n }\n}\n","import type {\n CredentialPayload,\n IAgentContext,\n ICredentialStatusVerifier,\n IDIDManager,\n IIdentifier,\n IResolver,\n IssuerType,\n PresentationPayload,\n VerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation,\n} from '@veramo/core'\nimport { _ExtendedIKey, isDefined, processEntryToArray } from '@veramo/utils'\nimport { decodeJWT } from 'did-jwt'\nimport {\n addVcdmContextIfNeeded,\n isVcdm1Credential,\n isVcdm2Credential,\n VCDM_CREDENTIAL_CONTEXT_V1,\n VCDM_CREDENTIAL_CONTEXT_V2,\n} from '@sphereon/ssi-types'\nimport { ICreateVerifiablePresentationLDArgs } from './types'\nimport { getKey } from '@sphereon/ssi-sdk-ext.did-utils'\n\n/**\n * Decodes a credential or presentation and returns the issuer ID\n * `iss` from a JWT or `issuer`/`issuer.id` from a VC or `holder` from a VP\n *\n * @param input - the credential or presentation whose issuer/holder needs to be extracted.\n * @param options - options for the extraction\n * removeParameters - Remove all DID parameters from the issuer ID\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function extractIssuer(\n input?: W3CVerifiableCredential | W3CVerifiablePresentation | CredentialPayload | PresentationPayload | null,\n options: { removeParameters?: boolean } = {},\n): string {\n if (!isDefined(input)) {\n return ''\n } else if (typeof input === 'string') {\n // JWT\n try {\n const { payload } = decodeJWT(input.split(`~`)[0])\n const iss = payload.iss ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n } catch (e: any) {\n return ''\n }\n } else {\n // JSON\n let iss: IssuerType\n if (input.issuer) {\n iss = input.issuer\n } else if (input.holder) {\n iss = input.holder\n } else {\n iss = ''\n }\n if (typeof iss !== 'string') iss = iss.id ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n }\n}\n\n/**\n * Remove all DID parameters from a DID url after the query part (?)\n *\n * @param did - the DID URL\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function removeDIDParameters(did: string): string {\n return did.replace(/\\?.*$/, '')\n}\n\nexport async function pickSigningKey(\n { identifier, kmsKeyRef }: { identifier: IIdentifier; kmsKeyRef?: string },\n context: IAgentContext<IResolver & IDIDManager>,\n): Promise<_ExtendedIKey> {\n const key = await getKey({ identifier, vmRelationship: 'assertionMethod', kmsKeyRef: kmsKeyRef }, context)\n return key\n}\n\nexport async function isRevoked(credential: VerifiableCredential, context: IAgentContext<ICredentialStatusVerifier>): Promise<boolean> {\n if (!credential.credentialStatus) return false\n\n if (typeof context.agent.checkCredentialStatus === 'function') {\n const status = await context.agent.checkCredentialStatus({ credential })\n return status?.revoked == true || status?.verified === false\n }\n\n throw new Error(`invalid_setup: The credential status can't be verified because there is no ICredentialStatusVerifier plugin installed.`)\n}\n\nexport function preProcessCredentialPayload({ credential, now = new Date() }: { credential: CredentialPayload; now?: number | Date }) {\n const credentialContext = addVcdmContextIfNeeded(credential?.['@context'])\n const isVdcm1 = isVcdm1Credential(credential)\n const isVdcm2 = isVcdm2Credential(credential)\n const credentialType = processEntryToArray(credential?.type, 'VerifiableCredential')\n let issuanceDate = credential?.validFrom ?? credential?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()\n let expirationDate = credential?.validUntil ?? credential?.expirationDate\n if (issuanceDate instanceof Date) {\n issuanceDate = issuanceDate.toISOString()\n }\n const credentialPayload: CredentialPayload = {\n ...credential,\n '@context': credentialContext,\n type: credentialType,\n ...(isVdcm1 && { issuanceDate }),\n ...(isVdcm1 && expirationDate && { expirationDate }),\n ...(isVdcm2 && { validFrom: issuanceDate }),\n ...(isVdcm2 && expirationDate && { validUntil: expirationDate }),\n }\n if (isVdcm1) {\n delete credentialPayload.validFrom\n delete credentialPayload.validUntil\n } else if (isVdcm2) {\n delete credentialPayload.issuanceDate\n delete credentialPayload.expirationDate\n }\n\n // debug(JSON.stringify(credentialPayload))\n\n const issuer = extractIssuer(credentialPayload, { removeParameters: true })\n if (!issuer || typeof issuer === 'undefined') {\n throw new Error('invalid_argument: args.credential.issuer must not be empty')\n }\n return { credential: credentialPayload, issuer, now }\n}\n\nexport function preProcessPresentation(args: ICreateVerifiablePresentationLDArgs) {\n const { presentation, now = new Date() } = args\n const credentials = presentation?.verifiableCredential ?? []\n const v1Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V1))\n ? VCDM_CREDENTIAL_CONTEXT_V1\n : undefined\n const v2Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V2))\n ? VCDM_CREDENTIAL_CONTEXT_V2\n : undefined\n const presentationContext = addVcdmContextIfNeeded(\n args?.presentation?.['@context'] ?? [],\n v2Credential ?? v1Credential ?? VCDM_CREDENTIAL_CONTEXT_V2,\n )\n const presentationType = processEntryToArray(args?.presentation?.type, 'VerifiablePresentation')\n\n let issuanceDate = presentation?.validFrom ?? presentation?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()\n if (issuanceDate instanceof Date) {\n issuanceDate = issuanceDate.toISOString()\n }\n const presentationPayload: PresentationPayload = {\n ...presentation,\n '@context': presentationContext,\n type: presentationType,\n ...(v1Credential && { issuanceDate }), // V1 only for JWT, but we remove it in the jsonld processor anyway\n ...(v2Credential && { validFrom: issuanceDate }),\n }\n // Workaround for bug in TypeError: Cannot read property 'length' of undefined\n // at VeramoEd25519Signature2018.preSigningPresModification\n /*if (!presentation.verifier) {\n presentation.verifier = []\n }*/\n\n if (!isDefined(presentationPayload.holder) || !presentationPayload.holder) {\n throw new Error('invalid_argument: args.presentation.holderDID must not be empty')\n }\n if (presentationPayload.verifiableCredential) {\n presentationPayload.verifiableCredential = presentationPayload.verifiableCredential.map((cred) => {\n // map JWT credentials to their canonical form\n if (typeof cred !== 'string' && cred.proof.jwt) {\n return cred.proof.jwt\n } else {\n return cred\n }\n })\n }\n return { presentation: presentationPayload, holder: removeDIDParameters(presentationPayload.holder) }\n}\n","/**\n * Provides a {@link @veramo/credential-w3c#CredentialPlugin | plugin} for the {@link @veramo/core#Agent} that\n * implements\n * {@link @veramo/core#ICredentialIssuer} interface.\n *\n * Provides a {@link @veramo/credential-w3c#W3cMessageHandler | plugin} for the\n * {@link @veramo/message-handler#MessageHandler} that verifies Credentials and Presentations in a message.\n *\n * @packageDocumentation\n */\nexport type * from './types'\nexport { W3cMessageHandler, MessageTypes } from './message-handler'\nimport { VcdmCredentialPlugin } from './vcdmCredentialPlugin'\n\n/**\n * @deprecated please use {@link VcdmCredentialPlugin} instead\n * @public\n */\nconst CredentialIssuer = VcdmCredentialPlugin\nexport { CredentialIssuer, VcdmCredentialPlugin }\n\n// For backward compatibility, re-export the plugin types that were moved to core in v4\nexport type { ICredentialIssuer, ICredentialVerifier } from '@veramo/core'\n\nexport * from './functions'\n"],"mappings":";;;;AACA,SAASA,8BAAuC;AAChD,SAASC,SAASC,kBAAkBC,0BAA0BC,qBAAqB;AAEnF,SACEC,qBACAC,uBACAC,8BACAC,sCACK;AAEP,SAASC,MAAMC,cAAc;AAC7B,OAAOC,WAAW;AAElB,IAAMC,QAAQC,MAAM,+BAAA;AAOb,IAAMC,eAAe;;EAE1BC,IAAI;;EAEJC,IAAI;AACN;AAsBO,IAAMC,oBAAN,cAAgCC,uBAAAA;EA/CvC,OA+CuCA;;;EACrC,MAAMC,OAAOC,SAAkBC,SA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ClB;AAPeyC;AASf,UAAMT,SAAS,MAAMS,0BAA0B,KAAKnE,OAAO;AAC3D,WAAO0D;EACT;AACF;;;AElLA,IAAMU,mBAAmBC;","names":["AbstractMessageHandler","asArray","computeEntryHash","decodeCredentialToObject","extractIssuer","normalizeCredential","normalizePresentation","validateJwtCredentialPayload","validateJwtPresentationPayload","v4","uuidv4","Debug","debug","Debug","MessageTypes","vc","vp","W3cMessageHandler","AbstractMessageHandler","handle","message","context","meta","getLastMetaData","type","raw","data","validateJwtPresentationPayload","presentation","normalizePresentation","credentials","verifiableCredential","id","computeEntryHash","from","holder","to","verifier","tag","threadId","createdAt","issuanceDate","presentations","e","validateJwtCredentialPayload","credential","normalizeCredential","issuer","credentialSubject","result","agent","verifyCredential","verified","uuidv4","extractIssuer","Error","error","verifyPresentation","challenge","domain","asArray","map","decodeCredentialToObject","asArray","CredentialMapper","schema","Debug","isDefined","processEntryToArray","decodeJWT","addVcdmContextIfNeeded","isVcdm1Credential","isVcdm2Credential","VCDM_CREDENTIAL_CONTEXT_V1","VCDM_CREDENTIAL_CONTEXT_V2","getKey","extractIssuer","input","options","isDefined","payload","decodeJWT","split","iss","removeParameters","removeDIDParameters","e","issuer","holder","id","did","replace","pickSigningKey","identifier","kmsKeyRef","context","key","getKey","vmRelationship","isRevoked","credential","credentialStatus","agent","checkCredentialStatus","status","revoked","verified","Error","preProcessCredentialPayload","now","Date","credentialContext","addVcdmContextIfNeeded","isVdcm1","isVcdm1Credential","isVdcm2","isVcdm2Credential","credentialType","processEntryToArray","type","issuanceDate","validFrom","toISOString","expirationDate","validUntil","credentialPayload","preProcessPresentation","args","presentation","credentials","verifiableCredential","v1Credential","find","cred","includes","VCDM_CREDENTIAL_CONTEXT_V1","undefined","v2Credential","VCDM_CREDENTIAL_CONTEXT_V2","presentationContext","presentationType","presentationPayload","map","proof","jwt","debug","Debug","VcdmCredentialPlugin","methods","schema","components","schemas","ICredentialIssuer","ICredentialVerifier","issuers","constructor","options","listUsableProofFormats","bind","createVerifiableCredential","verifyCredential","createVerifiablePresentation","verifyPresentation","did","context","signingOptions","keys","key","issuer","matchKeyForType","push","getTypeProofFormat","args","proofFormat","credential","now","preProcessCredentialPayload","agent","didManagerGet","e","Error","findAndIssueCredential","canIssueCredentialType","map","i","join","verifiableCredential","error","Promise","reject","policies","verifiedCredential","verificationResult","findAndVerifyCredential","canVerifyDocumentType","document","uniform","CredentialMapper","toUniformCredential","JSON","stringify","type","asArray","proof","credentialStatus","isRevoked","results","partialSingleResult","Array","isArray","verified","log","result","message","errorCode","id","valid","presentation","preProcessPresentation","verifiablePresentation","findAndCreatePresentation","findAndVerifyPresentation","CredentialIssuer","VcdmCredentialPlugin"]}
1
+ {"version":3,"sources":["../src/message-handler.ts","../src/vcdmCredentialPlugin.ts","../src/functions.ts","../src/index.ts"],"sourcesContent":["import type { IAgentContext, ICredentialVerifier, IResolver, VerifiableCredential, VerifiablePresentation } from '@veramo/core'\nimport { AbstractMessageHandler, Message } from '@veramo/message-handler'\nimport { asArray, computeEntryHash, decodeCredentialToObject, extractIssuer } from '@veramo/utils'\n\nimport {\n normalizeCredential,\n normalizePresentation,\n validateJwtCredentialPayload,\n validateJwtPresentationPayload, // @ts-ignore\n} from 'did-jwt-vc'\n\nimport { v4 as uuidv4 } from 'uuid'\nimport Debug from 'debug'\n\nconst debug = Debug('sphereon:vcdm:message-handler')\n\n/**\n * These types are used by `@veramo/data-store` when storing Verifiable Credentials and Presentations\n *\n * @internal\n */\nexport const MessageTypes = {\n /** Represents a Verifiable Credential */\n vc: 'w3c.vc',\n /** Represents a Verifiable Presentation */\n vp: 'w3c.vp',\n}\n\n/**\n * Represents the requirements that this plugin has.\n * The agent that is using this plugin is expected to provide these methods.\n *\n * This interface can be used for static type checks, to make sure your application is properly initialized.\n */\nexport type IContext = IAgentContext<IResolver & ICredentialVerifier>\n\n/**\n * An implementation of the {@link @veramo/message-handler#AbstractMessageHandler}.\n *\n * This plugin can handle incoming W3C Verifiable Credentials and Presentations and prepare them\n * for internal storage as {@link @veramo/message-handler#Message} types.\n *\n * The current version can only handle `JWT` encoded\n *\n * @remarks {@link @veramo/core#IDataStore | IDataStore }\n *\n * @public\n */\nexport class W3cMessageHandler extends AbstractMessageHandler {\n async handle(message: Message, context: IContext): Promise<Message> {\n const meta = message.getLastMetaData()\n\n // console.log(JSON.stringify(message, null, 2))\n\n //FIXME: messages should not be expected to be only JWT\n if (meta?.type === 'JWT' && message.raw) {\n const { data } = message\n\n try {\n validateJwtPresentationPayload(data)\n\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vp)\n const presentation = normalizePresentation(message.raw)\n const credentials = presentation.verifiableCredential\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vp\n message.from = presentation.holder\n message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = credentials\n\n return message\n } catch (e) {}\n\n try {\n validateJwtCredentialPayload(data)\n //FIXME: flagging this for potential privacy leaks\n debug('JWT is', MessageTypes.vc)\n const credential = normalizeCredential(message.raw)\n\n message.id = computeEntryHash(message.raw)\n message.type = MessageTypes.vc\n message.from = credential.issuer.id\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } catch (e) {}\n }\n\n // LDS Verification and Handling\n if (message.type === MessageTypes.vc && message.data) {\n // verify credential\n const credential = message.data as VerifiableCredential\n\n const result = await context.agent.verifyCredential({ credential })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vc\n message.from = extractIssuer(credential)\n message.to = credential.credentialSubject.id\n\n if (credential.tag) {\n message.threadId = credential.tag\n }\n\n message.createdAt = credential.issuanceDate\n message.credentials = [credential]\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n if (message.type === MessageTypes.vp && message.data) {\n // verify presentation\n const presentation = message.data as VerifiablePresentation\n\n // throws on error.\n const result = await context.agent.verifyPresentation({\n presentation,\n // FIXME: HARDCODED CHALLENGE VERIFICATION FOR NOW\n challenge: 'VERAMO',\n domain: 'VERAMO',\n })\n if (result.verified) {\n message.id = computeEntryHash(message.raw || message.id || uuidv4())\n message.type = MessageTypes.vp\n message.from = presentation.holder\n // message.to = presentation.verifier?.[0]\n\n if (presentation.tag) {\n message.threadId = presentation.tag\n }\n\n // message.createdAt = presentation.issuanceDate\n message.presentations = [presentation]\n message.credentials = asArray(presentation.verifiableCredential).map(decodeCredentialToObject)\n return message\n } else {\n throw new Error(result.error?.message)\n }\n }\n\n return super.handle(message, context)\n }\n}\n","import { asArray, type VerifiableCredentialSP, type VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'\nimport {\n CredentialMapper,\n IVerifyResult,\n IVerifySingleResultItem,\n OriginalVerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation\n} from '@sphereon/ssi-types'\nimport type { IAgentPlugin, IIdentifier, VerifiableCredential } from '@veramo/core'\nimport { schema } from '@veramo/core'\nimport Debug from 'debug'\nimport { isRevoked, preProcessCredentialPayload, preProcessPresentation } from './functions'\n\nimport type {\n ICreateVerifiableCredentialLDArgs,\n ICreateVerifiablePresentationLDArgs,\n IVcdmCredentialPlugin,\n IVcdmCredentialProvider,\n IVcdmIssuerAgentContext,\n IVcdmVerifierAgentContext,\n IVerifyCredentialVcdmArgs,\n IVerifyPresentationLDArgs\n} from './types'\n\nconst debug = Debug('sphereon:ssi-sdk:vcdm')\n\n/**\n * A plugin that implements the {@link @sphereon/ssi-sdk.credential-vcdm#IVcdmCredentialPlugin} methods.\n *\n * @public\n */\nexport class VcdmCredentialPlugin implements IAgentPlugin {\n readonly methods: IVcdmCredentialPlugin\n readonly schema = {\n components: {\n schemas: {\n ...schema.ICredentialIssuer.components.schemas,\n ...schema.ICredentialVerifier.components.schemas\n },\n methods: {\n ...schema.ICredentialIssuer.components.methods,\n ...schema.ICredentialVerifier.components.methods\n }\n }\n }\n private issuers: IVcdmCredentialProvider[]\n\n constructor(options: { issuers: IVcdmCredentialProvider[] }) {\n this.issuers = options.issuers\n this.methods = {\n listUsableProofFormats: this.listUsableProofFormats.bind(this),\n createVerifiableCredential: this.createVerifiableCredential.bind(this),\n verifyCredential: this.verifyCredential.bind(this),\n createVerifiablePresentation: this.createVerifiablePresentation.bind(this),\n verifyPresentation: this.verifyPresentation.bind(this)\n }\n }\n\n async listUsableProofFormats(did: IIdentifier, context: IVcdmIssuerAgentContext): Promise<string[]> {\n const signingOptions: string[] = []\n const keys = did.keys\n for (const key of keys) {\n for (const issuer of this.issuers) {\n if (issuer.matchKeyForType(key)) {\n signingOptions.push(issuer.getTypeProofFormat())\n }\n }\n }\n return signingOptions\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiableCredential} */\n async createVerifiableCredential(args: ICreateVerifiableCredentialLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiableCredentialSP> {\n let { proofFormat /* keyRef, removeOriginalFields, now , ...otherOptions */ } = args\n const { credential, issuer, now } = preProcessCredentialPayload(args)\n\n try {\n await context.agent.didManagerGet({ did: issuer })\n } catch (e) {\n throw new Error(`invalid_argument: credential.issuer must be a DID managed by this agent. ${e}`)\n }\n try {\n async function findAndIssueCredential(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiableCredential({ ...args, credential, now }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`\n )\n }\n\n const verifiableCredential = await findAndIssueCredential(this.issuers)\n return verifiableCredential\n } catch (error) {\n debug(error)\n return Promise.reject(error)\n }\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyCredential} */\n async verifyCredential(args: IVerifyCredentialVcdmArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { credential, policies /*, ...otherOptions*/ } = args\n let verifiedCredential: VerifiableCredential\n let verificationResult: IVerifyResult\n\n\n async function findAndVerifyCredential(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: credential as W3CVerifiableCredential })) {\n return issuer.verifyCredential(args, context)\n }\n }\n const uniform = CredentialMapper.toUniformCredential(args.credential as OriginalVerifiableCredential)\n return Promise.reject(\n Error(\n `invalid_setup: No verifier found for the provided credential credential\n type: ${JSON.stringify(uniform.type)} proof type \n ${asArray(uniform.proof)?.[0]?.type} supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`\n )\n )\n }\n\n verificationResult = await findAndVerifyCredential(this.issuers)\n verifiedCredential = <VerifiableCredential>credential\n\n if (policies?.credentialStatus !== false && (await isRevoked(verifiedCredential, context as any))) {\n const results = verificationResult.results\n const partialSingleResult: Partial<IVerifySingleResultItem> = (Array.isArray(results) ? results[0] : {\n credential: credential as OriginalVerifiableCredential,\n verified: false,\n log: []\n })\n const result: IVerifySingleResultItem = {\n ...partialSingleResult,\n credential: credential as OriginalVerifiableCredential,\n verified: false,\n error: {\n message: 'revoked: The credential was revoked by the issuer',\n errorCode: 'revoked'\n },\n log: [...partialSingleResult.log ?? [], { id: 'revocation_status', valid: false }]\n }\n verificationResult = {\n ...verificationResult,\n verified: false,\n error: result.error,\n results: [\n result\n ]\n }\n }\n\n return verificationResult\n }\n\n /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiablePresentation} */\n async createVerifiablePresentation(args: ICreateVerifiablePresentationLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiablePresentationSP> {\n const { proofFormat } = args\n const { presentation } = preProcessPresentation(args)\n\n let verifiablePresentation: VerifiablePresentationSP\n\n async function findAndCreatePresentation(issuers: IVcdmCredentialProvider[]) {\n for (const issuer of issuers) {\n if (issuer.canIssueCredentialType({ proofFormat })) {\n return await issuer.createVerifiablePresentation({ ...args, presentation }, context)\n }\n }\n throw new Error(\n `invalid_setup: No issuer found for the requested proof format: ${proofFormat}, supported: ${issuers.map((i) => i.getTypeProofFormat()).join(',')}`\n )\n }\n\n verifiablePresentation = await findAndCreatePresentation(this.issuers)\n return verifiablePresentation\n }\n\n /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyPresentation} */\n async verifyPresentation(args: IVerifyPresentationLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult> {\n let { presentation /*domain, challenge, fetchRemoteContexts, policies, ...otherOptions*/ } = args\n\n async function findAndVerifyPresentation(issuers: IVcdmCredentialProvider[]): Promise<IVerifyResult> {\n for (const issuer of issuers) {\n if (issuer.canVerifyDocumentType({ document: presentation as W3CVerifiablePresentation })) {\n return issuer.verifyPresentation(args, context)\n }\n }\n throw new Error('invalid_setup: No verifier found for the provided presentation')\n }\n\n const result = await findAndVerifyPresentation(this.issuers)\n return result\n }\n}\n","import type {\n CredentialPayload,\n IAgentContext,\n ICredentialStatusVerifier,\n IDIDManager,\n IIdentifier,\n IResolver,\n IssuerType,\n PresentationPayload,\n VerifiableCredential,\n W3CVerifiableCredential,\n W3CVerifiablePresentation,\n} from '@veramo/core'\nimport { _ExtendedIKey, isDefined, processEntryToArray } from '@veramo/utils'\nimport { decodeJWT } from 'did-jwt'\nimport {\n addVcdmContextIfNeeded,\n isVcdm1Credential,\n isVcdm2Credential,\n VCDM_CREDENTIAL_CONTEXT_V1,\n VCDM_CREDENTIAL_CONTEXT_V2,\n} from '@sphereon/ssi-types'\nimport { ICreateVerifiablePresentationLDArgs } from './types'\nimport { getKey } from '@sphereon/ssi-sdk-ext.did-utils'\n\n/**\n * Decodes a credential or presentation and returns the issuer ID\n * `iss` from a JWT or `issuer`/`issuer.id` from a VC or `holder` from a VP\n *\n * @param input - the credential or presentation whose issuer/holder needs to be extracted.\n * @param options - options for the extraction\n * removeParameters - Remove all DID parameters from the issuer ID\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function extractIssuer(\n input?: W3CVerifiableCredential | W3CVerifiablePresentation | CredentialPayload | PresentationPayload | null,\n options: { removeParameters?: boolean } = {},\n): string {\n if (!isDefined(input)) {\n return ''\n } else if (typeof input === 'string') {\n // JWT\n try {\n const { payload } = decodeJWT(input.split(`~`)[0])\n const iss = payload.iss ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n } catch (e: any) {\n return ''\n }\n } else {\n // JSON\n let iss: IssuerType\n if (input.issuer) {\n iss = input.issuer\n } else if (input.holder) {\n iss = input.holder\n } else {\n iss = ''\n }\n if (typeof iss !== 'string') iss = iss.id ?? ''\n return !!options.removeParameters ? removeDIDParameters(iss) : iss\n }\n}\n\n/**\n * Remove all DID parameters from a DID url after the query part (?)\n *\n * @param did - the DID URL\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport function removeDIDParameters(did: string): string {\n return did.replace(/\\?.*$/, '')\n}\n\nexport async function pickSigningKey(\n { identifier, kmsKeyRef }: { identifier: IIdentifier; kmsKeyRef?: string },\n context: IAgentContext<IResolver & IDIDManager>,\n): Promise<_ExtendedIKey> {\n const key = await getKey({ identifier, vmRelationship: 'assertionMethod', kmsKeyRef: kmsKeyRef }, context)\n return key\n}\n\nexport async function isRevoked(credential: VerifiableCredential, context: IAgentContext<ICredentialStatusVerifier>): Promise<boolean> {\n if (!credential.credentialStatus) return false\n\n if (typeof context.agent.checkCredentialStatus === 'function') {\n const status = await context.agent.checkCredentialStatus({ credential })\n return status?.revoked == true || status?.verified === false\n }\n\n throw new Error(`invalid_setup: The credential status can't be verified because there is no ICredentialStatusVerifier plugin installed.`)\n}\n\nexport function preProcessCredentialPayload({ credential, now = new Date() }: { credential: CredentialPayload; now?: number | Date }) {\n const credentialContext = addVcdmContextIfNeeded(credential?.['@context'])\n const isVdcm1 = isVcdm1Credential(credential)\n const isVdcm2 = isVcdm2Credential(credential)\n const credentialType = processEntryToArray(credential?.type, 'VerifiableCredential')\n let issuanceDate = credential?.validFrom ?? credential?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()\n let expirationDate = credential?.validUntil ?? credential?.expirationDate\n if (issuanceDate instanceof Date) {\n issuanceDate = issuanceDate.toISOString()\n }\n const credentialPayload: CredentialPayload = {\n ...credential,\n '@context': credentialContext,\n type: credentialType,\n ...(isVdcm1 && { issuanceDate }),\n ...(isVdcm1 && expirationDate && { expirationDate }),\n ...(isVdcm2 && { validFrom: issuanceDate }),\n ...(isVdcm2 && expirationDate && { validUntil: expirationDate }),\n }\n if (isVdcm1) {\n delete credentialPayload.validFrom\n delete credentialPayload.validUntil\n } else if (isVdcm2) {\n delete credentialPayload.issuanceDate\n delete credentialPayload.expirationDate\n }\n\n // debug(JSON.stringify(credentialPayload))\n\n const issuer = extractIssuer(credentialPayload, { removeParameters: true })\n if (!issuer || typeof issuer === 'undefined') {\n throw new Error('invalid_argument: args.credential.issuer must not be empty')\n }\n return { credential: credentialPayload, issuer, now }\n}\n\nexport function preProcessPresentation(args: ICreateVerifiablePresentationLDArgs) {\n const { presentation, now = new Date() } = args\n const credentials = presentation?.verifiableCredential ?? []\n const v1Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V1))\n ? VCDM_CREDENTIAL_CONTEXT_V1\n : undefined\n const v2Credential = credentials.find((cred) => typeof cred === 'object' && cred['@context'].includes(VCDM_CREDENTIAL_CONTEXT_V2))\n ? VCDM_CREDENTIAL_CONTEXT_V2\n : undefined\n const presentationContext = addVcdmContextIfNeeded(\n args?.presentation?.['@context'] ?? [],\n v2Credential ?? v1Credential ?? VCDM_CREDENTIAL_CONTEXT_V2,\n )\n const presentationType = processEntryToArray(args?.presentation?.type, 'VerifiablePresentation')\n\n let issuanceDate = presentation?.validFrom ?? presentation?.issuanceDate ?? (typeof now === 'number' ? new Date(now) : now).toISOString()\n if (issuanceDate instanceof Date) {\n issuanceDate = issuanceDate.toISOString()\n }\n const presentationPayload: PresentationPayload = {\n ...presentation,\n '@context': presentationContext,\n type: presentationType,\n ...(v1Credential && { issuanceDate }), // V1 only for JWT, but we remove it in the jsonld processor anyway\n ...(v2Credential && { validFrom: issuanceDate }),\n }\n // Workaround for bug in TypeError: Cannot read property 'length' of undefined\n // at VeramoEd25519Signature2018.preSigningPresModification\n /*if (!presentation.verifier) {\n presentation.verifier = []\n }*/\n\n if (!isDefined(presentationPayload.holder) || !presentationPayload.holder) {\n throw new Error('invalid_argument: args.presentation.holderDID must not be empty')\n }\n if (presentationPayload.verifiableCredential) {\n presentationPayload.verifiableCredential = presentationPayload.verifiableCredential.map((cred) => {\n // map JWT credentials to their canonical form\n if (typeof cred !== 'string' && cred.proof.jwt) {\n return cred.proof.jwt\n } else {\n return cred\n }\n })\n }\n return { presentation: presentationPayload, holder: removeDIDParameters(presentationPayload.holder) }\n}\n","/**\n * Provides a {@link @veramo/credential-w3c#CredentialPlugin | plugin} for the {@link @veramo/core#Agent} that\n * implements\n * {@link @veramo/core#ICredentialIssuer} interface.\n *\n * Provides a {@link @veramo/credential-w3c#W3cMessageHandler | plugin} for the\n * {@link @veramo/message-handler#MessageHandler} that verifies Credentials and Presentations in a message.\n *\n * @packageDocumentation\n */\nexport type * from './types'\nexport { W3cMessageHandler, MessageTypes } from './message-handler'\nimport { VcdmCredentialPlugin } from './vcdmCredentialPlugin'\n\n/**\n * @deprecated please use {@link VcdmCredentialPlugin} instead\n * @public\n */\nconst CredentialIssuer = VcdmCredentialPlugin\nexport { CredentialIssuer, VcdmCredentialPlugin }\n\n// For backward compatibility, re-export the plugin types that were moved to core in v4\nexport type { ICredentialIssuer, ICredentialVerifier } from '@veramo/core'\n\nexport * from './functions'\n"],"mappings":";;;;AACA,SAASA,8BAAuC;AAChD,SAASC,SAASC,kBAAkBC,0BAA0BC,qBAAqB;AAEnF,SACEC,qBACAC,uBACAC,8BACAC,sCACK;AAEP,SAASC,MAAMC,cAAc;AAC7B,OAAOC,WAAW;AAElB,IAAMC,QAAQC,MAAM,+BAAA;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,OAAO0B,sBAAsB;UAAEC,UAAUsB;QAA0C,CAAA,GAAI;AACzF,iBAAOjD,OAAON,mBAAmBU,MAAMR,OAAAA;QACzC;MACF;AACA,YAAM,IAAIgB,MAAM,gEAAA;IAClB;AAPeyC;AASf,UAAMT,SAAS,MAAMS,0BAA0B,KAAKlE,OAAO;AAC3D,WAAOyD;EACT;AACF;;;AElLA,IAAMU,mBAAmBC;","names":["AbstractMessageHandler","asArray","computeEntryHash","decodeCredentialToObject","extractIssuer","normalizeCredential","normalizePresentation","validateJwtCredentialPayload","validateJwtPresentationPayload","v4","uuidv4","Debug","debug","Debug","MessageTypes","vc","vp","W3cMessageHandler","AbstractMessageHandler","handle","message","context","meta","getLastMetaData","type","raw","data","validateJwtPresentationPayload","presentation","normalizePresentation","credentials","verifiableCredential","id","computeEntryHash","from","holder","to","verifier","tag","threadId","createdAt","issuanceDate","presentations","e","validateJwtCredentialPayload","credential","normalizeCredential","issuer","credentialSubject","result","agent","verifyCredential","verified","uuidv4","extractIssuer","Error","error","verifyPresentation","challenge","domain","asArray","map","decodeCredentialToObject","asArray","CredentialMapper","schema","Debug","isDefined","processEntryToArray","decodeJWT","addVcdmContextIfNeeded","isVcdm1Credential","isVcdm2Credential","VCDM_CREDENTIAL_CONTEXT_V1","VCDM_CREDENTIAL_CONTEXT_V2","getKey","extractIssuer","input","options","isDefined","payload","decodeJWT","split","iss","removeParameters","removeDIDParameters","e","issuer","holder","id","did","replace","pickSigningKey","identifier","kmsKeyRef","context","key","getKey","vmRelationship","isRevoked","credential","credentialStatus","agent","checkCredentialStatus","status","revoked","verified","Error","preProcessCredentialPayload","now","Date","credentialContext","addVcdmContextIfNeeded","isVdcm1","isVcdm1Credential","isVdcm2","isVcdm2Credential","credentialType","processEntryToArray","type","issuanceDate","validFrom","toISOString","expirationDate","validUntil","credentialPayload","preProcessPresentation","args","presentation","credentials","verifiableCredential","v1Credential","find","cred","includes","VCDM_CREDENTIAL_CONTEXT_V1","undefined","v2Credential","VCDM_CREDENTIAL_CONTEXT_V2","presentationContext","presentationType","presentationPayload","map","proof","jwt","debug","Debug","VcdmCredentialPlugin","methods","schema","components","schemas","ICredentialIssuer","ICredentialVerifier","issuers","options","listUsableProofFormats","bind","createVerifiableCredential","verifyCredential","createVerifiablePresentation","verifyPresentation","did","context","signingOptions","keys","key","issuer","matchKeyForType","push","getTypeProofFormat","args","proofFormat","credential","now","preProcessCredentialPayload","agent","didManagerGet","e","Error","findAndIssueCredential","canIssueCredentialType","map","i","join","verifiableCredential","error","Promise","reject","policies","verifiedCredential","verificationResult","findAndVerifyCredential","canVerifyDocumentType","document","uniform","CredentialMapper","toUniformCredential","JSON","stringify","type","asArray","proof","credentialStatus","isRevoked","results","partialSingleResult","Array","isArray","verified","log","result","message","errorCode","id","valid","presentation","preProcessPresentation","verifiablePresentation","findAndCreatePresentation","findAndVerifyPresentation","CredentialIssuer","VcdmCredentialPlugin"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sphereon/ssi-sdk.credential-vcdm",
3
3
  "description": "Plugin for working with W3C Verifiable Credentials DataModel 1 and 2 Credentials & Presentations.",
4
- "version": "0.34.1-feature.SSISDK.17.bitstring.sl.9+a052acba",
4
+ "version": "0.34.1-next.29+2593a430",
5
5
  "source": "src/index.ts",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
@@ -30,10 +30,9 @@
30
30
  "dependencies": {
31
31
  "@sphereon/ssi-sdk-ext.did-utils": "workspace:*",
32
32
  "@sphereon/ssi-sdk-ext.key-utils": "workspace:*",
33
- "@sphereon/ssi-sdk.agent-config": "0.34.1-feature.SSISDK.17.bitstring.sl.9+a052acba",
34
- "@sphereon/ssi-sdk.core": "0.34.1-feature.SSISDK.17.bitstring.sl.9+a052acba",
35
- "@sphereon/ssi-sdk.vc-status-list": "0.34.1-feature.SSISDK.17.bitstring.sl.9+a052acba",
36
- "@sphereon/ssi-types": "0.34.1-feature.SSISDK.17.bitstring.sl.9+a052acba",
33
+ "@sphereon/ssi-sdk.agent-config": "0.34.1-next.29+2593a430",
34
+ "@sphereon/ssi-sdk.core": "0.34.1-next.29+2593a430",
35
+ "@sphereon/ssi-types": "0.34.1-next.29+2593a430",
37
36
  "@veramo/core": "4.2.0",
38
37
  "@veramo/message-handler": "4.2.0",
39
38
  "@veramo/utils": "4.2.0",
@@ -45,9 +44,10 @@
45
44
  "uuid": "^9.0.1"
46
45
  },
47
46
  "devDependencies": {
48
- "@sphereon/ssi-sdk-ext.did-provider-key": "0.29.0",
49
- "@sphereon/ssi-sdk-ext.key-manager": "0.29.0",
50
- "@sphereon/ssi-sdk-ext.kms-local": "0.29.0",
47
+ "@sphereon/oid4vci-common": "0.19.0",
48
+ "@sphereon/ssi-sdk-ext.did-provider-key": "0.29.1-next.3",
49
+ "@sphereon/ssi-sdk-ext.key-manager": "0.29.1-next.3",
50
+ "@sphereon/ssi-sdk-ext.kms-local": "0.29.1-next.3",
51
51
  "@types/debug": "4.1.8",
52
52
  "@types/uuid": "9.0.2",
53
53
  "@veramo/did-manager": "4.2.0",
@@ -55,6 +55,7 @@
55
55
  "@veramo/did-resolver": "4.2.0",
56
56
  "@veramo/key-manager": "4.2.0",
57
57
  "ethr-did-resolver": "^11.0.3",
58
+ "typeorm": "0.3.20",
58
59
  "typescript": "5.8.3"
59
60
  },
60
61
  "files": [
@@ -91,5 +92,5 @@
91
92
  "node_modules",
92
93
  "src"
93
94
  ],
94
- "gitHead": "a052acbaa88acf4be22236ca3afaadd5b2821fe1"
95
+ "gitHead": "2593a430ac4faca47b620a3e12b297899518f2af"
95
96
  }
package/src/types.ts CHANGED
@@ -11,16 +11,18 @@ import type {
11
11
  } from '@veramo/core'
12
12
 
13
13
  import type { VerifiableCredentialSP, VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'
14
+ import type { StatusListOpts } from '@sphereon/oid4vci-common'
14
15
 
15
- import type { IIssueCredentialStatusOpts } from '@sphereon/ssi-sdk.vc-status-list'
16
16
  import type {
17
17
  ICredential,
18
18
  IVerifyResult,
19
19
  OriginalVerifiableCredential,
20
20
  W3CVerifiableCredential,
21
- W3CVerifiablePresentation
21
+ W3CVerifiablePresentation,
22
22
  } from '@sphereon/ssi-types'
23
23
 
24
+ import type { DataSource } from 'typeorm'
25
+
24
26
  export type IVcdmCredentialPlugin = IVcdmCredentialIssuer & IVcdmCredentialVerifier
25
27
 
26
28
  /**
@@ -108,6 +110,16 @@ export interface ICreateVerifiablePresentationLDArgs {
108
110
  now?: Date | number
109
111
  }
110
112
 
113
+ /**
114
+ * Statuslist credential options, cloned from packages/vc-status-list/src/types/index.ts to break cyclic dependency loop
115
+ */
116
+ export interface IIssueCredentialStatusOpts {
117
+ dataSource?: DataSource
118
+ statusLists?: Array<StatusListOpts>
119
+ credentialId?: string // An id to use for the credential. Normally should be set as the crdential.id value
120
+ value?: string
121
+ }
122
+
111
123
  /**
112
124
  * Encapsulates the parameters required to create a
113
125
  * {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential}