Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix signature hasDefinedHashtype #1284

Merged
merged 1 commit into from
Jul 1, 2015
Merged

fix signature hasDefinedHashtype #1284

merged 1 commit into from
Jul 1, 2015

Conversation

mruddy
Copy link
Contributor

@mruddy mruddy commented Jun 30, 2015

lib/crypto/signature.hasDefinedHashtype was not very closely matching Bitcoin Core's IsDefinedHashtypeSignature: https://github.com/bitcoin/bitcoin/blob/bc60b2b4b401f0adff5b8b9678903ff8feb5867b/src/script/interpreter.cpp#L180-189

This PR narrows that gap.

The purpose of the isNumber check is to protect against instances that simply have not had an nhashtype set (yet).

The previous version of this method was not considering Signature.SIGHASH_ANYONECANPAY at all. That was the obvious thing to fix.

@braydonf
Copy link
Contributor

LGTM

@mruddy
Copy link
Contributor Author

mruddy commented Jul 1, 2015

I just updated to also check with JSUtil.isNaturalNumber.

The reason is that I added another test case, nhashtype being set to the floating point 1.1, and that was passing. I figured it'd be better to have that case fail/return false because that might help library clients fail faster and narrow down a bug to an incorrectly set nhashtype.

I also saw that #1266 mentions the main hasDefinedHashtype bug fixed by this PR.

braydonf pushed a commit that referenced this pull request Jul 1, 2015
@braydonf braydonf merged commit e99ccb8 into bitpay:master Jul 1, 2015
@mruddy mruddy deleted the fix/signature_has_defined_hashtype branch July 1, 2015 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants