Skip to content

Commit

Permalink
feat: Add support to find keys by thumbprint, and not have to resolve…
Browse files Browse the repository at this point in the history
… to DID resolution in all cases
  • Loading branch information
nklomp committed Jun 20, 2024
1 parent e332562 commit d37c772
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/did-utils/src/did-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,18 @@ export async function getKey(
if (!identifier) {
return Promise.reject(new Error(`No identifier provided to getKey method!`))
}
const keys = await mapIdentifierKeysToDocWithJwkSupport(identifier, verificationMethodSection, context)
if (!keys || keys.length === 0) {
throw new Error(`No keys found for verificationMethodSection: ${verificationMethodSection} and did ${identifier.did}`)
let identifierKey = keyId ? identifier.keys.find((key: IKey) => key.kid === keyId || key?.meta?.jwkThumbprint === keyId) : undefined
if (!identifierKey) {
const keys = await mapIdentifierKeysToDocWithJwkSupport(identifier, verificationMethodSection, context)
if (!keys || keys.length === 0) {
throw new Error(`No keys found for verificationMethodSection: ${verificationMethodSection} and did ${identifier.did}`)
}
identifierKey = keyId ? keys.find((key: _ExtendedIKey) => key.meta.verificationMethod.id === keyId) : keys[0]
}

const identifierKey = keyId ? keys.find((key: _ExtendedIKey) => key.kid === keyId || key.meta.verificationMethod.id === keyId) : keys[0]
if (!identifierKey) {
throw new Error(`No matching verificationMethodSection key found for keyId: ${keyId}`)
throw new Error(
`No matching verificationMethodSection key found for keyId: ${keyId} and vmSection: ${verificationMethodSection} for id ${identifier.did}`
)
}

return identifierKey
Expand Down

0 comments on commit d37c772

Please sign in to comment.