Metadata-Version: 2.4
Name: digirails
Version: 0.1.0
Summary: Python SDK for the DR-Pay protocol — AI agent payments on DigiByte
Project-URL: Homepage, https://github.com/digirails-protocol/digirails-python
Project-URL: Repository, https://github.com/digirails-protocol/digirails-python
Project-URL: Specification, https://github.com/digirails-protocol/digirails-spec
Author: DigiRails Protocol
License-Expression: MIT
License-File: LICENSE
Keywords: ai-agents,blockchain,cryptocurrency,digibyte,payments
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
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: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: aiohttp>=3.9
Requires-Dist: cryptography>=42.0
Requires-Dist: ecdsa>=0.19
Requires-Dist: pydantic>=2.0
Provides-Extra: dev
Requires-Dist: aioresponses; extra == 'dev'
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest-cov; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Provides-Extra: fast
Requires-Dist: coincurve>=20.0; extra == 'fast'
Description-Content-Type: text/markdown

# digirails

Python SDK for the [DR-Pay protocol](https://github.com/digirails-protocol/digirails-spec) — permissionless AI agent payments on DigiByte.

## What is this?

DigiRails enables autonomous AI agents to discover, negotiate with, and pay each other using DigiByte's Layer 1 blockchain. This SDK implements the DR-Pay protocol: the 4-message payment flow, agent identity, service manifests, and on-chain data encoding.

Every payment settles on-chain as a standard DigiByte transaction. No sidechains, no Layer 2, no API keys.

## Install

```bash
pip install digirails
```

## Quick Start

### Buyer — purchase a service in one call

```python
import asyncio
from digirails import Agent, REGTEST

async def main():
    async with Agent.generate(
        network=REGTEST,
        rpc_url="http://digirails:digirails@127.0.0.1:18443",
    ) as buyer:
        result = await buyer.request_service(
            seller_url="http://127.0.0.1:9001",
            service_id="echo",
            params={"message": "Hello from DigiRails!"},
            max_amount="0.01",
        )
        print(result.result)

asyncio.run(main())
```

### Seller — offer a service

```python
import asyncio
from digirails import Agent, ServiceCategory, REGTEST

def handle_echo(params: dict) -> dict:
    return {"echo": params.get("message", "")}

async def main():
    seller = Agent.generate(
        network=REGTEST,
        rpc_url="http://digirails:digirails@127.0.0.1:18443",
    )
    seller.register_service(
        service_id="echo",
        handler=handle_echo,
        price="0.001",
        category=ServiceCategory.GENERAL_COMPUTE,
    )
    await seller.serve(port=9001)
    await asyncio.Event().wait()  # Run forever

asyncio.run(main())
```

## What happens under the hood

```
Buyer                                Seller
  |                                    |
  |  GET /.well-known/digirails.json   |
  |----------------------------------->|  1. Discover manifest
  |<-----------------------------------|
  |                                    |
  |  POST /drpay/request               |
  |----------------------------------->|  2. SERVICE_REQUEST
  |<-----------------------------------|  3. PAYMENT_INVOICE
  |                                    |
  |  [build, sign, broadcast tx]       |
  |                                    |
  |  POST /drpay/broadcast             |
  |----------------------------------->|  4. PAYMENT_BROADCAST
  |                                    |  5. Verify payment
  |                                    |  6. Execute service
  |<-----------------------------------|  7. SERVICE_DELIVERY
```

## Regtest Demo

Run the self-contained demo with two agents transacting locally:

```bash
# 1. Start DigiByte Core in regtest mode
digibyted -regtest -daemon -server \
  -rpcuser=digirails -rpcpassword=digirails \
  -txindex=1 -fallbackfee=0.0001

# 2. Run the demo
python examples/regtest_demo.py
```

## Features

- **Light mode**: No DigiByte node required. Connects to `rpc.digirails.org` or any RPC endpoint.
- **Async-native**: Built on asyncio + aiohttp.
- **Type-safe**: Pydantic models for all protocol messages.
- **4 dependencies**: pydantic, aiohttp, cryptography, ecdsa. All with pre-built wheels.
- **SegWit transactions**: BIP-143 signing for P2WPKH inputs.
- **Encrypted keystore**: AES-256-GCM encrypted key files.
- **All 18 service categories** from the DR-Pay spec.

## Protocol Version

Implements DR-Pay specification v0.3.0.

## License

MIT
