diff --git a/lib/bcoin/hd.js b/lib/bcoin/hd.js index 77a88f26..160863c1 100644 --- a/lib/bcoin/hd.js +++ b/lib/bcoin/hd.js @@ -642,6 +642,12 @@ function randomBytes(size) { return Array.prototype.slice.call(crypto.randomBytes(size)); } +function array32(data) { + var b = []; + utils.writeU32BE(b, data, 0); + return b; +} + /** * PDKBF2 * Credit to: https://github.com/stayradiated/pbkdf2-sha512 @@ -681,10 +687,10 @@ function pbkdf2(key, salt, iterations, dkLen) { utils.copy(salt.slice(0, salt.length), block1, 0); for (i = 1; i <= l; i++) { - block1[salt.length + 0] = (i >> 24 & 0xff); - block1[salt.length + 1] = (i >> 16 & 0xff); - block1[salt.length + 2] = (i >> 8 & 0xff); - block1[salt.length + 3] = (i >> 0 & 0xff); + block1[salt.length + 0] = i >> 24 & 0xff; + block1[salt.length + 1] = i >> 16 & 0xff; + block1[salt.length + 2] = i >> 8 & 0xff; + block1[salt.length + 3] = i >> 0 & 0xff; U = sha512hmac(block1, key); @@ -698,19 +704,13 @@ function pbkdf2(key, salt, iterations, dkLen) { } destPos = (i - 1) * hLen; - len = (i === l ? r : hLen); + len = i === l ? r : hLen; utils.copy(T.slice(0, len), DK, 0); } return DK; } -function array32(data) { - var b = []; - utils.writeU32BE(b, data, 0); - return b; -} - /** * Expose */ diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index fd01f76d..6081b888 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -86,10 +86,6 @@ function Wallet(options, passphrase) { this.tx = new bcoin.txPool(this); - // Just a constants, actually - this.fee = 10000; - this.dust = 5460; - this._init(); } @@ -352,6 +348,7 @@ Wallet.addr2hash = function addr2hash(addr, prefix) { return []; chk = utils.checksum(addr.slice(0, -4)); + if (utils.readU32(chk, 0) !== utils.readU32(addr, 21)) return [];