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]);
|
hashes.push(chain[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (hashes.length >= 10) {
|
if (hashes.length >= 10)
|
||||||
step *= 2;
|
step *= 2;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hashes;
|
return hashes;
|
||||||
@ -467,9 +466,8 @@ Chain.prototype.getOrphanRoot = function getOrphanRoot(hash) {
|
|||||||
var orphans = this.orphan.bmap;
|
var orphans = this.orphan.bmap;
|
||||||
|
|
||||||
var orphanRoot = hash;
|
var orphanRoot = hash;
|
||||||
while (orphans[orphanRoot.prevBlock]) {
|
while (orphans[orphanRoot.prevBlock])
|
||||||
orphanRoot = orphans[orphanRoot.prevBlock];
|
orphanRoot = orphans[orphanRoot.prevBlock];
|
||||||
}
|
|
||||||
|
|
||||||
return orphanRoot;
|
return orphanRoot;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -186,7 +186,7 @@ HDPriv.prototype._normalize = function(data, version) {
|
|||||||
if (data.privateKey.getPrivate)
|
if (data.privateKey.getPrivate)
|
||||||
data.privateKey = data.privateKey.getPrivate().toArray();
|
data.privateKey = data.privateKey.getPrivate().toArray();
|
||||||
else if (typeof data.privateKey === 'string')
|
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;
|
data.publicKey = data.publicKey || data.pub;
|
||||||
@ -194,7 +194,7 @@ HDPriv.prototype._normalize = function(data, version) {
|
|||||||
if (data.publicKey.getPublic)
|
if (data.publicKey.getPublic)
|
||||||
data.publicKey = data.privateKey.getPublic(true, 'array');
|
data.publicKey = data.privateKey.getPublic(true, 'array');
|
||||||
else if (typeof data.publicKey === 'string')
|
else if (typeof data.publicKey === 'string')
|
||||||
data.publicKey = utils.toArray(data.publicKey, 'hex');
|
data.publicKey = utils.toKeyArray(data.publicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof data.checksum === 'number') {
|
if (typeof data.checksum === 'number') {
|
||||||
@ -210,7 +210,7 @@ HDPriv.prototype._seed = function(seed) {
|
|||||||
if (seed instanceof HDSeed)
|
if (seed instanceof HDSeed)
|
||||||
seed = seed.seed;
|
seed = seed.seed;
|
||||||
|
|
||||||
if (typeof seed === 'string' && /^[0-9a-f]+$/i.test(seed))
|
if (utils.isHex(seed))
|
||||||
seed = utils.toArray(seed, 'hex');
|
seed = utils.toArray(seed, 'hex');
|
||||||
|
|
||||||
if (seed.length < MIN_ENTROPY || seed.length > MAX_ENTROPY)
|
if (seed.length < MIN_ENTROPY || seed.length > MAX_ENTROPY)
|
||||||
@ -316,11 +316,9 @@ HDPriv.prototype.derive = function(index, hard) {
|
|||||||
var index_ = [];
|
var index_ = [];
|
||||||
utils.writeU32BE(index_, index, 0);
|
utils.writeU32BE(index_, index, 0);
|
||||||
|
|
||||||
var data;
|
var data = hard
|
||||||
if (hard)
|
? [0].concat(this.privateKey).concat(index_)
|
||||||
data = [0].concat(this.privateKey).concat(index_);
|
: data = [].concat(this.publicKey).concat(index_);
|
||||||
else
|
|
||||||
data = [].concat(this.publicKey).concat(index_);
|
|
||||||
|
|
||||||
var hash = sha512hmac(data, this.chainCode);
|
var hash = sha512hmac(data, this.chainCode);
|
||||||
var leftPart = new bn(hash.slice(0, 32));
|
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));
|
this.loadHeaders(this.chain.locatorHashes(), this.chain.getOrphanRoot(hash));
|
||||||
continue;
|
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 }]);
|
this.getData([{ type: 'block', hash: hash }]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -131,21 +131,17 @@ Wallet.prototype.multisig = function multisig(options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Use p2sh multisig by default
|
// Use p2sh multisig by default
|
||||||
if (!options.addressType && this.sharedKeys.length) {
|
if (!options.addressType && this.sharedKeys.length)
|
||||||
this.addressType = 'p2sh';
|
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');
|
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');
|
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');
|
throw new Error(this.m + ' public keys required');
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.derive = function derive() {
|
Wallet.prototype.derive = function derive() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user