mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 11:57:29 +01:00
Simplifying the refactoring of the DecryptAndIndexProcessor
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user