diff options
| author | Your Name <you@example.com> | 2026-05-15 22:27:14 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-15 22:27:14 +0530 |
| commit | 1263d86314fc0760d9be8eea415ccecbc047a5eb (patch) | |
| tree | 778130f0beb59d52f68e0e5f11388bf4b1470130 /main/cashu.h | |
| parent | a7d0a672d59bf8985a6fc0e61b49015fabd96513 (diff) | |
Phase 2 WIP: Cashu payment endpoints, session tracking, updated checklist
- Add cashu.c/h: Cashu token decode (cashuA/base64url), proof state check via mint API, allotment calculator
- Add session.c/h: time-based session management with allotment/expiry, spent secret tracking
- Add tollgate_api.c/h: HTTP server on :2121 with GET / (kind=10021 discovery), POST / (payment processing), /usage, /whoami
- Update captive portal HTML: replace Grant Free Access with Cashu token paste form + Pay & Connect button
- Update tollgate_main.c: wire in session manager, TollGate API, 1s session tick loop
- Add tests/phase2.mjs: Phase 2 test suite (discovery, invalid token, wrong mint, valid payment)
- Update CHECKLIST.md: reflect Phase 1 complete, Phase 2 in progress with known bugs
Known issues (not yet flashed):
- Stack overflow crash in httpd POST handler (need stack_size=16384 + heap allocations)
- cashu_decode_token uses 2KB stack buffer (needs heap alloc)
- Mint URL should be testnut.cashu.space (nofee.testnut has API compat issues)
Diffstat (limited to 'main/cashu.h')
| -rw-r--r-- | main/cashu.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/main/cashu.h b/main/cashu.h new file mode 100644 index 0000000..17891c5 --- /dev/null +++ b/main/cashu.h | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | #ifndef CASHU_H | ||
| 2 | #define CASHU_H | ||
| 3 | |||
| 4 | #include "esp_err.h" | ||
| 5 | #include <stdint.h> | ||
| 6 | #include <stdbool.h> | ||
| 7 | |||
| 8 | #define CASHU_MAX_PROOFS 10 | ||
| 9 | #define CASHU_MAX_SECRET_LEN 128 | ||
| 10 | #define CASHU_MAX_ID_LEN 16 | ||
| 11 | #define CASHU_MAX_C_LEN 128 | ||
| 12 | |||
| 13 | typedef struct { | ||
| 14 | uint64_t amount; | ||
| 15 | char id[CASHU_MAX_ID_LEN]; | ||
| 16 | char secret[CASHU_MAX_SECRET_LEN]; | ||
| 17 | char c[CASHU_MAX_C_LEN]; | ||
| 18 | } cashu_proof_t; | ||
| 19 | |||
| 20 | typedef struct { | ||
| 21 | cashu_proof_t proofs[CASHU_MAX_PROOFS]; | ||
| 22 | int proof_count; | ||
| 23 | char mint_url[256]; | ||
| 24 | uint64_t total_amount; | ||
| 25 | } cashu_token_t; | ||
| 26 | |||
| 27 | typedef struct { | ||
| 28 | char y_hex[65]; | ||
| 29 | bool spent; | ||
| 30 | } cashu_proof_state_t; | ||
| 31 | |||
| 32 | esp_err_t cashu_decode_token(const char *token_str, cashu_token_t *out); | ||
| 33 | |||
| 34 | esp_err_t cashu_check_proof_states(const char *mint_url, const cashu_token_t *token, | ||
| 35 | cashu_proof_state_t *states, int *state_count); | ||
| 36 | |||
| 37 | uint64_t cashu_calculate_allotment_ms(uint64_t token_amount, uint64_t price_per_step, | ||
| 38 | uint64_t step_size_ms); | ||
| 39 | |||
| 40 | bool cashu_is_mint_accepted(const char *mint_url); | ||
| 41 | |||
| 42 | #endif | ||