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 {
|
object ReleaseInfo {
|
||||||
val group = "net.sergeych"
|
val group = "net.sergeych"
|
||||||
val bindingsVersion = "0.9.6"
|
val bindingsVersion = "0.9.8-SNAPSHOT"
|
||||||
}
|
}
|
||||||
|
|
||||||
object Deps {
|
object Deps {
|
||||||
@ -142,4 +142,3 @@ object PluginsDeps {
|
|||||||
val kotlinAndroid = "kotlin-android"
|
val kotlinAndroid = "kotlin-android"
|
||||||
val kapt = "kotlin-kapt"
|
val kapt = "kotlin-kapt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package ext.libsodium.com.ionspin.kotlin.crypto
|
|||||||
|
|
||||||
|
|
||||||
import org.khronos.webgl.Uint8Array
|
import org.khronos.webgl.Uint8Array
|
||||||
|
import kotlin.js.Promise
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ugljesa Jovanovic
|
* Created by Ugljesa Jovanovic
|
||||||
@ -16,7 +17,9 @@ external object JsSodium: JsAny {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JsModule("libsodium-wrappers-sumo")
|
@JsModule("libsodium-wrappers-sumo")
|
||||||
external object JsSodiumInterface: JsAny {
|
external interface JsSodiumInterface: JsAny {
|
||||||
|
val ready: Promise<JsAny?>
|
||||||
|
|
||||||
@JsName("crypto_generichash")
|
@JsName("crypto_generichash")
|
||||||
fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array
|
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.getSodiumLoaded
|
||||||
import com.ionspin.kotlin.crypto.sodiumLoaded
|
import com.ionspin.kotlin.crypto.sodiumLoaded
|
||||||
import ext.libsodium.*
|
|
||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,20 +11,9 @@ import kotlin.coroutines.suspendCoroutine
|
|||||||
*/
|
*/
|
||||||
object JsSodiumLoader {
|
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 ->
|
suspend fun load(): Unit = suspendCoroutine { continuation ->
|
||||||
if (!getSodiumLoaded()) {
|
if (!getSodiumLoaded()) {
|
||||||
_libsodiumPromise.then<JsAny?> {
|
JsSodium.default.ready.then<JsAny?> {
|
||||||
sodium_init()
|
|
||||||
sodiumLoaded = true
|
sodiumLoaded = true
|
||||||
continuation.resumeWith(Result.success(Unit))
|
continuation.resumeWith(Result.success(Unit))
|
||||||
null
|
null
|
||||||
@ -45,8 +33,7 @@ object JsSodiumLoader {
|
|||||||
|
|
||||||
fun loadWithCallback(doneCallback: () -> (Unit)) {
|
fun loadWithCallback(doneCallback: () -> (Unit)) {
|
||||||
if (!getSodiumLoaded()) {
|
if (!getSodiumLoaded()) {
|
||||||
_libsodiumPromise.then<JsAny?> {
|
JsSodium.default.ready.then<JsAny?> {
|
||||||
sodium_init()
|
|
||||||
sodiumLoaded = true
|
sodiumLoaded = true
|
||||||
doneCallback.invoke()
|
doneCallback.invoke()
|
||||||
null
|
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