hd refactor.
This commit is contained in:
parent
a1e31f02ae
commit
3a99b23cb3
@ -595,22 +595,11 @@ HDPrivateKey.prototype.derive = function derive(index, hardened) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
HDPrivateKey.prototype.deriveAccount44 = function deriveAccount44(accountIndex) {
|
HDPrivateKey.prototype.deriveAccount44 = function deriveAccount44(accountIndex) {
|
||||||
var coinType;
|
|
||||||
|
|
||||||
assert(utils.isNumber(accountIndex), 'Account index must be a number.');
|
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.');
|
assert(this.isMaster(), 'Cannot derive account index.');
|
||||||
|
|
||||||
coinType = this.network === 'main' ? 0 : 1;
|
|
||||||
|
|
||||||
return this
|
return this
|
||||||
.derive(44, true)
|
.derive(44, true)
|
||||||
.derive(coinType, true)
|
.derive(this.network === 'main' ? 0 : 1, true)
|
||||||
.derive(accountIndex, true);
|
.derive(accountIndex, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -620,13 +609,7 @@ HDPrivateKey.prototype.deriveAccount44 = function deriveAccount44(accountIndex)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
HDPrivateKey.prototype.derivePurpose45 = function derivePurpose45() {
|
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.');
|
assert(this.isMaster(), 'Cannot derive purpose 45.');
|
||||||
|
|
||||||
return this.derive(45, true);
|
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.
|
* @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).
|
* 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.
|
* @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.
|
* Test whether the key is a master key.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user