closedhumanPR #177Trust

action-state-group: capsule-emit trust layer — verifiable, anchored records for NANDA agents

Primary submission — supersedes #54 (same commits, branch renamed to hackathon/stevenmih-capsule-trust per review process requirement). Review history is in #54. Companion PR: #55 (Problem-09 SD-JWT privacy plugin, secondary submission).

Author

Status
Closed without merging
Opened on
Jul 10
Branch
hackathon/stevenmih-capsule-trust

Description

The pitch.

**Primary submission** — supersedes #54 (same commits, branch renamed to `hackathon/stevenmih-capsule-trust` per review process requirement). Review history is in #54. Companion PR: #55 (Problem-09 SD-JWT privacy plugin, secondary submission).

---

## What this adds

`capsule-emit-nanda` — a drop-in NANDA trust plugin backed by the [Agent Action Capsule](https://github.com/action-state-group/agent-action-capsule) spec (IETF draft). Every corroborated receipt triggers a `capsule_emit.emit()` call, sealing the reputation event to a tamper-evident ledger that any third party can independently verify — with zero changes to existing NANDA agent code.

A companion demo (`StripeCapsuledPayments`) shows the same capsule pattern applied to payment events.

## How it works

```
NANDA scenario  →  ctx.plugins.get("trust").report(agent, evidence)
                →  CapsuleEmitTrust.report()
                →  capsule_emit.emit(action, operator, agent_input, agent_output, anchor=True)
                →  anchored to https://anchor.agentactioncapsule.org/v1/digest (live public log)
                →  capsule sealed to local JSONL ledger
                →  agent-action-capsule verify --store capsule_ledger.jsonl  ✔
```

**Three gates before a receipt contributes to reputation:**
1. Valid — Ed25519 issuer signature verifies
2. Corroborated — distinct counterparty co-signed the same interaction
3. Anchored + ledger-verified — a capsule was emitted **and** `verify_input_digest()` confirms the sealed digest still matches the receipt content at score time

Gate 3 is the novel contribution. `agent_receipts` has no ledger reference and cannot detect post-seal record mutation. `CapsuleEmitTrust.score()` re-verifies every anchored receipt against the JSONL ledger; a mutated receipt fails `verify_input_digest()` and is excluded.

## Adversarial validator (Gate 3)

`test_gate3_tampered_receipt_excluded_from_score` demonstrates the attack `agent_receipts` misses:

1. `sign_receipt()` + `cosign_receipt()` → valid, corroborated receipt
2. `CapsuleEmitTrust.report()` → capsule sealed with `agent_input_digest = hash(receipt)`
3. `score()` before tamper → `score > 0` ✓
4. Adversary mutates `receipt["action"]["category"]` in-memory
5. `score()` re-runs → `verify_input_digest()` detects mismatch → **score = 0.0** ✓

`agent_receipts` returns `score > 0` at step 5 because it has no ledger check.

## Installable package

```
pip install -e examples/capsule-emit
```

```yaml
# scenario.yaml
layers:
  trust: capsule_emit
```

## Smoke tests

```
$ pip install -e examples/capsule-emit && pytest examples/capsule-emit/tests/ -v
tests/test_smoke.py::test_trust_report_and_score                         PASSED
tests/test_smoke.py::test_sandbox_pay                                    PASSED
tests/test_smoke.py::test_sandbox_pay_is_deterministic                   PASSED
tests/test_smoke.py::test_gate3_tampered_receipt_excluded_from_score     PASSED
```

## Files changed

| Path | Role |
|------|------|
| `examples/capsule-emit/capsule_emit_nanda/trust.py` | `CapsuleEmitTrust` — Gate 3 ledger re-verification in `score()` |
| `examples/capsule-emit/capsule_emit_nanda/payments.py` | `StripeCapsuledPayments` — env read inside `pay()`, deterministic sandbox seed |
| `examples/capsule-emit/pyproject.toml` | Installable package config, entry-points |
| `examples/capsule-emit/README.md` | Plugin docs |
| `examples/capsule-emit/tests/test_smoke.py` | 4 tests including adversarial Gate 3 test |
| `examples/capsule-emit/capsule_emit_nanda/__init__.py` | Package exports |
| `examples/stripe-capsule-payment/README.md` | Stripe demo docs |
| `scenarios/receipt_reputation_capsule.yaml` | Scenario using this trust layer |
| `pyproject.toml` | `exclude = ["examples"]` for pyright (examples have external deps not in workspace venv) |

## Demo clarifications

- `StripeCapsuledPayments` is a **standalone demo**, not a conforming NANDA Payments protocol implementation. See module docstring for p

…

Try it

Open PR on GitHubView diff

Checkout locally

git fetch origin pull/177/head:pr-177
git checkout pr-177