21 Commits

Author SHA1 Message Date
dea78f6eeb test: pin checkout test clock and cover x402_nonces in schema test
Checkout fixtures are dated 2026-09-29 but expiry reads the wall clock, so
24 tests started failing once the real date passed the checkout window.
The schema test predated the x402_nonces table, which is keyed by the
claimed authorization instead of id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 19:36:07 +03:00
40f90f1c5a feat: webhook event log with resend, test events, secret rotation and auto-disable (G8)
Every seller webhook delivery now keeps an attempt log (status code,
error, time, next retry) in the worker queue (Postgres) or in memory.
New routes: GET /v1/webhooks/deliveries(/:id), POST
/v1/webhooks/events/:id/resend, POST /v1/webhooks/endpoints/:id/test
(signed webhook.test event), rotate-secret with a 0-168h grace window
(both secrets sign as two v1 values, verified by @settlekit/webhooks, the
TS/Python/Go/Rust SDKs and the WooCommerce plugin), and disable/enable.
The worker retries on a 1m..6h exponential schedule instead of every tick,
signs with the live endpoint secret, skips disabled endpoints and
auto-disables one after 100 failed attempts in a row
(WEBHOOK_DISABLE_AFTER_FAILURES). Outbound requests get a 10s timeout.
The dashboard Webhooks page shows the event log with Resend and endpoint
actions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 05:34:39 +03:00
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
948ebfd761 fix(zcash): assign amount tags atomically per payTo
Tag assignment was read-then-write, so concurrent sessions paying the same
transparent address could lock the same tag and one payment would match
both. The base quote is now locked with tag 0 and the tag is chosen and
saved under a per-payTo lock (pg_advisory_xact_lock(hashtext(key)) shared
by the API and checkout when Postgres is wired, an in-process mutex
otherwise), with a post-save uniqueness re-check that retries on the next
tag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 20:04:13 +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
pextacy
71e89bdfd8 feat(lepton): attribution package (RFB 6.01) + creator-dashboard
Adds @settlekit/attribution — reuse-detection, weighted provenance lineage,
and HMAC-signed proofs-of-citation — wired live into the rsshub-citation-toll
sidecar (POST /attribution/{detect,proof,verify}) and persisted via
PgLineageStore/PgProofStore over new lepton_lineage_edges + lepton_citation_proofs
tables.

Adds apps/creator-dashboard — a Next.js earnings view in the Statement
greenbar-ledger design system, driven by real domain logic (createSource +
computeRoyaltyDistribution + detectReuse, not mocks). Statement / Sources /
Payouts / Reuse & proofs (interactive) / Wallet. next build green.

Also bundles in-progress settlement hardening: settlement-core idempotency
concurrency, api env validation, bundles + contracts/worker tweaks.

Verified: 943 vitest tests, 27 Foundry tests, next build all green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-20 01:19:22 +03:00
ff11f7754e feat(lepton): nanopayment modules + production settlement spine
Lepton Agents Hackathon (Canteen × Circle × Arc): agent-native nanopayments
on Arc, built on the existing SettleKit platform.

Hackathon modules (demo-ready, RFB-aligned):
- @settlekit/agent: autonomous paying agent (Claude tool-use loop) — RFB 1/3
- @settlekit/citation-toll: per-access content + recursive royalty splits — RFB 6
- @settlekit/streaming: per-second continuous-authorization settlement — RFB 4
- @settlekit/x402-client: x402 pay-and-retry + pluggable settler (local/Circle)
- @settlekit/agent-economy: closed-loop traction harness + CLI
- apps/api /v1/lepton: public live demo surface

Production settlement spine (Phase 1):
- @settlekit/settlement-core: configurable Gateway/Circle/local providers,
  idempotency, batch accumulator, on-chain reconciliation, nonce + receipt stores
- @settlekit/wallet-fleet: registry, spending caps + kill-switch, balances,
  Circle provisioning
- x402-client: provider-settler adapter + Arc-indexer on-chain verifier
- lepton DB schema (12 tables) + persistence Pg stores (settlements, nonces,
  sources, royalty legs, wallets, streams, payees)
- apps/worker jobs: lepton-settlement-reconcile, lepton-payout-sweep,
  lepton-stream-refund (no-op until the settlement spine is wired)

First real-world traction sidecar (Phase 2):
- @settlekit/payee-registry: identity→wallet payout rule (in-memory + Pg)
- services/sidecars/rsshub-citation-toll: ingest RSS items as priced citeable
  sources, x402-gated, settle per-citation royalties via settlement-core
- shared sweepPendingRoyalties used by the worker job and the sidecar
- services/sidecars/* wired as a TS workspace area (pnpm + vitest)

Docs: LEPTON.md, LEPTON_PRODUCTION_PLAN.md. All green: full typecheck + 870 tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 14:37:38 +03:00
3a52b61096 adas 2026-06-17 03:02:36 +03:00
3853551433 asad 2026-06-17 02:09:36 +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
3fe0c88942 feat: implement all 77 SettleKit packages with real code
Core engine: entitlements (§14), delivery action runner (§21).
Payment rails: arc (viem USDC verify), circle (REST), x402 middleware, payments, webhooks (HMAC), notifications (Resend).
Integrations: github (Octokit App), discord (REST v10).
Commerce: saas billing, bundles, license-keys, api-keys, file-delivery (signed URLs + SigV4), usage/credits, agent-services, escrow, marketplace-core, risk.
Persistence: database (Drizzle/Postgres, 48 tables §25).
Plus supporting domain packages.

561 tests passing across 117 files; tsc -b green for every package.
2026-06-15 03:24:19 +03:00
4afda54455 feat: monorepo scaffold + @settlekit/common contract package
- pnpm workspace, shared tsconfig, vitest
- common: ids, money (USDC base-unit math), Result/SettleKitError, time
- domain types: product, customer, payment, entitlement, delivery, integration
- 13 passing contract tests
2026-06-15 02:55:22 +03:00