Metadata-Version: 2.4
Name: x402-algorand
Version: 0.1.3
Summary: Algorand AVM extensions for the x402 payment protocol.
Author-email: AI Economy Team <team@aieconomy.com>
License: MIT
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: py-algorand-sdk>=2.0.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: fastapi>=0.95.0
Requires-Dist: httpx>=0.20.0

# x402-algorand

Algorand AVM extensions for the [x402 payment protocol](https://github.com/GoPlausible/x402-avm).

This package is a fork of [GoPlausible/x402-avm](https://github.com/GoPlausible/x402-avm) (v2.0.2) customized for seamless native ALGO settlement and private node / LocalNet integration.

## Key Changes in this Fork

1. **Native ALGO Payments (`asset == 0`)**:
   - `mechanisms/avm/exact/client.py`: Builds native `PaymentTxn` (type `pay`) instead of `AssetTransferTxn` (`axfer`) when `requirements.asset == "0"` or `0`.
   - `mechanisms/avm/exact/facilitator.py`: `verify()` checks for `TXN_TYPE_PAYMENT`, verifies receiver `payment_txn.receiver == requirements.pay_to`, and verifies `payment_txn.amount == requirements.amount`. For `asset != 0`, standard ASA transfer verification applies.

2. **Custom Algod Token Support**:
   - Added `algod_token` parameter to `ExactAvmScheme` client and `register_exact_avm_client`.
   - Enables direct authentication with local nodes, such as AlgoKit LocalNet (`X-Algo-API-Token: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`).

3. **CAIP-2 Network Resolution & Private Nodes**:
   - `mechanisms/avm/utils.py`: Known networks (MainNet, TestNet, FNet) are mapped via `NETWORK_CONFIGS`. Any custom or LocalNet CAIP-2 network (`algorand:<genesis_hash>`) is accepted by `normalize_network` without requiring a static table entry, and `get_genesis_hash` dynamically parses the genesis hash from the CAIP-2 string.
   - When configured with a custom `algod_url` / `algod_token`, clients and facilitators interact directly with private or LocalNet nodes for arbitrary genesis hashes.

## Installation

```bash
pip install -e .
```

## Running Tests

The test suite includes offline unit tests with mocked Algod/signers as well as integration tests on a live Algorand LocalNet network.

### Offline Unit Tests
Does not require a running node or network connection:
```bash
python -m pytest tests -q
```
*(Runs unit tests in `tests/test_avm_fork.py`; skips LocalNet tests)*

### LocalNet Integration Tests
Requires AlgoKit LocalNet running and accounts bootstrapped in `chain/accounts.json`:
```bash
LOCALNET=1 python -m pytest tests -q
```
*(Runs all unit tests plus `tests/test_localnet_algo_payment.py`, testing end-to-end payment creation, verification, and on-chain settlement)*
