UNPKG

@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

37 lines (36 loc) • 1.63 kB
import { asymmetricPublicJwkMatches } from "../kms/jwk/equals.mjs"; import { X25519PublicJwk } from "../kms/jwk/kty/okp/X25519PublicJwk.mjs"; import { Ed25519PublicJwk } from "../kms/jwk/kty/okp/Ed25519PublicJwk.mjs"; import "../kms/index.mjs"; import "./domain/verificationMethod/index.mjs"; import { getPublicJwkFromVerificationMethod } from "./domain/key-type/keyDidMapping.mjs"; //#region src/modules/dids/findMatchingEd25519Key.ts /** * Tries to find a matching Ed25519 key to the supplied X25519 key * @param x25519Key X25519 key * @param didDocument Did document containing all the keys * @returns a matching Ed25519 key or `undefined` (if no matching key found) */ function findMatchingEd25519Key(x25519Key, didDocument) { const verificationMethods = didDocument.verificationMethod ?? []; const keyAgreements = didDocument.keyAgreement ?? []; const authentications = didDocument.authentication ?? []; return [ ...verificationMethods, ...authentications.filter((keyAgreement) => typeof keyAgreement !== "string"), ...keyAgreements.filter((keyAgreement) => typeof keyAgreement !== "string") ].map((keyReference) => { const verificationMethod = didDocument.dereferenceKey(keyReference.id); return { publicJwk: getPublicJwkFromVerificationMethod(verificationMethod), verificationMethod }; }).find((v) => { if (!v.publicJwk.is(Ed25519PublicJwk)) return false; const keyX25519 = v.publicJwk.convertTo(X25519PublicJwk); return asymmetricPublicJwkMatches(keyX25519.toJson(), x25519Key.toJson()); }); } //#endregion export { findMatchingEd25519Key }; //# sourceMappingURL=findMatchingEd25519Key.mjs.map