2019-12-14 18:38:16 -08:00
|
|
|
package cash.z.ecc.kotlin.mnemonic
|
|
|
|
|
2020-02-12 04:59:47 -08:00
|
|
|
import cash.z.android.plugin.MnemonicPlugin
|
2020-06-10 04:49:38 -07:00
|
|
|
import cash.z.ecc.android.bip39.Mnemonics
|
2020-06-04 10:50:43 -07:00
|
|
|
import cash.z.ecc.android.bip39.Mnemonics.MnemonicCode
|
|
|
|
import cash.z.ecc.android.bip39.Mnemonics.WordCount
|
|
|
|
import cash.z.ecc.android.bip39.toEntropy
|
|
|
|
import cash.z.ecc.android.bip39.toSeed
|
|
|
|
import java.util.*
|
2020-06-10 04:49:38 -07:00
|
|
|
import java.util.Locale.ENGLISH
|
2019-12-17 13:20:23 -08:00
|
|
|
import javax.inject.Inject
|
|
|
|
|
2020-06-10 04:49:38 -07:00
|
|
|
class Mnemonics @Inject constructor() : MnemonicPlugin {
|
|
|
|
override fun fullWordList(languageCode: String) = Mnemonics.getCachedWords(Locale.ENGLISH.language)
|
|
|
|
override fun nextEntropy(): ByteArray = WordCount.COUNT_24.toEntropy()
|
|
|
|
override fun nextMnemonic(): CharArray = MnemonicCode(WordCount.COUNT_24).chars
|
|
|
|
override fun nextMnemonic(entropy: ByteArray): CharArray = MnemonicCode(entropy).chars
|
|
|
|
override fun nextMnemonicList(): List<CharArray> = MnemonicCode(WordCount.COUNT_24).words
|
|
|
|
override fun nextMnemonicList(entropy: ByteArray): List<CharArray> = MnemonicCode(entropy).words
|
|
|
|
override fun toSeed(mnemonic: CharArray): ByteArray = MnemonicCode(mnemonic).toSeed()
|
|
|
|
override fun toWordList(mnemonic: CharArray): List<CharArray> = MnemonicCode(mnemonic).words
|
2020-06-10 05:26:21 -07:00
|
|
|
|
|
|
|
fun validate(mnemonic: CharArray) {
|
|
|
|
MnemonicCode(mnemonic).validate()
|
|
|
|
}
|
2019-12-14 18:38:16 -08:00
|
|
|
}
|