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

timebasedcipher

v3.0.7

Published

Isomorphic time-based rotating encryption SDK using Web Crypto (AES-GCM + HKDF)

Readme

timebasedcipher

A lightweight, isomorphic (Node.js 18+ and modern browsers) library for secure token encryption and decryption using rotating keys.

It provides:

  • Secure encryption of JSON data
  • Automatic key rotation
  • Built-in integrity validation
  • Token expiration support
  • Replay protection
  • Compact URL-safe tokens
  • Zero external dependencies

Installation

npm install timebasedcipher
# or
yarn add timebasedcipher
# or
pnpm add timebasedcipher

Requirements

  • Node.js 18+ OR modern browser
  • A shared secret string
  • Same rotation interval used for encrypt and decrypt

Quick Start

import { encrypt, decrypt } from "timebasedcipher";

const secret = "mySuperSecret";
const intervalSeconds = 60;

const data = { userId: 123, role: "admin" };

// Encrypt
const token = await encrypt(data, secret, intervalSeconds);

// Decrypt
const result = await decrypt(token, secret, intervalSeconds);

console.log(result);

Token Behavior

Tokens created by this library:

  • Automatically expire
  • Cannot be tampered with
  • Cannot be reused (replay protection)
  • Are URL safe
  • Rotate keys automatically based on time interval

API Reference

encrypt(data, secret, intervalSeconds, options?)

Encrypts JSON data and returns a secure token.

Parameters

| Name | Type | Description | | ----------------- | ------ | ----------------------- | | data | any | JSON serializable value | | secret | string | Shared secret | | intervalSeconds | number | Key rotation interval | | options | object | Optional settings |

Options

| Name | Type | Default | Description | | ----------------------- | ------------------------------- | --------------- | --------------------- | | ttlSeconds | number | intervalSeconds | Token expiration time | | clockToleranceSeconds | number | 30 | Allowed clock drift | | env | "auto" \| "node" \| "browser" | auto | Runtime override |

Returns

Promise<string>

Secure encrypted token.


decrypt(token, secret, intervalSeconds, options?)

Decrypts and validates a token.

Parameters

| Name | Type | Description | | ----------------- | ------ | --------------------------- | | token | string | Token from encrypt | | secret | string | Same secret used to encrypt | | intervalSeconds | number | Same rotation interval | | options | object | Optional settings |

Returns

Promise<T> Original decrypted data.

Example With Options

const token = await encrypt(data, secret, 60, {
  ttlSeconds: 300,
  clockToleranceSeconds: 60,
});

const result = await decrypt(token, secret, 60);

Environment Usage

Node.js

await encrypt(data, secret, 60, { env: "node" });

Browser

await encrypt(data, secret, 60, { env: "browser" });

Auto Detect (default)

await encrypt(data, secret, 60);

Error Handling

Decryption may throw errors in these cases:

  • Token is invalid
  • Token has expired
  • Secret is incorrect
  • Token was already used
  • Token was modified
  • Unsupported token version

Common Use Cases

  • Session tokens
  • API authentication
  • Secure links
  • Temporary access tokens
  • Signed payload transport
  • Passwordless login links

Performance

Typical latency on modern hardware:

  • Encryption: ~0.3–1 ms
  • Decryption: ~0.3–1 ms

Security Notes

  • Keep your secret secure
  • Use sufficiently long secrets (32+ characters recommended)
  • Ensure system clocks are reasonably synchronized
  • For multi-server deployments, consider shared nonce storage

Environment Support

| Platform | Supported | | --------------- | --------- | | Node.js 18+ | Yes | | Modern Browsers | Yes | | React / Next.js | Yes | | Edge runtimes | Yes |


License

MIT License © 2026
Deb Kalyan Mohanty