

const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.js');
const require_KeyManagementError = require('../error/KeyManagementError.js');
const require_zod = require('../../../utils/zod.js');
const require_ecJwk = require('./kty/ec/ecJwk.js');
const require_octJwk = require('./kty/oct/octJwk.js');
const require_okpJwk = require('./kty/okp/okpJwk.js');
const require_rsaJwk = require('./kty/rsa/rsaJwk.js');
let zod = require("zod");

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

//#endregion
exports.assertJwkAsymmetric = assertJwkAsymmetric;
exports.isJwkAsymmetric = isJwkAsymmetric;
exports.publicJwkFromPrivateJwk = publicJwkFromPrivateJwk;
exports.zKmsJwkPrivate = zKmsJwkPrivate;
exports.zKmsJwkPublic = zKmsJwkPublic;
exports.zKmsJwkPublicAsymmetric = zKmsJwkPublicAsymmetric;