

const require_CredoError = require('../../../../error/CredoError.js');
require('../../../../error/index.js');
const require_humanDescription = require('../../../kms/jwk/humanDescription.js');
const require_PublicJwk = require('../../../kms/jwk/PublicJwk.js');
require('../../../kms/index.js');
const require_VerificationMethod = require('./VerificationMethod.js');

//#region src/modules/dids/domain/verificationMethod/Ed25519VerificationKey2020.ts
const VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2020 = "Ed25519VerificationKey2020";
/**
* Get a Ed25519VerificationKey2020 verification method.
*/
function getEd25519VerificationKey2020({ publicJwk, id, controller }) {
	return new require_VerificationMethod.VerificationMethod({
		id,
		type: VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2020,
		controller,
		publicKeyMultibase: publicJwk.fingerprint
	});
}
/**
* Check whether a verification method is a Ed25519VerificationKey2020 verification method.
*/
function isEd25519VerificationKey2020(verificationMethod) {
	return verificationMethod.type === VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2020;
}
/**
* Get a key from a Ed25519VerificationKey2020 verification method.
*/
function getPublicJwkFromEd25519VerificationKey2020(verificationMethod) {
	if (!verificationMethod.publicKeyMultibase) throw new require_CredoError.CredoError("verification method is missing publicKeyMultibase");
	const publicJwk = require_PublicJwk.PublicJwk.fromFingerprint(verificationMethod.publicKeyMultibase);
	const publicKey = publicJwk.publicKey;
	if (publicKey.kty !== "OKP" || publicKey.crv !== "Ed25519") throw new require_CredoError.CredoError(`Verification method ${verificationMethod.type} is for unexpected ${require_humanDescription.getJwkHumanDescription(publicJwk.toJson())}.`);
	return publicJwk;
}

//#endregion
exports.VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2020 = VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2020;
exports.getEd25519VerificationKey2020 = getEd25519VerificationKey2020;
exports.getPublicJwkFromEd25519VerificationKey2020 = getPublicJwkFromEd25519VerificationKey2020;
exports.isEd25519VerificationKey2020 = isEd25519VerificationKey2020;