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

56 lines (55 loc) • 2.21 kB
import { CredoError } from "../../../error/CredoError.mjs"; import "../../../error/index.mjs"; import { MessageValidator } from "../../../utils/MessageValidator.mjs"; import "../../../utils/index.mjs"; import "../models/ClaimFormat.mjs"; import "./W3cV2DataIntegrityVerifiableCredential.mjs"; //#region src/modules/vc/data-integrity/W3cV2DataIntegrityVerifiablePresentation.ts /** * Represents a Verifiable Presentation secured with Data Integrity proof(s). * * @see https://www.w3.org/TR/vc-data-integrity/ */ var W3cV2DataIntegrityVerifiablePresentation = class W3cV2DataIntegrityVerifiablePresentation { constructor(options) { this.securedPresentation = options.securedPresentation; this.resolvedPresentation = options.resolvedPresentation; this.validate(); } static fromObject(presentation, resolvedPresentation) { return new W3cV2DataIntegrityVerifiablePresentation({ securedPresentation: presentation, resolvedPresentation }); } /** * The JSON representation of this presentation. */ get encoded() { return JSON.stringify(this.securedPresentation); } /** * The {@link ClaimFormat} of the presentation. * * For W3C VP Data Integrity presentations this is always `di_vp`. */ get claimFormat() { return "di_vp"; } /** * Validates the presentation and proof structure. */ validate() { MessageValidator.validateSync(this.resolvedPresentation); const proof = this.securedPresentation.proof; if (!proof) throw new CredoError("The provided presentation does not have a proof field."); if (typeof proof !== "object") throw new CredoError("The proof field must be an object or array of objects."); if (!Array.isArray(proof) && typeof proof === "object" && (!("type" in proof) || proof.type !== "DataIntegrityProof")) throw new CredoError("The proof must have type \"DataIntegrityProof\"."); if (Array.isArray(proof)) { for (const p of proof) if (typeof p !== "object" || !("type" in p) || p.type !== "DataIntegrityProof") throw new CredoError("All proofs in the proof array must have type \"DataIntegrityProof\"."); } } }; //#endregion export { W3cV2DataIntegrityVerifiablePresentation }; //# sourceMappingURL=W3cV2DataIntegrityVerifiablePresentation.mjs.map