npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@web3auth/kyc-embed

v0.1.0

Published

Embed script

Downloads

4

Readme

KYC Embed

Demo

https://demo-kyc.web3auth.io

How it works:-

This sdk comes with two components:-

  1. Liveness embed:- This component allows your app to verify liveness of a user and to filter out bots from accessing your app. This component works by verify user's liveness by doing a live user's selfie video verification test.

    Additionally this component provides a way to check security of device connection using a optional captcha. Note:- Using captcha is a optional.

    You can use this component in both with or without wallet connection. If you want user to verify the liveness only once than it suggested to user it with any wallet connection. But if you want user to verify liveness on every new device session then non wallet login flow can be used.

  2. Kyc embed:- This component allows your app to verify user's kyc data. This component is currently only works for india region and supports verification of documents like:- AADHAR and PAN

Liveness Check Usage

Before you begin, you need a Web3auth Client ID to use LivenessCheck SDK. Please create one in web3auth dashboard if you don't have one.

Prerequisites

// package.json

// Copy the kyc-embed package and install the web3auth and web3 packages if you are planning to include authentication

"dependencies": {
  "@web3auth/kyc-embed": "^0.1.0",
  "@web3auth/base": "^8.0.0",
  "@web3auth/ethereum-provider": "^8.0.1",
  "@web3auth/modal": "^8.0.1",
  "web3": "^4.6.0"
},
// globals.ts

// Polyfill `Buffer` which is used in the iframe communication and inject `process` to access environment variables in Vite

import { Buffer } from "buffer";
import process from "process";

window.global = globalThis;
globalThis.Buffer = globalThis.Buffer || Buffer;
process.env = { ...process.env, ...(globalThis.process?.env || {}) };
globalThis.process = process;

Basic Usage (Without wallet and authentication)

import "./globals"
import { LivenessEmbed } from  "@web3auth/kyc-embed";
import { WEB3AUTH_NETWORK } from "@web3auth/base";

// 1. create an instance
const embedInstance = new LivenessEmbed({
  web3AuthClientId:  <YOUR_WEB3AUTH_CLIENT_ID>,
  web3AuthNetwork:  WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
});

// 2. initialize
await embedInstance.init();

// 3. start liveness check
embedInstance.initLivenessCheck({
  // this field is intended for the usage before login
  // setting this to `true` will allow users to access the liveness check without logging in
  // for the liveness check usage after login, please see the next section
  allowUnauthenticatedAccess: true,
});

Usage with authenticated users/wallets

You can authenticate with any EIP-1993 wallet. In this example code, we're using @web3auth/modal PNP modal SDK to login.

import "./globals"
import { LivenessEmbed } from  "@web3auth/kyc-embed";
import { CHAIN_NAMESPACES, WEB3AUTH_NETWORK } from "@web3auth/base";
import  { Web3Auth }  from  "@web3auth/modal";
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
...
const WEB3AUTH_CLIENT_ID = <YOUR_WEB3AUTH_CLIENT_ID>;
// 1. create and initialize LivenessEmbed instance
const embedInstance = new LivenessEmbed({ ... });
await embedInstance.init();
...
...
// 2. LOGIN
// setup config
const chainConfig = {
  chainId: "0x1", // Please use 0x1 for Mainnet
  rpcTarget: "https://rpc.ankr.com/eth",
  chainNamespace: CHAIN_NAMESPACES.EIP155,
  displayName: "Ethereum Mainnet",
  blockExplorerUrl: "https://etherscan.io/",
  ticker: "ETH",
  tickerName: "Ethereum",
  logo: "https://images.toruswallet.io/eth.svg",
};
// initialize a provider
const privateKeyProvider = new EthereumPrivateKeyProvider({
  config: { chainConfig: config.chainConfig },
});
// create web3auth login modal instance
const web3auth = new Web3Auth({
  clientId: WEB3AUTH_CLIENT_ID,
  web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
  privateKeyProvider: privateKeyProvider,
});
// initiate login modal
await web3auth.initModal();
...
...
// 3. Authenticate
// open login modal if user is not logged in
if (!web3auth.connected) {
  await web3auth.connect();
}
// generate the id token which will be used during the liveness check requests
const web3 = new Web3(web3auth.provider);
const accounts = await web3.eth.getAccounts();
// fetch the message from the server
const authMsg = await embedInstance.getAuthMessage({ address: accounts[0] });
// sign the message
const signedMessage = await web3.eth.personal.sign(authMsg?.message ?? "", accounts[0], "test password");
// get the authorization token. The authentication token will be saved in the LivenessEmbed State, so you don't need to pass around the token
const  { token } = await embedInstance.verifyAuthSignature({ address:accounts[0], signature: signedMessage });
...
...
// 4. Start the liveness check
await embedInstance.initLivenessCheck();

Check liveness status

For authenticated mode, you can call getLivenessCheckStatus method to check the status of the Liveness Check.

// NOTE:
// you must be in the `Authenticated` mode (`allowUnauthenticatedAccess: false,`)
// in order to use this method properly.

// under the hood, this method will use `Authentication Token` stored in the Embed State (refer to step 3 in Authenticated Usage)
let status = await livenessEmbed.getLivenessCheckStatus();

The below is the sample of Liveness Check Success Response

{
  "id": 40,
  "created_at": "2024-03-25T07:27:08.000Z",
  "updated_at": "2024-03-25T07:27:19.000Z",
  "liveness_analysis_status": "Success",
  "public_address": "0x750882A476DCC8c80f725C139e444143da9f8dBb",
  "client_id": "....",
  "retry": 2
}

Subscribe to UI Events

You can optionally call the subscribeEvents method to get the Liveness UI Events updates (such as success, failure, cancelled etc..)

// you can call embed's subscribeEvents() method to listen to the Liveness UI Events
// and perform any relevant actions by providing callback function as a method parameter
function cb(method:string,params?:any) {
  ...
  if (method === "on_cancelled_liveness") {
    console.log("user has cancelled the liveness check before finished");
    // do your things
    ...
  }
}
// call this method after `embedInstance.init()`
embedInstance.subscribeEvents(cb);

Enable Captcha

You can choose to use our built-in captcha, or use your own captcha system, or not use any captcha.

// Use Web3Auth built-in captcha
embedInstance.initLivenessCheck({ enableCaptcha: true });

// Use your own captcha or do not use any captcha
embedInstance.initLivenessCheck({ enableCaptcha: false /* or undefined */ });

Examples

Checkout the demo application for how you can integrate the Liveness Check in your frontend application.

Api References

Coming Soon