bgutils-js
Advanced tools
Comparing version 2.2.0 to 3.0.0
@@ -56,9 +56,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
const [messageId, script, , interpreterHash, challenge, globalName] = challengeData; | ||
const [messageId, wrappedScript, , interpreterHash, program, globalName, , clientExperimentsStateBlob] = challengeData; | ||
const privateDoNotAccessOrElseSafeScriptWrappedValue = Array.isArray(wrappedScript) ? wrappedScript.find((value) => value && typeof value === 'string') : null; | ||
return { | ||
script, | ||
messageId, | ||
interpreterJavascript: { | ||
privateDoNotAccessOrElseSafeScriptWrappedValue | ||
}, | ||
interpreterHash, | ||
program, | ||
globalName, | ||
challenge, | ||
messageId | ||
clientExperimentsStateBlob | ||
}; | ||
@@ -65,0 +69,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import type { PoTokenArgs } from '../utils/index.js'; | ||
import type { PoTokenArgs, PoTokenResult } from '../utils/index.js'; | ||
/** | ||
@@ -6,3 +6,3 @@ * Generates a Proof of Origin Token. | ||
*/ | ||
export declare function generate(args: PoTokenArgs): Promise<string | undefined>; | ||
export declare function generate(args: PoTokenArgs): Promise<PoTokenResult>; | ||
/** | ||
@@ -9,0 +9,0 @@ * Creates a placeholder PoToken. This can be used while `sps` (StreamProtectionStatus) is 2, but will not work once it changes to 3. |
@@ -18,10 +18,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b; | ||
const { program, bgConfig, globalName } = args; | ||
const { identifier } = bgConfig; | ||
const bg = yield invokeBotguard(program, globalName, bgConfig); | ||
if (bg.postProcessFunctions.length) { | ||
const processIntegrityToken = bg.postProcessFunctions[0]; | ||
const bgResult = yield invokeBotguard(program, globalName, bgConfig); | ||
if (bgResult.postProcessFunctions.length) { | ||
const processIntegrityToken = bgResult.postProcessFunctions[0]; | ||
if (!processIntegrityToken) | ||
throw new BGError(4, 'PMD:Undefined'); | ||
const acquirePo = yield processIntegrityToken(base64ToU8(bg.integrityToken)); | ||
const acquirePo = yield processIntegrityToken(base64ToU8((_b = (_a = bgResult.integrityTokenData.integrityToken) !== null && _a !== void 0 ? _a : bgResult.integrityTokenData.websafeFallbackToken) !== null && _b !== void 0 ? _b : '')); | ||
if (typeof acquirePo !== 'function') | ||
@@ -34,4 +35,8 @@ throw new BGError(16, 'APF:Failed'); | ||
throw new BGError(18, 'ODM:Invalid'); | ||
return u8ToBase64(result, true); | ||
return { | ||
poToken: u8ToBase64(result, true), | ||
integrityTokenData: bgResult.integrityTokenData | ||
}; | ||
} | ||
throw new BGError(0, '[BG]: Failed to process integrity token data'); | ||
}); | ||
@@ -56,3 +61,3 @@ } | ||
const attFunctions = {}; | ||
const attFunctionsCallback = (fn1, fn2, fn3, fn4) => { | ||
const setAttFunctions = (fn1, fn2, fn3, fn4) => { | ||
Object.assign(attFunctions, { fn1, fn2, fn3, fn4 }); | ||
@@ -63,3 +68,3 @@ }; | ||
try { | ||
yield vm.a(program, attFunctionsCallback, true, undefined, () => { }); | ||
yield vm.a(program, setAttFunctions, true, undefined, () => { }); | ||
} | ||
@@ -70,3 +75,3 @@ catch (err) { | ||
if (!attFunctions.fn1) | ||
throw new BGError(4, '[BG]: Att function 1 unavailable. Cannot proceed.'); | ||
throw new BGError(4, '[BG]: Att function unavailable. Cannot proceed.'); | ||
let botguardResponse; | ||
@@ -96,7 +101,18 @@ const postProcessFunctions = []; | ||
throw new BGError(8, '[GenerateIT]: No integrity token data received'); | ||
const integrityToken = integrityTokenData[0]; | ||
if (typeof integrityToken !== 'string') | ||
throw new BGError(9, `[GenerateIT]: Expected integrity token to be a string but got ${typeof integrityToken}`); | ||
const [integrityToken, estimatedTtlSecs, mintRefreshThreshold, websafeFallbackToken] = integrityTokenData; | ||
if (integrityToken !== undefined && typeof integrityToken !== 'string') | ||
throw new BGError(9, '[GenerateIT]: Invalid integrity token'); | ||
if (estimatedTtlSecs !== undefined && typeof estimatedTtlSecs !== 'number') | ||
throw new BGError(10, '[GenerateIT]: Invalid TTL'); | ||
if (mintRefreshThreshold !== undefined && typeof mintRefreshThreshold !== 'number') | ||
throw new BGError(11, '[GenerateIT]: Invalid mint refresh threshold'); | ||
if (websafeFallbackToken !== undefined && typeof websafeFallbackToken !== 'string') | ||
throw new BGError(12, '[GenerateIT]: Invalid websafe fallback token'); | ||
return { | ||
integrityToken, | ||
integrityTokenData: { | ||
integrityToken, | ||
estimatedTtlSecs, | ||
mintRefreshThreshold, | ||
websafeFallbackToken | ||
}, | ||
postProcessFunctions | ||
@@ -103,0 +119,0 @@ }; |
@@ -6,28 +6,45 @@ export type PoTokenArgs = { | ||
}; | ||
export type PoTokenResult = { | ||
poToken: string; | ||
integrityTokenData: IntegrityTokenData; | ||
}; | ||
export type PostProcessFunction = (buffer: Uint8Array) => Promise<(identifier: Uint8Array) => Promise<Uint8Array | undefined>>; | ||
export type IntegrityTokenData = { | ||
integrityToken?: string; | ||
estimatedTtlSecs?: number; | ||
mintRefreshThreshold?: number; | ||
websafeFallbackToken?: string; | ||
}; | ||
export type BotguardResponse = { | ||
integrityTokenData: IntegrityTokenData; | ||
postProcessFunctions: (PostProcessFunction | undefined)[]; | ||
integrityToken: string; | ||
}; | ||
export type InterpreterJavascript = { | ||
privateDoNotAccessOrElseSafeScriptWrappedValue: string | null; | ||
}; | ||
export type DescrambledChallenge = { | ||
/** | ||
* The ID of the JSPB message. | ||
*/ | ||
messageId?: string; | ||
/** | ||
* The script associated with the challenge. | ||
*/ | ||
script?: (string | null)[]; | ||
interpreterJavascript: InterpreterJavascript; | ||
/** | ||
* The hash of the script. | ||
*/ | ||
*/ | ||
interpreterHash: string; | ||
/** | ||
* The program. | ||
*/ | ||
program: string; | ||
/** | ||
* The name of the VM in the global scope. | ||
*/ | ||
*/ | ||
globalName: string; | ||
/** | ||
* The program / challenge. | ||
*/ | ||
challenge: string; | ||
/** | ||
* The ID of the JSPB message. | ||
*/ | ||
messageId: string; | ||
* The client experiments state blob. | ||
*/ | ||
clientExperimentsStateBlob?: string; | ||
}; | ||
@@ -34,0 +51,0 @@ export type FetchFunction = typeof fetch; |
{ | ||
"name": "bgutils-js", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "A JavaScript library for interfacing with Botguard.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -50,3 +50,3 @@ # What Is This? | ||
The descrambled data should consist of a message ID, a script, the interpreter hash, a program/challenge, and the script's global name. | ||
The descrambled data should consist of a message ID, the interpreter javascript, the interpreter hash, a program, and the script's global name. | ||
@@ -53,0 +53,0 @@ To make the VM available in the global scope, evaluate the script. If all goes well, you should be able to access the VM from your browser or program. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
60233
777