@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
40 lines (39 loc) • 2.13 kB
JavaScript
import { parseDid } from "../../dids/domain/parse.mjs";
import { getPublicJwkFromVerificationMethod } from "../../dids/domain/key-type/keyDidMapping.mjs";
import { DidsApi } from "../../dids/DidsApi.mjs";
import "../../dids/index.mjs";
//#region src/modules/w3c-di/proof-processing/keyUtils.ts
/**
* Extract public JWK from a verification method identifier.
*
* Resolves the DID document, dereferences the verification method,
* and extracts the public JWK.
*
* @param agentContext - The agent context for DID resolution
* @param verificationMethodId - The verification method identifier (typically a DID fragment)
* @returns Promise<PublicJwk> - The public JWK from the verification method
*/
async function publicJwkFromVerificationMethodId(agentContext, verificationMethodId) {
const verificationMethod = (await agentContext.dependencyManager.resolve(DidsApi).resolveDidDocument(verificationMethodId)).dereferenceVerificationMethod(verificationMethodId);
return getPublicJwkFromVerificationMethod(verificationMethod);
}
/**
* Map a verification method identifier to its KMS key ID.
*
* Attempts to find the key ID in the DID record's key metadata.
* Falls back to the public JWK's legacy key ID if not found.
*
* @param agentContext - The agent context for DID resolution and key lookup
* @param verificationMethodId - The verification method identifier (typically a DID fragment)
* @returns Promise<string> - The KMS key ID for the verification method
*/
async function publicKeyIdFromVerificationMethodId(agentContext, verificationMethodId) {
const didApi = agentContext.dependencyManager.resolve(DidsApi);
const parsedDid = parseDid(verificationMethodId);
const [didRecord] = await didApi.getCreatedDids({ did: parsedDid.did });
const publicJwk = await publicJwkFromVerificationMethodId(agentContext, verificationMethodId);
return didRecord?.keys?.find(({ didDocumentRelativeKeyId }) => didDocumentRelativeKeyId === `#${parsedDid.fragment}`)?.kmsKeyId ?? publicJwk.legacyKeyId;
}
//#endregion
export { publicJwkFromVerificationMethodId, publicKeyIdFromVerificationMethodId };
//# sourceMappingURL=keyUtils.mjs.map