1
- # js-multihashing-async
1
+ # js-multihashing-async <!-- omit in toc -->
2
2
3
3
[ ![ ] ( https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square )] ( http://ipn.io )
4
4
[ ![ ] ( https://img.shields.io/badge/project-multiformats-blue.svg?style=flat-square )] ( https://github.com/multiformats/multiformats )
5
5
[ ![ ] ( https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square )] ( https://webchat.freenode.net/?channels=%23ipfs )
6
6
[ ![ Coverage Status] ( https://coveralls.io/repos/github/multiformats/js-multihashing-async/badge.svg?branch=master )] ( https://coveralls.io/github/multiformats/js-multihashing-async?branch=master )
7
7
[ ![ Travis CI] ( https://flat.badgen.net/travis/ipfs/js-multihashing-async )] ( https://travis-ci.com/ipfs/js-multihashing-async )
8
- [ ![ Dependency Status] ( https://david-dm.org/multiformats/js-multihashing-async.svg?style=flat-square )] ( https://david-dm.org/multiformats/js-multihashing-async )
8
+ [ ![ Dependency Status] ( https://david-dm.org/multiformats/js-multihashing-async.svg?style=flat-square )] ( https://david-dm.org/multiformats/js-multihashing-async )
9
9
[ ![ js-standard-style] ( https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square )] ( https://github.com/feross/standard )
10
10
[ ![ ] ( https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square )] ( https://github.com/RichardLitt/standard-readme )
11
11
12
12
> Use all the functions in [ multihash] ( https://github.com/multiformats/multihash ) .
13
13
14
- ## Lead Maintainer
14
+ ## Lead Maintainer <!-- omit in toc -->
15
15
16
16
[ Hugo Dias] ( https://github.com/hugomrdias )
17
17
18
- ### Notice
19
- > This module is moving to async/await starting from 0.7.0.
18
+ ### Notice <!-- omit in toc -->
19
+ > This module is moving to async/await starting from 0.7.0.
20
20
> 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 ` .
21
21
22
- #### Wait, why, how is this different from Node ` crypto ` ?
22
+ #### Wait, why, how is this different from Node ` crypto ` ? <!-- omit in toc -->
23
23
24
24
This module just makes working with multihashes a bit nicer.
25
25
[ js-multihash] ( //github.com/multiformats/js-multihash ) is only for
@@ -29,21 +29,18 @@ It currently uses `crypto` and [`sha3`](https://github.com/phusion/node-sha3) in
29
29
In the browser [ ` webcrypto ` ] ( https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto )
30
30
and [ ` browserify-sha3 ` ] ( https://github.com/wanderer/browserify-sha3 ) are used.
31
31
32
- ## Table of Contents
33
-
34
- * [ Table of Contents] ( #table-of-contents )
35
- * [ Install] ( #install )
36
- + [ In Node.js through npm] ( #in-nodejs-through-npm )
37
- + [ Use in a browser with browserify, webpack or any other bundler] ( #use-in-a-browser-with-browserify-webpack-or-any-other-bundler )
38
- + [ Use in a browser Using a script tag] ( #use-in-a-browser-using-a-script-tag )
39
- - [ Gotchas] ( #gotchas )
40
- * [ Usage] ( #usage )
41
- * [ Examples] ( #examples )
42
- + [ Multihash output] ( #multihash-output )
43
- * [ API] ( #api )
44
- * [ Maintainers] ( #maintainers )
45
- * [ Contribute] ( #contribute )
46
- * [ License] ( #license )
32
+ ## Table of Contents <!-- omit in toc -->
33
+
34
+ - [ Install] ( #install )
35
+ - [ In Node.js through npm] ( #in-nodejs-through-npm )
36
+ - [ Use in a browser with browserify, webpack or any other bundler] ( #use-in-a-browser-with-browserify-webpack-or-any-other-bundler )
37
+ - [ Use in a browser Using a script tag] ( #use-in-a-browser-using-a-script-tag )
38
+ - [ Usage] ( #usage )
39
+ - [ Examples] ( #examples )
40
+ - [ Multihash output] ( #multihash-output )
41
+ - [ API] ( #api )
42
+ - [ Contribute] ( #contribute )
43
+ - [ License] ( #license )
47
44
48
45
## Install
49
46
@@ -78,24 +75,20 @@ available in the global namespace.
78
75
<script src =" https://unpkg.com/multihashing-async/dist/index.js" ></script >
79
76
```
80
77
81
- #### Gotchas
82
-
83
- 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 ) .
84
-
85
78
## Usage
86
79
87
80
``` js
88
81
const multihashing = require (' multihashing-async' )
89
- const buf = Buffer . from (' beep boop' )
82
+ const bytes = new TextEncoder (). encode (' beep boop' )
90
83
91
- const mh = await multihashing (buf , ' sha1' )
84
+ const mh = await multihashing (bytes , ' sha1' )
92
85
93
86
// Use `.digest(...)` if you want only the hash digest (drops the prefix indicating the hash type).
94
- const digest = await multihashing .digest (buf , ' sha1' )
87
+ const digest = await multihashing .digest (bytes , ' sha1' )
95
88
96
89
// Use `.createHash(...)` for the raw hash functions
97
90
const hash = multihashing .createHash (' sha1' )
98
- const digest = await hash (buf )
91
+ const digest = await hash (bytes )
99
92
```
100
93
101
94
## Examples
@@ -104,19 +97,19 @@ const digest = await hash(buf)
104
97
105
98
``` js
106
99
const multihashing = require (' multihashing-async' )
107
- const buf = Buffer . from (' beep boop' )
100
+ const bytes = new TextEncoder (). encode (' beep boop' )
108
101
109
- const mh = await multihashing (buf , ' sha1' )
102
+ const mh = await multihashing (bytes , ' sha1' )
110
103
console .log (mh)
111
- // => <Buffer 11 14 7c 83 57 57 7f 51 d4 f0 a8 d3 93 aa 1a aa fb 28 86 3d 94 21>
104
+ // => <Uint8Array 11 14 7c 83 57 57 7f 51 d4 f0 a8 d3 93 aa 1a aa fb 28 86 3d 94 21>
112
105
113
- const mh = await multihashing (buf , ' sha2-256' )
106
+ const mh = await multihashing (bytes , ' sha2-256' )
114
107
console .log (mh)
115
- // => <Buffer 12 20 90 ea 68 8e 27 5d 58 05 67 32 50 32 49 2b 59 7b c7 72 21 c6 24 93 e7 63 30 b8 5d dd a1 91 ef 7c>
108
+ // => <Uint8Array 12 20 90 ea 68 8e 27 5d 58 05 67 32 50 32 49 2b 59 7b c7 72 21 c6 24 93 e7 63 30 b8 5d dd a1 91 ef 7c>
116
109
117
- const mh = await multihashing (buf , ' sha2-512' )
110
+ const mh = await multihashing (bytes , ' sha2-512' )
118
111
console .log (mh)
119
- // => <Buffer 13 40 14 f3 01 f3 1b e2 43 f3 4c 56 68 93 78 83 77 1f a3 81 00 2f 1a aa 5f 31 b3 f7 8e 50 0b 66 ff 2f 4f 8e a5 e3 c9 f5 a6 1b d0 73 e2 45 2c 48 04 84 b0 ...>
112
+ // => <Uint8Array 13 40 14 f3 01 f3 1b e2 43 f3 4c 56 68 93 78 83 77 1f a3 81 00 2f 1a aa 5f 31 b3 f7 8e 50 0b 66 ff 2f 4f 8e a5 e3 c9 f5 a6 1b d0 73 e2 45 2c 48 04 84 b0 ...>
120
113
```
121
114
122
115
## API
0 commit comments