---
name: escrow-anything
description: Zero-custody 5-mode AI agent settlement, micro-USD double-entry metering ledger, 4D budget governance lock (allow/ask/deny), Proof-of-Delivery conditional escrow, integer-conserving multi-party splits, and Creem/Escrow.com two-way reconciliation over HTTP REST, native Streamable MCP (/mcp), Causal Bazaar (escrow_anything_settlement_v1), and treg hub (0% seller commission). Enforces strict $0 charge on invalid input, misses, fake-200 shells, or PoD mismatches.
---

# Escrow-Anything Agent Skill

`Escrow-Anything` (`https://escrow.fastmesh.dev`) is a pure Python 3 standard library, zero-custody settlement and spend-governance engine backed by one SQLite WAL (`BEGIN IMMEDIATE`) double-entry ledger (`1 USD = 1,000,000 micro-USD`).

It solves the three structural failures of post-paid agent billing: concurrent negative-balance overruns, paying for fake-200/CAPTCHA/empty upstream responses, and releasing funds for broken agent-to-agent deliverables.

## Hard Guarantees & Zero-Custody Boundary

1. **Zero Fiat Custody (`platform_retained_third_party_funds_micros == 0`)**: `Escrow-Anything` is purely software metering, pre-authorization locking, Proof-of-Delivery verification, and split/reconciliation instruction generation. All real fiat checkouts, VAT/GST, and chargebacks are processed by **Creem.io (Merchant of Record)**, and high-ticket `$500–$100k+` milestones route to **Escrow.com**.
2. **Unbreakable Non-Negative Balance (`SUM(debits) == SUM(credits)`)**: Every balance mutation runs inside `threading.RLock()` + SQLite `BEGIN IMMEDIATE` with `CHECK(available_micros >= 0)` and `CHECK(locked_micros >= 0)`. Concurrent agent swarms cannot pierce spend ceilings into negative balances.
3. **Strict `$0` Charge on Miss, Error, or Fake-200**: HTTP `422` invalid inputs, PII redline rejections (`pan`, `cvv`, `ssn`, `otp`, `password`), upstream errors, empty responses (`{}`, `[]`, `null`), and Cloudflare/CAPTCHA/login-wall `200 OK` shells automatically trigger `actual_cost_micros = 0` and release `100%` of locked funds.
4. **Zero Prompt & Trajectory Resale**: Customer deliverables, tool payloads, and execution traces are never sold, licensed, or reused to train third-party models.

## Verified Adversarial & Concurrency Benchmarks

- **Unit Suite**: `24/24` passed with `0` warnings under `python3 -W default`.
- **Adversarial Gauntlet (`gauntlet/gauntlet_report.json`)**: `16/16` scenarios passed (`$0.00` external spend):
  - `16`-thread concurrent reserve contention: `6/16` succeeded within `$1.00` balance, `10` rejected `insufficient_funds`, `0` negative balances, `0` SQLite lock errors.
  - `12`-thread duplicate `idem_key` replay storm: `1` unique reservation created, `0` double-charges; mutated payload raises HTTP `409 IDEMPOTENCY_CONFLICT`.
  - Fake-200 / CAPTCHA / empty JSON guard: `6/6` adversarial fixtures settled at `$0` with `100%` reserve release.
  - Global double-entry integrity: `drift_micros == 0`, `trial_balance_drift_micros == 0`, `negative_balance_count == 0`, `platform_retained_third_party_funds_micros == 0`.

## 5 Polymorphic Settlement Modes

| Mode | Core Endpoints | Native MCP Tools | Guarantee |
| :--- | :--- | :--- | :--- |
| **Mode 1: Pre-Reserve & Exact Settle** | `POST /v1/reserve`, `POST /v1/settle`, `POST /v1/release` | `escrow_reserve`, `escrow_settle` | Atomic `max_cost_micros` lock before call; exact settle with instant delta refund; `$0` on miss/fake-200 |
| **Mode 2: 4D Budget Governance Lock** | `POST /v1/budget/policy`, `POST /v1/budget/check`, `POST /v1/approvals/{ticket_id}/decide` | `escrow_budget_check`, `escrow_approval_decide` | Enforces `per_call`, `per_hour`, `per_day`, `per_task` caps + `deny > ask > allow`; rejecting `ask` unfreezes 100% |
| **Mode 3: Proof-of-Delivery Escrow** | `POST /v1/escrow/create`, `POST /v1/escrow/deliver`, `GET /v1/escrow/{escrow_id}` | `escrow_pod_create`, `escrow_pod_verify` | Funds stay locked until `json_schema`, `sha256`, `http_verifier`, or `composite` passes; failure auto-refunds 100% |
| **Mode 4: Multi-Party Split Ledger** | `POST /v1/splits/execute`, `POST /v1/splits/reverse` | `escrow_split` | Integer basis-point split (`SUM(bps) == 10000`) across `platform`, `creator`, `affiliate`; 0% split fee; `idem_key` dedup + reversal |
| **Mode 5: Creem & Escrow.com Reconciliation** | `POST /webhooks/creem`, `POST /v1/escrow-com/record`, `GET /v1/reconcile/report`, `GET /v1/ledger/audit` | `escrow_reconcile`, `escrow_balance` | Constant-time `creem-signature` HMAC-SHA256 (`401` on bad sig); idempotent `event_id`; automatic `refund.created` split clawback |

## Quick Invocation

### 1. Native Streamable MCP (`POST https://escrow.fastmesh.dev/mcp`)

