From 7c49b53a90ddeab24b6f774cccd63aa83790ae63 Mon Sep 17 00:00:00 2001 From: 0xkenta Date: Sat, 5 Sep 2026 16:45:12 +0900 Subject: [PATCH 1/2] refactor: reuse ContentId generation --- src/dasl/node.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/dasl/node.rs b/src/dasl/node.rs index 7de932c..003d503 100644 --- a/src/dasl/node.rs +++ b/src/dasl/node.rs @@ -1,8 +1,8 @@ +use super::cid::ContentId; use super::error::{DaslError, NodeValidationError, Result}; use cid::Cid; use multihash::Multihash; use serde::{Deserialize, Serialize}; -use sha2::{Digest, Sha256}; use std::collections::BTreeMap; /// For more details on these multicodec codes, see: @@ -75,9 +75,7 @@ where /// Returns a NodeError if serialization or hashing fails pub fn content_id(&self) -> Result { let buf = self.to_bytes()?; - let hash = Sha256::digest(&buf); - let mh = Multihash::<64>::wrap(SHA2_256_CODE, &hash)?; - Ok(Cid::new_v1(RAW_CODE, mh)) + Ok(ContentId::new(&buf)?.0) } /// Serializes this node using CBOR From 5a24fdf18511c57a453a08af8d9758d2ef62f20e Mon Sep 17 00:00:00 2001 From: 0xkenta Date: Sat, 5 Sep 2026 23:27:29 +0900 Subject: [PATCH 2/2] fix: remove unused node hashing symbols --- src/dasl/node.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/dasl/node.rs b/src/dasl/node.rs index 003d503..91347ec 100644 --- a/src/dasl/node.rs +++ b/src/dasl/node.rs @@ -1,15 +1,9 @@ use super::cid::ContentId; use super::error::{DaslError, NodeValidationError, Result}; use cid::Cid; -use multihash::Multihash; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; -/// For more details on these multicodec codes, see: -/// https://github.com/multiformats/multicodec/blob/master/table.csv -const SHA2_256_CODE: u64 = 0x12; -const RAW_CODE: u64 = 0x55; - /// This structure can store any type of payload data and metadata, making it versatile for various use cases. /// /// # Type Parameters @@ -153,13 +147,10 @@ where #[cfg(test)] mod tests { use super::*; - use sha2::{Digest, Sha256}; use std::collections::BTreeMap; fn create_test_content_id(data: &[u8]) -> Cid { - let hash = Sha256::digest(data); - let digest = Multihash::<64>::wrap(SHA2_256_CODE, &hash).unwrap(); - Cid::new_v1(RAW_CODE, digest) + ContentId::new(data).unwrap().0 } #[test]