Skip to content

Commit

Permalink
Replaced Convert.bytesToBin by new Buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sem committed Oct 26, 2014
1 parent 048017e commit e96728b
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions stealth.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,11 @@ var Buffer = require('buffer').Buffer;

var bufToArray = function(obj) {return Array.prototype.slice.call(obj, 0);};

var lpad = function(str, padString, length) {
while (str.length < length) str = padString + str;
return str;
};

var Convert = {
numToBytes: function(num, bytes) {
if (bytes === undefined) bytes = 8
if (bytes === 0) return []
return [num % 256].concat(Convert.numToBytes(Math.floor(num / 256), bytes - 1))
},
bytesToBin: function(bytes) {
if (Buffer.isBuffer(bytes)) bytes = bufToArray(bytes);
return bytes.map(function(x) {
return lpad(x.toString(2), '0', 8)
}).join('');
}
};

Expand Down Expand Up @@ -380,7 +369,7 @@ Stealth.addStealth = function(recipient, newTx, addressVersion, nonceVersion, ep
var nonceBytes = Convert.numToBytes(nonce, 4);

// Hash the nonce
outHash = bufToArray(Bitcoin.crypto.hash160(Convert.bytesToBin(nonceBytes.concat(ephemKey))));
outHash = bufToArray(Bitcoin.crypto.hash160(new Buffer(nonceBytes.concat(ephemKey))));
} while(iters < maxNonce && !Stealth.checkPrefix(outHash, stealthPrefix));

} while(!Stealth.checkPrefix(outHash, stealthPrefix));
Expand Down

0 comments on commit e96728b

Please sign in to comment.