Skip to content

Fix: Support complete multihash type mappings in Prefix#76

Open
sumanjeet0012 wants to merge 2 commits into
ipld:masterfrom
sumanjeet0012:fix-65-multihash-type-mappings
Open

Fix: Support complete multihash type mappings in Prefix#76
sumanjeet0012 wants to merge 2 commits into
ipld:masterfrom
sumanjeet0012:fix-65-multihash-type-mappings

Conversation

@sumanjeet0012

Copy link
Copy Markdown

Description

This PR addresses the issue where Prefix._mh_types_to_code() and Prefix._mh_code_to_type() were using a hardcoded, incomplete mapping of only 8 multihash types, which led to ValueError on valid multihashes like identity, shake-256, and blake3.

The mapping logic now properly delegates to the multihash library which acts as the source of truth for all supported multiformat hash codes.

Changes

  • Replaced the hardcoded mappings in cid/prefix.py for both _mh_types_to_code and _mh_code_to_type.
  • _mh_type_to_code now uses multihash.Func and multihash.coerce_code() to look up the type name safely.
  • _mh_code_to_type now converts the code back to the canonical name via multihash.Func.

This enables py-cid to parse and serialize any valid prefix supported by python-multihash.

@sumanjeet0012 sumanjeet0012 force-pushed the fix-65-multihash-type-mappings branch from 4231e10 to 7d07d6c Compare July 12, 2026 18:53
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.

1 participant