

import { CredoError } from "../../../../error/CredoError.mjs";
import "../../../../error/index.mjs";
import { PublicJwk } from "../../../kms/jwk/PublicJwk.mjs";
import "../../../kms/index.mjs";
import { getPublicJwkFromJsonWebKey2020, isJsonWebKey2020 } from "../verificationMethod/JsonWebKey2020.mjs";
import { getPublicJwkFromMultikey, isMultikey } from "../verificationMethod/Multikey.mjs";
import "../verificationMethod/index.mjs";
import { keyDidEd25519 } from "./ed25519.mjs";
import { keyDidJsonWebKey } from "./keyDidJsonWebKey.mjs";
import { keyDidSecp256k1 } from "./secp256k1.mjs";
import { keyDidX25519 } from "./x25519.mjs";

//#region src/modules/dids/domain/key-type/keyDidMapping.ts
const supportedKeyDids = [
	keyDidEd25519,
	keyDidX25519,
	keyDidJsonWebKey,
	keyDidSecp256k1
];
function getVerificationMethodsForPublicJwk(publicJwk, did) {
	const { getVerificationMethods } = getKeyDidMappingByPublicJwk(publicJwk);
	return getVerificationMethods(did, publicJwk);
}
function getSupportedVerificationMethodTypesForPublicJwk(publicJwk) {
	const { supportedVerificationMethodTypes } = getKeyDidMappingByPublicJwk(publicJwk);
	return supportedVerificationMethodTypes;
}
function getPublicJwkFromVerificationMethod(verificationMethod) {
	if (isJsonWebKey2020(verificationMethod)) return getPublicJwkFromJsonWebKey2020(verificationMethod);
	if (isMultikey(verificationMethod)) return getPublicJwkFromMultikey(verificationMethod);
	const keyDid = supportedKeyDids.find((keyDid$1) => keyDid$1.supportedVerificationMethodTypes.includes(verificationMethod.type));
	if (!keyDid) throw new CredoError(`Unsupported key did from verification method type '${verificationMethod.type}'`);
	return keyDid.getPublicJwkFromVerificationMethod(verificationMethod);
}
function getKeyDidMappingByPublicJwk(jwk) {
	const jwkTypeClass = jwk instanceof PublicJwk ? jwk.JwkClass : jwk;
	const keyDid = supportedKeyDids.find((supportedKeyDid) => supportedKeyDid.PublicJwkTypes.includes(jwkTypeClass));
	if (!keyDid) throw new CredoError(`Unsupported did mapping for jwk '${jwk instanceof PublicJwk ? jwk.jwkTypehumanDescription : jwk.name}'`);
	return keyDid;
}

//#endregion
export { getPublicJwkFromVerificationMethod, getSupportedVerificationMethodTypesForPublicJwk, getVerificationMethodsForPublicJwk };
//# sourceMappingURL=keyDidMapping.mjs.map