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 • 3.05 kB
{"version":3,"file":"keyUtils.mjs","names":[],"sources":["../../../../src/modules/w3c-di/proof-processing/keyUtils.ts"],"sourcesContent":["import type { AgentContext } from '../../../agent/context'\nimport { DidsApi, getPublicJwkFromVerificationMethod, parseDid } from '../../dids'\nimport type { PublicJwk } from '../../kms'\n\n/**\n * Extract public JWK from a verification method identifier.\n *\n * Resolves the DID document, dereferences the verification method,\n * and extracts the public JWK.\n *\n * @param agentContext - The agent context for DID resolution\n * @param verificationMethodId - The verification method identifier (typically a DID fragment)\n * @returns Promise<PublicJwk> - The public JWK from the verification method\n */\nexport async function publicJwkFromVerificationMethodId(\n agentContext: AgentContext,\n verificationMethodId: string\n): Promise<PublicJwk> {\n // Currently only DID-backed verification methods are supported. To support non-DID\n // verification method URLs (e.g. HTTP key registries), introduce a documentLoader\n // parameter here and dispatch on URL scheme before falling back to DidsApi resolution.\n const didApi = agentContext.dependencyManager.resolve(DidsApi)\n const didDocument = await didApi.resolveDidDocument(verificationMethodId)\n const verificationMethod = didDocument.dereferenceVerificationMethod(verificationMethodId)\n const publicJwk = getPublicJwkFromVerificationMethod(verificationMethod)\n return publicJwk\n}\n\n/**\n * Map a verification method identifier to its KMS key ID.\n *\n * Attempts to find the key ID in the DID record's key metadata.\n * Falls back to the public JWK's legacy key ID if not found.\n *\n * @param agentContext - The agent context for DID resolution and key lookup\n * @param verificationMethodId - The verification method identifier (typically a DID fragment)\n * @returns Promise<string> - The KMS key ID for the verification method\n */\nexport async function publicKeyIdFromVerificationMethodId(\n agentContext: AgentContext,\n verificationMethodId: string\n): Promise<string> {\n const didApi = agentContext.dependencyManager.resolve(DidsApi)\n const parsedDid = parseDid(verificationMethodId)\n const [didRecord] = await didApi.getCreatedDids({ did: parsedDid.did })\n\n const publicJwk = await publicJwkFromVerificationMethodId(agentContext, verificationMethodId)\n return (\n didRecord?.keys?.find(({ didDocumentRelativeKeyId }) => didDocumentRelativeKeyId === `#${parsedDid.fragment}`)\n ?.kmsKeyId ?? publicJwk.legacyKeyId\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,eAAsB,kCACpB,cACA,sBACoB;CAMpB,MAAM,sBAAqB,MAFZ,aAAa,kBAAkB,QAAQ,OACvB,CAAC,CAAC,mBAAmB,oBAAoB,EAAA,CACjC,8BAA8B,oBAAoB;CAEzF,OADkB,mCAAmC,kBACtC;AACjB;;;;;;;;;;;AAYA,eAAsB,oCACpB,cACA,sBACiB;CACjB,MAAM,SAAS,aAAa,kBAAkB,QAAQ,OAAO;CAC7D,MAAM,YAAY,SAAS,oBAAoB;CAC/C,MAAM,CAAC,aAAa,MAAM,OAAO,eAAe,EAAE,KAAK,UAAU,IAAI,CAAC;CAEtE,MAAM,YAAY,MAAM,kCAAkC,cAAc,oBAAoB;CAC5F,OACE,WAAW,MAAM,MAAM,EAAE,+BAA+B,6BAA6B,IAAI,UAAU,UAAU,CAAC,EAC1G,YAAY,UAAU;AAE9B"}