|
@ -5,7 +5,6 @@ var Key = imports.Key || require('./Key'); |
|
|
var Point = imports.Point || require('./Point'); |
|
|
var Point = imports.Point || require('./Point'); |
|
|
var SecureRandom = imports.SecureRandom || require('./SecureRandom'); |
|
|
var SecureRandom = imports.SecureRandom || require('./SecureRandom'); |
|
|
var bignum = imports.bignum || require('bignum'); |
|
|
var bignum = imports.bignum || require('bignum'); |
|
|
var crypto = require('crypto'); |
|
|
|
|
|
var networks = require('../networks'); |
|
|
var networks = require('../networks'); |
|
|
|
|
|
|
|
|
var secp256k1_n = new bignum('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141', 16); |
|
|
var secp256k1_n = new bignum('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141', 16); |
|
@ -56,41 +55,6 @@ var HierarchicalKey = function(bytes) { |
|
|
this.initFromBytes(bytes); |
|
|
this.initFromBytes(bytes); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
HierarchicalKey.mnemonic = function(wordlist, bits) { |
|
|
|
|
|
if (!bits) |
|
|
|
|
|
bits = 128; |
|
|
|
|
|
if (bits % 32 != 0) |
|
|
|
|
|
throw new Error("bits must be multiple of 32"); |
|
|
|
|
|
var bytes = crypto.randomBytes(bits / 8); |
|
|
|
|
|
return BIP32.to_mnemonic(wordlist, bytes); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
HierarchicalKey.to_mnemonic = function(wordlist, bytes) { |
|
|
|
|
|
var hash = coinUtil.sha256(new Buffer(bytes)); |
|
|
|
|
|
var bin = ""; |
|
|
|
|
|
var bits = bytes.length * 8; |
|
|
|
|
|
for (var i = 0 ; i < bytes.length ; i++) { |
|
|
|
|
|
bin = bin + ("00000000" + bytes[i].toString(2)).slice(-8); |
|
|
|
|
|
} |
|
|
|
|
|
var hashbits = hash[0].toString(2); |
|
|
|
|
|
hashbits = ("00000000" + hashbits).slice(-8).slice(0, bits/32); |
|
|
|
|
|
bin = bin + hashbits; |
|
|
|
|
|
if (bin.length % 11 != 0) |
|
|
|
|
|
throw new Error("interal error - entropy not an even multiple of 11 bits - " + bin.length); |
|
|
|
|
|
var mnemonic = ""; |
|
|
|
|
|
for (var i = 0 ; i < bin.length / 11 ; i++) { |
|
|
|
|
|
if (mnemonic != "") |
|
|
|
|
|
mnemonic = mnemonic + " "; |
|
|
|
|
|
var wi = parseInt(bin.slice(i*11, (i+1)*11), 2); |
|
|
|
|
|
mnemonic = mnemonic + wordlist[wi]; |
|
|
|
|
|
} |
|
|
|
|
|
return mnemonic; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
HierarchicalKey.mnemonic_to_seed = function(mnemonic, passphrase) { |
|
|
|
|
|
return cryptox.pbkdf2Sync_sha512(mnemonic, "mnemonic" + passphrase, 2048, 64); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
HierarchicalKey.seed = function(bytes, network) { |
|
|
HierarchicalKey.seed = function(bytes, network) { |
|
|
if (!network) |
|
|
if (!network) |
|
|
network = 'livenet'; |
|
|
network = 'livenet'; |
|
|