8 Commits

Author SHA1 Message Date
c14d0ab735 feat: team roles with invitations and enforced API key scopes (G9)
Security fix plus team access. Before this change any valid API key,
including access keys the delivery system hands to BUYERS, authenticated
as the merchant on the whole management API, and GET /v1/api-keys listed
every organization's keys. Now only platform keys (issued at sign-up or
via POST /v1/api-keys/platform, marked with the platform product id) can
call the API, and each request needs its resource scope
(<resource>:read|write, write implies read; platform:admin or * for
full access), answered with 403 and details.requiredScope otherwise.
Keys cannot mint broader keys, customer keys cannot carry management
scopes, key listing is tenant-scoped and keys can be revoked by id.

Dashboard sessions get team roles (owner, admin, developer, support,
viewer) mapped to scopes. /v1/team manages members and email
invitations (packages/invitations, token hash only, 7-day expiry);
/v1/auth/invitations/accept joins the org and creates the account. The
last owner is protected and only owners grant owner. Dashboard: Team
page, invite accept page, and an API keys page that creates restricted
keys and shows the secret once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 06:09:06 +03:00
b73437be14 feat(auth): active sessions — list + revoke (Phase 1.3)
- AuthService.listSessions (marks current) + revokeSessionById (account-scoped, not_found if not owned).
- store: listSessionsByAccount + deleteSessionById (InMemory + Pg).
- API: GET /v1/auth/sessions, DELETE /v1/auth/sessions/:id (bearer).
- dashboard: Security card — SessionList client + /api/sessions(+/[id]) routes (cookie->bearer, same-origin guard).
- Phase 1 complete. 1308 tests / 213 suites, typecheck + builds green.
2026-06-21 11:59:20 +03:00
56bcca8d5f feat(auth): profile update — PATCH /v1/auth/account (displayName)
- AuthService.updateAccount validates + persists displayName.
- PATCH /v1/auth/account (bearer). Dashboard profile UI follows in the app workflow.
- typecheck green.
2026-06-21 01:55:36 +03:00
7f3f850104 feat(auth): wallet unlink + development roadmap (continuous loop)
- AuthService.unlinkWallet — clears the linked wallet, refusing to strand a
  wallet-only account (no password) from its only sign-in method.
- DELETE /v1/auth/wallet (bearer); dashboard Unlink button + /api/wallet/link DELETE.
- InMemoryAuthStore.saveAccount removes the stale wallet index on unlink (Pg: column→NULL).
- docs/DEVELOPMENT_ROADMAP.md: phased feature plan driving the continuous loop.
- 1308 tests / 213 suites, typecheck + builds green.
2026-06-21 01:51:48 +03:00
fa6d2ec342 fix(security): harden web3/SIWE auth per security review (CRITICAL+HIGH)
CRITICAL-1: validate SIWE domain/chainId server-side (EIP-4361 cross-site replay guard); AuthService gains siweDomain/siweChainIds, wired from AUTH_SIWE_DOMAIN/AUTH_SIWE_CHAIN_IDS in apps/api context.
CRITICAL-2: UNIQUE index on auth_accounts.wallet_address (migration 0007) as the final gate against the link/login race; loginWithWallet + linkWallet catch the violation -> conflict. Verified on live Postgres (dup rejected, NULLs allowed).
CRITICAL-3: /api/session (dashboard + portal) now verify the token with the API before persisting the cookie (no session fixation); + same-origin check on cookie-setting + /api/wallet/link routes (MEDIUM-3 CSRF).
HIGH-1: require expirationTime; enforce notBefore + issuedAt skew (shared verifyWalletMessage); clients now set expirationTime.
HIGH-2 (rate-limiting, task a): /v1/auth no longer exempt — stricter AUTH_RATE_LIMIT_PER_MINUTE (default 20) in a separate bucket; opportunistic expired-nonce prune (store + Pg).
HIGH-3: reserve the wallet email domain — block email/magic-link registration on it (no synthetic-email squatting).
HIGH-4: gate X-Forwarded-For trust behind TRUST_PROXY.
LOW-1: require a 65-byte (130-hex) ECDSA signature at the API boundary.
+ web3 tests for domain mismatch, missing-expiration, reserved-email. 1308 tests / 213 suites, typecheck + full build green; migrations 0006/0007 verified on Postgres.
2026-06-21 01:30:27 +03:00
740ffe91aa feat(auth): web3 sign-in for portal + wallet-linking for existing accounts
- portal: 'Connect Wallet' SIWE sign-in on login/signup (customer accounts), lib/auth wallet helpers, viem dep. (checkout has no sign-in surface — skipped.)
- auth core: AuthService.linkWallet(sessionToken, {message, signature}) — verify session + SIWE sig + single-use nonce, attach wallet to the existing account, conflict if the wallet is already linked elsewhere. +2 tests (link, conflict).
- api: POST /v1/auth/wallet/link (bearer-authenticated).
- dashboard: 'Link wallet' button in Settings → /api/wallet/link route forwards the session cookie as bearer; Account.walletAddress surfaced.
- 1304 tests / 213 suites, typecheck + full build green.
2026-06-21 00:31:48 +03:00
7941e96f27 feat(auth): web3 wallet login (Sign-In-With-Ethereum)
- Add SIWE login to @settlekit/auth: requestWalletNonce + loginWithWallet on AuthService.
- web3.ts: viem-backed SIWE helpers (generateWalletNonce, buildSiweMessage, parseWalletMessage, offline EOA recoverWalletSigner) — no new external dep beyond viem (already in workspace).
- Single-use, address-bound, expiring nonce (replay-safe); nonce consumed only after the signature verifies.
- Account.walletAddress + WalletNonce types; optional findAccountByWallet/saveWalletNonce/consumeWalletNonce on AuthStore (non-breaking — PgAuthStore opts in later), implemented in InMemoryAuthStore.
- 6 tests: nonce issue/validation, login+account creation, returning account, replay rejection, expiry, wrong-signer rejection.
2026-06-20 23:57:15 +03:00
decf3ff96c feat: full-product round 1 — auth, ui design system, closed persistence gaps
- packages/auth: real storage-agnostic auth (scrypt passwords, opaque sessions,
  magic links, HMAC signed cookies, AuthStore + AuthService) on node:crypto.
- packages/ui: shared React 18 design system — theme.css tokens + Button/Card/
  Table/Badge/StatCard/Nav/EmptyState/CopyButton/Money/etc + format helpers.
- persistence gaps closed: download_grants + agent_reputations tables, relaxed
  saas_seats/agent_usage_events FKs (migration 0002, 52 tables); PgSeatStore,
  PgAgentUsageStore, PgGrantStore, PgAgentReputationStore wired into context.

Verified: full build 0 TS errors; 591 tests pass; live Postgres boot + full
purchase->entitlement flow with the new context wiring.
2026-06-15 16:43:50 +03:00