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

cosmic-auth

v1.0.0

Published

An npm package for generating passwords using truly random numbers from cosmic radiation via cTRNG

Downloads

9

Readme

Cosmic Auth

A Node.js package that generates passwords using truly random numbers from the cTRNG API.

Installation

npm install cosmic-auth

Environment Variables

Create a .env file in your project root with the following variables:

# Auth0 credentials for getting access token
ORBITPORT_API_URL=https://dev-1usujmbby8627ni8.us.auth0.com
ORBITPORT_AUTH_URL=https://op.spacecomputer.io
ORBITPORT_CLIENT_ID=your-client-id
ORBITPORT_CLIENT_SECRET=your-client-secret

Getting an Access Token

Before using the package, you need to get an access token from Auth0. Here's how:

  1. Make sure your .env file is set up with the correct credentials
  2. Run the following script to get your access token:
require('dotenv').config();
const fetch = require('node-fetch');

(async () => {
  try {
    const url = `${process.env.ORBITPORT_API_URL}/oauth/token`;
    const body = {
      client_id: process.env.ORBITPORT_CLIENT_ID,
      client_secret: process.env.ORBITPORT_CLIENT_SECRET,
      audience: `${process.env.ORBITPORT_AUTH_URL}/api`,
      grant_type: "client_credentials"
    };
    const res = await fetch(url, {
      method: "POST",
      headers: { "content-type": "application/json" },
      body: JSON.stringify(body)
    });
    const data = await res.json();
    console.log(data);
  } catch (err) {
    console.error("Error:", err);
  }
})();

The response will include your access token:

{
  "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IlRRaDYtdGZhTmxhNV9KeGtDeVNKZyJ9...",
  "expires_in": 86400,
  "token_type": "Bearer"
}

Usage

import { generatePassword } from 'cosmic-auth';

// Generate a password with default options
const password = await generatePassword();

// Or with custom options
const customPassword = await generatePassword({
  length: 16,
  includeUppercase: true,
  includeNumbers: true,
  includeSpecialChars: true
});

API

generatePassword(options?: PasswordOptions): Promise

Generates a random password using the cTRNG API.

Options

  • length (number): Length of the password (default: 12)
  • includeUppercase (boolean): Include uppercase letters (default: true)
  • includeNumbers (boolean): Include numbers (default: true)
  • includeSpecialChars (boolean): Include special characters (default: true)

Demo App

The demo app shows how to use the package in a Next.js application. It features a beautiful signup form with automatic password generation.

Key Features

  • Automatic password generation on first focus
  • Manual password generation with refresh button
  • Password suggestion with "Use this" option
  • Form validation and success feedback
  • Modern, responsive UI with Tailwind CSS

Implementation

The demo consists of two main files:

  1. Frontend (src/app/page.tsx):

    • Signup form with name, email, DOB, gender, and password fields
    • Password field with auto-generation on first focus
    • Refresh icon button for manual generation
    • Password suggestion display
    • Form submission handling
  2. Backend (src/app/api/generate/route.ts):

    • API route for password generation
    • Default password options
    • Error handling
    • Response formatting

How It Works

  1. First Focus Generation:

    const handlePasswordFocus = () => {
      if (!hasGenerated.current && !formData.password) {
        generatePassword();
      }
    };
  2. Manual Generation:

    <button
      type="button"
      onClick={generatePassword}
      className="absolute right-2 top-1/2 -translate-y-1/2 p-1"
    >
      <ArrowPathIcon className={`h-5 w-5 ${loading ? 'animate-spin' : ''}`} />
    </button>
  3. Password Suggestion:

    {suggestedPassword && (
      <div className="mt-2 p-2 bg-gray-50 rounded-md">
        <p className="text-sm text-black">Suggested password:</p>
        <div className="flex items-center justify-between gap-2">
          <code className="text-sm font-mono">{suggestedPassword}</code>
          <button onClick={() => setFormData({ ...formData, password: suggestedPassword })}>
            Use this
          </button>
        </div>
      </div>
    )}

Running the Demo

  1. Clone the repository
  2. Navigate to the demo directory:
    cd cosmic-auth-demo/cosmic-auth-demo
  3. Install dependencies:
    npm install
  4. Create a .env file with your Orbitport credentials
  5. Start the development server:
    npm run dev

The demo will be available at http://localhost:3000.

License

MIT