Skip to main content

TypeScript SDK

@skia-money/sdk is the hardened TypeScript client for the Skia settlement API — commit/reveal swaps, edge-layer payments, portfolio/tier reads, and an MCP (JSON-RPC 2.0) client. It is built against the live server contracts, not a spec guess: where the incoming skeleton and the server disagreed, the server won, and every hardening decision is recorded.
This page is the overview. The full package-level reference — configuration, authentication, the error taxonomy, advanced usage, and migration guides — lives at the SDK docs site sdk.skia.money (Docusaurus).

Install

The package is not published to npm yet; consume it from the monorepo (bun resolves TS directly):
Build declarations (dist/ with .d.ts):

One-shot sovereign swap

The taker address is the auth bearer (simulated ethSigAuth — commit/reveal authenticate as senderWallet). Pass bearerToken in the config to pin it.

Chain keys and settlement ids

The wire accepts twelve app-chain keys — eight live (each backed by a canonical testnet deployment) and four dormant (taiko, bsc, polygon, hyperevm; hyperevm staged). Dormant keys carry status: "dormant" everywhere and are refused client-side by the SDK.
SDK drift note: the SDK as of v0.2.1 carries ten keys (seven live + three dormant) and does not yet know monad or hyperevm. The catch-up toward the twelve-key wire is tracked in the drift ledger (docs/ops/sdk-hardening-drift.md). The wire truth above is what the server answers today.
Labels, statuses, and settlement ids are not the same thing:
  • SKIA_CHAINS[key].chainIdNumeric is the production id the label derives from — do NOT build signature domains or explorer links from it.
  • The real settlement ids live in SKIA_CHAINS[key].settlementChainIdNumeric and, authoritatively, in WalletSummary.settlementNetwork.chainIdNumeric.

Simulated settlements — txHash is nullable, always labeled

A swap can succeed without touching a chain (DB-simulated settlement on non-backed lanes). Every reveal response is normalized by the SDK:
The server historically wired a synthetic hash on the simulated path; the SDK normalizes it away so front ends cannot link a fake hash.

Reliability semantics

  • Idempotency: swap() and commit() accept an idempotencyKey, cached in a pluggable store (MemoryIdempotencyStore by default — inject your own for persistence across restarts).
  • Single-fire: reveal() never transport-retries (an already-revealed commit throws). commit() is single-fire by default too — the server ignores the Idempotency-Key header today (CONTRACT-1), so an automatic mid-timeout retry could double-commit. Opt in with retryMutatingRequests: true if you accept that trade.
  • Crash recovery: died between commit and reveal — resumeSwap({ commit }) reveals once and recovers from order history on ALREADY_REVEALED; died right after reveal — the next call recovers the txHash from GET /api/wallets/{address}/orders, matched by window + token hints and marked recovered: true. Zero or multiple candidates refuse to guess — money is never matched ambiguously.
  • Retries: exponential backoff with full jitter (base 500ms, cap 8s, 3 retries), honoring Retry-After. Transport errors and 429/5xx retry — including 5xx with no JSON body. Protocol errors (402, hash mismatch, single-fire semantics) never do.

Edge payments with a guard

Skia’s edge lane is a custom pay-and-resubmit protocol, honestly named not x402: a 402 carries a X-Payment-Request header (base64 JSON), the payment settles out of band via POST /api/payment/verify, and the identical quote request is resubmitted. Auto-pay is capped or refused — enabling autoPayX402 without a paymentGuard throws at construction time:
The guard checks amount caps, cumulative spend, payment count, and asset/recipient/network/purpose allow-lists before the executor runs. Violations raise PaymentGuardViolationError with the reason and paymentId.

MCP client

Error taxonomy at a glance

SkiaApiError (status + server code + retryable + details) with specializations: RateLimitError, PaymentRequiredError, AlreadyRevealedError, CommitExpiredError, OrderSenderMismatchError, SkiaNetworkError, PaymentGuardViolationError, McpRpcError/McpProtocolError, and client-side fail-fast InvalidParamError. Server codes map 1:1 (COMMITMENT_HASH_MISMATCH, QUOTE_EXPIRED, SIGNER_MISMATCH, …). A 2xx with a non-JSON body raises MALFORMED_RESPONSE — never a null that crashes downstream. The full table with retry rules is at sdk.skia.money.

Posture (read before quoting custody or auth)

  • WalletSummary.custody is one of server-custodial | simulated | external; server-custodial is the only production path in Phase 1.
  • The bearer is an UNSIGNED address (simulated ethSigAuth) — fine for testnet due diligence, a mainnet blocker. Auth stays pluggable; nothing in the SDK stores or transmits key material — signers are injected.

Where to next