Skip to content

Fix: Support all hash types in Prefix.sum()#75

Open
sumanjeet0012 wants to merge 2 commits into
ipld:masterfrom
sumanjeet0012:fix-64-prefix-sum-hash-types
Open

Fix: Support all hash types in Prefix.sum()#75
sumanjeet0012 wants to merge 2 commits into
ipld:masterfrom
sumanjeet0012:fix-64-prefix-sum-hash-types

Conversation

@sumanjeet0012

Copy link
Copy Markdown

Description

This PR addresses the limitation where Prefix.sum() and V1Builder.sum() only supported sha2-256 and sha2-512 by hardcoding hashlib.sha256/512. The hashing logic now correctly delegates to multihash.sum() which supports all registered hash functions in python-multihash.

Changes

  • Updated Prefix.sum() in cid/prefix.py to use multihash.sum() instead of manually invoking hashlib and checking mh_type.
  • Updated V0Builder.sum() and V1Builder.sum() in cid/builder.py similarly to delegate to multihash.sum().
  • Removed unnecessary hashlib imports from both modules.
  • Added tests in tests/test_prefix.py to ensure various multihash types like sha3-256, blake2b-256, and identity are supported.

@sumanjeet0012 sumanjeet0012 force-pushed the fix-64-prefix-sum-hash-types branch from 7efbc8d to 221efe7 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