@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.32 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 "../models/ClaimFormat.mjs";
import { decodeSdJwt } from "./W3cV2SdJwt.mjs";
import { W3cV2Presentation } from "../models/presentation/W3cV2Presentation.mjs";
//#region src/modules/vc/sd-jwt-vc/W3cV2SdJwtVerifiablePresentation.ts
/**
* Represents a Verifiable Presentation encoded as a SD-JWT.
*
* @see https://www.w3.org/TR/vc-jose-cose/#securing-vps-sd-jwt
*/
var W3cV2SdJwtVerifiablePresentation = class W3cV2SdJwtVerifiablePresentation {
constructor(options) {
this.sdJwt = options.sdJwt;
this.resolvedPresentation = JsonTransformer.fromJSON(options.sdJwt.prettyClaims, W3cV2Presentation, { validate: false });
this.validate();
}
static fromCompact(compact) {
const sdJwt = decodeSdJwt(compact, "vp+sd-jwt");
return new W3cV2SdJwtVerifiablePresentation({ sdJwt });
}
/**
* The encoded version of this presentation.
*/
get encoded() {
return this.sdJwt.compact;
}
/**
* The {@link ClaimFormat} of the presentation.
*
* For W3C VP SD-JWT credentials this is always `vp+sd-jwt`.
*/
get claimFormat() {
return "vp+sd-jwt";
}
/**
* Validates the SD-JWT and the resolved presentation.
*/
validate() {
MessageValidator.validateSync(this.resolvedPresentation);
const sdJwt = this.sdJwt;
const header = sdJwt.header;
const payload = sdJwt.prettyClaims;
if (header.alg === "none") throw new CredoError(`The provided W3C VP SD-JWT uses 'alg'='none', which is not allowed.`);
if ("typ" in header && header.typ !== "vp+sd-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 SD-JWT has both 'iss' and 'holder' claims, but they differ.`);
}
}
};
//#endregion
export { W3cV2SdJwtVerifiablePresentation };
//# sourceMappingURL=W3cV2SdJwtVerifiablePresentation.mjs.map