Foundations(iOS Sourceset): Linter fixes for EventHasherSerializer and Secp256k1Instance.
This commit is contained in:
+15
-17
@@ -30,7 +30,6 @@ import kotlinx.serialization.json.addJsonArray
|
|||||||
import kotlinx.serialization.json.buildJsonArray
|
import kotlinx.serialization.json.buildJsonArray
|
||||||
|
|
||||||
actual object EventHasherSerializer {
|
actual object EventHasherSerializer {
|
||||||
|
|
||||||
fun makeJsonObjectForId(
|
fun makeJsonObjectForId(
|
||||||
pubKey: HexKey,
|
pubKey: HexKey,
|
||||||
createdAt: Long,
|
createdAt: Long,
|
||||||
@@ -38,30 +37,30 @@ actual object EventHasherSerializer {
|
|||||||
tags: Array<Array<String>>,
|
tags: Array<Array<String>>,
|
||||||
content: String,
|
content: String,
|
||||||
): JsonArray {
|
): JsonArray {
|
||||||
val arrayBuilder = buildJsonArray {
|
val arrayBuilder =
|
||||||
add(0)
|
buildJsonArray {
|
||||||
add(pubKey)
|
add(0)
|
||||||
add(createdAt)
|
add(pubKey)
|
||||||
add(kind)
|
add(createdAt)
|
||||||
addJsonArray {
|
add(kind)
|
||||||
tags.fastForEach { tag ->
|
addJsonArray {
|
||||||
//add(JsonArray(content = tag.map { JsonPrimitive(it) }))
|
tags.fastForEach { tag ->
|
||||||
addJsonArray { tag.fastForEach { add(it) } }
|
// add(JsonArray(content = tag.map { JsonPrimitive(it) }))
|
||||||
|
addJsonArray { tag.fastForEach { add(it) } }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
add(content)
|
||||||
}
|
}
|
||||||
add(content)
|
|
||||||
}
|
|
||||||
return arrayBuilder
|
return arrayBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun makeJsonForId(
|
actual fun makeJsonForId(
|
||||||
pubKey: HexKey,
|
pubKey: HexKey,
|
||||||
createdAt: Long,
|
createdAt: Long,
|
||||||
kind: Int,
|
kind: Int,
|
||||||
tags: Array<Array<String>>,
|
tags: Array<Array<String>>,
|
||||||
content: String,
|
content: String,
|
||||||
): String {
|
): String = makeJsonObjectForId(pubKey, createdAt, kind, tags, content).toString()
|
||||||
return makeJsonObjectForId(pubKey, createdAt, kind, tags,content).toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
actual fun fastMakeJsonForId(
|
actual fun fastMakeJsonForId(
|
||||||
pubKey: HexKey,
|
pubKey: HexKey,
|
||||||
@@ -71,7 +70,7 @@ actual object EventHasherSerializer {
|
|||||||
content: String,
|
content: String,
|
||||||
): ByteArray {
|
): ByteArray {
|
||||||
// Also use makeJsonObjectForId(...) above. May change this if needed(for performance).
|
// Also use makeJsonObjectForId(...) above. May change this if needed(for performance).
|
||||||
return makeJsonObjectForId(pubKey, createdAt, kind, tags,content).toString().encodeToByteArray()
|
return makeJsonObjectForId(pubKey, createdAt, kind, tags, content).toString().encodeToByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun makeJsonForIdHashAndCheck(
|
actual fun makeJsonForIdHashAndCheck(
|
||||||
@@ -82,7 +81,6 @@ actual object EventHasherSerializer {
|
|||||||
tags: Array<Array<String>>,
|
tags: Array<Array<String>>,
|
||||||
content: String,
|
content: String,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
|
|
||||||
// Also use makeJsonObjectForId(...) above. May change byteArray encode method if needed.
|
// Also use makeJsonObjectForId(...) above. May change byteArray encode method if needed.
|
||||||
val eventIdHash = sha256(makeJsonObjectForId(pubKey, createdAt, kind, tags, content).toString().encodeToByteArray())
|
val eventIdHash = sha256(makeJsonObjectForId(pubKey, createdAt, kind, tags, content).toString().encodeToByteArray())
|
||||||
return Hex.isEqual(id, eventIdHash)
|
return Hex.isEqual(id, eventIdHash)
|
||||||
|
|||||||
@@ -23,17 +23,12 @@ package com.vitorpamplona.quartz.utils
|
|||||||
import fr.acinq.secp256k1.Secp256k1
|
import fr.acinq.secp256k1.Secp256k1
|
||||||
|
|
||||||
actual object Secp256k1Instance {
|
actual object Secp256k1Instance {
|
||||||
|
|
||||||
private val h02 = Hex.decode("02")
|
private val h02 = Hex.decode("02")
|
||||||
private val secp256k1Ref = Secp256k1.get()
|
private val secp256k1Ref = Secp256k1.get()
|
||||||
|
|
||||||
actual fun compressedPubKeyFor(privKey: ByteArray): ByteArray {
|
actual fun compressedPubKeyFor(privKey: ByteArray): ByteArray = secp256k1Ref.pubKeyCompress(secp256k1Ref.pubkeyCreate(privKey))
|
||||||
return secp256k1Ref.pubKeyCompress(secp256k1Ref.pubkeyCreate(privKey))
|
|
||||||
}
|
|
||||||
|
|
||||||
actual fun isPrivateKeyValid(il: ByteArray): Boolean {
|
actual fun isPrivateKeyValid(il: ByteArray): Boolean = secp256k1Ref.secKeyVerify(il)
|
||||||
return secp256k1Ref.secKeyVerify(il)
|
|
||||||
}
|
|
||||||
|
|
||||||
actual fun signSchnorr(
|
actual fun signSchnorr(
|
||||||
data: ByteArray,
|
data: ByteArray,
|
||||||
|
|||||||
Reference in New Issue
Block a user