@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.65 kB
Source Map (JSON)
{"version":3,"file":"W3cJsonLdVerifiableCredential.mjs","names":[],"sources":["../../../../../src/modules/vc/linked-data-proofs/models/W3cJsonLdVerifiableCredential.ts"],"sourcesContent":["import { ValidateNested } from 'class-validator'\nimport { CredoError } from '../../../../error'\nimport type { SingleOrArray } from '../../../../types'\nimport { asArray, IsInstanceOrArrayOfInstances, JsonTransformer, mapSingleOrArray } from '../../../../utils'\nimport type { AnonCredsW3cCredentialProofOptions } from '../../anoncreds-w3c-credential'\nimport { ANONCREDS_W3C_CREDENTIAL_CRYPTOSUITE, AnonCredsW3cCredentialProof } from '../../anoncreds-w3c-credential'\nimport { ClaimFormat } from '../../models/ClaimFormat'\nimport type { W3cCredentialOptions } from '../../models/credential/W3cCredential'\nimport { W3cCredential } from '../../models/credential/W3cCredential'\nimport type { W3cJsonCredential } from '../../models/credential/W3cJsonCredential'\nimport { ProofTransformer } from '../proof-ops/ProofTransformer'\nimport type { LinkedDataProofOptions } from './LinkedDataProof'\nimport { LinkedDataProof } from './LinkedDataProof'\n\nexport interface W3cJsonLdVerifiableCredentialOptions extends W3cCredentialOptions {\n proof: SingleOrArray<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 W3cJsonLdVerifiableCredential extends W3cCredential {\n public constructor(options: W3cJsonLdVerifiableCredentialOptions) {\n super(options)\n if (options) {\n this.proof = mapSingleOrArray(options.proof, mapProofOptionToProofClass)\n }\n }\n\n @ProofTransformer()\n @IsInstanceOrArrayOfInstances({ classType: [LinkedDataProof, AnonCredsW3cCredentialProof] })\n @ValidateNested()\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) as W3cJsonCredential\n }\n\n public static fromJson(json: Record<string, unknown>) {\n return JsonTransformer.fromJSON(json, W3cJsonLdVerifiableCredential)\n }\n\n /**\n * The {@link ClaimFormat} of the credential. For JSON-LD credentials this is always `ldp_vc`.\n */\n public get claimFormat(): ClaimFormat.LdpVc {\n return ClaimFormat.LdpVc\n }\n\n /**\n * Get the encoded variant of the W3C Verifiable Credential. For JSON-LD credentials this is\n * a JSON object.\n */\n public get encoded() {\n return this.toJson()\n }\n\n public get jsonCredential(): W3cJsonCredential {\n return this.toJson() as W3cJsonCredential\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkBA,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,gCAAb,MAAa,sCAAsC,cAAc;CAC/D,YAAmB,SAA+C;EAChE,MAAM,OAAO;EACb,IAAI,SACF,KAAK,QAAQ,iBAAiB,QAAQ,OAAO,0BAA0B;CAE3E;CAOA,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;CAEA,OAAc,SAAS,MAA+B;EACpD,OAAO,gBAAgB,SAAS,MAAM,6BAA6B;CACrE;;;;CAKA,IAAW,cAAiC;EAC1C,OAAA;CACF;;;;;CAMA,IAAW,UAAU;EACnB,OAAO,KAAK,OAAO;CACrB;CAEA,IAAW,iBAAoC;EAC7C,OAAO,KAAK,OAAO;CACrB;AACF;;CAlDG,iBAAiB;CACjB,6BAA6B,EAAE,WAAW,CAAC,iBAAiB,2BAA2B,EAAE,CAAC;CAC1F,eAAe"}