Fix libsodium initialization on Kotlin JS
This commit is contained in:
1 parent
eb9158d3e1
commit
e71ff35e14
3 files changed
+5
-51
No files matched your search
+3
@@ -3,6 +3,7 @@ package ext.libsodium.com.ionspin.kotlin.crypto
|
||||
|
||||
import com.ionspin.kotlin.crypto.box.BoxKeyPair
|
||||
import org.khronos.webgl.Uint8Array
|
||||
import kotlin.js.Promise
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
@@ -13,6 +14,8 @@ import org.khronos.webgl.Uint8Array
|
||||
@JsNonModule
|
||||
external object JsSodiumInterface {
|
||||
|
||||
val ready: Promise<dynamic>
|
||||
|
||||
|
||||
@JsName("crypto_generichash")
|
||||
fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array
|
||||
|
||||
+2
-20
@@ -2,12 +2,6 @@ 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
|
||||
|
||||
/**
|
||||
@@ -17,20 +11,9 @@ import kotlin.coroutines.suspendCoroutine
|
||||
*/
|
||||
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<dynamic> {
|
||||
sodium_init()
|
||||
JsSodiumInterface.ready.then<dynamic> {
|
||||
sodiumLoaded = true
|
||||
continuation.resumeWith(Result.success(Unit))
|
||||
}.catch { e ->
|
||||
@@ -43,8 +26,7 @@ object JsSodiumLoader {
|
||||
|
||||
fun loadWithCallback(doneCallback: () -> (Unit)) {
|
||||
if (!getSodiumLoaded()) {
|
||||
_libsodiumPromise.then<dynamic> {
|
||||
sodium_init()
|
||||
JsSodiumInterface.ready.then<dynamic> {
|
||||
sodiumLoaded = true
|
||||
doneCallback.invoke()
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
@file:JsModule("libsodium-sumo")
|
||||
@file:JsNonModule
|
||||
package ext.libsodium
|
||||
|
||||
import org.khronos.webgl.Uint8Array
|
||||
import kotlin.js.Promise
|
||||
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 25-May-2020
|
||||
*/
|
||||
|
||||
@JsName("ready")
|
||||
external val _libsodiumPromise : Promise<dynamic>
|
||||
|
||||
@JsName("_sodium_init")
|
||||
external fun sodium_init() : Int
|
||||
|
||||
external fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array) : Uint8Array
|
||||
|
||||
external fun crypto_hash_sha256(message: Uint8Array) : Uint8Array
|
||||
external fun crypto_hash_sha512(message: Uint8Array) : Uint8Array
|
||||
|
||||
external fun crypto_hash_sha256_init(): dynamic
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user