Skip to content

Validation of web3 signatures (i.e. from MetaMask) for server Ethereum authentication

License

Notifications You must be signed in to change notification settings

NodeFactoryIo/server-eth-auth

Repository files navigation

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

About

Validation of web3 signatures (i.e. from MetaMask) for server Ethereum authentication

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published