Skip to content

Conversation

vmx
Copy link

@vmx vmx commented Sep 11, 2025

libipld is deprecated. There wasn't really any IPLD used, but just some underlying Multiformats. Hence use cid directly.

Summary by CodeRabbit

  • Refactor

    • Reworked internal hashing implementation to use direct SHA-256 with multihash wrapping while preserving existing behavior.
    • No changes to the public API.
  • Chores

    • Updated dependencies to support the new hashing approach (added required crates, removed an outdated one).
  • Impact

    • No user-facing changes; existing functionality and outputs remain consistent.

`libipld` is deprecated. There wasn't really any IPLD used, but just
some underlying Multiformats. Hence use `cid` directly.
Copy link

coderabbitai bot commented Sep 11, 2025

Walkthrough

Replaces libipld-based multihash computation with direct sha2 hashing and cid’s Multihash wrapper. Updates Cargo.toml to add cid and sha2 dependencies and remove libipld. Oid public API remains unchanged; only internal hashing/Multihash construction is modified.

Changes

Cohort / File(s) Summary
Dependencies update
Cargo.toml
Added cid = "0.11.1" and sha2 = "0.10.9"; removed libipld = "0.16".
OID hashing implementation
src/oid.rs
Replaced libipld multihash usage with sha2::Sha256::digest and cid::multihash::Multihash::wrap using constant MULTIHASH_SHA2_256 = 0x12; imports updated; Oid public API unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant O as Oid::new
  participant H as sha2::Sha256
  participant M as cid::multihash::Multihash

  Caller->>O: new(bytes)
  O->>H: digest(bytes)
  H-->>O: sha256_digest
  O->>M: wrap(0x12, sha256_digest)
  M-->>O: multihash
  O-->>Caller: Oid (with multihash)
  
  note over O,M: 0x12 = MULTIHASH_SHA2_256
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "remove libipld dependency" is concise and directly reflects the primary change in the PR (removing libipld and switching to cid/sha2), so it clearly communicates the main intent to reviewers scanning history.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Poem

I nibble bytes with careful chew,
Swap fields of hash for something new—
A 0x12 to guide my hop,
Through sha2 lanes I never stop.
With cid crumbs I trace the trail,
My Oid is crisp, I thump my tail. 🥕🐇

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
Cargo.toml (1)

19-19: Prefer cid/multihash’s Code::Sha2_256 over a direct sha2 dependency.

You can drop the sha2 crate and compute the digest via multihash, simplifying deps and avoiding hard-coded multihash codes in src/oid.rs. If you keep sha2, consider default-features = false to minimize features.

Cargo diff (only if switching to multihash digest):

 [dependencies]
 base64 = "0.22"
 brotli = "6.0"
 cid = "0.11.1"
 cjson = "0.1"
 embed-doc-image = "0.1"
 multibase = "0.9"
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
-sha2 = "0.10.9"

Also applies to: 25-25

src/oid.rs (2)

1-2: Use multihash Code instead of manual sha2 + numeric code.

This lets you remove the sha2 import and the 0x12 constant; the multihash crate ensures length/algorithm correctness.

-use cid::{multihash::Multihash, Cid};
-use sha2::{Digest, Sha256};
+use cid::Cid;
+use cid::multihash::{Code, MultihashDigest};
@@
-const MULTIHASH_SHA2_256: u64 = 0x12;

Additionally, the doc still references “libipld”. Consider updating it to “cid crate”.

/// `Oid` is a struct that represents an object identifier (OID) backed by a `Cid` from the `cid` crate.

Also applies to: 5-6


34-36: Simplify digest construction; avoid hard-coded multihash code.

Leverage Code::Sha2_256.digest(bytes); no error path needed here.

-        let digest = Sha256::digest(bytes);
-        let hash = Multihash::wrap(MULTIHASH_SHA2_256, &digest)?;
-        let cid = Cid::new_v1(0x55, hash); // 0x55 is the code for raw codec
+        let hash = Code::Sha2_256.digest(bytes);
+        let cid = Cid::new_v1(0x55, hash); // raw codec

Optional: avoid the magic number by using the typed multicodec if available:

use cid::multicodec::Code as Codec;
// ...
let cid = Cid::new_v1(Codec::Raw.into(), hash);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f06fef and c03467b.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • Cargo.toml (1 hunks)
  • src/oid.rs (2 hunks)

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