Skip to content

@moq/token

JWT token generation and verification for MoQ in browsers.

Overview

@moq/token provides:

  • Generate signing keys (HMAC, RSA, ECDSA, EdDSA)
  • Sign and verify JWT tokens
  • Compatible with moq-relay authentication and moq-token-cli

Installation

bash
bun add @moq/token

Usage

For a complete working example covering key loading, signing, and verification, see js/token/examples/sign-and-verify.ts.

Token Claims

ClaimTypeDescription
rootstringRoot path for operations
putstring | string[]?Publishing permission paths
getstring | string[]?Subscription permission paths
clusterboolean?Cluster node flag
expnumber?Expiration timestamp
iatnumber?Issued at timestamp

CLI Usage

The package includes a CLI tool:

bash
# Generate a key
bun run @moq/token generate --key root.jwk

# Sign a token
bun run @moq/token sign --key root.jwk --root "rooms/123" --publish alice

# Verify a token from stdin
bun run @moq/token verify --key root.jwk --root "rooms/123" < token.jwt

Security Considerations

  • Never expose secret keys in browser code
  • Use asymmetric keys when possible
  • Generate tokens server-side for production
  • Set appropriate expiration times

Next Steps

Licensed under MIT or Apache-2.0