Metadata-Version: 2.4
Name: chain-receipt
Version: 0.1.0
Summary: Chain Receipt — verified AI output receipts. Client SDK for the OpenAI-compatible proxy and the offline receipt verifier.
Author: Cinian Studios Inc.
License-Expression: MIT
Project-URL: Homepage, https://chainreceipt.link
Project-URL: Repository, https://github.com/CinianStudios/chain-receipt
Project-URL: Documentation, https://chainreceipt.link/docs
Project-URL: Issue Tracker, https://github.com/CinianStudios/chain-receipt/issues
Keywords: ai,receipts,verification,ed25519,openai,chain-receipt
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Security :: Cryptography
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cryptography>=42
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: build>=1; extra == "dev"
Requires-Dist: twine>=5; extra == "dev"
Dynamic: license-file

# chain-receipt — Python SDK

Verified AI output receipts. Every call through the Chain Receipt
proxy gets a signed receipt: a canonical-JSON record (schema `air/1`)
whose SHA-256 hash is signed with Ed25519 and anchored to Bitcoin in
batches. This SDK calls the proxy, fetches receipts, downloads
evidence bundles, and verifies receipts **offline** — the signature
and hash checks need no network.

## Install

```bash
pip install chain-receipt
```

Requires Python 3.11+. The only runtime dependency is
[`cryptography`](https://cryptography.io/) (for Ed25519); HTTP uses
the standard library.

## Quickstart

```python
from chain_receipt import ChainReceiptClient

client = ChainReceiptClient(api_key="crk_live_...")  # or set CHAIN_RECEIPT_API_KEY

# 1. Call any model through the OpenAI-compatible proxy.
resp = client.chat_completions(
    model="openai/gpt-6-luna",
    messages=[{"role": "user", "content": "Say the word receipt."}],
    max_tokens=20,
)
print(resp["choices"][0]["message"]["content"])
receipt_id = resp["ai_receipt"]["receipt_id"]  # keep the salts too:
salts = resp["ai_receipt"]["salts"]            # returned ONCE, never stored

# 2. Fetch the receipt envelope and verify it offline.
result = client.verify_receipt(receipt_id)
print(result.valid, result.hash_ok, result.signature_ok)  # True True True

# 3. Or verify an envelope you already hold, with no client at all.
from chain_receipt import verify_receipt, fetch_public_keys

keys = fetch_public_keys()  # /.well-known/receipt-keys.json (public)
result = verify_receipt(envelope, public_keys=keys)
```

## Receipts

```python
# One receipt, full envelope (receipt, receipt_hash, signature, anchor, verify_url)
envelope = client.get_receipt("rcpt_...")

# Newest first, paginated (limit 1–100, default 50)
page = client.list_receipts(limit=10, status="complete")
for row in client.iter_receipts():  # walks every page
    print(row["receipt_id"], row["anchor_status"])

# Evidence bundle: envelope JSON + .ots Bitcoin proof (when batched)
bundle = client.download_bundle("rcpt_...", path="rcpt_....zip")
print(bundle.ots is not None)  # False until the receipt is batched
```

## Verify content, not just the signature

The receipt stores hashes of your prompt and the response, salted so
a short prompt cannot be guessed. Re-hash your own copies to prove
the receipt is *about* your call:

```python
from chain_receipt import build_prompt_commitment, verify_receipt_content

ok = verify_receipt_content(
    envelope["receipt"],
    salts,  # from ai_receipt, returned once at call time
    prompt_body=build_prompt_commitment(
        messages=[{"role": "user", "content": "Say the word receipt."}]
    ),
    response_json=resp,  # the full provider response object
)
```

## Streaming

```python
events = client.chat_completions(
    model="google/gemini-3.5-flash",
    messages=[{"role": "user", "content": "Count to three."}],
    max_tokens=30,
    stream=True,
)
for event in events:
    if event.get("object") == "ai_receipt":
        print("receipt:", event["ai_receipt"]["receipt_id"])
```

## Bring your own provider key

Pass it per call (never stored by the SDK) or save it on the portal
Keys page and omit it:

```python
resp = client.chat_completions(
    model="anthropic/claude-haiku-4-5",
    messages=[{"role": "user", "content": "Say the word receipt."}],
    provider_key="sk-ant-...",  # sent as X-Provider-Key
)
```

## What is verified, exactly

`verify_receipt` checks, each reported separately:

- **hash** — `receipt_hash` recomputes from the receipt object
  (SHA-256 over RFC 8785 canonical JSON).
- **signature** — Ed25519 verifies over the 32 raw hash bytes,
  against the published public key for `signature.key_id`.
- **merkle** — when the envelope carries an anchor proof, the leaf +
  proof recompute to the batch root (otherwise `None`).

`valid` is true when every check that could run passed. A genuine
receipt is valid before its batch confirms on Bitcoin — anchor
status is reported separately in the envelope.

## Golden vectors

The primitives in this SDK (JCS, Ed25519, SHA-256, Merkle root) pass
the same golden vectors as `@chain-receipt/core`, the verifier, and
the JS SDK: `packages/core/test-vectors/golden.json` (JCS from RFC
8785 §3.2.3, Ed25519 from RFC 8032 test 1, SHA-256 from FIPS 180-4).
Run them with `pytest` in `packages/sdk-py`.

## Links

- Site: https://chainreceipt.link
- Docs: https://chainreceipt.link/docs
- Verify a receipt in the browser: https://chainreceipt.link/verify
- Published signing keys: https://chainreceipt.link/.well-known/receipt-keys.json
