@crowdedkingdoms/crowdyjs 18.39.1 → 18.40.0-test.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/MIGRATION.md +62 -0
  2. package/README.md +420 -17
  3. package/dist/binary-wire.d.ts +94 -1
  4. package/dist/binary-wire.d.ts.map +1 -1
  5. package/dist/binary-wire.js +122 -20
  6. package/dist/crowdy-client.d.ts +7 -0
  7. package/dist/crowdy-client.d.ts.map +1 -1
  8. package/dist/crowdy-client.js +3 -0
  9. package/dist/default-origin.d.ts +6 -6
  10. package/dist/default-origin.js +6 -6
  11. package/dist/domains/admin.d.ts +7 -0
  12. package/dist/domains/admin.d.ts.map +1 -1
  13. package/dist/domains/admin.js +1 -0
  14. package/dist/domains/exec.d.ts +91 -3
  15. package/dist/domains/exec.d.ts.map +1 -1
  16. package/dist/domains/exec.js +132 -5
  17. package/dist/domains/fleetSessions.d.ts +87 -0
  18. package/dist/domains/fleetSessions.d.ts.map +1 -0
  19. package/dist/domains/fleetSessions.js +87 -0
  20. package/dist/dropped-read.d.ts +2 -1
  21. package/dist/dropped-read.d.ts.map +1 -1
  22. package/dist/dropped-read.js +2 -6
  23. package/dist/errors.d.ts +59 -0
  24. package/dist/errors.d.ts.map +1 -1
  25. package/dist/errors.js +70 -0
  26. package/dist/fleet/index.d.ts +4 -0
  27. package/dist/fleet/index.d.ts.map +1 -0
  28. package/dist/fleet/index.js +21 -0
  29. package/dist/fleet/session.d.ts +730 -0
  30. package/dist/fleet/session.d.ts.map +1 -0
  31. package/dist/fleet/session.js +1376 -0
  32. package/dist/fleet/socket.d.ts +59 -0
  33. package/dist/fleet/socket.d.ts.map +1 -0
  34. package/dist/fleet/socket.js +111 -0
  35. package/dist/fleet-wire.d.ts +272 -0
  36. package/dist/fleet-wire.d.ts.map +1 -0
  37. package/dist/fleet-wire.js +472 -0
  38. package/dist/generated/graphql-schema.d.ts +176 -13
  39. package/dist/generated/graphql-schema.d.ts.map +1 -1
  40. package/dist/generated/graphql-schema.js +15 -3
  41. package/dist/generated/graphql.d.ts +79 -0
  42. package/dist/generated/graphql.d.ts.map +1 -1
  43. package/dist/generated/graphql.js +5 -0
  44. package/dist/index.d.ts +6 -3
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +7 -3
  47. package/dist/server-only.d.ts +54 -0
  48. package/dist/server-only.d.ts.map +1 -0
  49. package/dist/server-only.js +55 -0
  50. package/package.json +5 -1
