From ec8c4a2608262c4b859f7c00651f78eafce8204e Mon Sep 17 00:00:00 2001 From: Doug Anderson444 Date: Mon, 2 Dec 2024 15:25:17 -0400 Subject: [PATCH 1/5] bump deps to blsful crates.io --- Cargo.toml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 46d6c91..e1ac56e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,12 +16,15 @@ dag_cbor = ["serde_cbor", "serde_cbor/tags"] multibase = { version = "1.0", git = "https://github.com/cryptidtech/rust-multibase.git" } multicodec = { version = "1.0", git = "https://github.com/cryptidtech/rust-multicodec.git" } multihash = { version = "1.0", git = "https://github.com/cryptidtech/multihash.git" } -multikey = { version = "1.0", git = "https://github.com/cryptidtech/multikey.git" } -multisig = { version = "1.0", git = "https://github.com/cryptidtech/multisig.git" } +multikey = { version = "1.0", git = "https://github.com/DougAnderson444/multikey.git" } +multisig = { version = "1.0", git = "https://github.com/DougAnderson444/multisig.git" } multitrait = { version = "1.0", git = "https://github.com/cryptidtech/multitrait.git" } multiutil = { version = "1.0", git = "https://github.com/cryptidtech/multiutil.git" } rand = "0.8" -serde = { version = "1.0", default-features = false, features = ["alloc", "derive"], optional = true } +serde = { version = "1.0", default-features = false, features = [ + "alloc", + "derive", +], optional = true } serde_cbor = { version = "0.11", optional = true } thiserror = "1.0" From 13e492c60f10f7e70612787c372c2382702d0db0 Mon Sep 17 00:00:00 2001 From: Doug Anderson444 Date: Tue, 11 Mar 2025 23:26:08 -0300 Subject: [PATCH 2/5] impl Cid with cid() method --- src/vlad.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/vlad.rs b/src/vlad.rs index 5342248..29c0689 100644 --- a/src/vlad.rs +++ b/src/vlad.rs @@ -52,6 +52,13 @@ impl Vlad { vv.verify(&ms, Some(&cidv))?; Ok(()) } + + /// Return the Vlad's [Cid]. + /// This is the content address of the verification function. + /// It should match the `vlad/cid` field in a Provenance Log's first Entry. + pub fn cid(&self) -> &Cid { + &self.cid + } } impl CodecInfo for Vlad { From bbcfccc11641569a68b1321c75ae4f0f7ba9c7f7 Mon Sep 17 00:00:00 2001 From: Doug Anderson444 Date: Tue, 11 Mar 2025 23:28:01 -0300 Subject: [PATCH 3/5] impl Display for Cid --- src/cid.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/cid.rs b/src/cid.rs index 5d878c5..2d526f9 100644 --- a/src/cid.rs +++ b/src/cid.rs @@ -156,6 +156,13 @@ impl fmt::Debug for Cid { } } +impl fmt::Display for Cid { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let encoded = EncodedCid::new(self.encoding(), self.clone()); + write!(f, "{}", encoded) + } +} + /// Hash builder that takes the codec and the data and produces a Multihash #[derive(Clone, Debug, Default)] pub struct Builder { @@ -210,8 +217,7 @@ impl Builder { return Err(CidError::LegacyCid.into()); } Ok(EncodedCid::new( - self.base_encoding - .unwrap_or_else(Cid::preferred_encoding), + self.base_encoding.unwrap_or_else(Cid::preferred_encoding), self.try_build()?, )) } @@ -275,17 +281,23 @@ mod tests { assert_eq!(Codec::Sha2256, v0_1.hash.codec()); // this does not assume a multibase encoded CID - let v0_2 = EncodedCid::try_from("bafybeihcrr5owouhnms63areolshu2lp4jjbjqlhf4exegk7tnso5ja6py").unwrap(); + let v0_2 = + EncodedCid::try_from("bafybeihcrr5owouhnms63areolshu2lp4jjbjqlhf4exegk7tnso5ja6py") + .unwrap(); assert_eq!(Codec::Cidv1, v0_2.codec()); assert_eq!(Codec::DagPb, v0_2.target_codec); assert_eq!(Codec::Sha2256, v0_2.hash.codec()); - let v0_3 = EncodedCid::try_from("f01701220e28c7aeb3a876b25ed822472e47a696fe25214c1672f0972195f9b64eea41e7e").unwrap(); + let v0_3 = EncodedCid::try_from( + "f01701220e28c7aeb3a876b25ed822472e47a696fe25214c1672f0972195f9b64eea41e7e", + ) + .unwrap(); assert_eq!(Codec::Cidv1, v0_3.codec()); assert_eq!(Codec::DagPb, v0_3.target_codec); assert_eq!(Codec::Sha2256, v0_3.hash.codec()); - let v0_4 = EncodedCid::try_from("uAXASIOKMeus6h2sl7YIkcuR6aW_iUhTBZy8Jchlfm2TupB5-").unwrap(); + let v0_4 = + EncodedCid::try_from("uAXASIOKMeus6h2sl7YIkcuR6aW_iUhTBZy8Jchlfm2TupB5-").unwrap(); assert_eq!(Codec::Cidv1, v0_4.codec()); assert_eq!(Codec::DagPb, v0_4.target_codec); assert_eq!(Codec::Sha2256, v0_4.hash.codec()); From 271258d21f4a778160e53a3df1b153b9d27e617e Mon Sep 17 00:00:00 2001 From: Doug Anderson444 Date: Tue, 11 Mar 2025 23:28:56 -0300 Subject: [PATCH 4/5] add `to_string()` test --- src/cid.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cid.rs b/src/cid.rs index 2d526f9..7cc0975 100644 --- a/src/cid.rs +++ b/src/cid.rs @@ -404,4 +404,20 @@ mod tests { assert!(cid1 != cid2); assert!(!cid2.is_null()); } + + #[test] + fn test_string_roundtrip() { + let v1 = Builder::new(Codec::Cidv1) + .with_target_codec(Codec::DagCbor) + .with_hash( + &mh::Builder::new_from_bytes(Codec::Sha3512, b"for great justice, move every zig!") + .unwrap() + .try_build() + .unwrap(), + ) + .try_build() + .unwrap(); + let s = v1.to_string(); + assert_eq!(s, EncodedCid::try_from(s.as_str()).unwrap().to_string()); + } } From 34ede78c749e102805d77dad2a459658ce4fdb44 Mon Sep 17 00:00:00 2001 From: Doug Anderson444 Date: Tue, 11 Mar 2025 23:34:04 -0300 Subject: [PATCH 5/5] switch deps back to cryptidtech repo now that chgs have merged --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e1ac56e..4c470e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,8 @@ dag_cbor = ["serde_cbor", "serde_cbor/tags"] multibase = { version = "1.0", git = "https://github.com/cryptidtech/rust-multibase.git" } multicodec = { version = "1.0", git = "https://github.com/cryptidtech/rust-multicodec.git" } multihash = { version = "1.0", git = "https://github.com/cryptidtech/multihash.git" } -multikey = { version = "1.0", git = "https://github.com/DougAnderson444/multikey.git" } -multisig = { version = "1.0", git = "https://github.com/DougAnderson444/multisig.git" } +multikey = { version = "1.0", git = "https://github.com/cryptidtech/multikey.git" } +multisig = { version = "1.0", git = "https://github.com/cryptidtech/multisig.git" } multitrait = { version = "1.0", git = "https://github.com/cryptidtech/multitrait.git" } multiutil = { version = "1.0", git = "https://github.com/cryptidtech/multiutil.git" } rand = "0.8"