Skip to content

Web3Auth/web3auth-backend

Repository files navigation

Web3Auth for Backend

lerna code style: prettier npm

Web3Auth is where passwordless auth meets non-custodial key infrastructure for Web3 apps and wallets. By aggregating OAuth (Google, Twitter, Discord) logins, different wallets and innovative Multi Party Computation (MPC) - Web3Auth provides a seamless login experience to every user on your application.

📖 Documentation

Checkout the official Web3Auth Documentation and SDK Reference to get started!

💡 Features

  • Plug and Play, OAuth based Web3 Authentication Service
  • Fully decentralized, non-custodial key infrastructure
  • End to end Whitelabelable solution
  • Threshold Cryptography based Key Reconstruction
  • Multi Factor Authentication Setup & Recovery (Includes password, backup phrase, device factor editing/deletion etc)
  • Support for WebAuthn & Passwordless Login
  • Support for connecting to multiple wallets
  • DApp Active Session Management

...and a lot more

💭 Choosing Between SDKs

For using Web3Auth in the web, you have two choices of SDKs to get started with.

Web3Auth Plug and Play Modal SDK @web3auth/modal: This package provides main class for using default Web3Auth Modal. The package includes all of our packages and gives you a simple way of implementing Web3Auth within your interface. Additionally, it is a child class of @web3auth/no-modal package.

Web3Auth Plug and Play NoModal SDK @web3auth/no-modal: Web3Auth Plug and Play No Modal is the main SDK that consists of the core module of Web3Auth Plug and Play. This SDK gives you all the needed modules for implementing the Web3Auth features, giving you the flexibility of implementing your own UI to use all the functionalities.b3Auth SDK working in the backend.

Web3Auth Backend SDK @web3auth/node-sdk: A simple and easy to use SDK to be used in your Node.js backend to get the same experience of Web3Auth frontend SDKs

⚡ Quick Start

Installation (Web3Auth Backend)

npm install --save @web3auth/node-sdk

Get your Client ID from Web3Auth Dashboard

Hop on to the Web3Auth Dashboard and create a new project. Use the Client ID of the project to start your integration.

Web3Auth Dashboard

Initialize Web3Auth for your preferred blockchain

Web3Auth needs to initialise as soon as your app loads up to enable the user to log in. Preferably done within a constructor, initialisation is the step where you can pass on all the configurations for Web3Auth you want. A simple integration for Ethereum blockchain will look like this:

import { Web3Auth } from "@web3auth/node-sdk";
const { EthereumPrivateKeyProvider } = require("@web3auth/ethereum-provider");

const web3auth = new Web3Auth({
  clientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ", // Get your Client ID from Web3Auth Dashboard
  web3AuthNetwork: "sapphire_mainnet", // Get your Network from Web3Auth Dashboard
});

const ethereumProvider = new EthereumPrivateKeyProvider({
  config: {
    chainConfig: {
      chainId: "0x1",
      rpcTarget: "https://rpc.ankr.com/eth",
    },
  },
});

web3auth.init({ provider: ethereumProvider });

Login your User

Once you're done initialising, logging in is as easy as:

const provider = await web3auth.connect({
  verifier: "YOUR_VERIFIER_NAME", // replace this with your own verifier name
  verifierId: "VERIFIER_ID_VALUE", // replace with your verifier id's value, for example, sub value of JWT Token, or email address.
  idToken: "JWT_TOKEN", // replace with your newly created unused JWT Token.
});

const eth_private_key = await provider.request({ method: "eth_private_key" });

⏪ Requirements

  • Node 18+

🩹 Examples

Checkout the examples for your preferred blockchain and platform in our pnp examples repository or core kit examples repository.

🌐 Demo

Checkout the Web3Auth Demo to see how Web3Auth can be used in your application.

Also, checkout the demo folder within this repository.

💬 Troubleshooting and Discussions