Skip to content

Multiformats multihash implementation without size in the type signature

License

Notifications You must be signed in to change notification settings

cryptidtech/multihash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multihash

Multiformats Multihash implementation without constant size in the type signature.

Features

  • Uses the [multiutil::BaseEncoded] smart pointers to wrap the Multihash into EncodecMultihash for base encoded multihashes; automating the encoding/decoding to/from strings and byte slices.
  • Serde support to/from human readable and binary formats.
  • Supports raw binary encoding and decoding using [Into<Vec<u8>>] and [TryFrom<&[u8]>] trait implementations.

Examples

Bulding a multihash from some bytes:

let mh = Builder::new_from_bytes(Codec::Sha3384, b"for great justice, move every zig!")?
    .try_build()?;

Building a base encoded multihash from some bytes:

let encoded_mh = Builder::new_from_bytes(Codec::Sha3256, b"for great justice, move every zig!")?
    .with_base_encoding(Base::Base58Btc)
    .try_build_encoded()?;

Existing multihash objects can be converted to [crate::mh::EncodedMultihash] objects by using .into():

let mh = Builder::new_from_bytes(Codec::Sha3384, b"for great justice, move every zig!")?
    .try_build()?;

// this will use the preferred encoding for multihash objects: Base::Base16Lower
let encoded_mh1: EncodedMultihash = mh.into();

// or you can chose the base enccoding...
let encoded_mh2: EncodedMultihash::new(Base::Base32Upper, mh);

About

Multiformats multihash implementation without size in the type signature

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages