formatting. make use of helpers in hd.
This commit is contained in:
parent
8a33f2efa1
commit
89f2a0dcc3
@ -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;
|
||||
};
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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 }]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user