Signature bugs

There are a number of bugs causing raw.sign on a wally wallet to have errors. raw.sign still does not work for me on a wally wallet (it does not sign the transaction), but at least it runs without errors with these bug fixes.