mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-17 21:31:57 +01:00
Reverses ATag Generalization (It just made things more complicated)
This commit is contained in:
parent
9e1a2bb1e4
commit
2de4bb1adc
@ -55,7 +55,7 @@ class BlossomServersEvent(
|
||||
|
||||
fun createAddressATag(pubKey: HexKey): ATag = ATag(KIND, pubKey, FIXED_D_TAG, null)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey): String = ATag.assembleATagId(KIND, pubKey, FIXED_D_TAG)
|
||||
fun createAddressTag(pubKey: HexKey): String = Address.assemble(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun createTagArray(servers: List<String>): Array<Array<String>> =
|
||||
servers
|
||||
|
@ -107,7 +107,7 @@ class PrivateOutboxRelayListEvent(
|
||||
|
||||
fun createAddressATag(pubKey: HexKey): ATag = ATag(KIND, pubKey, FIXED_D_TAG, null)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey): String = ATag.assembleATagId(KIND, pubKey, FIXED_D_TAG)
|
||||
fun createAddressTag(pubKey: HexKey): String = Address.assemble(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun encryptTags(
|
||||
privateTags: Array<Array<String>>? = null,
|
||||
|
@ -26,6 +26,7 @@ import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.dTags.dTag
|
||||
import com.vitorpamplona.quartz.nip22Comments.RootScope
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
@ -43,16 +44,16 @@ class InteractiveStoryPrologueEvent(
|
||||
const val KIND = 30296
|
||||
const val ALT = "The prologue of an interactive story called "
|
||||
|
||||
fun createAddress(
|
||||
pubKey: HexKey,
|
||||
dtag: String,
|
||||
): String = Address.assemble(KIND, pubKey, dtag)
|
||||
|
||||
fun createAddressATag(
|
||||
pubKey: HexKey,
|
||||
dtag: String,
|
||||
): ATag = ATag(KIND, pubKey, dtag, null)
|
||||
|
||||
fun createAddressTag(
|
||||
pubKey: HexKey,
|
||||
dtag: String,
|
||||
): String = ATag.assembleATagId(KIND, pubKey, dtag)
|
||||
|
||||
fun build(
|
||||
baseId: String,
|
||||
title: String,
|
||||
|
@ -78,7 +78,7 @@ class InteractiveStoryReadingStateEvent(
|
||||
fun createAddressTag(
|
||||
pubKey: HexKey,
|
||||
dtag: String,
|
||||
): String = ATag.assembleATagId(KIND, pubKey, dtag)
|
||||
): String = Address.assemble(KIND, pubKey, dtag)
|
||||
|
||||
fun update(
|
||||
base: InteractiveStoryReadingStateEvent,
|
||||
|
@ -25,6 +25,7 @@ import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.dTags.dTag
|
||||
import com.vitorpamplona.quartz.nip22Comments.RootScope
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
@ -50,7 +51,7 @@ class InteractiveStorySceneEvent(
|
||||
fun createAddressTag(
|
||||
pubKey: HexKey,
|
||||
dtag: String,
|
||||
): String = ATag.assembleATagId(KIND, pubKey, dtag)
|
||||
): String = Address.assemble(KIND, pubKey, dtag)
|
||||
|
||||
fun build(
|
||||
baseId: String,
|
||||
|
@ -25,6 +25,7 @@ import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.match
|
||||
import com.vitorpamplona.quartz.nip01Core.core.name
|
||||
import com.vitorpamplona.quartz.nip01Core.core.value
|
||||
import com.vitorpamplona.quartz.utils.arrayOfNotNull
|
||||
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
|
||||
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
|
||||
import com.vitorpamplona.quartz.utils.removeTrailingNullsAndEmptyOthers
|
||||
@ -45,7 +46,7 @@ data class ATag(
|
||||
dTag.bytesUsedInMemory() +
|
||||
(relay?.bytesUsedInMemory() ?: 0)
|
||||
|
||||
fun toTag() = assembleATagId(kind, pubKeyHex, dTag)
|
||||
fun toTag() = Address.assemble(kind, pubKeyHex, dTag)
|
||||
|
||||
fun toATagArray() = removeTrailingNullsAndEmptyOthers(TAG_NAME, toTag(), relay)
|
||||
|
||||
@ -65,68 +66,73 @@ data class ATag(
|
||||
fun isTagged(
|
||||
tag: Array<String>,
|
||||
addressId: String,
|
||||
) = ATagParser.isTagged(tag, TAG_NAME, addressId)
|
||||
) = tag.size >= TAG_SIZE && tag[0] == TAG_NAME && tag[1] == addressId
|
||||
|
||||
@JvmStatic
|
||||
fun isTagged(
|
||||
tag: Array<String>,
|
||||
address: ATag,
|
||||
) = ATagParser.isTagged(tag, TAG_NAME, address.toTag())
|
||||
) = tag.size >= TAG_SIZE && tag[0] == TAG_NAME && tag[1] == address.toTag()
|
||||
|
||||
@JvmStatic
|
||||
fun isIn(
|
||||
tag: Array<String>,
|
||||
addressIds: Set<String>,
|
||||
) = ATagParser.isIn(tag, TAG_NAME, addressIds)
|
||||
) = tag.size >= TAG_SIZE && tag[0] == TAG_NAME && tag[1] in addressIds
|
||||
|
||||
@JvmStatic
|
||||
fun isTaggedWithKind(
|
||||
tag: Array<String>,
|
||||
kind: String,
|
||||
) = ATagParser.isTaggedWithKind(tag, TAG_NAME, kind)
|
||||
|
||||
@JvmStatic
|
||||
fun assembleATagId(
|
||||
kind: Int,
|
||||
pubKey: HexKey,
|
||||
dTag: String,
|
||||
) = ATagParser.assembleATagId(kind, pubKey, dTag)
|
||||
) = tag.size >= TAG_SIZE && tag[0] == TAG_NAME && Address.isOfKind(tag[1], kind)
|
||||
|
||||
@JvmStatic
|
||||
fun parseIfOfKind(
|
||||
tag: Array<String>,
|
||||
kind: String,
|
||||
) = ATagParser.parseIfOfKind(tag, TAG_NAME, kind)
|
||||
) = if (isTaggedWithKind(tag, kind)) parse(tag[1], tag.getOrNull(2)) else null
|
||||
|
||||
@JvmStatic
|
||||
fun parseIfIsIn(
|
||||
tag: Array<String>,
|
||||
addresses: Set<String>,
|
||||
) = ATagParser.parseIfIsIn(tag, TAG_NAME, addresses)
|
||||
) = if (isIn(tag, addresses)) parse(tag[1], tag.getOrNull(2)) else null
|
||||
|
||||
@JvmStatic
|
||||
fun parse(
|
||||
aTagId: String,
|
||||
relay: String?,
|
||||
) = ATagParser.parse(aTagId, relay)
|
||||
) = Address.parse(aTagId)?.let { ATag(it.kind, it.pubKeyHex, it.dTag, relay) }
|
||||
|
||||
@JvmStatic
|
||||
fun parse(tag: Array<String>) = ATagParser.parse(TAG_NAME, tag)
|
||||
fun parse(tag: Array<String>): ATag? {
|
||||
if (tag.size < TAG_SIZE || tag[0] != TAG_NAME) return null
|
||||
return parse(tag[1], tag.getOrNull(2))
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun parseValidAddress(tag: Array<String>) = ATagParser.parseValidAddress(TAG_NAME, tag)
|
||||
fun parseValidAddress(tag: Array<String>): String? {
|
||||
if (tag.size < TAG_SIZE || tag[0] != TAG_NAME) return null
|
||||
return Address.parse(tag[1])?.toValue()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun parseAddress(tag: Array<String>) = ATagParser.parseAddress(TAG_NAME, tag)
|
||||
fun parseAddress(tag: Array<String>): Address? {
|
||||
if (tag.size < TAG_SIZE || tag[0] != TAG_NAME) return null
|
||||
return Address.parse(tag[1])
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun parseAddressId(tag: Array<String>) = ATagParser.parseAddressId(TAG_NAME, tag)
|
||||
fun parseAddressId(tag: Array<String>): String? {
|
||||
if (tag.size < TAG_SIZE || tag[0] != TAG_NAME) return null
|
||||
return tag[1]
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun assemble(
|
||||
aTagId: HexKey,
|
||||
relay: String?,
|
||||
) = ATagParser.assemble(TAG_NAME, aTagId, relay)
|
||||
) = arrayOfNotNull(TAG_NAME, aTagId, relay)
|
||||
|
||||
@JvmStatic
|
||||
fun assemble(
|
||||
@ -134,6 +140,6 @@ data class ATag(
|
||||
pubKey: String,
|
||||
dTag: String,
|
||||
relay: String?,
|
||||
) = ATagParser.assemble(TAG_NAME, kind, pubKey, dTag, relay)
|
||||
) = assemble(Address.assemble(kind, pubKey, dTag), relay)
|
||||
}
|
||||
}
|
||||
|
@ -1,132 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2024 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.tags.addressables
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.isNotName
|
||||
import com.vitorpamplona.quartz.nip01Core.core.match
|
||||
import com.vitorpamplona.quartz.utils.arrayOfNotNull
|
||||
|
||||
class ATagParser {
|
||||
companion object {
|
||||
const val TAG_SIZE = 2
|
||||
|
||||
@JvmStatic
|
||||
fun isTagged(
|
||||
tag: Array<String>,
|
||||
tagName: String,
|
||||
addressId: String,
|
||||
) = tag.match(tagName, addressId, TAG_SIZE)
|
||||
|
||||
@JvmStatic
|
||||
fun isIn(
|
||||
tag: Array<String>,
|
||||
tagName: String,
|
||||
addressIds: Set<String>,
|
||||
) = tag.match(tagName, addressIds, TAG_SIZE)
|
||||
|
||||
@JvmStatic
|
||||
fun isTaggedWithKind(
|
||||
tag: Array<String>,
|
||||
tagName: String,
|
||||
kind: String,
|
||||
) = tag.match(tagName, TAG_SIZE) && Address.isOfKind(tag[1], kind)
|
||||
|
||||
@JvmStatic
|
||||
fun assembleATagId(
|
||||
kind: Int,
|
||||
pubKeyHex: HexKey,
|
||||
dTag: String,
|
||||
) = Address.assemble(kind, pubKeyHex, dTag)
|
||||
|
||||
@JvmStatic
|
||||
fun parseIfOfKind(
|
||||
tag: Array<String>,
|
||||
tagName: String,
|
||||
kind: String,
|
||||
) = if (isTaggedWithKind(tag, tagName, kind)) parse(tag[1], tag.getOrNull(2)) else null
|
||||
|
||||
@JvmStatic
|
||||
fun parseIfIsIn(
|
||||
tag: Array<String>,
|
||||
tagName: String,
|
||||
addresses: Set<String>,
|
||||
) = if (isIn(tag, tagName, addresses)) parse(tag[1], tag.getOrNull(2)) else null
|
||||
|
||||
@JvmStatic
|
||||
fun parse(
|
||||
aTagId: String,
|
||||
relay: String?,
|
||||
) = Address.parse(aTagId)?.let { ATag(it.kind, it.pubKeyHex, it.dTag, relay) }
|
||||
|
||||
@JvmStatic
|
||||
fun parse(
|
||||
tagName: String,
|
||||
tag: Array<String>,
|
||||
): ATag? {
|
||||
if (tag.isNotName(tagName, TAG_SIZE)) return null
|
||||
return parse(tag[1], tag.getOrNull(2))
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun parseValidAddress(
|
||||
tagName: String,
|
||||
tag: Array<String>,
|
||||
): String? {
|
||||
if (tag.isNotName(tagName, TAG_SIZE)) return null
|
||||
return Address.parse(tag[1])?.toValue()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun parseAddress(
|
||||
tagName: String,
|
||||
tag: Array<String>,
|
||||
): Address? {
|
||||
if (tag.isNotName(tagName, TAG_SIZE)) return null
|
||||
return Address.parse(tag[1])
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun parseAddressId(
|
||||
tagName: String,
|
||||
tag: Array<String>,
|
||||
): String? {
|
||||
if (tag.isNotName(tagName, TAG_SIZE)) return null
|
||||
return tag[1]
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun assemble(
|
||||
tagName: String,
|
||||
aTagId: HexKey,
|
||||
relay: String?,
|
||||
) = arrayOfNotNull(tagName, aTagId, relay)
|
||||
|
||||
@JvmStatic
|
||||
fun assemble(
|
||||
tagName: String,
|
||||
kind: Int,
|
||||
pubKeyHex: String,
|
||||
dTag: String,
|
||||
relay: String?,
|
||||
) = arrayOfNotNull(tagName, assembleATagId(kind, pubKeyHex, dTag), relay)
|
||||
}
|
||||
}
|
@ -55,7 +55,7 @@ class ChatMessageRelayListEvent(
|
||||
|
||||
fun createAddressATag(pubKey: HexKey): ATag = ATag(KIND, pubKey, FIXED_D_TAG, null)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey): String = ATag.assembleATagId(KIND, pubKey, FIXED_D_TAG)
|
||||
fun createAddressTag(pubKey: HexKey): String = Address.assemble(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun createTagArray(relays: List<String>): Array<Array<String>> =
|
||||
relays
|
||||
|
@ -26,7 +26,7 @@ import addString
|
||||
import addStringIfNotNull
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip19Bech32.TlvTypes
|
||||
import com.vitorpamplona.quartz.nip19Bech32.bech32.bechToBytes
|
||||
import com.vitorpamplona.quartz.nip19Bech32.tlv.Tlv
|
||||
@ -40,7 +40,7 @@ data class NAddress(
|
||||
val dTag: String,
|
||||
val relay: List<String>,
|
||||
) : Entity {
|
||||
fun aTag(): String = ATag.assembleATagId(kind, author, dTag)
|
||||
fun aTag(): String = Address.assemble(kind, author, dTag)
|
||||
|
||||
companion object {
|
||||
fun parse(naddr: String): NAddress? {
|
||||
|
@ -27,7 +27,6 @@ import com.vitorpamplona.quartz.nip01Core.core.BaseReplaceableEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventUpdate
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.taggedATags
|
||||
import com.vitorpamplona.quartz.nip30CustomEmoji.pack.EmojiPackEvent
|
||||
@ -52,7 +51,7 @@ class EmojiPackSelectionEvent(
|
||||
|
||||
fun createAddress(pubKey: HexKey) = Address(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey) = ATag.assembleATagId(KIND, pubKey, FIXED_D_TAG)
|
||||
fun createAddressTag(pubKey: HexKey) = Address.assemble(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun add(
|
||||
currentSelection: EmojiPackSelectionEvent,
|
||||
|
@ -27,7 +27,7 @@ import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.BaseAddressableEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
|
||||
import com.vitorpamplona.quartz.nip22Comments.CommentEvent
|
||||
import com.vitorpamplona.quartz.nip28PublicChat.message.ChannelMessageEvent
|
||||
@ -125,7 +125,7 @@ class DraftEvent(
|
||||
fun createAddressTag(
|
||||
pubKey: HexKey,
|
||||
dTag: String,
|
||||
): String = ATag.assembleATagId(KIND, pubKey, dTag)
|
||||
): String = Address.assemble(KIND, pubKey, dTag)
|
||||
|
||||
fun create(
|
||||
dTag: String,
|
||||
|
@ -55,7 +55,7 @@ class SearchRelayListEvent(
|
||||
|
||||
fun createAddressATag(pubKey: HexKey): ATag = ATag(KIND, pubKey, FIXED_D_TAG, null)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey): String = ATag.assembleATagId(KIND, pubKey, FIXED_D_TAG)
|
||||
fun createAddressTag(pubKey: HexKey): String = Address.assemble(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun createTagArray(relays: List<String>): Array<Array<String>> =
|
||||
relays
|
||||
|
@ -90,7 +90,7 @@ class AdvertisedRelayListEvent(
|
||||
|
||||
fun createAddressATag(pubKey: HexKey): ATag = ATag(KIND, pubKey, FIXED_D_TAG, null)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey): String = ATag.assembleATagId(KIND, pubKey, FIXED_D_TAG)
|
||||
fun createAddressTag(pubKey: HexKey): String = Address.assemble(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun updateRelayList(
|
||||
earlierVersion: AdvertisedRelayListEvent,
|
||||
|
@ -50,7 +50,7 @@ class FileServersEvent(
|
||||
|
||||
fun createAddressATag(pubKey: HexKey): ATag = ATag(KIND, pubKey, FIXED_D_TAG, null)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey): String = ATag.assembleATagId(KIND, pubKey, FIXED_D_TAG)
|
||||
fun createAddressTag(pubKey: HexKey): String = Address.assemble(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun replaceServers(
|
||||
earlierVersion: FileServersEvent,
|
||||
|
Loading…
x
Reference in New Issue
Block a user