diff --git a/build.gradle b/build.gradle index 08e529dc..add2bf64 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ buildscript { ext { // App version - versionName = '2.1.3' + versionName = '2.1.4' versionCode = 1 // SDK and tools diff --git a/substrate-sdk-android/src/main/java/io/novasama/substrate_sdk_android/encrypt/mnemonic/MnemonicCreator.kt b/substrate-sdk-android/src/main/java/io/novasama/substrate_sdk_android/encrypt/mnemonic/MnemonicCreator.kt index fa6a60ff..cd29c1c3 100644 --- a/substrate-sdk-android/src/main/java/io/novasama/substrate_sdk_android/encrypt/mnemonic/MnemonicCreator.kt +++ b/substrate-sdk-android/src/main/java/io/novasama/substrate_sdk_android/encrypt/mnemonic/MnemonicCreator.kt @@ -7,7 +7,6 @@ import io.novasama.substrate_sdk_android.exceptions.Bip39Exception import java.security.SecureRandom import java.text.Normalizer import java.text.Normalizer.normalize -import java.util.Arrays import kotlin.math.floor private val DELIMITER_REGEX = "[\\s,]+".toRegex() @@ -21,11 +20,15 @@ object MnemonicCreator { SecureRandom().nextBytes(entropy) MnemonicGenerator(EnglishWordList.INSTANCE) .createMnemonic(entropy, secure::append) - Arrays.fill(entropy, 0.toByte()) val words = secure.toStringAble().toString() + val normalizedWords = normalizeWords(words) - fromWords(words) + Mnemonic( + words = normalizedWords, + wordList = toWordList(normalizedWords), + entropy = entropy + ) } fun fromWords(words: String): Mnemonic { @@ -61,11 +64,10 @@ object MnemonicCreator { } private fun generateWords(entropy: ByteArray): String { - SecureCharBuffer().use { secure -> + return SecureCharBuffer().use { secure -> MnemonicGenerator(EnglishWordList.INSTANCE) .createMnemonic(entropy, secure::append) - Arrays.fill(entropy, 0.toByte()) - return secure.toStringAble().toString() + secure.toStringAble().toString() } } diff --git a/substrate-sdk-android/src/test/java/io/novasama/substrate_sdk_android/encrypt/mnemonic/MnemonicCreatorTest.kt b/substrate-sdk-android/src/test/java/io/novasama/substrate_sdk_android/encrypt/mnemonic/MnemonicCreatorTest.kt index db0f57f5..b4cda969 100644 --- a/substrate-sdk-android/src/test/java/io/novasama/substrate_sdk_android/encrypt/mnemonic/MnemonicCreatorTest.kt +++ b/substrate-sdk-android/src/test/java/io/novasama/substrate_sdk_android/encrypt/mnemonic/MnemonicCreatorTest.kt @@ -14,6 +14,7 @@ class MnemonicCreatorTest { fun `should generate mnemonic of different length`() { val mnemonic = MnemonicCreator.randomMnemonic(Mnemonic.Length.TWELVE) assertEquals(12, mnemonic.wordList.size) + assertFalse(mnemonic.entropy.all { it.toInt() == 0 }) val mnemonic2 = MnemonicCreator.randomMnemonic(Mnemonic.Length.TWENTY_ONE) assertEquals(21, mnemonic2.wordList.size) @@ -29,6 +30,7 @@ class MnemonicCreatorTest { val mnemonic = MnemonicCreator.fromEntropy(expectedEntropyHex.fromHex()) assertEquals(expectedMnemonicWords, mnemonic.words) + assertArrayEquals(expectedEntropyHex.fromHex(), mnemonic.entropy) } @Test