1 unstable release

0.1.0 Jun 6, 2023

#12 in #multi-hash

Download history 17836/week @ 2023-12-14 11097/week @ 2023-12-21 7840/week @ 2023-12-28 16628/week @ 2024-01-04 18744/week @ 2024-01-11 23156/week @ 2024-01-18 21300/week @ 2024-01-25 16230/week @ 2024-02-01 23028/week @ 2024-02-08 26078/week @ 2024-02-15 26634/week @ 2024-02-22 22028/week @ 2024-02-29 19872/week @ 2024-03-07 21390/week @ 2024-03-14 26888/week @ 2024-03-21 20649/week @ 2024-03-28

93,151 downloads per month
Used in 59 crates (via multihash-derive)

MIT license

284 lines


Build Status Crates.io License Documentation Dependency Status Coverage Status

multihash implementation in Rust.

Table of Contents


First add this to your Cargo.toml

multihash = "*"

Then run cargo build.


The minimum supported Rust version for this library is 1.64.0. This is only guaranteed without additional features activated.


The multihash crate exposes a basic data structure for encoding and decoding multihash. It does not provide any hashing functionality itself. Multihash uses const-generics to define the internal buffer size. You should set this to the maximum size of the digest you want to support.

use multihash::Multihash;

const SHA2_256: u64 = 0x12;

fn main() {
	let hash = Multihash::<64>::wrap(SHA2_256, b"my digest");
	println!("{:?}", hash);

Using a custom code table

You can derive your own application specific code table using the multihash-derive crate. The multihash-codetable provides predefined hasher implementations if you don't want to implement your own.

use multihash_derive::MultihashDigest;

#[derive(Clone, Copy, Debug, Eq, MultihashDigest, PartialEq)]
#[mh(alloc_size = 64)]
pub enum Code {
    #[mh(code = 0x01, hasher = multihash_codetable::Sha2_256)]
    #[mh(code = 0x02, hasher = multihash_codetable::Sha2_512)]

fn main() {
    let hash = Code::Foo.digest(b"my hash");
    println!("{:02x?}", hash);

Supported Hash Types

  • SHA1
  • SHA2-256
  • SHA2-512
  • SHA3/Keccak
  • Blake2b-256/Blake2b-512/Blake2s-128/Blake2s-256
  • Blake3
  • Strobe


Captain: @dignifiedquire.


Contributions welcome. Please check out the issues.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.

Small note: If editing the README, please conform to the standard-readme specification.




This is an internal crate that implements the actual MultihashDigest derive.

The multihash-derive crate acts as a facade and defines additional symbols that our derive depends on. For example, the actual trait that we are deriving MultihashDigest, as well as the Hasher trait and the UnsupportedCode error type.


~76K SLoC