Compare commits

...
14 Commits
Author SHA1 Message Date
sergeych e71ff35e14 Fix libsodium initialization on Kotlin JS
Build project and push to maven snapshot / Build-And-Push-Linux (push) Has been cancelled
Build project and push to maven snapshot / Build-And-Push-Mac (push) Has been cancelled
Build project and push to maven snapshot / Build-And-Push-Windows (push) Has been cancelled
2026-07-28 10:07:29 +04:00
sergeych eb9158d3e1 Publish bindings alongside crypto2
Build project and push to maven snapshot / Build-And-Push-Linux (push) Waiting to run
Build project and push to maven snapshot / Build-And-Push-Mac (push) Waiting to run
Build project and push to maven snapshot / Build-And-Push-Windows (push) Waiting to run
2026-07-28 02:48:31 +04:00
sergeych 12ff5ed3cb Publish Wasm bindings from Linux CI
Build project and push to maven snapshot / Build-And-Push-Linux (push) Waiting to run
Build project and push to maven snapshot / Build-And-Push-Mac (push) Waiting to run
Build project and push to maven snapshot / Build-And-Push-Windows (push) Waiting to run
2026-07-28 02:37:32 +04:00
sergeych e17f5a8dd5 Fix libsodium initialization on Kotlin Wasm
Build project and push to maven snapshot / Build-And-Push-Linux (push) Waiting to run
Build project and push to maven snapshot / Build-And-Push-Mac (push) Waiting to run
Build project and push to maven snapshot / Build-And-Push-Windows (push) Waiting to run
2026-07-28 02:36:16 +04:00
chmaria b4b08f2e17 Version updated to 0.9.6
Build project and push to maven snapshot / Build-And-Push-Linux (push) Has been cancelled
Build project and push to maven snapshot / Build-And-Push-Mac (push) Has been cancelled
Build project and push to maven snapshot / Build-And-Push-Windows (push) Has been cancelled
2025-03-24 00:52:49 +03:00
kildishevps aeda210bc5 Version that was successfully published
Build project and push to maven snapshot / Build-And-Push-Linux (push) Has been cancelled
Build project and push to maven snapshot / Build-And-Push-Mac (push) Has been cancelled
Build project and push to maven snapshot / Build-And-Push-Windows (push) Has been cancelled
2025-03-03 12:55:13 +03:00
kildishevps 09622f8226 Gradle configuration that publishes linuxArm64 publication from terminal
Build project and push to maven snapshot / Build-And-Push-Linux (push) Has been cancelled
Build project and push to maven snapshot / Build-And-Push-Mac (push) Has been cancelled
Build project and push to maven snapshot / Build-And-Push-Windows (push) Has been cancelled
2025-02-22 22:11:40 +03:00
kildishevps c39c9ec71e Adding comment in hardly understandable part
Build project and push to maven snapshot / Build-And-Push-Linux (push) Has been cancelled
Build project and push to maven snapshot / Build-And-Push-Mac (push) Has been cancelled
Build project and push to maven snapshot / Build-And-Push-Windows (push) Has been cancelled
2025-02-05 00:37:27 +03:00
kildishevps 2acf7218b4 Changing README
Build project and push to maven snapshot / Build-And-Push-Linux (push) Waiting to run
Build project and push to maven snapshot / Build-And-Push-Mac (push) Waiting to run
Build project and push to maven snapshot / Build-And-Push-Windows (push) Waiting to run
2025-02-04 21:40:56 +03:00
kildishevps f1b8488707 Changing publishing paths back to YoungBlood organization
Build project and push to maven snapshot / Build-And-Push-Linux (push) Has been cancelled
Build project and push to maven snapshot / Build-And-Push-Windows (push) Has been cancelled
Build project and push to maven snapshot / Build-And-Push-Mac (push) Has been cancelled
2025-02-02 19:33:01 +03:00
kildishevps 8a2bbb3e33 Fixig publication again
Build project and push to maven snapshot / Build-And-Push-Mac (push) Waiting to run
Build project and push to maven snapshot / Build-And-Push-Windows (push) Waiting to run
Build project and push to maven snapshot / Build-And-Push-Linux (push) Waiting to run
2025-02-02 18:58:02 +03:00
kildishevps c87a0cf24c Fixig publication
Build project and push to maven snapshot / Build-And-Push-Linux (push) Has been cancelled
Build project and push to maven snapshot / Build-And-Push-Mac (push) Has been cancelled
Build project and push to maven snapshot / Build-And-Push-Windows (push) Has been cancelled
2025-02-01 05:49:07 +03:00
PlaceboAddict c8020e9200 Small fix to previous update
Build project and push to maven snapshot / Build-And-Push-Linux (push) Waiting to run
Build project and push to maven snapshot / Build-And-Push-Mac (push) Waiting to run
Build project and push to maven snapshot / Build-And-Push-Windows (push) Waiting to run
2025-01-31 21:33:37 +03:00
PlaceboAddict 3334a967b1 GroupID and some other things changed from "iospin" to "sergeych"
Build project and push to maven snapshot / Build-And-Push-Linux (push) Waiting to run
Build project and push to maven snapshot / Build-And-Push-Mac (push) Waiting to run
Build project and push to maven snapshot / Build-And-Push-Windows (push) Waiting to run
2025-01-31 20:51:54 +03:00
14 changed files with 47 additions and 187 deletions

