getHashTree method

List<Uint8List> getHashTree()

Implementation

List<Uint8List> getHashTree() {
  if (lookupEncoded.isEmpty) {
    return [Uint8List(32)..fillRange(0, 32, 0)];
  }

  final treeSize = lookupEncoded.length * 2 - 1;
  final hashTree = List<Uint8List>.filled(treeSize, Uint8List(0));

  final leavesStartIdx = lookupEncoded.length - 1;
  for (var i = 0; i < lookupEncoded.length; i++) {
    hashTree[leavesStartIdx + i] = blake3Hash(lookupEncoded[i]);
  }

  for (var i = hashTree.length - 2; i > 0; i -= 2) {
    hashTree[(i - 1) ~/ 2] = blake3Hash(mergeUint8([hashTree[i], hashTree[i + 1]]));
  }

  return hashTree;
}