Metadata-Version: 2.4
Name: lattifai-auth
Version: 0.2.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Typing :: Typed
Requires-Dist: pytest ; extra == 'test'
Provides-Extra: test
License-File: LICENSE
Summary: Cross-platform device fingerprinting and HMAC-SHA256 authentication library
Keywords: auth,hmac,device-fingerprint,hardware-id
Home-Page: https://github.com/lattifai/lattifai-auth
Author-email: LattifAI Technologies <tech@lattifai.com>
License: Apache-2.0
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/lattifai/lattifai-auth
Project-URL: Issues, https://github.com/lattifai/lattifai-auth/issues
Project-URL: Repository, https://github.com/lattifai/lattifai-auth

# LattifAI Auth

Core authentication and hardware fingerprinting library for LattifAI projects. Built with Rust for high performance and security, with bindings for Python and WebAssembly.

## Features

- **Hardware Fingerprinting**: Cross-platform (macOS, Windows, Linux) unique device ID generation.
- **Secure Signing**: HMAC-SHA256 request signing to prevent spoofing.
- **Multi-language Support**:
  - **Rust**: Native implementation.
  - **Python**: High-performance extension module (via PyO3).
  - **WebAssembly**: For browser-based authentication (via wasm-bindgen).
  - **C-FFI**: Compatible with any language that supports C calling conventions.

## Installation (Python)

```bash
pip install lattifai-auth
```

## Usage (Python)

```python
import lattifai_auth

# Get unique hardware ID (SHA-256 hex, 64 chars)
device_id = lattifai_auth.get_device_id()
print(f"Device ID: {device_id}")

# Generate signed payload for API requests
# Returns: {json}.{base64_signature}
api_key = "your-api-key"
payload = lattifai_auth.generate_auth_payload(api_key)
print(f"Payload: {payload}")

# Structured output with individual fields
parts = lattifai_auth.generate_auth_payload_parts(api_key)
print(f"Device:    {parts['device_id']}")
print(f"Timestamp: {parts['timestamp']}")
print(f"Platform:  {parts['platform']}")
print(f"Version:   {parts['version']}")
print(f"Signature: {parts['signature']}")
```

### Error Handling

All functions raise `ValueError` on failure:

```python
try:
    lattifai_auth.generate_auth_payload("")  # empty key
except ValueError as e:
    print(f"Error: {e}")  # "invalid input: api_key must not be empty"
```

## Development

### Prerequisites

- Rust toolchain (1.70+)
- Python 3.8+
- `maturin` for Python builds
- `wasm-pack` for WebAssembly builds

### Build Native Library

```bash
make build-native
```

### Build Python Wheel

```bash
maturin develop --features python   # install in dev mode
maturin build --release --features python  # build wheel
```

### Run Tests

```bash
cargo test                  # Rust unit tests
pytest tests/ -v            # Python integration tests
```

### Build WebAssembly

```bash
make build-wasm
```

## License

Apache-2.0

