Deletes experimental serializer on NIP-01

Moves classes to the appropriate packages on NIP-01
Adds a PoW miner to quartz.
Adds a PoW commit evaluator as a bytearray of the ID
This commit is contained in:
Vitor Pamplona
2025-02-18 17:47:34 -05:00
parent bcb3838e85
commit 9689acb5f3
275 changed files with 803 additions and 654 deletions
@@ -21,17 +21,17 @@
package com.vitorpamplona.quartz.bloom
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.crypto.Nip01
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
import com.vitorpamplona.quartz.utils.RandomInstance
import com.vitorpamplona.quartz.utils.sha256.Sha256Hasher
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertFalse
import junit.framework.TestCase.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import java.math.BigInteger
import java.security.MessageDigest
import java.util.Base64
import java.util.BitSet
import java.util.concurrent.locks.ReentrantReadWriteLock
@@ -44,7 +44,7 @@ class BloomFilter(
private val bits: BitSet = BitSet(size),
private val salt: ByteArray = RandomInstance.bytes(8),
) {
private val hash = MessageDigest.getInstance("SHA-256")
private val hash = Sha256Hasher()
private val lock = ReentrantReadWriteLock()
fun add(value: HexKey) = add(value.hexToByteArray())
@@ -83,7 +83,7 @@ class BloomFilter(
fun hash(
seed: Int,
value: ByteArray,
) = BigInteger(1, hash.digest(value + salt + seed.toByte()))
) = BigInteger(1, hash.hash(value + salt + seed.toByte()))
.remainder(BigInteger.valueOf(size.toLong()))
.toInt()
@@ -21,9 +21,11 @@
package com.vitorpamplona.quartz.nip01Core
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.Nip01
import com.vitorpamplona.quartz.utils.Secp256k1Instance
import com.vitorpamplona.quartz.utils.sha256
import com.vitorpamplona.quartz.utils.sha256.sha256
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertTrue
@@ -21,8 +21,8 @@
package com.vitorpamplona.quartz.nip01Core.crypto
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@@ -20,9 +20,9 @@
*/
package com.vitorpamplona.quartz.nip04Dm
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.Nip01
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.nip04Dm.crypto.EncryptedInfo
import com.vitorpamplona.quartz.nip04Dm.crypto.Encryption
import junit.framework.TestCase.assertEquals
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.nip06KeyDerivation
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import junit.framework.TestCase.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@@ -23,7 +23,7 @@ package com.vitorpamplona.quartz.nip06KeyDerivation
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.utils.Hex
import com.vitorpamplona.quartz.utils.RandomInstance
import junit.framework.TestCase.assertEquals
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.nip06KeyDerivation
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import junit.framework.TestCase.assertEquals
import org.junit.Ignore
import org.junit.Test
@@ -0,0 +1,68 @@
/**
* 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.nip13Pow
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
import com.vitorpamplona.quartz.nip13Pow.miner.PoWMiner
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class PoWMinerTest {
val baseTemplate =
EventTemplate<TextNoteEvent>(
1683596206,
TextNoteEvent.KIND,
arrayOf(
arrayOf("e", "27ac621d7dc4a932e1a79f984308e7d20656dd6fddb2ce9cdfcb6a67b9a7bcc3", "", "root"),
arrayOf("e", "be7245af96210a0dd048cab4ad38e52dbd6c09a53ea21a7edb6be8898e5727cc", "", "reply"),
arrayOf("p", "22aa81510ee63fe2b16cae16e0921f78e9ba9882e2868e7e63ad6d08ae9b5954"),
arrayOf("p", "22aa81510ee63fe2b16cae16e0921f78e9ba9882e2868e7e63ad6d08ae9b5954"),
arrayOf("p", "3f770d65d3a764a9c5cb503ae123e62ec7598ad035d836e2a810f3877a745b24"),
arrayOf("p", "ec4d241c334311b3a304433ee3442be29d0e88e7ec19b85edf2bba29b93565e2"),
arrayOf("p", "0fe0b18b4dbf0e0aa40fcd47209b2a49b3431fc453b460efcf45ca0bd16bd6ac"),
arrayOf("p", "8c0da4862130283ff9e67d889df264177a508974e2feb96de139804ea66d6168"),
arrayOf("p", "63fe6318dc58583cfe16810f86dd09e18bfd76aabc24a0081ce2856f330504ed"),
arrayOf("p", "4523be58d395b1b196a9b8c82b038b6895cb02b683d0c253a955068dba1facd0"),
arrayOf("p", "460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c"),
),
"Astral:\n\nhttps://void.cat/d/A5Fba5B1bcxwEmeyoD9nBs.webp\n\nIris:\n\nhttps://void.cat/d/44hTcVvhRps6xYYs99QsqA.webp\n\nSnort:\n\nhttps://void.cat/d/4nJD5TRePuQChM5tzteYbU.webp\n\nAmethyst agrees with Astral which I suspect are both wrong. nostr:npub13sx6fp3pxq5rl70x0kyfmunyzaa9pzt5utltjm0p8xqyafndv95q3saapa nostr:npub1v0lxxxxutpvrelsksy8cdhgfux9l6a42hsj2qzquu2zk7vc9qnkszrqj49 nostr:npub1g53mukxnjkcmr94fhryzkqutdz2ukq4ks0gvy5af25rgmwsl4ngq43drvk nostr:npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z ",
)
@Test
fun mine() {
val signer = NostrSignerSync(KeyPair())
println("Starting")
val template = PoWMiner.run(baseTemplate, signer.pubKey, 25)
println("Finished")
val event = signer.sign(template)
println(event?.toJson())
assertEquals(25, event!!.pow())
}
}
@@ -0,0 +1,73 @@
/**
* 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.nip13Pow
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip13Pow.miner.PoWRankEvaluator
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class PoWRankEvaluatorTest {
val tests =
mapOf(
"000006d8c378af1779d2feebc7603a125d99eca0ccf1085959b307f64e5dd358" to 21,
"6bf5b4f434813c64b523d2b0e6efe18f3bd0cbbd0a5effd8ece9e00fd2531996" to 1,
"00003479309ecdb46b1c04ce129d2709378518588bed6776e60474ebde3159ae" to 18,
"01a76167d41add96be4959d9e618b7a35f26551d62c43c11e5e64094c6b53c83" to 7,
"ac4f44bae06a45ebe88cfbd3c66358750159650a26c0d79e8ccaa92457fca4f6" to 0,
"0000000000000000006cfbd3c66358750159650a26c0d79e8ccaa92457fca4f6" to 73,
"00000026c91e9fc75fdb95b367776e2594b931cebda6d5ca3622501006669c9e" to 26,
)
@Test
fun testHex() {
tests.forEach {
assertEquals(it.value, PoWRankEvaluator.calculatePowRankOf(it.key))
}
}
@Test
fun testByte() {
tests.forEach {
assertEquals(it.value, PoWRankEvaluator.calculatePowRankOf(it.key.hexToByteArray()))
}
}
val commitmentTest = "00000026c91e9fc75fdb95b367776e2594b931cebda6d5ca3622501006669c9e"
@Test
fun setPoWIfCommited25() {
assertEquals(25, PoWRankEvaluator.compute(commitmentTest, 25))
}
@Test
fun setPoWIfCommited26() {
assertEquals(26, PoWRankEvaluator.compute(commitmentTest, 26))
}
@Test
fun setPoWIfCommited27() {
assertEquals(26, PoWRankEvaluator.compute(commitmentTest, 27))
}
}
@@ -22,7 +22,7 @@ package com.vitorpamplona.quartz.nip17Dm
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip17Dm.files.encryption.AESGCM
import junit.framework.TestCase.assertEquals
import org.junit.Test
@@ -23,8 +23,8 @@ package com.vitorpamplona.quartz.nip19Bech32
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.experimental.medical.FhirResourceEvent
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip01Core.verify
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
@@ -21,10 +21,10 @@
package com.vitorpamplona.quartz.nip44Encryption
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.crypto.Nip01
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.toHexKey
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@@ -23,12 +23,12 @@ package com.vitorpamplona.quartz.nip44Encryption
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.crypto.Nip01
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.utils.RandomInstance
import com.vitorpamplona.quartz.utils.sha256
import com.vitorpamplona.quartz.utils.sha256.sha256
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertNotNull
import junit.framework.TestCase.assertNull
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.nip49PrivKeyEnc
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertNotNull
import junit.framework.TestCase.fail
@@ -21,10 +21,10 @@
package com.vitorpamplona.quartz.nip55AndroidSigner
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.crypto.Nip01
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.toHexKey
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@@ -22,10 +22,10 @@ package com.vitorpamplona.quartz.nip57Zaps
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.nip57Zaps.PrivateZapEncryption.Companion.createEncryptionPrivateKey
import com.vitorpamplona.quartz.nip59GiftWraps.wait1SecondForResult
import com.vitorpamplona.quartz.utils.Hex
@@ -21,11 +21,11 @@
package com.vitorpamplona.quartz.nip59GiftWraps
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.checkSignature
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip01Core.tags.people.PTag
import com.vitorpamplona.quartz.nip01Core.tags.people.isTaggedUser
@@ -36,9 +36,9 @@ import com.vitorpamplona.quartz.experimental.nns.NNSEvent
import com.vitorpamplona.quartz.experimental.profileGallery.ProfileGalleryEntryEvent
import com.vitorpamplona.quartz.experimental.relationshipStatus.RelationshipStatusEvent
import com.vitorpamplona.quartz.experimental.zapPolls.PollNoteEvent
import com.vitorpamplona.quartz.nip01Core.EventHasher
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
import com.vitorpamplona.quartz.nip02FollowList.ContactListEvent
import com.vitorpamplona.quartz.nip03Timestamp.OtsEvent
@@ -21,8 +21,8 @@
package com.vitorpamplona.quartz.blossom
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
import com.vitorpamplona.quartz.utils.TimeUtils
@@ -21,8 +21,8 @@
package com.vitorpamplona.quartz.blossom
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.BaseReplaceableEvent
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
@@ -24,8 +24,8 @@ import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.experimental.audio.header.tags.DownloadUrlTag
import com.vitorpamplona.quartz.experimental.audio.header.tags.StreamUrlTag
import com.vitorpamplona.quartz.experimental.audio.header.tags.WaveformTag
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
import com.vitorpamplona.quartz.nip31Alts.alt
@@ -26,8 +26,8 @@ import com.vitorpamplona.quartz.experimental.audio.track.tags.MediaTag
import com.vitorpamplona.quartz.experimental.audio.track.tags.ParticipantTag
import com.vitorpamplona.quartz.experimental.audio.track.tags.PriceTag
import com.vitorpamplona.quartz.experimental.audio.track.tags.TypeTag
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.BaseAddressableEvent
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
import com.vitorpamplona.quartz.nip01Core.tags.dTags.dTag
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.experimental.audio.track.tags
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Tag
import com.vitorpamplona.quartz.nip01Core.core.isNotName
import com.vitorpamplona.quartz.nip01Core.tags.people.PubKeyReferenceTag
@@ -23,8 +23,8 @@ package com.vitorpamplona.quartz.experimental.edits
import android.util.Log
import androidx.compose.runtime.Immutable
import com.fasterxml.jackson.module.kotlin.readValue
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.BaseReplaceableEvent
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArray
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
@@ -21,8 +21,8 @@
package com.vitorpamplona.quartz.experimental.edits
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
import com.vitorpamplona.quartz.nip01Core.tags.events.firstTaggedEvent
import com.vitorpamplona.quartz.nip31Alts.AltTag
@@ -20,7 +20,7 @@
*/
package com.vitorpamplona.quartz.experimental.forks
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
import com.vitorpamplona.quartz.nip10Notes.BaseThreadedEvent
import com.vitorpamplona.quartz.nip10Notes.tags.MarkedETag
@@ -21,8 +21,8 @@
package com.vitorpamplona.quartz.experimental.interactiveStories
import com.vitorpamplona.quartz.experimental.interactiveStories.tags.StoryOptionTag
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.BaseAddressableEvent
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip23LongContent.tags.ImageTag
import com.vitorpamplona.quartz.nip23LongContent.tags.SummaryTag
import com.vitorpamplona.quartz.nip23LongContent.tags.TitleTag
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.experimental.interactiveStories
import com.vitorpamplona.quartz.experimental.interactiveStories.tags.StoryOptionTag
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
@@ -23,8 +23,8 @@ package com.vitorpamplona.quartz.experimental.interactiveStories
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.experimental.interactiveStories.tags.ReadStatusTag
import com.vitorpamplona.quartz.experimental.interactiveStories.tags.RootSceneTag
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.BaseAddressableEvent
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.core.builder
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.experimental.interactiveStories
import com.vitorpamplona.quartz.experimental.interactiveStories.tags.StoryOptionTag
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.experimental.interactiveStories.tags
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
@@ -22,8 +22,8 @@ package com.vitorpamplona.quartz.experimental.medical
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.experimental.nip95.data.FileStorageEvent.Companion.ALT
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
import com.vitorpamplona.quartz.nip31Alts.alt
@@ -21,8 +21,8 @@
package com.vitorpamplona.quartz.experimental.nip95.data
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
@@ -23,8 +23,8 @@ package com.vitorpamplona.quartz.experimental.nip95.header
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.experimental.nip95.data.FileStorageEvent
import com.vitorpamplona.quartz.nip01Core.EventHintBundle
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.core.any
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
@@ -20,7 +20,7 @@
*/
package com.vitorpamplona.quartz.experimental.nip95.header
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip94FileMetadata.tags.BlurhashTag
import com.vitorpamplona.quartz.nip94FileMetadata.tags.DimensionTag
@@ -24,8 +24,8 @@ import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.experimental.nns.tags.IPv4Tag
import com.vitorpamplona.quartz.experimental.nns.tags.IPv6Tag
import com.vitorpamplona.quartz.experimental.nns.tags.VersionTag
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.BaseAddressableEvent
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
import com.vitorpamplona.quartz.nip31Alts.alt
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.experimental.profileGallery
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
import com.vitorpamplona.quartz.nip31Alts.AltTag
@@ -21,8 +21,8 @@
package com.vitorpamplona.quartz.experimental.profileGallery
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.core.any
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
@@ -20,7 +20,7 @@
*/
package com.vitorpamplona.quartz.experimental.profileGallery
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.tags.events.ETag
import com.vitorpamplona.quartz.nip94FileMetadata.tags.BlurhashTag
@@ -24,7 +24,7 @@ import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.experimental.relationshipStatus.tags.PetnameTag
import com.vitorpamplona.quartz.experimental.relationshipStatus.tags.RankTag
import com.vitorpamplona.quartz.experimental.relationshipStatus.tags.SummaryTag
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.core.tagArray
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
@@ -26,7 +26,7 @@ import com.vitorpamplona.quartz.experimental.zapPolls.tags.ConsensusThresholdTag
import com.vitorpamplona.quartz.experimental.zapPolls.tags.MaximumTag
import com.vitorpamplona.quartz.experimental.zapPolls.tags.MinimumTag
import com.vitorpamplona.quartz.experimental.zapPolls.tags.PollOptionTag
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
import com.vitorpamplona.quartz.nip10Notes.BaseThreadedEvent
@@ -22,6 +22,7 @@ package com.vitorpamplona.quartz.nip01Core
import android.util.Log
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
import com.vitorpamplona.quartz.nip01Core.crypto.Nip01
import com.vitorpamplona.quartz.utils.Hex
@@ -21,7 +21,6 @@
package com.vitorpamplona.quartz.nip01Core.core
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
import com.vitorpamplona.quartz.nip01Core.tags.dTags.dTag
@@ -21,7 +21,6 @@
package com.vitorpamplona.quartz.nip01Core.core
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
@@ -22,7 +22,6 @@ package com.vitorpamplona.quartz.nip01Core.core
import androidx.compose.runtime.Immutable
import com.fasterxml.jackson.annotation.JsonProperty
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.jackson.EventManualSerializer
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
@@ -18,7 +18,7 @@
* 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
package com.vitorpamplona.quartz.nip01Core.core
import com.vitorpamplona.quartz.utils.Hex
@@ -20,8 +20,6 @@
*/
package com.vitorpamplona.quartz.nip01Core.core
import com.vitorpamplona.quartz.nip01Core.HexKey
typealias TagArray = Array<Array<String>>
fun <T : Event> TagArray.builder(initializer: TagArrayBuilder<T>.() -> Unit = {}) = TagArrayBuilder<T>().addAll(this).apply(initializer).build()
@@ -18,10 +18,12 @@
* 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
package com.vitorpamplona.quartz.nip01Core.crypto
import com.fasterxml.jackson.databind.node.ArrayNode
import com.fasterxml.jackson.databind.node.JsonNodeFactory
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
import com.vitorpamplona.quartz.utils.sha256.sha256
@@ -69,6 +71,8 @@ class EventHasher {
content: String,
): ByteArray = sha256(makeJsonForId(pubKey, createdAt, kind, tags, content).toByteArray())
fun hashId(serializedJsonAsBytes: ByteArray): String = sha256(serializedJsonAsBytes).toHexKey()
fun hashId(
pubKey: HexKey,
createdAt: Long,
@@ -20,7 +20,7 @@
*/
package com.vitorpamplona.quartz.nip01Core.crypto
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
class KeyPair(
privKey: ByteArray? = null,
@@ -1,277 +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.experimental
import com.vitorpamplona.quartz.nip01Core.core.Event
import java.nio.ByteBuffer
import java.nio.CharBuffer
import java.nio.charset.CodingErrorAction
import java.security.MessageDigest
class Nip01Serializer {
interface Writer {
fun append(
value: ByteArray,
offset: Int,
length: Int,
)
fun append(
value: String,
offset: Int,
length: Int,
)
fun append(value: ByteArray)
fun append(value: Byte)
fun dump()
}
class BufferedDigestWriter(
val digest: MessageDigest,
) : Writer {
val utf8Encoder =
Charsets.UTF_8
.newEncoder()
.onMalformedInput(CodingErrorAction.IGNORE)
.onUnmappableCharacter(CodingErrorAction.IGNORE)
companion object {
const val BUFFER_SIZE = 128
}
private val innerBuffer = ByteArray(BUFFER_SIZE)
private val byteBuffer = ByteBuffer.wrap(innerBuffer)
override fun append(value: Byte) {
if (byteBuffer.position() == byteBuffer.capacity()) {
dump()
}
byteBuffer.put(value)
}
override fun append(value: ByteArray) {
if (value.size >= BUFFER_SIZE) {
dump()
// don't cache if the cache is smaller than the value
digest.update(value)
} else {
if (value.size > byteBuffer.remaining()) {
dump()
}
value.copyInto(innerBuffer, byteBuffer.position(), 0, value.size)
byteBuffer.position(byteBuffer.position() + value.size)
}
}
override fun append(
value: ByteArray,
offset: Int,
length: Int,
) {
if (value.size >= BUFFER_SIZE) {
dump()
// don't cache if the cache is smaller than the value
digest.update(value, offset, length)
} else {
if (length > byteBuffer.remaining()) {
dump()
}
value.copyInto(innerBuffer, byteBuffer.position(), offset, offset + length)
byteBuffer.position(byteBuffer.position() + value.size)
}
}
override fun append(
value: String,
offset: Int,
length: Int,
) {
val toEncode = CharBuffer.wrap(value, offset, offset + length)
while (toEncode.hasRemaining()) {
val result = utf8Encoder.encode(toEncode, byteBuffer, false)
if (result.isOverflow) {
dump()
}
}
}
override fun dump() {
if (byteBuffer.position() > 0) {
digest.update(innerBuffer, 0, byteBuffer.position())
byteBuffer.clear()
}
}
}
class StringWriter : Writer {
private val stringBuilder: StringBuilder = StringBuilder()
override fun append(
value: ByteArray,
offset: Int,
length: Int,
) {
stringBuilder.append(value.decodeToString(offset, offset + length))
}
override fun append(value: ByteArray) {
stringBuilder.append(value.decodeToString())
}
override fun append(
value: String,
offset: Int,
length: Int,
) {
stringBuilder.append(value, offset, offset + length)
}
override fun append(value: Byte) {
stringBuilder.append(value.toInt().toChar())
}
override fun toString(): String = stringBuilder.toString()
override fun dump() {
}
}
companion object {
private const val DOUBLE_QUOTE_ASCII = 0x22
private const val BACKLASH_ASCII = 0x5C
private const val TAB_ASCII = 0x09
private const val BACKSPACE_ASCII = 0x08
private const val NEWLINE_ASCII = 0x0A
private const val RETURN_ASCII = 0x0D
private const val FORM_FEED_ASCII = 0x0C
private val ESCAPED_DOUBLE_QUOTE = "\\\"".toByteArray()
private val ESCAPED_DOUBLE_BACKLASH = "\\\\".toByteArray()
private val ESCAPED_TAB = "\\t".toByteArray()
private val ESCAPED_BACKSPACE = "\\b".toByteArray()
private val ESCAPED_NEW_LINE = "\\n".toByteArray()
private val ESCAPED_RETURN = "\\r".toByteArray()
private val ESCAPED_FORM_FEED = "\\f".toByteArray()
val ARRAY_ZERO_COMMA_QUOTE = "[0,\"".toByteArray()
val COMMA = ",".toByteArray()
val QUOTE = "\"".toByteArray()
val QUOTE_COMMA = "\",".toByteArray()
val QUOTE_COMMA_QUOTE = "\",\"".toByteArray()
val COMMA_OPEN_ARRAY = ",[".toByteArray()
val COMMA_OPEN_ARRAY_QUOTE = ",[\"".toByteArray()
val OPEN_ARRAY = "[".toByteArray()
val OPEN_ARRAY_QUOTE = "[\"".toByteArray()
val QUOTE_CLOSE_ARRAY = "\"]".toByteArray()
val CLOSE_ARRAY_COMMA_QUOTE = "],\"".toByteArray()
private val MAPPER = Array<ByteArray?>(255) { null }
init {
for (i in 0 until 0x1F) {
MAPPER[i] = String.format("\\u%04x", i.toByte()).toByteArray()
}
MAPPER[DOUBLE_QUOTE_ASCII] = ESCAPED_DOUBLE_QUOTE
MAPPER[BACKLASH_ASCII] = ESCAPED_DOUBLE_BACKLASH
MAPPER[TAB_ASCII] = ESCAPED_TAB
MAPPER[BACKSPACE_ASCII] = ESCAPED_BACKSPACE
MAPPER[NEWLINE_ASCII] = ESCAPED_NEW_LINE
MAPPER[RETURN_ASCII] = ESCAPED_RETURN
MAPPER[FORM_FEED_ASCII] = ESCAPED_FORM_FEED
}
}
fun escapeStringInto(
value: String,
writer: Writer,
) {
var lastNormalSequenceStarts = 0
var lastNormalSequenceLength = 0
for (i in value.indices) {
if (value[i].code >= 255) {
lastNormalSequenceLength++
} else {
val escaped = MAPPER[value[i].code]
if (escaped != null) {
if (lastNormalSequenceLength > 0) {
writer.append(value, lastNormalSequenceStarts, lastNormalSequenceLength)
}
lastNormalSequenceStarts = i + 1
lastNormalSequenceLength = 0
writer.append(escaped)
} else {
lastNormalSequenceLength++
}
}
}
if (lastNormalSequenceLength > 0) {
if (lastNormalSequenceLength == value.length) {
writer.append(value, 0, value.length)
} else {
writer.append(value, lastNormalSequenceStarts, lastNormalSequenceLength)
}
}
}
fun serializeEventInto(
event: Event,
writer: Writer,
) {
writer.append(ARRAY_ZERO_COMMA_QUOTE)
writer.append(event.pubKey.toByteArray())
writer.append(QUOTE_COMMA)
writer.append(event.createdAt.toString().toByteArray())
writer.append(COMMA)
writer.append(event.kind.toString().toByteArray())
writer.append(COMMA_OPEN_ARRAY)
for (index in event.tags.indices) {
val tag = event.tags[index]
if (index > 0) {
writer.append(COMMA_OPEN_ARRAY_QUOTE)
} else {
writer.append(OPEN_ARRAY_QUOTE)
}
for (sIndex in tag.indices) {
if (sIndex > 0) {
writer.append(QUOTE_COMMA_QUOTE)
}
escapeStringInto(tag[sIndex], writer)
}
writer.append(QUOTE_CLOSE_ARRAY)
}
writer.append(CLOSE_ARRAY_COMMA_QUOTE)
escapeStringInto(event.content, writer)
writer.append(QUOTE_CLOSE_ARRAY)
writer.dump()
}
}
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.nip01Core.jackson
import com.fasterxml.jackson.databind.node.JsonNodeFactory
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
class EventManualSerializer {
companion object {
@@ -23,8 +23,8 @@ package com.vitorpamplona.quartz.nip01Core.metadata
import android.util.Log
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.ObjectNode
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
@@ -21,8 +21,8 @@
package com.vitorpamplona.quartz.nip01Core.relay
import android.util.Log
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.AuthMessage
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.ClosedMessage
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.EoseMessage
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.nip01Core.relay.commands.toClient
import com.fasterxml.jackson.databind.JsonNode
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
class OkMessage(
val eventId: HexKey,
@@ -21,9 +21,9 @@
package com.vitorpamplona.quartz.nip01Core.signers
import com.vitorpamplona.quartz.EventFactory
import com.vitorpamplona.quartz.nip01Core.EventHasher
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
import com.vitorpamplona.quartz.nip04Dm.crypto.EncryptedInfo
import com.vitorpamplona.quartz.nip57Zaps.LnZapPrivateEvent
import com.vitorpamplona.quartz.nip57Zaps.LnZapRequestEvent
@@ -20,10 +20,10 @@
*/
package com.vitorpamplona.quartz.nip01Core.signers
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.nip57Zaps.LnZapPrivateEvent
import com.vitorpamplona.quartz.nip57Zaps.LnZapRequestEvent
@@ -22,13 +22,13 @@ package com.vitorpamplona.quartz.nip01Core.signers
import android.util.Log
import com.vitorpamplona.quartz.EventFactory
import com.vitorpamplona.quartz.nip01Core.EventHasher
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.crypto.Nip01
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.nip04Dm.crypto.Nip04
import com.vitorpamplona.quartz.nip44Encryption.Nip44
import com.vitorpamplona.quartz.nip57Zaps.LnZapPrivateEvent
@@ -39,6 +39,8 @@ class NostrSignerSync(
val keyPair: KeyPair,
val pubKey: HexKey = keyPair.pubKey.toHexKey(),
) {
fun <T : Event> sign(ev: EventTemplate<T>) = signNormal<T>(ev.createdAt, ev.kind, ev.tags, ev.content)
fun <T : Event> sign(
createdAt: Long,
kind: Int,
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.nip01Core.tags.addressables
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.match
import com.vitorpamplona.quartz.nip01Core.core.name
import com.vitorpamplona.quartz.nip01Core.core.value
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.nip01Core.tags.addressables
import android.util.Log
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.utils.Hex
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.nip01Core.tags.events
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip19Bech32.entities.NEvent
import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
@@ -20,8 +20,8 @@
*/
package com.vitorpamplona.quartz.nip01Core.tags.events
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
fun Event.forEachTaggedEventId(onEach: (eventId: HexKey) -> Unit) = tags.forEachTaggedEventId(onEach)
@@ -20,7 +20,7 @@
*/
package com.vitorpamplona.quartz.nip01Core.tags.events
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
class EventReference(
val eventId: HexKey,
@@ -20,7 +20,7 @@
*/
package com.vitorpamplona.quartz.nip01Core.tags.events
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
interface GenericETag {
val eventId: HexKey
@@ -20,11 +20,10 @@
*/
package com.vitorpamplona.quartz.nip01Core.tags.events
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArray
import com.vitorpamplona.quartz.nip01Core.core.any
import com.vitorpamplona.quartz.nip01Core.core.forEachTagged
import com.vitorpamplona.quartz.nip01Core.core.isTagged
import com.vitorpamplona.quartz.nip01Core.core.mapValueTagged
fun TagArray.forEachTaggedEventId(onEach: (eventId: HexKey) -> Unit) = this.forEachTagged(ETag.TAG_NAME, onEach)
@@ -20,8 +20,8 @@
*/
package com.vitorpamplona.quartz.nip01Core.tags.hashtags
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
fun Event.forEachHashTag(onEach: (eventId: HexKey) -> Unit) = tags.forEachHashTag(onEach)
@@ -20,7 +20,7 @@
*/
package com.vitorpamplona.quartz.nip01Core.tags.hashtags
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArray
import com.vitorpamplona.quartz.nip01Core.core.anyTagged
import com.vitorpamplona.quartz.nip01Core.core.firstAnyLowercaseTaggedValue
@@ -20,8 +20,8 @@
*/
package com.vitorpamplona.quartz.nip01Core.tags.kinds
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
fun Event.forEachKindTag(onEach: (eventId: HexKey) -> Unit) = tags.forEachKind(onEach)
@@ -20,7 +20,7 @@
*/
package com.vitorpamplona.quartz.nip01Core.tags.kinds
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArray
import com.vitorpamplona.quartz.nip01Core.core.any
import com.vitorpamplona.quartz.nip01Core.core.anyTagged
@@ -22,10 +22,10 @@ package com.vitorpamplona.quartz.nip01Core.tags.people
import android.util.Log
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Tag
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.isNotName
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
import com.vitorpamplona.quartz.nip19Bech32.entities.NProfile
import com.vitorpamplona.quartz.nip19Bech32.toNpub
import com.vitorpamplona.quartz.utils.arrayOfNotNull
@@ -20,7 +20,7 @@
*/
package com.vitorpamplona.quartz.nip01Core.tags.people
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
interface PubKeyReferenceTag {
val pubKey: HexKey
@@ -20,8 +20,8 @@
*/
package com.vitorpamplona.quartz.nip01Core.tags.people
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
fun <T : Event> TagArrayBuilder<T>.pTag(
@@ -21,8 +21,8 @@
package com.vitorpamplona.quartz.nip02FollowList
import androidx.compose.runtime.Stable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
@@ -22,8 +22,8 @@ package com.vitorpamplona.quartz.nip02FollowList
import android.util.Log
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip19Bech32.decodePublicKey
import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
@@ -22,10 +22,10 @@ package com.vitorpamplona.quartz.nip03Timestamp
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.EventHintBundle
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
import com.vitorpamplona.quartz.nip01Core.tags.events.ETag
import com.vitorpamplona.quartz.nip01Core.tags.events.eTag
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.nip03Timestamp
import android.util.LruCache
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.utils.TimeUtils
object VerificationStateCache {
@@ -22,8 +22,8 @@ package com.vitorpamplona.quartz.nip04Dm.messages
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.experimental.inlineMetadata.Nip54InlineMetadata
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.core.any
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
@@ -21,9 +21,9 @@
package com.vitorpamplona.quartz.nip09Deletions
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.AddressableEvent
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
@@ -21,8 +21,8 @@
package com.vitorpamplona.quartz.nip10Notes
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.tags.addressables.taggedATags
import com.vitorpamplona.quartz.nip01Core.tags.people.taggedUsers
import com.vitorpamplona.quartz.nip10Notes.content.findIndexTagsWithEventsOrAddresses
@@ -22,7 +22,7 @@ package com.vitorpamplona.quartz.nip10Notes
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.EventHintBundle
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
import com.vitorpamplona.quartz.nip10Notes.tags.markedETags
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.nip10Notes.tags
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.tags.events.GenericETag
import com.vitorpamplona.quartz.nip19Bech32.entities.NEvent
import com.vitorpamplona.quartz.utils.arrayOfNotNull
@@ -21,8 +21,13 @@
package com.vitorpamplona.quartz.nip13Pow
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip13Pow.miner.PoWRankEvaluator
fun Event.pow() = PoWRankProcessor.compute(id, tags.commitedPoW())
fun Event.pow() = PoWRankEvaluator.compute(id, tags.commitedPoW())
fun Event.powNonce() = tags.powTag()
fun Event.powNonces() = tags.powTags()
fun Event.hasPoWTag() = tags.hasPoW()
@@ -34,7 +39,7 @@ fun Event.hasPoWTag() = tags.hasPoW()
fun Event.strongPoWOrNull(min: Int = 20): Int? {
val commitment = tags.commitedPoW()
if (commitment != null) {
val pow = PoWRankProcessor.compute(id, commitment)
val pow = PoWRankEvaluator.compute(id, commitment)
if (pow >= min) {
return pow
}
@@ -22,6 +22,7 @@ package com.vitorpamplona.quartz.nip13Pow
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip13Pow.tags.PoWTag
fun <T : Event> TagArrayBuilder<T>.pow(
nonce: String,
@@ -21,9 +21,12 @@
package com.vitorpamplona.quartz.nip13Pow
import com.vitorpamplona.quartz.nip01Core.core.TagArray
import com.vitorpamplona.quartz.nip13Pow.tags.PoWTag
fun TagArray.commitedPoW() = this.firstNotNullOfOrNull(PoWTag::parseCommitment)
fun TagArray.hasPoW() = this.any(PoWTag::hasTagWithContent)
fun TagArray.powTag() = this.firstNotNullOfOrNull(PoWTag::parse)
fun TagArray.powTags() = this.mapNotNull(PoWTag::parse)
@@ -18,32 +18,32 @@
* 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.nip13Pow
package com.vitorpamplona.quartz.nip13Pow.miner
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
/** finds the sequence inside the bytearray */
fun ByteArray.indexOf(sequence: ByteArray): Int {
if (sequence.isEmpty()) throw IllegalArgumentException("non-empty byte sequence is required")
@RunWith(AndroidJUnit4::class)
class PoWRankProcessorTest {
@Test
fun setPoW() {
assertEquals(26, PoWRankProcessor.calculatePowRankOf("00000026c91e9fc75fdb95b367776e2594b931cebda6d5ca3622501006669c9e"))
var matchOffset = 0
var start = 0
for (offset in 0 until size) {
if (this[offset] == sequence[matchOffset]) {
if (matchOffset++ == 0) start = offset
if (matchOffset == sequence.size) return start
} else {
matchOffset = 0
}
}
return -1
}
@Test
fun setPoWIfCommited25() {
assertEquals(25, PoWRankProcessor.compute("00000026c91e9fc75fdb95b367776e2594b931cebda6d5ca3622501006669c9e", 25))
}
@Test
fun setPoWIfCommited26() {
assertEquals(26, PoWRankProcessor.compute("00000026c91e9fc75fdb95b367776e2594b931cebda6d5ca3622501006669c9e", 26))
}
@Test
fun setPoWIfCommited27() {
assertEquals(26, PoWRankProcessor.compute("00000026c91e9fc75fdb95b367776e2594b931cebda6d5ca3622501006669c9e", 27))
fun ByteArray.set(
value: ByteArray,
startIndex: Int,
) {
var index = startIndex
for (byte in value) {
this[index++] = byte
}
}
@@ -0,0 +1,29 @@
/**
* 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.nip13Pow.miner
class MiningBuffer(
val bytes: ByteArray,
val nonceStarts: Int,
val nonceEnds: Int,
) {
fun nonce() = String(bytes.copyOfRange(nonceStarts, nonceEnds))
}
@@ -0,0 +1,106 @@
/**
* 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.nip13Pow.miner
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
import com.vitorpamplona.quartz.nip13Pow.tags.PoWTag
import com.vitorpamplona.quartz.utils.sha256.Sha256Hasher
class PoWMiner(
val buffer: MiningBuffer,
val desiredPoW: Int,
) {
val hasher = Sha256Hasher()
fun rank(byteArray: ByteArray) = PoWRankEvaluator.calculatePowRankOf(hasher.hash(byteArray))
fun run() = runDigit(buffer.nonceStarts)
private fun runDigit(index: Int): Boolean {
for (testByte in VALID_BYTES) {
// replaces the background base by the nonce integers
buffer.bytes[index] = testByte
if (rank(buffer.bytes) >= desiredPoW) return true
if (index + 1 < buffer.nonceEnds && runDigit(index + 1)) return true
}
return false
}
companion object {
private val STARTING_NONCE_SIZE = 5
// make sure these chars are not escaped by the JSON stringifier
private val VALID_CHARS: List<Char> =
('0'..'9') + ('a'..'z') + ('A'..'Z') + "-()[]{}$@!*=;:?,".toCharArray().toList()
private val VALID_BYTES = VALID_CHARS.map { it.code.toByte() }
private fun randomBase(size: Int): String = CharArray(size) { VALID_CHARS.random() }.concatToString()
/**
* The miner creates a stringified json template and changes the nonce directly in the UTF-8 ByteArray representation
* to avoid having to recompute the json objects and stringify it.
*/
fun <T : Event> run(
template: EventTemplate<T>,
pubKey: HexKey,
desiredPoW: Int,
): EventTemplate<T> {
var nextSize = STARTING_NONCE_SIZE
do {
val initialNonce = randomBase(nextSize)
val bytes =
EventHasher
.makeJsonForId(
pubKey,
template.createdAt,
template.kind,
template.tags + PoWTag.assemble(initialNonce, desiredPoW),
template.content,
).toByteArray()
val startIndex = bytes.indexOf(initialNonce.toByteArray())
val buffer = MiningBuffer(bytes, startIndex, startIndex + nextSize)
if (PoWMiner(buffer, desiredPoW).run()) {
return EventTemplate(
template.createdAt,
template.kind,
template.tags + PoWTag.assemble(buffer.nonce(), desiredPoW),
template.content,
)
} else {
nextSize += STARTING_NONCE_SIZE
}
} while (nextSize < 50)
throw RuntimeException("Could not find PoW")
}
}
}
@@ -18,12 +18,22 @@
* 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.nip13Pow
package com.vitorpamplona.quartz.nip13Pow.miner
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
class PoWRankProcessor {
class PoWRankEvaluator {
companion object {
const val R8 = 0b00000000.toByte()
const val R7 = 0b00000001.toByte()
const val R6 = 0b00000010.toByte()
const val R5 = 0b00000100.toByte()
const val R4 = 0b00001000.toByte()
const val R3 = 0b00010000.toByte()
const val R2 = 0b00100000.toByte()
const val R1 = 0b01000000.toByte()
const val NEGATIVE = 0b10000000.toByte()
@JvmStatic
fun compute(
id: HexKey,
@@ -63,5 +73,35 @@ class PoWRankProcessor {
}
return rank
}
@JvmStatic
fun calculatePowRankOf(id: ByteArray): Int {
var rank = 0
for (byte in id) {
if (byte == R8) {
rank += 8
} else if (byte < 0) {
break
} else {
if (byte < R6) {
rank += 7
} else if (byte < R5) {
rank += 6
} else if (byte < R4) {
rank += 5
} else if (byte < R3) {
rank += 4
} else if (byte < R2) {
rank += 3
} else if (byte < R1) {
rank += 2
} else {
rank += 1
}
break
}
}
return rank
}
}
}
@@ -18,7 +18,7 @@
* 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.nip13Pow
package com.vitorpamplona.quartz.nip13Pow.tags
import com.vitorpamplona.quartz.utils.arrayOfNotNull
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
@@ -21,8 +21,8 @@
package com.vitorpamplona.quartz.nip17Dm
import com.vitorpamplona.quartz.nip01Core.EventHintBundle
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
import com.vitorpamplona.quartz.nip17Dm.files.ChatMessageEncryptedFileHeaderEvent
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.nip17Dm.base
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.tags.people.PTag
import com.vitorpamplona.quartz.nip59Giftwrap.WrappedEvent
import kotlinx.collections.immutable.toImmutableSet
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.nip17Dm.base
import androidx.compose.runtime.Stable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
@Stable
data class ChatroomKey(
@@ -20,7 +20,7 @@
*/
package com.vitorpamplona.quartz.nip17Dm.base
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
interface ChatroomKeyable {
fun chatroomKey(toRemove: HexKey): ChatroomKey
@@ -20,7 +20,7 @@
*/
package com.vitorpamplona.quartz.nip17Dm.base
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
interface NIP17Group {
fun groupMembers(): Set<HexKey>
@@ -22,7 +22,7 @@ package com.vitorpamplona.quartz.nip17Dm.files
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.EventHintBundle
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
import com.vitorpamplona.quartz.nip01Core.tags.events.ETag
@@ -21,7 +21,7 @@
package com.vitorpamplona.quartz.nip17Dm.files
import com.vitorpamplona.quartz.nip01Core.EventHintBundle
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.tags.people.PTag
import com.vitorpamplona.quartz.nip01Core.tags.people.pTag
@@ -20,7 +20,7 @@
*/
package com.vitorpamplona.quartz.nip17Dm.files.encryption
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.utils.RandomInstance
import javax.crypto.Cipher
import javax.crypto.spec.GCMParameterSpec
@@ -20,8 +20,8 @@
*/
package com.vitorpamplona.quartz.nip17Dm.files.tags
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
class EncryptionKey {
companion object {
@@ -20,8 +20,8 @@
*/
package com.vitorpamplona.quartz.nip17Dm.files.tags
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.toHexKey
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
class EncryptionNonce {
companion object {
@@ -22,7 +22,7 @@ package com.vitorpamplona.quartz.nip17Dm.messages
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.EventHintBundle
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
import com.vitorpamplona.quartz.nip01Core.tags.events.ETag
@@ -21,8 +21,8 @@
package com.vitorpamplona.quartz.nip17Dm.settings
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.BaseReplaceableEvent
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag

Some files were not shown because too many files have changed in this diff Show More