Moves Relay information to Quartz
Renames Nip19 object for better readability
This commit is contained in:
@@ -28,7 +28,7 @@ import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
|||||||
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
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.events.Event
|
import com.vitorpamplona.quartz.events.Event
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ class AntiSpamFilter {
|
|||||||
// really long, make it ok.
|
// really long, make it ok.
|
||||||
// The idea here is to avoid considering repeated "@Bot, command" messages spam, while still
|
// The idea here is to avoid considering repeated "@Bot, command" messages spam, while still
|
||||||
// blocking repeated "lnbc..." invoices or fishing urls
|
// blocking repeated "lnbc..." invoices or fishing urls
|
||||||
if (event.content.length < 180 && Nip19.nip19regex.matcher(event.content).find()) return false
|
if (event.content.length < 180 && Nip19Bech32.nip19regex.matcher(event.content).find()) return false
|
||||||
|
|
||||||
// double list strategy:
|
// double list strategy:
|
||||||
// if duplicated, it goes into spam. 1000 spam messages are saved into the spam list.
|
// if duplicated, it goes into spam. 1000 spam messages are saved into the spam list.
|
||||||
@@ -71,7 +71,7 @@ class AntiSpamFilter {
|
|||||||
) {
|
) {
|
||||||
Log.w(
|
Log.w(
|
||||||
"Potential SPAM Message for sharing",
|
"Potential SPAM Message for sharing",
|
||||||
"${Nip19.createNEvent(event.id, event.pubKey, event.kind, null)}",
|
"${Nip19Bech32.createNEvent(event.id, event.pubKey, event.kind, null)}",
|
||||||
)
|
)
|
||||||
Log.w(
|
Log.w(
|
||||||
"Potential SPAM Message",
|
"Potential SPAM Message",
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import com.vitorpamplona.quartz.encoders.ATag
|
|||||||
import com.vitorpamplona.quartz.encoders.Hex
|
import com.vitorpamplona.quartz.encoders.Hex
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
import com.vitorpamplona.quartz.encoders.HexValidator
|
import com.vitorpamplona.quartz.encoders.HexValidator
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.encoders.decodePublicKeyAsHexOrNull
|
import com.vitorpamplona.quartz.encoders.decodePublicKeyAsHexOrNull
|
||||||
import com.vitorpamplona.quartz.encoders.toHexKey
|
import com.vitorpamplona.quartz.encoders.toHexKey
|
||||||
import com.vitorpamplona.quartz.events.AddressableEvent
|
import com.vitorpamplona.quartz.events.AddressableEvent
|
||||||
@@ -1412,7 +1412,7 @@ object LocalCache {
|
|||||||
|
|
||||||
val key =
|
val key =
|
||||||
try {
|
try {
|
||||||
Nip19.uriToRoute(text)?.hex ?: Hex.decode(text).toHexKey()
|
Nip19Bech32.uriToRoute(text)?.hex ?: Hex.decode(text).toHexKey()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (e is CancellationException) throw e
|
if (e is CancellationException) throw e
|
||||||
null
|
null
|
||||||
@@ -1462,7 +1462,7 @@ object LocalCache {
|
|||||||
|
|
||||||
val key =
|
val key =
|
||||||
try {
|
try {
|
||||||
Nip19.uriToRoute(text)?.hex ?: Hex.decode(text).toHexKey()
|
Nip19Bech32.uriToRoute(text)?.hex ?: Hex.decode(text).toHexKey()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (e is CancellationException) throw e
|
if (e is CancellationException) throw e
|
||||||
null
|
null
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import com.vitorpamplona.quartz.encoders.ATag
|
|||||||
import com.vitorpamplona.quartz.encoders.Hex
|
import com.vitorpamplona.quartz.encoders.Hex
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
import com.vitorpamplona.quartz.encoders.LnInvoiceUtil
|
import com.vitorpamplona.quartz.encoders.LnInvoiceUtil
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.encoders.toNote
|
import com.vitorpamplona.quartz.encoders.toNote
|
||||||
import com.vitorpamplona.quartz.events.AddressableEvent
|
import com.vitorpamplona.quartz.events.AddressableEvent
|
||||||
import com.vitorpamplona.quartz.events.BaseTextNoteEvent
|
import com.vitorpamplona.quartz.events.BaseTextNoteEvent
|
||||||
@@ -138,17 +138,17 @@ open class Note(val idHex: String) {
|
|||||||
return if (myEvent is WrappedEvent) {
|
return if (myEvent is WrappedEvent) {
|
||||||
val host = myEvent.host
|
val host = myEvent.host
|
||||||
if (host != null) {
|
if (host != null) {
|
||||||
Nip19.createNEvent(
|
Nip19Bech32.createNEvent(
|
||||||
host.id,
|
host.id,
|
||||||
host.pubKey,
|
host.pubKey,
|
||||||
host.kind(),
|
host.kind(),
|
||||||
relays.firstOrNull()?.url,
|
relays.firstOrNull()?.url,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Nip19.createNEvent(idHex, author?.pubkeyHex, event?.kind(), relays.firstOrNull()?.url)
|
Nip19Bech32.createNEvent(idHex, author?.pubkeyHex, event?.kind(), relays.firstOrNull()?.url)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Nip19.createNEvent(idHex, author?.pubkeyHex, event?.kind(), relays.firstOrNull()?.url)
|
Nip19Bech32.createNEvent(idHex, author?.pubkeyHex, event?.kind(), relays.firstOrNull()?.url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ package com.vitorpamplona.amethyst.service
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.util.LruCache
|
import android.util.LruCache
|
||||||
import com.vitorpamplona.amethyst.model.RelayInformation
|
import com.vitorpamplona.quartz.encoders.Nip11RelayInformation
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import okhttp3.Call
|
import okhttp3.Call
|
||||||
import okhttp3.Callback
|
import okhttp3.Callback
|
||||||
@@ -31,12 +31,12 @@ import okhttp3.Response
|
|||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
object Nip11CachedRetriever {
|
object Nip11CachedRetriever {
|
||||||
val relayInformationDocumentCache = LruCache<String, RelayInformation>(100)
|
val relayInformationDocumentCache = LruCache<String, Nip11RelayInformation>(100)
|
||||||
val retriever = Nip11Retriever()
|
val retriever = Nip11Retriever()
|
||||||
|
|
||||||
suspend fun loadRelayInfo(
|
suspend fun loadRelayInfo(
|
||||||
dirtyUrl: String,
|
dirtyUrl: String,
|
||||||
onInfo: (RelayInformation) -> Unit,
|
onInfo: (Nip11RelayInformation) -> Unit,
|
||||||
onError: (String, Nip11Retriever.ErrorCode, String?) -> Unit,
|
onError: (String, Nip11Retriever.ErrorCode, String?) -> Unit,
|
||||||
) {
|
) {
|
||||||
val url = retriever.cleanUrl(dirtyUrl)
|
val url = retriever.cleanUrl(dirtyUrl)
|
||||||
@@ -78,7 +78,7 @@ class Nip11Retriever {
|
|||||||
suspend fun loadRelayInfo(
|
suspend fun loadRelayInfo(
|
||||||
url: String,
|
url: String,
|
||||||
dirtyUrl: String,
|
dirtyUrl: String,
|
||||||
onInfo: (RelayInformation) -> Unit,
|
onInfo: (Nip11RelayInformation) -> Unit,
|
||||||
onError: (String, ErrorCode, String?) -> Unit,
|
onError: (String, ErrorCode, String?) -> Unit,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
@@ -98,7 +98,7 @@ class Nip11Retriever {
|
|||||||
val body = it.body.string()
|
val body = it.body.string()
|
||||||
try {
|
try {
|
||||||
if (it.isSuccessful) {
|
if (it.isSuccessful) {
|
||||||
onInfo(RelayInformation.fromJson(body))
|
onInfo(Nip11RelayInformation.fromJson(body))
|
||||||
} else {
|
} else {
|
||||||
onError(dirtyUrl, ErrorCode.FAIL_WITH_HTTP_STATUS, it.code.toString())
|
onError(dirtyUrl, ErrorCode.FAIL_WITH_HTTP_STATUS, it.code.toString())
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -26,7 +26,7 @@ import com.vitorpamplona.amethyst.service.relays.JsonFilter
|
|||||||
import com.vitorpamplona.amethyst.service.relays.TypedFilter
|
import com.vitorpamplona.amethyst.service.relays.TypedFilter
|
||||||
import com.vitorpamplona.quartz.encoders.Hex
|
import com.vitorpamplona.quartz.encoders.Hex
|
||||||
import com.vitorpamplona.quartz.encoders.HexValidator
|
import com.vitorpamplona.quartz.encoders.HexValidator
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.encoders.toHexKey
|
import com.vitorpamplona.quartz.encoders.toHexKey
|
||||||
import com.vitorpamplona.quartz.events.AudioHeaderEvent
|
import com.vitorpamplona.quartz.events.AudioHeaderEvent
|
||||||
import com.vitorpamplona.quartz.events.AudioTrackEvent
|
import com.vitorpamplona.quartz.events.AudioTrackEvent
|
||||||
@@ -66,7 +66,7 @@ object NostrSearchEventOrUserDataSource : NostrDataSource("SearchEventFeed") {
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
Nip19.uriToRoute(mySearchString)?.hex ?: isAStraightHex
|
Nip19Bech32.uriToRoute(mySearchString)?.hex ?: isAStraightHex
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (e is CancellationException) throw e
|
if (e is CancellationException) throw e
|
||||||
null
|
null
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ import com.vitorpamplona.amethyst.ui.screen.AccountScreen
|
|||||||
import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel
|
import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.screen.SharedPreferencesViewModel
|
import com.vitorpamplona.amethyst.ui.screen.SharedPreferencesViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.AmethystTheme
|
import com.vitorpamplona.amethyst.ui.theme.AmethystTheme
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.encoders.Nip47WalletConnect
|
import com.vitorpamplona.quartz.encoders.Nip47WalletConnect
|
||||||
import com.vitorpamplona.quartz.events.ChannelCreateEvent
|
import com.vitorpamplona.quartz.events.ChannelCreateEvent
|
||||||
import com.vitorpamplona.quartz.events.ChannelMessageEvent
|
import com.vitorpamplona.quartz.events.ChannelMessageEvent
|
||||||
@@ -311,11 +311,11 @@ fun uriToRoute(uri: String?): String? {
|
|||||||
if (uri?.startsWith("nostr:Hashtag?id=") == true) {
|
if (uri?.startsWith("nostr:Hashtag?id=") == true) {
|
||||||
Route.Hashtag.route.replace("{id}", uri.removePrefix("nostr:Hashtag?id="))
|
Route.Hashtag.route.replace("{id}", uri.removePrefix("nostr:Hashtag?id="))
|
||||||
} else {
|
} else {
|
||||||
val nip19 = Nip19.uriToRoute(uri)
|
val nip19 = Nip19Bech32.uriToRoute(uri)
|
||||||
when (nip19?.type) {
|
when (nip19?.type) {
|
||||||
Nip19.Type.USER -> "User/${nip19.hex}"
|
Nip19Bech32.Type.USER -> "User/${nip19.hex}"
|
||||||
Nip19.Type.NOTE -> "Note/${nip19.hex}"
|
Nip19Bech32.Type.NOTE -> "Note/${nip19.hex}"
|
||||||
Nip19.Type.EVENT -> {
|
Nip19Bech32.Type.EVENT -> {
|
||||||
if (nip19.kind == PrivateDmEvent.KIND) {
|
if (nip19.kind == PrivateDmEvent.KIND) {
|
||||||
nip19.author?.let { "RoomByAuthor/$it" }
|
nip19.author?.let { "RoomByAuthor/$it" }
|
||||||
} else if (
|
} else if (
|
||||||
@@ -328,7 +328,7 @@ fun uriToRoute(uri: String?): String? {
|
|||||||
"Event/${nip19.hex}"
|
"Event/${nip19.hex}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Nip19.Type.ADDRESS ->
|
Nip19Bech32.Type.ADDRESS ->
|
||||||
if (nip19.kind == CommunityDefinitionEvent.KIND) {
|
if (nip19.kind == CommunityDefinitionEvent.KIND) {
|
||||||
"Community/${nip19.hex}"
|
"Community/${nip19.hex}"
|
||||||
} else if (nip19.kind == LiveActivitiesEvent.KIND) {
|
} else if (nip19.kind == LiveActivitiesEvent.KIND) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import com.vitorpamplona.amethyst.model.User
|
|||||||
import com.vitorpamplona.quartz.crypto.KeyPair
|
import com.vitorpamplona.quartz.crypto.KeyPair
|
||||||
import com.vitorpamplona.quartz.encoders.Bech32
|
import com.vitorpamplona.quartz.encoders.Bech32
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.encoders.bechToBytes
|
import com.vitorpamplona.quartz.encoders.bechToBytes
|
||||||
import com.vitorpamplona.quartz.encoders.toNpub
|
import com.vitorpamplona.quartz.encoders.toNpub
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
@@ -68,13 +68,13 @@ class NewMessageTagger(
|
|||||||
paragraph.split(' ').forEach { word: String ->
|
paragraph.split(' ').forEach { word: String ->
|
||||||
val results = parseDirtyWordForKey(word)
|
val results = parseDirtyWordForKey(word)
|
||||||
|
|
||||||
if (results?.key?.type == Nip19.Type.USER) {
|
if (results?.key?.type == Nip19Bech32.Type.USER) {
|
||||||
addUserToMentions(dao.getOrCreateUser(results.key.hex))
|
addUserToMentions(dao.getOrCreateUser(results.key.hex))
|
||||||
} else if (results?.key?.type == Nip19.Type.NOTE) {
|
} else if (results?.key?.type == Nip19Bech32.Type.NOTE) {
|
||||||
addNoteToReplyTos(dao.getOrCreateNote(results.key.hex))
|
addNoteToReplyTos(dao.getOrCreateNote(results.key.hex))
|
||||||
} else if (results?.key?.type == Nip19.Type.EVENT) {
|
} else if (results?.key?.type == Nip19Bech32.Type.EVENT) {
|
||||||
addNoteToReplyTos(dao.getOrCreateNote(results.key.hex))
|
addNoteToReplyTos(dao.getOrCreateNote(results.key.hex))
|
||||||
} else if (results?.key?.type == Nip19.Type.ADDRESS) {
|
} else if (results?.key?.type == Nip19Bech32.Type.ADDRESS) {
|
||||||
val note = dao.checkGetOrCreateAddressableNote(results.key.hex)
|
val note = dao.checkGetOrCreateAddressableNote(results.key.hex)
|
||||||
if (note != null) {
|
if (note != null) {
|
||||||
addNoteToReplyTos(note)
|
addNoteToReplyTos(note)
|
||||||
@@ -92,19 +92,19 @@ class NewMessageTagger(
|
|||||||
.split(' ')
|
.split(' ')
|
||||||
.map { word: String ->
|
.map { word: String ->
|
||||||
val results = parseDirtyWordForKey(word)
|
val results = parseDirtyWordForKey(word)
|
||||||
if (results?.key?.type == Nip19.Type.USER) {
|
if (results?.key?.type == Nip19Bech32.Type.USER) {
|
||||||
val user = dao.getOrCreateUser(results.key.hex)
|
val user = dao.getOrCreateUser(results.key.hex)
|
||||||
|
|
||||||
getNostrAddress(user.pubkeyNpub(), results.restOfWord)
|
getNostrAddress(user.pubkeyNpub(), results.restOfWord)
|
||||||
} else if (results?.key?.type == Nip19.Type.NOTE) {
|
} else if (results?.key?.type == Nip19Bech32.Type.NOTE) {
|
||||||
val note = dao.getOrCreateNote(results.key.hex)
|
val note = dao.getOrCreateNote(results.key.hex)
|
||||||
|
|
||||||
getNostrAddress(note.toNEvent(), results.restOfWord)
|
getNostrAddress(note.toNEvent(), results.restOfWord)
|
||||||
} else if (results?.key?.type == Nip19.Type.EVENT) {
|
} else if (results?.key?.type == Nip19Bech32.Type.EVENT) {
|
||||||
val note = dao.getOrCreateNote(results.key.hex)
|
val note = dao.getOrCreateNote(results.key.hex)
|
||||||
|
|
||||||
getNostrAddress(note.toNEvent(), results.restOfWord)
|
getNostrAddress(note.toNEvent(), results.restOfWord)
|
||||||
} else if (results?.key?.type == Nip19.Type.ADDRESS) {
|
} else if (results?.key?.type == Nip19Bech32.Type.ADDRESS) {
|
||||||
val note = dao.checkGetOrCreateAddressableNote(results.key.hex)
|
val note = dao.checkGetOrCreateAddressableNote(results.key.hex)
|
||||||
if (note != null) {
|
if (note != null) {
|
||||||
getNostrAddress(note.idNote(), results.restOfWord)
|
getNostrAddress(note.idNote(), results.restOfWord)
|
||||||
@@ -135,7 +135,7 @@ class NewMessageTagger(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Immutable data class DirtyKeyInfo(val key: Nip19.Return, val restOfWord: String)
|
@Immutable data class DirtyKeyInfo(val key: Nip19Bech32.Return, val restOfWord: String)
|
||||||
|
|
||||||
fun parseDirtyWordForKey(mightBeAKey: String): DirtyKeyInfo? {
|
fun parseDirtyWordForKey(mightBeAKey: String): DirtyKeyInfo? {
|
||||||
var key = mightBeAKey
|
var key = mightBeAKey
|
||||||
@@ -155,7 +155,7 @@ class NewMessageTagger(
|
|||||||
val restOfWord = key.substring(63)
|
val restOfWord = key.substring(63)
|
||||||
// Converts to npub
|
// Converts to npub
|
||||||
val pubkey =
|
val pubkey =
|
||||||
Nip19.uriToRoute(KeyPair(privKey = keyB32.bechToBytes()).pubKey.toNpub()) ?: return null
|
Nip19Bech32.uriToRoute(KeyPair(privKey = keyB32.bechToBytes()).pubKey.toNpub()) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(pubkey, restOfWord)
|
return DirtyKeyInfo(pubkey, restOfWord)
|
||||||
} else if (key.startsWith("npub1", true)) {
|
} else if (key.startsWith("npub1", true)) {
|
||||||
@@ -166,7 +166,7 @@ class NewMessageTagger(
|
|||||||
val keyB32 = key.substring(0, 63)
|
val keyB32 = key.substring(0, 63)
|
||||||
val restOfWord = key.substring(63)
|
val restOfWord = key.substring(63)
|
||||||
|
|
||||||
val pubkey = Nip19.uriToRoute(keyB32) ?: return null
|
val pubkey = Nip19Bech32.uriToRoute(keyB32) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(pubkey, restOfWord)
|
return DirtyKeyInfo(pubkey, restOfWord)
|
||||||
} else if (key.startsWith("note1", true)) {
|
} else if (key.startsWith("note1", true)) {
|
||||||
@@ -177,19 +177,19 @@ class NewMessageTagger(
|
|||||||
val keyB32 = key.substring(0, 63)
|
val keyB32 = key.substring(0, 63)
|
||||||
val restOfWord = key.substring(63)
|
val restOfWord = key.substring(63)
|
||||||
|
|
||||||
val noteId = Nip19.uriToRoute(keyB32) ?: return null
|
val noteId = Nip19Bech32.uriToRoute(keyB32) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(noteId, restOfWord)
|
return DirtyKeyInfo(noteId, restOfWord)
|
||||||
} else if (key.startsWith("nprofile", true)) {
|
} else if (key.startsWith("nprofile", true)) {
|
||||||
val pubkeyRelay = Nip19.uriToRoute(key) ?: return null
|
val pubkeyRelay = Nip19Bech32.uriToRoute(key) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(pubkeyRelay, pubkeyRelay.additionalChars)
|
return DirtyKeyInfo(pubkeyRelay, pubkeyRelay.additionalChars)
|
||||||
} else if (key.startsWith("nevent1", true)) {
|
} else if (key.startsWith("nevent1", true)) {
|
||||||
val noteRelayId = Nip19.uriToRoute(key) ?: return null
|
val noteRelayId = Nip19Bech32.uriToRoute(key) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(noteRelayId, noteRelayId.additionalChars)
|
return DirtyKeyInfo(noteRelayId, noteRelayId.additionalChars)
|
||||||
} else if (key.startsWith("naddr1", true)) {
|
} else if (key.startsWith("naddr1", true)) {
|
||||||
val address = Nip19.uriToRoute(key) ?: return null
|
val address = Nip19Bech32.uriToRoute(key) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(
|
return DirtyKeyInfo(
|
||||||
address,
|
address,
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import androidx.compose.ui.window.Dialog
|
|||||||
import androidx.compose.ui.window.DialogProperties
|
import androidx.compose.ui.window.DialogProperties
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.RelayBriefInfoCache
|
import com.vitorpamplona.amethyst.model.RelayBriefInfoCache
|
||||||
import com.vitorpamplona.amethyst.model.RelayInformation
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.ClickableEmail
|
import com.vitorpamplona.amethyst.ui.components.ClickableEmail
|
||||||
import com.vitorpamplona.amethyst.ui.components.ClickableUrl
|
import com.vitorpamplona.amethyst.ui.components.ClickableUrl
|
||||||
import com.vitorpamplona.amethyst.ui.note.LoadUser
|
import com.vitorpamplona.amethyst.ui.note.LoadUser
|
||||||
@@ -59,13 +58,14 @@ import com.vitorpamplona.amethyst.ui.theme.DoubleHorzSpacer
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.DoubleVertSpacer
|
import com.vitorpamplona.amethyst.ui.theme.DoubleVertSpacer
|
||||||
import com.vitorpamplona.amethyst.ui.theme.StdPadding
|
import com.vitorpamplona.amethyst.ui.theme.StdPadding
|
||||||
import com.vitorpamplona.amethyst.ui.theme.largeRelayIconModifier
|
import com.vitorpamplona.amethyst.ui.theme.largeRelayIconModifier
|
||||||
|
import com.vitorpamplona.quartz.encoders.Nip11RelayInformation
|
||||||
|
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun RelayInformationDialog(
|
fun RelayInformationDialog(
|
||||||
onClose: () -> Unit,
|
onClose: () -> Unit,
|
||||||
relayBriefInfo: RelayBriefInfoCache.RelayBriefInfo,
|
relayBriefInfo: RelayBriefInfoCache.RelayBriefInfo,
|
||||||
relayInfo: RelayInformation,
|
relayInfo: Nip11RelayInformation,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -236,7 +236,7 @@ fun RelayInformationDialog(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
private fun DisplaySupportedNips(relayInfo: RelayInformation) {
|
private fun DisplaySupportedNips(relayInfo: Nip11RelayInformation) {
|
||||||
FlowRow {
|
FlowRow {
|
||||||
relayInfo.supported_nips?.forEach { item ->
|
relayInfo.supported_nips?.forEach { item ->
|
||||||
val text = item.toString().padStart(2, '0')
|
val text = item.toString().padStart(2, '0')
|
||||||
@@ -261,7 +261,7 @@ private fun DisplaySupportedNips(relayInfo: RelayInformation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun DisplaySoftwareInformation(relayInfo: RelayInformation) {
|
private fun DisplaySoftwareInformation(relayInfo: Nip11RelayInformation) {
|
||||||
val url = (relayInfo.software ?: "").replace("git+", "")
|
val url = (relayInfo.software ?: "").replace("git+", "")
|
||||||
Box(modifier = Modifier.padding(start = 10.dp)) {
|
Box(modifier = Modifier.padding(start = 10.dp)) {
|
||||||
ClickableUrl(
|
ClickableUrl(
|
||||||
|
|||||||
@@ -47,11 +47,11 @@ import androidx.compose.ui.window.Dialog
|
|||||||
import androidx.compose.ui.window.DialogProperties
|
import androidx.compose.ui.window.DialogProperties
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.RelayBriefInfoCache
|
import com.vitorpamplona.amethyst.model.RelayBriefInfoCache
|
||||||
import com.vitorpamplona.amethyst.model.RelayInformation
|
|
||||||
import com.vitorpamplona.amethyst.service.Nip11Retriever
|
import com.vitorpamplona.amethyst.service.Nip11Retriever
|
||||||
import com.vitorpamplona.amethyst.service.relays.Relay
|
import com.vitorpamplona.amethyst.service.relays.Relay
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||||
|
import com.vitorpamplona.quartz.encoders.Nip11RelayInformation
|
||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ data class RelayList(
|
|||||||
|
|
||||||
data class RelayInfoDialog(
|
data class RelayInfoDialog(
|
||||||
val relayBriefInfo: RelayBriefInfoCache.RelayBriefInfo,
|
val relayBriefInfo: RelayBriefInfoCache.RelayBriefInfo,
|
||||||
val relayInfo: RelayInformation,
|
val relayInfo: Nip11RelayInformation,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ import com.vitorpamplona.amethyst.model.User
|
|||||||
import com.vitorpamplona.amethyst.ui.note.LoadChannel
|
import com.vitorpamplona.amethyst.ui.note.LoadChannel
|
||||||
import com.vitorpamplona.amethyst.ui.note.toShortenHex
|
import com.vitorpamplona.amethyst.ui.note.toShortenHex
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.encoders.Nip30CustomEmoji
|
import com.vitorpamplona.quartz.encoders.Nip30CustomEmoji
|
||||||
import com.vitorpamplona.quartz.events.ChannelCreateEvent
|
import com.vitorpamplona.quartz.events.ChannelCreateEvent
|
||||||
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
||||||
@@ -72,21 +72,21 @@ import kotlinx.collections.immutable.ImmutableMap
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ClickableRoute(
|
fun ClickableRoute(
|
||||||
nip19: Nip19.Return,
|
nip19: Nip19Bech32.Return,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
when (nip19.type) {
|
when (nip19.type) {
|
||||||
Nip19.Type.USER -> {
|
Nip19Bech32.Type.USER -> {
|
||||||
DisplayUser(nip19, accountViewModel, nav)
|
DisplayUser(nip19, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
Nip19.Type.ADDRESS -> {
|
Nip19Bech32.Type.ADDRESS -> {
|
||||||
DisplayAddress(nip19, accountViewModel, nav)
|
DisplayAddress(nip19, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
Nip19.Type.NOTE -> {
|
Nip19Bech32.Type.NOTE -> {
|
||||||
DisplayNote(nip19, accountViewModel, nav)
|
DisplayNote(nip19, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
Nip19.Type.EVENT -> {
|
Nip19Bech32.Type.EVENT -> {
|
||||||
DisplayEvent(nip19, accountViewModel, nav)
|
DisplayEvent(nip19, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
@@ -99,7 +99,7 @@ fun ClickableRoute(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun DisplayEvent(
|
private fun DisplayEvent(
|
||||||
nip19: Nip19.Return,
|
nip19: Nip19Bech32.Return,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -119,7 +119,7 @@ private fun DisplayEvent(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun DisplayNote(
|
private fun DisplayNote(
|
||||||
nip19: Nip19.Return,
|
nip19: Nip19Bech32.Return,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -140,7 +140,7 @@ private fun DisplayNote(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun DisplayNoteLink(
|
private fun DisplayNoteLink(
|
||||||
it: Note,
|
it: Note,
|
||||||
nip19: Nip19.Return,
|
nip19: Nip19Bech32.Return,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -194,7 +194,7 @@ private fun DisplayNoteLink(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun DisplayAddress(
|
private fun DisplayAddress(
|
||||||
nip19: Nip19.Return,
|
nip19: Nip19Bech32.Return,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -229,7 +229,7 @@ private fun DisplayAddress(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun DisplayUser(
|
private fun DisplayUser(
|
||||||
nip19: Nip19.Return,
|
nip19: Nip19Bech32.Return,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -258,7 +258,7 @@ private fun DisplayUser(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun RenderUserAsClickableText(
|
private fun RenderUserAsClickableText(
|
||||||
baseUser: User,
|
baseUser: User,
|
||||||
nip19: Nip19.Return,
|
nip19: Nip19Bech32.Return,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val userState by baseUser.live().metadata.observeAsState()
|
val userState by baseUser.live().metadata.observeAsState()
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import android.util.Patterns
|
|||||||
import com.vitorpamplona.amethyst.commons.RichTextParser
|
import com.vitorpamplona.amethyst.commons.RichTextParser
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
|
|
||||||
@@ -64,20 +64,20 @@ class MarkdownParser {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDisplayNameFromNip19(nip19: Nip19.Return): Pair<String, String>? {
|
private fun getDisplayNameFromNip19(nip19: Nip19Bech32.Return): Pair<String, String>? {
|
||||||
if (nip19.type == Nip19.Type.USER) {
|
if (nip19.type == Nip19Bech32.Type.USER) {
|
||||||
LocalCache.users[nip19.hex]?.let {
|
LocalCache.users[nip19.hex]?.let {
|
||||||
return Pair(it.toBestDisplayName(), it.pubkeyNpub())
|
return Pair(it.toBestDisplayName(), it.pubkeyNpub())
|
||||||
}
|
}
|
||||||
} else if (nip19.type == Nip19.Type.NOTE) {
|
} else if (nip19.type == Nip19Bech32.Type.NOTE) {
|
||||||
LocalCache.notes[nip19.hex]?.let {
|
LocalCache.notes[nip19.hex]?.let {
|
||||||
return Pair(it.idDisplayNote(), it.toNEvent())
|
return Pair(it.idDisplayNote(), it.toNEvent())
|
||||||
}
|
}
|
||||||
} else if (nip19.type == Nip19.Type.ADDRESS) {
|
} else if (nip19.type == Nip19Bech32.Type.ADDRESS) {
|
||||||
LocalCache.addressables[nip19.hex]?.let {
|
LocalCache.addressables[nip19.hex]?.let {
|
||||||
return Pair(it.idDisplayNote(), it.toNEvent())
|
return Pair(it.idDisplayNote(), it.toNEvent())
|
||||||
}
|
}
|
||||||
} else if (nip19.type == Nip19.Type.EVENT) {
|
} else if (nip19.type == Nip19Bech32.Type.EVENT) {
|
||||||
LocalCache.notes[nip19.hex]?.let {
|
LocalCache.notes[nip19.hex]?.let {
|
||||||
return Pair(it.idDisplayNote(), it.toNEvent())
|
return Pair(it.idDisplayNote(), it.toNEvent())
|
||||||
}
|
}
|
||||||
@@ -89,14 +89,14 @@ class MarkdownParser {
|
|||||||
fun returnNIP19References(
|
fun returnNIP19References(
|
||||||
content: String,
|
content: String,
|
||||||
tags: ImmutableListOfLists<String>?,
|
tags: ImmutableListOfLists<String>?,
|
||||||
): List<Nip19.Return> {
|
): List<Nip19Bech32.Return> {
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
|
|
||||||
val listOfReferences = mutableListOf<Nip19.Return>()
|
val listOfReferences = mutableListOf<Nip19Bech32.Return>()
|
||||||
content.split('\n').forEach { paragraph ->
|
content.split('\n').forEach { paragraph ->
|
||||||
paragraph.split(' ').forEach { word: String ->
|
paragraph.split(' ').forEach { word: String ->
|
||||||
if (RichTextParser.startsWithNIP19Scheme(word)) {
|
if (RichTextParser.startsWithNIP19Scheme(word)) {
|
||||||
val parsedNip19 = Nip19.uriToRoute(word)
|
val parsedNip19 = Nip19Bech32.uriToRoute(word)
|
||||||
parsedNip19?.let { listOfReferences.add(it) }
|
parsedNip19?.let { listOfReferences.add(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,11 +104,11 @@ class MarkdownParser {
|
|||||||
|
|
||||||
tags?.lists?.forEach {
|
tags?.lists?.forEach {
|
||||||
if (it[0] == "p" && it.size > 1) {
|
if (it[0] == "p" && it.size > 1) {
|
||||||
listOfReferences.add(Nip19.Return(Nip19.Type.USER, it[1], null, null, null, ""))
|
listOfReferences.add(Nip19Bech32.Return(Nip19Bech32.Type.USER, it[1], null, null, null, ""))
|
||||||
} else if (it[0] == "e" && it.size > 1) {
|
} else if (it[0] == "e" && it.size > 1) {
|
||||||
listOfReferences.add(Nip19.Return(Nip19.Type.NOTE, it[1], null, null, null, ""))
|
listOfReferences.add(Nip19Bech32.Return(Nip19Bech32.Type.NOTE, it[1], null, null, null, ""))
|
||||||
} else if (it[0] == "a" && it.size > 1) {
|
} else if (it[0] == "a" && it.size > 1) {
|
||||||
listOfReferences.add(Nip19.Return(Nip19.Type.ADDRESS, it[1], null, null, null, ""))
|
listOfReferences.add(Nip19Bech32.Return(Nip19Bech32.Type.ADDRESS, it[1], null, null, null, ""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ class MarkdownParser {
|
|||||||
} else if (Patterns.PHONE.matcher(word).matches() && word.length > 6) {
|
} else if (Patterns.PHONE.matcher(word).matches() && word.length > 6) {
|
||||||
returnContent += "[$word](tel:$word) "
|
returnContent += "[$word](tel:$word) "
|
||||||
} else if (RichTextParser.startsWithNIP19Scheme(word)) {
|
} else if (RichTextParser.startsWithNIP19Scheme(word)) {
|
||||||
val parsedNip19 = Nip19.uriToRoute(word)
|
val parsedNip19 = Nip19Bech32.uriToRoute(word)
|
||||||
returnContent +=
|
returnContent +=
|
||||||
if (parsedNip19 !== null) {
|
if (parsedNip19 !== null) {
|
||||||
val pair = getDisplayNameFromNip19(parsedNip19)
|
val pair = getDisplayNameFromNip19(parsedNip19)
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ import com.vitorpamplona.amethyst.ui.theme.innerPostModifier
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.markdownStyle
|
import com.vitorpamplona.amethyst.ui.theme.markdownStyle
|
||||||
import com.vitorpamplona.amethyst.ui.uriToRoute
|
import com.vitorpamplona.amethyst.ui.uriToRoute
|
||||||
import com.vitorpamplona.quartz.crypto.KeyPair
|
import com.vitorpamplona.quartz.crypto.KeyPair
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.events.EmptyTagList
|
import com.vitorpamplona.quartz.events.EmptyTagList
|
||||||
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
||||||
import fr.acinq.secp256k1.Hex
|
import fr.acinq.secp256k1.Hex
|
||||||
@@ -526,7 +526,7 @@ fun ObserverAllNIP19References(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
onRefresh: () -> Unit,
|
onRefresh: () -> Unit,
|
||||||
) {
|
) {
|
||||||
var nip19References by remember(content) { mutableStateOf<List<Nip19.Return>>(emptyList()) }
|
var nip19References by remember(content) { mutableStateOf<List<Nip19Bech32.Return>>(emptyList()) }
|
||||||
|
|
||||||
LaunchedEffect(key1 = content) {
|
LaunchedEffect(key1 = content) {
|
||||||
accountViewModel.returnNIP19References(content, tags) {
|
accountViewModel.returnNIP19References(content, tags) {
|
||||||
@@ -540,20 +540,20 @@ fun ObserverAllNIP19References(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ObserveNIP19(
|
fun ObserveNIP19(
|
||||||
it: Nip19.Return,
|
it: Nip19Bech32.Return,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
onRefresh: () -> Unit,
|
onRefresh: () -> Unit,
|
||||||
) {
|
) {
|
||||||
if (it.type == Nip19.Type.NOTE || it.type == Nip19.Type.EVENT || it.type == Nip19.Type.ADDRESS) {
|
if (it.type == Nip19Bech32.Type.NOTE || it.type == Nip19Bech32.Type.EVENT || it.type == Nip19Bech32.Type.ADDRESS) {
|
||||||
ObserveNIP19Event(it, accountViewModel, onRefresh)
|
ObserveNIP19Event(it, accountViewModel, onRefresh)
|
||||||
} else if (it.type == Nip19.Type.USER) {
|
} else if (it.type == Nip19Bech32.Type.USER) {
|
||||||
ObserveNIP19User(it, accountViewModel, onRefresh)
|
ObserveNIP19User(it, accountViewModel, onRefresh)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun ObserveNIP19Event(
|
private fun ObserveNIP19Event(
|
||||||
it: Nip19.Return,
|
it: Nip19Bech32.Return,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
onRefresh: () -> Unit,
|
onRefresh: () -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -562,7 +562,7 @@ private fun ObserveNIP19Event(
|
|||||||
if (baseNote == null) {
|
if (baseNote == null) {
|
||||||
LaunchedEffect(key1 = it.hex) {
|
LaunchedEffect(key1 = it.hex) {
|
||||||
if (
|
if (
|
||||||
it.type == Nip19.Type.NOTE || it.type == Nip19.Type.EVENT || it.type == Nip19.Type.ADDRESS
|
it.type == Nip19Bech32.Type.NOTE || it.type == Nip19Bech32.Type.EVENT || it.type == Nip19Bech32.Type.ADDRESS
|
||||||
) {
|
) {
|
||||||
accountViewModel.checkGetOrCreateNote(it.hex) { note ->
|
accountViewModel.checkGetOrCreateNote(it.hex) { note ->
|
||||||
launch(Dispatchers.Main) { baseNote = note }
|
launch(Dispatchers.Main) { baseNote = note }
|
||||||
@@ -590,7 +590,7 @@ fun ObserveNote(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun ObserveNIP19User(
|
private fun ObserveNIP19User(
|
||||||
it: Nip19.Return,
|
it: Nip19Bech32.Return,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
onRefresh: () -> Unit,
|
onRefresh: () -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -598,7 +598,7 @@ private fun ObserveNIP19User(
|
|||||||
|
|
||||||
if (baseUser == null) {
|
if (baseUser == null) {
|
||||||
LaunchedEffect(key1 = it.hex) {
|
LaunchedEffect(key1 = it.hex) {
|
||||||
if (it.type == Nip19.Type.USER) {
|
if (it.type == Nip19Bech32.Type.USER) {
|
||||||
accountViewModel.checkGetOrCreateUser(it.hex)?.let { user ->
|
accountViewModel.checkGetOrCreateUser(it.hex)?.let { user ->
|
||||||
launch(Dispatchers.Main) { baseUser = user }
|
launch(Dispatchers.Main) { baseUser = user }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ import androidx.lifecycle.map
|
|||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.RelayBriefInfoCache
|
import com.vitorpamplona.amethyst.model.RelayBriefInfoCache
|
||||||
import com.vitorpamplona.amethyst.model.RelayInformation
|
|
||||||
import com.vitorpamplona.amethyst.service.Nip11Retriever
|
import com.vitorpamplona.amethyst.service.Nip11Retriever
|
||||||
import com.vitorpamplona.amethyst.ui.actions.RelayInformationDialog
|
import com.vitorpamplona.amethyst.ui.actions.RelayInformationDialog
|
||||||
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
|
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
|
||||||
@@ -62,6 +61,7 @@ import com.vitorpamplona.amethyst.ui.theme.Size15dp
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.StdStartPadding
|
import com.vitorpamplona.amethyst.ui.theme.StdStartPadding
|
||||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||||
import com.vitorpamplona.amethyst.ui.theme.relayIconModifier
|
import com.vitorpamplona.amethyst.ui.theme.relayIconModifier
|
||||||
|
import com.vitorpamplona.quartz.encoders.Nip11RelayInformation
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
public fun RelayBadgesHorizontal(
|
public fun RelayBadgesHorizontal(
|
||||||
@@ -132,7 +132,7 @@ fun RenderRelay(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
var relayInfo: RelayInformation? by remember { mutableStateOf(null) }
|
var relayInfo: Nip11RelayInformation? by remember { mutableStateOf(null) }
|
||||||
|
|
||||||
if (relayInfo != null) {
|
if (relayInfo != null) {
|
||||||
RelayInformationDialog(
|
RelayInformationDialog(
|
||||||
|
|||||||
@@ -29,20 +29,20 @@ import com.google.zxing.client.android.Intents
|
|||||||
import com.journeyapps.barcodescanner.ScanContract
|
import com.journeyapps.barcodescanner.ScanContract
|
||||||
import com.journeyapps.barcodescanner.ScanOptions
|
import com.journeyapps.barcodescanner.ScanOptions
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun NIP19QrCodeScanner(onScan: (String?) -> Unit) {
|
fun NIP19QrCodeScanner(onScan: (String?) -> Unit) {
|
||||||
SimpleQrCodeScanner {
|
SimpleQrCodeScanner {
|
||||||
try {
|
try {
|
||||||
val nip19 = Nip19.uriToRoute(it)
|
val nip19 = Nip19Bech32.uriToRoute(it)
|
||||||
val startingPage =
|
val startingPage =
|
||||||
when (nip19?.type) {
|
when (nip19?.type) {
|
||||||
Nip19.Type.USER -> "User/${nip19.hex}"
|
Nip19Bech32.Type.USER -> "User/${nip19.hex}"
|
||||||
Nip19.Type.NOTE -> "Note/${nip19.hex}"
|
Nip19Bech32.Type.NOTE -> "Note/${nip19.hex}"
|
||||||
Nip19.Type.EVENT -> "Event/${nip19.hex}"
|
Nip19Bech32.Type.EVENT -> "Event/${nip19.hex}"
|
||||||
Nip19.Type.ADDRESS -> "Note/${nip19.hex}"
|
Nip19Bech32.Type.ADDRESS -> "Note/${nip19.hex}"
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import com.vitorpamplona.amethyst.service.relays.Client
|
|||||||
import com.vitorpamplona.quartz.crypto.CryptoUtils
|
import com.vitorpamplona.quartz.crypto.CryptoUtils
|
||||||
import com.vitorpamplona.quartz.crypto.KeyPair
|
import com.vitorpamplona.quartz.crypto.KeyPair
|
||||||
import com.vitorpamplona.quartz.encoders.Hex
|
import com.vitorpamplona.quartz.encoders.Hex
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.encoders.bechToBytes
|
import com.vitorpamplona.quartz.encoders.bechToBytes
|
||||||
import com.vitorpamplona.quartz.encoders.hexToByteArray
|
import com.vitorpamplona.quartz.encoders.hexToByteArray
|
||||||
import com.vitorpamplona.quartz.encoders.toHexKey
|
import com.vitorpamplona.quartz.encoders.toHexKey
|
||||||
@@ -85,7 +85,7 @@ class AccountStateViewModel() : ViewModel() {
|
|||||||
loginWithExternalSigner: Boolean = false,
|
loginWithExternalSigner: Boolean = false,
|
||||||
packageName: String = "",
|
packageName: String = "",
|
||||||
) = withContext(Dispatchers.IO) {
|
) = withContext(Dispatchers.IO) {
|
||||||
val parsed = Nip19.uriToRoute(key)
|
val parsed = Nip19Bech32.uriToRoute(key)
|
||||||
val pubKeyParsed = parsed?.hex?.hexToByteArray()
|
val pubKeyParsed = parsed?.hex?.hexToByteArray()
|
||||||
val proxy = HttpClientManager.initProxy(useProxy, "127.0.0.1", proxyPort)
|
val proxy = HttpClientManager.initProxy(useProxy, "127.0.0.1", proxyPort)
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ import com.vitorpamplona.amethyst.model.AddressableNote
|
|||||||
import com.vitorpamplona.amethyst.model.Channel
|
import com.vitorpamplona.amethyst.model.Channel
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.RelayInformation
|
|
||||||
import com.vitorpamplona.amethyst.model.UrlCachedPreviewer
|
import com.vitorpamplona.amethyst.model.UrlCachedPreviewer
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.model.UserState
|
import com.vitorpamplona.amethyst.model.UserState
|
||||||
@@ -69,7 +68,8 @@ import com.vitorpamplona.amethyst.ui.screen.CombinedZap
|
|||||||
import com.vitorpamplona.amethyst.ui.screen.SettingsState
|
import com.vitorpamplona.amethyst.ui.screen.SettingsState
|
||||||
import com.vitorpamplona.quartz.encoders.ATag
|
import com.vitorpamplona.quartz.encoders.ATag
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip11RelayInformation
|
||||||
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.events.ChatroomKey
|
import com.vitorpamplona.quartz.events.ChatroomKey
|
||||||
import com.vitorpamplona.quartz.events.ChatroomKeyable
|
import com.vitorpamplona.quartz.events.ChatroomKeyable
|
||||||
import com.vitorpamplona.quartz.events.Event
|
import com.vitorpamplona.quartz.events.Event
|
||||||
@@ -806,7 +806,7 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
|
|||||||
|
|
||||||
fun retrieveRelayDocument(
|
fun retrieveRelayDocument(
|
||||||
dirtyUrl: String,
|
dirtyUrl: String,
|
||||||
onInfo: (RelayInformation) -> Unit,
|
onInfo: (Nip11RelayInformation) -> Unit,
|
||||||
onError: (String, Nip11Retriever.ErrorCode, String?) -> Unit,
|
onError: (String, Nip11Retriever.ErrorCode, String?) -> Unit,
|
||||||
) {
|
) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
@@ -943,7 +943,7 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
|
|||||||
fun returnNIP19References(
|
fun returnNIP19References(
|
||||||
content: String,
|
content: String,
|
||||||
tags: ImmutableListOfLists<String>?,
|
tags: ImmutableListOfLists<String>?,
|
||||||
onNewReferences: (List<Nip19.Return>) -> Unit,
|
onNewReferences: (List<Nip19Bech32.Return>) -> Unit,
|
||||||
) {
|
) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
onNewReferences(MarkdownParser().returnNIP19References(content, tags))
|
onNewReferences(MarkdownParser().returnNIP19References(content, tags))
|
||||||
@@ -965,10 +965,10 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
|
|||||||
onNote: (LoadedBechLink) -> Unit,
|
onNote: (LoadedBechLink) -> Unit,
|
||||||
) {
|
) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
Nip19.uriToRoute(str)?.let {
|
Nip19Bech32.uriToRoute(str)?.let {
|
||||||
var returningNote: Note? = null
|
var returningNote: Note? = null
|
||||||
if (
|
if (
|
||||||
it.type == Nip19.Type.NOTE || it.type == Nip19.Type.EVENT || it.type == Nip19.Type.ADDRESS
|
it.type == Nip19Bech32.Type.NOTE || it.type == Nip19Bech32.Type.EVENT || it.type == Nip19Bech32.Type.ADDRESS
|
||||||
) {
|
) {
|
||||||
LocalCache.checkGetOrCreateNote(it.hex)?.let { note -> returningNote = note }
|
LocalCache.checkGetOrCreateNote(it.hex)?.let { note -> returningNote = note }
|
||||||
}
|
}
|
||||||
@@ -1270,7 +1270,7 @@ class HasNotificationDot(bottomNavigationItems: ImmutableList<Route>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Immutable data class LoadedBechLink(val baseNote: Note?, val nip19: Nip19.Return)
|
@Immutable data class LoadedBechLink(val baseNote: Note?, val nip19: Nip19Bech32.Return)
|
||||||
|
|
||||||
public fun <T, K> allOrNothingSigningOperations(
|
public fun <T, K> allOrNothingSigningOperations(
|
||||||
remainingTos: List<T>,
|
remainingTos: List<T>,
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import com.vitorpamplona.amethyst.model.Note
|
|||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.ui.actions.Dao
|
import com.vitorpamplona.amethyst.ui.actions.Dao
|
||||||
import com.vitorpamplona.amethyst.ui.actions.NewMessageTagger
|
import com.vitorpamplona.amethyst.ui.actions.NewMessageTagger
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ class NewMessageTaggerKeyParseTest {
|
|||||||
val result =
|
val result =
|
||||||
NewMessageTagger(message = "", dao = dao)
|
NewMessageTagger(message = "", dao = dao)
|
||||||
.parseDirtyWordForKey("note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn")
|
.parseDirtyWordForKey("note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn")
|
||||||
assertEquals(Nip19.Type.NOTE, result?.key?.type)
|
assertEquals(Nip19Bech32.Type.NOTE, result?.key?.type)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
|
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
|
||||||
result?.key?.hex,
|
result?.key?.hex,
|
||||||
@@ -67,7 +67,7 @@ class NewMessageTaggerKeyParseTest {
|
|||||||
val result =
|
val result =
|
||||||
NewMessageTagger(message = "", dao = dao)
|
NewMessageTagger(message = "", dao = dao)
|
||||||
.parseDirtyWordForKey("npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z")
|
.parseDirtyWordForKey("npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z")
|
||||||
assertEquals(Nip19.Type.USER, result?.key?.type)
|
assertEquals(Nip19Bech32.Type.USER, result?.key?.type)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
|
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
|
||||||
result?.key?.hex,
|
result?.key?.hex,
|
||||||
@@ -80,7 +80,7 @@ class NewMessageTaggerKeyParseTest {
|
|||||||
val result =
|
val result =
|
||||||
NewMessageTagger(message = "", dao = dao)
|
NewMessageTagger(message = "", dao = dao)
|
||||||
.parseDirtyWordForKey("note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,")
|
.parseDirtyWordForKey("note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,")
|
||||||
assertEquals(Nip19.Type.NOTE, result?.key?.type)
|
assertEquals(Nip19Bech32.Type.NOTE, result?.key?.type)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
|
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
|
||||||
result?.key?.hex,
|
result?.key?.hex,
|
||||||
@@ -93,7 +93,7 @@ class NewMessageTaggerKeyParseTest {
|
|||||||
val result =
|
val result =
|
||||||
NewMessageTagger(message = "", dao = dao)
|
NewMessageTagger(message = "", dao = dao)
|
||||||
.parseDirtyWordForKey("npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,")
|
.parseDirtyWordForKey("npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,")
|
||||||
assertEquals(Nip19.Type.USER, result?.key?.type)
|
assertEquals(Nip19Bech32.Type.USER, result?.key?.type)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
|
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
|
||||||
result?.key?.hex,
|
result?.key?.hex,
|
||||||
@@ -106,7 +106,7 @@ class NewMessageTaggerKeyParseTest {
|
|||||||
val result =
|
val result =
|
||||||
NewMessageTagger(message = "", dao = dao)
|
NewMessageTagger(message = "", dao = dao)
|
||||||
.parseDirtyWordForKey("@note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,")
|
.parseDirtyWordForKey("@note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,")
|
||||||
assertEquals(Nip19.Type.NOTE, result?.key?.type)
|
assertEquals(Nip19Bech32.Type.NOTE, result?.key?.type)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
|
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
|
||||||
result?.key?.hex,
|
result?.key?.hex,
|
||||||
@@ -119,7 +119,7 @@ class NewMessageTaggerKeyParseTest {
|
|||||||
val result =
|
val result =
|
||||||
NewMessageTagger(message = "", dao = dao)
|
NewMessageTagger(message = "", dao = dao)
|
||||||
.parseDirtyWordForKey("@npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,")
|
.parseDirtyWordForKey("@npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,")
|
||||||
assertEquals(Nip19.Type.USER, result?.key?.type)
|
assertEquals(Nip19Bech32.Type.USER, result?.key?.type)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
|
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
|
||||||
result?.key?.hex,
|
result?.key?.hex,
|
||||||
@@ -134,7 +134,7 @@ class NewMessageTaggerKeyParseTest {
|
|||||||
.parseDirtyWordForKey(
|
.parseDirtyWordForKey(
|
||||||
"nostr:note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,",
|
"nostr:note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,",
|
||||||
)
|
)
|
||||||
assertEquals(Nip19.Type.NOTE, result?.key?.type)
|
assertEquals(Nip19Bech32.Type.NOTE, result?.key?.type)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
|
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
|
||||||
result?.key?.hex,
|
result?.key?.hex,
|
||||||
@@ -149,7 +149,7 @@ class NewMessageTaggerKeyParseTest {
|
|||||||
.parseDirtyWordForKey(
|
.parseDirtyWordForKey(
|
||||||
"nostr:npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,",
|
"nostr:npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,",
|
||||||
)
|
)
|
||||||
assertEquals(Nip19.Type.USER, result?.key?.type)
|
assertEquals(Nip19Bech32.Type.USER, result?.key?.type)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
|
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
|
||||||
result?.key?.hex,
|
result?.key?.hex,
|
||||||
@@ -164,7 +164,7 @@ class NewMessageTaggerKeyParseTest {
|
|||||||
.parseDirtyWordForKey(
|
.parseDirtyWordForKey(
|
||||||
"Nostr:note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,",
|
"Nostr:note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,",
|
||||||
)
|
)
|
||||||
assertEquals(Nip19.Type.NOTE, result?.key?.type)
|
assertEquals(Nip19Bech32.Type.NOTE, result?.key?.type)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
|
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
|
||||||
result?.key?.hex,
|
result?.key?.hex,
|
||||||
@@ -179,7 +179,7 @@ class NewMessageTaggerKeyParseTest {
|
|||||||
.parseDirtyWordForKey(
|
.parseDirtyWordForKey(
|
||||||
"nOstr:npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,",
|
"nOstr:npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,",
|
||||||
)
|
)
|
||||||
assertEquals(Nip19.Type.USER, result?.key?.type)
|
assertEquals(Nip19Bech32.Type.USER, result?.key?.type)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
|
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
|
||||||
result?.key?.hex,
|
result?.key?.hex,
|
||||||
|
|||||||
@@ -30,10 +30,10 @@ data class ATag(val kind: Int, val pubKeyHex: String, val dTag: String, val rela
|
|||||||
fun toNAddr(): String {
|
fun toNAddr(): String {
|
||||||
return TlvBuilder()
|
return TlvBuilder()
|
||||||
.apply {
|
.apply {
|
||||||
addString(Nip19.TlvTypes.SPECIAL, dTag)
|
addString(Nip19Bech32.TlvTypes.SPECIAL, dTag)
|
||||||
addStringIfNotNull(Nip19.TlvTypes.RELAY, relay)
|
addStringIfNotNull(Nip19Bech32.TlvTypes.RELAY, relay)
|
||||||
addHex(Nip19.TlvTypes.AUTHOR, pubKeyHex)
|
addHex(Nip19Bech32.TlvTypes.AUTHOR, pubKeyHex)
|
||||||
addInt(Nip19.TlvTypes.KIND, kind)
|
addInt(Nip19Bech32.TlvTypes.KIND, kind)
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
.toNAddress()
|
.toNAddress()
|
||||||
@@ -76,10 +76,10 @@ data class ATag(val kind: Int, val pubKeyHex: String, val dTag: String, val rela
|
|||||||
if (key.startsWith("naddr")) {
|
if (key.startsWith("naddr")) {
|
||||||
val tlv = Tlv.parse(key.bechToBytes())
|
val tlv = Tlv.parse(key.bechToBytes())
|
||||||
|
|
||||||
val d = tlv.firstAsString(Nip19.TlvTypes.SPECIAL) ?: ""
|
val d = tlv.firstAsString(Nip19Bech32.TlvTypes.SPECIAL) ?: ""
|
||||||
val relay = tlv.firstAsString(Nip19.TlvTypes.RELAY)
|
val relay = tlv.firstAsString(Nip19Bech32.TlvTypes.RELAY)
|
||||||
val author = tlv.firstAsHex(Nip19.TlvTypes.AUTHOR)
|
val author = tlv.firstAsHex(Nip19Bech32.TlvTypes.AUTHOR)
|
||||||
val kind = tlv.firstAsInt(Nip19.TlvTypes.KIND)
|
val kind = tlv.firstAsInt(Nip19Bech32.TlvTypes.KIND)
|
||||||
|
|
||||||
if (kind != null && author != null) {
|
if (kind != null && author != null) {
|
||||||
return ATag(kind, author, d, relay)
|
return ATag(kind, author, d, relay)
|
||||||
|
|||||||
@@ -23,14 +23,16 @@ package com.vitorpamplona.quartz.encoders
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
val lnurlpPattern = Pattern.compile("(?i:http|https):\\/\\/((.+)\\/)*\\.well-known\\/lnurlp\\/(.*)")
|
|
||||||
|
|
||||||
class Lud06 {
|
class Lud06 {
|
||||||
|
companion object {
|
||||||
|
val LNURLP_PATTERN = Pattern.compile("(?i:http|https):\\/\\/((.+)\\/)*\\.well-known\\/lnurlp\\/(.*)")
|
||||||
|
}
|
||||||
|
|
||||||
fun toLud16(str: String): String? {
|
fun toLud16(str: String): String? {
|
||||||
return try {
|
return try {
|
||||||
val url = toLnUrlp(str)
|
val url = toLnUrlp(str)
|
||||||
|
|
||||||
val matcher = lnurlpPattern.matcher(url)
|
val matcher = LNURLP_PATTERN.matcher(url)
|
||||||
matcher.find()
|
matcher.find()
|
||||||
val domain = matcher.group(2)
|
val domain = matcher.group(2)
|
||||||
val username = matcher.group(3)
|
val username = matcher.group(3)
|
||||||
|
|||||||
+3
-3
@@ -18,14 +18,14 @@
|
|||||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* 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.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package com.vitorpamplona.amethyst.model
|
package com.vitorpamplona.quartz.encoders
|
||||||
|
|
||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature
|
import com.fasterxml.jackson.databind.DeserializationFeature
|
||||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
class RelayInformation(
|
class Nip11RelayInformation(
|
||||||
val id: String?,
|
val id: String?,
|
||||||
val name: String?,
|
val name: String?,
|
||||||
val description: String?,
|
val description: String?,
|
||||||
@@ -47,7 +47,7 @@ class RelayInformation(
|
|||||||
val mapper =
|
val mapper =
|
||||||
jacksonObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
jacksonObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||||
|
|
||||||
fun fromJson(json: String): RelayInformation = mapper.readValue(json, RelayInformation::class.java)
|
fun fromJson(json: String): Nip11RelayInformation = mapper.readValue(json, Nip11RelayInformation::class.java)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+12
-12
@@ -25,7 +25,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.quartz.crypto.KeyPair
|
import com.vitorpamplona.quartz.crypto.KeyPair
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
object Nip19 {
|
object Nip19Bech32 {
|
||||||
enum class Type {
|
enum class Type {
|
||||||
USER,
|
USER,
|
||||||
NOTE,
|
NOTE,
|
||||||
@@ -173,7 +173,7 @@ object Nip19 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun decodePublicKey(key: String): ByteArray {
|
fun decodePublicKey(key: String): ByteArray {
|
||||||
val parsed = Nip19.uriToRoute(key)
|
val parsed = Nip19Bech32.uriToRoute(key)
|
||||||
val pubKeyParsed = parsed?.hex?.hexToByteArray()
|
val pubKeyParsed = parsed?.hex?.hexToByteArray()
|
||||||
|
|
||||||
return if (key.startsWith("nsec")) {
|
return if (key.startsWith("nsec")) {
|
||||||
@@ -187,7 +187,7 @@ fun decodePublicKey(key: String): ByteArray {
|
|||||||
|
|
||||||
fun decodePublicKeyAsHexOrNull(key: String): HexKey? {
|
fun decodePublicKeyAsHexOrNull(key: String): HexKey? {
|
||||||
return try {
|
return try {
|
||||||
val parsed = Nip19.uriToRoute(key)
|
val parsed = Nip19Bech32.uriToRoute(key)
|
||||||
val pubKeyParsed = parsed?.hex
|
val pubKeyParsed = parsed?.hex
|
||||||
|
|
||||||
if (key.startsWith("nsec")) {
|
if (key.startsWith("nsec")) {
|
||||||
@@ -203,37 +203,37 @@ fun decodePublicKeyAsHexOrNull(key: String): HexKey? {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun TlvBuilder.addString(
|
fun TlvBuilder.addString(
|
||||||
type: Nip19.TlvTypes,
|
type: Nip19Bech32.TlvTypes,
|
||||||
string: String,
|
string: String,
|
||||||
) = addString(type.id, string)
|
) = addString(type.id, string)
|
||||||
|
|
||||||
fun TlvBuilder.addHex(
|
fun TlvBuilder.addHex(
|
||||||
type: Nip19.TlvTypes,
|
type: Nip19Bech32.TlvTypes,
|
||||||
key: HexKey,
|
key: HexKey,
|
||||||
) = addHex(type.id, key)
|
) = addHex(type.id, key)
|
||||||
|
|
||||||
fun TlvBuilder.addInt(
|
fun TlvBuilder.addInt(
|
||||||
type: Nip19.TlvTypes,
|
type: Nip19Bech32.TlvTypes,
|
||||||
data: Int,
|
data: Int,
|
||||||
) = addInt(type.id, data)
|
) = addInt(type.id, data)
|
||||||
|
|
||||||
fun TlvBuilder.addStringIfNotNull(
|
fun TlvBuilder.addStringIfNotNull(
|
||||||
type: Nip19.TlvTypes,
|
type: Nip19Bech32.TlvTypes,
|
||||||
data: String?,
|
data: String?,
|
||||||
) = addStringIfNotNull(type.id, data)
|
) = addStringIfNotNull(type.id, data)
|
||||||
|
|
||||||
fun TlvBuilder.addHexIfNotNull(
|
fun TlvBuilder.addHexIfNotNull(
|
||||||
type: Nip19.TlvTypes,
|
type: Nip19Bech32.TlvTypes,
|
||||||
data: HexKey?,
|
data: HexKey?,
|
||||||
) = addHexIfNotNull(type.id, data)
|
) = addHexIfNotNull(type.id, data)
|
||||||
|
|
||||||
fun TlvBuilder.addIntIfNotNull(
|
fun TlvBuilder.addIntIfNotNull(
|
||||||
type: Nip19.TlvTypes,
|
type: Nip19Bech32.TlvTypes,
|
||||||
data: Int?,
|
data: Int?,
|
||||||
) = addIntIfNotNull(type.id, data)
|
) = addIntIfNotNull(type.id, data)
|
||||||
|
|
||||||
fun Tlv.firstAsInt(type: Nip19.TlvTypes) = firstAsInt(type.id)
|
fun Tlv.firstAsInt(type: Nip19Bech32.TlvTypes) = firstAsInt(type.id)
|
||||||
|
|
||||||
fun Tlv.firstAsHex(type: Nip19.TlvTypes) = firstAsHex(type.id)
|
fun Tlv.firstAsHex(type: Nip19Bech32.TlvTypes) = firstAsHex(type.id)
|
||||||
|
|
||||||
fun Tlv.firstAsString(type: Nip19.TlvTypes) = firstAsString(type.id)
|
fun Tlv.firstAsString(type: Nip19Bech32.TlvTypes) = firstAsString(type.id)
|
||||||
@@ -23,8 +23,8 @@ package com.vitorpamplona.quartz.events
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19.nip19regex
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32.nip19regex
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
val tagSearch = Pattern.compile("(?:\\s|\\A)\\#\\[([0-9]+)\\]")
|
val tagSearch = Pattern.compile("(?:\\s|\\A)\\#\\[([0-9]+)\\]")
|
||||||
@@ -93,10 +93,10 @@ open class BaseTextNoteEvent(
|
|||||||
val additionalChars = matcher2.group(4) // additional chars
|
val additionalChars = matcher2.group(4) // additional chars
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val parsed = Nip19.parseComponents(uriScheme, type, key, additionalChars)
|
val parsed = Nip19Bech32.parseComponents(uriScheme, type, key, additionalChars)
|
||||||
|
|
||||||
if (parsed != null) {
|
if (parsed != null) {
|
||||||
if (parsed.type == Nip19.Type.USER) {
|
if (parsed.type == Nip19Bech32.Type.USER) {
|
||||||
returningList.add(parsed.hex)
|
returningList.add(parsed.hex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,10 +137,10 @@ open class BaseTextNoteEvent(
|
|||||||
val key = matcher2.group(3) // bech32
|
val key = matcher2.group(3) // bech32
|
||||||
val additionalChars = matcher2.group(4) // additional chars
|
val additionalChars = matcher2.group(4) // additional chars
|
||||||
|
|
||||||
val parsed = Nip19.parseComponents(uriScheme, type, key, additionalChars)
|
val parsed = Nip19Bech32.parseComponents(uriScheme, type, key, additionalChars)
|
||||||
|
|
||||||
if (parsed != null) {
|
if (parsed != null) {
|
||||||
if (parsed.type == Nip19.Type.EVENT || parsed.type == Nip19.Type.ADDRESS || parsed.type == Nip19.Type.NOTE) {
|
if (parsed.type == Nip19Bech32.Type.EVENT || parsed.type == Nip19Bech32.Type.ADDRESS || parsed.type == Nip19Bech32.Type.NOTE) {
|
||||||
citations.add(parsed.hex)
|
citations.add(parsed.hex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import com.vitorpamplona.quartz.crypto.CryptoUtils
|
|||||||
import com.vitorpamplona.quartz.encoders.ATag
|
import com.vitorpamplona.quartz.encoders.ATag
|
||||||
import com.vitorpamplona.quartz.encoders.Hex
|
import com.vitorpamplona.quartz.encoders.Hex
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.encoders.toHexKey
|
import com.vitorpamplona.quartz.encoders.toHexKey
|
||||||
import com.vitorpamplona.quartz.signers.NostrSigner
|
import com.vitorpamplona.quartz.signers.NostrSigner
|
||||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||||
@@ -253,7 +253,7 @@ open class Event(
|
|||||||
return if (this is AddressableEvent) {
|
return if (this is AddressableEvent) {
|
||||||
ATag(kind, pubKey, dTag(), null).toNAddr()
|
ATag(kind, pubKey, dTag(), null).toNAddr()
|
||||||
} else {
|
} else {
|
||||||
Nip19.createNEvent(id, pubKey, kind, null)
|
Nip19Bech32.createNEvent(id, pubKey, kind, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class NIP19ParserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun nAddrParser() {
|
fun nAddrParser() {
|
||||||
val result =
|
val result =
|
||||||
Nip19.uriToRoute(
|
Nip19Bech32.uriToRoute(
|
||||||
"nostr:naddr1qqqqygzxpsj7dqha57pjk5k37gkn6g4nzakewtmqmnwryyhd3jfwlpgxtspsgqqqw4rs3xyxus",
|
"nostr:naddr1qqqqygzxpsj7dqha57pjk5k37gkn6g4nzakewtmqmnwryyhd3jfwlpgxtspsgqqqw4rs3xyxus",
|
||||||
)
|
)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
@@ -39,7 +39,7 @@ class NIP19ParserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun nAddrParser2() {
|
fun nAddrParser2() {
|
||||||
val result =
|
val result =
|
||||||
Nip19.uriToRoute(
|
Nip19Bech32.uriToRoute(
|
||||||
"nostr:naddr1qq8kwatfv3jj6amfwfjkwatpwfjqygxsm6lelvfda7qlg0tud9pfhduysy4vrexj65azqtdk4tr75j6xdspsgqqqw4rsg32ag8",
|
"nostr:naddr1qq8kwatfv3jj6amfwfjkwatpwfjqygxsm6lelvfda7qlg0tud9pfhduysy4vrexj65azqtdk4tr75j6xdspsgqqqw4rsg32ag8",
|
||||||
)
|
)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
@@ -51,10 +51,10 @@ class NIP19ParserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun nAddrParse3() {
|
fun nAddrParse3() {
|
||||||
val result =
|
val result =
|
||||||
Nip19.uriToRoute(
|
Nip19Bech32.uriToRoute(
|
||||||
"naddr1qqyrswtyv5mnjv3sqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hsygx3uczxts4hwue9ayfn7ggq62anzstde2qs749pm9tx2csuthhpjvpsgqqqw4rs8pmj38",
|
"naddr1qqyrswtyv5mnjv3sqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hsygx3uczxts4hwue9ayfn7ggq62anzstde2qs749pm9tx2csuthhpjvpsgqqqw4rs8pmj38",
|
||||||
)
|
)
|
||||||
assertEquals(Nip19.Type.ADDRESS, result?.type)
|
assertEquals(Nip19Bech32.Type.ADDRESS, result?.type)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"30023:d1e60465c2b777325e9133f2100d2bb31416dca810f54a1d95665621c5dee193:89de7920",
|
"30023:d1e60465c2b777325e9133f2100d2bb31416dca810f54a1d95665621c5dee193:89de7920",
|
||||||
result?.hex,
|
result?.hex,
|
||||||
@@ -130,10 +130,10 @@ class NIP19ParserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun nAddrParserPablo() {
|
fun nAddrParserPablo() {
|
||||||
val result =
|
val result =
|
||||||
Nip19.uriToRoute(
|
Nip19Bech32.uriToRoute(
|
||||||
"naddr1qq2hs7p30p6kcunxxamkgcnyd33xxve3veshyq3qyujphdcz69z6jafxpnldae3xtymdekfeatkt3r4qusr3w5krqspqxpqqqpaxjlg805f",
|
"naddr1qq2hs7p30p6kcunxxamkgcnyd33xxve3veshyq3qyujphdcz69z6jafxpnldae3xtymdekfeatkt3r4qusr3w5krqspqxpqqqpaxjlg805f",
|
||||||
)
|
)
|
||||||
assertEquals(Nip19.Type.ADDRESS, result?.type)
|
assertEquals(Nip19Bech32.Type.ADDRESS, result?.type)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"31337:27241bb702d145a975260cfedee6265936dcd939eaecb88ea0e4071752c30402:xx1xulrf7wdbdlbc31far",
|
"31337:27241bb702d145a975260cfedee6265936dcd939eaecb88ea0e4071752c30402:xx1xulrf7wdbdlbc31far",
|
||||||
result?.hex,
|
result?.hex,
|
||||||
@@ -146,10 +146,10 @@ class NIP19ParserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun nAddrParserGizmo() {
|
fun nAddrParserGizmo() {
|
||||||
val result =
|
val result =
|
||||||
Nip19.uriToRoute(
|
Nip19Bech32.uriToRoute(
|
||||||
"naddr1qpqrvvfnvccrzdryxgunzvtxvgukge34xfjnqdpcv9sk2desxgmrscesvserzd3h8ycrywphvg6nsvf58ycnqef3v5mnsvt98pjnqdfs8ypzq3huhccxt6h34eupz3jeynjgjgek8lel2f4adaea0svyk94a3njdqvzqqqr4gudhrkyk",
|
"naddr1qpqrvvfnvccrzdryxgunzvtxvgukge34xfjnqdpcv9sk2desxgmrscesvserzd3h8ycrywphvg6nsvf58ycnqef3v5mnsvt98pjnqdfs8ypzq3huhccxt6h34eupz3jeynjgjgek8lel2f4adaea0svyk94a3njdqvzqqqr4gudhrkyk",
|
||||||
)
|
)
|
||||||
assertEquals(Nip19.Type.ADDRESS, result?.type)
|
assertEquals(Nip19Bech32.Type.ADDRESS, result?.type)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"30023:46fcbe3065eaf1ae7811465924e48923363ff3f526bd6f73d7c184b16bd8ce4d:613f014d2911fb9df52e048aae70268c0d216790287b5814910e1e781e8e0509",
|
"30023:46fcbe3065eaf1ae7811465924e48923363ff3f526bd6f73d7c184b16bd8ce4d:613f014d2911fb9df52e048aae70268c0d216790287b5814910e1e781e8e0509",
|
||||||
result?.hex,
|
result?.hex,
|
||||||
@@ -162,10 +162,10 @@ class NIP19ParserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun nAddrParserGizmo2() {
|
fun nAddrParserGizmo2() {
|
||||||
val result =
|
val result =
|
||||||
Nip19.uriToRoute(
|
Nip19Bech32.uriToRoute(
|
||||||
"naddr1qq9rzd3h8y6nqwf5xyuqygzxljlrqe027xh8sy2xtyjwfzfrxcll8afxh4hh847psjckhkxwf5psgqqqw4rsty50fx",
|
"naddr1qq9rzd3h8y6nqwf5xyuqygzxljlrqe027xh8sy2xtyjwfzfrxcll8afxh4hh847psjckhkxwf5psgqqqw4rsty50fx",
|
||||||
)
|
)
|
||||||
assertEquals(Nip19.Type.ADDRESS, result?.type)
|
assertEquals(Nip19Bech32.Type.ADDRESS, result?.type)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"30023:46fcbe3065eaf1ae7811465924e48923363ff3f526bd6f73d7c184b16bd8ce4d:1679509418",
|
"30023:46fcbe3065eaf1ae7811465924e48923363ff3f526bd6f73d7c184b16bd8ce4d:1679509418",
|
||||||
result?.hex,
|
result?.hex,
|
||||||
@@ -178,8 +178,8 @@ class NIP19ParserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun nEventParserTest() {
|
fun nEventParserTest() {
|
||||||
val result =
|
val result =
|
||||||
Nip19.uriToRoute("nostr:nevent1qqs0tsw8hjacs4fppgdg7f5yhgwwfkyua4xcs3re9wwkpkk2qeu6mhql22rcy")
|
Nip19Bech32.uriToRoute("nostr:nevent1qqs0tsw8hjacs4fppgdg7f5yhgwwfkyua4xcs3re9wwkpkk2qeu6mhql22rcy")
|
||||||
assertEquals(Nip19.Type.EVENT, result?.type)
|
assertEquals(Nip19Bech32.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?.author)
|
||||||
@@ -189,10 +189,10 @@ class NIP19ParserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun nEventParser() {
|
fun nEventParser() {
|
||||||
val result =
|
val result =
|
||||||
Nip19.uriToRoute(
|
Nip19Bech32.uriToRoute(
|
||||||
"nostr:nevent1qqstvrl6wftd8ht4g0vrp6m30tjs6pdxcvk977g769dcvlptkzu4ftqppamhxue69uhkummnw3ezumt0d5pzp78lz8r60568sd2a8dx3wnj6gume02gxaf92vx4fk67qv5kpagt6qvzqqqqqqygqr86c",
|
"nostr:nevent1qqstvrl6wftd8ht4g0vrp6m30tjs6pdxcvk977g769dcvlptkzu4ftqppamhxue69uhkummnw3ezumt0d5pzp78lz8r60568sd2a8dx3wnj6gume02gxaf92vx4fk67qv5kpagt6qvzqqqqqqygqr86c",
|
||||||
)
|
)
|
||||||
assertEquals(Nip19.Type.EVENT, result?.type)
|
assertEquals(Nip19Bech32.Type.EVENT, result?.type)
|
||||||
assertEquals("b60ffa7256d3dd7543d830eb717ae50d05a6c32c5f791ed15b867c2bb0b954ac", result?.hex)
|
assertEquals("b60ffa7256d3dd7543d830eb717ae50d05a6c32c5f791ed15b867c2bb0b954ac", result?.hex)
|
||||||
assertEquals("wss://nostr.mom", result?.relay)
|
assertEquals("wss://nostr.mom", result?.relay)
|
||||||
assertEquals("f8ff11c7a7d3478355d3b4d174e5a473797a906ea4aa61aa9b6bc0652c1ea17a", result?.author)
|
assertEquals("f8ff11c7a7d3478355d3b4d174e5a473797a906ea4aa61aa9b6bc0652c1ea17a", result?.author)
|
||||||
@@ -202,11 +202,11 @@ class NIP19ParserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun nEventParser2() {
|
fun nEventParser2() {
|
||||||
val result =
|
val result =
|
||||||
Nip19.uriToRoute(
|
Nip19Bech32.uriToRoute(
|
||||||
"nostr:nevent1qqsplpuwsgrrmq85rfup6w3w777rxmcmadu590emfx6z4msj2844euqpz3mhxue69uhhyetvv9ujuerpd46hxtnfdupzq3svyhng9ld8sv44950j957j9vchdktj7cxumsep9mvvjthc2pjuqvzqqqqqqye3a70w",
|
"nostr:nevent1qqsplpuwsgrrmq85rfup6w3w777rxmcmadu590emfx6z4msj2844euqpz3mhxue69uhhyetvv9ujuerpd46hxtnfdupzq3svyhng9ld8sv44950j957j9vchdktj7cxumsep9mvvjthc2pjuqvzqqqqqqye3a70w",
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(Nip19.Type.EVENT, result?.type)
|
assertEquals(Nip19Bech32.Type.EVENT, result?.type)
|
||||||
assertEquals("1f878e82063d80f41a781d3a2ef7bc336f1beb7942bf3b49b42aee1251eb5cf0", result?.hex)
|
assertEquals("1f878e82063d80f41a781d3a2ef7bc336f1beb7942bf3b49b42aee1251eb5cf0", result?.hex)
|
||||||
assertEquals("wss://relay.damus.io", result?.relay)
|
assertEquals("wss://relay.damus.io", result?.relay)
|
||||||
assertEquals("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c", result?.author)
|
assertEquals("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c", result?.author)
|
||||||
@@ -216,11 +216,11 @@ class NIP19ParserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun nEventParser3() {
|
fun nEventParser3() {
|
||||||
val result =
|
val result =
|
||||||
Nip19.uriToRoute(
|
Nip19Bech32.uriToRoute(
|
||||||
"nostr:nevent1qqsg6gechd3dhzx38n4z8a2lylzgsmmgeamhmtzz72m9ummsnf0xjfspsdmhxue69uhkummn9ekx7mpvwaehxw309ahx7um5wghx77r5wghxgetk93mhxue69uhhyetvv9ujumn0wd68ytnzvuk8wumn8ghj7mn0wd68ytn9d9h82mny0fmkzmn6d9njuumsv93k2trhwden5te0wfjkccte9ehx7um5wghxyctwvsk8wumn8ghj7un9d3shjtnyv9kh2uewd9hs3kqsdn",
|
"nostr:nevent1qqsg6gechd3dhzx38n4z8a2lylzgsmmgeamhmtzz72m9ummsnf0xjfspsdmhxue69uhkummn9ekx7mpvwaehxw309ahx7um5wghx77r5wghxgetk93mhxue69uhhyetvv9ujumn0wd68ytnzvuk8wumn8ghj7mn0wd68ytn9d9h82mny0fmkzmn6d9njuumsv93k2trhwden5te0wfjkccte9ehx7um5wghxyctwvsk8wumn8ghj7un9d3shjtnyv9kh2uewd9hs3kqsdn",
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(Nip19.Type.EVENT, result?.type)
|
assertEquals(Nip19Bech32.Type.EVENT, result?.type)
|
||||||
assertEquals("8d2338bb62db88d13cea23f55f27c4886f68cf777dac42f2b65e6f709a5e6926", result?.hex)
|
assertEquals("8d2338bb62db88d13cea23f55f27c4886f68cf777dac42f2b65e6f709a5e6926", result?.hex)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"wss://nos.lol,wss://nostr.oxtr.dev,wss://relay.nostr.bg,wss://nostr.einundzwanzig.space,wss://relay.nostr.band,wss://relay.damus.io",
|
"wss://nos.lol,wss://nostr.oxtr.dev,wss://relay.nostr.bg,wss://nostr.einundzwanzig.space,wss://relay.nostr.band,wss://relay.damus.io",
|
||||||
@@ -231,11 +231,11 @@ class NIP19ParserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun nEventParserInvalidChecksum() {
|
fun nEventParserInvalidChecksum() {
|
||||||
val result =
|
val result =
|
||||||
Nip19.uriToRoute(
|
Nip19Bech32.uriToRoute(
|
||||||
"nostr:nevent1qqsyxq8v0730nz38dupnjzp5jegkyz4gu2ptwcps4v32hjnrap0q0espz3mhxue69uhhyetvv9ujuerpd46hxtnfdupzq3svyhng9ld8sv44950j957j9vchdktj7cxumsep9mvvjthc2pjuqvzqqqqqqyn3t9gj",
|
"nostr:nevent1qqsyxq8v0730nz38dupnjzp5jegkyz4gu2ptwcps4v32hjnrap0q0espz3mhxue69uhhyetvv9ujuerpd46hxtnfdupzq3svyhng9ld8sv44950j957j9vchdktj7cxumsep9mvvjthc2pjuqvzqqqqqqyn3t9gj",
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(Nip19.Type.EVENT, result?.type)
|
assertEquals(Nip19Bech32.Type.EVENT, result?.type)
|
||||||
assertEquals("4300ec7fa2f98a276f033908349651620aa8e282b76030ab22abca63e85e07e6", result?.hex)
|
assertEquals("4300ec7fa2f98a276f033908349651620aa8e282b76030ab22abca63e85e07e6", result?.hex)
|
||||||
assertEquals("wss://relay.damus.io", result?.relay)
|
assertEquals("wss://relay.damus.io", result?.relay)
|
||||||
assertEquals("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c", result?.author)
|
assertEquals("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c", result?.author)
|
||||||
@@ -245,7 +245,7 @@ class NIP19ParserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun nEventFormatter() {
|
fun nEventFormatter() {
|
||||||
val nevent =
|
val nevent =
|
||||||
Nip19.createNEvent(
|
Nip19Bech32.createNEvent(
|
||||||
"f5c1c7bcbb8855210a1a8f2684ba1ce4d89ced4d8844792b9d60daca0679addc",
|
"f5c1c7bcbb8855210a1a8f2684ba1ce4d89ced4d8844792b9d60daca0679addc",
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
@@ -257,7 +257,7 @@ class NIP19ParserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun nEventFormatterWithExtraInfo() {
|
fun nEventFormatterWithExtraInfo() {
|
||||||
val nevent =
|
val nevent =
|
||||||
Nip19.createNEvent(
|
Nip19Bech32.createNEvent(
|
||||||
"f5c1c7bcbb8855210a1a8f2684ba1ce4d89ced4d8844792b9d60daca0679addc",
|
"f5c1c7bcbb8855210a1a8f2684ba1ce4d89ced4d8844792b9d60daca0679addc",
|
||||||
"7fa56f5d6962ab1e3cd424e758c3002b8665f7b0d8dcee9fe9e288d7751ac194",
|
"7fa56f5d6962ab1e3cd424e758c3002b8665f7b0d8dcee9fe9e288d7751ac194",
|
||||||
40,
|
40,
|
||||||
@@ -272,7 +272,7 @@ class NIP19ParserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun nEventFormatterWithFullInfo() {
|
fun nEventFormatterWithFullInfo() {
|
||||||
val nevent =
|
val nevent =
|
||||||
Nip19.createNEvent(
|
Nip19Bech32.createNEvent(
|
||||||
"1f878e82063d80f41a781d3a2ef7bc336f1beb7942bf3b49b42aee1251eb5cf0",
|
"1f878e82063d80f41a781d3a2ef7bc336f1beb7942bf3b49b42aee1251eb5cf0",
|
||||||
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
|
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
|
||||||
1,
|
1,
|
||||||
|
|||||||
+15
-15
@@ -24,17 +24,17 @@ import org.junit.Assert
|
|||||||
import org.junit.Ignore
|
import org.junit.Ignore
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class Nip19Test {
|
class Nip19Bech32Test {
|
||||||
@Test()
|
@Test()
|
||||||
fun uri_to_route_null() {
|
fun uri_to_route_null() {
|
||||||
val actual = Nip19.uriToRoute(null)
|
val actual = Nip19Bech32.uriToRoute(null)
|
||||||
|
|
||||||
Assert.assertEquals(null, actual)
|
Assert.assertEquals(null, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test()
|
@Test()
|
||||||
fun uri_to_route_unknown() {
|
fun uri_to_route_unknown() {
|
||||||
val actual = Nip19.uriToRoute("nostr:unknown")
|
val actual = Nip19Bech32.uriToRoute("nostr:unknown")
|
||||||
|
|
||||||
Assert.assertEquals(null, actual)
|
Assert.assertEquals(null, actual)
|
||||||
}
|
}
|
||||||
@@ -42,9 +42,9 @@ class Nip19Test {
|
|||||||
@Test()
|
@Test()
|
||||||
fun uri_to_route_npub() {
|
fun uri_to_route_npub() {
|
||||||
val actual =
|
val actual =
|
||||||
Nip19.uriToRoute("nostr:npub1hv7k2s755n697sptva8vkh9jz40lzfzklnwj6ekewfmxp5crwdjs27007y")
|
Nip19Bech32.uriToRoute("nostr:npub1hv7k2s755n697sptva8vkh9jz40lzfzklnwj6ekewfmxp5crwdjs27007y")
|
||||||
|
|
||||||
Assert.assertEquals(Nip19.Type.USER, actual?.type)
|
Assert.assertEquals(Nip19Bech32.Type.USER, actual?.type)
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"bb3d6543d4a4f45f402b674ecb5cb2155ff12456fcdd2d66d9727660d3037365",
|
"bb3d6543d4a4f45f402b674ecb5cb2155ff12456fcdd2d66d9727660d3037365",
|
||||||
actual?.hex,
|
actual?.hex,
|
||||||
@@ -54,9 +54,9 @@ class Nip19Test {
|
|||||||
@Test()
|
@Test()
|
||||||
fun uri_to_route_note() {
|
fun uri_to_route_note() {
|
||||||
val actual =
|
val actual =
|
||||||
Nip19.uriToRoute("nostr:note1stqea6wmwezg9x6yyr6qkukw95ewtdukyaztycws65l8wppjmtpscawevv")
|
Nip19Bech32.uriToRoute("nostr:note1stqea6wmwezg9x6yyr6qkukw95ewtdukyaztycws65l8wppjmtpscawevv")
|
||||||
|
|
||||||
Assert.assertEquals(Nip19.Type.NOTE, actual?.type)
|
Assert.assertEquals(Nip19Bech32.Type.NOTE, actual?.type)
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"82c19ee9db7644829b4420f40b72ce2d32e5b7962744b261d0d53e770432dac3",
|
"82c19ee9db7644829b4420f40b72ce2d32e5b7962744b261d0d53e770432dac3",
|
||||||
actual?.hex,
|
actual?.hex,
|
||||||
@@ -66,36 +66,36 @@ class Nip19Test {
|
|||||||
@Ignore("Test 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 = Nip19Bech32.uriToRoute("nostr:nprofile")
|
||||||
|
|
||||||
Assert.assertEquals(Nip19.Type.USER, actual?.type)
|
Assert.assertEquals(Nip19Bech32.Type.USER, actual?.type)
|
||||||
Assert.assertEquals("*", actual?.hex)
|
Assert.assertEquals("*", actual?.hex)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("Test 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 = Nip19Bech32.uriToRoute("nostr:nevent")
|
||||||
|
|
||||||
Assert.assertEquals(Nip19.Type.USER, actual?.type)
|
Assert.assertEquals(Nip19Bech32.Type.USER, actual?.type)
|
||||||
Assert.assertEquals("*", actual?.hex)
|
Assert.assertEquals("*", actual?.hex)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("Test 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 = Nip19Bech32.uriToRoute("nostr:nrelay")
|
||||||
|
|
||||||
Assert.assertEquals(Nip19.Type.RELAY, actual?.type)
|
Assert.assertEquals(Nip19Bech32.Type.RELAY, actual?.type)
|
||||||
Assert.assertEquals("*", actual?.hex)
|
Assert.assertEquals("*", actual?.hex)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("Test 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 = Nip19Bech32.uriToRoute("nostr:naddr")
|
||||||
|
|
||||||
Assert.assertEquals(Nip19.Type.ADDRESS, actual?.type)
|
Assert.assertEquals(Nip19Bech32.Type.ADDRESS, actual?.type)
|
||||||
Assert.assertEquals("*", actual?.hex)
|
Assert.assertEquals("*", actual?.hex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user