diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 7a901a88..025adeeb 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -449,9 +449,8 @@ Chain.prototype.locatorHashes = function(index) { hashes.push(chain[0]); break; } - if (hashes.length >= 10) { + if (hashes.length >= 10) step *= 2; - } } return hashes; @@ -467,9 +466,8 @@ Chain.prototype.getOrphanRoot = function getOrphanRoot(hash) { var orphans = this.orphan.bmap; var orphanRoot = hash; - while (orphans[orphanRoot.prevBlock]) { + while (orphans[orphanRoot.prevBlock]) orphanRoot = orphans[orphanRoot.prevBlock]; - } return orphanRoot; }; diff --git a/lib/bcoin/hd.js b/lib/bcoin/hd.js index 996e518e..6bd63298 100644 --- a/lib/bcoin/hd.js +++ b/lib/bcoin/hd.js @@ -186,7 +186,7 @@ HDPriv.prototype._normalize = function(data, version) { if (data.privateKey.getPrivate) data.privateKey = data.privateKey.getPrivate().toArray(); else if (typeof data.privateKey === 'string') - data.privateKey = utils.toArray(data.privateKey, 'hex'); + data.privateKey = utils.toKeyArray(data.privateKey); } data.publicKey = data.publicKey || data.pub; @@ -194,7 +194,7 @@ HDPriv.prototype._normalize = function(data, version) { if (data.publicKey.getPublic) data.publicKey = data.privateKey.getPublic(true, 'array'); else if (typeof data.publicKey === 'string') - data.publicKey = utils.toArray(data.publicKey, 'hex'); + data.publicKey = utils.toKeyArray(data.publicKey); } if (typeof data.checksum === 'number') { @@ -210,7 +210,7 @@ HDPriv.prototype._seed = function(seed) { if (seed instanceof HDSeed) seed = seed.seed; - if (typeof seed === 'string' && /^[0-9a-f]+$/i.test(seed)) + if (utils.isHex(seed)) seed = utils.toArray(seed, 'hex'); if (seed.length < MIN_ENTROPY || seed.length > MAX_ENTROPY) @@ -316,11 +316,9 @@ HDPriv.prototype.derive = function(index, hard) { var index_ = []; utils.writeU32BE(index_, index, 0); - var data; - if (hard) - data = [0].concat(this.privateKey).concat(index_); - else - data = [].concat(this.publicKey).concat(index_); + var data = hard + ? [0].concat(this.privateKey).concat(index_) + : data = [].concat(this.publicKey).concat(index_); var hash = sha512hmac(data, this.chainCode); var leftPart = new bn(hash.slice(0, 32)); diff --git a/lib/bcoin/peer.js b/lib/bcoin/peer.js index 8b8212c8..b06b8c22 100644 --- a/lib/bcoin/peer.js +++ b/lib/bcoin/peer.js @@ -466,9 +466,8 @@ Peer.prototype._handleHeaders = function handleHeaders(headers) { this.loadHeaders(this.chain.locatorHashes(), this.chain.getOrphanRoot(hash)); continue; } - if (!this.chain.index.bloom.test(hash, 'hex') || i === headers.length - 1) { + if (!this.chain.index.bloom.test(hash, 'hex') || i === headers.length - 1) this.getData([{ type: 'block', hash: hash }]); - } } } diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index 8e012156..6dfd9a33 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -131,21 +131,17 @@ Wallet.prototype.multisig = function multisig(options) { }); // Use p2sh multisig by default - if (!options.addressType && this.sharedKeys.length) { + if (!options.addressType && this.sharedKeys.length) this.addressType = 'p2sh'; - } - if (this.m < 1 || this.m > this.n) { + if (this.m < 1 || this.m > this.n) throw new Error('m ranges between 1 and n'); - } - if (this.n < 1 || this.n > 7) { + if (this.n < 1 || this.n > 7) throw new Error('n ranges between 1 and 7'); - } - if (this.sharedKeys.length < this.m - 1) { + if (this.sharedKeys.length < this.m - 1) throw new Error(this.m + ' public keys required'); - } }; Wallet.prototype.derive = function derive() {