Skip to content

Conversation

@dcousens
Copy link
Contributor

@dcousens dcousens commented Apr 22, 2016

@fanatid not the cleanest, but, it removes all the extra allocations :)

@dcousens
Copy link
Contributor Author

This is now 1:1 with decode, however, were you wanting to support encode 000001 giving back 01?

@fanatid
Copy link
Member

fanatid commented Apr 22, 2016

I see what you wanted, but yes, I wanted that encode give 01 for 000001

@fanatid
Copy link
Member

fanatid commented Apr 22, 2016

because this I used for-loop

@dcousens
Copy link
Contributor Author

@fanatid but we don't do that for decode.
So it would be inconsistent.

Also, you didn't add a test for that 😃

@fanatid
Copy link
Member

fanatid commented Apr 22, 2016

sorry, my fault with tests... (I only removed and fixed existed)
initially I wanted add leading zeros for expanding to 32-bytes in decode, but bip66 not checked that r/s longer than 32 bytes...

@fanatid
Copy link
Member

fanatid commented Apr 22, 2016

after decode we can't come back to 000001 from 01 because we don't knew how much zeros we should put

@dcousens
Copy link
Contributor Author

dcousens commented Apr 22, 2016

@fanatid in short, you wanted encode to trim all unnecessary padding? IMHO that is definitely out of scope, this change brings it back to a simple/sane implementation.
Especially since extraneous leading zeros are BIP66 compliant.

You could easily modify your buffer pre-encode to be trimmed with a 1-liner.
Eg count zeros then slice.

@fanatid
Copy link
Member

fanatid commented Apr 22, 2016

but should developer which uses bitcoinjs/bip66 think about padding? I'd like pass just buffer and don't think about leading zeros..
it is hard draw a line what should do encode/decode unlike check

@dcousens
Copy link
Contributor Author

dcousens commented Apr 22, 2016

@fanatid true, but developers that use this won't be feeding it signatures that have extraneous zeros unless they are making those themselves, in which case, I'd expect them to know what they're doing.

The change would also block a developer from being able to use bip66 to encode a extraneously padded signature... even if that seems pointless.

@fanatid fanatid merged commit 588e059 into master Apr 22, 2016
@fanatid
Copy link
Member

fanatid commented Apr 22, 2016

agreed, thanks

@fanatid fanatid deleted the cleanup branch April 22, 2016 09:29
fanatid added a commit that referenced this pull request Apr 25, 2016
dcousens added a commit that referenced this pull request Apr 26, 2016
Revert #2 and #4, update encode/tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants