Work on JsSodiumLoader in process. Current problem: wrong type in try-catch (JsAny instead of throwable)
This commit is contained in:
		
							parent
							
								
									99e6316120
								
							
						
					
					
						commit
						669e8ee0c9
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -27,14 +27,18 @@ object JsSodiumLoader {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    suspend fun load() = suspendCoroutine { continuation ->
 | 
			
		||||
    // TODO: попробовать сделать из этого suspend вместо continuation
 | 
			
		||||
    suspend fun load(): Unit = suspendCoroutine { continuation ->
 | 
			
		||||
        if (!getSodiumLoaded()) {
 | 
			
		||||
            _libsodiumPromise.then<dynamic> {
 | 
			
		||||
            _libsodiumPromise.then<JsAny?> {
 | 
			
		||||
                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<dynamic> {
 | 
			
		||||
            _libsodiumPromise.then<JsAny> {
 | 
			
		||||
                sodium_init()
 | 
			
		||||
                sodiumLoaded = true
 | 
			
		||||
                doneCallback.invoke()
 | 
			
		||||
 | 
			
		||||
@ -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<dynamic>
 | 
			
		||||
external val _libsodiumPromise : Promise<JsAny>
 | 
			
		||||
 | 
			
		||||
@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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user