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

@commonpub/protocol

v0.7.0

Published

ActivityPub federation protocol — HTTP signatures, WebFinger, NodeInfo

Readme

@commonpub/protocol

ActivityPub federation protocol implementation for CommonPub.

Overview

Implements the ActivityPub protocol layer: WebFinger discovery, NodeInfo, activity building and processing, content mapping, actor resolution, keypair management, and inbox/outbox handling. Wraps the Fedify framework with CommonPub-specific types.

Installation

pnpm add @commonpub/protocol

Usage

WebFinger Discovery

import { parseWebFingerResource, buildWebFingerResponse } from '@commonpub/protocol';

// Parse an acct: URI
const parsed = parseWebFingerResource('acct:[email protected]');
// { username: 'alice', domain: 'hack.build' }

// Build a WebFinger response
const response = buildWebFingerResponse({
  subject: 'acct:[email protected]',
  actorUrl: 'https://hack.build/users/alice',
  profileUrl: 'https://hack.build/@alice',
});

NodeInfo

import { buildNodeInfoResponse, buildNodeInfoWellKnown } from '@commonpub/protocol';

const nodeInfo = buildNodeInfoResponse({
  domain: 'hack.build',
  name: 'hack.build',
  description: 'A maker community',
  totalUsers: 42,
  activeMonth: 15,
  localPosts: 128,
});

Building Activities

import {
  buildCreateActivity,
  buildFollowActivity,
  buildLikeActivity,
  buildAnnounceActivity,
} from '@commonpub/protocol';

// Create a new article
const create = buildCreateActivity({
  actorId: 'https://hack.build/users/alice',
  object: article,
});

// Follow an actor
const follow = buildFollowActivity({
  actorId: 'https://hack.build/users/alice',
  targetId: 'https://deveco.io/users/bob',
});

Content Mapping

Bidirectional mapping between CommonPub content and AP objects:

import { contentToArticle, articleToContent, contentToNote, noteToComment } from '@commonpub/protocol';

// CommonPub content -> AP Article
const article = contentToArticle(contentItem, author);

// AP Article -> CommonPub content
const content = articleToContent(apArticle);

Actor Resolution

import { resolveActor, resolveActorViaWebFinger } from '@commonpub/protocol';

// Resolve by actor URL
const actor = await resolveActor('https://deveco.io/users/bob');

// Resolve via WebFinger
const actor = await resolveActorViaWebFinger('[email protected]');

Keypair Management

RSA 2048 keypairs for HTTP signatures:

import { generateKeypair, exportPublicKeyPem, buildKeyId } from '@commonpub/protocol';

const keypair = await generateKeypair();
const publicPem = await exportPublicKeyPem(keypair.publicKey);
const keyId = buildKeyId('https://hack.build/users/alice');

Inbox Processing

import { processInboxActivity } from '@commonpub/protocol';

const result = await processInboxActivity(activity, {
  onFollow: async (follower, target) => { /* ... */ },
  onLike: async (actor, object) => { /* ... */ },
  onAnnounce: async (actor, object) => { /* ... */ },
  // ... handlers for all 9 activity types
});

Supported Activity Types

| Activity | Direction | Description | | ---------- | --------- | ---------------------------------- | | Create | Out/In | New content published | | Update | Out/In | Content edited | | Delete | Out/In | Content removed (Tombstone) | | Follow | Out/In | Follow request | | Accept | Out/In | Follow request accepted | | Reject | Out/In | Follow request rejected | | Undo | Out/In | Undo a previous activity | | Like | Out/In | Content liked | | Announce | Out/In | Content shared/boosted |

AP Object Types

  • APArticle: Long-form content (projects, articles, guides)
  • APNote: Short-form content (comments, replies)
  • APTombstone: Deleted content marker

OAuth2 SSO

OAuth2 authorization and token validation for cross-instance SSO:

import { validateAuthorizeRequest, validateTokenRequest } from '@commonpub/protocol';

Development

pnpm build        # Compile TypeScript
pnpm test         # Run 42 tests
pnpm typecheck    # Type-check without emitting

Dependencies

  • jose: JWT and JWK operations
  • zod: Input validation
  • @commonpub/config: Feature flags
  • @commonpub/schema: Table definitions for federation state