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

1 lines • 2.56 kB
{"version":3,"file":"findMatchingEd25519Key.mjs","names":[],"sources":["../../../src/modules/dids/findMatchingEd25519Key.ts"],"sourcesContent":["import { asymmetricPublicJwkMatches, Ed25519PublicJwk, PublicJwk, X25519PublicJwk } from '../kms'\nimport type { DidDocument } from './domain/DidDocument'\nimport { getPublicJwkFromVerificationMethod } from './domain/key-type/keyDidMapping'\nimport { VerificationMethod } from './domain/verificationMethod'\n\n/**\n * Tries to find a matching Ed25519 key to the supplied X25519 key\n * @param x25519Key X25519 key\n * @param didDocument Did document containing all the keys\n * @returns a matching Ed25519 key or `undefined` (if no matching key found)\n */\nexport function findMatchingEd25519Key(\n x25519Key: PublicJwk<X25519PublicJwk>,\n didDocument: DidDocument\n): { publicJwk: PublicJwk<Ed25519PublicJwk>; verificationMethod: VerificationMethod } | undefined {\n const verificationMethods = didDocument.verificationMethod ?? []\n const keyAgreements = didDocument.keyAgreement ?? []\n const authentications = didDocument.authentication ?? []\n const allKeyReferences: VerificationMethod[] = [\n ...verificationMethods,\n ...authentications.filter((keyAgreement): keyAgreement is VerificationMethod => typeof keyAgreement !== 'string'),\n ...keyAgreements.filter((keyAgreement): keyAgreement is VerificationMethod => typeof keyAgreement !== 'string'),\n ]\n\n return allKeyReferences\n .map((keyReference) => {\n const verificationMethod = didDocument.dereferenceKey(keyReference.id)\n return {\n publicJwk: getPublicJwkFromVerificationMethod(verificationMethod),\n verificationMethod,\n }\n })\n\n .find((v): v is typeof v & { publicJwk: PublicJwk<Ed25519PublicJwk> } => {\n if (!v.publicJwk.is(Ed25519PublicJwk)) return false\n\n const keyX25519 = v.publicJwk.convertTo(X25519PublicJwk)\n return asymmetricPublicJwkMatches(keyX25519.toJson(), x25519Key.toJson())\n })\n}\n"],"mappings":";;;;;;;;;;;;;AAWA,SAAgB,uBACd,WACA,aACgG;CAChG,MAAM,sBAAsB,YAAY,sBAAsB,CAAC;CAC/D,MAAM,gBAAgB,YAAY,gBAAgB,CAAC;CACnD,MAAM,kBAAkB,YAAY,kBAAkB,CAAC;CAOvD,OAAO;EALL,GAAG;EACH,GAAG,gBAAgB,QAAQ,iBAAqD,OAAO,iBAAiB,QAAQ;EAChH,GAAG,cAAc,QAAQ,iBAAqD,OAAO,iBAAiB,QAAQ;CAG1F,CAAC,CACpB,KAAK,iBAAiB;EACrB,MAAM,qBAAqB,YAAY,eAAe,aAAa,EAAE;EACrE,OAAO;GACL,WAAW,mCAAmC,kBAAkB;GAChE;EACF;CACF,CAAC,CAAC,CAED,MAAM,MAAkE;EACvE,IAAI,CAAC,EAAE,UAAU,GAAG,gBAAgB,GAAG,OAAO;EAE9C,MAAM,YAAY,EAAE,UAAU,UAAU,eAAe;EACvD,OAAO,2BAA2B,UAAU,OAAO,GAAG,UAAU,OAAO,CAAC;CAC1E,CAAC;AACL"}