

const require_CredoError = require('../../error/CredoError.js');
require('../../error/index.js');
const require_TypedArrayEncoder = require('../../utils/TypedArrayEncoder.js');
const require_did = require('../../utils/did.js');
require('../../utils/index.js');
const require_Ed25519PublicJwk = require('../kms/jwk/kty/okp/Ed25519PublicJwk.js');
const require_PublicJwk = require('../kms/jwk/PublicJwk.js');
require('../kms/index.js');
const require_DidKey = require('./methods/key/DidKey.js');

//#region src/modules/dids/helpers.ts
function isDidKey(key) {
	return require_did.isDid(key, "key");
}
function didKeyToVerkey(key) {
	if (isDidKey(key)) {
		const publicKey = require_DidKey.DidKey.fromDid(key).publicJwk.publicKey;
		if (publicKey.kty !== "OKP" || publicKey.crv !== "Ed25519") throw new require_CredoError.CredoError("Expected OKP key with crv Ed25519");
		return require_TypedArrayEncoder.TypedArrayEncoder.toBase58(publicKey.publicKey);
	}
	return key;
}
function verkeyToDidKey(verkey) {
	if (isDidKey(verkey)) return verkey;
	return new require_DidKey.DidKey(verkeyToPublicJwk(verkey)).did;
}
function didKeyToEd25519PublicJwk(key) {
	const didKey = require_DidKey.DidKey.fromDid(key);
	if (didKey.publicJwk.is(require_Ed25519PublicJwk.Ed25519PublicJwk)) return didKey.publicJwk;
	throw new require_CredoError.CredoError(`Expected public jwk to have kty OKP with crv Ed25519, found ${didKey.publicJwk.jwkTypehumanDescription}`);
}
function verkeyToPublicJwk(verkey) {
	return require_PublicJwk.PublicJwk.fromPublicKey({
		kty: "OKP",
		crv: "Ed25519",
		publicKey: require_TypedArrayEncoder.TypedArrayEncoder.fromBase58(verkey)
	});
}

//#endregion
exports.didKeyToEd25519PublicJwk = didKeyToEd25519PublicJwk;
exports.didKeyToVerkey = didKeyToVerkey;
exports.isDidKey = isDidKey;
exports.verkeyToDidKey = verkeyToDidKey;
exports.verkeyToPublicJwk = verkeyToPublicJwk;