mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 07:37:12 +01:00
Moves to NIP-44v2
This commit is contained in:
@@ -5,12 +5,6 @@ import androidx.benchmark.junit4.measureRepeated
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.vitorpamplona.quartz.crypto.CryptoUtils
|
||||
import com.vitorpamplona.quartz.crypto.KeyPair
|
||||
import com.vitorpamplona.quartz.encoders.Bech32
|
||||
import com.vitorpamplona.quartz.encoders.Hex
|
||||
import com.vitorpamplona.quartz.encoders.bechToBytes
|
||||
import com.vitorpamplona.quartz.encoders.toNpub
|
||||
import com.vitorpamplona.quartz.events.Event
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import junit.framework.TestCase.assertNotNull
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
@@ -38,7 +32,7 @@ class CryptoBenchmark {
|
||||
val keyPair2 = KeyPair()
|
||||
|
||||
benchmarkRule.measureRepeated {
|
||||
assertNotNull(CryptoUtils.getSharedSecretNIP44(keyPair1.privKey!!, keyPair2.pubKey))
|
||||
assertNotNull(CryptoUtils.getSharedSecretNIP44v1(keyPair1.privKey!!, keyPair2.pubKey))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +52,7 @@ class CryptoBenchmark {
|
||||
val keyPair2 = KeyPair()
|
||||
|
||||
benchmarkRule.measureRepeated {
|
||||
assertNotNull(CryptoUtils.computeSharedSecretNIP44(keyPair1.privKey!!, keyPair2.pubKey))
|
||||
assertNotNull(CryptoUtils.computeSharedSecretNIP44v1(keyPair1.privKey!!, keyPair2.pubKey))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class GiftWrapBenchmark {
|
||||
|
||||
val countDownLatch2 = CountDownLatch(1)
|
||||
|
||||
Assert.assertEquals(expectedLength, events!!.wraps.map { it.toJson() }.joinToString("").length)
|
||||
Assert.assertEquals(expectedLength, events!!.wraps.map { println("TEST ${it.toJson()}"); it.toJson() }.joinToString("").length)
|
||||
|
||||
// Simulate Receiver
|
||||
events!!.wraps.forEach {
|
||||
|
||||
@@ -4,15 +4,12 @@ import androidx.benchmark.junit4.BenchmarkRule
|
||||
import androidx.benchmark.junit4.measureRepeated
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.vitorpamplona.quartz.crypto.CryptoUtils
|
||||
import com.vitorpamplona.quartz.encoders.toHexKey
|
||||
import com.vitorpamplona.quartz.crypto.KeyPair
|
||||
import com.vitorpamplona.quartz.crypto.decodeNIP44
|
||||
import com.vitorpamplona.quartz.encoders.hexToByteArray
|
||||
import com.vitorpamplona.quartz.events.ChatMessageEvent
|
||||
import com.vitorpamplona.quartz.events.Event
|
||||
import com.vitorpamplona.quartz.events.GiftWrapEvent
|
||||
import com.vitorpamplona.quartz.events.Gossip
|
||||
import com.vitorpamplona.quartz.events.NIP24Factory
|
||||
import com.vitorpamplona.quartz.events.SealedGossipEvent
|
||||
import com.vitorpamplona.quartz.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.signers.NostrSignerInternal
|
||||
@@ -139,18 +136,6 @@ class GiftWrapReceivingBenchmark {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun decodeWrapEvent() {
|
||||
val sender = NostrSignerInternal(KeyPair())
|
||||
val receiver = NostrSignerInternal(KeyPair())
|
||||
|
||||
val wrap = createWrap(sender, receiver)
|
||||
|
||||
benchmarkRule.measureRepeated {
|
||||
assertNotNull(decodeNIP44(wrap.content))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun decryptWrapEvent() {
|
||||
val sender = NostrSignerInternal(KeyPair())
|
||||
@@ -158,10 +143,8 @@ class GiftWrapReceivingBenchmark {
|
||||
|
||||
val wrap = createWrap(sender, receiver)
|
||||
|
||||
val toDecrypt = decodeNIP44(wrap.content) ?: return
|
||||
|
||||
benchmarkRule.measureRepeated {
|
||||
assertNotNull(CryptoUtils.decryptNIP44(toDecrypt, sender.keyPair.privKey!!, wrap.pubKey.hexToByteArray()))
|
||||
assertNotNull(CryptoUtils.decryptNIP44v1(wrap.content, sender.keyPair.privKey!!, wrap.pubKey.hexToByteArray()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,26 +155,13 @@ class GiftWrapReceivingBenchmark {
|
||||
|
||||
val wrap = createWrap(sender, receiver)
|
||||
|
||||
val toDecrypt = decodeNIP44(wrap.content) ?: return
|
||||
val innerJson = CryptoUtils.decryptNIP44(toDecrypt, receiver.keyPair.privKey!!, wrap.pubKey.hexToByteArray())
|
||||
val innerJson = CryptoUtils.decryptNIP44v1(wrap.content, receiver.keyPair.privKey!!, wrap.pubKey.hexToByteArray())
|
||||
|
||||
benchmarkRule.measureRepeated {
|
||||
assertNotNull(innerJson?.let { Event.fromJson(it) })
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun decodeSealEvent() {
|
||||
val sender = NostrSignerInternal(KeyPair())
|
||||
val receiver = NostrSignerInternal(KeyPair())
|
||||
|
||||
val seal = createSeal(sender, receiver)
|
||||
|
||||
benchmarkRule.measureRepeated {
|
||||
assertNotNull(decodeNIP44(seal.content))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun decryptSealedEvent() {
|
||||
val sender = NostrSignerInternal(KeyPair())
|
||||
@@ -199,10 +169,8 @@ class GiftWrapReceivingBenchmark {
|
||||
|
||||
val seal = createSeal(sender, receiver)
|
||||
|
||||
val toDecrypt = decodeNIP44(seal.content) ?: return
|
||||
|
||||
benchmarkRule.measureRepeated {
|
||||
assertNotNull(CryptoUtils.decryptNIP44(toDecrypt, sender.keyPair.privKey!!, seal.pubKey.hexToByteArray()))
|
||||
assertNotNull(CryptoUtils.decryptNIP44v1(seal.content, sender.keyPair.privKey!!, seal.pubKey.hexToByteArray()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,8 +181,7 @@ class GiftWrapReceivingBenchmark {
|
||||
|
||||
val seal = createSeal(sender, receiver)
|
||||
|
||||
val toDecrypt = decodeNIP44(seal.content) ?: return
|
||||
val innerJson = CryptoUtils.decryptNIP44(toDecrypt, receiver.keyPair.privKey!!, seal.pubKey.hexToByteArray())
|
||||
val innerJson = CryptoUtils.decryptNIP44v1(seal.content, receiver.keyPair.privKey!!, seal.pubKey.hexToByteArray())
|
||||
|
||||
benchmarkRule.measureRepeated {
|
||||
assertNotNull(innerJson?.let { Gossip.fromJson(it) })
|
||||
|
||||
Reference in New Issue
Block a user