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

@protocolwealthos/auth

v0.2.0

Published

JWT session signing/verification, role-hierarchy guards, and workspace-domain restriction for advisor platforms

Readme

@protocolwealthos/auth

JWT session signing/verification, role-hierarchy guards, and workspace-domain restriction. Zero runtime dependencies.

Apache 2.0 · Patent Pending: USPTO #64/034,215 · part of pwos-core.

What's in the box

  • signSession / verifySession — HS256 JWT, hand-rolled in ~80 lines. Refuses non-HS256 algorithms (including alg: "none"), validates iat/exp strictly, uses timingSafeEqual on the signature compare. Designed to be auditable in one read.
  • createRoleGuard — numeric-rank role hierarchy with isAuthorizedFor / assertAuthorizedFor. Default tiers: GUEST < CLIENT < EMPLOYEE < ADVISOR < PARTNER < OWNER. Bring your own hierarchy if those don't fit.
  • isInWorkspaceDomain / assertWorkspaceDomain — restrict sign-in to one or more workspace email domains (e.g. your Google Workspace tenant). Case-insensitive; subdomains are not auto-allowed.

Install

pnpm add @protocolwealthos/auth

Quick start

import {
  signSession,
  verifySession,
  createRoleGuard,
  assertWorkspaceDomain,
} from "@protocolwealthos/auth";

const SECRET = process.env.SESSION_SECRET!; // 32+ random bytes per env

// At sign-in, after Google SSO succeeds:
assertWorkspaceDomain(googleUser.email, ["example.com"]);
const token = signSession(SECRET, {
  sub: googleUser.id,
  email: googleUser.email,
  role: "ADVISOR",
  ttlSeconds: 900, // 15 minutes
  iss: "pwos-core",
  aud: "advisor-platform",
});

// On every request:
const claims = verifySession(SECRET, request.cookies.session, {
  expectedIssuer: "pwos-core",
  expectedAudience: "advisor-platform",
});

const guard = createRoleGuard();
guard.assertAuthorizedFor(claims.role, "ADVISOR"); // throws if rank too low

Why HS256 only

This package's HS256 implementation lives in src/jwtSession.ts — about 80 lines including all validation. You can read the entire crypto path in one sitting. RS256 / EdDSA with key rotation across multiple verifiers is genuinely worth a full library; we don't ship that here. Use jose or jsonwebtoken if you need it.

What we do refuse explicitly:

  • alg: "none" — refused by alg check
  • Non-HS256 headers — refused by alg check
  • Tampered payloads — caught by signature compare (timingSafeEqual)
  • Expired tokens — exp validation with optional clock-skew
  • Future-dated tokens — iat validation
  • Missing sub / email / role / iat / expmissing_claim error
  • Issuer/audience drift — when you opt in via expectedIssuer / expectedAudience

Role hierarchy

import { createRoleGuard, STANDARD_ROLE_HIERARCHY } from "@protocolwealthos/auth";

// Default hierarchy: GUEST(0) < CLIENT(10) < EMPLOYEE(20) < ADVISOR(30) < PARTNER(40) < OWNER(50)
const standard = createRoleGuard();

// Custom hierarchy:
const custom = createRoleGuard({ READER: 1, WRITER: 2, ADMIN: 3 });
custom.isAuthorizedFor("WRITER", "READER"); // true

Workspace-domain restriction

import { assertWorkspaceDomain } from "@protocolwealthos/auth";

assertWorkspaceDomain("[email protected]", ["example.com"]); // ok
assertWorkspaceDomain("[email protected]", ["example.com"]); // throws — subdomains not auto-allowed

License

Apache 2.0 with USPTO Application #64/034,215 defensive patent grant. See repo LICENSE, NOTICE, and PATENTS.txt.