Skip to main content

Organic Neural Interface Framework - Security library for brain-computer interfaces

Project description

ONI Framework

Organic Neural Interface Framework - A Python library for brain-computer interface security.

PyPI version License Python 3.9+ Tests

Research Status: This library implements theoretical frameworks for BCI security that have not yet been empirically validated. It is intended for research, experimentation, and to provide shared vocabulary for the emerging field of neural interface security. The mathematical models (Cₛ coherence metric, f × S ≈ k invariant) are derived from neuroscience literature but require experimental validation against real BCI data. Contributions and validation efforts are welcome.

Overview

The ONI Framework provides tools for validating and securing neural signals at the brain-computer interface boundary. It implements:

  • Coherence Metric (Cₛ) - Quantify signal trustworthiness across timing, pathway, and amplitude dimensions
  • 14-Layer Model - Unified architecture bridging biological (L1-L7) and silicon (L9-L14) domains
  • Neural Firewall - Zero-trust signal filtering at the Neural Gateway (L8)
  • Scale-Frequency Invariant - Validate signals against the f × S ≈ k constraint

Installation

# From PyPI (recommended)
pip install oni-framework

# With visualization support
pip install oni-framework[viz]

# From source (for development)
git clone https://github.com/qikevinl/ONI.git
cd ONI/MAIN/oni-framework
pip install -e ".[dev]"

Quick Start

Calculate Coherence Score

from oni import CoherenceMetric, calculate_cs

# Create metric with 40 Hz gamma reference
metric = CoherenceMetric(reference_freq=40.0)

# Sample signal data
arrival_times = [0.0, 0.025, 0.050, 0.075, 0.100]  # seconds
amplitudes = [100, 98, 102, 99, 101]  # μV

# Calculate coherence
cs = metric.calculate(arrival_times, amplitudes)
print(f"Coherence Score: {cs:.3f}")

# Interpret the score
level, description = metric.interpret(cs)
print(f"{level}: {description}")

Use the Neural Firewall

from oni import NeuralFirewall, Signal

# Create firewall with default thresholds
firewall = NeuralFirewall(
    threshold_high=0.6,
    threshold_low=0.3,
    amplitude_bounds=(0, 500),  # μV limits
)

# Create a signal to validate
signal = Signal(
    arrival_times=[0.0, 0.025, 0.050],
    amplitudes=[100, 98, 102],
    authenticated=True,
)

# Filter the signal
result = firewall.filter(signal)

print(f"Decision: {result.decision.name}")
print(f"Coherence: {result.coherence:.3f}")
print(f"Alert Level: {result.alert_level.name}")
print(f"Reason: {result.reason}")

Explore the 14-Layer Model

from oni import ONIStack

stack = ONIStack()

# Print the stack diagram
print(stack.ascii_diagram())

# Access specific layers
gateway = stack.layer(8)  # Neural Gateway
print(f"Layer 8: {gateway.name}")
print(f"Function: {gateway.function}")
print(f"Attack surfaces: {gateway.attack_surfaces}")

# Iterate through biological layers
for layer in stack.biological_layers():
    print(f"L{layer.number}: {layer.name}")

Validate Scale-Frequency Relationship

from oni import ScaleFrequencyInvariant

sfi = ScaleFrequencyInvariant()

# Check if 40 Hz at 100 μm scale is valid
frequency = 40  # Hz
spatial_scale = 1e-4  # meters (100 μm)

is_valid = sfi.validate(frequency, spatial_scale)
deviation = sfi.deviation(frequency, spatial_scale)

print(f"Valid: {is_valid}")
print(f"Deviation from k: {deviation:.1%}")

# Get expected frequency for a scale
expected_f = sfi.expected_frequency(spatial_scale=1e-3)
print(f"Expected frequency at 1mm: {expected_f:.1f} Hz")

# Print hierarchy report
print(sfi.hierarchy_report())

Core Concepts

Coherence Metric Formula

