function canFinalizeLeaf(leaf, tapScriptSig, hash) {
  const leafHash = tapleafHash({
    output: leaf.script,
    version: leaf.leafVersion,
  });
  const whiteListedHash = !hash || tools.compare(leafHash, hash) === 0;
  return (
    whiteListedHash &&
    tapScriptSig.find(tss => tools.compare(tss.leafHash, leafHash) === 0) !==
      undefined
  );
}
Determines whether a TapLeafScript can be finalized.

@param leaf - The TapLeafScript to check.
@param tapScriptSig - The array of TapScriptSig objects.
@param hash - The optional hash to compare with the leaf hash.
@returns A boolean indicating whether the TapLeafScript can be finalized.