mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-26 17:26:17 +02:00
Moves Bech32 encoders to Bech32 utils
This commit is contained in:
@@ -7,6 +7,7 @@ import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
|||||||
import com.vitorpamplona.amethyst.service.model.ATag
|
import com.vitorpamplona.amethyst.service.model.ATag
|
||||||
import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent
|
import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.LiveActivitiesEvent
|
import com.vitorpamplona.amethyst.service.model.LiveActivitiesEvent
|
||||||
|
import com.vitorpamplona.amethyst.service.toNote
|
||||||
import com.vitorpamplona.amethyst.ui.components.BundledUpdate
|
import com.vitorpamplona.amethyst.ui.components.BundledUpdate
|
||||||
import com.vitorpamplona.amethyst.ui.note.toShortenHex
|
import com.vitorpamplona.amethyst.ui.note.toShortenHex
|
||||||
import fr.acinq.secp256k1.Hex
|
import fr.acinq.secp256k1.Hex
|
||||||
|
@@ -11,6 +11,7 @@ import com.vitorpamplona.amethyst.service.model.*
|
|||||||
import com.vitorpamplona.amethyst.service.nip19.Nip19
|
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.service.toNote
|
||||||
import com.vitorpamplona.amethyst.ui.actions.ImmutableListOfLists
|
import com.vitorpamplona.amethyst.ui.actions.ImmutableListOfLists
|
||||||
import com.vitorpamplona.amethyst.ui.actions.updated
|
import com.vitorpamplona.amethyst.ui.actions.updated
|
||||||
import com.vitorpamplona.amethyst.ui.components.BundledUpdate
|
import com.vitorpamplona.amethyst.ui.components.BundledUpdate
|
||||||
|
@@ -201,6 +201,10 @@ object Bech32 {
|
|||||||
|
|
||||||
fun ByteArray.toNsec() = Bech32.encodeBytes(hrp = "nsec", this, Bech32.Encoding.Bech32)
|
fun ByteArray.toNsec() = Bech32.encodeBytes(hrp = "nsec", this, Bech32.Encoding.Bech32)
|
||||||
fun ByteArray.toNpub() = Bech32.encodeBytes(hrp = "npub", this, Bech32.Encoding.Bech32)
|
fun ByteArray.toNpub() = Bech32.encodeBytes(hrp = "npub", this, Bech32.Encoding.Bech32)
|
||||||
|
fun ByteArray.toNote() = Bech32.encodeBytes(hrp = "note", this, Bech32.Encoding.Bech32)
|
||||||
|
fun ByteArray.toNEvent() = Bech32.encodeBytes(hrp = "nevent", this, Bech32.Encoding.Bech32)
|
||||||
|
fun ByteArray.toNAddress() = Bech32.encodeBytes(hrp = "naddr", this, Bech32.Encoding.Bech32)
|
||||||
|
fun ByteArray.toLnUrl() = Bech32.encodeBytes(hrp = "lnurl", this, Bech32.Encoding.Bech32)
|
||||||
|
|
||||||
fun String.bechToBytes(hrp: String? = null): ByteArray {
|
fun String.bechToBytes(hrp: String? = null): ByteArray {
|
||||||
val decodedForm = Bech32.decodeBytes(this)
|
val decodedForm = Bech32.decodeBytes(this)
|
||||||
|
@@ -5,6 +5,7 @@ import com.vitorpamplona.amethyst.BuildConfig
|
|||||||
import com.vitorpamplona.amethyst.service.Bech32
|
import com.vitorpamplona.amethyst.service.Bech32
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClient
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
|
import com.vitorpamplona.amethyst.service.toLnUrl
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
@@ -131,7 +132,7 @@ class LightningAddressResolver() {
|
|||||||
fetchLightningAddressJson(
|
fetchLightningAddressJson(
|
||||||
lnaddress,
|
lnaddress,
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
onSuccess(Bech32.encodeBytes("lnurl", it.toByteArray(), Bech32.Encoding.Bech32))
|
onSuccess(it.toByteArray().toLnUrl())
|
||||||
},
|
},
|
||||||
onError = onError
|
onError = onError
|
||||||
)
|
)
|
||||||
|
@@ -4,10 +4,10 @@ import android.util.Log
|
|||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import com.vitorpamplona.amethyst.model.hexToByteArray
|
import com.vitorpamplona.amethyst.model.hexToByteArray
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Bech32
|
|
||||||
import com.vitorpamplona.amethyst.service.bechToBytes
|
import com.vitorpamplona.amethyst.service.bechToBytes
|
||||||
import com.vitorpamplona.amethyst.service.nip19.Tlv
|
import com.vitorpamplona.amethyst.service.nip19.Tlv
|
||||||
import com.vitorpamplona.amethyst.service.toByteArray
|
import com.vitorpamplona.amethyst.service.toByteArray
|
||||||
|
import com.vitorpamplona.amethyst.service.toNAddress
|
||||||
import fr.acinq.secp256k1.Hex
|
import fr.acinq.secp256k1.Hex
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -30,7 +30,7 @@ data class ATag(val kind: Int, val pubKeyHex: String, val dTag: String, val rela
|
|||||||
byteArrayOf(Tlv.Type.AUTHOR.id, author.size.toByte()) + author +
|
byteArrayOf(Tlv.Type.AUTHOR.id, author.size.toByte()) + author +
|
||||||
byteArrayOf(Tlv.Type.KIND.id, kind.size.toByte()) + kind
|
byteArrayOf(Tlv.Type.KIND.id, kind.size.toByte()) + kind
|
||||||
|
|
||||||
return Bech32.encodeBytes(hrp = "naddr", fullArray, Bech32.Encoding.Bech32)
|
return fullArray.toNAddress()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@@ -4,9 +4,9 @@ import android.util.Log
|
|||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import com.vitorpamplona.amethyst.model.hexToByteArray
|
import com.vitorpamplona.amethyst.model.hexToByteArray
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Bech32
|
|
||||||
import com.vitorpamplona.amethyst.service.bechToBytes
|
import com.vitorpamplona.amethyst.service.bechToBytes
|
||||||
import com.vitorpamplona.amethyst.service.toByteArray
|
import com.vitorpamplona.amethyst.service.toByteArray
|
||||||
|
import com.vitorpamplona.amethyst.service.toNEvent
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
object Nip19 {
|
object Nip19 {
|
||||||
@@ -167,6 +167,6 @@ object Nip19 {
|
|||||||
fullArray = fullArray + byteArrayOf(Tlv.Type.KIND.id, kind.size.toByte()) + kind
|
fullArray = fullArray + byteArrayOf(Tlv.Type.KIND.id, kind.size.toByte()) + kind
|
||||||
}
|
}
|
||||||
|
|
||||||
return Bech32.encodeBytes(hrp = "nevent", fullArray, Bech32.Encoding.Bech32)
|
return fullArray.toNEvent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user