Blake2b implemented in WASM
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
Mathias Buus 7d8efa4f71 2.4.0 2 years ago
.gitignore Bundle WAT using `wasm-tools` (#17) 2 years ago
.travis.yml pass @emilbayes' test vectors 7 years ago
LICENSE first commit 7 years ago
README.md Bundle WAT using `wasm-tools` (#17) 2 years ago
blake2b.js Bundle WAT using `wasm-tools` (#17) 2 years ago
blake2b.wat Use offset atom on stores and loads (#6) 6 years ago
example.html first commit 7 years ago
example.js Use `Buffer.from()` instead of `new Buffer` (#4) 6 years ago
generate-rounds.js style 7 years ago
index.js Bundle WAT using `wasm-tools` (#17) 2 years ago
package.json 2.4.0 2 years ago
test.js Add support for get/set of a partial hash (#16) 3 years ago

README.md

blake2b-wasm

Blake2b implemented in WASM

npm install blake2b-wasm

Works in browsers that support WASM and Node.js 8+.

Usage

var blake2b = require('blake2b-wasm')

if (!blake2b.SUPPORTED) {
  console.log('WebAssembly not supported by your runtime')
}

blake2b.ready(function (err) {
  if (err) throw err

  var hash = blake2b()
    .update(Buffer.from('hello')) // pass in a buffer or uint8array
    .update(Buffer.from(' '))
    .update(Buffer.from('world'))
    .digest('hex')

  console.log('Blake2b hash of "hello world" is %s', hash)
})

API

var hash = blake2b([digestLength], [key], [salt], [personal])

Create a new hash instance. digestLength defaults to 32.

hash.update(data)

Update the hash with a new piece of data. data should be a buffer or uint8array.

var digest = hash.digest([enc])

Digest the hash.

hash.getPartialHash()

Returns the current partial hash.

hash.setPartialHash(data)

Set the hash to a previously set hash. data should be the result of getPartialHash() (which returns uint8array)

var promise = blake2b.ready([cb])

Wait for the WASM code to load. Returns the WebAssembly instance promise as well for convenience. You have to call this at least once before instantiating the hash.

Browser demo

There is a browser example included in example.html and example.js.

Contributing

The bulk of this module is implemented in WebAssembly in the blake2b.wat file. To build the thin Javascript wrapper do:

npm run compile

License

MIT