Skip to content

Commit

Permalink
fix: Typescript assign the correct static variable names avoiding nam…
Browse files Browse the repository at this point in the history
…e mangling

Signed-off-by: Ahmed Moussa <[email protected]>
  • Loading branch information
elribonazo authored and hamada147 committed Oct 4, 2023
1 parent 72e2ba8 commit 60be160
Show file tree
Hide file tree
Showing 29 changed files with 129 additions and 457 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ ktlint_standard_no_semi = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_standard_function-signature = disabled
ktlint_standard_max-line-length = disabled
2 changes: 1 addition & 1 deletion .github/workflows/Deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ jobs:
- name: Publish Maven artifacts to Github Packages
id: publish
run: |
./gradlew publishAllPublicationsToGitHubPackagesRepository
./gradlew publishAllPublicationsToGitHubPackagesRepository :base-asymmetric-encryption:publishJsPackageToGithubRegistry
42 changes: 0 additions & 42 deletions apollo/Apollo.podspec

This file was deleted.

19 changes: 4 additions & 15 deletions apollo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ kotlin {
this.moduleName = currentModuleName
this.binaries.library()
this.useCommonJs()
generateTypeScriptDefinitions()
this.compilations["main"].packageJson {
this.version = rootProject.version.toString()
}
Expand Down Expand Up @@ -113,11 +114,11 @@ kotlin {

if (os.isMacOsX) {
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosX64Test") {
deviceId = "iPhone 14 Plus"
device.set("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"
device.set("iPhone 14 Plus")
}
}
}
Expand Down Expand Up @@ -153,23 +154,11 @@ android {
tasks.withType<DokkaTask> {
moduleName.set(project.name)
moduleVersion.set(rootProject.version.toString())
description = """
This is a Kotlin Multiplatform Library for cryptography
""".trimIndent()
description = "This is a Kotlin Multiplatform Library for cryptography"
dokkaSourceSets {
// TODO: Figure out how to include files to the documentations
named("commonMain") {
includes.from("Module.md", "docs/Module.md")
}
}
}

// afterEvaluate {
// tasks.withType<AbstractTestTask> {
// testLogging {
// events("passed", "skipped", "failed", "standard_out", "standard_error")
// showExceptions = true
// showStackTraces = true
// }
// }
// }
39 changes: 0 additions & 39 deletions base-asymmetric-encryption/base_asymmetric_encryption.podspec

This file was deleted.

41 changes: 36 additions & 5 deletions base-asymmetric-encryption/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dev.petuska.npm.publish.extension.domain.NpmAccess
import org.gradle.internal.os.OperatingSystem
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackOutput.Target
Expand All @@ -10,6 +11,7 @@ plugins {
id("io.github.luca992.multiplatform-swiftpackage") version "2.0.5-arm64"
id("com.android.library")
id("org.jetbrains.dokka")
id("dev.petuska.npm.publish") version "3.4.1"
}

kotlin {
Expand Down Expand Up @@ -87,6 +89,7 @@ kotlin {
this.moduleName = currentModuleName
this.binaries.library()
this.useCommonJs()
generateTypeScriptDefinitions()
this.compilations["main"].packageJson {
this.version = rootProject.version.toString()
}
Expand Down Expand Up @@ -223,11 +226,11 @@ kotlin {

if (os.isMacOsX) {
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosX64Test") {
deviceId = "iPhone 14 Plus"
device.set("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"
device.set("iPhone 14 Plus")
}
}
}
Expand Down Expand Up @@ -263,9 +266,7 @@ android {
tasks.withType<DokkaTask> {
moduleName.set(project.name)
moduleVersion.set(rootProject.version.toString())
description = """
This is a Kotlin Multiplatform Library for Base Asymmetric Encryption
""".trimIndent()
description = "This is a Kotlin Multiplatform Library for Base Asymmetric Encryption"
dokkaSourceSets {
// TODO: Figure out how to include files to the documentations
named("commonMain") {
Expand Down Expand Up @@ -293,3 +294,33 @@ ktlint {
exclude { projectDir.toURI().relativize(it.file.toURI()).path.contains("/external/") }
}
}

npmPublish {
organization.set("input-output-hk")
version.set(project.version.toString())
access.set(NpmAccess.PUBLIC)
packages {
access.set(NpmAccess.PUBLIC)
named("js") {
scope.set("input-output-hk")
packageName.set("apollo")
packageJson {
author {
name.set("IOG")
}
repository {
type.set("git")
url.set("https://github.com/input-output-hk/atala-prism-apollo.git")
}
}
}
}
registries {
access.set(NpmAccess.PUBLIC)
github {
uri.set("https://npm.pkg.github.com/")
access.set(NpmAccess.PUBLIC)
this.authToken.set(System.getenv("ATALA_GITHUB_TOKEN"))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package io.iohk.atala.prism.apollo.utils

import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

@OptIn(ExperimentalJsExport::class)
@JsExport
interface Encodable {
/**
* @return encoded version of the entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport
import kotlin.js.JsName

@OptIn(ExperimentalJsExport::class)
@JsExport
interface KMMECSecp256k1PrivateKeyCommonStaticInterface {
@JsName("secp256k1FromByteArray")
fun secp256k1FromByteArray(d: ByteArray): KMMECSecp256k1PrivateKey {
return KMMECSecp256k1PrivateKey(d)
}

fun secp256k1FromByteArray(d: ByteArray): KMMECSecp256k1PrivateKey

@Throws(ECPrivateKeyDecodingException::class)
fun tweak(privateKeyData: ByteArray, derivationPrivateKeyData: ByteArray): KMMECSecp256k1PrivateKey
fun tweak(
privateKeyData: ByteArray,
derivationPrivateKeyData: ByteArray
): KMMECSecp256k1PrivateKey {
val derivedKey = Secp256k1Lib().derivePrivateKey(privateKeyData, derivationPrivateKeyData)
return derivedKey?.let { KMMECSecp256k1PrivateKey(derivedKey) }
?: run { throw ECPrivateKeyDecodingException("Error while tweaking") }
}
}

@OptIn(ExperimentalJsExport::class)
Expand Down Expand Up @@ -53,18 +63,5 @@ class KMMECSecp256k1PrivateKey : Encodable {
return secp256k1Lib.verify(getPublicKey().raw, signature, data)
}

companion object : KMMECSecp256k1PrivateKeyCommonStaticInterface {
override fun secp256k1FromByteArray(d: ByteArray): KMMECSecp256k1PrivateKey {
return KMMECSecp256k1PrivateKey(d)
}

override fun tweak(
privateKeyData: ByteArray,
derivationPrivateKeyData: ByteArray
): KMMECSecp256k1PrivateKey {
val derivedKey = Secp256k1Lib().derivePrivateKey(privateKeyData, derivationPrivateKeyData)
return derivedKey?.let { KMMECSecp256k1PrivateKey(derivedKey) }
?: run { throw ECPrivateKeyDecodingException("Error while tweaking") }
}
}
companion object : KMMECSecp256k1PrivateKeyCommonStaticInterface
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface KMMECSecp256k1PublicKeyCommonStaticInterface {
* @return true if point on curve, false if not.
* @exception ClassCastException This method fails in JS. To be further investigated.
*/
@JsName("isPointOnSecp256k1Curve")
fun isPointOnSecp256k1Curve(point: KMMECPoint): Boolean {
val x = BigInteger.fromByteArray(point.x, Sign.POSITIVE)
val y = BigInteger.fromByteArray(point.y, Sign.POSITIVE)
Expand All @@ -24,6 +25,7 @@ interface KMMECSecp256k1PublicKeyCommonStaticInterface {
return ((y * y - x * x * x - ECConfig.b) mod ECConfig.p) == BigInteger.ZERO
}

@JsName("secp256k1FromBytes")
fun secp256k1FromBytes(encoded: ByteArray): KMMECSecp256k1PublicKey {
require(encoded.size == 33 || encoded.size == 65) {
"Encoded byte array's expected length is 33 (compressed) or 65 (uncompressed), but got ${encoded.size} bytes"
Expand Down Expand Up @@ -90,6 +92,7 @@ class KMMECSecp256k1PublicKey {
* Get compressed key
* @return compressed ByteArray
*/
@JsName("getCompressed")
fun getCompressed(): ByteArray {
return Secp256k1Lib().compressPublicKey(raw)
}
Expand Down
42 changes: 0 additions & 42 deletions base-symmetric-encryption/base_symmetric_encryption.podspec

This file was deleted.

19 changes: 4 additions & 15 deletions base-symmetric-encryption/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ kotlin {
this.moduleName = currentModuleName
this.binaries.library()
this.useCommonJs()
generateTypeScriptDefinitions()
this.compilations["main"].packageJson {
this.version = rootProject.version.toString()
}
Expand Down Expand Up @@ -149,11 +150,11 @@ kotlin {

if (os.isMacOsX) {
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosX64Test") {
deviceId = "iPhone 14 Plus"
device.set("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"
device.set("iPhone 14 Plus")
}
}
}
Expand Down Expand Up @@ -189,23 +190,11 @@ android {
tasks.withType<DokkaTask> {
moduleName.set(project.name)
moduleVersion.set(rootProject.version.toString())
description = """
This is a Kotlin Multiplatform Library for Base Symmetric Encryption
""".trimIndent()
description = "This is a Kotlin Multiplatform Library for Base Symmetric Encryption"
dokkaSourceSets {
// TODO: Figure out how to include files to the documentations
named("commonMain") {
includes.from("Module.md", "docs/Module.md")
}
}
}

// afterEvaluate {
// tasks.withType<AbstractTestTask> {
// testLogging {
// events("passed", "skipped", "failed", "standard_out", "standard_error")
// showExceptions = true
// showStackTraces = true
// }
// }
// }
Loading

0 comments on commit 60be160

Please sign in to comment.