

const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
const require_CredoError = require('../../error/CredoError.js');
require('../../error/index.js');
require('../../plugins/index.js');
const require_decorateMetadata = require('../../_virtual/_@oxc-project_runtime@0.97.0/helpers/decorateMetadata.js');
const require_decorate = require('../../_virtual/_@oxc-project_runtime@0.97.0/helpers/decorate.js');
const require_constants = require('./constants.js');
const require_ClaimFormat = require('./models/ClaimFormat.js');
const require_W3cJsonLdVerifiableCredential = require('./data-integrity/models/W3cJsonLdVerifiableCredential.js');
const require_W3cJwtVerifiableCredential = require('./jwt-vc/W3cJwtVerifiableCredential.js');
const require_W3cPresentation = require('./models/presentation/W3cPresentation.js');
const require_W3cJwtVerifiablePresentation = require('./jwt-vc/W3cJwtVerifiablePresentation.js');
const require_W3cJwtCredentialService = require('./jwt-vc/W3cJwtCredentialService.js');
require('./jwt-vc/index.js');
require('./models/index.js');
const require_W3cJsonLdVerifiablePresentation = require('./data-integrity/models/W3cJsonLdVerifiablePresentation.js');
const require_W3cJsonLdCredentialService = require('./data-integrity/W3cJsonLdCredentialService.js');
require('./data-integrity/index.js');
const require_W3cCredentialRepository = require('./repository/W3cCredentialRepository.js');
require('./repository/index.js');
let tsyringe = require("tsyringe");

//#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 === require_ClaimFormat.ClaimFormat.JwtVc) return await this.w3cJwtCredentialService.signCredential(agentContext, options);
		if (options.format === require_ClaimFormat.ClaimFormat.LdpVc) return await this.w3cJsonLdCredentialService.signCredential(agentContext, options);
		throw new require_CredoError.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 require_W3cJsonLdVerifiableCredential.W3cJsonLdVerifiableCredential) return this.w3cJsonLdCredentialService.verifyCredential(agentContext, options);
		if (options.credential instanceof require_W3cJwtVerifiableCredential.W3cJwtVerifiableCredential || typeof options.credential === "string") return this.w3cJwtCredentialService.verifyCredential(agentContext, options);
		throw new require_CredoError.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 require_W3cPresentation.W3cPresentation({
			context: [require_constants.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 === require_ClaimFormat.ClaimFormat.JwtVp) return await this.w3cJwtCredentialService.signPresentation(agentContext, options);
		if (options.format === require_ClaimFormat.ClaimFormat.LdpVp) return await this.w3cJsonLdCredentialService.signPresentation(agentContext, options);
		throw new require_CredoError.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 require_W3cJsonLdVerifiablePresentation.W3cJsonLdVerifiablePresentation) return this.w3cJsonLdCredentialService.verifyPresentation(agentContext, options);
		if (options.presentation instanceof require_W3cJwtVerifiablePresentation.W3cJwtVerifiablePresentation || typeof options.presentation === "string") return this.w3cJwtCredentialService.verifyPresentation(agentContext, options);
		throw new require_CredoError.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) {
		const credential = options.record.firstCredential;
		if (credential instanceof require_W3cJsonLdVerifiableCredential.W3cJsonLdVerifiableCredential && !options.record.getTag("expandedTypes")) options.record.setTag("expandedTypes", await this.w3cJsonLdCredentialService.getExpandedTypesForCredential(agentContext, credential));
		await this.w3cCredentialRepository.save(agentContext, options.record);
		return options.record;
	}
	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.firstCredential);
	}
	async findCredentialRecordByQuery(agentContext, query) {
		return (await this.w3cCredentialRepository.findSingleByQuery(agentContext, query))?.firstCredential;
	}
};
W3cCredentialService = require_decorate.__decorate([(0, tsyringe.injectable)(), require_decorateMetadata.__decorateMetadata("design:paramtypes", [
	typeof (_ref = typeof require_W3cCredentialRepository.W3cCredentialRepository !== "undefined" && require_W3cCredentialRepository.W3cCredentialRepository) === "function" ? _ref : Object,
	typeof (_ref2 = typeof require_W3cJsonLdCredentialService.W3cJsonLdCredentialService !== "undefined" && require_W3cJsonLdCredentialService.W3cJsonLdCredentialService) === "function" ? _ref2 : Object,
	typeof (_ref3 = typeof require_W3cJwtCredentialService.W3cJwtCredentialService !== "undefined" && require_W3cJwtCredentialService.W3cJwtCredentialService) === "function" ? _ref3 : Object
])], W3cCredentialService);

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