kopuz 0.8.2

A modern, lightweight music player built with Rust and Dioxus.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/* eslint-disable */
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// dist/index.js
var index_exports = {};
__export(index_exports, {
  BG: () => core_exports,
  BGError: () => BGError,
  GOOG_API_KEY: () => GOOG_API_KEY,
  GOOG_BASE_URL: () => GOOG_BASE_URL,
  USER_AGENT: () => USER_AGENT,
  YT_BASE_URL: () => YT_BASE_URL,
  base64ToU8: () => base64ToU8,
  buildURL: () => buildURL,
  default: () => index_default,
  getHeaders: () => getHeaders,
  isBrowser: () => isBrowser,
  u8ToBase64: () => u8ToBase64
});
module.exports = __toCommonJS(index_exports);

// dist/core/index.js
var core_exports = {};
__export(core_exports, {
  BotGuardClient: () => BotGuardClient,
  Challenge: () => challengeFetcher_exports,
  PoToken: () => webPoClient_exports,
  WebPoMinter: () => WebPoMinter
});

// dist/core/challengeFetcher.js
var challengeFetcher_exports = {};
__export(challengeFetcher_exports, {
  create: () => create,
  descramble: () => descramble,
  parseChallengeData: () => parseChallengeData
});

// dist/utils/constants.js
var GOOG_BASE_URL = "https://jnn-pa.googleapis.com";
var YT_BASE_URL = "https://www.youtube.com";
var GOOG_API_KEY = "AIzaSyDyT5W0Jh49F30Pqqtyfdf7pDLFKLJoAnw";
var USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36(KHTML, like Gecko)";

