@credo-ts/core
Version:
<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1
42 lines (41 loc) • 1.59 kB
JavaScript
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;
const ed25519Key = verkeyToPublicJwk(verkey);
return new DidKey(ed25519Key).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