

const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
const require_decorate = require('../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.js');
const require_TypedArrayEncoder = require('../../utils/TypedArrayEncoder.js');
const require_array = require('../../utils/array.js');
require('../../utils/index.js');
const require_X509Certificate = require('../x509/X509Certificate.js');
require('../x509/index.js');
const require_types = require('../../types.js');
const require_keyDidMapping = require('../dids/domain/key-type/keyDidMapping.js');
const require_DidsApi = require('../dids/DidsApi.js');
require('../dids/index.js');
const require_ClaimFormat = require('../vc/models/ClaimFormat.js');
const require_W3cV2SdJwtVerifiableCredential = require('../vc/sd-jwt-vc/W3cV2SdJwtVerifiableCredential.js');
const require_W3cV2EnvelopedVerifiableCredential = require('../vc/models/credential/W3cV2EnvelopedVerifiableCredential.js');
const require_jsonld_signatures = require('../vc/data-integrity/libraries/jsonld-signatures.js');
const require_SignatureSuiteRegistry = require('../vc/data-integrity/SignatureSuiteRegistry.js');
const require_W3cPresentation = require('../vc/models/presentation/W3cPresentation.js');
const require_W3cJsonLdCredentialService = require('../vc/data-integrity/W3cJsonLdCredentialService.js');
const require_W3cV2Presentation = require('../vc/models/presentation/W3cV2Presentation.js');
const require_W3cV2SdJwtCredentialService = require('../vc/sd-jwt-vc/W3cV2SdJwtCredentialService.js');
require('../vc/sd-jwt-vc/index.js');
const require_W3cCredentialRepository = require('../vc/repository/W3cCredentialRepository.js');
const require_W3cV2CredentialRepository = require('../vc/repository/W3cV2CredentialRepository.js');
const require_W3cCredentialService = require('../vc/W3cCredentialService.js');
const require_W3cV2CredentialService = require('../vc/W3cV2CredentialService.js');
require('../vc/index.js');
const require_Mdoc = require('../mdoc/Mdoc.js');
const require_MdocDeviceResponse = require('../mdoc/MdocDeviceResponse.js');
const require_MdocApi = require('../mdoc/MdocApi.js');
require('../mdoc/index.js');
const require_disclosureFrame = require('../sd-jwt-vc/disclosureFrame.js');
const require_SdJwtVcService = require('../sd-jwt-vc/SdJwtVcService.js');
const require_SdJwtVcApi = require('../sd-jwt-vc/SdJwtVcApi.js');
require('../sd-jwt-vc/index.js');
const require_DcqlError = require('./DcqlError.js');
const require_DcqlPresentationsToCreate = require('./utils/DcqlPresentationsToCreate.js');
require('./utils/index.js');
let tsyringe = require("tsyringe");
tsyringe = require_rolldown_runtime.__toESM(tsyringe);
let dcql = require("dcql");
dcql = require_rolldown_runtime.__toESM(dcql);

//#region src/modules/dcql/DcqlService.ts
let DcqlService = class DcqlService$1 {
	/**
	* Queries the wallet for credentials that match the given dcql query. This only does an initial query based on the
	* schema of the input descriptors. It does not do any further filtering based on the constraints in the input descriptors.
	*/
	async queryCredentialsForDcqlQuery(agentContext, dcqlQuery) {
		const formats = new Set(dcqlQuery.credentials.map((c) => c.format));
		const allRecords = [];
		const mdocDoctypes = dcqlQuery.credentials.filter((credentialQuery) => credentialQuery.format === "mso_mdoc").map((c) => c.meta?.doctype_value);
		const mdocApi = this.getMdocApi(agentContext);
		if (mdocDoctypes.every((doctype) => doctype !== void 0)) {
			const mdocRecords = await mdocApi.findAllByQuery({ $or: mdocDoctypes.map((docType) => ({ docType })) });
			allRecords.push(...mdocRecords);
		} else if (formats.has("mso_mdoc")) {
			const mdocRecords = await mdocApi.getAll();
			allRecords.push(...mdocRecords);
		}
		const sdJwts = dcqlQuery.credentials.filter((credentialQuery) => credentialQuery.format === "vc+sd-jwt" && !(credentialQuery.meta && "type_values" in credentialQuery.meta) || credentialQuery.format === "dc+sd-jwt");
		const sdJwtVctValues = sdJwts.flatMap((c) => c.meta?.vct_values);
		const sdJwtVcApi = this.getSdJwtVcApi(agentContext);
		if (sdJwtVctValues.every((vct) => vct !== void 0)) {
			const sdjwtVcRecords = await sdJwtVcApi.findAllByQuery({ $or: sdJwtVctValues.map((vct) => ({ vct })) });
			allRecords.push(...sdjwtVcRecords);
		} else if (sdJwts.length > 0) {
			const sdJwtVcRecords = await sdJwtVcApi.getAll();
			allRecords.push(...sdJwtVcRecords);
		}
		const w3cCredentialRepository = agentContext.dependencyManager.resolve(require_W3cCredentialRepository.W3cCredentialRepository);
		if (formats.has("jwt_vc_json")) {
			const w3cRecords = await w3cCredentialRepository.findByQuery(agentContext, {
				claimFormat: require_ClaimFormat.ClaimFormat.JwtVc,
				$or: dcqlQuery.credentials.flatMap((c) => c.format === "jwt_vc_json" ? c.meta.type_values : []).map((typeValues) => ({ types: typeValues }))
			});
			allRecords.push(...w3cRecords);
		}
		if (formats.has("ldp_vc")) {
			const w3cRecords = await w3cCredentialRepository.findByQuery(agentContext, {
				claimFormat: require_ClaimFormat.ClaimFormat.LdpVc,
				$or: dcqlQuery.credentials.flatMap((c) => c.format === "jwt_vc_json" ? c.meta.type_values : []).map((typeValues) => ({ expandedTypes: typeValues }))
			});
			allRecords.push(...w3cRecords);
		}
		if (dcqlQuery.credentials.filter((credentialQuery) => credentialQuery.format === "vc+sd-jwt" && !!credentialQuery.meta && "type_values" in credentialQuery.meta).length > 0) {
			const w3cV2Records = await agentContext.dependencyManager.resolve(require_W3cV2CredentialRepository.W3cV2CredentialRepository).findByQuery(agentContext, {
				claimFormat: require_ClaimFormat.ClaimFormat.SdJwtW3cVc,
				$or: dcqlQuery.credentials.flatMap((c) => c.format === "vc+sd-jwt" && c.meta && "type_values" in c.meta ? c.meta.type_values : []).map((typeValues) => ({ types: typeValues }))
			});
			allRecords.push(...w3cV2Records);
		}
		return allRecords;
	}
	async getDcqlCredentialRepresentation(agentContext, presentation, queryCredential) {
		if (presentation.claimFormat === require_ClaimFormat.ClaimFormat.SdJwtDc) return {
			cryptographic_holder_binding: true,
			credential_format: queryCredential.format === "dc+sd-jwt" ? "dc+sd-jwt" : "vc+sd-jwt",
			vct: presentation.prettyClaims.vct,
			claims: presentation.prettyClaims
		};
		if (presentation.claimFormat === require_ClaimFormat.ClaimFormat.MsoMdoc) {
			if (presentation.documents.length !== 1) throw new require_DcqlError.DcqlError("MDOC presentations must contain exactly one document");
			return {
				cryptographic_holder_binding: true,
				credential_format: "mso_mdoc",
				doctype: presentation.documents[0].docType,
				namespaces: presentation.documents[0].issuerSignedNamespaces
			};
		}
		if (presentation.claimFormat === require_ClaimFormat.ClaimFormat.JwtVp) {
			const vc = Array.isArray(presentation.verifiableCredential) ? presentation.verifiableCredential[0].jsonCredential : presentation.verifiableCredential;
			return {
				cryptographic_holder_binding: true,
				credential_format: "jwt_vc_json",
				claims: vc.jsonCredential,
				type: vc.type
			};
		}
		if (presentation.claimFormat === require_ClaimFormat.ClaimFormat.LdpVp) {
			const vc = Array.isArray(presentation.verifiableCredential) ? presentation.verifiableCredential[0] : presentation.verifiableCredential;
			const expandedTypes = await agentContext.dependencyManager.resolve(require_W3cJsonLdCredentialService.W3cJsonLdCredentialService).getExpandedTypesForCredential(agentContext, vc);
			return {
				cryptographic_holder_binding: true,
				credential_format: "ldp_vc",
				claims: vc.jsonCredential,
				type: expandedTypes
			};
		}
		if (presentation.claimFormat === require_ClaimFormat.ClaimFormat.SdJwtW3cVp) {
			const vc = Array.isArray(presentation.resolvedPresentation.verifiableCredential) ? presentation.resolvedPresentation.verifiableCredential[0].resolvedCredential : presentation.resolvedPresentation.verifiableCredential.resolvedCredential;
			return {
				cryptographic_holder_binding: true,
				credential_format: "vc+sd-jwt",
				type: require_array.asArray(vc.type),
				claims: vc.toJSON()
			};
		}
		throw new require_DcqlError.DcqlError("Unsupported claim format for presentation");
	}
	async getCredentialsForRequest(agentContext, dcqlQuery) {
		const credentialRecords = await this.queryCredentialsForDcqlQuery(agentContext, dcqlQuery);
		const credentialRecordsWithFormatDuplicates = [];
		const dcqlCredentials = credentialRecords.flatMap((record) => {
			if (record.type === "MdocRecord") {
				credentialRecordsWithFormatDuplicates.push(record);
				const mdoc = require_Mdoc.Mdoc.fromBase64Url(record.base64Url);
				const akiValues = mdoc.issuerSignedCertificateChain.map((c) => {
					const akiHex = require_X509Certificate.X509Certificate.fromRawCertificate(c).authorityKeyIdentifier;
					return akiHex ? require_TypedArrayEncoder.TypedArrayEncoder.toBase64URL(require_TypedArrayEncoder.TypedArrayEncoder.fromHex(akiHex)) : void 0;
				}).filter((aki) => aki !== void 0);
				return {
					authority: require_types.isNonEmptyArray(akiValues) ? {
						type: "aki",
						values: akiValues
					} : void 0,
					credential_format: "mso_mdoc",
					doctype: record.getTags().docType,
					namespaces: mdoc.issuerSignedNamespaces,
					cryptographic_holder_binding: true
				};
			}
			if (record.type === "SdJwtVcRecord") {
				const sdJwtVc = this.getSdJwtVcApi(agentContext).fromCompact(record.compactSdJwtVc);
				const claims = sdJwtVc.prettyClaims;
				const akiValues = sdJwtVc.header.x5c?.map((c) => {
					const akiHex = require_X509Certificate.X509Certificate.fromEncodedCertificate(c).authorityKeyIdentifier;
					return akiHex ? require_TypedArrayEncoder.TypedArrayEncoder.toBase64URL(require_TypedArrayEncoder.TypedArrayEncoder.fromHex(akiHex)) : void 0;
				}).filter((aki) => aki !== void 0);
				const authority = akiValues && require_types.isNonEmptyArray(akiValues) ? {
					type: "aki",
					values: akiValues
				} : void 0;
				credentialRecordsWithFormatDuplicates.push(record, record);
				return [{
					authority,
					credential_format: "dc+sd-jwt",
					vct: record.getTags().vct,
					claims,
					cryptographic_holder_binding: true
				}, {
					authority,
					credential_format: "vc+sd-jwt",
					vct: record.getTags().vct,
					claims,
					cryptographic_holder_binding: true
				}];
			}
			if (record.type === "W3cCredentialRecord") {
				credentialRecordsWithFormatDuplicates.push(record);
				if (record.credential.claimFormat === require_ClaimFormat.ClaimFormat.LdpVc) return {
					credential_format: "ldp_vc",
					type: record.getTags().expandedTypes ?? [],
					claims: record.credential.jsonCredential,
					cryptographic_holder_binding: true
				};
				return {
					credential_format: "jwt_vc_json",
					type: record.credential.type,
					claims: record.credential.jsonCredential,
					cryptographic_holder_binding: true
				};
			}
			if (record.type === "W3cV2CredentialRecord") {
				credentialRecordsWithFormatDuplicates.push(record);
				return {
					credential_format: "vc+sd-jwt",
					type: require_array.asArray(record.credential.resolvedCredential.type),
					claims: record.credential.resolvedCredential.toJSON(),
					cryptographic_holder_binding: true
				};
			}
			throw new require_DcqlError.DcqlError("Unsupported record type");
		});
		const queryResult = dcql.DcqlQuery.query(dcql.DcqlQuery.parse(dcqlQuery), dcqlCredentials);
		const matchesWithRecord = Object.fromEntries(Object.entries(queryResult.credential_matches).map(([credential_query_id, result]) => {
			const failedCredentials = result.failed_credentials ? require_types.mapNonEmptyArray(result.failed_credentials, (credential) => {
				const record = credentialRecordsWithFormatDuplicates[credential.input_credential_index];
				return {
					...credential,
					record,
					claims: credential.claims.success ? {
						...credential.claims,
						success: true,
						valid_claim_sets: require_types.mapNonEmptyArray(credential.claims.valid_claim_sets, (claimSet) => ({
							...claimSet,
							...record.type === "SdJwtVcRecord" ? { output: agentContext.dependencyManager.resolve(require_SdJwtVcService.SdJwtVcService).applyDisclosuresForPayload(record.compactSdJwtVc, claimSet.output).prettyClaims } : record.type === "W3cV2CredentialRecord" && record.credential instanceof require_W3cV2SdJwtVerifiableCredential.W3cV2SdJwtVerifiableCredential ? { output: agentContext.dependencyManager.resolve(require_SdJwtVcService.SdJwtVcService).applyDisclosuresForPayload(record.credential.encoded, claimSet.output).prettyClaims } : {}
						}))
					} : credential.claims
				};
			}) : void 0;
			if (!result.success) return [credential_query_id, {
				...result,
				failed_credentials: failedCredentials
			}];
			return [credential_query_id, {
				...result,
				failed_credentials: failedCredentials,
				valid_credentials: require_types.mapNonEmptyArray(result.valid_credentials, (credential) => {
					const record = credentialRecordsWithFormatDuplicates[credential.input_credential_index];
					return {
						...credential,
						record,
						claims: {
							...credential.claims,
							valid_claim_sets: require_types.mapNonEmptyArray(credential.claims.valid_claim_sets, (claimSet) => ({
								...claimSet,
								...record.type === "SdJwtVcRecord" ? { output: agentContext.dependencyManager.resolve(require_SdJwtVcService.SdJwtVcService).applyDisclosuresForPayload(record.compactSdJwtVc, claimSet.output).prettyClaims } : record.type === "W3cV2CredentialRecord" && record.credential instanceof require_W3cV2SdJwtVerifiableCredential.W3cV2SdJwtVerifiableCredential ? { output: agentContext.dependencyManager.resolve(require_SdJwtVcService.SdJwtVcService).applyDisclosuresForPayload(record.credential.encoded, claimSet.output).prettyClaims } : {}
							}))
						}
					};
				})
			}];
		}));
		return {
			...queryResult,
			credential_matches: matchesWithRecord
		};
	}
	async assertValidDcqlPresentation(agentContext, dcqlPresentation, dcqlQuery) {
		const internalDcqlPresentation = Object.fromEntries(await Promise.all(Object.entries(dcqlPresentation).map(async ([credentialId, presentations]) => {
			const queryCredential = dcqlQuery.credentials.find((c) => c.id === credentialId);
			if (!queryCredential) throw new require_DcqlError.DcqlError(`DCQL presentation contains presentation entry for credential id '${credentialId}', but this id is not present in the DCQL query`);
			return [credentialId, await Promise.all(presentations.map((presentation) => this.getDcqlCredentialRepresentation(agentContext, presentation, queryCredential)))];
		})));
		const presentationResult = dcql.DcqlPresentationResult.fromDcqlPresentation(internalDcqlPresentation, { dcqlQuery });
		if (!presentationResult.can_be_satisfied) throw new require_DcqlError.DcqlError("Presentations do not satisfy the DCQL query.", { additionalMessages: Object.entries(presentationResult.credential_matches ?? {}).flatMap(([queryId, match]) => match.success ? void 0 : !match.failed_credentials ? `Unable to match query credential '${queryId}'. No prsentations provided` : match.failed_credentials.map((failedCredential) => `Presentation at index ${failedCredential.input_credential_index} does not match query credential '${queryId}'. ${JSON.stringify({
			...failedCredential.claims.success ? {} : { claims: failedCredential.claims.failed_claim_sets.map((cs) => cs.issues) },
			...failedCredential.trusted_authorities.success ? {} : { trusted_authorities: failedCredential.trusted_authorities.failed_trusted_authorities.map((ta) => ta.issues) },
			...failedCredential.meta.success ? {} : { meta: failedCredential.meta.issues }
		}, null, 2)}`)).filter((message) => message !== void 0) });
		return presentationResult;
	}
	dcqlCredentialForRequestForValidCredential(validCredential) {
		if (validCredential.record.type === "MdocRecord") return {
			claimFormat: require_ClaimFormat.ClaimFormat.MsoMdoc,
			credentialRecord: validCredential.record,
			disclosedPayload: validCredential.claims.valid_claim_sets[0].output
		};
		if (validCredential.record.type === "SdJwtVcRecord") return {
			claimFormat: require_ClaimFormat.ClaimFormat.SdJwtDc,
			credentialRecord: validCredential.record,
			disclosedPayload: validCredential.claims.valid_claim_sets[0].output
		};
		if (validCredential.record.type === "W3cCredentialRecord") return {
			claimFormat: validCredential.record.credential.claimFormat,
			credentialRecord: validCredential.record,
			disclosedPayload: validCredential.record.credential.jsonCredential
		};
		if (validCredential.record.type === "W3cV2CredentialRecord") return {
			claimFormat: validCredential.record.credential.claimFormat,
			credentialRecord: validCredential.record,
			disclosedPayload: validCredential.claims.valid_claim_sets[0].output
		};
		throw new require_DcqlError.DcqlError("Unsupported record type for DCQL");
	}
	/**
	* Selects the credentials to use based on the output from `getCredentialsForRequest`
	* Use this method if you don't want to manually select the credentials yourself.
	*/
	selectCredentialsForRequest(dcqlQueryResult) {
		if (!dcqlQueryResult.can_be_satisfied) throw new require_DcqlError.DcqlError("Cannot select the credentials for the dcql query presentation if the request cannot be satisfied");
		const credentials = {};
		if (dcqlQueryResult.credential_sets) for (const credentialSet of dcqlQueryResult.credential_sets) {
			if (credentialSet.required === false) continue;
			const firstFullFillableOption = credentialSet.options.find((option) => option.every((credential_id) => dcqlQueryResult.credential_matches[credential_id].success));
			if (!firstFullFillableOption) throw new require_DcqlError.DcqlError("Invalid dcql query result. No option is fullfillable");
			for (const credentialQueryId of firstFullFillableOption) {
				const credentialMatch = dcqlQueryResult.credential_matches[credentialQueryId];
				if (!credentialMatch.success) throw new require_DcqlError.DcqlError("Invalid dcql query result. Cannot auto-select credentials");
				const credential = credentialMatch.valid_credentials[0];
				credentials[credentialQueryId] = [this.dcqlCredentialForRequestForValidCredential(credential)];
			}
		}
		else for (const credentialQuery of dcqlQueryResult.credentials) {
			const credentialMatch = dcqlQueryResult.credential_matches[credentialQuery.id];
			if (!credentialMatch.success) throw new require_DcqlError.DcqlError("Invalid dcql query result. Cannot auto-select credentials");
			const credential = credentialMatch.valid_credentials[0];
			credentials[credentialQuery.id] = [this.dcqlCredentialForRequestForValidCredential(credential)];
		}
		return credentials;
	}
	validateDcqlQuery(dcqlQuery) {
		const parsed = dcql.DcqlQuery.parse(dcqlQuery);
		dcql.DcqlQuery.validate(parsed);
		return parsed;
	}
	async createPresentation(agentContext, options) {
		const { domain, challenge, mdocSessionTranscript } = options;
		const dcqlPresentation = {};
		const encodedDcqlPresentation = {};
		const vcPresentationsToCreate = require_DcqlPresentationsToCreate.dcqlGetPresentationsToCreate(options.credentialQueryToCredential);
		for (const [credentialQueryId, presentationsToCreate] of Object.entries(vcPresentationsToCreate)) for (const presentationToCreate of presentationsToCreate) {
			let createdPresentation;
			let encodedCreatedPresentation;
			if (presentationToCreate.claimFormat === require_ClaimFormat.ClaimFormat.MsoMdoc) {
				const mdocRecord = presentationToCreate.credentialRecord;
				if (!mdocSessionTranscript) throw new require_DcqlError.DcqlError("Missing mdoc session transcript options for creating MDOC presentation.");
				const deviceResponse = await require_MdocDeviceResponse.MdocDeviceResponse.createDeviceResponse(agentContext, {
					mdocs: [require_Mdoc.Mdoc.fromBase64Url(mdocRecord.base64Url)],
					documentRequests: [{
						docType: mdocRecord.getTags().docType,
						nameSpaces: Object.fromEntries(Object.entries(presentationToCreate.disclosedPayload).map(([key, value]) => {
							return [key, Object.fromEntries(Object.entries(value).map(([key$1]) => [key$1, false]))];
						}))
					}],
					sessionTranscriptOptions: mdocSessionTranscript
				});
				const deviceResponseBase64Url = require_TypedArrayEncoder.TypedArrayEncoder.toBase64URL(deviceResponse);
				encodedCreatedPresentation = deviceResponseBase64Url;
				createdPresentation = require_MdocDeviceResponse.MdocDeviceResponse.fromBase64Url(deviceResponseBase64Url);
			} else if (presentationToCreate.claimFormat === require_ClaimFormat.ClaimFormat.SdJwtDc) {
				const presentationFrame = require_disclosureFrame.buildDisclosureFrameForPayload(presentationToCreate.disclosedPayload);
				if (!domain) throw new require_DcqlError.DcqlError("Missing domain property for creating SdJwtVc presentation.");
				const sdJwtVcApi = this.getSdJwtVcApi(agentContext);
				const presentation = await sdJwtVcApi.present({
					compactSdJwtVc: presentationToCreate.credentialRecord.compactSdJwtVc,
					presentationFrame,
					verifierMetadata: {
						audience: domain,
						nonce: challenge,
						issuedAt: Math.floor(Date.now() / 1e3)
					},
					additionalPayload: presentationToCreate.additionalPayload
				});
				encodedCreatedPresentation = presentation;
				createdPresentation = sdJwtVcApi.fromCompact(presentation);
			} else if (presentationToCreate.claimFormat === require_ClaimFormat.ClaimFormat.JwtVp) {
				if (!presentationToCreate.subjectIds) throw new require_DcqlError.DcqlError("Cannot create presentation for credentials without subject id");
				const verificationMethod = await this.getVerificationMethodForSubjectId(agentContext, presentationToCreate.subjectIds[0]);
				const w3cCredentialService = agentContext.resolve(require_W3cCredentialService.W3cCredentialService);
				const w3cPresentation = new require_W3cPresentation.W3cPresentation({
					verifiableCredential: [presentationToCreate.credentialRecord.credential],
					holder: verificationMethod.controller
				});
				const publicJwk = require_keyDidMapping.getPublicJwkFromVerificationMethod(verificationMethod);
				const signedPresentation = await w3cCredentialService.signPresentation(agentContext, {
					format: require_ClaimFormat.ClaimFormat.JwtVp,
					alg: publicJwk.signatureAlgorithm,
					verificationMethod: verificationMethod.id,
					presentation: w3cPresentation,
					challenge,
					domain
				});
				encodedCreatedPresentation = signedPresentation.encoded;
				createdPresentation = signedPresentation;
			} else if (presentationToCreate.claimFormat === require_ClaimFormat.ClaimFormat.LdpVp) {
				if (!presentationToCreate.subjectIds) throw new require_DcqlError.DcqlError("Cannot create presentation for credentials without subject id");
				const verificationMethod = await this.getVerificationMethodForSubjectId(agentContext, presentationToCreate.subjectIds[0]);
				const w3cCredentialService = agentContext.resolve(require_W3cCredentialService.W3cCredentialService);
				const w3cPresentation = new require_W3cPresentation.W3cPresentation({
					verifiableCredential: [presentationToCreate.credentialRecord.credential],
					holder: verificationMethod.controller
				});
				const signedPresentation = await w3cCredentialService.signPresentation(agentContext, {
					format: require_ClaimFormat.ClaimFormat.LdpVp,
					proofType: this.getProofTypeForLdpVc(agentContext, verificationMethod),
					proofPurpose: new require_jsonld_signatures.purposes.AuthenticationProofPurpose({
						challenge,
						domain
					}),
					verificationMethod: verificationMethod.id,
					presentation: w3cPresentation,
					challenge,
					domain
				});
				encodedCreatedPresentation = signedPresentation.encoded;
				createdPresentation = signedPresentation;
			} else if (presentationToCreate.claimFormat === require_ClaimFormat.ClaimFormat.JwtW3cVp) {
				if (!presentationToCreate.subjectIds) throw new require_DcqlError.DcqlError("Cannot create presentation for credentials without subject id");
				const w3cV2CredentialService = agentContext.resolve(require_W3cV2CredentialService.W3cV2CredentialService);
				const w3cV2Presentation = new require_W3cV2Presentation.W3cV2Presentation({
					holder: presentationToCreate.credentialRecord.credential.resolvedCredential.credentialSubjectIds[0],
					verifiableCredential: [require_W3cV2EnvelopedVerifiableCredential.W3cV2EnvelopedVerifiableCredential.fromVerifiableCredential(presentationToCreate.credentialRecord.credential)]
				});
				const signedPresentation = await w3cV2CredentialService.signPresentation(agentContext, {
					format: require_ClaimFormat.ClaimFormat.JwtW3cVp,
					presentation: w3cV2Presentation,
					challenge,
					domain
				});
				encodedCreatedPresentation = signedPresentation.encoded;
				createdPresentation = signedPresentation;
			} else if (presentationToCreate.claimFormat === require_ClaimFormat.ClaimFormat.SdJwtW3cVp) {
				if (!presentationToCreate.subjectIds) throw new require_DcqlError.DcqlError("Cannot create presentation for credentials without subject id");
				const presentationFrame = require_disclosureFrame.buildDisclosureFrameForPayload(presentationToCreate.disclosedPayload);
				if (!domain) throw new require_DcqlError.DcqlError("Missing domain property for creating SdJwtVc presentation.");
				const sdJwtVc = await agentContext.resolve(require_W3cV2SdJwtCredentialService.W3cV2SdJwtCredentialService).present(agentContext, {
					credential: presentationToCreate.credentialRecord.credential.encoded,
					presentationFrame
				});
				const w3cV2CredentialService = agentContext.resolve(require_W3cV2CredentialService.W3cV2CredentialService);
				const w3cV2Presentation = new require_W3cV2Presentation.W3cV2Presentation({
					holder: presentationToCreate.credentialRecord.credential.resolvedCredential.credentialSchemaIds[0],
					verifiableCredential: [require_W3cV2EnvelopedVerifiableCredential.W3cV2EnvelopedVerifiableCredential.fromVerifiableCredential(sdJwtVc)]
				});
				const signedPresentation = await w3cV2CredentialService.signPresentation(agentContext, {
					format: require_ClaimFormat.ClaimFormat.SdJwtW3cVp,
					presentation: w3cV2Presentation,
					challenge,
					domain
				});
				encodedCreatedPresentation = signedPresentation.encoded;
				createdPresentation = signedPresentation;
			} else throw new require_DcqlError.DcqlError("Unsupported presentation format.");
			if (!dcqlPresentation[credentialQueryId]) dcqlPresentation[credentialQueryId] = [createdPresentation];
			else dcqlPresentation[credentialQueryId].push(createdPresentation);
			if (!encodedDcqlPresentation[credentialQueryId]) encodedDcqlPresentation[credentialQueryId] = [encodedCreatedPresentation];
			else encodedDcqlPresentation[credentialQueryId].push(encodedCreatedPresentation);
		}
		return {
			dcqlPresentation,
			encodedDcqlPresentation
		};
	}
	getSdJwtVcApi(agentContext) {
		return agentContext.dependencyManager.resolve(require_SdJwtVcApi.SdJwtVcApi);
	}
	getMdocApi(agentContext) {
		return agentContext.dependencyManager.resolve(require_MdocApi.MdocApi);
	}
	async getVerificationMethodForSubjectId(agentContext, subjectId) {
		const didsApi = agentContext.dependencyManager.resolve(require_DidsApi.DidsApi);
		if (!subjectId.startsWith("did:")) throw new require_DcqlError.DcqlError(`Only dids are supported as credentialSubject id. ${subjectId} is not a valid did`);
		const didDocument = await didsApi.resolveDidDocument(subjectId);
		if (!didDocument.authentication || didDocument.authentication.length === 0) throw new require_DcqlError.DcqlError(`No authentication verificationMethods found for did ${subjectId} in did document`);
		let [verificationMethod] = didDocument.authentication;
		if (typeof verificationMethod === "string") verificationMethod = didDocument.dereferenceKey(verificationMethod, ["authentication"]);
		return verificationMethod;
	}
	getProofTypeForLdpVc(agentContext, verificationMethod) {
		const signatureSuiteRegistry = agentContext.dependencyManager.resolve(require_SignatureSuiteRegistry.SignatureSuiteRegistry);
		const publicJwk = require_keyDidMapping.getPublicJwkFromVerificationMethod(verificationMethod);
		const supportedSignatureSuites = signatureSuiteRegistry.getAllByPublicJwkType(publicJwk);
		if (supportedSignatureSuites.length === 0) throw new require_DcqlError.DcqlError(`Couldn't find a supported signature suite for the given jwk ${publicJwk.jwkTypehumanDescription}`);
		return supportedSignatureSuites[0].proofType;
	}
};
DcqlService = require_decorate.__decorate([(0, tsyringe.injectable)()], DcqlService);

//#endregion
Object.defineProperty(exports, 'DcqlService', {
  enumerable: true,
  get: function () {
    return DcqlService;
  }
});