code: public AggregationHashChain build(TreeNode leaf) throws KSIException {
          Util.notNull(leaf, "TreeNode");
          if (!leaf.isLeaf() || leaf.isRoot() || leaf instanceof MetadataNode) {
              throw new IllegalArgumentException("Aggregation hash chain can be built only from leaf nodes");
          }
  
          LinkedList<AggregationChainLink> links = new LinkedList<>();
          long levelCorrection = 0L;
          TreeNode node;
          if (leaf.getParent().getRightChildNode() instanceof MetadataNode) {
              links.add(createMetadataChainLink((MetadataNode) leaf.getParent().getRightChildNode(), leaf.getLevel()));
              node = leaf.getParent();
          } else {
              node = leaf;
              levelCorrection = node.getLevel();
          }
          createChainLinks(links, levelCorrection, node);
          LinkedList<Long> chainIndex = new LinkedList<>(singletonList(calculateIndex(links)));
          HashAlgorithm aggregationAlgorithm = new DataHash(leaf.getParent().getValue()).getAlgorithm();
          return SIGNATURE_COMPONENT_FACTORY.createAggregationHashChain(
                  new DataHash(leaf.getValue()), new Date(), chainIndex, links, aggregationAlgorithm);
      }
docs: Builds the {@link AggregationHashChain} instance.
  
  @param leaf leaf node from which to build the hash chain.
  @return Instance of {@link AggregationHashChain}.
  @throws KSIException in case any error occurs.