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

string-singer

v1.0.2

Published

A lightweight, secure, and runtime-agnostic library for signing and unsigning strings (such as cookie values) using HMAC-SHA256. It supports Node.js, Deno, Bun, and modern Web Browsers natively.

Readme

string-singer

A lightweight, secure, and runtime-agnostic library for signing and unsigning strings (such as cookie values) using HMAC-SHA256. It supports Node.js, Deno, Bun, and modern Web Browsers natively.

Inspired by and compatible in spirit with tj/node-cookie-signature, but modernized with TypeScript first and native Web Cryptography support.

Features

  • Runtime Agnostic: Seamlessly runs on Node.js, Deno, Bun, and standard Web browsers.
  • Web Cryptography API: Leverages the native globalThis.crypto.subtle API for high-performance and standard-compliant browser/edge environments.
  • Fast Synchronous Fallbacks: Provides a dedicated, synchronous Node.js adapter using the native node:crypto library.
  • Timing-Attack Safe: Employs constant-time comparisons (timingSafeEqual in Node, subtle.verify in Web Crypto) to defend against timing attacks.
  • TypeScript First: Full type safety and support out-of-the-box.

Installation

Install using your preferred package manager:

npm install string-singer
# or
bun add string-singer
# or
pnpm add string-singer

Usage

🟢 Node.js (Sync) — Default Entry Point

The default entry point exports synchronous versions of sign and unsign using the native node:crypto module.

import { sign, unsign } from 'string-singer';

const secret = 'keyboard cat'; // string, NodeJS.ArrayBufferView, or KeyObject

// Sign a value
const signed = sign('hello', secret);
console.log(signed); // "hello.XXXXX..."

// Unsign and verify a value
const unsigned = unsign(signed, secret);
console.log(unsigned); // "hello" (or false if tampered)

🌐 Universal (Async) — Browser, Deno, Bun, Edge

For Browser, Deno, Bun, or Edge environments requiring the Web Cryptography API, import from the appropriate subpath:

import { sign, unsign } from 'string-singer/browser'; // or string-singer/deno /bun

const secret = 'keyboard cat'; // string, BufferSource, or CryptoKey

// Sign a value
const signed = await sign('hello', secret);
console.log(signed); // "hello.XXXXX..."

// Unsign and verify a value
const unsigned = await unsign(signed, secret);
console.log(unsigned); // "hello" (or false if tampered)

Architecture & Exports

The library is structured as follows:

  • Root (string-singer): The default entry point. Re-exports the synchronous Node.js implementation (runtimes/node.ts).
  • Node.js (string-singer/node): Re-exports the synchronous Node.js implementation.
  • Browser (string-singer/browser): Asynchronous Browser-specific Web Cryptography adapter, delegating to:
    • runtimes/browser.subtle.ts (SubtleCrypto raw key import)
    • runtimes/browser.cryptokey.ts (CryptoKey signing and verification)
  • Deno (string-singer/deno): Asynchronous Deno adapter re-exporting the browser implementation.
  • Bun (string-singer/bun): Asynchronous Bun adapter re-exporting the browser implementation.
  • Utilities (utils/base64.ts): Contains URL-safe base64 helper functions (bytesToBase64Url, base64UrlToBytes).

Development & Testing

Each runtime adapter contains its own test suite:

  • Node.js & Browser (Vitest):

    npm test
  • Deno (native test runner):

    deno test --allow-net runtimes/deno.test.ts
  • Bun (native test runner):

    bun test runtimes/bun.test.ts
  • Running the Demo Locally (Development Mode):

    npm run dev:demo

License

MIT