Fix libsodium initialization on Kotlin Wasm
Some checks are pending
Some checks are pending
This commit is contained in:
parent
b4b08f2e17
commit
e17f5a8dd5
@ -37,7 +37,7 @@ object Versions {
|
||||
|
||||
object ReleaseInfo {
|
||||
val group = "net.sergeych"
|
||||
val bindingsVersion = "0.9.6"
|
||||
val bindingsVersion = "0.9.8-SNAPSHOT"
|
||||
}
|
||||
|
||||
object Deps {
|
||||
@ -142,4 +142,3 @@ object PluginsDeps {
|
||||
val kotlinAndroid = "kotlin-android"
|
||||
val kapt = "kotlin-kapt"
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ package ext.libsodium.com.ionspin.kotlin.crypto
|
||||
|
||||
|
||||
import org.khronos.webgl.Uint8Array
|
||||
import kotlin.js.Promise
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
@ -16,7 +17,9 @@ external object JsSodium: JsAny {
|
||||
}
|
||||
|
||||
@JsModule("libsodium-wrappers-sumo")
|
||||
external object JsSodiumInterface: JsAny {
|
||||
external interface JsSodiumInterface: JsAny {
|
||||
val ready: Promise<JsAny?>
|
||||
|
||||
@JsName("crypto_generichash")
|
||||
fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package ext.libsodium.com.ionspin.kotlin.crypto
|
||||
|
||||
import com.ionspin.kotlin.crypto.getSodiumLoaded
|
||||
import com.ionspin.kotlin.crypto.sodiumLoaded
|
||||
import ext.libsodium.*
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
/**
|
||||
@ -12,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(): Unit = suspendCoroutine { continuation ->
|
||||
if (!getSodiumLoaded()) {
|
||||
_libsodiumPromise.then<JsAny?> {
|
||||
sodium_init()
|
||||
JsSodium.default.ready.then<JsAny?> {
|
||||
sodiumLoaded = true
|
||||
continuation.resumeWith(Result.success(Unit))
|
||||
null
|
||||
@ -45,8 +33,7 @@ object JsSodiumLoader {
|
||||
|
||||
fun loadWithCallback(doneCallback: () -> (Unit)) {
|
||||
if (!getSodiumLoaded()) {
|
||||
_libsodiumPromise.then<JsAny?> {
|
||||
sodium_init()
|
||||
JsSodium.default.ready.then<JsAny?> {
|
||||
sodiumLoaded = true
|
||||
doneCallback.invoke()
|
||||
null
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
@file:JsModule("libsodium-sumo")
|
||||
package ext.libsodium
|
||||
|
||||
import org.khronos.webgl.Uint8Array
|
||||
import kotlin.js.Promise
|
||||
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 25-May-2020
|
||||
*/
|
||||
|
||||
@JsName("ready")
|
||||
external val _libsodiumPromise : Promise<JsAny?>
|
||||
|
||||
@JsName("_sodium_init")
|
||||
external fun sodium_init() : Int
|
||||
|
||||
external fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array) : Uint8Array
|
||||
|
||||
external fun crypto_hash_sha256(message: Uint8Array) : Uint8Array
|
||||
external fun crypto_hash_sha512(message: Uint8Array) : Uint8Array
|
||||
|
||||
external fun crypto_hash_sha256_init(): JsAny
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user