import { Hash , Hashable } from '@uniqys/signature' ; export namespace MerkleTree { export function root < T extends Hashable > ( items ) { if ( items . length === 0 ) { return Hash . fromData ( Buffer . alloc ( 0 ) ) ; } if ( items . length === 1 ) { return items [ 0 ] . hash ; } const split = splitPoint ( items . length ) ; return Hash . fromData ( Buffer . concat ( [ root ( items . slice ( 0 , split ) ) . buffer , root ( items . slice ( split ) ) . buffer ] ) ) ; } function splitPoint ( x ) { let i = 1 ; while ( i < x ) { i <<= 1 ; } return i >> 1 ; } }