Game servers
A game on this store can talk to servers of its own: accounts, a leaderboard of your own, matchmaking, an asset server. The store lets that happen on one condition: you declare every server in velox.json. The store shows the list to players, asks them once before the first launch, and the player's browser blocks every host that is not on it. A ticket from the store lets one of your declared servers verify which Velox player is connecting, without any account system of your own.
Declare your servers #
{
"servers": [
{
"origin": "https://clankmates.codai.app",
"purpose": { "en": "Accounts, friends and matchmaking", "de": "Konten, Freunde und Matchmaking" },
"operator": "Codai",
"privacy": "https://codai.app/privacy",
"realtime": true
}
]
}
The fields are in the velox.json reference (servers); the rules in short:
origin | https://host or wss://host, optionally with :port. No path, no wildcard, no IP address, no localhost (the store refuses those: a player's browser cannot reach your machine). One entry covers both the https and the wss address of the host; list every host once (another port is another host). |
purpose | What the game sends there and why, in plain words. Up to 200 characters per language, en required. Players read it. |
operator | Who runs the server: the party whose privacy policy applies. Up to 120 characters. |
privacy | The operator's privacy policy, an https:// address. |
realtime | Optional: the game keeps a live connection (WebSocket) to it. Only shown. |
| count | At most 8 servers per build. |
velox verify checks the list and says what is wrong in English and German; velox push carries it with the build (the CLI prints the declared hosts). A declaration belongs to a build: it is stored with the immutable build manifest, and a build serves exactly the hosts it declared. To add a server you push a new build; an older build keeps the older list, and a playtest branch can declare differently from the default branch. Pushing from a local dev stack that declares localhost needs --local-servers (and only works against a development store: production refuses it).
What players see #
- On the game page, a section Connects to lists each server: host, who runs it, the purpose and a link to the operator's privacy policy.
- Before the first launch of a game that declares servers, the player shows a one-time notice: "This game connects to servers run by <operator>: <hosts>. Their privacy policy applies to what the game sends there." with the link and a Continue button (a dialog the keyboard and screen readers can use). It is remembered per game in the player's browser and shown again only when your list of hosts or operators changes. Time spent reading it does not count as play time.
- Moderators read the declaration of every build of a game, any state, when they review it.
You are the controller under the GDPR for what your game sends to your servers and processes there, and the operator's privacy policy you link must cover it. This store does not pass account data to those servers: only what the ticket below contains, and only when your game asks for it. Declaring a server does not make it fine to use one you did not declare; using an undeclared server, or a declared one for a purpose other than the one you gave, breaches the developer terms.
What is enforced #
The CDN serves every file of a build with a Content-Security-Policy made from that build's declaration. The shape:
default-src 'self' blob: data:
script-src 'self' 'unsafe-inline' 'unsafe-eval' 'wasm-unsafe-eval' blob:
style-src 'self' 'unsafe-inline' blob:
img-src 'self' data: blob: <declared https hosts>
media-src 'self' data: blob: <declared https hosts>
font-src 'self' data: blob: <declared https hosts>
connect-src 'self' blob: data: <Velox cloud, net and telemetry> <declared https and wss hosts>
worker-src 'self' blob: object-src 'none' base-uri 'self' form-action 'self'
- Allowed: the game's own origin, Velox's own endpoints (cloud saves, realtime rooms, telemetry), and your declared hosts.
fetch,XMLHttpRequest,WebSocket,EventSourceandnavigator.sendBeaconfollowconnect-src; images, audio, video and fonts may also come from a declared host (an image URL is a way to send data too). - Blocked by the browser: every other host, for all of those. A blocked call fails like a network error and the browser console says
Refused to connect to ... because it violates the following Content Security Policy directive. - Never from a declared host: scripts and styles. A declared server is for data, not code; load code from your own bundle.
- Workers and the service worker carry the same policy, so a worker cannot fetch where the page cannot.
What it cannot enforce, and the developer terms forbid: WebRTC (peer-to-peer connections have no CSP directive; the SDK's own peer lobbies use them), and navigating the whole frame to another address. velox dev serves your game without this policy, so test against a pushed draft build to see what the player will block.
Player tickets #
Your server gets the player's identity without a login of its own. In the game:
const ticket = await velox.auth.getTicket("https://clankmates.codai.app"); // a string, or null
if (ticket) await fetch("https://clankmates.codai.app/join", { headers: { Authorization: `Bearer ${ticket}` } });
getTicket(audience) takes one of your declared origins exactly as you wrote it (the wss:// spelling of a declared host works too). It resolves null when the player is a guest, when the origin is not declared in the build that is running, when the store has no signing key, and in the local emulator (whose ticket is an unsigned toy that no server can verify). The ticket is valid 5 minutes: ask for a fresh one whenever you open a connection.
A ticket is a compact JWS signed with EdDSA (Ed25519) or ES256 (ECDSA P-256 with SHA-256); the header's alg says which, and the matching key in the key set carries the same alg. Accept only those two, and only when the header agrees with the key (never none, never an algorithm the token picks for itself). Its claims:
| claim | |
|---|---|
iss | the store's public origin, e.g. https://store.example (the address of the store the game runs on) |
aud | your server's origin, as the game asked for it. Accept only a ticket made out to you. |
sub | the player's id in this game (g_...): the same every time for one player in your game, different in every other game, never the account id. Key your own data on it. |
name | the player's Codai ID username (the one name Velox shows for them; they change it at Codai ID) |
game | your game's slug |
iat, exp | issued at and expiry, seconds; exp = iat + 300 |
jti | a unique id; remember it for five minutes if you want a ticket to work once |
The public keys are at <store origin>/.well-known/jwks.json; the header's kid names the key. A key set can hold several keys at once (the current one and, for a few minutes after a rotation, the one before it), and they need not use the same algorithm. The store rotates its key without notice to you: keep the key set for a few minutes and fetch it again when you meet an unknown kid. Verify on your server, never in the game.
Verifying a ticket (plain WebCrypto, no library) #
Runs in Node 20+, Bun, Deno and Workers:
const ISS = "https://store.example", AUD = "https://clankmates.codai.app"; // the store, and this server's declared origin
const b64 = (s) => Uint8Array.from(atob(s.replace(/-/g, "+").replace(/_/g, "/")), (c) => c.charCodeAt(0));
const ALGS = { ES256: [{ name: "ECDSA", namedCurve: "P-256" }, { name: "ECDSA", hash: "SHA-256" }], EdDSA: [{ name: "Ed25519" }, { name: "Ed25519" }] };
let jwks, fetchedAt = 0;
async function verifyTicket(token) {
const [h, p, s] = token.split(".");
const { alg, kid } = JSON.parse(new TextDecoder().decode(b64(h)));
if (!Object.hasOwn(ALGS, alg)) throw new Error("bad algorithm");
if (!jwks || !jwks.keys.some((k) => k.kid === kid) || Date.now() - fetchedAt > 300_000) { jwks = await (await fetch(`${ISS}/.well-known/jwks.json`)).json(); fetchedAt = Date.now(); }
const jwk = jwks.keys.find((k) => k.kid === kid);
if (!jwk) throw new Error("unknown key");
if (jwk.alg !== alg) throw new Error("bad algorithm"); // the KEY says which algorithm it is for, not the token
const key = await crypto.subtle.importKey("jwk", jwk, ALGS[alg][0], false, ["verify"]);
const ok = await crypto.subtle.verify(ALGS[alg][1], key, b64(s), new TextEncoder().encode(`${h}.${p}`));
const c = JSON.parse(new TextDecoder().decode(b64(p)));
if (!ok || c.iss !== ISS || c.aud !== AUD || c.exp * 1000 < Date.now()) throw new Error("not a valid ticket for this server");
return c; // { sub: "g_...", name, game, jti, iat, exp }
}
With a package instead: @velox/protocol/ticket exports verifyVeloxTicket(token, { issuer, audience, jwksUrl? | jwks? }), which does the same plus the lifetime check (a ticket valid for more than ten minutes is refused whatever its exp says), caches the key set and refetches once on an unknown key. It returns { ok: true, claims } or { ok: false, code } and never throws.
import { verifyVeloxTicket } from "@velox/protocol/ticket";
const r = await verifyVeloxTicket(token, { issuer: "https://store.example", audience: "https://clankmates.codai.app" });
if (!r.ok) return new Response("unauthorized", { status: 401 }); // r.code says why
A ticket proves who is connecting, once, for five minutes. It is not a session: give the player your own session after you verified it, and do not log tickets. The store keeps no record of the tickets it issues.