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

nacf-web-sdk

v0.1.1

Published

Web SDK for Neural Authentication Component Framework (NACF)

Downloads

5

Readme

NACF Web SDK

npm version License: Apache 2.0 TypeScript

JavaScript/TypeScript SDK for Neural Authentication Control Framework (NACF)

The NACF Web SDK provides a comprehensive client library for integrating neural authentication into web applications. Built with TypeScript, it offers type-safe APIs for EEG-based authentication, real-time signal processing, and secure token management.

🌟 Features

  • 🔐 Neural Authentication: EEG-based biometric authentication
  • ⚡ Real-time Processing: Sub-millisecond signal processing
  • 🔒 Secure Token Management: JWT handling with automatic refresh
  • 📡 WebSocket Support: Real-time communication with NACF servers
  • 🎯 TypeScript Support: Full type definitions and IntelliSense
  • 🛡️ Error Handling: Comprehensive error classes and recovery
  • 📊 Signal Processing: Built-in FFT and signal quality analysis
  • 🔄 Reactive Programming: RxJS-based event handling

📦 Installation

npm

npm install nacf-web-sdk

yarn

yarn add nacf-web-sdk

CDN

<script src="https://cdn.jsdelivr.net/npm/nacf-web-sdk@latest/dist/index.js"></script>

🚀 Quick Start

Basic Authentication

import { NeuroAuthClient } from 'nacf-web-sdk';

// Initialize the client
const client = new NeuroAuthClient({
  apiUrl: 'https://api.nacf.example.com/v1',
  autoRefresh: true,
});

// Authenticate with EEG data
const credentials = {
  identifier: '[email protected]',
  eegData: {
    samples: [/* EEG channel data */],
    sampleRate: 256,
  }
};

try {
  const result = await client.authenticate(credentials);
  console.log('Authentication successful:', result);
} catch (error) {
  console.error('Authentication failed:', error);
}

Browser Usage (CDN)

<!DOCTYPE html>
<html>
<head>
    <title>NACF Auth Demo</title>
    <script src="https://cdn.jsdelivr.net/npm/nacf-web-sdk@latest/dist/index.js"></script>
</head>
<body>
    <script>
        const client = new NACF.NeuroAuthClient({
            apiUrl: 'https://api.nacf.example.com/v1'
        });

        // Use the client...
    </script>
</body>
</html>

📖 Live Example - Interactive browser demo

React Integration

import React, { useState, useEffect } from 'react';
import { NeuroAuthClient } from 'nacf-web-sdk';

function AuthComponent() {
  const [client] = useState(() => new NeuroAuthClient({
    apiUrl: process.env.REACT_APP_NACF_API_URL,
  }));
  const [isAuthenticated, setIsAuthenticated] = useState(false);

  useEffect(() => {
    client.on('authStateChange', (state) => {
      setIsAuthenticated(state.isAuthenticated);
    });

    return () => {
      client.removeAllListeners();
    };
  }, [client]);

  const handleAuth = async (eegData: any) => {
    try {
      await client.authenticate({
        identifier: '[email protected]',
        eegData,
      });
    } catch (error) {
      console.error('Auth failed:', error);
    }
  };

  return (
    <div>
      {isAuthenticated ? (
        <p>Welcome! You are authenticated.</p>
      ) : (
        <button onClick={() => handleAuth(/* EEG data */)}>
          Authenticate with EEG
        </button>
      )}
    </div>
  );
}

📚 API Reference

NeuroAuthClient

The main client class for interacting with NACF services.

Constructor Options

interface AuthConfig {
  apiUrl?: string;                    // API base URL
  timeout?: number;                   // Request timeout in ms
  autoRefresh?: boolean;              // Auto-refresh tokens
  refreshThreshold?: number;          // Token refresh threshold in ms
  headers?: Record<string, string>;   // Additional headers
  onAuthStateChange?: (state: AuthState) => void;
  onTokenRefresh?: (token: string) => void;
  onError?: (error: Error) => void;
}

Methods

authenticate(credentials: AuthCredentials): Promise<AuthResult>

Authenticates a user with EEG data.

interface AuthCredentials {
  identifier: string;
  password?: string;
  eegData?: {
    samples: number[][];
    sampleRate: number;
    channels?: string[];
    metadata?: Record<string, any>;
  };
  deviceId?: string;
}

interface AuthResult {
  success: boolean;
  token?: string;
  refreshToken?: string;
  user?: User;
  session?: AuthSession;
}
verify(token: string): Promise<boolean>

Verifies a JWT token.

refresh(): Promise<AuthResult>

Refreshes the authentication token.

logout(): Promise<void>

Logs out the current user.

getAuthState(): AuthState

Returns the current authentication state.

Events

client.on('authStateChange', (state: AuthState) => {
  console.log('Auth state changed:', state);
});

client.on('tokenRefresh', (token: string) => {
  console.log('Token refreshed:', token);
});

client.on('error', (error: Error) => {
  console.error('Auth error:', error);
});

Signal Processing

EEG Data Validation

import { validateEEGData } from 'nacf-web-sdk';

const eegData = {
  samples: [[1, 2, 3], [4, 5, 6]], // Channel data
  sampleRate: 256,
};

try {
  validateEEGData(eegData);
  console.log('EEG data is valid');
} catch (error) {
  console.error('Invalid EEG data:', error);
}

Signal Processing Utilities

import { processEEGSamples } from 'nacf-web-sdk';

const rawSamples = [[/* channel 1 data */], [/* channel 2 data */]];
const processedSamples = processEEGSamples(rawSamples, 256);

🔧 Configuration

Environment Variables

// .env
REACT_APP_NACF_API_URL=https://api.nacf.example.com/v1
REACT_APP_NACF_TIMEOUT=30000

Advanced Configuration

const client = new NeuroAuthClient({
  apiUrl: 'https://api.nacf.example.com/v1',
  timeout: 30000,
  autoRefresh: true,
  refreshThreshold: 300000, // 5 minutes
  headers: {
    'X-API-Key': 'your-api-key',
  },
  onAuthStateChange: (state) => {
    console.log('Auth state:', state);
  },
  onError: (error) => {
    console.error('Auth error:', error);
  },
});

🛠️ Development

Building from Source

# Clone the repository
git clone https://github.com/pratikacharya1234/NAFC.git
cd nacf/web_sdk

# Install dependencies
npm install

# Build the SDK
npm run build

# Run tests
npm test

# Run linting
npm run lint

Project Structure

src/
├── client.ts          # Main client implementation
├── index.ts           # Public API exports
├── constants.ts       # Configuration constants
├── errors/            # Error classes
│   ├── index.ts
│   ├── auth-errors.ts
│   ├── network-errors.ts
│   └── validation-errors.ts
├── types/             # TypeScript definitions
│   ├── index.ts
│   ├── authentication.ts
│   ├── signal.ts
│   └── session.ts
└── utils/             # Utility functions
    ├── signal.ts
    └── validation.ts

📋 Requirements

  • Node.js: 16.0+ (for development)
  • Browser: Modern browsers with ES6 support
  • TypeScript: 4.5+ (for TypeScript projects)

🧪 Testing

# Run unit tests
npm test

# Run tests with coverage
npm run test:coverage

# Run tests in watch mode
npm run test:watch

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

📄 License

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

🆘 Support

🔗 Related Links


Built with ❤️ by the NACF Team