⛔️ DEPRECATED: This module has been superseded by [multiformats](https://github.com/multiformats/js-multiformats)
======
js-multihashing
===============
[](http://ipn.io)
[](https://github.com/multiformats/multiformats)
[](https://webchat.freenode.net/?channels=%23ipfs)
[](https://coveralls.io/github/jbenet/js-multihashing?branch=master)
[](https://travis-ci.org/multiformats/js-multihashing)
[](https://circleci.com/gh/jbenet/js-multihashing)
[](https://david-dm.org/jbenet/js-multihashing) [](https://github.com/feross/standard)
[](https://github.com/RichardLitt/standard-readme)
> Use all the functions in [multihash](https://github.com/multiformats/multihash).
## Lead Maintainer
[Hugo Dias](https://github.com/hugomrdias)
#### Wait, why, how is this different from Node `crypto`?
This module just makes working with multihashes a bit nicer.
[js-multihash](//github.com/jbenet/js-multihash) is only for
encoding/decoding multihashes, and does not depend on other libs.
This module will depend on various implementations for each hash.
For now, it just uses `crypto`, but will use `sha3` and `blake2`, etc.
## Table of Contents
- [js-multihashing](#js-multihashing)
- [Lead Maintainer](#lead-maintainer)
- [Wait, why, how is this different from Node `crypto`?](#wait-why-how-is-this-different-from-node-crypto)
- [Table of Contents](#table-of-contents)
- [Install](#install)
- [In Node.js through npm](#in-nodejs-through-npm)
- [Use in a browser with browserify, webpack or any other bundler](#use-in-a-browser-with-browserify-webpack-or-any-other-bundler)
- [Use in a browser Using a script tag](#use-in-a-browser-using-a-script-tag)
- [Gotchas](#gotchas)
- [Usage](#usage)
- [Examples](#examples)
- [Multihash output](#multihash-output)
- [Raw digest output](#raw-digest-output)
- [Verify a multihash](#verify-a-multihash)
- [API](#api)
- [`multihashing(buf, func, length)`](#multihashingbuf-func-length)
- [`digest(buf, func, length)`](#digestbuf-func-length)
- [`createHash(func, length)`](#createhashfunc-length)
- [`verify(hash, buf)`](#verifyhash-buf)
- [`functions`](#functions)
- [Contribute](#contribute)
- [License](#license)
## Install
### In Node.js through npm
```bash
$ npm install --save multihashing
```
```js
var multihashing = require('multihashing')
```
### Use in a browser with browserify, webpack or any other bundler
The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
```js
var multihashing = require('multihashing')
```
### Use in a browser Using a script tag
Loading this module through a script tag will make the `multihashing` obj available in the global namespace.
```html
```
#### Gotchas
You will need to use Node.js `Buffer` API compatible, if you are running inside the browser, you can access it by `multihashing.Buffer` or you can install Feross's [Buffer](https://github.com/feross/buffer).
## Usage
```js
var multihashing = require('multihashing')
var buf = Buffer.from('beep boop')
// by default returns a multihash.
multihashing(buf, 'sha1')
// Use `.digest(...)` if you want only the hash digest (drops the prefix indicating the hash type).
multihashing.digest(buf, 'sha1')
// Use `.createHash(...)` for a `crypto.createHash` interface.
var h = multihashing.createHash('sha1')
h.update(buf)
h.digest()
```
## Examples
### Multihash output
```js
> var multihashing = require('multihashing')
> var buf = Buffer.from('beep boop')
> console.log(multihashing(buf, 'sha1'))
// =>
> console.log(multihashing(buf, 'sha2-256'))
// =>
> console.log(multihashing(buf, 'sha2-512'))
// =>
```
### Raw digest output
```js
> var multihashing = require('multihashing')
> var buf = Buffer.from('beep boop')
> console.log(multihashing.digest(buf, 'sha1'))
// =>
> console.log(multihashing.digest(buf, 'sha2-256'))
// =>
> console.log(multihashing.digest(buf, 'sha2-512'))
// =>
```
### Verify a multihash
```js
> const right = new Buffer('beep boop')
> const wrong = new Buffer('oops')
> const hash = multihashing(right, 'sha1')
> console.log(multihashing.verify(hash, right))
// => true
> console.log(multihashing.verify(hash, wrong))
// => false
```
## API
### `multihashing(buf, func, length)`
### `digest(buf, func, length)`
### `createHash(func, length)`
### `verify(hash, buf)`
### `functions`
An object mapping hexcodes to their hash functions.
## Contribute
Contributions welcome. Please check out [the issues](https://github.com/multiformats/js-multihashing/issues).
Check out our [contributing document](https://github.com/multiformats/multiformats/blob/master/contributing.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
## License
[MIT](LICENSE) © 2016 Protocol Labs Inc.