diff --git a/sdk/openapi.json b/sdk/openapi.json index e8ca0c0..2c05d12 100644 --- a/sdk/openapi.json +++ b/sdk/openapi.json @@ -2,7 +2,7 @@ "openapi": "3.0.3", "info": { "title": "Provable.io Random Generator API", - "description": "Cryptographically verifiable random number generation. Generate random floats and integers, verify outcomes, and list per-seed history. Every endpoint is callable anonymously (rate-limited by IP); authenticated calls are attributed to your account for usage tracking, daily quotas, and webhook delivery.", + "description": "Cryptographically verifiable random number generation. Generate random floats and integers, verify outcomes, and list per-seed history. Every endpoint except batch and streaming is callable anonymously: draws are capped at 10 a minute and 100 a day per IP, verification and lookups at 120 requests a minute. Authenticated calls are attributed to your account for usage tracking, daily quotas, and webhook delivery.", "version": "1.0.0", "contact": { "name": "Provable.io Support", @@ -58,8 +58,16 @@ "Random" ], "summary": "Run many draws in one round trip", - "description": "Accepts up to 50 independent draws across any of the random-generating endpoints (`floats`, `ints`, `shuffle`, `pick`, `bytes`, `dice`, `gaussian`) and returns one result per draw in the same order.\n\n- Each draw uses its own `clientSeed`/`cursor`/`nonce`, so any single outcome is independently verifiable via `/api/verifyServerHash` and gets its own `shortId`/`permalink`.\n- A failing draw is reported as `{ ok: false, error }` and does **not** abort the batch — successful draws still persist their outcomes.\n- Authenticated calls bump usage counters once per **successful** draw. If the daily quota is reached mid-batch, the remaining draws short-circuit with `{ ok: false, error: \"…\", code: \"quota_exceeded\" }` instead of running.\n- One `Idempotency-Key` covers the whole batch: a retry with the same key replays the identical `results` array and does not re-run any draw.", + "description": "**Requires an API key.** Anonymous calls get `401` with code `account_required` and a `signupUrl`.\n\nAccepts up to 50 independent draws across any of the random-generating endpoints (`floats`, `ints`, `shuffle`, `pick`, `bytes`, `dice`, `gaussian`) and returns one result per draw in the same order.\n\n- Each draw uses its own `clientSeed`/`cursor`/`nonce`, so any single outcome is independently verifiable via `/api/verifyServerHash` and gets its own `shortId`/`permalink`.\n- A failing draw is reported as `{ ok: false, error }` and does **not** abort the batch — successful draws still persist their outcomes.\n- Authenticated calls bump usage counters once per **successful** draw. If the daily quota is reached mid-batch, the remaining draws short-circuit with `{ ok: false, error: \"…\", code: \"quota_exceeded\" }` instead of running.\n- One `Idempotency-Key` covers the whole batch: a retry with the same key replays the identical `results` array and does not re-run any draw.\n- Poisson `gaussian` draws in one batch may use at most 100,000 random floats in total (`count × max(50, 4·lambda + 50)` per draw); a heavier batch is refused with 400.", "operationId": "batchDraw", + "security": [ + { + "ApiKeyAuth": [] + }, + { + "BearerAuth": [] + } + ], "parameters": [ { "$ref": "#/components/parameters/IdempotencyKey" @@ -299,8 +307,23 @@ "Random" ], "summary": "Commit a server seed (commit-reveal step 1)", - "description": "Stronger fairness guarantee than `/api/floats` and `/api/ints`. The server generates a fresh `serverSeed`, publishes its `serverHash`, and holds the seed secret until you reveal. Because the hash is published *before* you submit your `clientSeed`, the server cannot pick its seed in response to yours. Follow with `POST /api/reveal` within the commit's TTL (default 10 minutes).", + "description": "Stronger fairness guarantee than `/api/floats` and `/api/ints`. The server generates a fresh `serverSeed`, publishes its `serverHash`, and holds the seed secret until you reveal. Because the hash is published *before* you submit your `clientSeed`, the server cannot pick its seed in response to yours. Follow with `POST /api/reveal` within the commit's TTL (default 10 minutes).\n\n**Sealed commits** (`{\"sealed\": true, \"label\": \"...\"}`, live key required) back sessions that compute outcomes locally, like a game round: the response includes the secret `serverSeed`, returned only to the key that made the commit. There is one sealed commit per key and label, ever; calling again returns the same commit, seed included, so a restart can recover it. The commit is public on `GET /api/commits` from the moment it's made, its seed is published when you reveal it or automatically when it expires (7 days), and sealed commits are never deleted.", "operationId": "createCommit", + "requestBody": { + "required": false, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "sealed": { "type": "boolean", "description": "Make a sealed commit. Requires a live (`pk_live_*`) API key and `label`." }, + "label": { "type": "string", "maxLength": 200, "description": "What the commit is for, e.g. `mygame:round:42`. Only with `sealed`; unique per key." } + } + }, + "example": { "sealed": true, "label": "mygame:round:42" } + } + } + }, "responses": { "200": { "description": "A new commit. Save `commitId` and `serverHash` for verification, then call `/api/reveal`.", @@ -322,7 +345,56 @@ } } }, + "400": { "$ref": "#/components/responses/BadRequest" }, "401": { "$ref": "#/components/responses/InvalidApiKey" }, + "403": { + "description": "A `pk_test_*` key asked for a sealed commit.", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Error" }, + "example": { "error": "sealed commits need a live (pk_live_*) api key", "code": "test_mode_forbidden" } + } + } + }, + "429": { + "$ref": "#/components/responses/RateLimited" + }, + "500": { + "$ref": "#/components/responses/ServerError" + } + } + } + }, + "/api/commits": { + "get": { + "tags": [ + "Verification" + ], + "summary": "List the sealed commits for a label", + "description": "Public, no key needed. Every sealed commit any key made for `label`, oldest first. Each key can make at most one per label, so this proves the owner didn't commit twice and keep the better seed. Seeds show once revealed or expired.", + "operationId": "listSealedCommits", + "parameters": [ + { "name": "label", "in": "query", "required": true, "schema": { "type": "string", "maxLength": 200 }, "example": "mygame:round:42" }, + { "name": "limit", "in": "query", "required": false, "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 100 } } + ], + "responses": { + "200": { + "description": "Sealed commits for the label, oldest first.", + "headers": { + "Server-Timing": { + "$ref": "#/components/headers/ServerTiming" + } + }, + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { "$ref": "#/components/schemas/SealedCommit" } + } + } + } + }, + "400": { "$ref": "#/components/responses/BadRequest" }, "429": { "$ref": "#/components/responses/RateLimited" }, @@ -347,7 +419,7 @@ { "name": "notation", "in": "query", - "description": "Dice notation `NdM`, `NdM+K`, or `NdM-K`. N: 1-100 dice. M: 2-1,000,000 sides. K: integer modifier added to the total. Examples: `3d6`, `2d20+5`, `1d100-10`.", + "description": "Dice notation `NdM`, `NdM+K`, or `NdM-K`. N: 1-100 dice. M: 2-1,000,000 sides. K: integer modifier added to the total, at most 1,000,000 either way. Examples: `3d6`, `2d20+5`, `1d100-10`.", "required": true, "example": "3d6+2", "schema": { @@ -514,7 +586,7 @@ { "name": "mean", "in": "query", - "description": "Mean (μ) for `normal`. Defaults to 0.", + "description": "Mean (μ) for `normal`, between -1e12 and 1e12. Defaults to 0.", "required": false, "schema": { "type": "number", @@ -524,7 +596,7 @@ { "name": "stddev", "in": "query", - "description": "Standard deviation (σ) for `normal`. Must be > 0. Defaults to 1.", + "description": "Standard deviation (σ) for `normal`. Must be > 0 and at most 1e12. Defaults to 1.", "required": false, "schema": { "type": "number", @@ -1250,7 +1322,7 @@ { "name": "items", "in": "query", - "description": "Items to choose from. Same encoding as `/api/shuffle`. 1-1000 entries.", + "description": "Items to choose from. Same encoding and limits as `/api/shuffle`. 1-1000 entries.", "required": true, "example": "common,rare,legendary", "schema": { @@ -1647,7 +1719,7 @@ { "name": "items", "in": "query", - "description": "Items to shuffle. Pass a JSON array (`items=[\"a\",\"b\",\"c\"]`), a comma-separated list (`items=a,b,c`), or repeat the parameter (`items=a&items=b&items=c`). 1-1000 entries.", + "description": "Items to shuffle. Pass a JSON array (`items=[\"a\",\"b\",\"c\"]`), a comma-separated list (`items=a,b,c`), or repeat the parameter (`items=a&items=b&items=c`). 1-1000 entries, each a string or number of at most 256 characters, 32 KB in total.", "required": true, "example": "a,b,c,d", "schema": { @@ -1724,8 +1796,16 @@ "Random" ], "summary": "Stream outcomes as Server-Sent Events", - "description": "Open a long-lived Server-Sent Events (SSE) connection that emits one verifiable outcome per `intervalMs`, up to a server-enforced 10-minute cap.\n\n**The response shape differs from every other endpoint here.** Instead of returning a single JSON body, the server holds the connection open and writes a stream of `text/event-stream` frames. Each frame is a self-contained `event: outcome` message whose `data:` field is a full JSON outcome (identical shape to the matching non-streaming endpoint, plus an `outcomeId` of `clientSeed:cursor:nonce`). Every emitted outcome verifies independently via `/api/verifyServerHash`.\n\nHeartbeat comments (`: heartbeat …`) are sent every ~15 seconds. When the duration cap or quota is reached the server emits a terminal `event: done` frame and closes — reconnect to keep streaming. Closing the client (e.g. `EventSource.close()`) cleanly stops billing. Each emitted outcome counts as one billed call for live-key streams.\n\n**Resuming after a disconnect.** Every `event: outcome` frame includes an `id:` line of `clientSeed:cursor:nonce`. On a transient drop, browsers' built-in `EventSource` auto-reconnects and replays it as a `Last-Event-ID` request header; raw `fetch` clients can pass the same value as a `?lastEventId=` query parameter. Either way the server only emits outcomes strictly after that point on the same `clientSeed`, so reconnects don't double-count or skip — and skipped duplicates aren't billed.", + "description": "**Requires an API key.** Anonymous calls get `401` with code `account_required` and a `signupUrl`.\n\nOpen a long-lived Server-Sent Events (SSE) connection that emits one verifiable outcome per `intervalMs`, up to a server-enforced 10-minute cap.\n\n**The response shape differs from every other endpoint here.** Instead of returning a single JSON body, the server holds the connection open and writes a stream of `text/event-stream` frames. Each frame is a self-contained `event: outcome` message whose `data:` field is a full JSON outcome (identical shape to the matching non-streaming endpoint, plus an `outcomeId` of `clientSeed:cursor:nonce`). Every emitted outcome verifies independently via `/api/verifyServerHash`.\n\nHeartbeat comments (`: heartbeat …`) are sent every ~15 seconds. When the duration cap or quota is reached the server emits a terminal `event: done` frame and closes — reconnect to keep streaming. Closing the client (e.g. `EventSource.close()`) cleanly stops billing. Each emitted outcome counts as one billed call for live-key streams.\n\n**Resuming after a disconnect.** Every `event: outcome` frame includes an `id:` line of `clientSeed:cursor:nonce`. On a transient drop, browsers' built-in `EventSource` auto-reconnects and replays it as a `Last-Event-ID` request header; raw `fetch` clients can pass the same value as a `?lastEventId=` query parameter. Either way the server only emits outcomes strictly after that point on the same `clientSeed`, so reconnects don't double-count or skip — and skipped duplicates aren't billed.", "operationId": "streamOutcomes", + "security": [ + { + "ApiKeyAuth": [] + }, + { + "BearerAuth": [] + } + ], "parameters": [ { "$ref": "#/components/parameters/ClientSeed" @@ -1891,7 +1971,7 @@ "Verification" ], "summary": "Verify an outcome by shortId", - "description": "Public, no-auth verifier used by the `/verify` landing page. Given a `shortId` returned by any random-generating endpoint (or visible in an `/o/:id` permalink), returns recorded metadata and a server-computed verification verdict. Password-tool receipts never return the generated integers or derivation coordinates. A response is `verified: true` when either (a) the live seed state still carries the same `serverHash` or (b) the `serverSeed` has been revealed and `sha256(serverSeed)` reproduces the recorded `serverHash`.", + "description": "Public, no-auth verifier used by the `/verify` landing page. Given a `shortId` returned by any random-generating endpoint (or visible in an `/o/:id` permalink), returns recorded metadata and a server-computed verification verdict. Password-tool receipts never return the generated integers or derivation coordinates. `status` is `verified` only when the revealed `serverSeed` hashes to the committed `serverHash` and replaying the draw reproduces the recorded result; `committed` before the reveal; `revealed` when the seed checks out but the record can't be replayed server-side; otherwise `mismatch`. `verified` is true only for `status: verified`.", "operationId": "verifyShortId", "parameters": [ { @@ -1927,6 +2007,10 @@ "verified": { "type": "boolean" }, + "status": { + "type": "string", + "enum": ["verified", "committed", "revealed", "mismatch"] + }, "reason": { "type": "string" }, @@ -1940,6 +2024,11 @@ "serverHash": { "type": "string" }, + "serverSeed": { + "type": "string", + "nullable": true, + "description": "The revealed server seed, or null until the client seed is rotated." + }, "cursor": { "type": "integer", "minimum": 0, @@ -1998,8 +2087,9 @@ } }, "example": { - "verified": true, - "reason": "Server seed hash on file matches the current state for this client seed.", + "verified": false, + "status": "committed", + "reason": "The serverHash was on file before this draw. The result can be replayed once the server seed is revealed by rotating the client seed.", "shortId": "k7Qm2A9bXz", "clientSeed": "my-app", "serverHash": "9f86d081884c7d65...", @@ -2028,6 +2118,33 @@ } } }, + "/o/stream": { + "get": { + "tags": [ + "Transparency" + ], + "summary": "Live feed of public draws (Server-Sent Events)", + "description": "Long-lived, no-auth `text/event-stream` connection that pushes every public live draw the moment it is made, from every caller (anonymous and keyed). Each frame is `event: draw` with `id:` set to the draw's `shortId` and a JSON `data:` field: `shortId`, `label` (endpoint, plus the range for ints), `result` (a short rendering of the values), `clientSeed`, `nonce` and `created` (ISO 8601). Open `/o/{id}` for the full record and its verification. Test-mode draws and password-tool results are never sent.\n\nNo history is replayed: read `/o.json` for the latest 8 draws, then follow this stream. Heartbeat comments (`: heartbeat …`) arrive every ~15 seconds, and the server ends each connection after 5 minutes; `EventSource` reconnects on its own (`retry: 5000`). A 204 means the feed is at capacity (20 connections per IP, 1,000 in total).", + "operationId": "streamPublicDraws", + "security": [], + "responses": { + "200": { + "description": "Event stream of public draws.", + "content": { + "text/event-stream": { + "schema": { + "type": "string" + }, + "example": "event: draw\nid: k7Qm2A9bXz\ndata: {\"shortId\":\"k7Qm2A9bXz\",\"label\":\"ints 1–100\",\"result\":\"57\",\"clientSeed\":\"player-42\",\"nonce\":18,\"created\":\"2026-11-09T22:41:07.512Z\"}\n\n" + } + } + }, + "204": { + "description": "The feed is at capacity; poll /o.json instead." + } + } + } + }, "/o/{id}": { "get": { "tags": [ @@ -2150,11 +2267,12 @@ "ClientSeed": { "name": "clientSeed", "in": "query", - "description": "Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `\"test\"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history.", + "description": "Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `\"test\"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. At most 256 characters.", "required": false, "schema": { "type": "string", "minLength": 1, + "maxLength": 256, "default": "test" } }, @@ -2726,7 +2844,12 @@ "type": "integer", "format": "int64", "description": "Unix timestamp in ms after which the commit is no longer revealable." - } + }, + "serverSeed": { "type": "string", "description": "Sealed commits only: the secret seed, returned to the owning key. Keep it private until you reveal." }, + "label": { "type": "string", "description": "Sealed commits only." }, + "sealed": { "type": "boolean", "description": "Present and `true` on sealed commits." }, + "created": { "type": "integer", "format": "int64", "description": "Sealed commits only: Unix ms when the commit was made." }, + "revealedAt": { "type": "integer", "format": "int64", "nullable": true, "description": "Sealed commits only: Unix ms of the reveal, or null." } }, "required": [ "commitId", @@ -2734,6 +2857,21 @@ "expiresAt" ] }, + "SealedCommit": { + "type": "object", + "description": "The public record of a sealed commit.", + "properties": { + "commitId": { "type": "string", "format": "uuid" }, + "keyId": { "type": "string", "format": "uuid", "description": "Public id of the API key that made the commit (not the key itself)." }, + "label": { "type": "string" }, + "serverHash": { "type": "string", "description": "SHA-256 of the seed, public from the moment of the commit." }, + "serverSeed": { "type": "string", "nullable": true, "description": "Null until the commit is revealed or expires." }, + "created": { "type": "integer", "format": "int64" }, + "expiresAt": { "type": "integer", "format": "int64" }, + "revealedAt": { "type": "integer", "format": "int64", "nullable": true, "description": "Unix ms of the reveal, or null." } + }, + "required": ["commitId", "keyId", "label", "serverHash", "serverSeed", "created", "expiresAt", "revealedAt"] + }, "RevealRequest": { "type": "object", "properties": { diff --git a/sdk/python/src/provableio/client.py b/sdk/python/src/provableio/client.py index 135bdc6..4debf95 100644 --- a/sdk/python/src/provableio/client.py +++ b/sdk/python/src/provableio/client.py @@ -4,7 +4,7 @@ import json from dataclasses import dataclass -from typing import Any, Dict, Generic, Iterator, Mapping, Optional, TypedDict, TypeVar, Union +from typing import Any, Dict, Generic, Iterator, List, Mapping, Optional, Tuple, TypedDict, TypeVar, Union try: from typing import Unpack except ImportError: @@ -68,7 +68,7 @@ def __init__( auth_headers["Authorization"] = f"Bearer {bearer_token}" self.base_url = base_url.rstrip("/") self._owns_client = http_client is None - self._client = http_client or httpx.Client(headers=auth_headers, timeout=timeout) + self._client = http_client or httpx.Client(headers=auth_headers, timeout=timeout, follow_redirects=True) self._headers = auth_headers def close(self) -> None: @@ -193,6 +193,9 @@ def increment_cursor(self, query: models.IncrementCursorParams, **options: Unpac def list_outcomes(self, query: Optional[models.ListOutcomesParams] = None, **options: Unpack[RequestOptions]) -> ApiResult[models.ListOutcomesResponse]: return self._operation("listOutcomes", query=query, options=options) + def list_sealed_commits(self, query: Optional[models.ListSealedCommitsParams] = None, **options: Unpack[RequestOptions]) -> ApiResult[models.ListSealedCommitsResponse]: + return self._operation("listSealedCommits", query=query, options=options) + def list_merkle_roots(self, query: Optional[models.ListMerkleRootsParams] = None, **options: Unpack[RequestOptions]) -> ApiResult[models.ListMerkleRootsResponse]: return self._operation("listMerkleRoots", query=query, options=options) @@ -237,18 +240,37 @@ def stream_outcomes( operation["method"], self.base_url + operation["path"], params=query, headers=stream_headers, ) as response: response.raise_for_status() + for event_name, data in _sse_events(response): + if event_name == "done": + return + if event_name in ("message", "outcome"): + yield json.loads(data) + + def stream_public_draws(self, *, headers: Optional[Mapping[str, str]] = None) -> Iterator[Dict[str, Any]]: + """Every public draw as it is made (GET /o/stream on provable.io; the API host redirects there). + + No history is replayed: read /o.json for the latest 8. The server ends each + connection after 5 minutes, so call this in a loop to keep following. + """ + operation = OPERATIONS["streamPublicDraws"] + stream_headers = {**self._headers, **dict(headers or {}), "Accept": "text/event-stream"} + with self._client.stream(operation["method"], self.base_url + operation["path"], headers=stream_headers) as response: + response.raise_for_status() + for event_name, data in _sse_events(response): + if event_name == "draw": + yield json.loads(data) + + +def _sse_events(response: httpx.Response) -> Iterator[Tuple[str, str]]: + """(event, data) pairs from a text/event-stream response.""" + data_lines: List[str] = [] + event_name = "message" + for line in response.iter_lines(): + if line.startswith("event:"): + event_name = line[6:].strip() + elif line.startswith("data:"): + data_lines.append(line[5:].lstrip()) + elif not line and data_lines: + yield event_name, "\n".join(data_lines) data_lines = [] event_name = "message" - for line in response.iter_lines(): - if line.startswith("event:"): - event_name = line[6:].strip() - elif line.startswith("data:"): - data_lines.append(line[5:].lstrip()) - elif not line and data_lines: - data = "\n".join(data_lines) - data_lines = [] - if event_name == "done": - return - if event_name in ("message", "outcome"): - yield json.loads(data) - event_name = "message" diff --git a/sdk/python/src/provableio/models.py b/sdk/python/src/provableio/models.py index 4fbf9cb..c0df4f0 100644 --- a/sdk/python/src/provableio/models.py +++ b/sdk/python/src/provableio/models.py @@ -82,6 +82,21 @@ class Commit(TypedDict, total=False): commitId: Required[str] serverHash: Required[str] expiresAt: Required[int] + serverSeed: str + label: str + sealed: bool + created: int + revealedAt: int + +class SealedCommit(TypedDict, total=False): + commitId: Required[str] + keyId: Required[str] + label: Required[str] + serverHash: Required[str] + serverSeed: Required[str] + created: Required[int] + expiresAt: Required[int] + revealedAt: Required[int] class RevealRequest(TypedDict, total=False): commitId: Required[str] @@ -251,8 +266,18 @@ class GetBytesParams(TypedDict, total=False): GetBytesResponse = BytesOutcome +class CreateCommitBody(TypedDict, total=False): + sealed: bool + label: str + CreateCommitResponse = Commit +class ListSealedCommitsParams(TypedDict, total=False): + label: Required[str] + limit: int + +ListSealedCommitsResponse = List[SealedCommit] + class RollDiceParams(TypedDict, total=False): clientSeed: str notation: Required[str] @@ -372,10 +397,12 @@ class VerifyShortIdParams(TypedDict, total=False): class VerifyShortIdResponse(TypedDict, total=False): verified: Required[bool] + status: Literal['verified', 'committed', 'revealed', 'mismatch'] reason: Required[str] shortId: Required[str] clientSeed: str serverHash: str + serverSeed: str cursor: int nonce: int endpoint: str @@ -389,6 +416,8 @@ class VerifyShortIdResponse(TypedDict, total=False): redacted: bool permalink: str +StreamPublicDrawsResponse = str + class GetOutcomePermalinkParams(TypedDict, total=False): id: Required[str] diff --git a/sdk/python/src/provableio/operations.py b/sdk/python/src/provableio/operations.py index 1fd2ebf..2935793 100644 --- a/sdk/python/src/provableio/operations.py +++ b/sdk/python/src/provableio/operations.py @@ -1,5 +1,5 @@ """Generated operation-to-method map. Do not edit by hand.""" -OPERATION_METHODS = {'batchDraw': 'batch', 'getBytes': 'get_bytes', 'createCommit': 'create_commit', 'rollDice': 'roll_dice', 'getFloats': 'get_floats', 'gaussian': 'gaussian', 'getHealth': 'get_health', 'getPublicMetrics': 'get_public_metrics', 'incrementCursor': 'increment_cursor', 'getInts': 'get_ints', 'listOutcomes': 'list_outcomes', 'listMerkleRoots': 'list_merkle_roots', 'getMerkleRoot': 'get_merkle_root', 'getMerkleProof': 'get_merkle_proof', 'getOutcome': 'get_outcome', 'pickItem': 'pick', 'revealCommit': 'reveal_commit', 'rotateServerSeed': 'rotate_server_seed', 'shuffleItems': 'shuffle', 'streamOutcomes': 'stream_outcomes', 'verifyServerHash': 'verify_server_hash', 'verifyShortId': 'verify_short_id', 'getOutcomePermalink': 'get_outcome_permalink', 'getOutcomeOgImage': 'get_outcome_og_image'} +OPERATION_METHODS = {'batchDraw': 'batch', 'getBytes': 'get_bytes', 'createCommit': 'create_commit', 'listSealedCommits': 'list_sealed_commits', 'rollDice': 'roll_dice', 'getFloats': 'get_floats', 'gaussian': 'gaussian', 'getHealth': 'get_health', 'getPublicMetrics': 'get_public_metrics', 'incrementCursor': 'increment_cursor', 'getInts': 'get_ints', 'listOutcomes': 'list_outcomes', 'listMerkleRoots': 'list_merkle_roots', 'getMerkleRoot': 'get_merkle_root', 'getMerkleProof': 'get_merkle_proof', 'getOutcome': 'get_outcome', 'pickItem': 'pick', 'revealCommit': 'reveal_commit', 'rotateServerSeed': 'rotate_server_seed', 'shuffleItems': 'shuffle', 'streamOutcomes': 'stream_outcomes', 'verifyServerHash': 'verify_server_hash', 'verifyShortId': 'verify_short_id', 'streamPublicDraws': 'stream_public_draws', 'getOutcomePermalink': 'get_outcome_permalink', 'getOutcomeOgImage': 'get_outcome_og_image'} -OPERATIONS = {'batchDraw': {'method': 'POST', 'path': '/api/batch', 'query': (), 'query_aliases': {}, 'path_params': (), 'has_body': True}, 'getBytes': {'method': 'GET', 'path': '/api/bytes', 'query': ('clientSeed', 'count', 'encoding'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'createCommit': {'method': 'POST', 'path': '/api/commit', 'query': (), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'rollDice': {'method': 'GET', 'path': '/api/dice', 'query': ('clientSeed', 'notation'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'getFloats': {'method': 'GET', 'path': '/api/floats', 'query': ('clientSeed', 'count'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'gaussian': {'method': 'GET', 'path': '/api/gaussian', 'query': ('clientSeed', 'count', 'distribution', 'mean', 'stddev', 'lambda'), 'query_aliases': {'lambda_': 'lambda'}, 'path_params': (), 'has_body': False}, 'getHealth': {'method': 'GET', 'path': '/api/health', 'query': (), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'getPublicMetrics': {'method': 'GET', 'path': '/api/public-metrics', 'query': (), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'incrementCursor': {'method': 'GET', 'path': '/api/incrementCursor', 'query': ('clientSeed',), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'getInts': {'method': 'GET', 'path': '/api/ints', 'query': ('clientSeed', 'count', 'min', 'max', 'toolMeta'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'listOutcomes': {'method': 'GET', 'path': '/api/listOutcomes', 'query': ('clientSeed', 'limit', 'before'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'listMerkleRoots': {'method': 'GET', 'path': '/api/merkle', 'query': ('limit',), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'getMerkleRoot': {'method': 'GET', 'path': '/api/merkle/{date}', 'query': (), 'query_aliases': {}, 'path_params': ('date',), 'has_body': False}, 'getMerkleProof': {'method': 'GET', 'path': '/api/merkle/{date}/proof/{outcomeId}', 'query': (), 'query_aliases': {}, 'path_params': ('date', 'outcomeId'), 'has_body': False}, 'getOutcome': {'method': 'GET', 'path': '/api/outcome', 'query': ('clientSeed', 'cursor', 'nonce'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'pickItem': {'method': 'GET', 'path': '/api/pick', 'query': ('clientSeed', 'items', 'weights'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'revealCommit': {'method': 'POST', 'path': '/api/reveal', 'query': (), 'query_aliases': {}, 'path_params': (), 'has_body': True}, 'rotateServerSeed': {'method': 'POST', 'path': '/api/rotate', 'query': (), 'query_aliases': {}, 'path_params': (), 'has_body': True}, 'shuffleItems': {'method': 'GET', 'path': '/api/shuffle', 'query': ('clientSeed', 'items', 'toolMeta'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'streamOutcomes': {'method': 'GET', 'path': '/api/stream', 'query': ('clientSeed', 'endpoint', 'intervalMs', 'lastEventId'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'verifyServerHash': {'method': 'GET', 'path': '/api/verifyServerHash', 'query': ('clientSeed', 'serverHash'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'verifyShortId': {'method': 'GET', 'path': '/api/verifyShortId', 'query': ('shortId',), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'getOutcomePermalink': {'method': 'GET', 'path': '/o/{id}', 'query': (), 'query_aliases': {}, 'path_params': ('id',), 'has_body': False}, 'getOutcomeOgImage': {'method': 'GET', 'path': '/o/{id}/og.png', 'query': (), 'query_aliases': {}, 'path_params': ('id',), 'has_body': False}} +OPERATIONS = {'batchDraw': {'method': 'POST', 'path': '/api/batch', 'query': (), 'query_aliases': {}, 'path_params': (), 'has_body': True}, 'getBytes': {'method': 'GET', 'path': '/api/bytes', 'query': ('clientSeed', 'count', 'encoding'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'createCommit': {'method': 'POST', 'path': '/api/commit', 'query': (), 'query_aliases': {}, 'path_params': (), 'has_body': True}, 'listSealedCommits': {'method': 'GET', 'path': '/api/commits', 'query': ('label', 'limit'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'rollDice': {'method': 'GET', 'path': '/api/dice', 'query': ('clientSeed', 'notation'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'getFloats': {'method': 'GET', 'path': '/api/floats', 'query': ('clientSeed', 'count'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'gaussian': {'method': 'GET', 'path': '/api/gaussian', 'query': ('clientSeed', 'count', 'distribution', 'mean', 'stddev', 'lambda'), 'query_aliases': {'lambda_': 'lambda'}, 'path_params': (), 'has_body': False}, 'getHealth': {'method': 'GET', 'path': '/api/health', 'query': (), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'getPublicMetrics': {'method': 'GET', 'path': '/api/public-metrics', 'query': (), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'incrementCursor': {'method': 'GET', 'path': '/api/incrementCursor', 'query': ('clientSeed',), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'getInts': {'method': 'GET', 'path': '/api/ints', 'query': ('clientSeed', 'count', 'min', 'max', 'toolMeta'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'listOutcomes': {'method': 'GET', 'path': '/api/listOutcomes', 'query': ('clientSeed', 'limit', 'before'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'listMerkleRoots': {'method': 'GET', 'path': '/api/merkle', 'query': ('limit',), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'getMerkleRoot': {'method': 'GET', 'path': '/api/merkle/{date}', 'query': (), 'query_aliases': {}, 'path_params': ('date',), 'has_body': False}, 'getMerkleProof': {'method': 'GET', 'path': '/api/merkle/{date}/proof/{outcomeId}', 'query': (), 'query_aliases': {}, 'path_params': ('date', 'outcomeId'), 'has_body': False}, 'getOutcome': {'method': 'GET', 'path': '/api/outcome', 'query': ('clientSeed', 'cursor', 'nonce'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'pickItem': {'method': 'GET', 'path': '/api/pick', 'query': ('clientSeed', 'items', 'weights'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'revealCommit': {'method': 'POST', 'path': '/api/reveal', 'query': (), 'query_aliases': {}, 'path_params': (), 'has_body': True}, 'rotateServerSeed': {'method': 'POST', 'path': '/api/rotate', 'query': (), 'query_aliases': {}, 'path_params': (), 'has_body': True}, 'shuffleItems': {'method': 'GET', 'path': '/api/shuffle', 'query': ('clientSeed', 'items', 'toolMeta'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'streamOutcomes': {'method': 'GET', 'path': '/api/stream', 'query': ('clientSeed', 'endpoint', 'intervalMs', 'lastEventId'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'verifyServerHash': {'method': 'GET', 'path': '/api/verifyServerHash', 'query': ('clientSeed', 'serverHash'), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'verifyShortId': {'method': 'GET', 'path': '/api/verifyShortId', 'query': ('shortId',), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'streamPublicDraws': {'method': 'GET', 'path': '/o/stream', 'query': (), 'query_aliases': {}, 'path_params': (), 'has_body': False}, 'getOutcomePermalink': {'method': 'GET', 'path': '/o/{id}', 'query': (), 'query_aliases': {}, 'path_params': ('id',), 'has_body': False}, 'getOutcomeOgImage': {'method': 'GET', 'path': '/o/{id}/og.png', 'query': (), 'query_aliases': {}, 'path_params': ('id',), 'has_body': False}} diff --git a/sdk/typescript/src/index.ts b/sdk/typescript/src/index.ts index abef55a..b9594d8 100644 --- a/sdk/typescript/src/index.ts +++ b/sdk/typescript/src/index.ts @@ -289,6 +289,17 @@ export class ProvableClient { }); } + /** Public sealed commits under a label (GET /api/commits). */ + listSealedCommits( + query: Query>, + opts?: RequestOptions, + ): Promise>>> { + return this.request("GET", "/api/commits", { + query: query as Record, + ...opts, + }); + } + getOutcomePermalink( pathParams: PathParams>, opts?: RequestOptions, @@ -381,11 +392,34 @@ export class ProvableClient { headers.set("Accept", "text/event-stream"); if (opts.lastEventId) headers.set("Last-Event-ID", opts.lastEventId); - const response = await this.fetchImpl(url, { - method: "GET", - headers, - signal: opts.signal, - }); + for await (const ev of this.sse(url, headers, opts.signal)) yield ev.data; + } + + /** + * Every public draw as it is made (GET /o/stream on provable.io; the API + * host redirects there). No history is replayed: read `/o.json` for the + * latest 8. The server ends each connection after 5 minutes, so loop. + * + * @example + * ```ts + * for await (const draw of client.streamPublicDraws()) console.log(draw); + * ``` + */ + async *streamPublicDraws(opts: RequestOptions = {}): AsyncGenerator { + const headers = this.buildHeaders(opts.headers); + headers.set("Accept", "text/event-stream"); + for await (const ev of this.sse(this.baseUrl + "/o/stream", headers, opts.signal)) { + if (ev.event === "draw") yield ev.data; + } + } + + /** Parsed `{ event, data }` frames of a text/event-stream response. */ + private async *sse( + url: string, + headers: Headers, + signal?: AbortSignal, + ): AsyncGenerator<{ event: string; data: unknown }, void, void> { + const response = await this.fetchImpl(url, { method: "GET", headers, signal }); if (!response.ok || !response.body) { throw new Error(`Stream failed: HTTP ${response.status}`); } @@ -402,17 +436,21 @@ export class ProvableClient { while ((idx = buf.indexOf("\n\n")) !== -1) { const raw = buf.slice(0, idx); buf = buf.slice(idx + 2); - const dataLines = raw - .split("\n") + const lines = raw.split("\n"); + const dataLines = lines .filter((l) => l.startsWith("data:")) .map((l) => l.slice(5).trimStart()); if (dataLines.length === 0) continue; + const eventLine = lines.find((l) => l.startsWith("event:")); + const event = eventLine ? eventLine.slice(6).trim() : "message"; const dataStr = dataLines.join("\n"); + let data: unknown = dataStr; try { - yield JSON.parse(dataStr); + data = JSON.parse(dataStr); } catch { - yield dataStr; + /* not JSON: pass the text through */ } + yield { event, data }; } } } finally { diff --git a/sdk/typescript/src/openapi-types.ts b/sdk/typescript/src/openapi-types.ts index 9ea68e3..03765c4 100644 --- a/sdk/typescript/src/openapi-types.ts +++ b/sdk/typescript/src/openapi-types.ts @@ -15,12 +15,15 @@ export interface paths { put?: never; /** * Run many draws in one round trip - * @description Accepts up to 50 independent draws across any of the random-generating endpoints (`floats`, `ints`, `shuffle`, `pick`, `bytes`, `dice`, `gaussian`) and returns one result per draw in the same order. + * @description **Requires an API key.** Anonymous calls get `401` with code `account_required` and a `signupUrl`. + * + * Accepts up to 50 independent draws across any of the random-generating endpoints (`floats`, `ints`, `shuffle`, `pick`, `bytes`, `dice`, `gaussian`) and returns one result per draw in the same order. * * - Each draw uses its own `clientSeed`/`cursor`/`nonce`, so any single outcome is independently verifiable via `/api/verifyServerHash` and gets its own `shortId`/`permalink`. * - A failing draw is reported as `{ ok: false, error }` and does **not** abort the batch — successful draws still persist their outcomes. * - Authenticated calls bump usage counters once per **successful** draw. If the daily quota is reached mid-batch, the remaining draws short-circuit with `{ ok: false, error: "…", code: "quota_exceeded" }` instead of running. * - One `Idempotency-Key` covers the whole batch: a retry with the same key replays the identical `results` array and does not re-run any draw. + * - Poisson `gaussian` draws in one batch may use at most 100,000 random floats in total (`count × max(50, 4·lambda + 50)` per draw); a heavier batch is refused with 400. */ post: operations["batchDraw"]; delete?: never; @@ -61,6 +64,8 @@ export interface paths { /** * Commit a server seed (commit-reveal step 1) * @description Stronger fairness guarantee than `/api/floats` and `/api/ints`. The server generates a fresh `serverSeed`, publishes its `serverHash`, and holds the seed secret until you reveal. Because the hash is published *before* you submit your `clientSeed`, the server cannot pick its seed in response to yours. Follow with `POST /api/reveal` within the commit's TTL (default 10 minutes). + * + * **Sealed commits** (`{"sealed": true, "label": "..."}`, live key required) back sessions that compute outcomes locally, like a game round: the response includes the secret `serverSeed`, returned only to the key that made the commit. There is one sealed commit per key and label, ever; calling again returns the same commit, seed included, so a restart can recover it. The commit is public on `GET /api/commits` from the moment it's made, its seed is published when you reveal it or automatically when it expires (7 days), and sealed commits are never deleted. */ post: operations["createCommit"]; delete?: never; @@ -69,6 +74,26 @@ export interface paths { patch?: never; trace?: never; }; + "/api/commits": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** + * List the sealed commits for a label + * @description Public, no key needed. Every sealed commit any key made for `label`, oldest first. Each key can make at most one per label, so this proves the owner didn't commit twice and keep the better seed. Seeds show once revealed or expired. + */ + get: operations["listSealedCommits"]; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; "/api/dice": { parameters: { query?: never; @@ -406,7 +431,9 @@ export interface paths { }; /** * Stream outcomes as Server-Sent Events - * @description Open a long-lived Server-Sent Events (SSE) connection that emits one verifiable outcome per `intervalMs`, up to a server-enforced 10-minute cap. + * @description **Requires an API key.** Anonymous calls get `401` with code `account_required` and a `signupUrl`. + * + * Open a long-lived Server-Sent Events (SSE) connection that emits one verifiable outcome per `intervalMs`, up to a server-enforced 10-minute cap. * * **The response shape differs from every other endpoint here.** Instead of returning a single JSON body, the server holds the connection open and writes a stream of `text/event-stream` frames. Each frame is a self-contained `event: outcome` message whose `data:` field is a full JSON outcome (identical shape to the matching non-streaming endpoint, plus an `outcomeId` of `clientSeed:cursor:nonce`). Every emitted outcome verifies independently via `/api/verifyServerHash`. * @@ -452,7 +479,7 @@ export interface paths { }; /** * Verify an outcome by shortId - * @description Public, no-auth verifier used by the `/verify` landing page. Given a `shortId` returned by any random-generating endpoint (or visible in an `/o/:id` permalink), returns recorded metadata and a server-computed verification verdict. Password-tool receipts never return the generated integers or derivation coordinates. A response is `verified: true` when either (a) the live seed state still carries the same `serverHash` or (b) the `serverSeed` has been revealed and `sha256(serverSeed)` reproduces the recorded `serverHash`. + * @description Public, no-auth verifier used by the `/verify` landing page. Given a `shortId` returned by any random-generating endpoint (or visible in an `/o/:id` permalink), returns recorded metadata and a server-computed verification verdict. Password-tool receipts never return the generated integers or derivation coordinates. `status` is `verified` only when the revealed `serverSeed` hashes to the committed `serverHash` and replaying the draw reproduces the recorded result; `committed` before the reveal; `revealed` when the seed checks out but the record can't be replayed server-side; otherwise `mismatch`. `verified` is true only for `status: verified`. */ get: operations["verifyShortId"]; put?: never; @@ -463,6 +490,28 @@ export interface paths { patch?: never; trace?: never; }; + "/o/stream": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** + * Live feed of public draws (Server-Sent Events) + * @description Long-lived, no-auth `text/event-stream` connection that pushes every public live draw the moment it is made, from every caller (anonymous and keyed). Each frame is `event: draw` with `id:` set to the draw's `shortId` and a JSON `data:` field: `shortId`, `label` (endpoint, plus the range for ints), `result` (a short rendering of the values), `clientSeed`, `nonce` and `created` (ISO 8601). Open `/o/{id}` for the full record and its verification. Test-mode draws and password-tool results are never sent. + * + * No history is replayed: read `/o.json` for the latest 8 draws, then follow this stream. Heartbeat comments (`: heartbeat …`) arrive every ~15 seconds, and the server ends each connection after 5 minutes; `EventSource` reconnects on its own (`retry: 5000`). A 204 means the feed is at capacity (20 connections per IP, 1,000 in total). + */ + get: operations["streamPublicDraws"]; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; "/o/{id}": { parameters: { query?: never; @@ -706,6 +755,46 @@ export interface components { * @description Unix timestamp in ms after which the commit is no longer revealable. */ expiresAt: number; + /** @description Sealed commits only: the secret seed, returned to the owning key. Keep it private until you reveal. */ + serverSeed?: string; + /** @description Sealed commits only. */ + label?: string; + /** @description Present and `true` on sealed commits. */ + sealed?: boolean; + /** + * Format: int64 + * @description Sealed commits only: Unix ms when the commit was made. + */ + created?: number; + /** + * Format: int64 + * @description Sealed commits only: Unix ms of the reveal, or null. + */ + revealedAt?: number | null; + }; + /** @description The public record of a sealed commit. */ + SealedCommit: { + /** Format: uuid */ + commitId: string; + /** + * Format: uuid + * @description Public id of the API key that made the commit (not the key itself). + */ + keyId: string; + label: string; + /** @description SHA-256 of the seed, public from the moment of the commit. */ + serverHash: string; + /** @description Null until the commit is revealed or expires. */ + serverSeed: string | null; + /** Format: int64 */ + created: number; + /** Format: int64 */ + expiresAt: number; + /** + * Format: int64 + * @description Unix ms of the reveal, or null. + */ + revealedAt: number | null; }; RevealRequest: { /** @@ -1002,7 +1091,7 @@ export interface components { }; }; parameters: { - /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. */ + /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. At most 256 characters. */ ClientSeed: string; /** @description Number of values to generate (1-100). */ Count: number; @@ -1170,7 +1259,7 @@ export interface operations { getBytes: { parameters: { query?: { - /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. */ + /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. At most 256 characters. */ clientSeed?: components["parameters"]["ClientSeed"]; /** @description Number of bytes to generate (1-1024). */ count?: number; @@ -1226,7 +1315,22 @@ export interface operations { path?: never; cookie?: never; }; - requestBody?: never; + requestBody?: { + content: { + /** + * @example { + * "sealed": true, + * "label": "mygame:round:42" + * } + */ + "application/json": { + /** @description Make a sealed commit. Requires a live (`pk_live_*`) API key and `label`. */ + sealed?: boolean; + /** @description What the commit is for, e.g. `mygame:round:42`. Only with `sealed`; unique per key. */ + label?: string; + }; + }; + }; responses: { /** @description A new commit. Save `commitId` and `serverHash` for verification, then call `/api/reveal`. */ 200: { @@ -1245,7 +1349,51 @@ export interface operations { "application/json": components["schemas"]["Commit"]; }; }; + 400: components["responses"]["BadRequest"]; 401: components["responses"]["InvalidApiKey"]; + /** @description A `pk_test_*` key asked for a sealed commit. */ + 403: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": "sealed commits need a live (pk_live_*) api key", + * "code": "test_mode_forbidden" + * } + */ + "application/json": components["schemas"]["Error"]; + }; + }; + 429: components["responses"]["RateLimited"]; + 500: components["responses"]["ServerError"]; + }; + }; + listSealedCommits: { + parameters: { + query: { + /** @example mygame:round:42 */ + label: string; + limit?: number; + }; + header?: never; + path?: never; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Sealed commits for the label, oldest first. */ + 200: { + headers: { + "Server-Timing": components["headers"]["ServerTiming"]; + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["SealedCommit"][]; + }; + }; + 400: components["responses"]["BadRequest"]; 429: components["responses"]["RateLimited"]; 500: components["responses"]["ServerError"]; }; @@ -1253,10 +1401,10 @@ export interface operations { rollDice: { parameters: { query: { - /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. */ + /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. At most 256 characters. */ clientSeed?: components["parameters"]["ClientSeed"]; /** - * @description Dice notation `NdM`, `NdM+K`, or `NdM-K`. N: 1-100 dice. M: 2-1,000,000 sides. K: integer modifier added to the total. Examples: `3d6`, `2d20+5`, `1d100-10`. + * @description Dice notation `NdM`, `NdM+K`, or `NdM-K`. N: 1-100 dice. M: 2-1,000,000 sides. K: integer modifier added to the total, at most 1,000,000 either way. Examples: `3d6`, `2d20+5`, `1d100-10`. * @example 3d6+2 */ notation: string; @@ -1316,7 +1464,7 @@ export interface operations { getFloats: { parameters: { query?: { - /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. */ + /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. At most 256 characters. */ clientSeed?: components["parameters"]["ClientSeed"]; /** @description Number of values to generate (1-100). */ count?: components["parameters"]["Count"]; @@ -1373,15 +1521,15 @@ export interface operations { gaussian: { parameters: { query?: { - /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. */ + /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. At most 256 characters. */ clientSeed?: components["parameters"]["ClientSeed"]; /** @description Number of values to generate (1-100). */ count?: components["parameters"]["Count"]; /** @description Which distribution to sample. */ distribution?: "normal" | "exponential" | "poisson"; - /** @description Mean (μ) for `normal`. Defaults to 0. */ + /** @description Mean (μ) for `normal`, between -1e12 and 1e12. Defaults to 0. */ mean?: number; - /** @description Standard deviation (σ) for `normal`. Must be > 0. Defaults to 1. */ + /** @description Standard deviation (σ) for `normal`. Must be > 0 and at most 1e12. Defaults to 1. */ stddev?: number; /** @description Rate parameter (λ) for `exponential` (> 0) or `poisson` (> 0, ≤ 100). Defaults to 1. */ lambda?: number; @@ -1502,7 +1650,7 @@ export interface operations { incrementCursor: { parameters: { query?: { - /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. */ + /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. At most 256 characters. */ clientSeed?: components["parameters"]["ClientSeed"]; }; header?: never; @@ -1549,7 +1697,7 @@ export interface operations { getInts: { parameters: { query?: { - /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. */ + /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. At most 256 characters. */ clientSeed?: components["parameters"]["ClientSeed"]; /** @description Number of values to generate (1-100). */ count?: components["parameters"]["Count"]; @@ -1614,7 +1762,7 @@ export interface operations { listOutcomes: { parameters: { query?: { - /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. */ + /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. At most 256 characters. */ clientSeed?: components["parameters"]["ClientSeed"]; /** @description Max outcomes to return (1-1000, default 1000). */ limit?: number; @@ -1833,7 +1981,7 @@ export interface operations { getOutcome: { parameters: { query: { - /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. */ + /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. At most 256 characters. */ clientSeed?: components["parameters"]["ClientSeed"]; /** * @description Cursor of the outcome to look up. @@ -1894,10 +2042,10 @@ export interface operations { pickItem: { parameters: { query: { - /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. */ + /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. At most 256 characters. */ clientSeed?: components["parameters"]["ClientSeed"]; /** - * @description Items to choose from. Same encoding as `/api/shuffle`. 1-1000 entries. + * @description Items to choose from. Same encoding and limits as `/api/shuffle`. 1-1000 entries. * @example common,rare,legendary */ items: string | string[]; @@ -2179,10 +2327,10 @@ export interface operations { shuffleItems: { parameters: { query: { - /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. */ + /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. At most 256 characters. */ clientSeed?: components["parameters"]["ClientSeed"]; /** - * @description Items to shuffle. Pass a JSON array (`items=["a","b","c"]`), a comma-separated list (`items=a,b,c`), or repeat the parameter (`items=a&items=b&items=c`). 1-1000 entries. + * @description Items to shuffle. Pass a JSON array (`items=["a","b","c"]`), a comma-separated list (`items=a,b,c`), or repeat the parameter (`items=a&items=b&items=c`). 1-1000 entries, each a string or number of at most 256 characters, 32 KB in total. * @example a,b,c,d */ items: string | string[]; @@ -2238,7 +2386,7 @@ export interface operations { streamOutcomes: { parameters: { query: { - /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. */ + /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. At most 256 characters. */ clientSeed?: components["parameters"]["ClientSeed"]; /** * @description Which generator to stream. @@ -2293,7 +2441,7 @@ export interface operations { verifyServerHash: { parameters: { query: { - /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. */ + /** @description Your seed for this generation. Combined with the server seed to produce provably fair output. Defaults to the literal string `"test"` when omitted, so anonymous demos work out of the box — production callers should always pass a stable, caller-owned value (your account id, a session id, etc.) to keep their own deterministic seed history. At most 256 characters. */ clientSeed?: components["parameters"]["ClientSeed"]; /** * @description The server hash returned with the original outcome. @@ -2364,8 +2512,9 @@ export interface operations { content: { /** * @example { - * "verified": true, - * "reason": "Server seed hash on file matches the current state for this client seed.", + * "verified": false, + * "status": "committed", + * "reason": "The serverHash was on file before this draw. The result can be replayed once the server seed is revealed by rotating the client seed.", * "shortId": "k7Qm2A9bXz", * "clientSeed": "my-app", * "serverHash": "9f86d081884c7d65...", @@ -2378,10 +2527,14 @@ export interface operations { */ "application/json": { verified: boolean; + /** @enum {string} */ + status?: "verified" | "committed" | "revealed" | "mismatch"; reason: string; shortId: string; clientSeed?: string | null; serverHash?: string; + /** @description The revealed server seed, or null until the client seed is rotated. */ + serverSeed?: string | null; cursor?: number | null; nonce?: number | null; endpoint?: string | null; @@ -2409,6 +2562,38 @@ export interface operations { 500: components["responses"]["ServerError"]; }; }; + streamPublicDraws: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Event stream of public draws. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example event: draw + * id: k7Qm2A9bXz + * data: {"shortId":"k7Qm2A9bXz","label":"ints 1–100","result":"57","clientSeed":"player-42","nonce":18,"created":"2026-11-09T22:41:07.512Z"} + */ + "text/event-stream": string; + }; + }; + /** @description The feed is at capacity; poll /o.json instead. */ + 204: { + headers: { + [name: string]: unknown; + }; + content?: never; + }; + }; + }; getOutcomePermalink: { parameters: { query?: never;