Skip to content

Commit f08d044

Browse files
authored
feat(rust/hermes-ipfs): Doc Sync .new and .diff payloads (#681)
1 parent 053e839 commit f08d044

File tree

5 files changed

+649
-1
lines changed

5 files changed

+649
-1
lines changed

.config/dictionaries/project.dic

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ blockdiag
2727
blockfetch
2828
blosc
2929
bmac
30+
bytemuck
3031
Bogale
3132
bootstrapper
3233
BROTLI

rust/hermes-ipfs/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ doc-sync = ["minicbor", "ed25519-dalek", "catalyst-types"]
1717

1818
[dependencies]
1919
anyhow = "1.0.100"
20-
derive_more = {version = "2.0.1", features = ["from","into","display"] }
20+
bytemuck = { version = "1.23.2", features = ["derive", "extern_crate_alloc"] }
21+
derive_more = {version = "2.0.1", features = ["from", "into", "display", "try_from", "deref"] }
2122
ipld-core = { version = "0.4.1", features = ["serde"]}
2223
# A fork of crates-io version with updated dependencies (`libp2p` and `ring` in particular).
2324
# rev-26b99cb as at July 30, 2025

rust/hermes-ipfs/src/doc_sync/envelope.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ impl EnvelopePayload {
128128
&self.payload
129129
}
130130

131+
/// Returns the decoded payload body.
132+
#[must_use]
133+
pub fn payload<T: for<'a> Decode<'a, ()>>(&self) -> Result<(), minicbor::decode::Error> {
134+
minicbor::decode(self.payload_bytes())
135+
}
136+
131137
/// Returns CBOR bytes for `[peer, seq, ver, payload]`.
132138
///
133139
/// These are the bytes the spec signs over.

rust/hermes-ipfs/src/doc_sync/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,29 @@
22
33
mod envelope;
44

5+
pub mod payload;
6+
57
pub use envelope::{Envelope, EnvelopePayload};
68

79
/// Current document synchronization protocol version.
810
const PROTOCOL_VERSION: u64 = 1;
11+
12+
/// `CID` version that Doc Sync supports.
13+
const CID_VERSION: u8 = 1;
14+
15+
/// `CID` codec that Doc Sync supports (CBOR).
16+
const CID_CODEC: u8 = 0x51;
17+
18+
/// `CID` multihash code that Doc Sync supports (SHA256).
19+
const CID_MULTIHASH_CODE: u8 = 0x12;
20+
21+
/// `CID` multihash digest size that Doc Sync supports.
22+
const CID_DIGEST_SIZE: u8 = 32;
23+
24+
/// Validates CID according to Doc Sync specification constraints.
25+
fn validate_cid(cid: &crate::Cid) -> bool {
26+
cid.version() as u8 == CID_VERSION
27+
&& cid.codec() == u64::from(CID_CODEC)
28+
&& cid.hash().code() == u64::from(CID_MULTIHASH_CODE)
29+
&& cid.hash().digest().len() == usize::from(CID_DIGEST_SIZE)
30+
}

0 commit comments

Comments
 (0)