got#Agents TypeScript Examples

The following examples show how to use got#Agents. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From hsolve with MIT License 6 votes vote down vote up
siteConfig = async (
  host: string,
  siteKey: string,
  userAgent: string,
  agent?: Agents
): Promise<SiteConfig["c"]> => {
  try {
    const { body } = await got(`https://hcaptcha.com/checksiteconfig`, {
      searchParams: {
        host,
        sitekey: siteKey,
        sc: 1,
        swa: 0,
      },
      headers: {
        "user-agent": userAgent,
      },
      responseType: `json`,
      agent,
    });
    return (body as SiteConfig).c;
  } catch (e) {
    if (e.response && e.response.statusCode === 429) {
      await sleep(30000);
    } else {
      throw new Error(e);
    }
  }
}
Example #2
Source File: functions.ts    From hsolve with MIT License 5 votes vote down vote up
createAgents = (proxy: string): Agents => {
  return {
    http: new HttpProxyAgent(parse(proxy)) as unknown as http.Agent,
    https: new HttpsProxyAgent(parse(proxy)) as unknown as https.Agent,
  }
}
Example #3
Source File: index.ts    From hsolve with MIT License 5 votes vote down vote up
getCaptcha = async (
  host: string,
  siteKey: string,
  userAgent: string,
  c: SiteConfig["c"],
  timestamp: number,
  agent?: Agents
): Promise<CaptchaTask> => {
  try {
    const { body } = await got.post(`https://hcaptcha.com/getcaptcha`, {
      searchParams: {
        host,
        sitekey: siteKey,
        sc: 1,
        swa: 0,
      },
      headers: {
        "user-agent": userAgent,
      },
      responseType: `json`,
      form: {
        sitekey: siteKey,
        host,
        n: await hsl(c.req),
        c: JSON.stringify(c),
        motionData: {
          st: timestamp,
          dct: timestamp,
          mm: generateMouse(timestamp),
        },
      },
      agent,
    });
    return body as CaptchaTask;
  } catch (e) {
    if (e.response && e.response.statusCode === 429) {
      await sleep(30000);
    } else {
      throw new Error(e);
    }
  }
}
Example #4
Source File: index.ts    From hsolve with MIT License 5 votes vote down vote up
submitCaptcha = async (
  host: string,
  siteKey: string,
  userAgent: string,
  timestamp: number,
  key: string,
  jobType: string,
  answers: {
    [key: string]: any;
  },
  agent?: Agents
): Promise<string> => {
  try {
    const { body }: { body: CaptchaTask } = await got.post(
      `https://hcaptcha.com/checkcaptcha/${key}`,
      {
        searchParams: {
          host,
          sitekey: siteKey,
          sc: 1,
          swa: 0,
        },
        headers: {
          "user-agent": userAgent,
        },
        responseType: `json`,
        form: {
          sitekey: siteKey,
          serverdomain: host,
          answers,
          job_mode: jobType,
          motionData: {
            st: timestamp,
            dct: timestamp,
            mm: generateMouse(timestamp),
          },
        },
        agent,
      }
    );
    return body.generated_pass_UUID ? body.generated_pass_UUID : null;
  } catch (e) {
    if (e.response && e.response.statusCode === 429) {
      await sleep(30000);
    } else {
      throw new Error(e);
    }
  }
}