lib/tree.js
function MerkleTree(leaves, hasher) {
  if (!(this instanceof MerkleTree)) {
    return new MerkleTree(leaves, hasher);
  }

  this._hasher = hasher || this._hasher;
  this._leaves = [];
  this._depth = 0;
  this._rows = [];
  this._count = 0;

  assert(Array.isArray(leaves), 'Invalid leaves array supplied');
  assert(typeof this._hasher === 'function', 'Invalid hash function supplied');

  for (var i = 0; i < leaves.length; i++) {
    this._feed(leaves[i]);
  }

  this._compute();
}
function MerkleTree(leaves, hasher) {
  if (!(this instanceof MerkleTree)) {
    return new MerkleTree(leaves, hasher);
  }

  this._hasher = hasher || this._hasher;
  this._leaves = [];
  this._depth = 0;
  this._rows = [];
  this._count = 0;

  assert(Array.isArray(leaves), 'Invalid leaves array supplied');
  assert(typeof this._hasher === 'function', 'Invalid hash function supplied');

  for (var i = 0; i < leaves.length; i++) {
    this._feed(leaves[i]);
  }

  this._compute();
}
function MerkleTree ( leaves , hasher ) { if ( ! ( this instanceof MerkleTree ) ) { return new MerkleTree ( leaves , hasher ) ; } this . _hasher = hasher || this . _hasher ; this . _leaves = [ ] ; this . _depth = 0 ; this . _rows = [ ] ; this . _count = 0 ; assert ( Array . isArray ( leaves ) , 'Invalid leaves array supplied' ) ; assert ( typeof this . _hasher === 'function' , 'Invalid hash function supplied' ) ; for ( var i = 0 ; i < leaves . length ; i ++ ) { this . _feed ( leaves [ i ] ) ; } this . _compute ( ) ; }
Implements a merkle hash tree
@constructor
@param {Array} leaves - Initial tree input
@param {Function} hasher - Hash function for building tree
Implements a merkle hash tree