|
|
@ -41,24 +41,24 @@ function HDPrivateKey(arg) { |
|
|
|
if (!(this instanceof HDPrivateKey)) { |
|
|
|
return new HDPrivateKey(arg); |
|
|
|
} |
|
|
|
if (arg) { |
|
|
|
if (_.isString(arg) || BufferUtil.isBuffer(arg)) { |
|
|
|
if (HDPrivateKey.isValidSerialized(arg)) { |
|
|
|
this._buildFromSerialized(arg); |
|
|
|
} else if (JSUtil.isValidJSON(arg)) { |
|
|
|
this._buildFromJSON(arg); |
|
|
|
} else { |
|
|
|
throw HDPrivateKey.getSerializedError(arg); |
|
|
|
} |
|
|
|
if (!arg) { |
|
|
|
return this._generateRandomly(); |
|
|
|
} |
|
|
|
|
|
|
|
if (Network.get(arg)) { |
|
|
|
return this._generateRandomly(arg); |
|
|
|
} else if (_.isString(arg) || BufferUtil.isBuffer(arg)) { |
|
|
|
if (HDPrivateKey.isValidSerialized(arg)) { |
|
|
|
this._buildFromSerialized(arg); |
|
|
|
} else if (JSUtil.isValidJSON(arg)) { |
|
|
|
this._buildFromJSON(arg); |
|
|
|
} else { |
|
|
|
if (_.isObject(arg)) { |
|
|
|
this._buildFromObject(arg); |
|
|
|
} else { |
|
|
|
throw new hdErrors.UnrecognizedArgument(arg); |
|
|
|
} |
|
|
|
throw HDPrivateKey.getSerializedError(arg); |
|
|
|
} |
|
|
|
} else if (_.isObject(arg)) { |
|
|
|
this._buildFromObject(arg); |
|
|
|
} else { |
|
|
|
return this._generateRandomly(); |
|
|
|
throw new hdErrors.UnrecognizedArgument(arg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -266,7 +266,6 @@ HDPrivateKey.prototype._generateRandomly = function(network) { |
|
|
|
*/ |
|
|
|
HDPrivateKey.fromSeed = function(hexa, network) { |
|
|
|
/* jshint maxcomplexity: 8 */ |
|
|
|
|
|
|
|
if (JSUtil.isHexaString(hexa)) { |
|
|
|
hexa = BufferUtil.hexToBuffer(hexa); |
|
|
|
} |
|
|
@ -282,7 +281,7 @@ HDPrivateKey.fromSeed = function(hexa, network) { |
|
|
|
var hash = Hash.sha512hmac(hexa, new buffer.Buffer('Bitcoin seed')); |
|
|
|
|
|
|
|
return new HDPrivateKey({ |
|
|
|
network: Network.get(network) || Network.livenet, |
|
|
|
network: Network.get(network) || Network.defaultNetwork, |
|
|
|
depth: 0, |
|
|
|
parentFingerPrint: 0, |
|
|
|
childIndex: 0, |
|
|
@ -441,7 +440,6 @@ HDPrivateKey.prototype.toJSON = function toJSON() { |
|
|
|
HDPrivateKey.DefaultDepth = 0; |
|
|
|
HDPrivateKey.DefaultFingerprint = 0; |
|
|
|
HDPrivateKey.DefaultChildIndex = 0; |
|
|
|
HDPrivateKey.DefaultNetwork = Network.livenet; |
|
|
|
HDPrivateKey.Hardened = 0x80000000; |
|
|
|
HDPrivateKey.RootElementAlias = ['m', 'M', 'm\'', 'M\'']; |
|
|
|
|
|
|
|