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

@webbuf/blake3

v3.0.26

Published

Rust/wasm optimized blake3 hash & mac for the web, node.js, deno, and bun.

Downloads

916

Readme

@webbuf/blake3

@webbuf/blake3 is a lightweight, inline synchronous WebAssembly (WASM) implementation of the BLAKE3 hashing algorithm. This library allows for high-performance hashing directly in JavaScript, using WASM for speed, and works seamlessly in both browsers and Node.js.

This package is optimized for inline Base64 WASM to ensure synchronous loading without requiring separate binary files. This means you can use it in your code without worrying about async loading or managing external files. However, it does mean the files are slightly larger than if they were separate.

Features

  • BLAKE3 hashing: Fast, cryptographic hash function.
  • Inline WASM as Base64: No need to manage external binary files.
  • Synchronous WASM loading: Runs efficiently without async loading.
  • Works across Node.js and browsers: Same interface for both environments.

Installation

Install the package using your favorite package manager:

# Using npm
npm install @webbuf/blake3

# Using yarn
yarn add @webbuf/blake3

# Using pnpm
pnpm add @webbuf/blake3

Usage

This package exposes three main functions: blake3Hash, doubleBlake3Hash, and blake3Mac. Each function takes WebBuf inputs and returns a WebBuf result.

1. Hashing Data with blake3Hash

import { blake3Hash } from '@webbuf/blake3';

const data = new WebBuf([104, 101, 108, 108, 111]); // "hello"
const hash = blake3Hash(data);

console.log(hash.buf.toHex()); // hex output

2. Double Hash with doubleBlake3Hash

import { doubleBlake3Hash } from '@webbuf/blake3';

const data = new WebBuf([104, 101, 108, 108, 111]);
const doubleHash = doubleBlake3Hash(data);

console.log(doubleHash.buf.toHex()); // hex output

3. Message Authentication Code (MAC) with blake3Mac

import { WebBuf } from "webbuf";
import { blake3Hash } from '@webbuf/blake3';
import { FixedBuf } from "@webbuf/fixedbuf";

const key = FixedBuf.fromHex(32, '...'); // Replace with your 32-byte key
const data = WebBuf.fromHex('...'); // Replace with your input data
const mac = blake3Mac(key, data);

console.log(mac.buf.toHex()); // hex output

API Reference

/**
 * Hashes the input data using BLAKE3.
 * @param {WebBuf} data - Input data to hash.
 * @returns {FixedBuf<32>} - BLAKE3 hash of the input data.
 */
export function blake3Hash(data: WebBuf): FixedBuf<32>;

/**
 * Applies BLAKE3 hash twice to the input data.
 * @param {WebBuf} data - Input data to double-hash.
 * @returns {FixedBuf<32>} - Result of applying BLAKE3 twice.
 */
export function doubleBlake3Hash(data: WebBuf): FixedBuf<32>;

/**
 * Creates a BLAKE3-based MAC (Message Authentication Code).
 * @param {FixedBuf<32>} key - 32-byte key for the MAC.
 * @param {WebBuf} data - Input data to authenticate.
 * @returns {FixedBuf<32>} - Authentication tag for the input data.
 */
export function blake3Mac(key: FixedBuf<32>, data: WebBuf): FixedBuf<32>;

TypeScript Support

This library comes with built-in TypeScript definitions, so you get full type support out of the box. Example:

import { WebBuf } from "webbuf";
import { blake3Hash } from '@webbuf/blake3';
import { FixedBuf } from "@webbuf/fixedbuf";

const data: WebBuf = new WebBuf([1, 2, 3, 4]);
const hash: FixedBuf<32> = blake3Hash(data);

Compatibility

This library supports Node.js (v14+) and modern browsers that support WebAssembly (WASM). Since it loads the WASM module inline as Base64, there is no need to manage external .wasm files.


License

This project is licensed under the MIT License.


Contributing

We welcome contributions! Please open an issue or submit a pull request on GitHub if you have any improvements or bug fixes.