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

dauth-sso

v1.2.1

Published

Dauth is a decentralized user authentication system

Downloads

1

Readme

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
);