Giter Club home page Giter Club logo

blake2b-wasm's Introduction

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.

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. The format of this file is S-Expressions that can be compiled to their binary WASM representation by doing

wat2wasm blake2b.wat -o blake2b.wasm

To build the thin Javascript wrapper for the WASM module use wat2js:

# also available as `npm run compile`
wat2js blake2b.wat -o blake2b.js

If you do not have wat2wasm installed follow the instructions here, https://github.com/WebAssembly/wabt

License

MIT

blake2b-wasm's People

Contributors

addaleax avatar emilbayes avatar jamen avatar mafintosh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.