{"name":"multiformats","version":"10.0.0-pre.2","keywords":["ipfs","ipld","multiformats"],"author":{"url":"https://www.mikealrogers.com/","name":"Mikeal Rogers","email":"mikeal.rogers@gmail.com"},"license":"Apache-2.0 OR MIT","_id":"multiformats@10.0.0-pre.2","maintainers":[{"name":"mikeal","email":"mikeal.rogers@gmail.com"},{"name":"rvagg","email":"r@va.gg"},{"name":"npm-service-account-multiformats","email":"npm-service-account+multiformats@protocol.ai"}],"homepage":"https://github.com/multiformats/js-multiformats#readme","bugs":{"url":"https://github.com/multiformats/js-multiformats/issues"},"dist":{"shasum":"ab921b429f62ba3e505b279b0f61cb5f9a2ed5f3","tarball":"http://registry-npm.ywwl.com/multiformats/download/multiformats-10.0.0-pre.2.tgz","fileCount":153,"integrity":"sha512-qGi8mpdm4W/JGrhVZIu+oDU9p9ve9kPnMBefTA4fP7OeZ7yHKmF/2xE3azY+9biU3SPWwBjmynCrw2BsxfdDzg==","signatures":[{"sig":"MEYCIQCe8GXLpFqAiIMV5wCOwARWI8Zlx3VqHthH25+CdxzrHQIhAL9aGXEUfv+MXtf63Rh3aUv3AcmPZK820PU1dnXE/j2E","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":234169,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjGDUlACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqn8hAAieeYlh1ibqImK+BGd823JSajLNTktFj2PQEe0PbQGUk5MjGr\r\ntJngCh50Bf4vKxT24vUxirqlkwTdFnFIymRQODu/1Mr7MhFiRfu/IVHZ5ZNn\r\nAgK+nOMLEucufj98HippXZgWMOlKpoUmiKpmbbdo0UDYyjo4Wd6s+CnIzdXy\r\n7RGOAWdj7/olzIe5R45cKmBtOX/Xw3J50/GqV51SOQlDQ+s49VrqJLkzBd8M\r\noQxTuc5CZtupfjslyfTszGfyff6omEWkpi5g3xVTJdrxqCRktp+k2tyJxjOi\r\nZCQ2uW9VaMKABO6ei2VavK5LXDWAiRs89eOd1poL9lcjezXWSDybtFn9MwqJ\r\n5fYBw8wdu0bfivdG95BeSL83T2A3QoY/ukThaASwfOFFpoA03G2i0P2s/8CV\r\n77lniJmblHGr9CBLUfnjaU3vGRU9OfajbYbkIiboS/vlgoJAraCJSUIOJEmN\r\nSpXASrpmcPa9N96P8FrUkt+yygcpP0MkyXvUOnZKn02FOQ6O4Mpb6w+3tkc3\r\n53b9DxN3+4CeL9lHs+QpoHzXMm0C28G9PS9TzW6+Op2SeBnQi6HGlqJi9NXy\r\n3GH/PglKOVQzhoir9NeSei/n/7IJfztYs6bCoRdInypQV+ofqHRNEtSyXWN7\r\n9IGYirLgOA9L5s0Diw6vPGO4fV3UFrbqfes=\r\n=gkjV\r\n-----END PGP SIGNATURE-----\r\n","size":56199,"noattachment":false,"key":"/multiformats/-/multiformats-10.0.0-pre.2.tgz"},"main":"./src/index.js","type":"module","aegir":{"test":{"cov":true,"target":["node","browser"]},"build":{"bundle":false}},"types":"./types/src/index.d.ts","readme":"# multiformats <!-- omit in toc -->\n\n[![multiformats.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://multiformats.io)\n[![codecov](https://img.shields.io/codecov/c/github/multiformats/js-multiformats.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-multiformats)\n[![CI](https://img.shields.io/github/workflow/status/multiformats/js-multiformats/test%20&%20maybe%20release/esm-migration?style=flat-square)](https://github.com/multiformats/js-multiformats/actions/workflows/js-test-and-release.yml)\n\n> Interface for multihash, multicodec, multibase and CID\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Interfaces](#interfaces)\n  - [Creating Blocks](#creating-blocks)\n  - [Multibase Encoders / Decoders / Codecs](#multibase-encoders--decoders--codecs)\n  - [Multicodec Encoders / Decoders / Codecs](#multicodec-encoders--decoders--codecs)\n  - [Multihash Hashers](#multihash-hashers)\n  - [Traversal](#traversal)\n- [Legacy interface](#legacy-interface)\n- [Implementations](#implementations)\n  - [Multibase codecs](#multibase-codecs)\n  - [Multihash hashers](#multihash-hashers-1)\n  - [IPLD codecs (multicodec)](#ipld-codecs-multicodec)\n- [License](#license)\n- [Contribution](#contribution)\n\n## Install\n\n```console\n$ npm i multiformats\n```\n\n## Interfaces\n\nThis 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.\n\nThis library provides implementations for most basics and many others can be found in linked repositories.\n\n```js\nimport { CID } from 'multiformats/cid'\nimport * as json from 'multiformats/codecs/json'\nimport { sha256 } from 'multiformats/hashes/sha2'\n\nconst bytes = json.encode({ hello: 'world' })\n\nconst hash = await sha256.digest(bytes)\nconst cid = CID.create(1, json.code, hash)\n//> CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)\n```\n\n### Creating Blocks\n\n```js\nimport * as Block from 'multiformats/block'\nimport * as codec from '@ipld/dag-cbor'\nimport { sha256 as hasher } from 'multiformats/hashes/sha2'\n\nconst value = { hello: 'world' }\n\n// encode a block\nlet block = await Block.encode({ value, codec, hasher })\n\nblock.value // { hello: 'world' }\nblock.bytes // Uint8Array\nblock.cid   // CID() w/ sha2-256 hash address and dag-cbor codec\n\n// you can also decode blocks from their binary state\nblock = await Block.decode({ bytes: block.bytes, codec, hasher })\n\n// if you have the cid you can also verify the hash on decode\nblock = await Block.create({ bytes: block.bytes, cid: block.cid, codec, hasher })\n```\n\n### Multibase Encoders / Decoders / Codecs\n\nCIDs can be serialized to string representation using multibase encoders that implement [`MultibaseEncoder`](https://github.com/multiformats/js-multiformats/blob/master/src/bases/interface.ts) interface. This library provides quite a few implementations that can be imported:\n\n```js\nimport { base64 } from \"multiformats/bases/base64\"\ncid.toString(base64.encoder)\n//> 'mAYAEEiCTojlxqRTl6svwqNJRVM2jCcPBxy+7mRTUfGDzy2gViA'\n```\n\nParsing CID string serialized CIDs requires multibase decoder that implements [`MultibaseDecoder`](https://github.com/multiformats/js-multiformats/blob/master/src/bases/interface.ts) interface. This library provides a decoder for every encoder it provides:\n\n```js\nCID.parse('mAYAEEiCTojlxqRTl6svwqNJRVM2jCcPBxy+7mRTUfGDzy2gViA', base64.decoder)\n//> CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)\n```\n\nDual of multibase encoder & decoder is defined as multibase codec and it exposes\nthem as `encoder` and `decoder` properties. For added convenience codecs also\nimplement `MultibaseEncoder` and `MultibaseDecoder` interfaces so they could be\nused as either or both:\n\n```js\ncid.toString(base64)\nCID.parse(cid.toString(base64), base64)\n```\n\n**Note:** CID implementation comes bundled with `base32` and `base58btc`\nmultibase codecs so that CIDs can be base serialized to (version specific)\ndefault base encoding and parsed without having to supply base encoders/decoders:\n\n```js\nconst v1 = CID.parse('bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea')\nv1.toString()\n//> 'bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea'\n\nconst v0 = CID.parse('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nv0.toString()\n//> 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'\nv0.toV1().toString()\n//> 'bafybeihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku'\n```\n\n### Multicodec Encoders / Decoders / Codecs\n\nThis library defines [`BlockEncoder`, `BlockDecoder` and `BlockCodec` interfaces](https://github.com/multiformats/js-multiformats/blob/master/src/codecs/interface.ts).\nCodec implementations should conform to the `BlockCodec` interface which implements both `BlockEncoder` and `BlockDecoder`.\nHere is an example implementation of JSON `BlockCodec`.\n\n```js\n/**\n * @template T\n * @type {BlockCodec<0x0200, T>}\n */\nexport const { name, code, encode, decode } = {\n  name: 'json',\n  code: 0x0200,\n  encode: json => new TextEncoder().encode(JSON.stringify(json)),\n  decode: bytes => JSON.parse(new TextDecoder().decode(bytes))\n}\n```\n\n### Multihash Hashers\n\nThis library defines [`MultihashHasher` and `MultihashDigest` interfaces](https://github.com/multiformats/js-multiformats/blob/master/src/hashes/interface.ts) and convinient function for implementing them:\n\n```js\nimport * as hasher from 'multiformats/hashes/hasher'\n\nconst sha256 = hasher.from({\n  // As per multiformats table\n  // https://github.com/multiformats/multicodec/blob/master/table.csv#L9\n  name: 'sha2-256',\n  code: 0x12,\n\n  encode: (input) => new Uint8Array(crypto.createHash('sha256').update(input).digest())\n})\n\nconst hash = await sha256.digest(json.encode({ hello: 'world' }))\nCID.create(1, json.code, hash)\n\n//> CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)\n```\n\n### Traversal\n\nThis library contains higher-order functions for traversing graphs of data easily.\n\n`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()`.\n\n```js\nimport { walk } from 'multiformats/traversal'\nimport * as Block from 'multiformats/block'\nimport * as codec from 'multiformats/codecs/json'\nimport { sha256 as hasher } from 'multiformats/hashes/sha2'\n\n// build a DAG (a single block for this simple example)\nconst value = { hello: 'world' }\nconst block = await Block.encode({ value, codec, hasher })\nconst { cid } = block\nconsole.log(cid)\n//> CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)\n\n// create a loader function that also collects CIDs of blocks in\n// their traversal order\nconst load = (cid, blocks) => async (cid) => {\n  // fetch a block using its cid\n  // e.g.: const block = await fetchBlockByCID(cid)\n  blocks.push(cid)\n  return block\n}\n\n// collect blocks in this DAG starting from the root `cid`\nconst blocks = []\nawait walk({ cid, load: load(cid, blocks) })\n\nconsole.log(blocks)\n//> [CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)]\n```\n\n## Legacy interface\n\n[`blockcodec-to-ipld-format`](https://github.com/ipld/js-blockcodec-to-ipld-format) converts a multiformats [`BlockCodec`](https://github.com/multiformats/js-multiformats/blob/master/src/codecs/interface.ts#L21) into an\n[`interface-ipld-format`](https://github.com/ipld/interface-ipld-format) for use with the [`ipld`](https://github.com/ipld/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.\n\n## Implementations\n\nBy default, no base encodings (other than base32 & base58btc), hash functions,\nor codec implementations are exposed by `multiformats`, you need to\nimport the ones you need yourself.\n\n### Multibase codecs\n\n| bases                                                         | import                      | repo                                                                                              |\n| ------------------------------------------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------- |\n| `base16`                                                      | `multiformats/bases/base16` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) |\n| `base32`, `base32pad`, `base32hex`, `base32hexpad`, `base32z` | `multiformats/bases/base32` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) |\n| `base64`, `base64pad`, `base64url`, `base64urlpad`            | `multiformats/bases/base64` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) |\n| `base58btc`, `base58flick4`                                   | `multiformats/bases/base58` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) |\n\nOther (less useful) bases implemented in [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) include: `base2`, `base8`, `base10`, `base36` and `base256emoji`.\n\n### Multihash hashers\n\n| hashes                                                                                                                          | import                         | repo                                                                                                               |\n| ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------ |\n| `sha2-256`, `sha2-512`                                                                                                          | `multiformats/hashes/sha2`     | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/src/hashes)             |\n| `sha3-224`, `sha3-256`, `sha3-384`,`sha3-512`, `shake-128`, `shake-256`, `keccak-224`, `keccak-256`, `keccak-384`, `keccak-512` | `@multiformats/sha3`           | [multiformats/js-sha3](https://github.com/multiformats/js-sha3)                                                    |\n| `identity`                                                                                                                      | `multiformats/hashes/identity` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/src/hashes/identity.js) |\n| `murmur3-128`, `murmur3-32`                                                                                                     | `@multiformats/murmur3`        | [multiformats/js-murmur3](https://github.com/multiformats/js-murmur3)                                              |\n| `blake2b-*`, `blake2s-*`                                                                                                        | `@multiformats/blake2`         | [multiformats/js-blake2](https://github.com/multiformats/js-blake2)                                                |\n\n### IPLD codecs (multicodec)\n\n| codec      | import                     | repo                                                                                                   |\n| ---------- | -------------------------- | ------------------------------------------------------------------------------------------------------ |\n| `raw`      | `multiformats/codecs/raw`  | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/src/codecs) |\n| `json`     | `multiformats/codecs/json` | [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/src/codecs) |\n| `dag-cbor` | `@ipld/dag-cbor`           | [ipld/js-dag-cbor](https://github.com/ipld/js-dag-cbor)                                                |\n| `dag-json` | `@ipld/dag-json`           | [ipld/js-dag-json](https://github.com/ipld/js-dag-json)                                                |\n| `dag-pb`   | `@ipld/dag-pb`             | [ipld/js-dag-pb](https://github.com/ipld/js-dag-pb)                                                    |\n| `dag-jose` | `dag-jose`                 | [ceramicnetwork/js-dag-jose](https://github.com/ceramicnetwork/js-dag-jose)                            |\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n","browser":{"./hashes/sha2":"./src/hashes/sha2-browser.js","./src/hashes/sha2.js":"./src/hashes/sha2-browser.js"},"engines":{"npm":">=7.0.0","node":">=16.0.0"},"exports":{".":{"types":"./types/src/index.d.ts","import":"./src/index.js"},"./cid":{"types":"./types/src/cid.d.ts","import":"./src/cid.js"},"./link":{"types":"./types/src/link.d.ts","import":"./src/link.js"},"./block":{"types":"./types/src/block.d.ts","import":"./src/block.js"},"./bytes":{"types":"./types/src/bytes.d.ts","import":"./src/bytes.js"},"./basics":{"types":"./types/src/basics.d.ts","import":"./src/basics.js"},"./interface":{"types":"./types/src/interface.d.ts","import":"./src/interface.js"},"./traversal":{"types":"./types/src/traversal.d.ts","import":"./src/traversal.js"},"./codecs/raw":{"types":"./types/src/codecs/raw.d.ts","import":"./src/codecs/raw.js"},"./bases/base2":{"types":"./types/src/bases/base2.d.ts","import":"./src/bases/base2.js"},"./bases/base8":{"types":"./types/src/bases/base8.d.ts","import":"./src/bases/base8.js"},"./codecs/json":{"types":"./types/src/codecs/json.d.ts","import":"./src/codecs/json.js"},"./hashes/sha2":{"types":"./types/src/hashes/sha2.d.ts","import":"./src/hashes/sha2.js","browser":"./src/hashes/sha2-browser.js"},"./bases/base10":{"types":"./types/src/bases/base10.d.ts","import":"./src/bases/base10.js"},"./bases/base16":{"types":"./types/src/bases/base16.d.ts","import":"./src/bases/base16.js"},"./bases/base32":{"types":"./types/src/bases/base32.d.ts","import":"./src/bases/base32.js"},"./bases/base36":{"types":"./types/src/bases/base36.d.ts","import":"./src/bases/base36.js"},"./bases/base58":{"types":"./types/src/bases/base58.d.ts","import":"./src/bases/base58.js"},"./bases/base64":{"types":"./types/src/bases/base64.d.ts","import":"./src/bases/base64.js"},"./hashes/digest":{"types":"./types/src/hashes/digest.d.ts","import":"./src/hashes/digest.js"},"./hashes/hasher":{"types":"./types/src/hashes/hasher.d.ts","import":"./src/hashes/hasher.js"},"./bases/identity":{"types":"./types/src/bases/identity.d.ts","import":"./src/bases/identity.js"},"./hashes/identity":{"types":"./types/src/hashes/identity.d.ts","import":"./src/hashes/identity.js"},"./bases/base256emoji":{"types":"./types/src/bases/base256emoji.d.ts","import":"./src/bases/base256emoji.js"}},"gitHead":"065b24a9e0710e254c21e40fc790e8b369aff36e","release":{"plugins":[["@semantic-release/commit-analyzer",{"preset":"conventionalcommits","releaseRules":[{"release":"major","breaking":true},{"revert":true,"release":"patch"},{"type":"feat","release":"minor"},{"type":"fix","release":"patch"},{"type":"docs","release":"patch"},{"type":"test","release":"patch"},{"type":"deps","release":"patch"},{"scope":"no-release","release":false}]}],["@semantic-release/release-notes-generator",{"preset":"conventionalcommits","presetConfig":{"types":[{"type":"feat","section":"Features"},{"type":"fix","section":"Bug Fixes"},{"type":"chore","section":"Trivial Changes"},{"type":"docs","section":"Documentation"},{"type":"deps","section":"Dependencies"},{"type":"test","section":"Tests"}]}}],"@semantic-release/changelog","@semantic-release/npm","@semantic-release/github","@semantic-release/git"],"branches":["esm-migration"]},"scripts":{"lint":"aegir lint","test":"npm run lint && npm run test:node && npm run test:chrome && npm run test:ts","build":"aegir build","clean":"aegir clean","release":"aegir release","test:ts":"npm run test --prefix test/ts-use","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:firefox":"aegir test -t browser -- --browser firefox --no-cov","test:electron-main":"aegir test -t electron-main","test:chrome-webworker":"aegir test -t webworker --no-cov","test:firefox-webworker":"aegir test -t webworker -- --browser firefox --no-cov"},"_npmUser":{"name":"rvagg","email":"r@va.gg"},"repository":{"url":"git+https://github.com/multiformats/js-multiformats.git","type":"git"},"_npmVersion":"8.1.2","description":"Interface for multihash, multicodec, multibase and CID","directories":{},"_nodeVersion":"16.13.1","eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"typesVersions":{"*":{"*":["*","types/*","types/src/*","types/src/*/index"],"src/*":["*","types/*","types/src/*","types/src/*/index"]}},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"chai":"^4.3.4","cids":"^1.1.9","aegir":"^37.5.1","buffer":"^6.0.3","@types/chai":"^4.3.0","@types/node":"^18.0.0","@types/mocha":"^9.0.0","chai-as-promised":"^7.1.1","@stablelib/sha256":"^1.0.1","@stablelib/sha512":"^1.0.1","@types/chai-as-promised":"^7.1.4"},"_npmOperationalInternal":{"tmp":"tmp/multiformats_10.0.0-pre.2_1662530853549_0.9509684001123613","host":"s3://npm-registry-packages"},"publish_time":1662530853785,"_cnpm_publish_time":1662530853785,"dist-tags":{"latest":"14.0.8","next":"10.0.0-pre.3"}}