Signing a transaction

Moved question into new post, as others may benefit from answer as well

Signing.sign requires

@param {Transaction} transaction
@param {PrivateKey} privateKey
@param {number} sighash
@param {number} inputIndex
@param {Script} subscript

  1. In a previous post I was told that subscript is the scriptPubKey of UTXO being spent, when the library code shows this script being inserted into the scriptSig of (a copy of) the transaction being spent:

Line 46 sighash.js: txcopy.inputs[inputNumber] = new Input(txcopy.inputs[inputNumber]).setScript(subscript);

  1. Whether it is in fact the scriptPubKey, or scriptSig of the input for which the signature is being computed,
    why would it need to be provided to compute a signature? Signatures depend on neither?