Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Publish npm package #103

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "secp256k1-kmp/native/secp256k1"]
path = secp256k1-kmp/native/secp256k1
url = https://github.com/bitcoin-core/secp256k1
branch = master
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.

56 changes: 43 additions & 13 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 @@ -149,12 +152,13 @@ kotlin {
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")
}
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")
Expand Down Expand Up @@ -214,20 +218,18 @@ kotlin {
val macosArm64Test by getting { this.dependsOn(iosTest) }
}
// if (os.isWindows) {
// // val mingwX86Main by getting // it depend on kotlinx-datetime lib to support this platform before we can support it as well
// // val mingwX86Test by getting // it depend on kotlinx-datetime lib to support this platform before we can support it as well
// val mingwX64Main by getting
// val mingwX64Test by getting
// }
}

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 +265,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 +293,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.

Loading