templateScript

You need to provide the template script to the signature generator (it is part of the sighash calculation), so this must be set before you can sign