UNPKG

@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 • 4.07 kB
{"version":3,"file":"W3cJsonLdVerifiablePresentation.mjs","names":[],"sources":["../../../../../src/modules/vc/linked-data-proofs/models/W3cJsonLdVerifiablePresentation.ts"],"sourcesContent":["import { CredoError } from '../../../../error'\nimport type { SingleOrArray } from '../../../../types'\nimport { asArray, IsInstanceOrArrayOfInstances, JsonTransformer } from '../../../../utils'\nimport type { AnonCredsW3cCredentialProofOptions } from '../../anoncreds-w3c-credential'\nimport { ANONCREDS_W3C_CREDENTIAL_CRYPTOSUITE, AnonCredsW3cCredentialProof } from '../../anoncreds-w3c-credential'\nimport { ClaimFormat } from '../../models'\nimport type { W3cPresentationOptions } from '../../models/presentation/W3cPresentation'\nimport { W3cPresentation } from '../../models/presentation/W3cPresentation'\nimport { ProofTransformer } from '../proof-ops/ProofTransformer'\nimport type { LinkedDataProofOptions } from './LinkedDataProof'\nimport { LinkedDataProof } from './LinkedDataProof'\n\nexport interface W3cJsonLdVerifiablePresentationOptions extends W3cPresentationOptions {\n proof: LinkedDataProofOptions | AnonCredsW3cCredentialProofOptions\n}\n\nconst mapProofOptionToProofClass = (proof: LinkedDataProofOptions | AnonCredsW3cCredentialProofOptions) => {\n if ('cryptosuite' in proof) {\n if (proof.type !== 'DataIntegrityProof' || proof.cryptosuite !== ANONCREDS_W3C_CREDENTIAL_CRYPTOSUITE) {\n throw new CredoError(\n `W3C credential proofs only support DataIntegrityProof with cryptosuite ${ANONCREDS_W3C_CREDENTIAL_CRYPTOSUITE}`\n )\n }\n\n return new AnonCredsW3cCredentialProof(proof)\n }\n\n return new LinkedDataProof(proof)\n}\n\nexport class W3cJsonLdVerifiablePresentation extends W3cPresentation {\n public constructor(options: W3cJsonLdVerifiablePresentationOptions) {\n super(options)\n if (options) {\n this.proof = mapProofOptionToProofClass(options.proof)\n }\n }\n\n @ProofTransformer()\n @IsInstanceOrArrayOfInstances({ classType: [LinkedDataProof, AnonCredsW3cCredentialProof] })\n public proof!: SingleOrArray<LinkedDataProof | AnonCredsW3cCredentialProof>\n\n public get proofTypes(): Array<string> {\n const proofArray = asArray(this.proof) ?? []\n return proofArray.map((proof) => proof.type)\n }\n\n public get anonCredsW3cCredentialCryptosuites(): Array<string> {\n const proofArray = asArray(this.proof) ?? []\n return proofArray\n .filter(\n (proof): proof is AnonCredsW3cCredentialProof => proof.type === 'DataIntegrityProof' && 'cryptosuite' in proof\n )\n .map((proof) => proof.cryptosuite)\n }\n\n /** @deprecated Use anonCredsW3cCredentialCryptosuites */\n public get dataIntegrityCryptosuites(): Array<string> {\n return this.anonCredsW3cCredentialCryptosuites\n }\n\n public toJson() {\n return JsonTransformer.toJSON(this)\n }\n\n /**\n * The {@link ClaimFormat} of the presentation. For JSON-LD credentials this is always `ldp_vp`.\n */\n public get claimFormat(): ClaimFormat.LdpVp {\n return ClaimFormat.LdpVp\n }\n\n /**\n * Get the encoded variant of the W3C Verifiable Presentation. For JSON-LD presentations this is\n * a JSON object.\n */\n public get encoded() {\n return this.toJson()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAM,8BAA8B,UAAuE;CACzG,IAAI,iBAAiB,OAAO;EAC1B,IAAI,MAAM,SAAS,wBAAwB,MAAM,gBAAA,kBAC/C,MAAM,IAAI,WACR,0EAA0E,sCAC5E;EAGF,OAAO,IAAI,4BAA4B,KAAK;CAC9C;CAEA,OAAO,IAAI,gBAAgB,KAAK;AAClC;AAEA,IAAa,kCAAb,cAAqD,gBAAgB;CACnE,YAAmB,SAAiD;EAClE,MAAM,OAAO;EACb,IAAI,SACF,KAAK,QAAQ,2BAA2B,QAAQ,KAAK;CAEzD;CAMA,IAAW,aAA4B;EAErC,QADmB,QAAQ,KAAK,KAAK,KAAK,CAAC,EAAA,CACzB,KAAK,UAAU,MAAM,IAAI;CAC7C;CAEA,IAAW,qCAAoD;EAE7D,QADmB,QAAQ,KAAK,KAAK,KAAK,CAAC,EAAA,CAExC,QACE,UAAgD,MAAM,SAAS,wBAAwB,iBAAiB,KAC3G,CAAC,CACA,KAAK,UAAU,MAAM,WAAW;CACrC;;CAGA,IAAW,4BAA2C;EACpD,OAAO,KAAK;CACd;CAEA,SAAgB;EACd,OAAO,gBAAgB,OAAO,IAAI;CACpC;;;;CAKA,IAAW,cAAiC;EAC1C,OAAA;CACF;;;;;CAMA,IAAW,UAAU;EACnB,OAAO,KAAK,OAAO;CACrB;AACF;;CAzCG,iBAAiB;CACjB,6BAA6B,EAAE,WAAW,CAAC,iBAAiB,2BAA2B,EAAE,CAAC"}