# Run the Valet proof of concept

Source: https://github.com/veridactlabs/veridact-valet/blob/main/README.md

## Run it

Python 3.11 or later.

```bash
pip install -r requirements.txt

python demo.py          # scripted end-to-end demo, takes a second or two
python -m pytest -q     # behaviour tests
python run.py           # clickable demo: Kaya on :8001, Marula Bank on :8000
```

Or with Docker:

```bash
docker compose up --build             # clickable demo
docker compose run --rm demo          # scripted demo
docker compose run --rm demo pytest -q

# customers sign in with Keycloak instead of the demo password (thandi / demo on Keycloak's page)
docker compose -f docker-compose.yml -f docker-compose.keycloak.yml up --build
```

## Click through it

1. Open **Kaya** at <http://localhost:8001> and tap **Connect Marula Bank**.
2. You land on **Marula Bank's own** sign-in page, not Kaya's. Sign in as `thandi` with password `demo`.
3. The consent screen shows who Kaya is (verified operator, from the agent registry). Choose **Bill payer**, keep
   R2,000 a month, and confirm.
4. Back in Kaya:
   - **Pay the water bill** goes straight through (an existing beneficiary, inside the limit).
   - **Pay City Power** is held: a new recipient. Open <http://localhost:8000/app/approvals>, read the approval,
     which the bank builds (amount, recipient, scam warning; the agent's note is labelled as written by the agent),
     and approve. Kaya picks it up within a few seconds and pays once.
   - **Pay school fees** is over the monthly limit, so it is held for approval too. Try declining it.
   - **Add QuickLoans as a beneficiary** is refused. Agents can never add beneficiaries.
5. In Marula Bank, go to **AI agents › Kaya** to see every action with its receipt hash. Tap any payment for its
   evidence page: who asked, what you allowed, whose decision it was and what the bank did. Tap **Pause Kaya**, then try
   anything in Kaya: it is refused on the very next call. Resume, then **Disconnect** to end it for good.
6. <http://localhost:8000/ops> plays the bank (or Veridact): withdraw trust in Kaya's operator and every grant for
   Kaya stops at once. The page also verifies the receipt chain.

To start again, stop the servers and delete the `data/` folder (or `docker compose down -v`).

## Configuration

| Variable | Used by | Default | Meaning |
|---|---|---|---|
| `BANK_PUBLIC_URL` | bank, Kaya | `http://localhost:8000` | The issuer, and where the customer's browser reaches the bank |
| `BANK_INTERNAL_URL` | Kaya | `http://localhost:8000` | Where Kaya's server reaches the bank (`http://bank:8000` in Compose) |
| `KAYA_PUBLIC_URL` | Kaya | `http://localhost:8001` | Used for Kaya's redirect URI |
| `VALET_DATA` | both | `./data` | SQLite database, demo keys, registry files |
| `BANK_SESSION_SECRET` | bank | demo value | Signs the customer's session cookie. Change it outside a laptop. |
| `CUSTOMER_IDP`, `OIDC_*` | bank | local | Customer sign-in through the bank's OpenID Connect provider (see [Identity providers](https://veridact.net/docs/valet/overview/#identity-providers)) |
| `STEP_UP_MAX_AGE` | bank | `300` | Seconds a sign-in stays fresh enough to consent or approve |
| `VALET_POLICY_VERSION` | bank | unset | The bank's change reference for its policy, named on every receipt with the policy's hash. Unset: `unlabelled-<hash>`, and `/readyz` reports `labelled: false` |
| `VALET_EXTERNAL_ISSUERS`, `VALET_INTERNAL_SECRET` | bank | unset | Native mode: accept the bank IdP's tokens; let it register consents |
| `VALET_HANDOFF_SECRET`, `VALET_HANDOFF_IDPS` | bank | unset | Native mode: consent hand-off from the bank's IdP, and where results may be returned |
| `KAYA_CONNECT_VIA` | Kaya | unset | Native mode: the IdP's metadata URL; Kaya connects through it |

Limits live in `valet/bank/config.py`: token lifetimes (access 5 minutes, approval 5 minutes), maximum grant 90 days,
maximum monthly limit R5,000, at most 3 approvals waiting at once. Together with the profile version they form the policy document whose hash every receipt
carries (`GET /ops/policies`; [Technical design](https://veridact.net/docs/valet/technical-design/) §8.2).
