<commit_before>var Crypto = require('crypto-js')
var path = require('path')
var includeFolder = require('include-folder')
var Wordlists = includeFolder(path.join(__dirname, 'wordlists'))

module.exports = BIP39

function BIP39(language){
  language = language || 'en'
  this.wordlist = JSON.parse(Wordlists[language])
}

BIP39.prototype.mnemonicToSeed = function(mnemonic, password){
  var options = {iterations: 2048, hasher: Crypto.algo.SHA512, keySize: 512/32}
  return Crypto.PBKDF2(mnemonic, salt(password), options).toString(Crypto.enc.Hex)
}

BIP39.prototype.entropyToMnemonic = function(entropy){
  var entropyBytes = hexToBytes(entropy)
  var bits = bytesToBinary(entropyBytes)

  var hash = Crypto.SHA256(bytesToWordArray(entropyBytes))
  var checksumBits = bytesToBinary(wordsToBytes(hash.words))
  var checksum = checksumBits.substr(0, bits.length / 32)

  var chunks = (bits + checksum).match(/(.{1,11})/g)
  return chunks.map(function(binary){
    var index = parseInt(binary, 2)
    return this.wordlist[index]
  }, this).join(' ')
}

function salt(password) {<commit_msg>add generateMnemonic<commit_after>var Crypto = require('crypto-js')
var path = require('path')
var includeFolder = require('include-folder')
var Wordlists = includeFolder(path.join(__dirname, 'wordlists'))

module.exports = BIP39

function BIP39(language){
  language = language || 'en'
  this.wordlist = JSON.parse(Wordlists[language])
}

BIP39.prototype.mnemonicToSeed = function(mnemonic, password){
  var options = {iterations: 2048, hasher: Crypto.algo.SHA512, keySize: 512/32}
  return Crypto.PBKDF2(mnemonic, salt(password), options).toString(Crypto.enc.Hex)
}

BIP39.prototype.entropyToMnemonic = function(entropy){
  var entropyBytes = hexToBytes(entropy)
  var bits = bytesToBinary(entropyBytes)

  var hash = Crypto.SHA256(bytesToWordArray(entropyBytes))
  var checksumBits = bytesToBinary(wordsToBytes(hash.words))
  var checksum = checksumBits.substr(0, bits.length / 32)

  var chunks = (bits + checksum).match(/(.{1,11})/g)
  return chunks.map(function(binary){
    var index = parseInt(binary, 2)
    return this.wordlist[index]
  }, this).join(' ')
}

BIP39.prototype.generateMnemonic = function(strength){
  var strength = strength || 128
  var entropy = crypto.randomBytes(strength/8).toString('hex')
  return this.entropyToMnemonic(entropy)
}

function salt(password) {
{'fraction_non_alphanumeric': 0.13425925925925927, 'fraction_numerical': 0.02861952861952862, 'mean_word_length': 5.621169916434541, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4760753', 'n_tokens_mistral': 846, 'n_tokens_neox': 794, 'n_words': 154}