UNPKG

1.63 kBMarkdownView Raw
1# blake2b-wasm
2
3Blake2b implemented in WASM
4
5```
6npm install blake2b-wasm
7```
8
9Works in browsers that support WASM and Node.js 8+.
10
11## Usage
12
13``` js
14var blake2b = require('blake2b-wasm')
15
16if (!blake2b.SUPPORTED) {
17 console.log('WebAssembly not supported by your runtime')
18}
19
20blake2b.ready(function (err) {
21 if (err) throw err
22
23 var hash = blake2b()
24 .update(Buffer.from('hello')) // pass in a buffer or uint8array
25 .update(Buffer.from(' '))
26 .update(Buffer.from('world'))
27 .digest('hex')
28
29 console.log('Blake2b hash of "hello world" is %s', hash)
30})
31```
32
33## API
34
35#### `var hash = blake2b([digestLength], [key], [salt], [personal])`
36
37Create a new hash instance. `digestLength` defaults to `32`.
38
39#### `hash.update(data)`
40
41Update the hash with a new piece of data. `data` should be a buffer or uint8array.
42
43#### `var digest = hash.digest([enc])`
44
45Digest the hash.
46
47#### `var promise = blake2b.ready([cb])`
48
49Wait for the WASM code to load. Returns the WebAssembly instance promise as well for convenience.
50You have to call this at least once before instantiating the hash.
51
52## Browser demo
53
54There is a browser example included in [example.html](example.html) and [example.js](example.js).
55
56## Contributing
57
58The bulk of this module is implemented in WebAssembly in the [blake2b.wat](blake2b.wat) file.
59The format of this file is S-Expressions that can be compiled to their binary WASM representation by doing
60
61```
62# also available as `npm run compile`
63wast2wasm blake2b.wat -o blake2b.wasm
64```
65
66If you do not have `wast2wasm` installed follow the instructions here, https://github.com/WebAssembly/wabt
67
68## License
69
70MIT