const require_rolldown_runtime = require('../../../../../../../../_virtual/rolldown_runtime.js');
const require_index = require('../../../../../../../../node_modules/.pnpm/class-transformer@0.5.1/node_modules/class-transformer/cjs/index.js');
const require_PublicKey = require('../publicKey/PublicKey.js');
const require_index$1 = require('../publicKey/index.js');
const require_Authentication = require('./Authentication.js');
const require_EmbeddedAuthentication = require('./EmbeddedAuthentication.js');
const require_ReferencedAuthentication = require('./ReferencedAuthentication.js');
let __credo_ts_core = require("@credo-ts/core");
__credo_ts_core = require_rolldown_runtime.__toESM(__credo_ts_core);

//#region ../didcomm/src/modules/connections/models/did/authentication/index.ts
var import_cjs = /* @__PURE__ */ require_rolldown_runtime.__toESM(require_index.require_cjs());
const authenticationTypes = {
	RsaVerificationKey2018: "RsaSignatureAuthentication2018",
	Ed25519VerificationKey2018: "Ed25519SignatureAuthentication2018",
	Secp256k1VerificationKey2018: "Secp256k1SignatureAuthenticationKey2018"
};
/**
* Decorator that transforms authentication json to corresponding class instances. See {@link authenticationTypes}
*
* @example
* class Example {
*   AuthenticationTransformer()
*   private authentication: Authentication
* }
*/
function AuthenticationTransformer() {
	return (0, import_cjs.Transform)(({ value, obj, type }) => {
		if (type === import_cjs.TransformationType.PLAIN_TO_CLASS) return value.map((auth) => {
			if (auth.publicKey) {
				const publicKeyJson = obj.publicKey.find((publicKey) => publicKey.id === auth.publicKey);
				if (!publicKeyJson) throw new __credo_ts_core.CredoError(`Invalid public key referenced ${auth.publicKey}`);
				return new require_ReferencedAuthentication.ReferencedAuthentication((0, import_cjs.plainToInstance)(require_index$1.publicKeyTypes[publicKeyJson.type] ?? require_PublicKey.PublicKey, publicKeyJson), auth.type);
			}
			return new require_EmbeddedAuthentication.EmbeddedAuthentication((0, import_cjs.plainToInstance)(require_index$1.publicKeyTypes[auth.type] ?? require_PublicKey.PublicKey, auth));
		});
		return value.map((auth) => auth instanceof require_EmbeddedAuthentication.EmbeddedAuthentication ? (0, import_cjs.instanceToPlain)(auth.publicKey) : auth);
	});
}

//#endregion
exports.AuthenticationTransformer = AuthenticationTransformer;
exports.authenticationTypes = authenticationTypes;