Skip to content

Commit

Permalink
Move CID-related constants to FVM-owned crates. (#1543)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemmih authored Jun 21, 2022
1 parent be7d883 commit f538c6d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 32 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion ipld/cid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ repository = "https://github.com/ChainSafe/forest"
features = ["cbor", "json"]

[dependencies]
fvm_shared = { version = "0.7.1", default-features = false }
fvm_ipld_encoding = "0.2"
cid = { version = "0.8", default-features = false, features = ["std"] }
multihash = { version = "0.16", default-features = false, features = [
"std",
Expand All @@ -25,7 +27,7 @@ forest_json_utils = { path = "../../utils/json_utils", optional = true, version
generic-array = "0.14"

[dev-dependencies]
serde_json = "1.0"
serde_json = "1.0"
serde_ipld_dagcbor = "0.1.2"

[features]
Expand Down
14 changes: 5 additions & 9 deletions ipld/cid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@ use multihash::Multihash;
use multihash::MultihashDigest;
use std::convert::TryFrom;

pub use fvm_ipld_encoding::DAG_CBOR;
pub use fvm_shared::commcid::FIL_COMMITMENT_SEALED;
pub use fvm_shared::commcid::FIL_COMMITMENT_UNSEALED;
pub use fvm_shared::IPLD_RAW as RAW;

#[cfg(feature = "json")]
pub mod json;

/// Cbor [Cid] codec.
pub const DAG_CBOR: u64 = 0x71;
/// Sealed commitment [Cid] codec.
pub const FIL_COMMITMENT_SEALED: u64 = 0xf102;
/// Unsealed commitment [Cid] codec.
pub const FIL_COMMITMENT_UNSEALED: u64 = 0xf101;
/// Raw [Cid] codec. This represents data that is not encoded using any protocol.
pub const RAW: u64 = 0x55;

/// Constructs a cid with bytes using default version and codec
pub fn new_from_cbor(bz: &[u8], code: Code) -> Cid {
let hash = code.digest(bz);
Expand Down
24 changes: 3 additions & 21 deletions ipld/cid/src/mh_code.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
// Copyright 2019-2022 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use multihash::derive::Multihash;

/// Multihash code for Poseidon BLS replica commitments.
pub const POSEIDON_BLS12_381_A1_FC1: u64 = 0xb401;

/// Multihash code for Sha2 256 trunc254 padded used in data commitments.
pub const SHA2_256_TRUNC254_PADDED: u64 = 0x1012;

/// Multihash generation codes for the Filecoin protocol. This is not an exhausting list of
/// codes used, just the ones used to generate multihashes.
#[derive(Clone, Copy, Debug, Eq, Multihash, PartialEq)]
#[mh(alloc_size = 64)]
pub enum Code {
/// BLAKE2b-256 (32-byte hash size)
#[mh(code = 0xb220, hasher = multihash::Blake2bHasher::<32>)]
Blake2b256,

/// Identity multihash (max 32 bytes)
#[mh(code = 0x00, hasher = multihash::IdentityHasher::<32>)]
Identity,
}
pub use cid::multihash::Code;
pub use fvm_shared::commcid::POSEIDON_BLS12_381_A1_FC1;
pub use fvm_shared::commcid::SHA2_256_TRUNC254_PADDED;
2 changes: 1 addition & 1 deletion ipld/cid/tests/base_cid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ fn test_prefix_retrieval() {
let prefix = Prefix::from(cid);
assert_eq!(prefix.version, Version::V1);
assert_eq!(prefix.codec, DAG_CBOR);
assert_eq!(prefix.mh_type, Code::Blake2b256.into());
assert_eq!(prefix.mh_type, u64::from(Code::Blake2b256));
}

0 comments on commit f538c6d

Please sign in to comment.