// dist/utils/helpers.js
var base64urlCharRegex = /[-_.]/g;
var base64urlToBase64Map = {
  "-": "+",
  _: "/",
  ".": "="
};
var BGError = class extends TypeError {
  constructor(message, info) {
    super(message);
    this.name = "BGError";
    if (info)
      this.info = info;
  }
};
function base64ToU8(base64) {
  let base64Mod;
  if (base64urlCharRegex.test(base64)) {
    base64Mod = base64.replace(base64urlCharRegex, function(match) {
      return base64urlToBase64Map[match];
    });
  } else {
    base64Mod = base64;
  }
  base64Mod = atob(base64Mod);
  return new Uint8Array([...base64Mod].map((char) => char.charCodeAt(0)));
}
function u8ToBase64(u8, base64url = false) {
  const result = btoa(String.fromCharCode(...u8));
  if (base64url) {
    return result.replace(/\+/g, "-").replace(/\//g, "_");
  }
  return result;
}
function isBrowser() {
  var _a, _b, _c;
  const isBrowser2 = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined" && typeof window.HTMLElement !== "undefined" && typeof window.navigator !== "undefined" && typeof window.getComputedStyle === "function" && typeof window.requestAnimationFrame === "function" && typeof window.matchMedia === "function";
  const hasValidWindow = (_c = (_b = (_a = Object.getOwnPropertyDescriptor(globalThis, "window")) == null ? void 0 : _a.get) == null ? void 0 : _b.toString().includes("[native code]")) != null ? _c : false;
  return isBrowser2 && hasValidWindow;
}
function getHeaders() {
  const headers = {
    "content-type": "application/json+protobuf",
    "x-goog-api-key": GOOG_API_KEY,
    "x-user-agent": "grpc-web-javascript/0.1"
  };
  if (!isBrowser()) {
    headers["user-agent"] = USER_AGENT;
  }
  return headers;
}
function buildURL(endpointName, useYouTubeAPI) {
  return `${useYouTubeAPI ? YT_BASE_URL : GOOG_BASE_URL}/${useYouTubeAPI ? "api/jnn/v1" : "$rpc/google.internal.waa.v1.Waa"}/${endpointName}`;
}

// dist/core/challengeFetcher.js
async function create(bgConfig, interpreterHash) {
  const requestKey = bgConfig.requestKey;
  if (!bgConfig.fetch)
    throw new BGError("[Challenge]: Fetch function not provided");
  const payload = [requestKey];
  if (interpreterHash)
    payload.push(interpreterHash);
  const response = await bgConfig.fetch(buildURL("Create", bgConfig.useYouTubeAPI), {
    method: "POST",
    headers: getHeaders(),
    body: JSON.stringify(payload)
  });
  if (!response.ok)
    throw new BGError("[Challenge]: Failed to fetch challenge", { status: response.status });
  const rawData = await response.json();
  return parseChallengeData(rawData);
}
function parseChallengeData(rawData) {
  let challengeData = [];
  if (rawData.length > 1 && typeof rawData[1] === "string") {
    const descrambled = descramble(rawData[1]);
    challengeData = JSON.parse(descrambled || "[]");
  } else if (rawData.length && typeof rawData[0] === "object") {
    challengeData = rawData[0];
  }
  const [messageId, wrappedScript, wrappedUrl, interpreterHash, program, globalName, , clientExperimentsStateBlob] = challengeData;
  const privateDoNotAccessOrElseSafeScriptWrappedValue = Array.isArray(wrappedScript) ? wrappedScript.find((value) => value && typeof value === "string") : null;
  const privateDoNotAccessOrElseTrustedResourceUrlWrappedValue = Array.isArray(wrappedUrl) ? wrappedUrl.find((value) => value && typeof value === "string") : null;
  return {
    messageId,
    interpreterJavascript: {
      privateDoNotAccessOrElseSafeScriptWrappedValue,
      privateDoNotAccessOrElseTrustedResourceUrlWrappedValue
    },
    interpreterHash,
    program,
    globalName,
    clientExperimentsStateBlob
  };
}
function descramble(scrambledChallenge) {
  const buffer = base64ToU8(scrambledChallenge);
  if (buffer.length)
    return new TextDecoder().decode(buffer.map((b) => b + 97));
}

// dist/core/webPoClient.js
var webPoClient_exports = {};
__export(webPoClient_exports, {
  decodeColdStartToken: () => decodeColdStartToken,
  generate: () => generate,
  generateColdStartToken: () => generateColdStartToken,
  generatePlaceholder: () => generatePlaceholder
});

// dist/core/botGuardClient.js
var BotGuardClient = class _BotGuardClient {
  constructor(options) {
    this.vmFunctions = {};
    this.userInteractionElement = options.userInteractionElement;
    this.vm = options.globalObj[options.globalName];
    this.program = options.program;
  }
  /**
   * Factory method to create and load a BotGuardClient instance.
   * @param options - Configuration options for the BotGuardClient.
   * @returns A promise that resolves to a loaded BotGuardClient instance.
   */
  static async create(options) {
    return await new _BotGuardClient(options).load();
  }
  async load() {
    if (!this.vm)
      throw new BGError("[BotGuardClient]: VM not found in the global object");
    if (!this.vm.a)
      throw new BGError("[BotGuardClient]: Could not load program");
    const vmFunctionsCallback = (asyncSnapshotFunction, shutdownFunction, passEventFunction, checkCameraFunction) => {
      Object.assign(this.vmFunctions, { asyncSnapshotFunction, shutdownFunction, passEventFunction, checkCameraFunction });
    };
    try {
      this.syncSnapshotFunction = await this.vm.a(this.program, vmFunctionsCallback, true, this.userInteractionElement, () => {
      }, [[], []])[0];
    } catch (error) {
      throw new BGError(`[BotGuardClient]: Failed to load program (${error.message})`);
    }
    return this;
  }
  /**
   * Takes a snapshot asynchronously.
   * @returns The snapshot result.
   * @example
   * ```ts
   * const result = await botguard.snapshot({
   *   contentBinding: {
   *     c: "a=6&a2=10&b=SZWDwKVIuixOp7Y4euGTgwckbJA&c=1729143849&d=1&t=7200&c1a=1&c6a=1&c6b=1&hh=HrMb5mRWTyxGJphDr0nW2Oxonh0_wl2BDqWuLHyeKLo",
   *     e: "ENGAGEMENT_TYPE_VIDEO_LIKE",
   *     encryptedVideoId: "P-vC09ZJcnM"
   *    }
   * });
   *
   * console.log(result);
   * ```
   */
  async snapshot(args) {
    return new Promise((resolve, reject) => {
      if (!this.vmFunctions.asyncSnapshotFunction)
        return reject(new BGError("[BotGuardClient]: Async snapshot function not found"));
      this.vmFunctions.asyncSnapshotFunction((response) => resolve(response), [
        args.contentBinding,
        args.signedTimestamp,
        args.webPoSignalOutput,
        args.skipPrivacyBuffer
      ]);
    });
  }
  /**
   * Takes a snapshot synchronously.
   * @returns The snapshot result.
   * @throws Error Throws an error if the synchronous snapshot function is not found.
   */
  async snapshotSynchronous(args) {
    if (!this.syncSnapshotFunction)
      throw new BGError("[BotGuardClient]: Sync snapshot function not found");
    return this.syncSnapshotFunction([
      args.contentBinding,
      args.signedTimestamp,
      args.webPoSignalOutput,
      args.skipPrivacyBuffer
    ]);
  }
  /**
   * Passes an event to the VM.
   * @throws Error Throws an error if the pass event function is not found.
   */
  passEvent(args) {
    if (!this.vmFunctions.passEventFunction)
      throw new BGError("[BotGuardClient]: Pass event function not found");
    this.vmFunctions.passEventFunction(args);
  }
  /**
   * Checks the "camera".
   * @throws Error Throws an error if the check camera function is not found.
   */
  checkCamera(args) {
    if (!this.vmFunctions.checkCameraFunction)
      throw new BGError("[BotGuardClient]: Check camera function not found");
    this.vmFunctions.checkCameraFunction(args);
  }
  /**
   * Shuts down the VM. Taking a snapshot after this will throw an error.
   * @throws Error Throws an error if the shutdown function is not found.
   */
  shutdown() {
    if (!this.vmFunctions.shutdownFunction)
      throw new BGError("[BotGuardClient]: Shutdown function not found");
    this.vmFunctions.shutdownFunction();
  }
};

// dist/core/webPoMinter.js
var WebPoMinter = class _WebPoMinter {
  constructor(mintCallback) {
    this.mintCallback = mintCallback;
  }
  static async create(integrityTokenResponse, webPoSignalOutput) {
    const getMinter = webPoSignalOutput[0];
    if (!getMinter)
      throw new BGError("PMD:Undefined");
    if (!integrityTokenResponse.integrityToken)
      throw new BGError("Failed to create WebPoMinter: No integrity token provided", integrityTokenResponse);
    const mintCallback = await getMinter(base64ToU8(integrityTokenResponse.integrityToken));
    if (!(mintCallback instanceof Function))
      throw new BGError("APF:Failed");
    return new _WebPoMinter(mintCallback);
  }
  async mintAsWebsafeString(identifier) {
    const result = await this.mint(identifier);
    return u8ToBase64(result, true);
  }
  async mint(identifier) {
    const result = await this.mintCallback(new TextEncoder().encode(identifier));
    if (!result)
      throw new BGError("YNJ:Undefined");
    if (!(result instanceof Uint8Array))
      throw new BGError("ODM:Invalid");
    return result;
  }
};

// dist/core/webPoClient.js
async function generate(args) {
  const { program, bgConfig, globalName } = args;
  const { identifier } = bgConfig;
  const botguard = await BotGuardClient.create({ program, globalName, globalObj: bgConfig.globalObj });
  const webPoSignalOutput = [];
  const botguardResponse = await botguard.snapshot({ webPoSignalOutput });
  const payload = [bgConfig.requestKey, botguardResponse];
  const integrityTokenResponse = await bgConfig.fetch(buildURL("GenerateIT", bgConfig.useYouTubeAPI), {
    method: "POST",
    headers: getHeaders(),
    body: JSON.stringify(payload)
  });
  const integrityTokenJson = await integrityTokenResponse.json();
  const [integrityToken, estimatedTtlSecs, mintRefreshThreshold, websafeFallbackToken] = integrityTokenJson;
  const integrityTokenData = {
    integrityToken,
    estimatedTtlSecs,
    mintRefreshThreshold,
    websafeFallbackToken
  };
  const webPoMinter = await WebPoMinter.create(integrityTokenData, webPoSignalOutput);
  const poToken = await webPoMinter.mintAsWebsafeString(identifier);
  return { poToken, integrityTokenData };
}
function generateColdStartToken(identifier, clientState) {
  const encodedIdentifier = new TextEncoder().encode(identifier);
  if (encodedIdentifier.length > 118)
    throw new BGError("DFO:Invalid", { identifier });
  const timestamp = Math.floor(Date.now() / 1e3);
  const randomKeys = [Math.floor(Math.random() * 256), Math.floor(Math.random() * 256)];
  const header = randomKeys.concat([
    0,
    clientState != null ? clientState : 1
  ], [
    timestamp >> 24 & 255,
    timestamp >> 16 & 255,
    timestamp >> 8 & 255,
    timestamp & 255
  ]);
  const packet = new Uint8Array(2 + header.length + encodedIdentifier.length);
  packet[0] = 34;
  packet[1] = header.length + encodedIdentifier.length;
  packet.set(header, 2);
  packet.set(encodedIdentifier, 2 + header.length);
  const payload = packet.subarray(2);
  const keyLength = randomKeys.length;
  for (let i = keyLength; i < payload.length; i++) {
    payload[i] ^= payload[i % keyLength];
  }
  return u8ToBase64(packet, true);
}
function generatePlaceholder(identifier, clientState) {
  return generateColdStartToken(identifier, clientState);
}
function decodeColdStartToken(token) {
  const packet = base64ToU8(token);
  const payloadLength = packet[1];
  const totalPacketLength = 2 + payloadLength;
  if (packet.length !== totalPacketLength)
    throw new BGError("Invalid packet length.", { packetLength: packet.length, expectedLength: totalPacketLength });
  const payload = packet.subarray(2);
  const keyLength = 2;
  for (let i = keyLength; i < payload.length; ++i) {
    payload[i] ^= payload[i % keyLength];
  }
  const keys = [payload[0], payload[1]];
  const unknownVal = payload[2];
  const clientState = payload[3];
  const timestamp = payload[4] << 24 | payload[5] << 16 | payload[6] << 8 | payload[7];
  const date = new Date(timestamp * 1e3);
  const identifier = new TextDecoder().decode(payload.subarray(8));
  return {
    identifier,
    timestamp,
    unknownVal,
    clientState,
    keys,
    date
  };
}

// dist/index.js
var index_default = core_exports;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  BG,
  BGError,
  GOOG_API_KEY,
  GOOG_BASE_URL,
  USER_AGENT,
  YT_BASE_URL,
  base64ToU8,
  buildURL,
  getHeaders,
  isBrowser,
  u8ToBase64
});
//# sourceMappingURL=index.cjs.map