self.toSeed = function(mnemonic, passphrase) {
passphrase = passphrase || '';
- mnemonic = normalizeString(mnemonic)
- passphrase = normalizeString(passphrase)
+ mnemonic = self.normalizeString(mnemonic)
+ passphrase = self.normalizeString(passphrase)
passphrase = "mnemonic" + passphrase;
//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);
}
- function normalizeString(str) {
+ self.normalizeString = function(str) {
if (typeof str.normalize == "function") {
return str.normalize("NFKD");
}
function calcBip32Seed(phrase, passphrase, path) {
var seed = mnemonic.toSeed(phrase, passphrase);
- var seedHash = Bitcoin.crypto.sha256(seed).toString("hex");
- bip32RootKey = Bitcoin.HDNode.fromSeedHex(seedHash, network);
+ bip32RootKey = Bitcoin.HDNode.fromSeedHex(seed, network);
bip32ExtendedKey = bip32RootKey;
// Derive the key from the path
var pathBits = path.split("/");
function findPhraseErrors(phrase) {
// TODO make this right
// Preprocess the words
+ phrase = mnemonic.normalizeString(phrase);
var parts = phrase.split(" ");
var proper = [];
for (var i=0; i<parts.length; i++) {
var index = i+ start;
var key = bip32ExtendedKey.derive(index);
var address = key.getAddress().toString();
- var privkey = key.privKey.toWIF();
+ var privkey = key.privKey.toWIF(network);
addAddressToList(index, address, privkey);
}
}