List all 9 flat settlement tools:

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/list",
  "params": {}
}
```

Reserve `500,000` micro-USD (`$0.50`) atomically before calling an upstream tool:

```json
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/call",
  "params": {
    "name": "escrow_reserve",
    "arguments": {
      "tenant_id": "tenant_demo",
      "tool_id": "search_api",
      "task_id": "task_alpha",
      "max_cost_micros": 500000,
      "idem_key": "res_idem_001"
    }
  }
}
```

Settle exact cost (`180,000` micro-USD) and auto-refund `320,000` micro-USD (or `100%` if fake-200):

```json
{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "escrow_settle",
    "arguments": {
      "reservation_id": "res_example_01",
      "actual_cost_micros": 180000,
      "response_status": 200,
      "response_body": {"verified": true}
    }
  }
}
```

### 2. HTTP REST API (`https://escrow.fastmesh.dev`)

Mode 1 Pre-Reserve & Settle:

```bash
curl -sS -X POST https://escrow.fastmesh.dev/v1/reserve \
  -H "Content-Type: application/json" \
  -d '{
    "tenant_id": "tenant_demo",
    "tool_id": "entity_lookup",
    "task_id": "onboarding_42",
    "max_cost_micros": 500000,
    "idem_key": "idem_res_42"
  }'
```

Mode 2 Configure 4D Budget & Evaluate `ask` / `deny`:

```bash
curl -sS -X POST https://escrow.fastmesh.dev/v1/budget/policy \
  -H "Content-Type: application/json" \
  -d '{
    "tenant_id": "tenant_demo",
    "caps": {
      "per_call_cap_micros": 200000,
      "per_hour_cap_micros": 2000000,
      "per_day_cap_micros": 10000000,
      "per_task_cap_micros": 1000000
    },
    "on_exceed": "ask"
  }'
```

Mode 3 Proof-of-Delivery Conditional Escrow:

```bash
curl -sS -X POST https://escrow.fastmesh.dev/v1/escrow/create \
  -H "Content-Type: application/json" \
  -d '{
    "tenant_id": "tenant_demo",
    "beneficiary_id": "agent_worker_07",
    "amount_micros": 1000000,
    "condition_type": "json_schema",
    "condition_spec": {"required_fields": ["status", "rows"]},
    "idem_key": "idem_pod_07"
  }'
```

Mode 4 Integer-Conserving Multi-Party Split (`SUM(bps) == 10000`):

```bash
curl -sS -X POST https://escrow.fastmesh.dev/v1/splits/execute \
  -H "Content-Type: application/json" \
  -d '{
    "tenant_id": "tenant_demo",
    "total_micros": 1000000,
    "parties": [
      {"role": "platform", "party_id": "escrow_anything", "bps": 1000},
      {"role": "creator", "party_id": "creator_01", "bps": 8000},
      {"role": "affiliate", "party_id": "aff_01", "bps": 1000}
    ],
    "remainder_role": "platform",
    "idem_key": "idem_split_01"
  }'
```

Mode 5 Two-Way Reconciliation & Global Double-Entry Audit:

```bash
curl -sS https://escrow.fastmesh.dev/v1/reconcile/report
curl -sS https://escrow.fastmesh.dev/v1/ledger/audit
```

### 3. Via `treg hub` (0% Seller Commission, `$0` on Failure)

```bash
treg call escrow-anything \
  --data '{"mode":"settle","tenant_id":"tenant_demo","options":"{\"reservation_id\":\"res_demo_01\",\"actual_cost_micros\":180000,\"response_status\":200,\"response_body\":{\"verified\":true}}"}'
```

### 4. Via Causal Bazaar Edge Hand (`run_hand.py`)

```bash
python3 /Users/a1-6/singularity/genesis/anything_engines/a05_escrow_anything/run_hand.py \
  --input '{"action":"verify-demos"}'
```

## Creem Webhook Verification (Mode 5 Reference)

`POST /webhooks/creem` reads `CREEM_WEBHOOK_SECRET` from environment or `0600` credential storage (never hardcoded), verifies `creem-signature` in constant time, rejects invalid/missing/tampered signatures with `HTTP 401`, deduplicates `event_id`, credits top-ups on `checkout.completed` / `payment.succeeded`, and executes automatic write-off + split clawback on `refund.created` / `chargeback.created`.

```python
import hashlib
import hmac

def verify_creem_signature(raw_body: bytes, header_sig: str, secret: str) -> bool:
    sig = header_sig.strip().lower()
    if sig.startswith("sha256="):
        sig = sig[7:]
    expected = hmac.new(secret.encode("utf-8"), raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, sig)
```

## Prepaid Credit Packs (Creem.io MoR, Non-Expiring, One-Time)

- **Starter (`$9.00`)**: `sku_escrow_starter_9` — `9,000,000` micro-USD (`$9.00` value) — `https://www.creem.io/product/prod_escrow_anything_starter_9`
- **Pro (`$29.00`, Recommended)**: `sku_escrow_pro_29` — `29,000,000` micro-USD (`$29.00` value) — `https://www.creem.io/product/prod_escrow_anything_pro_29`
- **Scale (`$99.00`)**: `sku_escrow_scale_99` — `99,000,000` micro-USD (`$99.00` value) — `https://www.creem.io/product/prod_escrow_anything_scale_99`
- **Enterprise (`$299.00`)**: `sku_escrow_enterprise_299` — `299,000,000` micro-USD (`$299.00` value) — `https://www.creem.io/product/prod_escrow_anything_enterprise_299`

## Support & Discovery

- Service Console & Try-Now: `https://escrow.fastmesh.dev/`
- Machine Index: `https://escrow.fastmesh.dev/llms.txt`
- OpenAPI 3.1.0 Spec: `https://escrow.fastmesh.dev/openapi.json`
- Technical Guides: `https://escrow.fastmesh.dev/guides`
- Contact: `ops@fastmesh.dev`
