

import { X25519PublicJwk } from "../kms/jwk/kty/okp/X25519PublicJwk.mjs";
import { Ed25519PublicJwk } from "../kms/jwk/kty/okp/Ed25519PublicJwk.mjs";
import { assymetricPublicJwkMatches } from "../kms/jwk/equals.mjs";
import "../kms/index.mjs";
import "./domain/verificationMethod/index.mjs";
import { getPublicJwkFromVerificationMethod } from "./domain/key-type/keyDidMapping.mjs";
import "./domain/DidDocument.mjs";

//#region src/modules/dids/findMatchingEd25519Key.ts
/**
* Tries to find a matching Ed25519 key to the supplied X25519 key
* @param x25519Key X25519 key
* @param didDocument Did document containing all the keys
* @returns a matching Ed25519 key or `undefined` (if no matching key found)
*/
function findMatchingEd25519Key(x25519Key, didDocument) {
	const verificationMethods = didDocument.verificationMethod ?? [];
	const keyAgreements = didDocument.keyAgreement ?? [];
	const authentications = didDocument.authentication ?? [];
	return [
		...verificationMethods,
		...authentications.filter((keyAgreement) => typeof keyAgreement !== "string"),
		...keyAgreements.filter((keyAgreement) => typeof keyAgreement !== "string")
	].map((keyReference) => {
		const verificationMethod = didDocument.dereferenceKey(keyReference.id);
		return {
			publicJwk: getPublicJwkFromVerificationMethod(verificationMethod),
			verificationMethod
		};
	}).find((v) => {
		if (!v.publicJwk.is(Ed25519PublicJwk)) return false;
		return assymetricPublicJwkMatches(v.publicJwk.convertTo(X25519PublicJwk).toJson(), x25519Key.toJson());
	});
}

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