function _tapTreeToList(tree, leaves = [], depth = 0) {
  if (depth > MAX_TAPTREE_DEPTH) throw new Error('Max taptree depth exceeded.');
  if (!tree) return [];
  if (isTapleaf(tree)) {
    leaves.push({
      depth,
      leafVersion: tree.version || LEAF_VERSION_TAPSCRIPT,
      script: tree.output,
    });
    return leaves;
  }
  if (tree[0]) _tapTreeToList(tree[0], leaves, depth + 1);
  if (tree[1]) _tapTreeToList(tree[1], leaves, depth + 1);
  return leaves;
}
Converts a binary tree to a BIP371 type list.
@param tree The binary tap tree.
@param leaves A list of tapleaves. Optional.
@param depth The current depth. Optional.
@returns A list of BIP 371 tapleaves.
@throws Throws an error if the taptree cannot be converted to a tapleaf list.