

const require_CredoError = require('../../../error/CredoError.js');
require('../../../error/index.js');
const require_MessageValidator = require('../../../utils/MessageValidator.js');
const require_JsonTransformer = require('../../../utils/JsonTransformer.js');
require('../../../utils/index.js');
const require_Jwt = require('../../../crypto/jose/jwt/Jwt.js');
const require_ClaimFormat = require('../models/ClaimFormat.js');
const require_W3cV2Presentation = require('../models/presentation/W3cV2Presentation.js');
require('../models/index.js');

//#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 = require_JsonTransformer.JsonTransformer.fromJSON(options.jwt.payload.additionalClaims, require_W3cV2Presentation.W3cV2Presentation, { validate: false });
		this.validate();
	}
	static fromCompact(compact) {
		return new W3cV2JwtVerifiablePresentation({ jwt: require_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 require_ClaimFormat.ClaimFormat.JwtW3cVp;
	}
	/**
	* Validates the JWT and the resolved presentation.
	*/
	validate() {
		require_MessageValidator.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 require_CredoError.CredoError(`The provided W3C VP JWT does not have the correct 'typ' header.`);
		if ("cyt" in header && header.cyt !== "vp") throw new require_CredoError.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 require_CredoError.CredoError(`The provided W3C VP JWT has both 'iss' and 'holder' claims, but they differ.`);
		}
	}
};

//#endregion
exports.W3cV2JwtVerifiablePresentation = W3cV2JwtVerifiablePresentation;