Ensure that generated signatures are semantically correct

Part of #748
Merge pull request #766 from dungpa/signature-validation

Ensure that generated signatures are semantically correct