16 Commits

Author SHA1 Message Date
5be25bbceb fix(worker): complete the checkout session and grant entitlements when the worker confirms a payment
The claimTxHash flow is designed so the worker's payment-confirm job can
finish confirming a payment even after the buyer closes the tab (an agent
that never polls hits the same path). But the job only flipped the payment
to "confirmed" and emitted the webhook — it never completed the checkout
session or created an entitlement, both of which only happened in the
buyer-driven confirmOnce/fulfillOnce flow and the API's /payments/:id/confirm
route.

Result: a payment the worker confirms settles on-chain and fires the
seller's webhook, but the session stays "open" forever, so the success/
receipt page 409s "not paid yet" indefinitely and no entitlement is ever
created — the GitHub/Discord retry jobs have nothing to retry since they
only act on entitlements that already exist.

Add WorkerStore.saveCheckoutSession (in-memory + Postgres) and complete the
session + grant a payment entitlement per line item right after the worker
confirms a payment, guarded against double-granting.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-18 00:14:20 +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
466c662ac3 feat: payable invoices and payment requests (G2)
Invoices can now be paid onchain. POST /v1/invoices/:id/send issues the
invoice, binds a public pay page (/i/<token> on the hosted checkout),
opens a checkout session for the invoice total on the merchant's
networks and emails the link. POST /v1/invoices/requests sends an
ad-hoc amount + memo to an email. The invoice turns paid only when a
confirmed onchain payment exists for one of its sessions (on read in the
API and in the new worker invoice-settle job) and emits invoice.paid.
Invoice and receipt PDFs render with pdfkit (MIT). Voiding cancels open
sessions. Dashboard gets a request-a-payment form, send buttons, pay
links and PDF downloads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 03:35:06 +03:00
2b2c8b471d chore: merge Tameion operator into main alongside multi-chain SettleKit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 22:43:33 +03:00
9986da20d9 feat(worker): route-watch job, HyperCore confirmation and Tempo memo enforcement
- jobs/route-watch.ts: polls in-flight any-token routes (Relay / LI.FI) and
  records a payment ONLY after the destination fill passes the session
  network's fail-closed verifier (Transfer to payTo >= amount owed, after
  session creation, hash not used by another payment); provider success
  without such a transfer stays unpaid and backs off; refunds are logged
- payment verification: hypercore via the payee's ledger (HYPERCORE_*),
  routed fills skip only the payer / Solana reference / Tempo memo bindings
  (Solana fills are bound by block time), requireMemo sessions need
  transferWithMemo, pending results carry retryable/claimable
- config: HYPERCORE_*, ROUTING_*, WORKER_ROUTE_WATCH_INTERVAL_MS

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 18:34:52 +03:00
3b5126d99e feat(worker): retry GitHub delivery for pending checkout entitlements
Checkout stores a GitHub entitlement as pending when the merchant's GitHub
App is not set up yet (or GitHub fails) and nothing retried it. The new
github-delivery-retry job (every 2 min, WORKER_GITHUB_RETRY_INTERVAL_MS)
re-delivers pending repo/team entitlements of confirmed payments through
the real GitHub App access client once an installation id is configured,
then marks them active. Targets come from the entitlement or product
metadata and the username from the checkout session; payments owned by the
delivery runner are skipped; failures back off 5 min doubling to 6 h.

