function tapScriptFinalizer(inputIndex, input, tapLeafHashToFinalize) {
  const tapLeaf = findTapLeafToFinalize(
    input,
    inputIndex,
    tapLeafHashToFinalize,
  );
  try {
    const sigs = sortSignatures(input, tapLeaf);
    const witness = sigs.concat(tapLeaf.script).concat(tapLeaf.controlBlock);
    return { finalScriptWitness: witnessStackToScriptWitness(witness) };
  } catch (err) {
    throw new Error(`Can not finalize taproot input #${inputIndex}: ${err}`);
  }
}
Default tapscript finalizer. It searches for the `tapLeafHashToFinalize` if provided.
Otherwise it will search for the tapleaf that has at least one signature and has the shortest path.
@param inputIndex the position of the PSBT input.
@param input the PSBT input.
@param tapLeafHashToFinalize optional, if provided the finalizer will search for a tapleaf that has this hash
                             and will try to build the finalScriptWitness.
@returns the finalScriptWitness or throws an exception if no tapleaf found.