Giter Site home page Giter Site logo

dauth's Introduction

Dauth - Decentralized User Authentication

Dauth is a package for decentralized user authentication, built using Ethereum smart contracts and the Ether.js library. With Dauth, you can easily create a decentralized user authentication system on the Ethereum blockchain.

Installation

To use Dauth in your project, you can install it via npm:

npm i dauth-sso

Usage

To use Dauth, you just need to have a object of the class Dauth. which will be an instance of all the package.

You can use the methods in the class to verify the user, get the user from address, or check user with username etc.

It will be very helpfull in building some application which needs a decentralized user authentication. you just need to import the npm package and initialize the object of the class Dauth, where you can access all the required methods.

const { Dauth } = require("dauth-sso");

const dauth = new Dauth();

In this example the Dauth is the class in the package which contains all the methods.


Creating user

For the integrity of the system we have decided to have an authorisation over creating a new user in the smart contract. therfore there is a modifire on the function of creating a user that only allows the admin of the smart contract to creat a user.

For getting the authority to create a user, the organization need to register themselves over the official website of the Dauth-SSO. After verification ther organisations adress will be admin of the smart contract and they can use the create user functionality.

const { DauthSigner } = require("dauth-sso");

const dauthWithSigner = new DauthSigner(privateKey);

The admin can create a object with signer in it as mentioned above, so that admin will able to use the createUser function (as write operation on blockchain requires gas fees).


Methods

Once you have an instance of the Dauth class, you can use the following methods to manage user authentication:

async verifyUser(username: string, password: string): Promise<bool>

Verifies the user's username and password and returns the boolean expression. If the username and password are not valid then it will return a false boolean expression.

const result = await dauth.verifyUser(username, password);
cosole.log(result);

OR

dauth
  .verifyUser(username, password)
  .then((res) => {
    if (res) {
      console.log("User is verified!");
    } else {
      console.log("User is not verified!");
    }
  })
  .catch((err) => {
    console.error(`Error verifying user: ${err}`);
  });

async isUserOfAddress(address: string): Promise<boolean>

Checks if a user with the specified Ethereum address exists in the authentication system.

const isUser = await dauth.isUserOfAddress(address);
if (isUser) {
  console.log("User of this address exist");
} else {
  console.log("User of this address does not exist");
}

async isUserOfName(username: string): Promise<boolean>

Checks if a user with the specified username exists in the authentication system.

const isUser = await dauth.isUserOfName(user);
if (isUser) {
  console.log("User of this username exist");
} else {
  console.log("User of this username does not exist");
}

async getUserNameByAddress(address: string): Promise<string>

Gets the username associated with the specified Ethereum address. If the address is not associated with a username, an error is thrown.

const username = await dauth.getUserNameByAddress(address);
console.log(username);

async createUser(address: string): Promise<bool>

Creats the user in the smart contract memory, needs to be evcated by the signed object of the package. thus need your private key for creating a signer for the transaction.

const result = await dauthWithSigner.createUser(
  username,
  email,
  password,
  address
);

dauth's People

Contributors

shubham1632 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.