@nodefactory/server-eth-auth
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

Server-eth-auth

Build Status GitHub Node Npm

This repository contains TypeScript implementation of validation for web3 signers signatures used for authenticating on server.

Usage

Install with yarn add @nodefactory/server-eth-auth or npm i @nodefactory/server-eth-auth

Example of usage:

import {EthAuth} from "@nodefactory/server-eth-auth";

const domain = "Nodefactory" // shown in signer when requesting signature
const ethAuth = new EthAuth(storage: IChallengeStorage, domain)

// Creating challenge for sending to user for signature
ethAuth.createChallenge(userEthereumAddress);

const challengeHash = "hash" // user sent value that was created in createChallenge under challenge.message.value
const signature = "signature" // signature returned from signer
// Validating user signature
const address = ethAuth.checkChallenge(challengeHash, signature)

This package should be used in controller with 2 api endpoints:

  • challenge endpoint that returns created challenge for user given ethereum address
  • login endpoint that validates signature generated by signer with checkChallenge and creates and returns authentication token that can be later validated

This package requires for IChallengeStorage to be implemented to store created challenge hashes. Type of storage is open to choice (eg. db, cache, memory, etc.)

License

MIT

Package Sidebar

Install

npm i @nodefactory/server-eth-auth

Weekly Downloads

6

Version

0.1.3

License

MIT

Unpacked Size

18.6 kB

Total Files

20

Last publish

Collaborators

  • mpetrunic
  • morrigan88
  • makmuftic