<commit_before>package org.kethereum.bip39

import org.kethereum.bip32.ExtendedKey
import org.kethereum.bip32.generateKey
import org.kethereum.extensions.toBitArray
import org.kethereum.extensions.toByteArray
import org.kethereum.hashes.sha256
import java.security.SecureRandom
import java.util.*
import javax.crypto.SecretKeyFactory
import javax.crypto.spec.PBEKeySpec

object Mnemonic {

    /**
     * Generates a seed buffer from a mnemonic phrase according to the BIP39 spec.
     * The mnemonic phrase is given as a list of words and the seed can be salted using a password
     */
    fun mnemonicToSeed(phrase: String, password: String = ""): ByteArray {
        return mnemonicToSeed(phrase.split(" ").toTypedArray(), password)
    }

    /**
     * Generates a seed buffer from a mnemonic phrase according to the BIP39 spec.
     * The mnemonic phrase is given as a list of words and the seed can be salted using a password
     */
    fun mnemonicToSeed(words: Array<String>, password: String = ""): ByteArray {
        val pass = words.joinToString(" ")
        val salt = "mn<PASSWORD>" + password

        val keyFactory = SecretKeyFactory.getInstance("PBKDF2withHmacSHA512")
        val spec = PBEKeySpec(pass.toCharArray(), salt.toByteArray(), 2048, 512)
        return keyFactory.generateSecret(spec).encoded
    }

    /**
     * Converts a phrase (list of words) into a [ByteArray] entropy buffer according to the BIP39 spec
     */
    fun mnemonicToEntropy(phrase: String): ByteArray {
        return mnemonicToEntropy(phrase.split(" ").toTypedArray())
    }<commit_msg>add `BouncyCastleProvider()` on `Mnemonic` init ( this fixes #20 )<commit_after>package org.kethereum.bip39

import org.kethereum.bip32.ExtendedKey
import org.kethereum.bip32.generateKey
import org.kethereum.extensions.toBitArray
import org.kethereum.extensions.toByteArray
import org.kethereum.hashes.sha256
import org.spongycastle.jce.provider.BouncyCastleProvider
import java.security.SecureRandom
import java.security.Security
import java.util.*
import javax.crypto.SecretKeyFactory
import javax.crypto.spec.PBEKeySpec

object Mnemonic {

    init {
        Security.insertProviderAt(BouncyCastleProvider(), 1)
    }

    /**
     * Generates a seed buffer from a mnemonic phrase according to the BIP39 spec.
     * The mnemonic phrase is given as a list of words and the seed can be salted using a password
     */
    fun mnemonicToSeed(phrase: String, password: String = ""): ByteArray {
        return mnemonicToSeed(phrase.split(" ").toTypedArray(), password)
    }

    /**
     * Generates a seed buffer from a mnemonic phrase according to the BIP39 spec.
     * The mnemonic phrase is given as a list of words and the seed can be salted using a password
     */
    fun mnemonicToSeed(words: Array<String>, password: String = ""): ByteArray {
        val pass = words.joinToString(" ")
        val salt = "<PASSWORD>" + password

        val keyFactory = SecretKeyFactory.getInstance("PBKDF2withHmacSHA512")
        val spec = PBEKeySpec(pass.toCharArray(), salt.toByteArray(), 2048, 512)
        return keyFactory.generateSecret(spec).encoded
    }

    /**
     * Converts a phrase (list of words) into a [ByteArray] entropy buffer according to the BIP39 spec
     */
    fun mnemonicToEntropy(phrase: String): ByteArray {
        return mnemonicToEntropy(phrase.split(" ").toTypedArray())
    }
{'fraction_non_alphanumeric': 0.09029411764705883, 'fraction_numerical': 0.016176470588235296, 'mean_word_length': 3.5528781793842037, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6196687', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1011, 'n_words': 301}