@@ -0,0 +1,59 @@
1
+ /** The realtime server a fleet session connects to: `openFleetSession`'s `server`. */
2
+ export interface FleetServer {
3
+ /**
4
+ * IPv4 address; used when it is not empty. Every realtime server has one, and it is the
5
+ * address `refreshFleetSession`'s `currentServer` names.
6
+ */
7
+ ip4?: string | null;
8
+ /** IPv6 address; used when there is no IPv4 address. */
9
+ ip6?: string | null;
10
+ /** The UDP port clients connect to. */
11
+ clientPort: number;
12
+ }
13
+ /** What a {@link FleetSocket} tells the session. */
14
+ export interface FleetSocketEvents {
15
+ /** One datagram arrived from the realtime server. */
16
+ onDatagram(datagram: Uint8Array): void;
17
+ /** The socket failed; the session reports it and keeps going. */
18
+ onError(error: Error): void;
19
+ }
20
+ /**
21
+ * The one thing a fleet session needs from the network: a UDP socket to one realtime server.
22
+ * The default is `node:dgram`; a test passes an in-memory one.
23
+ */
24
+ export interface FleetSocket {
25
+ /** Send one datagram to the realtime server the socket was opened for. */
26
+ send(datagram: Uint8Array): void;
27
+ /** Close the socket. No datagram is delivered afterwards. */
28
+ close(): void;
29
+ }
30
+ /** Opens a {@link FleetSocket} to `server`. */
31
+ export type FleetSocketFactory = (server: FleetServer, events: FleetSocketEvents) => Promise<FleetSocket> | FleetSocket;
32
+ /** Socket buffer sizes for {@link nodeFleetSocket}. */
33
+ export interface NodeFleetSocketOptions {
34
+ /**
35
+ * The socket's receive buffer, in bytes. Default 1,048,576: one session receives for every
36
+ * player it carries. The operating system may give less.
37
+ */
38
+ recvBufferSize?: number;
39
+ /** The socket's send buffer, in bytes. Default 1,048,576. */
40
+ sendBufferSize?: number;
41
+ }
42
+ /** The address a session dials for `server`: IPv4 when it has one, IPv6 otherwise. */
43
+ export declare function fleetServerAddress(server: FleetServer): {
44
+ host: string;
45
+ family: 4 | 6;
46
+ port: number;
47
+ };
48
+ /**
49
+ * Throws unless this runtime can have `node:dgram`: a `process` that says it runs Node's
50
+ * modules (Node, and the runtimes that carry them). The fleet entry point calls it when it
51
+ * is imported, so a bundle for a page fails on its first line instead of at the first send.
52
+ */
53
+ export declare function assertFleetRuntime(): void;
54
+ /**
55
+ * The default {@link FleetSocketFactory}: a `node:dgram` socket connected to the realtime
56
+ * server, so the operating system delivers only that server's datagrams. Node only.
57
+ */
58
+ export declare function nodeFleetSocket(options?: NodeFleetSocketOptions): FleetSocketFactory;
59
+ //# sourceMappingURL=socket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../src/fleet/socket.ts"],"names":[],"mappings":"AAEA,sFAAsF;AACtF,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,oDAAoD;AACpD,MAAM,WAAW,iBAAiB;IAChC,qDAAqD;IACrD,UAAU,CAAC,QAAQ,EAAE,UAAU,GAAG,IAAI,CAAC;IACvC,iEAAiE;IACjE,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,0EAA0E;IAC1E,IAAI,CAAC,QAAQ,EAAE,UAAU,GAAG,IAAI,CAAC;IACjC,6DAA6D;IAC7D,KAAK,IAAI,IAAI,CAAC;CACf;AAED,+CAA+C;AAC/C,MAAM,MAAM,kBAAkB,GAAG,CAC/B,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,iBAAiB,KACtB,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;AAExC,uDAAuD;AACvD,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,6DAA6D;IAC7D,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,sFAAsF;AACtF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAQrG;AAgCD;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAKzC;AAeD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,kBAAkB,CAqDxF"}
@@ -0,0 +1,111 @@
1
+ import { CrowdyError } from '../errors.js';
2
+ /** The address a session dials for `server`: IPv4 when it has one, IPv6 otherwise. */
3
+ export function fleetServerAddress(server) {
4
+ const port = server.clientPort;
5
+ if (!Number.isInteger(port) || port <= 0 || port > 65535) {
6
+ throw new CrowdyError({ message: `the realtime server names no usable clientPort: ${String(port)}` });
7
+ }
8
+ if (server.ip4)
9
+ return { host: server.ip4, family: 4, port };
10
+ if (server.ip6)
11
+ return { host: server.ip6, family: 6, port };
12
+ throw new CrowdyError({ message: 'the realtime server names no ip4 and no ip6 address' });
13
+ }
14
+ const NO_DGRAM = '@crowdedkingdoms/crowdyjs/fleet runs on a server your organization runs: it opens a UDP socket ' +
15
+ 'with node:dgram, which this runtime does not have. A fleet session never runs in a browser ' +
16
+ 'page or a game client, because the fleet token and the org token never go there.';
17
+ function processLike() {
18
+ return globalThis.process;
19
+ }
20
+ /**
21
+ * Throws unless this runtime can have `node:dgram`: a `process` that says it runs Node's
22
+ * modules (Node, and the runtimes that carry them). The fleet entry point calls it when it
23
+ * is imported, so a bundle for a page fails on its first line instead of at the first send.
24
+ */
25
+ export function assertFleetRuntime() {
26
+ const proc = processLike();
27
+ if (typeof proc?.getBuiltinModule === 'function' && proc.getBuiltinModule('node:dgram'))
28
+ return;
29
+ if (typeof proc?.versions?.node === 'string')
30
+ return;
31
+ throw new CrowdyError({ message: NO_DGRAM });
32
+ }
33
+ async function loadDgram() {
34
+ const proc = processLike();
35
+ const builtin = typeof proc?.getBuiltinModule === 'function' ? proc.getBuiltinModule('node:dgram') : null;
36
+ if (builtin)
37
+ return builtin;
38
+ try {
39
+ // Not a literal, so a bundler does not try to resolve it for a page.
40
+ const specifier = 'node:dgram';
41
+ return (await import(/* webpackIgnore: true */ /* @vite-ignore */ specifier));
42
+ }
43
+ catch (cause) {
44
+ throw new CrowdyError({ message: NO_DGRAM, cause });
45
+ }
46
+ }
47
+ /**
48
+ * The default {@link FleetSocketFactory}: a `node:dgram` socket connected to the realtime
49
+ * server, so the operating system delivers only that server's datagrams. Node only.
50
+ */
51
+ export function nodeFleetSocket(options = {}) {
52
+ const recvBufferSize = options.recvBufferSize ?? 1048576;
53
+ const sendBufferSize = options.sendBufferSize ?? 1048576;
54
+ return async (server, events) => {
55
+ const { host, family, port } = fleetServerAddress(server);
56
+ const dgram = await loadDgram();
57
+ const socket = dgram.createSocket({ type: family === 4 ? 'udp4' : 'udp6' });
58
+ await new Promise((resolve, reject) => {
59
+ const failed = (error) => {
60
+ try {
61
+ socket.close();
62
+ }
63
+ catch {
64
+ /* never opened */
65
+ }
66
+ reject(new CrowdyError({ message: `could not open a UDP socket to ${host}:${port}`, cause: error }));
67
+ };
68
+ socket.once('error', failed);
69
+ socket.connect(port, host, () => {
70
+ socket.removeListener('error', failed);
71
+ resolve();
72
+ });
73
+ });
74
+ for (const [set, size] of [
75
+ [(n) => socket.setRecvBufferSize(n), recvBufferSize],
76
+ [(n) => socket.setSendBufferSize(n), sendBufferSize],
77
+ ]) {
78
+ try {
79
+ if (size > 0)
80
+ set(size);
81
+ }
82
+ catch {
83
+ // The operating system's own size stands.
84
+ }
85
+ }
86
+ socket.on('message', (message) => events.onDatagram(message));
87
+ socket.on('error', (error) => events.onError(error));
88
+ let closed = false;
89
+ return {
90
+ send(datagram) {
91
+ if (closed)
92
+ return;
93
+ socket.send(datagram, (error) => {
94
+ if (error && !closed)
95
+ events.onError(error);
96
+ });
97
+ },
98
+ close() {
99
+ if (closed)
100
+ return;
101
+ closed = true;
102
+ try {
103
+ socket.close();
104
+ }
105
+ catch {
106
+ /* already closed */
107
+ }
108
+ },
109
+ };
110
+ };
111
+ }
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Wire codecs for a fleet session (realtime servers v0.50.3): one realtime session an
3
+ * organization's game server opens for itself, in which it carries the players who are on it.
4
+ *
5
+ * Pure functions with no I/O: they build and read bytes and compute HMACs with WebCrypto, so
6
+ * they run in any JavaScript runtime. `FleetSession` (`@crowdedkingdoms/crowdyjs/fleet`) is
7
+ * the session that sends and receives them over UDP.
8
+ *
9
+ * **A fleet token signs for every player its session carries. It stays on a server the
10
+ * organization runs, beside the organization's org token, and never goes into a browser page
11
+ * or a game client.**
12
+ *
13
+ * What a game server sends:
14
+ *
15
+ * - **For a carried player**, the message that player's own session would send, with the
16
+ * tail's game token id the player's and the tail's HMAC keyed with the fleet token. Build
17
+ * it with the serializers in binary-wire.ts and {@link carriedPlayerContext}.
18
+ * - **Under the session's own game token id**, only `CLIENT_CAPABILITIES` (29),
19
+ * `FLEET_CARRY` (49), `FLEET_RELEASE` (50) and `CLIENT_ACTOR_HEARTBEAT` (26, with no actor).
20
+ *
21
+ * What it receives is read by {@link parseFleetDatagram}, which verifies before it returns:
22
+ * `FLEET_CARRY_RESULT` (51), `FLEET_RELEASED` (52) and `FLEET_DELIVERY` (53) in both of their
23
+ * forms, plain notifications, and the control frames that move or end the session.
24
+ *
25
+ * All numbers are little endian. Game token ids and user ids are 64-bit and are returned as
26
+ * decimal strings, as the Application API returns them.
27
+ */
28
+ import { type RelaySignContext } from './binary-wire.js';
29
+ import type { UdpNotification } from './realtime.js';
30
+ /**
31
+ * The largest datagram a fleet session is sent: a `FLEET_DELIVERY` with one player, alone,
32
+ * with its own HMAC. Nothing else the realtime servers send a client is above 1,232 bytes.
33
+ * Size receive buffers for this.
34
+ */
35
+ export declare const FLEET_MAX_DATAGRAM_BYTES = 1242;
36
+ /** The most players one `FLEET_DELIVERY` lists; more are split over frames. */
37
+ export declare const FLEET_MAX_DELIVERY_PLAYERS = 32;
38
+ /** A token, as its 64 octets: a fleet token and a player's app token alike. */
39
+ export declare const FLEET_TOKEN_CHARS = 64;
40
+ /** The ASCII label a `FLEET_CARRY` proof starts with (14 bytes). */
41
+ export declare const FLEET_CARRY_PROOF_LABEL = "ck-fleet-carry";
42
+ /** A `FLEET_CARRY` whose time is further than this from the server's is refused (status 3). */
43
+ export declare const FLEET_CARRY_CLOCK_TOLERANCE_MS = 30000;
44
+ /** `FLEET_CARRY`'s app payload: `[8B player gameTokenId][8B epoch ms][32B proof]`. */
45
+ export declare const FLEET_CARRY_PAYLOAD_BYTES = 48;
46
+ /** `FLEET_CARRY_RESULT`: `[1B 51][8B player gameTokenId][8B user id][1B status]`. */
47
+ export declare const FLEET_CARRY_RESULT_BYTES = 18;
48
+ /** `FLEET_RELEASED`: `[1B 52][8B player gameTokenId][1B reason]`. */
49
+ export declare const FLEET_RELEASED_BYTES = 10;
50
+ /** `FLEET_CARRY_RESULT`'s status byte. Treat a value not listed as a refusal. */
51
+ export declare const FleetCarryStatus: {
52
+ /** The session carries the player; the result names their user id. */
53
+ readonly CARRIED: 0;
54
+ /** No live token by that game token id (also: a token of another app). */
55
+ readonly NO_LIVE_TOKEN: 1;
56
+ /** The token is another organization's player's. */
57
+ readonly OTHER_ORGANIZATION: 2;
58
+ /** The proof or its time failed (also: a carry sent again after it ended, a replay). */
59
+ readonly PROOF_FAILED: 3;
60
+ /** The session carries as many players as it may (also: the server has no place for it). */
61
+ readonly SESSION_FULL: 4;
62
+ };
63
+ /** `FLEET_RELEASED`'s reason byte. Treat a value not listed as the carry having ended. */
64
+ export declare const FleetReleaseReason: {
65
+ /** Another session carries the player now: they moved to another of your servers. */
66
+ readonly CARRIED_ELSEWHERE: 1;
67
+ /** The player's sign-in ended (revoked, or expired and not carried again with a live token). */
68
+ readonly SIGN_IN_ENDED: 2;
69
+ /** No gameplay input from the player for the app's idle timeout. */
70
+ readonly IDLE: 5;
71
+ };
72
+ /** `COMMAND_SESSION_RELEASED`'s reason byte. Treat a value not listed as `STALE`. */
73
+ export declare const SessionReleaseReason: {
74
+ readonly DEAUTHORIZED: 0;
75
+ readonly STALE: 1;
76
+ readonly TOKEN_EXPIRED: 2;
77
+ readonly OVERLOAD: 3;
78
+ readonly REBALANCE: 4;
79
+ readonly IDLE: 5;
80
+ };
81
+ /** A game token id or a user id: a 64-bit number as a decimal string, a bigint or a safe integer. */
82
+ export type FleetId = string | bigint | number;
83
+ /**
84
+ * The fleet session's own signing context: its `gameTokenId` and its token (the 64 characters
85
+ * `openFleetSession` answered) as the HMAC key. It signs the session's own messages
86
+ * (29, 49, 50, 26), verifies everything the session is sent, and is what
87
+ * {@link carriedPlayerContext} derives a player's context from.
88
+ * @throws {RangeError} for a token that is not 64 characters or an id that is not a 64-bit number.
89
+ */
90
+ export declare function createFleetSignContext(fleetGameTokenId: FleetId, fleetToken: string): Promise<RelaySignContext>;
91
+ /**
92
+ * The signing context for a message a fleet session sends for a carried player: the tail's
93
+ * game token id is the player's, and the HMAC is keyed with the fleet token. Pass it to any
94
+ * serializer in binary-wire.ts (`serializeActorUpdate`, `serializeVoxelUpdate`,
95
+ * `serializeClientEvent`, `serializeTextPacket`, `serializeAudioPacket`,
96
+ * `serializeVideoPacket`, `serializeClientMediaSpeakers`, `serializeActorHeartbeat`, the
97
+ * channel serializers) and the result is the message that player's own session would send,
98
+ * signed by the fleet session.
99
+ */
100
+ export declare function carriedPlayerContext(fleet: RelaySignContext, playerGameTokenId: FleetId): RelaySignContext;
101
+ /** What a `FLEET_CARRY` proves and names. */
102
+ export interface FleetCarryInput {
103
+ /** The session's app. */
104
+ appId: FleetId;
105
+ /** The player's app token's `gameTokenId`. */
106
+ playerGameTokenId: FleetId;
107
+ /** The player's app token: 64 characters. It keys the proof and is not sent. */
108
+ playerToken: string;
109
+ /**
110
+ * The time the proof is made for, in epoch milliseconds. The server refuses one more than
111
+ * 30 seconds from its own, and one older than the last carry of that player it accepted
112
+ * from this session: a carry sent again needs a new time and a new proof.
113
+ */
114
+ epochMillis: FleetId;
115
+ sequenceNumber?: number | null;
116
+ }
117
+ /**
118
+ * The proof inside a `FLEET_CARRY`: it shows the game server holds the player's token.
119
+ *
120
+ * ```
121
+ * HMAC-SHA256(key = the player's 64-octet token,
122
+ * "ck-fleet-carry" (14 ASCII bytes) || 8B fleet gameTokenId ||
123
+ * 8B player gameTokenId || 8B epoch ms)
124
+ * ```
125
+ */
126
+ export declare function fleetCarryProof(input: {
127
+ playerToken: string;
128
+ fleetGameTokenId: FleetId;
129
+ playerGameTokenId: FleetId;
130
+ epochMillis: FleetId;
131
+ }): Promise<Uint8Array>;
132
+ /**
133
+ * Build a `FLEET_CARRY` (49): "this session carries this player". The capabilities'
134
+ * long-spatial layout (chunk `(0,0,0)`, distance 0, no actor uuid) under the session's own
135
+ * game token id, with the app payload `[8B player gameTokenId][8B epoch ms][32B proof]`
136
+ * ({@link fleetCarryProof}). 157 bytes. The server answers `FLEET_CARRY_RESULT` (51), or
137
+ * nothing: send it again, with a new time and proof, until it does.
138
+ */
139
+ export declare function serializeFleetCarry(fleet: RelaySignContext, input: FleetCarryInput): Promise<Uint8Array>;
140
+ /**
141
+ * Build a `FLEET_RELEASE` (50): "this player left the game". `FLEET_CARRY`'s layout with the
142
+ * app payload `[8B player gameTokenId]`. 117 bytes. The server sends no answer, and sending
143
+ * it again changes nothing. The player's actors leave as when a player's own session ends.
144
+ */
145
+ export declare function serializeFleetRelease(fleet: RelaySignContext, input: {
146
+ appId: FleetId;
147
+ playerGameTokenId: FleetId;
148
+ sequenceNumber?: number | null;
149
+ }): Promise<Uint8Array>;
150
+ /** A `FLEET_CARRY_RESULT` (51): the answer to a `FLEET_CARRY`. */
151
+ export interface FleetCarryResultFrame {
152
+ playerGameTokenId: string;
153
+ /** The player's user id when `status` is 0; `'0'` otherwise. */
154
+ userId: string;
155
+ /** {@link FleetCarryStatus}. */
156
+ status: number;
157
+ }
158
+ /** A `FLEET_RELEASED` (52): the server ended a carry. */
159
+ export interface FleetReleasedFrame {
160
+ playerGameTokenId: string;
161
+ /** {@link FleetReleaseReason}. */
162
+ reason: number;
163
+ }
164
+ /** A `FLEET_DELIVERY` (53): one notification, and the carried players it is for. */
165
+ export interface FleetDeliveryFrame {
166
+ /** The carried players who may receive the notification, by game token id: 1 to 32. */
167
+ players: string[];
168
+ /** The notification, as the SDK's parsers produce it for a player's own session. */
169
+ notification: UdpNotification;
170
+ }
171
+ /**
172
+ * Read a `FLEET_CARRY_RESULT` (51) frame, `[1B 51][8B player gameTokenId][8B user id]
173
+ * [1B status]`, without its HMAC. `null` for a frame that is not one. This does not verify:
174
+ * {@link parseFleetDatagram} does.
175
+ */
176
+ export declare function parseFleetCarryResult(frame: Uint8Array): FleetCarryResultFrame | null;
177
+ /**
178
+ * Read a `FLEET_RELEASED` (52) frame, `[1B 52][8B player gameTokenId][1B reason]`, without
179
+ * its HMAC. `null` for a frame that is not one. This does not verify.
180
+ */
181
+ export declare function parseFleetReleased(frame: Uint8Array): FleetReleasedFrame | null;
182
+ /**
183
+ * Read a `FLEET_DELIVERY` (53) frame, `[1B 53][1B count][count x 8B player gameTokenId]
184
+ * [notification]`, without its HMAC, and unwrap the notification inside into the object the
185
+ * SDK's parsers produce. The notification is what a player's own session would have been
186
+ * sent, unsigned: a long-spatial one with its 9-byte tail and `containsAuth` 0, or a channel
187
+ * one (18 or 36). `null` for a count of 0 or above 32, a frame shorter than its count says,
188
+ * and a frame whose contents are not a notification that can be read. This does not verify.
189
+ */
190
+ export declare function parseFleetDelivery(frame: Uint8Array): FleetDeliveryFrame | null;
191
+ /** One verified message out of a datagram a fleet session was sent. */
192
+ export type FleetInbound = ({
193
+ kind: 'carryResult';
194
+ } & FleetCarryResultFrame) | ({
195
+ kind: 'released';
196
+ } & FleetReleasedFrame) | ({
197
+ kind: 'delivery';
198
+ } & FleetDeliveryFrame)
199
+ /**
200
+ * A plain notification: state, sent once for the session when at least one carried player
201
+ * may receive it, or a `GenericErrorResponse`. State is returned only verified. `verified`
202
+ * is false for one thing alone: an error frame (`[3][seq][code]`) that came outside a signed
203
+ * bundle. It has no room for an HMAC, so nothing shows the realtime server sent it.
204
+ */
205
+ | {
206
+ kind: 'notification';
207
+ notification: UdpNotification;
208
+ verified: boolean;
209
+ }
210
+ /** `COMMAND_RECONNECT` (22) or its bound form (44): connect to another realtime server. */
211
+ | {
212
+ kind: 'reconnect';
213
+ bound: boolean;
214
+ }
215
+ /** `COMMAND_SESSION_RELEASED` (28) or its bound form (45), with {@link SessionReleaseReason}. */
216
+ | {
217
+ kind: 'sessionReleased';
218
+ reason: number;
219
+ bound: boolean;
220
+ }
221
+ /** `CONTROL_BOUND_ACK` (46): the server accepted the capabilities that carried this nonce. */
222
+ | {
223
+ kind: 'controlBoundAck';
224
+ };
225
+ /** What {@link parseFleetDatagram} read, and what it dropped. */
226
+ export interface FleetDatagram {
227
+ /** The messages that verified, in the datagram's order. */
228
+ messages: FleetInbound[];
229
+ /** Frames dropped because their HMAC did not verify (a signed bundle counts once). */
230
+ hmacFailures: number;
231
+ /** Frames dropped because they could not be read. */
232
+ malformed: number;
233
+ /**
234
+ * Notifications dropped because they carried no HMAC and were not inside a signed bundle
235
+ * or a `FLEET_DELIVERY`. The realtime servers sign every notification they send a session,
236
+ * so one without a signature did not come from them. No option takes them.
237
+ */
238
+ unsigned: number;
239
+ /** Bound control frames dropped because their nonce is not this connection's. */
240
+ staleControl: number;
241
+ }
242
+ export interface FleetParseOptions {
243
+ /**
244
+ * The 8 bytes this connection sent with `BOUND_CONTROL` in its capabilities. A bound control
245
+ * frame (44, 45, 46) verifies only with this nonce; without one every bound frame is stale.
246
+ */
247
+ controlNonce?: Uint8Array | null;
248
+ }
249
+ /**
250
+ * Read one datagram a fleet session was sent, verifying everything in it with the fleet
251
+ * token before returning it. A frame that fails is dropped and counted, never returned.
252
+ *
253
+ * - **`MESSAGE_BUNDLE_SIGNED` (30)**, sent to a session that advertised `BUNDLE_SIGNED`: one
254
+ * HMAC over the datagram, checked once. Its members, 51 to 53 among them, carry none.
255
+ * - **51, 52 and 53 anywhere else** (alone in the datagram, or a member of a
256
+ * `MESSAGE_BUNDLE`, 2): each is followed by its own HMAC, its last 32 bytes:
257
+ * `HMAC-SHA256(key = the fleet token, message = every byte before the HMAC || the fleet
258
+ * token)`. A session that advertised `BUNDLE_SIGNED` is still sent a `FLEET_DELIVERY` above
259
+ * 1,197 bytes this way, alone, so every session reads both forms.
260
+ * - **A plain long-spatial notification** outside a signed bundle carries its own HMAC
261
+ * (`containsAuth` 1) and is checked with it. One with no signature is dropped and counted
262
+ * (`unsigned`).
263
+ * - **An error frame** (`[3][seq][code]`) has no room for an HMAC. It is returned either way,
264
+ * marked `verified` only when it was a member of a signed bundle.
265
+ * - **Control frames** (22, 28, 44, 45, 46) are always their own datagram, signed over their
266
+ * leading bytes.
267
+ *
268
+ * `fleet` is the session's own context ({@link createFleetSignContext}). A datagram above
269
+ * {@link FLEET_MAX_DATAGRAM_BYTES} is malformed.
270
+ */
271
+ export declare function parseFleetDatagram(fleet: RelaySignContext, datagram: Uint8Array, options?: FleetParseOptions): Promise<FleetDatagram>;
272
+ //# sourceMappingURL=fleet-wire.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fleet-wire.d.ts","sourceRoot":"","sources":["../src/fleet-wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAaL,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,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