Skip to content

Conversation

@acul71
Copy link
Contributor

@acul71 acul71 commented Dec 1, 2025

Summary

This PR implements all missing features identified in the gap analysis to bring py-multibase to 100% compatibility with reference implementations (go-multibase, rust-multibase, js-multiformats).

Changes

New Encodings (10 total)

  • ✅ base16upper (prefix F) - Uppercase hexadecimal encoding
  • ✅ base32upper (prefix B) - Uppercase base32 encoding
  • ✅ base32pad (prefix c) - Base32 with RFC 4648 padding
  • ✅ base32padupper (prefix C) - Base32 uppercase with padding
  • ✅ base32hexupper (prefix V) - Base32hex uppercase variant
  • ✅ base32hexpad (prefix t) - Base32hex with RFC 4648 padding
  • ✅ base32hexpadupper (prefix T) - Base32hex uppercase with padding
  • ✅ base64pad (prefix M) - Base64 with RFC 4648 padding
  • ✅ base64urlpad (prefix U) - Base64url with padding
  • ✅ base256emoji (prefix 🚀) - Emoji-based encoding

API Enhancements

  • ✅ Reusable Encoder and Decoder classes
  • decode(return_encoding=True) parameter to return encoding type
  • ✅ Structured exception classes: UnsupportedEncodingError, InvalidMultibaseStringError, DecodingError
  • ✅ Encoding metadata functions: get_encoding_info(), list_encodings(), is_encoding_supported()
  • ✅ Decoder composition support via Decoder.or_() method

Testing

  • ✅ All 265 tests passing
  • ✅ Added comprehensive tests for all new encodings
  • ✅ Added tests for all new API features
  • ✅ Fixed and uncommented existing padding tests

Documentation

  • ✅ Updated README.rst with all new encodings and API examples
  • ✅ Created towncrier news fragment

Results

  • Encoding coverage: 14/24 (58%) → 24/24 (100%)
  • Full compatibility with reference implementations
  • All linting checks pass
  • All tests pass

Closes #20

- Add 10 missing encodings: base16upper, base32upper, base32pad, base32padupper,
  base32hexupper, base32hexpad, base32hexpadupper, base64pad, base64urlpad, base256emoji
- Implement RFC 4648 padding support for base32 and base64 variants
- Add structured exception classes (UnsupportedEncodingError, InvalidMultibaseStringError, DecodingError)
- Add Encoder and Decoder classes for reusable encoding/decoding
- Add decode(return_encoding=True) to return encoding type
- Add encoding metadata functions (get_encoding_info, list_encodings, is_encoding_supported)
- Add decoder composition support via Decoder.or_() method
- Update tests for all new encodings and API features
- Update documentation and create news fragment

Closes #20
Achieves 100% encoding coverage (24/24 encodings)
@acul71 acul71 force-pushed the feat/new-features branch from 2cb4656 to 02ac83c Compare December 1, 2025 03:02
…prove docs, add test

- Simplify redundant padding logic in BaseByteStringConverter
- Add return type hints to Base256EmojiConverter methods
- Add clarifying comments to exception handling in decode()
- Add test for ComposedDecoder error messages when all decoders fail
- Improve Base256EmojiConverter documentation with better docstrings
…mentations

- Replace dynamic emoji generation with hardcoded alphabet matching js-multiformats and go-multibase
- Update decode method to iterate character-by-character (matching reference implementations)
- Ensures full compatibility with js-multiformats and go-multibase
- All test cases from js-multiformats spec tests now pass exactly

This fixes the compatibility issue where our implementation was generating
a different emoji set than the reference implementations.
@acul71
Copy link
Contributor Author

acul71 commented Dec 1, 2025

@seetadev

Implement all missing multibase encodings and API features

This PR implements all missing features identified in the gap analysis to bring py-multibase to 100% compatibility with reference implementations (go-multibase, rust-multibase, js-multiformats).

New Encodings (10 total)

