Foundations(iOS Sourceset): Implement secp256k1 instance functions. Small fixes in TestResourceLoader.

This commit is contained in:
KotlinGeekDev
2025-12-26 15:27:50 +01:00
parent aa2f969be6
commit 59c18f6b23
2 changed files with 15 additions and 19 deletions
@@ -20,49 +20,45 @@
*/
package com.vitorpamplona.quartz.utils
import fr.acinq.secp256k1.Secp256k1
actual object Secp256k1Instance {
private val h02 = Hex.decode("02")
private val secp256k1Ref = Secp256k1.get()
actual fun compressedPubKeyFor(privKey: ByteArray): ByteArray {
TODO("Not yet implemented")
return secp256k1Ref.pubKeyCompress(secp256k1Ref.pubkeyCreate(privKey))
}
actual fun isPrivateKeyValid(il: ByteArray): Boolean {
TODO("Not yet implemented")
return secp256k1Ref.secKeyVerify(il)
}
actual fun signSchnorr(
data: ByteArray,
privKey: ByteArray,
nonce: ByteArray?,
): ByteArray {
TODO("Not yet implemented")
}
): ByteArray = secp256k1Ref.signSchnorr(data, privKey, nonce)
actual fun signSchnorr(
data: ByteArray,
privKey: ByteArray,
): ByteArray {
TODO("Not yet implemented")
}
): ByteArray = secp256k1Ref.signSchnorr(data, privKey, null)
actual fun verifySchnorr(
signature: ByteArray,
hash: ByteArray,
pubKey: ByteArray,
): Boolean {
TODO("Not yet implemented")
}
): Boolean = secp256k1Ref.verifySchnorr(signature, hash, pubKey)
actual fun privateKeyAdd(
first: ByteArray,
second: ByteArray,
): ByteArray {
TODO("Not yet implemented")
}
): ByteArray = secp256k1Ref.privKeyTweakAdd(first, second)
actual fun pubKeyTweakMulCompact(
pubKey: ByteArray,
privateKey: ByteArray,
): ByteArray {
TODO("Not yet implemented")
}
): ByteArray = secp256k1Ref.pubKeyTweakMul(h02 + pubKey, privateKey).copyOfRange(1, 33)
}
@@ -32,11 +32,11 @@ import platform.darwin.NSObjectMeta
actual class TestResourceLoader {
@OptIn(ExperimentalForeignApi::class, BetaInteropApi::class)
actual fun loadString(file: String): String {
val bundle = NSBundle.Companion.bundleForClass(BundleMarker)
val bundle = NSBundle.bundleForClass(BundleMarker)
val path =
bundle.pathForResource(file, ofType = null)
?: throw IllegalArgumentException("Resource not found: $file")
return NSString.Companion.stringWithContentsOfFile(path, encoding = NSUTF8StringEncoding, error = null)!!
return NSString.stringWithContentsOfFile(path, encoding = NSUTF8StringEncoding, error = null)!!
}
private class BundleMarker : NSObject() {