# js-multihashing-async
[](http://ipn.io)
[](https://github.com/multiformats/multiformats)
[](https://webchat.freenode.net/?channels=%23ipfs)
[](https://coveralls.io/github/multiformats/js-multihashing-async?branch=master)
[](https://travis-ci.com/ipfs/js-multihashing-async)
[](https://david-dm.org/multiformats/js-multihashing-async)
[](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)
### Notice
> This module is moving to async/await starting from 0.7.0.
> The last minor version to support callbacks is 0.6.0, any backports will merged to the branch `callbacks` and released under `>0.6.0 <0.7.0`.
#### Wait, why, how is this different from Node `crypto`?
This module just makes working with multihashes a bit nicer.
[js-multihash](//github.com/multiformats/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.
It currently uses `crypto` and [`sha3`](https://github.com/phusion/node-sha3) in Node.js.
In the browser [`webcrypto`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto)
and [`browserify-sha3`](https://github.com/wanderer/browserify-sha3) are used.
## Table of Contents
* [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)
* [API](#api)
* [Maintainers](#maintainers)
* [Contribute](#contribute)
* [License](#license)
## Install
### In Node.js through npm
```bash
$ npm install --save multihashing-async
```
```js
const multihashing = require('multihashing-async')
```
### 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
const multihashing = require('multihashing-async')
```
### 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
const multihashing = require('multihashing-async')
const buf = Buffer.from('beep boop')
const mh = await multihashing(buf, 'sha1')
// Use `.digest(...)` if you want only the hash digest (drops the prefix indicating the hash type).
const digest = await multihashing.digest(buf, 'sha1')
// Use `.createHash(...)` for the raw hash functions
const hash = multihashing.createHash('sha1')
const digest = await hash(buf)
```
## Examples
### Multihash output
```js
const multihashing = require('multihashing-async')
const buf = Buffer.from('beep boop')
const mh = await multihashing(buf, 'sha1')
console.log(mh)
// =>
const mh = await multihashing(buf, 'sha2-256')
console.log(mh)
// =>
const mh = await multihashing(buf, 'sha2-512')
console.log(mh)
// =>
```
## API
https://multiformats.github.io/js-multihashing-async/
## Contribute
Contributions welcome. Please check out [the issues](https://github.com/multiformats/js-multihashing-async/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) © Protocol Labs Inc.