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

@moq/token

v0.1.1

Published

Media over QUIC - Token Generation and Validation

Readme

moq-token

A Javascript/Typescript library and CLI for implementing authentication with a MoQ relay. For comprehensive documentation including token structure, authorization rules, and examples, see the Authentication Documentation

Installation

For general installation as a library

npm add @moq/token

CLI

To use as a CLI (with node installed)

npm install -g @moq/token

And then run

moq-token generate ...

You can also just directly use it via bun as:

bunx @moq/token generate ...

Usage

Generation

You would first generate a token as so:

import {generate} from "@moq/token";
// Use this for signing
const key = await generate('HS256');

or as a CLI

# generate secret key
moq-token generate --key key.jwk

The default is HS256, you can choose other algorithms with --algorithm:

moq-token generate --key key.jwk --algorithm ES256

Signing

You can sign a token as shown below:

import { type Claims, load, sign, verify } from "@moq/token";

const key = load(keyString); // See generate example above
// Create claims
const claims: Claims = {
  root: "demo",
  put: "bbb", // Only `demo/bbb`
  get: "", // Any broadcast starting with `demo/`
  exp: Math.floor(Date.now() / 1000) + 3600, // 1 hour from now (in seconds)
  iat: Math.floor(Date.now() / 1000), // Issued at (in seconds)
};

// Sign a token
const token = await sign(key, claims);

Or you can sign as a CLI

moq-token sign --key "root.jwk" \
  --root "rooms/meeting-123" \
  --subscribe "" \
  --publish "alice" \
  --expires 1703980800 > "alice.jwt"

Verifying

You can also verify a token

import { verify } from "../src/index.ts";
const rootPath = "rooms/meeting-123";
try{
  const verifiedClaims =<Claims> await verify(key, token, rootPath);
  console.log("Valid token")
} catch(e){
  console.log("Invalid token")
}

or as a CLI

moq-token verify --key root.jwk --root "rooms/meeting-123" < alice.jwt

Working example

See examples/sign-and-verify.ts for a complete working example.

API

Algorithm

Supported algorithms:

  • HS256 - HMAC with SHA-256
  • HS384 - HMAC with SHA-384
  • HS512 - HMAC with SHA-512

Claims

The JWT payload structure:

interface Claims {
	root?: string;           // Root path for publish/subscribe (optional)
	publish?: string;        // Publish permission pattern
	subscribe?: string;      // Subscribe permission pattern
	cluster?: boolean;       // Whether this is a cluster node
	expires?: Date;          // Token expiration time
	issued?: Date;           // Token issued time
}

Key

Key management and JWT operations:

interface Key {
	algorithm: Algorithm;
	operations: Operation[];
	secret: string;          // Base64URL encoded secret
	kid?: string;            // Key ID (optional)
}

type Operation = "sign" | "verify" | "decrypt" | "encrypt";

// Load a key from a JWK string
function load(jwk: string): Key;

// Sign claims to create a JWT
function sign(key: Key, claims: Claims): Promise<string>;

// Verify and decode a JWT
function verify(key: Key, token: string): Promise<Claims>;

License

MIT OR Apache-2.0