Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement a proper botguard client and potoken minter #9

Merged
merged 2 commits into from
Oct 18, 2024

Conversation

LuanRT
Copy link
Owner

@LuanRT LuanRT commented Oct 17, 2024

This adds:

A proper BotGuard client.

It acts as an interface for the BotGuard VM. It can generate responses for user interactions, po tokens, and more.

Example:

/// ...
const botguard = await BG.BotGuardClient.create({
  program,
  globalName,
  globalObj
});

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);

WebPo Minter.

Used to create Po Tokens.

Example:

// ...
const webPoSignalOutput: WebPoSignalOutput = [];
const botguardResponse = await botguard.snapshot({ webPoSignalOutput });
 
const payload = [requestKey, botguardResponse];

const integrityTokenResponse = await fetch('https://jnn-pa.googleapis.com/$rpc/google.internal.waa.v1.Waa/GenerateIT', {
  method: 'POST',
  headers: {
    'content-type': 'application/json+protobuf',
    'x-goog-api-key': GOOG_API_KEY,
    'x-user-agent': 'grpc-web-javascript/0.1'
  },
  body: JSON.stringify(payload)
});

const integrityTokenJson = await integrityTokenResponse.json() as [string, number, number, string];

const [integrityToken, estimatedTtlSecs, mintRefreshThreshold, websafeFallbackToken] = integrityTokenJson;

const integrityTokenData = {
  integrityToken,
  estimatedTtlSecs,
  mintRefreshThreshold,
  websafeFallbackToken
};

const webPoMinter = await BG.WebPoMinter.create(integrityTokenData, webPoSignalOutput);

const poToken = await webPoMinter.mintAsWebsafeString(identifier);
console.log(poToken);

@LuanRT LuanRT merged commit fddd47f into main Oct 18, 2024
@LuanRT LuanRT deleted the refactor/proper-botguard-client branch October 18, 2024 00:26
@LuanRT LuanRT changed the title feat: Implement proper botguard client and potoken minter feat: Implement a proper botguard client and potoken minter Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant