

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_ClaimFormat = require('../models/ClaimFormat.js');
const require_W3cV2SdJwt = require('./W3cV2SdJwt.js');
const require_W3cV2Presentation = require('../models/presentation/W3cV2Presentation.js');
require('../models/index.js');

//#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 = require_JsonTransformer.JsonTransformer.fromJSON(options.sdJwt.prettyClaims, require_W3cV2Presentation.W3cV2Presentation, { validate: false });
		this.validate();
	}
	static fromCompact(compact) {
		return new W3cV2SdJwtVerifiablePresentation({ sdJwt: require_W3cV2SdJwt.decodeSdJwt(compact, require_ClaimFormat.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 require_ClaimFormat.ClaimFormat.SdJwtW3cVp;
	}
	/**
	* Validates the SD-JWT and the resolved presentation.
	*/
	validate() {
		require_MessageValidator.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 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 SD-JWT has both 'iss' and 'holder' claims, but they differ.`);
		}
	}
};

//#endregion
exports.W3cV2SdJwtVerifiablePresentation = W3cV2SdJwtVerifiablePresentation;