diff --git a/.idea/artifacts/crypto2_wasm_js_0_1_1_SNAPSHOT.xml b/.idea/artifacts/crypto2_wasm_js_0_1_1_SNAPSHOT.xml new file mode 100644 index 0000000..95644b9 --- /dev/null +++ b/.idea/artifacts/crypto2_wasm_js_0_1_1_SNAPSHOT.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/build/libs + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 76d6398..efbe595 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/build.gradle.kts b/build.gradle.kts index 301e7ae..5b834dd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType + plugins { kotlin("multiplatform") version "2.0.0" id("org.jetbrains.kotlin.plugin.serialization") version "2.0.0" @@ -15,23 +17,26 @@ repositories { } kotlin { - jvm() -// { -// jvmToolchain(8) -// withJava() -// testRuns.named("test") { -// executionTask.configure { -// useJUnitPlatform() -// } -// } -// } - js(IR) { - browser() - nodejs() + jvm { + jvmToolchain(8) + withJava() + testRuns.named("test") { + executionTask.configure { + useJUnitPlatform() + } + } } linuxX64("native") - val ktor_version = "2.3.6" + macosX64() + macosArm64() + iosX64() + iosArm64() + iosSimulatorArm64() + linuxX64() + mingwX64() + // wasmJs() no libsodimu bindings yet (strangely) +// val ktor_version = "2.3.6" sourceSets { all { @@ -46,7 +51,7 @@ kotlin { implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0") implementation("com.ionspin.kotlin:multiplatform-crypto-libsodium-bindings:0.9.0") - api("com.ionspin.kotlin:bignum:0.3.8") + api("com.ionspin.kotlin:bignum:0.3.9") api("net.sergeych:mp_bintools:0.1.5-SNAPSHOT") api("net.sergeych:mp_stools:1.4.1") @@ -69,11 +74,11 @@ kotlin { } } val jsTest by getting -// val nativeMain by getting { -// dependencies { -// } -// } -// val nativeTest by getting + val nativeMain by getting { + dependencies { + } + } + val nativeTest by getting } } diff --git a/src/commonMain/kotlin/net/sergeych/crypto2/contrail.kt b/src/commonMain/kotlin/net/sergeych/crypto2/contrail.kt index abfd8d9..f4de5e3 100644 --- a/src/commonMain/kotlin/net/sergeych/crypto2/contrail.kt +++ b/src/commonMain/kotlin/net/sergeych/crypto2/contrail.kt @@ -2,6 +2,8 @@ package net.sergeych.crypto2 import net.sergeych.bintools.CRC -fun isValidContrail(data: UByteArray): Boolean = CRC.crc8(data.copyOfRange(1, data.size)) == data[0] +fun isValidContrail(data: UByteArray): Boolean = CRC.crc8( + data.copyOfRange(1, data.size).toByteArray() +) == data[0] -fun createContrail(data: UByteArray): UByteArray = ubyteArrayOf(CRC.crc8(data)) + data \ No newline at end of file +fun createContrail(data: UByteArray): UByteArray = ubyteArrayOf(CRC.crc8(data.toByteArray())) + data \ No newline at end of file diff --git a/src/commonMain/kotlin/net/sergeych/tools/AtomicValue.kt b/src/commonMain/kotlin/net/sergeych/tools/AtomicValue.kt index a4a5155..50d4f43 100644 --- a/src/commonMain/kotlin/net/sergeych/tools/AtomicValue.kt +++ b/src/commonMain/kotlin/net/sergeych/tools/AtomicValue.kt @@ -1,5 +1,8 @@ package net.sergeych.tools +import net.sergeych.synctools.ProtectedOp +import net.sergeych.synctools.invoke + /** * Multiplatform (JS and battery included) atomically mutable value. * Actual value can be either changed in a block of [mutuate] when @@ -18,7 +21,7 @@ open class AtomicValue(initialValue: T) { * @return result of the mutation. Note that immediate call to property [value] * could already return modified bu some other thread value! */ - fun mutate(mutator: (T) -> T): T = op { + fun mutate(mutator: (T) -> T): T = op.invoke { actualValue = mutator(actualValue) actualValue } diff --git a/src/commonMain/kotlin/net/sergeych/tools/ProtectedOp.kt b/src/commonMain/kotlin/net/sergeych/tools/ProtectedOp.kt deleted file mode 100644 index be9720c..0000000 --- a/src/commonMain/kotlin/net/sergeych/tools/ProtectedOp.kt +++ /dev/null @@ -1,21 +0,0 @@ -package net.sergeych.tools - -/** - * Multiplatform interface to perform a regular (not suspend) operation - * protected by a platform mutex (where necessary). Get real implementation - * with [ProtectedOp] - */ -interface ProtectedOpImplementation { - /** - * Call [f] iin mutually exclusive mode, it means that only one invocation - * can be active at a time, all the rest are waiting until the current operation - * will finish. - */ - operator fun invoke(f: ()->T): T -} - - -/** - * Get the platform-depended implementation of a mutex-protected operation. - */ -expect fun ProtectedOp(): ProtectedOpImplementation \ No newline at end of file diff --git a/src/commonMain/kotlin/org/komputing/khash/keccak/extensions/PublicExtensions.kt b/src/commonMain/kotlin/org/komputing/khash/keccak/extensions/PublicExtensions.kt index d68f972..563ac88 100644 --- a/src/commonMain/kotlin/org/komputing/khash/keccak/extensions/PublicExtensions.kt +++ b/src/commonMain/kotlin/org/komputing/khash/keccak/extensions/PublicExtensions.kt @@ -11,6 +11,10 @@ fun ByteArray.digestKeccak(parameter: KeccakParameter): ByteArray { return Keccak.digest(this, parameter) } +fun UByteArray.digestKeccak(parameter: KeccakParameter): UByteArray { + return Keccak.digest(this.toByteArray(), parameter).toUByteArray() +} + /** * Computes the proper Keccak digest of [this] string based on the given [parameter] */ diff --git a/src/jsMain/kotlin/net/sergeych/tools/ProtectedOp.js.kt b/src/jsMain/kotlin/net/sergeych/tools/ProtectedOp.js.kt deleted file mode 100644 index acd7d7d..0000000 --- a/src/jsMain/kotlin/net/sergeych/tools/ProtectedOp.js.kt +++ /dev/null @@ -1,6 +0,0 @@ -package net.sergeych.tools - -actual fun ProtectedOp(): ProtectedOpImplementation = object : ProtectedOpImplementation { - // JS targets are inherently single-threaded, so we do noting: - override fun invoke(f: () -> T): T = f() -} \ No newline at end of file diff --git a/src/jvmMain/kotlin/net/sergeych/tools/ProtectedOp.jvm.kt b/src/jvmMain/kotlin/net/sergeych/tools/ProtectedOp.jvm.kt deleted file mode 100644 index 1114558..0000000 --- a/src/jvmMain/kotlin/net/sergeych/tools/ProtectedOp.jvm.kt +++ /dev/null @@ -1,8 +0,0 @@ -package net.sergeych.tools - -actual fun ProtectedOp(): ProtectedOpImplementation = object : ProtectedOpImplementation { - private val lock = Object() - override fun invoke(f: () -> T): T { - synchronized(lock) { return f() } - } -} \ No newline at end of file diff --git a/src/nativeMain/kotlin/net/sergeych/tools/ProtectedOp.native.kt b/src/nativeMain/kotlin/net/sergeych/tools/ProtectedOp.native.kt deleted file mode 100644 index c772602..0000000 --- a/src/nativeMain/kotlin/net/sergeych/tools/ProtectedOp.native.kt +++ /dev/null @@ -1,13 +0,0 @@ -package net.sergeych.tools - -import kotlinx.atomicfu.locks.SynchronizedObject -import kotlinx.atomicfu.locks.synchronized - -actual fun ProtectedOp(): ProtectedOpImplementation = object : ProtectedOpImplementation { - private val lock = SynchronizedObject() - override fun invoke(f: () -> T): T { - synchronized(lock) { - return f() - } - } -} \ No newline at end of file