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
@@ -0,0 +1,65 @@
/**
* 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.jackson
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip01Core.verify
import org.junit.Test
class EventDeserializerTest {
@Test
fun testEventTemplateToJson() {
val templateJson = """{"created_at":1234,"kind":1,"tags":[],"content":"This is an unsigned event."}"""
val template = EventTemplate.fromJson(templateJson)
val json = template.toJson()
assert(json == templateJson)
}
@Test
fun testEventTemplate() {
val templateJson = """{"kind":"1","content":"This is an unsigned event.","created_at":1234,"tags":[]}"""
val template = EventTemplate.fromJson(templateJson)
assert(template.kind == 1)
assert(template.content == "This is an unsigned event.")
assert(template.tags.isEmpty())
}
@Test
fun testSignedEvent() {
val keyPair = KeyPair()
val signer = NostrSignerInternal(keyPair)
val templateJson = """{"kind":"1","content":"This is an unsigned event.","created_at":1234,"tags":[]}"""
val template = EventTemplate.fromJson(templateJson)
val signedEvent = signer.signerSync.sign(template)!!
assert(signedEvent.id.isNotEmpty())
assert(signedEvent.sig.isNotEmpty())
assert(signedEvent.pubKey.isNotEmpty())
assert(signedEvent.verify())
}
}
@@ -0,0 +1,35 @@
/**
* 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.nip46RemoteSigner
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
import org.junit.Test
class BunkerRequestTest {
@Test
fun testBunkerRequestDeSerialization() {
val requestJson = """{"id":"123","method":"sign_event","params":["{\"created_at\":1234,\"kind\":1,\"tags\":[],\"content\":\"This is an unsigned event.\"}"]}"""
val bunkerRequest = EventMapper.mapper.readValue(requestJson, BunkerRequest::class.java)
assert(bunkerRequest is BunkerRequestSign)
assert((bunkerRequest as BunkerRequestSign).event.kind == 1)
}
}