{"name":"multiformats","version":"13.2.3","description":"Interface for multihash, multicodec, multibase and CID","author":{"name":"Mikeal Rogers","email":"mikeal.rogers@gmail.com","url":"https://www.mikealrogers.com/"},"license":"Apache-2.0 OR MIT","homepage":"https://github.com/multiformats/js-multiformats#readme","repository":{"type":"git","url":"git+https://github.com/multiformats/js-multiformats.git"},"bugs":{"url":"https://github.com/multiformats/js-multiformats/issues"},"keywords":["ipfs","ipld","multiformats"],"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./dist/src/index.js"},"./bases/base10":{"types":"./dist/src/bases/base10.d.ts","import":"./dist/src/bases/base10.js"},"./bases/base16":{"types":"./dist/src/bases/base16.d.ts","import":"./dist/src/bases/base16.js"},"./bases/base2":{"types":"./dist/src/bases/base2.d.ts","import":"./dist/src/bases/base2.js"},"./bases/base256emoji":{"types":"./dist/src/bases/base256emoji.d.ts","import":"./dist/src/bases/base256emoji.js"},"./bases/base32":{"types":"./dist/src/bases/base32.d.ts","import":"./dist/src/bases/base32.js"},"./bases/base36":{"types":"./dist/src/bases/base36.d.ts","import":"./dist/src/bases/base36.js"},"./bases/base58":{"types":"./dist/src/bases/base58.d.ts","import":"./dist/src/bases/base58.js"},"./bases/base64":{"types":"./dist/src/bases/base64.d.ts","import":"./dist/src/bases/base64.js"},"./bases/base8":{"types":"./dist/src/bases/base8.d.ts","import":"./dist/src/bases/base8.js"},"./bases/identity":{"types":"./dist/src/bases/identity.d.ts","import":"./dist/src/bases/identity.js"},"./bases/interface":{"types":"./dist/src/bases/interface.d.ts","import":"./dist/src/bases/interface.js"},"./basics":{"types":"./dist/src/basics.d.ts","import":"./dist/src/basics.js"},"./block":{"types":"./dist/src/block.d.ts","import":"./dist/src/block.js"},"./block/interface":{"types":"./dist/src/block/interface.d.ts","import":"./dist/src/block/interface.js"},"./bytes":{"types":"./dist/src/bytes.d.ts","import":"./dist/src/bytes.js"},"./cid":{"types":"./dist/src/cid.d.ts","import":"./dist/src/cid.js"},"./codecs/interface":{"types":"./dist/src/codecs/interface.d.ts","import":"./dist/src/codecs/interface.js"},"./codecs/json":{"types":"./dist/src/codecs/json.d.ts","import":"./dist/src/codecs/json.js"},"./codecs/raw":{"types":"./dist/src/codecs/raw.d.ts","import":"./dist/src/codecs/raw.js"},"./hashes/digest":{"types":"./dist/src/hashes/digest.d.ts","import":"./dist/src/hashes/digest.js"},"./hashes/hasher":{"types":"./dist/src/hashes/hasher.d.ts","import":"./dist/src/hashes/hasher.js"},"./hashes/identity":{"types":"./dist/src/hashes/identity.d.ts","import":"./dist/src/hashes/identity.js"},"./hashes/interface":{"types":"./dist/src/hashes/interface.d.ts","import":"./dist/src/hashes/interface.js"},"./hashes/sha1":{"types":"./dist/types/src/hashes/sha1.d.ts","browser":"./dist/src/hashes/sha1-browser.js","import":"./dist/src/hashes/sha1.js"},"./hashes/sha2":{"types":"./dist/src/hashes/sha2.d.ts","browser":"./dist/src/hashes/sha2-browser.js","import":"./dist/src/hashes/sha2.js"},"./interface":{"types":"./dist/src/interface.d.ts","import":"./dist/src/interface.js"},"./link":{"types":"./dist/src/link.d.ts","import":"./dist/src/link.js"},"./link/interface":{"types":"./dist/src/link/interface.d.ts","import":"./dist/src/link/interface.js"},"./traversal":{"types":"./dist/src/traversal.d.ts","import":"./dist/src/traversal.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"project":true,"sourceType":"module"}},"release":{"branches":["master"],"plugins":[["@semantic-release/commit-analyzer",{"preset":"conventionalcommits","releaseRules":[{"breaking":true,"release":"major"},{"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"]},"scripts":{"clean":"aegir clean","lint":"aegir lint","build":"aegir build","release":"aegir release","docs":"aegir docs","test":"npm run lint && npm run test:node && npm run test:chrome","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","test:electron-main":"aegir test -t electron-main"},"devDependencies":{"@stablelib/sha256":"^2.0.0","@stablelib/sha512":"^2.0.0","@types/node":"^22.0.0","aegir":"^43.0.1","buffer":"^6.0.3","cids":"^1.1.9","crypto-hash":"^3.0.0"},"aegir":{"test":{"target":["node","browser"]}},"browser":{"./hashes/sha1":"./dist/src/hashes/sha1-browser.js","./dist/src/hashes/sha1.js":"./dist/src/hashes/sha1-browser.js","./hashes/sha2":"./dist/src/hashes/sha2-browser.js","./dist/src/hashes/sha2.js":"./dist/src/hashes/sha2-browser.js"},"_id":"multiformats@13.2.3","gitHead":"1061ae7115594008679e6a8f90c9f48e144724f1","_nodeVersion":"20.17.0","_npmVersion":"10.8.3","dist":{"integrity":"sha512-TXwZIhK1GYOM6zO4H8tRYgXi9wRrRl+MSa3PY5DZaD7YdUMLYLXRbRTJwtCrqeDW8dLhzO9ehlC7A8vi6dMJyA==","shasum":"c1b6c52197499696b551f8a0b2d910b85ff614be","tarball":"http://registry-npm.ywwl.com/multiformats/download/multiformats-13.2.3.tgz","fileCount":187,"unpackedSize":322529,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIG2ii0Hfd5+wrYBaGht9q4mzQubDh94GQJ2yPDqRb7M8AiATIVkH06y0bJaz51B9FxUgU3vv6oWrR+AiMUyGUTWkgg=="}],"size":67763,"noattachment":false,"key":"/multiformats/-/multiformats-13.2.3.tgz"},"_npmUser":{"name":"npm-service-account-multiformats","email":"npm-service-account+multiformats@ipfs.tech"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/multiformats_13.2.3_1726167200578_0.6634385399180174"},"_hasShrinkwrap":false,"readme":"[![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/actions/workflow/status/multiformats/js-multiformats/js-test-and-release.yml?branch=master\\&style=flat-square)](https://github.com/multiformats/js-multiformats/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)\n\n> Interface for multihash, multicodec, multibase and CID\n\n# About\n\n<!--\n\n!IMPORTANT!\n\nEverything in this README between \"# About\" and \"# Install\" is automatically\ngenerated and will be overwritten the next time the doc generator is run.\n\nTo make changes to this section, please update the @packageDocumentation section\nof src/index.js or src/index.ts\n\nTo experiment with formatting, please run \"npm run docs\" from the root of this\nrepo and examine the changes made.\n\n-->\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```TypeScript\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```TypeScript\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```TypeScript\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```TypeScript\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```TypeScript\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```TypeScript\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```TypeScript\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```TypeScript\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```TypeScript\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# Install\n\n```console\n$ npm i multiformats\n```\n\n## Browser `<script>` tag\n\nLoading this module through a script tag will make it's exports available as `Multiformats` in the global namespace.\n\n```html\n<script src=\"https://unpkg.com/multiformats/dist/index.min.js\"></script>\n```\n\n# API Docs\n\n- <https://multiformats.github.io/js-multiformats>\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","publish_time":1726167200799,"maintainers":[{"name":"rvagg","email":"r@va.gg"},{"name":"npm-service-account-multiformats","email":"npm-service-account+multiformats@ipfs.tech"}],"_cnpm_publish_time":1726167200799,"dist-tags":{"latest":"14.0.8","next":"10.0.0-pre.3"}}