12 Commits

Author SHA1 Message Date
1b38e24f1f feat(x402-facilitator): Postgres nonce store and closed-by-default recipient allowlist
- PgX402NonceStore (x402_nonces, migration 0012): reserve is INSERT ... ON
  CONFLICT DO NOTHING on the primary key, so one settle wins across replicas.
  The API wires it whenever DATABASE_URL is set; otherwise the facilitator
  falls back to the in-memory store and logs a boot warning. One store is
  now shared by every per-environment facilitator part.
- allowedPayTo defaults to this deployment's own EVM receiving addresses
  (X402_EVM_PAY_TO + X402_PAY_TO_<CHAIN>); an empty allowlist refuses every
  recipient, and only X402_FACILITATOR_ALLOWED_PAY_TO=* opens the relayer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 20:59:42 +03:00
e169731b42 chore: merge feat/solana-colosseum into feat/x402-multichain
Brings in packages/routing, packages/hyperliquid (hypercore network), checkout
AnyTokenPay/HyperCorePay, Node 22 pins, tenant-ownership guards and the zcash
tag lock. Only conflict: drizzle _journal.json (kept 0010_onchain_billing and
0011_coupons_organization in order).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 20:39:32 +03:00
ec04f3ddb5 feat(persistence): Postgres store for onchain subscriptions, charges and escrow
Migration 0010 adds onchain_subscriptions, onchain_charges (UNIQUE per
subscription+period) and onchain_escrow_payments. PgOnchainBillingStore
claims a period under a row lock so API and worker replicas can never
charge the same period twice. Adds shared access hooks (extend/suspend
core subscription, record payments, expire entitlements) and links
escrow payments to their checkout session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 20:19:14 +03:00
9dff6e0e9a fix(api): scope refunds, disputes, dunning, invoices, license keys, coupons and entitlement lists to the caller's org
Coupons gain an organizationId (column + migration 0010); legacy rows with no
owner stay hidden from every tenant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 20:18:39 +03:00
06dea43c94 feat: enforce one payment per on-chain tx hash with a partial unique index
Replace payments_tx_hash_idx with a unique index on payments.tx_hash
(WHERE tx_hash IS NOT NULL) so a transaction can settle at most one
payment across processes. Migration 0009 + schema test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 14:59:08 +03:00
286ae8c8fc feat(api): agent + job registry — full Pg persistence (Phase 2.1/2.2)
- database: agent_registry + agent_jobs tables, migration 0008 (verified on Postgres: tables + indexes).
- persistence: AgentRegistryStore/AgentJobStore + InMemory + Pg impls (document-projection, org-scoped).
- api: org-scoped /v1/agents (register/list/get/feedback) + /v1/jobs (create/list/get/transition) with a forward-only lifecycle guard; wired into context (pick Pg/InMemory) + mounted under the api-key guard.
- Roadmap Phase 2 complete — all 5 phases shipped. 1308 tests / 213 suites, typecheck + build green; migrations 0006–0008 verified on a throwaway Postgres.
2026-06-21 12:22:44 +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
9229638cea feat(auth): wire web3 wallet login end-to-end (API + dashboard + Pg store)
- apps/api: POST /v1/auth/wallet/nonce + /v1/auth/wallet/login (zod-validated, sets the signed sk_session cookie like password/magic-link).
- apps/dashboard: 'Connect Wallet' SIWE sign-in (plain viem + EIP-1193 personal_sign, no heavy deps) on login + signup; lib/auth wallet helpers.
- persistence: PgAuthStore.findAccountByWallet/saveWalletNonce/consumeWalletNonce (atomic single-use consume); accounts.wallet_address projection.
- database: auth_accounts.wallet_address column + auth_wallet_nonces table, migration 0006_auth_web3 + journal; re-export gt/lt operators.
- 1302 tests / 213 suites, typecheck + full build green.
2026-06-21 00:09:44 +03:00
32b89f0515 firstof 2026-06-16 02:51:34 +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
f7c9cd735d feat(escrow): Postgres persistence for the full escrow lifecycle
- add missing escrow_refunds + escrow_reviews tables (schema + migration 0001)
- seed a default customer (DEFAULT_CUSTOMER_ID) to satisfy buyer_customer_id FK
- PgEscrowStore: document-projection over all 7 escrow tables; deterministic
  per-task ids for idempotent sub-record upserts; listTasks filters docs by org
- wire escrow to Postgres in context (in-memory fallback retained)

Verified live: create->fund->assign->submit->approve->release persists rows in
escrow_tasks/fundings/submissions/reviews/releases; documents round-trip (real
buyerCustomerId in __doc, FK-safe default projected). 50 tables; 590 tests pass.

Remaining in-memory in Postgres mode (deep FK chains / no clean table fit):
saas seats (subscription FK), agent usage (agent_buyers FK), file-download
grants + agent reputation (no backing table).
2026-06-15 12:04:32 +03:00
e84506c61d feat: distribution layer — SDK, React, migrations, deploy infra (no CI/CD)
- @settlekit/sdk: typed fetch HTTP client over the REST API; one resource
  client per /v1 resource (products, checkout, payments, entitlements,
  licenseKeys, apiKeys, bundles, github, discord, saas, escrow, agentServices…),
  AbortController timeouts, idempotency keys, SettleKitApiError envelope mapping.
- @settlekit/react: SettleKitProvider, useEntitlement/useCheckout/useCredits
  hooks, <Paywall> + <UpgradeButton> (React 18, plan §4).
- database: drizzle.config.ts + generated drizzle/0000_init.sql (48 tables,
  indexes, FKs) + db:generate/migrate/push/studio scripts.
- infra: README, ARCHITECTURE, CONTRIBUTING, .env.example, .dockerignore,
  docker-compose.yml, per-app Dockerfiles + Dockerfile.next, Makefile.

No tests. No CI/CD pipelines.
2026-06-15 11:02:39 +03:00