Renames Gossip to Rumor to match names on the NIP-59
This commit is contained in:
@@ -93,7 +93,7 @@ import com.vitorpamplona.quartz.nip58Badges.BadgeAwardEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.BadgeDefinitionEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.BadgeProfilesEvent
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.GiftWrapEvent
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.SealedGossipEvent
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.SealedRumorEvent
|
||||
import com.vitorpamplona.quartz.nip65RelayList.AdvertisedRelayListEvent
|
||||
import com.vitorpamplona.quartz.nip68Picture.PictureEvent
|
||||
import com.vitorpamplona.quartz.nip71Video.VideoHorizontalEvent
|
||||
@@ -242,7 +242,7 @@ class EventFactory {
|
||||
RelaySetEvent.KIND -> RelaySetEvent(id, pubKey, createdAt, tags, content, sig)
|
||||
ReportEvent.KIND -> ReportEvent(id, pubKey, createdAt, tags, content, sig)
|
||||
RepostEvent.KIND -> RepostEvent(id, pubKey, createdAt, tags, content, sig)
|
||||
SealedGossipEvent.KIND -> SealedGossipEvent(id, pubKey, createdAt, tags, content, sig)
|
||||
SealedRumorEvent.KIND -> SealedRumorEvent(id, pubKey, createdAt, tags, content, sig)
|
||||
SearchRelayListEvent.KIND -> SearchRelayListEvent(id, pubKey, createdAt, tags, content, sig)
|
||||
StatusEvent.KIND -> StatusEvent(id, pubKey, createdAt, tags, content, sig)
|
||||
TextNoteEvent.KIND -> TextNoteEvent(id, pubKey, createdAt, tags, content, sig)
|
||||
|
||||
@@ -35,9 +35,9 @@ import com.vitorpamplona.quartz.nip47WalletConnect.Request
|
||||
import com.vitorpamplona.quartz.nip47WalletConnect.RequestDeserializer
|
||||
import com.vitorpamplona.quartz.nip47WalletConnect.Response
|
||||
import com.vitorpamplona.quartz.nip47WalletConnect.ResponseDeserializer
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.Gossip
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.GossipDeserializer
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.GossipSerializer
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.Rumor
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.RumorDeserializer
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.RumorSerializer
|
||||
|
||||
class EventMapper {
|
||||
companion object {
|
||||
@@ -49,8 +49,8 @@ class EventMapper {
|
||||
SimpleModule()
|
||||
.addSerializer(Event::class.java, EventSerializer())
|
||||
.addDeserializer(Event::class.java, EventDeserializer())
|
||||
.addSerializer(Gossip::class.java, GossipSerializer())
|
||||
.addDeserializer(Gossip::class.java, GossipDeserializer())
|
||||
.addSerializer(Rumor::class.java, RumorSerializer())
|
||||
.addDeserializer(Rumor::class.java, RumorDeserializer())
|
||||
.addDeserializer(Response::class.java, ResponseDeserializer())
|
||||
.addDeserializer(Request::class.java, RequestDeserializer())
|
||||
.addDeserializer(BunkerMessage::class.java, BunkerMessage.BunkerMessageDeserializer())
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.vitorpamplona.quartz.nip25Reactions.ReactionEvent
|
||||
import com.vitorpamplona.quartz.nip30CustomEmoji.EmojiUrl
|
||||
import com.vitorpamplona.quartz.nip57Zaps.splits.ZapSplitSetup
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.GiftWrapEvent
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.SealedGossipEvent
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.SealedRumorEvent
|
||||
import com.vitorpamplona.quartz.nip92IMeta.IMetaTag
|
||||
import com.vitorpamplona.quartz.nip94FileMetadata.Dimension
|
||||
|
||||
@@ -51,7 +51,7 @@ class NIP17Factory {
|
||||
|
||||
val next = remainingTos.first()
|
||||
|
||||
SealedGossipEvent.create(
|
||||
SealedRumorEvent.create(
|
||||
event = event,
|
||||
encryptTo = next,
|
||||
signer = signer,
|
||||
|
||||
+5
-5
@@ -27,7 +27,7 @@ import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
|
||||
|
||||
class Gossip(
|
||||
class Rumor(
|
||||
val id: HexKey?,
|
||||
@JsonProperty("pubkey") val pubKey: HexKey?,
|
||||
@JsonProperty("created_at") val createdAt: Long?,
|
||||
@@ -35,7 +35,7 @@ class Gossip(
|
||||
val tags: Array<Array<String>>?,
|
||||
val content: String?,
|
||||
) {
|
||||
fun mergeWith(event: SealedGossipEvent): Event {
|
||||
fun mergeWith(event: SealedRumorEvent): Event {
|
||||
val newPubKey = event.pubKey // forces to be the pubkey of the seal to make sure impersonators don't impersonate
|
||||
val newCreatedAt = if (createdAt != null && createdAt > 1000) createdAt else event.createdAt
|
||||
val newKind = kind ?: -1
|
||||
@@ -48,10 +48,10 @@ class Gossip(
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun fromJson(json: String): Gossip = EventMapper.mapper.readValue(json, Gossip::class.java)
|
||||
fun fromJson(json: String): Rumor = EventMapper.mapper.readValue(json, Rumor::class.java)
|
||||
|
||||
fun toJson(event: Gossip): String = EventMapper.mapper.writeValueAsString(event)
|
||||
fun toJson(event: Rumor): String = EventMapper.mapper.writeValueAsString(event)
|
||||
|
||||
fun create(event: Event): Gossip = Gossip(event.id, event.pubKey, event.createdAt, event.kind, event.tags, event.content)
|
||||
fun create(event: Event): Rumor = Rumor(event.id, event.pubKey, event.createdAt, event.kind, event.tags, event.content)
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -26,13 +26,13 @@ import com.fasterxml.jackson.databind.JsonNode
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
|
||||
import com.vitorpamplona.quartz.nip01Core.jackson.toTypedArray
|
||||
|
||||
class GossipDeserializer : StdDeserializer<Gossip>(Gossip::class.java) {
|
||||
class RumorDeserializer : StdDeserializer<Rumor>(Rumor::class.java) {
|
||||
override fun deserialize(
|
||||
jp: JsonParser,
|
||||
ctxt: DeserializationContext,
|
||||
): Gossip {
|
||||
): Rumor {
|
||||
val jsonObject: JsonNode = jp.codec.readTree(jp)
|
||||
return Gossip(
|
||||
return Rumor(
|
||||
id = jsonObject.get("id")?.asText()?.intern(),
|
||||
pubKey = jsonObject.get("pubkey")?.asText()?.intern(),
|
||||
createdAt = jsonObject.get("created_at")?.asLong(),
|
||||
+2
-2
@@ -24,9 +24,9 @@ import com.fasterxml.jackson.core.JsonGenerator
|
||||
import com.fasterxml.jackson.databind.SerializerProvider
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer
|
||||
|
||||
class GossipSerializer : StdSerializer<Gossip>(Gossip::class.java) {
|
||||
class RumorSerializer : StdSerializer<Rumor>(Rumor::class.java) {
|
||||
override fun serialize(
|
||||
event: Gossip,
|
||||
event: Rumor,
|
||||
gen: JsonGenerator,
|
||||
provider: SerializerProvider,
|
||||
) {
|
||||
+14
-14
@@ -30,7 +30,7 @@ import com.vitorpamplona.quartz.utils.bytesUsedInMemory
|
||||
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
|
||||
|
||||
@Immutable
|
||||
class SealedGossipEvent(
|
||||
class SealedRumorEvent(
|
||||
id: HexKey,
|
||||
pubKey: HexKey,
|
||||
createdAt: Long,
|
||||
@@ -44,9 +44,9 @@ class SealedGossipEvent(
|
||||
super.countMemory() +
|
||||
pointerSizeInBytes + (innerEventId?.bytesUsedInMemory() ?: 0)
|
||||
|
||||
fun copyNoContent(): SealedGossipEvent {
|
||||
fun copyNoContent(): SealedRumorEvent {
|
||||
val copy =
|
||||
SealedGossipEvent(
|
||||
SealedRumorEvent(
|
||||
id,
|
||||
pubKey,
|
||||
createdAt,
|
||||
@@ -67,7 +67,7 @@ class SealedGossipEvent(
|
||||
message = "Heavy caching was removed from this class due to high memory use. Cache it separatedly",
|
||||
replaceWith = ReplaceWith("unseal"),
|
||||
)
|
||||
fun cachedGossip(
|
||||
fun cachedRumor(
|
||||
signer: NostrSigner,
|
||||
onReady: (Event) -> Unit,
|
||||
) = unseal(signer, onReady)
|
||||
@@ -79,8 +79,8 @@ class SealedGossipEvent(
|
||||
try {
|
||||
plainContent(signer) {
|
||||
try {
|
||||
val gossip = Gossip.fromJson(it)
|
||||
val event = gossip.mergeWith(this)
|
||||
val rumor = Rumor.fromJson(it)
|
||||
val event = rumor.mergeWith(this)
|
||||
if (event is WrappedEvent) {
|
||||
event.host = host ?: HostStub(this.id, this.pubKey, this.kind)
|
||||
}
|
||||
@@ -88,11 +88,11 @@ class SealedGossipEvent(
|
||||
|
||||
onReady(event)
|
||||
} catch (e: Exception) {
|
||||
Log.w("GossipEvent", "Fail to decrypt or parse Gossip", e)
|
||||
Log.w("RumorEvent", "Fail to decrypt or parse Rumor", e)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w("GossipEvent", "Fail to decrypt or parse Gossip", e)
|
||||
Log.w("RumorEvent", "Fail to decrypt or parse Rumor", e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,20 +113,20 @@ class SealedGossipEvent(
|
||||
encryptTo: HexKey,
|
||||
signer: NostrSigner,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
onReady: (SealedGossipEvent) -> Unit,
|
||||
onReady: (SealedRumorEvent) -> Unit,
|
||||
) {
|
||||
val gossip = Gossip.create(event)
|
||||
create(gossip, encryptTo, signer, createdAt, onReady)
|
||||
val rumor = Rumor.create(event)
|
||||
create(rumor, encryptTo, signer, createdAt, onReady)
|
||||
}
|
||||
|
||||
fun create(
|
||||
gossip: Gossip,
|
||||
rumor: Rumor,
|
||||
encryptTo: HexKey,
|
||||
signer: NostrSigner,
|
||||
createdAt: Long = TimeUtils.randomWithTwoDays(),
|
||||
onReady: (SealedGossipEvent) -> Unit,
|
||||
onReady: (SealedRumorEvent) -> Unit,
|
||||
) {
|
||||
val msg = Gossip.toJson(gossip)
|
||||
val msg = Rumor.toJson(rumor)
|
||||
|
||||
signer.nip44Encrypt(msg, encryptTo) { content ->
|
||||
signer.sign(createdAt, KIND, emptyArray(), content, onReady)
|
||||
Reference in New Issue
Block a user