Commit 8e353229 authored by Ivan Jose Lozano Fernandez's avatar Ivan Jose Lozano Fernandez Committed by Daniel Connolly

The Hashtype Verification is taken apart in a separate function, since there...

The Hashtype Verification is taken apart in a separate function, since there is an specific error that needs to be captured and processed separately.
parent 9cf8d1df
......@@ -89,6 +89,18 @@ public class TransactionSignature extends ECKey.ECDSASignature {
return sighashFlags;
}
/**
* Checkes if the Hashtype is properly set in the signature.
* @param signature Signature
* @return True (correct Hashtype)/ False
*/
public static boolean isValidHashType(byte[] signature) {
boolean result = true;
int hashType = (signature[signature.length-1] & 0xff) & ~(Transaction.SigHash.ANYONECANPAY.value| SigHash.FORKID.value); // mask the byte to prevent sign-extension hurting us
if (hashType < Transaction.SigHash.ALL.value || hashType > Transaction.SigHash.SINGLE.value)
result = false;
return result;
}
/**
* Returns true if the given signature is has canonical encoding, and will thus be accepted as standard by
* Bitcoin Core. DER and the SIGHASH encoding allow for quite some flexibility in how the same structures
......@@ -103,11 +115,8 @@ public class TransactionSignature extends ECKey.ECDSASignature {
// Where R and S are not negative (their first byte has its highest bit not set), and not
// excessively padded (do not start with a 0 byte, unless an otherwise negative number follows,
// in which case a single 0 byte is necessary and even required).
if (signature.length < 9 || signature.length > 73)
return false;
int hashType = (signature[signature.length-1] & 0xff) & ~(Transaction.SigHash.ANYONECANPAY.value| SigHash.FORKID.value); // mask the byte to prevent sign-extension hurting us
if (hashType < Transaction.SigHash.ALL.value || hashType > Transaction.SigHash.SINGLE.value)
if (signature.length < 9 || signature.length > 73)
return false;
// "wrong type" "wrong length marker"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment