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

@freesignal/crypto

v0.12.0

Published

Crypto package for Freesignal Protocol

Downloads

328

Readme

@freesignal/crypto

Crypto utilities for the FreeSignal Protocol.

This package provides a small wrapper around libsodium and msgpack to expose hashing, key derivation, authenticated encryption (secretbox), ECDH, EdDSA signing, UUID helpers and various encoding utilities.

Installation

Install from npm:

npm install @freesignal/crypto

The package depends on libsodium-wrappers, @msgpack/msgpack and uuid which are listed as dependencies and will be installed automatically.

Quick Start

Import the default crypto instance, in wich libsodium-wrappers and msgpack are imported dinamiccaly:

import crypto from '@freesignal/crypto';

// Hash some data
const data = crypto.Utils.encodeUTF8('hello');
const digest = crypto.hash(data);

// Generate random bytes
const r = crypto.randomBytes(16);

// Use Box (secretbox) to encrypt/decrypt
const key = crypto.Box.keyLength ? crypto.randomBytes(crypto.Box.keyLength) : crypto.randomBytes(32);
const nonce = crypto.randomBytes(crypto.Box.nonceLength);
const cipher = crypto.Box.encrypt(data, nonce, key);
const plain = crypto.Box.decrypt(cipher, nonce, key);

// ECDH keypair
const { publicKey, secretKey } = crypto.ECDH.keyPair();
const shared = crypto.ECDH.scalarMult(secretKey, publicKey);

// EdDSA signing
const ed = crypto.EdDSA.keyPair();
const sig = crypto.EdDSA.sign(data, ed.secretKey);
const ok = crypto.EdDSA.verify(sig, data, ed.publicKey);

// HKDF example
const prk = crypto.hash(data);
const derived = crypto.hkdf(prk, new Uint8Array(32).fill(0), 'context', 32);

// UUID
const id = crypto.UUID.generate();
console.log(id.toString());

// Encoding utilities (short helpers are exported in `utils` file)
const b64 = crypto.Utils.encodeBase64URL('hello');
const decoded = crypto.Utils.decodeBase64URL(b64);

Is possible to static import libsodium-wrappers and msgpack using:

import crypto from '@freesignal/crypto/static';

In JS versions prior to ES2017 you need to use:

import { createCrypto } from '@freesignal/crypto/legacy';

API Reference

Top-level default export: a ready-to-use Crypto instance.

Main methods and namespaces:

  • hash(message: Uint8Array, algorithm = 'blake2b') => Uint8Array
    • Blake2b-based generic hash (32 bytes).
  • pwhash(keyLength, password, salt, opsLimit, memLimit) => Uint8Array
    • Password-based key derivation (libsodium crypto_pwhash).
  • hmac(key, message, length = 32) => Uint8Array
    • HMAC-like construct using BLAKE2b.
  • hkdf(key, salt, info?, length = 32) => Uint8Array
    • HKDF implementation (extract+expand) built on BLAKE2b.
  • randomBytes(n) => Uint8Array
    • Secure random byte generator.

Namespaces:

  • Box (secretbox authenticated encryption)

    • keyLength, nonceLength
    • encrypt(msg, nonce, key) => Uint8Array
    • decrypt(msg, nonce, key) => Uint8Array | undefined
  • ECDH (Curve25519 shared secrets)

    • publicKeyLength, secretKeyLength
    • keyPair(secretKey?) => { publicKey, secretKey }
    • scalarMult(secretKey, publicKey) => Uint8Array
  • EdDSA (Ed25519 signing)

    • publicKeyLength, secretKeyLength, signatureLength
    • keyPair(secretKey?) => { publicKey, secretKey }
    • keyPairFromSeed(seed) => { publicKey, secretKey }
    • sign(msg, secretKey) => Uint8Array
    • verify(signature, message, publicKey) => boolean
    • toSecretECDHKey(secretKey) => Uint8Array
    • toPublicECDHKey(publicKey) => Uint8Array
  • UUID

    • generate() returns an object with toString(), toJSON() and bytes (Uint8Array)
    • stringify(arr, offset?), parse(uuid)
  • Utils (encoding, conversion, msgpack)

    • decodeUTF8, encodeUTF8
    • decodeBase64, encodeBase64
    • decodeBase64URL, encodeBase64URL
    • decodeHex, encodeHex
    • bytesToNumber, numberToBytes
    • compareBytes, concatBytes
    • encodeData, decodeData (msgpack encode/decode)

Additionally, src/utils.ts re-exports convenient helper functions for the Utils namespace so you can:

import { encodeData, decodeData, encodeBase64 } from '@freesignal/crypto/utils';

License

This project is released under the GNU GPL-3.0-or-later. See the LICENSE file for details.

Contributing

Create issues or PRs on the repository: https://github.com/christianbraghette/freesignal-crypto

If you want me to expand the README with API signatures, inline examples for each method, or usage from browsers, tell me which parts to expand.