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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@sigma-auth/server-plugin

v0.1.1

Published

Better Auth server plugin for Bitcoin signature-based authentication with Sigma Identity

Readme

@sigma-auth/server-plugin

Better Auth server plugin for Bitcoin signature-based authentication with Sigma Identity.

Installation

npm install @sigma-auth/server-plugin
# or
bun add @sigma-auth/server-plugin

What is Sigma Identity?

Sigma Identity (auth.sigmaidentity.com) is a centralized OAuth provider for Bitcoin-based authentication. This server plugin handles Bitcoin signature verification and OAuth token exchange for platforms integrating with Sigma.

Features

  • Bitcoin signature authentication - Verify Bitcoin signatures via bitcoin-auth
  • OAuth 2.0 integration - Handle authorization code exchange with Bitcoin-based client auth
  • Pubkey-based user identification - No passwords, users identified by Bitcoin public key
  • Optional BAP ID resolution - Integrate with Bitcoin Attestation Protocol
  • Optional subscription tiers - Track user subscription levels
  • Configurable dependencies - Inject your own DB pool, cache, and BAP resolver

Setup

Basic Setup

import { betterAuth } from "better-auth";
import { sigma } from "@sigma-auth/server-plugin";

export const auth = betterAuth({
  database: {
    // your database configuration
  },
  plugins: [
    sigma(), // Basic setup with no optional features
  ],
});

Advanced Setup (with BAP ID and Subscriptions)

import { betterAuth } from "better-auth";
import { sigma } from "@sigma-auth/server-plugin";
import { Pool } from "@neondatabase/serverless";
import { kv } from "@vercel/kv";
import { resolvePubkeyAndRegisterBAPId } from "./lib/bap/resolver";

export const auth = betterAuth({
  database: {
    // your database configuration
  },
  plugins: [
    sigma({
      // Enable subscription tier tracking
      enableSubscription: true,

      // Provide BAP ID resolver
      resolveBAPId: resolvePubkeyAndRegisterBAPId,

      // Provide database pool getter
      getPool: () => new Pool({
        connectionString: process.env.POSTGRES_URL,
      }),

      // Provide cache implementation (optional)
      cache: {
        get: async (key) => await kv.get(key),
        set: async (key, value) => await kv.set(key, value),
      },
    }),
  ],
});

API Reference

sigma(options?)

Creates the Sigma Auth server plugin for Better Auth.

Options:

interface SigmaPluginOptions {
  /**
   * Enable subscription tier support
   * Adds subscriptionTier field to user and session
   * @default false
   */
  enableSubscription?: boolean;

  /**
   * Optional BAP (Bitcoin Attestation Protocol) ID resolver
   * Resolves a Bitcoin pubkey to a BAP ID and registers it
   */
  resolveBAPId?: (
    pool: any,
    userId: string,
    pubkey: string,
    register: boolean
  ) => Promise<string | null>;

  /**
   * Optional database pool getter
   * Returns a database connection pool for BAP ID resolution
   */
  getPool?: () => any;

  /**
   * Optional cache implementation for BAP ID caching
   * Should provide get/set methods for key-value storage
   */
  cache?: {
    get: <T = any>(key: string) => Promise<T | null>;
    set: (key: string, value: any) => Promise<void>;
  };
}

Endpoints

The plugin provides these endpoints:

POST /api/auth/sign-in/sigma

Authenticates a user via Bitcoin signature.

Headers:

  • X-Auth-Token (required) - Bitcoin authentication token

Returns:

{
  "token": "session-token",
  "user": {
    "id": "user-id",
    "pubkey": "bitcoin-pubkey",
    "name": "user-name"
  }
}

OAuth 2.0 Integration

The plugin handles OAuth token exchange with Bitcoin-based client authentication via hooks on /oauth2/token.

Client Authentication:

  • Clients authenticate using Bitcoin signatures (no client_id/client_secret)
  • Platform pubkey is extracted from the X-Auth-Token signature
  • Platform must be registered in oauthApplication table with pubkey as clientId

Supported Grant Types:

  • authorization_code - Exchange authorization code for access token
  • refresh_token - Refresh an existing access token

Database Schema

The plugin extends Better Auth schema:

user: {
  pubkey: string (required, unique)
  subscriptionTier?: string (optional, if enableSubscription: true)
}

session: {
  subscriptionTier?: string (optional, if enableSubscription: true)
}

Run migrations after adding the plugin:

npx @better-auth/cli migrate

Client Integration

Use with @sigma-auth/client-plugin:

import { createAuthClient } from "better-auth/react";
import { sigmaClient } from "@sigma-auth/client-plugin";

export const authClient = createAuthClient({
  plugins: [sigmaClient()],
});

// Usage
authClient.signIn.sigma(); // Redirects to Sigma Identity OAuth flow

Environment Variables

# Optional: Database connection for BAP ID resolution
POSTGRES_URL=postgresql://...

# Optional: Your environment-specific config

Security

  • ✅ Bitcoin signature verification via bitcoin-auth
  • ✅ OAuth 2.0 authorization code flow with PKCE support
  • ✅ Platform authentication via Bitcoin signatures (no shared secrets)
  • ✅ User private keys never exposed to your platform

Requirements

  • better-auth ^1.3.34 (peer dependency)
  • @bsv/sdk ^2.0.0 (peer dependency)
  • bitcoin-auth ^1.0.0 (peer dependency)

Related Packages

License

MIT