Simplifying the refactoring of the DecryptAndIndexProcessor

This commit is contained in:
Vitor Pamplona
2025-08-05 15:04:23 -04:00
parent 4675212e1d
commit 63f62167a4
5 changed files with 140 additions and 244 deletions

View File

@@ -31,7 +31,7 @@ class PrivateDMCache(
private val decryptionCache =
object : LruCache<PrivateDmEvent, PrivateDMDecryptCache>(10000) {
override fun create(key: PrivateDmEvent): PrivateDMDecryptCache? {
val canDecrypt = key.canDecrypt(signer.pubKey)
val canDecrypt = key.isIncluded(signer.pubKey)
return if (key.content.isNotBlank() && canDecrypt) {
PrivateDMDecryptCache(signer)
} else {

View File

@@ -58,12 +58,12 @@ class PrivateDmEvent(
override fun isContentEncoded() = true
fun canDecrypt(signer: NostrSigner) = canDecrypt(signer.pubKey)
fun isIncluded(signer: NostrSigner) = isIncluded(signer.pubKey)
fun canDecrypt(signerPubKey: HexKey) = pubKey == signerPubKey || recipientPubKey() == signerPubKey
override fun isIncluded(user: HexKey) = pubKey == user || recipientPubKey() == user
suspend fun decryptContent(signer: NostrSigner): String {
if (!canDecrypt(signer.pubKey)) throw SignerExceptions.UnauthorizedDecryptionException()
if (!isIncluded(signer.pubKey)) throw SignerExceptions.UnauthorizedDecryptionException()
val retVal = signer.decrypt(content, talkingWith(signer.pubKey))
return if (retVal.startsWith(NIP_18_ADVERTISEMENT)) {

View File

@@ -21,7 +21,10 @@
package com.vitorpamplona.quartz.nip17Dm.base
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.IEvent
interface ChatroomKeyable : IEvent {
fun isIncluded(user: HexKey): Boolean
interface ChatroomKeyable {
fun chatroomKey(toRemove: HexKey): ChatroomKey
}