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

58 lines (57 loc) • 2.28 kB
import { CredoError } from "../../../error/CredoError.mjs"; import "../../../error/index.mjs"; import { MessageValidator } from "../../../utils/MessageValidator.mjs"; import { JsonTransformer } from "../../../utils/JsonTransformer.mjs"; import "../../../utils/index.mjs"; import { Jwt } from "../../../crypto/jose/jwt/Jwt.mjs"; import "../models/ClaimFormat.mjs"; import { W3cV2Presentation } from "../models/presentation/W3cV2Presentation.mjs"; //#region src/modules/vc/jwt-vc/W3cV2JwtVerifiablePresentation.ts /** * Represents a Verifiable Presentation encoded as a JWT. * * @see https://www.w3.org/TR/vc-jose-cose/#securing-vps-with-jose */ var W3cV2JwtVerifiablePresentation = class W3cV2JwtVerifiablePresentation { constructor(options) { this.jwt = options.jwt; this.resolvedPresentation = JsonTransformer.fromJSON(options.jwt.payload.additionalClaims, W3cV2Presentation, { validate: false }); this.validate(); } static fromCompact(compact) { const jwt = Jwt.fromSerializedJwt(compact); return new W3cV2JwtVerifiablePresentation({ jwt }); } /** * The encoded version of this presentation. */ get encoded() { return this.jwt.serializedJwt; } /** * The {@link ClaimFormat} of the presentation. * * For W3C VP JWT credentials this is always `vp+jwt`. */ get claimFormat() { return "vp+jwt"; } /** * Validates the JWT and the resolved presentation. */ validate() { MessageValidator.validateSync(this.resolvedPresentation); const jwt = this.jwt; const header = jwt.header; const payload = jwt.payload; if (header.alg === "none") throw new CredoError(`The provided W3C VP JWT uses 'alg'='none', which is not allowed.`); if ("typ" in header && header.typ !== "vp+jwt") throw new CredoError(`The provided W3C VP JWT does not have the correct 'typ' header.`); if ("cty" in header && header.cty !== "vp") throw new CredoError(`The provided W3C VP JWT does not have the correct 'cty' header.`); if (payload.iss && this.resolvedPresentation.holderId) { if (this.resolvedPresentation.holderId !== payload.iss) throw new CredoError(`The provided W3C VP JWT has both 'iss' and 'holder' claims, but they differ.`); } } }; //#endregion export { W3cV2JwtVerifiablePresentation }; //# sourceMappingURL=W3cV2JwtVerifiablePresentation.mjs.map