without_name_to_hide_package
v0.7.3
Published
Hidden description
Downloads
13
Readme
Sumsub OneID
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>
}