Skip to content

Phase 4: API routes - #112

Merged
MFrancis-dev merged 1 commit into
mainfrom
feat/api
Nov 4, 2026
Merged

MFrancis-dev merged 1 commit into
mainfrom
feat/api

Conversation

@MFrancis-dev

Copy link
Copy Markdown
Owner

Implements the Stack API (ARCHITECTURE §4.1, §6) on top of Phases 2–3.

What changed

  • Sessions (K4.1): GET /api/session issues a 32-byte nonce in a signed 5-minute cookie; POST verifies the NEP-413 signature (must be a full-access key; nonce, message and recipient must match) and sets an HMAC-signed HTTP-only session cookie; DELETE signs out. Middleware sends signed-out page visits to the landing page.
  • Onboard (K4.2): keeper creates the user's vault once (checks get_vault first), rate-limited.
  • Vault + tokens (K4.3): on-chain state + USDC balance; public cached token list.
  • Funding (K4.4): dry previews store nothing; real quotes store an attempt with the verified deposit address; tx-hash submit; status refreshed from 1Click on read, including expiry.
  • Plan preview (K4.5): dry buy quote → cost bps and the suggested minimum (a $10 BTC buy shows ~15%).
  • History (K4.6): buys list and a CSV export with the USD value of each buy (UTC, spreadsheet-formula safe).
  • Seam: every route uses getServices(); tests (and demo mode in Phase 7) inject their own. Missing real-mode config → 503 telling you what to set.

Closes #43
Closes #44
Closes #45
Closes #46
Closes #47
Closes #48
Closes #49

Roadmap

  • ROADMAP.md updated: K4.1–K4.7 done (Phase 4 at 100%), K8.7 started

Checks

  • 84 tests incl. 16 route tests on the real handlers, pnpm typecheck, pnpm lint, pnpm build

NEAR HACKATHON rules

  • No secrets; SESSION_SECRET required in production only
  • No funds moved, nothing signed with real keys

- Sign-in: challenge nonce in a signed cookie, NEP-413 verification
  (full-access key), HMAC-signed HTTP-only session; page middleware
- Routes: onboard (keeper creates the vault once), vault, tokens,
  funding quote (dry preview or stored attempt), submit-tx, status
  refreshed from 1Click on read, plan cost preview, buys, CSV export
- getServices() seam so tests and demo mode inject their own adapters;
  clear 503 when real mode isn't configured; rate limits
- 16 route tests on the real handlers (84 TS tests total)
@MFrancis-dev
MFrancis-dev merged commit 14baaca into main Nov 4, 2026
3 checks passed
@MFrancis-dev
MFrancis-dev deleted the feat/api branch November 4, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants