{"name":"multiformats","version":"4.6.0","keywords":["esm","build"],"author":{"url":"https://www.mikealrogers.com/","name":"Mikeal Rogers","email":"mikeal.rogers@gmail.com"},"license":"(Apache-2.0 AND MIT)","_id":"multiformats@4.6.0","maintainers":[{"name":"mikeal","email":"mikeal.rogers@gmail.com"}],"homepage":"https://github.com/multiformats/js-multiformats#readme","bugs":{"url":"https://github.com/multiformats/js-multiformats/issues"},"c8":{"exclude":["test/**","vendor/**"]},"dist":{"shasum":"6f0e524bb39e59204c1311bf5e702ea8f9bc20c3","tarball":"http://registry-npm.ywwl.com/multiformats/download/multiformats-4.6.0.tgz","fileCount":141,"integrity":"sha512-ZFTOb5y9hK7X+UFuqL3/2nyk3FeV+o+bIz2PysyDpBNriy3mRGb4YZqdy9+/uncxOb0MGks1eF2cYlEwHqU0tA==","signatures":[{"sig":"MEYCIQDl3+XWvlzQyvjpmQqQnPx/W2izONMnl4ZhMSMetlh/CwIhAMhvVfVu2aOjG/c/hxiTEoxunM3ebeNORpygO/u3Apqg","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":310814,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgRXNqCRA9TVsSAnZWagAAYFMP/iSDF0c27IKiyeO4U+zy\nk/d3gQ9AIcdnmqMOeut8l8ah/ksEFV3gD/AVSgaRu9fbWNgoxGbaDGeOEOEL\n8zI859K7gUku6FYQ0m8gNISUk1rJv2K0B+mJmALYCFDJCohBd9IQt8c2lldM\n4HMqVuNSpXM3LKoWWzVu5JFl/7xiFm7TE2N9FLaghUMvE3bx3Eoqrkg4CRqf\ntuBcWiyO/vTflOXPbSxnGGbizxyKhiksBdK82PEprYtrlF7zit2+c6BHJnCJ\nc8DH58jIy/fWGwvE9ssmLU7tPq5i1KkJ8OBF1fVGZa8v2TNN8e/HygJKsiYL\n8zGOjO62hCjPvST2HVlE4Ks437ez4dSpu3XHqY9T4WkxZv3L1KApcauQPIZt\n33jhBLwTksaCKQBTeV6yrkuWwKMoy7PR6/7voDz79Qpm8FRMSBohHO0+D4No\nG/9+slKiRCzHnazg+ntC6/E5BK2sRfEs+RhMhIjMMqRck4X0LuiLXcJprV2H\n5KDmALyPL44HUq3IagA8cSbbUkNREeMR6U0v+gwhhNSkJmH2rBTBCycSEhJo\n1UnRnO7cDCJiJJDEm3IeaVhmt4mMhKUxGT2af9mkWk/h3dHO5/VqwHKcPQeN\nax0eadW1Zf9l9boVetSJx8ER8f9EvVNs7fSY1qYmBTrYAMJjZIBAnSPFXtOB\n6iWV\r\n=ZSVE\r\n-----END PGP SIGNATURE-----\r\n","size":40810,"noattachment":false,"key":"/multiformats/-/multiformats-4.6.0.tgz"},"main":"./cjs/src/index.js","browser":{".":"./cjs/src/index.js","./cid":"./cjs/src/cid.js","./block":"./cjs/src/block.js","./legacy":"./cjs/src/legacy.js","./codecs/raw":"./cjs/src/codecs/raw.js","./codecs/json":"./cjs/src/codecs/json.js","./hashes/sha2":"./cjs/src/hashes/sha2-browser.js","./bases/base16":"./cjs/src/bases/base16.js","./bases/base32":"./cjs/src/bases/base32.js","./bases/base58":"./cjs/src/bases/base58.js","./bases/base64":"./cjs/src/bases/base64-browser.js","./codecs/codec":"./cjs/src/codecs/codec.js","./hashes/digest":"./cjs/src/hashes/digest.js","./hashes/hasher":"./cjs/src/hashes/hasher.js","./hashes/identity":"./cjs/src/hashes/identity.js"},"exports":{".":{"import":"./esm/src/index.js","browser":"./esm/src/index.js","require":"./cjs/src/index.js"},"./cid":{"import":"./esm/src/cid.js","browser":"./esm/src/cid.js","require":"./cjs/src/cid.js"},"./block":{"import":"./esm/src/block.js","browser":"./esm/src/block.js","require":"./cjs/src/block.js"},"./legacy":{"import":"./esm/src/legacy.js","browser":"./esm/src/legacy.js","require":"./cjs/src/legacy.js"},"./codecs/raw":{"import":"./esm/src/codecs/raw.js","browser":"./esm/src/codecs/raw.js","require":"./cjs/src/codecs/raw.js"},"./codecs/json":{"import":"./esm/src/codecs/json.js","browser":"./esm/src/codecs/json.js","require":"./cjs/src/codecs/json.js"},"./hashes/sha2":{"import":"./esm/src/hashes/sha2.js","browser":"./esm/src/hashes/sha2-browser.js","require":"./cjs/src/hashes/sha2.js"},"./bases/base16":{"import":"./esm/src/bases/base16.js","browser":"./esm/src/bases/base16.js","require":"./cjs/src/bases/base16.js"},"./bases/base32":{"import":"./esm/src/bases/base32.js","browser":"./esm/src/bases/base32.js","require":"./cjs/src/bases/base32.js"},"./bases/base58":{"import":"./esm/src/bases/base58.js","browser":"./esm/src/bases/base58.js","require":"./cjs/src/bases/base58.js"},"./bases/base64":{"import":"./esm/src/bases/base64-import.js","browser":"./esm/src/bases/base64-browser.js","require":"./cjs/src/bases/base64-import.js"},"./codecs/codec":{"import":"./esm/src/codecs/codec.js","browser":"./esm/src/codecs/codec.js","require":"./cjs/src/codecs/codec.js"},"./hashes/digest":{"import":"./esm/src/hashes/digest.js","browser":"./esm/src/hashes/digest.js","require":"./cjs/src/hashes/digest.js"},"./hashes/hasher":{"import":"./esm/src/hashes/hasher.js","browser":"./esm/src/hashes/hasher.js","require":"./cjs/src/hashes/hasher.js"},"./hashes/identity":{"import":"./esm/src/hashes/identity.js","browser":"./esm/src/hashes/identity.js","require":"./cjs/src/hashes/identity.js"}},"scripts":{"lint":"standard","test":"npm run lint && npm run test:node && npm run test:cjs && npm run test:ts","build":"npm run build:js && npm run build:types","check":"tsc --noEmit --noErrorTruncation","publish":"npm_config_yes=true npx ipjs@latest publish","test:ts":"npm run build:types && npm run test --prefix test/ts-use","build:js":"npm_config_yes=true npx ipjs@latest build --tests","coverage":"c8 --reporter=html mocha test/test-*.js && npm_config_yes=true npx st -d coverage -p 8080","test:cjs":"npm run build:js && mocha dist/cjs/node-test/test-*.js && npm run test:cjs:browser","test:node":"hundreds mocha test/test-*.js","build:types":"tsc --emitDeclarationOnly --declarationDir dist/types","build:vendor":"npm run build:vendor:varint && npm run build:vendor:base-x","test:node-v12":"mocha test/test-*.js && npm run test:cjs","test:cjs:browser":"polendina --page --worker --serviceworker --cleanup dist/cjs/browser-test/test-*.js","build:vendor:base-x":"npx brrp -x @multiformats/base-x > vendor/base-x.js","build:vendor:varint":"npx brrp -x varint > vendor/varint.js"},"_npmUser":{"name":"mikeal","email":"mikeal.rogers@gmail.com"},"standard":{"ignore":["dist","vendor"]},"repository":{"url":"git+https://github.com/multiformats/js-multiformats.git","type":"git"},"_npmVersion":"6.14.11","description":"Interface for multihash, multicodec, multibase and CID","directories":{"test":"test"},"_nodeVersion":"12.21.0","dependencies":{"cids":"^1.0.2","buffer":"^5.6.1","lodash.transform":"^4.6.0"},"typesVersions":{"*":{"*":["types/*"]}},"_hasShrinkwrap":false,"devDependencies":{"c8":"^7.3.5","mocha":"^8.2.0","hundreds":"0.0.9","standard":"^15.0.0","polendina":"^1.1.0","typescript":"^4.0.3","@types/node":"14.14.3","@typescript-eslint/parser":"^4.6.0","@typescript-eslint/eslint-plugin":"^4.6.0"},"_npmOperationalInternal":{"tmp":"tmp/multiformats_4.6.0_1615164265475_0.9001628039117002","host":"s3://npm-registry-packages"},"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":1615164265632,"_cnpm_publish_time":1615164265632,"dist-tags":{"latest":"14.0.8","next":"10.0.0-pre.3"}}