@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.28 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 { ClaimFormat } from "../models/ClaimFormat.mjs";
import { decodeSdJwt } from "./W3cV2SdJwt.mjs";
import { W3cV2Presentation } from "../models/presentation/W3cV2Presentation.mjs";
import "../models/index.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) {
return new W3cV2SdJwtVerifiablePresentation({ sdJwt: decodeSdJwt(compact, ClaimFormat.SdJwtW3cVp) });
}
/**
* 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 ClaimFormat.SdJwtW3cVp;
}
/**
* 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 ("typ" in header && header.typ !== "vp+sd-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 SD-JWT has both 'iss' and 'holder' claims, but they differ.`);
}
}
};
//#endregion
export { W3cV2SdJwtVerifiablePresentation };
//# sourceMappingURL=W3cV2SdJwtVerifiablePresentation.mjs.map