-
Notifications
You must be signed in to change notification settings - Fork 1
remove libipld dependency #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
`libipld` is deprecated. There wasn't really any IPLD used, but just some underlying Multiformats. Hence use `cid` directly.
WalkthroughReplaces 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks (3 passed)✅ Passed checks (3 passed)
Poem
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.
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 unit tests
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. Comment |
There was a problem hiding this 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 codecOptional: 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
⛔ 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)
libipld
is deprecated. There wasn't really any IPLD used, but just some underlying Multiformats. Hence usecid
directly.Summary by CodeRabbit
Refactor
Chores
Impact