Skip to content

Fix base58 encoding losing leading zero bytes#48

Open
sumanjeet0012 wants to merge 1 commit into
multiformats:masterfrom
sumanjeet0012:fix-issue-35-leading-zeros
Open

Fix base58 encoding losing leading zero bytes#48
sumanjeet0012 wants to merge 1 commit into
multiformats:masterfrom
sumanjeet0012:fix-issue-35-leading-zeros

Conversation

@sumanjeet0012

Copy link
Copy Markdown

Fixes #35

This PR fixes the issue where BaseStringConverter silently drops leading \x00 bytes during encoding and decoding for integer-based encodings (like base58btc). It now properly counts and preserves them by utilizing the encoding alphabet's zero character.

Changes made:

  • Modified BaseStringConverter.encode() and decode() to manually handle leading zero bytes.
  • Updated Base16StringConverter.decode() to use bytes.fromhex() directly to bypass the zero-counting logic, as base16 operates byte-by-byte.
  • Added comprehensive tests for base58btc, base58flickr, base32z, base36, base10, base8, and base2 with leading zero byte strings to ensure correct round-tripping.

All 287 tests pass successfully.

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.

Base58 encoding loses leading zero bytes

1 participant