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 🙏

© 2026 – Pkg Stats / Ryan Hefner

xsalsa20-csprng

v2.0.5

Published

CSPRNG and crypto library powered by XSalsa20

Downloads

29

Readme

xsalsa20-csprng NPM Version

CSPRNG and crypto library powered by XSalsa20. Small, fast, supports both browsers and Node.js, and optimized for CSPRNG usage.

pnpm add xsalsa20-csprng

This library is optimized to be used as CSPRNG rather than encrypting large data. Thus, this library doesn't contain native code or webassembly binding to reduce FFI overhead.

Usage

class XSalsa20CSPRNG

See reference for the further details.

import XSalsa20CSPRNG from 'xsalsa20-csprng'

const rng = new XSalsa20CSPRNG()

// Random 32bit int (-2147483648 ≤ x < 2147483648), takes about 85ns per each call
const i = rng.randomInt32()
// Random 32bit unsigned int (0 ≤ x < 4294967296)
const u = rng.randomUint32()
// Random int of desired range (0 ≤ x < 10)
const n = rng.uniformInt(10)

// You can use fixed nonce and key
const nonce = new Uint8Array([/* nonce with 24 bytes */])
const key = new Uint8Array([/* key with 32 bytes */])
const deterministic = XSalsa20CSPRNG.of(nonce, key)
// Fixed nonce and key will result in deterministic output
console.log(deterministic.randomInt32())
console.log(deterministic.randomInt32())
console.log(deterministic.randomInt32())

class XSalsa20

See reference for the further details.

import { XSalsa20 } from 'xsalsa20-csprng'

const nonce = new Uint8Array([/* nonce with 24 bytes */])
const key = new Uint8Array([/* key with 32 bytes */])

// Encrypt
const encoder = new XSalsa20(nonce, key)
const plaintext = Uint8Array.from('message')
const ciphertext = encoder.update(plaintext)

// Decrypt : same with encryption
const decoder = new XSalsa20(nonce, key)
const decrypted = decoder.update(ciphertext)
// plaintext and decrypted have same contents

// You can retrieve XSalsa20 streams if you want
const gen = new XSalsa20(nonce, key)
console.log(gen.stream(64))
console.log(gen.stream(64))