Socket
Socket
Sign inDemoInstall

@prosopo/procaptcha-react

Package Overview
Dependencies
Maintainers
0
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prosopo/procaptcha-react

React components for integrating the Prosopo [procaptcha](https://github.com/prosopo/procaptcha) into a React app.


Version published
Weekly downloads
105
increased by23.53%
Maintainers
0
Weekly downloads
 
Created
Source

Prosopo Procaptcha React Component Library

React components for integrating the Prosopo procaptcha into a React app.

Prosopo is a distributed human verification service that can be used to stop bots from interacting with your apps. Sign up to be a network beta tester.

Installation

You can install this library with:

npm install @prosopo/procaptcha-react --save

Basic Usage

See the client example for a minimal example of these components being used in a frontend app.

<Procaptcha config={config} callbacks={{ onError, onHuman, onExpired }} />

Callbacks

ProcaptchaEvents are passed to the captcha component at creation.

The captcha event callbacks are defined as follows:

/**
 * A list of all events which can occur during the Procaptcha process.
 */
export interface ProcaptchaEvents {
    onError: (error: Error) => void
    onHuman: (output: ProcaptchaOutput) => void
    onExtensionNotFound: () => void
    onExpired: () => void
    onFailed: () => void
}

onHuman

The onHuman callback is called when the user has successfully completed the captcha challenge. The ProcaptchaOutput object contains the following fields:

KeyTypeDescription
commitmentIdstringThe commitment ID of the captcha challenge. This is used to verify the user's response on-chain.
providerUrlstringThe URL of the provider that the user used to solve the captcha challenge.
dappstringThe SITE_KEY of your application / website
userstringThe user's account address
blockNumbernumberThe block number of the captcha challenge. This is used to verify that the contacted provider was randomly selected on-chain.

onError

The onError callback is called when an error occurs during the captcha process. The Error object is a standard JavaScript error.

onExpired

The onExpired callback is called when the captcha challenge has expired. This can occur if the user takes too long to complete the challenge.

onFailed

The onFailed callback is called when the user has failed the captcha challenge. This can occur if the user answers the challenge incorrectly.

Add the Procaptcha Widget to your Web page using a React Component

You can see Procaptcha being used as a React component in our React Demo.

The Procaptcha component is called as follows:

<Procaptcha config={config} callbacks={{ onError, onHuman, onExpired }} />

A config object is required and must contain your SITE_KEY. The callbacks are optional and can be used to handle the various Procaptcha events. The following config demonstrates the PROSOPO_SITE_KEY variable being pulled from environment variables.

const config: ProcaptchaClientConfigInput = {
    account: {
        address: process.env.PROSOPO_SITE_KEY || undefined,
    },
    web2: 'true',
    dappName: 'client-example',
    defaultEnvironment: 'rococo',
    networks: {
        rococo: {
            endpoint: 'wss://rococo-contracts-rpc.polkadot.io:443',
            contract: {
                address: '5HiVWQhJrysNcFNEWf2crArKht16zrhro3FcekVWocyQjx5u',
                name: 'prosopo',
            },
        },
    },
    solutionThreshold: 80,
}

Config Options

KeyTypeDescription
accountstringThe SITE_KEY you received when you signed up
web2stringSet to true to enable web2 support
dappNamestringThe name of your application / website
defaultEnvironmentstringThe default environment to use - set to rococo
networksobjectThe networks your application supports - copy paste this from the config above
solutionThresholdnumberThe percentage of captcha that a user must have answered correctly to identify as human

Verify the User Response Server Side

Please see the main README for instructions on how to implement the server side of Procaptcha.

FAQs

Package last updated on 26 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc