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

nostr-biometric-auth-utils

v0.2.1

Published

A utility library for biometric authentication in Nostr applications using WebAuthn.

Readme

Nostr Biometric Authentication Utilities

npm version License: MIT TypeScript

A comprehensive utility library for implementing biometric authentication in Nostr applications using WebAuthn. This library provides a flexible set of tools for adding secure biometric authentication as a step-up factor to your Nostr-based applications.

Features

  • WebAuthn Integration: Ready-to-use utilities for implementing WebAuthn-based biometric authentication
  • Platform Support:
    • TouchID/FaceID for iOS and macOS
    • Windows Hello
    • Android biometric authentication
    • Security Key support (FIDO2/U2F)
  • Nostr-Specific Tools:
    • Full NIP-19 compliance for entity encoding/decoding
    • Nostr profile integration
    • Direct message-based settings management
  • Type Safety: Comprehensive TypeScript support with strict typing
  • Flexible Integration: Can be used with any web framework or Nostr client
  • Security First: Built with security best practices and proper error handling

Installation

npm install nostr-biometric-auth-utils

Quick Start

Basic Authentication Flow

import { NostrBiometricClient } from 'nostr-biometric-auth-utils';

const client = new NostrBiometricClient({
  relays: ['wss://relay.damus.io'],
  magicLinkExpiry: 300,
  sessionDuration: 86400
});

// Start authentication for a user
await client.startAuth('npub1...');

// Listen for state changes
client.onStateChange((state) => {
  switch (state.step) {
    case 'WAITING_FOR_MAGIC_LINK':
      console.log('Please check your Nostr client for the magic link');
      break;
    case 'STARTING_WEBAUTHN':
      console.log('Please complete biometric verification');
      break;
    case 'COMPLETED':
      console.log('Authentication successful!');
      break;
  }
});

Settings Management

import { SettingsManager } from 'nostr-biometric-auth-utils';

const settings = new SettingsManager(nostrService, userPubkey);

// Load user settings
const currentSettings = await settings.loadSettings();

// Update settings
await settings.updateSettings({
  biometricEnabled: true,
  sessionDuration: 3600
});

Architecture

The library is organized into several core modules:

nostr-biometric-auth-utils/
├── src/
│   ├── client/          # Main client-side authentication flow
│   │   └── index.ts     # NostrBiometricClient implementation
│   ├── core/            # Core authentication implementations
│   │   ├── webauthn.ts  # WebAuthn registration & verification
│   │   ├── touchid.ts   # TouchID/FaceID integration
│   │   └── security-key.ts  # Hardware security key support
│   ├── settings/        # Nostr-based settings management
│   │   └── index.ts     # SettingsManager for DM-based config
│   └── utils/           # Helper functions
│       └── nostr.ts     # Nostr entity encoding/decoding (NIP-19)

Authentication Flow

1. User provides their npub
         │
         v
2. Magic link sent via Nostr DM
         │
         v
3. User clicks magic link
         │
         v
4. WebAuthn biometric challenge
   (TouchID / FaceID / Windows Hello / Security Key)
         │
         v
5. Session established

The flow combines Nostr's cryptographic identity with WebAuthn biometrics for two-factor authentication. The magic link verifies the user controls the Nostr key, and biometrics verify the user is physically present.

API Reference

NostrBiometricClient

The main client for managing the authentication flow.

const client = new NostrBiometricClient(options: ClientOptions);

| Option | Type | Description | |--------|------|-------------| | relays | string[] | Nostr relay URLs to connect to | | magicLinkExpiry | number | Magic link expiry in seconds (default: 300) | | sessionDuration | number | Session duration in seconds (default: 86400) |

Methods

  • startAuth(npub: string) — Begins the authentication flow for a given npub
  • onStateChange(callback) — Registers a callback for auth state transitions
  • cancelAuth() — Cancels an in-progress authentication

SettingsManager

Manages user settings stored via Nostr direct messages.

const settings = new SettingsManager(nostrService, userPubkey);

Methods

  • loadSettings() — Loads the user's current settings
  • updateSettings(settings) — Updates and persists settings
  • resetSettings() — Resets settings to defaults

WebAuthn Utilities

Low-level WebAuthn functions for custom flows.

import { registerCredential, verifyCredential } from 'nostr-biometric-auth-utils';

// Register a new biometric credential
const credential = await registerCredential({
  rpName: 'Your App',
  rpId: 'your-app.com',
  userId: npub,
  userName: displayName,
});

// Verify a credential during authentication
const result = await verifyCredential({
  credentialId: credential.id,
  challenge: serverChallenge,
});

Security Considerations

Dependency Vulnerability Status

We actively monitor and address security vulnerabilities in this codebase. npm audit --omit=dev reports zero vulnerabilities for this package — there are no known security issues in production dependencies.

Any remaining npm audit findings are in development-only tooling (eslint, typescript-eslint, vitest, etc.) and stem from transitive dependencies with no upstream fix available. These are devDependencies that are never included in the published package and pose no risk to consumers of this library. We monitor upstream fixes and update promptly when they become available.

Biometric Data Privacy

  • All biometric data remains on the user's device — it is never transmitted to servers
  • The WebAuthn protocol only exchanges cryptographic proofs, not biometric templates
  • Implements FIDO2 WebAuthn specifications for maximum interoperability

Key Management

  • Nostr private keys are never handled by this library
  • Magic link signing uses nostr-crypto-utils for NIP-compliant operations
  • WebAuthn credentials are bound to the origin (domain) and cannot be phished

Threat Model

| Threat | Mitigation | |--------|------------| | Stolen npub | Magic link requires access to Nostr DMs | | Compromised relay | Multi-relay support with verification | | Phishing | WebAuthn origin binding prevents cross-site use | | Session hijacking | Configurable session expiry with biometric re-auth |

Best Practices

  1. Always use multiple relays for magic link delivery
  2. Set appropriate expiry times for magic links (5-15 minutes)
  3. Implement session refresh with biometric re-verification
  4. Monitor failed authentication attempts
  5. Use HTTPS in production for WebAuthn origin verification

Examples

See the examples/ directory for complete working examples:

  • examples/proof_of_concept/ — Minimal Express.js server with WebAuthn flow

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

Changelog

See CHANGELOG.md for a detailed history of changes.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Related Projects