Merge remote-tracking branch 'origin/HEAD' into full-outbox

# Conflicts:
#	ammolite/src/main/java/com/vitorpamplona/ammolite/relays/NostrClient.kt
#	gradle/libs.versions.toml
This commit is contained in:
Vitor Pamplona
2025-07-02 08:23:54 -04:00
66 changed files with 628 additions and 176 deletions
@@ -20,19 +20,28 @@
*/
package com.vitorpamplona.quartz.nip01Core.signers
import com.fasterxml.jackson.annotation.JsonProperty
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.TagArray
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.core.builder
import com.vitorpamplona.quartz.nip01Core.core.tagArray
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
import com.vitorpamplona.quartz.utils.TimeUtils
class EventTemplate<T : Event>(
@JsonProperty("created_at")
val createdAt: Long,
val kind: Int,
val tags: TagArray,
val content: String,
)
) {
fun toJson(): String = EventMapper.mapper.writeValueAsString(this)
companion object {
fun fromJson(json: String): EventTemplate<Event> = EventTemplateManualDeserializer.fromJson(EventMapper.mapper.readTree(json))
}
}
inline fun <T : Event> eventTemplate(
kind: Int,
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.quartz.nip01Core.signers
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
import com.vitorpamplona.quartz.nip01Core.core.Event
class EventTemplateDeserializer : StdDeserializer<EventTemplate<Event>>(EventTemplate::class.java) {
override fun deserialize(
jp: JsonParser,
ctxt: DeserializationContext,
): EventTemplate<Event> = EventTemplateManualDeserializer.fromJson(jp.codec.readTree(jp))
}
@@ -0,0 +1,40 @@
/**
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.quartz.nip01Core.signers
import com.fasterxml.jackson.databind.JsonNode
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.jackson.toTypedArray
class EventTemplateManualDeserializer {
companion object {
fun fromJson(jsonObject: JsonNode): EventTemplate<Event> =
EventTemplate(
createdAt = jsonObject.get("created_at").asLong(),
kind = jsonObject.get("kind").asInt(),
tags =
jsonObject.get("tags").toTypedArray {
it.toTypedArray { s -> if (s.isNull) "" else s.asText().intern() }
},
content = jsonObject.get("content").asText(),
)
}
}
@@ -21,11 +21,12 @@
package com.vitorpamplona.quartz.nip46RemoteSigner
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
import java.util.UUID
class BunkerRequestSign(
id: String = UUID.randomUUID().toString(),
val event: Event,
val event: EventTemplate<Event>,
) : BunkerRequest(id, METHOD_NAME, arrayOf(event.toJson())) {
companion object {
val METHOD_NAME = "sign_event"
@@ -33,6 +34,6 @@ class BunkerRequestSign(
fun parse(
id: String,
params: Array<String>,
): BunkerRequestSign = BunkerRequestSign(id, Event.fromJson(params[0]))
): BunkerRequestSign = BunkerRequestSign(id, EventTemplate.fromJson(params[0]))
}
}