@credo-ts/core
Version:
<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1
1 lines • 5.89 kB
Source Map (JSON)
{"version":3,"file":"presentationsToCreate.mjs","names":[],"sources":["../../../../src/modules/dif-presentation-exchange/utils/presentationsToCreate.ts"],"sourcesContent":["import type { JsonObject } from '../../../types'\nimport { MdocRecord } from '../../mdoc'\nimport { SdJwtVcRecord } from '../../sd-jwt-vc'\nimport { ClaimFormat, W3cCredentialRecord } from '../../vc'\nimport type { DifPexInputDescriptorToCredentials } from '../models'\n\n// - the credentials included in the presentation\nexport interface SdJwtVcPresentationToCreate {\n claimFormat: ClaimFormat.SdJwtDc\n subjectIds: [] // subject is included in the cnf of the sd-jwt and automatically extracted by PEX\n verifiableCredentials: [\n {\n credential: SdJwtVcRecord\n inputDescriptorId: string\n\n /**\n * Additional payload to include in the Key Binding JWT\n */\n additionalPayload?: JsonObject\n },\n ] // only one credential supported for SD-JWT-VC\n}\n\nexport interface JwtVpPresentationToCreate {\n claimFormat: ClaimFormat.JwtVp\n subjectIds: [string] // only one subject id supported for JWT VP\n verifiableCredentials: Array<{\n credential: W3cCredentialRecord\n inputDescriptorId: string\n }> // multiple credentials supported for JWT VP\n}\n\nexport interface LdpVpPresentationToCreate {\n claimFormat: ClaimFormat.LdpVp\n // NOTE: we only support one subject id at the moment as we don't have proper\n // support yet for adding multiple proofs to an LDP-VP\n subjectIds: undefined | [string]\n verifiableCredentials: Array<{\n credential: W3cCredentialRecord\n inputDescriptorId: string\n }> // multiple credentials supported for LDP VP\n}\n\nexport interface MdocPresentationToCreate {\n claimFormat: ClaimFormat.MsoMdoc\n subjectIds: []\n verifiableCredentials: [\n {\n credential: MdocRecord\n inputDescriptorId: string\n },\n ] // only one credential supported for MDOC\n}\n\nexport type PresentationToCreate =\n | SdJwtVcPresentationToCreate\n | JwtVpPresentationToCreate\n | LdpVpPresentationToCreate\n | MdocPresentationToCreate\n\n// FIXME: we should extract supported format form top-level presentation definition, and input_descriptor as well\n// to make sure the presentation we are going to create is a presentation format supported by the verifier.\n// In addition we should allow to pass an override 'format' object, as specification like OID4VP do not use the\n// PD formats, but define their own.\nexport function getPresentationsToCreate(credentialsForInputDescriptor: DifPexInputDescriptorToCredentials) {\n const presentationsToCreate: Array<PresentationToCreate> = []\n\n // We map all credentials for a input descriptor to the different subject ids. Each subjectId will need\n // to create a separate proof (either on the same presentation or if not allowed by proof format on separate)\n // presentations\n for (const [inputDescriptorId, credentials] of Object.entries(credentialsForInputDescriptor)) {\n for (const credential of credentials) {\n if (credential.claimFormat === ClaimFormat.SdJwtDc) {\n // SD-JWT-VC always needs it's own presentation\n presentationsToCreate.push({\n claimFormat: ClaimFormat.SdJwtDc,\n subjectIds: [],\n verifiableCredentials: [\n {\n inputDescriptorId,\n credential: credential.credentialRecord,\n additionalPayload: credential.additionalPayload,\n },\n ],\n })\n } else if (credential.credentialRecord instanceof MdocRecord) {\n presentationsToCreate.push({\n claimFormat: ClaimFormat.MsoMdoc,\n verifiableCredentials: [{ inputDescriptorId, credential: credential.credentialRecord }],\n subjectIds: [],\n })\n } else {\n const subjectId = credential.credentialRecord.firstCredential.credentialSubjectIds[0]\n\n // NOTE: we only support one subjectId per VP -- once we have proper support\n // for multiple proofs on an LDP-VP we can add multiple subjectIds to a single VP for LDP-vp only\n const expectedClaimFormat =\n credential.credentialRecord.firstCredential.claimFormat === ClaimFormat.LdpVc\n ? ClaimFormat.LdpVp\n : ClaimFormat.JwtVp\n\n const matchingClaimFormatAndSubject = presentationsToCreate.find(\n (p): p is JwtVpPresentationToCreate =>\n p.claimFormat === expectedClaimFormat && Boolean(p.subjectIds?.includes(subjectId))\n )\n\n if (matchingClaimFormatAndSubject) {\n matchingClaimFormatAndSubject.verifiableCredentials.push({\n inputDescriptorId,\n credential: credential.credentialRecord,\n })\n } else {\n presentationsToCreate.push({\n claimFormat: expectedClaimFormat,\n subjectIds: [subjectId],\n verifiableCredentials: [{ credential: credential.credentialRecord, inputDescriptorId }],\n })\n }\n }\n }\n }\n\n return presentationsToCreate\n}\n"],"mappings":";;;;;;AAgEA,SAAgB,yBAAyB,+BAAmE;CAC1G,MAAM,wBAAqD,CAAC;CAK5D,KAAK,MAAM,CAAC,mBAAmB,gBAAgB,OAAO,QAAQ,6BAA6B,GACzF,KAAK,MAAM,cAAc,aACvB,IAAI,WAAW,gBAAA,aAEb,sBAAsB,KAAK;EACzB,aAAA;EACA,YAAY,CAAC;EACb,uBAAuB,CACrB;GACE;GACA,YAAY,WAAW;GACvB,mBAAmB,WAAW;EAChC,CACF;CACF,CAAC;MACI,IAAI,WAAW,4BAA4B,YAChD,sBAAsB,KAAK;EACzB,aAAA;EACA,uBAAuB,CAAC;GAAE;GAAmB,YAAY,WAAW;EAAiB,CAAC;EACtF,YAAY,CAAC;CACf,CAAC;MACI;EACL,MAAM,YAAY,WAAW,iBAAiB,gBAAgB,qBAAqB;EAInF,MAAM,sBACJ,WAAW,iBAAiB,gBAAgB,gBAAA,WAAA,WAAA;EAI9C,MAAM,gCAAgC,sBAAsB,MACzD,MACC,EAAE,gBAAgB,uBAAuB,QAAQ,EAAE,YAAY,SAAS,SAAS,CAAC,CACtF;EAEA,IAAI,+BACF,8BAA8B,sBAAsB,KAAK;GACvD;GACA,YAAY,WAAW;EACzB,CAAC;OAED,sBAAsB,KAAK;GACzB,aAAa;GACb,YAAY,CAAC,SAAS;GACtB,uBAAuB,CAAC;IAAE,YAAY,WAAW;IAAkB;GAAkB,CAAC;EACxF,CAAC;CAEL;CAIJ,OAAO;AACT"}