function witnessStackToScriptWitness(witness) {
  let buffer = new Uint8Array(0);
  function writeSlice(slice) {
    buffer = tools.concat([buffer, slice]);
  }
  function writeVarInt(i) {
    const currentLen = buffer.length;
    const varintLen = varuint.encodingLength(i);
    buffer = tools.concat([buffer, new Uint8Array(varintLen)]);
    varuint.encode(i, buffer, currentLen);
  }
  function writeVarSlice(slice) {
    writeVarInt(slice.length);
    writeSlice(slice);
  }
  function writeVector(vector) {
    writeVarInt(vector.length);
    vector.forEach(writeVarSlice);
  }
  writeVector(witness);
  return buffer;
}
Converts a witness stack to a script witness.
@param witness The witness stack to convert.
@returns The script witness as a Buffer.