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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@smartforge/auth-core

v2.0.0

Published

SmartForge Authentication Engine - SIWE, JWT, and role-based permissions.

Readme

@smartforge/auth-core

SmartForge Authentication Engine - SIWE, JWT, and role-based permissions.

Installation

npm install @smartforge/auth-core
# or
pnpm add @smartforge/auth-core

Usage

Basic Setup

import { AuthService } from "@smartforge/auth-core";

const authService = new AuthService({
  jwt: {
    secret: process.env.JWT_SECRET!,
    expiresIn: "7d",
  },
  domain: "https://yourdomain.com",
});

Sign In with Wallet (SIWE)

import { generateSIWEMessage, verifySIWE } from "@smartforge/auth-core";

// Generate SIWE message
const message = generateSIWEMessage({
  domain: "yourdomain.com",
  address: "0x...",
  statement: "Sign in to SmartForge",
  uri: "https://yourdomain.com",
  version: "1",
  chainId: 8453,
  nonce: "random-nonce",
  issuedAt: new Date(),
});

// Verify SIWE message and signature
const result = verifySIWE(message, signature);
if (result.valid) {
  console.log("Verified address:", result.parsed?.address);
}

JWT Token Management

import {
  issueToken,
  verifyToken,
  hasRole,
  UserRole,
} from "@smartforge/auth-core";

// Issue a JWT token
const token = issueToken(
  {
    userId: "user-id",
    walletAddress: "0x...",
    role: UserRole.ADMIN,
  },
  {
    secret: process.env.JWT_SECRET!,
    expiresIn: "7d",
  }
);

// Verify token
const verification = verifyToken(token, {
  secret: process.env.JWT_SECRET!,
  expiresIn: "7d",
});

// Check role permissions
const canWrite = hasRole(UserRole.WRITER, UserRole.READER); // true
const canAdmin = hasRole(UserRole.READER, UserRole.ADMIN); // false

Complete Authentication Flow

const result = await authService.signInWithWallet(
  message,
  signature,
  async (address) => {
    // Get user by address from database
    return await db.getUserByAddress(address);
  },
  async (address) => {
    // Create new user if doesn't exist
    return await db.createUser({ address });
  }
);

if (result.success) {
  console.log("Token:", result.token);
  console.log("User:", result.user);
}

API

AuthService

Main authentication service class.

Methods:

  • signInWithWallet() - Authenticate with SIWE
  • signInWithEmail() - Email authentication (stub)
  • verifyToken() - Verify JWT token
  • checkPermission() - Check role permissions
  • generateSignInMessage() - Generate SIWE message

UserRole

Enum of user roles:

  • UserRole.ADMIN - Full access
  • UserRole.WRITER - Can create/modify
  • UserRole.READER - Read-only access

SIWE Functions

  • generateSIWEMessage() - Generate SIWE message
  • parseSIWEMessage() - Parse SIWE message string
  • verifySIWE() - Verify SIWE message and signature

JWT Functions

  • issueToken() - Create JWT token
  • verifyToken() - Verify JWT token
  • decodeToken() - Decode token without verification
  • hasRole() - Check role hierarchy

License

ISC