@tinyburg/disco-zoo-sdk 0.0.0-stage → 0.1.0
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.
- package/LICENSE +674 -0
- package/README.md +8 -2
- package/dist/DiscoZoo.d.ts +83 -0
- package/dist/DiscoZoo.d.ts.map +1 -0
- package/dist/DiscoZoo.js +172 -0
- package/dist/DiscoZoo.js.map +1 -0
- package/dist/Endpoints.d.ts +200 -0
- package/dist/Endpoints.d.ts.map +1 -0
- package/dist/Endpoints.js +297 -0
- package/dist/Endpoints.js.map +1 -0
- package/dist/Scopes.d.ts +74 -0
- package/dist/Scopes.d.ts.map +1 -0
- package/dist/Scopes.js +81 -0
- package/dist/Scopes.js.map +1 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -3
- package/src/DiscoZoo.ts +186 -0
- package/src/Endpoints.ts +324 -0
- package/src/Scopes.ts +90 -0
- package/src/index.ts +58 -0
package/src/DiscoZoo.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disco Zoo 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 `dz` 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(`dz/${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(`dz/${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(`dz/${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(`dz/${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/Endpoints.ts
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disco Zoo (game code `dz`) 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
|
+
* `dz/<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/dz/: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/dz/: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/dz/: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/dz/: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/dz/: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/dz/: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/dz/: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/dz/: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
|
+
* `dz/<playerId>/<friendId>/<salt><playerAuthKey>`.
|
|
211
|
+
*
|
|
212
|
+
* @internal
|
|
213
|
+
*/
|
|
214
|
+
export const SocialPullFriendGameEndpoint = HttpApiEndpoint.get(
|
|
215
|
+
"SocialPullFriendGame",
|
|
216
|
+
"/friend/pull_game/dz/: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 `dz/<playerId>/<salt><friendId><playerAuthKey>`.
|
|
242
|
+
*
|
|
243
|
+
* @internal
|
|
244
|
+
*/
|
|
245
|
+
export const SocialPullFriendMetaEndpoint = HttpApiEndpoint.post(
|
|
246
|
+
"SocialPullFriendMeta",
|
|
247
|
+
"/friend/pull_meta/dz/: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/dz/:playerId/:salt/:hash`. Same envelope as get_items.
|
|
265
|
+
*
|
|
266
|
+
* @internal
|
|
267
|
+
*/
|
|
268
|
+
export const SocialGetVisitsEndpoint = HttpApiEndpoint.get("SocialGetVisits", "/get_visits/dz/:playerId/:salt/:hash", {
|
|
269
|
+
params: { playerId: NimblebitConfig.PlayerIdSchema, salt: U32, hash: Schema.String },
|
|
270
|
+
error: ApiErrors,
|
|
271
|
+
success: [
|
|
272
|
+
ErrorResponse,
|
|
273
|
+
NotFoundResponse,
|
|
274
|
+
Schema.Struct({ success: Schema.Literal("Found"), gifts: Schema.Array(Gift) }),
|
|
275
|
+
],
|
|
276
|
+
}).annotate(OAuthScope.Required, Scopes.Social.read.get_visits.required);
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Preimage `dz/<playerId>/<giftId>/<salt><playerAuthKey>`. Response DTO
|
|
280
|
+
* NBSyncItemsReceiveResponse (success/error/id).
|
|
281
|
+
*
|
|
282
|
+
* @internal
|
|
283
|
+
*/
|
|
284
|
+
export const SocialReceiveItemEndpoint = HttpApiEndpoint.get(
|
|
285
|
+
"SocialReceiveItem",
|
|
286
|
+
"/receive_item/dz/:playerId/:giftId/:salt/:hash",
|
|
287
|
+
{
|
|
288
|
+
params: { playerId: NimblebitConfig.PlayerIdSchema, giftId: Schema.Int, salt: U32, hash: Schema.String },
|
|
289
|
+
error: ApiErrors,
|
|
290
|
+
success: [
|
|
291
|
+
ErrorResponse,
|
|
292
|
+
Schema.Struct({ success: Schema.Literal("Received"), id: Schema.optionalKey(Schema.String) }),
|
|
293
|
+
Schema.Struct({ success: Schema.Literal("NotReceived") }),
|
|
294
|
+
],
|
|
295
|
+
}
|
|
296
|
+
).annotate(OAuthScope.Required, Scopes.Social.write.receive_item.required);
|
|
297
|
+
|
|
298
|
+
/** @internal */
|
|
299
|
+
export const DeviceManagementGroup = HttpApiGroup.make("DeviceManagementGroup")
|
|
300
|
+
.add(DeviceNewPlayerEndpoint)
|
|
301
|
+
.add(DevicePlayerDetailsEndpoint)
|
|
302
|
+
.add(DeviceVerifyDeviceEndpoint);
|
|
303
|
+
|
|
304
|
+
/** @internal */
|
|
305
|
+
export const SyncManagementGroup = HttpApiGroup.make("SyncManagementGroup")
|
|
306
|
+
.add(SyncPullSaveEndpoint)
|
|
307
|
+
.add(SyncCheckForNewerSaveEndpoint);
|
|
308
|
+
|
|
309
|
+
/** @internal */
|
|
310
|
+
export const SocialGroup = HttpApiGroup.make("SocialGroup")
|
|
311
|
+
.add(SocialGetItemsEndpoint)
|
|
312
|
+
.add(SocialGetVisitsEndpoint)
|
|
313
|
+
.add(SocialReceiveItemEndpoint)
|
|
314
|
+
.add(SocialSendItemEndpoint)
|
|
315
|
+
.add(SocialPullFriendGameEndpoint)
|
|
316
|
+
.add(SocialPullFriendMetaEndpoint);
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* The Disco Zoo NBSync api.
|
|
320
|
+
*
|
|
321
|
+
* @since 1.0.0
|
|
322
|
+
* @category Api
|
|
323
|
+
*/
|
|
324
|
+
export const Api = HttpApi.make("DiscoZooApi").add(DeviceManagementGroup).add(SyncManagementGroup).add(SocialGroup);
|
package/src/Scopes.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The scopes the Disco Zoo 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 DiscoZoo = defineGame({
|
|
18
|
+
name: "discozoo",
|
|
19
|
+
description: "Disco Zoo",
|
|
20
|
+
read: { description: "Everything in Disco Zoo that only looks" },
|
|
21
|
+
write: { description: "Everything in Disco Zoo 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 } = DiscoZoo.areas;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @since 1.0.0
|
|
70
|
+
* @category Tree
|
|
71
|
+
*/
|
|
72
|
+
export const Games: ReadonlyArray<Game> = [DiscoZoo];
|
|
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
|
+
]);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Disco Zoo SDK: signed calls against Nimblebit's NBSync service.
|
|
7
|
+
*
|
|
8
|
+
* Signing reuses `@tinyburg/nimblebit-sdk` (`NimblebitAuth`): the game secret
|
|
9
|
+
* salt (from `NBSync._ss`) is provided as the auth key, and each request is
|
|
10
|
+
* `md5(<preimage> + <secret salt>)` with a random uint32 `salt` in the path.
|
|
11
|
+
* All method preimages below are the Tiny Tower formula with the `dz` game code.
|
|
12
|
+
*
|
|
13
|
+
* The methods that were exercised live against sync.nimblebit.com are marked
|
|
14
|
+
* VERIFIED; save-bearing / write paths follow the same pattern but were not
|
|
15
|
+
* exercised. Save bytes are returned raw (base64-decoded); inflating (pako) and
|
|
16
|
+
* parsing into a save schema is left to the caller.
|
|
17
|
+
*
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
* @category SDK
|
|
20
|
+
*/
|
|
21
|
+
export * as DiscoZoo from "./DiscoZoo.ts"
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Disco Zoo (game code `dz`) NBSync api endpoints.
|
|
25
|
+
*
|
|
26
|
+
* Signing: a random `salt` (signed int32) goes in the path, and `hash` is
|
|
27
|
+
* `md5(<preimage> + <game secret salt>)` with the preimage
|
|
28
|
+
* `dz/<playerId>/<salt><playerAuthKey>` (variants noted per endpoint). The
|
|
29
|
+
* secret salt is the value extracted from `NBSync._ss`.
|
|
30
|
+
*
|
|
31
|
+
* Verification (live server + Frida DTO inspection of the game, 2026-08-26):
|
|
32
|
+
* - Signing is MD5, server-validated (same scheme as Tiny Tower / Pocket
|
|
33
|
+
* Planes; the game computes SHA-256 only for the unauthenticated `register`).
|
|
34
|
+
* - Response envelopes VERIFIED by reading the game's DTO classes at runtime:
|
|
35
|
+
* register, player_details, sync/pull (NBSyncGameSaveResponse), current_version,
|
|
36
|
+
* verify_device, friend/pull_game, friend/pull_meta (meta is a flat
|
|
37
|
+
* Dictionary<String,Object> on pt), send_item (NBSyncItemsSendResponse),
|
|
38
|
+
* get_items (NBSyncItemsGetResponse: success/gifts, NO `total` unlike pp).
|
|
39
|
+
* `get_items` was also exercised live with a burnbot.
|
|
40
|
+
* - Standard NBSync endpoint set plus get_visits and receive_item.
|
|
41
|
+
*
|
|
42
|
+
* Game-specific save/meta schemas are left as `Schema.Unknown` placeholders.
|
|
43
|
+
*
|
|
44
|
+
* @since 1.0.0
|
|
45
|
+
* @category Endpoints
|
|
46
|
+
*/
|
|
47
|
+
export * as Endpoints from "./Endpoints.ts"
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The scopes the Disco Zoo api is guarded by, as a game-rooted tree, built with
|
|
51
|
+
* `@tinyburg/nimblebit-sdk`'s `defineGame`. Only the endpoints this sdk defines
|
|
52
|
+
* are covered; areas without both a read and a write side are left out until
|
|
53
|
+
* their endpoints exist.
|
|
54
|
+
*
|
|
55
|
+
* @since 1.0.0
|
|
56
|
+
* @category Scopes
|
|
57
|
+
*/
|
|
58
|
+
export * as Scopes from "./Scopes.ts"
|