foxhat-anti-spam
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

Getting Started with FoxHat JavaScript Library

This guide will help you get started with using the FoxHat library in your JavaScript projects.

Installation

First, you need to install the foxhat-anti-spam library. You can do this using npm:

npm i foxhat-anti-spam

Usage

Import the library into your JavaScript file:

// JavaScript
const {FoxtHatAntiSpam} = require('foxhat-anti-spam');

// TypeScript
import FoxtHatAntiSpam from "foxhat-anti-spam";

Create a new FoxHat instance with your public token:

// JavaScript
const solver = new FoxtHatAntiSpam("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9........");

Process a challenge using the challenge() function.

// JavaScript
const foxhat = new FoxtHatAntiSpam("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9........");

try {
    const solution = await foxhat.challenge();
    await axios.post("https://foxhat.demo", {
        message,
        // 4. Forward the solution
        _foxhat: solution,
    });
} catch (error) {
    console.error("Error:", error);
}

Verifying solutions in Node.js

Create a new FoxHat instance with your secret token:

// JavaScript
const foxhat = new FoxtHatAntiSpam("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9........");

try {

    server.post('/message', async (req, res) => {
        const {message, _foxhat} = req.body;
        // 3. Verify the solution
        const verify = await foxhat.verify(_foxhat)
        if (!verify) {
            throw new Error('Invalid FoxHat solution')
        } else {
            // ...
        }
    })

} catch (error) {
    console.error("Error:", error);
}

/foxhat-anti-spam/

    Package Sidebar

    Install

    npm i foxhat-anti-spam

    Weekly Downloads

    1

    Version

    1.0.6

    License

    none

    Unpacked Size

    182 kB

    Total Files

    4

    Last publish

    Collaborators

    • foxhat