@tinyburg/pocket-planes-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,264 @@
1
+ /**
2
+ * Pocket Planes 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 `pp` 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(`pp/${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(`pp/${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(`pp/${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 visits (bitizen/plane exchanges) waiting for the player. VERIFIED.
150
+ *
151
+ * @since 1.0.0
152
+ * @category SDK
153
+ */
154
+ export const social_getVisits = Effect.fn("social_getVisits")(function* ({
155
+ playerAuthKey,
156
+ playerId,
157
+ }: Schema.Schema.Type<typeof NimblebitConfig.AuthenticatedPlayerSchema>) {
158
+ const nimblebitAuth = yield* NimblebitAuth.NimblebitAuth;
159
+ const httpClient = yield* HttpClient.HttpClient;
160
+
161
+ const maybeAddBearerToken =
162
+ nimblebitAuth.host !== "https://sync.nimblebit.com"
163
+ ? HttpClientRequest.bearerToken(nimblebitAuth.authKey)
164
+ : Function.identity;
165
+
166
+ const endpoint = yield* HttpApiClient.endpoint(Endpoints.Api, {
167
+ baseUrl: nimblebitAuth.host,
168
+ group: "SocialGroup",
169
+ endpoint: "SocialGetVisits",
170
+ httpClient: HttpClient.mapRequest(httpClient, maybeAddBearerToken),
171
+ });
172
+
173
+ const salt = yield* nimblebitAuth.salt;
174
+ const hash = yield* nimblebitAuth.sign(`pp/${playerId}/${salt}${Redacted.value(playerAuthKey)}`);
175
+ const response = yield* endpoint({ params: { playerId, salt, hash } });
176
+
177
+ if ("error" in response) {
178
+ return yield* new NimblebitError.NimblebitError({
179
+ method: "SocialGetVisits",
180
+ module: "SocialGroup",
181
+ cause: response.error,
182
+ });
183
+ }
184
+ return response;
185
+ });
186
+
187
+ /**
188
+ * Lists gifts waiting for the player. VERIFIED.
189
+ *
190
+ * @since 1.0.0
191
+ * @category SDK
192
+ */
193
+ export const social_getGifts = Effect.fn("social_getGifts")(function* ({
194
+ playerAuthKey,
195
+ playerId,
196
+ }: Schema.Schema.Type<typeof NimblebitConfig.AuthenticatedPlayerSchema>) {
197
+ const nimblebitAuth = yield* NimblebitAuth.NimblebitAuth;
198
+ const httpClient = yield* HttpClient.HttpClient;
199
+
200
+ const maybeAddBearerToken =
201
+ nimblebitAuth.host !== "https://sync.nimblebit.com"
202
+ ? HttpClientRequest.bearerToken(nimblebitAuth.authKey)
203
+ : Function.identity;
204
+
205
+ const endpoint = yield* HttpApiClient.endpoint(Endpoints.Api, {
206
+ baseUrl: nimblebitAuth.host,
207
+ group: "SocialGroup",
208
+ endpoint: "SocialGetGifts",
209
+ httpClient: HttpClient.mapRequest(httpClient, maybeAddBearerToken),
210
+ });
211
+
212
+ const salt = yield* nimblebitAuth.salt;
213
+ const hash = yield* nimblebitAuth.sign(`pp/${playerId}/${salt}${Redacted.value(playerAuthKey)}`);
214
+ const response = yield* endpoint({ params: { playerId, salt, hash } });
215
+
216
+ if ("error" in response) {
217
+ return yield* new NimblebitError.NimblebitError({
218
+ method: "SocialGetGifts",
219
+ module: "SocialGroup",
220
+ cause: response.error,
221
+ });
222
+ }
223
+ return response;
224
+ });
225
+
226
+ /**
227
+ * Lists item requests waiting for the player (Pocket Planes specific;
228
+ * `{ success, gifts }` with no `total`). VERIFIED.
229
+ *
230
+ * @since 1.0.0
231
+ * @category SDK
232
+ */
233
+ export const social_requestItems = Effect.fn("social_requestItems")(function* ({
234
+ playerAuthKey,
235
+ playerId,
236
+ }: Schema.Schema.Type<typeof NimblebitConfig.AuthenticatedPlayerSchema>) {
237
+ const nimblebitAuth = yield* NimblebitAuth.NimblebitAuth;
238
+ const httpClient = yield* HttpClient.HttpClient;
239
+
240
+ const maybeAddBearerToken =
241
+ nimblebitAuth.host !== "https://sync.nimblebit.com"
242
+ ? HttpClientRequest.bearerToken(nimblebitAuth.authKey)
243
+ : Function.identity;
244
+
245
+ const endpoint = yield* HttpApiClient.endpoint(Endpoints.Api, {
246
+ baseUrl: nimblebitAuth.host,
247
+ group: "SocialGroup",
248
+ endpoint: "SocialRequestItems",
249
+ httpClient: HttpClient.mapRequest(httpClient, maybeAddBearerToken),
250
+ });
251
+
252
+ const salt = yield* nimblebitAuth.salt;
253
+ const hash = yield* nimblebitAuth.sign(`pp/${playerId}/${salt}${Redacted.value(playerAuthKey)}`);
254
+ const response = yield* endpoint({ params: { playerId, salt, hash } });
255
+
256
+ if ("error" in response) {
257
+ return yield* new NimblebitError.NimblebitError({
258
+ method: "SocialRequestItems",
259
+ module: "SocialGroup",
260
+ cause: response.error,
261
+ });
262
+ }
263
+ return response;
264
+ });
package/src/Scopes.ts ADDED
@@ -0,0 +1,92 @@
1
+ /**
2
+ * The scopes the Pocket Planes 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 PocketPlanes = defineGame({
18
+ name: "pocketplanes",
19
+ description: "Pocket Planes",
20
+ read: { description: "Everything in Pocket Planes that only looks" },
21
+ write: { description: "Everything in Pocket Planes 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
+ register_email: "Attach an email address to a player",
35
+ verify_device: "Complete a device verification code",
36
+ },
37
+ },
38
+ },
39
+ social: {
40
+ description: "Gifts, visits and friends",
41
+ read: {
42
+ description: "See gifts, visits and friends' games",
43
+ leaves: {
44
+ get_visits: "See who has visited a player",
45
+ get_gifts: "See the gifts waiting for a player",
46
+ request_items: "See the item requests waiting for a player",
47
+ pull_friend_meta: "Fetch metadata about a player's friends",
48
+ pull_friend_game: "Download a friend's game data",
49
+ },
50
+ },
51
+ write: {
52
+ description: "Send and accept gifts and items",
53
+ leaves: {
54
+ send_item: "Send items to another player",
55
+ receive_item: "Accept an item on a player's behalf",
56
+ },
57
+ },
58
+ },
59
+ },
60
+ });
61
+
62
+ /**
63
+ * The game's areas, by name, for annotating endpoints.
64
+ *
65
+ * @since 1.0.0
66
+ * @category Areas
67
+ */
68
+ export const { device: Device, social: Social } = PocketPlanes.areas;
69
+
70
+ /**
71
+ * @since 1.0.0
72
+ * @category Tree
73
+ */
74
+ export const Games: ReadonlyArray<Game> = [PocketPlanes];
75
+
76
+ /**
77
+ * @since 1.0.0
78
+ * @category Tree
79
+ */
80
+ export const all = (): ReadonlyArray<ScopeDescription> =>
81
+ Games.flatMap((game) => [
82
+ game,
83
+ game.read,
84
+ game.write,
85
+ ...Object.values(game.areas).flatMap((area) => [
86
+ area,
87
+ area.read,
88
+ ...area.read.children,
89
+ area.write,
90
+ ...area.write.children,
91
+ ]),
92
+ ]);
package/src/index.ts ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+
5
+ /**
6
+ * Pocket Planes (game code `pp`) NBSync api endpoints.
7
+ *
8
+ * Signing: a random `salt` (signed int32 - the game emits negatives too) goes
9
+ * in the path, and `hash` is `md5(<preimage> + <game secret salt>)` where the
10
+ * preimage is `pp/<playerId>/<salt><playerAuthKey>` (variants noted per
11
+ * endpoint). The secret salt is the value extracted from `NBSync._ss`.
12
+ *
13
+ * Verification (against the live server + Frida inspection of the game,
14
+ * 2026-08-26):
15
+ * - Signing is MD5, VERIFIED server-side: `player_details` accepts the MD5 hash
16
+ * and rejects a garbage hash, no hash, and a SHA-256 hash. (The game itself
17
+ * computes SHA-256 in `NBSync.genHash` for the unauthenticated `register`
18
+ * call, which the server also accepts via MD5 - so it does not affect the
19
+ * authenticated endpoints this SDK signs.)
20
+ * - Response envelopes VERIFIED by reading the game's DTO classes at runtime
21
+ * (immune to the metadata obfuscation): register (NBSyncRegisterResponse),
22
+ * player_details (NBSyncPlayerDetailsResponse), sync/pull
23
+ * (NBSyncGameSaveResponse: success/h/id/data), current_version
24
+ * (NBSyncCurrentCheckResponse), verify_device (NBSyncVerifyCodeResponse:
25
+ * success/player_id/player_ss/player_email - no photo/nickname on pp),
26
+ * get_visits/get_gifts (NBSyncItemsGetResponse), send_item
27
+ * (NBSyncItemsSendResponse), receive_item (NBSyncItemsReceiveResponse: also
28
+ * carries an `id`), friend/pull_game (NBSyncFriendGameSaveResponse),
29
+ * friend/pull_meta (NBSyncFriendGameMetaResponse). register/player_details/
30
+ * get_visits/get_gifts/request_items were also exercised live with a burnbot.
31
+ * - Still open: pp appears to have NO snapshots (`sync/current_snapshots`
32
+ * returns Invalid Request), so `pull_snapshot` here is unconfirmed and may
33
+ * not exist. register_email is DERIVED from Tiny Tower.
34
+ *
35
+ * Game-specific payload/item schemas (the `gifts` element - real shape is
36
+ * NBSyncItemsGift {gift_id, gift_to, gift_from, gift_type, item_type, gift_str,
37
+ * h, c} - friend meta, save push meta) are `Schema.Unknown` placeholders for
38
+ * the data-schema work.
39
+ *
40
+ * @since 1.0.0
41
+ * @category Endpoints
42
+ */
43
+ export * as Endpoints from "./Endpoints.ts"
44
+
45
+ /**
46
+ * Pocket Planes SDK: signed calls against Nimblebit's NBSync service.
47
+ *
48
+ * Signing reuses `@tinyburg/nimblebit-sdk` (`NimblebitAuth`): the game secret
49
+ * salt (from `NBSync._ss`) is provided as the auth key, and each request is
50
+ * `md5(<preimage> + <secret salt>)` with a random uint32 `salt` in the path.
51
+ * All method preimages below are the Tiny Tower formula with the `pp` game code.
52
+ *
53
+ * The methods that were exercised live against sync.nimblebit.com are marked
54
+ * VERIFIED; save-bearing / write paths follow the same pattern but were not
55
+ * exercised. Save bytes are returned raw (base64-decoded); inflating (pako) and
56
+ * parsing into a save schema is left to the caller.
57
+ *
58
+ * @since 1.0.0
59
+ * @category SDK
60
+ */
61
+ export * as PocketPlanes from "./PocketPlanes.ts"
62
+
63
+ /**
64
+ * The scopes the Pocket Planes api is guarded by, as a game-rooted tree, built with
65
+ * `@tinyburg/nimblebit-sdk`'s `defineGame`. Only the endpoints this sdk defines
66
+ * are covered; areas without both a read and a write side are left out until
67
+ * their endpoints exist.
68
+ *
69
+ * @since 1.0.0
70
+ * @category Scopes
71
+ */
72
+ export * as Scopes from "./Scopes.ts"