From 59c18f6b233a8893eab70fc0f25df74a25e6d92b Mon Sep 17 00:00:00 2001 From: KotlinGeekDev Date: Fri, 26 Dec 2025 15:27:50 +0100 Subject: [PATCH] Foundations(iOS Sourceset): Implement secp256k1 instance functions. Small fixes in TestResourceLoader. --- .../quartz/utils/Secp256k1Instance.ios.kt | 30 ++++++++----------- .../quartz/TestResourceLoader.kt | 4 +-- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/quartz/src/iosMain/kotlin/com/vitorpamplona/quartz/utils/Secp256k1Instance.ios.kt b/quartz/src/iosMain/kotlin/com/vitorpamplona/quartz/utils/Secp256k1Instance.ios.kt index c08d8edef..d098cac0f 100644 --- a/quartz/src/iosMain/kotlin/com/vitorpamplona/quartz/utils/Secp256k1Instance.ios.kt +++ b/quartz/src/iosMain/kotlin/com/vitorpamplona/quartz/utils/Secp256k1Instance.ios.kt @@ -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) } diff --git a/quartz/src/iosTest/kotlin/com/vitorpamplona/quartz/TestResourceLoader.kt b/quartz/src/iosTest/kotlin/com/vitorpamplona/quartz/TestResourceLoader.kt index e9ff8dd5b..029347f73 100644 --- a/quartz/src/iosTest/kotlin/com/vitorpamplona/quartz/TestResourceLoader.kt +++ b/quartz/src/iosTest/kotlin/com/vitorpamplona/quartz/TestResourceLoader.kt @@ -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() {