bgutils-js
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -0,1 +1,2 @@ | ||
import { BGError } from '../utils/index.js'; | ||
export default class BotGuardClient { | ||
@@ -18,5 +19,5 @@ constructor(options) { | ||
if (!this.vm) | ||
throw new Error('[BotGuardClient]: VM not found in the global object'); | ||
throw new BGError('[BotGuardClient]: VM not found in the global object'); | ||
if (!this.vm.a) | ||
throw new Error('[BotGuardClient]: Could not load program'); | ||
throw new BGError('[BotGuardClient]: Could not load program'); | ||
const vmFunctionsCallback = (asyncSnapshotFunction, shutdownFunction, passEventFunction, checkCameraFunction) => { | ||
@@ -29,3 +30,3 @@ Object.assign(this.vmFunctions, { asyncSnapshotFunction, shutdownFunction, passEventFunction, checkCameraFunction }); | ||
catch (error) { | ||
throw new Error(`[BotGuardClient]: Failed to load program (${error.message})`); | ||
throw new BGError(`[BotGuardClient]: Failed to load program (${error.message})`); | ||
} | ||
@@ -53,3 +54,3 @@ return this; | ||
if (!this.vmFunctions.asyncSnapshotFunction) | ||
return reject(new Error('[BotGuardClient]: Async snapshot function not found')); | ||
return reject(new BGError('[BotGuardClient]: Async snapshot function not found')); | ||
this.vmFunctions.asyncSnapshotFunction((response) => resolve(response), [ | ||
@@ -70,3 +71,3 @@ args.contentBinding, | ||
if (!this.syncSnapshotFunction) | ||
throw new Error('[BotGuardClient]: Sync snapshot function not found'); | ||
throw new BGError('[BotGuardClient]: Sync snapshot function not found'); | ||
return this.syncSnapshotFunction([ | ||
@@ -85,3 +86,3 @@ args.contentBinding, | ||
if (!this.vmFunctions.passEventFunction) | ||
throw new Error('[BotGuardClient]: Pass event function not found'); | ||
throw new BGError('[BotGuardClient]: Pass event function not found'); | ||
this.vmFunctions.passEventFunction(args); | ||
@@ -95,3 +96,3 @@ } | ||
if (!this.vmFunctions.checkCameraFunction) | ||
throw new Error('[BotGuardClient]: Check camera function not found'); | ||
throw new BGError('[BotGuardClient]: Check camera function not found'); | ||
this.vmFunctions.checkCameraFunction(args); | ||
@@ -105,5 +106,5 @@ } | ||
if (!this.vmFunctions.shutdownFunction) | ||
throw new Error('[BotGuardClient]: Shutdown function not found'); | ||
throw new BGError('[BotGuardClient]: Shutdown function not found'); | ||
this.vmFunctions.shutdownFunction(); | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { base64ToU8, buildURL, getHeaders } from '../utils/index.js'; | ||
import { base64ToU8, BGError, buildURL, getHeaders } from '../utils/index.js'; | ||
/** | ||
@@ -12,3 +12,3 @@ * Creates a challenge. | ||
if (!bgConfig.fetch) | ||
throw new Error('[Challenge]: Fetch function not provided'); | ||
throw new BGError('[Challenge]: Fetch function not provided'); | ||
const payload = [requestKey]; | ||
@@ -23,3 +23,3 @@ if (interpreterHash) | ||
if (!response.ok) | ||
throw new Error(`[Challenge]: Failed to fetch challenge: ${response.status}`); | ||
throw new BGError('[Challenge]: Failed to fetch challenge', { status: response.status }); | ||
const rawData = await response.json(); | ||
@@ -26,0 +26,0 @@ return parseChallengeData(rawData); |
import BotGuardClient from './botGuardClient.js'; | ||
import WebPoMinter from './webPoMinter.js'; | ||
import { base64ToU8, buildURL, u8ToBase64, getHeaders } from '../utils/index.js'; | ||
import { base64ToU8, buildURL, u8ToBase64, getHeaders, BGError } from '../utils/index.js'; | ||
/** | ||
@@ -40,3 +40,3 @@ * Generates a Proof of Origin Token. | ||
if (encodedIdentifier.length > 118) | ||
throw new Error('DFO:Invalid'); | ||
throw new BGError('DFO:Invalid', { identifier }); | ||
const timestamp = Math.floor(Date.now() / 1000); | ||
@@ -76,3 +76,3 @@ const randomKeys = [Math.floor(Math.random() * 256), Math.floor(Math.random() * 256)]; | ||
if (packet.length !== totalPacketLength) | ||
throw new Error('Invalid packet length.'); | ||
throw new BGError('Invalid packet length.', { packetLength: packet.length, expectedLength: totalPacketLength }); | ||
const payload = packet.subarray(2); | ||
@@ -79,0 +79,0 @@ // Decrypt the payload by reversing the XOR operation |
@@ -1,2 +0,2 @@ | ||
import { base64ToU8, u8ToBase64 } from '../utils/helpers.js'; | ||
import { base64ToU8, BGError, u8ToBase64 } from '../utils/helpers.js'; | ||
export default class WebPoMinter { | ||
@@ -9,6 +9,8 @@ constructor(mintCallback) { | ||
if (!getMinter) | ||
throw new Error('PMD:Undefined'); | ||
const mintCallback = await getMinter(base64ToU8(integrityTokenResponse.integrityToken ?? '')); | ||
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 Error('APF:Failed'); | ||
throw new BGError('APF:Failed'); | ||
return new WebPoMinter(mintCallback); | ||
@@ -23,7 +25,7 @@ } | ||
if (!result) | ||
throw new Error('YNJ:Undefined'); | ||
throw new BGError('YNJ:Undefined'); | ||
if (!(result instanceof Uint8Array)) | ||
throw new Error('ODM:Invalid'); | ||
throw new BGError('ODM:Invalid'); | ||
return result; | ||
} | ||
} |
@@ -0,1 +1,5 @@ | ||
export declare class BGError extends TypeError { | ||
info?: any; | ||
constructor(message: string, info?: Record<string, any>); | ||
} | ||
export declare function base64ToU8(base64: string): Uint8Array; | ||
@@ -2,0 +6,0 @@ export declare function u8ToBase64(u8: Uint8Array, base64url?: boolean): string; |
@@ -8,2 +8,10 @@ import { GOOG_API_KEY, GOOG_BASE_URL, USER_AGENT, YT_BASE_URL } from './constants.js'; | ||
}; | ||
export class BGError extends TypeError { | ||
constructor(message, info) { | ||
super(message); | ||
this.name = 'BGError'; | ||
if (info) | ||
this.info = info; | ||
} | ||
} | ||
export function base64ToU8(base64) { | ||
@@ -10,0 +18,0 @@ let base64Mod; |
{ | ||
"name": "bgutils-js", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "A JavaScript library for interfacing with Botguard.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
69587
971