mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-07-04 23:40:43 +02:00
Removing additional dependencies in the base Event class
This commit is contained in:
@ -36,6 +36,7 @@ import com.vitorpamplona.quartz.experimental.nns.NNSEvent
|
|||||||
import com.vitorpamplona.quartz.experimental.profileGallery.ProfileGalleryEntryEvent
|
import com.vitorpamplona.quartz.experimental.profileGallery.ProfileGalleryEntryEvent
|
||||||
import com.vitorpamplona.quartz.experimental.relationshipStatus.RelationshipStatusEvent
|
import com.vitorpamplona.quartz.experimental.relationshipStatus.RelationshipStatusEvent
|
||||||
import com.vitorpamplona.quartz.experimental.zapPolls.PollNoteEvent
|
import com.vitorpamplona.quartz.experimental.zapPolls.PollNoteEvent
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.EventHasher
|
||||||
import com.vitorpamplona.quartz.nip01Core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||||
import com.vitorpamplona.quartz.nip01Core.MetadataEvent
|
import com.vitorpamplona.quartz.nip01Core.MetadataEvent
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
@ -155,7 +156,7 @@ class EventFactory {
|
|||||||
ChatMessageEncryptedFileHeaderEvent.KIND -> {
|
ChatMessageEncryptedFileHeaderEvent.KIND -> {
|
||||||
if (id.isBlank()) {
|
if (id.isBlank()) {
|
||||||
ChatMessageEncryptedFileHeaderEvent(
|
ChatMessageEncryptedFileHeaderEvent(
|
||||||
Event.generateId(pubKey, createdAt, kind, tags, content),
|
EventHasher.hashId(pubKey, createdAt, kind, tags, content),
|
||||||
pubKey,
|
pubKey,
|
||||||
createdAt,
|
createdAt,
|
||||||
tags,
|
tags,
|
||||||
@ -169,7 +170,7 @@ class EventFactory {
|
|||||||
ChatMessageEvent.KIND -> {
|
ChatMessageEvent.KIND -> {
|
||||||
if (id.isBlank()) {
|
if (id.isBlank()) {
|
||||||
ChatMessageEvent(
|
ChatMessageEvent(
|
||||||
Event.generateId(pubKey, createdAt, kind, tags, content),
|
EventHasher.hashId(pubKey, createdAt, kind, tags, content),
|
||||||
pubKey,
|
pubKey,
|
||||||
createdAt,
|
createdAt,
|
||||||
tags,
|
tags,
|
||||||
|
@ -25,6 +25,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import com.vitorpamplona.quartz.nip01Core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.BaseAddressableEvent
|
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.jackson.EventMapper
|
||||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||||
@ -88,7 +89,7 @@ class PrivateOutboxRelayListEvent(
|
|||||||
try {
|
try {
|
||||||
signer.nip44Decrypt(content, pubKey) {
|
signer.nip44Decrypt(content, pubKey) {
|
||||||
try {
|
try {
|
||||||
privateTagsCache = EventMapper.mapper.readValue<Array<Array<String>>>(it)
|
privateTagsCache = EventMapper.mapper.readValue<TagArray>(it)
|
||||||
privateTagsCache?.let { onReady(it) }
|
privateTagsCache?.let { onReady(it) }
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
Log.w("PrivateOutboxRelayListEvent", "Error parsing the JSON: ${e.message}. Json `$it` from event `${toNostrUri()}`")
|
Log.w("PrivateOutboxRelayListEvent", "Error parsing the JSON: ${e.message}. Json `$it` from event `${toNostrUri()}`")
|
||||||
|
@ -31,7 +31,7 @@ open class BaseAddressableEvent(
|
|||||||
pubKey: HexKey,
|
pubKey: HexKey,
|
||||||
createdAt: Long,
|
createdAt: Long,
|
||||||
kind: Int,
|
kind: Int,
|
||||||
tags: Array<Array<String>>,
|
tags: TagArray,
|
||||||
content: String,
|
content: String,
|
||||||
sig: HexKey,
|
sig: HexKey,
|
||||||
) : Event(id, pubKey, createdAt, kind, tags, content, sig),
|
) : Event(id, pubKey, createdAt, kind, tags, content, sig),
|
||||||
|
@ -22,7 +22,6 @@ package com.vitorpamplona.quartz.nip01Core.core
|
|||||||
|
|
||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import com.vitorpamplona.quartz.nip01Core.EventHasher
|
|
||||||
import com.vitorpamplona.quartz.nip01Core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||||
import com.vitorpamplona.quartz.nip01Core.jackson.EventManualSerializer
|
import com.vitorpamplona.quartz.nip01Core.jackson.EventManualSerializer
|
||||||
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
|
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
|
||||||
@ -57,24 +56,6 @@ open class Event(
|
|||||||
companion object {
|
companion object {
|
||||||
fun fromJson(json: String): Event = EventMapper.fromJson(json)
|
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(
|
fun create(
|
||||||
signer: NostrSigner,
|
signer: NostrSigner,
|
||||||
kind: Int,
|
kind: Int,
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
package com.vitorpamplona.quartz.nip01Core.signers
|
package com.vitorpamplona.quartz.nip01Core.signers
|
||||||
|
|
||||||
import com.vitorpamplona.quartz.EventFactory
|
import com.vitorpamplona.quartz.EventFactory
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.EventHasher
|
||||||
import com.vitorpamplona.quartz.nip01Core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
import com.vitorpamplona.quartz.nip04Dm.Nip04
|
import com.vitorpamplona.quartz.nip04Dm.Nip04
|
||||||
@ -86,11 +87,9 @@ abstract class NostrSigner(
|
|||||||
content: String,
|
content: String,
|
||||||
onReady: (T) -> Unit,
|
onReady: (T) -> Unit,
|
||||||
) {
|
) {
|
||||||
val id = Event.generateId(pubKey, createdAt, kind, tags, content)
|
|
||||||
|
|
||||||
onReady(
|
onReady(
|
||||||
EventFactory.create(
|
EventFactory.create(
|
||||||
id = id,
|
id = EventHasher.hashId(pubKey, createdAt, kind, tags, content),
|
||||||
pubKey = pubKey,
|
pubKey = pubKey,
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
kind = kind,
|
kind = kind,
|
||||||
|
@ -23,6 +23,7 @@ package com.vitorpamplona.quartz.nip01Core.signers
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.vitorpamplona.quartz.CryptoUtils
|
import com.vitorpamplona.quartz.CryptoUtils
|
||||||
import com.vitorpamplona.quartz.EventFactory
|
import com.vitorpamplona.quartz.EventFactory
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.EventHasher
|
||||||
import com.vitorpamplona.quartz.nip01Core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||||
import com.vitorpamplona.quartz.nip01Core.KeyPair
|
import com.vitorpamplona.quartz.nip01Core.KeyPair
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
@ -67,7 +68,7 @@ class NostrSignerSync(
|
|||||||
): T? {
|
): T? {
|
||||||
if (keyPair.privKey == null) return null
|
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()
|
val sig = CryptoUtils.sign(id, keyPair.privKey).toHexKey()
|
||||||
|
|
||||||
return EventFactory.create(
|
return EventFactory.create(
|
||||||
|
@ -23,6 +23,7 @@ package com.vitorpamplona.quartz.nip55AndroidSigner
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.goterl.lazysodium.BuildConfig
|
import com.goterl.lazysodium.BuildConfig
|
||||||
import com.vitorpamplona.quartz.EventFactory
|
import com.vitorpamplona.quartz.EventFactory
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.EventHasher
|
||||||
import com.vitorpamplona.quartz.nip01Core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||||
@ -40,11 +41,9 @@ class NostrSignerExternal(
|
|||||||
content: String,
|
content: String,
|
||||||
onReady: (T) -> Unit,
|
onReady: (T) -> Unit,
|
||||||
) {
|
) {
|
||||||
val id = Event.generateId(pubKey, createdAt, kind, tags, content)
|
|
||||||
|
|
||||||
val event =
|
val event =
|
||||||
Event(
|
Event(
|
||||||
id = id,
|
id = EventHasher.hashId(pubKey, createdAt, kind, tags, content),
|
||||||
pubKey = pubKey,
|
pubKey = pubKey,
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
kind = kind,
|
kind = kind,
|
||||||
|
@ -22,6 +22,7 @@ package com.vitorpamplona.quartz.nip59Giftwrap
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import com.vitorpamplona.quartz.EventFactory
|
import com.vitorpamplona.quartz.EventFactory
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.EventHasher
|
||||||
import com.vitorpamplona.quartz.nip01Core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
|
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
|
||||||
@ -40,7 +41,7 @@ class Gossip(
|
|||||||
val newKind = kind ?: -1
|
val newKind = kind ?: -1
|
||||||
val newTags = (tags ?: emptyArray()).plus(event.tags)
|
val newTags = (tags ?: emptyArray()).plus(event.tags)
|
||||||
val newContent = content ?: ""
|
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 = ""
|
val sig = ""
|
||||||
|
|
||||||
return EventFactory.create(newID, newPubKey, newCreatedAt, newKind, newTags, newContent, sig)
|
return EventFactory.create(newID, newPubKey, newCreatedAt, newKind, newTags, newContent, sig)
|
||||||
|
Reference in New Issue
Block a user