Deprecating #[]s tags
This commit is contained in:
@@ -84,15 +84,15 @@ fun parseDirtyWordForKey(mightBeAKey: String): DirtyKeyInfo? {
|
|||||||
} else if (key.startsWith("nprofile", true)) {
|
} else if (key.startsWith("nprofile", true)) {
|
||||||
val pubkeyRelay = Nip19.uriToRoute(keyB32 + restOfWord) ?: return null
|
val pubkeyRelay = Nip19.uriToRoute(keyB32 + restOfWord) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(pubkeyRelay, restOfWord)
|
return DirtyKeyInfo(pubkeyRelay, pubkeyRelay.additionalChars)
|
||||||
} else if (key.startsWith("nevent", true)) {
|
} else if (key.startsWith("nevent1", true)) {
|
||||||
val noteRelayId = Nip19.uriToRoute(keyB32 + restOfWord) ?: return null
|
val noteRelayId = Nip19.uriToRoute(keyB32 + restOfWord) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(noteRelayId, restOfWord)
|
return DirtyKeyInfo(noteRelayId, noteRelayId.additionalChars)
|
||||||
} else if (key.startsWith("naddr1", true)) {
|
} else if (key.startsWith("naddr1", true)) {
|
||||||
val address = Nip19.uriToRoute(keyB32 + restOfWord) ?: return null
|
val address = Nip19.uriToRoute(keyB32 + restOfWord) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(address, "") // no way to know when they address ends and dirt begins
|
return DirtyKeyInfo(address, address.additionalChars) // no way to know when they address ends and dirt begins
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.vitorpamplona.amethyst.model
|
|||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import com.vitorpamplona.amethyst.service.NostrSingleEventDataSource
|
import com.vitorpamplona.amethyst.service.NostrSingleEventDataSource
|
||||||
import com.vitorpamplona.amethyst.service.model.*
|
import com.vitorpamplona.amethyst.service.model.*
|
||||||
|
import com.vitorpamplona.amethyst.service.nip19.Nip19
|
||||||
import com.vitorpamplona.amethyst.service.relays.EOSETime
|
import com.vitorpamplona.amethyst.service.relays.EOSETime
|
||||||
import com.vitorpamplona.amethyst.service.relays.Relay
|
import com.vitorpamplona.amethyst.service.relays.Relay
|
||||||
import com.vitorpamplona.amethyst.ui.components.BundledUpdate
|
import com.vitorpamplona.amethyst.ui.components.BundledUpdate
|
||||||
@@ -20,6 +21,7 @@ val tagSearch = Pattern.compile("(?:\\s|\\A)\\#\\[([0-9]+)\\]")
|
|||||||
|
|
||||||
class AddressableNote(val address: ATag) : Note(address.toTag()) {
|
class AddressableNote(val address: ATag) : Note(address.toTag()) {
|
||||||
override fun idNote() = address.toNAddr()
|
override fun idNote() = address.toNAddr()
|
||||||
|
override fun toNEvent() = address.toNAddr()
|
||||||
override fun idDisplayNote() = idNote().toShortenHex()
|
override fun idDisplayNote() = idNote().toShortenHex()
|
||||||
override fun address() = address
|
override fun address() = address
|
||||||
override fun createdAt() = (event as? LongTextNoteEvent)?.publishedAt() ?: event?.createdAt()
|
override fun createdAt() = (event as? LongTextNoteEvent)?.publishedAt() ?: event?.createdAt()
|
||||||
@@ -51,6 +53,11 @@ open class Note(val idHex: String) {
|
|||||||
|
|
||||||
fun id() = Hex.decode(idHex)
|
fun id() = Hex.decode(idHex)
|
||||||
open fun idNote() = id().toNote()
|
open fun idNote() = id().toNote()
|
||||||
|
|
||||||
|
open fun toNEvent(): String {
|
||||||
|
return Nip19.createNEvent(idHex, author?.pubkeyHex, event?.kind(), relays.firstOrNull())
|
||||||
|
}
|
||||||
|
|
||||||
open fun idDisplayNote() = idNote().toShortenHex()
|
open fun idDisplayNote() = idNote().toShortenHex()
|
||||||
|
|
||||||
fun channelHex(): HexKey? {
|
fun channelHex(): HexKey? {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class User(val pubkeyHex: String) {
|
|||||||
|
|
||||||
fun pubkey() = Hex.decode(pubkeyHex)
|
fun pubkey() = Hex.decode(pubkeyHex)
|
||||||
fun pubkeyNpub() = pubkey().toNpub()
|
fun pubkeyNpub() = pubkey().toNpub()
|
||||||
|
|
||||||
fun pubkeyDisplayHex() = pubkeyNpub().toShortenHex()
|
fun pubkeyDisplayHex() = pubkeyNpub().toShortenHex()
|
||||||
|
|
||||||
override fun toString(): String = pubkeyHex
|
override fun toString(): String = pubkeyHex
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.vitorpamplona.amethyst.service.model
|
|||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.tagSearch
|
import com.vitorpamplona.amethyst.model.tagSearch
|
||||||
|
import com.vitorpamplona.amethyst.service.nip19.Nip19
|
||||||
|
import com.vitorpamplona.amethyst.service.nip19.Nip19.nip19regex
|
||||||
|
|
||||||
open class BaseTextNoteEvent(
|
open class BaseTextNoteEvent(
|
||||||
id: HexKey,
|
id: HexKey,
|
||||||
@@ -31,6 +33,28 @@ open class BaseTextNoteEvent(
|
|||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val matcher2 = nip19regex.matcher(content)
|
||||||
|
while (matcher2.find()) {
|
||||||
|
val uriScheme = matcher2.group(1) // nostr:
|
||||||
|
val type = matcher2.group(2) // npub1
|
||||||
|
val key = matcher2.group(3) // bech32
|
||||||
|
val additionalChars = matcher2.group(4) // additional chars
|
||||||
|
|
||||||
|
val parsed = Nip19.parseComponents(uriScheme, type, key, additionalChars)
|
||||||
|
|
||||||
|
if (parsed != null) {
|
||||||
|
try {
|
||||||
|
val tag = tags.firstOrNull { it.size > 1 && it[1] == parsed.hex }
|
||||||
|
|
||||||
|
if (tag != null && tag[0] == "p") {
|
||||||
|
returningList.add(tag[1])
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
citedUsersCache = returningList
|
citedUsersCache = returningList
|
||||||
return returningList
|
return returningList
|
||||||
}
|
}
|
||||||
@@ -51,6 +75,35 @@ open class BaseTextNoteEvent(
|
|||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val matcher2 = nip19regex.matcher(content)
|
||||||
|
while (matcher2.find()) {
|
||||||
|
val uriScheme = matcher2.group(1) // nostr:
|
||||||
|
val type = matcher2.group(2) // npub1
|
||||||
|
val key = matcher2.group(3) // bech32
|
||||||
|
val additionalChars = matcher2.group(4) // additional chars
|
||||||
|
|
||||||
|
val parsed = Nip19.parseComponents(uriScheme, type, key, additionalChars)
|
||||||
|
|
||||||
|
if (parsed != null) {
|
||||||
|
if (content.contains("Testing event")) {
|
||||||
|
println("AAAA $key")
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
val tag = tags.firstOrNull { it.size > 1 && it[1] == parsed.hex }
|
||||||
|
|
||||||
|
if (tag != null && tag[0] == "e") {
|
||||||
|
citations.add(tag[1])
|
||||||
|
}
|
||||||
|
if (tag != null && tag[0] == "a") {
|
||||||
|
citations.add(tag[1])
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return citations
|
return citations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package com.vitorpamplona.amethyst.service.nip19
|
package com.vitorpamplona.amethyst.service.nip19
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import com.vitorpamplona.amethyst.model.toByteArray
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
|
import nostr.postr.Bech32
|
||||||
import nostr.postr.bechToBytes
|
import nostr.postr.bechToBytes
|
||||||
|
import nostr.postr.toByteArray
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
object Nip19 {
|
object Nip19 {
|
||||||
@@ -12,7 +15,14 @@ object Nip19 {
|
|||||||
|
|
||||||
val nip19regex = Pattern.compile("(nostr:)?@?(nsec1|npub1|nevent1|naddr1|note1|nprofile1|nrelay1)([qpzry9x8gf2tvdw0s3jn54khce6mua7l]+)(.*)", Pattern.CASE_INSENSITIVE)
|
val nip19regex = Pattern.compile("(nostr:)?@?(nsec1|npub1|nevent1|naddr1|note1|nprofile1|nrelay1)([qpzry9x8gf2tvdw0s3jn54khce6mua7l]+)(.*)", Pattern.CASE_INSENSITIVE)
|
||||||
|
|
||||||
data class Return(val type: Type, val hex: String, val relay: String? = null, val additionalChars: String = "")
|
data class Return(
|
||||||
|
val type: Type,
|
||||||
|
val hex: String,
|
||||||
|
val relay: String? = null,
|
||||||
|
val author: String? = null,
|
||||||
|
val kind: Long? = null,
|
||||||
|
val additionalChars: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
fun uriToRoute(uri: String?): Return? {
|
fun uriToRoute(uri: String?): Return? {
|
||||||
if (uri == null) return null
|
if (uri == null) return null
|
||||||
@@ -26,8 +36,23 @@ object Nip19 {
|
|||||||
val uriScheme = matcher.group(1) // nostr:
|
val uriScheme = matcher.group(1) // nostr:
|
||||||
val type = matcher.group(2) // npub1
|
val type = matcher.group(2) // npub1
|
||||||
val key = matcher.group(3) // bech32
|
val key = matcher.group(3) // bech32
|
||||||
val additionalChars = matcher.group(4) ?: "" // additional chars
|
val additionalChars = matcher.group(4) // additional chars
|
||||||
|
|
||||||
|
return parseComponents(uriScheme, type, key, additionalChars)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Log.e("NIP19 Parser", "Issue trying to Decode NIP19 $uri: ${e.message}", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun parseComponents(
|
||||||
|
uriScheme: String?,
|
||||||
|
type: String,
|
||||||
|
key: String?,
|
||||||
|
additionalChars: String?
|
||||||
|
): Return? {
|
||||||
|
return try {
|
||||||
val bytes = (type + key).bechToBytes()
|
val bytes = (type + key).bechToBytes()
|
||||||
val parsed = when (type.lowercase()) {
|
val parsed = when (type.lowercase()) {
|
||||||
"npub1" -> npub(bytes)
|
"npub1" -> npub(bytes)
|
||||||
@@ -38,12 +63,11 @@ object Nip19 {
|
|||||||
"naddr1" -> naddr(bytes)
|
"naddr1" -> naddr(bytes)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
return parsed?.copy(additionalChars = additionalChars)
|
parsed?.copy(additionalChars = additionalChars ?: "")
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
Log.e("NIP19 Parser", "Issue trying to Decode NIP19 $uri: ${e.message}", e)
|
Log.e("NIP19 Parser", "Issue trying to Decode NIP19 $key: ${e.message}", e)
|
||||||
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun npub(bytes: ByteArray): Return {
|
private fun npub(bytes: ByteArray): Return {
|
||||||
@@ -79,7 +103,15 @@ object Nip19 {
|
|||||||
?.get(0)
|
?.get(0)
|
||||||
?.toString(Charsets.UTF_8)
|
?.toString(Charsets.UTF_8)
|
||||||
|
|
||||||
return Return(Type.EVENT, hex, relay)
|
val author = tlv.get(Tlv.Type.AUTHOR.id)
|
||||||
|
?.get(0)
|
||||||
|
?.toHexKey()
|
||||||
|
|
||||||
|
val kind = tlv.get(Tlv.Type.KIND.id)
|
||||||
|
?.get(0)
|
||||||
|
?.let { Tlv.toInt32(it) }?.toLong()
|
||||||
|
|
||||||
|
return Return(Type.EVENT, hex, relay, author, kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun nrelay(bytes: ByteArray): Return? {
|
private fun nrelay(bytes: ByteArray): Return? {
|
||||||
@@ -108,8 +140,31 @@ object Nip19 {
|
|||||||
|
|
||||||
val kind = tlv.get(Tlv.Type.KIND.id)
|
val kind = tlv.get(Tlv.Type.KIND.id)
|
||||||
?.get(0)
|
?.get(0)
|
||||||
?.let { Tlv.toInt32(it) }
|
?.let { Tlv.toInt32(it) }?.toLong()
|
||||||
|
|
||||||
return Return(Type.ADDRESS, "$kind:$author:$d", relay)
|
return Return(Type.ADDRESS, "$kind:$author:$d", relay, author, kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun createNEvent(idHex: String, author: String?, kind: Int?, relay: String?): String {
|
||||||
|
val kind = kind?.toByteArray()
|
||||||
|
val author = author?.toByteArray()
|
||||||
|
val idHex = idHex.toByteArray()
|
||||||
|
val relay = relay?.toByteArray(Charsets.UTF_8)
|
||||||
|
|
||||||
|
var fullArray = byteArrayOf(Tlv.Type.SPECIAL.id, idHex.size.toByte()) + idHex
|
||||||
|
|
||||||
|
if (relay != null) {
|
||||||
|
fullArray = fullArray + byteArrayOf(Tlv.Type.RELAY.id, relay.size.toByte()) + relay
|
||||||
|
}
|
||||||
|
|
||||||
|
if (author != null) {
|
||||||
|
fullArray = fullArray + byteArrayOf(Tlv.Type.AUTHOR.id, author.size.toByte()) + author
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kind != null) {
|
||||||
|
fullArray = fullArray + byteArrayOf(Tlv.Type.KIND.id, kind.size.toByte()) + kind
|
||||||
|
}
|
||||||
|
|
||||||
|
return Bech32.encodeBytes(hrp = "nevent", fullArray, Bech32.Encoding.Bech32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,19 +56,19 @@ class NewMessageTagger(var channel: Channel?, var mentions: List<User>?, var rep
|
|||||||
if (results?.key?.type == Nip19.Type.USER) {
|
if (results?.key?.type == Nip19.Type.USER) {
|
||||||
val user = LocalCache.getOrCreateUser(results.key.hex)
|
val user = LocalCache.getOrCreateUser(results.key.hex)
|
||||||
|
|
||||||
"#[${tagIndex(user)}]${results.restOfWord}"
|
"nostr:${user.pubkeyNpub()}${results.restOfWord}"
|
||||||
} else if (results?.key?.type == Nip19.Type.NOTE) {
|
} else if (results?.key?.type == Nip19.Type.NOTE) {
|
||||||
val note = LocalCache.getOrCreateNote(results.key.hex)
|
val note = LocalCache.getOrCreateNote(results.key.hex)
|
||||||
|
|
||||||
"#[${tagIndex(note)}]${results.restOfWord}"
|
"nostr:${note.toNEvent()}${results.restOfWord}"
|
||||||
} else if (results?.key?.type == Nip19.Type.EVENT) {
|
} else if (results?.key?.type == Nip19.Type.EVENT) {
|
||||||
val note = LocalCache.getOrCreateNote(results.key.hex)
|
val note = LocalCache.getOrCreateNote(results.key.hex)
|
||||||
|
|
||||||
"#[${tagIndex(note)}]${results.restOfWord}"
|
"nostr:${note.toNEvent()}${results.restOfWord}"
|
||||||
} else if (results?.key?.type == Nip19.Type.ADDRESS) {
|
} else if (results?.key?.type == Nip19.Type.ADDRESS) {
|
||||||
val note = LocalCache.checkGetOrCreateAddressableNote(results.key.hex)
|
val note = LocalCache.checkGetOrCreateAddressableNote(results.key.hex)
|
||||||
if (note != null) {
|
if (note != null) {
|
||||||
"#[${tagIndex(note)}]${results.restOfWord}"
|
"nostr:${note.idNote()}${results.restOfWord}"
|
||||||
} else {
|
} else {
|
||||||
word
|
word
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ open class NewPostViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
quote?.let {
|
quote?.let {
|
||||||
message = TextFieldValue(message.text + "\n\n@${it.idNote()}")
|
message = TextFieldValue(message.text + "\n\n@${it.toNEvent()}")
|
||||||
}
|
}
|
||||||
|
|
||||||
canAddInvoice = account.userProfile().info?.lnAddress() != null
|
canAddInvoice = account.userProfile().info?.lnAddress() != null
|
||||||
@@ -232,7 +232,7 @@ open class NewPostViewModel : ViewModel() {
|
|||||||
if (note == null) {
|
if (note == null) {
|
||||||
message = TextFieldValue(message.text + "\n\n" + imageUrl)
|
message = TextFieldValue(message.text + "\n\n" + imageUrl)
|
||||||
} else {
|
} else {
|
||||||
message = TextFieldValue(message.text + "\n\nnostr:" + note.idNote())
|
message = TextFieldValue(message.text + "\n\nnostr:" + note.toNEvent())
|
||||||
}
|
}
|
||||||
|
|
||||||
urlPreview = findUrlInMessage()
|
urlPreview = findUrlInMessage()
|
||||||
|
|||||||
@@ -1196,10 +1196,10 @@ fun NoteDropDownMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Unit,
|
|||||||
DropdownMenuItem(onClick = { clipboardManager.setText(AnnotatedString(accountViewModel.decrypt(note) ?: "")); onDismiss() }) {
|
DropdownMenuItem(onClick = { clipboardManager.setText(AnnotatedString(accountViewModel.decrypt(note) ?: "")); onDismiss() }) {
|
||||||
Text(stringResource(R.string.copy_text))
|
Text(stringResource(R.string.copy_text))
|
||||||
}
|
}
|
||||||
DropdownMenuItem(onClick = { clipboardManager.setText(AnnotatedString("@${note.author?.pubkeyNpub()}")); onDismiss() }) {
|
DropdownMenuItem(onClick = { clipboardManager.setText(AnnotatedString("nostr:${note.author?.pubkeyNpub()}")); onDismiss() }) {
|
||||||
Text(stringResource(R.string.copy_user_pubkey))
|
Text(stringResource(R.string.copy_user_pubkey))
|
||||||
}
|
}
|
||||||
DropdownMenuItem(onClick = { clipboardManager.setText(AnnotatedString(note.idNote())); onDismiss() }) {
|
DropdownMenuItem(onClick = { clipboardManager.setText(AnnotatedString("nostr:" + note.toNEvent())); onDismiss() }) {
|
||||||
Text(stringResource(R.string.copy_note_id))
|
Text(stringResource(R.string.copy_note_id))
|
||||||
}
|
}
|
||||||
DropdownMenuItem(onClick = {
|
DropdownMenuItem(onClick = {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ val externalLinkForNote = { note: Note ->
|
|||||||
"https://habla.news/a/${note.address().toNAddr()}"
|
"https://habla.news/a/${note.address().toNAddr()}"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
"https://snort.social/e/${note.idNote()}"
|
"https://snort.social/e/${note.toNEvent()}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,13 +152,13 @@ fun NoteQuickActionMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Uni
|
|||||||
}
|
}
|
||||||
VerticalDivider(primaryLight)
|
VerticalDivider(primaryLight)
|
||||||
NoteQuickActionItem(Icons.Default.AlternateEmail, stringResource(R.string.quick_action_copy_user_id)) {
|
NoteQuickActionItem(Icons.Default.AlternateEmail, stringResource(R.string.quick_action_copy_user_id)) {
|
||||||
clipboardManager.setText(AnnotatedString("@${note.author?.pubkeyNpub()}"))
|
clipboardManager.setText(AnnotatedString("nostr:${note.author?.pubkeyNpub()}"))
|
||||||
showToast(R.string.copied_user_id_to_clipboard)
|
showToast(R.string.copied_user_id_to_clipboard)
|
||||||
onDismiss()
|
onDismiss()
|
||||||
}
|
}
|
||||||
VerticalDivider(primaryLight)
|
VerticalDivider(primaryLight)
|
||||||
NoteQuickActionItem(Icons.Default.FormatQuote, stringResource(R.string.quick_action_copy_note_id)) {
|
NoteQuickActionItem(Icons.Default.FormatQuote, stringResource(R.string.quick_action_copy_note_id)) {
|
||||||
clipboardManager.setText(AnnotatedString("@${note.idNote()}"))
|
clipboardManager.setText(AnnotatedString("nostr:${note.toNEvent()}"))
|
||||||
showToast(R.string.copied_note_id_to_clipboard)
|
showToast(R.string.copied_note_id_to_clipboard)
|
||||||
onDismiss()
|
onDismiss()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,12 +54,24 @@ class NIP19ParserTest {
|
|||||||
assertEquals("naddr1qqyrswtyv5mnjv3sqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hsygx3uczxts4hwue9ayfn7ggq62anzstde2qs749pm9tx2csuthhpjvpsgqqqw4rs8pmj38", address.toNAddr())
|
assertEquals("naddr1qqyrswtyv5mnjv3sqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hsygx3uczxts4hwue9ayfn7ggq62anzstde2qs749pm9tx2csuthhpjvpsgqqqw4rs8pmj38", address.toNAddr())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nAddrParserPablo() {
|
||||||
|
val result = Nip19.uriToRoute("naddr1qq2hs7p30p6kcunxxamkgcnyd33xxve3veshyq3qyujphdcz69z6jafxpnldae3xtymdekfeatkt3r4qusr3w5krqspqxpqqqpaxjlg805f")
|
||||||
|
assertEquals(Nip19.Type.ADDRESS, result?.type)
|
||||||
|
assertEquals("31337:27241bb702d145a975260cfedee6265936dcd939eaecb88ea0e4071752c30402:xx1xulrf7wdbdlbc31far", result?.hex)
|
||||||
|
assertEquals(null, result?.relay)
|
||||||
|
assertEquals("27241bb702d145a975260cfedee6265936dcd939eaecb88ea0e4071752c30402", result?.author)
|
||||||
|
assertEquals(31337L, result?.kind)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun nAddrParserGizmo() {
|
fun nAddrParserGizmo() {
|
||||||
val result = Nip19.uriToRoute("naddr1qpqrvvfnvccrzdryxgunzvtxvgukge34xfjnqdpcv9sk2desxgmrscesvserzd3h8ycrywphvg6nsvf58ycnqef3v5mnsvt98pjnqdfs8ypzq3huhccxt6h34eupz3jeynjgjgek8lel2f4adaea0svyk94a3njdqvzqqqr4gudhrkyk")
|
val result = Nip19.uriToRoute("naddr1qpqrvvfnvccrzdryxgunzvtxvgukge34xfjnqdpcv9sk2desxgmrscesvserzd3h8ycrywphvg6nsvf58ycnqef3v5mnsvt98pjnqdfs8ypzq3huhccxt6h34eupz3jeynjgjgek8lel2f4adaea0svyk94a3njdqvzqqqr4gudhrkyk")
|
||||||
assertEquals(Nip19.Type.ADDRESS, result?.type)
|
assertEquals(Nip19.Type.ADDRESS, result?.type)
|
||||||
assertEquals("30023:46fcbe3065eaf1ae7811465924e48923363ff3f526bd6f73d7c184b16bd8ce4d:613f014d2911fb9df52e048aae70268c0d216790287b5814910e1e781e8e0509", result?.hex)
|
assertEquals("30023:46fcbe3065eaf1ae7811465924e48923363ff3f526bd6f73d7c184b16bd8ce4d:613f014d2911fb9df52e048aae70268c0d216790287b5814910e1e781e8e0509", result?.hex)
|
||||||
assertEquals(null, result?.relay)
|
assertEquals(null, result?.relay)
|
||||||
|
assertEquals("46fcbe3065eaf1ae7811465924e48923363ff3f526bd6f73d7c184b16bd8ce4d", result?.author)
|
||||||
|
assertEquals(30023L, result?.kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -68,6 +80,8 @@ class NIP19ParserTest {
|
|||||||
assertEquals(Nip19.Type.ADDRESS, result?.type)
|
assertEquals(Nip19.Type.ADDRESS, result?.type)
|
||||||
assertEquals("30023:46fcbe3065eaf1ae7811465924e48923363ff3f526bd6f73d7c184b16bd8ce4d:1679509418", result?.hex)
|
assertEquals("30023:46fcbe3065eaf1ae7811465924e48923363ff3f526bd6f73d7c184b16bd8ce4d:1679509418", result?.hex)
|
||||||
assertEquals(null, result?.relay)
|
assertEquals(null, result?.relay)
|
||||||
|
assertEquals("46fcbe3065eaf1ae7811465924e48923363ff3f526bd6f73d7c184b16bd8ce4d", result?.author)
|
||||||
|
assertEquals(30023L, result?.kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -76,5 +90,62 @@ class NIP19ParserTest {
|
|||||||
assertEquals(Nip19.Type.EVENT, result?.type)
|
assertEquals(Nip19.Type.EVENT, result?.type)
|
||||||
assertEquals("f5c1c7bcbb8855210a1a8f2684ba1ce4d89ced4d8844792b9d60daca0679addc", result?.hex)
|
assertEquals("f5c1c7bcbb8855210a1a8f2684ba1ce4d89ced4d8844792b9d60daca0679addc", result?.hex)
|
||||||
assertEquals(null, result?.relay)
|
assertEquals(null, result?.relay)
|
||||||
|
assertEquals(null, result?.author)
|
||||||
|
assertEquals(null, result?.kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nEventParser() {
|
||||||
|
val result = Nip19.uriToRoute("nostr:nevent1qqstvrl6wftd8ht4g0vrp6m30tjs6pdxcvk977g769dcvlptkzu4ftqppamhxue69uhkummnw3ezumt0d5pzp78lz8r60568sd2a8dx3wnj6gume02gxaf92vx4fk67qv5kpagt6qvzqqqqqqygqr86c")
|
||||||
|
assertEquals(Nip19.Type.EVENT, result?.type)
|
||||||
|
assertEquals("b60ffa7256d3dd7543d830eb717ae50d05a6c32c5f791ed15b867c2bb0b954ac", result?.hex)
|
||||||
|
assertEquals("wss://nostr.mom", result?.relay)
|
||||||
|
assertEquals("f8ff11c7a7d3478355d3b4d174e5a473797a906ea4aa61aa9b6bc0652c1ea17a", result?.author)
|
||||||
|
assertEquals(1L, result?.kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nEventParser2() {
|
||||||
|
val result = Nip19.uriToRoute("nostr:nevent1qqsplpuwsgrrmq85rfup6w3w777rxmcmadu590emfx6z4msj2844euqpz3mhxue69uhhyetvv9ujuerpd46hxtnfdupzq3svyhng9ld8sv44950j957j9vchdktj7cxumsep9mvvjthc2pjuqvzqqqqqqye3a70w")
|
||||||
|
|
||||||
|
assertEquals(Nip19.Type.EVENT, result?.type)
|
||||||
|
assertEquals("1f878e82063d80f41a781d3a2ef7bc336f1beb7942bf3b49b42aee1251eb5cf0", result?.hex)
|
||||||
|
assertEquals("wss://relay.damus.io", result?.relay)
|
||||||
|
assertEquals("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c", result?.author)
|
||||||
|
assertEquals(1L, result?.kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nEventParserInvalidChecksum() {
|
||||||
|
val result = Nip19.uriToRoute("nostr:nevent1qqsyxq8v0730nz38dupnjzp5jegkyz4gu2ptwcps4v32hjnrap0q0espz3mhxue69uhhyetvv9ujuerpd46hxtnfdupzq3svyhng9ld8sv44950j957j9vchdktj7cxumsep9mvvjthc2pjuqvzqqqqqqyn3t9gj")
|
||||||
|
|
||||||
|
assertEquals(Nip19.Type.EVENT, result?.type)
|
||||||
|
assertEquals("4300ec7fa2f98a276f033908349651620aa8e282b76030ab22abca63e85e07e6", result?.hex)
|
||||||
|
assertEquals("wss://relay.damus.io", result?.relay)
|
||||||
|
assertEquals("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c", result?.author)
|
||||||
|
assertEquals(1L, result?.kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nEventFormatter() {
|
||||||
|
val nevent = Nip19.createNEvent("f5c1c7bcbb8855210a1a8f2684ba1ce4d89ced4d8844792b9d60daca0679addc", null, null, null)
|
||||||
|
assertEquals("nevent1qqs0tsw8hjacs4fppgdg7f5yhgwwfkyua4xcs3re9wwkpkk2qeu6mhql22rcy", nevent)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nEventFormatterWithExtraInfo() {
|
||||||
|
val nevent = Nip19.createNEvent("f5c1c7bcbb8855210a1a8f2684ba1ce4d89ced4d8844792b9d60daca0679addc", "7fa56f5d6962ab1e3cd424e758c3002b8665f7b0d8dcee9fe9e288d7751ac194", 40, null)
|
||||||
|
assertEquals("nevent1qqs0tsw8hjacs4fppgdg7f5yhgwwfkyua4xcs3re9wwkpkk2qeu6mhqzypl62m6ad932k83u6sjwwkxrqq4cve0hkrvdem5la83g34m4rtqegqcyqqqqq2qh26va4", nevent)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nEventFormatterWithFullInfo() {
|
||||||
|
val nevent = Nip19.createNEvent(
|
||||||
|
"1f878e82063d80f41a781d3a2ef7bc336f1beb7942bf3b49b42aee1251eb5cf0",
|
||||||
|
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
|
||||||
|
1,
|
||||||
|
"wss://relay.damus.io"
|
||||||
|
)
|
||||||
|
assertEquals("nevent1qqsplpuwsgrrmq85rfup6w3w777rxmcmadu590emfx6z4msj2844euqpz3mhxue69uhhyetvv9ujuerpd46hxtnfdupzq3svyhng9ld8sv44950j957j9vchdktj7cxumsep9mvvjthc2pjuqvzqqqqqqye3a70w", nevent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user