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.
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 componentsinterpret(cs)→ (level, description) tuple
oni.NeuralFirewall
filter(signal)→ FilterResult with decisionfilter_batch(signals)→ List of FilterResultsget_stats()→ Filtering statisticsregister_callback(level, fn)→ Alert callbacks
oni.ONIStack
layer(n)→ Get layer by number (1-14)biological_layers()→ L1-L7silicon_layers()→ L9-L14bridge_layer()→ L8 (Neural Gateway)ascii_diagram()→ Visual representation
oni.ScaleFrequencyInvariant
validate(frequency, scale)→ Boolean validitydeviation(frequency, scale)→ Fractional deviationexpected_frequency(scale)→ Predicted frequencyanomaly_score(frequency, scale)→ 0-1 anomaly score
Research Background
This library implements concepts from the ONI Framework research:
- ONI Framework Overview
- Coherence Metric Technical Document
- Neural Firewall Architecture
- Scale-Frequency Invariant
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58d2019c87c02c5e22cdca68c771680b56719aef9ed3a9e1d39f3d5866c5a149
|
|
| MD5 |
923077cac70b85a95066c77b32d878ea
|
|
| BLAKE2b-256 |
90a5fafd7d1b6a80b7a1c7ccd7d7d9af0a3f75c982b9ae58cf6f062d62bee931
|
Provenance
The following attestation bundles were made for oni_framework-0.1.0.tar.gz:
Publisher:
publish.yml on qikevinl/ONI
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oni_framework-0.1.0.tar.gz -
Subject digest:
58d2019c87c02c5e22cdca68c771680b56719aef9ed3a9e1d39f3d5866c5a149 - Sigstore transparency entry: 844605867
- Sigstore integration time:
-
Permalink:
qikevinl/ONI@e2237c4b8e9e0b4d30b8ce9030b39fac2be476c3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/qikevinl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e2237c4b8e9e0b4d30b8ce9030b39fac2be476c3 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cdd3f2a8f433ec4f93605bd4c80bcedd99815fd3096092f6a84c04b6bc9e8fb
|
|
| MD5 |
8002035fa01ef688b42b98d32e8bb42e
|
|
| BLAKE2b-256 |
1b625263fd9e5228ab384cb94645b922b11ce8db304fd52cc35a694649b121da
|
Provenance
The following attestation bundles were made for oni_framework-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on qikevinl/ONI
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oni_framework-0.1.0-py3-none-any.whl -
Subject digest:
2cdd3f2a8f433ec4f93605bd4c80bcedd99815fd3096092f6a84c04b6bc9e8fb - Sigstore transparency entry: 844605868
- Sigstore integration time:
-
Permalink:
qikevinl/ONI@e2237c4b8e9e0b4d30b8ce9030b39fac2be476c3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/qikevinl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e2237c4b8e9e0b4d30b8ce9030b39fac2be476c3 -
Trigger Event:
release
-
Statement type: