Skip to content

Commit

Permalink
feat(secp256k1): add library to be our dependency for secp256k1 in an…
Browse files Browse the repository at this point in the history
…droid, jvm, ios, macos, js

add library for secp256k1 in iOS, macOS
add libraries for secp256k1 in JVM/Android and removed bouncy castle secp256k1
add new implementation of secp256k1 in common
  • Loading branch information
goncalo-frade-iohk committed Jul 13, 2023
1 parent 31a913f commit 3e41246
Show file tree
Hide file tree
Showing 100 changed files with 2,411 additions and 2,910 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
APPLY_FIXES_MODE: commit
VALIDATE_ALL_CODEBASE: ${{ github.ref_name == 'main' }}
DISABLE: COPYPASTE,SPELL
DISABLE_LINTERS: REPOSITORY_CHECKOV
DISABLE_LINTERS: REPOSITORY_CHECKOV,REPOSITORY_GITLEAKS,BASH_SHELLCHECK,
GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }}
steps:
- name: Checkout Code
Expand Down
3 changes: 3 additions & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ a3cb543f5569a83597a4fcada367914beb55ed70:base-asymmetric-encryption/src/commonTe
c8e0b0e540e5b35e2b87be63d3866895afc2e709:base-asymmetric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMECSecp256k1KeyPair.kt:generic-api-key:4
c8e0b0e540e5b35e2b87be63d3866895afc2e709:ecdsa/src/commonTest/kotlin/io/iohk/atala/prism/apollo/ecdsa/KMMECDSATests.kt:generic-api-key:125
4227c2c7612f2f209438746185751419f9e52efc:base-asymmetric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMX25519KeyPair.kt:generic-api-key:4
a8f125101006831bbb27999fcf7c1d27b0d76a8d:base-asymmetric-encryption/src/commonTest/kotlin/io/iohk/atala/prism/apollo/utils/GenerateECKeyPairTests.kt:generic-api-key:58
a8f125101006831bbb27999fcf7c1d27b0d76a8d:base-asymmetric-encryption/src/commonTest/kotlin/io/iohk/atala/prism/apollo/utils/Secp256k1LibTests.kt:generic-api-key:34
a8f125101006831bbb27999fcf7c1d27b0d76a8d:base-asymmetric-encryption/src/commonTest/kotlin/io/iohk/atala/prism/apollo/utils/Secp256k1LibTests.kt:generic-api-key:43
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "secp256k1/secp256k1"]
path = secp256k1/secp256k1
url = https://github.com/bitcoin-core/secp256k1/
[submodule "secp256k1-kmp/native/secp256k1"]
path = secp256k1-kmp/native/secp256k1
url = https://github.com/bitcoin-core/secp256k1
43 changes: 31 additions & 12 deletions aes/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ kotlin {
ios()
// tvos()
// watchos()
// macosX64()
macosX64()
if (System.getProperty("os.arch") != "x86_64") { // M1Chip
iosSimulatorArm64()
// tvosSimulatorArm64()
// watchosSimulatorArm64()
// macosArm64()
macosArm64()
}
}
// if (os.isWindows) {
Expand Down Expand Up @@ -137,14 +137,22 @@ kotlin {
}
val jsTest by getting
if (os.isMacOsX) {
val iosMain by getting
val iosTest by getting
val iosMain by getting {
this.dependsOn(commonMain)
}
val iosTest by getting {
this.dependsOn(commonTest)
}
// val tvosMain by getting
// val tvosTest by getting
// val watchosMain by getting
// val watchosTest by getting
// val macosX64Main by getting
// val macosX64Test by getting
val macosX64Main by getting {
this.dependsOn(iosMain)
}
val macosX64Test by getting {
this.dependsOn(iosTest)
}
if (System.getProperty("os.arch") != "x86_64") { // M1Chip
val iosSimulatorArm64Main by getting {
this.dependsOn(iosMain)
Expand All @@ -164,12 +172,12 @@ kotlin {
// val watchosSimulatorArm64Test by getting {
// this.dependsOn(watchosTest)
// }
// val macosArm64Main by getting {
// this.dependsOn(macosX64Main)
// }
// val macosArm64Test by getting {
// this.dependsOn(macosX64Test)
// }
val macosArm64Main by getting {
this.dependsOn(macosX64Main)
}
val macosArm64Test by getting {
this.dependsOn(macosX64Test)
}
}
}
// if (os.isWindows) {
Expand All @@ -179,6 +187,17 @@ kotlin {
// val mingwX64Test by getting
// }
}

if (os.isMacOsX) {
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosX64Test") {
deviceId = "iPhone 14 Plus"
}
if (System.getProperty("os.arch") != "x86_64") { // M1Chip
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosSimulatorArm64Test") {
deviceId = "iPhone 14 Plus"
}
}
}
}

