2020-08-18 09:51:20 +02:00
2020-08-02 20:08:02 +02:00
2020-07-01 18:26:24 +02:00
2020-07-09 14:54:34 +02:00
2020-06-26 20:50:32 +02:00
2020-06-26 13:48:50 +02:00
2020-08-18 09:51:20 +02:00
2020-07-09 14:54:34 +02:00
2020-06-29 18:19:32 +02:00
2020-06-29 18:19:32 +02:00
Doc
2020-06-29 13:06:59 +02:00
2020-07-09 17:54:22 +02:00
2020-07-09 14:54:34 +02:00

Secp256k1 for Kotlin/Multiplatform

Kotlin/Multiplatform wrapper for Bitcoin Core's secp256k1 library. Targets: JVM, Android, iOS & Linux.

Installation

Download

First, you need to add the ACINQ libraries repository:

// build.gradle.kts
repositories {
    maven(url = "https://dl.bintray.com/acinq/libs")
}

Then, the actual dependency depends on your targeted platform(s):

Multiplatform

Add the secp256k1 dependency to the common sourceSet, and the JNI dependencies to JVM and Android sourcesets:

// build.gradle.kts

kotlin {
    jvm()
    android()
    linuxX64("linux")
    ios()

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(kotlin("stdlib-common"))
                implementation(kotlin("fr.acinq.secp256k1:secp256k1:$secp256k1_version"))
            }
        }
        val jvmMain by getting {
            dependencies {
                implementation(kotlin("stdlib"))
                implementation(kotlin("fr.acinq.secp256k1:secp256k1-jni-jvm:$secp256k1_version"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation(kotlin("stdlib"))
                implementation(kotlin("fr.acinq.secp256k1:secp256k1-jni-android:$secp256k1_version"))
            }
        }
    }
}

Native targets (iOS, linux64)

Native targets include libsecp256k1, called through KMP's c-interop, simply add the fr.acinq.secp256k1:secp256k1 dependency.

JVM targets & Android

The JVM library uses JNI bindings for libsecp256k1, which is much faster than BouncyCastle. It will extract and load native bindings for your operating system in a temporary directory.

JNI libraries are included for:

  • Linux 64 bits
  • Windows 64 bits
  • Macos 64 bits

Along this library, you must specify which JNI native library to use in your dependency manager:

  • For desktop or server JVMs, you must add the dependency:
    • Either the fr.acinq.secp256k1:secp256k1-jni-jvm dependency which imports all supported platforms.
    • Or the platform specific dependencies (note that you can add multiple as they do not conflict):
      • fr.acinq.secp256k1:secp256k1-jni-jvm-linux for Linux
      • fr.acinq.secp256k1:secp256k1-jni-jvm-darwin for Mac OS X
      • fr.acinq.secp256k1:secp256k1-jni-jvm-mingw for Windows
  • For Android, you must add the fr.acinq.secp256k1:secp256k1-jni-android dependency

If you are using the JVM on an OS for which we don't provide JNI bindings (32 bits OS for example), you can use your own library native library by adding the fr.acinq.secp256k1:secp256k1-jni-jvm dependency and specifying its path with -Dfr.acinq.secp256k1.lib.path and optionally its name with -Dfr.acinq.secp256k1.lib.name (if unspecified bitcoink use the standard name for your OS i.e. libsecp256k1.so on Linux, secp256k1.dll on Windows, ...).

To compile your own JNI bindings, have a look add the native/build.sh and jni/build.sh scripts.

You can also specify the temporary directory where the library will be extracted with -Djava.io.tmpdir or -Dfr.acinq.secp256k1.tmpdir (if you want to use a different directory from -Djava.io.tmpdir).

Usage

Please have a look at unit tests, more samples will be added soon.

Description
Kotlin Multi Platform bindings for Bitcoin secp256k1 library.
Readme 1.2 MiB
Languages
Kotlin 46.3%
C 24%
C++ 20.4%
Java 6%
Shell 3.2%
Other 0.1%