fix signature code and add reference client sighash tests