mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-10 19:53:50 +02:00
Remove non-used imports in Nip19
This commit is contained in:
@@ -1,13 +1,9 @@
|
|||||||
package com.vitorpamplona.amethyst.service
|
package com.vitorpamplona.amethyst.service
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.toByteArray
|
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.model.ATag
|
import nostr.postr.bechToBytes
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
import java.nio.ByteOrder
|
import java.nio.ByteOrder
|
||||||
import nostr.postr.Bech32
|
|
||||||
import nostr.postr.bechToBytes
|
|
||||||
import nostr.postr.toByteArray
|
|
||||||
|
|
||||||
class Nip19 {
|
class Nip19 {
|
||||||
|
|
||||||
@@ -37,7 +33,6 @@ class Nip19 {
|
|||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
println("Issue trying to Decode NIP19 ${uri}: ${e.message}")
|
println("Issue trying to Decode NIP19 ${uri}: ${e.message}")
|
||||||
//e.printStackTrace()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
@@ -52,8 +47,10 @@ class Nip19 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun nprofile(bytes: ByteArray): Return? {
|
private fun nprofile(bytes: ByteArray): Return? {
|
||||||
val tlv = parseTLV(bytes)
|
val hex = parseTLV(bytes)
|
||||||
val hex = tlv.get(NIP19TLVTypes.SPECIAL.id)?.get(0)?.toHexKey() ?: return null
|
.get(NIP19TLVTypes.SPECIAL.id)
|
||||||
|
?.get(0)
|
||||||
|
?.toHexKey() ?: return null
|
||||||
|
|
||||||
return Return(Type.USER, hex)
|
return Return(Type.USER, hex)
|
||||||
}
|
}
|
||||||
@@ -78,16 +75,29 @@ class Nip19 {
|
|||||||
|
|
||||||
private fun naddr(bytes: ByteArray): Return? {
|
private fun naddr(bytes: ByteArray): Return? {
|
||||||
val tlv = parseTLV(bytes)
|
val tlv = parseTLV(bytes)
|
||||||
val d = tlv.get(NIP19TLVTypes.SPECIAL.id)?.get(0)?.toString(Charsets.UTF_8) ?: return null
|
|
||||||
val relay = tlv.get(NIP19TLVTypes.RELAY.id)?.get(0)?.toString(Charsets.UTF_8)
|
val d = tlv.get(NIP19TLVTypes.SPECIAL.id)
|
||||||
val author = tlv.get(NIP19TLVTypes.AUTHOR.id)?.get(0)?.toHexKey()
|
?.get(0)
|
||||||
val kind = tlv.get(NIP19TLVTypes.KIND.id)?.get(0)?.let { toInt32(it) }
|
?.toString(Charsets.UTF_8) ?: return null
|
||||||
|
|
||||||
|
val relay = tlv.get(NIP19TLVTypes.RELAY.id)
|
||||||
|
?.get(0)
|
||||||
|
?.toString(Charsets.UTF_8)
|
||||||
|
|
||||||
|
val author = tlv.get(NIP19TLVTypes.AUTHOR.id)
|
||||||
|
?.get(0)
|
||||||
|
?.toHexKey()
|
||||||
|
|
||||||
|
val kind = tlv.get(NIP19TLVTypes.KIND.id)
|
||||||
|
?.get(0)
|
||||||
|
?.let { toInt32(it) }
|
||||||
|
|
||||||
return Return(Type.ADDRESS, "$kind:$author:$d")
|
return Return(Type.ADDRESS, "$kind:$author:$d")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class NIP19TLVTypes(val id: Byte) { //classes should start with an uppercase letter in kotlin
|
// Classes should start with an uppercase letter in kotlin
|
||||||
|
enum class NIP19TLVTypes(val id: Byte) {
|
||||||
SPECIAL(0),
|
SPECIAL(0),
|
||||||
RELAY(1),
|
RELAY(1),
|
||||||
AUTHOR(2),
|
AUTHOR(2),
|
||||||
|
@@ -25,10 +25,10 @@ class Nip19Test {
|
|||||||
Assert.assertEquals(16909060, actual)
|
Assert.assertEquals(16909060, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("Not implemented yet")
|
@Ignore("Test not implemented yet")
|
||||||
@Test()
|
@Test()
|
||||||
fun parse_TLV() {
|
fun parse_TLV() {
|
||||||
// TODO
|
// TODO: I don't know how to test this (?)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test()
|
@Test()
|
||||||
@@ -69,7 +69,7 @@ class Nip19Test {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("Not implemented yet")
|
@Ignore("Test not implemented yet")
|
||||||
@Test()
|
@Test()
|
||||||
fun uri_to_route_nprofile() {
|
fun uri_to_route_nprofile() {
|
||||||
val actual = nip19.uriToRoute("nostr:nprofile")
|
val actual = nip19.uriToRoute("nostr:nprofile")
|
||||||
@@ -78,7 +78,7 @@ class Nip19Test {
|
|||||||
Assert.assertEquals("*", actual?.hex)
|
Assert.assertEquals("*", actual?.hex)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("Not implemented yet")
|
@Ignore("Test not implemented yet")
|
||||||
@Test()
|
@Test()
|
||||||
fun uri_to_route_nevent() {
|
fun uri_to_route_nevent() {
|
||||||
val actual = nip19.uriToRoute("nostr:nevent")
|
val actual = nip19.uriToRoute("nostr:nevent")
|
||||||
@@ -87,7 +87,7 @@ class Nip19Test {
|
|||||||
Assert.assertEquals("*", actual?.hex)
|
Assert.assertEquals("*", actual?.hex)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("Not implemented yet")
|
@Ignore("Test not implemented yet")
|
||||||
@Test()
|
@Test()
|
||||||
fun uri_to_route_nrelay() {
|
fun uri_to_route_nrelay() {
|
||||||
val actual = nip19.uriToRoute("nostr:nrelay")
|
val actual = nip19.uriToRoute("nostr:nrelay")
|
||||||
@@ -96,7 +96,7 @@ class Nip19Test {
|
|||||||
Assert.assertEquals("*", actual?.hex)
|
Assert.assertEquals("*", actual?.hex)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("Not implemented yet")
|
@Ignore("Test not implemented yet")
|
||||||
@Test()
|
@Test()
|
||||||
fun uri_to_route_naddr() {
|
fun uri_to_route_naddr() {
|
||||||
val actual = nip19.uriToRoute("nostr:naddr")
|
val actual = nip19.uriToRoute("nostr:naddr")
|
||||||
|
Reference in New Issue
Block a user