Foundations(iOS Sourceset): Implement secp256k1 instance functions. Small fixes in TestResourceLoader.
This commit is contained in:
@@ -20,49 +20,45 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.quartz.utils
|
package com.vitorpamplona.quartz.utils
|
||||||
|
|
||||||
|
import fr.acinq.secp256k1.Secp256k1
|
||||||
|
|
||||||
actual object Secp256k1Instance {
|
actual object Secp256k1Instance {
|
||||||
|
|
||||||
|
private val h02 = Hex.decode("02")
|
||||||
|
private val secp256k1Ref = Secp256k1.get()
|
||||||
|
|
||||||
actual fun compressedPubKeyFor(privKey: ByteArray): ByteArray {
|
actual fun compressedPubKeyFor(privKey: ByteArray): ByteArray {
|
||||||
TODO("Not yet implemented")
|
return secp256k1Ref.pubKeyCompress(secp256k1Ref.pubkeyCreate(privKey))
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun isPrivateKeyValid(il: ByteArray): Boolean {
|
actual fun isPrivateKeyValid(il: ByteArray): Boolean {
|
||||||
TODO("Not yet implemented")
|
return secp256k1Ref.secKeyVerify(il)
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun signSchnorr(
|
actual fun signSchnorr(
|
||||||
data: ByteArray,
|
data: ByteArray,
|
||||||
privKey: ByteArray,
|
privKey: ByteArray,
|
||||||
nonce: ByteArray?,
|
nonce: ByteArray?,
|
||||||
): ByteArray {
|
): ByteArray = secp256k1Ref.signSchnorr(data, privKey, nonce)
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
actual fun signSchnorr(
|
actual fun signSchnorr(
|
||||||
data: ByteArray,
|
data: ByteArray,
|
||||||
privKey: ByteArray,
|
privKey: ByteArray,
|
||||||
): ByteArray {
|
): ByteArray = secp256k1Ref.signSchnorr(data, privKey, null)
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
actual fun verifySchnorr(
|
actual fun verifySchnorr(
|
||||||
signature: ByteArray,
|
signature: ByteArray,
|
||||||
hash: ByteArray,
|
hash: ByteArray,
|
||||||
pubKey: ByteArray,
|
pubKey: ByteArray,
|
||||||
): Boolean {
|
): Boolean = secp256k1Ref.verifySchnorr(signature, hash, pubKey)
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
actual fun privateKeyAdd(
|
actual fun privateKeyAdd(
|
||||||
first: ByteArray,
|
first: ByteArray,
|
||||||
second: ByteArray,
|
second: ByteArray,
|
||||||
): ByteArray {
|
): ByteArray = secp256k1Ref.privKeyTweakAdd(first, second)
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
actual fun pubKeyTweakMulCompact(
|
actual fun pubKeyTweakMulCompact(
|
||||||
pubKey: ByteArray,
|
pubKey: ByteArray,
|
||||||
privateKey: ByteArray,
|
privateKey: ByteArray,
|
||||||
): ByteArray {
|
): ByteArray = secp256k1Ref.pubKeyTweakMul(h02 + pubKey, privateKey).copyOfRange(1, 33)
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ import platform.darwin.NSObjectMeta
|
|||||||
actual class TestResourceLoader {
|
actual class TestResourceLoader {
|
||||||
@OptIn(ExperimentalForeignApi::class, BetaInteropApi::class)
|
@OptIn(ExperimentalForeignApi::class, BetaInteropApi::class)
|
||||||
actual fun loadString(file: String): String {
|
actual fun loadString(file: String): String {
|
||||||
val bundle = NSBundle.Companion.bundleForClass(BundleMarker)
|
val bundle = NSBundle.bundleForClass(BundleMarker)
|
||||||
val path =
|
val path =
|
||||||
bundle.pathForResource(file, ofType = null)
|
bundle.pathForResource(file, ofType = null)
|
||||||
?: throw IllegalArgumentException("Resource not found: $file")
|
?: 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() {
|
private class BundleMarker : NSObject() {
|
||||||
|
|||||||
Reference in New Issue
Block a user