From df86967662a16ce51ec20396f9e0a70c29fe07b0 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Wed, 20 Nov 2024 22:24:43 +0300 Subject: [PATCH 01/27] Our sweet start --- gradle/wrapper/gradle-wrapper.properties | 19 ++----------------- sample/webpack.config.d/devServer.config.js | 8 ++++---- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 752c77c..ac499ec 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,21 +1,6 @@ -# -# Copyright 2019 Ugljesa Jovanovic -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - +#Mon Nov 11 15:13:29 MSK 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/sample/webpack.config.d/devServer.config.js b/sample/webpack.config.d/devServer.config.js index c4d84c0..7ceedfc 100644 --- a/sample/webpack.config.d/devServer.config.js +++ b/sample/webpack.config.d/devServer.config.js @@ -1,7 +1,7 @@ config.devServer = config.devServer || {} config.devServer.port = 8081 config.devServer.open = false -config.devServer.watchOptions = { - "aggregateTimeout": 1000, - "poll": 1000 -} \ No newline at end of file +//config.devServer.watchOptions = { +// "aggregateTimeout": 1000, +// "poll": 1000 +//} \ No newline at end of file From d26ef0d41e89c0e54b6d3a63fe809d1c98a20bb6 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Thu, 21 Nov 2024 14:12:51 +0300 Subject: [PATCH 02/27] Our sweet start --- buildSrc/src/main/kotlin/Deps.kt | 14 + .../build.gradle.kts | 30 ++ .../kotlin/crypto/JsSodiumInterface.kt | 367 ++++++++++++++++++ .../ionspin/kotlin/crypto/JsSodiumLoader.kt | 55 +++ .../com/ionspin/kotlin/crypto/JsUtil.kt | 27 ++ .../kotlin/crypto/LibsodiumInitializer.kt | 36 ++ ...thenticatedEncryptionWithAssociatedData.kt | 247 ++++++++++++ .../com/ionspin/kotlin/crypto/auth/Auth.kt | 74 ++++ .../com/ionspin/kotlin/crypto/box/Box.kt | 200 ++++++++++ .../kotlin/crypto/generichash/GenericHash.kt | 82 ++++ .../com/ionspin/kotlin/crypto/hash/Hash.kt | 45 +++ .../com/ionspin/kotlin/crypto/kdf/Kdf.kt | 43 ++ .../kotlin/crypto/keyexchange/KeyExchange.kt | 57 +++ .../kotlin/crypto/pwhash/PasswordHash.kt | 98 +++++ .../crypto/scalarmult/ScalarMultiplication.kt | 40 ++ .../kotlin/crypto/secretbox/SecretBox.kt | 74 ++++ .../crypto/secretstream/SecretStream.kt | 58 +++ .../kotlin/crypto/shortinputhash/ShortHash.kt | 21 + .../kotlin/crypto/signature/Signature.kt | 161 ++++++++ .../ionspin/kotlin/crypto/stream/Stream.kt | 122 ++++++ .../kotlin/crypto/util/LibsodiumRandom.kt | 48 +++ .../kotlin/crypto/util/LibsodiumUtil.kt | 50 +++ .../wasmJsMain/kotlin/debug/test/DebugTest.kt | 113 ++++++ .../src/wasmJsMain/kotlin/libsodium.kt | 31 ++ 24 files changed, 2093 insertions(+) create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/box/Box.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/keyexchange/KeyExchange.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/scalarmult/ScalarMultiplication.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/shortinputhash/ShortHash.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/signature/Signature.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/stream/Stream.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumRandom.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumUtil.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/debug/test/DebugTest.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/libsodium.kt diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 709cd62..6022e06 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -72,6 +72,20 @@ object Deps { } + object wasmJs { + val stdLib = "stdlib-wasm" + val test = "test-wasm" + // TODO: написано от балды \/ +// val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:${Versions.kotlinCoroutines}" +// val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:${Versions.kotlinSerialization}" + + + object Npm { + val libsodiumWrappers = Pair("libsodium-wrappers-sumo", "0.7.13") + + } + } + object Jvm { val stdLib = "stdlib-jdk8" val test = "test" diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index 2b39ae8..43158aa 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -92,6 +92,15 @@ kotlin { runningOnLinuxx86_64 { println("Configuring Linux X86-64 targets") + wasmJs { + browser { + testTask { + useKarma { + useChromeHeadless() + } + } + } + } js { browser { @@ -557,6 +566,19 @@ kotlin { runningOnLinuxx86_64 { println("Configuring Linux 64 Bit source sets") + val wasmJsMain by getting { + // TODO: разобраться (и с test) + dependencies { + implementation(kotlin(Deps.wasmJs.stdLib)) + implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + } + } + val wasmJsTest by getting { + dependencies { + implementation(kotlin(Deps.wasmJs.test)) + implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + } + } val jsMain by getting { dependencies { @@ -709,6 +731,14 @@ tasks { // } // } + // TODO: ваще не жс тест, помогите + val wasmJsBrowserTest by getting(KotlinJsTest::class) { + testLogging { + events("PASSED", "FAILED", "SKIPPED") + showStandardStreams = true + } + } + val jsBrowserTest by getting(KotlinJsTest::class) { testLogging { events("PASSED", "FAILED", "SKIPPED") diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt new file mode 100644 index 0000000..ed74443 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -0,0 +1,367 @@ +package ext.libsodium.com.ionspin.kotlin.crypto + + +import com.ionspin.kotlin.crypto.box.BoxKeyPair +import org.khronos.webgl.Uint8Array + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 27-May-2020 + */ +@JsModule("libsodium-wrappers-sumo") +@JsNonModule +external object JsSodiumInterface { + + + @JsName("crypto_generichash") + fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array + + @JsName("crypto_hash_sha256") + fun crypto_hash_sha256(message: Uint8Array): Uint8Array + + @JsName("crypto_hash_sha512") + fun crypto_hash_sha512(message: Uint8Array): Uint8Array + + // ---- Generic hash ---- // Updateable + + @JsName("crypto_generichash_init") + fun crypto_generichash_init(key : Uint8Array, hashLength: Int) : dynamic + + @JsName("crypto_generichash_update") + fun crypto_generichash_update(state: dynamic, inputMessage: Uint8Array) + + @JsName("crypto_generichash_final") + fun crypto_generichash_final(state: dynamic, hashLength: Int) : Uint8Array + + @JsName("crypto_generichash_keygen") + fun crypto_generichash_keygen() : Uint8Array + + // ---- Generic hash end ---- // Updateable + + // ---- Blake2b ---- + + @JsName("crypto_generichash_blake2b") + fun crypto_generichash_blake2b(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array + + @JsName("crypto_generichash_blake2b_init") + fun crypto_generichash_blake2b_init(key : Uint8Array, hashLength: Int) : dynamic + + @JsName("crypto_generichash_blake2b_update") + fun crypto_generichash_blake2b_update(state: dynamic, inputMessage: Uint8Array) + + @JsName("crypto_generichash_blake2b_final") + fun crypto_generichash_blake2b_final(state: dynamic, hashLength: Int) : Uint8Array + + @JsName("crypto_generichash_blake2b_keygen") + fun crypto_generichash_blake2b_keygen() : Uint8Array + + // ---- Blake2b end ---- + + // ---- Short hash ---- + @JsName("crypto_shorthash") + fun crypto_shorthash(data : Uint8Array, key: Uint8Array) : Uint8Array + + @JsName("crypto_shorthash_keygen") + fun crypto_shorthash_keygen() : Uint8Array + // ---- Short hash end ---- + + + @JsName("crypto_hash_sha256_init") + fun crypto_hash_sha256_init() : dynamic + + @JsName("crypto_hash_sha256_update") + fun crypto_hash_sha256_update(state: dynamic, message: Uint8Array) + + @JsName("crypto_hash_sha256_final") + fun crypto_hash_sha256_final(state: dynamic): Uint8Array + + @JsName("crypto_hash_sha512_init") + fun crypto_hash_sha512_init() : dynamic + + @JsName("crypto_hash_sha512_update") + fun crypto_hash_sha512_update(state: dynamic, message: Uint8Array) + + @JsName("crypto_hash_sha512_final") + fun crypto_hash_sha512_final(state: dynamic): Uint8Array + + //XChaCha20Poly1305 - also in bindings + //fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, secretNonce: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array + //fun crypto_aead_xchacha20poly1305_ietf_decrypt(secretNonce: Uint8Array, ciphertext: Uint8Array, associatedData: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array + + //XChaCha20Poly1305 + //encrypt + @JsName("crypto_secretstream_xchacha20poly1305_init_push") + fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : dynamic + @JsName("crypto_secretstream_xchacha20poly1305_push") + fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, associatedData: Uint8Array, tag: UByte) : Uint8Array + + //decrypt + @JsName("crypto_secretstream_xchacha20poly1305_init_pull") + fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic + @JsName("crypto_secretstream_xchacha20poly1305_pull") + fun crypto_secretstream_xchacha20poly1305_pull(state: dynamic, ciphertext: Uint8Array, associatedData: Uint8Array) : dynamic + + //keygen and rekey + @JsName("crypto_secretstream_xchacha20poly1305_keygen") + fun crypto_secretstream_xchacha20poly1305_keygen() : Uint8Array + @JsName("crypto_secretstream_xchacha20poly1305_rekey") + fun crypto_secretstream_xchacha20poly1305_rekey(state: dynamic) + + // ---- SecretBox ---- + @JsName("crypto_secretbox_detached") + fun crypto_secretbox_detached(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : dynamic + @JsName("crypto_secretbox_easy") + fun crypto_secretbox_easy(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array + @JsName("crypto_secretbox_keygen") + fun crypto_secretbox_keygen() : Uint8Array + @JsName("crypto_secretbox_open_detached") + fun crypto_secretbox_open_detached(ciphertext : Uint8Array, tag : Uint8Array, nonce: Uint8Array, key: Uint8Array) : dynamic + @JsName("crypto_secretbox_open_easy") + fun crypto_secretbox_open_easy(ciphertext : Uint8Array, nonce: Uint8Array, key: Uint8Array) : dynamic + + + // ---- SecretBox End ---- + + + // ---- AEAD ---- + @JsName("crypto_aead_chacha20poly1305_decrypt") + fun crypto_aead_chacha20poly1305_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array + @JsName("crypto_aead_chacha20poly1305_decrypt_detached") + fun crypto_aead_chacha20poly1305_decrypt_detached(nsec: Uint8Array?, ciphertext: Uint8Array, mac: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array): Uint8Array + @JsName("crypto_aead_chacha20poly1305_encrypt") + fun crypto_aead_chacha20poly1305_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array + @JsName("crypto_aead_chacha20poly1305_encrypt_detached") + fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : dynamic + @JsName("crypto_aead_chacha20poly1305_ietf_decrypt") + fun crypto_aead_chacha20poly1305_ietf_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array + @JsName("crypto_aead_chacha20poly1305_ietf_decrypt_detached") + fun crypto_aead_chacha20poly1305_ietf_decrypt_detached(nsec: Uint8Array?, ciphertext: Uint8Array, mac: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array): Uint8Array + @JsName("crypto_aead_chacha20poly1305_ietf_encrypt") + fun crypto_aead_chacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array + @JsName("crypto_aead_chacha20poly1305_ietf_encrypt_detached") + fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : dynamic + @JsName("crypto_aead_chacha20poly1305_ietf_keygen") + fun crypto_aead_chacha20poly1305_ietf_keygen() : Uint8Array + @JsName("crypto_aead_chacha20poly1305_keygen") + fun crypto_aead_chacha20poly1305_keygen() : Uint8Array + @JsName("crypto_aead_xchacha20poly1305_ietf_decrypt") + fun crypto_aead_xchacha20poly1305_ietf_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array + @JsName("crypto_aead_xchacha20poly1305_ietf_decrypt_detached") + fun crypto_aead_xchacha20poly1305_ietf_decrypt_detached(nsec: Uint8Array?, ciphertext: Uint8Array, mac: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array): Uint8Array + @JsName("crypto_aead_xchacha20poly1305_ietf_encrypt") + fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array + @JsName("crypto_aead_xchacha20poly1305_ietf_encrypt_detached") + fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : dynamic + @JsName("crypto_aead_xchacha20poly1305_ietf_keygen") + fun crypto_aead_xchacha20poly1305_ietf_keygen(): Uint8Array + + // ---- AEAD end ---- + + // ---- Auth ---- + + @JsName("crypto_auth") + fun crypto_auth(message: Uint8Array, key: Uint8Array) : Uint8Array + @JsName("crypto_auth_keygen") + fun crypto_auth_keygen() : Uint8Array + @JsName("crypto_auth_verify") + fun crypto_auth_verify(tag: Uint8Array, message: Uint8Array, key: Uint8Array) : Boolean + @JsName("crypto_auth_hmacsha256") + fun crypto_auth_hmacsha256(message: Uint8Array, key: Uint8Array) : Uint8Array + @JsName("crypto_auth_hmacsha256_keygen") + fun crypto_auth_hmacsha256_keygen() : Uint8Array + @JsName("crypto_auth_hmacsha256_verify") + fun crypto_auth_hmacsha256_verify(tag: Uint8Array, message: Uint8Array, key: Uint8Array) : Boolean + @JsName("crypto_auth_hmacsha512") + fun crypto_auth_hmacsha512(message: Uint8Array, key: Uint8Array) : Uint8Array + @JsName("crypto_auth_hmacsha512_keygen") + fun crypto_auth_hmacsha512_keygen() : Uint8Array + @JsName("crypto_auth_hmacsha512_verify") + fun crypto_auth_hmacsha512_verify(tag: Uint8Array, message: Uint8Array, key: Uint8Array) : Boolean + + // ---- Auth end ---- + + // ---- Box ---- + + @JsName("crypto_box_keypair") + fun crypto_box_keypair() : dynamic + @JsName("crypto_box_seed_keypair") + fun crypto_box_seed_keypair(seed : Uint8Array) : dynamic + @JsName("crypto_box_easy") + fun crypto_box_easy(message: Uint8Array, + nonce: Uint8Array, + recipientsPublicKey: Uint8Array, + sendersSecretKey: Uint8Array) : Uint8Array + @JsName("crypto_box_open_easy") + fun crypto_box_open_easy(ciphertext: Uint8Array, + nonce: Uint8Array, + sendersPublicKey: Uint8Array, + recipientsSecretKey: Uint8Array) : Uint8Array + @JsName("crypto_box_detached") + fun crypto_box_detached(message: Uint8Array, + nonce: Uint8Array, + recipientsPublicKey: Uint8Array, + sendersSecretKey: Uint8Array) : dynamic + @JsName("crypto_box_open_detached") + fun crypto_box_open_detached(ciphertext: Uint8Array, + tag: Uint8Array, + nonce: Uint8Array, + sendersPublicKey: Uint8Array, + recipientsSecretKey: Uint8Array) : Uint8Array + @JsName("crypto_box_beforenm") + fun crypto_box_beforenm(publicKey: Uint8Array, secretKey: Uint8Array) : Uint8Array + @JsName("crypto_box_easy_afternm") + fun crypto_box_easy_afternm(message: Uint8Array, + nonce: Uint8Array, + precomputedKey: Uint8Array) : Uint8Array + @JsName("crypto_box_open_easy_afternm") + fun crypto_box_open_easy_afternm(ciphertext: Uint8Array, + nonce: Uint8Array, + precomputedKey: Uint8Array) : Uint8Array + @JsName("crypto_box_seal") + fun crypto_box_seal(message: Uint8Array, recipientsPublicKey: Uint8Array) : Uint8Array + @JsName("crypto_box_seal_open") + fun crypto_box_seal_open(ciphertext: Uint8Array, recipientsPublicKey: Uint8Array, recipientsSecretKey: Uint8Array) : Uint8Array + + // ---- Box end ---- + + // ---- Sign start ---- + @JsName("crypto_sign") + fun crypto_sign(message: Uint8Array, secretKey: Uint8Array) : Uint8Array + @JsName("crypto_sign_detached") + fun crypto_sign_detached(message: Uint8Array, secretKey: Uint8Array) : Uint8Array + @JsName("crypto_sign_ed25519_pk_to_curve25519") + fun crypto_sign_ed25519_pk_to_curve25519(ed25519PublicKey: Uint8Array) : Uint8Array + @JsName("crypto_sign_ed25519_sk_to_curve25519") + fun crypto_sign_ed25519_sk_to_curve25519(ed25519SecretKey: Uint8Array) : Uint8Array + @JsName("crypto_sign_ed25519_sk_to_pk") + fun crypto_sign_ed25519_sk_to_pk(ed25519SecretKey: Uint8Array) : Uint8Array + @JsName("crypto_sign_ed25519_sk_to_seed") + fun crypto_sign_ed25519_sk_to_seed(ed25519SecretKey: Uint8Array) : Uint8Array + @JsName("crypto_sign_final_create") + fun crypto_sign_final_create(state: dynamic, secretKey: Uint8Array) : Uint8Array + @JsName("crypto_sign_final_verify") + fun crypto_sign_final_verify(state: dynamic, signature: Uint8Array, publicKey: Uint8Array) : Boolean + @JsName("crypto_sign_init") + fun crypto_sign_init() : dynamic + @JsName("crypto_sign_keypair") + fun crypto_sign_keypair() : dynamic + @JsName("crypto_sign_open") + fun crypto_sign_open(signedMessage: Uint8Array, publicKey: Uint8Array) : Uint8Array + @JsName("crypto_sign_seed_keypair") + fun crypto_sign_seed_keypair(seed: Uint8Array) : dynamic + @JsName("crypto_sign_update") + fun crypto_sign_update(state: dynamic, message: Uint8Array) + @JsName("crypto_sign_verify_detached") + fun crypto_sign_verify_detached(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array) : Boolean + + + // ---- Sign end ---- + + + // ---- KDF ---- + + @JsName("crypto_kdf_derive_from_key") + fun crypto_kdf_derive_from_key(subkey_len: UInt, subkeyId : UInt, ctx: String, key: Uint8Array) : Uint8Array + @JsName("crypto_kdf_keygen") + fun crypto_kdf_keygen() : Uint8Array + + // ---- KDF end ----- + + // ---- Password hashing ---- + + @JsName("crypto_pwhash") + fun crypto_pwhash(keyLength : UInt, password : Uint8Array, salt: Uint8Array, opsLimit: UInt, memLimit: UInt, algorithm: UInt) : Uint8Array + @JsName("crypto_pwhash_str") + fun crypto_pwhash_str(password: Uint8Array, opsLimit: UInt, memLimit: UInt) : String + @JsName("crypto_pwhash_str_needs_rehash") + fun crypto_pwhash_str_needs_rehash(hashedPassword: String, opsLimit: UInt, memLimit: UInt) : Boolean + @JsName("crypto_pwhash_str_verify") + fun crypto_pwhash_str_verify(hashedPassword: String, password: Uint8Array) : Boolean + + + // ---- Password hashing end ---- + + // ---- Utils ---- + + @JsName("memcmp") + fun memcmp(first: Uint8Array, second: Uint8Array) : Boolean + @JsName("memzero") + fun memzero(data: Uint8Array) + @JsName("pad") + fun pad(data : Uint8Array, blocksize: Int) : Uint8Array + @JsName("unpad") + fun unpad(data: Uint8Array, blocksize: Int) : Uint8Array + @JsName("to_base64") + fun to_base64(data: Uint8Array, variant: Int) : String + @JsName("to_hex") + fun to_hex(data: Uint8Array) : String + @JsName("to_string") + fun to_string(data: Uint8Array) : String + @JsName("from_base64") + fun from_base64(data: String, variant: Int): Uint8Array + @JsName("from_hex") + fun from_hex(data : String): Uint8Array + @JsName("from_string") + fun from_string(data : String): Uint8Array + + // ---- > ---- Random ---- < ----- + + @JsName("randombytes_buf") + fun randombytes_buf(length: Int) : Uint8Array + @JsName("randombytes_buf_deterministic") + fun randombytes_buf_deterministic(length: UInt, seed : Uint8Array) : Uint8Array + @JsName("randombytes_random") + fun randombytes_random() : UInt + @JsName("randombytes_uniform") + fun randombytes_uniform(upper_bound: UInt) : UInt + + // ---- Utils end ---- + + // ---- Key exchange ---- + @JsName("crypto_kx_client_session_keys") + fun crypto_kx_client_session_keys(clientPublicKey: Uint8Array, clientSecretKey: Uint8Array, serverPublicKey: Uint8Array) : dynamic + @JsName("crypto_kx_keypair") + fun crypto_kx_keypair() : dynamic + @JsName("crypto_kx_seed_keypair") + fun crypto_kx_seed_keypair(seed: Uint8Array) : dynamic + @JsName("crypto_kx_server_session_keys") + fun crypto_kx_server_session_keys(serverPublicKey: Uint8Array, serverSecretKey: Uint8Array, clientPublicKey: Uint8Array) : dynamic + + // ---- Key exchange end ---- + + // -- Stream ---- + @JsName("crypto_stream_chacha20") + fun crypto_stream_chacha20(outLength: UInt, key: Uint8Array, nonce: Uint8Array) : Uint8Array + @JsName("crypto_stream_chacha20_ietf_xor") + fun crypto_stream_chacha20_ietf_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array + @JsName("crypto_stream_chacha20_ietf_xor_ic") + fun crypto_stream_chacha20_ietf_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array + @JsName("crypto_stream_chacha20_keygen") + fun crypto_stream_chacha20_keygen() : Uint8Array + @JsName("crypto_stream_chacha20_xor") + fun crypto_stream_chacha20_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array + @JsName("crypto_stream_chacha20_xor_ic") + fun crypto_stream_chacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array + + @JsName("crypto_stream_xchacha20_keygen") + fun crypto_stream_xchacha20_keygen() : Uint8Array + @JsName("crypto_stream_xchacha20_xor") + fun crypto_stream_xchacha20_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array + @JsName("crypto_stream_xchacha20_xor_ic") + fun crypto_stream_xchacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array + + // ---- Stream end ---- + + // ---- Scalar multiplication ---- + + @JsName("crypto_scalarmult") + fun crypto_scalarmult(privateKey: Uint8Array, publicKey: Uint8Array) : Uint8Array + @JsName("crypto_scalarmult_base") + fun crypto_scalarmult_base(privateKey: Uint8Array) : Uint8Array + + // ---- Scalar multiplication end ---- + + + +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt new file mode 100644 index 0000000..a4509a0 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt @@ -0,0 +1,55 @@ +package ext.libsodium.com.ionspin.kotlin.crypto + +import com.ionspin.kotlin.crypto.getSodiumLoaded +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 + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 27-May-2020 + */ +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 -> + if (!getSodiumLoaded()) { + _libsodiumPromise.then { + sodium_init() + sodiumLoaded = true + continuation.resumeWith(Result.success(Unit)) + }.catch { e -> + continuation.resumeWith(Result.failure(e)) + } + } else { + continuation.resumeWith(Result.success(Unit)) + } + } + + fun loadWithCallback(doneCallback: () -> (Unit)) { + if (!getSodiumLoaded()) { + _libsodiumPromise.then { + sodium_init() + sodiumLoaded = true + doneCallback.invoke() + } + } else { + doneCallback.invoke() + } + } +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt new file mode 100644 index 0000000..ec40078 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt @@ -0,0 +1,27 @@ +package ext.libsodium.com.ionspin.kotlin.crypto + +import org.khronos.webgl.Uint8Array +import org.khronos.webgl.get + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 02-Aug-2020 + */ +fun UByteArray.toUInt8Array() : Uint8Array { + val uint8Result = Uint8Array(toByteArray().toTypedArray()) + return uint8Result +} + + +fun Uint8Array.toUByteArray() : UByteArray { + if (length.asDynamic() == undefined) { + println("Error") + } + val result = UByteArray(length) + for (i in 0 until length) { + result[i] = get(i).toUByte() + } + + return result +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt new file mode 100644 index 0000000..20bf538 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt @@ -0,0 +1,36 @@ +package com.ionspin.kotlin.crypto + +import ext.libsodium.com.ionspin.kotlin.crypto.JsSodiumInterface +import ext.libsodium.com.ionspin.kotlin.crypto.JsSodiumLoader + +var sodiumLoaded: Boolean = false + +fun getSodium() : JsSodiumInterface = JsSodiumInterface + +fun getSodiumLoaded() : Boolean = sodiumLoaded + +fun setSodiumLoaded(loaded: Boolean) { + sodiumLoaded = loaded +} + +actual object LibsodiumInitializer { + private var isPlatformInitialized = false + + actual suspend fun initialize() { + JsSodiumLoader.load() + isPlatformInitialized = true + } + + actual fun initializeWithCallback(done: () -> Unit) { + JsSodiumLoader.loadWithCallback { + isPlatformInitialized = true + done() + } + } + + actual fun isInitialized(): Boolean { + return isPlatformInitialized + } + + +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt new file mode 100644 index 0000000..c74369b --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt @@ -0,0 +1,247 @@ +package com.ionspin.kotlin.crypto.aead + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array +import org.khronos.webgl.Uint8Array + +actual object AuthenticatedEncryptionWithAssociatedData { + + // Ietf + + // Original chacha20poly1305 + actual fun xChaCha20Poly1305IetfEncrypt( + message: UByteArray, + associatedData: UByteArray, + nonce: UByteArray, + key: UByteArray + ): UByteArray { + return getSodium().crypto_aead_xchacha20poly1305_ietf_encrypt( + message.toUInt8Array(), + associatedData.toUInt8Array(), + null, + nonce.toUInt8Array(), + key.toUInt8Array(), + ).toUByteArray() + } + + actual fun xChaCha20Poly1305IetfDecrypt( + ciphertextAndTag: UByteArray, + associatedData: UByteArray, + nonce: UByteArray, + key: UByteArray + ): UByteArray { + try { + return getSodium().crypto_aead_xchacha20poly1305_ietf_decrypt( + null, + ciphertextAndTag.toUInt8Array(), + associatedData.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } catch (error: Throwable) { + throw AeadCorrupedOrTamperedDataException() + } + } + + actual fun xChaCha20Poly1305IetfEncryptDetached( + message: UByteArray, + associatedData: UByteArray, + nonce: UByteArray, + key: UByteArray + ): AeadEncryptedDataAndTag { + val result = getSodium().crypto_aead_xchacha20poly1305_ietf_encrypt_detached( + message.toUInt8Array(), + associatedData.toUInt8Array(), + null, + nonce.toUInt8Array(), + key.toUInt8Array(), + ) + return AeadEncryptedDataAndTag( + (result.ciphertext as Uint8Array).toUByteArray(), + (result.mac as Uint8Array).toUByteArray() + ) + } + + actual fun xChaCha20Poly1305IetfDecryptDetached( + ciphertext: UByteArray, + tag: UByteArray, + associatedData: UByteArray, + nonce: UByteArray, + key: UByteArray + ): UByteArray { + try { + return getSodium().crypto_aead_xchacha20poly1305_ietf_decrypt_detached( + null, + ciphertext.toUInt8Array(), + tag.toUInt8Array(), + associatedData.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } catch (error: Throwable) { + throw AeadCorrupedOrTamperedDataException() + } + } + + actual fun chaCha20Poly1305IetfEncrypt( + message: UByteArray, + associatedData: UByteArray, + nonce: UByteArray, + key: UByteArray + ): UByteArray { + return getSodium().crypto_aead_chacha20poly1305_ietf_encrypt( + message.toUInt8Array(), + associatedData.toUInt8Array(), + null, + nonce.toUInt8Array(), + key.toUInt8Array(), + ).toUByteArray() + } + + actual fun chaCha20Poly1305IetfDecrypt( + ciphertextAndTag: UByteArray, + associatedData: UByteArray, + nonce: UByteArray, + key: UByteArray + ): UByteArray { + try { + return getSodium().crypto_aead_chacha20poly1305_ietf_decrypt( + null, + ciphertextAndTag.toUInt8Array(), + associatedData.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } catch (error: Throwable) { + throw AeadCorrupedOrTamperedDataException() + } + } + + actual fun chaCha20Poly1305IetfEncryptDetached( + message: UByteArray, + associatedData: UByteArray, + nonce: UByteArray, + key: UByteArray + ): AeadEncryptedDataAndTag { + val result = getSodium().crypto_aead_chacha20poly1305_ietf_encrypt_detached( + message.toUInt8Array(), + associatedData.toUInt8Array(), + null, + nonce.toUInt8Array(), + key.toUInt8Array(), + ) + return AeadEncryptedDataAndTag( + (result.ciphertext as Uint8Array).toUByteArray(), + (result.mac as Uint8Array).toUByteArray() + ) + } + + actual fun chaCha20Poly1305IetfDecryptDetached( + ciphertext: UByteArray, + tag: UByteArray, + associatedData: UByteArray, + nonce: UByteArray, + key: UByteArray + ): UByteArray { + try { + return getSodium().crypto_aead_chacha20poly1305_ietf_decrypt_detached( + null, + ciphertext.toUInt8Array(), + tag.toUInt8Array(), + associatedData.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } catch (error: Throwable) { + throw AeadCorrupedOrTamperedDataException() + } + } + + actual fun chaCha20Poly1305Encrypt( + message: UByteArray, + associatedData: UByteArray, + nonce: UByteArray, + key: UByteArray + ): UByteArray { + return getSodium().crypto_aead_chacha20poly1305_encrypt( + message.toUInt8Array(), + associatedData.toUInt8Array(), + null, + nonce.toUInt8Array(), + key.toUInt8Array(), + ).toUByteArray() + } + + actual fun chaCha20Poly1305Decrypt( + ciphertextAndTag: UByteArray, + associatedData: UByteArray, + nonce: UByteArray, + key: UByteArray + ): UByteArray { + try { + return getSodium().crypto_aead_chacha20poly1305_decrypt( + null, + ciphertextAndTag.toUInt8Array(), + associatedData.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } catch (error: Throwable) { + throw AeadCorrupedOrTamperedDataException() + } + } + + actual fun chaCha20Poly1305EncryptDetached( + message: UByteArray, + associatedData: UByteArray, + nonce: UByteArray, + key: UByteArray + ): AeadEncryptedDataAndTag { + val result = getSodium().crypto_aead_chacha20poly1305_encrypt_detached( + message.toUInt8Array(), + associatedData.toUInt8Array(), + null, + nonce.toUInt8Array(), + key.toUInt8Array(), + ) + return AeadEncryptedDataAndTag( + (result.ciphertext as Uint8Array).toUByteArray(), + (result.mac as Uint8Array).toUByteArray() + ) + } + + actual fun chaCha20Poly1305DecryptDetached( + ciphertext: UByteArray, + tag: UByteArray, + associatedData: UByteArray, + nonce: UByteArray, + key: UByteArray + ): UByteArray { + try { + return getSodium().crypto_aead_chacha20poly1305_decrypt_detached( + null, + ciphertext.toUInt8Array(), + tag.toUInt8Array(), + associatedData.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } catch (error: Throwable) { + throw AeadCorrupedOrTamperedDataException() + } + } + + actual fun xChaCha20Poly1305IetfKeygen(): UByteArray { + return getSodium().crypto_aead_xchacha20poly1305_ietf_keygen().toUByteArray() + } + + actual fun chaCha20Poly1305IetfKeygen(): UByteArray { + return getSodium().crypto_aead_chacha20poly1305_ietf_keygen().toUByteArray() + } + + actual fun chaCha20Poly1305Keygen(): UByteArray { + return getSodium().crypto_aead_chacha20poly1305_keygen().toUByteArray() + } + +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt new file mode 100644 index 0000000..338cc3d --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt @@ -0,0 +1,74 @@ +package com.ionspin.kotlin.crypto.auth + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array + +actual object Auth { + actual fun authKeygen(): UByteArray { + return getSodium().crypto_auth_keygen().toUByteArray() + } + + actual fun auth(message: UByteArray, key: UByteArray): UByteArray { + return getSodium().crypto_auth( + message.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + + } + + actual fun authVerify(tag: UByteArray, message: UByteArray, key: UByteArray): Boolean { + return getSodium().crypto_auth_verify( + tag.toUInt8Array(), + message.toUInt8Array(), + key.toUInt8Array() + ) + } + + actual fun authHmacSha256Keygen(): UByteArray { + return getSodium().crypto_auth_hmacsha256_keygen().toUByteArray() + } + + actual fun authHmacSha256(message: UByteArray, key: UByteArray): UByteArray { + return getSodium().crypto_auth_hmacsha256( + message.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } + + actual fun authHmacSha256Verify( + tag: UByteArray, + message: UByteArray, + key: UByteArray + ): Boolean { + return getSodium().crypto_auth_hmacsha256_verify( + tag.toUInt8Array(), + message.toUInt8Array(), + key.toUInt8Array() + ) + } + + actual fun authHmacSha512Keygen(): UByteArray { + return getSodium().crypto_auth_hmacsha512_keygen().toUByteArray() + } + + actual fun authHmacSha512(message: UByteArray, key: UByteArray): UByteArray { + return getSodium().crypto_auth_hmacsha512( + message.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } + + actual fun authHmacSha512Verify( + tag: UByteArray, + message: UByteArray, + key: UByteArray + ): Boolean { + return getSodium().crypto_auth_hmacsha512_verify( + tag.toUInt8Array(), + message.toUInt8Array(), + key.toUInt8Array() + ) + } + +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/box/Box.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/box/Box.kt new file mode 100644 index 0000000..376f4a6 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/box/Box.kt @@ -0,0 +1,200 @@ +package com.ionspin.kotlin.crypto.box + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array +import org.khronos.webgl.Uint8Array + +actual object Box { + /** + * The crypto_box_keypair() function randomly generates a secret key and a corresponding public key. + * The public key is put into pk (crypto_box_PUBLICKEYBYTES bytes) and the secret key into + * sk (crypto_box_SECRETKEYBYTES bytes). + */ + actual fun keypair(): BoxKeyPair { + val keypair = getSodium().crypto_box_keypair() + return BoxKeyPair( + (keypair.publicKey as Uint8Array).toUByteArray(), + (keypair.privateKey as Uint8Array).toUByteArray() + ) + } + + /** + * Using crypto_box_seed_keypair(), the key pair can also be deterministically derived from a single key seed (crypto_box_SEEDBYTES bytes). + */ + actual fun seedKeypair(seed: UByteArray): BoxKeyPair { + val keypair = getSodium().crypto_box_seed_keypair(seed.toUInt8Array()) + return BoxKeyPair( + (keypair.publicKey as Uint8Array).toUByteArray(), + (keypair.privateKey as Uint8Array).toUByteArray() + ) + } + + /** + * The crypto_box_easy() function encrypts a message m whose length is mlen bytes, with a recipient's public key pk, a sender's secret key sk and a nonce n. + * n should be crypto_box_NONCEBYTES bytes. + * c should be at least crypto_box_MACBYTES + mlen bytes long. + * This function writes the authentication tag, whose length is crypto_box_MACBYTES bytes, in c, + * immediately followed by the encrypted message, whose length is the same as the plaintext: mlen. + */ + actual fun easy( + message: UByteArray, + nonce: UByteArray, + recipientsPublicKey: UByteArray, + sendersSecretKey: UByteArray + ): UByteArray { + return getSodium().crypto_box_easy( + message.toUInt8Array(), + nonce.toUInt8Array(), + recipientsPublicKey.toUInt8Array(), + sendersSecretKey.toUInt8Array(), + ).toUByteArray() + + } + + /** + * The crypto_box_open_easy() function verifies and decrypts a ciphertext produced by crypto_box_easy(). + * c is a pointer to an authentication tag + encrypted message combination, as produced by crypto_box_easy(). clen is the length of this authentication tag + encrypted message combination. Put differently, clen is the number of bytes written by crypto_box_easy(), which is crypto_box_MACBYTES + the length of the message. + * The nonce n has to match the nonce used to encrypt and authenticate the message. + * pk is the public key of the sender that encrypted the message. sk is the secret key of the recipient that is willing to verify and decrypt it. + * The function throws [BoxCorruptedOrTamperedDataException] if the verification fails. + */ + actual fun openEasy( + ciphertext: UByteArray, + nonce: UByteArray, + sendersPublicKey: UByteArray, + recipientsSecretKey: UByteArray + ): UByteArray { + try { + return getSodium().crypto_box_open_easy( + ciphertext.toUInt8Array(), + nonce.toUInt8Array(), + sendersPublicKey.toUInt8Array(), + recipientsSecretKey.toUInt8Array(), + ).toUByteArray() + } catch (error: Throwable) { + throw BoxCorruptedOrTamperedDataException() + } + + } + + /** + * The crypto_box_beforenm() function computes a shared secret key given a public key pk and a secret key sk, + * and puts it into k (crypto_box_BEFORENMBYTES bytes). + */ + actual fun beforeNM(publicKey: UByteArray, secretKey: UByteArray): UByteArray { + return getSodium().crypto_box_beforenm( + publicKey.toUInt8Array(), + secretKey.toUInt8Array() + ).toUByteArray() + } + + /** + * The _afternm variants of the previously described functions accept a precalculated shared secret key k instead of a key pair. + */ + actual fun easyAfterNM( + message: UByteArray, + nonce: UByteArray, + precomputedKey: UByteArray + ): UByteArray { + return getSodium().crypto_box_easy_afternm( + message.toUInt8Array(), + nonce.toUInt8Array(), + precomputedKey.toUInt8Array() + ).toUByteArray() + } + + /** + * The _afternm variants of the previously described functions accept a precalculated shared secret key k instead of a key pair. + */ + actual fun openEasyAfterNM( + ciphertext: UByteArray, + nonce: UByteArray, + precomputedKey: UByteArray + ): UByteArray { + try { + return getSodium().crypto_box_open_easy_afternm( + ciphertext.toUInt8Array(), + nonce.toUInt8Array(), + precomputedKey.toUInt8Array(), + ).toUByteArray() + } catch (error: Throwable) { + throw BoxCorruptedOrTamperedDataException() + } + } + + /** + * This function encrypts a message m of length mlen with a nonce n and a secret key sk for a recipient whose + * public key is pk, and puts the encrypted message into c. + * Exactly mlen bytes will be put into c, since this function does not prepend the authentication tag. + * The tag, whose size is crypto_box_MACBYTES bytes, will be put into mac. + */ + actual fun detached( + message: UByteArray, + nonce: UByteArray, + recipientsPublicKey: UByteArray, + sendersSecretKey: UByteArray + ): BoxEncryptedDataAndTag { + val detached = getSodium().crypto_box_detached( + message.toUInt8Array(), + nonce.toUInt8Array(), + recipientsPublicKey.toUInt8Array(), + sendersSecretKey.toUInt8Array(), + ) + return BoxEncryptedDataAndTag( + (detached.ciphertext as Uint8Array).toUByteArray(), + (detached.mac as Uint8Array).toUByteArray() + ) + } + + /** + * The crypto_box_open_detached() function verifies and decrypts an encrypted message c whose length is clen using the recipient's secret key sk and the sender's public key pk. + * clen doesn't include the tag, so this length is the same as the plaintext. + * The plaintext is put into m after verifying that mac is a valid authentication tag for this ciphertext, with the given nonce n and key k. + * The function throws [BoxCorruptedOrTamperedDataException] if the verification fails. + */ + actual fun openDetached( + ciphertext: UByteArray, + tag: UByteArray, + nonce: UByteArray, + sendersPublicKey: UByteArray, + recipientsSecretKey: UByteArray + ): UByteArray { + try { + return getSodium().crypto_box_open_detached( + ciphertext.toUInt8Array(), + tag.toUInt8Array(), + nonce.toUInt8Array(), + sendersPublicKey.toUInt8Array(), + recipientsSecretKey.toUInt8Array(), + ).toUByteArray() + } catch (error: Throwable) { + throw BoxCorruptedOrTamperedDataException() + } + } + + actual fun seal(message: UByteArray, recipientsPublicKey: UByteArray): UByteArray { + return getSodium().crypto_box_seal( + message.toUInt8Array(), + recipientsPublicKey.toUInt8Array() + ).toUByteArray() + } + + actual fun sealOpen( + ciphertext: UByteArray, + recipientsPublicKey: UByteArray, + recipientsSecretKey: UByteArray + ): UByteArray { + try { + return getSodium().crypto_box_seal_open( + ciphertext.toUInt8Array(), + recipientsPublicKey.toUInt8Array(), + recipientsSecretKey.toUInt8Array(), + ).toUByteArray() + } catch (error: Throwable) { + throw BoxCorruptedOrTamperedDataException() + } + } + + +} \ No newline at end of file diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt new file mode 100644 index 0000000..3ea5001 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt @@ -0,0 +1,82 @@ +package com.ionspin.kotlin.crypto.generichash + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array +import org.khronos.webgl.Uint8Array + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 21-Aug-2020 + */ + +actual typealias GenericHashStateInternal = Any + +actual object GenericHash { + actual fun genericHash( + message: UByteArray, + requestedHashLength: Int, + key: UByteArray? + ): UByteArray { + return getSodium().crypto_generichash( + requestedHashLength, + message.toUInt8Array(), + key?.toUInt8Array() ?: Uint8Array(0) + ).toUByteArray() + } + + actual fun genericHashInit( + requestedHashLength: Int, + key: UByteArray? + ): GenericHashState { + val state = getSodium().crypto_generichash_init(key?.toUInt8Array() ?: Uint8Array(0), requestedHashLength) + return GenericHashState(requestedHashLength, state) + } + + actual fun genericHashUpdate( + state: GenericHashState, + messagePart: UByteArray + ) { + getSodium().crypto_generichash_update(state.internalState, messagePart.toUInt8Array()) + } + + actual fun genericHashFinal(state: GenericHashState): UByteArray { + return getSodium().crypto_generichash_final(state.internalState, state.hashLength).toUByteArray() + } + + actual fun genericHashKeygen(): UByteArray { + return getSodium().crypto_generichash_keygen().toUByteArray() + } +// -- Not present in LazySodium nor libsodium.js +// actual fun blake2b(message: UByteArray, requestedHashLength: Int, key: UByteArray?) : UByteArray { +// return getSodium().crypto_generichash_blake2b( +// requestedHashLength, +// message.toUInt8Array(), +// key?.toUInt8Array() ?: Uint8Array(0) +// ).toUByteArray() +// } +// +// actual fun blake2bInit( +// requestedHashLength: Int, +// key: UByteArray? +// ): Blake2bState { +// val state = getSodium().crypto_generichash_blake2b_init(key?.toUInt8Array() ?: Uint8Array(0), requestedHashLength) +// return Blake2bState(requestedHashLength, state) +// } +// +// actual fun blake2bUpdate( +// state: GenericHashState, +// messagePart: UByteArray +// ) { +// getSodium().crypto_generichash_blake2b_update(state.internalState, messagePart.toUInt8Array()) +// } +// +// actual fun blake2bFinal(state: GenericHashState): UByteArray { +// return getSodium().crypto_generichash_blake2b_final(state.internalState, state.hashLength).toUByteArray() +// } +// +// actual fun blake2bKeygen(): UByteArray { +// return getSodium().crypto_generichash_blake2b_keygen().toUByteArray() +// } +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt new file mode 100644 index 0000000..5956ba8 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt @@ -0,0 +1,45 @@ +package com.ionspin.kotlin.crypto.hash + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array + +actual typealias Sha256State = Any +actual typealias Sha512State = Any + +actual object Hash { + + actual fun sha256(data: UByteArray): UByteArray { + return getSodium().crypto_hash_sha256(data.toUInt8Array()).toUByteArray() + } + + actual fun sha256Init(): Sha256State { + return getSodium().crypto_hash_sha256_init() + } + + actual fun sha256Update(state: Sha256State, data: UByteArray) { + getSodium().crypto_hash_sha256_update(state, data.toUInt8Array()) + } + + actual fun sha256Final(state: Sha256State): UByteArray { + return getSodium().crypto_hash_sha256_final(state).toUByteArray() + } + + actual fun sha512(data: UByteArray): UByteArray { + return getSodium().crypto_hash_sha512(data.toUInt8Array()).toUByteArray() + } + + actual fun sha512Init(): Sha512State { + return getSodium().crypto_hash_sha512_init() + } + + actual fun sha512Update(state: Sha512State, data: UByteArray) { + getSodium().crypto_hash_sha512_update(state, data.toUInt8Array()) + } + + actual fun sha512Final(state: Sha512State): UByteArray { + return getSodium().crypto_hash_sha512_final(state).toUByteArray() + } + + +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt new file mode 100644 index 0000000..8cf0a31 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt @@ -0,0 +1,43 @@ +package com.ionspin.kotlin.crypto.kdf + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array + +actual object Kdf { + /** + * The deriveFromKey function derives a subkeyId-th subkey of length subkeyLenght bytes using + * the master key key and the context ctx. + * subkey_id can be any value up to (2^32) because javascript doesn't support long types. + * subkey_len has to be between crypto_kdf_BYTES_MIN (inclusive) and crypto_kdf_BYTES_MAX (inclusive). + * Similar to a type, the context ctx is a 8 characters string describing what the key is going to be used for. + * Its purpose is to mitigate accidental bugs by separating domains. The same function used with the same key but + * in two distinct contexts is likely to generate two different outputs. + * Contexts don't have to be secret and can have a low entropy. + * Examples of contexts include UserName, __auth__, pictures and userdata. + * They must be crypto_kdf_CONTEXTBYTES bytes long. + * If more convenient, it is also fine to use a single global context for a whole application. This will still + * prevent the same keys from being mistakenly used by another application. + */ + actual fun deriveFromKey( + subkeyId: UInt, + subkeyLength: Int, + context: String, + masterKey: UByteArray + ): UByteArray { + return getSodium().crypto_kdf_derive_from_key( + subkeyLength.toUInt(), + subkeyId, + context, + masterKey.toUInt8Array() + ).toUByteArray() + } + + /** + * The crypto_kdf_keygen() function creates a master key. + */ + actual fun keygen(): UByteArray { + return getSodium().crypto_kdf_keygen().toUByteArray() + } + +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/keyexchange/KeyExchange.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/keyexchange/KeyExchange.kt new file mode 100644 index 0000000..2f40309 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/keyexchange/KeyExchange.kt @@ -0,0 +1,57 @@ +package com.ionspin.kotlin.crypto.keyexchange + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array +import org.khronos.webgl.Uint8Array + +actual object KeyExchange { + actual fun clientSessionKeys(clientPublicKey: UByteArray, clientSecretKey: UByteArray, serverPublicKey: UByteArray) : KeyExchangeSessionKeyPair { + + + val result = getSodium().crypto_kx_client_session_keys( + clientPublicKey.toUInt8Array(), + clientSecretKey.toUInt8Array(), + serverPublicKey.toUInt8Array() + ) + + val receiveKey = (result.sharedRx as Uint8Array).toUByteArray() + val sendKey = (result.sharedTx as Uint8Array).toUByteArray() + + + + return KeyExchangeSessionKeyPair(receiveKey, sendKey) + } + + actual fun keypair() : KeyExchangeKeyPair { + val result = getSodium().crypto_kx_keypair() + + val publicKey = (result.publicKey as Uint8Array).toUByteArray() + val secretKey = (result.privateKey as Uint8Array).toUByteArray() + + return KeyExchangeKeyPair(publicKey, secretKey) + } + + actual fun seedKeypair(seed: UByteArray) : KeyExchangeKeyPair { + val result = getSodium().crypto_kx_seed_keypair(seed.toUInt8Array()) + + val publicKey = (result.publicKey as Uint8Array).toUByteArray() + val secretKey = (result.privateKey as Uint8Array).toUByteArray() + + return KeyExchangeKeyPair(publicKey, secretKey) + } + + actual fun serverSessionKeys(serverPublicKey: UByteArray, serverSecretKey: UByteArray, clientPublicKey: UByteArray) : KeyExchangeSessionKeyPair { + + val result = getSodium().crypto_kx_server_session_keys( + serverPublicKey.toUInt8Array(), + serverSecretKey.toUInt8Array(), + clientPublicKey.toUInt8Array() + ) + + val receiveKey = (result.sharedRx as Uint8Array).toUByteArray() + val sendKey = (result.sharedTx as Uint8Array).toUByteArray() + + return KeyExchangeSessionKeyPair(receiveKey, sendKey) + } +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt new file mode 100644 index 0000000..82bf6c4 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt @@ -0,0 +1,98 @@ +package com.ionspin.kotlin.crypto.pwhash + +import com.ionspin.kotlin.crypto.getSodium +import com.ionspin.kotlin.crypto.util.encodeToUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array + +actual object PasswordHash { + /** + * The crypto_pwhash() function derives an outlen bytes long key from a password passwd whose length is passwdlen + * and a salt whose fixed length is crypto_pwhash_SALTBYTES bytes. passwdlen should be at least crypto_pwhash_ + * PASSWD_MIN and crypto_pwhash_PASSWD_MAX. outlen should be at least crypto_pwhash_BYTES_MIN = 16 (128 bits) and + * at most crypto_pwhash_BYTES_MAX. + * + * See https://libsodium.gitbook.io/doc/password_hashing/default_phf for more details + */ + actual fun pwhash( + outputLength: Int, + password: String, + salt: UByteArray, + opsLimit: ULong, + memLimit: Int, + algorithm: Int + ): UByteArray { + if (opsLimit > UInt.MAX_VALUE) { + throw RuntimeException("Javascript doesnt support more than ${UInt.MAX_VALUE} for opslimit") + } + return getSodium().crypto_pwhash( + outputLength.toUInt(), + password.encodeToUByteArray().toUInt8Array(), + salt.toUInt8Array(), + opsLimit.toUInt(), + memLimit.toUInt(), + algorithm.toUInt() + ).toUByteArray() + } + + /** + * The crypto_pwhash_str() function puts an ASCII encoded string into out, which includes: + * the result of a memory-hard, CPU-intensive hash function applied to the password passwd of length passwdlen + * the automatically generated salt used for the previous computation + * the other parameters required to verify the password, including the algorithm identifier, its version, opslimit and memlimit. + * out must be large enough to hold crypto_pwhash_STRBYTES bytes, but the actual output string may be shorter. + * The output string is zero-terminated, includes only ASCII characters and can be safely stored into SQL databases + * and other data stores. No extra information has to be stored in order to verify the password. + * The function returns 0 on success and -1 if it didn't complete successfully. + */ + actual fun str(password: String, opslimit: ULong, memlimit: Int): String { + if (opslimit > UInt.MAX_VALUE) { + throw RuntimeException("Javascript doesnt support more than ${UInt.MAX_VALUE} for opslimit") + } + return getSodium().crypto_pwhash_str( + password.encodeToUByteArray().toUInt8Array(), + opslimit.toUInt(), + memlimit.toUInt() + ) + } + + /** + * Check if a password verification string str matches the parameters opslimit and memlimit, and the current default algorithm. + * The function returns 1 if the string appears to be correct, but doesn't match the given parameters. In that situation, applications may want to compute a new hash using the current parameters the next time the user logs in. + * The function returns 0 if the parameters already match the given ones. + * It returns -1 on error. If it happens, applications may want to compute a correct hash the next time the user logs in. + */ + actual fun strNeedsRehash( + passwordHash: String, + opslimit: ULong, + memlimit: Int + ): Int { + if (opslimit > UInt.MAX_VALUE) { + throw RuntimeException("Javascript doesnt support more than ${UInt.MAX_VALUE} for opslimit") + } + return if ( + getSodium().crypto_pwhash_str_needs_rehash( + passwordHash, + opslimit.toUInt(), + memlimit.toUInt() + ) + ) { + 1 + } else { + 0 + } + } + + /** + * his function verifies that str is a valid password verification string (as generated by crypto_pwhash_str()) for passwd whose length is passwdlen. + * str has to be zero-terminated. + * It returns 0 if the verification succeeds, and -1 on error. + */ + actual fun strVerify(passwordHash: String, password: String): Boolean { + return getSodium().crypto_pwhash_str_verify( + passwordHash, + password.encodeToUByteArray().toUInt8Array() + ) + } + +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/scalarmult/ScalarMultiplication.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/scalarmult/ScalarMultiplication.kt new file mode 100644 index 0000000..ce98b3b --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/scalarmult/ScalarMultiplication.kt @@ -0,0 +1,40 @@ +package com.ionspin.kotlin.crypto.scalarmult + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array + +actual object ScalarMultiplication { + /** + * This function can be used to compute a shared secret q given a user's secret key and another user's public key. + * n is crypto_scalarmult_SCALARBYTES bytes long, p and the output are crypto_scalarmult_BYTES bytes long. + * q represents the X coordinate of a point on the curve. As a result, the number of possible keys is limited to + * the group size (≈2^252), which is smaller than the key space. + * For this reason, and to mitigate subtle attacks due to the fact many (p, n) pairs produce the same result, + * using the output of the multiplication q directly as a shared key is not recommended. + * A better way to compute a shared key is h(q ‖ pk1 ‖ pk2), with pk1 and pk2 being the public keys. + * By doing so, each party can prove what exact public key they intended to perform a key exchange with + * (for a given public key, 11 other public keys producing the same shared secret can be trivially computed). + * This can be achieved with the following code snippet: + */ + actual fun scalarMultiplication(secretKeyN: UByteArray, publicKeyP: UByteArray): UByteArray { + val result = getSodium().crypto_scalarmult(secretKeyN.toUInt8Array(), publicKeyP.toUInt8Array()) + + return result.toUByteArray() + } + + /** + * Given a user's secret key n (crypto_scalarmult_SCALARBYTES bytes), the crypto_scalarmult_base() function + * computes the user's public key and puts it into q (crypto_scalarmult_BYTES bytes). + * crypto_scalarmult_BYTES and crypto_scalarmult_SCALARBYTES are provided for consistency, + * but it is safe to assume that crypto_scalarmult_BYTES == crypto_scalarmult_SCALARBYTES. + */ + actual fun scalarMultiplicationBase( + secretKeyN: UByteArray + ): UByteArray { + val result = getSodium().crypto_scalarmult_base( secretKeyN.toUInt8Array()) + + return result.toUByteArray() + } + +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt new file mode 100644 index 0000000..4ff9188 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt @@ -0,0 +1,74 @@ +package com.ionspin.kotlin.crypto.secretbox + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array +import org.khronos.webgl.Uint8Array + +actual object SecretBox { + actual fun easy(message: UByteArray, nonce: UByteArray, key: UByteArray): UByteArray { + return getSodium().crypto_secretbox_easy( + message.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ).toUByteArray() + } + + actual fun openEasy( + ciphertext: UByteArray, + nonce: UByteArray, + key: UByteArray + ): UByteArray { + try { + val decryptionResult = getSodium().crypto_secretbox_open_easy( + ciphertext.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ) + return (decryptionResult as Uint8Array).toUByteArray() + } catch (error: Throwable) { + throw SecretBoxCorruptedOrTamperedDataExceptionOrInvalidKey() + } + } + + actual fun detached( + message: UByteArray, + nonce: UByteArray, + key: UByteArray + ): SecretBoxEncryptedDataAndTag { + val result = getSodium().crypto_secretbox_detached( + message.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ) + return SecretBoxEncryptedDataAndTag( + (result.cipher as Uint8Array).toUByteArray(), + (result.mac as Uint8Array).toUByteArray() + ) + } + + actual fun openDetached( + ciphertext: UByteArray, + tag: UByteArray, + nonce: UByteArray, + key: UByteArray + ): UByteArray { + try { + val decryptionResult = getSodium().crypto_secretbox_open_detached( + ciphertext.toUInt8Array(), + tag.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ) + return (decryptionResult as Uint8Array).toUByteArray() + } catch (error: Throwable) { + throw SecretBoxCorruptedOrTamperedDataExceptionOrInvalidKey() + } + + } + + actual fun keygen(): UByteArray { + return getSodium().crypto_secretbox_keygen().toUByteArray() + } + +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt new file mode 100644 index 0000000..27856e8 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt @@ -0,0 +1,58 @@ +package com.ionspin.kotlin.crypto.secretstream + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array +import org.khronos.webgl.Uint8Array + +actual typealias SecretStreamState = Any + +actual object SecretStream { + actual fun xChaCha20Poly1305InitPush(key: UByteArray): SecretStreamStateAndHeader { + val state = getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array()) + return SecretStreamStateAndHeader(state.state, (state.header as Uint8Array).toUByteArray()) + } + + actual fun xChaCha20Poly1305Push( + state: SecretStreamState, + message: UByteArray, + associatedData: UByteArray, + tag: UByte + ): UByteArray { + return getSodium().crypto_secretstream_xchacha20poly1305_push( + state, message.toUInt8Array(), associatedData.toUInt8Array(), tag + ).toUByteArray() + } + + actual fun xChaCha20Poly1305InitPull( + key: UByteArray, + header: UByteArray + ): SecretStreamStateAndHeader { + val state = getSodium().crypto_secretstream_xchacha20poly1305_init_pull(header.toUInt8Array(), key.toUInt8Array()) + return SecretStreamStateAndHeader(state, header) + } + + actual fun xChaCha20Poly1305Pull( + state: SecretStreamState, + ciphertext: UByteArray, + associatedData: UByteArray + ): DecryptedDataAndTag { + val dataAndTag = getSodium().crypto_secretstream_xchacha20poly1305_pull( + state, ciphertext.toUInt8Array(), associatedData.toUInt8Array() + ) + if (dataAndTag == false) { + throw SecretStreamCorruptedOrTamperedDataException() + } + return DecryptedDataAndTag((dataAndTag.message as Uint8Array).toUByteArray(), dataAndTag.tag) + + } + + actual fun xChaCha20Poly1305Keygen(): UByteArray { + return getSodium().crypto_shorthash_keygen().toUByteArray() + } + + actual fun xChaCha20Poly1305Rekey(state: SecretStreamState) { + getSodium().crypto_secretstream_xchacha20poly1305_rekey(state) + } + +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/shortinputhash/ShortHash.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/shortinputhash/ShortHash.kt new file mode 100644 index 0000000..df47ed7 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/shortinputhash/ShortHash.kt @@ -0,0 +1,21 @@ +package com.ionspin.kotlin.crypto.shortinputhash + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 21-Aug-2020 + */ +actual object ShortHash { + actual fun shortHash(data: UByteArray, key: UByteArray): UByteArray { + return getSodium().crypto_shorthash(data.toUInt8Array(), key.toUInt8Array()).toUByteArray() + } + + actual fun shortHashKeygen(): UByteArray { + return getSodium().crypto_shorthash_keygen().toUByteArray() + } + +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/signature/Signature.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/signature/Signature.kt new file mode 100644 index 0000000..6b6fb3b --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/signature/Signature.kt @@ -0,0 +1,161 @@ +package com.ionspin.kotlin.crypto.signature + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array +import org.khronos.webgl.Uint8Array + +actual typealias SignatureState = Any + +actual object Signature { + actual fun init(): SignatureState { + return getSodium().crypto_sign_init() + } + + actual fun update(state: SignatureState, data: UByteArray) { + getSodium().crypto_sign_update(state, data.toUInt8Array()) + } + + actual fun finalCreate( + state: SignatureState, + secretKey: UByteArray + ): UByteArray { + return getSodium().crypto_sign_final_create( + state, + secretKey.toUInt8Array() + ).toUByteArray() + } + + actual fun finalVerify( + state: SignatureState, + signature: UByteArray, + publicKey: UByteArray + ) { + val verificationResult = getSodium().crypto_sign_final_verify( + state, + signature.toUInt8Array(), + publicKey.toUInt8Array() + ) + if (verificationResult == false) { + throw InvalidSignatureException() + } + } + + /** + * The crypto_sign_keypair() function randomly generates a secret key and a corresponding public key. + * The public key is put into pk (crypto_sign_PUBLICKEYBYTES bytes) and the secret key into sk (crypto_sign_SECRETKEYBYTES bytes). + */ + actual fun keypair(): SignatureKeyPair { + val keypair = getSodium().crypto_sign_keypair() + return SignatureKeyPair( + (keypair.publicKey as Uint8Array).toUByteArray(), + (keypair.privateKey as Uint8Array).toUByteArray() + ) + } + + /** + * The crypto_sign_keypair() function randomly generates a secret key and a corresponding public key. + * The public key is put into pk (crypto_sign_PUBLICKEYBYTES bytes) and the secret key into sk (crypto_sign_SECRETKEYBYTES bytes). + * Using crypto_sign_seed_keypair(), the key pair can also be deterministically derived from a single key seed (crypto_sign_SEEDBYTES bytes). + */ + actual fun seedKeypair(seed: UByteArray): SignatureKeyPair { + val keypair = getSodium().crypto_sign_seed_keypair(seed.toUInt8Array()) + return SignatureKeyPair( + (keypair.publicKey as Uint8Array).toUByteArray(), + (keypair.privateKey as Uint8Array).toUByteArray() + ) + } + + /** + * The crypto_sign() function prepends a signature to a message m whose length is mlen bytes, using the secret key sk. + * The signed message, which includes the signature + a plain copy of the message, is put into sm, and is crypto_sign_BYTES + mlen bytes long. + */ + actual fun sign(message: UByteArray, secretKey: UByteArray): UByteArray { + return getSodium().crypto_sign( + message.toUInt8Array(), + secretKey.toUInt8Array() + ).toUByteArray() + } + + /** + * The crypto_sign_open() function checks that the signed message sm whose length is smlen bytes has a valid signature for the public key pk. + * If the signature is doesn't appear to be valid, the function throws an exception + */ + actual fun open(signedMessage: UByteArray, publicKey: UByteArray): UByteArray { + try { + return getSodium().crypto_sign_open( + signedMessage.toUInt8Array(), + publicKey.toUInt8Array() + ).toUByteArray() + } catch (error : Throwable) { + throw InvalidSignatureException() + } + } + + /** + * In detached mode, the signature is stored without attaching a copy of the original message to it. + * The crypto_sign_detached() function signs the message m whose length is mlen bytes, using the secret key sk, + * and puts the signature into sig, which can be up to crypto_sign_BYTES bytes long. + */ + actual fun detached(message: UByteArray, secretKey: UByteArray): UByteArray { + return getSodium().crypto_sign_detached( + message.toUInt8Array(), + secretKey.toUInt8Array() + ).toUByteArray() + } + + /** + * The crypto_sign_verify_detached() function verifies that sig is a valid signature for the message m whose length + * is mlen bytes, using the signer's public key pk. + */ + actual fun verifyDetached(signature: UByteArray, message: UByteArray, publicKey: UByteArray) { + val verificationResult = getSodium().crypto_sign_verify_detached( + signature.toUInt8Array(), + message.toUInt8Array(), + publicKey.toUInt8Array() + ) + + if (verificationResult == false) { + throw InvalidSignatureException() + } + } + + /** + * The crypto_sign_ed25519_pk_to_curve25519() function converts an Ed25519 public key ed25519_pk to an X25519 public key and stores it into x25519_pk. + */ + actual fun ed25519PkToCurve25519(ed25519PublicKey: UByteArray): UByteArray { + return getSodium().crypto_sign_ed25519_pk_to_curve25519( + ed25519PublicKey.toUInt8Array() + ).toUByteArray() + } + + /** + * The crypto_sign_ed25519_sk_to_curve25519() function converts an Ed25519 secret key ed25519_sk to an X25519 secret key and stores it into x25519_sk. + */ + actual fun ed25519SkToCurve25519(ed25519SecretKey: UByteArray): UByteArray { + return getSodium().crypto_sign_ed25519_sk_to_curve25519( + ed25519SecretKey.toUInt8Array() + ).toUByteArray() + } + + /** + * The secret key actually includes the seed (either a random seed or the one given to crypto_sign_seed_keypair()) as well as the public key. + * While the public key can always be derived from the seed, the precomputation saves a significant amount of CPU cycles when signing. + */ + actual fun ed25519SkToSeed(secretKey: UByteArray): UByteArray { + return getSodium().crypto_sign_ed25519_sk_to_seed( + secretKey.toUInt8Array() + ).toUByteArray() + } + + /** + * The secret key actually includes the seed (either a random seed or the one given to crypto_sign_seed_keypair()) as well as the public key. + * While the public key can always be derived from the seed, the precomputation saves a significant amount of CPU cycles when signing. + */ + actual fun ed25519SkToPk(secretKey: UByteArray): UByteArray { + return getSodium().crypto_sign_ed25519_sk_to_pk( + secretKey.toUInt8Array() + ).toUByteArray() + } + +} \ No newline at end of file diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/stream/Stream.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/stream/Stream.kt new file mode 100644 index 0000000..35a9348 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/stream/Stream.kt @@ -0,0 +1,122 @@ +package com.ionspin.kotlin.crypto.stream + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array + +actual object Stream { + actual fun chacha20(clen: Int, nonce: UByteArray, key: UByteArray): UByteArray { + //Note, unlike the other ones, here the positions of key and nonce are reversed. + val result = getSodium().crypto_stream_chacha20(clen.toUInt(), key.toUInt8Array(), nonce.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun chacha20IetfXor( + message: UByteArray, + nonce: UByteArray, + key: UByteArray + ): UByteArray { + val result = getSodium().crypto_stream_chacha20_ietf_xor( + message.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ) + + return result.toUByteArray() + } + + actual fun chacha20IetfXorIc( + message: UByteArray, + nonce: UByteArray, + initialCounter: UInt, + key: UByteArray + ): UByteArray { + val result = getSodium().crypto_stream_chacha20_ietf_xor_ic( + message.toUInt8Array(), + nonce.toUInt8Array(), + initialCounter, + key.toUInt8Array() + ) + + return result.toUByteArray() + } + + actual fun chacha20Keygen(): UByteArray { + val result = getSodium().crypto_stream_chacha20_keygen() + + return result.toUByteArray() + } + + actual fun chacha20Xor( + message: UByteArray, + nonce: UByteArray, + key: UByteArray + ): UByteArray { + val result = getSodium().crypto_stream_chacha20_xor( + message.toUInt8Array(), + nonce.toUInt8Array(), + key.toUInt8Array() + ) + + return result.toUByteArray() + } + + actual fun chacha20XorIc( + message: UByteArray, + nonce: UByteArray, + initialCounter: ULong, + key: UByteArray + ): UByteArray { + if (initialCounter > UInt.MAX_VALUE) { + throw RuntimeException("Javascript doesnt support more than ${UInt.MAX_VALUE} for initial counter") + } + val result = getSodium().crypto_stream_chacha20_xor_ic( + message.toUInt8Array(), + nonce.toUInt8Array(), + initialCounter.toUInt(), + key.toUInt8Array() + ) + + + return result.toUByteArray() + } + +// actual fun xChacha20Keygen(): UByteArray { +// val result = getSodium().crypto_stream_xchacha20_keygen() +// +// return result.toUByteArray() +// } +// +// actual fun xChacha20Xor( +// message: UByteArray, +// nonce: UByteArray, +// key: UByteArray +// ): UByteArray { +// val result = getSodium().crypto_stream_xchacha20_xor( +// message.toUInt8Array(), +// nonce.toUInt8Array(), +// key.toUInt8Array() +// ) +// +// return result.toUByteArray() +// } +// +// actual fun xChacha20XorIc( +// message: UByteArray, +// nonce: UByteArray, +// initialCounter: ULong, +// key: UByteArray +// ): UByteArray { +// val result = getSodium().crypto_stream_xchacha20_xor_ic( +// message.toUInt8Array(), +// nonce.toUInt8Array(), +// initialCounter.toUInt(), +// key.toUInt8Array() +// ) +// +// return result.toUByteArray() +// } + + +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumRandom.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumRandom.kt new file mode 100644 index 0000000..1854710 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumRandom.kt @@ -0,0 +1,48 @@ +package com.ionspin.kotlin.crypto.util + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 27-Sep-2020 + */ +actual object LibsodiumRandom { + /** + * The randombytes_buf() function fills size bytes starting at buf with an unpredictable sequence of bytes. + */ + actual fun buf(size: Int): UByteArray { + return getSodium().randombytes_buf(size).toUByteArray() + } + + /** + * The randombytes_buf_deterministic function stores size bytes into buf indistinguishable from random bytes without knowing seed. + * For a given seed, this function will always output the same sequence. size can be up to 2^31 (~8GB) because we use kotlin arrays + * and they are limited by Int primitive type + * seed is randombytes_SEEDBYTES bytes long. + * This function is mainly useful for writing tests, and was introduced in libsodium 1.0.12. Under the hood, it uses the ChaCha20 stream cipher. + * + */ + actual fun bufDeterministic(size: Int, seed: UByteArray): UByteArray { + return getSodium().randombytes_buf_deterministic(size.toUInt(), seed.toUInt8Array()).toUByteArray() + } + + /** + * The randombytes_random() function returns an unpredictable value between 0 and 0xffffffff (included). + */ + actual fun random(): UInt { + return getSodium().randombytes_random() + } + + /** + * The randombytes_uniform() function returns an unpredictable value between 0 and upper_bound (excluded). Unlike r + * andombytes_random() % upper_bound, it guarantees a uniform distribution of the possible output values even when + * upper_bound is not a power of 2. Note that an upper_bound < 2 leaves only a single element to be chosen, namely 0 + */ + actual fun uniform(upperBound: UInt): UInt { + return getSodium().randombytes_uniform(upperBound) + } + +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumUtil.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumUtil.kt new file mode 100644 index 0000000..e9c83fd --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumUtil.kt @@ -0,0 +1,50 @@ +package com.ionspin.kotlin.crypto.util + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array + +actual object LibsodiumUtil { + actual fun memcmp(first: UByteArray, second: UByteArray): Boolean { + return getSodium().memcmp(first.toUInt8Array(), second.toUInt8Array()) + } + + actual fun memzero(target: UByteArray) { + // libsodium.js does this as well, and theres no clear way at the moment of casting ubytearray to uint8array + // although I feel like there should be a way to work around it + (target.indices).forEach { + index -> target[index] = 0U + } + } + + actual fun pad(unpaddedData: UByteArray, blocksize: Int): UByteArray { + return getSodium().pad(unpaddedData.toUInt8Array(), blocksize).toUByteArray() + } + + actual fun unpad(paddedData: UByteArray, blocksize: Int): UByteArray { + return getSodium().unpad(paddedData.toUInt8Array(), blocksize).toUByteArray() + } + + actual fun toBase64( + data: UByteArray, + variant: Base64Variants + ): String { + return getSodium().to_base64(data.toUInt8Array(), variant.value) + } + + actual fun toHex(data: UByteArray): String { + return getSodium().to_hex(data.toUInt8Array()) + } + + actual fun fromBase64( + data: String, + variant: Base64Variants + ): UByteArray { + return getSodium().from_base64(data, variant.value).toUByteArray() + } + + actual fun fromHex(data: String): UByteArray { + return getSodium().from_hex(data).toUByteArray() + } + +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/debug/test/DebugTest.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/debug/test/DebugTest.kt new file mode 100644 index 0000000..43b49bc --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/debug/test/DebugTest.kt @@ -0,0 +1,113 @@ +//package debug.test +// +//import com.ionspin.kotlin.crypto.getSodium +//import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +//import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array +//import kotlin.Any +//import kotlin.Int +//import kotlin.UByte +//import kotlin.UByteArray +//import org.khronos.webgl.Uint8Array +// +//actual typealias Sha256State = Any +// +//actual typealias Sha512State = Any +// +//actual typealias GenericHashState = Any +// +//actual typealias SecretStreamState = Any +// +//actual class Crypto internal actual constructor() { +// /** +// * Initialize the SHA256 hash +// * returns sha 256 state +// */ +// actual fun crypto_hash_sha256_init(): dynamic { +// println("Debug crypto_hash_sha256_init") +// val result = js("getSodium().crypto_hash_sha256_init()") +// return result +// } +// +// actual fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray) { +// println("Debug crypto_hash_sha256_update") +// getSodium().crypto_hash_sha256_update(state, input.toUInt8Array()) +// } +// +// actual fun crypto_hash_sha256_final(state: Sha256State): UByteArray { +// println("Debug crypto_hash_sha256_final") +// return getSodium().crypto_hash_sha256_final(state).toUByteArray() +// } +// +// actual fun crypto_hash_sha512_init(): dynamic { +// println("Debug crypto_hash_sha512_init") +// val result = js("getSodium().crypto_hash_sha512_init()") +// return result +// } +// +// actual fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray) { +// println("Debug crypto_hash_sha512_update") +// getSodium().crypto_hash_sha512_update(state, input.toUInt8Array()) +// } +// +// actual fun crypto_hash_sha512_final(state: Sha512State): UByteArray { +// println("Debug crypto_hash_sha512_final") +// return getSodium().crypto_hash_sha512_final(state).toUByteArray() +// } +// +// actual fun crypto_generichash_init(key: UByteArray, outlen: Int): dynamic { +// println("Debug crypto_generichash_init") +// return getSodium().crypto_generichash_init(key.toUInt8Array(), outlen) +// } +// +// /** +// * Initialize a state and generate a random header. Both are returned inside +// * `SecretStreamStateAndHeader` object. +// */ +// actual fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray): +// SecretStreamStateAndHeader { +// println("Debug crypto_secretstream_xchacha20poly1305_init_push") +// val stateAndHeader = +// getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array()) +// val state = stateAndHeader.state +// val header = (stateAndHeader.header as Uint8Array).toUByteArray() +// return SecretStreamStateAndHeader(state, header) +// } +// +// /** +// * Initialize state from header and key. The state can then be used for decryption. +// */ +// actual fun crypto_secretstream_xchacha20poly1305_init_pull(header: UByteArray, key: UByteArray): +// dynamic { +// println("Debug crypto_secretstream_xchacha20poly1305_init_pull") +// return getSodium().crypto_secretstream_xchacha20poly1305_init_pull(header.toUInt8Array(), +// key.toUInt8Array()) +// } +// +// /** +// * Encrypt next block of data using the previously initialized state. Returns encrypted block. +// */ +// actual fun crypto_secretstream_xchacha20poly1305_push( +// state: SecretStreamState, +// m: UByteArray, +// ad: UByteArray, +// tag: UByte +// ): UByteArray { +// println("Debug crypto_secretstream_xchacha20poly1305_push") +// return getSodium().crypto_secretstream_xchacha20poly1305_push(state, m.toUInt8Array(), +// ad.toUInt8Array(), tag).toUByteArray() +// } +// +// /** +// * Decrypt next block of data using the previously initialized state. Returns decrypted block. +// */ +// actual fun crypto_secretstream_xchacha20poly1305_pull( +// state: SecretStreamState, +// c: UByteArray, +// ad: UByteArray +// ): DecryptedDataAndTag { +// println("Debug crypto_secretstream_xchacha20poly1305_pull") +//// return getSodium().crypto_secretstream_xchacha20poly1305_pull(state, c.toUInt8Array(), +//// ad.toUInt8Array()) +// return DecryptedDataAndTag(ubyteArrayOf(), 0U) +// } +//} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/libsodium.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/libsodium.kt new file mode 100644 index 0000000..85ff707 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/libsodium.kt @@ -0,0 +1,31 @@ +@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 + +@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 + + + + + From 0a561e4f10a5a4c656e04c3ec0776248f075fe6c Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Sat, 23 Nov 2024 23:32:36 +0300 Subject: [PATCH 03/27] Wasm connected (hopefully) --- buildSrc/src/main/kotlin/Deps.kt | 4 ++-- .../build.gradle.kts | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 6022e06..8ff2a7a 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -73,8 +73,8 @@ object Deps { } object wasmJs { - val stdLib = "stdlib-wasm" - val test = "test-wasm" +// val stdLib = "stdlib-wasm" +// val test = "test-wasm" // TODO: написано от балды \/ // val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:${Versions.kotlinCoroutines}" // val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:${Versions.kotlinSerialization}" diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index 43158aa..f21cbb0 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -569,13 +569,13 @@ kotlin { val wasmJsMain by getting { // TODO: разобраться (и с test) dependencies { - implementation(kotlin(Deps.wasmJs.stdLib)) + // implementation(kotlin(Deps.wasmJs.stdLib)) implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) } } val wasmJsTest by getting { dependencies { - implementation(kotlin(Deps.wasmJs.test)) +// implementation(kotlin(Deps.wasmJs.test)) implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) } } @@ -732,12 +732,12 @@ tasks { // } // TODO: ваще не жс тест, помогите - val wasmJsBrowserTest by getting(KotlinJsTest::class) { - testLogging { - events("PASSED", "FAILED", "SKIPPED") - showStandardStreams = true - } - } +// val wasmJsBrowserTest by getting(KotlinJsTest::class) { +// testLogging { +// events("PASSED", "FAILED", "SKIPPED") +// showStandardStreams = true +// } +// } val jsBrowserTest by getting(KotlinJsTest::class) { testLogging { From 99e6316120b4e3e8fd5e7bc5c013a04a2f99068b Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Wed, 27 Nov 2024 21:27:28 +0300 Subject: [PATCH 04/27] Deleted @JsNonModule, dynamic (and Any) type switched to JsAny --- .../kotlin/crypto/JsSodiumInterface.kt | 73 +++++++++---------- .../kotlin/crypto/generichash/GenericHash.kt | 5 +- .../com/ionspin/kotlin/crypto/hash/Hash.kt | 7 +- 3 files changed, 45 insertions(+), 40 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt index ed74443..a1af2a2 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -10,7 +10,6 @@ import org.khronos.webgl.Uint8Array * on 27-May-2020 */ @JsModule("libsodium-wrappers-sumo") -@JsNonModule external object JsSodiumInterface { @@ -26,13 +25,13 @@ external object JsSodiumInterface { // ---- Generic hash ---- // Updateable @JsName("crypto_generichash_init") - fun crypto_generichash_init(key : Uint8Array, hashLength: Int) : dynamic + fun crypto_generichash_init(key : Uint8Array, hashLength: Int) : JsAny @JsName("crypto_generichash_update") - fun crypto_generichash_update(state: dynamic, inputMessage: Uint8Array) + fun crypto_generichash_update(state: JsAny, inputMessage: Uint8Array) @JsName("crypto_generichash_final") - fun crypto_generichash_final(state: dynamic, hashLength: Int) : Uint8Array + fun crypto_generichash_final(state: JsAny, hashLength: Int) : Uint8Array @JsName("crypto_generichash_keygen") fun crypto_generichash_keygen() : Uint8Array @@ -45,13 +44,13 @@ external object JsSodiumInterface { fun crypto_generichash_blake2b(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array @JsName("crypto_generichash_blake2b_init") - fun crypto_generichash_blake2b_init(key : Uint8Array, hashLength: Int) : dynamic + fun crypto_generichash_blake2b_init(key : Uint8Array, hashLength: Int) : JsAny @JsName("crypto_generichash_blake2b_update") - fun crypto_generichash_blake2b_update(state: dynamic, inputMessage: Uint8Array) + fun crypto_generichash_blake2b_update(state: JsAny, inputMessage: Uint8Array) @JsName("crypto_generichash_blake2b_final") - fun crypto_generichash_blake2b_final(state: dynamic, hashLength: Int) : Uint8Array + fun crypto_generichash_blake2b_final(state: JsAny, hashLength: Int) : Uint8Array @JsName("crypto_generichash_blake2b_keygen") fun crypto_generichash_blake2b_keygen() : Uint8Array @@ -68,22 +67,22 @@ external object JsSodiumInterface { @JsName("crypto_hash_sha256_init") - fun crypto_hash_sha256_init() : dynamic + fun crypto_hash_sha256_init() : JsAny @JsName("crypto_hash_sha256_update") - fun crypto_hash_sha256_update(state: dynamic, message: Uint8Array) + fun crypto_hash_sha256_update(state: JsAny, message: Uint8Array) @JsName("crypto_hash_sha256_final") - fun crypto_hash_sha256_final(state: dynamic): Uint8Array + fun crypto_hash_sha256_final(state: JsAny): Uint8Array @JsName("crypto_hash_sha512_init") - fun crypto_hash_sha512_init() : dynamic + fun crypto_hash_sha512_init() : JsAny @JsName("crypto_hash_sha512_update") - fun crypto_hash_sha512_update(state: dynamic, message: Uint8Array) + fun crypto_hash_sha512_update(state: JsAny, message: Uint8Array) @JsName("crypto_hash_sha512_final") - fun crypto_hash_sha512_final(state: dynamic): Uint8Array + fun crypto_hash_sha512_final(state: JsAny): Uint8Array //XChaCha20Poly1305 - also in bindings //fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, secretNonce: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array @@ -92,33 +91,33 @@ external object JsSodiumInterface { //XChaCha20Poly1305 //encrypt @JsName("crypto_secretstream_xchacha20poly1305_init_push") - fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : dynamic + fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : JsAny @JsName("crypto_secretstream_xchacha20poly1305_push") - fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, associatedData: Uint8Array, tag: UByte) : Uint8Array + fun crypto_secretstream_xchacha20poly1305_push(state: JsAny, message: Uint8Array, associatedData: Uint8Array, tag: UByte) : Uint8Array //decrypt @JsName("crypto_secretstream_xchacha20poly1305_init_pull") - fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic + fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : JsAny @JsName("crypto_secretstream_xchacha20poly1305_pull") - fun crypto_secretstream_xchacha20poly1305_pull(state: dynamic, ciphertext: Uint8Array, associatedData: Uint8Array) : dynamic + fun crypto_secretstream_xchacha20poly1305_pull(state: JsAny, ciphertext: Uint8Array, associatedData: Uint8Array) : JsAny //keygen and rekey @JsName("crypto_secretstream_xchacha20poly1305_keygen") fun crypto_secretstream_xchacha20poly1305_keygen() : Uint8Array @JsName("crypto_secretstream_xchacha20poly1305_rekey") - fun crypto_secretstream_xchacha20poly1305_rekey(state: dynamic) + fun crypto_secretstream_xchacha20poly1305_rekey(state: JsAny) // ---- SecretBox ---- @JsName("crypto_secretbox_detached") - fun crypto_secretbox_detached(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : dynamic + fun crypto_secretbox_detached(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : JsAny @JsName("crypto_secretbox_easy") fun crypto_secretbox_easy(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_secretbox_keygen") fun crypto_secretbox_keygen() : Uint8Array @JsName("crypto_secretbox_open_detached") - fun crypto_secretbox_open_detached(ciphertext : Uint8Array, tag : Uint8Array, nonce: Uint8Array, key: Uint8Array) : dynamic + fun crypto_secretbox_open_detached(ciphertext : Uint8Array, tag : Uint8Array, nonce: Uint8Array, key: Uint8Array) : JsAny @JsName("crypto_secretbox_open_easy") - fun crypto_secretbox_open_easy(ciphertext : Uint8Array, nonce: Uint8Array, key: Uint8Array) : dynamic + fun crypto_secretbox_open_easy(ciphertext : Uint8Array, nonce: Uint8Array, key: Uint8Array) : JsAny // ---- SecretBox End ---- @@ -132,7 +131,7 @@ external object JsSodiumInterface { @JsName("crypto_aead_chacha20poly1305_encrypt") fun crypto_aead_chacha20poly1305_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_encrypt_detached") - fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : dynamic + fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : JsAny @JsName("crypto_aead_chacha20poly1305_ietf_decrypt") fun crypto_aead_chacha20poly1305_ietf_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_ietf_decrypt_detached") @@ -140,7 +139,7 @@ external object JsSodiumInterface { @JsName("crypto_aead_chacha20poly1305_ietf_encrypt") fun crypto_aead_chacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_ietf_encrypt_detached") - fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : dynamic + fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : JsAny @JsName("crypto_aead_chacha20poly1305_ietf_keygen") fun crypto_aead_chacha20poly1305_ietf_keygen() : Uint8Array @JsName("crypto_aead_chacha20poly1305_keygen") @@ -152,7 +151,7 @@ external object JsSodiumInterface { @JsName("crypto_aead_xchacha20poly1305_ietf_encrypt") fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_xchacha20poly1305_ietf_encrypt_detached") - fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : dynamic + fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : JsAny @JsName("crypto_aead_xchacha20poly1305_ietf_keygen") fun crypto_aead_xchacha20poly1305_ietf_keygen(): Uint8Array @@ -184,9 +183,9 @@ external object JsSodiumInterface { // ---- Box ---- @JsName("crypto_box_keypair") - fun crypto_box_keypair() : dynamic + fun crypto_box_keypair() : JsAny @JsName("crypto_box_seed_keypair") - fun crypto_box_seed_keypair(seed : Uint8Array) : dynamic + fun crypto_box_seed_keypair(seed : Uint8Array) : JsAny @JsName("crypto_box_easy") fun crypto_box_easy(message: Uint8Array, nonce: Uint8Array, @@ -201,7 +200,7 @@ external object JsSodiumInterface { fun crypto_box_detached(message: Uint8Array, nonce: Uint8Array, recipientsPublicKey: Uint8Array, - sendersSecretKey: Uint8Array) : dynamic + sendersSecretKey: Uint8Array) : JsAny @JsName("crypto_box_open_detached") fun crypto_box_open_detached(ciphertext: Uint8Array, tag: Uint8Array, @@ -239,19 +238,19 @@ external object JsSodiumInterface { @JsName("crypto_sign_ed25519_sk_to_seed") fun crypto_sign_ed25519_sk_to_seed(ed25519SecretKey: Uint8Array) : Uint8Array @JsName("crypto_sign_final_create") - fun crypto_sign_final_create(state: dynamic, secretKey: Uint8Array) : Uint8Array + fun crypto_sign_final_create(state: JsAny, secretKey: Uint8Array) : Uint8Array @JsName("crypto_sign_final_verify") - fun crypto_sign_final_verify(state: dynamic, signature: Uint8Array, publicKey: Uint8Array) : Boolean + fun crypto_sign_final_verify(state: JsAny, signature: Uint8Array, publicKey: Uint8Array) : Boolean @JsName("crypto_sign_init") - fun crypto_sign_init() : dynamic + fun crypto_sign_init() : JsAny @JsName("crypto_sign_keypair") - fun crypto_sign_keypair() : dynamic + fun crypto_sign_keypair() : JsAny @JsName("crypto_sign_open") fun crypto_sign_open(signedMessage: Uint8Array, publicKey: Uint8Array) : Uint8Array @JsName("crypto_sign_seed_keypair") - fun crypto_sign_seed_keypair(seed: Uint8Array) : dynamic + fun crypto_sign_seed_keypair(seed: Uint8Array) : JsAny @JsName("crypto_sign_update") - fun crypto_sign_update(state: dynamic, message: Uint8Array) + fun crypto_sign_update(state: JsAny, message: Uint8Array) @JsName("crypto_sign_verify_detached") fun crypto_sign_verify_detached(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array) : Boolean @@ -320,13 +319,13 @@ external object JsSodiumInterface { // ---- Key exchange ---- @JsName("crypto_kx_client_session_keys") - fun crypto_kx_client_session_keys(clientPublicKey: Uint8Array, clientSecretKey: Uint8Array, serverPublicKey: Uint8Array) : dynamic + fun crypto_kx_client_session_keys(clientPublicKey: Uint8Array, clientSecretKey: Uint8Array, serverPublicKey: Uint8Array) : JsAny @JsName("crypto_kx_keypair") - fun crypto_kx_keypair() : dynamic + fun crypto_kx_keypair() : JsAny @JsName("crypto_kx_seed_keypair") - fun crypto_kx_seed_keypair(seed: Uint8Array) : dynamic + fun crypto_kx_seed_keypair(seed: Uint8Array) : JsAny @JsName("crypto_kx_server_session_keys") - fun crypto_kx_server_session_keys(serverPublicKey: Uint8Array, serverSecretKey: Uint8Array, clientPublicKey: Uint8Array) : dynamic + fun crypto_kx_server_session_keys(serverPublicKey: Uint8Array, serverSecretKey: Uint8Array, clientPublicKey: Uint8Array) : JsAny // ---- Key exchange end ---- diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt index 3ea5001..b5ebaab 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt @@ -11,7 +11,10 @@ import org.khronos.webgl.Uint8Array * on 21-Aug-2020 */ -actual typealias GenericHashStateInternal = Any + + //Раз используется как жсЭни, то можно написать = ЖсЭни +//actual typealias GenericHashStateInternal = Any +typealias GenericHashStateInternal = JsAny actual object GenericHash { actual fun genericHash( diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt index 5956ba8..5e95fff 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt @@ -4,8 +4,11 @@ import com.ionspin.kotlin.crypto.getSodium import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array -actual typealias Sha256State = Any -actual typealias Sha512State = Any +// TODO: проверить, что эти штуки юзаются как жсЭни +typealias Sha256State = JsAny +typealias Sha512State = JsAny +//actual typealias Sha256State = Any +//actual typealias Sha512State = Any actual object Hash { From 669e8ee0c953b7cc4735c4728b0e4c519f8d27b6 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Sun, 1 Dec 2024 20:51:43 +0300 Subject: [PATCH 05/27] Work on JsSodiumLoader in process. Current problem: wrong type in try-catch (JsAny instead of throwable) --- .../com/ionspin/kotlin/crypto/JsSodiumInterface.kt | 8 ++++++++ .../com/ionspin/kotlin/crypto/JsSodiumLoader.kt | 12 ++++++++---- .../src/wasmJsMain/kotlin/libsodium.kt | 6 +++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt index a1af2a2..7be5d75 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -9,6 +9,11 @@ import org.khronos.webgl.Uint8Array * ugljesa.jovanovic@ionspin.com * on 27-May-2020 */ + +typealias UByte = Int +typealias UInt = Long + + @JsModule("libsodium-wrappers-sumo") external object JsSodiumInterface { @@ -93,6 +98,9 @@ external object JsSodiumInterface { @JsName("crypto_secretstream_xchacha20poly1305_init_push") fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : JsAny @JsName("crypto_secretstream_xchacha20poly1305_push") + // TODO: два варианта: \/ + // 1. Меняем юбайт на байт и юинт на инт \/ + // 2. Меняем юбайт на инт и юинт на лонг \/ и далее по списку fun crypto_secretstream_xchacha20poly1305_push(state: JsAny, message: Uint8Array, associatedData: Uint8Array, tag: UByte) : Uint8Array //decrypt diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt index a4509a0..f85eacd 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt @@ -27,14 +27,18 @@ object JsSodiumLoader { } - suspend fun load() = suspendCoroutine { continuation -> + // TODO: попробовать сделать из этого suspend вместо continuation + suspend fun load(): Unit = suspendCoroutine { continuation -> if (!getSodiumLoaded()) { - _libsodiumPromise.then { + _libsodiumPromise.then { sodium_init() sodiumLoaded = true + //Dynamic может быть Юнит, но Unit не может быть JsAny? continuation.resumeWith(Result.success(Unit)) - }.catch { e -> + null + }.catch { e-> continuation.resumeWith(Result.failure(e)) + null } } else { continuation.resumeWith(Result.success(Unit)) @@ -43,7 +47,7 @@ object JsSodiumLoader { fun loadWithCallback(doneCallback: () -> (Unit)) { if (!getSodiumLoaded()) { - _libsodiumPromise.then { + _libsodiumPromise.then { sodium_init() sodiumLoaded = true doneCallback.invoke() diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/libsodium.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/libsodium.kt index 85ff707..e55db33 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/libsodium.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/libsodium.kt @@ -1,5 +1,5 @@ @file:JsModule("libsodium-sumo") -@file:JsNonModule +//@file:JsNonModule package ext.libsodium import org.khronos.webgl.Uint8Array @@ -13,7 +13,7 @@ import kotlin.js.Promise */ @JsName("ready") -external val _libsodiumPromise : Promise +external val _libsodiumPromise : Promise @JsName("_sodium_init") external fun sodium_init() : Int @@ -23,7 +23,7 @@ external fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array) : Uin external fun crypto_hash_sha256(message: Uint8Array) : Uint8Array external fun crypto_hash_sha512(message: Uint8Array) : Uint8Array -external fun crypto_hash_sha256_init(): dynamic +external fun crypto_hash_sha256_init(): JsAny From f161aef4ac25cee622c6519b2df89fd28c8333d9 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Sun, 1 Dec 2024 21:14:19 +0300 Subject: [PATCH 06/27] The JsLibsodiumLoader file has been fixed, but the quality of fix is unknown --- .../com/ionspin/kotlin/crypto/JsSodiumLoader.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt index f85eacd..391c0c2 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt @@ -36,8 +36,13 @@ object JsSodiumLoader { //Dynamic может быть Юнит, но Unit не может быть JsAny? continuation.resumeWith(Result.success(Unit)) null - }.catch { e-> - continuation.resumeWith(Result.failure(e)) + }.catch { e -> + val throwable = e as? Throwable + if (throwable != null) { + continuation.resumeWith(Result.failure(throwable)) + } else { + continuation.resumeWith(Result.failure(Exception("Error: $e"))) + } null } } else { @@ -45,9 +50,9 @@ object JsSodiumLoader { } } - fun loadWithCallback(doneCallback: () -> (Unit)) { + fun loadWithCallback(doneCallback: () -> (JsAny)) { if (!getSodiumLoaded()) { - _libsodiumPromise.then { + _libsodiumPromise.then { sodium_init() sodiumLoaded = true doneCallback.invoke() From f7bb312273afebf4e966ae8d16587c5289f08ac3 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Mon, 2 Dec 2024 03:40:00 +0300 Subject: [PATCH 07/27] Fixed JsUtil.kt, Uint8Array type to ByteArray --- .../wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt index ec40078..5e08095 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt @@ -8,14 +8,14 @@ import org.khronos.webgl.get * ugljesa.jovanovic@ionspin.com * on 02-Aug-2020 */ -fun UByteArray.toUInt8Array() : Uint8Array { - val uint8Result = Uint8Array(toByteArray().toTypedArray()) - return uint8Result +fun UByteArray.toByteArray() : ByteArray { +// val uint8Result = ByteArray(toTypedArray()) + return toByteArray() } fun Uint8Array.toUByteArray() : UByteArray { - if (length.asDynamic() == undefined) { + if (length == null) { println("Error") } val result = UByteArray(length) From 4bea64ad21c38583ce21ef41b8e46216d1d264b4 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Mon, 2 Dec 2024 05:19:17 +0300 Subject: [PATCH 08/27] Fixed initializeWithCallback func in LibsodiumInitializer. Note: now it returns a JsString "null" instead of nothing --- .../kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt | 2 +- .../kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt index 391c0c2..14937b2 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt @@ -52,7 +52,7 @@ object JsSodiumLoader { fun loadWithCallback(doneCallback: () -> (JsAny)) { if (!getSodiumLoaded()) { - _libsodiumPromise.then { + _libsodiumPromise.then { sodium_init() sodiumLoaded = true doneCallback.invoke() diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt index 20bf538..e1c4ae1 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt @@ -21,10 +21,12 @@ actual object LibsodiumInitializer { isPlatformInitialized = true } + actual fun initializeWithCallback(done: () -> Unit) { JsSodiumLoader.loadWithCallback { isPlatformInitialized = true done() + "null".toJsString() } } From 2fdecba8477491a85f5c73ffaf8a76bf95ec3233 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Fri, 6 Dec 2024 00:31:33 +0300 Subject: [PATCH 09/27] Made a .toUInt8Array() function in JsUtil.kt file. --- .../kotlin/com/ionspin/kotlin/crypto/JsUtil.kt | 9 +++++++++ .../com/ionspin/kotlin/crypto/LibsodiumInitializer.kt | 1 + 2 files changed, 10 insertions(+) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt index 5e08095..776af6d 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt @@ -13,6 +13,15 @@ fun UByteArray.toByteArray() : ByteArray { return toByteArray() } +fun UByteArray.toUInt8Array() : Uint8Array { + var jsArray = JsArray() + for (i in this.indices) { + jsArray[i] = this[i].toInt().toJsNumber() + } + var uint8Result = Uint8Array(jsArray) + return uint8Result +} + fun Uint8Array.toUByteArray() : UByteArray { if (length == null) { diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt index e1c4ae1..6d63773 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt @@ -26,6 +26,7 @@ actual object LibsodiumInitializer { JsSodiumLoader.loadWithCallback { isPlatformInitialized = true done() + // TODO: there's no return needed!!! "null".toJsString() } } From 0d2300c47f021372549c2e3af1e3425172ebb8f5 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Sat, 7 Dec 2024 19:12:57 +0300 Subject: [PATCH 10/27] Add chacha20poly1305EncryptDetachedResult return type to corresponding functions (mac and ciphertext were fixed) --- .../com/ionspin/kotlin/crypto/JsSodiumInterface.kt | 10 +++++++--- .../kotlin/com/ionspin/kotlin/crypto/JsUtil.kt | 1 - .../aead/AuthenticatedEncryptionWithAssociatedData.kt | 5 ++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt index 7be5d75..b5fd28f 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -13,6 +13,10 @@ import org.khronos.webgl.Uint8Array typealias UByte = Int typealias UInt = Long +external object chacha20poly1305EncryptDetachedResult : JsAny { + val ciphertext: Uint8Array + var mac: Uint8Array +} @JsModule("libsodium-wrappers-sumo") external object JsSodiumInterface { @@ -139,7 +143,7 @@ external object JsSodiumInterface { @JsName("crypto_aead_chacha20poly1305_encrypt") fun crypto_aead_chacha20poly1305_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_encrypt_detached") - fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : JsAny + fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : chacha20poly1305EncryptDetachedResult @JsName("crypto_aead_chacha20poly1305_ietf_decrypt") fun crypto_aead_chacha20poly1305_ietf_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_ietf_decrypt_detached") @@ -147,7 +151,7 @@ external object JsSodiumInterface { @JsName("crypto_aead_chacha20poly1305_ietf_encrypt") fun crypto_aead_chacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_ietf_encrypt_detached") - fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : JsAny + fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : chacha20poly1305EncryptDetachedResult @JsName("crypto_aead_chacha20poly1305_ietf_keygen") fun crypto_aead_chacha20poly1305_ietf_keygen() : Uint8Array @JsName("crypto_aead_chacha20poly1305_keygen") @@ -159,7 +163,7 @@ external object JsSodiumInterface { @JsName("crypto_aead_xchacha20poly1305_ietf_encrypt") fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_xchacha20poly1305_ietf_encrypt_detached") - fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : JsAny + fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : chacha20poly1305EncryptDetachedResult @JsName("crypto_aead_xchacha20poly1305_ietf_keygen") fun crypto_aead_xchacha20poly1305_ietf_keygen(): Uint8Array diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt index 776af6d..2adfe0f 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt @@ -9,7 +9,6 @@ import org.khronos.webgl.get * on 02-Aug-2020 */ fun UByteArray.toByteArray() : ByteArray { -// val uint8Result = ByteArray(toTypedArray()) return toByteArray() } diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt index c74369b..0c5ee80 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt @@ -8,7 +8,6 @@ import org.khronos.webgl.Uint8Array actual object AuthenticatedEncryptionWithAssociatedData { // Ietf - // Original chacha20poly1305 actual fun xChaCha20Poly1305IetfEncrypt( message: UByteArray, @@ -58,8 +57,8 @@ actual object AuthenticatedEncryptionWithAssociatedData { key.toUInt8Array(), ) return AeadEncryptedDataAndTag( - (result.ciphertext as Uint8Array).toUByteArray(), - (result.mac as Uint8Array).toUByteArray() + (result.ciphertext).toUByteArray(), + (result.mac).toUByteArray() ) } From 014daefc43fcd093d11926ac860c3f13c3068926 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Mon, 9 Dec 2024 01:16:46 +0300 Subject: [PATCH 11/27] Created a big amount of external objects in JsSodiumInterface.kt for Hash.kt, Kdf.kt and KeyExchange.kt files. Reason: values had these fields in dynamic type but not in JsAny type. --- .../kotlin/crypto/JsSodiumInterface.kt | 52 +++++++++++++++---- .../com/ionspin/kotlin/crypto/box/Box.kt | 12 ++--- .../kotlin/crypto/generichash/GenericHash.kt | 7 ++- .../com/ionspin/kotlin/crypto/hash/Hash.kt | 13 +++-- .../com/ionspin/kotlin/crypto/kdf/Kdf.kt | 4 +- .../kotlin/crypto/keyexchange/KeyExchange.kt | 18 ++++--- 6 files changed, 73 insertions(+), 33 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt index b5fd28f..3c34d40 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -13,11 +13,41 @@ import org.khronos.webgl.Uint8Array typealias UByte = Int typealias UInt = Long -external object chacha20poly1305EncryptDetachedResult : JsAny { +external object Chacha20poly1305EncryptDetachedResult : JsAny { val ciphertext: Uint8Array var mac: Uint8Array } +external object CryptoBoxDetachedResult : JsAny { + val ciphertext: Uint8Array + var mac: Uint8Array +} + +external object CryptoBoxKeypairResult: JsAny { + val publicKey: Uint8Array + val privateKey: Uint8Array +} + +external object CryptoKxClientSessionKeysResult: JsAny { + val sharedRx: Uint8Array + val sharedTx: Uint8Array +} + +external object CryptoKxKeypairResult: JsAny { + val publicKey: Uint8Array + val privateKey: Uint8Array +} + +external object CryptoKxSeedKeypairResult: JsAny { + val publicKey: Uint8Array + val privateKey: Uint8Array +} + +external object CryptoKxServerSessionKeysResult: JsAny { + val sharedRx: Uint8Array + val sharedTx: Uint8Array +} + @JsModule("libsodium-wrappers-sumo") external object JsSodiumInterface { @@ -143,7 +173,7 @@ external object JsSodiumInterface { @JsName("crypto_aead_chacha20poly1305_encrypt") fun crypto_aead_chacha20poly1305_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_encrypt_detached") - fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : chacha20poly1305EncryptDetachedResult + fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Chacha20poly1305EncryptDetachedResult @JsName("crypto_aead_chacha20poly1305_ietf_decrypt") fun crypto_aead_chacha20poly1305_ietf_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_ietf_decrypt_detached") @@ -151,7 +181,7 @@ external object JsSodiumInterface { @JsName("crypto_aead_chacha20poly1305_ietf_encrypt") fun crypto_aead_chacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_ietf_encrypt_detached") - fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : chacha20poly1305EncryptDetachedResult + fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Chacha20poly1305EncryptDetachedResult @JsName("crypto_aead_chacha20poly1305_ietf_keygen") fun crypto_aead_chacha20poly1305_ietf_keygen() : Uint8Array @JsName("crypto_aead_chacha20poly1305_keygen") @@ -163,7 +193,7 @@ external object JsSodiumInterface { @JsName("crypto_aead_xchacha20poly1305_ietf_encrypt") fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_xchacha20poly1305_ietf_encrypt_detached") - fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : chacha20poly1305EncryptDetachedResult + fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Chacha20poly1305EncryptDetachedResult @JsName("crypto_aead_xchacha20poly1305_ietf_keygen") fun crypto_aead_xchacha20poly1305_ietf_keygen(): Uint8Array @@ -195,9 +225,9 @@ external object JsSodiumInterface { // ---- Box ---- @JsName("crypto_box_keypair") - fun crypto_box_keypair() : JsAny + fun crypto_box_keypair() : CryptoBoxKeypairResult @JsName("crypto_box_seed_keypair") - fun crypto_box_seed_keypair(seed : Uint8Array) : JsAny + fun crypto_box_seed_keypair(seed : Uint8Array) : CryptoBoxKeypairResult @JsName("crypto_box_easy") fun crypto_box_easy(message: Uint8Array, nonce: Uint8Array, @@ -212,7 +242,7 @@ external object JsSodiumInterface { fun crypto_box_detached(message: Uint8Array, nonce: Uint8Array, recipientsPublicKey: Uint8Array, - sendersSecretKey: Uint8Array) : JsAny + sendersSecretKey: Uint8Array) : CryptoBoxDetachedResult @JsName("crypto_box_open_detached") fun crypto_box_open_detached(ciphertext: Uint8Array, tag: Uint8Array, @@ -331,13 +361,13 @@ external object JsSodiumInterface { // ---- Key exchange ---- @JsName("crypto_kx_client_session_keys") - fun crypto_kx_client_session_keys(clientPublicKey: Uint8Array, clientSecretKey: Uint8Array, serverPublicKey: Uint8Array) : JsAny + fun crypto_kx_client_session_keys(clientPublicKey: Uint8Array, clientSecretKey: Uint8Array, serverPublicKey: Uint8Array) : CryptoKxClientSessionKeysResult @JsName("crypto_kx_keypair") - fun crypto_kx_keypair() : JsAny + fun crypto_kx_keypair() : CryptoKxKeypairResult @JsName("crypto_kx_seed_keypair") - fun crypto_kx_seed_keypair(seed: Uint8Array) : JsAny + fun crypto_kx_seed_keypair(seed: Uint8Array) : CryptoKxSeedKeypairResult @JsName("crypto_kx_server_session_keys") - fun crypto_kx_server_session_keys(serverPublicKey: Uint8Array, serverSecretKey: Uint8Array, clientPublicKey: Uint8Array) : JsAny + fun crypto_kx_server_session_keys(serverPublicKey: Uint8Array, serverSecretKey: Uint8Array, clientPublicKey: Uint8Array) : CryptoKxServerSessionKeysResult // ---- Key exchange end ---- diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/box/Box.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/box/Box.kt index 376f4a6..ac30d55 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/box/Box.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/box/Box.kt @@ -14,8 +14,8 @@ actual object Box { actual fun keypair(): BoxKeyPair { val keypair = getSodium().crypto_box_keypair() return BoxKeyPair( - (keypair.publicKey as Uint8Array).toUByteArray(), - (keypair.privateKey as Uint8Array).toUByteArray() + (keypair.publicKey).toUByteArray(), + (keypair.privateKey).toUByteArray() ) } @@ -25,8 +25,8 @@ actual object Box { actual fun seedKeypair(seed: UByteArray): BoxKeyPair { val keypair = getSodium().crypto_box_seed_keypair(seed.toUInt8Array()) return BoxKeyPair( - (keypair.publicKey as Uint8Array).toUByteArray(), - (keypair.privateKey as Uint8Array).toUByteArray() + (keypair.publicKey).toUByteArray(), + (keypair.privateKey).toUByteArray() ) } @@ -142,8 +142,8 @@ actual object Box { sendersSecretKey.toUInt8Array(), ) return BoxEncryptedDataAndTag( - (detached.ciphertext as Uint8Array).toUByteArray(), - (detached.mac as Uint8Array).toUByteArray() + (detached.ciphertext).toUByteArray(), + (detached.mac).toUByteArray() ) } diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt index b5ebaab..86a9f16 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt @@ -11,10 +11,13 @@ import org.khronos.webgl.Uint8Array * on 21-Aug-2020 */ +// TODO: посмотреть, как оно используется +external object GenericHashStateInternalType: JsAny //Раз используется как жсЭни, то можно написать = ЖсЭни //actual typealias GenericHashStateInternal = Any -typealias GenericHashStateInternal = JsAny +actual typealias GenericHashStateInternal = GenericHashStateInternalType + actual object GenericHash { actual fun genericHash( @@ -34,7 +37,7 @@ actual object GenericHash { key: UByteArray? ): GenericHashState { val state = getSodium().crypto_generichash_init(key?.toUInt8Array() ?: Uint8Array(0), requestedHashLength) - return GenericHashState(requestedHashLength, state) + return GenericHashState(requestedHashLength, state as GenericHashStateInternal) } actual fun genericHashUpdate( diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt index 5e95fff..ce3d7ab 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt @@ -5,11 +5,16 @@ import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array // TODO: проверить, что эти штуки юзаются как жсЭни -typealias Sha256State = JsAny -typealias Sha512State = JsAny +//typealias Sha256State = JsAny +//typealias Sha512State = JsAny //actual typealias Sha256State = Any //actual typealias Sha512State = Any +external object Sha256StateType: JsAny + +actual typealias Sha256State = Sha256StateType +actual typealias Sha512State = Sha256StateType + actual object Hash { actual fun sha256(data: UByteArray): UByteArray { @@ -17,7 +22,7 @@ actual object Hash { } actual fun sha256Init(): Sha256State { - return getSodium().crypto_hash_sha256_init() + return getSodium().crypto_hash_sha256_init() as Sha256State } actual fun sha256Update(state: Sha256State, data: UByteArray) { @@ -33,7 +38,7 @@ actual object Hash { } actual fun sha512Init(): Sha512State { - return getSodium().crypto_hash_sha512_init() + return getSodium().crypto_hash_sha512_init() as Sha512State } actual fun sha512Update(state: Sha512State, data: UByteArray) { diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt index 8cf0a31..bdf88c0 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt @@ -26,8 +26,8 @@ actual object Kdf { masterKey: UByteArray ): UByteArray { return getSodium().crypto_kdf_derive_from_key( - subkeyLength.toUInt(), - subkeyId, + subkeyLength.toLong(), + subkeyId.toLong(), context, masterKey.toUInt8Array() ).toUByteArray() diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/keyexchange/KeyExchange.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/keyexchange/KeyExchange.kt index 2f40309..5ceef64 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/keyexchange/KeyExchange.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/keyexchange/KeyExchange.kt @@ -5,6 +5,7 @@ import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array import org.khronos.webgl.Uint8Array + actual object KeyExchange { actual fun clientSessionKeys(clientPublicKey: UByteArray, clientSecretKey: UByteArray, serverPublicKey: UByteArray) : KeyExchangeSessionKeyPair { @@ -15,8 +16,9 @@ actual object KeyExchange { serverPublicKey.toUInt8Array() ) - val receiveKey = (result.sharedRx as Uint8Array).toUByteArray() - val sendKey = (result.sharedTx as Uint8Array).toUByteArray() + // Он был в dynamic, но его нет в JsAny + val receiveKey = result.sharedRx.toUByteArray() + val sendKey = result.sharedTx.toUByteArray() @@ -26,8 +28,8 @@ actual object KeyExchange { actual fun keypair() : KeyExchangeKeyPair { val result = getSodium().crypto_kx_keypair() - val publicKey = (result.publicKey as Uint8Array).toUByteArray() - val secretKey = (result.privateKey as Uint8Array).toUByteArray() + val publicKey = result.publicKey.toUByteArray() + val secretKey = result.privateKey.toUByteArray() return KeyExchangeKeyPair(publicKey, secretKey) } @@ -35,8 +37,8 @@ actual object KeyExchange { actual fun seedKeypair(seed: UByteArray) : KeyExchangeKeyPair { val result = getSodium().crypto_kx_seed_keypair(seed.toUInt8Array()) - val publicKey = (result.publicKey as Uint8Array).toUByteArray() - val secretKey = (result.privateKey as Uint8Array).toUByteArray() + val publicKey = result.publicKey.toUByteArray() + val secretKey = result.privateKey.toUByteArray() return KeyExchangeKeyPair(publicKey, secretKey) } @@ -49,8 +51,8 @@ actual object KeyExchange { clientPublicKey.toUInt8Array() ) - val receiveKey = (result.sharedRx as Uint8Array).toUByteArray() - val sendKey = (result.sharedTx as Uint8Array).toUByteArray() + val receiveKey = result.sharedRx.toUByteArray() + val sendKey = result.sharedTx.toUByteArray() return KeyExchangeSessionKeyPair(receiveKey, sendKey) } From 12ebea9550fbfb03b9500db40c81ff3ccb1458e8 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Mon, 9 Dec 2024 03:27:29 +0300 Subject: [PATCH 12/27] SecretStream.kt fixed by using a lot of external objects on JsSodiumInterface.kt. Problem: function crypto_secretstream_xchacha20poly1305_pull returns JsAny (via an external object) to dataAndTag value. Later dataAndTag is compared to Boolean. Check it out later. It may cause problems. --- .../kotlin/crypto/JsSodiumInterface.kt | 26 ++++++++++++++++--- .../kotlin/crypto/pwhash/PasswordHash.kt | 16 ++++++------ .../kotlin/crypto/secretbox/SecretBox.kt | 4 +-- .../crypto/secretstream/SecretStream.kt | 16 +++++++----- 4 files changed, 42 insertions(+), 20 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt index 3c34d40..13fa4b1 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -48,6 +48,23 @@ external object CryptoKxServerSessionKeysResult: JsAny { val sharedTx: Uint8Array } +external object CryptoSecretboxDetachedResult: JsAny { + val cipher: Uint8Array + val mac: Uint8Array +} + +external object CryptoSecretstreamXchacha20poly1305InitPushResult: JsAny { + val state: Uint8Array + val header: Uint8Array +} + +external object CryptoSecretstreamXchacha20poly1305PullResult: JsAny { + val message: Uint8Array + val tag: UByte +} + + + @JsModule("libsodium-wrappers-sumo") external object JsSodiumInterface { @@ -87,7 +104,8 @@ external object JsSodiumInterface { @JsName("crypto_generichash_blake2b_update") fun crypto_generichash_blake2b_update(state: JsAny, inputMessage: Uint8Array) - + // TODO: строка ниже просто висела без ничего, я ее закомментила +//crypto_secretstream_xchacha20poly1305_init_push @JsName("crypto_generichash_blake2b_final") fun crypto_generichash_blake2b_final(state: JsAny, hashLength: Int) : Uint8Array @@ -130,7 +148,7 @@ external object JsSodiumInterface { //XChaCha20Poly1305 //encrypt @JsName("crypto_secretstream_xchacha20poly1305_init_push") - fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : JsAny + fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : CryptoSecretstreamXchacha20poly1305InitPushResult @JsName("crypto_secretstream_xchacha20poly1305_push") // TODO: два варианта: \/ // 1. Меняем юбайт на байт и юинт на инт \/ @@ -141,7 +159,7 @@ external object JsSodiumInterface { @JsName("crypto_secretstream_xchacha20poly1305_init_pull") fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : JsAny @JsName("crypto_secretstream_xchacha20poly1305_pull") - fun crypto_secretstream_xchacha20poly1305_pull(state: JsAny, ciphertext: Uint8Array, associatedData: Uint8Array) : JsAny + fun crypto_secretstream_xchacha20poly1305_pull(state: JsAny, ciphertext: Uint8Array, associatedData: Uint8Array) : CryptoSecretstreamXchacha20poly1305PullResult //keygen and rekey @JsName("crypto_secretstream_xchacha20poly1305_keygen") @@ -151,7 +169,7 @@ external object JsSodiumInterface { // ---- SecretBox ---- @JsName("crypto_secretbox_detached") - fun crypto_secretbox_detached(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : JsAny + fun crypto_secretbox_detached(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : CryptoSecretboxDetachedResult @JsName("crypto_secretbox_easy") fun crypto_secretbox_easy(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_secretbox_keygen") diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt index 82bf6c4..e678013 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt @@ -26,12 +26,12 @@ actual object PasswordHash { throw RuntimeException("Javascript doesnt support more than ${UInt.MAX_VALUE} for opslimit") } return getSodium().crypto_pwhash( - outputLength.toUInt(), + outputLength.toLong(), password.encodeToUByteArray().toUInt8Array(), salt.toUInt8Array(), - opsLimit.toUInt(), - memLimit.toUInt(), - algorithm.toUInt() + opsLimit.toLong(), + memLimit.toLong(), + algorithm.toLong() ).toUByteArray() } @@ -51,8 +51,8 @@ actual object PasswordHash { } return getSodium().crypto_pwhash_str( password.encodeToUByteArray().toUInt8Array(), - opslimit.toUInt(), - memlimit.toUInt() + opslimit.toLong(), + memlimit.toLong() ) } @@ -73,8 +73,8 @@ actual object PasswordHash { return if ( getSodium().crypto_pwhash_str_needs_rehash( passwordHash, - opslimit.toUInt(), - memlimit.toUInt() + opslimit.toLong(), + memlimit.toLong() ) ) { 1 diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt index 4ff9188..e61d14f 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt @@ -42,8 +42,8 @@ actual object SecretBox { key.toUInt8Array() ) return SecretBoxEncryptedDataAndTag( - (result.cipher as Uint8Array).toUByteArray(), - (result.mac as Uint8Array).toUByteArray() + result.cipher.toUByteArray(), + result.mac.toUByteArray() ) } diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt index 27856e8..6cb67fd 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt @@ -5,12 +5,14 @@ import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array import org.khronos.webgl.Uint8Array -actual typealias SecretStreamState = Any +external object SecretStreamStateType: JsAny + +actual typealias SecretStreamState = SecretStreamStateType actual object SecretStream { actual fun xChaCha20Poly1305InitPush(key: UByteArray): SecretStreamStateAndHeader { val state = getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array()) - return SecretStreamStateAndHeader(state.state, (state.header as Uint8Array).toUByteArray()) + return SecretStreamStateAndHeader(state.state as SecretStreamState, state.header.toUByteArray()) } actual fun xChaCha20Poly1305Push( @@ -20,7 +22,7 @@ actual object SecretStream { tag: UByte ): UByteArray { return getSodium().crypto_secretstream_xchacha20poly1305_push( - state, message.toUInt8Array(), associatedData.toUInt8Array(), tag + state, message.toUInt8Array(), associatedData.toUInt8Array(), tag.toInt() ).toUByteArray() } @@ -29,7 +31,7 @@ actual object SecretStream { header: UByteArray ): SecretStreamStateAndHeader { val state = getSodium().crypto_secretstream_xchacha20poly1305_init_pull(header.toUInt8Array(), key.toUInt8Array()) - return SecretStreamStateAndHeader(state, header) + return SecretStreamStateAndHeader(state as SecretStreamState, header) } actual fun xChaCha20Poly1305Pull( @@ -40,10 +42,12 @@ actual object SecretStream { val dataAndTag = getSodium().crypto_secretstream_xchacha20poly1305_pull( state, ciphertext.toUInt8Array(), associatedData.toUInt8Array() ) - if (dataAndTag == false) { + // TODO: cast definitely will succeed (i hope), + // but it needs to be checked \/ i'm not sure about this move + if (dataAndTag as Boolean == false) { throw SecretStreamCorruptedOrTamperedDataException() } - return DecryptedDataAndTag((dataAndTag.message as Uint8Array).toUByteArray(), dataAndTag.tag) + return DecryptedDataAndTag(dataAndTag.message.toUByteArray(), dataAndTag.tag.toUByte()) } From 03116127e86a90be2547bddd976a923644f20e51 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Tue, 10 Dec 2024 19:41:52 +0300 Subject: [PATCH 13/27] Exception has been handled in func xChaCha20Poly1305Pull (file SecretStream.kt) --- .../kotlin/crypto/secretstream/SecretStream.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt index 6cb67fd..6d74972 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt @@ -5,6 +5,12 @@ import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array import org.khronos.webgl.Uint8Array +//TODO: вынести все external objects в отдельный файл (и в JsSodiumInterface.kt) +external object CryptoSecretstreamXchacha20poly1305PullResult: JsAny { + val message: Uint8Array + val tag: Byte +} + external object SecretStreamStateType: JsAny actual typealias SecretStreamState = SecretStreamStateType @@ -22,7 +28,7 @@ actual object SecretStream { tag: UByte ): UByteArray { return getSodium().crypto_secretstream_xchacha20poly1305_push( - state, message.toUInt8Array(), associatedData.toUInt8Array(), tag.toInt() + state, message.toUInt8Array(), associatedData.toUInt8Array(), tag.toByte() ).toUByteArray() } @@ -42,12 +48,10 @@ actual object SecretStream { val dataAndTag = getSodium().crypto_secretstream_xchacha20poly1305_pull( state, ciphertext.toUInt8Array(), associatedData.toUInt8Array() ) - // TODO: cast definitely will succeed (i hope), - // but it needs to be checked \/ i'm not sure about this move - if (dataAndTag as Boolean == false) { + if (dataAndTag as? JsBoolean == false.toJsBoolean()) { throw SecretStreamCorruptedOrTamperedDataException() } - return DecryptedDataAndTag(dataAndTag.message.toUByteArray(), dataAndTag.tag.toUByte()) + return DecryptedDataAndTag((dataAndTag as CryptoSecretstreamXchacha20poly1305PullResult).message.toUByteArray(), dataAndTag.tag.toUByte()) } From 6a9cfd5006265da46d92f1ba49a2533fe31d7054 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Tue, 10 Dec 2024 20:08:28 +0300 Subject: [PATCH 14/27] External objects have been moved to Types.kt. JsSodiumInterface.kt changes: Ubyte -> Byte; UInt -> Int Next step: tests. --- .../kotlin/crypto/JsSodiumInterface.kt | 95 ++++--------------- .../kotlin/com/ionspin/kotlin/crypto/Types.kt | 58 +++++++++++ .../com/ionspin/kotlin/crypto/kdf/Kdf.kt | 4 +- .../kotlin/crypto/pwhash/PasswordHash.kt | 16 ++-- .../crypto/secretstream/SecretStream.kt | 6 +- .../kotlin/crypto/signature/Signature.kt | 13 ++- .../ionspin/kotlin/crypto/stream/Stream.kt | 6 +- .../kotlin/crypto/util/LibsodiumRandom.kt | 6 +- 8 files changed, 103 insertions(+), 101 deletions(-) create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/Types.kt diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt index 13fa4b1..3f5f890 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -10,61 +10,6 @@ import org.khronos.webgl.Uint8Array * on 27-May-2020 */ -typealias UByte = Int -typealias UInt = Long - -external object Chacha20poly1305EncryptDetachedResult : JsAny { - val ciphertext: Uint8Array - var mac: Uint8Array -} - -external object CryptoBoxDetachedResult : JsAny { - val ciphertext: Uint8Array - var mac: Uint8Array -} - -external object CryptoBoxKeypairResult: JsAny { - val publicKey: Uint8Array - val privateKey: Uint8Array -} - -external object CryptoKxClientSessionKeysResult: JsAny { - val sharedRx: Uint8Array - val sharedTx: Uint8Array -} - -external object CryptoKxKeypairResult: JsAny { - val publicKey: Uint8Array - val privateKey: Uint8Array -} - -external object CryptoKxSeedKeypairResult: JsAny { - val publicKey: Uint8Array - val privateKey: Uint8Array -} - -external object CryptoKxServerSessionKeysResult: JsAny { - val sharedRx: Uint8Array - val sharedTx: Uint8Array -} - -external object CryptoSecretboxDetachedResult: JsAny { - val cipher: Uint8Array - val mac: Uint8Array -} - -external object CryptoSecretstreamXchacha20poly1305InitPushResult: JsAny { - val state: Uint8Array - val header: Uint8Array -} - -external object CryptoSecretstreamXchacha20poly1305PullResult: JsAny { - val message: Uint8Array - val tag: UByte -} - - - @JsModule("libsodium-wrappers-sumo") external object JsSodiumInterface { @@ -153,13 +98,13 @@ external object JsSodiumInterface { // TODO: два варианта: \/ // 1. Меняем юбайт на байт и юинт на инт \/ // 2. Меняем юбайт на инт и юинт на лонг \/ и далее по списку - fun crypto_secretstream_xchacha20poly1305_push(state: JsAny, message: Uint8Array, associatedData: Uint8Array, tag: UByte) : Uint8Array + fun crypto_secretstream_xchacha20poly1305_push(state: JsAny, message: Uint8Array, associatedData: Uint8Array, tag: Byte) : Uint8Array //decrypt @JsName("crypto_secretstream_xchacha20poly1305_init_pull") fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : JsAny @JsName("crypto_secretstream_xchacha20poly1305_pull") - fun crypto_secretstream_xchacha20poly1305_pull(state: JsAny, ciphertext: Uint8Array, associatedData: Uint8Array) : CryptoSecretstreamXchacha20poly1305PullResult + fun crypto_secretstream_xchacha20poly1305_pull(state: JsAny, ciphertext: Uint8Array, associatedData: Uint8Array) : JsAny //keygen and rekey @JsName("crypto_secretstream_xchacha20poly1305_keygen") @@ -243,9 +188,9 @@ external object JsSodiumInterface { // ---- Box ---- @JsName("crypto_box_keypair") - fun crypto_box_keypair() : CryptoBoxKeypairResult + fun crypto_box_keypair() : Keypair @JsName("crypto_box_seed_keypair") - fun crypto_box_seed_keypair(seed : Uint8Array) : CryptoBoxKeypairResult + fun crypto_box_seed_keypair(seed : Uint8Array) : Keypair @JsName("crypto_box_easy") fun crypto_box_easy(message: Uint8Array, nonce: Uint8Array, @@ -302,13 +247,13 @@ external object JsSodiumInterface { @JsName("crypto_sign_final_verify") fun crypto_sign_final_verify(state: JsAny, signature: Uint8Array, publicKey: Uint8Array) : Boolean @JsName("crypto_sign_init") - fun crypto_sign_init() : JsAny + fun crypto_sign_init() : SignatureStateType @JsName("crypto_sign_keypair") - fun crypto_sign_keypair() : JsAny + fun crypto_sign_keypair() : Keypair @JsName("crypto_sign_open") fun crypto_sign_open(signedMessage: Uint8Array, publicKey: Uint8Array) : Uint8Array @JsName("crypto_sign_seed_keypair") - fun crypto_sign_seed_keypair(seed: Uint8Array) : JsAny + fun crypto_sign_seed_keypair(seed: Uint8Array) : Keypair @JsName("crypto_sign_update") fun crypto_sign_update(state: JsAny, message: Uint8Array) @JsName("crypto_sign_verify_detached") @@ -321,7 +266,7 @@ external object JsSodiumInterface { // ---- KDF ---- @JsName("crypto_kdf_derive_from_key") - fun crypto_kdf_derive_from_key(subkey_len: UInt, subkeyId : UInt, ctx: String, key: Uint8Array) : Uint8Array + fun crypto_kdf_derive_from_key(subkey_len: Int, subkeyId : Int, ctx: String, key: Uint8Array) : Uint8Array @JsName("crypto_kdf_keygen") fun crypto_kdf_keygen() : Uint8Array @@ -330,11 +275,11 @@ external object JsSodiumInterface { // ---- Password hashing ---- @JsName("crypto_pwhash") - fun crypto_pwhash(keyLength : UInt, password : Uint8Array, salt: Uint8Array, opsLimit: UInt, memLimit: UInt, algorithm: UInt) : Uint8Array + fun crypto_pwhash(keyLength : Int, password : Uint8Array, salt: Uint8Array, opsLimit: Int, memLimit: Int, algorithm: Int) : Uint8Array @JsName("crypto_pwhash_str") - fun crypto_pwhash_str(password: Uint8Array, opsLimit: UInt, memLimit: UInt) : String + fun crypto_pwhash_str(password: Uint8Array, opsLimit: Int, memLimit: Int) : String @JsName("crypto_pwhash_str_needs_rehash") - fun crypto_pwhash_str_needs_rehash(hashedPassword: String, opsLimit: UInt, memLimit: UInt) : Boolean + fun crypto_pwhash_str_needs_rehash(hashedPassword: String, opsLimit: Int, memLimit: Int) : Boolean @JsName("crypto_pwhash_str_verify") fun crypto_pwhash_str_verify(hashedPassword: String, password: Uint8Array) : Boolean @@ -369,11 +314,11 @@ external object JsSodiumInterface { @JsName("randombytes_buf") fun randombytes_buf(length: Int) : Uint8Array @JsName("randombytes_buf_deterministic") - fun randombytes_buf_deterministic(length: UInt, seed : Uint8Array) : Uint8Array + fun randombytes_buf_deterministic(length: Int, seed : Uint8Array) : Uint8Array @JsName("randombytes_random") - fun randombytes_random() : UInt + fun randombytes_random() : Int @JsName("randombytes_uniform") - fun randombytes_uniform(upper_bound: UInt) : UInt + fun randombytes_uniform(upper_bound: Int) : Int // ---- Utils end ---- @@ -381,9 +326,9 @@ external object JsSodiumInterface { @JsName("crypto_kx_client_session_keys") fun crypto_kx_client_session_keys(clientPublicKey: Uint8Array, clientSecretKey: Uint8Array, serverPublicKey: Uint8Array) : CryptoKxClientSessionKeysResult @JsName("crypto_kx_keypair") - fun crypto_kx_keypair() : CryptoKxKeypairResult + fun crypto_kx_keypair() : Keypair @JsName("crypto_kx_seed_keypair") - fun crypto_kx_seed_keypair(seed: Uint8Array) : CryptoKxSeedKeypairResult + fun crypto_kx_seed_keypair(seed: Uint8Array) : Keypair @JsName("crypto_kx_server_session_keys") fun crypto_kx_server_session_keys(serverPublicKey: Uint8Array, serverSecretKey: Uint8Array, clientPublicKey: Uint8Array) : CryptoKxServerSessionKeysResult @@ -391,24 +336,24 @@ external object JsSodiumInterface { // -- Stream ---- @JsName("crypto_stream_chacha20") - fun crypto_stream_chacha20(outLength: UInt, key: Uint8Array, nonce: Uint8Array) : Uint8Array + fun crypto_stream_chacha20(outLength: Int, key: Uint8Array, nonce: Uint8Array) : Uint8Array @JsName("crypto_stream_chacha20_ietf_xor") fun crypto_stream_chacha20_ietf_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_stream_chacha20_ietf_xor_ic") - fun crypto_stream_chacha20_ietf_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array + fun crypto_stream_chacha20_ietf_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: Int, key: Uint8Array) : Uint8Array @JsName("crypto_stream_chacha20_keygen") fun crypto_stream_chacha20_keygen() : Uint8Array @JsName("crypto_stream_chacha20_xor") fun crypto_stream_chacha20_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_stream_chacha20_xor_ic") - fun crypto_stream_chacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array + fun crypto_stream_chacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: Int, key: Uint8Array) : Uint8Array @JsName("crypto_stream_xchacha20_keygen") fun crypto_stream_xchacha20_keygen() : Uint8Array @JsName("crypto_stream_xchacha20_xor") fun crypto_stream_xchacha20_xor(message : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_stream_xchacha20_xor_ic") - fun crypto_stream_xchacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array + fun crypto_stream_xchacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: Int, key: Uint8Array) : Uint8Array // ---- Stream end ---- diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/Types.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/Types.kt new file mode 100644 index 0000000..1ca6f46 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/Types.kt @@ -0,0 +1,58 @@ +package ext.libsodium.com.ionspin.kotlin.crypto + + +import org.khronos.webgl.Uint8Array + +//TODO: может быть стоит поудалять ненужное + +external object SignatureStateType: JsAny + +external object Chacha20poly1305EncryptDetachedResult : JsAny { + val ciphertext: Uint8Array + var mac: Uint8Array +} + +external object CryptoBoxDetachedResult : JsAny { + val ciphertext: Uint8Array + var mac: Uint8Array +} + +//external object CryptoBoxKeypairResult: JsAny { +// val publicKey: Uint8Array +// val privateKey: Uint8Array +//} + +external object CryptoKxClientSessionKeysResult: JsAny { + val sharedRx: Uint8Array + val sharedTx: Uint8Array +} + +//external object CryptoKxKeypairResult: JsAny { +// val publicKey: Uint8Array +// val privateKey: Uint8Array +//} + +external object Keypair: JsAny { + val publicKey: Uint8Array + val privateKey: Uint8Array +} +// +external object CryptoKxServerSessionKeysResult: JsAny { + val sharedRx: Uint8Array + val sharedTx: Uint8Array +} + +external object CryptoSecretboxDetachedResult: JsAny { + val cipher: Uint8Array + val mac: Uint8Array +} + +external object CryptoSecretstreamXchacha20poly1305InitPushResult: JsAny { + val state: Uint8Array + val header: Uint8Array +} + +external object CryptoSecretstreamXchacha20poly1305PullResult: JsAny { + val message: Uint8Array + val tag: Byte +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt index bdf88c0..f6c1925 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt @@ -26,8 +26,8 @@ actual object Kdf { masterKey: UByteArray ): UByteArray { return getSodium().crypto_kdf_derive_from_key( - subkeyLength.toLong(), - subkeyId.toLong(), + subkeyLength, + subkeyId.toInt(), context, masterKey.toUInt8Array() ).toUByteArray() diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt index e678013..5f5b3be 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt @@ -26,12 +26,12 @@ actual object PasswordHash { throw RuntimeException("Javascript doesnt support more than ${UInt.MAX_VALUE} for opslimit") } return getSodium().crypto_pwhash( - outputLength.toLong(), + outputLength, password.encodeToUByteArray().toUInt8Array(), salt.toUInt8Array(), - opsLimit.toLong(), - memLimit.toLong(), - algorithm.toLong() + opsLimit.toInt(), + memLimit, + algorithm ).toUByteArray() } @@ -51,8 +51,8 @@ actual object PasswordHash { } return getSodium().crypto_pwhash_str( password.encodeToUByteArray().toUInt8Array(), - opslimit.toLong(), - memlimit.toLong() + opslimit.toInt(), + memlimit ) } @@ -73,8 +73,8 @@ actual object PasswordHash { return if ( getSodium().crypto_pwhash_str_needs_rehash( passwordHash, - opslimit.toLong(), - memlimit.toLong() + opslimit.toInt(), + memlimit ) ) { 1 diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt index 6d74972..652f3c8 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt @@ -1,15 +1,11 @@ package com.ionspin.kotlin.crypto.secretstream import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.CryptoSecretstreamXchacha20poly1305PullResult import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array import org.khronos.webgl.Uint8Array -//TODO: вынести все external objects в отдельный файл (и в JsSodiumInterface.kt) -external object CryptoSecretstreamXchacha20poly1305PullResult: JsAny { - val message: Uint8Array - val tag: Byte -} external object SecretStreamStateType: JsAny diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/signature/Signature.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/signature/Signature.kt index 6b6fb3b..aaf5940 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/signature/Signature.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/signature/Signature.kt @@ -1,11 +1,14 @@ package com.ionspin.kotlin.crypto.signature import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.SignatureStateType import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array import org.khronos.webgl.Uint8Array -actual typealias SignatureState = Any + + +actual typealias SignatureState = SignatureStateType actual object Signature { actual fun init(): SignatureState { @@ -48,8 +51,8 @@ actual object Signature { actual fun keypair(): SignatureKeyPair { val keypair = getSodium().crypto_sign_keypair() return SignatureKeyPair( - (keypair.publicKey as Uint8Array).toUByteArray(), - (keypair.privateKey as Uint8Array).toUByteArray() + keypair.publicKey.toUByteArray(), + keypair.privateKey.toUByteArray() ) } @@ -61,8 +64,8 @@ actual object Signature { actual fun seedKeypair(seed: UByteArray): SignatureKeyPair { val keypair = getSodium().crypto_sign_seed_keypair(seed.toUInt8Array()) return SignatureKeyPair( - (keypair.publicKey as Uint8Array).toUByteArray(), - (keypair.privateKey as Uint8Array).toUByteArray() + keypair.publicKey.toUByteArray(), + keypair.privateKey.toUByteArray() ) } diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/stream/Stream.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/stream/Stream.kt index 35a9348..eb076bb 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/stream/Stream.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/stream/Stream.kt @@ -7,7 +7,7 @@ import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array actual object Stream { actual fun chacha20(clen: Int, nonce: UByteArray, key: UByteArray): UByteArray { //Note, unlike the other ones, here the positions of key and nonce are reversed. - val result = getSodium().crypto_stream_chacha20(clen.toUInt(), key.toUInt8Array(), nonce.toUInt8Array()) + val result = getSodium().crypto_stream_chacha20(clen, key.toUInt8Array(), nonce.toUInt8Array()) return result.toUByteArray() } @@ -35,7 +35,7 @@ actual object Stream { val result = getSodium().crypto_stream_chacha20_ietf_xor_ic( message.toUInt8Array(), nonce.toUInt8Array(), - initialCounter, + initialCounter.toInt(), key.toUInt8Array() ) @@ -74,7 +74,7 @@ actual object Stream { val result = getSodium().crypto_stream_chacha20_xor_ic( message.toUInt8Array(), nonce.toUInt8Array(), - initialCounter.toUInt(), + initialCounter.toInt(), key.toUInt8Array() ) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumRandom.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumRandom.kt index 1854710..de82fe4 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumRandom.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumRandom.kt @@ -26,14 +26,14 @@ actual object LibsodiumRandom { * */ actual fun bufDeterministic(size: Int, seed: UByteArray): UByteArray { - return getSodium().randombytes_buf_deterministic(size.toUInt(), seed.toUInt8Array()).toUByteArray() + return getSodium().randombytes_buf_deterministic(size, seed.toUInt8Array()).toUByteArray() } /** * The randombytes_random() function returns an unpredictable value between 0 and 0xffffffff (included). */ actual fun random(): UInt { - return getSodium().randombytes_random() + return getSodium().randombytes_random().toUInt() } /** @@ -42,7 +42,7 @@ actual object LibsodiumRandom { * upper_bound is not a power of 2. Note that an upper_bound < 2 leaves only a single element to be chosen, namely 0 */ actual fun uniform(upperBound: UInt): UInt { - return getSodium().randombytes_uniform(upperBound) + return getSodium().randombytes_uniform(upperBound.toInt()).toUInt() } } From ccb47be795b2fc6b2bcabe712844134cd0cbee05 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Mon, 16 Dec 2024 22:46:25 +0300 Subject: [PATCH 15/27] We have runTest for wasmJs now, but there is a weird problem with library files --- .../build.gradle.kts | 9 +++++++++ .../ionspin/kotlin/crypto/debug/WasmSymbolsTest.kt | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/debug/WasmSymbolsTest.kt diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index f21cbb0..f8bbe2f 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -302,6 +302,10 @@ kotlin { implementation(kotlin(Deps.Common.test)) implementation(kotlin(Deps.Common.testAnnotation)) implementation(Deps.Common.coroutines) + +// implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") +// implementation(kotlin("test")) +// implementation(kotlin("test-junit")) } } @@ -577,6 +581,11 @@ kotlin { dependencies { // implementation(kotlin(Deps.wasmJs.test)) implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") +// implementation("kotlinx-coroutines-test") + + implementation(kotlin("test")) + implementation(kotlin("test-junit")) } } diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/debug/WasmSymbolsTest.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/debug/WasmSymbolsTest.kt new file mode 100644 index 0000000..766a1ac --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/debug/WasmSymbolsTest.kt @@ -0,0 +1,11 @@ +package com.ionspin.kotlin.crypto.debug + +import kotlin.test.Test +import kotlin.test.assertEquals + +class WasmSymbolsTest { +// @Test +// fun wasmSymbolsTest() { +// assertEquals(42, 42) +// } +} From 9f7fc6e379aa2b24fcc85b956c126ac73b8a20ac Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Thu, 26 Dec 2024 00:54:34 +0300 Subject: [PATCH 16/27] runTest that should work as it works in test project --- .../com/ionspin/kotlin/crypto/debug/DebugTest.kt | 9 +++++++++ .../ionspin/kotlin/crypto/secretstream/modifyState.kt | 4 ++++ .../kotlin/com/ionspin/kotlin/crypto/util/runTest.kt | 10 ++++++++++ 3 files changed, 23 insertions(+) create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/debug/DebugTest.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/secretstream/modifyState.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/debug/DebugTest.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/debug/DebugTest.kt new file mode 100644 index 0000000..9c23968 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/debug/DebugTest.kt @@ -0,0 +1,9 @@ +package com.ionspin.kotlin.crypto.debug + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 08-Feb-2021 + */ +class DebugTest { +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/secretstream/modifyState.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/secretstream/modifyState.kt new file mode 100644 index 0000000..27130e3 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/secretstream/modifyState.kt @@ -0,0 +1,4 @@ +package com.ionspin.kotlin.crypto.secretstream + +actual fun modifyState(state: SecretStreamState, forceNonce: UByteArray) { +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt new file mode 100644 index 0000000..ba77e1e --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt @@ -0,0 +1,10 @@ +package com.ionspin.kotlin.crypto.util + +import kotlinx.coroutines.CoroutineScope + + +actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) { + kotlinx.coroutines.test.runTest { + block(this) + } +} From bd83e9aee00ec6e4ba8b5aeacf185b80f6e8162e Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Thu, 26 Dec 2024 01:03:48 +0300 Subject: [PATCH 17/27] Changed gradle files to be like in test project, wasmJsBrowser run appeared. Also added wasmJs to crypto-api gradle --- gradle.properties | 2 ++ multiplatform-crypto-api/build.gradle.kts | 30 +++++++++++++++++++ .../build.gradle.kts | 25 ++++++++-------- settings.gradle.kts | 6 ++++ 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/gradle.properties b/gradle.properties index 395b98b..f7dbe07 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,3 +26,5 @@ org.gradle.jvmargs=-Xmx4g android.useAndroidX=true kotlin.js.webpack.major.version=4 + +kotlin.mpp.applyDefaultHierarchyTemplate=false diff --git a/multiplatform-crypto-api/build.gradle.kts b/multiplatform-crypto-api/build.gradle.kts index 00be5d9..8ea9db2 100644 --- a/multiplatform-crypto-api/build.gradle.kts +++ b/multiplatform-crypto-api/build.gradle.kts @@ -17,6 +17,7 @@ @file:Suppress("UnstableApiUsage") +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest plugins { @@ -39,6 +40,19 @@ kotlin { val hostOsName = getHostOsName() runningOnLinuxx86_64 { jvm() + + // TODO: wasm тут копирует не апишный, если поменялся тот, то поменять и тут + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + browser { + testTask { + useKarma { + useChromeHeadless() + } + } + } + } + js(IR) { browser { testTask { @@ -142,6 +156,22 @@ kotlin { } } + // TODO: может сунуть обратно в ранинг онг линукс, как и то, что выше + val wasmJsMain by getting { + dependencies { + // implementation(kotlin(Deps.wasmJs.stdLib)) + implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + } + } + val wasmJsTest by getting { + dependencies { + implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") + + implementation(kotlin("test")) + } + } + runningOnMacos { val tvosX64Main by getting { dependsOn(commonMain) diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index f8bbe2f..10d4636 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -17,10 +17,12 @@ @file:Suppress("UnstableApiUsage") -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest -import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest import org.gradle.api.tasks.testing.logging.TestExceptionFormat +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest +import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig +import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest plugins { kotlin(PluginsDeps.multiplatform) @@ -702,16 +704,15 @@ tasks { } - val jvmTest by getting(Test::class) { - testLogging { - events("PASSED", "FAILED", "SKIPPED") - exceptionFormat = TestExceptionFormat.FULL - showStandardStreams = true - showStackTraces = true - } - } - if (getHostOsName() == "linux" && getHostArchitecture() == "x86-64") { + val jvmTest by getting(Test::class) { + testLogging { + events("PASSED", "FAILED", "SKIPPED") + exceptionFormat = TestExceptionFormat.FULL + showStandardStreams = true + showStackTraces = true + } + } val linuxX64Test by getting(KotlinNativeTest::class) { diff --git a/settings.gradle.kts b/settings.gradle.kts index 8719ca8..a0fd1b4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -19,6 +19,7 @@ pluginManagement { repositories { mavenCentral() maven("https://plugins.gradle.org/m2/") + gradlePluginPortal() } resolutionStrategy { @@ -28,6 +29,11 @@ pluginManagement { } } } + + plugins { + kotlin("multiplatform") version "2.0.21" + kotlin("plugin.serialization") version "2.0.0" + } } rootProject.name = "KotlinMultiplatformLibsodium" include("multiplatform-crypto-api") From 59f2d77890ca913271572d8c575c922b7c6e1d05 Mon Sep 17 00:00:00 2001 From: PlaceboAddict Date: Sat, 28 Dec 2024 00:23:46 +0300 Subject: [PATCH 18/27] Problem with 1.9.23 KMP version. It's been fixed in 2.0 so it needs to be updated --- build.gradle.kts | 2 +- multiplatform-crypto-api/build.gradle.kts | 2 +- .../build.gradle.kts | 51 +++++++++---------- .../com/ionspin/kotlin/crypto/SmokeTest.kt | 1 + .../src/wasmJsTest/kotlin/TestTest.kt | 11 ++++ .../kotlin/crypto/debug/WasmSymbolsTest.kt | 8 +-- package-lock.json | 17 +++++++ sample/build.gradle.kts | 50 +++++++++++++++++- .../com/ionspin/kotlin/crypto/sample/App.kt | 0 .../com/ionspin/kotlin/crypto/sample/Main.kt | 12 +++++ sample/src/wasmJsMain/resources/index.html | 12 +++++ 11 files changed, 132 insertions(+), 34 deletions(-) create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/TestTest.kt create mode 100644 package-lock.json create mode 100644 sample/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/sample/App.kt create mode 100644 sample/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/sample/Main.kt create mode 100644 sample/src/wasmJsMain/resources/index.html diff --git a/build.gradle.kts b/build.gradle.kts index 701a712..903e93b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,7 +20,7 @@ buildscript { dependencies { classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23") classpath("com.android.tools.build:gradle:7.2.2") - classpath ("org.jetbrains.dokka:dokka-gradle-plugin:1.9.20") + classpath("org.jetbrains.dokka:dokka-gradle-plugin:1.9.20") } repositories { diff --git a/multiplatform-crypto-api/build.gradle.kts b/multiplatform-crypto-api/build.gradle.kts index 8ea9db2..39cb7ce 100644 --- a/multiplatform-crypto-api/build.gradle.kts +++ b/multiplatform-crypto-api/build.gradle.kts @@ -47,7 +47,7 @@ kotlin { browser { testTask { useKarma { - useChromeHeadless() + useChrome() } } } diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index 10d4636..1d16ecf 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -306,7 +306,7 @@ kotlin { implementation(Deps.Common.coroutines) // implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") -// implementation(kotlin("test")) + implementation(kotlin("test")) // implementation(kotlin("test-junit")) } } @@ -333,6 +333,24 @@ kotlin { } } + // TODO: это скопипасчено с блока runningOnLinuxx86_64 (примерно 590 строка) + val wasmJsMain by getting { + dependencies { + // implementation(kotlin(Deps.wasmJs.stdLib)) + implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + } + } + val wasmJsTest by getting { + dependencies { + dependsOn(commonTest) + implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") + + implementation(kotlin("test")) + } + } + + //Set up shared source sets //linux, linuxArm32Hfp, linuxArm64 val linux64Bit = setOf( @@ -572,25 +590,6 @@ kotlin { runningOnLinuxx86_64 { println("Configuring Linux 64 Bit source sets") - val wasmJsMain by getting { - // TODO: разобраться (и с test) - dependencies { - // implementation(kotlin(Deps.wasmJs.stdLib)) - implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) - } - } - val wasmJsTest by getting { - dependencies { -// implementation(kotlin(Deps.wasmJs.test)) - implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") -// implementation("kotlinx-coroutines-test") - - implementation(kotlin("test")) - implementation(kotlin("test-junit")) - } - } - val jsMain by getting { dependencies { implementation(kotlin(Deps.Js.stdLib)) @@ -742,12 +741,12 @@ tasks { // } // TODO: ваще не жс тест, помогите -// val wasmJsBrowserTest by getting(KotlinJsTest::class) { -// testLogging { -// events("PASSED", "FAILED", "SKIPPED") -// showStandardStreams = true -// } -// } + val wasmJsBrowserTest by getting(KotlinJsTest::class) { + testLogging { + events("PASSED", "FAILED", "SKIPPED") + showStandardStreams = true + } + } val jsBrowserTest by getting(KotlinJsTest::class) { testLogging { diff --git a/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SmokeTest.kt b/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SmokeTest.kt index f43e8c7..6214ac8 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SmokeTest.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SmokeTest.kt @@ -17,6 +17,7 @@ class SmokeTest { //TODO Browser ignores our testBlocking, node works fine though @Test fun testIfLibraryIsNotOnFire() { + throw Exception("aoaoao") testBlocking { LibsodiumInitializer.initialize() val hashResult = GenericHash.genericHash("Hello".encodeToUByteArray(), 64) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/TestTest.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/TestTest.kt new file mode 100644 index 0000000..902727a --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/TestTest.kt @@ -0,0 +1,11 @@ +//package com.ionspin.kotlin.crypto.debug + +import kotlin.test.Test +import kotlin.test.assertEquals + +class TestTest { + @Test + fun wasmSymbolsTest() { + assertEquals(42, 42) + } +} diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/debug/WasmSymbolsTest.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/debug/WasmSymbolsTest.kt index 766a1ac..1f7b960 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/debug/WasmSymbolsTest.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/debug/WasmSymbolsTest.kt @@ -4,8 +4,8 @@ import kotlin.test.Test import kotlin.test.assertEquals class WasmSymbolsTest { -// @Test -// fun wasmSymbolsTest() { -// assertEquals(42, 42) -// } + @Test + fun wasmSymbolsTest() { + assertEquals(42, 42) + } } diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a2f7fcd --- /dev/null +++ b/package-lock.json @@ -0,0 +1,17 @@ +{ + "name": "kotlin-multiplatform-libsodium", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "libsodium-sumo": "^0.7.15" + } + }, + "node_modules/libsodium-sumo": { + "version": "0.7.15", + "resolved": "https://registry.npmjs.org/libsodium-sumo/-/libsodium-sumo-0.7.15.tgz", + "integrity": "sha512-5tPmqPmq8T8Nikpm1Nqj0hBHvsLFCXvdhBFV7SGOitQPZAA6jso8XoL0r4L7vmfKXr486fiQInvErHtEvizFMw==" + } + } +} diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index f65e1a9..cc0d7a8 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -17,9 +17,9 @@ @file:Suppress("UnstableApiUsage") -import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest -import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest import org.gradle.api.tasks.testing.logging.TestExceptionFormat +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask plugins { @@ -82,6 +82,36 @@ kotlin { } + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + browser { + webpackTask { + + } + testTask { + useKarma { + useChrome() + } + } + } + binaries.executable() +// browser { +// val rootDirPath = project.rootDir.path +// val projectDirPath = project.projectDir.path +// commonWebpackConfig { +// outputFileName = "composeApp.js" +// devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply { +//// static = (static ?: mutableListOf()).apply { +//// // Serve sources to debug inside browser +//// add(rootDirPath) +//// add(projectDirPath) +//// } +// } +// } +// } +// binaries.executable() + } + linuxX64("linux") { binaries { @@ -207,6 +237,22 @@ kotlin { } } + val wasmJsMain by getting { + dependencies { + // implementation(kotlin(Deps.wasmJs.stdLib)) + implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + } + } + val wasmJsTest by getting { + dependencies { + dependsOn(commonTest) + implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") + + implementation(kotlin("test")) + } + } + // val nativeMain by creating { diff --git a/sample/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/sample/App.kt b/sample/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/sample/App.kt new file mode 100644 index 0000000..e69de29 diff --git a/sample/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/sample/Main.kt b/sample/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/sample/Main.kt new file mode 100644 index 0000000..c514c11 --- /dev/null +++ b/sample/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/sample/Main.kt @@ -0,0 +1,12 @@ + + +import com.ionspin.kotlin.crypto.LibsodiumInitializer + + +fun main() { + LibsodiumInitializer.initializeWithCallback { +// val hash = Hash.sha512("123".encodeToUByteArray()) +// println("Hash (SHA512) of 123: ${hash.toHexString()}") + println("Hello") + } +} diff --git a/sample/src/wasmJsMain/resources/index.html b/sample/src/wasmJsMain/resources/index.html new file mode 100644 index 0000000..9f04a20 --- /dev/null +++ b/sample/src/wasmJsMain/resources/index.html @@ -0,0 +1,12 @@ + + + + + Libsodium bindings sample app! + + + +
+ + + From 504e8db46b79939be3726f2071f9f60014bf6800 Mon Sep 17 00:00:00 2001 From: kildishevps Date: Sat, 28 Dec 2024 06:22:08 +0300 Subject: [PATCH 19/27] Changed gradle and kotlin versions and made LibsodiumInitializer.initializeWithCallback a bit prettier --- build.gradle.kts | 2 +- buildSrc/src/main/kotlin/Deps.kt | 2 +- .../build.gradle.kts | 2 +- .../com/ionspin/kotlin/crypto/JsSodiumLoader.kt | 12 ++++-------- .../ionspin/kotlin/crypto/LibsodiumInitializer.kt | 2 -- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 903e93b..dc29a2f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ buildscript { dependencies { - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21") classpath("com.android.tools.build:gradle:7.2.2") classpath("org.jetbrains.dokka:dokka-gradle-plugin:1.9.20") } diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 8ff2a7a..5b8d02d 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -16,7 +16,7 @@ object Versions { val kotlinCoroutines = "1.8.0" - val kotlin = "1.9.23" + val kotlin = "2.0.21" val kotlinSerialization = "1.6.3" val kotlinSerializationPlugin = kotlin val taskTreePlugin = "1.5" diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index 1d16ecf..d4e2de5 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -407,7 +407,7 @@ kotlin { ) ) - compilations.getByName("main") { + this@withType.compilations.getByName("main") { val libsodiumCinterop by cinterops.creating { defFile(projectRef.file("src/nativeInterop/cinterop/libsodium.def")) compilerOpts.add("-I${projectRef.rootDir}/sodiumWrapper/static-arm64/include/") diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt index 14937b2..7dfa7a4 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt @@ -2,12 +2,7 @@ package ext.libsodium.com.ionspin.kotlin.crypto import com.ionspin.kotlin.crypto.getSodiumLoaded 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 ext.libsodium.* import kotlin.coroutines.suspendCoroutine /** @@ -50,12 +45,13 @@ object JsSodiumLoader { } } - fun loadWithCallback(doneCallback: () -> (JsAny)) { + fun loadWithCallback(doneCallback: () -> (Unit)) { if (!getSodiumLoaded()) { - _libsodiumPromise.then { + _libsodiumPromise.then { sodium_init() sodiumLoaded = true doneCallback.invoke() + null } } else { doneCallback.invoke() diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt index 6d63773..aa5254b 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt @@ -26,8 +26,6 @@ actual object LibsodiumInitializer { JsSodiumLoader.loadWithCallback { isPlatformInitialized = true done() - // TODO: there's no return needed!!! - "null".toJsString() } } From c6946c90b46037bfb6d65eaf48356738f4e8aebd Mon Sep 17 00:00:00 2001 From: kildishevps Date: Sun, 29 Dec 2024 17:41:29 +0300 Subject: [PATCH 20/27] Fixed Throable cast error and changed gradle version in one more place --- buildSrc/build.gradle.kts | 2 +- multiplatform-crypto-api/build.gradle.kts | 2 +- multiplatform-crypto-libsodium-bindings/build.gradle.kts | 2 +- .../kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt | 4 ++-- sample/build.gradle.kts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 3d33254..1ea0a09 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -28,7 +28,7 @@ repositories { } dependencies { - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21") implementation("com.android.tools.build:gradle:7.2.2") implementation ("org.jetbrains.dokka:dokka-gradle-plugin:1.9.20") } diff --git a/multiplatform-crypto-api/build.gradle.kts b/multiplatform-crypto-api/build.gradle.kts index 39cb7ce..423c93a 100644 --- a/multiplatform-crypto-api/build.gradle.kts +++ b/multiplatform-crypto-api/build.gradle.kts @@ -17,7 +17,7 @@ @file:Suppress("UnstableApiUsage") -import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest plugins { diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index d4e2de5..399e413 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -18,8 +18,8 @@ @file:Suppress("UnstableApiUsage") import org.gradle.api.tasks.testing.logging.TestExceptionFormat +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt index 7dfa7a4..a96f2d4 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt @@ -32,11 +32,11 @@ object JsSodiumLoader { continuation.resumeWith(Result.success(Unit)) null }.catch { e -> - val throwable = e as? Throwable + val throwable = e.toThrowableOrNull() if (throwable != null) { continuation.resumeWith(Result.failure(throwable)) } else { - continuation.resumeWith(Result.failure(Exception("Error: $e"))) + continuation.resumeWith(Result.failure(Throwable("Unknown error", throwable))) } null } diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index cc0d7a8..1eefd25 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -18,7 +18,7 @@ @file:Suppress("UnstableApiUsage") import org.gradle.api.tasks.testing.logging.TestExceptionFormat -import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask From e2a079f0d2915074d5630e0f65487af9dab522fa Mon Sep 17 00:00:00 2001 From: kildishevps Date: Mon, 30 Dec 2024 17:36:14 +0300 Subject: [PATCH 21/27] Fixed libsodiumPromise.then TypeCastError error --- .../src/wasmJsMain/kotlin/libsodium.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/libsodium.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/libsodium.kt index e55db33..9c3b6be 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/libsodium.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/libsodium.kt @@ -1,5 +1,4 @@ @file:JsModule("libsodium-sumo") -//@file:JsNonModule package ext.libsodium import org.khronos.webgl.Uint8Array @@ -13,7 +12,7 @@ import kotlin.js.Promise */ @JsName("ready") -external val _libsodiumPromise : Promise +external val _libsodiumPromise : Promise @JsName("_sodium_init") external fun sodium_init() : Int From 083df8a73c279fd31aad8e56db6021bc92f77982 Mon Sep 17 00:00:00 2001 From: kildishevps Date: Tue, 31 Dec 2024 01:30:15 +0300 Subject: [PATCH 22/27] Sample (and maybe something else too, idk) works now!! --- kotlin-js-store/yarn.lock | 785 +++++++++--------- .../com/ionspin/kotlin/crypto/SmokeTest.kt | 2 - .../kotlin/crypto/JsSodiumInterface.kt | 9 +- .../kotlin/crypto/LibsodiumInitializer.kt | 3 +- .../webpack.config.d/patch.js | 4 + .../com/ionspin/kotlin/crypto/sample/Main.kt | 13 +- 6 files changed, 432 insertions(+), 384 deletions(-) create mode 100644 multiplatform-crypto-libsodium-bindings/webpack.config.d/patch.js diff --git a/kotlin-js-store/yarn.lock b/kotlin-js-store/yarn.lock index 43b2e38..e381855 100644 --- a/kotlin-js-store/yarn.lock +++ b/kotlin-js-store/yarn.lock @@ -44,7 +44,15 @@ resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32" integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg== -"@jridgewell/trace-mapping@^0.3.17", "@jridgewell/trace-mapping@^0.3.9": +"@jridgewell/trace-mapping@^0.3.25": + version "0.3.25" + resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz#15f190e98895f3fc23276ee14bc76b675c2e50f0" + integrity sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ== + dependencies: + "@jridgewell/resolve-uri" "^3.1.0" + "@jridgewell/sourcemap-codec" "^1.4.14" + +"@jridgewell/trace-mapping@^0.3.9": version "0.3.19" resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz#f8a3249862f91be48d3127c3cfe992f79b4b8811" integrity sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw== @@ -57,6 +65,11 @@ resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b" integrity sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A== +"@socket.io/component-emitter@~3.1.0": + version "3.1.2" + resolved "https://registry.yarnpkg.com/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz#821f8442f4175d8f0467b9daf26e3a18e2d02af2" + integrity sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA== + "@types/body-parser@*": version "1.19.2" resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.2.tgz#aea2059e28b7658639081347ac4fab3de166e6f0" @@ -72,11 +85,6 @@ dependencies: "@types/node" "*" -"@types/component-emitter@^1.2.10": - version "1.2.11" - resolved "https://registry.yarnpkg.com/@types/component-emitter/-/component-emitter-1.2.11.tgz#50d47d42b347253817a39709fef03ce66a108506" - integrity sha512-SRXjM+tfsSlA9VuG8hGO2nft2p8zjXCK1VcC6N4NXbBbYbSia9kzCChYQajIjzIqOOOuh5Ock6MmV2oux4jDZQ== - "@types/connect-history-api-fallback@^1.3.5": version "1.5.0" resolved "https://registry.yarnpkg.com/@types/connect-history-api-fallback/-/connect-history-api-fallback-1.5.0.tgz#9fd20b3974bdc2bcd4ac6567e2e0f6885cb2cf41" @@ -118,11 +126,16 @@ "@types/estree" "*" "@types/json-schema" "*" -"@types/estree@*", "@types/estree@^1.0.0": +"@types/estree@*": version "1.0.1" resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.1.tgz#aa22750962f3bf0e79d753d3cc067f010c95f194" integrity sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA== +"@types/estree@^1.0.5": + version "1.0.6" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.6.tgz#628effeeae2064a1b4e79f78e81d87b7e5fc7b50" + integrity sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw== + "@types/express-serve-static-core@*", "@types/express-serve-static-core@^4.17.33": version "4.17.35" resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.35.tgz#c95dd4424f0d32e525d23812aa8ab8e4d3906c4f" @@ -221,145 +234,145 @@ dependencies: "@types/node" "*" -"@types/ws@^8.5.1": - version "8.5.5" - resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.5.tgz#af587964aa06682702ee6dcbc7be41a80e4b28eb" - integrity sha512-lwhs8hktwxSjf9UaZ9tG5M03PGogvFaH8gUgLNbN9HKIg0dvv6q+gkSuJ8HN4/VbyxkuLzCjlN7GquQ0gUJfIg== +"@types/ws@^8.5.5": + version "8.5.13" + resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.13.tgz#6414c280875e2691d0d1e080b05addbf5cb91e20" + integrity sha512-osM/gWBTPKgHV8XkTunnegTRIsvF6owmf5w+JtAfOw472dptdm0dlGv4xCt6GwQRcC2XVOvvRE/0bAoQcL2QkA== dependencies: "@types/node" "*" -"@webassemblyjs/ast@1.11.6", "@webassemblyjs/ast@^1.11.5": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.6.tgz#db046555d3c413f8966ca50a95176a0e2c642e24" - integrity sha512-IN1xI7PwOvLPgjcf180gC1bqn3q/QaOCwYUahIOhbYUu8KA/3tw2RT/T0Gidi1l7Hhj5D/INhJxiICObqpMu4Q== +"@webassemblyjs/ast@1.14.1", "@webassemblyjs/ast@^1.12.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.14.1.tgz#a9f6a07f2b03c95c8d38c4536a1fdfb521ff55b6" + integrity sha512-nuBEDgQfm1ccRp/8bCQrx1frohyufl4JlbMMZ4P1wpeOfDhF6FQkxZJ1b/e+PLwr6X1Nhw6OLme5usuBWYBvuQ== dependencies: - "@webassemblyjs/helper-numbers" "1.11.6" - "@webassemblyjs/helper-wasm-bytecode" "1.11.6" + "@webassemblyjs/helper-numbers" "1.13.2" + "@webassemblyjs/helper-wasm-bytecode" "1.13.2" -"@webassemblyjs/floating-point-hex-parser@1.11.6": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.6.tgz#dacbcb95aff135c8260f77fa3b4c5fea600a6431" - integrity sha512-ejAj9hfRJ2XMsNHk/v6Fu2dGS+i4UaXBXGemOfQ/JfQ6mdQg/WXtwleQRLLS4OvfDhv8rYnVwH27YJLMyYsxhw== +"@webassemblyjs/floating-point-hex-parser@1.13.2": + version "1.13.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.13.2.tgz#fcca1eeddb1cc4e7b6eed4fc7956d6813b21b9fb" + integrity sha512-6oXyTOzbKxGH4steLbLNOu71Oj+C8Lg34n6CqRvqfS2O71BxY6ByfMDRhBytzknj9yGUPVJ1qIKhRlAwO1AovA== -"@webassemblyjs/helper-api-error@1.11.6": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.6.tgz#6132f68c4acd59dcd141c44b18cbebbd9f2fa768" - integrity sha512-o0YkoP4pVu4rN8aTJgAyj9hC2Sv5UlkzCHhxqWj8butaLvnpdc2jOwh4ewE6CX0txSfLn/UYaV/pheS2Txg//Q== +"@webassemblyjs/helper-api-error@1.13.2": + version "1.13.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.13.2.tgz#e0a16152248bc38daee76dd7e21f15c5ef3ab1e7" + integrity sha512-U56GMYxy4ZQCbDZd6JuvvNV/WFildOjsaWD3Tzzvmw/mas3cXzRJPMjP83JqEsgSbyrmaGjBfDtV7KDXV9UzFQ== -"@webassemblyjs/helper-buffer@1.11.6": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.6.tgz#b66d73c43e296fd5e88006f18524feb0f2c7c093" - integrity sha512-z3nFzdcp1mb8nEOFFk8DrYLpHvhKC3grJD2ardfKOzmbmJvEf/tPIqCY+sNcwZIY8ZD7IkB2l7/pqhUhqm7hLA== +"@webassemblyjs/helper-buffer@1.14.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.14.1.tgz#822a9bc603166531f7d5df84e67b5bf99b72b96b" + integrity sha512-jyH7wtcHiKssDtFPRB+iQdxlDf96m0E39yb0k5uJVhFGleZFoNw1c4aeIcVUPPbXUVJ94wwnMOAqUHyzoEPVMA== -"@webassemblyjs/helper-numbers@1.11.6": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.6.tgz#cbce5e7e0c1bd32cf4905ae444ef64cea919f1b5" - integrity sha512-vUIhZ8LZoIWHBohiEObxVm6hwP034jwmc9kuq5GdHZH0wiLVLIPcMCdpJzG4C11cHoQ25TFIQj9kaVADVX7N3g== +"@webassemblyjs/helper-numbers@1.13.2": + version "1.13.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.13.2.tgz#dbd932548e7119f4b8a7877fd5a8d20e63490b2d" + integrity sha512-FE8aCmS5Q6eQYcV3gI35O4J789wlQA+7JrqTTpJqn5emA4U2hvwJmvFRC0HODS+3Ye6WioDklgd6scJ3+PLnEA== dependencies: - "@webassemblyjs/floating-point-hex-parser" "1.11.6" - "@webassemblyjs/helper-api-error" "1.11.6" + "@webassemblyjs/floating-point-hex-parser" "1.13.2" + "@webassemblyjs/helper-api-error" "1.13.2" "@xtuc/long" "4.2.2" -"@webassemblyjs/helper-wasm-bytecode@1.11.6": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.6.tgz#bb2ebdb3b83aa26d9baad4c46d4315283acd51e9" - integrity sha512-sFFHKwcmBprO9e7Icf0+gddyWYDViL8bpPjJJl0WHxCdETktXdmtWLGVzoHbqUcY4Be1LkNfwTmXOJUFZYSJdA== +"@webassemblyjs/helper-wasm-bytecode@1.13.2": + version "1.13.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.13.2.tgz#e556108758f448aae84c850e593ce18a0eb31e0b" + integrity sha512-3QbLKy93F0EAIXLh0ogEVR6rOubA9AoZ+WRYhNbFyuB70j3dRdwH9g+qXhLAO0kiYGlg3TxDV+I4rQTr/YNXkA== -"@webassemblyjs/helper-wasm-section@1.11.6": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.6.tgz#ff97f3863c55ee7f580fd5c41a381e9def4aa577" - integrity sha512-LPpZbSOwTpEC2cgn4hTydySy1Ke+XEu+ETXuoyvuyezHO3Kjdu90KK95Sh9xTbmjrCsUwvWwCOQQNta37VrS9g== +"@webassemblyjs/helper-wasm-section@1.14.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.14.1.tgz#9629dda9c4430eab54b591053d6dc6f3ba050348" + integrity sha512-ds5mXEqTJ6oxRoqjhWDU83OgzAYjwsCV8Lo/N+oRsNDmx/ZDpqalmrtgOMkHwxsG0iI//3BwWAErYRHtgn0dZw== dependencies: - "@webassemblyjs/ast" "1.11.6" - "@webassemblyjs/helper-buffer" "1.11.6" - "@webassemblyjs/helper-wasm-bytecode" "1.11.6" - "@webassemblyjs/wasm-gen" "1.11.6" + "@webassemblyjs/ast" "1.14.1" + "@webassemblyjs/helper-buffer" "1.14.1" + "@webassemblyjs/helper-wasm-bytecode" "1.13.2" + "@webassemblyjs/wasm-gen" "1.14.1" -"@webassemblyjs/ieee754@1.11.6": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ieee754/-/ieee754-1.11.6.tgz#bb665c91d0b14fffceb0e38298c329af043c6e3a" - integrity sha512-LM4p2csPNvbij6U1f19v6WR56QZ8JcHg3QIJTlSwzFcmx6WSORicYj6I63f9yU1kEUtrpG+kjkiIAkevHpDXrg== +"@webassemblyjs/ieee754@1.13.2": + version "1.13.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ieee754/-/ieee754-1.13.2.tgz#1c5eaace1d606ada2c7fd7045ea9356c59ee0dba" + integrity sha512-4LtOzh58S/5lX4ITKxnAK2USuNEvpdVV9AlgGQb8rJDHaLeHciwG4zlGr0j/SNWlr7x3vO1lDEsuePvtcDNCkw== dependencies: "@xtuc/ieee754" "^1.2.0" -"@webassemblyjs/leb128@1.11.6": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.11.6.tgz#70e60e5e82f9ac81118bc25381a0b283893240d7" - integrity sha512-m7a0FhE67DQXgouf1tbN5XQcdWoNgaAuoULHIfGFIEVKA6tu/edls6XnIlkmS6FrXAquJRPni3ZZKjw6FSPjPQ== +"@webassemblyjs/leb128@1.13.2": + version "1.13.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.13.2.tgz#57c5c3deb0105d02ce25fa3fd74f4ebc9fd0bbb0" + integrity sha512-Lde1oNoIdzVzdkNEAWZ1dZ5orIbff80YPdHx20mrHwHrVNNTjNr8E3xz9BdpcGqRQbAEa+fkrCb+fRFTl/6sQw== dependencies: "@xtuc/long" "4.2.2" -"@webassemblyjs/utf8@1.11.6": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/utf8/-/utf8-1.11.6.tgz#90f8bc34c561595fe156603be7253cdbcd0fab5a" - integrity sha512-vtXf2wTQ3+up9Zsg8sa2yWiQpzSsMyXj0qViVP6xKGCUT8p8YJ6HqI7l5eCnWx1T/FYdsv07HQs2wTFbbof/RA== +"@webassemblyjs/utf8@1.13.2": + version "1.13.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/utf8/-/utf8-1.13.2.tgz#917a20e93f71ad5602966c2d685ae0c6c21f60f1" + integrity sha512-3NQWGjKTASY1xV5m7Hr0iPeXD9+RDobLll3T9d2AO+g3my8xy5peVyjSag4I50mR1bBSN/Ct12lo+R9tJk0NZQ== -"@webassemblyjs/wasm-edit@^1.11.5": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.6.tgz#c72fa8220524c9b416249f3d94c2958dfe70ceab" - integrity sha512-Ybn2I6fnfIGuCR+Faaz7YcvtBKxvoLV3Lebn1tM4o/IAJzmi9AWYIPWpyBfU8cC+JxAO57bk4+zdsTjJR+VTOw== +"@webassemblyjs/wasm-edit@^1.12.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.14.1.tgz#ac6689f502219b59198ddec42dcd496b1004d597" + integrity sha512-RNJUIQH/J8iA/1NzlE4N7KtyZNHi3w7at7hDjvRNm5rcUXa00z1vRz3glZoULfJ5mpvYhLybmVcwcjGrC1pRrQ== dependencies: - "@webassemblyjs/ast" "1.11.6" - "@webassemblyjs/helper-buffer" "1.11.6" - "@webassemblyjs/helper-wasm-bytecode" "1.11.6" - "@webassemblyjs/helper-wasm-section" "1.11.6" - "@webassemblyjs/wasm-gen" "1.11.6" - "@webassemblyjs/wasm-opt" "1.11.6" - "@webassemblyjs/wasm-parser" "1.11.6" - "@webassemblyjs/wast-printer" "1.11.6" + "@webassemblyjs/ast" "1.14.1" + "@webassemblyjs/helper-buffer" "1.14.1" + "@webassemblyjs/helper-wasm-bytecode" "1.13.2" + "@webassemblyjs/helper-wasm-section" "1.14.1" + "@webassemblyjs/wasm-gen" "1.14.1" + "@webassemblyjs/wasm-opt" "1.14.1" + "@webassemblyjs/wasm-parser" "1.14.1" + "@webassemblyjs/wast-printer" "1.14.1" -"@webassemblyjs/wasm-gen@1.11.6": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.6.tgz#fb5283e0e8b4551cc4e9c3c0d7184a65faf7c268" - integrity sha512-3XOqkZP/y6B4F0PBAXvI1/bky7GryoogUtfwExeP/v7Nzwo1QLcq5oQmpKlftZLbT+ERUOAZVQjuNVak6UXjPA== +"@webassemblyjs/wasm-gen@1.14.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.14.1.tgz#991e7f0c090cb0bb62bbac882076e3d219da9570" + integrity sha512-AmomSIjP8ZbfGQhumkNvgC33AY7qtMCXnN6bL2u2Js4gVCg8fp735aEiMSBbDR7UQIj90n4wKAFUSEd0QN2Ukg== dependencies: - "@webassemblyjs/ast" "1.11.6" - "@webassemblyjs/helper-wasm-bytecode" "1.11.6" - "@webassemblyjs/ieee754" "1.11.6" - "@webassemblyjs/leb128" "1.11.6" - "@webassemblyjs/utf8" "1.11.6" + "@webassemblyjs/ast" "1.14.1" + "@webassemblyjs/helper-wasm-bytecode" "1.13.2" + "@webassemblyjs/ieee754" "1.13.2" + "@webassemblyjs/leb128" "1.13.2" + "@webassemblyjs/utf8" "1.13.2" -"@webassemblyjs/wasm-opt@1.11.6": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.6.tgz#d9a22d651248422ca498b09aa3232a81041487c2" - integrity sha512-cOrKuLRE7PCe6AsOVl7WasYf3wbSo4CeOk6PkrjS7g57MFfVUF9u6ysQBBODX0LdgSvQqRiGz3CXvIDKcPNy4g== +"@webassemblyjs/wasm-opt@1.14.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.14.1.tgz#e6f71ed7ccae46781c206017d3c14c50efa8106b" + integrity sha512-PTcKLUNvBqnY2U6E5bdOQcSM+oVP/PmrDY9NzowJjislEjwP/C4an2303MCVS2Mg9d3AJpIGdUFIQQWbPds0Sw== dependencies: - "@webassemblyjs/ast" "1.11.6" - "@webassemblyjs/helper-buffer" "1.11.6" - "@webassemblyjs/wasm-gen" "1.11.6" - "@webassemblyjs/wasm-parser" "1.11.6" + "@webassemblyjs/ast" "1.14.1" + "@webassemblyjs/helper-buffer" "1.14.1" + "@webassemblyjs/wasm-gen" "1.14.1" + "@webassemblyjs/wasm-parser" "1.14.1" -"@webassemblyjs/wasm-parser@1.11.6", "@webassemblyjs/wasm-parser@^1.11.5": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.6.tgz#bb85378c527df824004812bbdb784eea539174a1" - integrity sha512-6ZwPeGzMJM3Dqp3hCsLgESxBGtT/OeCvCZ4TA1JUPYgmhAx38tTPR9JaKy0S5H3evQpO/h2uWs2j6Yc/fjkpTQ== +"@webassemblyjs/wasm-parser@1.14.1", "@webassemblyjs/wasm-parser@^1.12.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.14.1.tgz#b3e13f1893605ca78b52c68e54cf6a865f90b9fb" + integrity sha512-JLBl+KZ0R5qB7mCnud/yyX08jWFw5MsoalJ1pQ4EdFlgj9VdXKGuENGsiCIjegI1W7p91rUlcB/LB5yRJKNTcQ== dependencies: - "@webassemblyjs/ast" "1.11.6" - "@webassemblyjs/helper-api-error" "1.11.6" - "@webassemblyjs/helper-wasm-bytecode" "1.11.6" - "@webassemblyjs/ieee754" "1.11.6" - "@webassemblyjs/leb128" "1.11.6" - "@webassemblyjs/utf8" "1.11.6" + "@webassemblyjs/ast" "1.14.1" + "@webassemblyjs/helper-api-error" "1.13.2" + "@webassemblyjs/helper-wasm-bytecode" "1.13.2" + "@webassemblyjs/ieee754" "1.13.2" + "@webassemblyjs/leb128" "1.13.2" + "@webassemblyjs/utf8" "1.13.2" -"@webassemblyjs/wast-printer@1.11.6": - version "1.11.6" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.11.6.tgz#a7bf8dd7e362aeb1668ff43f35cb849f188eff20" - integrity sha512-JM7AhRcE+yW2GWYaKeHL5vt4xqee5N2WcezptmgyhNS+ScggqcT1OtXykhAb13Sn5Yas0j2uv9tHgrjwvzAP4A== +"@webassemblyjs/wast-printer@1.14.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.14.1.tgz#3bb3e9638a8ae5fdaf9610e7a06b4d9f9aa6fe07" + integrity sha512-kPSSXE6De1XOR820C90RIo2ogvZG+c3KiHzqUoO/F34Y2shGzesfqv7o57xrxovZJH/MetF5UjroJ/R/3isoiw== dependencies: - "@webassemblyjs/ast" "1.11.6" + "@webassemblyjs/ast" "1.14.1" "@xtuc/long" "4.2.2" -"@webpack-cli/configtest@^2.1.0": +"@webpack-cli/configtest@^2.1.1": version "2.1.1" resolved "https://registry.yarnpkg.com/@webpack-cli/configtest/-/configtest-2.1.1.tgz#3b2f852e91dac6e3b85fb2a314fb8bef46d94646" integrity sha512-wy0mglZpDSiSS0XHrVR+BAdId2+yxPSoJW8fsna3ZpYSlufjvxnP4YbKTCBZnNIcGN4r6ZPXV55X4mYExOfLmw== -"@webpack-cli/info@^2.0.1": +"@webpack-cli/info@^2.0.2": version "2.0.2" resolved "https://registry.yarnpkg.com/@webpack-cli/info/-/info-2.0.2.tgz#cc3fbf22efeb88ff62310cf885c5b09f44ae0fdd" integrity sha512-zLHQdI/Qs1UyT5UBdWNqsARasIA+AaF8t+4u2aS2nEpBQh2mWIVb8qAklq0eUENnC5mOItrIB4LiS9xMtph18A== -"@webpack-cli/serve@^2.0.3": +"@webpack-cli/serve@^2.0.5": version "2.0.5" resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-2.0.5.tgz#325db42395cd49fe6c14057f9a900e427df8810e" integrity sha512-lqaoKnRYBdo1UgDX8uF24AfGMifWK19TxPmM5FHc2vAGxrJ/qtyUyFBWoY1tISZdelsQ5fBcOusifo5o5wSJxQ== @@ -374,11 +387,6 @@ resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d" integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ== -abab@^2.0.6: - version "2.0.6" - resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.6.tgz#41b80f2c871d19686216b82309231cfd3cb3d291" - integrity sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA== - accepts@~1.3.4, accepts@~1.3.5: version "1.3.7" resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd" @@ -395,10 +403,10 @@ accepts@~1.3.8: mime-types "~2.1.34" negotiator "0.6.3" -acorn-import-assertions@^1.7.6: - version "1.9.0" - resolved "https://registry.yarnpkg.com/acorn-import-assertions/-/acorn-import-assertions-1.9.0.tgz#507276249d684797c84e0734ef84860334cfb1ac" - integrity sha512-cmMwop9x+8KFhxvKrKfPYmN6/pKTYYHBqLa0DfvVZcKMJWNyWLnaqND7dx/qn66R7ewM1UX5XMaDVP5wlVTaVA== +acorn-import-attributes@^1.9.5: + version "1.9.5" + resolved "https://registry.yarnpkg.com/acorn-import-attributes/-/acorn-import-attributes-1.9.5.tgz#7eb1557b1ba05ef18b5ed0ec67591bfab04688ef" + integrity sha512-n02Vykv5uA3eHGM/Z2dQrcD56kL8TyDb2p1+0P83PClMnC/nc+anbQRhIOWnSq4Ke/KvDPrY3C9hDtC/A3eHnQ== acorn@^8.7.1, acorn@^8.8.2: version "8.10.0" @@ -444,10 +452,10 @@ ajv@^8.0.0, ajv@^8.9.0: require-from-string "^2.0.2" uri-js "^4.2.2" -ansi-colors@4.1.1: - version "4.1.1" - resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" - integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== +ansi-colors@^4.1.3: + version "4.1.3" + resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.3.tgz#37611340eb2243e70cc604cad35d63270d48781b" + integrity sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw== ansi-html-community@^0.0.8: version "0.0.8" @@ -575,20 +583,20 @@ braces@^3.0.2, braces@~3.0.2: dependencies: fill-range "^7.0.1" -browser-stdout@1.3.1: +browser-stdout@^1.3.1: version "1.3.1" resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60" integrity sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw== -browserslist@^4.14.5: - version "4.21.10" - resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.21.10.tgz#dbbac576628c13d3b2231332cb2ec5a46e015bb0" - integrity sha512-bipEBdZfVH5/pwrvqc+Ub0kUPVfGUhlKxbvfD+z1BDnPEO/X98ruXGA1WP5ASpAFKan7Qr6j736IacbZQuAlKQ== +browserslist@^4.21.10: + version "4.24.3" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.24.3.tgz#5fc2725ca8fb3c1432e13dac278c7cc103e026d2" + integrity sha512-1CPmv8iobE2fyRMV97dAcMVegvvWKxmq94hkLiAkUGwKVTyDLw33K+ZxiFrREKmmps4rIw6grcCFCnTMSZ/YiA== dependencies: - caniuse-lite "^1.0.30001517" - electron-to-chromium "^1.4.477" - node-releases "^2.0.13" - update-browserslist-db "^1.0.11" + caniuse-lite "^1.0.30001688" + electron-to-chromium "^1.5.73" + node-releases "^2.0.19" + update-browserslist-db "^1.1.1" buffer-from@^1.0.0: version "1.1.2" @@ -623,10 +631,10 @@ camelcase@^6.0.0: resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.2.0.tgz#924af881c9d525ac9d87f40d964e5cea982a1809" integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg== -caniuse-lite@^1.0.30001517: - version "1.0.30001521" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001521.tgz#e9930cf499f7c1e80334b6c1fbca52e00d889e56" - integrity sha512-fnx1grfpEOvDGH+V17eccmNjucGUnCbP6KL+l5KqBIerp26WK/+RQ7CIDE37KGJjaPyqWXXlFUyKiWmvdNNKmQ== +caniuse-lite@^1.0.30001688: + version "1.0.30001690" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001690.tgz#f2d15e3aaf8e18f76b2b8c1481abde063b8104c8" + integrity sha512-5ExiE3qQN6oF8Clf8ifIDcMRCRE/dMGcETG/XGMD8/XiXm6HXQgQTh1yZYLXXpSOsEUlJm1Xr7kGULZTuGtP/w== chalk@^4.1.0: version "4.1.2" @@ -636,10 +644,10 @@ chalk@^4.1.0: ansi-styles "^4.1.0" supports-color "^7.1.0" -chokidar@3.5.3, chokidar@^3.5.3: - version "3.5.3" - resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" - integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== +chokidar@^3.5.1: + version "3.5.2" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.2.tgz#dba3976fcadb016f66fd365021d91600d01c1e75" + integrity sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ== dependencies: anymatch "~3.1.2" braces "~3.0.2" @@ -651,10 +659,10 @@ chokidar@3.5.3, chokidar@^3.5.3: optionalDependencies: fsevents "~2.3.2" -chokidar@^3.5.1: - version "3.5.2" - resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.2.tgz#dba3976fcadb016f66fd365021d91600d01c1e75" - integrity sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ== +chokidar@^3.5.3: + version "3.5.3" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" + integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== dependencies: anymatch "~3.1.2" braces "~3.0.2" @@ -716,11 +724,6 @@ commander@^2.20.0: resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== -component-emitter@~1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0" - integrity sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg== - compressible@~2.0.16: version "2.0.18" resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.18.tgz#af53cca6b070d4c3c0750fbd77286a6d7cc46fba" @@ -783,10 +786,10 @@ cookie@0.5.0: resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b" integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw== -cookie@~0.4.1: - version "0.4.1" - resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.1.tgz#afd713fe26ebd21ba95ceb61f9a8116e50a537d1" - integrity sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA== +cookie@~0.7.2: + version "0.7.2" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.7.2.tgz#556369c472a2ba910f2979891b526b3436237ed7" + integrity sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w== core-util-is@~1.0.0: version "1.0.3" @@ -827,13 +830,6 @@ debug@2.6.9: dependencies: ms "2.0.0" -debug@4.3.4, debug@^4.3.4, debug@~4.3.2: - version "4.3.4" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" - integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== - dependencies: - ms "2.1.2" - debug@^4.1.0, debug@~4.3.1: version "4.3.3" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664" @@ -841,6 +837,27 @@ debug@^4.1.0, debug@~4.3.1: dependencies: ms "2.1.2" +debug@^4.3.4, debug@~4.3.2: + version "4.3.4" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" + integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== + dependencies: + ms "2.1.2" + +debug@^4.3.5: + version "4.4.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.4.0.tgz#2b3f2aea2ffeb776477460267377dc8710faba8a" + integrity sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA== + dependencies: + ms "^2.1.3" + +debug@~4.3.4: + version "4.3.7" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.7.tgz#87945b4151a011d76d95a198d7111c865c360a52" + integrity sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ== + dependencies: + ms "^2.1.3" + decamelize@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-4.0.0.tgz#aa472d7bf660eb15f3494efd531cab7f2a709837" @@ -883,10 +900,10 @@ di@^0.0.1: resolved "https://registry.yarnpkg.com/di/-/di-0.0.1.tgz#806649326ceaa7caa3306d75d985ea2748ba913c" integrity sha1-gGZJMmzqp8qjMG112YXqJ0i6kTw= -diff@5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b" - integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w== +diff@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-5.2.0.tgz#26ded047cd1179b78b9537d5ef725503ce1ae531" + integrity sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A== dns-equal@^1.0.0: version "1.0.0" @@ -915,10 +932,10 @@ ee-first@1.1.1: resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= -electron-to-chromium@^1.4.477: - version "1.4.494" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.494.tgz#588f7a3d19d32a31f3a7e05d81b61d95d25b1555" - integrity sha512-KF7wtsFFDu4ws1ZsSOt4pdmO1yWVNWCFtijVYZPUeW4SV7/hy/AESjLn/+qIWgq7mHscNOKAwN5AIM1+YAy+Ww== +electron-to-chromium@^1.5.73: + version "1.5.76" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.76.tgz#db20295c5061b68f07c8ea4dfcbd701485d94a3d" + integrity sha512-CjVQyG7n7Sr+eBXE86HIulnL5N8xZY1sgmOPGuq/F0Rr0FJq63lg0kEtOIDfZBk44FnDLf6FUJ+dsJcuiUDdDQ== emoji-regex@^8.0.0: version "8.0.0" @@ -930,31 +947,31 @@ encodeurl@~1.0.2: resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" integrity sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k= -engine.io-parser@~5.0.3: - version "5.0.4" - resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-5.0.4.tgz#0b13f704fa9271b3ec4f33112410d8f3f41d0fc0" - integrity sha512-+nVFp+5z1E3HcToEnO7ZIj3g+3k9389DvWtvJZz0T6/eOCPIyyxehFcedoYrZQrp0LgQbD9pPXhpMBKMd5QURg== +engine.io-parser@~5.2.1: + version "5.2.3" + resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-5.2.3.tgz#00dc5b97b1f233a23c9398d0209504cf5f94d92f" + integrity sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q== -engine.io@~6.2.0: - version "6.2.0" - resolved "https://registry.yarnpkg.com/engine.io/-/engine.io-6.2.0.tgz#003bec48f6815926f2b1b17873e576acd54f41d0" - integrity sha512-4KzwW3F3bk+KlzSOY57fj/Jx6LyRQ1nbcyIadehl+AnXjKT7gDO0ORdRi/84ixvMKTym6ZKuxvbzN62HDDU1Lg== +engine.io@~6.6.0: + version "6.6.2" + resolved "https://registry.yarnpkg.com/engine.io/-/engine.io-6.6.2.tgz#32bd845b4db708f8c774a4edef4e5c8a98b3da72" + integrity sha512-gmNvsYi9C8iErnZdVcJnvCpSKbWTt1E8+JZo8b+daLninywUWi5NQ5STSHZ9rFjFO7imNcvb8Pc5pe/wMR5xEw== dependencies: "@types/cookie" "^0.4.1" "@types/cors" "^2.8.12" "@types/node" ">=10.0.0" accepts "~1.3.4" base64id "2.0.0" - cookie "~0.4.1" + cookie "~0.7.2" cors "~2.8.5" debug "~4.3.1" - engine.io-parser "~5.0.3" - ws "~8.2.3" + engine.io-parser "~5.2.1" + ws "~8.17.1" -enhanced-resolve@^5.13.0: - version "5.15.0" - resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz#1af946c7d93603eb88e9896cee4904dc012e9c35" - integrity sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg== +enhanced-resolve@^5.17.0: + version "5.18.0" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.18.0.tgz#91eb1db193896b9801251eeff1c6980278b1e404" + integrity sha512-0/r0MySGYG8YqlayBZ6MuCfECmHFdJ5qyPh8s8wa5Hnm6SaFLSK1VYCbj+NKp090Nm1caZhD+QTnmxO7esYGyQ== dependencies: graceful-fs "^4.2.4" tapable "^2.2.0" @@ -979,12 +996,17 @@ escalade@^3.1.1: resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" integrity sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw== +escalade@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.2.0.tgz#011a3f69856ba189dffa7dc8fcce99d2a87903e5" + integrity sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA== + escape-html@~1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" integrity sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg= -escape-string-regexp@4.0.0: +escape-string-regexp@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== @@ -1141,14 +1163,6 @@ finalhandler@1.2.0: statuses "2.0.1" unpipe "~1.0.0" -find-up@5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc" - integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng== - dependencies: - locate-path "^6.0.0" - path-exists "^4.0.0" - find-up@^4.0.0: version "4.1.0" resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19" @@ -1157,6 +1171,14 @@ find-up@^4.0.0: locate-path "^5.0.0" path-exists "^4.0.0" +find-up@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc" + integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng== + dependencies: + locate-path "^6.0.0" + path-exists "^4.0.0" + flat@^5.0.2: version "5.0.2" resolved "https://registry.yarnpkg.com/flat/-/flat-5.0.2.tgz#8ca6fe332069ffa9d324c327198c598259ceb241" @@ -1247,18 +1269,6 @@ glob-to-regexp@^0.4.1: resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz#c75297087c851b9a578bd217dd59a92f59fe546e" integrity sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw== -glob@7.2.0, glob@^7.1.7: - version "7.2.0" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023" - integrity sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q== - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^3.0.4" - once "^1.3.0" - path-is-absolute "^1.0.0" - glob@^7.1.3: version "7.1.7" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90" @@ -1271,6 +1281,29 @@ glob@^7.1.3: once "^1.3.0" path-is-absolute "^1.0.0" +glob@^7.1.7: + version "7.2.0" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023" + integrity sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + +glob@^8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e" + integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^5.0.1" + once "^1.3.0" + graceful-fs@^4.1.2: version "4.2.8" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a" @@ -1281,7 +1314,7 @@ graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.6: resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz#041b05df45755e587a24942279b9d113146e1c96" integrity sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ== -graceful-fs@^4.2.10, graceful-fs@^4.2.4, graceful-fs@^4.2.9: +graceful-fs@^4.2.10, graceful-fs@^4.2.11, graceful-fs@^4.2.4: version "4.2.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== @@ -1308,7 +1341,7 @@ has@^1.0.3: dependencies: function-bind "^1.1.1" -he@1.2.0: +he@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== @@ -1554,7 +1587,7 @@ jest-worker@^27.4.5: merge-stream "^2.0.0" supports-color "^8.0.0" -js-yaml@4.1.0: +js-yaml@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA== @@ -1604,19 +1637,19 @@ karma-sourcemap-loader@0.4.0: dependencies: graceful-fs "^4.2.10" -karma-webpack@5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/karma-webpack/-/karma-webpack-5.0.0.tgz#2a2c7b80163fe7ffd1010f83f5507f95ef39f840" - integrity sha512-+54i/cd3/piZuP3dr54+NcFeKOPnys5QeM1IY+0SPASwrtHsliXUiCL50iW+K9WWA7RvamC4macvvQ86l3KtaA== +karma-webpack@5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/karma-webpack/-/karma-webpack-5.0.1.tgz#4eafd31bbe684a747a6e8f3e4ad373e53979ced4" + integrity sha512-oo38O+P3W2mSPCSUrQdySSPv1LvPpXP+f+bBimNomS5sW+1V4SuhCuW8TfJzV+rDv921w2fDSDw0xJbPe6U+kQ== dependencies: glob "^7.1.3" - minimatch "^3.0.4" + minimatch "^9.0.3" webpack-merge "^4.1.5" -karma@6.4.2: - version "6.4.2" - resolved "https://registry.yarnpkg.com/karma/-/karma-6.4.2.tgz#a983f874cee6f35990c4b2dcc3d274653714de8e" - integrity sha512-C6SU/53LB31BEgRg+omznBEMY4SjHU3ricV6zBcAe1EeILKkeScr+fZXtaI5WyDbkVowJxxAI6h73NcFPmXolQ== +karma@6.4.3: + version "6.4.3" + resolved "https://registry.yarnpkg.com/karma/-/karma-6.4.3.tgz#763e500f99597218bbb536de1a14acc4ceea7ce8" + integrity sha512-LuucC/RE92tJ8mlCwqEoRWXP38UMAqpnq98vktmS9SznSoUPPUJQbc91dHcxcunROvfQjdORVA/YFviH+Xci9Q== dependencies: "@colors/colors" "1.5.0" body-parser "^1.19.0" @@ -1637,7 +1670,7 @@ karma@6.4.2: qjobs "^1.2.0" range-parser "^1.2.1" rimraf "^3.0.2" - socket.io "^4.4.1" + socket.io "^4.7.2" source-map "^0.6.1" tmp "^0.2.1" ua-parser-js "^0.7.30" @@ -1692,7 +1725,7 @@ lodash@^4.17.15, lodash@^4.17.21: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== -log-symbols@4.1.0: +log-symbols@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-4.1.0.tgz#3fbdbb95b4683ac9fc785111e792e558d4abd503" integrity sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg== @@ -1790,13 +1823,6 @@ minimalistic-assert@^1.0.0: resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7" integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A== -minimatch@5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.0.1.tgz#fb9022f7528125187c92bd9e9b6366be1cf3415b" - integrity sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g== - dependencies: - brace-expansion "^2.0.1" - minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" @@ -1804,6 +1830,20 @@ minimatch@^3.0.4: dependencies: brace-expansion "^1.1.7" +minimatch@^5.0.1, minimatch@^5.1.6: + version "5.1.6" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96" + integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g== + dependencies: + brace-expansion "^2.0.1" + +minimatch@^9.0.3: + version "9.0.5" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.5.tgz#d74f9dd6b57d83d8e98cfb82133b03978bc929e5" + integrity sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow== + dependencies: + brace-expansion "^2.0.1" + minimist@^1.2.3, minimist@^1.2.5: version "1.2.5" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" @@ -1816,32 +1856,31 @@ mkdirp@^0.5.5: dependencies: minimist "^1.2.5" -mocha@10.2.0: - version "10.2.0" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.2.0.tgz#1fd4a7c32ba5ac372e03a17eef435bd00e5c68b8" - integrity sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg== +mocha@10.7.0: + version "10.7.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.7.0.tgz#9e5cbed8fa9b37537a25bd1f7fb4f6fc45458b9a" + integrity sha512-v8/rBWr2VO5YkspYINnvu81inSz2y3ODJrhO175/Exzor1RcEZZkizgE2A+w/CAXXoESS8Kys5E62dOHGHzULA== dependencies: - ansi-colors "4.1.1" - browser-stdout "1.3.1" - chokidar "3.5.3" - debug "4.3.4" - diff "5.0.0" - escape-string-regexp "4.0.0" - find-up "5.0.0" - glob "7.2.0" - he "1.2.0" - js-yaml "4.1.0" - log-symbols "4.1.0" - minimatch "5.0.1" - ms "2.1.3" - nanoid "3.3.3" - serialize-javascript "6.0.0" - strip-json-comments "3.1.1" - supports-color "8.1.1" - workerpool "6.2.1" - yargs "16.2.0" - yargs-parser "20.2.4" - yargs-unparser "2.0.0" + ansi-colors "^4.1.3" + browser-stdout "^1.3.1" + chokidar "^3.5.3" + debug "^4.3.5" + diff "^5.2.0" + escape-string-regexp "^4.0.0" + find-up "^5.0.0" + glob "^8.1.0" + he "^1.2.0" + js-yaml "^4.1.0" + log-symbols "^4.1.0" + minimatch "^5.1.6" + ms "^2.1.3" + serialize-javascript "^6.0.2" + strip-json-comments "^3.1.1" + supports-color "^8.1.1" + workerpool "^6.5.1" + yargs "^16.2.0" + yargs-parser "^20.2.9" + yargs-unparser "^2.0.0" ms@2.0.0: version "2.0.0" @@ -1853,7 +1892,7 @@ ms@2.1.2: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== -ms@2.1.3: +ms@2.1.3, ms@^2.1.3: version "2.1.3" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== @@ -1866,11 +1905,6 @@ multicast-dns@^7.2.5: dns-packet "^5.2.2" thunky "^1.0.2" -nanoid@3.3.3: - version "3.3.3" - resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.3.tgz#fd8e8b7aa761fe807dba2d1b98fb7241bb724a25" - integrity sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w== - negotiator@0.6.2: version "0.6.2" resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb" @@ -1891,10 +1925,10 @@ node-forge@^1: resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.1.tgz#be8da2af243b2417d5f646a770663a92b7e9ded3" integrity sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA== -node-releases@^2.0.13: - version "2.0.13" - resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.13.tgz#d5ed1627c23e3461e819b02e57b75e4899b1c81d" - integrity sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ== +node-releases@^2.0.19: + version "2.0.19" + resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.19.tgz#9e445a52950951ec4d177d843af370b411caf314" + integrity sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw== normalize-path@^3.0.0, normalize-path@~3.0.0: version "3.0.0" @@ -2041,6 +2075,11 @@ picocolors@^1.0.0: resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ== +picocolors@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.1.tgz#3d321af3eab939b083c8f929a1d12cda81c26b6b" + integrity sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA== + picomatch@^2.0.4, picomatch@^2.2.1: version "2.3.0" resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.0.tgz#f1f061de8f6a4bf022892e2d128234fb98302972" @@ -2229,7 +2268,7 @@ safe-buffer@5.2.1, safe-buffer@>=5.1.0, safe-buffer@^5.1.0, safe-buffer@~5.2.0: resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== -schema-utils@^3.1.1, schema-utils@^3.1.2: +schema-utils@^3.2.0: version "3.3.0" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.3.0.tgz#f50a88877c3c01652a15b622ae9e9795df7a60fe" integrity sha512-pN/yOAvcC+5rQ5nERGuwrjLlYvLTbCibnZ1I7B1LaiAz9BRBlE9GMgE/eqV30P7aJQUf7Ddimy/RsbYO/GrVGg== @@ -2248,6 +2287,16 @@ schema-utils@^4.0.0: ajv-formats "^2.1.1" ajv-keywords "^5.1.0" +schema-utils@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-4.3.0.tgz#3b669f04f71ff2dfb5aba7ce2d5a9d79b35622c0" + integrity sha512-Gf9qqc58SpCA/xdziiHz35F4GNIWYWZrEshUc/G/r5BnLph6xpKuLeoJoQuj5WfBIx/eQLf+hmVPYHaxJu7V2g== + dependencies: + "@types/json-schema" "^7.0.9" + ajv "^8.9.0" + ajv-formats "^2.1.1" + ajv-keywords "^5.1.0" + select-hose@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca" @@ -2279,17 +2328,10 @@ send@0.18.0: range-parser "~1.2.1" statuses "2.0.1" -serialize-javascript@6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz#efae5d88f45d7924141da8b5c3a7a7e663fefeb8" - integrity sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag== - dependencies: - randombytes "^2.1.0" - -serialize-javascript@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.1.tgz#b206efb27c3da0b0ab6b52f48d170b7996458e5c" - integrity sha512-owoXEFjWRllis8/M1Q+Cw5k8ZH40e3zhp/ovX+Xr/vi1qj6QesbyXXViFbpNvWvPNAD62SutwEXavefrLJWj7w== +serialize-javascript@^6.0.2: + version "6.0.2" + resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.2.tgz#defa1e055c83bf6d59ea805d8da862254eb6a6c2" + integrity sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g== dependencies: randombytes "^2.1.0" @@ -2364,31 +2406,34 @@ signal-exit@^3.0.3: resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== -socket.io-adapter@~2.4.0: - version "2.4.0" - resolved "https://registry.yarnpkg.com/socket.io-adapter/-/socket.io-adapter-2.4.0.tgz#b50a4a9ecdd00c34d4c8c808224daa1a786152a6" - integrity sha512-W4N+o69rkMEGVuk2D/cvca3uYsvGlMwsySWV447y99gUPghxq42BxqLNMndb+a1mm/5/7NeXVQS7RLa2XyXvYg== - -socket.io-parser@~4.0.4: - version "4.0.5" - resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-4.0.5.tgz#cb404382c32324cc962f27f3a44058cf6e0552df" - integrity sha512-sNjbT9dX63nqUFIOv95tTVm6elyIU4RvB1m8dOeZt+IgWwcWklFDOdmGcfo3zSiRsnR/3pJkjY5lfoGqEe4Eig== +socket.io-adapter@~2.5.2: + version "2.5.5" + resolved "https://registry.yarnpkg.com/socket.io-adapter/-/socket.io-adapter-2.5.5.tgz#c7a1f9c703d7756844751b6ff9abfc1780664082" + integrity sha512-eLDQas5dzPgOWCk9GuuJC2lBqItuhKI4uxGgo9aIV7MYbk2h9Q6uULEh8WBzThoI7l+qU9Ast9fVUmkqPP9wYg== dependencies: - "@types/component-emitter" "^1.2.10" - component-emitter "~1.3.0" + debug "~4.3.4" + ws "~8.17.1" + +socket.io-parser@~4.2.4: + version "4.2.4" + resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-4.2.4.tgz#c806966cf7270601e47469ddeec30fbdfda44c83" + integrity sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew== + dependencies: + "@socket.io/component-emitter" "~3.1.0" debug "~4.3.1" -socket.io@^4.4.1: - version "4.5.1" - resolved "https://registry.yarnpkg.com/socket.io/-/socket.io-4.5.1.tgz#aa7e73f8a6ce20ee3c54b2446d321bbb6b1a9029" - integrity sha512-0y9pnIso5a9i+lJmsCdtmTTgJFFSvNQKDnPQRz28mGNnxbmqYg2QPtJTLFxhymFZhAIn50eHAKzJeiNaKr+yUQ== +socket.io@^4.7.2: + version "4.8.1" + resolved "https://registry.yarnpkg.com/socket.io/-/socket.io-4.8.1.tgz#fa0eaff965cc97fdf4245e8d4794618459f7558a" + integrity sha512-oZ7iUCxph8WYRHHcjBEc9unw3adt5CmSNlppj/5Q4k2RIrhl8Z5yY2Xr4j9zj0+wzVZ0bxmYoGSzKJnRl6A4yg== dependencies: accepts "~1.3.4" base64id "~2.0.0" + cors "~2.8.5" debug "~4.3.2" - engine.io "~6.2.0" - socket.io-adapter "~2.4.0" - socket.io-parser "~4.0.4" + engine.io "~6.6.0" + socket.io-adapter "~2.5.2" + socket.io-parser "~4.2.4" sockjs@^0.3.24: version "0.3.24" @@ -2404,12 +2449,11 @@ source-map-js@^1.0.2: resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c" integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw== -source-map-loader@4.0.1: - version "4.0.1" - resolved "https://registry.yarnpkg.com/source-map-loader/-/source-map-loader-4.0.1.tgz#72f00d05f5d1f90f80974eda781cbd7107c125f2" - integrity sha512-oqXpzDIByKONVY8g1NUPOTQhe0UTU5bWUl32GSkqK2LjJj0HmwTMVKxcUip0RgAYhY1mqgOxjbQM48a0mmeNfA== +source-map-loader@5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/source-map-loader/-/source-map-loader-5.0.0.tgz#f593a916e1cc54471cfc8851b905c8a845fc7e38" + integrity sha512-k2Dur7CbSLcAH73sBcIkV5xjPV4SzqO1NJ7+XaQl8if3VODDUj3FNchNGpqgJSKbvUfJuhVdv8K2Eu8/TNl2eA== dependencies: - abab "^2.0.6" iconv-lite "^0.6.3" source-map-js "^1.0.2" @@ -2503,18 +2547,11 @@ strip-final-newline@^2.0.0: resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad" integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA== -strip-json-comments@3.1.1: +strip-json-comments@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== -supports-color@8.1.1, supports-color@^8.0.0: - version "8.1.1" - resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c" - integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q== - dependencies: - has-flag "^4.0.0" - supports-color@^7.1.0: version "7.2.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" @@ -2522,6 +2559,13 @@ supports-color@^7.1.0: dependencies: has-flag "^4.0.0" +supports-color@^8.0.0, supports-color@^8.1.1: + version "8.1.1" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c" + integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q== + dependencies: + has-flag "^4.0.0" + supports-preserve-symlinks-flag@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09" @@ -2532,21 +2576,21 @@ tapable@^2.1.1, tapable@^2.2.0: resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0" integrity sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ== -terser-webpack-plugin@^5.3.7: - version "5.3.9" - resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.9.tgz#832536999c51b46d468067f9e37662a3b96adfe1" - integrity sha512-ZuXsqE07EcggTWQjXUj+Aot/OMcD0bMKGgF63f7UxYcu5/AJF53aIpK1YoP5xR9l6s/Hy2b+t1AM0bLNPRuhwA== +terser-webpack-plugin@^5.3.10: + version "5.3.11" + resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.11.tgz#93c21f44ca86634257cac176f884f942b7ba3832" + integrity sha512-RVCsMfuD0+cTt3EwX8hSl2Ks56EbFHWmhluwcqoPKtBnfjiT6olaq7PRIRfhyU8nnC2MrnDrBLfrD/RGE+cVXQ== dependencies: - "@jridgewell/trace-mapping" "^0.3.17" + "@jridgewell/trace-mapping" "^0.3.25" jest-worker "^27.4.5" - schema-utils "^3.1.1" - serialize-javascript "^6.0.1" - terser "^5.16.8" + schema-utils "^4.3.0" + serialize-javascript "^6.0.2" + terser "^5.31.1" -terser@^5.16.8: - version "5.19.2" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.19.2.tgz#bdb8017a9a4a8de4663a7983f45c506534f9234e" - integrity sha512-qC5+dmecKJA4cpYxRa5aVkKehYsQKc+AHeKl0Oe62aYjBL8ZA33tTljktDHJSaxxMnbI5ZYw+o/S2DxxLu8OfA== +terser@^5.31.1: + version "5.37.0" + resolved "https://registry.yarnpkg.com/terser/-/terser-5.37.0.tgz#38aa66d1cfc43d0638fab54e43ff8a4f72a21ba3" + integrity sha512-B8wRRkmre4ERucLM/uXx4MOV5cbnOlVAqUst+1+iLKPI0dOgFO28f84ptoQt9HEI537PMzfYa/d+GEPKTRXmYA== dependencies: "@jridgewell/source-map" "^0.3.3" acorn "^8.8.2" @@ -2585,10 +2629,10 @@ type-is@~1.6.18: media-typer "0.3.0" mime-types "~2.1.24" -typescript@5.0.4: - version "5.0.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b" - integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw== +typescript@5.5.4: + version "5.5.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba" + integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q== ua-parser-js@^0.7.30: version "0.7.31" @@ -2605,13 +2649,13 @@ unpipe@1.0.0, unpipe@~1.0.0: resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" integrity sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw= -update-browserslist-db@^1.0.11: - version "1.0.11" - resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.11.tgz#9a2a641ad2907ae7b3616506f4b977851db5b940" - integrity sha512-dCwEFf0/oT85M1fHBg4F0jtLwJrutGoHSQXCh7u4o2t1drG+c0a9Flnqww6XUKSfQMPpJBRjU8d4RXB09qtvaA== +update-browserslist-db@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz#80846fba1d79e82547fb661f8d141e0945755fe5" + integrity sha512-R8UzCaa9Az+38REPiJ1tXlImTJXlVfgHZsglwBD/k6nj76ctsH1E3q4doGrukiLQd3sGQYu56r5+lo5r94l29A== dependencies: - escalade "^3.1.1" - picocolors "^1.0.0" + escalade "^3.2.0" + picocolors "^1.1.0" uri-js@^4.2.2: version "4.4.1" @@ -2645,10 +2689,10 @@ void-elements@^2.0.0: resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec" integrity sha1-wGavtYK7HLQSjWDqkjkulNXp2+w= -watchpack@^2.4.0: - version "2.4.0" - resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.4.0.tgz#fa33032374962c78113f93c7f2fb4c54c9862a5d" - integrity sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg== +watchpack@^2.4.1: + version "2.4.2" + resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.4.2.tgz#2feeaed67412e7c33184e5a79ca738fbd38564da" + integrity sha512-TnbFSbcOCcDgjZ4piURLCbJ3nJhznVh9kw6F6iokjiFPl8ONxe9A6nMDVXDiNbrSfLILs6vB07F7wLBrwPYzJw== dependencies: glob-to-regexp "^0.4.1" graceful-fs "^4.1.2" @@ -2660,15 +2704,15 @@ wbuf@^1.1.0, wbuf@^1.7.3: dependencies: minimalistic-assert "^1.0.0" -webpack-cli@5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-5.1.0.tgz#abc4b1f44b50250f2632d8b8b536cfe2f6257891" - integrity sha512-a7KRJnCxejFoDpYTOwzm5o21ZXMaNqtRlvS183XzGDUPRdVEzJNImcQokqYZ8BNTnk9DkKiuWxw75+DCCoZ26w== +webpack-cli@5.1.4: + version "5.1.4" + resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-5.1.4.tgz#c8e046ba7eaae4911d7e71e2b25b776fcc35759b" + integrity sha512-pIDJHIEI9LR0yxHXQ+Qh95k2EvXpWzZ5l+d+jIo+RdSm9MiHfzazIxwwni/p7+x4eJZuvG1AJwgC4TNQ7NRgsg== dependencies: "@discoveryjs/json-ext" "^0.5.0" - "@webpack-cli/configtest" "^2.1.0" - "@webpack-cli/info" "^2.0.1" - "@webpack-cli/serve" "^2.0.3" + "@webpack-cli/configtest" "^2.1.1" + "@webpack-cli/info" "^2.0.2" + "@webpack-cli/serve" "^2.0.5" colorette "^2.0.14" commander "^10.0.1" cross-spawn "^7.0.3" @@ -2679,10 +2723,10 @@ webpack-cli@5.1.0: rechoir "^0.8.0" webpack-merge "^5.7.3" -webpack-dev-middleware@^5.3.1: - version "5.3.3" - resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-5.3.3.tgz#efae67c2793908e7311f1d9b06f2a08dcc97e51f" - integrity sha512-hj5CYrY0bZLB+eTO+x/j67Pkrquiy7kWepMHmUMoPsmcUaeEnQJqFzHJOyxgWlq746/wUuA64p9ta34Kyb01pA== +webpack-dev-middleware@^5.3.4: + version "5.3.4" + resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-5.3.4.tgz#eb7b39281cbce10e104eb2b8bf2b63fce49a3517" + integrity sha512-BVdTqhhs+0IfoeAf7EoH5WE+exCmqGerHfDM0IL096Px60Tq2Mn9MAbnaGUe6HiMa41KMCYF19gyzZmBcq/o4Q== dependencies: colorette "^2.0.10" memfs "^3.4.3" @@ -2690,10 +2734,10 @@ webpack-dev-middleware@^5.3.1: range-parser "^1.2.1" schema-utils "^4.0.0" -webpack-dev-server@4.15.0: - version "4.15.0" - resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-4.15.0.tgz#87ba9006eca53c551607ea0d663f4ae88be7af21" - integrity sha512-HmNB5QeSl1KpulTBQ8UT4FPrByYyaLxpJoQ0+s7EvUrMc16m0ZS1sgb1XGqzmgCPk0c9y+aaXxn11tbLzuM7NQ== +webpack-dev-server@4.15.2: + version "4.15.2" + resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-4.15.2.tgz#9e0c70a42a012560860adb186986da1248333173" + integrity sha512-0XavAZbNJ5sDrCbkpWL8mia0o5WPOd2YGtxrEiZkBK9FjLppIUK2TgxK6qGD2P3hUXTJNNPVibrerKcx5WkR1g== dependencies: "@types/bonjour" "^3.5.9" "@types/connect-history-api-fallback" "^1.3.5" @@ -2701,7 +2745,7 @@ webpack-dev-server@4.15.0: "@types/serve-index" "^1.9.1" "@types/serve-static" "^1.13.10" "@types/sockjs" "^0.3.33" - "@types/ws" "^8.5.1" + "@types/ws" "^8.5.5" ansi-html-community "^0.0.8" bonjour-service "^1.0.11" chokidar "^3.5.3" @@ -2723,7 +2767,7 @@ webpack-dev-server@4.15.0: serve-index "^1.9.1" sockjs "^0.3.24" spdy "^4.0.2" - webpack-dev-middleware "^5.3.1" + webpack-dev-middleware "^5.3.4" ws "^8.13.0" webpack-merge@^4.1.5: @@ -2746,34 +2790,34 @@ webpack-sources@^3.2.3: resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde" integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== -webpack@5.82.0: - version "5.82.0" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.82.0.tgz#3c0d074dec79401db026b4ba0fb23d6333f88e7d" - integrity sha512-iGNA2fHhnDcV1bONdUu554eZx+XeldsaeQ8T67H6KKHl2nUSwX8Zm7cmzOA46ox/X1ARxf7Bjv8wQ/HsB5fxBg== +webpack@5.93.0: + version "5.93.0" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.93.0.tgz#2e89ec7035579bdfba9760d26c63ac5c3462a5e5" + integrity sha512-Y0m5oEY1LRuwly578VqluorkXbvXKh7U3rLoQCEO04M97ScRr44afGVkI0FQFsXzysk5OgFAxjZAb9rsGQVihA== dependencies: "@types/eslint-scope" "^3.7.3" - "@types/estree" "^1.0.0" - "@webassemblyjs/ast" "^1.11.5" - "@webassemblyjs/wasm-edit" "^1.11.5" - "@webassemblyjs/wasm-parser" "^1.11.5" + "@types/estree" "^1.0.5" + "@webassemblyjs/ast" "^1.12.1" + "@webassemblyjs/wasm-edit" "^1.12.1" + "@webassemblyjs/wasm-parser" "^1.12.1" acorn "^8.7.1" - acorn-import-assertions "^1.7.6" - browserslist "^4.14.5" + acorn-import-attributes "^1.9.5" + browserslist "^4.21.10" chrome-trace-event "^1.0.2" - enhanced-resolve "^5.13.0" + enhanced-resolve "^5.17.0" es-module-lexer "^1.2.1" eslint-scope "5.1.1" events "^3.2.0" glob-to-regexp "^0.4.1" - graceful-fs "^4.2.9" + graceful-fs "^4.2.11" json-parse-even-better-errors "^2.3.1" loader-runner "^4.2.0" mime-types "^2.1.27" neo-async "^2.6.2" - schema-utils "^3.1.2" + schema-utils "^3.2.0" tapable "^2.1.1" - terser-webpack-plugin "^5.3.7" - watchpack "^2.4.0" + terser-webpack-plugin "^5.3.10" + watchpack "^2.4.1" webpack-sources "^3.2.3" websocket-driver@>=0.5.1, websocket-driver@^0.7.4: @@ -2809,10 +2853,10 @@ wildcard@^2.0.0: resolved "https://registry.yarnpkg.com/wildcard/-/wildcard-2.0.1.tgz#5ab10d02487198954836b6349f74fff961e10f67" integrity sha512-CC1bOL87PIWSBhDcTrdeLo6eGT7mCFtrg0uIJtqJUFyK+eJnzl8A1niH56uu7KMa5XFrtiV+AQuHO3n7DsHnLQ== -workerpool@6.2.1: - version "6.2.1" - resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343" - integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw== +workerpool@^6.5.1: + version "6.5.1" + resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544" + integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA== wrap-ansi@^7.0.0: version "7.0.0" @@ -2833,27 +2877,22 @@ ws@^8.13.0: resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0" integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== -ws@~8.2.3: - version "8.2.3" - resolved "https://registry.yarnpkg.com/ws/-/ws-8.2.3.tgz#63a56456db1b04367d0b721a0b80cae6d8becbba" - integrity sha512-wBuoj1BDpC6ZQ1B7DWQBYVLphPWkm8i9Y0/3YdHjHKHiohOJ1ws+3OccDWtH+PoC9DZD5WOTrJvNbWvjS6JWaA== +ws@~8.17.1: + version "8.17.1" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.17.1.tgz#9293da530bb548febc95371d90f9c878727d919b" + integrity sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ== y18n@^5.0.5: version "5.0.8" resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55" integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA== -yargs-parser@20.2.4: - version "20.2.4" - resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54" - integrity sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA== - -yargs-parser@^20.2.2: +yargs-parser@^20.2.2, yargs-parser@^20.2.9: version "20.2.9" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee" integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w== -yargs-unparser@2.0.0: +yargs-unparser@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/yargs-unparser/-/yargs-unparser-2.0.0.tgz#f131f9226911ae5d9ad38c432fe809366c2325eb" integrity sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA== @@ -2863,7 +2902,7 @@ yargs-unparser@2.0.0: flat "^5.0.2" is-plain-obj "^2.1.0" -yargs@16.2.0, yargs@^16.1.1: +yargs@^16.1.1, yargs@^16.2.0: version "16.2.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66" integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw== diff --git a/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SmokeTest.kt b/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SmokeTest.kt index 6214ac8..0b1a8c0 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SmokeTest.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SmokeTest.kt @@ -4,7 +4,6 @@ import com.ionspin.kotlin.crypto.generichash.GenericHash import com.ionspin.kotlin.crypto.util.encodeToUByteArray import com.ionspin.kotlin.crypto.util.testBlocking import com.ionspin.kotlin.crypto.util.toHexString -import com.ionspin.kotlin.crypto.util.runTest import kotlin.test.Test import kotlin.test.assertTrue @@ -17,7 +16,6 @@ class SmokeTest { //TODO Browser ignores our testBlocking, node works fine though @Test fun testIfLibraryIsNotOnFire() { - throw Exception("aoaoao") testBlocking { LibsodiumInitializer.initialize() val hashResult = GenericHash.genericHash("Hello".encodeToUByteArray(), 64) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt index 3f5f890..ee79ddd 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -1,7 +1,6 @@ package ext.libsodium.com.ionspin.kotlin.crypto -import com.ionspin.kotlin.crypto.box.BoxKeyPair import org.khronos.webgl.Uint8Array /** @@ -11,9 +10,13 @@ import org.khronos.webgl.Uint8Array */ @JsModule("libsodium-wrappers-sumo") -external object JsSodiumInterface { - +external object JsSodium: JsAny { + @JsName("default") + val default : JsSodiumInterface +} +@JsModule("libsodium-wrappers-sumo") +external object JsSodiumInterface: JsAny { @JsName("crypto_generichash") fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt index aa5254b..e47e0bf 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/LibsodiumInitializer.kt @@ -1,11 +1,12 @@ package com.ionspin.kotlin.crypto +import ext.libsodium.com.ionspin.kotlin.crypto.JsSodium import ext.libsodium.com.ionspin.kotlin.crypto.JsSodiumInterface import ext.libsodium.com.ionspin.kotlin.crypto.JsSodiumLoader var sodiumLoaded: Boolean = false -fun getSodium() : JsSodiumInterface = JsSodiumInterface +fun getSodium() : JsSodiumInterface = JsSodium.default fun getSodiumLoaded() : Boolean = sodiumLoaded diff --git a/multiplatform-crypto-libsodium-bindings/webpack.config.d/patch.js b/multiplatform-crypto-libsodium-bindings/webpack.config.d/patch.js new file mode 100644 index 0000000..8648212 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/webpack.config.d/patch.js @@ -0,0 +1,4 @@ +config.resolve.alias = { + "crypto": false, +// "path": false, +} diff --git a/sample/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/sample/Main.kt b/sample/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/sample/Main.kt index c514c11..f041e31 100644 --- a/sample/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/sample/Main.kt +++ b/sample/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/sample/Main.kt @@ -1,12 +1,15 @@ import com.ionspin.kotlin.crypto.LibsodiumInitializer +import com.ionspin.kotlin.crypto.getSodium +import com.ionspin.kotlin.crypto.hash.Hash +import com.ionspin.kotlin.crypto.util.encodeToUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.JsSodiumInterface fun main() { - LibsodiumInitializer.initializeWithCallback { -// val hash = Hash.sha512("123".encodeToUByteArray()) -// println("Hash (SHA512) of 123: ${hash.toHexString()}") - println("Hello") - } + LibsodiumInitializer.initializeWithCallback { + val hash = Hash.sha512("123".encodeToUByteArray()) + println("Hash (SHA512) of 123: ${hash.toHexString()}") + } } From db219a351fdf20ed7eaab45821cf1f29f90d81d6 Mon Sep 17 00:00:00 2001 From: kildishevps Date: Tue, 31 Dec 2024 05:36:26 +0300 Subject: [PATCH 23/27] Fixing all functions that didn't work and renaming types --- .../kotlin/crypto/JsSodiumInterface.kt | 75 +++++++++---------- .../ionspin/kotlin/crypto/JsSodiumLoader.kt | 1 - .../kotlin/com/ionspin/kotlin/crypto/Types.kt | 42 +++++------ ...thenticatedEncryptionWithAssociatedData.kt | 9 +-- .../kotlin/crypto/generichash/GenericHash.kt | 9 +-- .../com/ionspin/kotlin/crypto/hash/Hash.kt | 15 ++-- .../kotlin/crypto/secretbox/SecretBox.kt | 5 +- .../crypto/secretstream/SecretStream.kt | 21 +++--- sample/build.gradle.kts | 1 - 9 files changed, 76 insertions(+), 102 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt index ee79ddd..37af828 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -29,13 +29,13 @@ external object JsSodiumInterface: JsAny { // ---- Generic hash ---- // Updateable @JsName("crypto_generichash_init") - fun crypto_generichash_init(key : Uint8Array, hashLength: Int) : JsAny + fun crypto_generichash_init(key : Uint8Array, hashLength: Int) : GenericHashStateInternalType @JsName("crypto_generichash_update") - fun crypto_generichash_update(state: JsAny, inputMessage: Uint8Array) + fun crypto_generichash_update(state: GenericHashStateInternalType, inputMessage: Uint8Array) @JsName("crypto_generichash_final") - fun crypto_generichash_final(state: JsAny, hashLength: Int) : Uint8Array + fun crypto_generichash_final(state: GenericHashStateInternalType, hashLength: Int) : Uint8Array @JsName("crypto_generichash_keygen") fun crypto_generichash_keygen() : Uint8Array @@ -43,19 +43,18 @@ external object JsSodiumInterface: JsAny { // ---- Generic hash end ---- // Updateable // ---- Blake2b ---- - + // I @JsName("crypto_generichash_blake2b") fun crypto_generichash_blake2b(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array @JsName("crypto_generichash_blake2b_init") - fun crypto_generichash_blake2b_init(key : Uint8Array, hashLength: Int) : JsAny + fun crypto_generichash_blake2b_init(key : Uint8Array, hashLength: Int) : Blake2bInternalStateType @JsName("crypto_generichash_blake2b_update") - fun crypto_generichash_blake2b_update(state: JsAny, inputMessage: Uint8Array) - // TODO: строка ниже просто висела без ничего, я ее закомментила -//crypto_secretstream_xchacha20poly1305_init_push + fun crypto_generichash_blake2b_update(state: Blake2bInternalStateType, inputMessage: Uint8Array) + @JsName("crypto_generichash_blake2b_final") - fun crypto_generichash_blake2b_final(state: JsAny, hashLength: Int) : Uint8Array + fun crypto_generichash_blake2b_final(state: Blake2bInternalStateType, hashLength: Int) : Uint8Array @JsName("crypto_generichash_blake2b_keygen") fun crypto_generichash_blake2b_keygen() : Uint8Array @@ -72,22 +71,22 @@ external object JsSodiumInterface: JsAny { @JsName("crypto_hash_sha256_init") - fun crypto_hash_sha256_init() : JsAny + fun crypto_hash_sha256_init() : Sha256StateType @JsName("crypto_hash_sha256_update") - fun crypto_hash_sha256_update(state: JsAny, message: Uint8Array) + fun crypto_hash_sha256_update(state: Sha256StateType, message: Uint8Array) @JsName("crypto_hash_sha256_final") - fun crypto_hash_sha256_final(state: JsAny): Uint8Array + fun crypto_hash_sha256_final(state: Sha256StateType): Uint8Array @JsName("crypto_hash_sha512_init") - fun crypto_hash_sha512_init() : JsAny + fun crypto_hash_sha512_init() : Sha512StateType @JsName("crypto_hash_sha512_update") - fun crypto_hash_sha512_update(state: JsAny, message: Uint8Array) + fun crypto_hash_sha512_update(state: Sha512StateType, message: Uint8Array) @JsName("crypto_hash_sha512_final") - fun crypto_hash_sha512_final(state: JsAny): Uint8Array + fun crypto_hash_sha512_final(state: Sha512StateType): Uint8Array //XChaCha20Poly1305 - also in bindings //fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, secretNonce: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array @@ -96,36 +95,36 @@ external object JsSodiumInterface: JsAny { //XChaCha20Poly1305 //encrypt @JsName("crypto_secretstream_xchacha20poly1305_init_push") - fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : CryptoSecretstreamXchacha20poly1305InitPushResult + fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : SecretStreamStateAndHeaderType @JsName("crypto_secretstream_xchacha20poly1305_push") // TODO: два варианта: \/ // 1. Меняем юбайт на байт и юинт на инт \/ // 2. Меняем юбайт на инт и юинт на лонг \/ и далее по списку - fun crypto_secretstream_xchacha20poly1305_push(state: JsAny, message: Uint8Array, associatedData: Uint8Array, tag: Byte) : Uint8Array + fun crypto_secretstream_xchacha20poly1305_push(state: SecretStreamStateType, message: Uint8Array, associatedData: Uint8Array, tag: Byte) : Uint8Array //decrypt @JsName("crypto_secretstream_xchacha20poly1305_init_pull") - fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : JsAny + fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : SecretStreamStateType @JsName("crypto_secretstream_xchacha20poly1305_pull") - fun crypto_secretstream_xchacha20poly1305_pull(state: JsAny, ciphertext: Uint8Array, associatedData: Uint8Array) : JsAny + fun crypto_secretstream_xchacha20poly1305_pull(state: SecretStreamStateType, ciphertext: Uint8Array, associatedData: Uint8Array) : DecryptedDataAndTagType //keygen and rekey @JsName("crypto_secretstream_xchacha20poly1305_keygen") fun crypto_secretstream_xchacha20poly1305_keygen() : Uint8Array @JsName("crypto_secretstream_xchacha20poly1305_rekey") - fun crypto_secretstream_xchacha20poly1305_rekey(state: JsAny) + fun crypto_secretstream_xchacha20poly1305_rekey(state: SecretStreamStateType) // ---- SecretBox ---- @JsName("crypto_secretbox_detached") - fun crypto_secretbox_detached(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : CryptoSecretboxDetachedResult + fun crypto_secretbox_detached(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : SecretBoxEncryptedType @JsName("crypto_secretbox_easy") fun crypto_secretbox_easy(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_secretbox_keygen") fun crypto_secretbox_keygen() : Uint8Array @JsName("crypto_secretbox_open_detached") - fun crypto_secretbox_open_detached(ciphertext : Uint8Array, tag : Uint8Array, nonce: Uint8Array, key: Uint8Array) : JsAny + fun crypto_secretbox_open_detached(ciphertext : Uint8Array, tag : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_secretbox_open_easy") - fun crypto_secretbox_open_easy(ciphertext : Uint8Array, nonce: Uint8Array, key: Uint8Array) : JsAny + fun crypto_secretbox_open_easy(ciphertext : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array // ---- SecretBox End ---- @@ -139,7 +138,7 @@ external object JsSodiumInterface: JsAny { @JsName("crypto_aead_chacha20poly1305_encrypt") fun crypto_aead_chacha20poly1305_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_encrypt_detached") - fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Chacha20poly1305EncryptDetachedResult + fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : AeadEncryptedType @JsName("crypto_aead_chacha20poly1305_ietf_decrypt") fun crypto_aead_chacha20poly1305_ietf_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_ietf_decrypt_detached") @@ -147,7 +146,7 @@ external object JsSodiumInterface: JsAny { @JsName("crypto_aead_chacha20poly1305_ietf_encrypt") fun crypto_aead_chacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_chacha20poly1305_ietf_encrypt_detached") - fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Chacha20poly1305EncryptDetachedResult + fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : AeadEncryptedType @JsName("crypto_aead_chacha20poly1305_ietf_keygen") fun crypto_aead_chacha20poly1305_ietf_keygen() : Uint8Array @JsName("crypto_aead_chacha20poly1305_keygen") @@ -159,7 +158,7 @@ external object JsSodiumInterface: JsAny { @JsName("crypto_aead_xchacha20poly1305_ietf_encrypt") fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array @JsName("crypto_aead_xchacha20poly1305_ietf_encrypt_detached") - fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Chacha20poly1305EncryptDetachedResult + fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : AeadEncryptedType @JsName("crypto_aead_xchacha20poly1305_ietf_keygen") fun crypto_aead_xchacha20poly1305_ietf_keygen(): Uint8Array @@ -191,9 +190,9 @@ external object JsSodiumInterface: JsAny { // ---- Box ---- @JsName("crypto_box_keypair") - fun crypto_box_keypair() : Keypair + fun crypto_box_keypair() : KeyExchangeKeyPairType @JsName("crypto_box_seed_keypair") - fun crypto_box_seed_keypair(seed : Uint8Array) : Keypair + fun crypto_box_seed_keypair(seed : Uint8Array) : KeyExchangeKeyPairType @JsName("crypto_box_easy") fun crypto_box_easy(message: Uint8Array, nonce: Uint8Array, @@ -208,7 +207,7 @@ external object JsSodiumInterface: JsAny { fun crypto_box_detached(message: Uint8Array, nonce: Uint8Array, recipientsPublicKey: Uint8Array, - sendersSecretKey: Uint8Array) : CryptoBoxDetachedResult + sendersSecretKey: Uint8Array) : BoxEncryptedType @JsName("crypto_box_open_detached") fun crypto_box_open_detached(ciphertext: Uint8Array, tag: Uint8Array, @@ -246,19 +245,19 @@ external object JsSodiumInterface: JsAny { @JsName("crypto_sign_ed25519_sk_to_seed") fun crypto_sign_ed25519_sk_to_seed(ed25519SecretKey: Uint8Array) : Uint8Array @JsName("crypto_sign_final_create") - fun crypto_sign_final_create(state: JsAny, secretKey: Uint8Array) : Uint8Array + fun crypto_sign_final_create(state: SignatureStateType, secretKey: Uint8Array) : Uint8Array @JsName("crypto_sign_final_verify") - fun crypto_sign_final_verify(state: JsAny, signature: Uint8Array, publicKey: Uint8Array) : Boolean + fun crypto_sign_final_verify(state: SignatureStateType, signature: Uint8Array, publicKey: Uint8Array) : Boolean @JsName("crypto_sign_init") fun crypto_sign_init() : SignatureStateType @JsName("crypto_sign_keypair") - fun crypto_sign_keypair() : Keypair + fun crypto_sign_keypair() : KeyExchangeKeyPairType @JsName("crypto_sign_open") fun crypto_sign_open(signedMessage: Uint8Array, publicKey: Uint8Array) : Uint8Array @JsName("crypto_sign_seed_keypair") - fun crypto_sign_seed_keypair(seed: Uint8Array) : Keypair + fun crypto_sign_seed_keypair(seed: Uint8Array) : KeyExchangeKeyPairType @JsName("crypto_sign_update") - fun crypto_sign_update(state: JsAny, message: Uint8Array) + fun crypto_sign_update(state: SignatureStateType, message: Uint8Array) @JsName("crypto_sign_verify_detached") fun crypto_sign_verify_detached(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array) : Boolean @@ -327,13 +326,13 @@ external object JsSodiumInterface: JsAny { // ---- Key exchange ---- @JsName("crypto_kx_client_session_keys") - fun crypto_kx_client_session_keys(clientPublicKey: Uint8Array, clientSecretKey: Uint8Array, serverPublicKey: Uint8Array) : CryptoKxClientSessionKeysResult + fun crypto_kx_client_session_keys(clientPublicKey: Uint8Array, clientSecretKey: Uint8Array, serverPublicKey: Uint8Array) : KeyExchangeSessionKeyPairType @JsName("crypto_kx_keypair") - fun crypto_kx_keypair() : Keypair + fun crypto_kx_keypair() : KeyExchangeKeyPairType @JsName("crypto_kx_seed_keypair") - fun crypto_kx_seed_keypair(seed: Uint8Array) : Keypair + fun crypto_kx_seed_keypair(seed: Uint8Array) : KeyExchangeKeyPairType @JsName("crypto_kx_server_session_keys") - fun crypto_kx_server_session_keys(serverPublicKey: Uint8Array, serverSecretKey: Uint8Array, clientPublicKey: Uint8Array) : CryptoKxServerSessionKeysResult + fun crypto_kx_server_session_keys(serverPublicKey: Uint8Array, serverSecretKey: Uint8Array, clientPublicKey: Uint8Array) : KeyExchangeSessionKeyPairType // ---- Key exchange end ---- diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt index a96f2d4..ec7306b 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt @@ -28,7 +28,6 @@ object JsSodiumLoader { _libsodiumPromise.then { sodium_init() sodiumLoaded = true - //Dynamic может быть Юнит, но Unit не может быть JsAny? continuation.resumeWith(Result.success(Unit)) null }.catch { e -> diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/Types.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/Types.kt index 1ca6f46..753003a 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/Types.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/Types.kt @@ -1,58 +1,50 @@ package ext.libsodium.com.ionspin.kotlin.crypto - import org.khronos.webgl.Uint8Array -//TODO: может быть стоит поудалять ненужное + +external object Sha256StateType: JsAny +external object Sha512StateType: JsAny external object SignatureStateType: JsAny -external object Chacha20poly1305EncryptDetachedResult : JsAny { +external object AeadEncryptedType : JsAny { val ciphertext: Uint8Array var mac: Uint8Array } -external object CryptoBoxDetachedResult : JsAny { +external object BoxEncryptedType : JsAny { val ciphertext: Uint8Array var mac: Uint8Array } -//external object CryptoBoxKeypairResult: JsAny { -// val publicKey: Uint8Array -// val privateKey: Uint8Array -//} - -external object CryptoKxClientSessionKeysResult: JsAny { +external object KeyExchangeSessionKeyPairType: JsAny { val sharedRx: Uint8Array val sharedTx: Uint8Array } -//external object CryptoKxKeypairResult: JsAny { -// val publicKey: Uint8Array -// val privateKey: Uint8Array -//} - -external object Keypair: JsAny { +external object KeyExchangeKeyPairType: JsAny { val publicKey: Uint8Array val privateKey: Uint8Array } -// -external object CryptoKxServerSessionKeysResult: JsAny { - val sharedRx: Uint8Array - val sharedTx: Uint8Array -} -external object CryptoSecretboxDetachedResult: JsAny { +external object SecretBoxEncryptedType: JsAny { val cipher: Uint8Array val mac: Uint8Array } -external object CryptoSecretstreamXchacha20poly1305InitPushResult: JsAny { - val state: Uint8Array +external object SecretStreamStateType: JsAny + +external object SecretStreamStateAndHeaderType: JsAny { + val state: SecretStreamStateType val header: Uint8Array } -external object CryptoSecretstreamXchacha20poly1305PullResult: JsAny { +external object DecryptedDataAndTagType: JsAny { val message: Uint8Array val tag: Byte } + +external object GenericHashStateInternalType: JsAny + +external object Blake2bInternalStateType: JsAny diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt index 0c5ee80..d4fbda6 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt @@ -3,7 +3,6 @@ package com.ionspin.kotlin.crypto.aead import com.ionspin.kotlin.crypto.getSodium import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array -import org.khronos.webgl.Uint8Array actual object AuthenticatedEncryptionWithAssociatedData { @@ -131,8 +130,8 @@ actual object AuthenticatedEncryptionWithAssociatedData { key.toUInt8Array(), ) return AeadEncryptedDataAndTag( - (result.ciphertext as Uint8Array).toUByteArray(), - (result.mac as Uint8Array).toUByteArray() + result.ciphertext.toUByteArray(), + result.mac.toUByteArray() ) } @@ -205,8 +204,8 @@ actual object AuthenticatedEncryptionWithAssociatedData { key.toUInt8Array(), ) return AeadEncryptedDataAndTag( - (result.ciphertext as Uint8Array).toUByteArray(), - (result.mac as Uint8Array).toUByteArray() + result.ciphertext.toUByteArray(), + result.mac.toUByteArray() ) } diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt index 86a9f16..5fd9f0f 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/generichash/GenericHash.kt @@ -1,6 +1,7 @@ package com.ionspin.kotlin.crypto.generichash import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.GenericHashStateInternalType import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array import org.khronos.webgl.Uint8Array @@ -11,14 +12,8 @@ import org.khronos.webgl.Uint8Array * on 21-Aug-2020 */ -// TODO: посмотреть, как оно используется -external object GenericHashStateInternalType: JsAny - - //Раз используется как жсЭни, то можно написать = ЖсЭни -//actual typealias GenericHashStateInternal = Any actual typealias GenericHashStateInternal = GenericHashStateInternalType - actual object GenericHash { actual fun genericHash( message: UByteArray, @@ -37,7 +32,7 @@ actual object GenericHash { key: UByteArray? ): GenericHashState { val state = getSodium().crypto_generichash_init(key?.toUInt8Array() ?: Uint8Array(0), requestedHashLength) - return GenericHashState(requestedHashLength, state as GenericHashStateInternal) + return GenericHashState(requestedHashLength, state) } actual fun genericHashUpdate( diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt index ce3d7ab..9287f80 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt @@ -1,19 +1,14 @@ package com.ionspin.kotlin.crypto.hash import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.Sha256StateType +import ext.libsodium.com.ionspin.kotlin.crypto.Sha512StateType import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array -// TODO: проверить, что эти штуки юзаются как жсЭни -//typealias Sha256State = JsAny -//typealias Sha512State = JsAny -//actual typealias Sha256State = Any -//actual typealias Sha512State = Any - -external object Sha256StateType: JsAny actual typealias Sha256State = Sha256StateType -actual typealias Sha512State = Sha256StateType +actual typealias Sha512State = Sha512StateType actual object Hash { @@ -22,7 +17,7 @@ actual object Hash { } actual fun sha256Init(): Sha256State { - return getSodium().crypto_hash_sha256_init() as Sha256State + return getSodium().crypto_hash_sha256_init() } actual fun sha256Update(state: Sha256State, data: UByteArray) { @@ -38,7 +33,7 @@ actual object Hash { } actual fun sha512Init(): Sha512State { - return getSodium().crypto_hash_sha512_init() as Sha512State + return getSodium().crypto_hash_sha512_init() } actual fun sha512Update(state: Sha512State, data: UByteArray) { diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt index e61d14f..7b609b2 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretbox/SecretBox.kt @@ -3,7 +3,6 @@ package com.ionspin.kotlin.crypto.secretbox import com.ionspin.kotlin.crypto.getSodium import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array -import org.khronos.webgl.Uint8Array actual object SecretBox { actual fun easy(message: UByteArray, nonce: UByteArray, key: UByteArray): UByteArray { @@ -25,7 +24,7 @@ actual object SecretBox { nonce.toUInt8Array(), key.toUInt8Array() ) - return (decryptionResult as Uint8Array).toUByteArray() + return decryptionResult.toUByteArray() } catch (error: Throwable) { throw SecretBoxCorruptedOrTamperedDataExceptionOrInvalidKey() } @@ -60,7 +59,7 @@ actual object SecretBox { nonce.toUInt8Array(), key.toUInt8Array() ) - return (decryptionResult as Uint8Array).toUByteArray() + return decryptionResult.toUByteArray() } catch (error: Throwable) { throw SecretBoxCorruptedOrTamperedDataExceptionOrInvalidKey() } diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt index 652f3c8..db56a66 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt @@ -1,20 +1,17 @@ package com.ionspin.kotlin.crypto.secretstream import com.ionspin.kotlin.crypto.getSodium -import ext.libsodium.com.ionspin.kotlin.crypto.CryptoSecretstreamXchacha20poly1305PullResult +import ext.libsodium.com.ionspin.kotlin.crypto.SecretStreamStateType import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array -import org.khronos.webgl.Uint8Array -external object SecretStreamStateType: JsAny - actual typealias SecretStreamState = SecretStreamStateType actual object SecretStream { actual fun xChaCha20Poly1305InitPush(key: UByteArray): SecretStreamStateAndHeader { val state = getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array()) - return SecretStreamStateAndHeader(state.state as SecretStreamState, state.header.toUByteArray()) + return SecretStreamStateAndHeader(state.state, state.header.toUByteArray()) } actual fun xChaCha20Poly1305Push( @@ -33,7 +30,7 @@ actual object SecretStream { header: UByteArray ): SecretStreamStateAndHeader { val state = getSodium().crypto_secretstream_xchacha20poly1305_init_pull(header.toUInt8Array(), key.toUInt8Array()) - return SecretStreamStateAndHeader(state as SecretStreamState, header) + return SecretStreamStateAndHeader(state, header) } actual fun xChaCha20Poly1305Pull( @@ -41,14 +38,14 @@ actual object SecretStream { ciphertext: UByteArray, associatedData: UByteArray ): DecryptedDataAndTag { - val dataAndTag = getSodium().crypto_secretstream_xchacha20poly1305_pull( - state, ciphertext.toUInt8Array(), associatedData.toUInt8Array() - ) - if (dataAndTag as? JsBoolean == false.toJsBoolean()) { + try { + val dataAndTag = getSodium().crypto_secretstream_xchacha20poly1305_pull( + state, ciphertext.toUInt8Array(), associatedData.toUInt8Array() + ) + return DecryptedDataAndTag(dataAndTag.message.toUByteArray(), dataAndTag.tag.toUByte()) + } catch (error: Throwable) { throw SecretStreamCorruptedOrTamperedDataException() } - return DecryptedDataAndTag((dataAndTag as CryptoSecretstreamXchacha20poly1305PullResult).message.toUByteArray(), dataAndTag.tag.toUByte()) - } actual fun xChaCha20Poly1305Keygen(): UByteArray { diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 1eefd25..92311bc 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -245,7 +245,6 @@ kotlin { } val wasmJsTest by getting { dependencies { - dependsOn(commonTest) implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") From f548a162e702a0db0dc68ec0f5b127528e360cf4 Mon Sep 17 00:00:00 2001 From: kildishevps Date: Tue, 31 Dec 2024 05:43:13 +0300 Subject: [PATCH 24/27] Attempt on fixing tests --- .../build.gradle.kts | 2 -- .../com/ionspin/kotlin/crypto/util/TestUtil.kt | 2 +- .../kotlin/com/ionspin/kotlin/crypto/util/runTest.kt | 10 +++++----- .../kotlin/com/ionspin/kotlin/crypto/util/runTest.kt | 8 ++++---- .../com/ionspin/kotlin/crypto/util/TestUtil.kt | 8 ++++---- .../kotlin/com/ionspin/kotlin/crypto/util/runTest.kt | 12 ++++++------ 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index 399e413..bbe7b7b 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -18,10 +18,8 @@ @file:Suppress("UnstableApiUsage") import org.gradle.api.tasks.testing.logging.TestExceptionFormat -import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest -import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest plugins { diff --git a/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt b/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt index 1f28e02..617ad65 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt @@ -36,6 +36,6 @@ fun testBlocking(block : suspend () -> Unit) { block.startCoroutine(continuation) } -expect fun runTest(block: suspend (scope : CoroutineScope) -> Unit) +fun runTest(block: suspend (scope : CoroutineScope) -> Unit) = kotlinx.coroutines.test.runTest { block(this) } diff --git a/multiplatform-crypto-libsodium-bindings/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt b/multiplatform-crypto-libsodium-bindings/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt index 3308acc..9feaae4 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt @@ -1,7 +1,7 @@ package com.ionspin.kotlin.crypto.util -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.promise - -actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit): dynamic = GlobalScope.promise { block(this) } +//import kotlinx.coroutines.CoroutineScope +//import kotlinx.coroutines.GlobalScope +//import kotlinx.coroutines.promise +// +//actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit): dynamic = GlobalScope.promise { block(this) } diff --git a/multiplatform-crypto-libsodium-bindings/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt b/multiplatform-crypto-libsodium-bindings/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt index 1bfc4a2..b3ab999 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt @@ -1,7 +1,7 @@ package com.ionspin.kotlin.crypto.util -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.runBlocking - -actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) = runBlocking { block(this) } +//import kotlinx.coroutines.CoroutineScope +//import kotlinx.coroutines.runBlocking +// +//actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) = runBlocking { block(this) } diff --git a/multiplatform-crypto-libsodium-bindings/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt b/multiplatform-crypto-libsodium-bindings/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt index 1bfc4a2..b3ab999 100644 --- a/multiplatform-crypto-libsodium-bindings/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt +++ b/multiplatform-crypto-libsodium-bindings/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt @@ -1,7 +1,7 @@ package com.ionspin.kotlin.crypto.util -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.runBlocking - -actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) = runBlocking { block(this) } +//import kotlinx.coroutines.CoroutineScope +//import kotlinx.coroutines.runBlocking +// +//actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) = runBlocking { block(this) } diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt index ba77e1e..32c3fc4 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsTest/kotlin/com/ionspin/kotlin/crypto/util/runTest.kt @@ -1,10 +1,10 @@ package com.ionspin.kotlin.crypto.util -import kotlinx.coroutines.CoroutineScope +//import kotlinx.coroutines.CoroutineScope -actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) { - kotlinx.coroutines.test.runTest { - block(this) - } -} +//actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) { +// kotlinx.coroutines.test.runTest { +// block(this) +// } +//} From c5e91fc8eed03af1af603c16ec0f6b676c073b26 Mon Sep 17 00:00:00 2001 From: kildishevps Date: Tue, 31 Dec 2024 17:35:13 +0300 Subject: [PATCH 25/27] Moved all wasmJs to runningOnLinuxx in gradle, deleted unneded TODOS and dependencies --- buildSrc/src/main/kotlin/Deps.kt | 9 +-- multiplatform-crypto-api/build.gradle.kts | 49 ++++++------- .../build.gradle.kts | 70 +++++++++---------- .../kotlin/crypto/JsSodiumInterface.kt | 3 - .../ionspin/kotlin/crypto/JsSodiumLoader.kt | 1 - sample/build.gradle.kts | 48 ++++--------- 6 files changed, 67 insertions(+), 113 deletions(-) diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 5b8d02d..66f7f34 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -16,6 +16,7 @@ object Versions { val kotlinCoroutines = "1.8.0" + val kotlinCoroutinesTest = "1.9.0" val kotlin = "2.0.21" val kotlinSerialization = "1.6.3" val kotlinSerializationPlugin = kotlin @@ -46,6 +47,7 @@ object Deps { val test = "test-common" val testAnnotation = "test-annotations-common" val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.kotlinCoroutines}" + val coroutinesTest = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.kotlinCoroutinesTest}" val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-json:${Versions.kotlinSerialization}" val kotlinBigNum = "com.ionspin.kotlin:bignum:${Versions.kotlinBigNumVersion}" @@ -73,13 +75,6 @@ object Deps { } object wasmJs { -// val stdLib = "stdlib-wasm" -// val test = "test-wasm" - // TODO: написано от балды \/ -// val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:${Versions.kotlinCoroutines}" -// val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:${Versions.kotlinSerialization}" - - object Npm { val libsodiumWrappers = Pair("libsodium-wrappers-sumo", "0.7.13") diff --git a/multiplatform-crypto-api/build.gradle.kts b/multiplatform-crypto-api/build.gradle.kts index 423c93a..0956baa 100644 --- a/multiplatform-crypto-api/build.gradle.kts +++ b/multiplatform-crypto-api/build.gradle.kts @@ -41,18 +41,6 @@ kotlin { runningOnLinuxx86_64 { jvm() - // TODO: wasm тут копирует не апишный, если поменялся тот, то поменять и тут - @OptIn(ExperimentalWasmDsl::class) - wasmJs { - browser { - testTask { - useKarma { - useChrome() - } - } - } - } - js(IR) { browser { testTask { @@ -71,6 +59,16 @@ kotlin { } } + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + browser { + testTask { + useKarma { + useChrome() + } + } + } + } linuxX64("linux") { binaries { staticLib { @@ -126,6 +124,8 @@ kotlin { dependencies { implementation(kotlin(Deps.Common.test)) implementation(kotlin(Deps.Common.testAnnotation)) + implementation(Deps.Common.coroutinesTest) + implementation(kotlin("test")) } } @@ -154,24 +154,17 @@ kotlin { implementation(kotlin(Deps.Js.test)) } } - } - - // TODO: может сунуть обратно в ранинг онг линукс, как и то, что выше - val wasmJsMain by getting { - dependencies { - // implementation(kotlin(Deps.wasmJs.stdLib)) - implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + val wasmJsMain by getting { + dependencies { + implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + } + } + val wasmJsTest by getting { + dependencies { + implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + } } } - val wasmJsTest by getting { - dependencies { - implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") - - implementation(kotlin("test")) - } - } - runningOnMacos { val tvosX64Main by getting { dependsOn(commonMain) diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index bbe7b7b..8698438 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -18,6 +18,7 @@ @file:Suppress("UnstableApiUsage") import org.gradle.api.tasks.testing.logging.TestExceptionFormat +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest @@ -88,20 +89,11 @@ kotlin { } jvm() + val projectRef = project runningOnLinuxx86_64 { println("Configuring Linux X86-64 targets") - wasmJs { - browser { - testTask { - useKarma { - useChromeHeadless() - } - } - } - } - js { browser { testTask { @@ -119,6 +111,18 @@ kotlin { } } + + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + browser { + testTask { + useKarma { + useChrome() + } + } + } + } + linuxX64() { compilations.getByName("main") { val libsodiumCinterop by cinterops.creating { @@ -302,10 +306,8 @@ kotlin { implementation(kotlin(Deps.Common.test)) implementation(kotlin(Deps.Common.testAnnotation)) implementation(Deps.Common.coroutines) - -// implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") + implementation(Deps.Common.coroutinesTest) implementation(kotlin("test")) -// implementation(kotlin("test-junit")) } } @@ -331,24 +333,6 @@ kotlin { } } - // TODO: это скопипасчено с блока runningOnLinuxx86_64 (примерно 590 строка) - val wasmJsMain by getting { - dependencies { - // implementation(kotlin(Deps.wasmJs.stdLib)) - implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) - } - } - val wasmJsTest by getting { - dependencies { - dependsOn(commonTest) - implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") - - implementation(kotlin("test")) - } - } - - //Set up shared source sets //linux, linuxArm32Hfp, linuxArm64 val linux64Bit = setOf( @@ -600,6 +584,17 @@ kotlin { implementation(npm(Deps.Js.Npm.libsodiumWrappers.first, Deps.Js.Npm.libsodiumWrappers.second)) } } + val wasmJsMain by getting { + dependencies { + implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + } + } + val wasmJsTest by getting { + dependencies { + implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") + } + } val linuxX64Main by getting { isRunningInIdea { kotlin.srcDir("src/nativeMain/kotlin") @@ -738,13 +733,12 @@ tasks { // } // } - // TODO: ваще не жс тест, помогите - val wasmJsBrowserTest by getting(KotlinJsTest::class) { - testLogging { - events("PASSED", "FAILED", "SKIPPED") - showStandardStreams = true - } - } +// val wasmJsBrowserTest by getting(KotlinJsTest::class) { +// testLogging { +// events("PASSED", "FAILED", "SKIPPED") +// showStandardStreams = true +// } +// } val jsBrowserTest by getting(KotlinJsTest::class) { testLogging { diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt index 37af828..8260758 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -97,9 +97,6 @@ external object JsSodiumInterface: JsAny { @JsName("crypto_secretstream_xchacha20poly1305_init_push") fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : SecretStreamStateAndHeaderType @JsName("crypto_secretstream_xchacha20poly1305_push") - // TODO: два варианта: \/ - // 1. Меняем юбайт на байт и юинт на инт \/ - // 2. Меняем юбайт на инт и юинт на лонг \/ и далее по списку fun crypto_secretstream_xchacha20poly1305_push(state: SecretStreamStateType, message: Uint8Array, associatedData: Uint8Array, tag: Byte) : Uint8Array //decrypt diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt index ec7306b..183bb85 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt @@ -22,7 +22,6 @@ object JsSodiumLoader { } - // TODO: попробовать сделать из этого suspend вместо continuation suspend fun load(): Unit = suspendCoroutine { continuation -> if (!getSodiumLoaded()) { _libsodiumPromise.then { diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 92311bc..a70eb0a 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -81,7 +81,6 @@ kotlin { binaries.executable() } - @OptIn(ExperimentalWasmDsl::class) wasmJs { browser { @@ -95,24 +94,7 @@ kotlin { } } binaries.executable() -// browser { -// val rootDirPath = project.rootDir.path -// val projectDirPath = project.projectDir.path -// commonWebpackConfig { -// outputFileName = "composeApp.js" -// devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply { -//// static = (static ?: mutableListOf()).apply { -//// // Serve sources to debug inside browser -//// add(rootDirPath) -//// add(projectDirPath) -//// } -// } -// } -// } -// binaries.executable() } - - linuxX64("linux") { binaries { executable { @@ -213,6 +195,8 @@ kotlin { dependencies { implementation(kotlin(Deps.Common.test)) implementation(kotlin(Deps.Common.testAnnotation)) + implementation(Deps.Common.coroutinesTest) + implementation(kotlin("test")) } } @@ -237,23 +221,6 @@ kotlin { } } - val wasmJsMain by getting { - dependencies { - // implementation(kotlin(Deps.wasmJs.stdLib)) - implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) - } - } - val wasmJsTest by getting { - dependencies { - implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") - - implementation(kotlin("test")) - } - } - - - // val nativeMain by creating { // dependsOn(commonMain) // dependencies { @@ -327,7 +294,16 @@ kotlin { implementation(kotlin(Deps.Js.test)) } } - + val wasmJsMain by getting { + dependencies { + implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + } + } + val wasmJsTest by getting { + dependencies { + implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second)) + } + } val linuxMain by getting { dependsOn(nativeMain) } From bd64211bab6cb1f68fe0663683f5e9e329da2ba9 Mon Sep 17 00:00:00 2001 From: kildishevps Date: Sun, 19 Jan 2025 01:25:51 +0300 Subject: [PATCH 26/27] Changed lib version to 0.9.4-SNAPSHOT --- buildSrc/src/main/kotlin/Deps.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 66f7f34..9a729df 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -37,7 +37,7 @@ object Versions { object ReleaseInfo { val group = "com.ionspin.kotlin" - val bindingsVersion = "0.9.3-SNAPSHOT" + val bindingsVersion = "0.9.4-SNAPSHOT" } object Deps { From 90feb762db40ea90d56f9f44056a430197d4f569 Mon Sep 17 00:00:00 2001 From: kildishevps Date: Thu, 23 Jan 2025 00:35:54 +0300 Subject: [PATCH 27/27] Rebase and adapting new functions to wasmJs --- .../kotlin/crypto/JsSodiumInterface.kt | 107 ++++++++++++++++++ .../kotlin/crypto/ed25519/Ed25519LowLevel.kt | 106 +++++++++++++++++ .../ristretto255/Ristretto255LowLevel.kt | 94 +++++++++++++++ 3 files changed, 307 insertions(+) create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt create mode 100644 multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt index 8260758..e766fa5 100644 --- a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -366,5 +366,112 @@ external object JsSodiumInterface: JsAny { // ---- Scalar multiplication end ---- + // + // ---- Ristretto255 ---- + @JsName("crypto_core_ristretto255_is_valid_point") + fun crypto_core_ristretto255_is_valid_point(p: Uint8Array): Boolean + + @JsName("crypto_core_ristretto255_random") + fun crypto_core_ristretto255_random(): Uint8Array + + @JsName("crypto_core_ristretto255_from_hash") + fun crypto_core_ristretto255_from_hash(r: Uint8Array): Uint8Array + + @JsName("crypto_core_ristretto255_add") + fun crypto_core_ristretto255_add(p: Uint8Array, q: Uint8Array): Uint8Array + + @JsName("crypto_core_ristretto255_sub") + fun crypto_core_ristretto255_sub(p: Uint8Array, q: Uint8Array): Uint8Array + + @JsName("crypto_core_ristretto255_scalar_random") + fun crypto_core_ristretto255_scalar_random(): Uint8Array + + @JsName("crypto_core_ristretto255_scalar_reduce") + fun crypto_core_ristretto255_scalar_reduce(s: Uint8Array): Uint8Array + + @JsName("crypto_core_ristretto255_scalar_invert") + fun crypto_core_ristretto255_scalar_invert(s: Uint8Array): Uint8Array + + @JsName("crypto_core_ristretto255_scalar_negate") + fun crypto_core_ristretto255_scalar_negate(s: Uint8Array): Uint8Array + + @JsName("crypto_core_ristretto255_scalar_complement") + fun crypto_core_ristretto255_scalar_complement(s: Uint8Array): Uint8Array + + @JsName("crypto_core_ristretto255_scalar_add") + fun crypto_core_ristretto255_scalar_add(x: Uint8Array, y: Uint8Array): Uint8Array + + @JsName("crypto_core_ristretto255_scalar_sub") + fun crypto_core_ristretto255_scalar_sub(x: Uint8Array, y: Uint8Array): Uint8Array + + @JsName("crypto_core_ristretto255_scalar_mul") + fun crypto_core_ristretto255_scalar_mul(x: Uint8Array, y: Uint8Array): Uint8Array + + @JsName("crypto_scalarmult_ristretto255") + fun crypto_scalarmult_ristretto255(n: Uint8Array, p: Uint8Array): Uint8Array + + @JsName("crypto_scalarmult_ristretto255_base") + fun crypto_scalarmult_ristretto255_base(n: Uint8Array): Uint8Array + + // + // ---- Ristretto255 end ---- + + + // + // ---- Ed25519 ---- + + @JsName("crypto_core_ed25519_is_valid_point") + fun crypto_core_ed25519_is_valid_point(p: Uint8Array): Boolean + + @JsName("crypto_core_ed25519_random") + fun crypto_core_ed25519_random(): Uint8Array + + @JsName("crypto_core_ed25519_from_uniform") + fun crypto_core_ed25519_from_uniform(r: Uint8Array): Uint8Array + + @JsName("crypto_core_ed25519_add") + fun crypto_core_ed25519_add(p: Uint8Array, q: Uint8Array): Uint8Array + + @JsName("crypto_core_ed25519_sub") + fun crypto_core_ed25519_sub(p: Uint8Array, q: Uint8Array): Uint8Array + + @JsName("crypto_core_ed25519_scalar_random") + fun crypto_core_ed25519_scalar_random(): Uint8Array + + @JsName("crypto_core_ed25519_scalar_reduce") + fun crypto_core_ed25519_scalar_reduce(s: Uint8Array): Uint8Array + + @JsName("crypto_core_ed25519_scalar_invert") + fun crypto_core_ed25519_scalar_invert(s: Uint8Array): Uint8Array + + @JsName("crypto_core_ed25519_scalar_negate") + fun crypto_core_ed25519_scalar_negate(s: Uint8Array): Uint8Array + + @JsName("crypto_core_ed25519_scalar_complement") + fun crypto_core_ed25519_scalar_complement(s: Uint8Array): Uint8Array + + @JsName("crypto_core_ed25519_scalar_add") + fun crypto_core_ed25519_scalar_add(x: Uint8Array, y: Uint8Array): Uint8Array + + @JsName("crypto_core_ed25519_scalar_sub") + fun crypto_core_ed25519_scalar_sub(x: Uint8Array, y: Uint8Array): Uint8Array + + @JsName("crypto_core_ed25519_scalar_mul") + fun crypto_core_ed25519_scalar_mul(x: Uint8Array, y: Uint8Array): Uint8Array + + @JsName("crypto_scalarmult_ed25519") + fun crypto_scalarmult_ed25519(n: Uint8Array, p: Uint8Array): Uint8Array + + @JsName("crypto_scalarmult_ed25519_noclamp") + fun crypto_scalarmult_ed25519_noclamp(n: Uint8Array, p: Uint8Array): Uint8Array + + @JsName("crypto_scalarmult_ed25519_base") + fun crypto_scalarmult_ed25519_base(n: Uint8Array): Uint8Array + + @JsName("crypto_scalarmult_ed25519_base_noclamp") + fun crypto_scalarmult_ed25519_base_noclamp(n: Uint8Array): Uint8Array + + // + // ---- Ed25519 end ---- } diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt new file mode 100644 index 0000000..4e33907 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt @@ -0,0 +1,106 @@ +package com.ionspin.kotlin.crypto.ed25519 + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array + +actual object Ed25519LowLevel { + actual fun isValidPoint(encoded: UByteArray): Boolean = + getSodium().crypto_core_ed25519_is_valid_point(encoded.toUInt8Array()) + + actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray { + val result = getSodium().crypto_core_ed25519_add(p.toUInt8Array(), q.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray { + val result = getSodium().crypto_core_ed25519_sub(p.toUInt8Array(), q.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun pointFromUniform(uniform: UByteArray): UByteArray { + val result = getSodium().crypto_core_ed25519_from_uniform(uniform.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun randomPoint(): UByteArray { + val result = getSodium().crypto_core_ed25519_random() + + return result.toUByteArray() + } + + actual fun randomScalar(): UByteArray { + val result = getSodium().crypto_core_ed25519_scalar_random() + + return result.toUByteArray() + } + + actual fun invertScalar(scalar: UByteArray): UByteArray { + val result = getSodium().crypto_core_ed25519_scalar_invert(scalar.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun negateScalar(scalar: UByteArray): UByteArray { + val result = getSodium().crypto_core_ed25519_scalar_negate(scalar.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun complementScalar(scalar: UByteArray): UByteArray { + val result = getSodium().crypto_core_ed25519_scalar_complement(scalar.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = getSodium().crypto_core_ed25519_scalar_add(x.toUInt8Array(), y.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = getSodium().crypto_core_ed25519_scalar_sub(x.toUInt8Array(), y.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = getSodium().crypto_core_ed25519_scalar_mul(x.toUInt8Array(), y.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun reduceScalar(scalar: UByteArray): UByteArray { + val result = getSodium().crypto_core_ed25519_scalar_reduce(scalar.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray { + val result = getSodium().crypto_scalarmult_ed25519(n.toUInt8Array(), p.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun scalarMultiplicationNoClamp(n: UByteArray, p: UByteArray): UByteArray { + val result = getSodium().crypto_scalarmult_ed25519_noclamp(n.toUInt8Array(), p.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun scalarMultiplicationBase(n: UByteArray): UByteArray { + val result = getSodium().crypto_scalarmult_ed25519_base(n.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun scalarMultiplicationBaseNoClamp(n: UByteArray): UByteArray { + val result = getSodium().crypto_scalarmult_ed25519_base_noclamp(n.toUInt8Array()) + + return result.toUByteArray() + } +} \ No newline at end of file diff --git a/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt new file mode 100644 index 0000000..6e40b1c --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/wasmJsMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt @@ -0,0 +1,94 @@ +package com.ionspin.kotlin.crypto.ristretto255 + +import com.ionspin.kotlin.crypto.getSodium +import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray +import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array + +actual object Ristretto255LowLevel { + actual fun isValidPoint(encoded: UByteArray): Boolean = + getSodium().crypto_core_ristretto255_is_valid_point(encoded.toUInt8Array()) + + actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray { + val result = getSodium().crypto_core_ristretto255_add(p.toUInt8Array(), q.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray { + val result = getSodium().crypto_core_ristretto255_sub(p.toUInt8Array(), q.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun pointFromHash(hash: UByteArray): UByteArray { + val result = getSodium().crypto_core_ristretto255_from_hash(hash.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun randomPoint(): UByteArray { + val result = getSodium().crypto_core_ristretto255_random() + + return result.toUByteArray() + } + + actual fun randomScalar(): UByteArray { + val result = getSodium().crypto_core_ristretto255_scalar_random() + + return result.toUByteArray() + } + + actual fun invertScalar(scalar: UByteArray): UByteArray { + val result = getSodium().crypto_core_ristretto255_scalar_invert(scalar.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun negateScalar(scalar: UByteArray): UByteArray { + val result = getSodium().crypto_core_ristretto255_scalar_negate(scalar.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun complementScalar(scalar: UByteArray): UByteArray { + val result = getSodium().crypto_core_ristretto255_scalar_complement(scalar.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = getSodium().crypto_core_ristretto255_scalar_add(x.toUInt8Array(), y.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = getSodium().crypto_core_ristretto255_scalar_sub(x.toUInt8Array(), y.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = getSodium().crypto_core_ristretto255_scalar_mul(x.toUInt8Array(), y.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun reduceScalar(scalar: UByteArray): UByteArray { + val result = getSodium().crypto_core_ristretto255_scalar_reduce(scalar.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray { + val result = getSodium().crypto_scalarmult_ristretto255(n.toUInt8Array(), p.toUInt8Array()) + + return result.toUByteArray() + } + + actual fun scalarMultiplicationBase(n: UByteArray): UByteArray { + val result = getSodium().crypto_scalarmult_ristretto255_base(n.toUInt8Array()) + + return result.toUByteArray() + } +} \ No newline at end of file