This library defines common interfaces and low level building blocks for various interrelated multiformat technologies (multicodec, multihash, multibase, and CID). They can be used to implement custom base encoders / decoders / codecs, codec encoders /decoders and multihash hashers that comply to the interface that layers above assume.
This library provides implementations for most basics and many others can be found in linked repositories.
CIDs can be serialized to string representation using multibase encoders that implement MultibaseEncoder interface. This library provides quite a few implementations that can be imported:
Parsing CID string serialized CIDs requires multibase decoder that implements MultibaseDecoder interface. This library provides a decoder for every encoder it provides:
Dual of multibase encoder & decoder is defined as multibase codec and it exposes
them as encoder and decoder properties. For added convenience codecs also
implement MultibaseEncoder and MultibaseDecoder interfaces so they could be
used as either or both:
Note: CID implementation comes bundled with base32 and base58btc
multibase codecs so that CIDs can be base serialized to (version specific)
default base encoding and parsed without having to supply base encoders/decoders:
This library defines BlockEncoder, BlockDecoder and BlockCodec interfaces.
Codec implementations should conform to the BlockCodec interface which implements both BlockEncoder and BlockDecoder.
Here is an example implementation of JSON BlockCodec.
This library contains higher-order functions for traversing graphs of data easily.
walk() walks through the links in each block of a DAG calling a user-supplied loader function for each one, in depth-first order with no duplicate block visits. The loader should return a Block object and can be used to inspect and collect block ordering for a full DAG walk. The loader should throw on error, and return null if a block should be skipped by walk().
// build a DAG (a single block for this simple example) constvalue = { hello:'world' } constblock = awaitBlock.encode({ value, codec, hasher }) const { cid } = block console.log(cid) //> CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)
// create a loader function that also collects CIDs of blocks in // their traversal order constload = (cid, blocks) =>async (cid) => { // fetch a block using its cid // e.g.: const block = await fetchBlockByCID(cid) blocks.push(cid) returnblock }
// collect blocks in this DAG starting from the root `cid` constblocks = [] awaitwalk({ cid, load:load(cid, blocks) })
blockcodec-to-ipld-format converts a multiformats BlockCodec into an
interface-ipld-format for use with the ipld package. This can help bridge IPLD codecs implemented using the structure and interfaces defined here to existing code that assumes, or requires interface-ipld-format. This bridge also includes the relevant TypeScript definitions.
By default, no base encodings (other than base32 & base58btc), hash functions,
or codec implementations are exposed by multiformats, you need to
import the ones you need yourself.
This library defines common interfaces and low level building blocks for various interrelated multiformat technologies (multicodec, multihash, multibase, and CID). They can be used to implement custom base encoders / decoders / codecs, codec encoders /decoders and multihash hashers that comply to the interface that layers above assume.
This library provides implementations for most basics and many others can be found in linked repositories.
Creating Blocks
Multibase Encoders / Decoders / Codecs
CIDs can be serialized to string representation using multibase encoders that implement
MultibaseEncoder
interface. This library provides quite a few implementations that can be imported:Parsing CID string serialized CIDs requires multibase decoder that implements
MultibaseDecoder
interface. This library provides a decoder for every encoder it provides:Dual of multibase encoder & decoder is defined as multibase codec and it exposes them as
encoder
anddecoder
properties. For added convenience codecs also implementMultibaseEncoder
andMultibaseDecoder
interfaces so they could be used as either or both:Note: CID implementation comes bundled with
base32
andbase58btc
multibase codecs so that CIDs can be base serialized to (version specific) default base encoding and parsed without having to supply base encoders/decoders:Multicodec Encoders / Decoders / Codecs
This library defines
BlockEncoder
,BlockDecoder
andBlockCodec
interfaces. Codec implementations should conform to theBlockCodec
interface which implements bothBlockEncoder
andBlockDecoder
. Here is an example implementation of JSONBlockCodec
.Multihash Hashers
This library defines
MultihashHasher
andMultihashDigest
interfaces and convinient function for implementing them:Traversal
This library contains higher-order functions for traversing graphs of data easily.
walk()
walks through the links in each block of a DAG calling a user-supplied loader function for each one, in depth-first order with no duplicate block visits. The loader should return aBlock
object and can be used to inspect and collect block ordering for a full DAG walk. The loader shouldthrow
on error, and returnnull
if a block should be skipped bywalk()
.Legacy interface
blockcodec-to-ipld-format
converts a multiformatsBlockCodec
into aninterface-ipld-format
for use with theipld
package. This can help bridge IPLD codecs implemented using the structure and interfaces defined here to existing code that assumes, or requiresinterface-ipld-format
. This bridge also includes the relevant TypeScript definitions.Implementations
By default, no base encodings (other than base32 & base58btc), hash functions, or codec implementations are exposed by
multiformats
, you need to import the ones you need yourself.Multibase codecs
base16
multiformats/bases/base16
base32
,base32pad
,base32hex
,base32hexpad
,base32z
multiformats/bases/base32
base64
,base64pad
,base64url
,base64urlpad
multiformats/bases/base64
base58btc
,base58flick4
multiformats/bases/base58
Other (less useful) bases implemented in multiformats/js-multiformats include:
base2
,base8
,base10
,base36
andbase256emoji
.Multihash hashers
sha2-256
,sha2-512
multiformats/hashes/sha2
sha3-224
,sha3-256
,sha3-384
,sha3-512
,shake-128
,shake-256
,keccak-224
,keccak-256
,keccak-384
,keccak-512
@multiformats/sha3
identity
multiformats/hashes/identity
murmur3-128
,murmur3-32
@multiformats/murmur3
blake2b-*
,blake2s-*
@multiformats/blake2
IPLD codecs (multicodec)
raw
multiformats/codecs/raw
json
multiformats/codecs/json
dag-cbor
@ipld/dag-cbor
dag-json
@ipld/dag-json
dag-pb
@ipld/dag-pb
dag-jose
dag-jose