npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

highwayhash-wasm

v1.2.6

Published

HighwayHash WASM bindings for browser and node environments

Downloads

1,407

Readme

highwayhash-wasm

highwayhash-wasm

npm version npm downloads Github Actions CI License

JS bindings for browser and Node.js environment of the Rust implementation of HighwayHash, Google's fast, keyed, portable (output is hardware independent) and secure hash function.

Features

  • Run on Node.js and browser with same API
  • Zero dependencies
  • Prebuilt and optimized WASM binary
  • Generate hashes at over 2GB/s when running on SIMD enabled WebAssembly
  • Generate 64, 128 and 256 bit hashes
  • Output hash as string, hexadecimal string
  • Hash data in chunks

Install

Add highwayhash-wasm dependency to your project:

# using npm
npm i highwayhash-wasm

# using yarn
yarn add highwayhash-wasm

# using pnpm
pnpm add highwayhash-wasm

Usage

Use this method to generate hashes is the length of the data is not known in advance:

// import the library using esm or cjs syntax
import { useHighwayHash } from 'highwayhash-wasm'
const { useHighwayHash } = require('highwayhash-wasm')

// Some 32 byte key
const key = new Uint8Array(32).fill(8)
// Some data to hash
const data = Uint8Array.from([0])

// Load the wasm module which returns the the Highway object
const highway = await useHighwayHash({
  // Optional: pass a key and keep it hidden from attackers to ensure
  // unpredictability, and attackers can't mount a DoS attack
  key: key,
  // Optional: use SIMD for faster encryption, enabled by default
  simd: true
})

// 1. method - encrypt data with Highway and return the hash
const h1 = highway.hash64(data).toString()
console.log(h1) // 4652207699671410156

// 2. method - if the data to hash is not known, create a hasher, and append
// the data.
const hasher = highway.new(key)
hasher.append(data)
// After all data is appended, call the hash method to get the hash
// do not call any additional methods on the hasher after finalizing
const h2 = hasher.finalize64().toString()
console.log(h2) // 4652207699671410156

// 3. method - hash the data with separate key and data
const h3 = highway.hasher.hash64(key, data).toString()
console.log(h3) // 4652207699671410156

API

hasher

The hasher initializes with SIMD if supported.

hash

The following methods are available to output hashes:

toString

// returns the hash as a string
const hash = hasher.hash64(key, data).toString()
// 4652207699671410156

toHex

// returns the hash as a hexadecimal string
const hash = hasher.hash64(key, data).toHex()
// 408FF641204065EC

toBinary

// returns the hash as a binary string
const hash = hasher.hash64(key, data).toBinary()
// 100000010001111111101100100000100100000010000000110010111101100

toOctal

// returns the hash as an octal string
const hash = hasher.hash64(key, data).toOctal()
// 402177544044020062754

toBytes

// returns the hash as a Uint8Array
const hash = hasher.hash64(key, data).toBytes()
// Uint8Array(8) [236, 101, 64, 32, 65, 246, 143, 64]

toUint32Array

// returns the hash as a Uint32Array
const hash = hasher.hash64(key, data).toUint32Array()
// Uint32Array(1) [65]

toBigUint64Array

// returns the hash as a Uint64Array
const hash = hasher.hash64(key, data).toBigUint64Array()
// BigUint64Array(1) [4652207699671410156n]