Metadata-Version: 2.4
Name: arken-auth
Version: 0.3.0
Summary: Zero-storage authentication middleware. No passwords. No sessions. Nothing to breach.
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/arkenforge/arken-auth
Project-URL: Repository, https://github.com/arkenforge/arken-auth
Project-URL: Issues, https://github.com/arkenforge/arken-auth/issues
Keywords: authentication,did,did:key,fastapi,a401,secp256k1
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: fastapi>=0.100.0
Provides-Extra: dev
Requires-Dist: uvicorn>=0.24.0; extra == "dev"
Requires-Dist: httpx>=0.25.0; extra == "dev"
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"

# arken-auth (Python)

Zero-storage authentication dependency for FastAPI. No passwords. No sessions. Nothing to breach.

## Install

Requires [Rust](https://rustup.rs) — used once to compile the native crypto core.

```bash
pip install arken-auth
python scripts/build_native.py  # compiles the Rust core (requires rustup.rs)
```

## Usage

```python
from fastapi import FastAPI, Depends
from arken_auth import ArkenAuth

app = FastAPI()

@app.get("/protected")
async def protected(did: str = Depends(ArkenAuth())):
    return {"user": did}
```

## How it works

1. First request hits your route with no `Authorization` header
2. Dependency raises a `401` HTTPException with a JSON challenge
3. Client signs the nonce and resends with `Authorization: Signature did="...",nonce="...",signature="..."`
4. Dependency verifies the signature and returns the authenticated DID
5. FastAPI injects it as the `did` parameter

## Options

```python
ArkenAuth(statement="Sign to access the API.")
```

## 401 response format

```json
{
  "challenge": {
    "nonce": "a7b3c9...",
    "statement": "Sign this message to prove you control this DID."
  }
}
```

## Security model

- The server never sees a private key
- Nonces are single-use and expire after 60 seconds
- Signature verification runs in Rust (ethers/k256, audited)
- Thread-safe: uses a Mutex in the native library

## License

Apache-2.0
