

import { CredoError } from "../../error/CredoError.mjs";
import "../../error/index.mjs";
import { TypedArrayEncoder } from "../../utils/TypedArrayEncoder.mjs";
import { isDid } from "../../utils/did.mjs";
import "../../utils/index.mjs";
import { Ed25519PublicJwk } from "../kms/jwk/kty/okp/Ed25519PublicJwk.mjs";
import { PublicJwk } from "../kms/jwk/PublicJwk.mjs";
import "../kms/index.mjs";
import { DidKey } from "./methods/key/DidKey.mjs";

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

//#endregion
export { didKeyToEd25519PublicJwk, didKeyToVerkey, isDidKey, verkeyToDidKey, verkeyToPublicJwk };
//# sourceMappingURL=helpers.mjs.map