No files matched your search

+4 -12
View File
@@ -13,20 +13,12 @@ attack surfaces, bugs and other issues and you shouldn't use it in production un
#### Gradle #### Gradle
```kotlin ```kotlin
implementation("com.ionspin.kotlin:multiplatform-crypto-libsodium-bindings:0.9.2")
```
#### Snapshot builds
```kotlin
repositories { repositories {
maven("https://oss.sonatype.org/content/repositories/snapshots") maven("https://gitea.sergeych.net/api/packages/YoungBlood/maven")
} }
implementation("com.ionspin.kotlin:multiplatform-crypto-libsodium-bindings:0.9.3-SNAPSHOT") implementation("net.sergeych:multiplatform-crypto-libsodium-bindings:0.9.6")
``` ```
## Usage ## Usage
Before using the wrapper you need to initialize the underlying libsodium library. You can use either a callback or coroutines approach Before using the wrapper you need to initialize the underlying libsodium library. You can use either a callback or coroutines approach
@@ -146,7 +138,7 @@ Currently supported native platforms (Apple Silicon is supported since 0.8.5) :
Android .so files come from running dist-build scripts in libsodium which you can find in the libsodium submodule Android .so files come from running dist-build scripts in libsodium which you can find in the libsodium submodule
Java Linux Arm/X86_64 and Mac so and dylib are the same as produced by multiplatform builds, also based on the same submodule commit Java Linux Arm/X86_64 and Mac so and dylib are the same as produced by multiplatform builds, also based on the same submodule commit
Java Windows dll is from https://download.libsodium.org/libsodium/releases/libsodium-1.0.19-stable-msvc.zip Java Windows dll is from https://download.libsodium.org/libsodium/releases/libsodium-1.0.19-stable-msvc.zip
Javascript is from libsodium-wrappers-sumo npm package version 0.7.13 (https://github.com/jedisct1/libsodium.js) Javascript and WebAssembly is from libsodium-wrappers-sumo npm package version 0.7.13 (https://github.com/jedisct1/libsodium.js)
### TODO: ### TODO:
- Improve documentation - Improve documentation
@@ -156,7 +148,7 @@ Javascript is from libsodium-wrappers-sumo npm package version 0.7.13 (https://g
- Find a better way of fetching Konan dependencies than having a dummy project. - Find a better way of fetching Konan dependencies than having a dummy project.
### Building ### Building
Clone the git, init the submodule and run `./gradlew build`. Note that current build settings are such that only linux builds `js` target. Clone the git, init the submodule and run `./gradlew build`. Note that current build settings are such that only linux builds `js` and `wasmJs` targets.
#### Notes for Github runners: #### Notes for Github runners:
- At the moment all runners need to have android sdk present even though not all are building Android build - At the moment all runners need to have android sdk present even though not all are building Android build
+2 -4
View File
@@ -36,13 +36,11 @@ allprojects {
repositories { repositories {
mavenCentral() mavenCentral()
google() google()
maven { maven("https://gitea.sergeych.net/api/packages/YoungBlood/maven")
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
} }
} }
group = "com.ionspin.kotlin" group = ReleaseInfo.group
apply { apply {
+3 -4
View File
@@ -36,8 +36,8 @@ object Versions {
} }
object ReleaseInfo { object ReleaseInfo {
val group = "com.ionspin.kotlin" val group = "net.sergeych"
val bindingsVersion = "0.9.4-SNAPSHOT" val bindingsVersion = "0.9.8-SNAPSHOT"
} }
object Deps { object Deps {
@@ -54,7 +54,7 @@ object Deps {
val apiProject = ":multiplatform-crypto-api" val apiProject = ":multiplatform-crypto-api"
val libsodiumBindings = "com.ionspin.kotlin:multiplatform-crypto-libsodium-bindings:${Versions.sampleLibsodiumBindings}" val libsodiumBindings = "net.sergeych:multiplatform-crypto-libsodium-bindings:${Versions.sampleLibsodiumBindings}"
val kodein = "org.kodein.di:kodein-di:${Versions.kodeinVersion}" val kodein = "org.kodein.di:kodein-di:${Versions.kodeinVersion}"
} }
@@ -142,4 +142,3 @@ object PluginsDeps {
val kotlinAndroid = "kotlin-android" val kotlinAndroid = "kotlin-android"
val kapt = "kotlin-kapt" val kapt = "kotlin-kapt"
} }
@@ -33,22 +33,11 @@ plugins {
} }
val sonatypeStaging = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
val sonatypeSnapshots = "https://oss.sonatype.org/content/repositories/snapshots/"
val sonatypePassword: String? by project
val sonatypeUsername: String? by project
val sonatypePasswordEnv: String? = System.getenv()["SONATYPE_PASSWORD"]
val sonatypeUsernameEnv: String? = System.getenv()["SONATYPE_USERNAME"]
repositories { repositories {
mavenCentral() mavenCentral()
mavenLocal() mavenLocal()
maven { maven("https://gitea.sergeych.net/api/packages/YoungBlood/maven")
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
} }
group = ReleaseInfo.group group = ReleaseInfo.group
@@ -139,14 +128,14 @@ kotlin {
} }
} }
if (ideaActive.not()) { // if (ideaActive.not()) {
linuxArm64() { linuxArm64() {
binaries { binaries {
staticLib { staticLib {
} }
} }
} }
} // }
} }
@@ -339,11 +328,11 @@ kotlin {
"linuxX64" "linuxX64"
) )
val linuxArm64Bit = setOf( val linuxArm64Bit = setOf(
if (ideaActive.not()) { // if (ideaActive.not()) {
"linuxArm64" "linuxArm64"
} else { // } else {
"" // ""
} // }
) )
//iosArm64, iosX64, macosX64, metadata, tvosArm64, tvosX64, watchosArm32, watchosArm64 //iosArm64, iosX64, macosX64, metadata, tvosArm64, tvosX64, watchosArm32, watchosArm64
@@ -382,22 +371,15 @@ kotlin {
defaultSourceSet.dependsOn(nativeMain) defaultSourceSet.dependsOn(nativeMain)
} }
if (linuxArm64Bit.contains(this@withType.name)) { if (linuxArm64Bit.contains(this@withType.name)) {
defaultSourceSet.dependsOn( defaultSourceSet.dependsOn(nativeMain)
createWorkaroundNativeMainSourceSet(
this@withType.name,
nativeDependencies
)
)
this@withType.compilations.getByName("main") { val libsodiumCinterop by cinterops.creating {
val libsodiumCinterop by cinterops.creating { defFile(projectRef.file("src/nativeInterop/cinterop/libsodium.def"))
defFile(projectRef.file("src/nativeInterop/cinterop/libsodium.def")) compilerOpts.add("-I${projectRef.rootDir}/sodiumWrapper/static-arm64/include/")
compilerOpts.add("-I${projectRef.rootDir}/sodiumWrapper/static-arm64/include/")
}
kotlinOptions.freeCompilerArgs = listOf(
"-include-binary", "${projectRef.rootDir}/sodiumWrapper/static-arm64/lib/libsodium.a"
)
} }
kotlinOptions.freeCompilerArgs = listOf(
"-include-binary", "${projectRef.rootDir}/sodiumWrapper/static-arm64/lib/libsodium.a"
)
} }
if (macos64Bit.contains(this@withType.name)) { if (macos64Bit.contains(this@withType.name)) {
@@ -817,26 +799,21 @@ publishing {
} }
} }
val mavenToken by lazy {
File("${System.getProperty("user.home")}/.gitea_token").readText()
}
repositories { repositories {
maven { maven {
credentials(HttpHeaderCredentials::class) {
url = uri(sonatypeStaging) name = "Authorization"
credentials { value = mavenToken
username = sonatypeUsername ?: sonatypeUsernameEnv ?: ""
password = sonatypePassword ?: sonatypePasswordEnv ?: ""
} }
} url = uri("https://gitea.sergeych.net/api/packages/SergeychWorks/maven")
authentication {
maven { create("Authorization", HttpHeaderAuthentication::class)
name = "snapshot"
url = uri(sonatypeSnapshots)
credentials {
username = sonatypeUsername ?: sonatypeUsernameEnv ?: ""
password = sonatypePassword ?: sonatypePasswordEnv ?: ""
} }
} }
} }
} }
@@ -3,6 +3,7 @@ package ext.libsodium.com.ionspin.kotlin.crypto
import com.ionspin.kotlin.crypto.box.BoxKeyPair import com.ionspin.kotlin.crypto.box.BoxKeyPair
import org.khronos.webgl.Uint8Array import org.khronos.webgl.Uint8Array
import kotlin.js.Promise
/** /**
* Created by Ugljesa Jovanovic * Created by Ugljesa Jovanovic
@@ -13,6 +14,8 @@ import org.khronos.webgl.Uint8Array
@JsNonModule @JsNonModule
external object JsSodiumInterface { external object JsSodiumInterface {
val ready: Promise<dynamic>
@JsName("crypto_generichash") @JsName("crypto_generichash")
fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array
@@ -2,12 +2,6 @@ package ext.libsodium.com.ionspin.kotlin.crypto
import com.ionspin.kotlin.crypto.getSodiumLoaded import com.ionspin.kotlin.crypto.getSodiumLoaded
import com.ionspin.kotlin.crypto.sodiumLoaded import com.ionspin.kotlin.crypto.sodiumLoaded
import ext.libsodium._libsodiumPromise
import ext.libsodium.crypto_generichash
import ext.libsodium.crypto_hash_sha256
import ext.libsodium.crypto_hash_sha256_init
import ext.libsodium.crypto_hash_sha512
import ext.libsodium.sodium_init
import kotlin.coroutines.suspendCoroutine import kotlin.coroutines.suspendCoroutine
/** /**
@@ -17,20 +11,9 @@ import kotlin.coroutines.suspendCoroutine
*/ */
object JsSodiumLoader { object JsSodiumLoader {
class _EmitJsSodiumFunction {
init {
println(::crypto_generichash)
println(::crypto_hash_sha256)
println(::crypto_hash_sha512)
println(::crypto_hash_sha256_init)
}
}
suspend fun load() = suspendCoroutine { continuation -> suspend fun load() = suspendCoroutine { continuation ->
if (!getSodiumLoaded()) { if (!getSodiumLoaded()) {
_libsodiumPromise.then<dynamic> { JsSodiumInterface.ready.then<dynamic> {
sodium_init()
sodiumLoaded = true sodiumLoaded = true
continuation.resumeWith(Result.success(Unit)) continuation.resumeWith(Result.success(Unit))
}.catch { e -> }.catch { e ->
@@ -43,8 +26,7 @@ object JsSodiumLoader {
fun loadWithCallback(doneCallback: () -> (Unit)) { fun loadWithCallback(doneCallback: () -> (Unit)) {
if (!getSodiumLoaded()) { if (!getSodiumLoaded()) {
_libsodiumPromise.then<dynamic> { JsSodiumInterface.ready.then<dynamic> {
sodium_init()
sodiumLoaded = true sodiumLoaded = true
doneCallback.invoke() doneCallback.invoke()
} }
@@ -1,31 +0,0 @@
@file:JsModule("libsodium-sumo")
@file:JsNonModule
package ext.libsodium
import org.khronos.webgl.Uint8Array
import kotlin.js.Promise
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 25-May-2020
*/
@JsName("ready")
external val _libsodiumPromise : Promise<dynamic>
@JsName("_sodium_init")
external fun sodium_init() : Int
external fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array) : Uint8Array
external fun crypto_hash_sha256(message: Uint8Array) : Uint8Array
external fun crypto_hash_sha512(message: Uint8Array) : Uint8Array
external fun crypto_hash_sha256_init(): dynamic
@@ -2,6 +2,7 @@ package ext.libsodium.com.ionspin.kotlin.crypto
import org.khronos.webgl.Uint8Array import org.khronos.webgl.Uint8Array
import kotlin.js.Promise
/** /**
* Created by Ugljesa Jovanovic * Created by Ugljesa Jovanovic
@@ -16,7 +17,9 @@ external object JsSodium: JsAny {
} }
@JsModule("libsodium-wrappers-sumo") @JsModule("libsodium-wrappers-sumo")
external object JsSodiumInterface: JsAny { external interface JsSodiumInterface: JsAny {
val ready: Promise<JsAny?>
@JsName("crypto_generichash") @JsName("crypto_generichash")
fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array
@@ -2,7 +2,6 @@ package ext.libsodium.com.ionspin.kotlin.crypto
import com.ionspin.kotlin.crypto.getSodiumLoaded import com.ionspin.kotlin.crypto.getSodiumLoaded
import com.ionspin.kotlin.crypto.sodiumLoaded import com.ionspin.kotlin.crypto.sodiumLoaded
import ext.libsodium.*
import kotlin.coroutines.suspendCoroutine import kotlin.coroutines.suspendCoroutine
/** /**
@@ -12,20 +11,9 @@ import kotlin.coroutines.suspendCoroutine
*/ */
object JsSodiumLoader { object JsSodiumLoader {
class _EmitJsSodiumFunction {
init {
println(::crypto_generichash)
println(::crypto_hash_sha256)
println(::crypto_hash_sha512)
println(::crypto_hash_sha256_init)
}
}
suspend fun load(): Unit = suspendCoroutine { continuation -> suspend fun load(): Unit = suspendCoroutine { continuation ->
if (!getSodiumLoaded()) { if (!getSodiumLoaded()) {
_libsodiumPromise.then<JsAny?> { JsSodium.default.ready.then<JsAny?> {
sodium_init()
sodiumLoaded = true sodiumLoaded = true
continuation.resumeWith(Result.success(Unit)) continuation.resumeWith(Result.success(Unit))
null null
@@ -45,8 +33,7 @@ object JsSodiumLoader {
fun loadWithCallback(doneCallback: () -> (Unit)) { fun loadWithCallback(doneCallback: () -> (Unit)) {
if (!getSodiumLoaded()) { if (!getSodiumLoaded()) {
_libsodiumPromise.then<JsAny?> { JsSodium.default.ready.then<JsAny?> {
sodium_init()
sodiumLoaded = true sodiumLoaded = true
doneCallback.invoke() doneCallback.invoke()
null null
@@ -38,6 +38,8 @@ actual object SecretStream {
ciphertext: UByteArray, ciphertext: UByteArray,
associatedData: UByteArray associatedData: UByteArray
): DecryptedDataAndTag { ): DecryptedDataAndTag {
// crypto_secretstream_xchacha20poly1305_pull JavaScript realization returns either 0
// or DecryptedDataAndTagType object, therefore if 0 is returned an identifying exception is thrown
try { try {
val dataAndTag = getSodium().crypto_secretstream_xchacha20poly1305_pull( val dataAndTag = getSodium().crypto_secretstream_xchacha20poly1305_pull(
state, ciphertext.toUInt8Array(), associatedData.toUInt8Array() state, ciphertext.toUInt8Array(), associatedData.toUInt8Array()
@@ -1,30 +0,0 @@
@file:JsModule("libsodium-sumo")
package ext.libsodium
import org.khronos.webgl.Uint8Array
import kotlin.js.Promise
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 25-May-2020
*/
@JsName("ready")
external val _libsodiumPromise : Promise<JsAny?>
@JsName("_sodium_init")
external fun sodium_init() : Int
external fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array) : Uint8Array
external fun crypto_hash_sha256(message: Uint8Array) : Uint8Array
external fun crypto_hash_sha512(message: Uint8Array) : Uint8Array
external fun crypto_hash_sha256_init(): JsAny
@@ -1,11 +0,0 @@
//package com.ionspin.kotlin.crypto.debug
import kotlin.test.Test
import kotlin.test.assertEquals
class TestTest {
@Test
fun wasmSymbolsTest() {
assertEquals(42, 42)
}
}
@@ -1,11 +0,0 @@
package com.ionspin.kotlin.crypto.debug
import kotlin.test.Test
import kotlin.test.assertEquals
class WasmSymbolsTest {
@Test
fun wasmSymbolsTest() {
assertEquals(42, 42)
}
}
+2 -2
View File
@@ -39,10 +39,10 @@ val sonatypeSnapshots = "https://oss.sonatype.org/content/repositories/snapshots
repositories { repositories {
mavenCentral() mavenCentral()
mavenLocal() mavenLocal()
maven("https://oss.sonatype.org/content/repositories/snapshots/") maven("https://gitea.sergeych.net/api/packages/YoungBlood/maven")
} }
group = "com.ionspin.kotlin" group = "net.sergeych"
version = "0.1.0-SNAPSHOT" version = "0.1.0-SNAPSHOT"
val ideaActive = System.getProperty("idea.active") == "true" val ideaActive = System.getProperty("idea.active") == "true"