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

r-secure-token

v1.0.5

Published

R secure token generation library using AES-GCM and Ed25519

Downloads

35

Readme

R-Secure-Token

🔐 A secure alternative to JWT, using AES-256-GCM encryption and Ed25519 digital signatures for authentication and authorization.

R-Secure-Token provides a high-security approach for token generation and verification, ensuring tamper-proof and encrypted payloads.


🌟 Features

AES-256-GCM Encryption – Strong encryption for payload security.
Ed25519 Signatures – Prevents forgery and tampering.
Replay Attack Prevention – Unique nonce per token.
JWT Alternative – Secure and stateless authentication.
High Performance – Optimized for speed and security.


📦 Installation

Install via NPM:

npm install r-secure-token

or with Yarn:

yarn add r-secure-token

🚀 Usage

1️⃣ Generating a Secure Token

import { RSecureToken } from 'r-secure-token';

(async () => {
  const tokenService = new RSecureToken();
  const payload = { data: { userId: 123 }, exp: Date.now() + 60000 }; // 1-minute expiry
  const tokenData = await tokenService.generateToken(payload);

  console.log('Token:', tokenData.token);
  console.log('Signature:', tokenData.signature);
})();

2️⃣ Verifying & Decrypting a Secure Token

import { RSecureToken } from 'r-secure-token';

(async () => {
  const tokenService = new RSecureToken();
  const { token, signature } = /* Token received from user */;
  
  const verifiedPayload = await tokenService.verifyToken(token, signature);

  if (verifiedPayload) {
    console.log('Valid Token:', verifiedPayload);
  } else {
    console.log('Invalid or Expired Token!');
  }
})();

🔬 How It Works

1. Token Generation

  • Encrypts the payload using AES-256-GCM.
  • Generates a secure nonce for each token.
  • Signs the encrypted token using Ed25519.

2. Token Verification

  • Checks the Ed25519 signature for authenticity.
  • Decrypts the token using AES-256-GCM.
  • Validates token expiration.

🔐 Security Advantages Over JWT

| Feature | JWT (JSON Web Tokens) | R-Secure-Token | |----------------------|----------------------------|----------------------| | Encryption | ❌ No built-in encryption | ✅ AES-256-GCM | | Signature Type | RSA / HMAC / ECDSA | ✅ Ed25519 | | Tamper Protection| ✅ Yes | ✅ Yes | | Readable Payload | ❌ Exposed (Base64-encoded JSON) | ✅ Encrypted | | Replay Attack Resistance | ❌ None | ✅ Unique nonce per token | | Verification Type | Requires shared secret (HMAC) or public-private keypair | ✅ Uses asymmetric cryptography |


📄 API Reference

new RSecureToken(secretKey?: Buffer)

Creates a new instance of RSecureToken. If no secret key is provided, a random one is generated.

generateToken(payload: TokenPayload): Promise

Creates a secure, signed token.

Parameters:

  • payload (object) – The data to include in the token, including an exp (expiration timestamp).

Returns:

{
  token: string;     // Encrypted token
  signature: string; // Ed25519 signature
}

verifyToken(token: string, signature: string): Promise<TokenPayload | null>

Verifies and decrypts the token if valid.

Parameters:

  • token (string) – The encrypted token.
  • signature (string) – The digital signature for verification.

Returns:

  • Valid: Returns the decrypted payload object.
  • Invalid: Returns null.

Example Response:

{
  data: { userId: 123 },
  exp: 1700000000000
}

⚠️ Best Practices

🔹 Store Secret Keys Securely: Never hardcode them in your source code. Use environment variables or a secure key management system.
🔹 Rotate Keys Periodically: Regularly update encryption and signing keys to minimize security risks.
🔹 Use Short-Lived Tokens: Prevent token abuse by setting short expiration times (exp).
🔹 Avoid Token Storage in Local Storage: Instead, store tokens in HTTP-only cookies or secure storage solutions.


📜 License

This project is licensed under the MIT License.


📞 Support & Contributions

👨‍💻 Contributions are welcome! Feel free to submit pull requests or report issues on GitHub.
📧 Need Help? Open an issue or contact us!