

import { zParseWithErrorHandling } from "../../../utils/zod.mjs";
import { KeyManagementError } from "../error/KeyManagementError.mjs";
import { zKmsJwkPrivateEc, zKmsJwkPrivateToPublicEc, zKmsJwkPublicEc } from "./kty/ec/ecJwk.mjs";
import { zKmsJwkPrivateOct, zKmsJwkPrivateToPublicOct, zKmsJwkPublicOct } from "./kty/oct/octJwk.mjs";
import { zKmsJwkPrivateOkp, zKmsJwkPrivateToPublicOkp, zKmsJwkPublicOkp } from "./kty/okp/okpJwk.mjs";
import { zKmsJwkPrivateRsa, zKmsJwkPrivateToPublicRsa, zKmsJwkPublicRsa } from "./kty/rsa/rsaJwk.mjs";
import { z } from "zod";

//#region src/modules/kms/jwk/knownJwk.ts
const zKmsJwkPublicAsymmetric = z.discriminatedUnion("kty", [
	zKmsJwkPublicEc,
	zKmsJwkPublicRsa,
	zKmsJwkPublicOkp
]);
function isJwkAsymmetric(jwk) {
	return jwk.kty !== "oct";
}
function assertJwkAsymmetric(jwk, keyId) {
	if (!isJwkAsymmetric(jwk)) {
		if (keyId) throw new KeyManagementError(`Expected jwk with keyId ${keyId} to be an assymetric jwk, but found kty 'oct'`);
		throw new KeyManagementError("Expected jwk to be an assymetric jwk, but found kty 'oct'");
	}
}
const zKmsJwkPublicCrv = z.discriminatedUnion("kty", [zKmsJwkPublicEc, zKmsJwkPublicOkp]);
const zKmsJwkPublic = z.discriminatedUnion("kty", [
	zKmsJwkPublicEc,
	zKmsJwkPublicRsa,
	zKmsJwkPublicOct,
	zKmsJwkPublicOkp
]);
const zKmsJwkPrivateToPublic = z.discriminatedUnion("kty", [
	zKmsJwkPrivateToPublicEc,
	zKmsJwkPrivateToPublicRsa,
	zKmsJwkPrivateToPublicOct,
	zKmsJwkPrivateToPublicOkp
]).transform((jwk) => Object.fromEntries(Object.entries(jwk).filter(([, value]) => value !== void 0)));
const zKmsJwkPrivateCrv = z.discriminatedUnion("kty", [zKmsJwkPrivateEc, zKmsJwkPrivateOkp]);
const zKmsJwkPrivate = z.discriminatedUnion("kty", [
	zKmsJwkPrivateEc,
	zKmsJwkPrivateRsa,
	zKmsJwkPrivateOct,
	zKmsJwkPrivateOkp
]);
const zKmsJwkPrivateAsymmetric = z.discriminatedUnion("kty", [
	zKmsJwkPrivateEc,
	zKmsJwkPrivateRsa,
	zKmsJwkPrivateOkp
]);
function publicJwkFromPrivateJwk(privateJwk) {
	return zParseWithErrorHandling(zKmsJwkPrivateToPublic, privateJwk);
}

//#endregion
export { assertJwkAsymmetric, isJwkAsymmetric, publicJwkFromPrivateJwk, zKmsJwkPrivate, zKmsJwkPublic, zKmsJwkPublicAsymmetric };
//# sourceMappingURL=knownJwk.mjs.map