Skip to content

Commit

Permalink
fix: 337-null-pointer-exception-when-deleting-a-didjwk (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean authored Sep 17, 2023
1 parent adf5bfe commit 7d7119a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/main/kotlin/id/walt/services/did/DidService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ object DidService {
//region did-delete
fun deleteDid(didUrl: String) {
loadOrResolveAnyDid(didUrl)?.let { did ->
didCache.invalidate(DidUrl.from(didUrl))
didCache.invalidate(did.url)
ContextManager.hkvStore.delete(HKVKey("did", "created", didUrl), recursive = true)
did.verificationMethod?.forEach {
ContextManager.keyStore.delete(it.id)
Expand Down Expand Up @@ -164,10 +164,9 @@ object DidService {

fun loadOrResolveAnyDid(didStr: String): Did? {
log.debug { "Loading or resolving \"$didStr\"..." }
val url = DidUrl.from(didStr)
val storedDid = loadDid(didStr)

log.debug { "loadOrResolve: url=$url, length of stored=${storedDid?.length}" }
val url = runCatching { DidUrl.from(didStr) }.fold(onSuccess = { it }, onFailure = { null })
log.debug { "loadOrResolve: url=${url ?: didStr}, length of stored=${storedDid?.length}" }
return when (storedDid) {
null -> resolve(didStr).also { did -> storeDid(did) }
else -> Did.decode(storedDid)
Expand Down

0 comments on commit 7d7119a

Please sign in to comment.