cryptocoinjs / base-x

Encode/decode any base
MIT License
312 stars 75 forks source link

Differences in decoded buffer size with the same data length? #79

Closed dartess closed 2 years ago

dartess commented 2 years ago

Hey! I noticed strange behavior. Does it match the plan or not?

https://codesandbox.io/s/bold-burnell-i3uil?file=/src/index.js

In one of the cases, the number of characters in the buffer is greater than the required one by 1. The data itself is correct, but at the beginning there is a parasitic zero.

junderw commented 2 years ago

This is as expected, your alphabet starts with A, so A is "the zero value" (ie. numbers would start with 0 "0123456789").

Any time the first letter of a given base-x parameter characters string is at the beginning of the encoded string, an extra 0x00 byte is added to the beginning.

This is how the spec works.