@tinyburg/tinytower-vegas-sdk 0.0.0-stage → 0.1.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.
@@ -0,0 +1,361 @@
1
+ /**
2
+ * Tiny Tower Vegas (game code `vegas`) NBSync api endpoints.
3
+ *
4
+ * Signing: a random `salt` (signed int32) goes in the path, and `hash` is
5
+ * `md5(<preimage> + <game secret salt>)` with the preimage
6
+ * `vegas/<playerId>/<salt><playerAuthKey>` (variants noted per endpoint). The
7
+ * secret salt is the value extracted from `NBSync._ss`.
8
+ *
9
+ * Verification (live server + Frida DTO inspection of the game, 2026-08-26):
10
+ * - Signing is MD5, server-validated (same scheme as Tiny Tower / Pocket
11
+ * Planes; the game computes SHA-256 only for the unauthenticated `register`).
12
+ * - Response envelopes VERIFIED by reading the game's DTO classes at runtime:
13
+ * register, player_details, sync/pull (NBSyncGameSaveResponse), current_version,
14
+ * verify_device, friend/pull_game, friend/pull_meta (meta is a flat
15
+ * Dictionary<String,Object> on pt), send_item (NBSyncItemsSendResponse),
16
+ * get_items (NBSyncItemsGetResponse: success/gifts, NO `total` unlike pp).
17
+ * `get_items` was also exercised live with a burnbot.
18
+ * - Standard NBSync endpoint set plus get_visits and receive_item.
19
+ *
20
+ * Game-specific save/meta schemas are left as `Schema.Unknown` placeholders.
21
+ *
22
+ * @since 1.0.0
23
+ * @category Endpoints
24
+ */
25
+
26
+ import { HttpApi, HttpApiEndpoint, HttpApiError, HttpApiGroup } from "effect/http-api";
27
+ import * as Schema from "effect/Schema";
28
+
29
+ import * as NimblebitConfig from "@tinyburg/nimblebit-sdk/NimblebitConfig";
30
+ import * as OAuthScope from "@yielded/auth/OAuthScope";
31
+
32
+ import * as Scopes from "./Scopes.ts";
33
+
34
+ /** @internal */
35
+ export const U32 = Schema.Int.check(Schema.isUint32());
36
+
37
+ /** @internal */
38
+ export const ApiErrors = [
39
+ HttpApiError.Forbidden,
40
+ HttpApiError.BadRequest,
41
+ HttpApiError.Unauthorized,
42
+ HttpApiError.InternalServerError,
43
+ ] as const;
44
+
45
+ /** @internal */
46
+ export const ErrorResponse = Schema.Struct({ error: Schema.String });
47
+
48
+ /** @internal */
49
+ export const NotFoundResponse = Schema.Struct({ success: Schema.Literal("NotFound") });
50
+
51
+ /** @internal */
52
+ export const SentResponse = Schema.Struct({ success: Schema.Literal("Sent") });
53
+
54
+ /** @internal */
55
+ export const NotSentResponse = Schema.Struct({ success: Schema.Literal("NotSent") });
56
+
57
+ /**
58
+ * A gift/item in the general item channel (get_items / send_item). Verified DTO
59
+ * NBSyncItemsGift on pt: `{gift_id, gift_to, gift_from, gift_type, item_type,
60
+ * gift_str, h}` (no `c`, unlike pp). Left open for the data-schema work.
61
+ *
62
+ * @since 1.0.0
63
+ * @category Schemas
64
+ */
65
+ export const Gift = Schema.Unknown;
66
+
67
+ /** @internal */
68
+ export const DeviceNewPlayerEndpoint = HttpApiEndpoint.get("DeviceNewPlayer", "/register/vegas/:salt1/:salt2/:hash", {
69
+ params: { salt1: U32, salt2: U32, hash: Schema.String },
70
+ error: ApiErrors,
71
+ success: [
72
+ ErrorResponse,
73
+ Schema.Struct({
74
+ playerId: NimblebitConfig.PlayerIdSchema,
75
+ playerSs: NimblebitConfig.PlayerAuthKeySchema,
76
+ }).pipe(Schema.encodeKeys({ playerId: "player_id", playerSs: "player_ss" })),
77
+ ],
78
+ });
79
+
80
+ /** @internal */
81
+ export const DevicePlayerDetailsEndpoint = HttpApiEndpoint.get(
82
+ "DevicePlayerDetails",
83
+ "/player_details/vegas/:playerId/:salt/:hash",
84
+ {
85
+ params: { playerId: NimblebitConfig.PlayerIdSchema, salt: U32, hash: Schema.String },
86
+ error: ApiErrors,
87
+ success: [
88
+ ErrorResponse,
89
+ Schema.Struct({
90
+ success: Schema.Literal("Found"),
91
+ player: Schema.Struct({
92
+ playerId: NimblebitConfig.PlayerIdSchema,
93
+ playerEmail: NimblebitConfig.PlayerEmailSchema,
94
+ registered: Schema.NumberFromString.pipe(Schema.decodeTo(Schema.BooleanFromBit)),
95
+ blacklisted: Schema.NumberFromString.pipe(Schema.decodeTo(Schema.BooleanFromBit)),
96
+ saveVersion: Schema.NumberFromString.pipe(Schema.decodeTo(Schema.Int)),
97
+ checksum: Schema.String,
98
+ }).pipe(Schema.encodeKeys({ playerId: "player_id", playerEmail: "email", checksum: "h" })),
99
+ }),
100
+ ],
101
+ }
102
+ ).annotate(OAuthScope.Required, Scopes.Device.read.player_details.required);
103
+
104
+ /** @internal */
105
+ export const DeviceVerifyDeviceEndpoint = HttpApiEndpoint.get(
106
+ "DeviceVerifyDevice",
107
+ "/verify_device/vegas/:playerId/:verificationCode",
108
+ {
109
+ params: { playerId: NimblebitConfig.PlayerIdSchema, verificationCode: Schema.String },
110
+ error: ApiErrors,
111
+ success: [
112
+ ErrorResponse,
113
+ Schema.Struct({
114
+ success: Schema.Literal("NewDevice"),
115
+ playerId: NimblebitConfig.PlayerIdSchema,
116
+ playerAuthKey: NimblebitConfig.PlayerAuthKeySchema,
117
+ playerEmail: NimblebitConfig.PlayerEmailSchema,
118
+ }).pipe(
119
+ Schema.encodeKeys({ playerId: "player_id", playerAuthKey: "player_ss", playerEmail: "player_email" })
120
+ ),
121
+ ],
122
+ }
123
+ ).annotate(OAuthScope.Required, Scopes.Device.write.verify_device.required);
124
+
125
+ /**
126
+ * Pull the player's cloud save. VERIFIED envelope (NBSyncGameSaveResponse). No-save
127
+ * case returns `{ error: "SaveNotFound" }`. `data` is base64 pako-deflated bytes.
128
+ *
129
+ * @internal
130
+ */
131
+ export const SyncPullSaveEndpoint = HttpApiEndpoint.get("SyncPullSave", "/sync/pull/vegas/:playerId/:salt/:hash", {
132
+ params: { playerId: NimblebitConfig.PlayerIdSchema, salt: U32, hash: Schema.String },
133
+ error: ApiErrors,
134
+ success: [
135
+ ErrorResponse,
136
+ NotFoundResponse,
137
+ Schema.Struct({
138
+ success: Schema.Literal("Found"),
139
+ data: Schema.Uint8ArrayFromBase64,
140
+ checksum: Schema.String,
141
+ saveId: Schema.NumberFromString,
142
+ }).pipe(Schema.encodeKeys({ checksum: "h", saveId: "id" })),
143
+ ],
144
+ });
145
+
146
+ /**
147
+ * VERIFIED envelope (NBSyncCurrentCheckResponse); no-save returns `{ error: "NoSave" }`.
148
+ *
149
+ * @internal
150
+ */
151
+ export const SyncCheckForNewerSaveEndpoint = HttpApiEndpoint.get(
152
+ "SyncCheckForNewerSave",
153
+ "/sync/current_version/vegas/:playerId/:salt/:hash",
154
+ {
155
+ params: { playerId: NimblebitConfig.PlayerIdSchema, salt: U32, hash: Schema.String },
156
+ error: ApiErrors,
157
+ success: [
158
+ ErrorResponse,
159
+ NotFoundResponse,
160
+ Schema.Struct({
161
+ success: Schema.Literal("Found"),
162
+ checksum: Schema.String,
163
+ saveId: Schema.NumberFromString,
164
+ }).pipe(Schema.encodeKeys({ checksum: "h", saveId: "id" })),
165
+ ],
166
+ }
167
+ );
168
+
169
+ /**
170
+ * VERIFIED live: `/get_items/vegas/:playerId/:salt/:hash` -> `{ success:"Found",
171
+ * gifts:[...] }` (NBSyncItemsGetResponse; no `total` on pt).
172
+ *
173
+ * @internal
174
+ */
175
+ export const SocialGetItemsEndpoint = HttpApiEndpoint.get("SocialGetItems", "/get_items/vegas/:playerId/:salt/:hash", {
176
+ params: { playerId: NimblebitConfig.PlayerIdSchema, salt: U32, hash: Schema.String },
177
+ error: ApiErrors,
178
+ success: [
179
+ ErrorResponse,
180
+ NotFoundResponse,
181
+ Schema.Struct({ success: Schema.Literal("Found"), gifts: Schema.Array(Gift) }),
182
+ ],
183
+ }).annotate(OAuthScope.Required, Scopes.Social.read.get_items.required);
184
+
185
+ /**
186
+ * DERIVED from Tiny Tower. Sends an item to a friend. Response VERIFIED
187
+ * (NBSyncItemsSendResponse: success/error). pt also has a `/send_pt/` variant.
188
+ *
189
+ * @internal
190
+ */
191
+ export const SocialSendItemEndpoint = HttpApiEndpoint.post(
192
+ "SocialSendItem",
193
+ "/send_item/vegas/:itemType/:playerId/:friendId/:salt/:hash",
194
+ {
195
+ params: {
196
+ itemType: Schema.String,
197
+ playerId: NimblebitConfig.PlayerIdSchema,
198
+ friendId: NimblebitConfig.PlayerIdSchema,
199
+ salt: U32,
200
+ hash: Schema.String,
201
+ },
202
+ payload: Schema.Struct({ itemStr: Schema.String }),
203
+ error: ApiErrors,
204
+ success: [ErrorResponse, SentResponse, NotSentResponse],
205
+ }
206
+ ).annotate(OAuthScope.Required, Scopes.Social.write.send_item.required);
207
+
208
+ /**
209
+ * VERIFIED envelope (NBSyncFriendGameSaveResponse); preimage
210
+ * `vegas/<playerId>/<friendId>/<salt><playerAuthKey>`.
211
+ *
212
+ * @internal
213
+ */
214
+ export const SocialPullFriendGameEndpoint = HttpApiEndpoint.get(
215
+ "SocialPullFriendGame",
216
+ "/friend/pull_game/vegas/:playerId/:friendId/:salt/:hash",
217
+ {
218
+ params: {
219
+ playerId: NimblebitConfig.PlayerIdSchema,
220
+ friendId: NimblebitConfig.PlayerIdSchema,
221
+ salt: U32,
222
+ hash: Schema.String,
223
+ },
224
+ error: ApiErrors,
225
+ success: [
226
+ ErrorResponse,
227
+ NotFoundResponse,
228
+ Schema.Struct({
229
+ success: Schema.Literal("Found"),
230
+ data: Schema.Uint8ArrayFromBase64,
231
+ checksum: Schema.String,
232
+ saveId: Schema.NumberFromString,
233
+ playerId: NimblebitConfig.PlayerIdSchema,
234
+ }).pipe(Schema.encodeKeys({ checksum: "h", saveId: "id", playerId: "player_id" })),
235
+ ],
236
+ }
237
+ ).annotate(OAuthScope.Required, Scopes.Social.read.pull_friend_game.required);
238
+
239
+ /**
240
+ * VERIFIED envelope (NBSyncFriendGameMetaResponse; `meta` is a flat
241
+ * Dictionary<String,Object> on pt). Preimage `vegas/<playerId>/<salt><friendId><playerAuthKey>`.
242
+ *
243
+ * @internal
244
+ */
245
+ export const SocialPullFriendMetaEndpoint = HttpApiEndpoint.post(
246
+ "SocialPullFriendMeta",
247
+ "/friend/pull_meta/vegas/:playerId/:salt/:hash",
248
+ {
249
+ params: { playerId: NimblebitConfig.PlayerIdSchema, salt: U32, hash: Schema.String },
250
+ payload: Schema.Struct({ friends: NimblebitConfig.PlayerIdSchema }),
251
+ error: ApiErrors,
252
+ success: [
253
+ ErrorResponse,
254
+ NotFoundResponse,
255
+ Schema.Struct({
256
+ success: Schema.Literal("Found"),
257
+ meta: Schema.Record(NimblebitConfig.PlayerIdSchema, Schema.Unknown),
258
+ }),
259
+ ],
260
+ }
261
+ ).annotate(OAuthScope.Required, Scopes.Social.read.pull_friend_meta.required);
262
+
263
+ /**
264
+ * VERIFIED path: `/get_visits/vegas/:playerId/:salt/:hash`. Same envelope as get_items.
265
+ *
266
+ * @internal
267
+ */
268
+ export const SocialGetVisitsEndpoint = HttpApiEndpoint.get(
269
+ "SocialGetVisits",
270
+ "/get_visits/vegas/:playerId/:salt/:hash",
271
+ {
272
+ params: { playerId: NimblebitConfig.PlayerIdSchema, salt: U32, hash: Schema.String },
273
+ error: ApiErrors,
274
+ success: [
275
+ ErrorResponse,
276
+ NotFoundResponse,
277
+ Schema.Struct({ success: Schema.Literal("Found"), gifts: Schema.Array(Gift) }),
278
+ ],
279
+ }
280
+ ).annotate(OAuthScope.Required, Scopes.Social.read.get_visits.required);
281
+
282
+ /**
283
+ * Preimage `vegas/<playerId>/<giftId>/<salt><playerAuthKey>`. Response DTO
284
+ * NBSyncItemsReceiveResponse (success/error/id).
285
+ *
286
+ * @internal
287
+ */
288
+ export const SocialReceiveItemEndpoint = HttpApiEndpoint.get(
289
+ "SocialReceiveItem",
290
+ "/receive_item/vegas/:playerId/:giftId/:salt/:hash",
291
+ {
292
+ params: { playerId: NimblebitConfig.PlayerIdSchema, giftId: Schema.Int, salt: U32, hash: Schema.String },
293
+ error: ApiErrors,
294
+ success: [
295
+ ErrorResponse,
296
+ Schema.Struct({ success: Schema.Literal("Received"), id: Schema.optionalKey(Schema.String) }),
297
+ Schema.Struct({ success: Schema.Literal("NotReceived") }),
298
+ ],
299
+ }
300
+ ).annotate(OAuthScope.Required, Scopes.Social.write.receive_item.required);
301
+
302
+ /**
303
+ * Snapshot list. Vegas exposes `/sync/current_snapshots/` (and a friend variant).
304
+ * Envelope follows the Tiny Tower snapshot list shape.
305
+ *
306
+ * @internal
307
+ */
308
+ export const SyncRetrieveSnapshotListEndpoint = HttpApiEndpoint.get(
309
+ "SyncRetrieveSnapshotList",
310
+ "/sync/current_snapshots/vegas/:playerId/:salt/:hash",
311
+ {
312
+ params: { playerId: NimblebitConfig.PlayerIdSchema, salt: U32, hash: Schema.String },
313
+ error: ApiErrors,
314
+ success: [
315
+ ErrorResponse,
316
+ NotFoundResponse,
317
+ Schema.Struct({
318
+ success: Schema.Literal("Found"),
319
+ saves: Schema.Array(
320
+ Schema.Struct({
321
+ id: Schema.Int,
322
+ created: Schema.Int,
323
+ meta: Schema.Record(Schema.String, Schema.Unknown),
324
+ })
325
+ ),
326
+ }),
327
+ ],
328
+ }
329
+ );
330
+
331
+ /** @internal */
332
+ export const DeviceManagementGroup = HttpApiGroup.make("DeviceManagementGroup")
333
+ .add(DeviceNewPlayerEndpoint)
334
+ .add(DevicePlayerDetailsEndpoint)
335
+ .add(DeviceVerifyDeviceEndpoint);
336
+
337
+ /** @internal */
338
+ export const SyncManagementGroup = HttpApiGroup.make("SyncManagementGroup")
339
+ .add(SyncPullSaveEndpoint)
340
+ .add(SyncCheckForNewerSaveEndpoint)
341
+ .add(SyncRetrieveSnapshotListEndpoint);
342
+
343
+ /** @internal */
344
+ export const SocialGroup = HttpApiGroup.make("SocialGroup")
345
+ .add(SocialGetItemsEndpoint)
346
+ .add(SocialGetVisitsEndpoint)
347
+ .add(SocialReceiveItemEndpoint)
348
+ .add(SocialSendItemEndpoint)
349
+ .add(SocialPullFriendGameEndpoint)
350
+ .add(SocialPullFriendMetaEndpoint);
351
+
352
+ /**
353
+ * The Tiny Tower Vegas NBSync api.
354
+ *
355
+ * @since 1.0.0
356
+ * @category Api
357
+ */
358
+ export const Api = HttpApi.make("TinyTowerVegasApi")
359
+ .add(DeviceManagementGroup)
360
+ .add(SyncManagementGroup)
361
+ .add(SocialGroup);
package/src/Scopes.ts ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * The scopes the Tiny Tower Vegas api is guarded by, as a game-rooted tree, built with
3
+ * `@tinyburg/nimblebit-sdk`'s `defineGame`. Only the endpoints this sdk defines
4
+ * are covered; areas without both a read and a write side are left out until
5
+ * their endpoints exist.
6
+ *
7
+ * @since 1.0.0
8
+ * @category Scopes
9
+ */
10
+
11
+ import { type Game, type ScopeDescription, defineGame } from "@tinyburg/nimblebit-sdk/NimblebitScopes";
12
+
13
+ /**
14
+ * @since 1.0.0
15
+ * @category Games
16
+ */
17
+ export const TinyTowerVegas = defineGame({
18
+ name: "tinytowervegas",
19
+ description: "Tiny Tower Vegas",
20
+ read: { description: "Everything in Tiny Tower Vegas that only looks" },
21
+ write: { description: "Everything in Tiny Tower Vegas that changes a player's game" },
22
+ areas: {
23
+ device: {
24
+ description: "Player accounts and their devices",
25
+ read: {
26
+ description: "Look up player accounts",
27
+ leaves: {
28
+ player_details: "Look up a player's public profile details",
29
+ },
30
+ },
31
+ write: {
32
+ description: "Change a player's account or devices",
33
+ leaves: {
34
+ verify_device: "Complete a device verification code",
35
+ },
36
+ },
37
+ },
38
+ social: {
39
+ description: "Gifts, visits and friends",
40
+ read: {
41
+ description: "See gifts, visits and friends' games",
42
+ leaves: {
43
+ get_items: "See the items waiting for a player",
44
+ get_visits: "See who has visited a player",
45
+ pull_friend_game: "Download a friend's game data",
46
+ pull_friend_meta: "Fetch metadata about a player's friends",
47
+ },
48
+ },
49
+ write: {
50
+ description: "Send and accept gifts and items",
51
+ leaves: {
52
+ send_item: "Send items to another player",
53
+ receive_item: "Accept an item on a player's behalf",
54
+ },
55
+ },
56
+ },
57
+ },
58
+ });
59
+
60
+ /**
61
+ * The game's areas, by name, for annotating endpoints.
62
+ *
63
+ * @since 1.0.0
64
+ * @category Areas
65
+ */
66
+ export const { device: Device, social: Social } = TinyTowerVegas.areas;
67
+
68
+ /**
69
+ * @since 1.0.0
70
+ * @category Tree
71
+ */
72
+ export const Games: ReadonlyArray<Game> = [TinyTowerVegas];
73
+
74
+ /**
75
+ * @since 1.0.0
76
+ * @category Tree
77
+ */
78
+ export const all = (): ReadonlyArray<ScopeDescription> =>
79
+ Games.flatMap((game) => [
80
+ game,
81
+ game.read,
82
+ game.write,
83
+ ...Object.values(game.areas).flatMap((area) => [
84
+ area,
85
+ area.read,
86
+ ...area.read.children,
87
+ area.write,
88
+ ...area.write.children,
89
+ ]),
90
+ ]);
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Tiny Tower Vegas SDK: signed calls against Nimblebit's NBSync service.
3
+ *
4
+ * Signing reuses `@tinyburg/nimblebit-sdk` (`NimblebitAuth`): the game secret
5
+ * salt (from `NBSync._ss`) is provided as the auth key, and each request is
6
+ * `md5(<preimage> + <secret salt>)` with a random uint32 `salt` in the path.
7
+ * All method preimages below are the Tiny Tower formula with the `vegas` game code.
8
+ *
9
+ * The methods that were exercised live against sync.nimblebit.com are marked
10
+ * VERIFIED; save-bearing / write paths follow the same pattern but were not
11
+ * exercised. Save bytes are returned raw (base64-decoded); inflating (pako) and
12
+ * parsing into a save schema is left to the caller.
13
+ *
14
+ * @since 1.0.0
15
+ * @category SDK
16
+ */
17
+
18
+ import type * as Schema from "effect/Schema";
19
+
20
+ import * as Effect from "effect/Effect";
21
+ import * as Function from "effect/Function";
22
+ import { HttpClient, HttpClientRequest } from "effect/http";
23
+ import { HttpApiClient } from "effect/http-api";
24
+ import * as Redacted from "effect/Redacted";
25
+
26
+ import type { NimblebitConfig } from "@tinyburg/nimblebit-sdk";
27
+
28
+ import { NimblebitAuth, NimblebitError } from "@tinyburg/nimblebit-sdk";
29
+
30
+ import * as Endpoints from "./Endpoints.ts";
31
+
32
+ /**
33
+ * Requests a new player ("burnbot") from the Nimblebit servers. VERIFIED.
34
+ *
35
+ * @since 1.0.0
36
+ * @category SDK
37
+ */
38
+ export const device_newPlayer = Effect.gen(function* () {
39
+ const nimblebitAuth = yield* NimblebitAuth.NimblebitAuth;
40
+ const httpClient = yield* HttpClient.HttpClient;
41
+
42
+ const maybeAddBearerToken =
43
+ nimblebitAuth.host !== "https://sync.nimblebit.com"
44
+ ? HttpClientRequest.bearerToken(nimblebitAuth.authKey)
45
+ : Function.identity;
46
+
47
+ const endpoint = yield* HttpApiClient.endpoint(Endpoints.Api, {
48
+ baseUrl: nimblebitAuth.host,
49
+ group: "DeviceManagementGroup",
50
+ endpoint: "DeviceNewPlayer",
51
+ httpClient: HttpClient.mapRequest(httpClient, maybeAddBearerToken),
52
+ });
53
+
54
+ const salt1 = yield* nimblebitAuth.salt;
55
+ const salt2 = yield* nimblebitAuth.salt;
56
+ const hash = yield* nimblebitAuth.sign(`vegas/${salt1}/${salt2}`);
57
+ const response = yield* endpoint({ params: { salt1, salt2, hash } });
58
+
59
+ if ("error" in response) {
60
+ return yield* new NimblebitError.NimblebitError({
61
+ method: "DeviceNewPlayer",
62
+ module: "DeviceManagementGroup",
63
+ cause: response.error,
64
+ });
65
+ }
66
+ return response;
67
+ });
68
+
69
+ /**
70
+ * Retrieves player details. VERIFIED.
71
+ *
72
+ * @since 1.0.0
73
+ * @category SDK
74
+ */
75
+ export const device_playerDetails = Effect.fn("device_playerDetails")(function* ({
76
+ playerAuthKey,
77
+ playerId,
78
+ }: Schema.Schema.Type<typeof NimblebitConfig.AuthenticatedPlayerSchema>) {
79
+ const nimblebitAuth = yield* NimblebitAuth.NimblebitAuth;
80
+ const httpClient = yield* HttpClient.HttpClient;
81
+
82
+ const maybeAddBearerToken =
83
+ nimblebitAuth.host !== "https://sync.nimblebit.com"
84
+ ? HttpClientRequest.bearerToken(nimblebitAuth.authKey)
85
+ : Function.identity;
86
+
87
+ const endpoint = yield* HttpApiClient.endpoint(Endpoints.Api, {
88
+ baseUrl: nimblebitAuth.host,
89
+ group: "DeviceManagementGroup",
90
+ endpoint: "DevicePlayerDetails",
91
+ httpClient: HttpClient.mapRequest(httpClient, maybeAddBearerToken),
92
+ });
93
+
94
+ const salt = yield* nimblebitAuth.salt;
95
+ const hash = yield* nimblebitAuth.sign(`vegas/${playerId}/${salt}${Redacted.value(playerAuthKey)}`);
96
+ const response = yield* endpoint({ params: { playerId, salt, hash } });
97
+
98
+ if ("error" in response) {
99
+ return yield* new NimblebitError.NimblebitError({
100
+ method: "DevicePlayerDetails",
101
+ module: "DeviceManagementGroup",
102
+ cause: response.error,
103
+ });
104
+ }
105
+ return response.player;
106
+ });
107
+
108
+ /**
109
+ * Pulls the player's cloud save. Returns raw base64-decoded bytes (inflate +
110
+ * parse separately). Success envelope DERIVED from Tiny Tower.
111
+ *
112
+ * @since 1.0.0
113
+ * @category SDK
114
+ */
115
+ export const sync_pullSave = Effect.fn("sync_pullSave")(function* ({
116
+ playerAuthKey,
117
+ playerId,
118
+ }: Schema.Schema.Type<typeof NimblebitConfig.AuthenticatedPlayerSchema>) {
119
+ const nimblebitAuth = yield* NimblebitAuth.NimblebitAuth;
120
+ const httpClient = yield* HttpClient.HttpClient;
121
+
122
+ const maybeAddBearerToken =
123
+ nimblebitAuth.host !== "https://sync.nimblebit.com"
124
+ ? HttpClientRequest.bearerToken(nimblebitAuth.authKey)
125
+ : Function.identity;
126
+
127
+ const endpoint = yield* HttpApiClient.endpoint(Endpoints.Api, {
128
+ baseUrl: nimblebitAuth.host,
129
+ group: "SyncManagementGroup",
130
+ endpoint: "SyncPullSave",
131
+ httpClient: HttpClient.mapRequest(httpClient, maybeAddBearerToken),
132
+ });
133
+
134
+ const salt = yield* nimblebitAuth.salt;
135
+ const hash = yield* nimblebitAuth.sign(`vegas/${playerId}/${salt}${Redacted.value(playerAuthKey)}`);
136
+ const response = yield* endpoint({ params: { playerId, salt, hash } });
137
+
138
+ if ("error" in response) {
139
+ return yield* new NimblebitError.NimblebitError({
140
+ method: "SyncPullSave",
141
+ module: "SyncManagementGroup",
142
+ cause: response.error,
143
+ });
144
+ }
145
+ return response;
146
+ });
147
+
148
+ /**
149
+ * Lists items (parts/gifts) waiting for the player. VERIFIED
150
+ * (`/get_items/pt/...` -> `{ success:"Found", gifts:[...] }`, no total).
151
+ *
152
+ * @since 1.0.0
153
+ * @category SDK
154
+ */
155
+ export const social_getItems = Effect.fn("social_getItems")(function* ({
156
+ playerAuthKey,
157
+ playerId,
158
+ }: Schema.Schema.Type<typeof NimblebitConfig.AuthenticatedPlayerSchema>) {
159
+ const nimblebitAuth = yield* NimblebitAuth.NimblebitAuth;
160
+ const httpClient = yield* HttpClient.HttpClient;
161
+
162
+ const maybeAddBearerToken =
163
+ nimblebitAuth.host !== "https://sync.nimblebit.com"
164
+ ? HttpClientRequest.bearerToken(nimblebitAuth.authKey)
165
+ : Function.identity;
166
+
167
+ const endpoint = yield* HttpApiClient.endpoint(Endpoints.Api, {
168
+ baseUrl: nimblebitAuth.host,
169
+ group: "SocialGroup",
170
+ endpoint: "SocialGetItems",
171
+ httpClient: HttpClient.mapRequest(httpClient, maybeAddBearerToken),
172
+ });
173
+
174
+ const salt = yield* nimblebitAuth.salt;
175
+ const hash = yield* nimblebitAuth.sign(`vegas/${playerId}/${salt}${Redacted.value(playerAuthKey)}`);
176
+ const response = yield* endpoint({ params: { playerId, salt, hash } });
177
+
178
+ if ("error" in response) {
179
+ return yield* new NimblebitError.NimblebitError({
180
+ method: "SocialGetItems",
181
+ module: "SocialGroup",
182
+ cause: response.error,
183
+ });
184
+ }
185
+ return response;
186
+ });
package/src/index.ts ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+
5
+ /**
6
+ * Tiny Tower Vegas (game code `vegas`) NBSync api endpoints.
7
+ *
8
+ * Signing: a random `salt` (signed int32) goes in the path, and `hash` is
9
+ * `md5(<preimage> + <game secret salt>)` with the preimage
10
+ * `vegas/<playerId>/<salt><playerAuthKey>` (variants noted per endpoint). The
11
+ * secret salt is the value extracted from `NBSync._ss`.
12
+ *
13
+ * Verification (live server + Frida DTO inspection of the game, 2026-08-26):
14
+ * - Signing is MD5, server-validated (same scheme as Tiny Tower / Pocket
15
+ * Planes; the game computes SHA-256 only for the unauthenticated `register`).
16
+ * - Response envelopes VERIFIED by reading the game's DTO classes at runtime:
17
+ * register, player_details, sync/pull (NBSyncGameSaveResponse), current_version,
18
+ * verify_device, friend/pull_game, friend/pull_meta (meta is a flat
19
+ * Dictionary<String,Object> on pt), send_item (NBSyncItemsSendResponse),
20
+ * get_items (NBSyncItemsGetResponse: success/gifts, NO `total` unlike pp).
21
+ * `get_items` was also exercised live with a burnbot.
22
+ * - Standard NBSync endpoint set plus get_visits and receive_item.
23
+ *
24
+ * Game-specific save/meta schemas are left as `Schema.Unknown` placeholders.
25
+ *
26
+ * @since 1.0.0
27
+ * @category Endpoints
28
+ */
29
+ export * as Endpoints from "./Endpoints.ts"
30
+
31
+ /**
32
+ * The scopes the Tiny Tower Vegas api is guarded by, as a game-rooted tree, built with
33
+ * `@tinyburg/nimblebit-sdk`'s `defineGame`. Only the endpoints this sdk defines
34
+ * are covered; areas without both a read and a write side are left out until
35
+ * their endpoints exist.
36
+ *
37
+ * @since 1.0.0
38
+ * @category Scopes
39
+ */
40
+ export * as Scopes from "./Scopes.ts"
41
+
42
+ /**
43
+ * Tiny Tower Vegas SDK: signed calls against Nimblebit's NBSync service.
44
+ *
45
+ * Signing reuses `@tinyburg/nimblebit-sdk` (`NimblebitAuth`): the game secret
46
+ * salt (from `NBSync._ss`) is provided as the auth key, and each request is
47
+ * `md5(<preimage> + <secret salt>)` with a random uint32 `salt` in the path.
48
+ * All method preimages below are the Tiny Tower formula with the `vegas` game code.
49
+ *
50
+ * The methods that were exercised live against sync.nimblebit.com are marked
51
+ * VERIFIED; save-bearing / write paths follow the same pattern but were not
52
+ * exercised. Save bytes are returned raw (base64-decoded); inflating (pako) and
53
+ * parsing into a save schema is left to the caller.
54
+ *
55
+ * @since 1.0.0
56
+ * @category SDK
57
+ */
58
+ export * as TinyTowerVegas from "./TinyTowerVegas.ts"