Cₛ = e^(−(σ²φ + σ²τ + σ²γ))

Where:
- σ²φ = phase variance (timing jitter)
- σ²τ = transport variance (pathway integrity)
- σ²γ = gain variance (amplitude stability)

Firewall Decision Matrix

Coherence Authentication Decision
High (>0.6) Valid ACCEPT
High (>0.6) Invalid REJECT
Medium (0.3-0.6) Valid ACCEPT + FLAG
Medium (0.3-0.6) Invalid REJECT
Low (<0.3) Any REJECT

Scale-Frequency Invariant

f × S ≈ k (constant)

Higher frequencies → Smaller spatial scales
Lower frequencies → Larger spatial scales

Project Structure

oni-framework/
├── oni/
│   ├── __init__.py      # Package exports
│   ├── coherence.py     # Cₛ calculation
│   ├── layers.py        # 14-layer model
│   ├── firewall.py      # Signal filtering
│   └── scale_freq.py    # f × S ≈ k invariant
├── tests/
│   └── test_*.py        # Unit tests
├── pyproject.toml       # Package configuration
└── README.md            # This file

API Reference

oni.CoherenceMetric

  • calculate(arrival_times, amplitudes) → Coherence score (0-1)
  • calculate_variances(...) → Individual variance components
  • interpret(cs) → (level, description) tuple

oni.NeuralFirewall

  • filter(signal) → FilterResult with decision
  • filter_batch(signals) → List of FilterResults
  • get_stats() → Filtering statistics
  • register_callback(level, fn) → Alert callbacks

oni.ONIStack

  • layer(n) → Get layer by number (1-14)
  • biological_layers() → L1-L7
  • silicon_layers() → L9-L14
  • bridge_layer() → L8 (Neural Gateway)
  • ascii_diagram() → Visual representation

oni.ScaleFrequencyInvariant

  • validate(frequency, scale) → Boolean validity
  • deviation(frequency, scale) → Fractional deviation
  • expected_frequency(scale) → Predicted frequency
  • anomaly_score(frequency, scale) → 0-1 anomaly score

Research Background

This library implements concepts from the ONI Framework research:

Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.

Seeking input from:

  • Neuroscientists — Validate biological assumptions
  • Security engineers — Identify attack vectors
  • BCI researchers — Test against real data

License

Apache License 2.0 - See LICENSE

Citation

If you use this library in research, please cite:

@software{oni_framework,
  author = {Qi, Kevin L.},
  title = {ONI Framework: Security Library for Brain-Computer Interfaces},
  year = {2026},
  url = {https://github.com/qikevinl/ONI}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oni_framework-0.1.0.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oni_framework-0.1.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file oni_framework-0.1.0.tar.gz.

File metadata

  • Download URL: oni_framework-0.1.0.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for oni_framework-0.1.0.tar.gz
Algorithm Hash digest
SHA256 58d2019c87c02c5e22cdca68c771680b56719aef9ed3a9e1d39f3d5866c5a149
MD5 923077cac70b85a95066c77b32d878ea
BLAKE2b-256 90a5fafd7d1b6a80b7a1c7ccd7d7d9af0a3f75c982b9ae58cf6f062d62bee931

See more details on using hashes here.

Provenance

The following attestation bundles were made for oni_framework-0.1.0.tar.gz:

Publisher: publish.yml on qikevinl/ONI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oni_framework-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: oni_framework-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for oni_framework-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2cdd3f2a8f433ec4f93605bd4c80bcedd99815fd3096092f6a84c04b6bc9e8fb
MD5 8002035fa01ef688b42b98d32e8bb42e
BLAKE2b-256 1b625263fd9e5228ab384cb94645b922b11ce8db304fd52cc35a694649b121da

See more details on using hashes here.

Provenance

The following attestation bundles were made for oni_framework-0.1.0-py3-none-any.whl:

Publisher: publish.yml on qikevinl/ONI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page