android {
Expand Down
51 changes: 37 additions & 14 deletions apollo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ kotlin {
}
if (os.isMacOsX) {
ios()
// if (System.getProperty("os.arch") != "x86_64") { // M1Chip
// iosSimulatorArm64()
// }
macosX64()
if (System.getProperty("os.arch") != "x86_64") { // M1Chip
iosSimulatorArm64()
macosArm64()
}
}
js(IR) {
this.moduleName = currentModuleName
Expand All @@ -48,9 +50,9 @@ kotlin {
this.output.libraryTarget = Target.VAR
}
this.commonWebpackConfig {
this.cssSupport {
this.enabled = true
}
// this.cssSupport {
// enabled(true)
// }
}
this.testTask {
this.useKarma {
Expand Down Expand Up @@ -112,14 +114,35 @@ kotlin {
if (os.isMacOsX) {
val iosMain by getting
val iosTest by getting
// if (System.getProperty("os.arch") != "x86_64") { // M1Chip
// val iosSimulatorArm64Main by getting {
// this.dependsOn(iosMain)
// }
// val iosSimulatorArm64Test by getting {
// this.dependsOn(iosTest)
// }
// }

val macosX64Main by getting
val macosX64Test by getting

if (System.getProperty("os.arch") != "x86_64") { // M1Chip
val iosSimulatorArm64Main by getting {
this.dependsOn(iosMain)
}
val iosSimulatorArm64Test by getting {
this.dependsOn(iosTest)
}
val macosArm64Main by getting {
this.dependsOn(macosX64Main)
}
val macosArm64Test by getting {
this.dependsOn(macosX64Test)
}
}
}
}

if (os.isMacOsX) {
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosX64Test") {
deviceId = "iPhone 14 Plus"
}
if (System.getProperty("os.arch") != "x86_64") { // M1Chip
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosSimulatorArm64Test") {
deviceId = "iPhone 14 Plus"
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.iohk.atala.prism.apollo

import kotlin.native.Platform

actual object Platform {
actual val OS: String
get() = "macOS-${Platform.osFamily.name}"
}
133 changes: 75 additions & 58 deletions base-asymmetric-encryption/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import org.gradle.internal.os.OperatingSystem
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackOutput.Target

val currentModuleName = "ApolloBaseAsymmetricEncryption"
Expand All @@ -13,45 +12,49 @@ plugins {
id("org.jetbrains.dokka")
}

fun KotlinNativeTarget.secp256k1CInterop(target: String) {
compilations["main"].cinterops {
val libsecp256k1 by creating {
includeDirs.headerFilterOnly(project.file("../secp256k1/secp256k1/include/"))
tasks[interopProcessingTaskName].dependsOn(":secp256k1:buildSecp256k1${target.capitalize()}")
}
}
}

kotlin {
android {
publishAllLibraryVariants()
}

jvm {
compilations.all {
kotlinOptions {
jvmTarget = "11"
}
}

testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
if (os.isMacOsX) {
ios {
// secp256k1CInterop("ios")
}
// tvos()
// watchos()
// macosX64()
// if (System.getProperty("os.arch") != "x86_64") { // M1Chip
// iosSimulatorArm64 {
// secp256k1CInterop("ios")
// }
ios()
macosX64()

if (System.getProperty("os.arch") != "x86_64") { // M1Chip
iosSimulatorArm64()
// tvosSimulatorArm64()
// watchosSimulatorArm64()
// macosArm64()
// }
macosArm64()
}
}
// if (os.isMacOsX) {
// ios {
// // secp256k1CInterop("ios")
// }
// // tvos()
// // watchos()
// // macosX64()
// // if (System.getProperty("os.arch") != "x86_64") { // M1Chip
// // iosSimulatorArm64 {
// // secp256k1CInterop("ios")
// // }
// // tvosSimulatorArm64()
// // watchosSimulatorArm64()
// // macosArm64()
// // }
// }
// if (os.isWindows) {
// // mingwX86() // it depend on kotlinx-datetime lib to support this platform before we can support it as well
// mingwX64()
Expand Down Expand Up @@ -129,26 +132,42 @@ kotlin {
implementation(project(":utils"))
implementation(project(":secure-random"))
implementation("com.ionspin.kotlin:bignum:0.3.7")
implementation(project(":base64"))
implementation(project(":hashing"))
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(project(":base64"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4") // or the latest version
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4")
}
}
val jvmMain by getting {
dependencies {
dependencies {
api("fr.acinq.secp256k1:secp256k1-kmp:0.9.0")
}
val target = when {
os.isLinux -> "linux"
os.isMacOsX -> "darwin"
os.isWindows -> "mingw"
else -> error("Unsupported OS $os")
}
implementation("fr.acinq.secp256k1:secp256k1-kmp-jni-jvm-$target:0.9.0")
implementation("com.google.guava:guava:30.1-jre")
implementation("org.bouncycastle:bcprov-jdk15on:1.68")
implementation("org.bitcoinj:bitcoinj-core:0.15.10")
}
}
val jvmTest by getting
val androidMain by getting {
dependencies {
api("fr.acinq.secp256k1:secp256k1-kmp:0.9.0")
implementation("fr.acinq.secp256k1:secp256k1-kmp-jni-jvm:0.9.0")
implementation("fr.acinq.secp256k1:secp256k1-kmp-jni-android:0.9.0")
implementation("com.google.guava:guava:30.1-jre")
implementation("org.bouncycastle:bcprov-jdk15on:1.68")
implementation("org.bitcoinj:bitcoinj-core:0.15.10")
}
}
val androidTest by getting {
Expand All @@ -160,8 +179,7 @@ kotlin {
dependencies {
implementation(npm("elliptic", "6.5.4"))
implementation(npm("@types/elliptic", "6.4.14"))
implementation(npm("bip32", "2.0.6"))
implementation(npm("bip39", "3.0.4"))
implementation(npm("@noble/secp256k1", "2.0.0"))

// Polyfill dependencies
implementation(npm("stream-browserify", "3.0.0"))
Expand All @@ -172,44 +190,32 @@ kotlin {
}
}
val jsTest by getting

if (os.isMacOsX) {
val iosMain by getting {
dependencies {
implementation("fr.acinq.bitcoin:bitcoin-kmp:0.11.0")
implementation(project(":secp256k1-kmp"))
}
}
val iosTest by getting
// val tvosMain by getting
// val tvosTest by getting
// val watchosMain by getting
// val watchosTest by getting
// val macosX64Main by getting
// val macosX64Test by getting

val iosTest by getting {
this.dependsOn(commonTest)
}
val macosX64Main by getting {
this.dependsOn(iosMain)
}
val macosX64Test by getting {
this.dependsOn(iosTest)
}
if (System.getProperty("os.arch") != "x86_64") { // M1Chip
// val iosSimulatorArm64Main by getting {
// this.dependsOn(iosMain)
// }
// val iosSimulatorArm64Test by getting {
// this.dependsOn(iosTest)
// }
// val tvosSimulatorArm64Main by getting {
// this.dependsOn(tvosMain)
// }
// val tvosSimulatorArm64Test by getting {
// this.dependsOn(tvosTest)
// }
// val watchosSimulatorArm64Main by getting {
// this.dependsOn(watchosMain)
// }
// val watchosSimulatorArm64Test by getting {
// this.dependsOn(watchosTest)
// }
// val macosArm64Main by getting {
// this.dependsOn(macosX64Main)
// }
// val macosArm64Test by getting {
// this.dependsOn(macosX64Test)
// }
val iosSimulatorArm64Main by getting {
this.dependsOn(iosMain)
}
val iosSimulatorArm64Test by getting {
this.dependsOn(iosTest)
}
val macosArm64Main by getting { this.dependsOn(macosX64Main) }
val macosArm64Test by getting { this.dependsOn(macosX64Test) }
}
}
// if (os.isWindows) {
Expand All @@ -219,6 +225,17 @@ kotlin {
// val mingwX64Test by getting
// }
}

if (os.isMacOsX) {
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosX64Test") {
deviceId = "iPhone 14 Plus"
}
if (System.getProperty("os.arch") != "x86_64") { // M1Chip
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosSimulatorArm64Test") {
deviceId = "iPhone 14 Plus"
}
}
}
}

android {
Expand Down
Loading

0 comments on commit 3e41246

Please sign in to comment.