diff --git a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt index d87f002..ed74443 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -94,7 +94,7 @@ external object JsSodiumInterface { @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: Byte) : Uint8Array + fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, associatedData: Uint8Array, tag: UByte) : Uint8Array //decrypt @JsName("crypto_secretstream_xchacha20poly1305_init_pull") @@ -262,7 +262,7 @@ external object JsSodiumInterface { // ---- KDF ---- @JsName("crypto_kdf_derive_from_key") - fun crypto_kdf_derive_from_key(subkey_len: Int, subkeyId : Int, ctx: String, key: Uint8Array) : Uint8Array + 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 @@ -271,11 +271,11 @@ external object JsSodiumInterface { // ---- Password hashing ---- @JsName("crypto_pwhash") - fun crypto_pwhash(keyLength : Int, password : Uint8Array, salt: Uint8Array, opsLimit: Int, memLimit: Int, algorithm: Int) : Uint8Array + 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: Int, memLimit: Int) : String + 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: Int, memLimit: Int) : Boolean + 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 @@ -310,11 +310,11 @@ external object JsSodiumInterface { @JsName("randombytes_buf") fun randombytes_buf(length: Int) : Uint8Array @JsName("randombytes_buf_deterministic") - fun randombytes_buf_deterministic(length: Int, seed : Uint8Array) : Uint8Array + fun randombytes_buf_deterministic(length: UInt, seed : Uint8Array) : Uint8Array @JsName("randombytes_random") - fun randombytes_random() : Int + fun randombytes_random() : UInt @JsName("randombytes_uniform") - fun randombytes_uniform(upper_bound: Int) : Int + fun randombytes_uniform(upper_bound: UInt) : UInt // ---- Utils end ---- @@ -332,24 +332,24 @@ external object JsSodiumInterface { // -- Stream ---- @JsName("crypto_stream_chacha20") - fun crypto_stream_chacha20(outLength: Int, key: Uint8Array, nonce: Uint8Array) : Uint8Array + 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: Int, key: Uint8Array) : Uint8Array + 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: Int, key: Uint8Array) : Uint8Array + 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: Int, key: Uint8Array) : Uint8Array + fun crypto_stream_xchacha20_xor_ic(message : Uint8Array, nonce: Uint8Array, initialCounter: UInt, key: Uint8Array) : Uint8Array // ---- Stream end ---- diff --git a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt index c865599..e9f72e6 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt @@ -1,13 +1,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 com.ionspin.kotlin.crypto.* +import ext.libsodium.* import kotlin.coroutines.suspendCoroutine /** diff --git a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt index f6c1925..028a19e 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/kdf/Kdf.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jsMain/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, - subkeyId.toInt(), + subkeyLength.toUInt(), + subkeyId.toUInt(), context, masterKey.toUInt8Array() ).toUByteArray() diff --git a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt index 006bc35..b13ee3e 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/pwhash/PasswordHash.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jsMain/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, + outputLength.toUInt(), password.encodeToUByteArray().toUInt8Array(), salt.toUInt8Array(), - opsLimit.toInt(), - memLimit, - algorithm + opsLimit.toUInt(), + memLimit.toUInt(), + algorithm.toUInt() ).toUByteArray() } @@ -51,8 +51,8 @@ actual object PasswordHash { } return getSodium().crypto_pwhash_str( password.encodeToUByteArray().toUInt8Array(), - opslimit.toInt(), - memlimit + opslimit.toUInt(), + memlimit.toUInt() ).encodeToUByteArray() } @@ -73,8 +73,8 @@ actual object PasswordHash { return if ( getSodium().crypto_pwhash_str_needs_rehash( passwordHash.asByteArray().decodeToString(), - opslimit.toInt(), - memlimit + opslimit.toUInt(), + memlimit.toUInt() ) ) { 1 diff --git a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt index 2aff541..27856e8 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/secretstream/SecretStream.kt @@ -20,7 +20,7 @@ actual object SecretStream { tag: UByte ): UByteArray { return getSodium().crypto_secretstream_xchacha20poly1305_push( - state, message.toUInt8Array(), associatedData.toUInt8Array(), tag.toByte() + state, message.toUInt8Array(), associatedData.toUInt8Array(), tag ).toUByteArray() } diff --git a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/stream/Stream.kt b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/stream/Stream.kt index eb076bb..6ee03bd 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/stream/Stream.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jsMain/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, key.toUInt8Array(), nonce.toUInt8Array()) + val result = getSodium().crypto_stream_chacha20(clen.toUInt(), 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.toInt(), + initialCounter.toUInt(), key.toUInt8Array() ) @@ -74,7 +74,7 @@ actual object Stream { val result = getSodium().crypto_stream_chacha20_xor_ic( message.toUInt8Array(), nonce.toUInt8Array(), - initialCounter.toInt(), + initialCounter.toUInt(), key.toUInt8Array() ) diff --git a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumRandom.kt b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumRandom.kt index de82fe4..1854710 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/util/LibsodiumRandom.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jsMain/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, seed.toUInt8Array()).toUByteArray() + 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().toUInt() + return getSodium().randombytes_random() } /** @@ -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.toInt()).toUInt() + return getSodium().randombytes_uniform(upperBound) } }