Browse Source

remove multiple concats with one, more efficient, concat

patch-2
Ryan X. Charles 11 years ago
parent
commit
d52e8ac8ed
  1. 75
      lib/BIP32.js

75
lib/BIP32.js

@ -136,28 +136,20 @@ BIP32.prototype.buildExtendedPublicKey = function() {
}
// Version
this.extendedPublicKey = Buffer.concat([this.extendedPublicKey, new Buffer([v >> 24])]);
this.extendedPublicKey = Buffer.concat([this.extendedPublicKey, new Buffer([(v >> 16) & 0xff])]);
this.extendedPublicKey = Buffer.concat([this.extendedPublicKey, new Buffer([(v >> 8) & 0xff])]);
this.extendedPublicKey = Buffer.concat([this.extendedPublicKey, new Buffer([v & 0xff])]);
// Depth
this.extendedPublicKey = Buffer.concat([this.extendedPublicKey, new Buffer([this.depth])]);
// Parent fingerprint
this.extendedPublicKey = Buffer.concat([this.extendedPublicKey, this.parentFingerprint]);
// Child index
this.extendedPublicKey = Buffer.concat([this.extendedPublicKey, new Buffer([this.childIndex >>> 24])]);
this.extendedPublicKey = Buffer.concat([this.extendedPublicKey, new Buffer([(this.childIndex >>> 16) & 0xff])]);
this.extendedPublicKey = Buffer.concat([this.extendedPublicKey, new Buffer([(this.childIndex >>> 8) & 0xff])]);
this.extendedPublicKey = Buffer.concat([this.extendedPublicKey, new Buffer([this.childIndex & 0xff])]);
// Chain code
this.extendedPublicKey = Buffer.concat([this.extendedPublicKey, this.chainCode]);
// Public key
this.extendedPublicKey = Buffer.concat([this.extendedPublicKey, this.eckey.public]);
this.extendedPublicKey = Buffer.concat([
new Buffer([v >> 24]),
new Buffer([(v >> 16) & 0xff]),
new Buffer([(v >> 8) & 0xff]),
new Buffer([v & 0xff]),
new Buffer([this.depth]),
this.parentFingerprint,
new Buffer([this.childIndex >>> 24]),
new Buffer([(this.childIndex >>> 16) & 0xff]),
new Buffer([(this.childIndex >>> 8) & 0xff]),
new Buffer([this.childIndex & 0xff]),
this.chainCode,
this.eckey.public
]);
}
BIP32.prototype.extendedPublicKeyString = function(format) {
@ -179,30 +171,21 @@ BIP32.prototype.buildExtendedPrivateKey = function() {
var v = this.version;
// Version
this.extendedPrivateKey = Buffer.concat([this.extendedPrivateKey, new Buffer([v >> 24])]);
this.extendedPrivateKey = Buffer.concat([this.extendedPrivateKey, new Buffer([(v >> 16) & 0xff])]);
this.extendedPrivateKey = Buffer.concat([this.extendedPrivateKey, new Buffer([(v >> 8) & 0xff])]);
this.extendedPrivateKey = Buffer.concat([this.extendedPrivateKey, new Buffer([v & 0xff])]);
// Depth
this.extendedPrivateKey = Buffer.concat([this.extendedPrivateKey, new Buffer([this.depth])]);
// Parent fingerprint
this.extendedPrivateKey = Buffer.concat([this.extendedPrivateKey, this.parentFingerprint]);
// Child index
this.extendedPrivateKey = Buffer.concat([this.extendedPrivateKey, new Buffer([this.childIndex >>> 24])]);
this.extendedPrivateKey = Buffer.concat([this.extendedPrivateKey, new Buffer([(this.childIndex >>> 16) & 0xff])]);
this.extendedPrivateKey = Buffer.concat([this.extendedPrivateKey, new Buffer([(this.childIndex >>> 8) & 0xff])]);
this.extendedPrivateKey = Buffer.concat([this.extendedPrivateKey, new Buffer([this.childIndex & 0xff])]);
// Chain code
this.extendedPrivateKey = Buffer.concat([this.extendedPrivateKey, this.chainCode]);
// Private key
this.extendedPrivateKey = Buffer.concat([this.extendedPrivateKey, new Buffer([0])]);
this.extendedPrivateKey = Buffer.concat([this.extendedPrivateKey, this.eckey.private]);
this.extendedPrivateKey = Buffer.concat([
new Buffer([v >> 24]),
new Buffer([(v >> 16) & 0xff]),
new Buffer([(v >> 8) & 0xff]),
new Buffer([v & 0xff]),
new Buffer([this.depth]),
this.parentFingerprint,
new Buffer([this.childIndex >>> 24]),
new Buffer([(this.childIndex >>> 16) & 0xff]),
new Buffer([(this.childIndex >>> 8) & 0xff]),
new Buffer([this.childIndex & 0xff]),
this.chainCode,
new Buffer([0]),
this.eckey.private
]);
}
BIP32.prototype.extendedPrivateKeyString = function(format) {

Loading…
Cancel
Save