more hd optimization.

This commit is contained in:
Christopher Jeffrey 2016-02-23 19:35:47 -08:00
parent ebee3965f7
commit 3804c2ea74

View File

@ -662,14 +662,17 @@ HDPrivateKey.prototype._unbuild = function _unbuild(xkey) {
else else
this.network = 'testnet'; this.network = 'testnet';
this.xprivkey = xkey;
return data; return data;
}; };
HDPrivateKey.prototype._build = function _build(data) { HDPrivateKey.prototype._build = function _build(data) {
var sequence = new Buffer(82);
var off = 0; var off = 0;
var checksum; var sequence, checksum;
if (!this.xprivkey) {
sequence = new Buffer(82);
off += utils.copy(data.version, sequence, off); off += utils.copy(data.version, sequence, off);
off += utils.copy(data.depth, sequence, off); off += utils.copy(data.depth, sequence, off);
off += utils.copy(data.parentFingerPrint, sequence, off); off += utils.copy(data.parentFingerPrint, sequence, off);
@ -682,6 +685,9 @@ HDPrivateKey.prototype._build = function _build(data) {
off += utils.copy(checksum, sequence, off); off += utils.copy(checksum, sequence, off);
assert(off === 82, off); assert(off === 82, off);
this.xprivkey = utils.toBase58(sequence);
}
this.version = data.version; this.version = data.version;
this.depth = data.depth; this.depth = data.depth;
this.parentFingerPrint = data.parentFingerPrint; this.parentFingerPrint = data.parentFingerPrint;
@ -694,7 +700,6 @@ HDPrivateKey.prototype._build = function _build(data) {
this.fingerPrint = null; this.fingerPrint = null;
this.hdPrivateKey = this; this.hdPrivateKey = this;
this.xprivkey = utils.toBase58(sequence);
this.hdPublicKey = new HDPublicKey({ this.hdPublicKey = new HDPublicKey({
network: this.network, network: this.network,
@ -1026,14 +1031,17 @@ HDPublicKey.prototype._unbuild = function _unbuild(xkey) {
else else
this.network = 'testnet'; this.network = 'testnet';
this.xpubkey = xkey;
return data; return data;
}; };
HDPublicKey.prototype._build = function _build(data) { HDPublicKey.prototype._build = function _build(data) {
var sequence = new Buffer(82);
var off = 0; var off = 0;
var checksum; var sequence, checksum;
if (!this.xpubkey) {
sequence = new Buffer(82);
off += utils.copy(data.version, sequence, off); off += utils.copy(data.version, sequence, off);
off += utils.copy(data.depth, sequence, off); off += utils.copy(data.depth, sequence, off);
off += utils.copy(data.parentFingerPrint, sequence, off); off += utils.copy(data.parentFingerPrint, sequence, off);
@ -1050,6 +1058,9 @@ HDPublicKey.prototype._build = function _build(data) {
else if (utils.toHex(checksum) !== utils.toHex(data.checksum)) else if (utils.toHex(checksum) !== utils.toHex(data.checksum))
throw new Error('checksum mismatch'); throw new Error('checksum mismatch');
this.xpubkey = utils.toBase58(sequence);
}
this.version = data.version; this.version = data.version;
this.depth = data.depth; this.depth = data.depth;
this.parentFingerPrint = data.parentFingerPrint; this.parentFingerPrint = data.parentFingerPrint;
@ -1062,7 +1073,6 @@ HDPublicKey.prototype._build = function _build(data) {
this.fingerPrint = null; this.fingerPrint = null;
this.hdPublicKey = this; this.hdPublicKey = this;
this.xpubkey = utils.toBase58(sequence);
this.hdPrivateKey = null; this.hdPrivateKey = null;
this.xprivkey = null; this.xprivkey = null;