Using the KYC plugin
Using Sumsub Plugin with React
/** install ethers, axios and crypto-js: npm i ethers axios crypto-js **/
//Import ethers, axios e.t.c
import { ethers } from 'ethers';
import axios from 'axios';
import hmacSHA256 from 'crypto-js/hmac-sha256';
import hex from 'crypto-js/enc-hex';
const abiCoder = new ethers.utils.AbiCoder();
const userAddress = 'address of user for kyc';
const networkId = 'chain id(string) of network connected to';
const hashedAddress = abiCoder.encode(
["string", "string"],
[userAddress, networkId]
);
const userId = hashedAddress + Math.random().toString(36).substr(2, 9); //id verified uses
const baseUrl = 'https://api.sumsub.com'; //sumsub base url. note: without '/'
const secondUrl = `/resources/accessTokens?userId=${userId}&levelName=contact-details&ttlInSecs=1200`; //note: starts with '/'
const sumsubAppToken = 'your sumsub app token'; //contact Verified Network Team on Discord to get this
const sumsubSecretKey = 'your sumsub secret key'; //contact Verified Network Team on Discord to get this
const ts = Math.floor(Date.now() / 1000); //format current time
const hmacMessage = ts + "POST" + secondUrl; //combine ts, request method(POST) and second url
const signature = hmacSHA256(hmacMessage, sumsubSecretKey); //hash the message with sumsub secret key
//note: url = baseUrl + secondUrl;
//api url to use is 'https://api.sumsub.com/resources/accessTokens?userId=${userId}&levelName=contact-details&ttlInSecs=1200'
const generateSumsubAccessToken = async (url) => {
return await axios({
method: "POST",
url: url,
headers: {
Accept: "application/json",
"X-App-Token": sumsubAppToken,
"X-App-Access-Ts": ts,
"X-App-Access-Sig": hex.stringify(signature),
},
})
.then((res) => {
const response = res.data;
return response.token; //return access token
})
.catch((err) => {
//handle request error
console.error(`Post request to url: ${url} failed with error: ${err}`);
return;
});
};
const url = baseUrl + secondUrl;
const accessToken = await generateSumsubAccessToken(url);Last updated