Git Product home page Git Product logo

poh-react's Introduction

Proof-of-Humanity-React

NPM

Proof-of-Humanity Core Component for React.

Used as a wrapper for PoH validators.

Live dApp demo

https://poh-counter.bakoush.in (source code)

Install

npm install poh-react

Usage

1. Wrap your app into the ProofOfHumanityProvider

import { ProofOfHumanityProvider } from 'poh-react';

<ProofOfHumanityProvider>
  <App />
</ProofOfHumanityProvider>;

2. Initialize at least one PoH validator plugin (e.g. poh-validator-hcaptcha)

import hCaptchaValidator from 'poh-validator-hcaptcha';

const validator = (
  <HCaptchaValidator
    sitekey="10000000-ffff-ffff-ffff-000000000001"
    url="http://localhost:3000/api/v1/proof"
  />
);

3. Initialize the getProofOfHumanity method from the PoH hook

import { useProofOfHumanity } from 'poh-react';

const { getProofOfHumanity } = useProofOfHumanity(validator);

4. Obtain the Proof-Of-Humanity prior to sending any sensitive transaction

const handleClick = () => {
  try {
      const { error, errorMessage, proof } = await getProofOfHumanity();

      if (!error) {
        const tx = await mySmartContract.someImportantMethod(proof);
      }
  } catch(error) {
    console.error(error);
  }
}

<button onClick={handleClick}>Send transaction</button>

The method in the smart contract must know how to deal with the proof. You can leverage a Solidity library just for that: poh-contracts

Using Sovereign PoH

If you want to use sovereign PoH instead of the basic one, you have to provide additional options object to useProofOfHumanity hook.

Options object has two properties:

  • type – if sovereign, the PoH component should ask the user to confirm their address ownership. The default value is basic
  • ethereum – specifies MetaMask API used to sign address ownership confirmation

Example:

import { useProofOfHumanity } from 'poh-react';

const { getProofOfHumanity } = useProofOfHumanity(validator, {
  type: 'sovereign',
  ethereum
});

Supported Validator Plugins

Validator Plugin Requirements

Validator plugin component must be a React component accepting the following props:

renderLogoOnly (boolean) – if true, the component should render its own logo instead of actual validator interface

data (string) – data (a hex string) to be included into signed proof-of-humanity. Can be a random hex challege, or a random hex challenge along with address owner signature

onVerify (function) – must be called once validation is complete with the object with following keys as the only parameter:

  • error (boolean)true in case of error; otherwise false

  • errorMessage (string) – in case of error; otherwise null

  • proof (string): proof-of-humanity (a hex string); null in case of error

Example plugin: hCaptcha validator

See also

Author

Alex Bakoushin

License

MIT

poh-react's People

Contributors

bakoushin avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.