diff options
Diffstat (limited to 'CHECKLIST.md')
| -rw-r--r-- | CHECKLIST.md | 382 |
1 files changed, 106 insertions, 276 deletions
diff --git a/CHECKLIST.md b/CHECKLIST.md index 5cedd30..b71bd14 100644 --- a/CHECKLIST.md +++ b/CHECKLIST.md | |||
| @@ -43,34 +43,10 @@ | |||
| 43 | - [x] Makefile: nutshell wallet targets (wallet-setup, wallet-info, mint-token, send-token) | 43 | - [x] Makefile: nutshell wallet targets (wallet-setup, wallet-info, mint-token, send-token) |
| 44 | - [x] `tests/phase2.mjs`: `/whoami` test checks `includes('mac=')` | 44 | - [x] `tests/phase2.mjs`: `/whoami` test checks `includes('mac=')` |
| 45 | 45 | ||
| 46 | ### Infrastructure | ||
| 47 | - [x] Upstream gateway on enx00e04c633a90 (192.168.2.0/24, metric 101, default route) | ||
| 48 | - [x] WiFi wlp59s0 free for ESP32 TollGate connection | ||
| 49 | - [x] Mint URL verified: `testnut.cashu.space` works (auto-pays invoices) | ||
| 50 | |||
| 51 | ### Tests Passing | 46 | ### Tests Passing |
| 52 | - [x] Test 15: Advertisement valid (kind=10021 with price_per_step) — PASSING | 47 | - [x] Tests 15-24: ALL PASSING |
| 53 | - [x] Test 16: Valid payment (POST :2121/ with valid Cashu token → kind=1022 session) — PASSING | ||
| 54 | - [x] Test 17: Usage tracking after payment (GET :2121/usage → active usage) — PASSING | ||
| 55 | - [x] Test 18: Internet after payment (ping through TollGate works) — PASSING | ||
| 56 | - [x] Test 19: Invalid token rejected (POST garbage → 400, kind=21023) — PASSING | ||
| 57 | - [x] Test 20: Spent token rejected (reuse token → kind=21023) — PASSING | ||
| 58 | - [x] Test 21: Wrong mint rejected (POST token from wrong mint → kind=21023) — PASSING | ||
| 59 | - [x] Test 22: Session expiry (wait for allotment → internet blocked) — PASSING | ||
| 60 | - [x] Test 23: Session renewal (second payment → allotment extended) — PASSING | ||
| 61 | - [x] Test: /whoami returns ip=X.X.X.X mac=XX:XX:XX:XX:XX:XX — PASSING | ||
| 62 | - [x] Test: Portal has payment form (Cashu token input + Pay button) — PASSING | ||
| 63 | |||
| 64 | ### Captive Portal Detection Fix | ||
| 65 | - [x] Added DoT reject server on port 853 (TCP RST forces DNS fallback to port 53) | ||
| 66 | - [x] DNS hijack now returns NXDOMAIN for ALL non-A query types (prevents DNS leaks) | ||
| 67 | - [x] Shorter TTL on hijack responses (10s) for faster detection | ||
| 68 | - [x] Explicit 302 redirect handlers for all captive detection URIs (/generate_204, /hotspot-detect.html, etc.) | ||
| 69 | - [x] HTTP request logging for captive detection endpoints | ||
| 70 | - [x] DNS query logging for unauthenticated clients | ||
| 71 | - [x] Verified working with GrapheneOS phone (commit `236b61d`) | ||
| 72 | 48 | ||
| 73 | ## Phase 3: On-Device Wallet + Nostr Identity + Wifistr — IN PROGRESS | 49 | ## Phase 3: On-Device Wallet + Nostr Identity + Wifistr — COMPLETE |
| 74 | ### nucula Wallet Integration | 50 | ### nucula Wallet Integration |
| 75 | - [x] Add nucula as git submodule (`nucula_src/`) | 51 | - [x] Add nucula as git submodule (`nucula_src/`) |
| 76 | - [x] Create `components/secp256k1/` (symlink to nucula's libsecp256k1) | 52 | - [x] Create `components/secp256k1/` (symlink to nucula's libsecp256k1) |
| @@ -79,271 +55,125 @@ | |||
| 79 | - [x] All wallet operations tested on Board A: pay, swap, send, persistence | 55 | - [x] All wallet operations tested on Board A: pay, swap, send, persistence |
| 80 | 56 | ||
| 81 | ### Nostr Identity Derivation (identity.c/h) | 57 | ### Nostr Identity Derivation (identity.c/h) |
| 82 | - [x] Create `identity.h` — API: `identity_init(nsec_hex)`, derived value accessors | 58 | - [x] HMAC-SHA512 derivation via mbedtls, npub via secp256k1 |
| 83 | - [x] Create `identity.c` — HMAC-SHA512 derivation via mbedtls, npub via secp256k1 | 59 | - [x] Derive STA/AP MAC, SSID, AP IP from nsec |
| 84 | - [x] Derive STA MAC: `tollgate_derive(nsec, "sta-mac", 0)` → 6 bytes, locally administered | ||
| 85 | - [x] Derive AP MAC: `tollgate_derive(nsec, "ap-mac", 0)` → 6 bytes, locally administered | ||
| 86 | - [x] Derive SSID: `"TollGate-" + hex(AP_MAC[3:6])` | ||
| 87 | - [x] Derive AP IP: hash-based from AP MAC bytes | ||
| 88 | - [x] Compute npub: secp256k1 x-only pubkey from nsec | ||
| 89 | - [x] Set MACs via `esp_wifi_set_mac()` in boot sequence | 60 | - [x] Set MACs via `esp_wifi_set_mac()` in boot sequence |
| 61 | - [x] 24/24 unit tests passing | ||
| 90 | 62 | ||
| 91 | ### Nostr Event Signing (nostr_event.c/h) | 63 | ### Nostr Event Signing (nostr_event.c/h) |
| 92 | - [x] Create `nostr_event.h` — NIP-01 event struct + sign/serialize API | 64 | - [x] NIP-01 canonical JSON, SHA-256 ID, Schnorr signature |
| 93 | - [x] Create `nostr_event.c` — canonical JSON, SHA-256 ID, Schnorr signature | 65 | - [x] 23/23 unit tests passing |
| 94 | - [x] Uses `secp256k1_schnorrsig_sign32()` for BIP-340 signatures | ||
| 95 | 66 | ||
| 96 | ### Geohash Encoding (geohash.c/h) | 67 | ### Geohash Encoding (geohash.c/h) |
| 97 | - [x] Create `geohash.h` — `geohash_encode(lat, lon, precision, out)` | 68 | - [x] Standard base-32 geohash encoding |
| 98 | - [x] Create `geohash.c` — standard base-32 geohash encoding | 69 | - [x] 11/11 unit tests passing |
| 99 | 70 | ||
| 100 | ### Wifistr Service Discovery (wifistr.c/h) | 71 | ### Wifistr Service Discovery (wifistr.c/h) |
| 101 | - [x] Create `wifistr.h` — `wifistr_publish()` API | 72 | - [x] kind 38787 event builder + WebSocket relay publish |
| 102 | - [x] Create `wifistr.c` — kind 38787 event builder + WebSocket relay publish | ||
| 103 | - [x] Build event with tags: d, ssid, h, security, g, c | ||
| 104 | - [x] WebSocket client: raw TCP + TLS (esp_tls.h) + HTTP Upgrade | ||
| 105 | - [x] Publish on boot + periodic timer (6h default) | 73 | - [x] Publish on boot + periodic timer (6h default) |
| 106 | 74 | - [x] Verified published to relay.damus.io and nos.lol | |
| 107 | ### Config Changes (config.c/h) | 75 | |
| 108 | - [x] Add to struct: nsec, npub, nostr_geohash, nostr_relays, nostr_publish_interval_s, sta_mac, ap_mac | 76 | ## Phase 4: ESP32 TollGate Client Detection + Auto-Payment — COMPLETE (commit `78dd599`) |
| 109 | - [x] Remove from JSON parsing: ap_ssid, ap_ip (now derived from nsec) | 77 | - [x] tollgate_client.c/h — detection, payment, monitoring, state machine |
| 110 | - [x] Keep: ap_password, ap_channel, ap_max_conn (hardcoded defaults) | 78 | - [x] Config fields: client_enabled, client_steps_to_buy, etc. |
| 111 | - [x] Update default config.json template with nsec and Nostr fields | 79 | - [x] Integration into tollgate_main.c |
| 112 | 80 | - [x] 30/30 unit tests passing | |
| 113 | ### Boot Sequence Changes (tollgate_main.c) | 81 | |
| 114 | - [x] Call `identity_init(nsec)` after config load, before WiFi init | 82 | ## Phase 5: Lightning Auto-Payout — COMPLETE (commit `cb4bd7d`) |
| 115 | - [x] Set STA/AP MAC via `esp_wifi_set_mac()` after `esp_wifi_init()`, before `esp_wifi_start()` | 83 | - [x] lnurl_pay.c/h — LNURL-pay HTTP flow |
| 116 | - [x] Remove old `tollgate_config_derive_unique()` call | 84 | - [x] lightning_payout.c/h — periodic balance check, threshold, multi-recipient split, melt |
| 117 | - [x] Use derived SSID/IP in AP configuration | 85 | - [x] nucula_wallet_melt() bridge for NUT-05 |
| 118 | - [x] Start wifistr publish task after services start | 86 | - [x] Config: payout.enabled, recipients, mints, fee_tolerance, etc. |
| 119 | 87 | - [x] 7/7 lnurl_pay + 11/11 lightning_payout = 18 unit tests passing | |
| 120 | ### Build System | 88 | |
| 121 | - [x] Add identity.c, nostr_event.c, geohash.c, wifistr.c to CMakeLists.txt SRCS | 89 | ## Phase 6: Bytes-Based Billing — COMPLETE (commit `edd125d`) |
| 122 | - [x] Add `secp256k1` to REQUIRES (for identity.c and nostr_event.c) | 90 | - [x] Dual-metric session support (milliseconds + bytes) |
| 123 | - [x] Clean build (0 errors, 0 warnings) | 91 | - [x] session_create_bytes(), session_add_bytes() |
| 124 | 92 | - [x] Config: metric, step_size_bytes | |
| 125 | ### Hardware Testing | 93 | - [x] Discovery endpoint advertises correct metric |
| 126 | - [x] Flash Board A, verify wallet boot (keyset fetch succeeds) | 94 | - [x] Unit tests: bytes session lifecycle, mixed metrics |
| 127 | - [x] Pay Board A with Cashu token, verify proofs stored (GET /wallet) | 95 | |
| 128 | - [x] Test POST /wallet/swap on Board A | 96 | ## Phase 7: MCP Handler + NIP-04 + CVM Server — COMPLETE (commit `fdf662f`) |
| 129 | - [x] Test POST /wallet/send on Board A, verify token is valid | 97 | - [x] mcp_handler.c/h — 4 tools (get_config, set_config, get_balance, wallet_send), 25 unit tests |
| 130 | - [x] Flash Board A with new identity derivation, verify derived SSID/MAC/IP | 98 | - [x] nip04.c/h — AES-256-CBC + ECDH with 0x02 compressed pubkey prefix, 15 unit tests |
| 131 | - [x] Verify captive portal works with new SSID/IP | 99 | - [x] cvm_server.c/h — Nostr DM listener skeleton with FreeRTOS task |
| 132 | - [x] Verify payment flow still works with identity-derived config | 100 | - [x] Fixed NIP-04 IV bug: mbedtls_aes_crypt_cbc modifies IV in-place |
| 133 | - [x] Verify wifistr event published to relay (damus + nos.lol) | 101 | - [x] Fixed missing esp_random.h include in nip04.c |
| 134 | - [ ] Flash Board B with new firmware (different nsec) | 102 | - [x] 156 total unit tests passing across 10 test binaries |
| 135 | - [ ] Cross-board payment: Board B token → Board A | 103 | |
| 136 | - [ ] Verify both boards show correct balances after cross-board payment | 104 | ## Bug Fixes — COMPLETE (commit `3342c8e`) |
| 137 | 105 | - [x] reset_auth_handler now calls session_revoke_all() before firewall_revoke_all() | |
| 138 | ### Tests 25-27 (deferred from Phase 2, need Board B) | 106 | - [x] Port 80 /usage shows real session data (remaining/total) instead of "0/0" |
| 139 | - [ ] Test 25: Two clients pay independently (laptop + Board B) | 107 | - [x] Config metric defaults to "milliseconds" (ESP32 can't track per-client bytes from NAT) |
| 140 | - [ ] Test 26: Client isolation (only payer gets internet) | 108 | - [x] Fixed sys_evt stack overflow: deferred start_services() to dedicated 32KB task |
| 141 | - [ ] Test 27: Full e2e: portal → pay → browse | 109 | |
| 142 | 110 | ## Playwright Interop Tests — COMPLETE (commit `4fb44e7`) | |
| 143 | ### Tests 28-38 (Phase 3 specific) | 111 | - [x] 18/18 tests passing (11 ESP32 + 7 ESP32↔OpenWRT interop) |
| 144 | - [ ] Test 28: Wallet boot (keysets loaded) | 112 | - [x] 7 screenshots generated |
| 145 | - [ ] Test 29: Receive via wallet (balance incremented) | 113 | - [x] Double-spend rejection verified on live hardware |
| 146 | - [ ] Test 30: Wallet swap (same balance, new proofs) | 114 | |
| 147 | - [ ] Test 31: Wallet send (valid cashuA token) | 115 | --- |
| 148 | - [ ] Test 32: Persistence survives reboot | 116 | |
| 149 | - [ ] Test 33: Cross-board payment | 117 | ## TODO — In Progress |
| 150 | - [ ] Test 34: 5 consecutive payments | 118 | |
| 151 | - [ ] Test 35: Stress: rapid pay/expire | 119 | ### Per-Client NAT Filtering (Multi-Client Fix) |
| 152 | 120 | - [ ] Create `main/lwip_tollgate_hooks.h` — LWIP_HOOK_IP4_CANFORWARD definition | |
| 153 | ### Automated Tests | 121 | - [ ] Update `CMakeLists.txt` — inject hook header into lwIP compilation |
| 154 | - [ ] Write tests/phase3.mjs (wallet endpoint tests + cross-board) | 122 | - [ ] Add `tollgate_ip4_canforward_filter()` to `firewall.c` — filter forwarded packets by source IP |
| 155 | - [ ] All Phase 3 tests passing | 123 | - [ ] Change firewall strategy: NAT always ON, per-client filter in lwIP forwarding path |
| 156 | 124 | - [ ] Remove `update_nat()`, `firewall_enable_nat()`, `firewall_disable_nat()` from firewall.c | |
| 157 | ## Test Coverage — IN PROGRESS | 125 | - [ ] Update `stop_services()` in tollgate_main.c — remove `firewall_disable_nat()` call |
| 158 | 126 | - [ ] Add unit test for filter function | |
| 159 | ### Host Unit Tests (tests/unit/) | 127 | - [ ] Build, flash, test on Board A |
| 160 | - [ ] Create `tests/unit/stubs/` — clean ESP-IDF type stubs for host compilation | 128 | - [ ] Verify multi-client isolation: expire one client while other is active |
| 161 | - [ ] Create `tests/unit/Makefile` — compiles all unit tests with host gcc | 129 | |
| 162 | - [ ] Install system deps: `libmbedtls-dev`, `libcjson-dev` | 130 | ### Spent-Secret Cleanup |
| 163 | - [ ] `test_geohash.c` — geohash_encode against reference vectors (Munich, NYC, origin) | 131 | - [ ] Remove `s_spent_secrets[]` and `session_is_secret_spent()` from `session.c` |
| 164 | - [ ] `test_identity.c` — HMAC-SHA512 derivation, MAC bits, SSID/IP determinism | 132 | - [ ] Remove `spent_secrets` field from `session_t` struct in `session.h` |
| 165 | - [ ] `test_nostr_event.c` — NIP-01 event ID, Schnorr sign+verify, JSON serialization | 133 | - [ ] Remove `spent_secrets` params from `session_create()` and `session_create_bytes()` |
| 166 | - [ ] `test_cashu.c` — token decode, allotment calc, mint validation | 134 | - [ ] Remove local spent-secret check in `tollgate_api.c` (lines 227-239) |
| 167 | - [ ] `test_session.c` — session lifecycle, expiry, spent-secret dedup | 135 | - [ ] Remove `secrets[]` array construction in `tollgate_api.c` |
| 168 | - [ ] `make test-unit` passes all unit tests | 136 | - [ ] Update `tests/unit/test_session.c` — remove secret-tracking tests |
| 137 | - [ ] Run `make test-unit` — all tests pass | ||
| 138 | |||
| 139 | ### Integration Tests (tests/integration/) | ||
| 140 | - [ ] Create `tests/integration/` directory | ||
| 141 | - [ ] Move existing tests (api.mjs, network.mjs, smoke.mjs, phase2.mjs) into integration/ | ||
| 142 | - [ ] Write `test-reset-auth.mjs` — verify sessions cleared after reset | ||
| 143 | - [ ] Write `test-session-lifecycle.mjs` — pay → verify usage → wait expiry → verify blocked (65s) | ||
| 144 | - [ ] Write `test-dns-firewall.mjs` — DNS hijack before auth, forward after auth | ||
| 145 | - [ ] Update Makefile targets for new paths | ||
| 146 | - [ ] All integration tests passing | ||
| 169 | 147 | ||
| 170 | ### Test Reorganization | 148 | ### Test Reorganization |
| 171 | - [ ] Move `tests/api.mjs` → `tests/integration/phase1_api.mjs` | 149 | - [ ] Fix all hardcoded IPs → `process.env.TOLLGATE_IP` |
| 172 | - [ ] Move `tests/network.mjs` → `tests/integration/phase1_network.mjs` | 150 | - [ ] Move `tests/captive-portal.spec.mjs` → `tests/e2e/` |
| 173 | - [ ] Move `tests/smoke.mjs` → `tests/integration/smoke.mjs` | 151 | - [ ] Move `tests/interop-happy-path.spec.mjs` → `tests/e2e/` or `tests/integration/` |
| 174 | - [ ] Move `tests/phase2.mjs` → `tests/integration/phase2.mjs` | 152 | - [ ] Move `tests/playwright.config.mjs` → `tests/e2e/` |
| 175 | - [ ] Move `tests/captive-portal.spec.mjs` → `tests/e2e/captive-portal.spec.mjs` | ||
| 176 | - [ ] Move `tests/playwright.config.mjs` → `tests/e2e/playwright.config.mjs` | ||
| 177 | - [ ] Fix all hardcoded IPs (`192.168.4.1`) → `process.env.TOLLGATE_IP` | ||
| 178 | |||
| 179 | ### New Integration Tests | ||
| 180 | - [ ] `tests/integration/phase3.mjs` — wallet GET/swap/send, identity SSID/IP, wifistr on relay | ||
| 181 | - [ ] All Phase 3 integration tests passing | ||
| 182 | |||
| 183 | ### New E2E Tests | ||
| 184 | - [ ] `tests/e2e/payment.spec.mjs` — paste token → pay → success, error handling, full flow | ||
| 185 | - [ ] All E2E tests passing | ||
| 186 | |||
| 187 | ### Build System Updates | ||
| 188 | - [ ] Update `Makefile` with `test-unit`, `test-integration`, `test-e2e`, `test-all` targets | ||
| 189 | - [ ] Update `package.json` npm scripts for new paths | ||
| 190 | - [ ] All `make test-*` targets work | ||
| 191 | |||
| 192 | ## Phase 4: ESP32 TollGate Client Detection + Auto-Payment — IN PROGRESS | ||
| 193 | |||
| 194 | ### tollgate_client.c/h (New) | ||
| 195 | - [x] Create `tollgate_client.h` — types: `tollgate_discovery_t`, `tollgate_client_state_t` enum (IDLE/DETECTING/NEEDS_PAY/PAYING/PAID/RENEWING) | ||
| 196 | - [x] Create `tollgate_client.c` — detection, payment, monitoring, state machine | ||
| 197 | - [x] `tollgate_client_detect(gw_ip)` — HTTP GET `http://{gw}:2121/`, parse kind=10021, extract price tags | ||
| 198 | - [x] `tollgate_client_pay(gw_ip, amount_sats)` — `nucula_wallet_send()` → POST to upstream → parse kind=1022/21023 | ||
| 199 | - [x] `tollgate_client_on_sta_connected()` — extract gw from DHCP, detect, pay (blocking) | ||
| 200 | - [x] `tollgate_client_tick()` — GET `/usage`, renew at 20% remaining | ||
| 201 | - [x] `tollgate_client_on_sta_disconnected()` — reset state | ||
| 202 | - [x] `tollgate_client_get_usage(gw_ip)` — GET `/usage` → parse remaining/total | ||
| 203 | |||
| 204 | ### Config Changes | ||
| 205 | - [x] Add to `config.h`: `client_enabled`, `client_steps_to_buy`, `client_renewal_threshold_pct`, `client_retry_interval_ms` | ||
| 206 | - [x] Parse new fields in `config.c` | ||
| 207 | |||
| 208 | ### Integration (tollgate_main.c) | ||
| 209 | - [x] Make wallet init synchronous (call `nucula_wallet_init()` directly, not as task) | ||
| 210 | - [x] Add `tollgate_client_on_sta_connected()` in `ip_event_handler` (blocking, before `start_services()`) | ||
| 211 | - [x] Add `tollgate_client_on_sta_disconnected()` in `wifi_event_handler` | ||
| 212 | - [x] Add `tollgate_client_tick()` in main loop | ||
| 213 | - [x] Update `main/CMakeLists.txt` — add `tollgate_client.c` | ||
| 214 | |||
| 215 | ### Unit Tests | ||
| 216 | - [x] `tests/unit/test_tollgate_client.c` — discovery parsing, price extraction, state machine, renewal threshold | ||
| 217 | - [x] All unit tests passing (30 new, 116 total) — committed at `78dd599` | ||
| 218 | |||
| 219 | ### Integration Tests | ||
| 220 | - [ ] ESP32→OpenWRT auto-payment (Scenario 4) | ||
| 221 | - [ ] ESP32→ESP32 auto-payment (Scenario 5, needs Board B) | ||
| 222 | |||
| 223 | ### Test Cases 39-43 | ||
| 224 | - [ ] Test 39: Client detection (kind=10021 parse) | ||
| 225 | - [ ] Test 40: Client payment flow (mock HTTP) | ||
| 226 | - [ ] Test 41: Session renewal (20% threshold) | ||
| 227 | - [ ] Test 42: ESP32→OpenWRT auto-pay | ||
| 228 | - [ ] Test 43: ESP32→ESP32 auto-pay | ||
| 229 | |||
| 230 | ## Phase 5: Lightning Auto-Payout — NOT STARTED | ||
| 231 | |||
| 232 | ### lnurl_pay.c/h (New) | ||
| 233 | - [ ] Create `lnurl_pay.h` — `lnurl_get_invoice(lightning_address, amount_sats, bolt11_out, out_size)` | ||
| 234 | - [ ] Create `lnurl_pay.c` — GET `.well-known/lnurlp/{user}` → parse callback → GET callback with amount → extract BOLT11 | ||
| 235 | |||
| 236 | ### lightning_payout.c/h (New) | ||
| 237 | - [ ] Create `lightning_payout.h` — `payout_recipient_t`, config, init/tick API | ||
| 238 | - [ ] Create `lightning_payout.c` — periodic balance check, threshold, multi-recipient split, melt with retry | ||
| 239 | |||
| 240 | ### nucula Bridge Extension | ||
| 241 | - [ ] Add `nucula_wallet_melt(bolt11, max_fee_sats)` to `nucula_wallet.h/cpp` | ||
| 242 | - [ ] Wraps `Wallet::request_melt_quote()` + `Wallet::melt_tokens()` (NUT-05) | ||
| 243 | |||
| 244 | ### Config Changes | ||
| 245 | - [ ] Add payout config to `config.h`: `payout_enabled`, `min_payout_amount`, `min_balance`, `fee_tolerance_pct`, `check_interval_s`, `recipients[]` | ||
| 246 | - [ ] Parse payout config in `config.c` | ||
| 247 | |||
| 248 | ### Integration (tollgate_main.c) | ||
| 249 | - [ ] Add periodic payout timer (60s interval) | ||
| 250 | - [ ] Update `main/CMakeLists.txt` | ||
| 251 | |||
| 252 | ### Unit Tests | ||
| 253 | - [ ] `tests/unit/test_lnurl_pay.c` — LNURL-pay URL construction, response parsing | ||
| 254 | - [ ] `tests/unit/test_lightning_payout.c` — threshold check, multi-recipient split, fee tolerance | ||
| 255 | |||
| 256 | ### Test Cases 44-48 | ||
| 257 | - [ ] Test 44: LNURL-pay flow | ||
| 258 | - [ ] Test 45: Payout threshold | ||
| 259 | - [ ] Test 46: Multi-recipient split | ||
| 260 | - [ ] Test 47: Melt with fee tolerance | ||
| 261 | - [ ] Test 48: Full payout cycle | ||
| 262 | |||
| 263 | ## Phase 6: Bytes-Based Billing — NOT STARTED | ||
| 264 | |||
| 265 | ### lwIP NAPT Stats Component (New) | ||
| 266 | - [ ] Create `components/lwip_napt_stats/` — patched `ip4_napt.c` with byte counters | ||
| 267 | - [ ] Add `uint64_t bytes_up/bytes_down` to `struct ip_napt_entry` | ||
| 268 | - [ ] Increment in `ip_napt_forward()` and `ip_napt_recv()` | ||
| 269 | - [ ] Add public API: `ip_napt_get_client_bytes(client_ip, &up, &down)` | ||
| 270 | - [ ] Create component CMakeLists.txt | ||
| 271 | |||
| 272 | ### Session Changes | ||
| 273 | - [ ] Add `allotment_bytes`, `bytes_consumed` to `session_t` | ||
| 274 | - [ ] Dual-metric `session_is_expired()` dispatches on metric type | ||
| 275 | - [ ] `session_add_bytes(client_ip, byte_count)` called from firewall counting | ||
| 276 | |||
| 277 | ### Config Changes | ||
| 278 | - [ ] Add `metric` field ("milliseconds" or "bytes") to `config.h` | ||
| 279 | - [ ] Add `step_size_bytes` to `config.h` | ||
| 280 | - [ ] Parse in `config.c` | ||
| 281 | |||
| 282 | ### TollGate API Changes | ||
| 283 | - [ ] Discovery endpoint advertises correct metric | ||
| 284 | - [ ] `/usage` returns byte-based or time-based values | ||
| 285 | - [ ] Allotment calculation dispatches on metric | ||
| 286 | |||
| 287 | ### Firewall Changes | ||
| 288 | - [ ] `firewall_count_traffic()` — queries NAPT byte counters per active client | ||
| 289 | - [ ] Called from `session_tick()` or main loop | ||
| 290 | |||
| 291 | ### Cashu Changes | ||
| 292 | - [ ] Unify `cashu_calculate_allotment()` for both metrics | ||
| 293 | |||
| 294 | ### Unit Tests | ||
| 295 | - [ ] `tests/unit/test_bytes_metric.c` — byte allotment calc, dual-metric session expiry | ||
| 296 | |||
| 297 | ### Test Cases 49-52 | ||
| 298 | - [ ] Test 49: Byte allotment calc | ||
| 299 | - [ ] Test 50: Byte session expiry | ||
| 300 | - [ ] Test 51: NAPT byte counting | ||
| 301 | - [ ] Test 52: Bytes metric end-to-end | ||
| 302 | |||
| 303 | ## Phase 7: ContextVM Server (MCP over Nostr) — NOT STARTED | ||
| 304 | |||
| 305 | ### NIP-44 Encryption (New) | ||
| 306 | - [ ] Create `nip44.h` — encrypt/decrypt API | ||
| 307 | - [ ] Create `nip44.c` — XChaCha20-Poly1305 + secp256k1 ECDH + conversation key derivation | ||
| 308 | |||
| 309 | ### MCP Handler (New) | ||
| 310 | - [ ] Create `mcp_handler.h` — tool registration, JSON-RPC parse/dispatch | ||
| 311 | - [ ] Create `mcp_handler.c` — register tools, handle requests, build responses | ||
| 312 | |||
| 313 | ### CVM Server (New) | ||
| 314 | - [ ] Create `cvm_server.h` — init/start/stop API | ||
| 315 | - [ ] Create `cvm_server.c` — WebSocket listener, DM subscription, NIP-44 decrypt, MCP dispatch | ||
| 316 | |||
| 317 | ### MCP Tool Registration | ||
| 318 | - [ ] `get_config`, `set_config`, `get_balance`, `get_sessions`, `get_usage` | ||
| 319 | - [ ] `set_payout`, `set_metric`, `set_price`, `wallet_send`, `wallet_melt` | ||
| 320 | 153 | ||
| 321 | ### Auth | 154 | ### Playwright Video Recording Fix |
| 322 | - [ ] Only accept commands from owner npub | 155 | - [ ] Per-test context isolation (not shared serial context) |
| 156 | - [ ] Verify `.webm` files generated in test-results/ | ||
| 323 | 157 | ||
| 324 | ### Integration (tollgate_main.c) | 158 | ### OpenWRT Interop |
| 325 | - [ ] Start CVM server alongside wifistr | 159 | - [ ] Investigate `nofee.testnut.cashu.space` API compatibility issues |
| 326 | - [ ] Update `main/CMakeLists.txt` | 160 | - [ ] Fix cashu CLI v0.19.2 Pydantic validation failures with missing `active` field |
| 327 | 161 | ||
| 328 | ### Unit Tests | 162 | ### Board B |
| 329 | - [ ] `tests/unit/test_nip44.c` — encrypt/decrypt roundtrip | 163 | - [ ] Flash Board B with current firmware (different nsec) |
| 330 | - [ ] `tests/unit/test_mcp_handler.c` — JSON-RPC parse, tool dispatch | 164 | - [ ] Cross-board payment test: Board B → Board A |
| 165 | - [ ] ESP32→ESP32 auto-payment (Scenario 5) | ||
| 331 | 166 | ||
| 332 | ### Test Cases 53-56 | 167 | --- |
| 333 | - [ ] Test 53: NIP-44 encrypt/decrypt | ||
| 334 | - [ ] Test 54: MCP JSON-RPC parse | ||
| 335 | - [ ] Test 55: Config change via DM | ||
| 336 | - [ ] Test 56: Balance query via CVM | ||
| 337 | 168 | ||
| 338 | ## Reminders | 169 | ## Reminders |
| 339 | - Do NOT ask for instructions — proceed independently, skip blocked items, work on unblocked ones | ||
| 340 | - **Commit + push every time a test passes that previously didn't pass** | 170 | - **Commit + push every time a test passes that previously didn't pass** |
| 341 | - Board A: `/dev/ttyACM0`, factory MAC `94:a9:90:2e:37:7c` | 171 | - Board A: `/dev/ttyACM0`, MAC `94:a9:90:2e:37:7c`, SSID `TollGate-C0E9CA`, AP IP `10.192.45.1` |
| 342 | - Board B: `/dev/ttyACM1`, factory MAC `fc:01:2c:c5:50:50` | 172 | - Board B: `/dev/ttyACM1`, MAC `fc:01:2c:c5:50:50` |
| 343 | - Identity is now derived from nsec in config.json (SSID, IP, MAC all deterministic) | 173 | - OpenWRT Router: SSH `root@10.47.41.1`, port 2121 |
| 344 | - testnut.cashu.space auto-pays invoices: `cashu -h https://testnut.cashu.space invoice <amount>` | 174 | - `source ~/esp/esp-idf/export.sh` before `idf.py` |
| 345 | - Token generation: `cashu -h https://testnut.cashu.space send --legacy <amount> 2>&1 | grep '^cashuA' | head -1` | 175 | - Latest commit: `3342c8e` |
| 176 | - 156 unit tests + 18 Playwright tests — all passing | ||
| 346 | - sudo password: `c03rad0r123` | 177 | - sudo password: `c03rad0r123` |
| 347 | - Run `make test-unit` after any code change — must pass before commit | 178 | - Token generation: `cashu -h https://testnut.cashu.space send --legacy 21` |
| 348 | - See `AGENTS.md` for full testing rules and project context | 179 | - See `AGENTS.md` for full testing rules |
| 349 | - Proceed to Phase 4 after completing Phase 3 | ||