The worker also accepts GITHUB_APP_INSTALLATION_ID (the checkout's name)
and gains WorkerStore.getProduct for product delivery metadata.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 17:15:25 +03:00
2134532ba3 fix: drop Solana from the Tameion branch while keeping fail-closed confirmation
The cherry-picked fail-closed payment fixes imported @settlekit/solana, which
does not exist on this branch, breaking tsc -b and the api/worker suites.
Solana verification, env and session references are removed; arc/base/
ethereum keep the per-network verifier registry and the worker keeps
payTo-bound verification. A solana network is now rejected as unsupported
(400 on checkout/observe, unsupported in the worker). Also adds the missing
packages/circle project reference to the api, points the api/worker test
scripts at the root vitest config, and removes the operator's
vitest.apps.config.ts workaround.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:55:28 +03:00
1e20ece9df feat: add operator tick job to the worker
Each run expires stale escalations (vault-held ones on-chain, bills closed
as rejected), turns confirmed Arc payments into the operator vault without
a decision into revenue.received (payer read from the USDC transfer), raises
bill.due for open bills inside the due window, and emits one tick per UTC
day. Event ids are deterministic so nothing is decided twice. The API and
worker only run the operator with OPERATOR_VAULT_ADDRESS set or an explicit
OPERATOR_SIMULATION=1; otherwise the job no-ops and the routes answer 503.

Registered with one export in jobs/index.ts and one scheduler entry in
runtime.ts (the scheduler lists jobs explicitly).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:23:29 +03:00
39a69f5123 feat(worker): verify every enabled chain and watch open Zcash sessions
- config: loadEvmChains + Zcash (ZCASH_ENABLED, explorer, confirmations)
  and WORKER_ZCASH_WATCH_INTERVAL_MS (default 90s)
- payment verification routes every EVM key through @settlekit/chains
  (Arc moves onto the same path; chain-id asserted), Solana as before, and
  Zcash against the locked quote; late Zcash payments go to manual review;
  payTo resolves per network and acceptedNetworks is honoured
- new zcash-watch job: no network call unless open watchable Zcash
  sessions exist, one explorer call per payTo, exact-amount match, attaches
  or records the pending payment and never reuses a txid
- chains: transport failures are retryable rpc_unavailable, never paid

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:21:48 +03:00
b2c4a50da0 fix: verify worker payment confirmations against the session payTo per network
The payment-confirm job verified every pending payment on Arc with
to = the USDC contract address instead of the merchant's payTo, so a
transfer to anyone could confirm. It now loads the payment's checkout
session (new WorkerStore.getCheckoutSession, in-memory + Pg) and routes
by network: Arc via the Arc client against session.payToAddress, Solana
via @settlekit/solana (base58 signature, session paymentReference, no
0x check). Networks the worker cannot verify (base/ethereum, or solana
without SOLANA_CLUSTER) stay pending — fail closed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 14:55:35 +03:00
0dc3728389 fix: verify worker payment confirmations against the session payTo per network
The payment-confirm job verified every pending payment on Arc with
to = the USDC contract address instead of the merchant's payTo, so a
transfer to anyone could confirm. It now loads the payment's checkout
session (new WorkerStore.getCheckoutSession, in-memory + Pg) and routes
by network: Arc via the Arc client against session.payToAddress, Solana
via @settlekit/solana (base58 signature, session paymentReference, no
0x check). Networks the worker cannot verify (base/ethereum, or solana
without SOLANA_CLUSTER) stay pending — fail closed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 06:37:40 +03:00
7d0589fb2e feat(arc): live viem adapters (erc8004/erc8183/app-kit) + worker Arc settlement wiring
- @settlekit/erc8004-viem: viem adapter implementing Erc8004Port against deployed ERC-8004 registries (real ABIs, keccak256 hash derivation, Transfer-log agentId lookup).
- @settlekit/erc8183-viem: ABI-injectable viem adapter for Erc8183Port.
- @settlekit/app-kit-viem: viem-backed AppKitSdk (USDC ERC-20 transfer for Send + estimate; bridge/swap/unified throw a clear unsupported error).
- apps/worker: env-gated Arc settlement provider (SETTLEMENT_PROVIDER=arc) via app-kit-viem -> configureAppKit -> ArcSettlementProvider, falling back to local when unconfigured (default unchanged).
- apps/examples: Arc-commerce checkout demo (offline via LocalAppKitSdk).
- fixes: viem chain/account typing, app-kit-viem unsupported methods made async.
1233 tests / 208 suites, typecheck + full build green.
2026-06-20 23:42:01 +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
3853551433 asad 2026-06-17 02:09:36 +03:00
32b89f0515 firstof 2026-06-16 02:51:34 +03:00
598cd03f05 feat: implement all 8 SettleKit apps + fix x402 nonce round-trip
apps:
- api: Hono REST server, all §26 endpoints, 14 tests
- worker: delivery runner + payment-confirm + access-sync + renewal + webhook-retry jobs wired to real package clients
- dashboard: Next.js merchant dashboard, full §16/§27 sections + §28 product builder
- checkout: Next.js hosted USDC checkout with real delivery materialization
- marketplace: Next.js public marketplace + agent metadata.json route
- admin: Next.js risk/ops console wired to @settlekit/risk + database
- docs: Next.js docs site (9 static routes)
- examples: 5 runnable end-to-end examples

fix(x402): support pinned config.nonce so a stateless verifier can confirm
the challenge nonce round-trips (default stays random; package tests intact).

Full workspace: 590 tests passing (122 files), tsc green for all packages +
api/worker/examples, all 5 Next apps typecheck clean, docs next build green.
2026-06-15 10:49:14 +03:00