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

@earthbucks/blake3

v0.9.0

Published

Inline wasm blake3 for EarthBucks.

Downloads

36

Readme

@earthbucks/blake3

@earthbucks/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 @earthbucks/blake3

# Using yarn
yarn add @earthbucks/blake3

# Using pnpm
pnpm add @earthbucks/blake3

Usage

This package exposes three main functions: blake3_hash, double_blake3_hash, and blake3_mac. Each function takes Uint8Array inputs and returns a Uint8Array result.

1. Hashing Data with blake3_hash

import { blake3_hash } from '@earthbucks/blake3';

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

console.log(hash); // Uint8Array output

2. Double Hash with double_blake3_hash

import { double_blake3_hash } from '@earthbucks/blake3';

const data = new Uint8Array([104, 101, 108, 108, 111]);
const doubleHash = double_blake3_hash(data);

console.log(doubleHash); // Uint8Array output

3. Message Authentication Code (MAC) with blake3_mac

import { blake3_mac } from '@earthbucks/blake3';

const key = new Uint8Array(32); // Replace with your 32-byte key
const data = new Uint8Array([104, 101, 108, 108, 111]);
const mac = blake3_mac(key, data);

console.log(mac); // Uint8Array output

API Reference

/**
 * Hashes the input data using BLAKE3.
 * @param {Uint8Array} data - Input data to hash.
 * @returns {Uint8Array} - BLAKE3 hash of the input data.
 */
export function blake3_hash(data: Uint8Array): Uint8Array;

/**
 * Applies BLAKE3 hash twice to the input data.
 * @param {Uint8Array} data - Input data to double-hash.
 * @returns {Uint8Array} - Result of applying BLAKE3 twice.
 */
export function double_blake3_hash(data: Uint8Array): Uint8Array;

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

TypeScript Support

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

import { blake3_hash } from '@earthbucks/blake3';

const data: Uint8Array = new Uint8Array([1, 2, 3, 4]);
const hash: Uint8Array = blake3_hash(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.