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

@teikyo/access

v0.6.0

Published

Access grants and revocation for Enkaku servers

Readme

@teikyo/access

Access grants and capability revocation for Enkaku servers on @sozai/http-server. It provides the access:grants and access:revocation plugins (exported as ACCESS_GRANTS and ACCESS_REVOCATION), both backed by the hozon:db plugin from @teikyo/hozon, plus a short-lived grant cache and the access pattern helpers.

Install

pnpm add @teikyo/access @sozai/http-server hono

Grants plugin

accessGrantsPlugin() provides the grant store and an allow() predicate for Enkaku access rules. It is normally consumed through @teikyo/enkaku's access.grants option.

import { createServer } from '@sozai/http-server'
import { accessGrantsPlugin, accessRevocationPlugin } from '@teikyo/access'
import { hozonDBPlugin } from '@teikyo/hozon'

const server = await createServer({
  plugins: [
    hozonDBPlugin({ db: './app.db' }),
    accessGrantsPlugin({ cacheTTLMs: 5000 }),
    accessRevocationPlugin({ requireJTI: true }),
  ],
})

| Option | Type | Description | | --- | --- | --- | | accessGrantsPlugin({ cacheTTLMs }) | number (optional) | Maximum age of cached grants in milliseconds, 5000 by default. Must be a non-negative integer (0 disables caching); anything else throws Invalid cacheTTLMs. | | accessRevocationPlugin({ requireJTI }) | boolean (optional) | Reject capabilities without a jti. Defaults to true. It also accepts the DID resolution options (resolver, cache, methods). |

Rule composition

The allow() predicate admits a caller when any of these holds:

  1. the token issuer holds a grant matching the procedure;
  2. the token sub holds a matching grant and the delegation chain verifies, so a delegate acts with the grants of the subject that delegated to it.

Anything else is denied, and a store failure is logged and denied with Access denied. When used through @teikyo/enkaku, the gated patterns get this predicate and caller-supplied rules must not overlap them (see that package).

Operator capability

Enkaku handles two server-identity cases before access rules are consulted, and neither calls the grants predicate or needs a grant:

  • A token whose sub is the server identity is checked directly as a capability. The verifyToken hook still runs on its chain, so with access.revocation enabled the capability can be revoked, and while requireJTI is true it must carry a jti.
  • A token whose iss is the server identity itself bypasses both the rules and the revocation hook.

Issue such capabilities and keys only to operators.

Cache delay across processes

GrantCache drops a subject's entry as soon as the store in the same process reports a change. A grant created or revoked by another process sharing the database is only seen once the cached entry expires, so the delay is at most one cache TTL (cacheTTLMs, 5 s by default).

Store and cache

import { GRANT_STORE, GrantCache, type GrantStore, grantStoreDefinition } from '@teikyo/access'

db.register(grantStoreDefinition)
const store = await db.getStore<GrantStore>(GRANT_STORE)
await store.grant({ subject: 'did:key:z6Mk...', pattern: 'app/*', createdBy: 'did:key:z6Mk...' })

const cache = new GrantCache({ store })
await cache.allows('did:key:z6Mk...', 'app/read')
  • GrantStore upserts grants by (created_by, subject, pattern), normalises DIDs and validates patterns.
  • grant and revoke require createdBy, scope writes to that creator, and increment its set version.
  • replaceSet atomically replaces one creator's grants using expectedVersion. Stale versions throw GrantVersionConflictError with currentVersion.
  • getSetVersion returns zero before the first mutation. replaceSet can enforce maxEntries, throwing GrantLimitError without writes.
  • accessGrantsPlugin({ operators }) reconciles config:operators to one admin/* grant per configured DID during setup.
  • reconcileOperators(store, { dids, pattern? }) exposes the same reconciliation with an optional pattern.
  • GrantCache holds active grants per subject for ttlMs (default 5000), or until the earliest grant expiry, and drops a subject's entry as soon as the store reports a change.
  • patternMatches(pattern, procedure) uses the matcher Enkaku applies to access rules; patternsOverlap(a, b) reports whether two patterns can cover a common procedure.

Revocation

accessRevocationPlugin() (plugin name access:revocation) provides a Hozon-backed revocation store and a verifyToken hook for Enkaku servers.

  • Records are scoped by issuer: the store's get(jti, issuer) only returns records signed by issuer, and the hook looks up the capability's own issuer, so another identity cannot revoke or shadow a jti it does not own.
  • requireJTI defaults to true, so tokens created without an explicit jti are rejected with Token without jti rejected; set it to false to accept them (they can never be revoked).
  • Register the store through the plugin, which carries the DID resolution options (resolver, cache, methods) that add needs.