Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

poh-tron-react

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

poh-tron-react

Proof-of-Humanity TRON Core React Component

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Proof-of-Humanity TRON Core React Component

NPM

Proof-of-Humanity TRON Core Component for React.

Used as a wrapper for PoH validators.

Live dApp demo

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

Install

npm install poh-tron-react

Usage

1. Wrap your app into the ProofOfHumanityProvider

import { ProofOfHumanityProvider } from "poh-tron-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-tron-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) {
        await mySmartContract.someImportantMethod(proof).send({
            feeLimit: 100_000_000,
            callValue: 0
        });
      }
  } 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-tron-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
  • tronWeb – specifies TronWeb API used to sign address ownership confirmation

Example:

import { useProofOfHumanity } from "poh-tron-react";

const { getProofOfHumanity } = useProofOfHumanity(validator, {
  type: "sovereign",
  tronWeb,
});

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

Keywords

FAQs

Package last updated on 20 Jul 2022

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