High Priority (9 encodings)

  • base16upper (prefix F) - Uppercase hexadecimal encoding
  • base32upper (prefix B) - Uppercase base32 encoding
  • base32pad (prefix c) - Base32 with RFC 4648 padding
  • base32padupper (prefix C) - Base32 uppercase with padding
  • base32hexupper (prefix V) - Base32hex uppercase variant
  • base32hexpad (prefix t) - Base32hex with RFC 4648 padding
  • base32hexpadupper (prefix T) - Base32hex uppercase with padding
  • base64pad (prefix M) - Base64 with RFC 4648 padding
  • base64urlpad (prefix U) - Base64url with padding

Low Priority (1 encoding)

  • base256emoji (prefix 🚀) - Emoji-based encoding
    • Uses exact hardcoded alphabet from js-multiformats and go-multibase
    • Ensures full compatibility with reference implementations

API Enhancements

Reusable Encoder/Decoder Classes

  • Added Encoder class for reusable encoding operations
  • Added Decoder class for reusable decoding operations
  • Added ComposedDecoder class via Decoder.or_() method for trying multiple decoders in sequence

Return Encoding Type on Decode

  • Added decode(return_encoding=True) parameter
  • Returns tuple (encoding, decoded_data) when enabled
  • Maintains backward compatibility (defaults to False)

Structured Exception Classes

  • Added MultibaseError base exception class
  • Added UnsupportedEncodingError for unsupported encodings
  • Added InvalidMultibaseStringError for invalid multibase strings
  • Added DecodingError for decoding failures
  • All exceptions inherit from ValueError for backward compatibility

Encoding Metadata Functions

  • Added get_encoding_info(encoding) - Returns Encoding namedtuple with encoding name, code, and converter
  • Added list_encodings() - Returns list of all supported encoding names
  • Added is_encoding_supported(encoding) - Returns boolean indicating if encoding is supported

Implementation Details

Padding Support

  • Implemented RFC 4648 padding for base32 and base64 variants
  • Padding is added during encoding when needed
  • Padding is stripped during decoding
  • Simplified padding calculation logic

Base256Emoji Implementation

  • Uses exact hardcoded alphabet matching js-multiformats and go-multibase
  • Decodes character-by-character (matching reference implementations)
  • All test cases from js-multiformats spec tests pass exactly

Code Quality

  • Added comprehensive type hints
  • Improved documentation and docstrings
  • Added clarifying comments for exception handling
  • All 266 tests passing
  • All linting and type checking passes

Testing

  • ✅ All 266 tests passing (increased from 265 with new test)
  • ✅ Comprehensive tests for all new encodings
  • ✅ Tests for all new API features
  • ✅ Fixed and uncommented existing padding tests
  • ✅ Compatibility verified with js-multiformats spec tests

Documentation

  • ✅ Updated README.rst with all new encodings and API examples
  • ✅ Created towncrier news fragment (20.feature.rst)
  • ✅ Enhanced docstrings with proper ReST formatting
  • ✅ Added usage examples for new API features

Results

  • Encoding coverage: 14/24 (58%) → 24/24 (100%)
  • Full compatibility with reference implementations
  • All linting checks pass
  • All tests pass
  • All type checks pass
  • Documentation builds successfully

Breaking Changes

None. All changes are backward compatible.

Related

Closes #20

@acul71 acul71 closed this Dec 1, 2025
@acul71 acul71 reopened this Dec 1, 2025
@acul71 acul71 merged commit b995f21 into master Dec 1, 2025
42 checks passed
@seetadev
Copy link

seetadev commented Dec 1, 2025

Amazing work, @acul71! 🎉

This is a huge milestone for py-multibase — taking it from 58% → 100% encoding coverage and bringing full parity with go / rust / js implementations is a massive achievement. The implementation quality, attention to detail, API improvements, and exhaustive test coverage really stand out.

Thank you for the thorough gap analysis, clean design of the new Encoder/Decoder abstractions, well-structured exceptions, and for ensuring complete compatibility (including the tricky base256emoji). The documentation, type hints, padding fixes, and newsfragment are all perfectly done.

All tests, linting, and docs build cleanly — fantastic contribution. 🚀

Really appreciate the level of polish and care you bring to the project!

@aspiringsecurity
Copy link

@acul71 : Wonderful, Luca :) Appreciate the contribution.

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.

Implement missing multibase encodings and API features

4 participants