Compare commits
10 Commits
59f2d77890
...
186db7478a
Author | SHA1 | Date | |
---|---|---|---|
|
186db7478a | ||
|
90feb762db | ||
|
bd64211bab | ||
|
c5e91fc8ee | ||
|
f548a162e7 | ||
|
db219a351f | ||
|
083df8a73c | ||
|
e2a079f0d2 | ||
|
c6946c90b4 | ||
|
504e8db46b |
@ -18,7 +18,7 @@
|
||||
buildscript {
|
||||
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23")
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21")
|
||||
classpath("com.android.tools.build:gradle:7.2.2")
|
||||
classpath("org.jetbrains.dokka:dokka-gradle-plugin:1.9.20")
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23")
|
||||
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21")
|
||||
implementation("com.android.tools.build:gradle:7.2.2")
|
||||
implementation ("org.jetbrains.dokka:dokka-gradle-plugin:1.9.20")
|
||||
}
|
||||
|
@ -16,7 +16,8 @@
|
||||
|
||||
object Versions {
|
||||
val kotlinCoroutines = "1.8.0"
|
||||
val kotlin = "1.9.23"
|
||||
val kotlinCoroutinesTest = "1.9.0"
|
||||
val kotlin = "2.0.21"
|
||||
val kotlinSerialization = "1.6.3"
|
||||
val kotlinSerializationPlugin = kotlin
|
||||
val taskTreePlugin = "1.5"
|
||||
@ -36,7 +37,7 @@ object Versions {
|
||||
|
||||
object ReleaseInfo {
|
||||
val group = "com.ionspin.kotlin"
|
||||
val bindingsVersion = "0.9.3-SNAPSHOT"
|
||||
val bindingsVersion = "0.9.4-SNAPSHOT"
|
||||
}
|
||||
|
||||
object Deps {
|
||||
@ -46,6 +47,7 @@ object Deps {
|
||||
val test = "test-common"
|
||||
val testAnnotation = "test-annotations-common"
|
||||
val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.kotlinCoroutines}"
|
||||
val coroutinesTest = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.kotlinCoroutinesTest}"
|
||||
val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-json:${Versions.kotlinSerialization}"
|
||||
|
||||
val kotlinBigNum = "com.ionspin.kotlin:bignum:${Versions.kotlinBigNumVersion}"
|
||||
@ -73,13 +75,6 @@ object Deps {
|
||||
}
|
||||
|
||||
object wasmJs {
|
||||
// val stdLib = "stdlib-wasm"
|
||||
// val test = "test-wasm"
|
||||
// TODO: написано от балды \/
|
||||
// val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:${Versions.kotlinCoroutines}"
|
||||
// val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:${Versions.kotlinSerialization}"
|
||||
|
||||
|
||||
object Npm {
|
||||
val libsodiumWrappers = Pair("libsodium-wrappers-sumo", "0.7.13")
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -17,7 +17,7 @@
|
||||
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
|
||||
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
|
||||
|
||||
plugins {
|
||||
@ -41,18 +41,6 @@ kotlin {
|
||||
runningOnLinuxx86_64 {
|
||||
jvm()
|
||||
|
||||
// TODO: wasm тут копирует не апишный, если поменялся тот, то поменять и тут
|
||||
@OptIn(ExperimentalWasmDsl::class)
|
||||
wasmJs {
|
||||
browser {
|
||||
testTask {
|
||||
useKarma {
|
||||
useChrome()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
js(IR) {
|
||||
browser {
|
||||
testTask {
|
||||
@ -71,6 +59,16 @@ kotlin {
|
||||
}
|
||||
|
||||
}
|
||||
@OptIn(ExperimentalWasmDsl::class)
|
||||
wasmJs {
|
||||
browser {
|
||||
testTask {
|
||||
useKarma {
|
||||
useChrome()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
linuxX64("linux") {
|
||||
binaries {
|
||||
staticLib {
|
||||
@ -126,6 +124,8 @@ kotlin {
|
||||
dependencies {
|
||||
implementation(kotlin(Deps.Common.test))
|
||||
implementation(kotlin(Deps.Common.testAnnotation))
|
||||
implementation(Deps.Common.coroutinesTest)
|
||||
implementation(kotlin("test"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,24 +154,17 @@ kotlin {
|
||||
implementation(kotlin(Deps.Js.test))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: может сунуть обратно в ранинг онг линукс, как и то, что выше
|
||||
val wasmJsMain by getting {
|
||||
dependencies {
|
||||
// implementation(kotlin(Deps.wasmJs.stdLib))
|
||||
implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second))
|
||||
val wasmJsMain by getting {
|
||||
dependencies {
|
||||
implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second))
|
||||
}
|
||||
}
|
||||
val wasmJsTest by getting {
|
||||
dependencies {
|
||||
implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second))
|
||||
}
|
||||
}
|
||||
}
|
||||
val wasmJsTest by getting {
|
||||
dependencies {
|
||||
implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second))
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0")
|
||||
|
||||
implementation(kotlin("test"))
|
||||
}
|
||||
}
|
||||
|
||||
runningOnMacos {
|
||||
val tvosX64Main by getting {
|
||||
dependsOn(commonMain)
|
||||
|
@ -18,10 +18,9 @@
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
|
||||
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
|
||||
|
||||
plugins {
|
||||
@ -90,20 +89,11 @@ kotlin {
|
||||
}
|
||||
|
||||
jvm()
|
||||
|
||||
val projectRef = project
|
||||
runningOnLinuxx86_64 {
|
||||
println("Configuring Linux X86-64 targets")
|
||||
|
||||
wasmJs {
|
||||
browser {
|
||||
testTask {
|
||||
useKarma {
|
||||
useChromeHeadless()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
js {
|
||||
browser {
|
||||
testTask {
|
||||
@ -121,6 +111,18 @@ kotlin {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalWasmDsl::class)
|
||||
wasmJs {
|
||||
browser {
|
||||
testTask {
|
||||
useKarma {
|
||||
useChrome()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
linuxX64() {
|
||||
compilations.getByName("main") {
|
||||
val libsodiumCinterop by cinterops.creating {
|
||||
@ -304,10 +306,8 @@ kotlin {
|
||||
implementation(kotlin(Deps.Common.test))
|
||||
implementation(kotlin(Deps.Common.testAnnotation))
|
||||
implementation(Deps.Common.coroutines)
|
||||
|
||||
// implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0")
|
||||
implementation(Deps.Common.coroutinesTest)
|
||||
implementation(kotlin("test"))
|
||||
// implementation(kotlin("test-junit"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -333,24 +333,6 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: это скопипасчено с блока runningOnLinuxx86_64 (примерно 590 строка)
|
||||
val wasmJsMain by getting {
|
||||
dependencies {
|
||||
// implementation(kotlin(Deps.wasmJs.stdLib))
|
||||
implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second))
|
||||
}
|
||||
}
|
||||
val wasmJsTest by getting {
|
||||
dependencies {
|
||||
dependsOn(commonTest)
|
||||
implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second))
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0")
|
||||
|
||||
implementation(kotlin("test"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Set up shared source sets
|
||||
//linux, linuxArm32Hfp, linuxArm64
|
||||
val linux64Bit = setOf(
|
||||
@ -407,7 +389,7 @@ kotlin {
|
||||
)
|
||||
)
|
||||
|
||||
compilations.getByName("main") {
|
||||
this@withType.compilations.getByName("main") {
|
||||
val libsodiumCinterop by cinterops.creating {
|
||||
defFile(projectRef.file("src/nativeInterop/cinterop/libsodium.def"))
|
||||
compilerOpts.add("-I${projectRef.rootDir}/sodiumWrapper/static-arm64/include/")
|
||||
@ -602,6 +584,17 @@ kotlin {
|
||||
implementation(npm(Deps.Js.Npm.libsodiumWrappers.first, Deps.Js.Npm.libsodiumWrappers.second))
|
||||
}
|
||||
}
|
||||
val wasmJsMain by getting {
|
||||
dependencies {
|
||||
implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second))
|
||||
}
|
||||
}
|
||||
val wasmJsTest by getting {
|
||||
dependencies {
|
||||
implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second))
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0")
|
||||
}
|
||||
}
|
||||
val linuxX64Main by getting {
|
||||
isRunningInIdea {
|
||||
kotlin.srcDir("src/nativeMain/kotlin")
|
||||
@ -740,13 +733,12 @@ tasks {
|
||||
// }
|
||||
// }
|
||||
|
||||
// TODO: ваще не жс тест, помогите
|
||||
val wasmJsBrowserTest by getting(KotlinJsTest::class) {
|
||||
testLogging {
|
||||
events("PASSED", "FAILED", "SKIPPED")
|
||||
showStandardStreams = true
|
||||
}
|
||||
}
|
||||
// val wasmJsBrowserTest by getting(KotlinJsTest::class) {
|
||||
// testLogging {
|
||||
// events("PASSED", "FAILED", "SKIPPED")
|
||||
// showStandardStreams = true
|
||||
// }
|
||||
// }
|
||||
|
||||
val jsBrowserTest by getting(KotlinJsTest::class) {
|
||||
testLogging {
|
||||
|
@ -4,7 +4,6 @@ import com.ionspin.kotlin.crypto.generichash.GenericHash
|
||||
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
|
||||
import com.ionspin.kotlin.crypto.util.testBlocking
|
||||
import com.ionspin.kotlin.crypto.util.toHexString
|
||||
import com.ionspin.kotlin.crypto.util.runTest
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@ -17,7 +16,6 @@ class SmokeTest {
|
||||
//TODO Browser ignores our testBlocking, node works fine though
|
||||
@Test
|
||||
fun testIfLibraryIsNotOnFire() {
|
||||
throw Exception("aoaoao")
|
||||
testBlocking {
|
||||
LibsodiumInitializer.initialize()
|
||||
val hashResult = GenericHash.genericHash("Hello".encodeToUByteArray(), 64)
|
||||
|
@ -36,6 +36,6 @@ fun testBlocking(block : suspend () -> Unit) {
|
||||
block.startCoroutine(continuation)
|
||||
}
|
||||
|
||||
expect fun runTest(block: suspend (scope : CoroutineScope) -> Unit)
|
||||
fun runTest(block: suspend (scope : CoroutineScope) -> Unit) = kotlinx.coroutines.test.runTest { block(this) }
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.ionspin.kotlin.crypto.util
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.promise
|
||||
|
||||
actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit): dynamic = GlobalScope.promise { block(this) }
|
||||
//import kotlinx.coroutines.CoroutineScope
|
||||
//import kotlinx.coroutines.GlobalScope
|
||||
//import kotlinx.coroutines.promise
|
||||
//
|
||||
//actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit): dynamic = GlobalScope.promise { block(this) }
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.ionspin.kotlin.crypto.util
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) = runBlocking { block(this) }
|
||||
//import kotlinx.coroutines.CoroutineScope
|
||||
//import kotlinx.coroutines.runBlocking
|
||||
//
|
||||
//actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) = runBlocking { block(this) }
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.ionspin.kotlin.crypto.util
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) = runBlocking { block(this) }
|
||||
//import kotlinx.coroutines.CoroutineScope
|
||||
//import kotlinx.coroutines.runBlocking
|
||||
//
|
||||
//actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) = runBlocking { block(this) }
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package ext.libsodium.com.ionspin.kotlin.crypto
|
||||
|
||||
|
||||
import com.ionspin.kotlin.crypto.box.BoxKeyPair
|
||||
import org.khronos.webgl.Uint8Array
|
||||
|
||||
/**
|
||||
@ -11,9 +10,13 @@ import org.khronos.webgl.Uint8Array
|
||||
*/
|
||||
|
||||
@JsModule("libsodium-wrappers-sumo")
|
||||
external object JsSodiumInterface {
|
||||
|
||||
external object JsSodium: JsAny {
|
||||
@JsName("default")
|
||||
val default : JsSodiumInterface
|
||||
}
|
||||
|
||||
@JsModule("libsodium-wrappers-sumo")
|
||||
external object JsSodiumInterface: JsAny {
|
||||
@JsName("crypto_generichash")
|
||||
fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array
|
||||
|
||||
@ -26,13 +29,13 @@ external object JsSodiumInterface {
|
||||
// ---- Generic hash ---- // Updateable
|
||||
|
||||
@JsName("crypto_generichash_init")
|
||||
fun crypto_generichash_init(key : Uint8Array, hashLength: Int) : JsAny
|
||||
fun crypto_generichash_init(key : Uint8Array, hashLength: Int) : GenericHashStateInternalType
|
||||
|
||||
@JsName("crypto_generichash_update")
|
||||
fun crypto_generichash_update(state: JsAny, inputMessage: Uint8Array)
|
||||
fun crypto_generichash_update(state: GenericHashStateInternalType, inputMessage: Uint8Array)
|
||||
|
||||
@JsName("crypto_generichash_final")
|
||||
fun crypto_generichash_final(state: JsAny, hashLength: Int) : Uint8Array
|
||||
fun crypto_generichash_final(state: GenericHashStateInternalType, hashLength: Int) : Uint8Array
|
||||
|
||||
@JsName("crypto_generichash_keygen")
|
||||
fun crypto_generichash_keygen() : Uint8Array
|
||||
@ -40,19 +43,18 @@ external object JsSodiumInterface {
|
||||
// ---- Generic hash end ---- // Updateable
|
||||
|
||||
// ---- Blake2b ----
|
||||
|
||||
// I
|
||||
@JsName("crypto_generichash_blake2b")
|
||||
fun crypto_generichash_blake2b(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_generichash_blake2b_init")
|
||||
fun crypto_generichash_blake2b_init(key : Uint8Array, hashLength: Int) : JsAny
|
||||
fun crypto_generichash_blake2b_init(key : Uint8Array, hashLength: Int) : Blake2bInternalStateType
|
||||
|
||||
@JsName("crypto_generichash_blake2b_update")
|
||||
fun crypto_generichash_blake2b_update(state: JsAny, inputMessage: Uint8Array)
|
||||
// TODO: строка ниже просто висела без ничего, я ее закомментила
|
||||
//crypto_secretstream_xchacha20poly1305_init_push
|
||||
fun crypto_generichash_blake2b_update(state: Blake2bInternalStateType, inputMessage: Uint8Array)
|
||||
|
||||
@JsName("crypto_generichash_blake2b_final")
|
||||
fun crypto_generichash_blake2b_final(state: JsAny, hashLength: Int) : Uint8Array
|
||||
fun crypto_generichash_blake2b_final(state: Blake2bInternalStateType, hashLength: Int) : Uint8Array
|
||||
|
||||
@JsName("crypto_generichash_blake2b_keygen")
|
||||
fun crypto_generichash_blake2b_keygen() : Uint8Array
|
||||
@ -69,22 +71,22 @@ external object JsSodiumInterface {
|
||||
|
||||
|
||||
@JsName("crypto_hash_sha256_init")
|
||||
fun crypto_hash_sha256_init() : JsAny
|
||||
fun crypto_hash_sha256_init() : Sha256StateType
|
||||
|
||||
@JsName("crypto_hash_sha256_update")
|
||||
fun crypto_hash_sha256_update(state: JsAny, message: Uint8Array)
|
||||
fun crypto_hash_sha256_update(state: Sha256StateType, message: Uint8Array)
|
||||
|
||||
@JsName("crypto_hash_sha256_final")
|
||||
fun crypto_hash_sha256_final(state: JsAny): Uint8Array
|
||||
fun crypto_hash_sha256_final(state: Sha256StateType): Uint8Array
|
||||
|
||||
@JsName("crypto_hash_sha512_init")
|
||||
fun crypto_hash_sha512_init() : JsAny
|
||||
fun crypto_hash_sha512_init() : Sha512StateType
|
||||
|
||||
@JsName("crypto_hash_sha512_update")
|
||||
fun crypto_hash_sha512_update(state: JsAny, message: Uint8Array)
|
||||
fun crypto_hash_sha512_update(state: Sha512StateType, message: Uint8Array)
|
||||
|
||||
@JsName("crypto_hash_sha512_final")
|
||||
fun crypto_hash_sha512_final(state: JsAny): Uint8Array
|
||||
fun crypto_hash_sha512_final(state: Sha512StateType): Uint8Array
|
||||
|
||||
//XChaCha20Poly1305 - also in bindings
|
||||
//fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, secretNonce: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
@ -93,36 +95,33 @@ external object JsSodiumInterface {
|
||||
//XChaCha20Poly1305
|
||||
//encrypt
|
||||
@JsName("crypto_secretstream_xchacha20poly1305_init_push")
|
||||
fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : CryptoSecretstreamXchacha20poly1305InitPushResult
|
||||
fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : SecretStreamStateAndHeaderType
|
||||
@JsName("crypto_secretstream_xchacha20poly1305_push")
|
||||
// TODO: два варианта: \/
|
||||
// 1. Меняем юбайт на байт и юинт на инт \/
|
||||
// 2. Меняем юбайт на инт и юинт на лонг \/ и далее по списку
|
||||
fun crypto_secretstream_xchacha20poly1305_push(state: JsAny, message: Uint8Array, associatedData: Uint8Array, tag: Byte) : Uint8Array
|
||||
fun crypto_secretstream_xchacha20poly1305_push(state: SecretStreamStateType, message: Uint8Array, associatedData: Uint8Array, tag: Byte) : Uint8Array
|
||||
|
||||
//decrypt
|
||||
@JsName("crypto_secretstream_xchacha20poly1305_init_pull")
|
||||
fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : JsAny
|
||||
fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : SecretStreamStateType
|
||||
@JsName("crypto_secretstream_xchacha20poly1305_pull")
|
||||
fun crypto_secretstream_xchacha20poly1305_pull(state: JsAny, ciphertext: Uint8Array, associatedData: Uint8Array) : JsAny
|
||||
fun crypto_secretstream_xchacha20poly1305_pull(state: SecretStreamStateType, ciphertext: Uint8Array, associatedData: Uint8Array) : DecryptedDataAndTagType
|
||||
|
||||
//keygen and rekey
|
||||
@JsName("crypto_secretstream_xchacha20poly1305_keygen")
|
||||
fun crypto_secretstream_xchacha20poly1305_keygen() : Uint8Array
|
||||
@JsName("crypto_secretstream_xchacha20poly1305_rekey")
|
||||
fun crypto_secretstream_xchacha20poly1305_rekey(state: JsAny)
|
||||
fun crypto_secretstream_xchacha20poly1305_rekey(state: SecretStreamStateType)
|
||||
|
||||
// ---- SecretBox ----
|
||||
@JsName("crypto_secretbox_detached")
|
||||
fun crypto_secretbox_detached(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : CryptoSecretboxDetachedResult
|
||||
fun crypto_secretbox_detached(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : SecretBoxEncryptedType
|
||||
@JsName("crypto_secretbox_easy")
|
||||
fun crypto_secretbox_easy(message: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
@JsName("crypto_secretbox_keygen")
|
||||
fun crypto_secretbox_keygen() : Uint8Array
|
||||
@JsName("crypto_secretbox_open_detached")
|
||||
fun crypto_secretbox_open_detached(ciphertext : Uint8Array, tag : Uint8Array, nonce: Uint8Array, key: Uint8Array) : JsAny
|
||||
fun crypto_secretbox_open_detached(ciphertext : Uint8Array, tag : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
@JsName("crypto_secretbox_open_easy")
|
||||
fun crypto_secretbox_open_easy(ciphertext : Uint8Array, nonce: Uint8Array, key: Uint8Array) : JsAny
|
||||
fun crypto_secretbox_open_easy(ciphertext : Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
|
||||
|
||||
// ---- SecretBox End ----
|
||||
@ -136,7 +135,7 @@ external object JsSodiumInterface {
|
||||
@JsName("crypto_aead_chacha20poly1305_encrypt")
|
||||
fun crypto_aead_chacha20poly1305_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
@JsName("crypto_aead_chacha20poly1305_encrypt_detached")
|
||||
fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Chacha20poly1305EncryptDetachedResult
|
||||
fun crypto_aead_chacha20poly1305_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : AeadEncryptedType
|
||||
@JsName("crypto_aead_chacha20poly1305_ietf_decrypt")
|
||||
fun crypto_aead_chacha20poly1305_ietf_decrypt(nsec : Uint8Array?, ciphertext: Uint8Array, associatedData: Uint8Array, npub: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
@JsName("crypto_aead_chacha20poly1305_ietf_decrypt_detached")
|
||||
@ -144,7 +143,7 @@ external object JsSodiumInterface {
|
||||
@JsName("crypto_aead_chacha20poly1305_ietf_encrypt")
|
||||
fun crypto_aead_chacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
@JsName("crypto_aead_chacha20poly1305_ietf_encrypt_detached")
|
||||
fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Chacha20poly1305EncryptDetachedResult
|
||||
fun crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : AeadEncryptedType
|
||||
@JsName("crypto_aead_chacha20poly1305_ietf_keygen")
|
||||
fun crypto_aead_chacha20poly1305_ietf_keygen() : Uint8Array
|
||||
@JsName("crypto_aead_chacha20poly1305_keygen")
|
||||
@ -156,7 +155,7 @@ external object JsSodiumInterface {
|
||||
@JsName("crypto_aead_xchacha20poly1305_ietf_encrypt")
|
||||
fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
@JsName("crypto_aead_xchacha20poly1305_ietf_encrypt_detached")
|
||||
fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : Chacha20poly1305EncryptDetachedResult
|
||||
fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: Uint8Array, associatedData: Uint8Array, nsec: Uint8Array?, npub: Uint8Array, key: Uint8Array) : AeadEncryptedType
|
||||
@JsName("crypto_aead_xchacha20poly1305_ietf_keygen")
|
||||
fun crypto_aead_xchacha20poly1305_ietf_keygen(): Uint8Array
|
||||
|
||||
@ -188,9 +187,9 @@ external object JsSodiumInterface {
|
||||
// ---- Box ----
|
||||
|
||||
@JsName("crypto_box_keypair")
|
||||
fun crypto_box_keypair() : Keypair
|
||||
fun crypto_box_keypair() : KeyExchangeKeyPairType
|
||||
@JsName("crypto_box_seed_keypair")
|
||||
fun crypto_box_seed_keypair(seed : Uint8Array) : Keypair
|
||||
fun crypto_box_seed_keypair(seed : Uint8Array) : KeyExchangeKeyPairType
|
||||
@JsName("crypto_box_easy")
|
||||
fun crypto_box_easy(message: Uint8Array,
|
||||
nonce: Uint8Array,
|
||||
@ -205,7 +204,7 @@ external object JsSodiumInterface {
|
||||
fun crypto_box_detached(message: Uint8Array,
|
||||
nonce: Uint8Array,
|
||||
recipientsPublicKey: Uint8Array,
|
||||
sendersSecretKey: Uint8Array) : CryptoBoxDetachedResult
|
||||
sendersSecretKey: Uint8Array) : BoxEncryptedType
|
||||
@JsName("crypto_box_open_detached")
|
||||
fun crypto_box_open_detached(ciphertext: Uint8Array,
|
||||
tag: Uint8Array,
|
||||
@ -243,19 +242,19 @@ external object JsSodiumInterface {
|
||||
@JsName("crypto_sign_ed25519_sk_to_seed")
|
||||
fun crypto_sign_ed25519_sk_to_seed(ed25519SecretKey: Uint8Array) : Uint8Array
|
||||
@JsName("crypto_sign_final_create")
|
||||
fun crypto_sign_final_create(state: JsAny, secretKey: Uint8Array) : Uint8Array
|
||||
fun crypto_sign_final_create(state: SignatureStateType, secretKey: Uint8Array) : Uint8Array
|
||||
@JsName("crypto_sign_final_verify")
|
||||
fun crypto_sign_final_verify(state: JsAny, signature: Uint8Array, publicKey: Uint8Array) : Boolean
|
||||
fun crypto_sign_final_verify(state: SignatureStateType, signature: Uint8Array, publicKey: Uint8Array) : Boolean
|
||||
@JsName("crypto_sign_init")
|
||||
fun crypto_sign_init() : SignatureStateType
|
||||
@JsName("crypto_sign_keypair")
|
||||
fun crypto_sign_keypair() : Keypair
|
||||
fun crypto_sign_keypair() : KeyExchangeKeyPairType
|
||||
@JsName("crypto_sign_open")
|
||||
fun crypto_sign_open(signedMessage: Uint8Array, publicKey: Uint8Array) : Uint8Array
|
||||
@JsName("crypto_sign_seed_keypair")
|
||||
fun crypto_sign_seed_keypair(seed: Uint8Array) : Keypair
|
||||
fun crypto_sign_seed_keypair(seed: Uint8Array) : KeyExchangeKeyPairType
|
||||
@JsName("crypto_sign_update")
|
||||
fun crypto_sign_update(state: JsAny, message: Uint8Array)
|
||||
fun crypto_sign_update(state: SignatureStateType, message: Uint8Array)
|
||||
@JsName("crypto_sign_verify_detached")
|
||||
fun crypto_sign_verify_detached(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array) : Boolean
|
||||
|
||||
@ -324,13 +323,13 @@ external object JsSodiumInterface {
|
||||
|
||||
// ---- Key exchange ----
|
||||
@JsName("crypto_kx_client_session_keys")
|
||||
fun crypto_kx_client_session_keys(clientPublicKey: Uint8Array, clientSecretKey: Uint8Array, serverPublicKey: Uint8Array) : CryptoKxClientSessionKeysResult
|
||||
fun crypto_kx_client_session_keys(clientPublicKey: Uint8Array, clientSecretKey: Uint8Array, serverPublicKey: Uint8Array) : KeyExchangeSessionKeyPairType
|
||||
@JsName("crypto_kx_keypair")
|
||||
fun crypto_kx_keypair() : Keypair
|
||||
fun crypto_kx_keypair() : KeyExchangeKeyPairType
|
||||
@JsName("crypto_kx_seed_keypair")
|
||||
fun crypto_kx_seed_keypair(seed: Uint8Array) : Keypair
|
||||
fun crypto_kx_seed_keypair(seed: Uint8Array) : KeyExchangeKeyPairType
|
||||
@JsName("crypto_kx_server_session_keys")
|
||||
fun crypto_kx_server_session_keys(serverPublicKey: Uint8Array, serverSecretKey: Uint8Array, clientPublicKey: Uint8Array) : CryptoKxServerSessionKeysResult
|
||||
fun crypto_kx_server_session_keys(serverPublicKey: Uint8Array, serverSecretKey: Uint8Array, clientPublicKey: Uint8Array) : KeyExchangeSessionKeyPairType
|
||||
|
||||
// ---- Key exchange end ----
|
||||
|
||||
@ -367,5 +366,112 @@ external object JsSodiumInterface {
|
||||
// ---- Scalar multiplication end ----
|
||||
|
||||
|
||||
//
|
||||
// ---- Ristretto255 ----
|
||||
|
||||
@JsName("crypto_core_ristretto255_is_valid_point")
|
||||
fun crypto_core_ristretto255_is_valid_point(p: Uint8Array): Boolean
|
||||
|
||||
@JsName("crypto_core_ristretto255_random")
|
||||
fun crypto_core_ristretto255_random(): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_from_hash")
|
||||
fun crypto_core_ristretto255_from_hash(r: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_add")
|
||||
fun crypto_core_ristretto255_add(p: Uint8Array, q: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_sub")
|
||||
fun crypto_core_ristretto255_sub(p: Uint8Array, q: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_random")
|
||||
fun crypto_core_ristretto255_scalar_random(): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_reduce")
|
||||
fun crypto_core_ristretto255_scalar_reduce(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_invert")
|
||||
fun crypto_core_ristretto255_scalar_invert(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_negate")
|
||||
fun crypto_core_ristretto255_scalar_negate(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_complement")
|
||||
fun crypto_core_ristretto255_scalar_complement(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_add")
|
||||
fun crypto_core_ristretto255_scalar_add(x: Uint8Array, y: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_sub")
|
||||
fun crypto_core_ristretto255_scalar_sub(x: Uint8Array, y: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_mul")
|
||||
fun crypto_core_ristretto255_scalar_mul(x: Uint8Array, y: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_scalarmult_ristretto255")
|
||||
fun crypto_scalarmult_ristretto255(n: Uint8Array, p: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_scalarmult_ristretto255_base")
|
||||
fun crypto_scalarmult_ristretto255_base(n: Uint8Array): Uint8Array
|
||||
|
||||
//
|
||||
// ---- Ristretto255 end ----
|
||||
|
||||
|
||||
//
|
||||
// ---- Ed25519 ----
|
||||
|
||||
@JsName("crypto_core_ed25519_is_valid_point")
|
||||
fun crypto_core_ed25519_is_valid_point(p: Uint8Array): Boolean
|
||||
|
||||
@JsName("crypto_core_ed25519_random")
|
||||
fun crypto_core_ed25519_random(): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_from_uniform")
|
||||
fun crypto_core_ed25519_from_uniform(r: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_add")
|
||||
fun crypto_core_ed25519_add(p: Uint8Array, q: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_sub")
|
||||
fun crypto_core_ed25519_sub(p: Uint8Array, q: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_random")
|
||||
fun crypto_core_ed25519_scalar_random(): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_reduce")
|
||||
fun crypto_core_ed25519_scalar_reduce(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_invert")
|
||||
fun crypto_core_ed25519_scalar_invert(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_negate")
|
||||
fun crypto_core_ed25519_scalar_negate(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_complement")
|
||||
fun crypto_core_ed25519_scalar_complement(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_add")
|
||||
fun crypto_core_ed25519_scalar_add(x: Uint8Array, y: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_sub")
|
||||
fun crypto_core_ed25519_scalar_sub(x: Uint8Array, y: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_mul")
|
||||
fun crypto_core_ed25519_scalar_mul(x: Uint8Array, y: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_scalarmult_ed25519")
|
||||
fun crypto_scalarmult_ed25519(n: Uint8Array, p: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_scalarmult_ed25519_noclamp")
|
||||
fun crypto_scalarmult_ed25519_noclamp(n: Uint8Array, p: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_scalarmult_ed25519_base")
|
||||
fun crypto_scalarmult_ed25519_base(n: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_scalarmult_ed25519_base_noclamp")
|
||||
fun crypto_scalarmult_ed25519_base_noclamp(n: Uint8Array): Uint8Array
|
||||
|
||||
//
|
||||
// ---- Ed25519 end ----
|
||||
}
|
||||
|
@ -2,12 +2,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 ext.libsodium.*
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
/**
|
||||
@ -27,21 +22,19 @@ object JsSodiumLoader {
|
||||
|
||||
}
|
||||
|
||||
// TODO: попробовать сделать из этого suspend вместо continuation
|
||||
suspend fun load(): Unit = suspendCoroutine { continuation ->
|
||||
if (!getSodiumLoaded()) {
|
||||
_libsodiumPromise.then<JsAny?> {
|
||||
sodium_init()
|
||||
sodiumLoaded = true
|
||||
//Dynamic может быть Юнит, но Unit не может быть JsAny?
|
||||
continuation.resumeWith(Result.success(Unit))
|
||||
null
|
||||
}.catch { e ->
|
||||
val throwable = e as? Throwable
|
||||
val throwable = e.toThrowableOrNull()
|
||||
if (throwable != null) {
|
||||
continuation.resumeWith(Result.failure(throwable))
|
||||
} else {
|
||||
continuation.resumeWith(Result.failure(Exception("Error: $e")))
|
||||
continuation.resumeWith(Result.failure(Throwable("Unknown error", throwable)))
|
||||
}
|
||||
null
|
||||
}
|
||||
@ -50,12 +43,13 @@ object JsSodiumLoader {
|
||||
}
|
||||
}
|
||||
|
||||
fun loadWithCallback(doneCallback: () -> (JsAny)) {
|
||||
fun loadWithCallback(doneCallback: () -> (Unit)) {
|
||||
if (!getSodiumLoaded()) {
|
||||
_libsodiumPromise.then<JsAny> {
|
||||
_libsodiumPromise.then<JsAny?> {
|
||||
sodium_init()
|
||||
sodiumLoaded = true
|
||||
doneCallback.invoke()
|
||||
null
|
||||
}
|
||||
} else {
|
||||
doneCallback.invoke()
|
||||
|
@ -1,11 +1,12 @@
|
||||
package com.ionspin.kotlin.crypto
|
||||
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.JsSodium
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.JsSodiumInterface
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.JsSodiumLoader
|
||||
|
||||
var sodiumLoaded: Boolean = false
|
||||
|
||||
fun getSodium() : JsSodiumInterface = JsSodiumInterface
|
||||
fun getSodium() : JsSodiumInterface = JsSodium.default
|
||||
|
||||
fun getSodiumLoaded() : Boolean = sodiumLoaded
|
||||
|
||||
@ -26,8 +27,6 @@ actual object LibsodiumInitializer {
|
||||
JsSodiumLoader.loadWithCallback {
|
||||
isPlatformInitialized = true
|
||||
done()
|
||||
// TODO: there's no return needed!!!
|
||||
"null".toJsString()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,58 +1,50 @@
|
||||
package ext.libsodium.com.ionspin.kotlin.crypto
|
||||
|
||||
|
||||
import org.khronos.webgl.Uint8Array
|
||||
|
||||
//TODO: может быть стоит поудалять ненужное
|
||||
|
||||
external object Sha256StateType: JsAny
|
||||
external object Sha512StateType: JsAny
|
||||
|
||||
external object SignatureStateType: JsAny
|
||||
|
||||
external object Chacha20poly1305EncryptDetachedResult : JsAny {
|
||||
external object AeadEncryptedType : JsAny {
|
||||
val ciphertext: Uint8Array
|
||||
var mac: Uint8Array
|
||||
}
|
||||
|
||||
external object CryptoBoxDetachedResult : JsAny {
|
||||
external object BoxEncryptedType : JsAny {
|
||||
val ciphertext: Uint8Array
|
||||
var mac: Uint8Array
|
||||
}
|
||||
|
||||
//external object CryptoBoxKeypairResult: JsAny {
|
||||
// val publicKey: Uint8Array
|
||||
// val privateKey: Uint8Array
|
||||
//}
|
||||
|
||||
external object CryptoKxClientSessionKeysResult: JsAny {
|
||||
external object KeyExchangeSessionKeyPairType: JsAny {
|
||||
val sharedRx: Uint8Array
|
||||
val sharedTx: Uint8Array
|
||||
}
|
||||
|
||||
//external object CryptoKxKeypairResult: JsAny {
|
||||
// val publicKey: Uint8Array
|
||||
// val privateKey: Uint8Array
|
||||
//}
|
||||
|
||||
external object Keypair: JsAny {
|
||||
external object KeyExchangeKeyPairType: JsAny {
|
||||
val publicKey: Uint8Array
|
||||
val privateKey: Uint8Array
|
||||
}
|
||||
//
|
||||
external object CryptoKxServerSessionKeysResult: JsAny {
|
||||
val sharedRx: Uint8Array
|
||||
val sharedTx: Uint8Array
|
||||
}
|
||||
|
||||
external object CryptoSecretboxDetachedResult: JsAny {
|
||||
external object SecretBoxEncryptedType: JsAny {
|
||||
val cipher: Uint8Array
|
||||
val mac: Uint8Array
|
||||
}
|
||||
|
||||
external object CryptoSecretstreamXchacha20poly1305InitPushResult: JsAny {
|
||||
val state: Uint8Array
|
||||
external object SecretStreamStateType: JsAny
|
||||
|
||||
external object SecretStreamStateAndHeaderType: JsAny {
|
||||
val state: SecretStreamStateType
|
||||
val header: Uint8Array
|
||||
}
|
||||
|
||||
external object CryptoSecretstreamXchacha20poly1305PullResult: JsAny {
|
||||
external object DecryptedDataAndTagType: JsAny {
|
||||
val message: Uint8Array
|
||||
val tag: Byte
|
||||
}
|
||||
|
||||
external object GenericHashStateInternalType: JsAny
|
||||
|
||||
external object Blake2bInternalStateType: JsAny
|
||||
|
@ -3,7 +3,6 @@ package com.ionspin.kotlin.crypto.aead
|
||||
import com.ionspin.kotlin.crypto.getSodium
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
|
||||
import org.khronos.webgl.Uint8Array
|
||||
|
||||
actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
|
||||
@ -131,8 +130,8 @@ actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
key.toUInt8Array(),
|
||||
)
|
||||
return AeadEncryptedDataAndTag(
|
||||
(result.ciphertext as Uint8Array).toUByteArray(),
|
||||
(result.mac as Uint8Array).toUByteArray()
|
||||
result.ciphertext.toUByteArray(),
|
||||
result.mac.toUByteArray()
|
||||
)
|
||||
}
|
||||
|
||||
@ -205,8 +204,8 @@ actual object AuthenticatedEncryptionWithAssociatedData {
|
||||
key.toUInt8Array(),
|
||||
)
|
||||
return AeadEncryptedDataAndTag(
|
||||
(result.ciphertext as Uint8Array).toUByteArray(),
|
||||
(result.mac as Uint8Array).toUByteArray()
|
||||
result.ciphertext.toUByteArray(),
|
||||
result.mac.toUByteArray()
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,106 @@
|
||||
package com.ionspin.kotlin.crypto.ed25519
|
||||
|
||||
import com.ionspin.kotlin.crypto.getSodium
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
|
||||
|
||||
actual object Ed25519LowLevel {
|
||||
actual fun isValidPoint(encoded: UByteArray): Boolean =
|
||||
getSodium().crypto_core_ed25519_is_valid_point(encoded.toUInt8Array())
|
||||
|
||||
actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_add(p.toUInt8Array(), q.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_sub(p.toUInt8Array(), q.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun pointFromUniform(uniform: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_from_uniform(uniform.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun randomPoint(): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_random()
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun randomScalar(): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_random()
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun invertScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_invert(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun negateScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_negate(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun complementScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_complement(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_add(x.toUInt8Array(), y.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_sub(x.toUInt8Array(), y.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_mul(x.toUInt8Array(), y.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun reduceScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_reduce(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_scalarmult_ed25519(n.toUInt8Array(), p.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun scalarMultiplicationNoClamp(n: UByteArray, p: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_scalarmult_ed25519_noclamp(n.toUInt8Array(), p.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun scalarMultiplicationBase(n: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_scalarmult_ed25519_base(n.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun scalarMultiplicationBaseNoClamp(n: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_scalarmult_ed25519_base_noclamp(n.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.ionspin.kotlin.crypto.generichash
|
||||
|
||||
import com.ionspin.kotlin.crypto.getSodium
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.GenericHashStateInternalType
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
|
||||
import org.khronos.webgl.Uint8Array
|
||||
@ -11,14 +12,8 @@ import org.khronos.webgl.Uint8Array
|
||||
* on 21-Aug-2020
|
||||
*/
|
||||
|
||||
// TODO: посмотреть, как оно используется
|
||||
external object GenericHashStateInternalType: JsAny
|
||||
|
||||
//Раз используется как жсЭни, то можно написать = ЖсЭни
|
||||
//actual typealias GenericHashStateInternal = Any
|
||||
actual typealias GenericHashStateInternal = GenericHashStateInternalType
|
||||
|
||||
|
||||
actual object GenericHash {
|
||||
actual fun genericHash(
|
||||
message: UByteArray,
|
||||
@ -37,7 +32,7 @@ actual object GenericHash {
|
||||
key: UByteArray?
|
||||
): GenericHashState {
|
||||
val state = getSodium().crypto_generichash_init(key?.toUInt8Array() ?: Uint8Array(0), requestedHashLength)
|
||||
return GenericHashState(requestedHashLength, state as GenericHashStateInternal)
|
||||
return GenericHashState(requestedHashLength, state)
|
||||
}
|
||||
|
||||
actual fun genericHashUpdate(
|
||||
|
@ -1,19 +1,14 @@
|
||||
package com.ionspin.kotlin.crypto.hash
|
||||
|
||||
import com.ionspin.kotlin.crypto.getSodium
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.Sha256StateType
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.Sha512StateType
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
|
||||
|
||||
// TODO: проверить, что эти штуки юзаются как жсЭни
|
||||
//typealias Sha256State = JsAny
|
||||
//typealias Sha512State = JsAny
|
||||
//actual typealias Sha256State = Any
|
||||
//actual typealias Sha512State = Any
|
||||
|
||||
external object Sha256StateType: JsAny
|
||||
|
||||
actual typealias Sha256State = Sha256StateType
|
||||
actual typealias Sha512State = Sha256StateType
|
||||
actual typealias Sha512State = Sha512StateType
|
||||
|
||||
actual object Hash {
|
||||
|
||||
@ -22,7 +17,7 @@ actual object Hash {
|
||||
}
|
||||
|
||||
actual fun sha256Init(): Sha256State {
|
||||
return getSodium().crypto_hash_sha256_init() as Sha256State
|
||||
return getSodium().crypto_hash_sha256_init()
|
||||
}
|
||||
|
||||
actual fun sha256Update(state: Sha256State, data: UByteArray) {
|
||||
@ -38,7 +33,7 @@ actual object Hash {
|
||||
}
|
||||
|
||||
actual fun sha512Init(): Sha512State {
|
||||
return getSodium().crypto_hash_sha512_init() as Sha512State
|
||||
return getSodium().crypto_hash_sha512_init()
|
||||
}
|
||||
|
||||
actual fun sha512Update(state: Sha512State, data: UByteArray) {
|
||||
|
@ -0,0 +1,94 @@
|
||||
package com.ionspin.kotlin.crypto.ristretto255
|
||||
|
||||
import com.ionspin.kotlin.crypto.getSodium
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
|
||||
|
||||
actual object Ristretto255LowLevel {
|
||||
actual fun isValidPoint(encoded: UByteArray): Boolean =
|
||||
getSodium().crypto_core_ristretto255_is_valid_point(encoded.toUInt8Array())
|
||||
|
||||
actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_add(p.toUInt8Array(), q.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_sub(p.toUInt8Array(), q.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun pointFromHash(hash: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_from_hash(hash.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun randomPoint(): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_random()
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun randomScalar(): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_random()
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun invertScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_invert(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun negateScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_negate(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun complementScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_complement(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_add(x.toUInt8Array(), y.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_sub(x.toUInt8Array(), y.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_mul(x.toUInt8Array(), y.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun reduceScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_reduce(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_scalarmult_ristretto255(n.toUInt8Array(), p.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun scalarMultiplicationBase(n: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_scalarmult_ristretto255_base(n.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ package com.ionspin.kotlin.crypto.secretbox
|
||||
import com.ionspin.kotlin.crypto.getSodium
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
|
||||
import org.khronos.webgl.Uint8Array
|
||||
|
||||
actual object SecretBox {
|
||||
actual fun easy(message: UByteArray, nonce: UByteArray, key: UByteArray): UByteArray {
|
||||
@ -25,7 +24,7 @@ actual object SecretBox {
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array()
|
||||
)
|
||||
return (decryptionResult as Uint8Array).toUByteArray()
|
||||
return decryptionResult.toUByteArray()
|
||||
} catch (error: Throwable) {
|
||||
throw SecretBoxCorruptedOrTamperedDataExceptionOrInvalidKey()
|
||||
}
|
||||
@ -60,7 +59,7 @@ actual object SecretBox {
|
||||
nonce.toUInt8Array(),
|
||||
key.toUInt8Array()
|
||||
)
|
||||
return (decryptionResult as Uint8Array).toUByteArray()
|
||||
return decryptionResult.toUByteArray()
|
||||
} catch (error: Throwable) {
|
||||
throw SecretBoxCorruptedOrTamperedDataExceptionOrInvalidKey()
|
||||
}
|
||||
|
@ -1,20 +1,17 @@
|
||||
package com.ionspin.kotlin.crypto.secretstream
|
||||
|
||||
import com.ionspin.kotlin.crypto.getSodium
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.CryptoSecretstreamXchacha20poly1305PullResult
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.SecretStreamStateType
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
|
||||
import org.khronos.webgl.Uint8Array
|
||||
|
||||
|
||||
external object SecretStreamStateType: JsAny
|
||||
|
||||
actual typealias SecretStreamState = SecretStreamStateType
|
||||
|
||||
actual object SecretStream {
|
||||
actual fun xChaCha20Poly1305InitPush(key: UByteArray): SecretStreamStateAndHeader {
|
||||
val state = getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array())
|
||||
return SecretStreamStateAndHeader(state.state as SecretStreamState, state.header.toUByteArray())
|
||||
return SecretStreamStateAndHeader(state.state, state.header.toUByteArray())
|
||||
}
|
||||
|
||||
actual fun xChaCha20Poly1305Push(
|
||||
@ -33,7 +30,7 @@ actual object SecretStream {
|
||||
header: UByteArray
|
||||
): SecretStreamStateAndHeader {
|
||||
val state = getSodium().crypto_secretstream_xchacha20poly1305_init_pull(header.toUInt8Array(), key.toUInt8Array())
|
||||
return SecretStreamStateAndHeader(state as SecretStreamState, header)
|
||||
return SecretStreamStateAndHeader(state, header)
|
||||
}
|
||||
|
||||
actual fun xChaCha20Poly1305Pull(
|
||||
@ -41,14 +38,14 @@ actual object SecretStream {
|
||||
ciphertext: UByteArray,
|
||||
associatedData: UByteArray
|
||||
): DecryptedDataAndTag {
|
||||
val dataAndTag = getSodium().crypto_secretstream_xchacha20poly1305_pull(
|
||||
state, ciphertext.toUInt8Array(), associatedData.toUInt8Array()
|
||||
)
|
||||
if (dataAndTag as? JsBoolean == false.toJsBoolean()) {
|
||||
try {
|
||||
val dataAndTag = getSodium().crypto_secretstream_xchacha20poly1305_pull(
|
||||
state, ciphertext.toUInt8Array(), associatedData.toUInt8Array()
|
||||
)
|
||||
return DecryptedDataAndTag(dataAndTag.message.toUByteArray(), dataAndTag.tag.toUByte())
|
||||
} catch (error: Throwable) {
|
||||
throw SecretStreamCorruptedOrTamperedDataException()
|
||||
}
|
||||
return DecryptedDataAndTag((dataAndTag as CryptoSecretstreamXchacha20poly1305PullResult).message.toUByteArray(), dataAndTag.tag.toUByte())
|
||||
|
||||
}
|
||||
|
||||
actual fun xChaCha20Poly1305Keygen(): UByteArray {
|
||||
|
@ -1,5 +1,4 @@
|
||||
@file:JsModule("libsodium-sumo")
|
||||
//@file:JsNonModule
|
||||
package ext.libsodium
|
||||
|
||||
import org.khronos.webgl.Uint8Array
|
||||
@ -13,7 +12,7 @@ import kotlin.js.Promise
|
||||
*/
|
||||
|
||||
@JsName("ready")
|
||||
external val _libsodiumPromise : Promise<JsAny>
|
||||
external val _libsodiumPromise : Promise<JsAny?>
|
||||
|
||||
@JsName("_sodium_init")
|
||||
external fun sodium_init() : Int
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.ionspin.kotlin.crypto.util
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
//import kotlinx.coroutines.CoroutineScope
|
||||
|
||||
|
||||
actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) {
|
||||
kotlinx.coroutines.test.runTest {
|
||||
block(this)
|
||||
}
|
||||
}
|
||||
//actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) {
|
||||
// kotlinx.coroutines.test.runTest {
|
||||
// block(this)
|
||||
// }
|
||||
//}
|
||||
|
@ -0,0 +1,4 @@
|
||||
config.resolve.alias = {
|
||||
"crypto": false,
|
||||
// "path": false,
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
|
||||
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
|
||||
import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask
|
||||
|
||||
@ -81,7 +81,6 @@ kotlin {
|
||||
binaries.executable()
|
||||
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalWasmDsl::class)
|
||||
wasmJs {
|
||||
browser {
|
||||
@ -95,24 +94,7 @@ kotlin {
|
||||
}
|
||||
}
|
||||
binaries.executable()
|
||||
// browser {
|
||||
// val rootDirPath = project.rootDir.path
|
||||
// val projectDirPath = project.projectDir.path
|
||||
// commonWebpackConfig {
|
||||
// outputFileName = "composeApp.js"
|
||||
// devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
|
||||
//// static = (static ?: mutableListOf()).apply {
|
||||
//// // Serve sources to debug inside browser
|
||||
//// add(rootDirPath)
|
||||
//// add(projectDirPath)
|
||||
//// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// binaries.executable()
|
||||
}
|
||||
|
||||
|
||||
linuxX64("linux") {
|
||||
binaries {
|
||||
executable {
|
||||
@ -213,6 +195,8 @@ kotlin {
|
||||
dependencies {
|
||||
implementation(kotlin(Deps.Common.test))
|
||||
implementation(kotlin(Deps.Common.testAnnotation))
|
||||
implementation(Deps.Common.coroutinesTest)
|
||||
implementation(kotlin("test"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,24 +221,6 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
val wasmJsMain by getting {
|
||||
dependencies {
|
||||
// implementation(kotlin(Deps.wasmJs.stdLib))
|
||||
implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second))
|
||||
}
|
||||
}
|
||||
val wasmJsTest by getting {
|
||||
dependencies {
|
||||
dependsOn(commonTest)
|
||||
implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second))
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0")
|
||||
|
||||
implementation(kotlin("test"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// val nativeMain by creating {
|
||||
// dependsOn(commonMain)
|
||||
// dependencies {
|
||||
@ -328,7 +294,16 @@ kotlin {
|
||||
implementation(kotlin(Deps.Js.test))
|
||||
}
|
||||
}
|
||||
|
||||
val wasmJsMain by getting {
|
||||
dependencies {
|
||||
implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second))
|
||||
}
|
||||
}
|
||||
val wasmJsTest by getting {
|
||||
dependencies {
|
||||
implementation(npm(Deps.wasmJs.Npm.libsodiumWrappers.first, Deps.wasmJs.Npm.libsodiumWrappers.second))
|
||||
}
|
||||
}
|
||||
val linuxMain by getting {
|
||||
dependsOn(nativeMain)
|
||||
}
|
||||
|
@ -1,12 +1,15 @@
|
||||
|
||||
|
||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer
|
||||
import com.ionspin.kotlin.crypto.getSodium
|
||||
import com.ionspin.kotlin.crypto.hash.Hash
|
||||
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.JsSodiumInterface
|
||||
|
||||
|
||||
fun main() {
|
||||
LibsodiumInitializer.initializeWithCallback {
|
||||
// val hash = Hash.sha512("123".encodeToUByteArray())
|
||||
// println("Hash (SHA512) of 123: ${hash.toHexString()}")
|
||||
println("Hello")
|
||||
}
|
||||
LibsodiumInitializer.initializeWithCallback {
|
||||
val hash = Hash.sha512("123".encodeToUByteArray())
|
||||
println("Hash (SHA512) of 123: ${hash.toHexString()}")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user