Skip to content

Commit 295738a

Browse files
elribonazohamada147
andcommitted
fix: Publish npm package (#103)
Co-authored-by: Ahmed Moussa <[email protected]> Signed-off-by: Javi Ribo <[email protected]>
1 parent 1d47d83 commit 295738a

File tree

30 files changed

+139
-468
lines changed

30 files changed

+139
-468
lines changed

.editorconfig

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ ktlint_standard_no_semi = disabled
66
ktlint_standard_trailing-comma-on-call-site = disabled
77
ktlint_standard_trailing-comma-on-declaration-site = disabled
88
ktlint_standard_function-signature = disabled
9+
ktlint_standard_max-line-length = disabled

.github/workflows/Deployment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ jobs:
7373
- name: Publish Maven artifacts to Github Packages
7474
id: publish
7575
run: |
76-
./gradlew publishAllPublicationsToGitHubPackagesRepository
76+
./gradlew publishAllPublicationsToGitHubPackagesRepository :base-asymmetric-encryption:publishJsPackageToGithubRegistry

.gitmodules

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[submodule "secp256k1-kmp/native/secp256k1"]
22
path = secp256k1-kmp/native/secp256k1
33
url = https://github.com/bitcoin-core/secp256k1
4+
branch = master

apollo/Apollo.podspec

-42
This file was deleted.

apollo/build.gradle.kts

+4-15
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ kotlin {
3636
this.moduleName = currentModuleName
3737
this.binaries.library()
3838
this.useCommonJs()
39+
generateTypeScriptDefinitions()
3940
this.compilations["main"].packageJson {
4041
this.version = rootProject.version.toString()
4142
}
@@ -113,11 +114,11 @@ kotlin {
113114

114115
if (os.isMacOsX) {
115116
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosX64Test") {
116-
deviceId = "iPhone 14 Plus"
117+
device.set("iPhone 14 Plus")
117118
}
118119
if (System.getProperty("os.arch") != "x86_64") { // M1Chip
119120
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosSimulatorArm64Test") {
120-
deviceId = "iPhone 14 Plus"
121+
device.set("iPhone 14 Plus")
121122
}
122123
}
123124
}
@@ -153,23 +154,11 @@ android {
153154
tasks.withType<DokkaTask> {
154155
moduleName.set(project.name)
155156
moduleVersion.set(rootProject.version.toString())
156-
description = """
157-
This is a Kotlin Multiplatform Library for cryptography
158-
""".trimIndent()
157+
description = "This is a Kotlin Multiplatform Library for cryptography"
159158
dokkaSourceSets {
160159
// TODO: Figure out how to include files to the documentations
161160
named("commonMain") {
162161
includes.from("Module.md", "docs/Module.md")
163162
}
164163
}
165164
}
166-
167-
// afterEvaluate {
168-
// tasks.withType<AbstractTestTask> {
169-
// testLogging {
170-
// events("passed", "skipped", "failed", "standard_out", "standard_error")
171-
// showExceptions = true
172-
// showStackTraces = true
173-
// }
174-
// }
175-
// }

base-asymmetric-encryption/base_asymmetric_encryption.podspec

-39
This file was deleted.

base-asymmetric-encryption/build.gradle.kts

+43-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import dev.petuska.npm.publish.extension.domain.NpmAccess
12
import org.gradle.internal.os.OperatingSystem
23
import org.jetbrains.dokka.gradle.DokkaTask
34
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackOutput.Target
@@ -10,6 +11,7 @@ plugins {
1011
id("io.github.luca992.multiplatform-swiftpackage") version "2.0.5-arm64"
1112
id("com.android.library")
1213
id("org.jetbrains.dokka")
14+
id("dev.petuska.npm.publish") version "3.4.1"
1315
}
1416

1517
kotlin {
@@ -87,6 +89,7 @@ kotlin {
8789
this.moduleName = currentModuleName
8890
this.binaries.library()
8991
this.useCommonJs()
92+
generateTypeScriptDefinitions()
9093
this.compilations["main"].packageJson {
9194
this.version = rootProject.version.toString()
9295
}
@@ -149,12 +152,13 @@ kotlin {
149152
dependencies {
150153
api("fr.acinq.secp256k1:secp256k1-kmp:0.9.0")
151154
}
152-
val target = when {
153-
os.isLinux -> "linux"
154-
os.isMacOsX -> "darwin"
155-
os.isWindows -> "mingw"
156-
else -> error("Unsupported OS $os")
157-
}
155+
val target =
156+
when {
157+
os.isLinux -> "linux"
158+
os.isMacOsX -> "darwin"
159+
os.isWindows -> "mingw"
160+
else -> error("Unsupported OS $os")
161+
}
158162
implementation("fr.acinq.secp256k1:secp256k1-kmp-jni-jvm-$target:0.9.0")
159163
implementation("com.google.guava:guava:30.1-jre")
160164
implementation("org.bouncycastle:bcprov-jdk15on:1.68")
@@ -214,20 +218,18 @@ kotlin {
214218
val macosArm64Test by getting { this.dependsOn(iosTest) }
215219
}
216220
// if (os.isWindows) {
217-
// // val mingwX86Main by getting // it depend on kotlinx-datetime lib to support this platform before we can support it as well
218-
// // val mingwX86Test by getting // it depend on kotlinx-datetime lib to support this platform before we can support it as well
219221
// val mingwX64Main by getting
220222
// val mingwX64Test by getting
221223
// }
222224
}
223225

224226
if (os.isMacOsX) {
225227
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosX64Test") {
226-
deviceId = "iPhone 14 Plus"
228+
device.set("iPhone 14 Plus")
227229
}
228230
if (System.getProperty("os.arch") != "x86_64") { // M1Chip
229231
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosSimulatorArm64Test") {
230-
deviceId = "iPhone 14 Plus"
232+
device.set("iPhone 14 Plus")
231233
}
232234
}
233235
}
@@ -263,9 +265,7 @@ android {
263265
tasks.withType<DokkaTask> {
264266
moduleName.set(project.name)
265267
moduleVersion.set(rootProject.version.toString())
266-
description = """
267-
This is a Kotlin Multiplatform Library for Base Asymmetric Encryption
268-
""".trimIndent()
268+
description = "This is a Kotlin Multiplatform Library for Base Asymmetric Encryption"
269269
dokkaSourceSets {
270270
// TODO: Figure out how to include files to the documentations
271271
named("commonMain") {
@@ -293,3 +293,33 @@ ktlint {
293293
exclude { projectDir.toURI().relativize(it.file.toURI()).path.contains("/external/") }
294294
}
295295
}
296+
297+
npmPublish {
298+
organization.set("input-output-hk")
299+
version.set(project.version.toString())
300+
access.set(NpmAccess.PUBLIC)
301+
packages {
302+
access.set(NpmAccess.PUBLIC)
303+
named("js") {
304+
scope.set("input-output-hk")
305+
packageName.set("apollo")
306+
packageJson {
307+
author {
308+
name.set("IOG")
309+
}
310+
repository {
311+
type.set("git")
312+
url.set("https://github.com/input-output-hk/atala-prism-apollo.git")
313+
}
314+
}
315+
}
316+
}
317+
registries {
318+
access.set(NpmAccess.PUBLIC)
319+
github {
320+
uri.set("https://npm.pkg.github.com/")
321+
access.set(NpmAccess.PUBLIC)
322+
this.authToken.set(System.getenv("ATALA_GITHUB_TOKEN"))
323+
}
324+
}
325+
}

base-asymmetric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/Encodable.kt

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package io.iohk.atala.prism.apollo.utils
22

3+
import kotlin.js.ExperimentalJsExport
4+
import kotlin.js.JsExport
5+
6+
@OptIn(ExperimentalJsExport::class)
7+
@JsExport
38
interface Encodable {
49
/**
510
* @return encoded version of the entity

base-asymmetric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMECSecp256k1PrivateKey.kt

+15-18
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ import kotlin.js.ExperimentalJsExport
55
import kotlin.js.JsExport
66
import kotlin.js.JsName
77

8+
@OptIn(ExperimentalJsExport::class)
9+
@JsExport
810
interface KMMECSecp256k1PrivateKeyCommonStaticInterface {
11+
@JsName("secp256k1FromByteArray")
12+
fun secp256k1FromByteArray(d: ByteArray): KMMECSecp256k1PrivateKey {
13+
return KMMECSecp256k1PrivateKey(d)
14+
}
915

10-
fun secp256k1FromByteArray(d: ByteArray): KMMECSecp256k1PrivateKey
11-
12-
@Throws(ECPrivateKeyDecodingException::class)
13-
fun tweak(privateKeyData: ByteArray, derivationPrivateKeyData: ByteArray): KMMECSecp256k1PrivateKey
16+
fun tweak(
17+
privateKeyData: ByteArray,
18+
derivationPrivateKeyData: ByteArray
19+
): KMMECSecp256k1PrivateKey {
20+
val derivedKey = Secp256k1Lib().derivePrivateKey(privateKeyData, derivationPrivateKeyData)
21+
return derivedKey?.let { KMMECSecp256k1PrivateKey(derivedKey) }
22+
?: run { throw ECPrivateKeyDecodingException("Error while tweaking") }
23+
}
1424
}
1525

1626
@OptIn(ExperimentalJsExport::class)
@@ -53,18 +63,5 @@ class KMMECSecp256k1PrivateKey : Encodable {
5363
return secp256k1Lib.verify(getPublicKey().raw, signature, data)
5464
}
5565

56-
companion object : KMMECSecp256k1PrivateKeyCommonStaticInterface {
57-
override fun secp256k1FromByteArray(d: ByteArray): KMMECSecp256k1PrivateKey {
58-
return KMMECSecp256k1PrivateKey(d)
59-
}
60-
61-
override fun tweak(
62-
privateKeyData: ByteArray,
63-
derivationPrivateKeyData: ByteArray
64-
): KMMECSecp256k1PrivateKey {
65-
val derivedKey = Secp256k1Lib().derivePrivateKey(privateKeyData, derivationPrivateKeyData)
66-
return derivedKey?.let { KMMECSecp256k1PrivateKey(derivedKey) }
67-
?: run { throw ECPrivateKeyDecodingException("Error while tweaking") }
68-
}
69-
}
66+
companion object : KMMECSecp256k1PrivateKeyCommonStaticInterface
7067
}

base-asymmetric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMECSecp256k1PublicKey.kt

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface KMMECSecp256k1PublicKeyCommonStaticInterface {
1616
* @return true if point on curve, false if not.
1717
* @exception ClassCastException This method fails in JS. To be further investigated.
1818
*/
19+
@JsName("isPointOnSecp256k1Curve")
1920
fun isPointOnSecp256k1Curve(point: KMMECPoint): Boolean {
2021
val x = BigInteger.fromByteArray(point.x, Sign.POSITIVE)
2122
val y = BigInteger.fromByteArray(point.y, Sign.POSITIVE)
@@ -24,6 +25,7 @@ interface KMMECSecp256k1PublicKeyCommonStaticInterface {
2425
return ((y * y - x * x * x - ECConfig.b) mod ECConfig.p) == BigInteger.ZERO
2526
}
2627

28+
@JsName("secp256k1FromBytes")
2729
fun secp256k1FromBytes(encoded: ByteArray): KMMECSecp256k1PublicKey {
2830
require(encoded.size == 33 || encoded.size == 65) {
2931
"Encoded byte array's expected length is 33 (compressed) or 65 (uncompressed), but got ${encoded.size} bytes"
@@ -90,6 +92,7 @@ class KMMECSecp256k1PublicKey {
9092
* Get compressed key
9193
* @return compressed ByteArray
9294
*/
95+
@JsName("getCompressed")
9396
fun getCompressed(): ByteArray {
9497
return Secp256k1Lib().compressPublicKey(raw)
9598
}

base-symmetric-encryption/base_symmetric_encryption.podspec

-42
This file was deleted.

0 commit comments

Comments
 (0)