|
@ -52,6 +52,8 @@ function HDPrivateKey(arg) { |
|
|
this._buildFromSerialized(arg); |
|
|
this._buildFromSerialized(arg); |
|
|
} else if (JSUtil.isValidJSON(arg)) { |
|
|
} else if (JSUtil.isValidJSON(arg)) { |
|
|
this._buildFromJSON(arg); |
|
|
this._buildFromJSON(arg); |
|
|
|
|
|
} else if (BufferUtil.isBuffer(arg) && HDPrivateKey.isValidSerialized(arg.toString())) { |
|
|
|
|
|
this._buildFromSerialized(arg.toString()); |
|
|
} else { |
|
|
} else { |
|
|
throw HDPrivateKey.getSerializedError(arg); |
|
|
throw HDPrivateKey.getSerializedError(arg); |
|
|
} |
|
|
} |
|
@ -377,12 +379,8 @@ HDPrivateKey.prototype._buildFromBuffers = function(arg) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var xprivkey; |
|
|
var xprivkey; |
|
|
|
|
|
xprivkey = Base58Check.encode(buffer.Buffer.concat(sequence)); |
|
|
if (!arg.xprivkey) { |
|
|
arg.xprivkey = new Buffer(xprivkey); |
|
|
xprivkey = Base58Check.encode(buffer.Buffer.concat(sequence)); |
|
|
|
|
|
} else { |
|
|
|
|
|
xprivkey = arg.xprivkey; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var privateKey = new PrivateKey(BN.fromBuffer(arg.privateKey)); |
|
|
var privateKey = new PrivateKey(BN.fromBuffer(arg.privateKey)); |
|
|
var publicKey = privateKey.toPublicKey(); |
|
|
var publicKey = privateKey.toPublicKey(); |
|
@ -480,10 +478,34 @@ HDPrivateKey.prototype.toObject = function toObject() { |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Returns a JSON representation of the HDPrivateKey |
|
|
|
|
|
* |
|
|
|
|
|
* @return {string} |
|
|
|
|
|
*/ |
|
|
HDPrivateKey.prototype.toJSON = function toJSON() { |
|
|
HDPrivateKey.prototype.toJSON = function toJSON() { |
|
|
return JSON.stringify(this.toObject()); |
|
|
return JSON.stringify(this.toObject()); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Build a HDPrivateKey from a buffer |
|
|
|
|
|
* |
|
|
|
|
|
* @param {Buffer} arg |
|
|
|
|
|
* @return {HDPrivateKey} |
|
|
|
|
|
*/ |
|
|
|
|
|
HDPrivateKey.fromBuffer = function(arg) { |
|
|
|
|
|
return new HDPrivateKey(arg.toString()); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Returns a buffer representation of the HDPrivateKey |
|
|
|
|
|
* |
|
|
|
|
|
* @return {string} |
|
|
|
|
|
*/ |
|
|
|
|
|
HDPrivateKey.prototype.toBuffer = function() { |
|
|
|
|
|
return BufferUtil.copy(this._buffers.xprivkey); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
HDPrivateKey.DefaultDepth = 0; |
|
|
HDPrivateKey.DefaultDepth = 0; |
|
|
HDPrivateKey.DefaultFingerprint = 0; |
|
|
HDPrivateKey.DefaultFingerprint = 0; |
|
|
HDPrivateKey.DefaultChildIndex = 0; |
|
|
HDPrivateKey.DefaultChildIndex = 0; |
|
|