hd refactor.

This commit is contained in:
Christopher Jeffrey 2016-06-18 22:10:07 -07:00
parent a1e31f02ae
commit 3a99b23cb3
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -595,22 +595,11 @@ HDPrivateKey.prototype.derive = function derive(index, hardened) {
*/
HDPrivateKey.prototype.deriveAccount44 = function deriveAccount44(accountIndex) {
var coinType;
assert(utils.isNumber(accountIndex), 'Account index must be a number.');
if (this instanceof HDPublicKey) {
assert(this.isAccount44(accountIndex), 'Cannot derive account index.');
return this;
}
assert(this.isMaster(), 'Cannot derive account index.');
coinType = this.network === 'main' ? 0 : 1;
return this
.derive(44, true)
.derive(coinType, true)
.derive(this.network === 'main' ? 0 : 1, true)
.derive(accountIndex, true);
};
@ -620,13 +609,7 @@ HDPrivateKey.prototype.deriveAccount44 = function deriveAccount44(accountIndex)
*/
HDPrivateKey.prototype.derivePurpose45 = function derivePurpose45() {
if (this instanceof HDPublicKey) {
assert(this.isPurpose45(), 'Cannot derive purpose 45.');
return this;
}
assert(this.isMaster(), 'Cannot derive purpose 45.');
return this.derive(45, true);
};
@ -1246,7 +1229,10 @@ HDPublicKey.prototype.derive = function derive(index, hardened) {
* @throws Error if key is not already an account key.
*/
HDPublicKey.prototype.deriveAccount44 = HDPrivateKey.prototype.deriveAccount44;
HDPublicKey.prototype.deriveAccount44 = function deriveAccount44(accountIndex) {
assert(this.isAccount44(accountIndex), 'Cannot derive account index.');
return this;
};
/**
* Derive a BIP45 purpose key (does not derive, only ensures account key).
@ -1255,7 +1241,10 @@ HDPublicKey.prototype.deriveAccount44 = HDPrivateKey.prototype.deriveAccount44;
* @throws Error if key is not already a purpose key.
*/
HDPublicKey.prototype.derivePurpose45 = HDPrivateKey.prototype.derivePurpose45;
HDPublicKey.prototype.derivePurpose45 = function derivePurpose45() {
assert(this.isPurpose45(), 'Cannot derive purpose 45.');
return this;
};
/**
* Test whether the key is a master key.