- //return PBKDF2(mnemonic, 'mnemonic' + passphrase, iterations=PBKDF2_ROUNDS, macmodule=hmac, digestmodule=hashlib.sha512).read(64)
- return asmCrypto.PBKDF2_HMAC_SHA512.hex(mnemonic, passphrase, PBKDF2_ROUNDS, 512/8);
+ var mnemonicBits = sjcl.codec.utf8String.toBits(mnemonicNormalized);
+ var passphraseBits = sjcl.codec.utf8String.toBits(passphrase);
+ var result = sjcl.misc.pbkdf2(mnemonicBits, passphraseBits, PBKDF2_ROUNDS, 512, hmacSHA512);
+ var hashHex = sjcl.codec.hex.fromBits(result);
+ return hashHex;
+ }
+
+ self.splitWords = function(mnemonic) {
+ return mnemonic.split(/\s/g).filter(function(x) { return x.length; });
+ }
+
+ self.joinWords = function(words) {
+ // Set space correctly depending on the language
+ // see https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md#japanese
+ var space = " ";
+ if (language == "japanese") {
+ space = "\u3000"; // ideographic space
+ }
+ return words.join(space);