0.7.3 • Published 1 year ago

without_name_to_hide_package v0.7.3

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Sumsub OneID

npm

OneID - decentralized identity protocol.

Installation

npm install --save without_name_to_hide_package

or:

yarn add without_name_to_hide_package

Usage

Typescript

import sumsub from "without_name_to_hide_package";

const library = new Web3(WEB3_PROVIDER_URL);
const owns: boolean = await sumsub.checkOneIDOwnership(library, account);

console.log(`checkOneIDOwnership for account ${account}: ` + owns);

Solidity

Copy contract address for you chainId from without_name_to_hide_package/lib/addresses.json

pragma solidity ^0.8.0;

import "without_name_to_hide_package/lib/contracts/ISumsub.sol";

contract Demo {
  ISumsub sumsub;

  constructor(address sumsubContractAddress) {
    sumsub = ISumsub(sumsubContractAddress);
  }

  modifier onlyVerified() {
    _checkOneIDVerification();
    _;
  }

  function _checkOneIDVerification() internal view {
    require(sumsub.hasOneID(msg.sender), "Identification error: OneID is required");
  }

  function doSomething() external payable onlyVerified {
    // do something
  }
}

React

yarn add @web3-react/core @ethersproject/providers

App.tsx

import { Web3Provider } from "@ethersproject/providers";
import { Web3ReactProvider } from "@web3-react/core";

import DApp from "./DApp";

const getLibrary = (provider): Web3Provider => {
  return new Web3Provider(provider);
};

export default function App() {
  return <Web3ReactProvider getLibrary={getLibrary}>
    <DApp />
  </Web3ReactProvider>
}

DApp.tsx

import { useState } from 'react';
import { useSumsubContract } from "without_name_to_hide_package/lib/react/hooks/useSumsubContract";
import { useWeb3React } from "@web3-react/core";

export default function DApp() {
  const [exists, setExists] = useState<boolean>(false);
  const [isDuplicate, setIsDuplicate] = useState<boolean>(false);
  const [tokenId, setTokenID] = useState<number>(0);
  const [sumsubId, setSumsubId] = useState<string>('');
  const [duplicatesCount, setDuplicatesCount] = useState<number>(0);
  const [mainOneIDAddress, setMainOneIDAddress] = useState<string>('');
  
  const contract = useSumsubContract();
  const { account } = useWeb3React();
  
  const loadData = async () => {
    const exists = await contract.hasOneID(account);
    setExists(exists);
    const tokenId = await contract.getOneID(account);
    setTokenID(tokenId.toNumber());
    const sumsubId = await contract.getSumsubId(account);
    setSumsubId(sumsubId);
    const isDuplicate = await contract.hasOneIDDuplicate(account);
    setIsDuplicate(isDuplicate ? 1 : 0);

    if (!isDuplicate) {
      const duplicatesCount = await sumsub.getOneIDDuplicatesCount(account);
      setDuplicatesCount(duplicatesCount.toNumber());
      setMainOneIDAddress("");
    } else {
      setDuplicatesCount(0);
      const mainOneIDAddress = await sumsub.getDuplicateMainAccount(account);
      setMainOneIDAddress(mainOneIDAddress);
    }
  }
  
  useEffect(() => {
    if (account) {
      void loadData();
    }
  }, [account]);
  
  return <div>
    {contract && <>
      <p>Account: {account}</p>
      <p>OneID exists: {exists ? 'yes': 'no'}</p>
      {exists && <>
        <p>TokenId: {tokenId}</p>
        <p>SumsubId: {sumsubId}</p>
        <p>It's duplicate: {isDuplicate ? 'yes': 'no'}</p>
        {!isDuplicate ? <>
          <p>Duplicates count: {duplicatesCount}</p>
        </> : <>
          <p>Main account: {mainOneIDAddress}</p>
        </p>}
      </>}
    </>}
  </div>
}
0.7.2

1 year ago

0.7.1

1 year ago

0.7.3

1 year ago

0.7.0

1 year ago

0.5.4

1 year ago

0.5.3

1 year ago

0.3.5

2 years ago

0.5.6

1 year ago

0.5.5

1 year ago

0.5.0

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.3.53

2 years ago

0.2.41

2 years ago

0.3.52

2 years ago

0.3.51

2 years ago

0.5.8

1 year ago

0.5.7

1 year ago

0.5.9

1 year ago

0.3.54

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.4.5

1 year ago

0.4.4

2 years ago

0.4.1

2 years ago

0.2.3

2 years ago

0.4.0

2 years ago

0.2.2

2 years ago

0.6.1

1 year ago

0.4.3

2 years ago

0.6.0

1 year ago

0.4.2

2 years ago

0.2.4

2 years ago

0.1.0

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago