

import { CredoError } from "../../error/CredoError.mjs";
import "../../error/index.mjs";
import { injectable } from "../../plugins/index.mjs";
import { __decorateMetadata } from "../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.mjs";
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.mjs";
import { CREDENTIALS_CONTEXT_V1_URL } from "./constants.mjs";
import { ClaimFormat } from "./models/ClaimFormat.mjs";
import { W3cJsonLdVerifiableCredential } from "./data-integrity/models/W3cJsonLdVerifiableCredential.mjs";
import { W3cJwtVerifiableCredential } from "./jwt-vc/W3cJwtVerifiableCredential.mjs";
import { W3cPresentation } from "./models/presentation/W3cPresentation.mjs";
import { W3cJsonLdVerifiablePresentation } from "./data-integrity/models/W3cJsonLdVerifiablePresentation.mjs";
import { W3cJsonLdCredentialService } from "./data-integrity/W3cJsonLdCredentialService.mjs";
import "./data-integrity/index.mjs";
import { W3cJwtVerifiablePresentation } from "./jwt-vc/W3cJwtVerifiablePresentation.mjs";
import { W3cJwtCredentialService } from "./jwt-vc/W3cJwtCredentialService.mjs";
import "./jwt-vc/index.mjs";
import "./models/index.mjs";
import { W3cCredentialRecord } from "./repository/W3cCredentialRecord.mjs";
import { W3cCredentialRepository } from "./repository/W3cCredentialRepository.mjs";
import "./repository/index.mjs";

//#region src/modules/vc/W3cCredentialService.ts
var _ref, _ref2, _ref3;
let W3cCredentialService = class W3cCredentialService$1 {
	constructor(w3cCredentialRepository, w3cJsonLdCredentialService, w3cJwtCredentialService) {
		this.w3cCredentialRepository = w3cCredentialRepository;
		this.w3cJsonLdCredentialService = w3cJsonLdCredentialService;
		this.w3cJwtCredentialService = w3cJwtCredentialService;
	}
	/**
	* Signs a credential
	*
	* @param credential the credential to be signed
	* @returns the signed credential
	*/
	async signCredential(agentContext, options) {
		if (options.format === ClaimFormat.JwtVc) return await this.w3cJwtCredentialService.signCredential(agentContext, options);
		if (options.format === ClaimFormat.LdpVc) return await this.w3cJsonLdCredentialService.signCredential(agentContext, options);
		throw new CredoError(`Unsupported format in options. Format must be either 'jwt_vc' or 'ldp_vc'`);
	}
	/**
	* Verifies the signature(s) of a credential
	*/
	async verifyCredential(agentContext, options) {
		if (options.credential instanceof W3cJsonLdVerifiableCredential) return this.w3cJsonLdCredentialService.verifyCredential(agentContext, options);
		if (options.credential instanceof W3cJwtVerifiableCredential || typeof options.credential === "string") return this.w3cJwtCredentialService.verifyCredential(agentContext, options);
		throw new CredoError("Unsupported credential type in options. Credential must be either a W3cJsonLdVerifiableCredential or a W3cJwtVerifiableCredential");
	}
	/**
	* Utility method that creates a {@link W3cPresentation} from one or more {@link W3cJsonLdVerifiableCredential}s.
	*
	* **NOTE: the presentation that is returned is unsigned.**
	*
	* @returns An instance of {@link W3cPresentation}
	*/
	async createPresentation(options) {
		return new W3cPresentation({
			context: [CREDENTIALS_CONTEXT_V1_URL],
			type: ["VerifiablePresentation"],
			verifiableCredential: options.credentials,
			holder: options.holder,
			id: options.id
		});
	}
	/**
	* Signs a presentation including the credentials it includes
	*
	* @param presentation the presentation to be signed
	* @returns the signed presentation
	*/
	async signPresentation(agentContext, options) {
		if (options.format === ClaimFormat.JwtVp) return await this.w3cJwtCredentialService.signPresentation(agentContext, options);
		if (options.format === ClaimFormat.LdpVp) return await this.w3cJsonLdCredentialService.signPresentation(agentContext, options);
		throw new CredoError(`Unsupported format in options. Format must be either 'jwt_vp' or 'ldp_vp'`);
	}
	/**
	* Verifies a presentation including the credentials it includes
	*
	* @param presentation the presentation to be verified
	* @returns the verification result
	*/
	async verifyPresentation(agentContext, options) {
		if (options.presentation instanceof W3cJsonLdVerifiablePresentation) return this.w3cJsonLdCredentialService.verifyPresentation(agentContext, options);
		if (options.presentation instanceof W3cJwtVerifiablePresentation || typeof options.presentation === "string") return this.w3cJwtCredentialService.verifyPresentation(agentContext, options);
		throw new CredoError("Unsupported credential type in options. Presentation must be either a W3cJsonLdVerifiablePresentation or a W3cJwtVerifiablePresentation");
	}
	/**
	* Writes a credential to storage
	*
	* @param record the credential to be stored
	* @returns the credential record that was written to storage
	*/
	async storeCredential(agentContext, options) {
		let expandedTypes = [];
		if (options.credential instanceof W3cJsonLdVerifiableCredential) expandedTypes = await this.w3cJsonLdCredentialService.getExpandedTypesForCredential(agentContext, options.credential);
		const w3cCredentialRecord = new W3cCredentialRecord({
			tags: { expandedTypes },
			credential: options.credential
		});
		await this.w3cCredentialRepository.save(agentContext, w3cCredentialRecord);
		return w3cCredentialRecord;
	}
	async removeCredentialRecord(agentContext, id) {
		await this.w3cCredentialRepository.deleteById(agentContext, id);
	}
	async getAllCredentialRecords(agentContext) {
		return await this.w3cCredentialRepository.getAll(agentContext);
	}
	async getCredentialRecordById(agentContext, id) {
		return await this.w3cCredentialRepository.getById(agentContext, id);
	}
	async findCredentialsByQuery(agentContext, query, queryOptions) {
		return (await this.w3cCredentialRepository.findByQuery(agentContext, query, queryOptions)).map((record) => record.credential);
	}
	async findCredentialRecordByQuery(agentContext, query) {
		return (await this.w3cCredentialRepository.findSingleByQuery(agentContext, query))?.credential;
	}
};
W3cCredentialService = __decorate([injectable(), __decorateMetadata("design:paramtypes", [
	typeof (_ref = typeof W3cCredentialRepository !== "undefined" && W3cCredentialRepository) === "function" ? _ref : Object,
	typeof (_ref2 = typeof W3cJsonLdCredentialService !== "undefined" && W3cJsonLdCredentialService) === "function" ? _ref2 : Object,
	typeof (_ref3 = typeof W3cJwtCredentialService !== "undefined" && W3cJwtCredentialService) === "function" ? _ref3 : Object
])], W3cCredentialService);

//#endregion
export { W3cCredentialService };
//# sourceMappingURL=W3cCredentialService.mjs.map