

const require_P256PublicJwk = require('../../modules/kms/jwk/kty/ec/P256PublicJwk.js');
const require_P384PublicJwk = require('../../modules/kms/jwk/kty/ec/P384PublicJwk.js');
const require_P521PublicJwk = require('../../modules/kms/jwk/kty/ec/P521PublicJwk.js');
const require_Secp256k1PublicJwk = require('../../modules/kms/jwk/kty/ec/Secp256k1PublicJwk.js');
const require_Ed25519PublicJwk = require('../../modules/kms/jwk/kty/okp/Ed25519PublicJwk.js');
const require_RsaPublicJwk = require('../../modules/kms/jwk/kty/rsa/RsaPublicJwk.js');
require('../../modules/kms/index.js');
const require_CredoWebCryptoError = require('./CredoWebCryptoError.js');

//#region src/crypto/webcrypto/types.ts
/**
* Derives the JWA algorithm name from KeySignParams or KeyVerifyParams
* @param params - The signing or verification parameters
* @returns The corresponding JWA algorithm string
*/
function keyParamsToJwaAlgorithm(params, key) {
	if (params.name === "Ed25519") {
		if (!key.publicJwk.is(require_Ed25519PublicJwk.Ed25519PublicJwk)) throw new require_CredoWebCryptoError.CredoWebCryptoError(`Unsupported key for algorithm for Ed25519: ${key.publicJwk.jwkTypehumanDescription}`);
		return "EdDSA";
	}
	if (params.name === "ECDSA") {
		const hashName = typeof params.hash === "string" ? params.hash : params.hash.name;
		if (key.publicJwk.is(require_Secp256k1PublicJwk.Secp256k1PublicJwk)) switch (hashName) {
			case "SHA-256": return "ES256K";
			default: throw new require_CredoWebCryptoError.CredoWebCryptoError(`Unsupported hash algorithm for ECDSA with Secp255K1: ${hashName}`);
		}
		if (key.publicJwk.is(require_P256PublicJwk.P256PublicJwk)) switch (hashName) {
			case "SHA-256": return "ES256";
			default: throw new require_CredoWebCryptoError.CredoWebCryptoError(`Unsupported hash algorithm for ECDSA with P256: ${hashName}`);
		}
		if (key.publicJwk.is(require_P384PublicJwk.P384PublicJwk)) switch (hashName) {
			case "SHA-384": return "ES384";
			default: throw new require_CredoWebCryptoError.CredoWebCryptoError(`Unsupported hash algorithm for ECDSA with P384: ${hashName}`);
		}
		if (key.publicJwk.is(require_P521PublicJwk.P521PublicJwk)) switch (hashName) {
			case "SHA-512": return "ES512";
			default: throw new require_CredoWebCryptoError.CredoWebCryptoError(`Unsupported hash algorithm for ECDSA with P521: ${hashName}`);
		}
		throw new require_CredoWebCryptoError.CredoWebCryptoError(`Unsupported key ${key.publicJwk.jwkTypehumanDescription} or hash algorithm '${hashName}' for ECDSA`);
	}
	if (params.name === "RSASSA-PKCS1-v1_5") {
		const hashName = typeof params.hash === "string" ? params.hash : params.hash.name;
		if (!key.publicJwk.is(require_RsaPublicJwk.RsaPublicJwk)) throw new require_CredoWebCryptoError.CredoWebCryptoError(`Unsupported key for algorithm for RSASSA-PKCS1-v1_5: ${key.publicJwk.jwkTypehumanDescription}`);
		switch (hashName) {
			case "SHA-256": return "RS256";
			case "SHA-384": return "RS384";
			case "SHA-512": return "RS512";
			default: throw new require_CredoWebCryptoError.CredoWebCryptoError(`Unsupported hash algorithm for RSASSA-PKCS1-v1_5: ${hashName}`);
		}
	}
	if (params.name === "RSA-PSS") {
		const hashName = typeof params.hash === "string" ? params.hash : params.hash.name;
		if (!key.publicJwk.is(require_RsaPublicJwk.RsaPublicJwk)) throw new require_CredoWebCryptoError.CredoWebCryptoError(`Unsupported key for algorithm for RSA-PSS: ${key.publicJwk.jwkTypehumanDescription}`);
		switch (hashName) {
			case "SHA-256": return "PS256";
			case "SHA-384": return "PS384";
			case "SHA-512": return "PS512";
			default: throw new require_CredoWebCryptoError.CredoWebCryptoError(`Unsupported hash algorithm for RSA-PSS: ${hashName}`);
		}
	}
	throw new require_CredoWebCryptoError.CredoWebCryptoError(`Unsupported algorithm: ${params.name}`);
}

//#endregion
exports.keyParamsToJwaAlgorithm = keyParamsToJwaAlgorithm;