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

bcrypt-edge

v0.0.6

Published

Bcrypt implementation specifically for web workers

Downloads

1,271

Readme

bcrypt-edge

npm

ESM Edge/worker conversion for bcrypt.js.

Description

This is a re-implementation of Bcrypt specifically for web workers, in particular Cloudflare. The following differences can be observed from the source library:

  • The package is now an ESM, so it can easily be bundled
  • All async methods have been removed. These don't work in a Web Worker environment, so they were removed.
    • Perhaps there is some method of re-introducing them, but the originals relied upon process.nextTick
    • Additionally in a worker scenario, each request is theoretically isolated anyway so async isn't as impactful
  • Unit tests were preserved/translated as best as they could be
    • Tests are run against the Cloudflare crypto compatibility layer via Miniflare
    • No discrepencies between the original implementation and this one have been observed

Care was taken to disturb as little as possible with the initial implementation.

Usage

Usage is similar to the original library, except it's an ESM worker module now and has no async methods.

import {
  genSaltSync,
  hashSync,
  compareSync,
  getRounds,
  getSaltSync,
} from 'bcrypt-edge';

// Hashing
const salt = bcrypt.genSaltSync(10);
const hash = bcrypt.hashSync('B4c0//', salt);

// Create Salt+Hash in one line
const hash = bcrypt.hashSync('bacon', 8);

// Comparing
bcrypt.compareSync('B4c0//', hash); // true
bcrypt.compareSync('not_bacon', hash); // false

Benchmarks

Running bcrypt-edge in Miniflare against the original bcrypt package, the benchmarks are as follows. It is very likely that platform specific inhancements could be made to improve performace of bcrypt-edge.

| Library | Rounds | Hash Time | | ----------- | ------ | --------- | | bcryptjs | 8 | 20ms | | bcrypt-edge | 8 | 35ms | | bcryptjs | 9 | 40ms | | bcrypt-edge | 9 | 72ms | | bcryptjs | 10 | 81ms | | bcrypt-edge | 10 | 143ms | | bcryptjs | 11 | 161ms | | bcrypt-edge | 11 | 278ms | | bcryptjs | 12 | 326ms | | bcrypt-edge | 12 | 564ms | | bcryptjs | 13 | 653ms | | bcrypt-edge | 13 | 1138ms | | bcryptjs | 14 | 1316ms | | bcrypt-edge | 14 | 2266ms | | bcryptjs | 15 | 2646ms | | bcrypt-edge | 15 | 4498ms |