Removing additional dependencies in the base Event class

This commit is contained in:
Vitor Pamplona 2025-01-15 08:53:13 -05:00
parent 8e25271bd6
commit d1c64a0d15
8 changed files with 14 additions and 31 deletions

View File

@ -36,6 +36,7 @@ import com.vitorpamplona.quartz.experimental.nns.NNSEvent
import com.vitorpamplona.quartz.experimental.profileGallery.ProfileGalleryEntryEvent
import com.vitorpamplona.quartz.experimental.relationshipStatus.RelationshipStatusEvent
import com.vitorpamplona.quartz.experimental.zapPolls.PollNoteEvent
import com.vitorpamplona.quartz.nip01Core.EventHasher
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.MetadataEvent
import com.vitorpamplona.quartz.nip01Core.core.Event
@ -155,7 +156,7 @@ class EventFactory {
ChatMessageEncryptedFileHeaderEvent.KIND -> {
if (id.isBlank()) {
ChatMessageEncryptedFileHeaderEvent(
Event.generateId(pubKey, createdAt, kind, tags, content),
EventHasher.hashId(pubKey, createdAt, kind, tags, content),
pubKey,
createdAt,
tags,
@ -169,7 +170,7 @@ class EventFactory {
ChatMessageEvent.KIND -> {
if (id.isBlank()) {
ChatMessageEvent(
Event.generateId(pubKey, createdAt, kind, tags, content),
EventHasher.hashId(pubKey, createdAt, kind, tags, content),
pubKey,
createdAt,
tags,

View File

@ -25,6 +25,7 @@ import androidx.compose.runtime.Immutable
import com.fasterxml.jackson.module.kotlin.readValue
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.BaseAddressableEvent
import com.vitorpamplona.quartz.nip01Core.core.TagArray
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
@ -88,7 +89,7 @@ class PrivateOutboxRelayListEvent(
try {
signer.nip44Decrypt(content, pubKey) {
try {
privateTagsCache = EventMapper.mapper.readValue<Array<Array<String>>>(it)
privateTagsCache = EventMapper.mapper.readValue<TagArray>(it)
privateTagsCache?.let { onReady(it) }
} catch (e: Throwable) {
Log.w("PrivateOutboxRelayListEvent", "Error parsing the JSON: ${e.message}. Json `$it` from event `${toNostrUri()}`")

View File

@ -31,7 +31,7 @@ open class BaseAddressableEvent(
pubKey: HexKey,
createdAt: Long,
kind: Int,
tags: Array<Array<String>>,
tags: TagArray,
content: String,
sig: HexKey,
) : Event(id, pubKey, createdAt, kind, tags, content, sig),

View File

@ -22,7 +22,6 @@ package com.vitorpamplona.quartz.nip01Core.core
import androidx.compose.runtime.Immutable
import com.fasterxml.jackson.annotation.JsonProperty
import com.vitorpamplona.quartz.nip01Core.EventHasher
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.jackson.EventManualSerializer
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
@ -57,24 +56,6 @@ open class Event(
companion object {
fun fromJson(json: String): Event = EventMapper.fromJson(json)
fun toJson(event: Event): String = EventMapper.toJson(event)
fun generateId(
pubKey: HexKey,
createdAt: Long,
kind: Int,
tags: Array<Array<String>>,
content: String,
): HexKey = EventHasher.hashId(pubKey, createdAt, kind, tags, content)
fun generateIdBytes(
pubKey: HexKey,
createdAt: Long,
kind: Int,
tags: Array<Array<String>>,
content: String,
): ByteArray = EventHasher.hashIdBytes(pubKey, createdAt, kind, tags, content)
fun create(
signer: NostrSigner,
kind: Int,

View File

@ -21,6 +21,7 @@
package com.vitorpamplona.quartz.nip01Core.signers
import com.vitorpamplona.quartz.EventFactory
import com.vitorpamplona.quartz.nip01Core.EventHasher
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip04Dm.Nip04
@ -86,11 +87,9 @@ abstract class NostrSigner(
content: String,
onReady: (T) -> Unit,
) {
val id = Event.generateId(pubKey, createdAt, kind, tags, content)
onReady(
EventFactory.create(
id = id,
id = EventHasher.hashId(pubKey, createdAt, kind, tags, content),
pubKey = pubKey,
createdAt = createdAt,
kind = kind,

View File

@ -23,6 +23,7 @@ package com.vitorpamplona.quartz.nip01Core.signers
import android.util.Log
import com.vitorpamplona.quartz.CryptoUtils
import com.vitorpamplona.quartz.EventFactory
import com.vitorpamplona.quartz.nip01Core.EventHasher
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.KeyPair
import com.vitorpamplona.quartz.nip01Core.core.Event
@ -67,7 +68,7 @@ class NostrSignerSync(
): T? {
if (keyPair.privKey == null) return null
val id = Event.generateIdBytes(pubKey, createdAt, kind, tags, content)
val id = EventHasher.hashIdBytes(pubKey, createdAt, kind, tags, content)
val sig = CryptoUtils.sign(id, keyPair.privKey).toHexKey()
return EventFactory.create(

View File

@ -23,6 +23,7 @@ package com.vitorpamplona.quartz.nip55AndroidSigner
import android.util.Log
import com.goterl.lazysodium.BuildConfig
import com.vitorpamplona.quartz.EventFactory
import com.vitorpamplona.quartz.nip01Core.EventHasher
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
@ -40,11 +41,9 @@ class NostrSignerExternal(
content: String,
onReady: (T) -> Unit,
) {
val id = Event.generateId(pubKey, createdAt, kind, tags, content)
val event =
Event(
id = id,
id = EventHasher.hashId(pubKey, createdAt, kind, tags, content),
pubKey = pubKey,
createdAt = createdAt,
kind = kind,

View File

@ -22,6 +22,7 @@ package com.vitorpamplona.quartz.nip59Giftwrap
import com.fasterxml.jackson.annotation.JsonProperty
import com.vitorpamplona.quartz.EventFactory
import com.vitorpamplona.quartz.nip01Core.EventHasher
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
@ -40,7 +41,7 @@ class Gossip(
val newKind = kind ?: -1
val newTags = (tags ?: emptyArray()).plus(event.tags)
val newContent = content ?: ""
val newID = id?.ifBlank { null } ?: Event.generateId(newPubKey, newCreatedAt, newKind, newTags, newContent)
val newID = id?.ifBlank { null } ?: EventHasher.hashId(newPubKey, newCreatedAt, newKind, newTags, newContent)
val sig = ""
return EventFactory.create(newID, newPubKey, newCreatedAt, newKind, newTags, newContent, sig)