@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
61 lines (57 loc) • 2.24 kB
JavaScript
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 { ClaimFormat } from "../models/ClaimFormat.mjs";
import { W3cV2Presentation } from "../models/presentation/W3cV2Presentation.mjs";
import "../models/index.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) {
return new W3cV2JwtVerifiablePresentation({ jwt: Jwt.fromSerializedJwt(compact) });
}
/**
* 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 ClaimFormat.JwtW3cVp;
}
/**
* 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 ("typ" in header && header.typ !== "vp+jwt") throw new CredoError(`The provided W3C VP JWT does not have the correct 'typ' header.`);
if ("cyt" in header && header.cyt !== "vp") throw new CredoError(`The provided W3C VP JWT does not have the correct 'cyt' header.`);
const iss = header.iss ?? payload.iss;
if (iss && this.resolvedPresentation.holderId) {
if (this.resolvedPresentation.holderId !== 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