From a07805c8cc655f64bfd6975974873c0c23a1576a Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Mon, 29 Apr 2024 17:08:20 -0700 Subject: [PATCH] Remove Cryptography multiplatform library - Added extension functions to convert BigInteger to hex string, and viceversa. - Updated Android Gradle Plugin to the latest version. - Updated AndroidX Activity Compose to the latest stable version. --- gradle/libs.versions.toml | 8 +++----- library/crypto/build.gradle.kts | 2 -- .../kotlin/net/agorise/shared/crypto/BigIntegerKtx.kt | 11 +++++++++++ library/stargate/build.gradle.kts | 1 - .../agorise/shared/stargate/mnemonics/Mnemonics.kt | 7 +++---- .../shared/stargate/mnemonics/MnemonicsTest.kt | 2 +- 6 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 library/crypto/src/main/kotlin/net/agorise/shared/crypto/BigIntegerKtx.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4810a32..b7a27b5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,13 +1,12 @@ [versions] -agp = "8.2.0" +agp = "8.2.2" android-compileSdk = "34" android-minSdk = "26" android-targetSdk = "34" -androidx-activityCompose = "1.8.2" -composeCompiler = "1.5.12" +androidx-activityCompose = "1.9.0" composeBom = "2024.04.01" +composeCompiler = "1.5.12" coroutines = "1.8.0" -cryptography = "0.3.0" kotlin = "1.9.23" ktor = "2.3.9" multiplatform-settings = "1.1.1" @@ -25,7 +24,6 @@ compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-mani compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" } coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" } -cryptography-bigint = { group = "dev.whyoleg.cryptography", name = "cryptography-bigint", version.ref = "cryptography" } kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" } ktor-client-cio = { group = "io.ktor", name = "ktor-client-cio", version.ref = "ktor" } ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor" } diff --git a/library/crypto/build.gradle.kts b/library/crypto/build.gradle.kts index e199814..a0e08fe 100644 --- a/library/crypto/build.gradle.kts +++ b/library/crypto/build.gradle.kts @@ -3,7 +3,5 @@ plugins { } dependencies { - implementation(libs.cryptography.bigint) - testImplementation(libs.kotlin.test) } diff --git a/library/crypto/src/main/kotlin/net/agorise/shared/crypto/BigIntegerKtx.kt b/library/crypto/src/main/kotlin/net/agorise/shared/crypto/BigIntegerKtx.kt new file mode 100644 index 0000000..6d1de13 --- /dev/null +++ b/library/crypto/src/main/kotlin/net/agorise/shared/crypto/BigIntegerKtx.kt @@ -0,0 +1,11 @@ +package net.agorise.shared.crypto + +import java.math.BigInteger + +@OptIn(ExperimentalStdlibApi::class) +fun BigInteger.toHexString(format: HexFormat = HexFormat.Default): String = + toByteArray().toHexString(format) + +@OptIn(ExperimentalStdlibApi::class) +fun String.hexToBigInteger(format: HexFormat = HexFormat.Default): BigInteger = + BigInteger(hexToByteArray(format)) diff --git a/library/stargate/build.gradle.kts b/library/stargate/build.gradle.kts index 103b826..c3576b9 100644 --- a/library/stargate/build.gradle.kts +++ b/library/stargate/build.gradle.kts @@ -6,7 +6,6 @@ dependencies { implementation(projects.library.crypto) implementation(libs.coroutines.core) - implementation(libs.cryptography.bigint) implementation(libs.ktor.client.cio) implementation(libs.ktor.client.core) implementation(libs.ktor.client.websockets) diff --git a/library/stargate/src/main/kotlin/net/agorise/shared/stargate/mnemonics/Mnemonics.kt b/library/stargate/src/main/kotlin/net/agorise/shared/stargate/mnemonics/Mnemonics.kt index 4ed891c..20f16ea 100644 --- a/library/stargate/src/main/kotlin/net/agorise/shared/stargate/mnemonics/Mnemonics.kt +++ b/library/stargate/src/main/kotlin/net/agorise/shared/stargate/mnemonics/Mnemonics.kt @@ -1,9 +1,8 @@ package net.agorise.shared.stargate.mnemonics -import dev.whyoleg.cryptography.bigint.BigInt -import dev.whyoleg.cryptography.bigint.decodeToBigInt import io.ktor.utils.io.core.toByteArray import net.agorise.shared.crypto.Crc32 +import java.math.BigInteger /** * Provides functionality to create and validate mnemonics. @@ -40,7 +39,7 @@ class Mnemonics { /** * Given a list of words, returns the associated key if the words are valid or an exception otherwise */ - fun getKeyAndLanguageFromWords(words: List): Result> { + fun getKeyAndLanguageFromWords(words: List): Result> { // The list must contain SEED_LENGTH + 1 words. The SEED_LENGTH + 1 word is the checksum if (words.size != (SEED_LENGTH + 1)) { return Result.failure(Exception("Invalid seed")) @@ -79,7 +78,7 @@ class Mnemonics { val languageName = languages[languageIndex].name - return Result.success(Pair(key.decodeToBigInt(), languageName)) + return Result.success(Pair(BigInteger(key), languageName)) } /** diff --git a/library/stargate/src/test/kotlin/net/agorise/shared/stargate/mnemonics/MnemonicsTest.kt b/library/stargate/src/test/kotlin/net/agorise/shared/stargate/mnemonics/MnemonicsTest.kt index 0670c0c..a65f105 100644 --- a/library/stargate/src/test/kotlin/net/agorise/shared/stargate/mnemonics/MnemonicsTest.kt +++ b/library/stargate/src/test/kotlin/net/agorise/shared/stargate/mnemonics/MnemonicsTest.kt @@ -1,10 +1,10 @@ package net.agorise.shared.stargate.mnemonics -import dev.whyoleg.cryptography.bigint.toHexString import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue +import net.agorise.shared.crypto.toHexString class MnemonicsTest { private val mnemonics = Mnemonics()