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

@very-amused/argon2-wasm

v0.3.5

Published

Implementation of the argon2 key derivation function using WebAssembly and Typescript, to be run clientside in web applications.

Downloads

19

Readme

@very-amused/argon2-wasm

WebAssembly/Typescript Bindings for Biryukov, Dinu, and Khovratovich's Argon2 key derivation function for clientside use in web applications. For documentation see docs.

NPM

Argon2 Modes

Argon2i, Argon2d, and Argon2id are all supported. If unsure, Argon2i is recommended because of its security against side-channel attacks due to data-independent memory access.

Security

This library zeroes all memory used by default, but it is still required that users of this library understand and implement secure memory handling for returned data. Hash output should be zeroed a minimum of 3 times after use.

Web Worker

These bindings are called entirely by channel-based communication with a Web Worker. The compiled code for this worker is located in build/worker.js (and build/worker.min.js for production), these files must be self-hosted at a path on the origin where argon2 will be used. It may be desired to deliver a Content-Security-Policy header along with the script, as no CSP from the origin is enforced by default for Web Workers.

Errors

The web worker will never return an error through anything other than a standard message. To check if a message is an error, check if the code property is not equal to 0. Non-zero codes correspond to different errors, most of which are identical to argon2 upstream. See the ErrorCodes enum for details.

Usage

import { Argon2 } from '@very-amused/argon2-wasm'
import { makeSalt, base64 } from 'cs-crypto'

// 1. Open a connection to a new argon2 worker thread
const argon2 = new Argon2.WorkerConnection(
  new Worker('/argon2/worker.js') // Change to worker.min.js in production
)

// 2. Load the Argon2 WebAssembly
{
  const message = await argon2.postMessage({
    method: Argon2.Methods.LoadArgon2,
    params: {
      wasmRoot: '/argon2',
      simd: true, /* The worker will test SIMD support by validating {wasmRoot}/simd-test.wasm,
      and load a build with SIMD instructions if possible */
      pthread: false /* The worker will test shared memory support,
      and load a build with pthread/multithreading instructions if possible */
    }
  })
  if (message.code !== 0) {
    throw new Error(`failed to load argon2: code ${message.code}`)
  }
}

// 3. Collect input
const password = document.querySelector('input#password').value

// 4. Generate a cryptographically random 16 byte salt
const salt = makeSalt(16)

// 5. Determine time and memory costs
const timeCost = 3 // a 3 pass minimum is recommended by Dmitry Khovratovich
const memoryCost = 1024 * 128 // Memory cost is in # of KiB, i.e m = 1024 = 1MiB

// 6. Run argon2i
const result = await argon2.postMessage({
  method: Argon2.Methods.Hash2i, // Use Hash2d for argon2d, Hash2id for argon2id
  params: {
    password,
    salt,
    timeCost,
    memoryCost,
    threads: 1, // Number of threads to utilize, clamped to 1 on non-pthread builds
    hashLen: 32 // Desired output size (in bytes)
  }
})
if (result.code !== 0) {
  throw new Error(`failed to run argon2i: code ${result.code}`)
}

// 7. The hash result will be stored in the body property of the result
console.log(`hash result: ${base64.encode(result.body)}`)

// 8. Terminate the worker thread (this will also free resources associated with the wasm instance)
argon2.terminate()