

const require_KeyManagementError = require('./error/KeyManagementError.js');
const require_TypedArrayEncoder = require('../../utils/TypedArrayEncoder.js');
require('../../utils/index.js');
require('./jwk/index.js');

//#region src/modules/kms/legacy.ts
/**
* Returns the legacy key id based on the public key encoded as base58
*
* This is what was has been used by askar
*/
function legacyKeyIdFromPublicJwk(publicJwk) {
	const compresedPublicKey = publicJwk.compressedPublicKey;
	if (compresedPublicKey) return require_TypedArrayEncoder.TypedArrayEncoder.toBase58(compresedPublicKey.publicKey);
	const publicKey = publicJwk.publicKey;
	if (publicKey.kty === "RSA") throw new require_KeyManagementError.KeyManagementError("Unable to derive legacy key id from RSA key. Support for RSA keys was only added after explit key ids were added.");
	return require_TypedArrayEncoder.TypedArrayEncoder.toBase58(publicKey.publicKey);
}

//#endregion
exports.legacyKeyIdFromPublicJwk = legacyKeyIdFromPublicJwk;