Metadata-Version: 2.1
Name: fastapi-walletauth
Version: 1.0.0
Summary: FastAPI extension for user authentication through signature challenges
Keywords: FastAPI,authentication,signature,wallet,ethereum,solana,web3,jwt
Author: mhh
Author-email: mike.hukiewitz@robotter.ai
Requires-Python: >=3.8.1,<4.0
Classifier: Environment :: Web Environment
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Topic :: Security
Classifier: Typing :: Typed
Requires-Dist: base58 (>=2.0.0,<3.0)
Requires-Dist: cryptography (>=41.0.3,<42.0.0)
Requires-Dist: eth-account (>=0.9.0,<0.10.0)
Requires-Dist: eth-keys (>=0.4.0,<0.5.0)
Requires-Dist: fastapi (>=0.60.1,<1.0)
Requires-Dist: pydantic-settings (>=2.0.3,<3.0.0)
Requires-Dist: pyjwt (>=2.8.0,<3.0.0)
Requires-Dist: pynacl (>=1.5.0,<2.0.0)
Description-Content-Type: text/markdown

# FastAPI Wallet Authentication

fastapi-walletauth provides a simple way to authenticate users in FastAPI applications using a wallet.
It currently supports Ethereum and Solana wallets/signatures.

## Installation

```shell
pip install fastapi-walletauth
```

## Usage

Adding the authentication endpoints is as simple as importing the `authorization_routes` from `fastapi_walletauth`:

```python
from fastapi import FastAPI
from fastapi_walletauth import authorization_routes

app = FastAPI()

app.include_router(authorization_routes)
```

This will add the following endpoints to your application:

- `POST /authentication/challenge`: Returns a challenge for the user to sign
- `POST /authentication/solve`: Returns a Bearer token if the signature is valid
- `POST /authentication/logout`: Invalidates the current token
- `POST /authentication/refresh`: Returns a new token if the current token is valid

You can then use `WalletAuthDep` to protect your endpoints:

```python
from fastapi import FastAPI
from fastapi_walletauth import WalletAuthDep, authorization_routes

app = FastAPI()
app.include_router(authorization_routes)

@app.get("/protected")
def protected(wa: WalletAuthDep):
    return wa.address
```

## Signing the challenge

The challenge is a serialized JSON object containing the following fields:

```python
message = {
    "chain": "ETH",
    "address": "0x...",
    "app": "myapp",
    "time": 1688819493.8691394
}
```

**PLEASE NOTE**: The `app` field needs to be set to the name of your application. This is used to prevent replay attacks.
```shell
export FASTAPI_WALLETAUTH_APP=myapp
```

The signature format depends on the wallet type and is specified in the `chain` field. This signature is then sent to the
`/authentication/solve` endpoint to obtain a Bearer token.

## Liability

This software is provided "as is" and "with all faults." I make no representations or warranties of any kind concerning
the safety, suitability, inaccuracies, typographical errors, or other harmful components of this
software. There are inherent dangers in the use of any software, especially cryptographic implementations. You are solely
responsible for determining whether this software is compatible with your machine and other software installed on your
computer. You are also solely responsible for the choice of a wallet and the security of your private keys. You
acknowledge and agree to waive any liability claim against me from any loss or damage of any kind arising out of or in
connection with your use of this software.
