Skip to content

feat: lit-payments crate foundation + magic-link auth#359

Open
clawdbot-glitch003 wants to merge 2 commits into
nextfrom
glitch003/lit-payments-foundation
Open

feat: lit-payments crate foundation + magic-link auth#359
clawdbot-glitch003 wants to merge 2 commits into
nextfrom
glitch003/lit-payments-foundation

Conversation

@clawdbot-glitch003
Copy link
Copy Markdown
Collaborator

Summary

  • New lit-payments/ crate — Rocket binary, sqlx-postgres, depends on lit-billing-core. Foundation only; admin credit portal comes in the next stacked PR.
  • Magic-link auth end-to-end: HMAC-signed tokens (15-min expiry, constant-time verify), Resend integration, private session cookies (7-day), Postgres-backed operators + sessions tables. Seed migration includes chris@litprotocol.com (admin) and the Discord mod (mod).
  • Vanilla HTML/JS login + signed-in pages, multi-stage Dockerfile for Railway, README covering local dev + Railway + Resend DNS.

Stacked on #358 — targets glitch003/lit-billing-core. When #358 lands, I'll rebase this onto next.

Test plan

  • cargo check clean
  • cargo test --lib — 6 token-verification tests pass (roundtrip + expired + tampered + wrong-key + malformed + constant-time)
  • cargo clippy --all-targets -- -D warnings clean
  • cargo fmt --check clean
  • Manual smoke test against a local Postgres + Resend test mode (deferred to reviewer; setup steps in README)

@clawdbot-glitch003 clawdbot-glitch003 requested a review from a team May 19, 2026 23:17
@clawdbot-glitch003 clawdbot-glitch003 force-pushed the glitch003/lit-payments-foundation branch from f68c988 to a13625d Compare May 19, 2026 23:50
glitch003 and others added 2 commits May 20, 2026 10:59
New ops-facing billing service. Deploys to Railway, outside the TEE.
This PR ships the crate skeleton + magic-link auth + login UI; the
admin credit portal endpoints come in a follow-up PR.

What's here:
  - Rocket binary crate at lit-payments/, sibling to lit-billing-core.
  - Postgres migrations for operators + sessions tables.
  - Seed migration with chris@litprotocol.com (admin) +
    Salamiademola73@gmail.com (mod).
  - HMAC-signed magic-link tokens (15-min expiry), verified at
    /auth/verify with constant-time signature compare.
  - Resend integration for sending magic-link emails.
  - Session cookies (private/HttpOnly/Secure/SameSite=Lax, 7-day).
  - Operator request guard so future protected routes just take
    `operator: Operator`.
  - Vanilla HTML/JS login page + signed-in landing page.
  - Multi-stage Dockerfile for Railway (build context = repo root).
  - README covering local dev + Railway deploy + Resend setup.

Stacked on glitch003/lit-billing-core (PR #358). Targets that branch
so it can land cleanly once the extraction merges.

cargo check + cargo test --lib + cargo clippy -D warnings + cargo fmt
all clean. Tests cover the token issue/verify roundtrip + the
expired/tampered/wrong-key failure modes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Codex review on the foundation PR flagged two real holes in the magic-
link request endpoint. Both fixed:

1. Per-email rate limit (60s cooldown, in-memory via moka). Checked
   *before* the operators table is touched so a flood of requests for
   any single email returns at constant time regardless of allowlist
   status. Defeats inbox spam + Resend-quota burning by anyone who
   knows or guesses an operator's email.

2. Email send is now spawned via tokio::spawn instead of awaited
   inline. The operator-found branch and the not-found branch return
   at the same speed (DB-lookup-bounded), so an external caller can no
   longer distinguish operators from non-operators by latency.

New file: src/auth/rate_limit.rs (40 LoC + 3 unit tests).
Mailer derives Clone for the spawn move.
Cargo deps: moka 0.12 (already used by lit-api-server).

cargo check + cargo test --lib (9 tests, 3 new) + clippy -D warnings +
cargo fmt --check all clean.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@clawdbot-glitch003 clawdbot-glitch003 force-pushed the glitch003/lit-payments-foundation branch from 742d64a to a41d7aa Compare May 20, 2026 17:59
@clawdbot-glitch003 clawdbot-glitch003 changed the base branch from glitch003/lit-billing-core to next May 20, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants